Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(519)

Unified Diff: chrome/renderer/resources/extensions/extension_custom_bindings.js

Issue 10991044: Revert 158830 - Revert 156678 - Native messaging now uses the MessageService back-end. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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);
+ });
});

Powered by Google App Engine
This is Rietveld 408576698