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

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: Really add #include 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 #include <array>
11
9 #include "base/strings/string_util.h" 12 #include "base/strings/string_util.h"
10 #include "base/strings/stringprintf.h" 13 #include "base/strings/stringprintf.h"
11 #include "chrome/common/media_router/media_source.h" 14 #include "chrome/common/media_router/media_source.h"
12 #include "url/gurl.h" 15 #include "url/gurl.h"
13 16
14 namespace media_router { 17 namespace media_router {
15 18
16 namespace { 19 namespace {
17 20
18 // Prefixes used to format and detect various protocols' media source URNs. 21 // Prefixes used to format and detect various protocols' media source URNs.
19 // See: https://www.ietf.org/rfc/rfc3406.txt 22 // See: https://www.ietf.org/rfc/rfc3406.txt
20 constexpr char kTabMediaUrnFormat[] = "urn:x-org.chromium.media:source:tab:%d"; 23 constexpr char kTabMediaUrnFormat[] = "urn:x-org.chromium.media:source:tab:%d";
21 constexpr char kDesktopMediaUrn[] = "urn:x-org.chromium.media:source:desktop"; 24 constexpr char kDesktopMediaUrn[] = "urn:x-org.chromium.media:source:desktop";
22 constexpr char kTabRemotingUrnFormat[] = 25 constexpr char kTabRemotingUrnFormat[] =
23 "urn:x-org.chromium.media:source:tab_content_remoting:%d"; 26 "urn:x-org.chromium.media:source:tab_content_remoting:%d";
24 constexpr char kCastPresentationUrlDomain[] = "google.com"; 27 constexpr char kCastPresentationUrlDomain[] = "google.com";
25 constexpr char kCastPresentationUrlPath[] = "/cast"; 28 constexpr char kCastPresentationUrlPath[] = "/cast";
26 29
27 // This value must be the same as |chrome.cast.AUTO_JOIN_PRESENTATION_ID| in the 30 // This value must be the same as |chrome.cast.AUTO_JOIN_PRESENTATION_ID| in the
28 // component extension. 31 // component extension.
29 constexpr char kAutoJoinPresentationId[] = "auto-join"; 32 constexpr char kAutoJoinPresentationId[] = "auto-join";
30 33
34 // List of non-http(s) schemes that are allowed in a Presentation URL.
35 constexpr std::array<const char* const, 4> kAllowedSchemes{
36 {"cast", "dial", "remote-playback", "test"}};
37
38 bool IsSchemeAllowed(const GURL& url) {
39 return url.SchemeIsHTTPOrHTTPS() ||
40 std::any_of(
41 kAllowedSchemes.begin(), kAllowedSchemes.end(),
42 [&url](const char* const scheme) { return url.SchemeIs(scheme); });
43 }
44
31 } // namespace 45 } // namespace
32 46
33 MediaSource MediaSourceForTab(int tab_id) { 47 MediaSource MediaSourceForTab(int tab_id) {
34 return MediaSource(base::StringPrintf(kTabMediaUrnFormat, tab_id)); 48 return MediaSource(base::StringPrintf(kTabMediaUrnFormat, tab_id));
35 } 49 }
36 50
37 MediaSource MediaSourceForTabContentRemoting(int tab_id) { 51 MediaSource MediaSourceForTabContentRemoting(int tab_id) {
38 return MediaSource(base::StringPrintf(kTabRemotingUrnFormat, tab_id)); 52 return MediaSource(base::StringPrintf(kTabRemotingUrnFormat, tab_id));
39 } 53 }
40 54
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 return -1; 94 return -1;
81 } 95 }
82 96
83 bool IsValidMediaSource(const MediaSource& source) { 97 bool IsValidMediaSource(const MediaSource& source) {
84 return TabIdFromMediaSource(source) > 0 || 98 return TabIdFromMediaSource(source) > 0 ||
85 IsDesktopMirroringMediaSource(source) || 99 IsDesktopMirroringMediaSource(source) ||
86 IsValidPresentationUrl(GURL(source.id())); 100 IsValidPresentationUrl(GURL(source.id()));
87 } 101 }
88 102
89 bool IsValidPresentationUrl(const GURL& url) { 103 bool IsValidPresentationUrl(const GURL& url) {
90 return url.is_valid() && url.SchemeIsHTTPOrHTTPS(); 104 return url.is_valid() && IsSchemeAllowed(url);
91 } 105 }
92 106
93 bool IsAutoJoinPresentationId(const std::string& presentation_id) { 107 bool IsAutoJoinPresentationId(const std::string& presentation_id) {
94 return presentation_id == kAutoJoinPresentationId; 108 return presentation_id == kAutoJoinPresentationId;
95 } 109 }
96 110
97 } // namespace media_router 111 } // namespace media_router
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698