| 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 3428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3439 "Missing or invalid 'path'"); | 3439 "Missing or invalid 'path'"); |
| 3440 return; | 3440 return; |
| 3441 } | 3441 } |
| 3442 if (!args->GetBoolean("with_ui", &with_ui)) { | 3442 if (!args->GetBoolean("with_ui", &with_ui)) { |
| 3443 AutomationJSONReply(this, reply_message).SendError( | 3443 AutomationJSONReply(this, reply_message).SendError( |
| 3444 "Missing or invalid 'with_ui'"); | 3444 "Missing or invalid 'with_ui'"); |
| 3445 return; | 3445 return; |
| 3446 } | 3446 } |
| 3447 args->GetBoolean("from_webstore", &from_webstore); | 3447 args->GetBoolean("from_webstore", &from_webstore); |
| 3448 | 3448 |
| 3449 ExtensionService* service = extensions::ExtensionSystem::Get( | 3449 extensions::ExtensionSystem* system = |
| 3450 browser->profile())->extension_service(); | 3450 extensions::ExtensionSystem::Get(browser->profile()); |
| 3451 extensions::ProcessManager* manager = | 3451 ExtensionService* service = system->extension_service(); |
| 3452 extensions::ExtensionSystem::Get(browser->profile())->process_manager(); | 3452 if (service) { |
| 3453 if (service && manager) { | |
| 3454 // The observer will delete itself when done. | 3453 // The observer will delete itself when done. |
| 3455 new ExtensionReadyNotificationObserver( | 3454 new ExtensionReadyNotificationObserver( |
| 3456 manager, | 3455 system, |
| 3457 service, | |
| 3458 this, | 3456 this, |
| 3459 reply_message); | 3457 reply_message); |
| 3460 | 3458 |
| 3461 base::FilePath extension_path(path_string); | 3459 base::FilePath extension_path(path_string); |
| 3462 // If the given path has a 'crx' extension, assume it is a packed extension | 3460 // If the given path has a 'crx' extension, assume it is a packed extension |
| 3463 // and install it. Otherwise load it as an unpacked extension. | 3461 // and install it. Otherwise load it as an unpacked extension. |
| 3464 if (extension_path.MatchesExtension(FILE_PATH_LITERAL(".crx"))) { | 3462 if (extension_path.MatchesExtension(FILE_PATH_LITERAL(".crx"))) { |
| 3465 scoped_ptr<ExtensionInstallPrompt> client( | 3463 scoped_ptr<ExtensionInstallPrompt> client( |
| 3466 with_ui ? new ExtensionInstallPrompt(tab) : NULL); | 3464 with_ui ? new ExtensionInstallPrompt(tab) : NULL); |
| 3467 scoped_refptr<extensions::CrxInstaller> installer( | 3465 scoped_refptr<extensions::CrxInstaller> installer( |
| 3468 extensions::CrxInstaller::Create(service, client.Pass())); | 3466 extensions::CrxInstaller::Create(service, client.Pass())); |
| 3469 if (!with_ui) | 3467 if (!with_ui) |
| 3470 installer->set_allow_silent_install(true); | 3468 installer->set_allow_silent_install(true); |
| 3471 installer->set_install_cause(extension_misc::INSTALL_CAUSE_AUTOMATION); | 3469 installer->set_install_cause(extension_misc::INSTALL_CAUSE_AUTOMATION); |
| 3472 if (from_webstore) | 3470 if (from_webstore) |
| 3473 installer->set_creation_flags(Extension::FROM_WEBSTORE); | 3471 installer->set_creation_flags(Extension::FROM_WEBSTORE); |
| 3474 installer->InstallCrx(extension_path); | 3472 installer->InstallCrx(extension_path); |
| 3475 } else { | 3473 } else { |
| 3476 scoped_refptr<extensions::UnpackedInstaller> installer( | 3474 scoped_refptr<extensions::UnpackedInstaller> installer( |
| 3477 extensions::UnpackedInstaller::Create(service)); | 3475 extensions::UnpackedInstaller::Create(service)); |
| 3478 installer->set_prompt_for_plugins(with_ui); | 3476 installer->set_prompt_for_plugins(with_ui); |
| 3479 installer->Load(extension_path); | 3477 installer->Load(extension_path); |
| 3480 } | 3478 } |
| 3481 } else { | 3479 } else { |
| 3482 AutomationJSONReply(this, reply_message).SendError( | 3480 AutomationJSONReply(this, reply_message).SendError( |
| 3483 "Extensions service/process manager is not available"); | 3481 "Extensions service is not available"); |
| 3484 } | 3482 } |
| 3485 } | 3483 } |
| 3486 | 3484 |
| 3487 namespace { | 3485 namespace { |
| 3488 | 3486 |
| 3489 base::ListValue* GetHostPermissions(const Extension* ext, bool effective_perm) { | 3487 base::ListValue* GetHostPermissions(const Extension* ext, bool effective_perm) { |
| 3490 extensions::URLPatternSet pattern_set; | 3488 extensions::URLPatternSet pattern_set; |
| 3491 if (effective_perm) { | 3489 if (effective_perm) { |
| 3492 pattern_set = | 3490 pattern_set = |
| 3493 extensions::PermissionsData::GetEffectiveHostPermissions(ext); | 3491 extensions::PermissionsData::GetEffectiveHostPermissions(ext); |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3653 return; | 3651 return; |
| 3654 } | 3652 } |
| 3655 | 3653 |
| 3656 if (allow_in_incognito && !enable) { | 3654 if (allow_in_incognito && !enable) { |
| 3657 AutomationJSONReply(this, reply_message) | 3655 AutomationJSONReply(this, reply_message) |
| 3658 .SendError("Invalid state: Disabled extension " | 3656 .SendError("Invalid state: Disabled extension " |
| 3659 "cannot be allowed in incognito mode."); | 3657 "cannot be allowed in incognito mode."); |
| 3660 return; | 3658 return; |
| 3661 } | 3659 } |
| 3662 | 3660 |
| 3663 ExtensionService* service = extensions::ExtensionSystem::Get( | 3661 extensions::ExtensionSystem* system = |
| 3664 browser->profile())->extension_service(); | 3662 extensions::ExtensionSystem::Get(browser->profile()); |
| 3665 extensions::ProcessManager* manager = | 3663 ExtensionService* service = system->extension_service(); |
| 3666 extensions::ExtensionSystem::Get(browser->profile())->process_manager(); | |
| 3667 if (!service) { | 3664 if (!service) { |
| 3668 AutomationJSONReply(this, reply_message) | 3665 AutomationJSONReply(this, reply_message) |
| 3669 .SendError("No extensions service or process manager."); | 3666 .SendError("No extensions service."); |
| 3670 return; | 3667 return; |
| 3671 } | 3668 } |
| 3672 | 3669 |
| 3673 if (enable) { | 3670 if (enable) { |
| 3674 if (!service->IsExtensionEnabled(extension->id())) { | 3671 if (!service->IsExtensionEnabled(extension->id())) { |
| 3675 new ExtensionReadyNotificationObserver( | 3672 new ExtensionReadyNotificationObserver( |
| 3676 manager, | 3673 system, |
| 3677 service, | |
| 3678 this, | 3674 this, |
| 3679 reply_message); | 3675 reply_message); |
| 3680 service->EnableExtension(extension->id()); | 3676 service->EnableExtension(extension->id()); |
| 3681 } else { | 3677 } else { |
| 3682 AutomationJSONReply(this, reply_message).SendSuccess(NULL); | 3678 AutomationJSONReply(this, reply_message).SendSuccess(NULL); |
| 3683 } | 3679 } |
| 3684 } else { | 3680 } else { |
| 3685 service->DisableExtension(extension->id(), | 3681 service->DisableExtension(extension->id(), |
| 3686 Extension::DISABLE_USER_ACTION); | 3682 Extension::DISABLE_USER_ACTION); |
| 3687 AutomationJSONReply(this, reply_message).SendSuccess(NULL); | 3683 AutomationJSONReply(this, reply_message).SendSuccess(NULL); |
| (...skipping 1710 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5398 if (g_browser_process) | 5394 if (g_browser_process) |
| 5399 g_browser_process->GetAutomationProviderList()->RemoveProvider(this); | 5395 g_browser_process->GetAutomationProviderList()->RemoveProvider(this); |
| 5400 } | 5396 } |
| 5401 | 5397 |
| 5402 void TestingAutomationProvider::EnsureTabSelected(Browser* browser, | 5398 void TestingAutomationProvider::EnsureTabSelected(Browser* browser, |
| 5403 WebContents* tab) { | 5399 WebContents* tab) { |
| 5404 TabStripModel* tab_strip = browser->tab_strip_model(); | 5400 TabStripModel* tab_strip = browser->tab_strip_model(); |
| 5405 if (tab_strip->GetActiveWebContents() != tab) | 5401 if (tab_strip->GetActiveWebContents() != tab) |
| 5406 tab_strip->ActivateTabAt(tab_strip->GetIndexOfWebContents(tab), true); | 5402 tab_strip->ActivateTabAt(tab_strip->GetIndexOfWebContents(tab), true); |
| 5407 } | 5403 } |
| OLD | NEW |