Chromium Code Reviews| 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 const char kOrigin[] = ""; | |
| 19 | 20 |
| 20 MediaSource MediaSourceForTab(int tab_id) { | 21 MediaSource MediaSourceForTab(int tab_id) { |
| 21 return MediaSource(base::StringPrintf("%s:%d", kTabMediaUrnPrefix, tab_id)); | 22 return MediaSource(base::StringPrintf("%s:%d", kTabMediaUrnPrefix, tab_id)); |
| 22 } | 23 } |
| 23 | 24 |
| 24 MediaSource MediaSourceForDesktop() { | 25 MediaSource MediaSourceForDesktop() { |
| 25 return MediaSource(std::string(kDesktopMediaUrn)); | 26 return MediaSource(std::string(kDesktopMediaUrn)); |
| 26 } | 27 } |
| 27 | 28 |
| 29 GURL OriginForDesktop() { | |
|
mark a. foltz
2016/02/17 21:50:51
If we need an origin for tab and desktop casting,
matt.boetger
2016/02/18 00:50:33
Done.
| |
| 30 return GURL(std::string(kOrigin)); | |
| 31 } | |
| 32 | |
| 28 MediaSource MediaSourceForCastApp(const std::string& app_id) { | 33 MediaSource MediaSourceForCastApp(const std::string& app_id) { |
| 29 return MediaSource(kCastUrnPrefix + app_id); | 34 return MediaSource(kCastUrnPrefix + app_id); |
| 30 } | 35 } |
| 31 | 36 |
| 32 MediaSource MediaSourceForPresentationUrl(const std::string& presentation_url) { | 37 MediaSource MediaSourceForPresentationUrl(const std::string& presentation_url) { |
| 33 return MediaSource(presentation_url); | 38 return MediaSource(presentation_url); |
| 34 } | 39 } |
| 35 | 40 |
| 36 bool IsDesktopMirroringMediaSource(const MediaSource& source) { | 41 bool IsDesktopMirroringMediaSource(const MediaSource& source) { |
| 37 return base::StartsWith(source.id(), kDesktopMediaUrn, | 42 return base::StartsWith(source.id(), kDesktopMediaUrn, |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 61 std::string PresentationUrlFromMediaSource(const MediaSource& source) { | 66 std::string PresentationUrlFromMediaSource(const MediaSource& source) { |
| 62 return IsValidPresentationUrl(source.id()) ? source.id() : ""; | 67 return IsValidPresentationUrl(source.id()) ? source.id() : ""; |
| 63 } | 68 } |
| 64 | 69 |
| 65 bool IsValidPresentationUrl(const std::string& url) { | 70 bool IsValidPresentationUrl(const std::string& url) { |
| 66 GURL gurl(url); | 71 GURL gurl(url); |
| 67 return gurl.is_valid() && gurl.SchemeIsHTTPOrHTTPS(); | 72 return gurl.is_valid() && gurl.SchemeIsHTTPOrHTTPS(); |
| 68 } | 73 } |
| 69 | 74 |
| 70 } // namespace media_router | 75 } // namespace media_router |
| OLD | NEW |