| Index: chrome/renderer/resources/extensions/extension_custom_bindings.js
|
| diff --git a/chrome/renderer/resources/extensions/extension_custom_bindings.js b/chrome/renderer/resources/extensions/extension_custom_bindings.js
|
| index 970e11f9ad24286b379e657737277aee15118618..66603532d1a5c6c61960ea1495db7fd001157d27 100644
|
| --- a/chrome/renderer/resources/extensions/extension_custom_bindings.js
|
| +++ b/chrome/renderer/resources/extensions/extension_custom_bindings.js
|
| @@ -52,7 +52,7 @@ chromeHidden.registerCustomHook('extension',
|
| return 'chrome-extension://' + extensionId + path;
|
| });
|
|
|
| - apiFunctions.setUpdateArgumentsPreValidate('sendRequest', function() {
|
| + function sendMessageUpdateArguments() {
|
| // Align missing (optional) function arguments with the arguments that
|
| // schema validation is expecting, e.g.
|
| // extension.sendRequest(req) -> extension.sendRequest(null, req)
|
| @@ -73,38 +73,26 @@ chromeHidden.registerCustomHook('extension',
|
| targetId = arguments[lastArg--];
|
|
|
| if (lastArg != -1)
|
| - throw new Error('Invalid arguments to sendRequest.');
|
| + throw new Error('Invalid arguments to sendMessage.');
|
| return [targetId, request, responseCallback];
|
| - });
|
| + }
|
| + apiFunctions.setUpdateArgumentsPreValidate('sendRequest',
|
| + sendMessageUpdateArguments);
|
| + apiFunctions.setUpdateArgumentsPreValidate('sendMessage',
|
| + sendMessageUpdateArguments);
|
|
|
| apiFunctions.setHandleRequest('sendRequest',
|
| function(targetId, request, responseCallback) {
|
| - if (!targetId)
|
| - targetId = extensionId;
|
| - if (!responseCallback)
|
| - responseCallback = function() {};
|
| -
|
| - var connectInfo = { name: chromeHidden.kRequestChannel };
|
| - var port = chrome.extension.connect(targetId, connectInfo);
|
| -
|
| - port.postMessage(request);
|
| - port.onDisconnect.addListener(function() {
|
| - // For onDisconnects, we only notify the callback if there was an error
|
| - try {
|
| - if (chrome.extension.lastError)
|
| - responseCallback();
|
| - } finally {
|
| - port = null;
|
| - }
|
| - });
|
| - port.onMessage.addListener(function(response) {
|
| - try {
|
| - responseCallback(response);
|
| - } finally {
|
| - port.disconnect();
|
| - port = null;
|
| - }
|
| - });
|
| + var port = chrome.extension.connect(targetId || extensionId,
|
| + {name: chromeHidden.kRequestChannel});
|
| + chromeHidden.Port.sendMessageImpl(port, request, responseCallback);
|
| + });
|
| +
|
| + apiFunctions.setHandleRequest('sendMessage',
|
| + function(targetId, message, responseCallback) {
|
| + var port = chrome.extension.connect(targetId || extensionId,
|
| + {name: chromeHidden.kMessageChannel});
|
| + chromeHidden.Port.sendMessageImpl(port, message, responseCallback);
|
| });
|
|
|
| apiFunctions.setUpdateArgumentsPreValidate('connect', function() {
|
|
|