Chromium Code Reviews| Index: chrome/renderer/resources/extension_process_bindings.js |
| =================================================================== |
| --- chrome/renderer/resources/extension_process_bindings.js (revision 42220) |
| +++ chrome/renderer/resources/extension_process_bindings.js (working copy) |
| @@ -80,6 +80,9 @@ |
| }; |
| } |
| + if (request.customCallback) |
|
rafaelw
2010/03/22 22:27:21
need curly braces
|
| + request.customCallback(name, request, response); |
| + |
| if (request.callback) { |
| // Callbacks currently only support one callback argument. |
| var callbackArgs = response ? [JSON.parse(response)] : []; |
| @@ -165,8 +168,11 @@ |
| } |
| // Send an API request and optionally register a callback. |
| - function sendRequest(functionName, args, argSchemas) { |
| + function sendRequest(functionName, args, argSchemas, customCallback) { |
| var request = prepareRequest(args, argSchemas); |
| + if (customCallback) { |
| + request.customCallback = customCallback; |
| + } |
| // JSON.stringify doesn't support a root object which is undefined. |
| if (request.args === undefined) |
| request.args = null; |
| @@ -187,8 +193,8 @@ |
| } |
| var requestId = GetNextRequestId(); |
| requests[requestId] = request; |
| - return StartRequest(functionName, sargs, requestId, |
| - request.callback ? true : false); |
| + var hasCallback = (request.callback || customCallback) ? true : false; |
| + return StartRequest(functionName, sargs, requestId, hasCallback); |
| } |
| // Send a special API request that is not JSON stringifiable, and optionally |
| @@ -289,6 +295,23 @@ |
| new chrome.Event("experimental.popup.onClosed." + renderViewId); |
| } |
| + function setupHiddenContextMenuEvent(extensionId) { |
| + var eventName = "contextMenu/" + extensionId; |
| + chromeHidden.contextMenuEvent = new chrome.Event(eventName); |
| + chromeHidden.contextMenuHandlers = {}; |
| + chromeHidden.contextMenuEvent.addListener(function() { |
| + var menuItemId = arguments[0].menuItemId; |
| + var onclick = chromeHidden.contextMenuHandlers[menuItemId]; |
| + if (onclick) |
|
rafaelw
2010/03/22 22:27:21
need curly braces
|
| + onclick.apply(onclick, arguments); |
| + |
| + var parentMenuItemId = arguments[0].parentMenuItemId; |
| + var parentOnclick = chromeHidden.contextMenuHandlers[parentMenuItemId]; |
| + if (parentOnclick) |
|
rafaelw
2010/03/22 22:27:21
need curly braces
|
| + parentOnclick.apply(parentOnclick, arguments); |
| + }); |
| + } |
| + |
| chromeHidden.onLoad.addListener(function (extensionId) { |
| chrome.initExtension(extensionId, false); |
| @@ -341,7 +364,8 @@ |
| retval = this.handleRequest.apply(this, arguments); |
| } else { |
| retval = sendRequest(this.name, arguments, |
| - this.definition.parameters); |
| + this.definition.parameters, |
| + this.customCallback); |
| } |
| // Validate return value if defined - only in debug. |
| @@ -549,6 +573,28 @@ |
| details, this.name, this.definition.parameters, "page action"); |
| }; |
| + apiFunctions["experimental.contextMenu.create"].customCallback = |
| + function(name, request, response) { |
| + if (chrome.extension.lastError || !response) |
|
rafaelw
2010/03/22 22:27:21
need curly braces
|
| + return; |
| + |
| + // Set up the onclick handler if we were passed one in the request. |
| + if (request.args.onclick) { |
| + var menuItemId = JSON.parse(response); |
| + chromeHidden.contextMenuHandlers[menuItemId] = request.args.onclick; |
| + } |
| + }; |
| + |
| + apiFunctions["experimental.contextMenu.remove"].customCallback = |
| + function(name, request, response) { |
| + // Remove any onclick handler we had registered for this menu item. |
| + if (request.args.length > 0) { |
| + var menuItemId = request.args[0]; |
| + if (chromeHidden.contextMenuHandlers[menuItemId]) |
|
rafaelw
2010/03/22 22:27:21
don't need the test here. you can just delete. (ot
|
| + delete chromeHidden.contextMenuHandlers[menuItemId]; |
| + } |
| + } |
| + |
| if (chrome.test) { |
| chrome.test.getApiDefinitions = GetExtensionAPIDefinition; |
| } |
| @@ -557,6 +603,7 @@ |
| setupPageActionEvents(extensionId); |
| setupToolstripEvents(GetRenderViewId()); |
| setupPopupEvents(GetRenderViewId()); |
| + setupHiddenContextMenuEvent(extensionId); |
| }); |
| if (!chrome.experimental) |