| 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 #include "chrome/browser/bookmarks/bookmark_model.h" | 42 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 43 #include "chrome/browser/bookmarks/bookmark_storage.h" | 43 #include "chrome/browser/bookmarks/bookmark_storage.h" |
| 44 #include "chrome/browser/browser_process.h" | 44 #include "chrome/browser/browser_process.h" |
| 45 #include "chrome/browser/browser_shutdown.h" | 45 #include "chrome/browser/browser_shutdown.h" |
| 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/crx_installer.h" |
| 52 #include "chrome/browser/extensions/extension_browser_event_router.h" | 53 #include "chrome/browser/extensions/extension_browser_event_router.h" |
| 53 #include "chrome/browser/extensions/extension_host.h" | 54 #include "chrome/browser/extensions/extension_host.h" |
| 54 #include "chrome/browser/extensions/extension_process_manager.h" | 55 #include "chrome/browser/extensions/extension_process_manager.h" |
| 55 #include "chrome/browser/extensions/extension_service.h" | 56 #include "chrome/browser/extensions/extension_service.h" |
| 56 #include "chrome/browser/extensions/extension_updater.h" | 57 #include "chrome/browser/extensions/extension_updater.h" |
| 58 #include "chrome/browser/extensions/unpacked_installer.h" |
| 57 #include "chrome/browser/history/top_sites.h" | 59 #include "chrome/browser/history/top_sites.h" |
| 58 #include "chrome/browser/importer/importer_host.h" | 60 #include "chrome/browser/importer/importer_host.h" |
| 59 #include "chrome/browser/importer/importer_list.h" | 61 #include "chrome/browser/importer/importer_list.h" |
| 60 #include "chrome/browser/infobars/infobar_tab_helper.h" | 62 #include "chrome/browser/infobars/infobar_tab_helper.h" |
| 61 #include "chrome/browser/instant/instant_controller.h" | 63 #include "chrome/browser/instant/instant_controller.h" |
| 62 #include "chrome/browser/notifications/balloon.h" | 64 #include "chrome/browser/notifications/balloon.h" |
| 63 #include "chrome/browser/notifications/balloon_collection.h" | 65 #include "chrome/browser/notifications/balloon_collection.h" |
| 64 #include "chrome/browser/notifications/notification.h" | 66 #include "chrome/browser/notifications/notification.h" |
| 65 #include "chrome/browser/notifications/notification_ui_manager.h" | 67 #include "chrome/browser/notifications/notification_ui_manager.h" |
| 66 #include "chrome/browser/password_manager/password_store.h" | 68 #include "chrome/browser/password_manager/password_store.h" |
| (...skipping 2259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2326 handler_map["OpenNewBrowserWindowWithNewProfile"] = | 2328 handler_map["OpenNewBrowserWindowWithNewProfile"] = |
| 2327 &TestingAutomationProvider::OpenNewBrowserWindowWithNewProfile; | 2329 &TestingAutomationProvider::OpenNewBrowserWindowWithNewProfile; |
| 2328 handler_map["GetMultiProfileInfo"] = | 2330 handler_map["GetMultiProfileInfo"] = |
| 2329 &TestingAutomationProvider::GetMultiProfileInfo; | 2331 &TestingAutomationProvider::GetMultiProfileInfo; |
| 2330 handler_map["GetProcessInfo"] = | 2332 handler_map["GetProcessInfo"] = |
| 2331 &TestingAutomationProvider::GetProcessInfo; | 2333 &TestingAutomationProvider::GetProcessInfo; |
| 2332 handler_map["SetPolicies"] = | 2334 handler_map["SetPolicies"] = |
| 2333 &TestingAutomationProvider::SetPolicies; | 2335 &TestingAutomationProvider::SetPolicies; |
| 2334 handler_map["GetPolicyDefinitionList"] = | 2336 handler_map["GetPolicyDefinitionList"] = |
| 2335 &TestingAutomationProvider::GetPolicyDefinitionList; | 2337 &TestingAutomationProvider::GetPolicyDefinitionList; |
| 2338 handler_map["InstallExtension"] = |
| 2339 &TestingAutomationProvider::InstallExtension; |
| 2340 handler_map["GetExtensionsInfo"] = |
| 2341 &TestingAutomationProvider::GetExtensionsInfo; |
| 2336 #if defined(OS_CHROMEOS) | 2342 #if defined(OS_CHROMEOS) |
| 2337 handler_map["GetLoginInfo"] = &TestingAutomationProvider::GetLoginInfo; | 2343 handler_map["GetLoginInfo"] = &TestingAutomationProvider::GetLoginInfo; |
| 2338 handler_map["ShowCreateAccountUI"] = | 2344 handler_map["ShowCreateAccountUI"] = |
| 2339 &TestingAutomationProvider::ShowCreateAccountUI; | 2345 &TestingAutomationProvider::ShowCreateAccountUI; |
| 2340 handler_map["LoginAsGuest"] = &TestingAutomationProvider::LoginAsGuest; | 2346 handler_map["LoginAsGuest"] = &TestingAutomationProvider::LoginAsGuest; |
| 2341 handler_map["Login"] = &TestingAutomationProvider::Login; | 2347 handler_map["Login"] = &TestingAutomationProvider::Login; |
| 2342 | 2348 |
| 2343 handler_map["LockScreen"] = &TestingAutomationProvider::LockScreen; | 2349 handler_map["LockScreen"] = &TestingAutomationProvider::LockScreen; |
| 2344 handler_map["UnlockScreen"] = &TestingAutomationProvider::UnlockScreen; | 2350 handler_map["UnlockScreen"] = &TestingAutomationProvider::UnlockScreen; |
| 2345 handler_map["SignoutInScreenLocker"] = | 2351 handler_map["SignoutInScreenLocker"] = |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2470 | 2476 |
| 2471 browser_handler_map["GetBlockedPopupsInfo"] = | 2477 browser_handler_map["GetBlockedPopupsInfo"] = |
| 2472 &TestingAutomationProvider::GetBlockedPopupsInfo; | 2478 &TestingAutomationProvider::GetBlockedPopupsInfo; |
| 2473 browser_handler_map["UnblockAndLaunchBlockedPopup"] = | 2479 browser_handler_map["UnblockAndLaunchBlockedPopup"] = |
| 2474 &TestingAutomationProvider::UnblockAndLaunchBlockedPopup; | 2480 &TestingAutomationProvider::UnblockAndLaunchBlockedPopup; |
| 2475 | 2481 |
| 2476 // SetTheme() implemented using InstallExtension(). | 2482 // SetTheme() implemented using InstallExtension(). |
| 2477 browser_handler_map["GetThemeInfo"] = | 2483 browser_handler_map["GetThemeInfo"] = |
| 2478 &TestingAutomationProvider::GetThemeInfo; | 2484 &TestingAutomationProvider::GetThemeInfo; |
| 2479 | 2485 |
| 2480 // InstallExtension() present in pyauto.py. | |
| 2481 browser_handler_map["GetExtensionsInfo"] = | |
| 2482 &TestingAutomationProvider::GetExtensionsInfo; | |
| 2483 browser_handler_map["UninstallExtensionById"] = | 2486 browser_handler_map["UninstallExtensionById"] = |
| 2484 &TestingAutomationProvider::UninstallExtensionById; | 2487 &TestingAutomationProvider::UninstallExtensionById; |
| 2485 | 2488 |
| 2486 browser_handler_map["SetExtensionStateById"] = | 2489 browser_handler_map["SetExtensionStateById"] = |
| 2487 &TestingAutomationProvider::SetExtensionStateById; | 2490 &TestingAutomationProvider::SetExtensionStateById; |
| 2488 | 2491 |
| 2489 browser_handler_map["FindInPage"] = &TestingAutomationProvider::FindInPage; | 2492 browser_handler_map["FindInPage"] = &TestingAutomationProvider::FindInPage; |
| 2490 | 2493 |
| 2491 browser_handler_map["SelectTranslateOption"] = | 2494 browser_handler_map["SelectTranslateOption"] = |
| 2492 &TestingAutomationProvider::SelectTranslateOption; | 2495 &TestingAutomationProvider::SelectTranslateOption; |
| (...skipping 1785 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4278 const Extension* theme = ThemeServiceFactory::GetThemeForProfile(profile()); | 4281 const Extension* theme = ThemeServiceFactory::GetThemeForProfile(profile()); |
| 4279 if (theme) { | 4282 if (theme) { |
| 4280 return_value->SetString("name", theme->name()); | 4283 return_value->SetString("name", theme->name()); |
| 4281 return_value->Set("images", theme->GetThemeImages()->DeepCopy()); | 4284 return_value->Set("images", theme->GetThemeImages()->DeepCopy()); |
| 4282 return_value->Set("colors", theme->GetThemeColors()->DeepCopy()); | 4285 return_value->Set("colors", theme->GetThemeColors()->DeepCopy()); |
| 4283 return_value->Set("tints", theme->GetThemeTints()->DeepCopy()); | 4286 return_value->Set("tints", theme->GetThemeTints()->DeepCopy()); |
| 4284 } | 4287 } |
| 4285 AutomationJSONReply(this, reply_message).SendSuccess(return_value.get()); | 4288 AutomationJSONReply(this, reply_message).SendSuccess(return_value.get()); |
| 4286 } | 4289 } |
| 4287 | 4290 |
| 4291 void TestingAutomationProvider::InstallExtension( |
| 4292 DictionaryValue* args, IPC::Message* reply_message) { |
| 4293 FilePath::StringType path_string; |
| 4294 if (!args->GetString("path", &path_string)) { |
| 4295 AutomationJSONReply(this, reply_message).SendError( |
| 4296 "Missing or invalid 'path'"); |
| 4297 return; |
| 4298 } |
| 4299 ExtensionService* service = profile()->GetExtensionService(); |
| 4300 ExtensionProcessManager* manager = profile()->GetExtensionProcessManager(); |
| 4301 if (service && manager) { |
| 4302 // The observer will delete itself when done. |
| 4303 new ExtensionReadyNotificationObserver( |
| 4304 manager, |
| 4305 service, |
| 4306 this, |
| 4307 reply_message); |
| 4308 |
| 4309 FilePath extension_path(path_string); |
| 4310 // If the given path has a 'crx' extension, assume it is a packed extension |
| 4311 // and install it. Otherwise load it as an unpacked extension. |
| 4312 if (extension_path.MatchesExtension(FILE_PATH_LITERAL(".crx"))) { |
| 4313 scoped_refptr<CrxInstaller> installer( |
| 4314 CrxInstaller::Create(service, NULL)); |
| 4315 installer->set_allow_silent_install(true); |
| 4316 installer->set_install_cause(extension_misc::INSTALL_CAUSE_AUTOMATION); |
| 4317 installer->InstallCrx(extension_path); |
| 4318 } else { |
| 4319 scoped_refptr<extensions::UnpackedInstaller> installer( |
| 4320 extensions::UnpackedInstaller::Create(service)); |
| 4321 installer->set_prompt_for_plugins(false); |
| 4322 installer->Load(extension_path); |
| 4323 } |
| 4324 } else { |
| 4325 AutomationJSONReply(this, reply_message).SendError( |
| 4326 "Extensions service/process manager is not available"); |
| 4327 } |
| 4328 } |
| 4329 |
| 4288 namespace { | 4330 namespace { |
| 4289 | 4331 |
| 4290 ListValue* GetHostPermissions(const Extension* ext, bool effective_perm) { | 4332 ListValue* GetHostPermissions(const Extension* ext, bool effective_perm) { |
| 4291 URLPatternSet pattern_set; | 4333 URLPatternSet pattern_set; |
| 4292 if (effective_perm) | 4334 if (effective_perm) |
| 4293 pattern_set = ext->GetEffectiveHostPermissions(); | 4335 pattern_set = ext->GetEffectiveHostPermissions(); |
| 4294 else | 4336 else |
| 4295 pattern_set = ext->GetActivePermissions()->explicit_hosts(); | 4337 pattern_set = ext->GetActivePermissions()->explicit_hosts(); |
| 4296 | 4338 |
| 4297 ListValue* permissions = new ListValue; | 4339 ListValue* permissions = new ListValue; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 4313 } | 4355 } |
| 4314 return permissions; | 4356 return permissions; |
| 4315 } | 4357 } |
| 4316 | 4358 |
| 4317 } // namespace | 4359 } // namespace |
| 4318 | 4360 |
| 4319 // Sample json input: { "command": "GetExtensionsInfo" } | 4361 // Sample json input: { "command": "GetExtensionsInfo" } |
| 4320 // See GetExtensionsInfo() in chrome/test/pyautolib/pyauto.py for sample json | 4362 // See GetExtensionsInfo() in chrome/test/pyautolib/pyauto.py for sample json |
| 4321 // output. | 4363 // output. |
| 4322 void TestingAutomationProvider::GetExtensionsInfo( | 4364 void TestingAutomationProvider::GetExtensionsInfo( |
| 4323 Browser* browser, | |
| 4324 DictionaryValue* args, | 4365 DictionaryValue* args, |
| 4325 IPC::Message* reply_message) { | 4366 IPC::Message* reply_message) { |
| 4326 AutomationJSONReply reply(this, reply_message); | 4367 AutomationJSONReply reply(this, reply_message); |
| 4327 ExtensionService* service = profile()->GetExtensionService(); | 4368 ExtensionService* service = profile()->GetExtensionService(); |
| 4328 if (!service) { | 4369 if (!service) { |
| 4329 reply.SendError("No extensions service."); | 4370 reply.SendError("No extensions service."); |
| 4330 return; | 4371 return; |
| 4331 } | 4372 } |
| 4332 scoped_ptr<DictionaryValue> return_value(new DictionaryValue); | 4373 scoped_ptr<DictionaryValue> return_value(new DictionaryValue); |
| 4333 ListValue* extensions_values = new ListValue; | 4374 ListValue* extensions_values = new ListValue; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 4352 extension_value->SetString("description", extension->description()); | 4393 extension_value->SetString("description", extension->description()); |
| 4353 extension_value->SetString("background_url", | 4394 extension_value->SetString("background_url", |
| 4354 extension->background_url().spec()); | 4395 extension->background_url().spec()); |
| 4355 extension_value->SetString("options_url", | 4396 extension_value->SetString("options_url", |
| 4356 extension->options_url().spec()); | 4397 extension->options_url().spec()); |
| 4357 extension_value->Set("host_permissions", | 4398 extension_value->Set("host_permissions", |
| 4358 GetHostPermissions(extension, false)); | 4399 GetHostPermissions(extension, false)); |
| 4359 extension_value->Set("effective_host_permissions", | 4400 extension_value->Set("effective_host_permissions", |
| 4360 GetHostPermissions(extension, true)); | 4401 GetHostPermissions(extension, true)); |
| 4361 extension_value->Set("api_permissions", GetAPIPermissions(extension)); | 4402 extension_value->Set("api_permissions", GetAPIPermissions(extension)); |
| 4362 extension_value->SetBoolean("is_component_extension", | 4403 extension_value->SetBoolean("is_component", |
| 4363 extension->location() == Extension::COMPONENT); | 4404 extension->location() == Extension::COMPONENT); |
| 4405 extension_value->SetBoolean("is_internal", |
| 4406 extension->location() == Extension::INTERNAL); |
| 4364 extension_value->SetBoolean("is_enabled", service->IsExtensionEnabled(id)); | 4407 extension_value->SetBoolean("is_enabled", service->IsExtensionEnabled(id)); |
| 4365 extension_value->SetBoolean("allowed_in_incognito", | 4408 extension_value->SetBoolean("allowed_in_incognito", |
| 4366 service->IsIncognitoEnabled(id)); | 4409 service->IsIncognitoEnabled(id)); |
| 4367 extensions_values->Append(extension_value); | 4410 extensions_values->Append(extension_value); |
| 4368 } | 4411 } |
| 4369 return_value->Set("extensions", extensions_values); | 4412 return_value->Set("extensions", extensions_values); |
| 4370 reply.SendSuccess(return_value.get()); | 4413 reply.SendSuccess(return_value.get()); |
| 4371 } | 4414 } |
| 4372 | 4415 |
| 4373 // See UninstallExtensionById() in chrome/test/pyautolib/pyauto.py for sample | 4416 // See UninstallExtensionById() in chrome/test/pyautolib/pyauto.py for sample |
| (...skipping 2014 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6388 | 6431 |
| 6389 Send(reply_message_); | 6432 Send(reply_message_); |
| 6390 redirect_query_ = 0; | 6433 redirect_query_ = 0; |
| 6391 reply_message_ = NULL; | 6434 reply_message_ = NULL; |
| 6392 } | 6435 } |
| 6393 | 6436 |
| 6394 void TestingAutomationProvider::OnRemoveProvider() { | 6437 void TestingAutomationProvider::OnRemoveProvider() { |
| 6395 if (g_browser_process) | 6438 if (g_browser_process) |
| 6396 g_browser_process->GetAutomationProviderList()->RemoveProvider(this); | 6439 g_browser_process->GetAutomationProviderList()->RemoveProvider(this); |
| 6397 } | 6440 } |
| OLD | NEW |