| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 3434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3445 "Missing or invalid 'path'"); | 3445 "Missing or invalid 'path'"); |
| 3446 return; | 3446 return; |
| 3447 } | 3447 } |
| 3448 if (!args->GetBoolean("with_ui", &with_ui)) { | 3448 if (!args->GetBoolean("with_ui", &with_ui)) { |
| 3449 AutomationJSONReply(this, reply_message).SendError( | 3449 AutomationJSONReply(this, reply_message).SendError( |
| 3450 "Missing or invalid 'with_ui'"); | 3450 "Missing or invalid 'with_ui'"); |
| 3451 return; | 3451 return; |
| 3452 } | 3452 } |
| 3453 args->GetBoolean("from_webstore", &from_webstore); | 3453 args->GetBoolean("from_webstore", &from_webstore); |
| 3454 | 3454 |
| 3455 ExtensionService* service = extensions::ExtensionSystem::Get( | 3455 extensions::ExtensionSystem* system = |
| 3456 browser->profile())->extension_service(); | 3456 extensions::ExtensionSystem::Get(browser->profile()); |
| 3457 extensions::ProcessManager* manager = | 3457 ExtensionService* service = system->extension_service(); |
| 3458 extensions::ExtensionSystem::Get(browser->profile())->process_manager(); | 3458 if (service) { |
| 3459 if (service && manager) { | |
| 3460 // The observer will delete itself when done. | 3459 // The observer will delete itself when done. |
| 3461 new ExtensionReadyNotificationObserver( | 3460 new ExtensionReadyNotificationObserver( |
| 3462 manager, | 3461 system, |
| 3463 service, | |
| 3464 this, | 3462 this, |
| 3465 reply_message); | 3463 reply_message); |
| 3466 | 3464 |
| 3467 base::FilePath extension_path(path_string); | 3465 base::FilePath extension_path(path_string); |
| 3468 // If the given path has a 'crx' extension, assume it is a packed extension | 3466 // If the given path has a 'crx' extension, assume it is a packed extension |
| 3469 // and install it. Otherwise load it as an unpacked extension. | 3467 // and install it. Otherwise load it as an unpacked extension. |
| 3470 if (extension_path.MatchesExtension(FILE_PATH_LITERAL(".crx"))) { | 3468 if (extension_path.MatchesExtension(FILE_PATH_LITERAL(".crx"))) { |
| 3471 scoped_ptr<ExtensionInstallPrompt> client( | 3469 scoped_ptr<ExtensionInstallPrompt> client( |
| 3472 with_ui ? new ExtensionInstallPrompt(tab) : NULL); | 3470 with_ui ? new ExtensionInstallPrompt(tab) : NULL); |
| 3473 scoped_refptr<extensions::CrxInstaller> installer( | 3471 scoped_refptr<extensions::CrxInstaller> installer( |
| 3474 extensions::CrxInstaller::Create(service, client.Pass())); | 3472 extensions::CrxInstaller::Create(service, client.Pass())); |
| 3475 if (!with_ui) | 3473 if (!with_ui) |
| 3476 installer->set_allow_silent_install(true); | 3474 installer->set_allow_silent_install(true); |
| 3477 installer->set_install_cause(extension_misc::INSTALL_CAUSE_AUTOMATION); | 3475 installer->set_install_cause(extension_misc::INSTALL_CAUSE_AUTOMATION); |
| 3478 if (from_webstore) | 3476 if (from_webstore) |
| 3479 installer->set_creation_flags(Extension::FROM_WEBSTORE); | 3477 installer->set_creation_flags(Extension::FROM_WEBSTORE); |
| 3480 installer->InstallCrx(extension_path); | 3478 installer->InstallCrx(extension_path); |
| 3481 } else { | 3479 } else { |
| 3482 scoped_refptr<extensions::UnpackedInstaller> installer( | 3480 scoped_refptr<extensions::UnpackedInstaller> installer( |
| 3483 extensions::UnpackedInstaller::Create(service)); | 3481 extensions::UnpackedInstaller::Create(service)); |
| 3484 installer->set_prompt_for_plugins(with_ui); | 3482 installer->set_prompt_for_plugins(with_ui); |
| 3485 installer->Load(extension_path); | 3483 installer->Load(extension_path); |
| 3486 } | 3484 } |
| 3487 } else { | 3485 } else { |
| 3488 AutomationJSONReply(this, reply_message).SendError( | 3486 AutomationJSONReply(this, reply_message).SendError( |
| 3489 "Extensions service/process manager is not available"); | 3487 "Extensions service is not available"); |
| 3490 } | 3488 } |
| 3491 } | 3489 } |
| 3492 | 3490 |
| 3493 namespace { | 3491 namespace { |
| 3494 | 3492 |
| 3495 base::ListValue* GetHostPermissions(const Extension* ext, bool effective_perm) { | 3493 base::ListValue* GetHostPermissions(const Extension* ext, bool effective_perm) { |
| 3496 extensions::URLPatternSet pattern_set; | 3494 extensions::URLPatternSet pattern_set; |
| 3497 if (effective_perm) { | 3495 if (effective_perm) { |
| 3498 pattern_set = | 3496 pattern_set = |
| 3499 extensions::PermissionsData::GetEffectiveHostPermissions(ext); | 3497 extensions::PermissionsData::GetEffectiveHostPermissions(ext); |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3659 return; | 3657 return; |
| 3660 } | 3658 } |
| 3661 | 3659 |
| 3662 if (allow_in_incognito && !enable) { | 3660 if (allow_in_incognito && !enable) { |
| 3663 AutomationJSONReply(this, reply_message) | 3661 AutomationJSONReply(this, reply_message) |
| 3664 .SendError("Invalid state: Disabled extension " | 3662 .SendError("Invalid state: Disabled extension " |
| 3665 "cannot be allowed in incognito mode."); | 3663 "cannot be allowed in incognito mode."); |
| 3666 return; | 3664 return; |
| 3667 } | 3665 } |
| 3668 | 3666 |
| 3669 ExtensionService* service = extensions::ExtensionSystem::Get( | 3667 extensions::ExtensionSystem* system = |
| 3670 browser->profile())->extension_service(); | 3668 extensions::ExtensionSystem::Get(browser->profile()); |
| 3671 extensions::ProcessManager* manager = | 3669 ExtensionService* service = system->extension_service(); |
| 3672 extensions::ExtensionSystem::Get(browser->profile())->process_manager(); | |
| 3673 if (!service) { | 3670 if (!service) { |
| 3674 AutomationJSONReply(this, reply_message) | 3671 AutomationJSONReply(this, reply_message) |
| 3675 .SendError("No extensions service or process manager."); | 3672 .SendError("No extensions service."); |
| 3676 return; | 3673 return; |
| 3677 } | 3674 } |
| 3678 | 3675 |
| 3679 if (enable) { | 3676 if (enable) { |
| 3680 if (!service->IsExtensionEnabled(extension->id())) { | 3677 if (!service->IsExtensionEnabled(extension->id())) { |
| 3681 new ExtensionReadyNotificationObserver( | 3678 new ExtensionReadyNotificationObserver( |
| 3682 manager, | 3679 system, |
| 3683 service, | |
| 3684 this, | 3680 this, |
| 3685 reply_message); | 3681 reply_message); |
| 3686 service->EnableExtension(extension->id()); | 3682 service->EnableExtension(extension->id()); |
| 3687 } else { | 3683 } else { |
| 3688 AutomationJSONReply(this, reply_message).SendSuccess(NULL); | 3684 AutomationJSONReply(this, reply_message).SendSuccess(NULL); |
| 3689 } | 3685 } |
| 3690 } else { | 3686 } else { |
| 3691 service->DisableExtension(extension->id(), | 3687 service->DisableExtension(extension->id(), |
| 3692 Extension::DISABLE_USER_ACTION); | 3688 Extension::DISABLE_USER_ACTION); |
| 3693 AutomationJSONReply(this, reply_message).SendSuccess(NULL); | 3689 AutomationJSONReply(this, reply_message).SendSuccess(NULL); |
| (...skipping 1770 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5464 if (g_browser_process) | 5460 if (g_browser_process) |
| 5465 g_browser_process->GetAutomationProviderList()->RemoveProvider(this); | 5461 g_browser_process->GetAutomationProviderList()->RemoveProvider(this); |
| 5466 } | 5462 } |
| 5467 | 5463 |
| 5468 void TestingAutomationProvider::EnsureTabSelected(Browser* browser, | 5464 void TestingAutomationProvider::EnsureTabSelected(Browser* browser, |
| 5469 WebContents* tab) { | 5465 WebContents* tab) { |
| 5470 TabStripModel* tab_strip = browser->tab_strip_model(); | 5466 TabStripModel* tab_strip = browser->tab_strip_model(); |
| 5471 if (tab_strip->GetActiveWebContents() != tab) | 5467 if (tab_strip->GetActiveWebContents() != tab) |
| 5472 tab_strip->ActivateTabAt(tab_strip->GetIndexOfWebContents(tab), true); | 5468 tab_strip->ActivateTabAt(tab_strip->GetIndexOfWebContents(tab), true); |
| 5473 } | 5469 } |
| OLD | NEW |