Index: chrome/renderer/resources/extensions/extension_custom_bindings.js |
=================================================================== |
--- chrome/renderer/resources/extensions/extension_custom_bindings.js (revision 158832) |
+++ chrome/renderer/resources/extensions/extension_custom_bindings.js (working copy) |
@@ -7,6 +7,7 @@ |
var extensionNatives = requireNative('extension'); |
var GetExtensionViews = extensionNatives.GetExtensionViews; |
var OpenChannelToExtension = extensionNatives.OpenChannelToExtension; |
+var OpenChannelToNativeApp = extensionNatives.OpenChannelToNativeApp; |
var chromeHidden = requireNative('chrome_hidden').GetChromeHidden(); |
@@ -93,6 +94,8 @@ |
sendMessageUpdateArguments.bind(null, 'sendRequest')); |
apiFunctions.setUpdateArgumentsPreValidate('sendMessage', |
sendMessageUpdateArguments.bind(null, 'sendMessage')); |
+ apiFunctions.setUpdateArgumentsPreValidate('sendNativeMessage', |
+ sendMessageUpdateArguments.bind(null, 'sendNativeMessage')); |
apiFunctions.setHandleRequest('sendRequest', |
function(targetId, request, responseCallback) { |
@@ -108,6 +111,13 @@ |
chromeHidden.Port.sendMessageImpl(port, message, responseCallback); |
}); |
+ apiFunctions.setHandleRequest('sendNativeMessage', |
+ function(targetId, message, responseCallback) { |
+ var port = chrome.extension.connectNative( |
+ targetId, message, chromeHidden.kNativeMessageChannel); |
+ chromeHidden.Port.sendMessageImpl(port, '', responseCallback); |
+ }); |
+ |
apiFunctions.setUpdateArgumentsPreValidate('connect', function() { |
// Align missing (optional) function arguments with the arguments that |
// schema validation is expecting, e.g. |
@@ -126,10 +136,29 @@ |
connectInfo = arguments[nextArg++]; |
if (nextArg != arguments.length) |
- throw new Error('Invalid arguments to connect'); |
+ throw new Error('Invalid arguments to connect.'); |
return [targetId, connectInfo]; |
}); |
+ apiFunctions.setUpdateArgumentsPreValidate('connectNative', function() { |
+ var nextArg = 0; |
+ |
+ // appName is required. |
+ var appName = arguments[nextArg++]; |
+ |
+ // connectionMessage is required. |
+ var connectMessage = arguments[nextArg++]; |
+ |
+ // channelName is only passed by sendMessage |
+ var channelName = 'connectNative'; |
+ if (typeof(arguments[nextArg]) == 'string') |
+ channelName = arguments[nextArg++]; |
+ |
+ if (nextArg != arguments.length) |
+ throw new Error('Invalid arguments to connectNative.'); |
+ return [appName, {name: channelName, message: connectMessage}]; |
+ }); |
+ |
apiFunctions.setHandleRequest('connect', function(targetId, connectInfo) { |
if (!targetId) |
targetId = extensionId; |
@@ -142,4 +171,17 @@ |
return chromeHidden.Port.createPort(portId, name); |
throw new Error('Error connecting to extension ' + targetId); |
}); |
+ |
+ apiFunctions.setHandleRequest('connectNative', |
+ function(nativeAppName, connectInfo) { |
+ // Turn the object into a string here, because it eventually will be. |
+ var portId = OpenChannelToNativeApp(extensionId, |
+ nativeAppName, |
+ connectInfo.name, |
+ JSON.stringify(connectInfo.message)); |
+ if (portId >= 0) { |
+ return chromeHidden.Port.createPort(portId, connectInfo.name); |
+ } |
+ throw new Error('Error connecting to native app: ' + nativeAppName); |
+ }); |
}); |