diff options
author | mpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-09 19:55:19 +0000 |
---|---|---|
committer | mpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-09 19:55:19 +0000 |
commit | e8c729aac97f4059a8bf7c2e880aceb9eb683e12 (patch) | |
tree | 0949a984c47c3184563b243bb77e9080d242ec50 | |
parent | 753efc479384c254e263fd11390846a060fa6ce0 (diff) | |
download | chromium_src-e8c729aac97f4059a8bf7c2e880aceb9eb683e12.zip chromium_src-e8c729aac97f4059a8bf7c2e880aceb9eb683e12.tar.gz chromium_src-e8c729aac97f4059a8bf7c2e880aceb9eb683e12.tar.bz2 |
Persistent "Load unpacked extension" extensions across browser restarts.
BUG=24850
Review URL: http://codereview.chromium.org/681001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@41068 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/extensions/extension_prefs.cc | 15 | ||||
-rw-r--r-- | chrome/browser/extensions/extensions_service.cc | 42 | ||||
-rw-r--r-- | chrome/browser/extensions/extensions_service.h | 3 | ||||
-rw-r--r-- | chrome/browser/extensions/extensions_service_unittest.cc | 6 |
4 files changed, 34 insertions, 32 deletions
diff --git a/chrome/browser/extensions/extension_prefs.cc b/chrome/browser/extensions/extension_prefs.cc index 388172d..10c5056 100644 --- a/chrome/browser/extensions/extension_prefs.cc +++ b/chrome/browser/extensions/extension_prefs.cc @@ -96,6 +96,12 @@ void ExtensionPrefs::MakePathsRelative() { DictionaryValue* extension_dict; if (!dict->GetDictionaryWithoutPathExpansion(*i, &extension_dict)) continue; + int location_value; + if (extension_dict->GetInteger(kPrefLocation, &location_value) && + location_value == Extension::LOAD) { + // Unpacked extensions can have absolute paths. + continue; + } FilePath::StringType path_string; if (!extension_dict->GetString(kPrefPath, &path_string)) continue; @@ -120,6 +126,12 @@ void ExtensionPrefs::MakePathsAbsolute(DictionaryValue* dict) { NOTREACHED(); continue; } + int location_value; + if (extension_dict->GetInteger(kPrefLocation, &location_value) && + location_value == Extension::LOAD) { + // Unpacked extensions will already have absolute paths. + continue; + } FilePath::StringType path_string; if (!extension_dict->GetString(kPrefPath, &path_string)) { if (!IsBlacklistBitSet(extension_dict)) { @@ -539,11 +551,12 @@ ExtensionPrefs::ExtensionsInfo* ExtensionPrefs::CollectExtensionsInfo( continue; } - // Only internal and external extensions can be installed permanently in the + // Only the following extension types can be installed permanently in the // preferences. Extension::Location location = static_cast<Extension::Location>(location_value); if (location != Extension::INTERNAL && + location != Extension::LOAD && !Extension::IsExternalLocation(location)) { NOTREACHED(); continue; diff --git a/chrome/browser/extensions/extensions_service.cc b/chrome/browser/extensions/extensions_service.cc index 128d7d3..b4373ec0 100644 --- a/chrome/browser/extensions/extensions_service.cc +++ b/chrome/browser/extensions/extensions_service.cc @@ -271,9 +271,7 @@ 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); + extension_prefs_->SetExtensionState(extension, Extension::ENABLED); // Move it over to the enabled list. extensions_.push_back(extension); @@ -295,9 +293,7 @@ void ExtensionsService::DisableExtension(const std::string& extension_id) { if (!extension) return; - // Remember that we disabled it, unless it's temporary. - if (extension->location() != Extension::LOAD) - extension_prefs_->SetExtensionState(extension, Extension::DISABLED); + extension_prefs_->SetExtensionState(extension, Extension::DISABLED); // Move it over to the disabled list. disabled_extensions_.push_back(extension); @@ -408,6 +404,11 @@ void ExtensionsService::ContinueLoadAllExtensions( if ((*ex)->location() == Extension::COMPONENT) continue; + // Don't count unpacked extensions, since they're a developer-specific + // feature. + if ((*ex)->location() == Extension::LOAD) + continue; + if ((*ex)->IsTheme()) { theme_count++; } else if ((*ex)->converted_from_user_script()) { @@ -440,7 +441,8 @@ void ExtensionsService::LoadInstalledExtension(const ExtensionInfo& info, Extension* extension = NULL; if (info.extension_manifest.get()) { scoped_ptr<Extension> tmp(new Extension(info.extension_path)); - if (tmp->InitFromValue(*info.extension_manifest, true, &error)) + bool require_key = info.extension_location != Extension::LOAD; + if (tmp->InitFromValue(*info.extension_manifest, require_key, &error)) extension = tmp.release(); } else { error = errors::kManifestUnreadable; @@ -745,15 +747,8 @@ void ExtensionsService::OnExtensionLoaded(Extension* extension, NotifyExtensionLoaded(extension); - if (extension->IsTheme() && extension->location() == Extension::LOAD) { - NotificationService::current()->Notify( - NotificationType::THEME_INSTALLED, - Source<Profile>(profile_), - Details<Extension>(extension)); - } else { - ExtensionDOMUI::RegisterChromeURLOverrides(profile_, - extension->GetChromeURLOverrides()); - } + ExtensionDOMUI::RegisterChromeURLOverrides(profile_, + extension->GetChromeURLOverrides()); break; case Extension::DISABLED: disabled_extensions_.push_back(scoped_extension.release()); @@ -1006,7 +1001,13 @@ void ExtensionsServiceBackend::LoadSingleExtension( } extension->set_location(Extension::LOAD); - ReportExtensionLoaded(extension); + + // Report this as an installed extension so that it gets remembered in the + // prefs. + ChromeThread::PostTask( + ChromeThread::UI, FROM_HERE, + NewRunnableMethod(frontend_, &ExtensionsService::OnExtensionInstalled, + extension, true)); } void ExtensionsServiceBackend::ReportExtensionLoadError( @@ -1019,13 +1020,6 @@ void ExtensionsServiceBackend::ReportExtensionLoadError( error, NotificationType::EXTENSION_INSTALL_ERROR, alert_on_error_)); } -void ExtensionsServiceBackend::ReportExtensionLoaded(Extension* extension) { - ChromeThread::PostTask( - ChromeThread::UI, FROM_HERE, - NewRunnableMethod( - frontend_, &ExtensionsService::OnExtensionLoaded, extension, true)); -} - bool ExtensionsServiceBackend::LookupExternalExtension( const std::string& id, Version** version, Extension::Location* location) { scoped_ptr<Version> extension_version; diff --git a/chrome/browser/extensions/extensions_service.h b/chrome/browser/extensions/extensions_service.h index 6501824..ef7678f 100644 --- a/chrome/browser/extensions/extensions_service.h +++ b/chrome/browser/extensions/extensions_service.h @@ -436,9 +436,6 @@ class ExtensionsServiceBackend void ReportExtensionLoadError(const FilePath& extension_path, const std::string& error); - // Notify the frontend that an extension was loaded. - void ReportExtensionLoaded(Extension* extension); - // Lookup an external extension by |id| by going through all registered // external extension providers until we find a provider that contains an // extension that matches. If |version| is not NULL, the extension version diff --git a/chrome/browser/extensions/extensions_service_unittest.cc b/chrome/browser/extensions/extensions_service_unittest.cc index eb2520a..e866d26 100644 --- a/chrome/browser/extensions/extensions_service_unittest.cc +++ b/chrome/browser/extensions/extensions_service_unittest.cc @@ -1277,8 +1277,7 @@ TEST_F(ExtensionsServiceTest, LoadExtension) { EXPECT_EQ(Extension::LOAD, loaded_[0]->location()); EXPECT_EQ(1u, service_->extensions()->size()); - // --load-extension doesn't add entries to prefs - ValidatePrefKeyCount(0); + ValidatePrefKeyCount(1); FilePath no_manifest = extensions_path .AppendASCII("bad") @@ -1318,8 +1317,7 @@ TEST_F(ExtensionsServiceTest, GenerateID) { ASSERT_TRUE(Extension::IdIsValid(loaded_[0]->id())); EXPECT_EQ(loaded_[0]->location(), Extension::LOAD); - // --load-extension doesn't add entries to prefs - ValidatePrefKeyCount(0); + ValidatePrefKeyCount(1); std::string previous_id = loaded_[0]->id(); |