Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(434)

Unified Diff: chrome/browser/media/router/media_source_helper.cc

Issue 2138013003: media::mojom::Remoter and CastRemotingConnector/Sender (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Split-out some interfaces in prep for landing multi-part changes. Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/media/router/media_source_helper.cc
diff --git a/chrome/browser/media/router/media_source_helper.cc b/chrome/browser/media/router/media_source_helper.cc
index 9cf7620fe58bc83fab8aab13a3dcf98356488cba..374816d535ab399cb4b48250587fb42302a0e6ec 100644
--- a/chrome/browser/media/router/media_source_helper.cc
+++ b/chrome/browser/media/router/media_source_helper.cc
@@ -4,21 +4,32 @@
#include "chrome/browser/media/router/media_source_helper.h"
+#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "chrome/browser/media/router/media_source.h"
+#include "chrome/browser/sessions/session_tab_helper.h"
+#include "chrome/browser/ui/browser.h"
+#include "chrome/browser/ui/browser_list.h"
+#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "url/gurl.h"
namespace media_router {
+namespace {
+
// Prefixes used to format and detect various protocols' media source URNs.
// See: https://www.ietf.org/rfc/rfc3406.txt
-const char kTabMediaUrnPrefix[] = "urn:x-org.chromium.media:source:tab";
+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:";
+constexpr size_t kTabMediaUrnPrefixLength = sizeof(kTabMediaUrnPrefix) - 1;
+
+} // namespace
+
MediaSource MediaSourceForTab(int tab_id) {
- return MediaSource(base::StringPrintf("%s:%d", kTabMediaUrnPrefix, tab_id));
+ return MediaSource(base::StringPrintf("%s%d", kTabMediaUrnPrefix, tab_id));
}
MediaSource MediaSourceForDesktop() {
@@ -58,6 +69,37 @@ bool IsValidMediaSource(const MediaSource& source) {
return url.is_valid() && url.SchemeIsHTTPOrHTTPS();
}
+content::WebContents* WebContentsFromMediaSource(const MediaSource& source) {
+ if (!IsTabMirroringMediaSource(source))
+ return nullptr;
+
+ // Extract SessionTabHelper ID from the URN.
+ int tab_id = 0;
+ if (!base::StringToInt(
+ base::StringPiece(source.id().begin() + kTabMediaUrnPrefixLength,
+ source.id().end()),
+ &tab_id)) {
+ return nullptr;
+ }
+
+ // Look-up the WebContents instance associated with the |tab_id|.
+ //
+ // TODO(miu): This is broken for WebContentses that are not associated with
+ // Browser tabs (such as the offscreen presentations provided by the
+ // tabCapture API).
+ for (const Browser* target_browser : *BrowserList::GetInstance()) {
+ TabStripModel* const target_tab_strip = target_browser->tab_strip_model();
+ for (int i = 0; i < target_tab_strip->count(); ++i) {
+ content::WebContents* const contents =
+ target_tab_strip->GetWebContentsAt(i);
+ if (SessionTabHelper::IdForTab(contents) == tab_id)
+ return contents;
+ }
+ }
+
+ return nullptr;
+}
+
std::string PresentationUrlFromMediaSource(const MediaSource& source) {
return IsValidPresentationUrl(source.id()) ? source.id() : "";
}
« no previous file with comments | « chrome/browser/media/router/media_source_helper.h ('k') | chrome/browser/media/router/mojo/media_remoter.mojom » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698