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 |
17 if (response) { | 16 if (response) { |
18 var options = {}; | 17 var options = {}; |
19 if (response.audioConstraints) | 18 if (response.audioConstraints) |
20 options.audio = response.audioConstraints; | 19 options.audio = response.audioConstraints; |
21 if (response.videoConstraints) | 20 if (response.videoConstraints) |
22 options.video = response.videoConstraints; | 21 options.video = response.videoConstraints; |
23 | 22 |
24 try { | 23 try { |
25 navigator.webkitGetUserMedia(options, | 24 navigator.webkitGetUserMedia(options, |
26 function(stream) { callback(stream); }, | 25 function(stream) { callback(stream); }, |
27 function() { callback(null); }); | 26 function(exception) { callback(null); }); |
28 } catch (e) { | 27 } catch (e) { |
29 callback(null); | 28 callback(null); |
30 } | 29 } |
31 } else { | 30 } else { |
32 callback(null); | 31 callback(null); |
33 } | 32 } |
34 }); | 33 } |
| 34 |
| 35 apiFunctions.setCustomCallback('capture', proxyToGetUserMedia); |
| 36 apiFunctions.setCustomCallback('capturePresentation', proxyToGetUserMedia); |
35 }); | 37 }); |
36 | 38 |
37 exports.binding = binding.generate(); | 39 exports.binding = binding.generate(); |
OLD | NEW |