Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(791)

Side by Side Diff: chrome/common/media_router/media_source_helper.cc

Issue 2927503002: [Presentation API / Media Router] Relax PresentationRequest URL check. (Closed)
Patch Set: updated scheme check in mr + tests Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/common/media_router/media_source_helper.h" 5 #include "chrome/common/media_router/media_source_helper.h"
6 6
7 #include <stdio.h> 7 #include <stdio.h>
8 8
9 #include <algorithm>
10
9 #include "base/strings/string_util.h" 11 #include "base/strings/string_util.h"
10 #include "base/strings/stringprintf.h" 12 #include "base/strings/stringprintf.h"
11 #include "chrome/common/media_router/media_source.h" 13 #include "chrome/common/media_router/media_source.h"
12 #include "url/gurl.h" 14 #include "url/gurl.h"
13 15
14 namespace media_router { 16 namespace media_router {
15 17
16 namespace { 18 namespace {
17 19
18 // Prefixes used to format and detect various protocols' media source URNs. 20 // Prefixes used to format and detect various protocols' media source URNs.
19 // See: https://www.ietf.org/rfc/rfc3406.txt 21 // See: https://www.ietf.org/rfc/rfc3406.txt
20 constexpr char kTabMediaUrnFormat[] = "urn:x-org.chromium.media:source:tab:%d"; 22 constexpr char kTabMediaUrnFormat[] = "urn:x-org.chromium.media:source:tab:%d";
21 constexpr char kDesktopMediaUrn[] = "urn:x-org.chromium.media:source:desktop"; 23 constexpr char kDesktopMediaUrn[] = "urn:x-org.chromium.media:source:desktop";
22 constexpr char kTabRemotingUrnFormat[] = 24 constexpr char kTabRemotingUrnFormat[] =
23 "urn:x-org.chromium.media:source:tab_content_remoting:%d"; 25 "urn:x-org.chromium.media:source:tab_content_remoting:%d";
24 constexpr char kCastPresentationUrlDomain[] = "google.com"; 26 constexpr char kCastPresentationUrlDomain[] = "google.com";
25 constexpr char kCastPresentationUrlPath[] = "/cast"; 27 constexpr char kCastPresentationUrlPath[] = "/cast";
26 28
27 // This value must be the same as |chrome.cast.AUTO_JOIN_PRESENTATION_ID| in the 29 // This value must be the same as |chrome.cast.AUTO_JOIN_PRESENTATION_ID| in the
28 // component extension. 30 // component extension.
29 constexpr char kAutoJoinPresentationId[] = "auto-join"; 31 constexpr char kAutoJoinPresentationId[] = "auto-join";
30 32
33 // List of non-http(s) schemes that are allowed in a Presentation URL.
34 constexpr std::array<const char* const, 4> kAllowedSchemes{
mark a. foltz 2017/06/06 22:49:08 Is std::array a type alias to POD or does it have
imcheng 2017/06/07 00:53:43 Yep, this is a POD. https://stackoverflow.com/ques
35 {"cast", "dial", "remote-playback", "test"}};
36
37 bool IsUrlAllowed(const GURL& url) {
mark a. foltz 2017/06/06 22:49:08 IsSchemeAllowed?
imcheng 2017/06/07 00:53:43 Done.
38 return url.SchemeIsHTTPOrHTTPS() ||
39 std::any_of(
mark a. foltz 2017/06/06 22:49:08 I think a for loop over a kAllowedSchemes array wo
imcheng 2017/06/07 00:53:43 A decent compiler should be able to optimize this.
40 kAllowedSchemes.begin(), kAllowedSchemes.end(),
41 [&url](const char* const scheme) { return url.SchemeIs(scheme); });
42 }
43
31 } // namespace 44 } // namespace
32 45
33 MediaSource MediaSourceForTab(int tab_id) { 46 MediaSource MediaSourceForTab(int tab_id) {
34 return MediaSource(base::StringPrintf(kTabMediaUrnFormat, tab_id)); 47 return MediaSource(base::StringPrintf(kTabMediaUrnFormat, tab_id));
35 } 48 }
36 49
37 MediaSource MediaSourceForTabContentRemoting(int tab_id) { 50 MediaSource MediaSourceForTabContentRemoting(int tab_id) {
38 return MediaSource(base::StringPrintf(kTabRemotingUrnFormat, tab_id)); 51 return MediaSource(base::StringPrintf(kTabRemotingUrnFormat, tab_id));
39 } 52 }
40 53
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 return -1; 93 return -1;
81 } 94 }
82 95
83 bool IsValidMediaSource(const MediaSource& source) { 96 bool IsValidMediaSource(const MediaSource& source) {
84 return TabIdFromMediaSource(source) > 0 || 97 return TabIdFromMediaSource(source) > 0 ||
85 IsDesktopMirroringMediaSource(source) || 98 IsDesktopMirroringMediaSource(source) ||
86 IsValidPresentationUrl(GURL(source.id())); 99 IsValidPresentationUrl(GURL(source.id()));
87 } 100 }
88 101
89 bool IsValidPresentationUrl(const GURL& url) { 102 bool IsValidPresentationUrl(const GURL& url) {
90 return url.is_valid() && url.SchemeIsHTTPOrHTTPS(); 103 return url.is_valid() && IsUrlAllowed(url);
91 } 104 }
92 105
93 bool IsAutoJoinPresentationId(const std::string& presentation_id) { 106 bool IsAutoJoinPresentationId(const std::string& presentation_id) {
94 return presentation_id == kAutoJoinPresentationId; 107 return presentation_id == kAutoJoinPresentationId;
95 } 108 }
96 109
97 } // namespace media_router 110 } // namespace media_router
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698