summaryrefslogtreecommitdiffstats
path: root/chrome/renderer/extensions
diff options
context:
space:
mode:
authorrafaelw@chromium.org <rafaelw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-16 22:20:00 +0000
committerrafaelw@chromium.org <rafaelw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-16 22:20:00 +0000
commit434c21e053a20e5d417125a62f6f9de31258a8ce (patch)
tree67e26ed41a65e474c7e5fa45bddf791e1897f492 /chrome/renderer/extensions
parent44b4b0ccfdfc1ca2a8a56094d86a554b79f43ce7 (diff)
downloadchromium_src-434c21e053a20e5d417125a62f6f9de31258a8ce.zip
chromium_src-434c21e053a20e5d417125a62f6f9de31258a8ce.tar.gz
chromium_src-434c21e053a20e5d417125a62f6f9de31258a8ce.tar.bz2
First step in abstracting extension api to common/shared "IDL" files (jsonschema).
In this step, All "normal" api calls and events (those that arrive or originate from the browser process) are routed through a single v8::Extension API Call ("StartRequest"). Additionally, internal string names for methods and events now match the js namespace (i.e. "RemoveTab" -> "tabs.remove"), in anticipation of having names be implicit from their api module & name in the api "IDL". TBR=aa,mpcomplete Review URL: http://codereview.chromium.org/149730 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@20910 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer/extensions')
-rw-r--r--chrome/renderer/extensions/extension_api_client_unittest.cc68
-rw-r--r--chrome/renderer/extensions/extension_process_bindings.cc23
2 files changed, 47 insertions, 44 deletions
diff --git a/chrome/renderer/extensions/extension_api_client_unittest.cc b/chrome/renderer/extensions/extension_api_client_unittest.cc
index 05d631e..33fdbe1 100644
--- a/chrome/renderer/extensions/extension_api_client_unittest.cc
+++ b/chrome/renderer/extensions/extension_api_client_unittest.cc
@@ -120,7 +120,7 @@ TEST_F(ExtensionAPIClientTest, GetWindow) {
"Expected 'function' but got 'integer'.");
ExpectJsPass("chrome.windows.get(2, function(){})",
- "GetWindow", "2");
+ "windows.get", "2");
}
TEST_F(ExtensionAPIClientTest, GetCurentWindow) {
@@ -135,7 +135,7 @@ TEST_F(ExtensionAPIClientTest, GetCurentWindow) {
"Expected 'function' but got 'string'.");
ExpectJsPass("chrome.windows.getCurrent(function(){})",
- "GetCurrentWindow", "null");
+ "windows.getCurrent", "null");
}
TEST_F(ExtensionAPIClientTest, GetLastFocusedWindow) {
@@ -150,7 +150,7 @@ TEST_F(ExtensionAPIClientTest, GetLastFocusedWindow) {
"Expected 'function' but got 'string'.");
ExpectJsPass("chrome.windows.getLastFocused(function(){})",
- "GetLastFocusedWindow", "null");
+ "windows.getLastFocused", "null");
}
TEST_F(ExtensionAPIClientTest, GetAllWindows) {
@@ -162,13 +162,13 @@ TEST_F(ExtensionAPIClientTest, GetAllWindows) {
"Expected 'boolean' but got 'integer'.");
ExpectJsPass("chrome.windows.getAll(true, function(){})",
- "GetAllWindows", "true");
+ "windows.getAll", "true");
ExpectJsPass("chrome.windows.getAll(null, function(){})",
- "GetAllWindows", "null");
+ "windows.getAll", "null");
ExpectJsPass("chrome.windows.getAll(undefined, function(){})",
- "GetAllWindows", "null");
+ "windows.getAll", "null");
}
TEST_F(ExtensionAPIClientTest, CreateWindow) {
@@ -198,7 +198,7 @@ TEST_F(ExtensionAPIClientTest, CreateWindow) {
" width:100,"
" height:200"
"})",
- "CreateWindow",
+ "windows.create",
"{\"url\":\"http://www.google.com/\","
"\"left\":0,"
"\"top\":10,"
@@ -229,7 +229,7 @@ TEST_F(ExtensionAPIClientTest, UpdateWindow) {
" width:100,"
" height:200"
"})",
- "UpdateWindow",
+ "windows.update",
"[42,"
"{\"width\":100,"
"\"height\":200}]");
@@ -248,10 +248,10 @@ TEST_F(ExtensionAPIClientTest, RemoveWindow) {
"Expected 'function' but got 'integer'.");
ExpectJsPass("chrome.windows.remove(2, function(){})",
- "RemoveWindow", "2");
+ "windows.remove", "2");
ExpectJsPass("chrome.windows.remove(2)",
- "RemoveWindow", "2");
+ "windows.remove", "2");
}
// Tab API tests
@@ -272,7 +272,7 @@ TEST_F(ExtensionAPIClientTest, GetTab) {
"Expected 'function' but got 'integer'.");
ExpectJsPass("chrome.tabs.get(2, function(){})",
- "GetTab", "2");
+ "tabs.get", "2");
}
#if defined(OS_WIN)
@@ -289,7 +289,7 @@ TEST_F(ExtensionAPIClientTest, DetectTabLanguage) {
"Expected 'function' but got 'integer'.");
ExpectJsPass("chrome.tabs.detectLanguage(null, function(){})",
- "DetectTabLanguage", "null");
+ "tabs.detectLanguage", "null");
}
#endif
@@ -309,10 +309,10 @@ TEST_F(ExtensionAPIClientTest, GetSelectedTab) {
"Expected 'function' but got 'integer'.");
ExpectJsPass("chrome.tabs.getSelected(2, function(){})",
- "GetSelectedTab", "2");
+ "tabs.getSelected", "2");
ExpectJsPass("chrome.tabs.getSelected(null, function(){})",
- "GetSelectedTab", "null");
+ "tabs.getSelected", "null");
}
@@ -332,10 +332,10 @@ TEST_F(ExtensionAPIClientTest, GetAllTabsInWindow) {
"Expected 'integer' but got 'string'.");
ExpectJsPass("chrome.tabs.getAllInWindow(32, function(){})",
- "GetAllTabsInWindow", "32");
+ "tabs.getAllInWindow", "32");
ExpectJsPass("chrome.tabs.getAllInWindow(undefined, function(){})",
- "GetAllTabsInWindow", "null");
+ "tabs.getAllInWindow", "null");
}
TEST_F(ExtensionAPIClientTest, CreateTab) {
@@ -355,7 +355,7 @@ TEST_F(ExtensionAPIClientTest, CreateTab) {
" index: 2,"
" windowId:4"
"})",
- "CreateTab",
+ "tabs.create",
"{\"url\":\"http://www.google.com/\","
"\"selected\":true,"
"\"index\":2,"
@@ -376,7 +376,7 @@ TEST_F(ExtensionAPIClientTest, UpdateTab) {
" url:'http://www.google.com/',"
" selected:true"
"})",
- "UpdateTab",
+ "tabs.update",
"[42,"
"{\"url\":\"http://www.google.com/\","
"\"selected\":true}]");
@@ -396,7 +396,7 @@ TEST_F(ExtensionAPIClientTest, MoveTab) {
" index:3,"
" windowId:21"
"})",
- "MoveTab",
+ "tabs.move",
"[42,"
"{\"index\":3,"
"\"windowId\":21}]");
@@ -416,10 +416,10 @@ TEST_F(ExtensionAPIClientTest, RemoveTab) {
"Expected 'function' but got 'integer'.");
ExpectJsPass("chrome.tabs.remove(2, function(){})",
- "RemoveTab", "2");
+ "tabs.remove", "2");
ExpectJsPass("chrome.tabs.remove(2)",
- "RemoveTab", "2");
+ "tabs.remove", "2");
}
// Bookmark API tests
@@ -434,16 +434,16 @@ TEST_F(ExtensionAPIClientTest, CreateBookmark) {
ExpectJsPass(
"chrome.bookmarks.create({parentId:0, title:'x'}, function(){})",
- "CreateBookmark",
+ "bookmarks.create",
"{\"parentId\":0,\"title\":\"x\"}");
}
TEST_F(ExtensionAPIClientTest, GetBookmarks) {
ExpectJsPass("chrome.bookmarks.get(0, function(){});",
- "GetBookmarks",
+ "bookmarks.get",
"0");
ExpectJsPass("chrome.bookmarks.get([0,1,2,3], function(){});",
- "GetBookmarks",
+ "bookmarks.get",
"[0,1,2,3]");
ExpectJsFail("chrome.bookmarks.get(null, function(){});",
"Uncaught Error: Parameter 0 is required.");
@@ -458,43 +458,43 @@ TEST_F(ExtensionAPIClientTest, GetBookmarks) {
TEST_F(ExtensionAPIClientTest, GetBookmarkChildren) {
ExpectJsPass("chrome.bookmarks.getChildren(42, function(){});",
- "GetBookmarkChildren",
+ "bookmarks.getChildren",
"42");
}
TEST_F(ExtensionAPIClientTest, GetBookmarkTree) {
ExpectJsPass("chrome.bookmarks.getTree(function(){});",
- "GetBookmarkTree",
+ "bookmarks.getTree",
"null");
}
TEST_F(ExtensionAPIClientTest, SearchBookmarks) {
ExpectJsPass("chrome.bookmarks.search('hello',function(){});",
- "SearchBookmarks",
+ "bookmarks.search",
"\"hello\"");
}
TEST_F(ExtensionAPIClientTest, RemoveBookmark) {
ExpectJsPass("chrome.bookmarks.remove(42);",
- "RemoveBookmark",
+ "bookmarks.remove",
"[42,false]");
}
TEST_F(ExtensionAPIClientTest, RemoveBookmarkTree) {
ExpectJsPass("chrome.bookmarks.removeTree(42);",
- "RemoveBookmark",
+ "bookmarks.removeTree",
"[42,true]");
}
TEST_F(ExtensionAPIClientTest, MoveBookmark) {
ExpectJsPass("chrome.bookmarks.move(42,{parentId:1,index:0});",
- "MoveBookmark",
+ "bookmarks.move",
"[42,{\"parentId\":1,\"index\":0}]");
}
TEST_F(ExtensionAPIClientTest, SetBookmarkTitle) {
ExpectJsPass("chrome.bookmarks.update(42,{title:'x'});",
- "SetBookmarkTitle",
+ "bookmarks.update",
"[42,{\"title\":\"x\"}]");
}
@@ -502,19 +502,19 @@ TEST_F(ExtensionAPIClientTest, EnablePageAction) {
// Basic old-school enablePageAction call.
ExpectJsPass("chrome.pageActions.enableForTab("
"\"dummy\", {tabId: 0, url: \"http://foo/\"});",
- "EnablePageAction",
+ "pageActions.enableForTab",
"[\"dummy\",{\"tabId\":0,\"url\":\"http://foo/\"}]");
// Try both optional parameters (title and iconId).
ExpectJsPass("chrome.pageActions.enableForTab("
"\"dummy\", {tabId: 0, url: \"http://foo/\","
"title: \"a\", iconId: 0});",
- "EnablePageAction",
+ "pageActions.enableForTab",
"[\"dummy\",{\"tabId\":0,\"url\":\"http://foo/\","
"\"title\":\"a\",\"iconId\":0}]");
// Now try disablePageAction.
ExpectJsPass("chrome.pageActions.disableForTab("
"\"dummy\", {tabId: 0, url: \"http://foo/\"});",
- "DisablePageAction",
+ "pageActions.disableForTab",
"[\"dummy\",{\"tabId\":0,\"url\":\"http://foo/\"}]");
}
diff --git a/chrome/renderer/extensions/extension_process_bindings.cc b/chrome/renderer/extensions/extension_process_bindings.cc
index fd70dcf..35fa0a4 100644
--- a/chrome/renderer/extensions/extension_process_bindings.cc
+++ b/chrome/renderer/extensions/extension_process_bindings.cc
@@ -64,16 +64,14 @@ class ExtensionImpl : public ExtensionBase {
virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction(
v8::Handle<v8::String> name) {
- std::set<std::string>* names = GetFunctionNameSet();
-
if (name->Equals(v8::String::New("GetViews"))) {
return v8::FunctionTemplate::New(GetViews);
} else if (name->Equals(v8::String::New("GetNextRequestId"))) {
return v8::FunctionTemplate::New(GetNextRequestId);
} else if (name->Equals(v8::String::New("GetCurrentPageActions"))) {
return v8::FunctionTemplate::New(GetCurrentPageActions);
- } else if (names->find(*v8::String::AsciiValue(name)) != names->end()) {
- return v8::FunctionTemplate::New(StartRequest, name);
+ } else if (name->Equals(v8::String::New("StartRequest"))) {
+ return v8::FunctionTemplate::New(StartRequest);
}
return ExtensionBase::GetNativeFunction(name);
@@ -146,14 +144,19 @@ class ExtensionImpl : public ExtensionBase {
if (!renderview)
return v8::Undefined();
- if (args.Length() != 3 || !args[0]->IsString() || !args[1]->IsInt32() ||
- !args[2]->IsBoolean())
+ if (args.Length() != 4 || !args[0]->IsString() || !args[1]->IsString() ||
+ !args[2]->IsInt32() || !args[3]->IsBoolean())
+ return v8::Undefined();
+
+ std::string name = *v8::String::AsciiValue(args[0]);
+ if (GetFunctionNameSet()->find(name) == GetFunctionNameSet()->end()) {
+ NOTREACHED() << "Unexpected function " << name;
return v8::Undefined();
+ }
- std::string name = *v8::String::AsciiValue(args.Data());
- std::string json_args = *v8::String::Utf8Value(args[0]);
- int request_id = args[1]->Int32Value();
- bool has_callback = args[2]->BooleanValue();
+ std::string json_args = *v8::String::Utf8Value(args[1]);
+ int request_id = args[2]->Int32Value();
+ bool has_callback = args[3]->BooleanValue();
v8::Persistent<v8::Context> current_context =
v8::Persistent<v8::Context>::New(v8::Context::GetCurrent());