The change has the followings:
1. Auto-updating of extension blacklist.
2. Handle extensions in the blacklist. If an extension is in the blacklist,
a. browser will not load the extension at start time;
b. browser will unload the extension at running time;
c. browser will not install the extension;
BUG=12118
TEST=Verify behavior described above works (they should be covered in the unittests in this change).
Review URL: http://codereview.chromium.org/165164
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@23423 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/chrome/browser/extensions/extensions_service.cc b/chrome/browser/extensions/extensions_service.cc
index 1b83a61..70fa3dbd 100644
--- a/chrome/browser/extensions/extensions_service.cc
+++ b/chrome/browser/extensions/extensions_service.cc
@@ -63,10 +63,11 @@
show_extensions_prompts_(true),
ready_(false) {
// Figure out if extension installation should be enabled.
- if (command_line->HasSwitch(switches::kEnableExtensions))
+ if (command_line->HasSwitch(switches::kEnableExtensions)) {
extensions_enabled_ = true;
- else if (profile->GetPrefs()->GetBoolean(prefs::kEnableExtensions))
+ } else if (profile->GetPrefs()->GetBoolean(prefs::kEnableExtensions)) {
extensions_enabled_ = true;
+ }
// Set up the ExtensionUpdater
if (autoupdate_enabled) {
@@ -172,6 +173,33 @@
new InstalledExtensions(extension_prefs_.get())));
}
+void ExtensionsService::UpdateExtensionBlacklist(
+ const std::vector<std::string>& blacklist) {
+ // Use this set to indicate if an extension in the blacklist has been used.
+ std::set<std::string> blacklist_set;
+ for (unsigned int i = 0; i < blacklist.size(); ++i) {
+ if (Extension::IdIsValid(blacklist[i])) {
+ blacklist_set.insert(blacklist[i]);
+ }
+ }
+ extension_prefs_->UpdateBlacklist(blacklist_set);
+ std::vector<std::string> to_be_removed;
+ // Loop current extensions, unload installed extensions.
+ for (ExtensionList::const_iterator iter = extensions_.begin();
+ iter != extensions_.end(); ++iter) {
+ Extension* extension = (*iter);
+ if (blacklist_set.find(extension->id()) != blacklist_set.end()) {
+ to_be_removed.push_back(extension->id());
+ }
+ }
+
+ // UnloadExtension will change the extensions_ list. So, we should
+ // call it outside the iterator loop.
+ for (unsigned int i = 0; i < to_be_removed.size(); ++i) {
+ UnloadExtension(to_be_removed[i]);
+ }
+}
+
void ExtensionsService::CheckForExternalUpdates() {
// This installs or updates externally provided extensions.
// TODO(aa): Why pass this list into the provider, why not just filter it