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

Side by Side Diff: chrome/browser/media/router/media_source_helper.cc

Issue 2517833004: [MR] Cancel auto-switching from tab mirroring to Cast SDK at page navigation based on user pref (Closed)
Patch Set: Address Mark and Jennifer's comments Created 4 years 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/browser/media/router/media_source_helper.h" 5 #include "chrome/browser/media/router/media_source_helper.h"
6 6
7 #include <stdio.h> 7 #include <stdio.h>
8 8
9 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
10 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
11 #include "chrome/browser/media/router/media_source.h" 11 #include "chrome/browser/media/router/media_source.h"
12 #include "chrome/browser/sessions/session_tab_helper.h" 12 #include "chrome/browser/sessions/session_tab_helper.h"
13 #include "url/gurl.h" 13 #include "url/gurl.h"
14 14
15 namespace media_router { 15 namespace media_router {
16 16
17 namespace { 17 namespace {
18 18
19 // Prefixes used to format and detect various protocols' media source URNs. 19 // Prefixes used to format and detect various protocols' media source URNs.
20 // See: https://www.ietf.org/rfc/rfc3406.txt 20 // See: https://www.ietf.org/rfc/rfc3406.txt
21 constexpr char kTabMediaUrnFormat[] = "urn:x-org.chromium.media:source:tab:%d"; 21 constexpr char kTabMediaUrnFormat[] = "urn:x-org.chromium.media:source:tab:%d";
22 constexpr char kDesktopMediaUrn[] = "urn:x-org.chromium.media:source:desktop"; 22 constexpr char kDesktopMediaUrn[] = "urn:x-org.chromium.media:source:desktop";
23 constexpr char kTabRemotingUrnFormat[] = 23 constexpr char kTabRemotingUrnFormat[] =
24 "urn:x-org.chromium.media:source:tab_content_remoting:%d"; 24 "urn:x-org.chromium.media:source:tab_content_remoting:%d";
25 constexpr char kCastPresentationUrlDomain[] = "google.com"; 25 constexpr char kCastPresentationUrlDomain[] = "google.com";
26 constexpr char kCastPresentationUrlPath[] = "/cast"; 26 constexpr char kCastPresentationUrlPath[] = "/cast";
27
28 // This value must be the same as |chrome.cast.AUTO_JOIN_PRESENTATION_ID| in the
29 // component extension.
30 constexpr char kAutoJoinPresentationId[] = "auto-join";
31
27 } // namespace 32 } // namespace
28 33
29 MediaSource MediaSourceForTab(int tab_id) { 34 MediaSource MediaSourceForTab(int tab_id) {
30 return MediaSource(base::StringPrintf(kTabMediaUrnFormat, tab_id)); 35 return MediaSource(base::StringPrintf(kTabMediaUrnFormat, tab_id));
31 } 36 }
32 37
33 MediaSource MediaSourceForTabContentRemoting(content::WebContents* contents) { 38 MediaSource MediaSourceForTabContentRemoting(content::WebContents* contents) {
34 DCHECK(contents); 39 DCHECK(contents);
35 return MediaSource(base::StringPrintf(kTabRemotingUrnFormat, 40 return MediaSource(base::StringPrintf(kTabRemotingUrnFormat,
36 SessionTabHelper::IdForTab(contents))); 41 SessionTabHelper::IdForTab(contents)));
(...skipping 17 matching lines...) Expand all
54 return sscanf(source.id().c_str(), kTabMediaUrnFormat, &tab_id) == 1 && 59 return sscanf(source.id().c_str(), kTabMediaUrnFormat, &tab_id) == 1 &&
55 tab_id > 0; 60 tab_id > 0;
56 } 61 }
57 62
58 bool IsMirroringMediaSource(const MediaSource& source) { 63 bool IsMirroringMediaSource(const MediaSource& source) {
59 return IsDesktopMirroringMediaSource(source) || 64 return IsDesktopMirroringMediaSource(source) ||
60 IsTabMirroringMediaSource(source); 65 IsTabMirroringMediaSource(source);
61 } 66 }
62 67
63 bool CanConnectToMediaSource(const MediaSource& source) { 68 bool CanConnectToMediaSource(const MediaSource& source) {
64 // compare host, port, scheme, and path prefix for source.url() 69 // Compare host, port, scheme, and path prefix for source.url().
65 if (!source.url().SchemeIs(url::kHttpsScheme) || 70 return source.url().SchemeIs(url::kHttpsScheme) &&
66 !source.url().DomainIs(kCastPresentationUrlDomain) || 71 source.url().DomainIs(kCastPresentationUrlDomain) &&
67 (!source.url().has_path() || 72 source.url().has_path() &&
68 source.url().path() != kCastPresentationUrlPath)) 73 source.url().path() == kCastPresentationUrlPath;
69 return false;
70
71 return true;
72 } 74 }
73 75
74 int TabIdFromMediaSource(const MediaSource& source) { 76 int TabIdFromMediaSource(const MediaSource& source) {
75 int tab_id; 77 int tab_id;
76 if (sscanf(source.id().c_str(), kTabMediaUrnFormat, &tab_id) == 1) 78 if (sscanf(source.id().c_str(), kTabMediaUrnFormat, &tab_id) == 1)
77 return tab_id; 79 return tab_id;
78 else if (sscanf(source.id().c_str(), kTabRemotingUrnFormat, &tab_id) == 1) 80 else if (sscanf(source.id().c_str(), kTabRemotingUrnFormat, &tab_id) == 1)
79 return tab_id; 81 return tab_id;
80 else 82 else
81 return -1; 83 return -1;
82 } 84 }
83 85
84 bool IsValidMediaSource(const MediaSource& source) { 86 bool IsValidMediaSource(const MediaSource& source) {
85 return TabIdFromMediaSource(source) > 0 || 87 return TabIdFromMediaSource(source) > 0 ||
86 IsDesktopMirroringMediaSource(source) || 88 IsDesktopMirroringMediaSource(source) ||
87 IsValidPresentationUrl(GURL(source.id())); 89 IsValidPresentationUrl(GURL(source.id()));
88 } 90 }
89 91
90 bool IsValidPresentationUrl(const GURL& url) { 92 bool IsValidPresentationUrl(const GURL& url) {
91 return url.is_valid() && url.SchemeIsHTTPOrHTTPS(); 93 return url.is_valid() && url.SchemeIsHTTPOrHTTPS();
92 } 94 }
93 95
96 bool IsAutoJoinPresentationId(const std::string& presentation_id) {
97 return presentation_id == kAutoJoinPresentationId;
98 }
99
94 } // namespace media_router 100 } // namespace media_router
OLDNEW
« no previous file with comments | « chrome/browser/media/router/media_source_helper.h ('k') | chrome/browser/media/router/presentation_service_delegate_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698