diff options
-rw-r--r-- | chrome/browser/extensions/crx_installer.cc | 2 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_browsertest.cc | 2 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_prefs.cc | 19 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_prefs.h | 6 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_prefs_unittest.cc | 9 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_service.cc | 16 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_service.h | 8 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_service_unittest.cc | 37 | ||||
-rw-r--r-- | chrome/browser/extensions/test_extension_prefs.cc | 2 | ||||
-rw-r--r-- | chrome/test/live_sync/live_sync_extension_helper.cc | 3 |
10 files changed, 88 insertions, 16 deletions
diff --git a/chrome/browser/extensions/crx_installer.cc b/chrome/browser/extensions/crx_installer.cc index 3581571..2c6042f 100644 --- a/chrome/browser/extensions/crx_installer.cc +++ b/chrome/browser/extensions/crx_installer.cc @@ -556,7 +556,7 @@ void CrxInstaller::ReportSuccessFromUIThread() { // Tell the frontend about the installation and hand off ownership of // extension_ to it. - frontend_weak_->OnExtensionInstalled(extension_); + frontend_weak_->OnExtensionInstalled(extension_, is_gallery_install()); extension_ = NULL; NotifyCrxInstallComplete(); diff --git a/chrome/browser/extensions/extension_browsertest.cc b/chrome/browser/extensions/extension_browsertest.cc index 540b8e3..54a715e 100644 --- a/chrome/browser/extensions/extension_browsertest.cc +++ b/chrome/browser/extensions/extension_browsertest.cc @@ -90,7 +90,7 @@ const Extension* ExtensionBrowserTest::LoadExtensionImpl( // The call to OnExtensionInstalled ensures the other extension prefs // are set up with the defaults. service->extension_prefs()->OnExtensionInstalled( - extension, Extension::ENABLED); + extension, Extension::ENABLED, false); service->SetIsIncognitoEnabled(extension_id, incognito_enabled); ui_test_utils::WindowedNotificationObserver extension_loaded_signal( diff --git a/chrome/browser/extensions/extension_prefs.cc b/chrome/browser/extensions/extension_prefs.cc index 4a1dd2c..f47b451 100644 --- a/chrome/browser/extensions/extension_prefs.cc +++ b/chrome/browser/extensions/extension_prefs.cc @@ -116,6 +116,10 @@ const char kPrefOldGrantedAPIs[] = "granted_permissions.api"; // A preference that indicates when an extension was installed. const char kPrefInstallTime[] = "install_time"; +// A preference that indicates whether the extension was installed from the +// Chrome Web Store. +const char kPrefFromWebStore[] = "from_webstore"; + // A preference that contains any extension-controlled preferences. const char kPrefPreferences[] = "preferences"; @@ -881,7 +885,9 @@ void ExtensionPrefs::SetToolbarOrder( } void ExtensionPrefs::OnExtensionInstalled( - const Extension* extension, Extension::State initial_state) { + const Extension* extension, + Extension::State initial_state, + bool from_webstore) { const std::string& id = extension->id(); CHECK(Extension::IdIsValid(id)); ScopedExtensionPrefUpdate update(prefs_, id); @@ -890,6 +896,8 @@ void ExtensionPrefs::OnExtensionInstalled( extension_dict->Set(kPrefState, Value::CreateIntegerValue(initial_state)); extension_dict->Set(kPrefLocation, Value::CreateIntegerValue(extension->location())); + extension_dict->Set(kPrefFromWebStore, + Value::CreateBooleanValue(from_webstore)); extension_dict->Set(kPrefInstallTime, Value::CreateStringValue( base::Int64ToString(install_time.ToInternalValue()))); @@ -1349,6 +1357,15 @@ void ExtensionPrefs::OnContentSettingChanged( } } +bool ExtensionPrefs::IsFromWebStore( + const std::string& extension_id) const { + const DictionaryValue* dictionary = GetExtensionPref(extension_id); + bool result = false; + if (dictionary && dictionary->GetBoolean(kPrefFromWebStore, &result)) + return result; + return false; +} + base::Time ExtensionPrefs::GetInstallTime( const std::string& extension_id) const { const DictionaryValue* extension = GetExtensionPref(extension_id); diff --git a/chrome/browser/extensions/extension_prefs.h b/chrome/browser/extensions/extension_prefs.h index a5fbbb1..6e25c5b 100644 --- a/chrome/browser/extensions/extension_prefs.h +++ b/chrome/browser/extensions/extension_prefs.h @@ -97,7 +97,8 @@ class ExtensionPrefs : public ExtensionContentSettingsStore::Observer { // Called when an extension is installed, so that prefs get created. void OnExtensionInstalled(const Extension* extension, - Extension::State initial_state); + Extension::State initial_state, + bool from_webstore); // Called when an extension is uninstalled, so that prefs get cleaned up. void OnExtensionUninstalled(const std::string& extension_id, @@ -322,6 +323,9 @@ class ExtensionPrefs : public ExtensionContentSettingsStore::Observer { // Clears incognito session-only content settings for all extensions. void ClearIncognitoSessionOnlyContentSettings(); + // Returns true if the extension was installed from the Chrome Web Store. + bool IsFromWebStore(const std::string& extension_id) const; + // Helper method to acquire the installation time of an extension. // Returns base::Time() if the installation time could not be parsed or // found. diff --git a/chrome/browser/extensions/extension_prefs_unittest.cc b/chrome/browser/extensions/extension_prefs_unittest.cc index 31f86d1..c502e49 100644 --- a/chrome/browser/extensions/extension_prefs_unittest.cc +++ b/chrome/browser/extensions/extension_prefs_unittest.cc @@ -545,7 +545,8 @@ class ExtensionPrefsOnExtensionInstalled : public ExtensionPrefsTest { extension_ = prefs_.AddExtension("on_extension_installed"); EXPECT_EQ(Extension::ENABLED, prefs()->GetExtensionState(extension_->id())); - prefs()->OnExtensionInstalled(extension_.get(), Extension::DISABLED); + prefs()->OnExtensionInstalled( + extension_.get(), Extension::DISABLED, false); } virtual void Verify() { @@ -568,7 +569,7 @@ class ExtensionPrefsAppLaunchIndex : public ExtensionPrefsTest { extension_ = prefs_.AddExtension("on_extension_installed"); EXPECT_EQ(Extension::ENABLED, prefs()->GetExtensionState(extension_->id())); - prefs()->OnExtensionInstalled(extension_.get(), Extension::ENABLED); + prefs()->OnExtensionInstalled(extension_.get(), Extension::ENABLED, false); } virtual void Verify() { @@ -623,7 +624,7 @@ class ExtensionPrefsAppDraggedByUser : public ExtensionPrefsTest { virtual void Initialize() { extension_ = prefs_.AddExtension("on_extension_installed"); EXPECT_FALSE(prefs()->WasAppDraggedByUser(extension_->id())); - prefs()->OnExtensionInstalled(extension_.get(), Extension::ENABLED); + prefs()->OnExtensionInstalled(extension_.get(), Extension::ENABLED, false); } virtual void Verify() { @@ -737,7 +738,7 @@ class ExtensionPrefsPreferencesBase : public ExtensionPrefsTest { Extension* extensions[] = {ext1_, ext2_, ext3_}; for (int i = 0; i < 3; ++i) { if (ext == extensions[i] && !installed[i]) { - prefs()->OnExtensionInstalled(ext, Extension::ENABLED); + prefs()->OnExtensionInstalled(ext, Extension::ENABLED, false); installed[i] = true; break; } diff --git a/chrome/browser/extensions/extension_service.cc b/chrome/browser/extensions/extension_service.cc index 8449ce3..a786653 100644 --- a/chrome/browser/extensions/extension_service.cc +++ b/chrome/browser/extensions/extension_service.cc @@ -183,7 +183,8 @@ void SimpleExtensionLoadPrompt::ShowPrompt() { void SimpleExtensionLoadPrompt::InstallUIProceed() { if (extension_service_.get()) - extension_service_->OnExtensionInstalled(extension_); + extension_service_->OnExtensionInstalled( + extension_, false); // Not from web store. delete this; } @@ -468,6 +469,10 @@ bool ExtensionService::IsDownloadFromGallery(const GURL& download_url, return (referrer_valid && download_valid); } +bool ExtensionService::IsFromWebStore(const std::string& id) const { + return extension_prefs_->IsFromWebStore(id); +} + bool ExtensionService::IsDownloadFromMiniGallery(const GURL& download_url) { return StartsWithASCII(download_url.spec(), extension_urls::kMiniGalleryDownloadPrefix, @@ -2021,10 +2026,11 @@ void ExtensionService::OnLoadSingleExtension(const Extension* extension) { prompt->ShowPrompt(); return; // continues in SimpleExtensionLoadPrompt::InstallUI* } - OnExtensionInstalled(extension); + OnExtensionInstalled(extension, false); // Not from web store. } -void ExtensionService::OnExtensionInstalled(const Extension* extension) { +void ExtensionService::OnExtensionInstalled( + const Extension* extension, bool from_webstore) { CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); // Ensure extension is deleted unless we transfer ownership. @@ -2076,7 +2082,9 @@ void ExtensionService::OnExtensionInstalled(const Extension* extension) { ShownSectionsHandler::OnExtensionInstalled(profile_->GetPrefs(), extension); extension_prefs_->OnExtensionInstalled( - extension, initial_enable ? Extension::ENABLED : Extension::DISABLED); + extension, + initial_enable ? Extension::ENABLED : Extension::DISABLED, + from_webstore); // Unpacked extensions default to allowing file access, but if that has been // overridden, don't reset the value. diff --git a/chrome/browser/extensions/extension_service.h b/chrome/browser/extensions/extension_service.h index d8c84c9..99c576e 100644 --- a/chrome/browser/extensions/extension_service.h +++ b/chrome/browser/extensions/extension_service.h @@ -166,6 +166,9 @@ class ExtensionService bool IsDownloadFromGallery(const GURL& download_url, const GURL& referrer_url); + // Returns true if the extension was installed from the web store. + bool IsFromWebStore(const std::string& id) const; + // Determine if the downloaded extension came from the theme mini-gallery, // Used to test if we need to show the "Loading" dialog for themes. static bool IsDownloadFromMiniGallery(const GURL& download_url); @@ -397,7 +400,8 @@ class ExtensionService void OnLoadSingleExtension(const Extension* extension); // Called by the backend when an extension has been installed. - void OnExtensionInstalled(const Extension* extension); + void OnExtensionInstalled( + const Extension* extension, bool from_webstore); // Checks if the privileges requested by |extension| have increased, and if // so, disables the extension and prompts the user to approve the change. @@ -406,7 +410,7 @@ class ExtensionService // Go through each extensions in pref, unload blacklisted extensions // and update the blacklist state in pref. virtual void UpdateExtensionBlacklist( - const std::vector<std::string>& blacklist) OVERRIDE; + const std::vector<std::string>& blacklist) OVERRIDE; // Go through each extension and unload those that the network admin has // put on the blacklist (not to be confused with the Google managed blacklist diff --git a/chrome/browser/extensions/extension_service_unittest.cc b/chrome/browser/extensions/extension_service_unittest.cc index 2bac463..3a2b05d 100644 --- a/chrome/browser/extensions/extension_service_unittest.cc +++ b/chrome/browser/extensions/extension_service_unittest.cc @@ -582,11 +582,16 @@ class ExtensionServiceTest // method directly. Instead, use InstallCrx(), which waits for // the crx to be installed and does extra error checking. void StartCrxInstall(const FilePath& crx_path) { + StartCrxInstall(crx_path, false); + } + + void StartCrxInstall(const FilePath& crx_path, bool from_webstore) { ASSERT_TRUE(file_util::PathExists(crx_path)) << "Path does not exist: "<< crx_path.value().c_str(); scoped_refptr<CrxInstaller> installer( service_->MakeCrxInstaller(NULL)); installer->set_allow_silent_install(true); + installer->set_is_gallery_install(from_webstore); installer->InstallCrx(crx_path); } @@ -1912,6 +1917,38 @@ TEST_F(ExtensionServiceTest, Reinstall) { ValidateIntegerPref(good_crx, "location", Extension::INTERNAL); } +// Test that extension prefs remember if .crx came from web store. +TEST_F(ExtensionServiceTest, FromWebStore) { + InitializeEmptyExtensionService(); + + // A simple extension that should install without error. + FilePath path = data_dir_.AppendASCII("good.crx"); + StartCrxInstall(path, false); // Not from web store. + loop_.RunAllPending(); + + ASSERT_TRUE(installed_); + ASSERT_EQ(1u, loaded_.size()); + ASSERT_EQ(0u, GetErrors().size()); + ValidatePrefKeyCount(1); + ValidateBooleanPref(good_crx, "from_webstore", false); + ASSERT_FALSE(service_->IsFromWebStore(good_crx)); + + installed_ = NULL; + loaded_.clear(); + ExtensionErrorReporter::GetInstance()->ClearErrors(); + + // Test install from web store. + StartCrxInstall(path, true); // From web store. + loop_.RunAllPending(); + + ASSERT_TRUE(installed_); + ASSERT_EQ(1u, loaded_.size()); + ASSERT_EQ(0u, GetErrors().size()); + ValidatePrefKeyCount(1); + ValidateBooleanPref(good_crx, "from_webstore", true); + ASSERT_TRUE(service_->IsFromWebStore(good_crx)); +} + // Test upgrading a signed extension. TEST_F(ExtensionServiceTest, UpgradeSignedGood) { InitializeEmptyExtensionService(); diff --git a/chrome/browser/extensions/test_extension_prefs.cc b/chrome/browser/extensions/test_extension_prefs.cc index 3fbe89b..00d9682 100644 --- a/chrome/browser/extensions/test_extension_prefs.cc +++ b/chrome/browser/extensions/test_extension_prefs.cc @@ -114,7 +114,7 @@ scoped_refptr<Extension> TestExtensionPrefs::AddExtensionWithManifest( return NULL; EXPECT_TRUE(Extension::IdIsValid(extension->id())); - prefs_->OnExtensionInstalled(extension, Extension::ENABLED); + prefs_->OnExtensionInstalled(extension, Extension::ENABLED, false); return extension; } diff --git a/chrome/test/live_sync/live_sync_extension_helper.cc b/chrome/test/live_sync/live_sync_extension_helper.cc index c5772c3..c58251b 100644 --- a/chrome/test/live_sync/live_sync_extension_helper.cc +++ b/chrome/test/live_sync/live_sync_extension_helper.cc @@ -50,7 +50,8 @@ void LiveSyncExtensionHelper::InstallExtension( scoped_refptr<Extension> extension = GetExtension(profile, name, type); ASSERT_TRUE(extension.get()) << "Could not get extension " << name << " (profile = " << profile << ")"; - profile->GetExtensionService()->OnExtensionInstalled(extension); + profile->GetExtensionService()->OnExtensionInstalled( + extension, extension->UpdatesFromGallery()); } void LiveSyncExtensionHelper::UninstallExtension( |