summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authoraa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-22 21:53:52 +0000
committeraa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-22 21:53:52 +0000
commit2df4a3857876b0a0f45c57f1fe8e7a29b48fd248 (patch)
treeb06568a4187490649f199cc7b4318ba5b23e48b6 /chrome
parentd4fa01ce3bc4264775acedd804e44738d3030084 (diff)
downloadchromium_src-2df4a3857876b0a0f45c57f1fe8e7a29b48fd248.zip
chromium_src-2df4a3857876b0a0f45c57f1fe8e7a29b48fd248.tar.gz
chromium_src-2df4a3857876b0a0f45c57f1fe8e7a29b48fd248.tar.bz2
TBR: Fix dead tree.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@18964 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/extensions/extensions_service.cc66
-rw-r--r--chrome/browser/extensions/extensions_service.h16
-rw-r--r--chrome/browser/extensions/extensions_service_unittest.cc53
-rw-r--r--chrome/browser/profile.cc2
-rw-r--r--chrome/browser/renderer_host/browser_render_process_host.cc19
-rw-r--r--chrome/browser/views/frame/browser_view.cc7
6 files changed, 44 insertions, 119 deletions
diff --git a/chrome/browser/extensions/extensions_service.cc b/chrome/browser/extensions/extensions_service.cc
index 4ef4d08..a9f81ca 100644
--- a/chrome/browser/extensions/extensions_service.cc
+++ b/chrome/browser/extensions/extensions_service.cc
@@ -211,38 +211,27 @@ class ExtensionsServiceBackend::UnpackerClient
};
ExtensionsService::ExtensionsService(Profile* profile,
- const CommandLine* command_line,
MessageLoop* frontend_loop,
MessageLoop* backend_loop)
: extension_prefs_(new ExtensionPrefs(profile->GetPrefs())),
backend_loop_(backend_loop),
install_directory_(profile->GetPath().AppendASCII(kInstallDirectoryName)),
- extensions_enabled_(false),
+ extensions_enabled_(
+ CommandLine::ForCurrentProcess()->
+ HasSwitch(switches::kEnableExtensions)),
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(
install_directory_, g_browser_process->resource_dispatcher_host(),
- frontend_loop, extensions, extensions_enabled());
+ frontend_loop, extensions);
}
ExtensionsService::~ExtensionsService() {
UnloadAllExtensions();
}
-void ExtensionsService::SetExtensionsEnabled(bool enabled) {
- extensions_enabled_ = true;
- backend_loop_->PostTask(FROM_HERE, NewRunnableMethod(backend_.get(),
- &ExtensionsServiceBackend::set_extensions_enabled, enabled));
-}
-
void ExtensionsService::Init() {
DCHECK(extensions_.size() == 0);
@@ -365,14 +354,13 @@ void ExtensionsService::OnLoadedInstalledExtensions() {
void ExtensionsService::OnExtensionsLoaded(ExtensionList* new_extensions) {
scoped_ptr<ExtensionList> cleanup(new_extensions);
- // Filter out any extensions that shouldn't be loaded. Themes are always
- // loaded, but other extensions are only loaded if the extensions system is
- // enabled.
+ // Filter out any extensions we don't want to enable. Themes are always
+ // enabled, but other extensions are only loaded if --enable-extensions is
+ // present.
ExtensionList enabled_extensions;
for (ExtensionList::iterator iter = new_extensions->begin();
iter != new_extensions->end(); ++iter) {
- if (extensions_enabled() || (*iter)->IsTheme() ||
- (*iter)->location() == Extension::EXTERNAL_REGISTRY) {
+ if (extensions_enabled() || (*iter)->IsTheme()) {
Extension* old = GetExtensionById((*iter)->id());
if (old) {
if ((*iter)->version()->CompareTo(*(old->version())) > 0) {
@@ -463,14 +451,12 @@ void ExtensionsService::SetProviderForTesting(
ExtensionsServiceBackend::ExtensionsServiceBackend(
const FilePath& install_directory, ResourceDispatcherHost* rdh,
- MessageLoop* frontend_loop, DictionaryValue* extension_prefs,
- bool extensions_enabled)
+ MessageLoop* frontend_loop, DictionaryValue* extension_prefs)
: frontend_(NULL),
install_directory_(install_directory),
resource_dispatcher_host_(rdh),
alert_on_error_(false),
- frontend_loop_(frontend_loop),
- extensions_enabled_(extensions_enabled) {
+ frontend_loop_(frontend_loop) {
external_extension_providers_[Extension::EXTERNAL_PREF] =
linked_ptr<ExternalExtensionProvider>(
new ExternalPrefExtensionProvider(extension_prefs));
@@ -970,26 +956,28 @@ void ExtensionsServiceBackend::OnExtensionUnpacked(
return;
}
- Extension::Location location = Extension::INTERNAL;
- LookupExternalExtension(extension.id(), NULL, &location);
-
- // We currently only allow themes and registry-installed extensions to be
- // installed.
- if (!extensions_enabled_ &&
- !extension.IsTheme() &&
- location != Extension::EXTERNAL_REGISTRY) {
+ if (!frontend_->extensions_enabled() && !extension.IsTheme()) {
+#if defined(OS_WIN)
+ if (frontend_->show_extensions_prompts()) {
+ win_util::MessageBox(GetForegroundWindow(),
+ L"Extensions are not enabled. Add --enable-extensions to the "
+ L"command-line to enable extensions.\n\n"
+ L"This is a temporary message and it will be removed when extensions "
+ L"UI is finalized.",
+ l10n_util::GetString(IDS_PRODUCT_NAME).c_str(), MB_OK);
+ }
+#endif
ReportExtensionInstallError(extension_path,
- "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.");
+ "Extensions are not enabled.");
return;
}
+ Extension::Location location = Extension::INTERNAL;
+ LookupExternalExtension(extension.id(), NULL, &location);
#if defined(OS_WIN)
- // We don't show the install dialog for themes or external extensions.
- if (!extension.IsTheme() &&
- !Extension::IsExternalLocation(location) &&
+ bool from_external = Extension::IsExternalLocation(location);
+
+ if (!extension.IsTheme() && !from_external &&
frontend_->show_extensions_prompts() &&
win_util::MessageBox(GetForegroundWindow(),
L"Are you sure you want to install this extension?\n\n"
diff --git a/chrome/browser/extensions/extensions_service.h b/chrome/browser/extensions/extensions_service.h
index f4be29b..f2f0b56 100644
--- a/chrome/browser/extensions/extensions_service.h
+++ b/chrome/browser/extensions/extensions_service.h
@@ -10,7 +10,6 @@
#include <string>
#include <vector>
-#include "base/command_line.h"
#include "base/file_path.h"
#include "base/linked_ptr.h"
#include "base/ref_counted.h"
@@ -73,7 +72,6 @@ class ExtensionsService
};
ExtensionsService(Profile* profile,
- const CommandLine* command_line,
MessageLoop* frontend_loop,
MessageLoop* backend_loop);
~ExtensionsService();
@@ -134,13 +132,12 @@ class ExtensionsService
// The name of the file that the current active version number is stored in.
static const char* kCurrentVersionFileName;
- void SetExtensionsEnabled(bool enabled);
- bool extensions_enabled() { return extensions_enabled_; }
-
+ void set_extensions_enabled(bool enabled) { extensions_enabled_ = enabled; }
void set_show_extensions_prompts(bool enabled) {
show_extensions_prompts_ = enabled;
}
+ bool extensions_enabled() { return extensions_enabled_; }
bool show_extensions_prompts() {
return show_extensions_prompts_;
}
@@ -212,13 +209,10 @@ class ExtensionsServiceBackend
ExtensionsServiceBackend(const FilePath& install_directory,
ResourceDispatcherHost* rdh,
MessageLoop* frontend_loop,
- DictionaryValue* extension_prefs,
- bool extensions_enabled);
+ DictionaryValue* extension_prefs);
virtual ~ExtensionsServiceBackend();
- void set_extensions_enabled(bool enabled) { extensions_enabled_ = enabled; }
-
// Loads the installed extensions.
// Errors are reported through ExtensionErrorReporter. On completion,
// OnExtensionsLoaded() is called with any successfully loaded extensions.
@@ -405,10 +399,6 @@ class ExtensionsServiceBackend
// The message loop to use to call the frontend.
MessageLoop* frontend_loop_;
- // Whether non-theme extensions are enabled (themes and externally registered
- // extensions are always enabled).
- bool extensions_enabled_;
-
// A map of all external extension providers.
typedef std::map<Extension::Location,
linked_ptr<ExternalExtensionProvider> > ProviderMap;
diff --git a/chrome/browser/extensions/extensions_service_unittest.cc b/chrome/browser/extensions/extensions_service_unittest.cc
index 06d343c..e2dd984 100644
--- a/chrome/browser/extensions/extensions_service_unittest.cc
+++ b/chrome/browser/extensions/extensions_service_unittest.cc
@@ -5,7 +5,6 @@
#include <algorithm>
#include <vector>
-#include "base/command_line.h"
#include "base/file_path.h"
#include "base/file_util.h"
#include "base/json_reader.h"
@@ -25,7 +24,6 @@
#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"
@@ -132,9 +130,8 @@ class ExtensionsServiceTest
NotificationService::AllSources());
profile_.reset(new TestingProfile());
- service_ = new ExtensionsService(
- profile_.get(), CommandLine::ForCurrentProcess(), &loop_, &loop_);
- service_->SetExtensionsEnabled(true);
+ service_ = new ExtensionsService(profile_.get(), &loop_, &loop_);
+ service_->set_extensions_enabled(true);
service_->set_show_extensions_prompts(false);
// When we start up, we want to make sure there is no external provider,
@@ -194,7 +191,7 @@ class ExtensionsServiceTest
}
void SetExtensionsEnabled(bool enabled) {
- service_->SetExtensionsEnabled(enabled);
+ service_->set_extensions_enabled(enabled);
}
void SetMockExternalProvider(Extension::Location location,
@@ -501,6 +498,8 @@ TEST_F(ExtensionsServiceTest, InstallExtension) {
// Test Packaging and installing an extension.
// TODO(rafaelw): add more tests for failure cases.
TEST_F(ExtensionsServiceTest, PackExtension) {
+ SetExtensionsEnabled(true);
+
FilePath extensions_path;
ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path));
extensions_path = extensions_path.AppendASCII("extensions");
@@ -531,6 +530,8 @@ TEST_F(ExtensionsServiceTest, PackExtension) {
// The privkey.pem is a PrivateKey, and the pcks8 -topk8 creates a
// PrivateKeyInfo ASN.1 structure, we our RSAPrivateKey expects.
TEST_F(ExtensionsServiceTest, PackExtensionOpenSSLKey) {
+ SetExtensionsEnabled(true);
+
FilePath extensions_path;
ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path));
extensions_path = extensions_path.AppendASCII("extensions");
@@ -803,9 +804,6 @@ TEST_F(ExtensionsServiceTest, GenerateID) {
#if defined(OS_WIN)
TEST_F(ExtensionsServiceTest, ExternalInstallRegistry) {
- // This should all work, even when normal extension installation is disabled.
- SetExtensionsEnabled(false);
-
// Verify that starting with no providers loads no extensions.
service_->Init();
loop_.RunAllPending();
@@ -1015,41 +1013,4 @@ TEST_F(ExtensionsServiceTest, ExternalInstallPref) {
extension_path = extension_path.AppendASCII(good_crx);
EXPECT_FALSE(file_util::PathExists(extension_path)) <<
extension_path.ToWStringHack();
-
- // This shouldn't work if extensions are disabled.
- SetExtensionsEnabled(false);
-
- pref_provider->UpdateOrAddExtension(good_crx, "1.0", source_path);
- service_->CheckForUpdates();
- loop_.RunAllPending();
-
- 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 67e9810..179f506 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, CommandLine::ForCurrentProcess(), MessageLoop::current(),
+ this, MessageLoop::current(),
g_browser_process->file_thread()->message_loop());
extensions_service_->Init();
diff --git a/chrome/browser/renderer_host/browser_render_process_host.cc b/chrome/browser/renderer_host/browser_render_process_host.cc
index a865349..06405ed 100644
--- a/chrome/browser/renderer_host/browser_render_process_host.cc
+++ b/chrome/browser/renderer_host/browser_render_process_host.cc
@@ -30,7 +30,6 @@
#include "chrome/browser/browser_process.h"
#include "chrome/browser/child_process_security_policy.h"
#include "chrome/browser/extensions/extension_message_service.h"
-#include "chrome/browser/extensions/extensions_service.h"
#include "chrome/browser/extensions/user_script_master.h"
#include "chrome/browser/history/history.h"
#include "chrome/browser/plugin_service.h"
@@ -274,6 +273,7 @@ bool BrowserRenderProcessHost::Init() {
switches::kUseLowFragHeapCrt,
switches::kEnableWebWorkers,
switches::kEnableStatsTable,
+ switches::kEnableExtensions,
switches::kDisableOutOfProcessDevTools,
switches::kAutoSpellCorrect,
switches::kDisableAudio,
@@ -288,23 +288,6 @@ bool BrowserRenderProcessHost::Init() {
}
}
- // Tell the renderer to enable extensions if there are any extensions loaded.
- //
- // NOTE: This is subtly different than just passing along whether
- // --enable-extenisons is present in the browser process. For example, there
- // is also an extensions.enabled preference, and there may be various special
- // cases about whether to allow extensions to load.
- //
- // This introduces a race condition where the first renderer never gets
- // extensions enabled, so we also set the flag if extensions_enabled(). This
- // isn't perfect though, because of the special cases above.
- //
- // TODO(aa): We need to get rid of the need to pass this flag at all. It is
- // only used in one place in the renderer.
- if (profile()->GetExtensionsService()->extensions()->size() > 0 ||
- profile()->GetExtensionsService()->extensions_enabled())
- cmd_line.AppendSwitch(switches::kEnableExtensions);
-
// Pass on the browser locale.
const std::wstring locale = g_browser_process->GetApplicationLocale();
cmd_line.AppendSwitchWithValue(switches::kLang, locale);
diff --git a/chrome/browser/views/frame/browser_view.cc b/chrome/browser/views/frame/browser_view.cc
index d01ee94..8aa44b6 100644
--- a/chrome/browser/views/frame/browser_view.cc
+++ b/chrome/browser/views/frame/browser_view.cc
@@ -1402,8 +1402,11 @@ void BrowserView::Init() {
status_bubble_.reset(new StatusBubbleViews(GetWidget()));
- extension_shelf_ = new ExtensionShelf(browser_.get());
- AddChildView(extension_shelf_);
+ if (CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kEnableExtensions)) {
+ extension_shelf_ = new ExtensionShelf(browser_.get());
+ AddChildView(extension_shelf_);
+ }
#if defined(OS_WIN)
InitSystemMenu();