diff options
author | rafaelw@chromium.org <rafaelw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-16 22:20:00 +0000 |
---|---|---|
committer | rafaelw@chromium.org <rafaelw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-16 22:20:00 +0000 |
commit | 434c21e053a20e5d417125a62f6f9de31258a8ce (patch) | |
tree | 67e26ed41a65e474c7e5fa45bddf791e1897f492 /chrome | |
parent | 44b4b0ccfdfc1ca2a8a56094d86a554b79f43ce7 (diff) | |
download | chromium_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')
12 files changed, 158 insertions, 174 deletions
diff --git a/chrome/browser/extensions/extension_bookmarks_module_constants.cc b/chrome/browser/extensions/extension_bookmarks_module_constants.cc index 24d7c92..222728b 100644 --- a/chrome/browser/extensions/extension_bookmarks_module_constants.cc +++ b/chrome/browser/extensions/extension_bookmarks_module_constants.cc @@ -27,19 +27,20 @@ const char kInvalidIndexError[] = "Index out of bounds."; const char kInvalidUrlError[] = "Invalid URL."; const char kModifySpecialError[] = "Can't modify the root bookmark folders."; -const char kOnBookmarkAdded[] = "bookmark-added"; -const char kOnBookmarkRemoved[] = "bookmark-removed"; -const char kOnBookmarkChanged[] = "bookmark-changed"; -const char kOnBookmarkMoved[] = "bookmark-moved"; -const char kOnBookmarkChildrenReordered[] = "bookmark-children-reordered"; +const char kOnBookmarkAdded[] = "bookmarks.onAdded"; +const char kOnBookmarkRemoved[] = "bookmarks.onRemoved"; +const char kOnBookmarkChanged[] = "bookmarks.onChanged"; +const char kOnBookmarkMoved[] = "bookmarks.onMoved"; +const char kOnBookmarkChildrenReordered[] = "bookmarks.onChildrenReordered"; -const char kGetBookmarksFunction[] = "GetBookmarks"; -const char kGetBookmarkChildrenFunction[] = "GetBookmarkChildren"; -const char kGetBookmarkTreeFunction[] = "GetBookmarkTree"; -const char kSearchBookmarksFunction[] = "SearchBookmarks"; -const char kRemoveBookmarkFunction[] = "RemoveBookmark"; -const char kCreateBookmarkFunction[] = "CreateBookmark"; -const char kMoveBookmarkFunction[] = "MoveBookmark"; -const char kSetBookmarkTitleFunction[] = "SetBookmarkTitle"; +const char kGetBookmarksFunction[] = "bookmarks.get"; +const char kGetBookmarkChildrenFunction[] = "bookmarks.getChildren"; +const char kGetBookmarkTreeFunction[] = "bookmarks.getTree"; +const char kSearchBookmarksFunction[] = "bookmarks.search"; +const char kRemoveBookmarkFunction[] = "bookmarks.remove"; +const char kRemoveBookmarkTreeFunction[] = "bookmarks.removeTree"; +const char kCreateBookmarkFunction[] = "bookmarks.create"; +const char kMoveBookmarkFunction[] = "bookmarks.move"; +const char kSetBookmarkTitleFunction[] = "bookmarks.update"; } // namespace extension_bookmarks_module_constants diff --git a/chrome/browser/extensions/extension_bookmarks_module_constants.h b/chrome/browser/extensions/extension_bookmarks_module_constants.h index 665747c..7c2af58 100644 --- a/chrome/browser/extensions/extension_bookmarks_module_constants.h +++ b/chrome/browser/extensions/extension_bookmarks_module_constants.h @@ -44,6 +44,7 @@ extern const char kGetBookmarkChildrenFunction[]; extern const char kGetBookmarkTreeFunction[]; extern const char kSearchBookmarksFunction[]; extern const char kRemoveBookmarkFunction[]; +extern const char kRemoveBookmarkTreeFunction[]; extern const char kCreateBookmarkFunction[]; extern const char kMoveBookmarkFunction[]; extern const char kSetBookmarkTitleFunction[]; diff --git a/chrome/browser/extensions/extension_browser_event_router.cc b/chrome/browser/extensions/extension_browser_event_router.cc index c7a5b33..a689d32 100644 --- a/chrome/browser/extensions/extension_browser_event_router.cc +++ b/chrome/browser/extensions/extension_browser_event_router.cc @@ -162,7 +162,7 @@ void ExtensionBrowserEventRouter::TabCreatedAt(TabContents* contents, void ExtensionBrowserEventRouter::TabInsertedAt(TabContents* contents, int index, bool foreground) { - // If tab is new, send tab-created event. + // If tab is new, send created event. int tab_id = ExtensionTabUtil::GetTabId(contents); if (tab_entries_.find(tab_id) == tab_entries_.end()) { tab_entries_[tab_id] = TabEntry(contents); diff --git a/chrome/browser/extensions/extension_event_names.cc b/chrome/browser/extensions/extension_event_names.cc index 214d37b..421bab8 100644 --- a/chrome/browser/extensions/extension_event_names.cc +++ b/chrome/browser/extensions/extension_event_names.cc @@ -6,16 +6,16 @@ namespace extension_event_names { -const char kOnTabAttached[] = "tab-attached"; -const char kOnTabCreated[] = "tab-created"; -const char kOnTabDetached[] = "tab-detached"; -const char kOnTabMoved[] = "tab-moved"; -const char kOnTabRemoved[] = "tab-removed"; -const char kOnTabSelectionChanged[] = "tab-selection-changed"; -const char kOnTabUpdated[] = "tab-updated"; -const char kOnWindowCreated[] = "window-created"; -const char kOnWindowFocusedChanged[] = "window-focus-changed"; -const char kOnWindowRemoved[] = "window-removed"; +const char kOnTabAttached[] = "tabs.onAttached"; +const char kOnTabCreated[] = "tabs.onCreated"; +const char kOnTabDetached[] = "tabs.onDetached"; +const char kOnTabMoved[] = "tabs.onMoved"; +const char kOnTabRemoved[] = "tabs.onRemoved"; +const char kOnTabSelectionChanged[] = "tabs.onSelectionChanged"; +const char kOnTabUpdated[] = "tabs.onUpdated"; +const char kOnWindowCreated[] = "windows.onCreated"; +const char kOnWindowFocusedChanged[] = "windows.onFocusChanged"; +const char kOnWindowRemoved[] = "windows.onRemoved"; } // namespace extension_event_names diff --git a/chrome/browser/extensions/extension_function_dispatcher.cc b/chrome/browser/extensions/extension_function_dispatcher.cc index 971349b..4b13d98 100644 --- a/chrome/browser/extensions/extension_function_dispatcher.cc +++ b/chrome/browser/extensions/extension_function_dispatcher.cc @@ -119,6 +119,8 @@ void FactoryRegistry::ResetFunctions() { &NewExtensionFunction<SearchBookmarksFunction>; factories_[bookmarks::kRemoveBookmarkFunction] = &NewExtensionFunction<RemoveBookmarkFunction>; + factories_[bookmarks::kRemoveBookmarkTreeFunction] = + &NewExtensionFunction<RemoveBookmarkFunction>; factories_[bookmarks::kCreateBookmarkFunction] = &NewExtensionFunction<CreateBookmarkFunction>; factories_[bookmarks::kMoveBookmarkFunction] = diff --git a/chrome/browser/extensions/extension_page_actions_module_constants.cc b/chrome/browser/extensions/extension_page_actions_module_constants.cc index 2b54f1b..bda4d37 100644 --- a/chrome/browser/extensions/extension_page_actions_module_constants.cc +++ b/chrome/browser/extensions/extension_page_actions_module_constants.cc @@ -16,7 +16,7 @@ const char kNoTabError[] = "No tab with id: *."; const char kNoPageActionError[] = "No PageAction with id: *."; const char kUrlNotActiveError[] = "This url is no longer active: *."; -const char kEnablePageActionFunction[] = "EnablePageAction"; -const char kDisablePageActionFunction[] = "DisablePageAction"; +const char kEnablePageActionFunction[] = "pageActions.enableForTab"; +const char kDisablePageActionFunction[] = "pageActions.disableForTab"; } // namespace extension_page_actions_module_constants diff --git a/chrome/browser/extensions/extension_tabs_module_constants.cc b/chrome/browser/extensions/extension_tabs_module_constants.cc index d4d1cf8..11e7dad 100644 --- a/chrome/browser/extensions/extension_tabs_module_constants.cc +++ b/chrome/browser/extensions/extension_tabs_module_constants.cc @@ -41,21 +41,21 @@ const char kTabNotFoundError[] = "No tab with id: *."; const char kNoSelectedTabError[] = "No selected tab"; const char kInvalidUrlError[] = "Invalid url: \"*\"."; -const char kGetWindowFunction[] = "GetWindow"; -const char kGetCurrentWindowFunction[] = "GetCurrentWindow"; -const char kGetLastFocusedWindowFunction[] = "GetLastFocusedWindow"; -const char kGetAllWindowsFunction[] = "GetAllWindows"; -const char kCreateWindowFunction[] = "CreateWindow"; -const char kUpdateWindowFunction[] = "UpdateWindow"; -const char kRemoveWindowFunction[] = "RemoveWindow"; - -const char kGetTabFunction[] = "GetTab"; -const char kGetSelectedTabFunction[] = "GetSelectedTab"; -const char kGetAllTabsInWindowFunction[] = "GetAllTabsInWindow"; -const char kCreateTabFunction[] = "CreateTab"; -const char kUpdateTabFunction[] = "UpdateTab"; -const char kMoveTabFunction[] = "MoveTab"; -const char kRemoveTabFunction[] = "RemoveTab"; -const char kDetectTabLanguageFunction[] = "DetectTabLanguage"; +const char kGetWindowFunction[] = "windows.get"; +const char kGetCurrentWindowFunction[] = "windows.getCurrent"; +const char kGetLastFocusedWindowFunction[] = "windows.getLastFocused"; +const char kGetAllWindowsFunction[] = "windows.getAll"; +const char kCreateWindowFunction[] = "windows.create"; +const char kUpdateWindowFunction[] = "windows.update"; +const char kRemoveWindowFunction[] = "windows.remove"; + +const char kGetTabFunction[] = "tabs.get"; +const char kGetSelectedTabFunction[] = "tabs.getSelected"; +const char kGetAllTabsInWindowFunction[] = "tabs.getAllInWindow"; +const char kCreateTabFunction[] = "tabs.create"; +const char kUpdateTabFunction[] = "tabs.update"; +const char kMoveTabFunction[] = "tabs.move"; +const char kRemoveTabFunction[] = "tabs.remove"; +const char kDetectTabLanguageFunction[] = "tabs.detectLanguage"; } // namespace extension_tabs_module_constants diff --git a/chrome/browser/extensions/extension_uitest.cc b/chrome/browser/extensions/extension_uitest.cc index 6945446..89faa41 100644 --- a/chrome/browser/extensions/extension_uitest.cc +++ b/chrome/browser/extensions/extension_uitest.cc @@ -130,7 +130,7 @@ TEST_F(SimpleApiCallExtensionTest, RunTest) { reinterpret_cast<DictionaryValue*>(message_value.get()); std::string result; message_dict->GetString(keys::kAutomationNameKey, &result); - EXPECT_EQ(result, "RemoveTab"); + EXPECT_EQ(result, "tabs.remove"); result = ""; message_dict->GetString(keys::kAutomationArgsKey, &result); @@ -224,7 +224,7 @@ class RoundtripAutomationProxy : public MultiMessageAutomationProxy { &has_callback)); if (messages_received_ == 1) { - EXPECT_EQ(function_name, "GetLastFocusedWindow"); + EXPECT_EQ(function_name, "windows.getLastFocused"); EXPECT_GE(request_id, 0); EXPECT_TRUE(has_callback); @@ -241,7 +241,7 @@ class RoundtripAutomationProxy : public MultiMessageAutomationProxy { keys::kAutomationOrigin, keys::kAutomationResponseTarget); } else if (messages_received_ == 2) { - EXPECT_EQ(function_name, "RemoveTab"); + EXPECT_EQ(function_name, "tabs.remove"); EXPECT_FALSE(has_callback); std::string args; @@ -318,25 +318,25 @@ class BrowserEventAutomationProxy : public MultiMessageAutomationProxy { const char* BrowserEventAutomationProxy::event_names_[] = { // Window events. - "window-created", - "window-removed", - "window-focus-changed", + "windows.onCreated", + "windows.onRemoved", + "windows.onFocusChanged", // Tab events. - "tab-created", - "tab-updated", - "tab-moved", - "tab-selection-changed", - "tab-attached", - "tab-detached", - "tab-removed", + "tabs.onCreated", + "tabs.onUpdated", + "tabs.onMoved", + "tabs.onSelectionChanged", + "tabs.onAttached", + "tabs.onDetached", + "tabs.onRemoved", // Bookmark events. - "bookmark-added", - "bookmark-removed", - "bookmark-changed", - "bookmark-moved", - "bookmark-children-reordered", + "bookmarks.onAdded", + "bookmarks.onRemoved", + "bookmarks.onChanged", + "bookmarks.onMoved", + "bookmarks.onChildrenReordered", }; void BrowserEventAutomationProxy::HandleMessageFromChrome() { @@ -361,7 +361,7 @@ void BrowserEventAutomationProxy::HandleMessageFromChrome() { std::string name; message_dict->GetString(keys::kAutomationNameKey, &name); - ASSERT_STREQ(name.c_str(), "GetCurrentWindow"); + ASSERT_STREQ(name.c_str(), "windows.getCurrent"); // Send an OpenChannelToExtension message to chrome. Note: the JSON // reader expects quoted property keys. See the comment in 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()); diff --git a/chrome/renderer/renderer_resources.grd b/chrome/renderer/renderer_resources.grd index 3067b3e..4af745f 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. sidchat1 --> +without changes to the corresponding grd file. weeeeee! --> <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 9423afe..3f05543 100644 --- a/chrome/renderer/resources/extension_process_bindings.js +++ b/chrome/renderer/resources/extension_process_bindings.js @@ -12,33 +12,10 @@ var chrome = chrome || {}; (function() { + native function StartRequest(); + native function GetCurrentPageActions(); native function GetViews(); - native function GetWindow(); - native function GetCurrentWindow(); - native function GetLastFocusedWindow(); - native function CreateWindow(); - native function UpdateWindow(); - native function RemoveWindow(); - native function GetAllWindows(); - native function GetTab(); - native function GetSelectedTab(); - native function GetAllTabsInWindow(); - native function CreateTab(); - native function UpdateTab(); - native function MoveTab(); - native function RemoveTab(); - native function DetectTabLanguage(); - native function EnablePageAction(); - native function DisablePageAction(); native function GetCurrentPageActions(); - native function GetBookmarks(); - native function GetBookmarkChildren(); - native function GetBookmarkTree(); - native function SearchBookmarks(); - native function RemoveBookmark(); - native function CreateBookmark(); - native function MoveBookmark(); - native function SetBookmarkTitle(); native function GetChromeHidden(); native function GetNextRequestId(); @@ -103,7 +80,7 @@ var chrome = chrome || {}; }; // Send an API request and optionally register a callback. - function sendRequest(request, args, callback) { + function sendRequest(functionName, args, callback) { // JSON.stringify doesn't support a root object which is undefined. if (args === undefined) args = null; @@ -114,7 +91,7 @@ var chrome = chrome || {}; hasCallback = true; callbacks[requestId] = callback; } - request(sargs, requestId, hasCallback); + StartRequest(functionName, sargs, requestId, hasCallback); } //---------------------------------------------------------------------------- @@ -124,7 +101,7 @@ var chrome = chrome || {}; chrome.windows.get = function(windowId, callback) { validate(arguments, arguments.callee.params); - sendRequest(GetWindow, windowId, callback); + sendRequest("windows.get", windowId, callback); }; chrome.windows.get.params = [ @@ -134,7 +111,7 @@ var chrome = chrome || {}; chrome.windows.getCurrent = function(callback) { validate(arguments, arguments.callee.params); - sendRequest(GetCurrentWindow, null, callback); + sendRequest("windows.getCurrent", null, callback); }; chrome.windows.getCurrent.params = [ @@ -143,7 +120,7 @@ var chrome = chrome || {}; chrome.windows.getLastFocused = function(callback) { validate(arguments, arguments.callee.params); - sendRequest(GetLastFocusedWindow, null, callback); + sendRequest("windows.getLastFocused", null, callback); }; chrome.windows.getLastFocused.params = [ @@ -152,7 +129,7 @@ var chrome = chrome || {}; chrome.windows.getAll = function(populate, callback) { validate(arguments, arguments.callee.params); - sendRequest(GetAllWindows, populate, callback); + sendRequest("windows.getAll", populate, callback); }; chrome.windows.getAll.params = [ @@ -162,7 +139,7 @@ var chrome = chrome || {}; chrome.windows.create = function(createData, callback) { validate(arguments, arguments.callee.params); - sendRequest(CreateWindow, createData, callback); + sendRequest("windows.create", createData, callback); }; chrome.windows.create.params = [ { @@ -181,7 +158,7 @@ var chrome = chrome || {}; chrome.windows.update = function(windowId, updateData, callback) { validate(arguments, arguments.callee.params); - sendRequest(UpdateWindow, [windowId, updateData], callback); + sendRequest("windows.update", [windowId, updateData], callback); }; chrome.windows.update.params = [ chrome.types.pInt, @@ -199,7 +176,7 @@ var chrome = chrome || {}; chrome.windows.remove = function(windowId, callback) { validate(arguments, arguments.callee.params); - sendRequest(RemoveWindow, windowId, callback); + sendRequest("windows.remove", windowId, callback); }; chrome.windows.remove.params = [ @@ -209,17 +186,17 @@ var chrome = chrome || {}; // sends (windowId). // *WILL* be followed by tab-attached AND then tab-selection-changed. - chrome.windows.onCreated = new chrome.Event("window-created"); + chrome.windows.onCreated = new chrome.Event("windows.onCreated"); // sends (windowId). // *WILL* be preceded by sequences of tab-removed AND then // tab-selection-changed -- one for each tab that was contained in the window // that closed - chrome.windows.onRemoved = new chrome.Event("window-removed"); + chrome.windows.onRemoved = new chrome.Event("windows.onRemoved"); // sends (windowId). chrome.windows.onFocusChanged = - new chrome.Event("window-focus-changed"); + new chrome.Event("windows.onFocusChanged"); //---------------------------------------------------------------------------- @@ -228,7 +205,7 @@ var chrome = chrome || {}; chrome.tabs.get = function(tabId, callback) { validate(arguments, arguments.callee.params); - sendRequest(GetTab, tabId, callback); + sendRequest("tabs.get", tabId, callback); }; chrome.tabs.get.params = [ @@ -238,7 +215,7 @@ var chrome = chrome || {}; chrome.tabs.getSelected = function(windowId, callback) { validate(arguments, arguments.callee.params); - sendRequest(GetSelectedTab, windowId, callback); + sendRequest("tabs.getSelected", windowId, callback); }; chrome.tabs.getSelected.params = [ @@ -248,7 +225,7 @@ var chrome = chrome || {}; chrome.tabs.getAllInWindow = function(windowId, callback) { validate(arguments, arguments.callee.params); - sendRequest(GetAllTabsInWindow, windowId, callback); + sendRequest("tabs.getAllInWindow", windowId, callback); }; chrome.tabs.getAllInWindow.params = [ @@ -258,7 +235,7 @@ var chrome = chrome || {}; chrome.tabs.create = function(tab, callback) { validate(arguments, arguments.callee.params); - sendRequest(CreateTab, tab, callback); + sendRequest("tabs.create", tab, callback); }; chrome.tabs.create.params = [ @@ -276,7 +253,7 @@ var chrome = chrome || {}; chrome.tabs.update = function(tabId, updates, callback) { validate(arguments, arguments.callee.params); - sendRequest(UpdateTab, [tabId, updates], callback); + sendRequest("tabs.update", [tabId, updates], callback); }; chrome.tabs.update.params = [ @@ -293,7 +270,7 @@ var chrome = chrome || {}; chrome.tabs.move = function(tabId, moveProps, callback) { validate(arguments, arguments.callee.params); - sendRequest(MoveTab, [tabId, moveProps], callback); + sendRequest("tabs.move", [tabId, moveProps], callback); }; chrome.tabs.move.params = [ @@ -310,7 +287,7 @@ var chrome = chrome || {}; chrome.tabs.remove = function(tabId, callback) { validate(arguments, arguments.callee.params); - sendRequest(RemoveTab, tabId, callback); + sendRequest("tabs.remove", tabId, callback); }; chrome.tabs.remove.params = [ @@ -320,7 +297,7 @@ var chrome = chrome || {}; chrome.tabs.detectLanguage = function(tabId, callback) { validate(arguments, arguments.callee.params); - sendRequest(DetectTabLanguage, tabId, callback); + sendRequest("tabs.detectLanguage", tabId, callback); }; chrome.tabs.detectLanguage.params = [ @@ -331,31 +308,31 @@ var chrome = chrome || {}; // Sends ({Tab}). // Will *NOT* be followed by tab-attached - it is implied. // *MAY* be followed by tab-selection-changed. - chrome.tabs.onCreated = new chrome.Event("tab-created"); + chrome.tabs.onCreated = new chrome.Event("tabs.onCreated"); // Sends (tabId, {ChangedProps}). - chrome.tabs.onUpdated = new chrome.Event("tab-updated"); + chrome.tabs.onUpdated = new chrome.Event("tabs.onUpdated"); // Sends (tabId, {windowId, fromIndex, toIndex}). // Tabs can only "move" within a window. - chrome.tabs.onMoved = new chrome.Event("tab-moved"); + chrome.tabs.onMoved = new chrome.Event("tabs.onMoved"); // Sends (tabId, {windowId}). chrome.tabs.onSelectionChanged = - new chrome.Event("tab-selection-changed"); + new chrome.Event("tabs.onSelectionChanged"); // Sends (tabId, {newWindowId, newPosition}). // *MAY* be followed by tab-selection-changed. - chrome.tabs.onAttached = new chrome.Event("tab-attached"); + chrome.tabs.onAttached = new chrome.Event("tabs.onAttached"); // Sends (tabId, {oldWindowId, oldPosition}). // *WILL* be followed by tab-selection-changed. - chrome.tabs.onDetached = new chrome.Event("tab-detached"); + chrome.tabs.onDetached = new chrome.Event("tabs.onDetached"); // Sends (tabId). // *WILL* be followed by tab-selection-changed. // Will *NOT* be followed or preceded by tab-detached. - chrome.tabs.onRemoved = new chrome.Event("tab-removed"); + chrome.tabs.onRemoved = new chrome.Event("tabs.onRemoved"); //---------------------------------------------------------------------------- @@ -364,7 +341,7 @@ var chrome = chrome || {}; chrome.pageActions.enableForTab = function(pageActionId, action) { validate(arguments, arguments.callee.params); - sendRequest(EnablePageAction, [pageActionId, action]); + sendRequest("pageActions.enableForTab", [pageActionId, action]); } chrome.pageActions.enableForTab.params = [ @@ -383,7 +360,7 @@ var chrome = chrome || {}; chrome.pageActions.disableForTab = function(pageActionId, action) { validate(arguments, arguments.callee.params); - sendRequest(DisablePageAction, [pageActionId, action]); + sendRequest("pageActions.disableForTab", [pageActionId, action]); } chrome.pageActions.disableForTab.params = [ @@ -415,7 +392,7 @@ var chrome = chrome || {}; chrome.bookmarks.get = function(ids, callback) { validate(arguments, arguments.callee.params); - sendRequest(GetBookmarks, ids, callback); + sendRequest("bookmarks.get", ids, callback); }; chrome.bookmarks.get.params = [ @@ -425,7 +402,7 @@ var chrome = chrome || {}; chrome.bookmarks.getChildren = function(id, callback) { validate(arguments, arguments.callee.params); - sendRequest(GetBookmarkChildren, id, callback); + sendRequest("bookmarks.getChildren", id, callback); }; chrome.bookmarks.getChildren.params = [ @@ -435,7 +412,7 @@ var chrome = chrome || {}; chrome.bookmarks.getTree = function(callback) { validate(arguments, arguments.callee.params); - sendRequest(GetBookmarkTree, null, callback); + sendRequest("bookmarks.getTree", null, callback); }; // TODO(erikkay): allow it to take an optional id as a starting point @@ -446,7 +423,7 @@ var chrome = chrome || {}; chrome.bookmarks.search = function(query, callback) { validate(arguments, arguments.callee.params); - sendRequest(SearchBookmarks, query, callback); + sendRequest("bookmarks.search", query, callback); }; chrome.bookmarks.search.params = [ @@ -456,7 +433,7 @@ var chrome = chrome || {}; chrome.bookmarks.remove = function(id, callback) { validate(arguments, arguments.callee.params); - sendRequest(RemoveBookmark, [id, false], callback); + sendRequest("bookmarks.remove", [id, false], callback); }; chrome.bookmarks.remove.params = [ @@ -466,7 +443,7 @@ var chrome = chrome || {}; chrome.bookmarks.removeTree = function(id, callback) { validate(arguments, arguments.callee.params); - sendRequest(RemoveBookmark, [id, true], callback); + sendRequest("bookmarks.removeTree", [id, true], callback); }; chrome.bookmarks.removeTree.params = [ @@ -476,7 +453,7 @@ var chrome = chrome || {}; chrome.bookmarks.create = function(bookmark, callback) { validate(arguments, arguments.callee.params); - sendRequest(CreateBookmark, bookmark, callback); + sendRequest("bookmarks.create", bookmark, callback); }; chrome.bookmarks.create.params = [ @@ -494,7 +471,7 @@ var chrome = chrome || {}; chrome.bookmarks.move = function(id, destination, callback) { validate(arguments, arguments.callee.params); - sendRequest(MoveBookmark, [id, destination], callback); + sendRequest("bookmarks.move", [id, destination], callback); }; chrome.bookmarks.move.params = [ @@ -511,7 +488,7 @@ var chrome = chrome || {}; chrome.bookmarks.update = function(id, changes, callback) { validate(arguments, arguments.callee.params); - sendRequest(SetBookmarkTitle, [id, changes], callback); + sendRequest("bookmarks.update", [id, changes], callback); }; chrome.bookmarks.update.params = [ @@ -529,21 +506,21 @@ var chrome = chrome || {}; // Sends (id, {title, url, parentId, index, dateAdded, dateGroupModified}) // date values are milliseconds since the UTC epoch. - chrome.bookmarks.onAdded = new chrome.Event("bookmark-added"); + chrome.bookmarks.onAdded = new chrome.Event("bookmarks.onAdded"); // Sends (id, {parentId, index}) - chrome.bookmarks.onRemoved = new chrome.Event("bookmark-removed"); + chrome.bookmarks.onRemoved = new chrome.Event("bookmarks.onRemoved"); // Sends (id, object) where object has list of properties that have changed. // Currently, this only ever includes 'title'. - chrome.bookmarks.onChanged = new chrome.Event("bookmark-changed"); + chrome.bookmarks.onChanged = new chrome.Event("bookmarks.onChanged"); // Sends (id, {parentId, index, oldParentId, oldIndex}) - chrome.bookmarks.onMoved = new chrome.Event("bookmark-moved"); + chrome.bookmarks.onMoved = new chrome.Event("bookmarks.onMoved"); // Sends (id, [childrenIds]) chrome.bookmarks.onChildrenReordered = - new chrome.Event("bookmark-children-reordered"); + new chrome.Event("bookmarks.onChildrenReordered"); //---------------------------------------------------------------------------- |