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

Unified Diff: content/public/browser/desktop_media_id.cc

Issue 1503563004: Desktop chrome tab capture-chooseDesktopMedia() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years 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: content/public/browser/desktop_media_id.cc
diff --git a/content/public/browser/desktop_media_id.cc b/content/public/browser/desktop_media_id.cc
index 1ec49b7b4de8594b3788e8b3a250ad3bf9164f6c..4c558d40d23f71a9687db36f8aa6970882bddc7a 100644
--- a/content/public/browser/desktop_media_id.cc
+++ b/content/public/browser/desktop_media_id.cc
@@ -73,13 +73,15 @@ namespace content {
const char kScreenPrefix[] = "screen";
const char kWindowPrefix[] = "window";
+// Prefix for tab and consist with existing code for tab capture.
+const char kTabPrefix[] = "web-contents-media-stream";
miu 2015/12/08 01:54:38 This and a lot of the other changes in this file d
GeorgeZ 2015/12/09 19:36:38 After modification, DesktopMediaID has an instance
#if defined(USE_AURA)
// static
DesktopMediaID DesktopMediaID::RegisterAuraWindow(DesktopMediaID::Type type,
aura::Window* window) {
- DCHECK(type == TYPE_SCREEN || type == TYPE_WINDOW);
+ DCHECK(type == TYPE_SCREEN || type == TYPE_WINDOW || type == TYPE_TAB);
DCHECK(window);
DesktopMediaID media_id(type, kNullId);
media_id.aura_id = AuraWindowRegistry::GetInstance()->RegisterWindow(window);
@@ -94,44 +96,74 @@ aura::Window* DesktopMediaID::GetAuraWindowById(const DesktopMediaID& id) {
#endif // defined(USE_AURA)
// static
+// Input string should in format:
+// for tab: web-contents-media-stream://"render_process_id":"render_process_id"
+// for no tab and aura: screen:"window_id" or window:"window_id"
+// for no tab and no aura: screen:"window_id:aura_id" or
+// window:"window_id:aura_id".
DesktopMediaID DesktopMediaID::Parse(const std::string& str) {
std::vector<std::string> parts = base::SplitString(
str, ":", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
-#if defined(USE_AURA)
- if (parts.size() != 3)
- return DesktopMediaID();
-#else
- if (parts.size() != 2)
+ if (parts.size() < 2)
return DesktopMediaID();
-#endif
Type type = TYPE_NONE;
if (parts[0] == kScreenPrefix) {
type = TYPE_SCREEN;
} else if (parts[0] == kWindowPrefix) {
type = TYPE_WINDOW;
+ } else if (parts[0] == kTabPrefix) {
+ type = TYPE_TAB;
} else {
return DesktopMediaID();
}
+ if (type == TYPE_TAB) {
+ if (parts.size() != 3)
+ return DesktopMediaID();
+ } else {
+#if defined(USE_AURA)
+ if (parts.size() != 3)
+ return DesktopMediaID();
+#else
+ if (parts.size() != 2)
+ return DesktopMediaID();
+#endif // defined(USE_AURA)
+ }
+
int64 id;
- if (!base::StringToInt64(parts[1], &id))
- return DesktopMediaID();
+ if (type != TYPE_TAB) {
+ if (!base::StringToInt64(parts[1], &id))
+ return DesktopMediaID();
- DesktopMediaID media_id(type, id);
+ DesktopMediaID media_id(type, id);
#if defined(USE_AURA)
- int64 aura_id;
- if (!base::StringToInt64(parts[2], &aura_id))
- return DesktopMediaID();
- media_id.aura_id = aura_id;
+ int64 aura_id;
+ if (!base::StringToInt64(parts[2], &aura_id))
+ return DesktopMediaID();
+ media_id.aura_id = aura_id;
#endif // defined(USE_AURA)
- return media_id;
+ return media_id;
+ } else {
+ int64 rend_process_id, main_render_frame_id;
+ if (!base::StringToInt64(parts[1].substr(2, parts[1].size() - 2),
+ &rend_process_id))
+ return DesktopMediaID();
+
+ if (!base::StringToInt64(parts[2], &main_render_frame_id))
+ return DesktopMediaID();
+
+ DesktopMediaID media_id(type, 0);
+ media_id.render_process_id = rend_process_id;
qiangchen 2015/12/07 22:45:56 Consider adding a constructor for DesktopMediaID.
GeorgeZ 2015/12/09 19:36:38 Done.
+ media_id.main_render_frame_id = main_render_frame_id;
+ return media_id;
+ }
}
-std::string DesktopMediaID::ToString() {
+std::string DesktopMediaID::ToString() const {
std::string prefix;
switch (type) {
case TYPE_NONE:
@@ -143,16 +175,26 @@ std::string DesktopMediaID::ToString() {
case TYPE_WINDOW:
prefix = kWindowPrefix;
break;
+ case TYPE_TAB:
+ prefix = kTabPrefix;
+ break;
}
DCHECK(!prefix.empty());
- prefix.append(":");
- prefix.append(base::Int64ToString(id));
+ if (type != TYPE_TAB) {
+ prefix.append(":");
+ prefix.append(base::Int64ToString(id));
#if defined(USE_AURA)
- prefix.append(":");
- prefix.append(base::Int64ToString(aura_id));
+ prefix.append(":");
+ prefix.append(base::Int64ToString(aura_id));
#endif // defined(USE_AURA)
+ } else {
+ prefix.append("://");
+ prefix.append(base::Int64ToString(render_process_id));
+ prefix.append(":");
+ prefix.append(base::Int64ToString(main_render_frame_id));
+ }
return prefix;
}
« content/public/browser/desktop_media_id.h ('K') | « content/public/browser/desktop_media_id.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698