diff options
Diffstat (limited to 'chrome')
6 files changed, 72 insertions, 11 deletions
diff --git a/chrome/browser/extensions/extension_disabled_infobar_delegate.cc b/chrome/browser/extensions/extension_disabled_infobar_delegate.cc index feaa264..c95c2bb 100644 --- a/chrome/browser/extensions/extension_disabled_infobar_delegate.cc +++ b/chrome/browser/extensions/extension_disabled_infobar_delegate.cc @@ -38,6 +38,8 @@ class ExtensionDisabledDialogDelegate // ExtensionInstallUI::Delegate virtual void InstallUIProceed() { + ExtensionPrefs* prefs = service_->extension_prefs(); + prefs->SetShowInstallWarningOnEnable(extension_, false); service_->EnableExtension(extension_->id()); Release(); } @@ -157,3 +159,9 @@ void ShowExtensionDisabledUI(ExtensionsService* service, Profile* profile, tab_contents->AddInfoBar(new ExtensionDisabledInfobarDelegate( tab_contents, service, extension)); } + +void ShowExtensionDisabledDialog(ExtensionsService* service, Profile* profile, + Extension* extension) { + // This object manages its own lifetime. + new ExtensionDisabledDialogDelegate(profile, service, extension); +} diff --git a/chrome/browser/extensions/extension_disabled_infobar_delegate.h b/chrome/browser/extensions/extension_disabled_infobar_delegate.h index 0c66ce9..25efd3f 100644 --- a/chrome/browser/extensions/extension_disabled_infobar_delegate.h +++ b/chrome/browser/extensions/extension_disabled_infobar_delegate.h @@ -16,4 +16,8 @@ class Profile; void ShowExtensionDisabledUI(ExtensionsService* service, Profile* profile, Extension* extension); +// Shows the extension install dialog. +void ShowExtensionDisabledDialog(ExtensionsService* service, Profile* profile, + Extension* extension); + #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_DISABLED_INFOBAR_DELEGATE_H_ diff --git a/chrome/browser/extensions/extension_prefs.cc b/chrome/browser/extensions/extension_prefs.cc index d3d8b87..e835f32 100644 --- a/chrome/browser/extensions/extension_prefs.cc +++ b/chrome/browser/extensions/extension_prefs.cc @@ -33,6 +33,9 @@ const wchar_t kPrefVersion[] = L"manifest.version"; // Indicates if an extension is blacklisted: const wchar_t kPrefBlacklist[] = L"blacklist"; +// Indicates whether to show an install warning when the user enables. +const wchar_t kShowInstallWarning[] = L"install_warning_on_enable"; + // A preference that tracks extension shelf configuration. This is a list // object read from the Preferences file, containing a list of toolstrip URLs. const wchar_t kExtensionShelf[] = L"extensions.shelf"; @@ -133,19 +136,20 @@ DictionaryValue* ExtensionPrefs::CopyCurrentExtensions() { return new DictionaryValue; } -bool ExtensionPrefs::IsBlacklistBitSet(DictionaryValue* ext) { - if (!ext->HasKey(kPrefBlacklist)) return false; - bool is_blacklisted = false; - if (!ext->GetBoolean(kPrefBlacklist, &is_blacklisted)) { - NOTREACHED() << "Failed to fetch blacklist flag."; - // In case we could not fetch the flag, we consider the extension - // is NOT blacklisted. +bool ExtensionPrefs::ReadBooleanFromPref( + DictionaryValue* ext, const std::wstring& pref_key) { + if (!ext->HasKey(pref_key)) return false; + bool bool_value = false; + if (!ext->GetBoolean(pref_key, &bool_value)) { + NOTREACHED() << "Failed to fetch " << pref_key << " flag."; + // In case we could not fetch the flag, we treat it as false. return false; } - return is_blacklisted; + return bool_value; } -bool ExtensionPrefs::IsExtensionBlacklisted(const std::string& extension_id) { +bool ExtensionPrefs::ReadExtensionPrefBoolean( + const std::string& extension_id, const std::wstring& pref_key) { const DictionaryValue* extensions = prefs_->GetDictionary(kExtensionsPref); DCHECK(extensions); @@ -159,7 +163,20 @@ bool ExtensionPrefs::IsExtensionBlacklisted(const std::string& extension_id) { // No such extension yet. return false; } - return IsBlacklistBitSet(ext); + return ReadBooleanFromPref(ext, pref_key); +} + +bool ExtensionPrefs::IsBlacklistBitSet(DictionaryValue* ext) { + return ReadBooleanFromPref(ext, kPrefBlacklist); +} + +bool ExtensionPrefs::IsExtensionBlacklisted(const std::string& extension_id) { + return ReadExtensionPrefBoolean(extension_id, kExtensionsPref); +} + +bool ExtensionPrefs::DidExtensionEscalatePermissions( + const std::string& extension_id) { + return ReadExtensionPrefBoolean(extension_id, kShowInstallWarning); } void ExtensionPrefs::UpdateBlacklist( @@ -351,6 +368,13 @@ void ExtensionPrefs::SetExtensionState(Extension* extension, prefs_->SavePersistentPrefs(); } +void ExtensionPrefs::SetShowInstallWarningOnEnable( + Extension* extension, bool require) { + UpdateExtensionPref(extension->id(), kShowInstallWarning, + Value::CreateBooleanValue(require)); + prefs_->SavePersistentPrefs(); +} + std::string ExtensionPrefs::GetVersionString(const std::string& extension_id) { DictionaryValue* extension = GetExtensionPref(extension_id); if (!extension) diff --git a/chrome/browser/extensions/extension_prefs.h b/chrome/browser/extensions/extension_prefs.h index 0488545..e976b53 100644 --- a/chrome/browser/extensions/extension_prefs.h +++ b/chrome/browser/extensions/extension_prefs.h @@ -58,6 +58,10 @@ class ExtensionPrefs { // Called to change the extension's state when it is enabled/disabled. void SetExtensionState(Extension* extension, Extension::State); + // If |require| is true, the preferences for |extension| will be set to + // require the install warning when the user tries to enable. + void SetShowInstallWarningOnEnable(Extension* extension, bool require); + // Returns the version string for the currently installed extension, or // the empty string if not found. std::string GetVersionString(const std::string& extension_id); @@ -78,6 +82,9 @@ class ExtensionPrefs { // Based on extension id, checks prefs to see if it is blacklisted. bool IsExtensionBlacklisted(const std::string& id); + // Did the extension ask to escalate its permission during an upgrade? + bool DidExtensionEscalatePermissions(const std::string& id); + // Saves ExtensionInfo for each installed extension with the path to the // version directory and the location. Blacklisted extensions won't be saved // and neither will external extensions the user has explicitly uninstalled. @@ -102,6 +109,14 @@ class ExtensionPrefs { // Deletes the pref dictionary for extension |id|. void DeleteExtensionPrefs(const std::string& id); + // Reads a boolean pref from |ext| with key |pref_key|. + // Return false if the value is false or kPrefBlacklist does not exist. + bool ReadBooleanFromPref(DictionaryValue* ext, const std::wstring& pref_key); + + // Reads a boolean pref |pref_key| from extension with id |extension_id|. + bool ReadExtensionPrefBoolean(const std::string& extension_id, + const std::wstring& pref_key); + // Ensures and returns a mutable dictionary for extension |id|'s prefs. DictionaryValue* GetOrCreateExtensionPref(const std::string& id); diff --git a/chrome/browser/extensions/extensions_service.cc b/chrome/browser/extensions/extensions_service.cc index ae251f7..e64956a 100644 --- a/chrome/browser/extensions/extensions_service.cc +++ b/chrome/browser/extensions/extensions_service.cc @@ -620,6 +620,7 @@ void ExtensionsService::OnExtensionLoaded(Extension* extension, // Extension has changed permissions significantly. Disable it. We // send a notification below. extension_prefs_->SetExtensionState(extension, Extension::DISABLED); + extension_prefs_->SetShowInstallWarningOnEnable(extension, true); } } else { // We already have the extension of the same or older version. diff --git a/chrome/browser/extensions/extensions_ui.cc b/chrome/browser/extensions/extensions_ui.cc index 950b9b4..eadeafe 100644 --- a/chrome/browser/extensions/extensions_ui.cc +++ b/chrome/browser/extensions/extensions_ui.cc @@ -17,6 +17,7 @@ #include "chrome/browser/browser_process.h" #include "chrome/browser/debugger/devtools_manager.h" #include "chrome/browser/extensions/crx_installer.h" +#include "chrome/browser/extensions/extension_disabled_infobar_delegate.h" #include "chrome/browser/extensions/extension_function_dispatcher.h" #include "chrome/browser/extensions/extension_message_service.h" #include "chrome/browser/extensions/extensions_service.h" @@ -386,7 +387,15 @@ void ExtensionsDOMHandler::HandleEnableMessage(const Value* value) { CHECK(list->GetString(0, &extension_id)); CHECK(list->GetString(1, &enable_str)); if (enable_str == "true") { - extensions_service_->EnableExtension(extension_id); + ExtensionPrefs* prefs = extensions_service_->extension_prefs(); + if (prefs->DidExtensionEscalatePermissions(extension_id)) { + Extension* extension = + extensions_service_->GetExtensionById(extension_id, true); + ShowExtensionDisabledDialog(extensions_service_, + dom_ui_->GetProfile(), extension); + } else { + extensions_service_->EnableExtension(extension_id); + } } else { extensions_service_->DisableExtension(extension_id); } |