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
parent b7f044b6
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!-- This comment is only here because changes to resources are not picked up <!-- 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"> <grit latest_public_release="0" current_release="1">
<outputs> <outputs>
<output filename="grit/browser_resources.h" type="rc_header"> <output filename="grit/browser_resources.h" type="rc_header">
......
...@@ -502,6 +502,34 @@ IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, UninstallDisabled) { ...@@ -502,6 +502,34 @@ IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, UninstallDisabled) {
EXPECT_EQ(0u, service->disabled_extensions()->size()); 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. // Helper function for common code shared by the 3 WindowOpen tests below.
static TabContents* WindowOpenHelper(Browser* browser, const GURL& start_url, static TabContents* WindowOpenHelper(Browser* browser, const GURL& start_url,
const std::string& newtab_url) { const std::string& newtab_url) {
......
...@@ -220,8 +220,11 @@ void ExtensionsService::EnableExtension(const std::string& extension_id) { ...@@ -220,8 +220,11 @@ void ExtensionsService::EnableExtension(const std::string& extension_id) {
return; 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. // Move it over to the enabled list.
extension_prefs_->SetExtensionState(extension, Extension::ENABLED);
extensions_.push_back(extension); extensions_.push_back(extension);
ExtensionList::iterator iter = std::find(disabled_extensions_.begin(), ExtensionList::iterator iter = std::find(disabled_extensions_.begin(),
disabled_extensions_.end(), disabled_extensions_.end(),
...@@ -237,6 +240,33 @@ void ExtensionsService::EnableExtension(const std::string& extension_id) { ...@@ -237,6 +240,33 @@ void ExtensionsService::EnableExtension(const std::string& extension_id) {
Details<Extension>(extension)); 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) { void ExtensionsService::LoadExtension(const FilePath& extension_path) {
backend_loop_->PostTask(FROM_HERE, NewRunnableMethod(backend_.get(), backend_loop_->PostTask(FROM_HERE, NewRunnableMethod(backend_.get(),
&ExtensionsServiceBackend::LoadSingleExtension, &ExtensionsServiceBackend::LoadSingleExtension,
......
...@@ -129,10 +129,10 @@ class ExtensionsService ...@@ -129,10 +129,10 @@ class ExtensionsService
void UninstallExtension(const std::string& extension_id, void UninstallExtension(const std::string& extension_id,
bool external_uninstall); bool external_uninstall);
// Enable a previously disabled extension and reload it. The extension should // Enable or disable an extension. The extension must be in the opposite state
// already exist in the extension prefs. // before calling.
// TODO(mpcomplete): add DisableExtension.
void EnableExtension(const std::string& extension_id); void EnableExtension(const std::string& extension_id);
void DisableExtension(const std::string& extension_id);
// Load the extension from the directory |extension_path|. // Load the extension from the directory |extension_path|.
void LoadExtension(const FilePath& extension_path); void LoadExtension(const FilePath& extension_path);
......
...@@ -121,6 +121,7 @@ void ExtensionsDOMHandler::HandleRequestExtensionsData(const Value* value) { ...@@ -121,6 +121,7 @@ void ExtensionsDOMHandler::HandleRequestExtensionsData(const Value* value) {
dom_ui_->CallJavascriptFunction(L"returnExtensionsData", results); dom_ui_->CallJavascriptFunction(L"returnExtensionsData", results);
// Register for notifications that we need to reload the page. // Register for notifications that we need to reload the page.
registrar_.RemoveAll();
registrar_.Add(this, NotificationType::EXTENSION_LOADED, registrar_.Add(this, NotificationType::EXTENSION_LOADED,
NotificationService::AllSources()); NotificationService::AllSources());
registrar_.Add(this, NotificationType::EXTENSION_UNLOADED, registrar_.Add(this, NotificationType::EXTENSION_UNLOADED,
...@@ -165,10 +166,15 @@ void ExtensionsDOMHandler::HandleReloadMessage(const Value* value) { ...@@ -165,10 +166,15 @@ void ExtensionsDOMHandler::HandleReloadMessage(const Value* value) {
void ExtensionsDOMHandler::HandleEnableMessage(const Value* value) { void ExtensionsDOMHandler::HandleEnableMessage(const Value* value) {
CHECK(value->IsType(Value::TYPE_LIST)); CHECK(value->IsType(Value::TYPE_LIST));
const ListValue* list = static_cast<const ListValue*>(value); const ListValue* list = static_cast<const ListValue*>(value);
CHECK(list->GetSize() == 1); CHECK(list->GetSize() == 2);
std::string extension_id; std::string extension_id, enable_str;
CHECK(list->GetString(0, &extension_id)); 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) { void ExtensionsDOMHandler::HandleUninstallMessage(const Value* value) {
......
...@@ -247,11 +247,11 @@ function handleReloadExtension(node) { ...@@ -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. // Tell the C++ ExtensionDOMHandler to reload the extension.
chrome.send('enable', [node.extensionId]); chrome.send('enable', [node.extensionId, String(enable)]);
requestExtensionsData(); requestExtensionsData();
} }
...@@ -323,10 +323,15 @@ function autoUpdate() { ...@@ -323,10 +323,15 @@ function autoUpdate() {
>Inspect</a> >Inspect</a>
</ul> </ul>
<div class="extension-actions"> <div class="extension-actions">
<button
jsvalues=".extensionId:id"
jsdisplay="enabled"
onclick="handleEnableExtension(this, false)"
>Disable</button>
<button <button
jsvalues=".extensionId:id" jsvalues=".extensionId:id"
jsdisplay="!enabled" jsdisplay="!enabled"
onclick="handleEnableExtension(this)" onclick="handleEnableExtension(this, true)"
>Enable</button> >Enable</button>
<button <button
jsvalues=".extensionId:id" jsvalues=".extensionId:id"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment