| Index: chrome/browser/media/router/media_source.cc
|
| diff --git a/chrome/browser/media/router/media_source.cc b/chrome/browser/media/router/media_source.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..fca12446f424144f2ce7da1a6b06ee1950ba705a
|
| --- /dev/null
|
| +++ b/chrome/browser/media/router/media_source.cc
|
| @@ -0,0 +1,75 @@
|
| +// Copyright 2015 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "chrome/browser/media/router/media_source.h"
|
| +
|
| +#include "base/strings/string_util.h"
|
| +#include "base/strings/stringprintf.h"
|
| +#include "url/gurl.h"
|
| +
|
| +namespace media_router {
|
| +
|
| +namespace {
|
| +
|
| +// See: https://www.ietf.org/rfc/rfc3406.txt
|
| +const char kTabMediaUrnPrefix[] = "urn:x-org.chromium.media:source:tab";
|
| +const char kDesktopMediaUrn[] = "urn:x-org.chromium.media:source:desktop";
|
| +const char kCastUrnPrefix[] = "urn:x-com.google.cast:application:";
|
| +
|
| +bool IdSupportsMirroring(const std::string& id) {
|
| + return StartsWithASCII(id, kDesktopMediaUrn, true) ||
|
| + StartsWithASCII(id, kTabMediaUrnPrefix, true);
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| +MediaSource::MediaSource(const std::string& source_id) : id_(source_id) {}
|
| +
|
| +MediaSource::~MediaSource() {}
|
| +
|
| +
|
| +const std::string& MediaSource::id() const {
|
| + return id_;
|
| +}
|
| +
|
| +// static
|
| +MediaSource MediaSource::ForTab(int tab_id) {
|
| + return MediaSource(base::StringPrintf("%s:%d", kTabMediaUrnPrefix, tab_id));
|
| +}
|
| +
|
| +// static
|
| +MediaSource MediaSource::ForDesktop() {
|
| + return MediaSource(std::string(kDesktopMediaUrn));
|
| +}
|
| +
|
| +// static
|
| +// TODO(mfoltz): Remove when the TODO in
|
| +// MediaSourceManager::GetDefaultMediaSource is resolved.
|
| +MediaSource MediaSource::ForCastApp(const std::string& app_id) {
|
| + return MediaSource(kCastUrnPrefix + app_id);
|
| +}
|
| +
|
| +// static
|
| +MediaSource MediaSource::ForPresentationUrl(
|
| + const std::string& presentation_url) {
|
| + return MediaSource(presentation_url);
|
| +}
|
| +
|
| +bool MediaSource::Parse(const std::string& id) {
|
| + if (!IdSupportsMirroring(id) &&
|
| + !StartsWithASCII(id, kCastUrnPrefix, true)) {
|
| + GURL url(id);
|
| + if (!url.is_valid() || !url.SchemeIsHTTPOrHTTPS()) {
|
| + return false;
|
| + }
|
| + }
|
| + id_ = id;
|
| + return true;
|
| +}
|
| +
|
| +bool MediaSource::SupportsMirroring() const {
|
| + return IdSupportsMirroring(id_);
|
| +}
|
| +
|
| +} // namespace media_router
|
|
|