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/browser/media/router/media_source_helper.h" |
6 | 6 |
7 #include "base/strings/string_util.h" | 7 #include "base/strings/string_util.h" |
8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
9 #include "chrome/browser/media/router/media_source.h" | 9 #include "chrome/browser/media/router/media_source.h" |
10 #include "url/gurl.h" | 10 #include "url/gurl.h" |
11 | 11 |
12 namespace media_router { | 12 namespace media_router { |
13 | 13 |
14 // Prefixes used to format and detect various protocols' media source URNs. | 14 // Prefixes used to format and detect various protocols' media source URNs. |
15 // See: https://www.ietf.org/rfc/rfc3406.txt | 15 // See: https://www.ietf.org/rfc/rfc3406.txt |
16 const char kTabMediaUrnPrefix[] = "urn:x-org.chromium.media:source:tab"; | 16 const char kTabMediaUrnPrefix[] = "urn:x-org.chromium.media:source:tab"; |
17 const char kDesktopMediaUrn[] = "urn:x-org.chromium.media:source:desktop"; | 17 const char kDesktopMediaUrn[] = "urn:x-org.chromium.media:source:desktop"; |
18 const char kCastUrnPrefix[] = "urn:x-com.google.cast:application:"; | 18 const char kCastUrnPrefix[] = "urn:x-com.google.cast:application:"; |
19 | 19 |
20 MediaSource ForTabMediaSource(int tab_id) { | 20 MediaSource MediaSourceForTab(int tab_id) { |
21 return MediaSource(base::StringPrintf("%s:%d", kTabMediaUrnPrefix, tab_id)); | 21 return MediaSource(base::StringPrintf("%s:%d", kTabMediaUrnPrefix, tab_id)); |
22 } | 22 } |
23 | 23 |
24 MediaSource ForDesktopMediaSource() { | 24 MediaSource MediaSourceForDesktop() { |
25 return MediaSource(std::string(kDesktopMediaUrn)); | 25 return MediaSource(std::string(kDesktopMediaUrn)); |
26 } | 26 } |
27 | 27 |
28 // TODO(mfoltz): Remove when the TODO in | 28 MediaSource MediaSourceForCastApp(const std::string& app_id) { |
29 // MediaSourceManager::GetDefaultMediaSource is resolved. | |
30 MediaSource ForCastAppMediaSource(const std::string& app_id) { | |
31 return MediaSource(kCastUrnPrefix + app_id); | 29 return MediaSource(kCastUrnPrefix + app_id); |
32 } | 30 } |
33 | 31 |
34 MediaSource ForPresentationUrl(const std::string& presentation_url) { | 32 MediaSource MediaSourceForPresentationUrl(const std::string& presentation_url) { |
35 return MediaSource(presentation_url); | 33 return MediaSource(presentation_url); |
36 } | 34 } |
37 | 35 |
38 bool IsMirroringMediaSource(const MediaSource& source) { | 36 bool IsMirroringMediaSource(const MediaSource& source) { |
39 return StartsWithASCII(source.id(), kDesktopMediaUrn, true) || | 37 return StartsWithASCII(source.id(), kDesktopMediaUrn, true) || |
40 StartsWithASCII(source.id(), kTabMediaUrnPrefix, true); | 38 StartsWithASCII(source.id(), kTabMediaUrnPrefix, true); |
41 } | 39 } |
42 | 40 |
43 bool IsValidMediaSource(const MediaSource& source) { | 41 bool IsValidMediaSource(const MediaSource& source) { |
44 if (IsMirroringMediaSource(source) || | 42 if (IsMirroringMediaSource(source) || |
45 StartsWithASCII(source.id(), kCastUrnPrefix, true)) { | 43 StartsWithASCII(source.id(), kCastUrnPrefix, true)) { |
46 return true; | 44 return true; |
47 } | 45 } |
48 GURL url(source.id()); | 46 GURL url(source.id()); |
49 return url.is_valid() && url.SchemeIsHTTPOrHTTPS(); | 47 return url.is_valid() && url.SchemeIsHTTPOrHTTPS(); |
50 } | 48 } |
51 | 49 |
| 50 std::string PresentationUrlFromMediaSource(const MediaSource& source) { |
| 51 return IsValidPresentationUrl(source.id()) ? source.id() : ""; |
| 52 } |
| 53 |
| 54 bool IsValidPresentationUrl(const std::string& url) { |
| 55 GURL gurl(url); |
| 56 return gurl.is_valid() && gurl.SchemeIsHTTPOrHTTPS(); |
| 57 } |
| 58 |
52 } // namespace media_router | 59 } // namespace media_router |
OLD | NEW |