summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoraa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-22 21:32:10 +0000
committeraa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-22 21:32:10 +0000
commite18236b8e1bb3a02bc21e5f8f3e9dec2c3dfc785 (patch)
treed4690b93b45f731d9cc5e85f7ec48a866df17a2d
parent95792eb13df32a536a13a5e8b712be06fb059457 (diff)
downloadchromium_src-e18236b8e1bb3a02bc21e5f8f3e9dec2c3dfc785.zip
chromium_src-e18236b8e1bb3a02bc21e5f8f3e9dec2c3dfc785.tar.gz
chromium_src-e18236b8e1bb3a02bc21e5f8f3e9dec2c3dfc785.tar.bz2
Re-enable the --enable-extensions flag. Fix a bug where the extensions.enable pref was not being honored. Add tests.
This is intended to be submitted after: http://codereview.chromium.org/132003 BUG=13467 TEST=Added unit tests Review URL: http://codereview.chromium.org/132045 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@18962 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/extensions/extensions_service.cc15
-rw-r--r--chrome/browser/extensions/extensions_service.h2
-rw-r--r--chrome/browser/extensions/extensions_service_unittest.cc32
-rw-r--r--chrome/browser/profile.cc2
4 files changed, 47 insertions, 4 deletions
diff --git a/chrome/browser/extensions/extensions_service.cc b/chrome/browser/extensions/extensions_service.cc
index 7960664..4ef4d08 100644
--- a/chrome/browser/extensions/extensions_service.cc
+++ b/chrome/browser/extensions/extensions_service.cc
@@ -211,6 +211,7 @@ class ExtensionsServiceBackend::UnpackerClient
};
ExtensionsService::ExtensionsService(Profile* profile,
+ const CommandLine* command_line,
MessageLoop* frontend_loop,
MessageLoop* backend_loop)
: extension_prefs_(new ExtensionPrefs(profile->GetPrefs())),
@@ -219,6 +220,12 @@ ExtensionsService::ExtensionsService(Profile* profile,
extensions_enabled_(false),
show_extensions_prompts_(true),
ready_(false) {
+ // Figure out if extension installation should be enabled.
+ if (command_line->HasSwitch(switches::kEnableExtensions))
+ extensions_enabled_ = true;
+ else if (profile->GetPrefs()->GetBoolean(prefs::kEnableExtensions))
+ extensions_enabled_ = true;
+
// We pass ownership of this object to the Backend.
DictionaryValue* extensions = extension_prefs_->CopyCurrentExtensions();
backend_ = new ExtensionsServiceBackend(
@@ -463,7 +470,7 @@ ExtensionsServiceBackend::ExtensionsServiceBackend(
resource_dispatcher_host_(rdh),
alert_on_error_(false),
frontend_loop_(frontend_loop),
- extensions_enabled_(false) {
+ extensions_enabled_(extensions_enabled) {
external_extension_providers_[Extension::EXTERNAL_PREF] =
linked_ptr<ExternalExtensionProvider>(
new ExternalPrefExtensionProvider(extension_prefs));
@@ -972,11 +979,15 @@ void ExtensionsServiceBackend::OnExtensionUnpacked(
!extension.IsTheme() &&
location != Extension::EXTERNAL_REGISTRY) {
ReportExtensionInstallError(extension_path,
- "Extensions are not enabled (yet!)");
+ "Extensions are not enabled. Add --enable-extensions to the "
+ "command-line to enable extensions.\n\n"
+ "This is a temporary message and it will be removed when extensions "
+ "UI is finalized.");
return;
}
#if defined(OS_WIN)
+ // We don't show the install dialog for themes or external extensions.
if (!extension.IsTheme() &&
!Extension::IsExternalLocation(location) &&
frontend_->show_extensions_prompts() &&
diff --git a/chrome/browser/extensions/extensions_service.h b/chrome/browser/extensions/extensions_service.h
index 87c387f..f4be29b 100644
--- a/chrome/browser/extensions/extensions_service.h
+++ b/chrome/browser/extensions/extensions_service.h
@@ -10,6 +10,7 @@
#include <string>
#include <vector>
+#include "base/command_line.h"
#include "base/file_path.h"
#include "base/linked_ptr.h"
#include "base/ref_counted.h"
@@ -72,6 +73,7 @@ class ExtensionsService
};
ExtensionsService(Profile* profile,
+ const CommandLine* command_line,
MessageLoop* frontend_loop,
MessageLoop* backend_loop);
~ExtensionsService();
diff --git a/chrome/browser/extensions/extensions_service_unittest.cc b/chrome/browser/extensions/extensions_service_unittest.cc
index e41a84a..06d343c 100644
--- a/chrome/browser/extensions/extensions_service_unittest.cc
+++ b/chrome/browser/extensions/extensions_service_unittest.cc
@@ -5,6 +5,7 @@
#include <algorithm>
#include <vector>
+#include "base/command_line.h"
#include "base/file_path.h"
#include "base/file_util.h"
#include "base/json_reader.h"
@@ -24,6 +25,7 @@
#include "chrome/common/notification_registrar.h"
#include "chrome/common/notification_service.h"
#include "chrome/common/notification_type.h"
+#include "chrome/common/pref_names.h"
#include "chrome/test/testing_profile.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/platform_test.h"
@@ -130,7 +132,8 @@ class ExtensionsServiceTest
NotificationService::AllSources());
profile_.reset(new TestingProfile());
- service_ = new ExtensionsService(profile_.get(), &loop_, &loop_);
+ service_ = new ExtensionsService(
+ profile_.get(), CommandLine::ForCurrentProcess(), &loop_, &loop_);
service_->SetExtensionsEnabled(true);
service_->set_show_extensions_prompts(false);
@@ -1023,3 +1026,30 @@ TEST_F(ExtensionsServiceTest, ExternalInstallPref) {
ASSERT_EQ(0u, loaded_.size());
ASSERT_EQ(1u, GetErrors().size());
}
+
+// Test that we get enabled/disabled correctly for all the pref/command-line
+// combinations.
+TEST(ExtensionsServiceTest2, Enabledness) {
+ TestingProfile profile;
+ MessageLoop loop;
+ scoped_ptr<CommandLine> command_line;
+ scoped_refptr<ExtensionsService> service;
+
+ // By default, we are disabled.
+ command_line.reset(new CommandLine(L""));
+ service = new ExtensionsService(&profile, command_line.get(), &loop, &loop);
+ EXPECT_FALSE(service->extensions_enabled());
+
+ // If either the command line or pref is set, we are enabled.
+ command_line->AppendSwitch(switches::kEnableExtensions);
+ service = new ExtensionsService(&profile, command_line.get(), &loop, &loop);
+ EXPECT_TRUE(service->extensions_enabled());
+
+ profile.GetPrefs()->SetBoolean(prefs::kEnableExtensions, true);
+ service = new ExtensionsService(&profile, command_line.get(), &loop, &loop);
+ EXPECT_TRUE(service->extensions_enabled());
+
+ command_line.reset(new CommandLine(L""));
+ service = new ExtensionsService(&profile, command_line.get(), &loop, &loop);
+ EXPECT_TRUE(service->extensions_enabled());
+}
diff --git a/chrome/browser/profile.cc b/chrome/browser/profile.cc
index 179f506..67e9810 100644
--- a/chrome/browser/profile.cc
+++ b/chrome/browser/profile.cc
@@ -478,7 +478,7 @@ void ProfileImpl::InitExtensions() {
g_browser_process->file_thread()->message_loop(),
script_dir);
extensions_service_ = new ExtensionsService(
- this, MessageLoop::current(),
+ this, CommandLine::ForCurrentProcess(), MessageLoop::current(),
g_browser_process->file_thread()->message_loop());
extensions_service_->Init();