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 // 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(options, |
26 function(stream) { callback(stream); }, | 27 function(stream) { callback(stream); }, |
27 function() { callback(null); }); | 28 function(exception) { callback(null); }); |
28 } catch (e) { | 29 } catch (e) { |
29 callback(null); | 30 callback(null); |
30 } | 31 } |
31 } else { | 32 } else { |
32 callback(null); | 33 callback(null); |
33 } | 34 } |
34 }); | 35 } |
| 36 |
| 37 apiFunctions.setCustomCallback('capture', proxyToGetUserMedia); |
| 38 apiFunctions.setCustomCallback('captureOffscreenTab', proxyToGetUserMedia); |
35 }); | 39 }); |
36 | 40 |
37 exports.binding = binding.generate(); | 41 exports.binding = binding.generate(); |
OLD | NEW |