OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/media/router/media_source.h" |
| 6 |
| 7 #include "base/strings/string_util.h" |
| 8 #include "base/strings/stringprintf.h" |
| 9 #include "url/gurl.h" |
| 10 |
| 11 namespace media_router { |
| 12 |
| 13 namespace { |
| 14 |
| 15 // See: https://www.ietf.org/rfc/rfc3406.txt |
| 16 const char kTabMediaUrnPrefix[] = "urn:x-org.chromium.media:source:tab"; |
| 17 const char kDesktopMediaUrn[] = "urn:x-org.chromium.media:source:desktop"; |
| 18 const char kCastUrnPrefix[] = "urn:x-com.google.cast:application:"; |
| 19 |
| 20 bool IdSupportsMirroring(const std::string& id) { |
| 21 return StartsWithASCII(id, kDesktopMediaUrn, true) || |
| 22 StartsWithASCII(id, kTabMediaUrnPrefix, true); |
| 23 } |
| 24 |
| 25 } // namespace |
| 26 |
| 27 MediaSource::MediaSource(const std::string& source_id) : id_(source_id) {} |
| 28 |
| 29 MediaSource::~MediaSource() {} |
| 30 |
| 31 |
| 32 const std::string& MediaSource::id() const { |
| 33 return id_; |
| 34 } |
| 35 |
| 36 // static |
| 37 MediaSource MediaSource::ForTab(int tab_id) { |
| 38 return MediaSource(base::StringPrintf("%s:%d", kTabMediaUrnPrefix, tab_id)); |
| 39 } |
| 40 |
| 41 // static |
| 42 MediaSource MediaSource::ForDesktop() { |
| 43 return MediaSource(std::string(kDesktopMediaUrn)); |
| 44 } |
| 45 |
| 46 // static |
| 47 // TODO(mfoltz): Remove when the TODO in |
| 48 // MediaSourceManager::GetDefaultMediaSource is resolved. |
| 49 MediaSource MediaSource::ForCastApp(const std::string& app_id) { |
| 50 return MediaSource(kCastUrnPrefix + app_id); |
| 51 } |
| 52 |
| 53 // static |
| 54 MediaSource MediaSource::ForPresentationUrl( |
| 55 const std::string& presentation_url) { |
| 56 return MediaSource(presentation_url); |
| 57 } |
| 58 |
| 59 bool MediaSource::Parse(const std::string& id) { |
| 60 if (!IdSupportsMirroring(id) && |
| 61 !StartsWithASCII(id, kCastUrnPrefix, true)) { |
| 62 GURL url(id); |
| 63 if (!url.is_valid() || !url.SchemeIsHTTPOrHTTPS()) { |
| 64 return false; |
| 65 } |
| 66 } |
| 67 id_ = id; |
| 68 return true; |
| 69 } |
| 70 |
| 71 bool MediaSource::SupportsMirroring() const { |
| 72 return IdSupportsMirroring(id_); |
| 73 } |
| 74 |
| 75 } // namespace media_router |
OLD | NEW |