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

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: Rebase 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()
apacible 2016/12/09 18:04:09 nit: capitalize "compare" and period at the end of
takumif 2016/12/09 19:18:12 Done.
65 if (!source.url().SchemeIs(url::kHttpsScheme) || 70 if (!source.url().SchemeIs(url::kHttpsScheme) ||
apacible 2016/12/09 18:04:09 Personal preference to just have this function jus
takumif 2016/12/09 19:18:12 Changed.
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; 74 return false;
70 75
71 return true; 76 return true;
72 } 77 }
73 78
74 int TabIdFromMediaSource(const MediaSource& source) { 79 int TabIdFromMediaSource(const MediaSource& source) {
75 int tab_id; 80 int tab_id;
76 if (sscanf(source.id().c_str(), kTabMediaUrnFormat, &tab_id) == 1) 81 if (sscanf(source.id().c_str(), kTabMediaUrnFormat, &tab_id) == 1)
77 return tab_id; 82 return tab_id;
78 else if (sscanf(source.id().c_str(), kTabRemotingUrnFormat, &tab_id) == 1) 83 else if (sscanf(source.id().c_str(), kTabRemotingUrnFormat, &tab_id) == 1)
79 return tab_id; 84 return tab_id;
80 else 85 else
81 return -1; 86 return -1;
82 } 87 }
83 88
84 bool IsValidMediaSource(const MediaSource& source) { 89 bool IsValidMediaSource(const MediaSource& source) {
85 return TabIdFromMediaSource(source) > 0 || 90 return TabIdFromMediaSource(source) > 0 ||
86 IsDesktopMirroringMediaSource(source) || 91 IsDesktopMirroringMediaSource(source) ||
87 IsValidPresentationUrl(GURL(source.id())); 92 IsValidPresentationUrl(GURL(source.id()));
88 } 93 }
89 94
90 bool IsValidPresentationUrl(const GURL& url) { 95 bool IsValidPresentationUrl(const GURL& url) {
91 return url.is_valid() && url.SchemeIsHTTPOrHTTPS(); 96 return url.is_valid() && url.SchemeIsHTTPOrHTTPS();
92 } 97 }
93 98
99 bool IsAutoJoinPresentationId(const std::string& presentation_id) {
100 return presentation_id == kAutoJoinPresentationId;
101 }
102
94 } // namespace media_router 103 } // namespace media_router
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698