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 <set> | 11 #include <set> |
11 #include <string> | 12 #include <string> |
| 13 #include <utility> |
12 #include <vector> | 14 #include <vector> |
13 | 15 |
14 #include "base/command_line.h" | 16 #include "base/command_line.h" |
15 #include "base/macros.h" | 17 #include "base/macros.h" |
16 #include "base/strings/stringprintf.h" | 18 #include "base/strings/stringprintf.h" |
17 #include "base/values.h" | 19 #include "base/values.h" |
18 #include "chrome/browser/extensions/api/tab_capture/offscreen_tab.h" | 20 #include "chrome/browser/extensions/api/tab_capture/offscreen_tab.h" |
19 #include "chrome/browser/extensions/api/tab_capture/tab_capture_registry.h" | 21 #include "chrome/browser/extensions/api/tab_capture/tab_capture_registry.h" |
20 #include "chrome/browser/profiles/profile.h" | 22 #include "chrome/browser/profiles/profile.h" |
21 #include "chrome/browser/sessions/session_tab_helper.h" | 23 #include "chrome/browser/sessions/session_tab_helper.h" |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 AddMediaStreamSourceConstraints(target_contents, ¶ms->options); | 252 AddMediaStreamSourceConstraints(target_contents, ¶ms->options); |
251 | 253 |
252 // At this point, everything is set up in the browser process. It's now up to | 254 // At this point, everything is set up in the browser process. It's now up to |
253 // the custom JS bindings in the extension's render process to request a | 255 // the custom JS bindings in the extension's render process to request a |
254 // MediaStream using navigator.webkitGetUserMedia(). The result dictionary, | 256 // MediaStream using navigator.webkitGetUserMedia(). The result dictionary, |
255 // passed to SetResult() here, contains the extra "hidden options" that will | 257 // passed to SetResult() here, contains the extra "hidden options" that will |
256 // allow the Chrome platform implementation for getUserMedia() to start the | 258 // allow the Chrome platform implementation for getUserMedia() to start the |
257 // virtual audio/video capture devices and set up all the data flows. The | 259 // virtual audio/video capture devices and set up all the data flows. The |
258 // custom JS bindings can be found here: | 260 // custom JS bindings can be found here: |
259 // chrome/renderer/resources/extensions/tab_capture_custom_bindings.js | 261 // chrome/renderer/resources/extensions/tab_capture_custom_bindings.js |
260 base::DictionaryValue* result = new base::DictionaryValue(); | 262 std::unique_ptr<base::DictionaryValue> result(new base::DictionaryValue()); |
261 result->MergeDictionary(params->options.ToValue().get()); | 263 result->MergeDictionary(params->options.ToValue().get()); |
262 SetResult(result); | 264 SetResult(std::move(result)); |
263 return true; | 265 return true; |
264 } | 266 } |
265 | 267 |
266 bool TabCaptureGetCapturedTabsFunction::RunSync() { | 268 bool TabCaptureGetCapturedTabsFunction::RunSync() { |
267 TabCaptureRegistry* registry = TabCaptureRegistry::Get(GetProfile()); | 269 TabCaptureRegistry* registry = TabCaptureRegistry::Get(GetProfile()); |
268 base::ListValue* const list = new base::ListValue(); | 270 std::unique_ptr<base::ListValue> list(new base::ListValue()); |
269 if (registry) | 271 if (registry) |
270 registry->GetCapturedTabs(extension()->id(), list); | 272 registry->GetCapturedTabs(extension()->id(), list.get()); |
271 SetResult(list); | 273 SetResult(std::move(list)); |
272 return true; | 274 return true; |
273 } | 275 } |
274 | 276 |
275 bool TabCaptureCaptureOffscreenTabFunction::RunSync() { | 277 bool TabCaptureCaptureOffscreenTabFunction::RunSync() { |
276 std::unique_ptr<TabCapture::CaptureOffscreenTab::Params> params = | 278 std::unique_ptr<TabCapture::CaptureOffscreenTab::Params> params = |
277 TabCapture::CaptureOffscreenTab::Params::Create(*args_); | 279 TabCapture::CaptureOffscreenTab::Params::Create(*args_); |
278 EXTENSION_FUNCTION_VALIDATE(params); | 280 EXTENSION_FUNCTION_VALIDATE(params); |
279 | 281 |
280 // 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 |
281 // Chrome channel. | 283 // Chrome channel. |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
326 return false; | 328 return false; |
327 } | 329 } |
328 FilterDeprecatedGoogConstraints(¶ms->options); | 330 FilterDeprecatedGoogConstraints(¶ms->options); |
329 AddMediaStreamSourceConstraints(offscreen_tab->web_contents(), | 331 AddMediaStreamSourceConstraints(offscreen_tab->web_contents(), |
330 ¶ms->options); | 332 ¶ms->options); |
331 | 333 |
332 // At this point, everything is set up in the browser process. It's now up to | 334 // At this point, everything is set up in the browser process. It's now up to |
333 // the custom JS bindings in the extension's render process to complete the | 335 // the custom JS bindings in the extension's render process to complete the |
334 // request. See the comment at end of TabCaptureCaptureFunction::RunSync() | 336 // request. See the comment at end of TabCaptureCaptureFunction::RunSync() |
335 // for more details. | 337 // for more details. |
336 base::DictionaryValue* const result = new base::DictionaryValue(); | 338 std::unique_ptr<base::DictionaryValue> result(new base::DictionaryValue()); |
337 result->MergeDictionary(params->options.ToValue().get()); | 339 result->MergeDictionary(params->options.ToValue().get()); |
338 SetResult(result); | 340 SetResult(std::move(result)); |
339 return true; | 341 return true; |
340 } | 342 } |
341 | 343 |
342 // static | 344 // static |
343 gfx::Size TabCaptureCaptureOffscreenTabFunction::DetermineInitialSize( | 345 gfx::Size TabCaptureCaptureOffscreenTabFunction::DetermineInitialSize( |
344 const TabCapture::CaptureOptions& options) { | 346 const TabCapture::CaptureOptions& options) { |
345 static const int kDefaultWidth = 1280; | 347 static const int kDefaultWidth = 1280; |
346 static const int kDefaultHeight = 720; | 348 static const int kDefaultHeight = 720; |
347 | 349 |
348 if (!options.video_constraints) | 350 if (!options.video_constraints) |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
382 } | 384 } |
383 } | 385 } |
384 | 386 |
385 // No maximum size was provided, so just return the default size bounded by | 387 // No maximum size was provided, so just return the default size bounded by |
386 // the minimum size. | 388 // the minimum size. |
387 return gfx::Size(std::max(kDefaultWidth, min_size.width()), | 389 return gfx::Size(std::max(kDefaultWidth, min_size.width()), |
388 std::max(kDefaultHeight, min_size.height())); | 390 std::max(kDefaultHeight, min_size.height())); |
389 } | 391 } |
390 | 392 |
391 } // namespace extensions | 393 } // namespace extensions |
OLD | NEW |