OLD | NEW |
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/common/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/common/media_router/media_source.h" |
12 #include "chrome/browser/sessions/session_tab_helper.h" | |
13 #include "url/gurl.h" | 12 #include "url/gurl.h" |
14 | 13 |
15 namespace media_router { | 14 namespace media_router { |
16 | 15 |
17 namespace { | 16 namespace { |
18 | 17 |
19 // Prefixes used to format and detect various protocols' media source URNs. | 18 // Prefixes used to format and detect various protocols' media source URNs. |
20 // See: https://www.ietf.org/rfc/rfc3406.txt | 19 // See: https://www.ietf.org/rfc/rfc3406.txt |
21 constexpr char kTabMediaUrnFormat[] = "urn:x-org.chromium.media:source:tab:%d"; | 20 constexpr char kTabMediaUrnFormat[] = "urn:x-org.chromium.media:source:tab:%d"; |
22 constexpr char kDesktopMediaUrn[] = "urn:x-org.chromium.media:source:desktop"; | 21 constexpr char kDesktopMediaUrn[] = "urn:x-org.chromium.media:source:desktop"; |
23 constexpr char kTabRemotingUrnFormat[] = | 22 constexpr char kTabRemotingUrnFormat[] = |
24 "urn:x-org.chromium.media:source:tab_content_remoting:%d"; | 23 "urn:x-org.chromium.media:source:tab_content_remoting:%d"; |
25 constexpr char kCastPresentationUrlDomain[] = "google.com"; | 24 constexpr char kCastPresentationUrlDomain[] = "google.com"; |
26 constexpr char kCastPresentationUrlPath[] = "/cast"; | 25 constexpr char kCastPresentationUrlPath[] = "/cast"; |
27 | 26 |
28 // This value must be the same as |chrome.cast.AUTO_JOIN_PRESENTATION_ID| in the | 27 // This value must be the same as |chrome.cast.AUTO_JOIN_PRESENTATION_ID| in the |
29 // component extension. | 28 // component extension. |
30 constexpr char kAutoJoinPresentationId[] = "auto-join"; | 29 constexpr char kAutoJoinPresentationId[] = "auto-join"; |
31 | 30 |
32 } // namespace | 31 } // namespace |
33 | 32 |
34 MediaSource MediaSourceForTab(int tab_id) { | 33 MediaSource MediaSourceForTab(int tab_id) { |
35 return MediaSource(base::StringPrintf(kTabMediaUrnFormat, tab_id)); | 34 return MediaSource(base::StringPrintf(kTabMediaUrnFormat, tab_id)); |
36 } | 35 } |
37 | 36 |
38 MediaSource MediaSourceForTabContentRemoting(content::WebContents* contents) { | 37 MediaSource MediaSourceForTabContentRemoting(int tab_id) { |
39 DCHECK(contents); | 38 return MediaSource(base::StringPrintf(kTabRemotingUrnFormat, tab_id)); |
40 return MediaSource(base::StringPrintf(kTabRemotingUrnFormat, | |
41 SessionTabHelper::IdForTab(contents))); | |
42 } | 39 } |
43 | 40 |
44 MediaSource MediaSourceForDesktop() { | 41 MediaSource MediaSourceForDesktop() { |
45 return MediaSource(std::string(kDesktopMediaUrn)); | 42 return MediaSource(std::string(kDesktopMediaUrn)); |
46 } | 43 } |
47 | 44 |
48 MediaSource MediaSourceForPresentationUrl(const GURL& presentation_url) { | 45 MediaSource MediaSourceForPresentationUrl(const GURL& presentation_url) { |
49 return MediaSource(presentation_url); | 46 return MediaSource(presentation_url); |
50 } | 47 } |
51 | 48 |
52 bool IsDesktopMirroringMediaSource(const MediaSource& source) { | 49 bool IsDesktopMirroringMediaSource(const MediaSource& source) { |
53 return base::StartsWith(source.id(), kDesktopMediaUrn, | 50 return base::StartsWith(source.id(), kDesktopMediaUrn, |
54 base::CompareCase::SENSITIVE); | 51 base::CompareCase::SENSITIVE); |
55 } | 52 } |
56 | 53 |
57 bool IsTabMirroringMediaSource(const MediaSource& source) { | 54 bool IsTabMirroringMediaSource(const MediaSource& source) { |
58 int tab_id; | 55 int tab_id; |
59 return sscanf(source.id().c_str(), kTabMediaUrnFormat, &tab_id) == 1 && | 56 return sscanf(source.id().c_str(), kTabMediaUrnFormat, &tab_id) == 1 && |
60 tab_id > 0; | 57 tab_id > 0; |
61 } | 58 } |
62 | 59 |
63 bool IsMirroringMediaSource(const MediaSource& source) { | 60 bool IsMirroringMediaSource(const MediaSource& source) { |
64 return IsDesktopMirroringMediaSource(source) || | 61 return IsDesktopMirroringMediaSource(source) || |
65 IsTabMirroringMediaSource(source); | 62 IsTabMirroringMediaSource(source); |
66 } | 63 } |
67 | 64 |
68 bool CanConnectToMediaSource(const MediaSource& source) { | 65 bool CanConnectToMediaSource(const MediaSource& source) { |
69 // Compare host, port, scheme, and path prefix for source.url(). | 66 // Compare host, port, scheme, and path prefix for source.url(). |
70 return source.url().SchemeIs(url::kHttpsScheme) && | 67 return source.url().SchemeIs(url::kHttpsScheme) && |
(...skipping 20 matching lines...) Expand all Loading... |
91 | 88 |
92 bool IsValidPresentationUrl(const GURL& url) { | 89 bool IsValidPresentationUrl(const GURL& url) { |
93 return url.is_valid() && url.SchemeIsHTTPOrHTTPS(); | 90 return url.is_valid() && url.SchemeIsHTTPOrHTTPS(); |
94 } | 91 } |
95 | 92 |
96 bool IsAutoJoinPresentationId(const std::string& presentation_id) { | 93 bool IsAutoJoinPresentationId(const std::string& presentation_id) { |
97 return presentation_id == kAutoJoinPresentationId; | 94 return presentation_id == kAutoJoinPresentationId; |
98 } | 95 } |
99 | 96 |
100 } // namespace media_router | 97 } // namespace media_router |
OLD | NEW |