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

Side by Side Diff: chrome/renderer/resources/extensions/tab_capture_custom_bindings.js

Issue 1221483002: New tabCapture.captureOffscreenTab API, initially for Presentation API 1UA mode (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Register off-screen tabs as presentations via separate private API. Created 5 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 // Custom binding for the Tab Capture API. 5 // Custom binding for the Tab Capture API.
6 6
7 var binding = require('binding').Binding.create('tabCapture'); 7 var binding = require('binding').Binding.create('tabCapture');
8 8
9 binding.registerCustomHook(function(bindingsAPI, extensionId) { 9 binding.registerCustomHook(function(bindingsAPI, extensionId) {
10 var apiFunctions = bindingsAPI.apiFunctions; 10 var apiFunctions = bindingsAPI.apiFunctions;
11 11
12 apiFunctions.setCustomCallback('capture', 12 function proxyToGetUserMedia(name, request, callback, response) {
13 function(name, request, callback, response) {
14 if (!callback) 13 if (!callback)
15 return; 14 return;
16 15
16 // TODO(miu): Propagate exceptions and always provide a useful error when
17 // callback() is invoked with a null argument. http://crbug.com/463679
17 if (response) { 18 if (response) {
18 var options = {}; 19 var options = {};
19 if (response.audioConstraints) 20 if (response.audioConstraints)
20 options.audio = response.audioConstraints; 21 options.audio = response.audioConstraints;
21 if (response.videoConstraints) 22 if (response.videoConstraints)
22 options.video = response.videoConstraints; 23 options.video = response.videoConstraints;
23 24
24 try { 25 try {
25 navigator.webkitGetUserMedia(options, 26 navigator.webkitGetUserMedia(
26 function(stream) { callback(stream); }, 27 options,
27 function() { callback(null); }); 28 function(stream) {
29 if (stream && ('offscreenTabId' in response)) {
30 Object.defineProperty(stream, 'offscreenTabId', {
31 configureable: false,
32 enumerable: false,
33 value: response['offscreenTabId'],
34 writable: false
35 });
36 }
37 callback(stream);
38 },
39 function(exception) {
40 callback(null);
41 }
42 );
28 } catch (e) { 43 } catch (e) {
29 callback(null); 44 callback(null);
30 } 45 }
31 } else { 46 } else {
32 callback(null); 47 callback(null);
33 } 48 }
34 }); 49 }
50
51 apiFunctions.setCustomCallback('capture', proxyToGetUserMedia);
52 apiFunctions.setCustomCallback('captureOffscreenTab', proxyToGetUserMedia);
35 }); 53 });
36 54
37 exports.binding = binding.generate(); 55 exports.binding = binding.generate();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698