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

Side by Side Diff: chrome/browser/extensions/api/tab_capture/tab_capture_api.cc

Issue 2399423004: [Extensions] Convert some ChromeSyncExtensionFunctions (Closed)
Patch Set: Created 4 years, 2 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 // Implements the Chrome Extensions Tab Capture API. 5 // Implements the Chrome Extensions Tab Capture API.
6 6
7 #include "chrome/browser/extensions/api/tab_capture/tab_capture_api.h" 7 #include "chrome/browser/extensions/api/tab_capture/tab_capture_api.h"
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <memory> 10 #include <memory>
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 kBetaChromecastExtensionId, // Google Cast Beta 192 kBetaChromecastExtensionId, // Google Cast Beta
193 kStableChromecastExtensionId, // Google Cast Stable 193 kStableChromecastExtensionId, // Google Cast Stable
194 "hlgmmjhlnlapooncikdpiiokdjcdpjme", // Test cast extension 194 "hlgmmjhlnlapooncikdpiiokdjcdpjme", // Test cast extension
195 }; 195 };
196 196
197 const char* const kMediaRouterExtensionIds[] = { 197 const char* const kMediaRouterExtensionIds[] = {
198 "pkedcjkdefgpdelpbcmbmeomcjbeemfm", // Stable 198 "pkedcjkdefgpdelpbcmbmeomcjbeemfm", // Stable
199 "ekpaaapppgpmolpcldedioblbkmijaca", // Beta 199 "ekpaaapppgpmolpcldedioblbkmijaca", // Beta
200 }; 200 };
201 201
202 bool TabCaptureCaptureFunction::RunSync() { 202 ExtensionFunction::ResponseAction TabCaptureCaptureFunction::Run() {
203 std::unique_ptr<api::tab_capture::Capture::Params> params = 203 std::unique_ptr<api::tab_capture::Capture::Params> params =
204 TabCapture::Capture::Params::Create(*args_); 204 TabCapture::Capture::Params::Create(*args_);
205 EXTENSION_FUNCTION_VALIDATE(params); 205 EXTENSION_FUNCTION_VALIDATE(params);
206 206
207 // Figure out the active WebContents and retrieve the needed ids. 207 // Figure out the active WebContents and retrieve the needed ids.
208 Browser* target_browser = 208 Browser* target_browser = chrome::FindAnyBrowser(
209 chrome::FindAnyBrowser(GetProfile(), include_incognito()); 209 Profile::FromBrowserContext(browser_context()), include_incognito());
210 if (!target_browser) { 210 if (!target_browser)
211 error_ = kFindingTabError; 211 return RespondNow(Error(kFindingTabError));
212 return false;
213 }
214 212
215 content::WebContents* target_contents = 213 content::WebContents* target_contents =
216 target_browser->tab_strip_model()->GetActiveWebContents(); 214 target_browser->tab_strip_model()->GetActiveWebContents();
217 if (!target_contents) { 215 if (!target_contents)
218 error_ = kFindingTabError; 216 return RespondNow(Error(kFindingTabError));
219 return false;
220 }
221 217
222 const std::string& extension_id = extension()->id(); 218 const std::string& extension_id = extension()->id();
223 219
224 // Make sure either we have been granted permission to capture through an 220 // Make sure either we have been granted permission to capture through an
225 // extension icon click or our extension is whitelisted. 221 // extension icon click or our extension is whitelisted.
226 if (!extension()->permissions_data()->HasAPIPermissionForTab( 222 if (!extension()->permissions_data()->HasAPIPermissionForTab(
227 SessionTabHelper::IdForTab(target_contents), 223 SessionTabHelper::IdForTab(target_contents),
228 APIPermission::kTabCaptureForTab) && 224 APIPermission::kTabCaptureForTab) &&
229 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( 225 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
230 switches::kWhitelistedExtensionID) != extension_id && 226 switches::kWhitelistedExtensionID) != extension_id &&
231 !SimpleFeature::IsIdInArray(extension_id, kChromecastExtensionIds, 227 !SimpleFeature::IsIdInArray(extension_id, kChromecastExtensionIds,
232 arraysize(kChromecastExtensionIds)) && 228 arraysize(kChromecastExtensionIds)) &&
233 !SimpleFeature::IsIdInArray(extension_id, kMediaRouterExtensionIds, 229 !SimpleFeature::IsIdInArray(extension_id, kMediaRouterExtensionIds,
234 arraysize(kMediaRouterExtensionIds))) { 230 arraysize(kMediaRouterExtensionIds))) {
235 error_ = kGrantError; 231 return RespondNow(Error(kGrantError));
236 return false;
237 } 232 }
238 233
239 if (!OptionsSpecifyAudioOrVideo(params->options)) { 234 if (!OptionsSpecifyAudioOrVideo(params->options))
240 error_ = kNoAudioOrVideo; 235 return RespondNow(Error(kNoAudioOrVideo));
241 return false;
242 }
243 236
244 TabCaptureRegistry* registry = TabCaptureRegistry::Get(GetProfile()); 237 TabCaptureRegistry* registry = TabCaptureRegistry::Get(browser_context());
245 if (!registry->AddRequest(target_contents, extension_id, false)) { 238 if (!registry->AddRequest(target_contents, extension_id, false)) {
246 // TODO(miu): Allow multiple consumers of single tab capture. 239 // TODO(miu): Allow multiple consumers of single tab capture.
247 // http://crbug.com/535336 240 // http://crbug.com/535336
248 error_ = kCapturingSameTab; 241 return RespondNow(Error(kCapturingSameTab));
249 return false;
250 } 242 }
251 FilterDeprecatedGoogConstraints(&params->options); 243 FilterDeprecatedGoogConstraints(&params->options);
252 AddMediaStreamSourceConstraints(target_contents, &params->options); 244 AddMediaStreamSourceConstraints(target_contents, &params->options);
253 245
254 // At this point, everything is set up in the browser process. It's now up to 246 // At this point, everything is set up in the browser process. It's now up to
255 // the custom JS bindings in the extension's render process to request a 247 // the custom JS bindings in the extension's render process to request a
256 // MediaStream using navigator.webkitGetUserMedia(). The result dictionary, 248 // MediaStream using navigator.webkitGetUserMedia(). The result dictionary,
257 // passed to SetResult() here, contains the extra "hidden options" that will 249 // passed to SetResult() here, contains the extra "hidden options" that will
258 // allow the Chrome platform implementation for getUserMedia() to start the 250 // allow the Chrome platform implementation for getUserMedia() to start the
259 // virtual audio/video capture devices and set up all the data flows. The 251 // virtual audio/video capture devices and set up all the data flows. The
260 // custom JS bindings can be found here: 252 // custom JS bindings can be found here:
261 // chrome/renderer/resources/extensions/tab_capture_custom_bindings.js 253 // chrome/renderer/resources/extensions/tab_capture_custom_bindings.js
262 std::unique_ptr<base::DictionaryValue> result(new base::DictionaryValue()); 254 std::unique_ptr<base::DictionaryValue> result(new base::DictionaryValue());
263 result->MergeDictionary(params->options.ToValue().get()); 255 result->MergeDictionary(params->options.ToValue().get());
264 SetResult(std::move(result)); 256 return RespondNow(OneArgument(std::move(result)));
265 return true;
266 } 257 }
267 258
268 bool TabCaptureGetCapturedTabsFunction::RunSync() { 259 ExtensionFunction::ResponseAction TabCaptureGetCapturedTabsFunction::Run() {
269 TabCaptureRegistry* registry = TabCaptureRegistry::Get(GetProfile()); 260 TabCaptureRegistry* registry = TabCaptureRegistry::Get(browser_context());
270 std::unique_ptr<base::ListValue> list(new base::ListValue()); 261 std::unique_ptr<base::ListValue> list(new base::ListValue());
271 if (registry) 262 if (registry)
272 registry->GetCapturedTabs(extension()->id(), list.get()); 263 registry->GetCapturedTabs(extension()->id(), list.get());
273 SetResult(std::move(list)); 264 return RespondNow(OneArgument(std::move(list)));
274 return true;
275 } 265 }
276 266
277 ExtensionFunction::ResponseAction TabCaptureCaptureOffscreenTabFunction::Run() { 267 ExtensionFunction::ResponseAction TabCaptureCaptureOffscreenTabFunction::Run() {
278 std::unique_ptr<TabCapture::CaptureOffscreenTab::Params> params = 268 std::unique_ptr<TabCapture::CaptureOffscreenTab::Params> params =
279 TabCapture::CaptureOffscreenTab::Params::Create(*args_); 269 TabCapture::CaptureOffscreenTab::Params::Create(*args_);
280 EXTENSION_FUNCTION_VALIDATE(params); 270 EXTENSION_FUNCTION_VALIDATE(params);
281 271
282 // Make sure the extension is whitelisted for using this API, regardless of 272 // Make sure the extension is whitelisted for using this API, regardless of
283 // Chrome channel. 273 // Chrome channel.
284 // 274 //
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 } 362 }
373 } 363 }
374 364
375 // No maximum size was provided, so just return the default size bounded by 365 // No maximum size was provided, so just return the default size bounded by
376 // the minimum size. 366 // the minimum size.
377 return gfx::Size(std::max(kDefaultWidth, min_size.width()), 367 return gfx::Size(std::max(kDefaultWidth, min_size.width()),
378 std::max(kDefaultHeight, min_size.height())); 368 std::max(kDefaultHeight, min_size.height()));
379 } 369 }
380 370
381 } // namespace extensions 371 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698