summaryrefslogtreecommitdiffstats
path: root/chrome/renderer
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/renderer')
-rw-r--r--chrome/renderer/extensions/extension_api_client_unittest.cc56
-rw-r--r--chrome/renderer/renderer_resources.grd2
-rw-r--r--chrome/renderer/resources/extension_process_bindings.js32
-rw-r--r--chrome/renderer/resources/renderer_extension_bindings.js12
4 files changed, 62 insertions, 40 deletions
diff --git a/chrome/renderer/extensions/extension_api_client_unittest.cc b/chrome/renderer/extensions/extension_api_client_unittest.cc
index d5f73bb..874f2bf 100644
--- a/chrome/renderer/extensions/extension_api_client_unittest.cc
+++ b/chrome/renderer/extensions/extension_api_client_unittest.cc
@@ -157,19 +157,22 @@ TEST_F(ExtensionAPIClientTest, GetLastFocusedWindow) {
}
TEST_F(ExtensionAPIClientTest, GetAllWindows) {
- ExpectJsFail("chrome.windows.getAll(true, function(){}, 20);",
+ ExpectJsFail("chrome.windows.getAll({populate: true}, function(){}, 20);",
"Uncaught Error: Too many arguments.");
ExpectJsFail("chrome.windows.getAll(1, function(){});",
"Uncaught Error: Invalid value for argument 0. "
- "Expected 'boolean' but got 'integer'.");
+ "Expected 'object' but got 'integer'.");
- ExpectJsPass("chrome.windows.getAll(true, function(){})",
- "windows.getAll", "true");
+ ExpectJsPass("chrome.windows.getAll({populate:true}, function(){})",
+ "windows.getAll", "{\"populate\":true}");
ExpectJsPass("chrome.windows.getAll(null, function(){})",
"windows.getAll", "null");
+ ExpectJsPass("chrome.windows.getAll({}, function(){})",
+ "windows.getAll", "{}");
+
ExpectJsPass("chrome.windows.getAll(undefined, function(){})",
"windows.getAll", "null");
}
@@ -535,42 +538,53 @@ TEST_F(ExtensionAPIClientTest, EnablePageAction) {
}
TEST_F(ExtensionAPIClientTest, ExpandToolstrip) {
- ExpectJsPass("chrome.toolstrip.expand(100, 'http://foo/')",
+ ExpectJsPass("chrome.toolstrip.expand({height:100, url:'http://foo/'})",
"toolstrip.expand",
- "[100,\"http://foo/\"]");
- ExpectJsPass("chrome.toolstrip.expand(100, null)",
+ "{\"height\":100,\"url\":\"http://foo/\"}");
+ ExpectJsPass("chrome.toolstrip.expand({height:100}, null)",
"toolstrip.expand",
- "[100,null]");
- ExpectJsPass("chrome.toolstrip.expand(100, 'http://foo/', function(){})",
+ "{\"height\":100}");
+ ExpectJsPass("chrome.toolstrip.expand({height:100,url:'http://foo/'}, "
+ "function(){})",
"toolstrip.expand",
- "[100,\"http://foo/\"]");
+ "{\"height\":100,\"url\":\"http://foo/\"}");
+
- ExpectJsFail("chrome.toolstrip.expand('100', 'http://foo/')",
+ ExpectJsFail("chrome.toolstrip.expand()",
+ "Uncaught Error: Parameter 0 is required.");
+ ExpectJsFail("chrome.toolstrip.expand(1)",
+ "Uncaught Error: Invalid value for argument 0. "
+ "Expected 'object' but got 'integer'.");
+ ExpectJsFail("chrome.toolstrip.expand({height:'100', url:'http://foo/'})",
"Uncaught Error: Invalid value for argument 0. "
+ "Property 'height': "
"Expected 'integer' but got 'string'.");
- ExpectJsFail("chrome.toolstrip.expand(100, 100)",
- "Uncaught Error: Invalid value for argument 1. "
+ ExpectJsFail("chrome.toolstrip.expand({height:100,url:100})",
+ "Uncaught Error: Invalid value for argument 0. Property 'url': "
"Expected 'string' but got 'integer'.");
- ExpectJsFail("chrome.toolstrip.expand(100, 'http://foo/', 32)",
- "Uncaught Error: Invalid value for argument 2. "
+ ExpectJsFail("chrome.toolstrip.expand({height:100,'url':'http://foo/'}, 32)",
+ "Uncaught Error: Invalid value for argument 1. "
"Expected 'function' but got 'integer'.");
}
TEST_F(ExtensionAPIClientTest, CollapseToolstrip) {
- ExpectJsPass("chrome.toolstrip.collapse('http://foo/')",
+ ExpectJsPass("chrome.toolstrip.collapse({url:'http://foo/'})",
"toolstrip.collapse",
- "\"http://foo/\"");
+ "{\"url\":\"http://foo/\"}");
ExpectJsPass("chrome.toolstrip.collapse(null)",
"toolstrip.collapse",
"null");
- ExpectJsPass("chrome.toolstrip.collapse('http://foo/', function(){})",
+ ExpectJsPass("chrome.toolstrip.collapse({url:'http://foo/'}, function(){})",
"toolstrip.collapse",
- "\"http://foo/\"");
+ "{\"url\":\"http://foo/\"}");
+ ExpectJsFail("chrome.toolstrip.collapse(1)",
+ "Uncaught Error: Invalid value for argument 0. "
+ "Expected 'object' but got 'integer'.");
ExpectJsFail("chrome.toolstrip.collapse(100)",
"Uncaught Error: Invalid value for argument 0. "
- "Expected 'string' but got 'integer'.");
- ExpectJsFail("chrome.toolstrip.collapse('http://foo/', 32)",
+ "Expected 'object' but got 'integer'.");
+ ExpectJsFail("chrome.toolstrip.collapse({url:'http://foo/'}, 32)",
"Uncaught Error: Invalid value for argument 1. "
"Expected 'function' but got 'integer'.");
}
diff --git a/chrome/renderer/renderer_resources.grd b/chrome/renderer/renderer_resources.grd
index b426d6e..5ec2309 100644
--- a/chrome/renderer/renderer_resources.grd
+++ b/chrome/renderer/renderer_resources.grd
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- This comment is only here because changes to resources are not picked up
-without changes to the corresponding grd file. aa4 -->
+without changes to the corresponding grd file. rw -->
<grit latest_public_release="0" current_release="1">
<outputs>
<output filename="grit/renderer_resources.h" type="rc_header">
diff --git a/chrome/renderer/resources/extension_process_bindings.js b/chrome/renderer/resources/extension_process_bindings.js
index 697e0a7..4312d04 100644
--- a/chrome/renderer/resources/extension_process_bindings.js
+++ b/chrome/renderer/resources/extension_process_bindings.js
@@ -75,7 +75,7 @@ var chrome = chrome || {};
"message": error
};
}
-
+
if (request.callback) {
// Callbacks currently only support one callback argument.
var callbackArgs = response ? [JSON.parse(response)] : [];
@@ -117,7 +117,7 @@ var chrome = chrome || {};
function prepareRequest(args, argSchemas) {
var request = {};
var argCount = args.length;
-
+
// Look for callback param.
if (argSchemas.length > 0 &&
args.length == argSchemas.length &&
@@ -138,7 +138,7 @@ var chrome = chrome || {};
request.args[k] = args[k];
}
}
-
+
return request;
}
@@ -154,7 +154,7 @@ var chrome = chrome || {};
return StartRequest(functionName, sargs, requestId,
request.callback ? true : false);
}
-
+
// Using forEach for convenience, and to bind |module|s & |apiDefs|s via
// closures.
function forEach(a, f) {
@@ -189,7 +189,7 @@ var chrome = chrome || {};
// http://code.google.com/p/chromium/issues/detail?id=16356
chrome.self = chrome.extension;
- // |apiFunctions| is a hash of name -> object that stores the
+ // |apiFunctions| is a hash of name -> object that stores the
// name & definition of the apiFunction. Custom handling of api functions
// is implemented by adding a "handleRequest" function to the object.
var apiFunctions = {};
@@ -199,7 +199,7 @@ var chrome = chrome || {};
// and validating either here, in a unit_test or both.
// TODO(rafaelw): Handle synchronous functions.
// TOOD(rafaelw): Consider providing some convenient override points
- // for api functions that wish to insert themselves into the call.
+ // for api functions that wish to insert themselves into the call.
var apiDefinitions = JSON.parse(GetExtensionAPIDefinition());
forEach(apiDefinitions, function(apiDef) {
@@ -221,19 +221,19 @@ var chrome = chrome || {};
if (module[functionDef.name])
return;
- var apiFunction = {};
+ var apiFunction = {};
apiFunction.definition = functionDef;
apiFunction.name = apiDef.namespace + "." + functionDef.name;;
apiFunctions[apiFunction.name] = apiFunction;
-
+
module[functionDef.name] = bind(apiFunction, function() {
chromeHidden.validate(arguments, this.definition.parameters);
-
+
if (this.handleRequest)
return this.handleRequest.apply(this, arguments);
- else
+ else
return sendRequest(this.name, arguments,
- this.definition.parameters);
+ this.definition.parameters);
});
});
}
@@ -253,10 +253,14 @@ var chrome = chrome || {};
}
});
- apiFunctions["tabs.connect"].handleRequest = function(tabId, opt_name) {
+ apiFunctions["tabs.connect"].handleRequest = function(tabId, connectInfo) {
+ var name = "";
+ if (connectInfo) {
+ name = connectInfo.name || name;
+ }
var portId = OpenChannelToTab(
- tabId, chrome.extension.id_, opt_name || "");
- return chromeHidden.Port.createPort(portId, opt_name);
+ tabId, chrome.extension.id_, name);
+ return chromeHidden.Port.createPort(portId, name);
}
apiFunctions["extension.getViews"].handleRequest = function() {
diff --git a/chrome/renderer/resources/renderer_extension_bindings.js b/chrome/renderer/resources/renderer_extension_bindings.js
index cf53de9..6e9b387 100644
--- a/chrome/renderer/resources/renderer_extension_bindings.js
+++ b/chrome/renderer/resources/renderer_extension_bindings.js
@@ -16,7 +16,7 @@
var chrome = chrome || {};
(function () {
- native function OpenChannelToExtension(id);
+ native function OpenChannelToExtension(id, name);
native function CloseChannel(portId);
native function PortAddRef(portId);
native function PortRelease(portId);
@@ -115,11 +115,15 @@ var chrome = chrome || {};
// Opens a message channel to the extension. Returns a Port for
// message passing.
- chrome.Extension.prototype.connect = function(opt_name) {
- var portId = OpenChannelToExtension(this.id_, opt_name || "");
+ chrome.Extension.prototype.connect = function(connectInfo) {
+ var name = "";
+ if (connectInfo) {
+ name = connectInfo.name || name;
+ }
+ var portId = OpenChannelToExtension(this.id_, name);
if (portId == -1)
throw new Error("No such extension: '" + this.id_ + "'");
- return chromeHidden.Port.createPort(portId, opt_name);
+ return chromeHidden.Port.createPort(portId, name);
};
// Returns a resource URL that can be used to fetch a resource from this