Chromium Code Reviews| Index: chrome/renderer/resources/extension_process_bindings.js |
| diff --git a/chrome/renderer/resources/extension_process_bindings.js b/chrome/renderer/resources/extension_process_bindings.js |
| index af682c07e189a3c97fa5363260f7862ab0a1cc22..5c3006851382c66edf7a784906c439c2bfbc5559 100644 |
| --- a/chrome/renderer/resources/extension_process_bindings.js |
| +++ b/chrome/renderer/resources/extension_process_bindings.js |
| @@ -183,31 +183,35 @@ var chrome = chrome || {}; |
| } |
| // Send an API request and optionally register a callback. |
| - function sendRequest(functionName, args, argSchemas, customCallback) { |
| + // |opt_args| is an object with optional parameters as follows: |
| + // - rawArgs: true if we should not stringify the request arguments. |
|
Mihai Parparita -not on Chrome
2011/06/09 18:37:24
noStringify or another boolean-like name seems bet
Matt Perry
2011/06/09 18:50:30
Done.
|
| + // - customCallback: a callback that should be called instead of the standard |
| + // callback. |
| + // - nativeFunction: the v8 native function to handle the request, or |
| + // StartRequest if missing. |
| + // - forIOThread: true if this function should be handled on the browser IO |
| + // thread. |
| + function sendRequest(functionName, args, argSchemas, opt_args) { |
| + if (!opt_args) |
| + opt_args = {}; |
| var request = prepareRequest(args, argSchemas); |
| - if (customCallback) { |
| - request.customCallback = customCallback; |
| + if (opt_args.customCallback) { |
| + request.customCallback = opt_args.customCallback; |
| } |
| // JSON.stringify doesn't support a root object which is undefined. |
| if (request.args === undefined) |
| request.args = null; |
| - var sargs = chromeHidden.JSON.stringify(request.args); |
| + var sargs = opt_args.rawArgs ? |
| + request.args : chromeHidden.JSON.stringify(request.args); |
| + var nativeFunction = opt_args.nativeFunction || StartRequest; |
| var requestId = GetNextRequestId(); |
| requests[requestId] = request; |
| - 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 |
| - // register a callback. |
| - function sendCustomRequest(nativeFunction, functionName, args, argSchemas) { |
| - var request = prepareRequest(args, argSchemas); |
| - var requestId = GetNextRequestId(); |
| - requests[requestId] = request; |
| - return nativeFunction(functionName, request.args, requestId, |
| - request.callback ? true : false); |
| + var hasCallback = |
| + (request.callback || opt_args.customCallback) ? true : false; |
| + return nativeFunction(functionName, sargs, requestId, hasCallback, |
| + opt_args.forIOThread); |
| } |
| // Helper function for positioning pop-up windows relative to DOM objects. |
| @@ -567,7 +571,7 @@ var chrome = chrome || {}; |
| } else { |
| retval = sendRequest(this.name, args, |
| this.definition.parameters, |
| - this.customCallback); |
| + {customCallback: this.customCallback}); |
| } |
| // Validate return value if defined - only in debug. |
| @@ -750,7 +754,8 @@ var chrome = chrome || {}; |
| "is no larger than " + iconSize + " pixels square."); |
| } |
| - sendCustomRequest(nativeFunction, name, [details], parameters); |
| + sendRequest(name, [details], parameters, |
| + {rawArgs: true, nativeFunction: nativeFunction}); |
| } else if ("path" in details) { |
| var img = new Image(); |
| img.onerror = function() { |
| @@ -768,7 +773,8 @@ var chrome = chrome || {}; |
| delete details.path; |
| details.imageData = canvas_context.getImageData(0, 0, canvas.width, |
| canvas.height); |
| - sendCustomRequest(nativeFunction, name, [details], parameters); |
| + sendRequest(name, [details], parameters, |
| + {rawArgs: true, nativeFunction: nativeFunction}); |
| }; |
| img.src = details.path; |
| } else { |
| @@ -808,7 +814,7 @@ var chrome = chrome || {}; |
| var id = GetNextContextMenuId(); |
| args[0].generatedId = id; |
| sendRequest(this.name, args, this.definition.parameters, |
| - this.customCallback); |
| + {customCallback: this.customCallback}); |
| return id; |
| }; |
| @@ -818,6 +824,20 @@ var chrome = chrome || {}; |
| sendRequest(this.name, [parseResult], this.definition.parameters); |
| }; |
| + apiFunctions["experimental.webRequest.addEventListener"].handleRequest = |
| + function() { |
| + var args = Array.prototype.slice.call(arguments); |
| + sendRequest(this.name, args, this.definition.parameters, |
| + {forIOThread: true}); |
| + }; |
| + |
| + apiFunctions["experimental.webRequest.eventHandled"].handleRequest = |
| + function() { |
| + var args = Array.prototype.slice.call(arguments); |
| + sendRequest(this.name, args, this.definition.parameters, |
| + {forIOThread: true}); |
| + }; |
| + |
| apiFunctions["contextMenus.create"].customCallback = |
| function(name, request, response) { |
| if (chrome.extension.lastError) { |