OLD | NEW |
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 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 | 267 |
268 bool TabCaptureGetCapturedTabsFunction::RunSync() { | 268 bool TabCaptureGetCapturedTabsFunction::RunSync() { |
269 TabCaptureRegistry* registry = TabCaptureRegistry::Get(GetProfile()); | 269 TabCaptureRegistry* registry = TabCaptureRegistry::Get(GetProfile()); |
270 std::unique_ptr<base::ListValue> list(new base::ListValue()); | 270 std::unique_ptr<base::ListValue> list(new base::ListValue()); |
271 if (registry) | 271 if (registry) |
272 registry->GetCapturedTabs(extension()->id(), list.get()); | 272 registry->GetCapturedTabs(extension()->id(), list.get()); |
273 SetResult(std::move(list)); | 273 SetResult(std::move(list)); |
274 return true; | 274 return true; |
275 } | 275 } |
276 | 276 |
277 bool TabCaptureCaptureOffscreenTabFunction::RunSync() { | 277 ExtensionFunction::ResponseAction TabCaptureCaptureOffscreenTabFunction::Run() { |
278 std::unique_ptr<TabCapture::CaptureOffscreenTab::Params> params = | 278 std::unique_ptr<TabCapture::CaptureOffscreenTab::Params> params = |
279 TabCapture::CaptureOffscreenTab::Params::Create(*args_); | 279 TabCapture::CaptureOffscreenTab::Params::Create(*args_); |
280 EXTENSION_FUNCTION_VALIDATE(params); | 280 EXTENSION_FUNCTION_VALIDATE(params); |
281 | 281 |
282 // Make sure the extension is whitelisted for using this API, regardless of | 282 // Make sure the extension is whitelisted for using this API, regardless of |
283 // Chrome channel. | 283 // Chrome channel. |
284 // | 284 // |
285 // TODO(miu): Use _api_features.json and extensions::Feature library instead. | 285 // TODO(miu): Use _api_features.json and extensions::Feature library instead. |
286 // http://crbug.com/537732 | 286 // http://crbug.com/537732 |
287 const bool is_whitelisted_extension = | 287 const bool is_whitelisted_extension = |
288 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 288 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
289 switches::kWhitelistedExtensionID) == extension()->id() || | 289 switches::kWhitelistedExtensionID) == extension()->id() || |
290 SimpleFeature::IsIdInArray(extension()->id(), kChromecastExtensionIds, | 290 SimpleFeature::IsIdInArray(extension()->id(), kChromecastExtensionIds, |
291 arraysize(kChromecastExtensionIds)) || | 291 arraysize(kChromecastExtensionIds)) || |
292 SimpleFeature::IsIdInArray(extension()->id(), kMediaRouterExtensionIds, | 292 SimpleFeature::IsIdInArray(extension()->id(), kMediaRouterExtensionIds, |
293 arraysize(kMediaRouterExtensionIds)); | 293 arraysize(kMediaRouterExtensionIds)); |
294 if (!is_whitelisted_extension) { | 294 if (!is_whitelisted_extension) |
295 error_ = kNotWhitelistedForOffscreenTabApi; | 295 return RespondNow(Error(kNotWhitelistedForOffscreenTabApi)); |
296 return false; | |
297 } | |
298 | 296 |
299 const GURL start_url(params->start_url); | 297 const GURL start_url(params->start_url); |
300 if (!IsAcceptableOffscreenTabUrl(start_url)) { | 298 if (!IsAcceptableOffscreenTabUrl(start_url)) |
301 SetError(kInvalidStartUrl); | 299 return RespondNow(Error(kInvalidStartUrl)); |
302 return false; | |
303 } | |
304 | 300 |
305 if (!OptionsSpecifyAudioOrVideo(params->options)) { | 301 if (!OptionsSpecifyAudioOrVideo(params->options)) |
306 SetError(kNoAudioOrVideo); | 302 return RespondNow(Error(kNoAudioOrVideo)); |
307 return false; | |
308 } | |
309 | 303 |
310 content::WebContents* const extension_web_contents = GetSenderWebContents(); | 304 content::WebContents* const extension_web_contents = GetSenderWebContents(); |
311 EXTENSION_FUNCTION_VALIDATE(extension_web_contents); | 305 EXTENSION_FUNCTION_VALIDATE(extension_web_contents); |
312 OffscreenTab* const offscreen_tab = | 306 OffscreenTab* const offscreen_tab = |
313 OffscreenTabsOwner::Get(extension_web_contents)->OpenNewTab( | 307 OffscreenTabsOwner::Get(extension_web_contents)->OpenNewTab( |
314 start_url, | 308 start_url, |
315 DetermineInitialSize(params->options), | 309 DetermineInitialSize(params->options), |
316 (is_whitelisted_extension && params->options.presentation_id) ? | 310 (is_whitelisted_extension && params->options.presentation_id) ? |
317 *params->options.presentation_id : std::string()); | 311 *params->options.presentation_id : std::string()); |
318 if (!offscreen_tab) { | 312 if (!offscreen_tab) |
319 SetError(kTooManyOffscreenTabs); | 313 return RespondNow(Error(kTooManyOffscreenTabs)); |
320 return false; | |
321 } | |
322 | 314 |
323 if (!TabCaptureRegistry::Get(browser_context())->AddRequest( | 315 if (!TabCaptureRegistry::Get(browser_context())->AddRequest( |
324 offscreen_tab->web_contents(), extension()->id(), true)) { | 316 offscreen_tab->web_contents(), extension()->id(), true)) { |
325 // TODO(miu): Allow multiple consumers of single tab capture. | 317 // TODO(miu): Allow multiple consumers of single tab capture. |
326 // http://crbug.com/535336 | 318 // http://crbug.com/535336 |
327 SetError(kCapturingSameOffscreenTab); | 319 return RespondNow(Error(kCapturingSameOffscreenTab)); |
328 return false; | |
329 } | 320 } |
330 FilterDeprecatedGoogConstraints(¶ms->options); | 321 FilterDeprecatedGoogConstraints(¶ms->options); |
331 AddMediaStreamSourceConstraints(offscreen_tab->web_contents(), | 322 AddMediaStreamSourceConstraints(offscreen_tab->web_contents(), |
332 ¶ms->options); | 323 ¶ms->options); |
333 | 324 |
334 // At this point, everything is set up in the browser process. It's now up to | 325 // At this point, everything is set up in the browser process. It's now up to |
335 // the custom JS bindings in the extension's render process to complete the | 326 // the custom JS bindings in the extension's render process to complete the |
336 // request. See the comment at end of TabCaptureCaptureFunction::RunSync() | 327 // request. See the comment at end of TabCaptureCaptureFunction::RunSync() |
337 // for more details. | 328 // for more details. |
338 std::unique_ptr<base::DictionaryValue> result(new base::DictionaryValue()); | 329 return RespondNow(OneArgument(params->options.ToValue())); |
339 result->MergeDictionary(params->options.ToValue().get()); | |
340 SetResult(std::move(result)); | |
341 return true; | |
342 } | 330 } |
343 | 331 |
344 // static | 332 // static |
345 gfx::Size TabCaptureCaptureOffscreenTabFunction::DetermineInitialSize( | 333 gfx::Size TabCaptureCaptureOffscreenTabFunction::DetermineInitialSize( |
346 const TabCapture::CaptureOptions& options) { | 334 const TabCapture::CaptureOptions& options) { |
347 static const int kDefaultWidth = 1280; | 335 static const int kDefaultWidth = 1280; |
348 static const int kDefaultHeight = 720; | 336 static const int kDefaultHeight = 720; |
349 | 337 |
350 if (!options.video_constraints) | 338 if (!options.video_constraints) |
351 return gfx::Size(kDefaultWidth, kDefaultHeight); | 339 return gfx::Size(kDefaultWidth, kDefaultHeight); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
384 } | 372 } |
385 } | 373 } |
386 | 374 |
387 // No maximum size was provided, so just return the default size bounded by | 375 // No maximum size was provided, so just return the default size bounded by |
388 // the minimum size. | 376 // the minimum size. |
389 return gfx::Size(std::max(kDefaultWidth, min_size.width()), | 377 return gfx::Size(std::max(kDefaultWidth, min_size.width()), |
390 std::max(kDefaultHeight, min_size.height())); | 378 std::max(kDefaultHeight, min_size.height())); |
391 } | 379 } |
392 | 380 |
393 } // namespace extensions | 381 } // namespace extensions |
OLD | NEW |