Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/automation/testing_automation_provider.h" | 5 #include "chrome/browser/automation/testing_automation_provider.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 46 #include "chrome/browser/content_settings/host_content_settings_map.h" | 46 #include "chrome/browser/content_settings/host_content_settings_map.h" |
| 47 #include "chrome/browser/debugger/devtools_window.h" | 47 #include "chrome/browser/debugger/devtools_window.h" |
| 48 #include "chrome/browser/download/download_prefs.h" | 48 #include "chrome/browser/download/download_prefs.h" |
| 49 #include "chrome/browser/download/download_service.h" | 49 #include "chrome/browser/download/download_service.h" |
| 50 #include "chrome/browser/download/download_service_factory.h" | 50 #include "chrome/browser/download/download_service_factory.h" |
| 51 #include "chrome/browser/download/save_package_file_picker.h" | 51 #include "chrome/browser/download/save_package_file_picker.h" |
| 52 #include "chrome/browser/extensions/extension_browser_event_router.h" | 52 #include "chrome/browser/extensions/extension_browser_event_router.h" |
| 53 #include "chrome/browser/extensions/extension_host.h" | 53 #include "chrome/browser/extensions/extension_host.h" |
| 54 #include "chrome/browser/extensions/extension_process_manager.h" | 54 #include "chrome/browser/extensions/extension_process_manager.h" |
| 55 #include "chrome/browser/extensions/extension_service.h" | 55 #include "chrome/browser/extensions/extension_service.h" |
| 56 #include "chrome/browser/extensions/extension_tab_util.h" | |
| 56 #include "chrome/browser/extensions/extension_updater.h" | 57 #include "chrome/browser/extensions/extension_updater.h" |
| 57 #include "chrome/browser/history/top_sites.h" | 58 #include "chrome/browser/history/top_sites.h" |
| 58 #include "chrome/browser/importer/importer_host.h" | 59 #include "chrome/browser/importer/importer_host.h" |
| 59 #include "chrome/browser/importer/importer_list.h" | 60 #include "chrome/browser/importer/importer_list.h" |
| 60 #include "chrome/browser/infobars/infobar_tab_helper.h" | 61 #include "chrome/browser/infobars/infobar_tab_helper.h" |
| 61 #include "chrome/browser/instant/instant_controller.h" | 62 #include "chrome/browser/instant/instant_controller.h" |
| 62 #include "chrome/browser/notifications/balloon.h" | 63 #include "chrome/browser/notifications/balloon.h" |
| 63 #include "chrome/browser/notifications/balloon_collection.h" | 64 #include "chrome/browser/notifications/balloon_collection.h" |
| 64 #include "chrome/browser/notifications/notification.h" | 65 #include "chrome/browser/notifications/notification.h" |
| 65 #include "chrome/browser/notifications/notification_ui_manager.h" | 66 #include "chrome/browser/notifications/notification_ui_manager.h" |
| (...skipping 2405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2471 | 2472 |
| 2472 // SetTheme() implemented using InstallExtension(). | 2473 // SetTheme() implemented using InstallExtension(). |
| 2473 browser_handler_map["GetThemeInfo"] = | 2474 browser_handler_map["GetThemeInfo"] = |
| 2474 &TestingAutomationProvider::GetThemeInfo; | 2475 &TestingAutomationProvider::GetThemeInfo; |
| 2475 | 2476 |
| 2476 // InstallExtension() present in pyauto.py. | 2477 // InstallExtension() present in pyauto.py. |
| 2477 browser_handler_map["GetExtensionsInfo"] = | 2478 browser_handler_map["GetExtensionsInfo"] = |
| 2478 &TestingAutomationProvider::GetExtensionsInfo; | 2479 &TestingAutomationProvider::GetExtensionsInfo; |
| 2479 browser_handler_map["UninstallExtensionById"] = | 2480 browser_handler_map["UninstallExtensionById"] = |
| 2480 &TestingAutomationProvider::UninstallExtensionById; | 2481 &TestingAutomationProvider::UninstallExtensionById; |
| 2481 | |
| 2482 browser_handler_map["SetExtensionStateById"] = | 2482 browser_handler_map["SetExtensionStateById"] = |
| 2483 &TestingAutomationProvider::SetExtensionStateById; | 2483 &TestingAutomationProvider::SetExtensionStateById; |
| 2484 browser_handler_map["TriggerExtensionActionById"] = | |
| 2485 &TestingAutomationProvider::TriggerExtensionActionById; | |
| 2484 | 2486 |
| 2485 browser_handler_map["FindInPage"] = &TestingAutomationProvider::FindInPage; | 2487 browser_handler_map["FindInPage"] = &TestingAutomationProvider::FindInPage; |
| 2486 | 2488 |
| 2487 browser_handler_map["SelectTranslateOption"] = | 2489 browser_handler_map["SelectTranslateOption"] = |
| 2488 &TestingAutomationProvider::SelectTranslateOption; | 2490 &TestingAutomationProvider::SelectTranslateOption; |
| 2489 browser_handler_map["GetTranslateInfo"] = | 2491 browser_handler_map["GetTranslateInfo"] = |
| 2490 &TestingAutomationProvider::GetTranslateInfo; | 2492 &TestingAutomationProvider::GetTranslateInfo; |
| 2491 | 2493 |
| 2492 browser_handler_map["GetAutofillProfile"] = | 2494 browser_handler_map["GetAutofillProfile"] = |
| 2493 &TestingAutomationProvider::GetAutofillProfile; | 2495 &TestingAutomationProvider::GetAutofillProfile; |
| (...skipping 1955 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4449 | 4451 |
| 4450 if (enable) | 4452 if (enable) |
| 4451 service->EnableExtension(id); | 4453 service->EnableExtension(id); |
| 4452 else | 4454 else |
| 4453 service->DisableExtension(id); | 4455 service->DisableExtension(id); |
| 4454 | 4456 |
| 4455 service->SetIsIncognitoEnabled(id, allow_in_incognito); | 4457 service->SetIsIncognitoEnabled(id, allow_in_incognito); |
| 4456 reply.SendSuccess(NULL); | 4458 reply.SendSuccess(NULL); |
| 4457 } | 4459 } |
| 4458 | 4460 |
| 4461 // See TriggerExtensionActionById() in chrome/test/pyautolib/pyauto.py | |
| 4462 // for sample json input. | |
| 4463 void TestingAutomationProvider::TriggerExtensionActionById( | |
| 4464 Browser* browser, | |
|
kkania
2011/11/17 17:49:09
could you use the new non-browser style for this a
frankf
2011/11/21 02:01:46
Done.
| |
| 4465 DictionaryValue* args, | |
| 4466 IPC::Message* reply_message) { | |
| 4467 AutomationJSONReply reply(this, reply_message); | |
| 4468 | |
| 4469 std::string id; | |
| 4470 if (!args->GetString("id", &id)) { | |
| 4471 reply.SendError("Missing or invalid key: id"); | |
| 4472 return; | |
| 4473 } | |
| 4474 | |
| 4475 ExtensionService* service = browser->profile()->GetExtensionService(); | |
| 4476 if (!service) { | |
| 4477 reply.SendError("No extensions service."); | |
| 4478 return; | |
| 4479 } | |
| 4480 | |
| 4481 if (!service->GetInstalledExtension(id)) { | |
| 4482 // The extension ID does not correspond to any extension, whether crashed | |
| 4483 // or not. | |
| 4484 reply.SendError(base::StringPrintf("Extension does not exist: %s.", | |
| 4485 id.c_str())); | |
| 4486 return; | |
| 4487 } | |
| 4488 | |
| 4489 const Extension* extension = service->GetExtensionById(id, false); | |
| 4490 if (!extension) { | |
| 4491 reply.SendError("Extension is disabled or has crashed."); | |
| 4492 return; | |
| 4493 } | |
| 4494 | |
| 4495 if (extension->page_action()) { | |
| 4496 int tab_id = ExtensionTabUtil::GetTabId(browser->GetSelectedTabContents()); | |
| 4497 service->browser_event_router()->PageActionExecuted( | |
|
kkania
2011/11/17 17:49:09
I think you should throw an error if the page acti
frankf
2011/11/21 02:01:46
Done.
| |
| 4498 browser->profile(), id, "action", tab_id, "", 1); | |
| 4499 reply.SendSuccess(NULL); | |
| 4500 } else if (extension->browser_action()) { | |
| 4501 service->browser_event_router()->BrowserActionExecuted( | |
|
kkania
2011/11/17 17:49:09
this doesn't work for popups
frankf
2011/11/21 02:01:46
Done.
| |
| 4502 browser->profile(), id, browser); | |
| 4503 reply.SendSuccess(NULL); | |
| 4504 } else { | |
| 4505 reply.SendError("Extension doesn't have any page/browser action."); | |
| 4506 } | |
| 4507 } | |
| 4508 | |
| 4459 // Sample json input: | 4509 // Sample json input: |
| 4460 // { "command": "GetAutofillProfile" } | 4510 // { "command": "GetAutofillProfile" } |
| 4461 // Refer to GetAutofillProfile() in chrome/test/pyautolib/pyauto.py for sample | 4511 // Refer to GetAutofillProfile() in chrome/test/pyautolib/pyauto.py for sample |
| 4462 // json output. | 4512 // json output. |
| 4463 void TestingAutomationProvider::GetAutofillProfile( | 4513 void TestingAutomationProvider::GetAutofillProfile( |
| 4464 Browser* browser, | 4514 Browser* browser, |
| 4465 DictionaryValue* args, | 4515 DictionaryValue* args, |
| 4466 IPC::Message* reply_message) { | 4516 IPC::Message* reply_message) { |
| 4467 AutomationJSONReply reply(this, reply_message); | 4517 AutomationJSONReply reply(this, reply_message); |
| 4468 // Get the AutofillProfiles currently in the database. | 4518 // Get the AutofillProfiles currently in the database. |
| (...skipping 1915 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6384 | 6434 |
| 6385 Send(reply_message_); | 6435 Send(reply_message_); |
| 6386 redirect_query_ = 0; | 6436 redirect_query_ = 0; |
| 6387 reply_message_ = NULL; | 6437 reply_message_ = NULL; |
| 6388 } | 6438 } |
| 6389 | 6439 |
| 6390 void TestingAutomationProvider::OnRemoveProvider() { | 6440 void TestingAutomationProvider::OnRemoveProvider() { |
| 6391 if (g_browser_process) | 6441 if (g_browser_process) |
| 6392 g_browser_process->GetAutomationProviderList()->RemoveProvider(this); | 6442 g_browser_process->GetAutomationProviderList()->RemoveProvider(this); |
| 6393 } | 6443 } |
| OLD | NEW |