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

Side by Side 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 4 years, 11 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "content/public/browser/desktop_media_id.h" 5 #include "content/public/browser/desktop_media_id.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <vector> 9 #include <vector>
10 10
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 namespace content { 75 namespace content {
76 76
77 const char kScreenPrefix[] = "screen"; 77 const char kScreenPrefix[] = "screen";
78 const char kWindowPrefix[] = "window"; 78 const char kWindowPrefix[] = "window";
79 79
80 #if defined(USE_AURA) 80 #if defined(USE_AURA)
81 81
82 // static 82 // static
83 DesktopMediaID DesktopMediaID::RegisterAuraWindow(DesktopMediaID::Type type, 83 DesktopMediaID DesktopMediaID::RegisterAuraWindow(DesktopMediaID::Type type,
84 aura::Window* window) { 84 aura::Window* window) {
85 DCHECK(type == TYPE_SCREEN || type == TYPE_WINDOW); 85 DCHECK(type == TYPE_SCREEN || type == TYPE_WINDOW ||
86 type == TYPE_WEB_CONTENTS);
Sergey Ulanov 2016/01/13 19:06:11 I don't think TYPE_WEB_CONTENTS makes sense here.
GeorgeZ 2016/01/13 22:29:02 Done.
86 DCHECK(window); 87 DCHECK(window);
87 DesktopMediaID media_id(type, kNullId); 88 DesktopMediaID media_id(type, kNullId);
88 media_id.aura_id = AuraWindowRegistry::GetInstance()->RegisterWindow(window); 89 media_id.aura_id = AuraWindowRegistry::GetInstance()->RegisterWindow(window);
89 return media_id; 90 return media_id;
90 } 91 }
91 92
92 // static 93 // static
93 aura::Window* DesktopMediaID::GetAuraWindowById(const DesktopMediaID& id) { 94 aura::Window* DesktopMediaID::GetAuraWindowById(const DesktopMediaID& id) {
94 return AuraWindowRegistry::GetInstance()->GetWindowById(id.aura_id); 95 return AuraWindowRegistry::GetInstance()->GetWindowById(id.aura_id);
95 } 96 }
96 97
97 #endif // defined(USE_AURA) 98 #endif // defined(USE_AURA)
98 99
100 bool DesktopMediaID::operator<(const DesktopMediaID& other) const {
101 #if defined(USE_AURA)
102 return std::tie(type, id, aura_id, web_contents_id) <
103 std::tie(other.type, other.id, other.aura_id, other.web_contents_id);
104 #else
105 return std::tie(type, id, web_contents_id) <
106 std::tie(other.type, other.id, web_contents_id);
107 #endif
108 }
109
110 bool DesktopMediaID::operator==(const DesktopMediaID& other) const {
111 #if defined(USE_AURA)
112 return type == other.type && id == other.id && aura_id == other.aura_id &&
113 web_contents_id == other.web_contents_id;
114 #else
115 return type == other.type && id == other.id &&
116 web_contents_id == other.web_contents_id;
117 #endif
118 }
119
99 // static 120 // static
121 // Input string should in format:
122 // for WebContents:
123 // web-contents-media-stream://"render_process_id":"render_process_id"
124 // for no WebContents and aura: screen:"window_id" or window:"window_id"
125 // for no web_contents and no aura: screen:"window_id:aura_id" or
126 // window:"window_id:aura_id".
100 DesktopMediaID DesktopMediaID::Parse(const std::string& str) { 127 DesktopMediaID DesktopMediaID::Parse(const std::string& str) {
101 std::vector<std::string> parts = base::SplitString( 128 std::vector<std::string> parts = base::SplitString(
102 str, ":", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); 129 str, ":", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
103 130
131 if (parts.size() < 2)
132 return DesktopMediaID();
133
134 Type type = TYPE_NONE;
135 if (parts[0] == kScreenPrefix) {
136 type = TYPE_SCREEN;
137 } else if (parts[0] == kWindowPrefix) {
138 type = TYPE_WINDOW;
139 } else if (parts[0] == kWebContentsCaptureScheme) {
140 type = TYPE_WEB_CONTENTS;
141 } else {
142 return DesktopMediaID();
143 }
144
145 // WebContents type.
146 if (type == TYPE_WEB_CONTENTS) {
147 WebContentsMediaCaptureId temp_id = WebContentsMediaCaptureId::Parse(str);
148 return DesktopMediaID(type, 0, temp_id);
Sergey Ulanov 2016/01/13 19:06:11 WebContentsMediaCaptureId::Parse() may fail and th
GeorgeZ 2016/01/13 22:29:02 Good idea.
149 }
150
151 // Screen and window types.
104 #if defined(USE_AURA) 152 #if defined(USE_AURA)
105 if (parts.size() != 3) 153 if (parts.size() != 3)
106 return DesktopMediaID(); 154 return DesktopMediaID();
107 #else 155 #else
108 if (parts.size() != 2) 156 if (parts.size() != 2)
109 return DesktopMediaID(); 157 return DesktopMediaID();
110 #endif 158 #endif // defined(USE_AURA)
111 159
112 Type type = TYPE_NONE; 160 int64_t tempid;
Sergey Ulanov 2016/01/13 19:06:11 Please keep this called 'id' instead of 'tempid'.
GeorgeZ 2016/01/13 22:29:02 Done.
113 if (parts[0] == kScreenPrefix) { 161 if (!base::StringToInt64(parts[1], &tempid))
114 type = TYPE_SCREEN;
115 } else if (parts[0] == kWindowPrefix) {
116 type = TYPE_WINDOW;
117 } else {
118 return DesktopMediaID();
119 }
120
121 int64_t id;
122 if (!base::StringToInt64(parts[1], &id))
123 return DesktopMediaID(); 162 return DesktopMediaID();
124 163
125 DesktopMediaID media_id(type, id); 164 DesktopMediaID media_id(type, tempid);
126 165
127 #if defined(USE_AURA) 166 #if defined(USE_AURA)
128 int64_t aura_id; 167 int64_t aura_id;
129 if (!base::StringToInt64(parts[2], &aura_id)) 168 if (!base::StringToInt64(parts[2], &aura_id))
130 return DesktopMediaID(); 169 return DesktopMediaID();
170
131 media_id.aura_id = aura_id; 171 media_id.aura_id = aura_id;
132 #endif // defined(USE_AURA) 172 #endif // defined(USE_AURA)
133 173
134 return media_id; 174 return media_id;
135 } 175 }
136 176
137 std::string DesktopMediaID::ToString() { 177 std::string DesktopMediaID::ToString() const {
138 std::string prefix; 178 std::string prefix;
139 switch (type) { 179 switch (type) {
140 case TYPE_NONE: 180 case TYPE_NONE:
141 NOTREACHED(); 181 NOTREACHED();
142 return std::string(); 182 return std::string();
143 case TYPE_SCREEN: 183 case TYPE_SCREEN:
144 prefix = kScreenPrefix; 184 prefix = kScreenPrefix;
145 break; 185 break;
146 case TYPE_WINDOW: 186 case TYPE_WINDOW:
147 prefix = kWindowPrefix; 187 prefix = kWindowPrefix;
148 break; 188 break;
189 case TYPE_WEB_CONTENTS:
190 return web_contents_id.ToString();
191 break;
149 } 192 }
150 DCHECK(!prefix.empty()); 193 DCHECK(!prefix.empty());
151 194
195 // Screen and Window types.
152 prefix.append(":"); 196 prefix.append(":");
153 prefix.append(base::Int64ToString(id)); 197 prefix.append(base::Int64ToString(id));
154 198
155 #if defined(USE_AURA) 199 #if defined(USE_AURA)
156 prefix.append(":"); 200 prefix.append(":");
157 prefix.append(base::Int64ToString(aura_id)); 201 prefix.append(base::Int64ToString(aura_id));
158 #endif // defined(USE_AURA) 202 #endif // defined(USE_AURA)
159 203
160 return prefix; 204 return prefix;
161 } 205 }
162 206
163 } // namespace content 207 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698