Chromium Code Reviews| Index: chrome/browser/automation/testing_automation_provider.cc |
| diff --git a/chrome/browser/automation/testing_automation_provider.cc b/chrome/browser/automation/testing_automation_provider.cc |
| index 696baa0982c6bcfc6e8591ba9afe6a306082ce5e..acd15bc2ebf1567463c8ace53cfa97272e38f299 100644 |
| --- a/chrome/browser/automation/testing_automation_provider.cc |
| +++ b/chrome/browser/automation/testing_automation_provider.cc |
| @@ -53,6 +53,7 @@ |
| #include "chrome/browser/extensions/extension_host.h" |
| #include "chrome/browser/extensions/extension_process_manager.h" |
| #include "chrome/browser/extensions/extension_service.h" |
| +#include "chrome/browser/extensions/extension_tab_util.h" |
| #include "chrome/browser/extensions/extension_updater.h" |
| #include "chrome/browser/history/top_sites.h" |
| #include "chrome/browser/importer/importer_host.h" |
| @@ -2478,9 +2479,10 @@ void TestingAutomationProvider::SendJSONRequest(int handle, |
| &TestingAutomationProvider::GetExtensionsInfo; |
| browser_handler_map["UninstallExtensionById"] = |
| &TestingAutomationProvider::UninstallExtensionById; |
| - |
| browser_handler_map["SetExtensionStateById"] = |
| &TestingAutomationProvider::SetExtensionStateById; |
| + browser_handler_map["TriggerExtensionActionById"] = |
| + &TestingAutomationProvider::TriggerExtensionActionById; |
| browser_handler_map["FindInPage"] = &TestingAutomationProvider::FindInPage; |
| @@ -4456,6 +4458,54 @@ void TestingAutomationProvider::SetExtensionStateById( |
| reply.SendSuccess(NULL); |
| } |
| +// See TriggerExtensionActionById() in chrome/test/pyautolib/pyauto.py |
| +// for sample json input. |
| +void TestingAutomationProvider::TriggerExtensionActionById( |
| + Browser* browser, |
| + DictionaryValue* args, |
| + IPC::Message* reply_message) { |
| + AutomationJSONReply reply(this, reply_message); |
| + |
| + std::string id; |
| + if (!args->GetString("id", &id)) { |
| + reply.SendError("Missing or invalid key: id"); |
| + return; |
| + } |
| + |
| + ExtensionService* service = browser->profile()->GetExtensionService(); |
| + if (!service) { |
| + reply.SendError("No extensions service."); |
| + return; |
| + } |
| + |
| + if (!service->GetInstalledExtension(id)) { |
| + // The extension ID does not correspond to any extension, whether crashed |
| + // or not. |
| + reply.SendError(base::StringPrintf("Extension does not exist: %s.", |
| + id.c_str())); |
| + return; |
| + } |
| + |
| + const Extension* extension = service->GetExtensionById(id, false); |
| + if (!extension) { |
| + reply.SendError("Extension is disabled or has crashed."); |
| + return; |
| + } |
| + |
| + if (extension->page_action()) { |
| + int tab_id = ExtensionTabUtil::GetTabId(browser->GetSelectedTabContents()); |
|
dennis_jeffrey
2011/11/17 00:11:32
The hook assumes that the page action should be tr
frankf
2011/11/17 00:25:03
It is mentioned in pyauto.py :)
dennis_jeffrey
2011/11/17 00:53:17
Oops, you're right - I missed it.
|
| + service->browser_event_router()->PageActionExecuted( |
| + browser->profile(), id, "action", tab_id, "", 1); |
|
dennis_jeffrey
2011/11/17 00:11:32
Is there anyone you know who is an expert on the e
frankf
2011/11/17 00:25:03
Done.
|
| + reply.SendSuccess(NULL); |
| + } else if (extension->browser_action()) { |
| + service->browser_event_router()->BrowserActionExecuted( |
| + browser->profile(), id, browser); |
| + reply.SendSuccess(NULL); |
| + } else { |
| + reply.SendError("Extension doesn't have any page/browser action."); |
| + } |
| +} |
| + |
| // Sample json input: |
| // { "command": "GetAutofillProfile" } |
| // Refer to GetAutofillProfile() in chrome/test/pyautolib/pyauto.py for sample |