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..8e33dab6a820775c8c8a3923f044f2b99efa02b3 100644 |
--- a/chrome/renderer/resources/extension_process_bindings.js |
+++ b/chrome/renderer/resources/extension_process_bindings.js |
@@ -9,6 +9,7 @@ var chrome = chrome || {}; |
(function() { |
native function GetExtensionAPIDefinition(); |
native function StartRequest(); |
+ native function StartRequestForIOThread(); |
native function GetCurrentPageActions(extensionId); |
native function GetExtensionViews(); |
native function GetChromeHidden(); |
@@ -183,31 +184,26 @@ var chrome = chrome || {}; |
} |
// Send an API request and optionally register a callback. |
- function sendRequest(functionName, args, argSchemas, customCallback) { |
+ // If |opt_rawargs| is true, don't JSONify the arguments. If |
+ // |opt_nativeFunction| is provided, use that instead of StartRequest. |
+ function sendRequest(functionName, args, argSchemas, opt_customCallback, |
Mihai Parparita -not on Chrome
2011/06/08 01:11:59
The callsites of this are confusing to follow beca
Matt Perry
2011/06/08 20:47:00
I've changed the optional arguments to a single op
|
+ opt_rawargs, opt_nativeFunction) { |
var request = prepareRequest(args, argSchemas); |
- if (customCallback) { |
- request.customCallback = customCallback; |
+ if (opt_customCallback) { |
+ request.customCallback = opt_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_rawargs ? |
+ request.args : chromeHidden.JSON.stringify(request.args); |
+ var nativeFunction = opt_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_customCallback) ? true : false; |
+ return nativeFunction(functionName, sargs, requestId, hasCallback); |
} |
// Helper function for positioning pop-up windows relative to DOM objects. |
@@ -750,7 +746,7 @@ var chrome = chrome || {}; |
"is no larger than " + iconSize + " pixels square."); |
} |
- sendCustomRequest(nativeFunction, name, [details], parameters); |
+ sendRequest(name, [details], parameters, null, true, nativeFunction); |
} else if ("path" in details) { |
var img = new Image(); |
img.onerror = function() { |
@@ -768,7 +764,7 @@ 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, null, true, nativeFunction); |
}; |
img.src = details.path; |
} else { |
@@ -818,6 +814,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, |
+ null, false, StartRequestForIOThread); |
+ }; |
+ |
+ apiFunctions["experimental.webRequest.eventHandled"].handleRequest = |
+ function() { |
+ var args = Array.prototype.slice.call(arguments); |
+ sendRequest(this.name, args, this.definition.parameters, |
+ null, false, StartRequestForIOThread); |
+ }; |
+ |
apiFunctions["contextMenus.create"].customCallback = |
function(name, request, response) { |
if (chrome.extension.lastError) { |