Index: chrome/renderer/resources/extensions/tab_capture_custom_bindings.js |
diff --git a/chrome/renderer/resources/extensions/tab_capture_custom_bindings.js b/chrome/renderer/resources/extensions/tab_capture_custom_bindings.js |
index 93a60549e3743d366c47fabe14f7d8c63bff316d..b0fdedb8c4dcb89a3dc4ff6889b61fd77266391e 100644 |
--- a/chrome/renderer/resources/extensions/tab_capture_custom_bindings.js |
+++ b/chrome/renderer/resources/extensions/tab_capture_custom_bindings.js |
@@ -9,11 +9,12 @@ var binding = require('binding').Binding.create('tabCapture'); |
binding.registerCustomHook(function(bindingsAPI, extensionId) { |
var apiFunctions = bindingsAPI.apiFunctions; |
- apiFunctions.setCustomCallback('capture', |
- function(name, request, callback, response) { |
+ function proxyToGetUserMedia(name, request, callback, response) { |
if (!callback) |
return; |
+ // TODO(miu): Propagate exceptions and always provide a useful error when |
+ // callback() is invoked with a null argument. http://crbug.com/463679 |
if (response) { |
var options = {}; |
if (response.audioConstraints) |
@@ -22,16 +23,33 @@ binding.registerCustomHook(function(bindingsAPI, extensionId) { |
options.video = response.videoConstraints; |
try { |
- navigator.webkitGetUserMedia(options, |
- function(stream) { callback(stream); }, |
- function() { callback(null); }); |
+ navigator.webkitGetUserMedia( |
+ options, |
+ function(stream) { |
+ if (stream && ('offscreenTabId' in response)) { |
+ Object.defineProperty(stream, 'offscreenTabId', { |
+ configureable: false, |
+ enumerable: false, |
+ value: response['offscreenTabId'], |
+ writable: false |
+ }); |
+ } |
+ callback(stream); |
+ }, |
+ function(exception) { |
+ callback(null); |
+ } |
+ ); |
} catch (e) { |
callback(null); |
} |
} else { |
callback(null); |
} |
- }); |
+ } |
+ |
+ apiFunctions.setCustomCallback('capture', proxyToGetUserMedia); |
+ apiFunctions.setCustomCallback('captureOffscreenTab', proxyToGetUserMedia); |
}); |
exports.binding = binding.generate(); |