diff options
author | mpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-08 21:01:52 +0000 |
---|---|---|
committer | mpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-08 21:01:52 +0000 |
commit | 1784e83a07f691ac0caa78d32eaf527cfe02b834 (patch) | |
tree | bef5aae98152a1d2835cd321cd715dcd4ce8205f | |
parent | b7f044b62aa5547ecb4a6862c4a7b3fa5ec83de3 (diff) | |
download | chromium_src-1784e83a07f691ac0caa78d32eaf527cfe02b834.zip chromium_src-1784e83a07f691ac0caa78d32eaf527cfe02b834.tar.gz chromium_src-1784e83a07f691ac0caa78d32eaf527cfe02b834.tar.bz2 |
Add a disable button to the Extension management UI.
TEST=Try installing and/or loading some extensions, and toggling between enable and disable in the management UI (chrome://extensions).
BUG=12122
Review URL: http://codereview.chromium.org/199018
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@25659 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/browser_resources.grd | 2 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_browsertests_misc.cc | 28 | ||||
-rw-r--r-- | chrome/browser/extensions/extensions_service.cc | 32 | ||||
-rw-r--r-- | chrome/browser/extensions/extensions_service.h | 6 | ||||
-rw-r--r-- | chrome/browser/extensions/extensions_ui.cc | 12 | ||||
-rw-r--r-- | chrome/browser/resources/extensions_ui.html | 13 |
6 files changed, 81 insertions, 12 deletions
diff --git a/chrome/browser/browser_resources.grd b/chrome/browser/browser_resources.grd index b1dec77..15777e7 100644 --- a/chrome/browser/browser_resources.grd +++ b/chrome/browser/browser_resources.grd @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="UTF-8"?> <!-- This comment is only here because changes to resources are not picked up -without changes to the corresponding grd file. as1 --> +without changes to the corresponding grd file. mp2 --> <grit latest_public_release="0" current_release="1"> <outputs> <output filename="grit/browser_resources.h" type="rc_header"> diff --git a/chrome/browser/extensions/extension_browsertests_misc.cc b/chrome/browser/extensions/extension_browsertests_misc.cc index 4ddfd83..3da3b0c 100644 --- a/chrome/browser/extensions/extension_browsertests_misc.cc +++ b/chrome/browser/extensions/extension_browsertests_misc.cc @@ -502,6 +502,34 @@ IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, UninstallDisabled) { EXPECT_EQ(0u, service->disabled_extensions()->size()); } +// Tests that disabling and re-enabling an extension works. +IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, DisableEnable) { + ExtensionsService* service = browser()->profile()->GetExtensionsService(); + ExtensionProcessManager* manager = + browser()->profile()->GetExtensionProcessManager(); + + // Load an extension, expect the toolstrip to be available. + ASSERT_TRUE(LoadExtension( + test_data_dir_.AppendASCII("good").AppendASCII("Extensions") + .AppendASCII("bjafgdebaacbbbecmhlhpofkepfkgcpa") + .AppendASCII("1.0"))); + EXPECT_EQ(1u, service->extensions()->size()); + EXPECT_EQ(0u, service->disabled_extensions()->size()); + EXPECT_TRUE(FindHostWithPath(manager, "/toolstrip.html", 1)); + + // After disabling, the toolstrip should go away. + service->DisableExtension("bjafgdebaacbbbecmhlhpofkepfkgcpa"); + EXPECT_EQ(0u, service->extensions()->size()); + EXPECT_EQ(1u, service->disabled_extensions()->size()); + EXPECT_FALSE(FindHostWithPath(manager, "/toolstrip.html", 0)); + + // And bring it back. + service->EnableExtension("bjafgdebaacbbbecmhlhpofkepfkgcpa"); + EXPECT_EQ(1u, service->extensions()->size()); + EXPECT_EQ(0u, service->disabled_extensions()->size()); + EXPECT_TRUE(FindHostWithPath(manager, "/toolstrip.html", 1)); +} + // Helper function for common code shared by the 3 WindowOpen tests below. static TabContents* WindowOpenHelper(Browser* browser, const GURL& start_url, const std::string& newtab_url) { diff --git a/chrome/browser/extensions/extensions_service.cc b/chrome/browser/extensions/extensions_service.cc index 46bce98..d7cb206 100644 --- a/chrome/browser/extensions/extensions_service.cc +++ b/chrome/browser/extensions/extensions_service.cc @@ -220,8 +220,11 @@ void ExtensionsService::EnableExtension(const std::string& extension_id) { return; } + // Remember that we enabled it, unless it's temporary. + if (extension->location() != Extension::LOAD) + extension_prefs_->SetExtensionState(extension, Extension::ENABLED); + // Move it over to the enabled list. - extension_prefs_->SetExtensionState(extension, Extension::ENABLED); extensions_.push_back(extension); ExtensionList::iterator iter = std::find(disabled_extensions_.begin(), disabled_extensions_.end(), @@ -237,6 +240,33 @@ void ExtensionsService::EnableExtension(const std::string& extension_id) { Details<Extension>(extension)); } +void ExtensionsService::DisableExtension(const std::string& extension_id) { + Extension* extension = GetExtensionByIdInternal(extension_id, true, false); + if (!extension) { + NOTREACHED() << "Trying to disable an extension that isn't enabled."; + return; + } + + // Remember that we disabled it, unless it's temporary. + if (extension->location() != Extension::LOAD) + extension_prefs_->SetExtensionState(extension, Extension::DISABLED); + + // Move it over to the disabled list. + disabled_extensions_.push_back(extension); + ExtensionList::iterator iter = std::find(extensions_.begin(), + extensions_.end(), + extension); + extensions_.erase(iter); + + ExtensionDOMUI::UnregisterChromeURLOverrides(profile_, + extension->GetChromeURLOverrides()); + + NotificationService::current()->Notify( + NotificationType::EXTENSION_UNLOADED, + Source<ExtensionsService>(this), + Details<Extension>(extension)); +} + void ExtensionsService::LoadExtension(const FilePath& extension_path) { backend_loop_->PostTask(FROM_HERE, NewRunnableMethod(backend_.get(), &ExtensionsServiceBackend::LoadSingleExtension, diff --git a/chrome/browser/extensions/extensions_service.h b/chrome/browser/extensions/extensions_service.h index 4702e5a..a17ef93 100644 --- a/chrome/browser/extensions/extensions_service.h +++ b/chrome/browser/extensions/extensions_service.h @@ -129,10 +129,10 @@ class ExtensionsService void UninstallExtension(const std::string& extension_id, bool external_uninstall); - // Enable a previously disabled extension and reload it. The extension should - // already exist in the extension prefs. - // TODO(mpcomplete): add DisableExtension. + // Enable or disable an extension. The extension must be in the opposite state + // before calling. void EnableExtension(const std::string& extension_id); + void DisableExtension(const std::string& extension_id); // Load the extension from the directory |extension_path|. void LoadExtension(const FilePath& extension_path); diff --git a/chrome/browser/extensions/extensions_ui.cc b/chrome/browser/extensions/extensions_ui.cc index c251b2f..708b7e6 100644 --- a/chrome/browser/extensions/extensions_ui.cc +++ b/chrome/browser/extensions/extensions_ui.cc @@ -121,6 +121,7 @@ void ExtensionsDOMHandler::HandleRequestExtensionsData(const Value* value) { dom_ui_->CallJavascriptFunction(L"returnExtensionsData", results); // Register for notifications that we need to reload the page. + registrar_.RemoveAll(); registrar_.Add(this, NotificationType::EXTENSION_LOADED, NotificationService::AllSources()); registrar_.Add(this, NotificationType::EXTENSION_UNLOADED, @@ -165,10 +166,15 @@ void ExtensionsDOMHandler::HandleReloadMessage(const Value* value) { void ExtensionsDOMHandler::HandleEnableMessage(const Value* value) { CHECK(value->IsType(Value::TYPE_LIST)); const ListValue* list = static_cast<const ListValue*>(value); - CHECK(list->GetSize() == 1); - std::string extension_id; + CHECK(list->GetSize() == 2); + std::string extension_id, enable_str; CHECK(list->GetString(0, &extension_id)); - extensions_service_->EnableExtension(extension_id); + CHECK(list->GetString(1, &enable_str)); + if (enable_str == "true") { + extensions_service_->EnableExtension(extension_id); + } else { + extensions_service_->DisableExtension(extension_id); + } } void ExtensionsDOMHandler::HandleUninstallMessage(const Value* value) { diff --git a/chrome/browser/resources/extensions_ui.html b/chrome/browser/resources/extensions_ui.html index 0542d1c..0c9273b 100644 --- a/chrome/browser/resources/extensions_ui.html +++ b/chrome/browser/resources/extensions_ui.html @@ -247,11 +247,11 @@ function handleReloadExtension(node) { } /** - * Handles a 'reenable' button getting clicked. + * Handles a 'enable' or 'disable' button getting clicked. */ -function handleEnableExtension(node) { +function handleEnableExtension(node, enable) { // Tell the C++ ExtensionDOMHandler to reload the extension. - chrome.send('enable', [node.extensionId]); + chrome.send('enable', [node.extensionId, String(enable)]); requestExtensionsData(); } @@ -325,8 +325,13 @@ function autoUpdate() { <div class="extension-actions"> <button jsvalues=".extensionId:id" + jsdisplay="enabled" + onclick="handleEnableExtension(this, false)" + >Disable</button> + <button + jsvalues=".extensionId:id" jsdisplay="!enabled" - onclick="handleEnableExtension(this)" + onclick="handleEnableExtension(this, true)" >Enable</button> <button jsvalues=".extensionId:id" |