OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 #include "chrome/browser/download/download_service_factory.h" | 48 #include "chrome/browser/download/download_service_factory.h" |
49 #include "chrome/browser/download/download_shelf.h" | 49 #include "chrome/browser/download/download_shelf.h" |
50 #include "chrome/browser/download/save_package_file_picker.h" | 50 #include "chrome/browser/download/save_package_file_picker.h" |
51 #include "chrome/browser/extensions/browser_action_test_util.h" | 51 #include "chrome/browser/extensions/browser_action_test_util.h" |
52 #include "chrome/browser/extensions/crx_installer.h" | 52 #include "chrome/browser/extensions/crx_installer.h" |
53 #include "chrome/browser/extensions/extension_action.h" | 53 #include "chrome/browser/extensions/extension_action.h" |
54 #include "chrome/browser/extensions/extension_action_manager.h" | 54 #include "chrome/browser/extensions/extension_action_manager.h" |
55 #include "chrome/browser/extensions/extension_host.h" | 55 #include "chrome/browser/extensions/extension_host.h" |
56 #include "chrome/browser/extensions/extension_process_manager.h" | 56 #include "chrome/browser/extensions/extension_process_manager.h" |
57 #include "chrome/browser/extensions/extension_service.h" | 57 #include "chrome/browser/extensions/extension_service.h" |
| 58 #include "chrome/browser/extensions/extension_system.h" |
58 #include "chrome/browser/extensions/extension_tab_util.h" | 59 #include "chrome/browser/extensions/extension_tab_util.h" |
59 #include "chrome/browser/extensions/unpacked_installer.h" | 60 #include "chrome/browser/extensions/unpacked_installer.h" |
60 #include "chrome/browser/extensions/updater/extension_updater.h" | 61 #include "chrome/browser/extensions/updater/extension_updater.h" |
61 #include "chrome/browser/history/history_service_factory.h" | 62 #include "chrome/browser/history/history_service_factory.h" |
62 #include "chrome/browser/history/top_sites.h" | 63 #include "chrome/browser/history/top_sites.h" |
63 #include "chrome/browser/importer/importer_host.h" | 64 #include "chrome/browser/importer/importer_host.h" |
64 #include "chrome/browser/importer/importer_list.h" | 65 #include "chrome/browser/importer/importer_list.h" |
65 #include "chrome/browser/infobars/infobar_tab_helper.h" | 66 #include "chrome/browser/infobars/infobar_tab_helper.h" |
66 #include "chrome/browser/instant/instant_controller.h" | 67 #include "chrome/browser/instant/instant_controller.h" |
67 #include "chrome/browser/lifetime/application_lifetime.h" | 68 #include "chrome/browser/lifetime/application_lifetime.h" |
(...skipping 2356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2424 int flags = ChildProcessHost::CHILD_NORMAL; | 2425 int flags = ChildProcessHost::CHILD_NORMAL; |
2425 #endif | 2426 #endif |
2426 | 2427 |
2427 // Add all extension processes in a list of dictionaries, one dictionary | 2428 // Add all extension processes in a list of dictionaries, one dictionary |
2428 // item per extension process. | 2429 // item per extension process. |
2429 ListValue* extension_views = new ListValue; | 2430 ListValue* extension_views = new ListValue; |
2430 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 2431 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
2431 std::vector<Profile*> profiles(profile_manager->GetLoadedProfiles()); | 2432 std::vector<Profile*> profiles(profile_manager->GetLoadedProfiles()); |
2432 for (size_t i = 0; i < profiles.size(); ++i) { | 2433 for (size_t i = 0; i < profiles.size(); ++i) { |
2433 ExtensionProcessManager* process_manager = | 2434 ExtensionProcessManager* process_manager = |
2434 profiles[i]->GetExtensionProcessManager(); | 2435 extensions::ExtensionSystem::Get(profiles[i])->process_manager(); |
2435 if (!process_manager) | 2436 if (!process_manager) |
2436 continue; | 2437 continue; |
2437 const ExtensionProcessManager::ViewSet view_set = | 2438 const ExtensionProcessManager::ViewSet view_set = |
2438 process_manager->GetAllViews(); | 2439 process_manager->GetAllViews(); |
2439 for (ExtensionProcessManager::ViewSet::const_iterator jt = | 2440 for (ExtensionProcessManager::ViewSet::const_iterator jt = |
2440 view_set.begin(); | 2441 view_set.begin(); |
2441 jt != view_set.end(); ++jt) { | 2442 jt != view_set.end(); ++jt) { |
2442 content::RenderViewHost* render_view_host = *jt; | 2443 content::RenderViewHost* render_view_host = *jt; |
2443 // Don't add dead extension processes. | 2444 // Don't add dead extension processes. |
2444 if (!render_view_host->IsRenderViewLive()) | 2445 if (!render_view_host->IsRenderViewLive()) |
(...skipping 1243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3688 } | 3689 } |
3689 if (!args->GetBoolean("with_ui", &with_ui)) { | 3690 if (!args->GetBoolean("with_ui", &with_ui)) { |
3690 AutomationJSONReply(this, reply_message).SendError( | 3691 AutomationJSONReply(this, reply_message).SendError( |
3691 "Missing or invalid 'with_ui'"); | 3692 "Missing or invalid 'with_ui'"); |
3692 return; | 3693 return; |
3693 } | 3694 } |
3694 args->GetBoolean("from_webstore", &from_webstore); | 3695 args->GetBoolean("from_webstore", &from_webstore); |
3695 | 3696 |
3696 ExtensionService* service = browser->profile()->GetExtensionService(); | 3697 ExtensionService* service = browser->profile()->GetExtensionService(); |
3697 ExtensionProcessManager* manager = | 3698 ExtensionProcessManager* manager = |
3698 browser->profile()->GetExtensionProcessManager(); | 3699 extensions::ExtensionSystem::Get(browser->profile())->process_manager(); |
3699 if (service && manager) { | 3700 if (service && manager) { |
3700 // The observer will delete itself when done. | 3701 // The observer will delete itself when done. |
3701 new ExtensionReadyNotificationObserver( | 3702 new ExtensionReadyNotificationObserver( |
3702 manager, | 3703 manager, |
3703 service, | 3704 service, |
3704 this, | 3705 this, |
3705 reply_message); | 3706 reply_message); |
3706 | 3707 |
3707 FilePath extension_path(path_string); | 3708 FilePath extension_path(path_string); |
3708 // If the given path has a 'crx' extension, assume it is a packed extension | 3709 // If the given path has a 'crx' extension, assume it is a packed extension |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3896 | 3897 |
3897 if (allow_in_incognito && !enable) { | 3898 if (allow_in_incognito && !enable) { |
3898 AutomationJSONReply(this, reply_message) | 3899 AutomationJSONReply(this, reply_message) |
3899 .SendError("Invalid state: Disabled extension " | 3900 .SendError("Invalid state: Disabled extension " |
3900 "cannot be allowed in incognito mode."); | 3901 "cannot be allowed in incognito mode."); |
3901 return; | 3902 return; |
3902 } | 3903 } |
3903 | 3904 |
3904 ExtensionService* service = browser->profile()->GetExtensionService(); | 3905 ExtensionService* service = browser->profile()->GetExtensionService(); |
3905 ExtensionProcessManager* manager = | 3906 ExtensionProcessManager* manager = |
3906 browser->profile()->GetExtensionProcessManager(); | 3907 extensions::ExtensionSystem::Get(browser->profile())->process_manager(); |
3907 if (!service) { | 3908 if (!service) { |
3908 AutomationJSONReply(this, reply_message) | 3909 AutomationJSONReply(this, reply_message) |
3909 .SendError("No extensions service or process manager."); | 3910 .SendError("No extensions service or process manager."); |
3910 return; | 3911 return; |
3911 } | 3912 } |
3912 | 3913 |
3913 if (enable) { | 3914 if (enable) { |
3914 if (!service->IsExtensionEnabled(extension->id())) { | 3915 if (!service->IsExtensionEnabled(extension->id())) { |
3915 new ExtensionReadyNotificationObserver( | 3916 new ExtensionReadyNotificationObserver( |
3916 manager, | 3917 manager, |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4125 } | 4126 } |
4126 | 4127 |
4127 extensions::ExtensionUpdater* updater = service->updater(); | 4128 extensions::ExtensionUpdater* updater = service->updater(); |
4128 if (!updater) { | 4129 if (!updater) { |
4129 AutomationJSONReply(this, reply_message).SendError( | 4130 AutomationJSONReply(this, reply_message).SendError( |
4130 "No updater for extensions service."); | 4131 "No updater for extensions service."); |
4131 return; | 4132 return; |
4132 } | 4133 } |
4133 | 4134 |
4134 ExtensionProcessManager* manager = | 4135 ExtensionProcessManager* manager = |
4135 browser->profile()->GetExtensionProcessManager(); | 4136 extensions::ExtensionSystem::Get(browser->profile())->process_manager(); |
4136 if (!manager) { | 4137 if (!manager) { |
4137 AutomationJSONReply(this, reply_message).SendError( | 4138 AutomationJSONReply(this, reply_message).SendError( |
4138 "No extension process manager."); | 4139 "No extension process manager."); |
4139 return; | 4140 return; |
4140 } | 4141 } |
4141 | 4142 |
4142 // Create a new observer that waits until the extensions have been fully | 4143 // Create a new observer that waits until the extensions have been fully |
4143 // updated (we should not send the reply until after all extensions have | 4144 // updated (we should not send the reply until after all extensions have |
4144 // been updated). This observer will delete itself. | 4145 // been updated). This observer will delete itself. |
4145 new ExtensionsUpdatedObserver(manager, this, reply_message); | 4146 new ExtensionsUpdatedObserver(manager, this, reply_message); |
(...skipping 1123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5269 void TestingAutomationProvider::WaitForAllViewsToStopLoading( | 5270 void TestingAutomationProvider::WaitForAllViewsToStopLoading( |
5270 DictionaryValue* args, | 5271 DictionaryValue* args, |
5271 IPC::Message* reply_message) { | 5272 IPC::Message* reply_message) { |
5272 if (AppModalDialogQueue::GetInstance()->HasActiveDialog()) { | 5273 if (AppModalDialogQueue::GetInstance()->HasActiveDialog()) { |
5273 AutomationJSONReply(this, reply_message).SendSuccess(NULL); | 5274 AutomationJSONReply(this, reply_message).SendSuccess(NULL); |
5274 return; | 5275 return; |
5275 } | 5276 } |
5276 | 5277 |
5277 // This class will send the message immediately if no tab is loading. | 5278 // This class will send the message immediately if no tab is loading. |
5278 new AllViewsStoppedLoadingObserver( | 5279 new AllViewsStoppedLoadingObserver( |
5279 this, reply_message, profile()->GetExtensionProcessManager()); | 5280 this, reply_message, |
| 5281 extensions::ExtensionSystem::Get(profile())->process_manager()); |
5280 } | 5282 } |
5281 | 5283 |
5282 void TestingAutomationProvider::WaitForTabToBeRestored( | 5284 void TestingAutomationProvider::WaitForTabToBeRestored( |
5283 DictionaryValue* args, | 5285 DictionaryValue* args, |
5284 IPC::Message* reply_message) { | 5286 IPC::Message* reply_message) { |
5285 WebContents* web_contents; | 5287 WebContents* web_contents; |
5286 std::string error; | 5288 std::string error; |
5287 if (!GetTabFromJSONArgs(args, &web_contents, &error)) { | 5289 if (!GetTabFromJSONArgs(args, &web_contents, &error)) { |
5288 AutomationJSONReply(this, reply_message).SendError(error); | 5290 AutomationJSONReply(this, reply_message).SendError(error); |
5289 return; | 5291 return; |
(...skipping 754 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6044 DictionaryValue* dict = new DictionaryValue(); | 6046 DictionaryValue* dict = new DictionaryValue(); |
6045 AutomationId id = automation_util::GetIdForTab(preview_tab); | 6047 AutomationId id = automation_util::GetIdForTab(preview_tab); |
6046 dict->Set("auto_id", id.ToValue()); | 6048 dict->Set("auto_id", id.ToValue()); |
6047 view_list->Append(dict); | 6049 view_list->Append(dict); |
6048 } | 6050 } |
6049 } | 6051 } |
6050 } | 6052 } |
6051 } | 6053 } |
6052 | 6054 |
6053 ExtensionProcessManager* extension_mgr = | 6055 ExtensionProcessManager* extension_mgr = |
6054 profile()->GetExtensionProcessManager(); | 6056 extensions::ExtensionSystem::Get(profile())->process_manager(); |
6055 const ExtensionProcessManager::ViewSet all_views = | 6057 const ExtensionProcessManager::ViewSet all_views = |
6056 extension_mgr->GetAllViews(); | 6058 extension_mgr->GetAllViews(); |
6057 ExtensionProcessManager::ViewSet::const_iterator iter; | 6059 ExtensionProcessManager::ViewSet::const_iterator iter; |
6058 for (iter = all_views.begin(); iter != all_views.end(); ++iter) { | 6060 for (iter = all_views.begin(); iter != all_views.end(); ++iter) { |
6059 content::RenderViewHost* host = (*iter); | 6061 content::RenderViewHost* host = (*iter); |
6060 AutomationId id = automation_util::GetIdForExtensionView(host); | 6062 AutomationId id = automation_util::GetIdForExtensionView(host); |
6061 if (!id.is_valid()) | 6063 if (!id.is_valid()) |
6062 continue; | 6064 continue; |
6063 const Extension* extension = | 6065 const Extension* extension = |
6064 extension_mgr->GetExtensionForRenderViewHost(host); | 6066 extension_mgr->GetExtensionForRenderViewHost(host); |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6341 void TestingAutomationProvider::OnRemoveProvider() { | 6343 void TestingAutomationProvider::OnRemoveProvider() { |
6342 if (g_browser_process) | 6344 if (g_browser_process) |
6343 g_browser_process->GetAutomationProviderList()->RemoveProvider(this); | 6345 g_browser_process->GetAutomationProviderList()->RemoveProvider(this); |
6344 } | 6346 } |
6345 | 6347 |
6346 void TestingAutomationProvider::EnsureTabSelected(Browser* browser, | 6348 void TestingAutomationProvider::EnsureTabSelected(Browser* browser, |
6347 WebContents* tab) { | 6349 WebContents* tab) { |
6348 if (chrome::GetActiveWebContents(browser) != tab) | 6350 if (chrome::GetActiveWebContents(browser) != tab) |
6349 chrome::ActivateTabAt(browser, chrome::GetIndexOfTab(browser, tab), true); | 6351 chrome::ActivateTabAt(browser, chrome::GetIndexOfTab(browser, tab), true); |
6350 } | 6352 } |
OLD | NEW |