Index: chrome/renderer/resources/extensions/runtime_custom_bindings.js |
diff --git a/chrome/renderer/resources/extensions/runtime_custom_bindings.js b/chrome/renderer/resources/extensions/runtime_custom_bindings.js |
index 91d402b1fb8ec6330bbc1d6f4ec4b1bc0bf23ce0..61be155e68ce283630a526bc6ebcf875efbed65a 100644 |
--- a/chrome/renderer/resources/extensions/runtime_custom_bindings.js |
+++ b/chrome/renderer/resources/extensions/runtime_custom_bindings.js |
@@ -2,7 +2,9 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-// Custom bindings for the runtime API. |
+// Custom binding for the runtime API. |
+ |
+var binding = require('binding').Binding.create('runtime'); |
var runtimeNatives = requireNative('runtime'); |
var extensionNatives = requireNative('extension'); |
@@ -13,14 +15,15 @@ var chromeHidden = requireNative('chrome_hidden').GetChromeHidden(); |
var sendMessageUpdateArguments = |
require('miscellaneous_bindings').sendMessageUpdateArguments; |
-chromeHidden.registerCustomHook('runtime', function(bindings, id, contextType) { |
- var apiFunctions = bindings.apiFunctions; |
+binding.registerCustomHook(function(binding, id, contextType) { |
+ var apiFunctions = binding.apiFunctions; |
+ var runtime = binding.compiledApi; |
// |
// Unprivileged APIs. |
// |
- chrome.runtime.id = id; |
+ runtime.id = id; |
apiFunctions.setHandleRequest('getManifest', function() { |
return runtimeNatives.GetManifest(); |
@@ -40,14 +43,14 @@ chromeHidden.registerCustomHook('runtime', function(bindings, id, contextType) { |
apiFunctions.setHandleRequest('sendMessage', |
function(targetId, message, responseCallback) { |
- var port = chrome.runtime.connect(targetId || chrome.runtime.id, |
+ var port = runtime.connect(targetId || runtime.id, |
{name: chromeHidden.kMessageChannel}); |
chromeHidden.Port.sendMessageImpl(port, message, responseCallback); |
}); |
apiFunctions.setHandleRequest('sendNativeMessage', |
function(targetId, message, responseCallback) { |
- var port = chrome.runtime.connectNative(targetId); |
+ var port = runtime.connectNative(targetId); |
chromeHidden.Port.sendMessageImpl(port, message, responseCallback); |
}); |
@@ -83,7 +86,7 @@ chromeHidden.registerCustomHook('runtime', function(bindings, id, contextType) { |
apiFunctions.setHandleRequest('connect', function(targetId, connectInfo) { |
if (!targetId) |
- targetId = chrome.runtime.id; |
+ targetId = runtime.id; |
var name = ''; |
if (connectInfo && connectInfo.name) |
name = connectInfo.name; |
@@ -91,7 +94,7 @@ chromeHidden.registerCustomHook('runtime', function(bindings, id, contextType) { |
// Don't let orphaned content scripts communicate with their extension. |
// http://crbug.com/168263 |
if (!chromeHidden.wasUnloaded) { |
- var portId = OpenChannelToExtension(chrome.runtime.id, targetId, name); |
+ var portId = OpenChannelToExtension(runtime.id, targetId, name); |
if (portId >= 0) |
return chromeHidden.Port.createPort(portId, name); |
} |
@@ -107,7 +110,7 @@ chromeHidden.registerCustomHook('runtime', function(bindings, id, contextType) { |
apiFunctions.setHandleRequest('connectNative', |
function(nativeAppName) { |
if (!chromeHidden.wasUnloaded) { |
- var portId = OpenChannelToNativeApp(chrome.runtime.id, nativeAppName); |
+ var portId = OpenChannelToNativeApp(runtime.id, nativeAppName); |
if (portId >= 0) |
return chromeHidden.Port.createPort(portId, ''); |
} |
@@ -124,3 +127,5 @@ chromeHidden.registerCustomHook('runtime', function(bindings, id, contextType) { |
}); |
}); |
+ |
+exports.binding = binding.generate(); |