Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(490)

Unified Diff: chrome/browser/extensions/extensions_service.cc

Issue 4687005: Track permissions granted to extensions in prefs (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 10 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/extensions_service.cc
diff --git a/chrome/browser/extensions/extensions_service.cc b/chrome/browser/extensions/extensions_service.cc
index f58f5daacfb04b9ee9ff255c010948c5ed34c5b0..365de8adefa0aaec255323f061ecbd6501167622 100644
--- a/chrome/browser/extensions/extensions_service.cc
+++ b/chrome/browser/extensions/extensions_service.cc
@@ -951,6 +951,25 @@ void ExtensionsService::DisableExtension(const std::string& extension_id) {
UpdateActiveExtensionsInCrashReporter();
}
+void ExtensionsService::GrantPermissions(const Extension* extension) {
+ DCHECK(extension);
+
+ std::set<std::string> effective_hosts;
+ extension->GetEffectiveHostPermissions().GetAsStringSet(&effective_hosts);
+
+ extension_prefs_->GrantPermissions(extension->id(),
+ extension->api_permissions(),
+ effective_hosts);
+}
+
+void ExtensionsService::GrantPermissionsAndEnableExtension(
+ const Extension* extension) {
+ DCHECK(extension);
+ GrantPermissions(extension);
+ extension_prefs_->SetDidExtensionEscalatePermissions(extension, false);
+ EnableExtension(extension->id());
+}
+
void ExtensionsService::LoadExtension(const FilePath& extension_path) {
BrowserThread::PostTask(
BrowserThread::FILE, FROM_HERE,
@@ -1135,9 +1154,10 @@ void ExtensionsService::LoadInstalledExtension(const ExtensionInfo& info,
if (write_to_prefs)
extension_prefs_->UpdateManifest(extension);
- OnExtensionLoaded(extension, true);
-
+ // External extensions are allowed to increase their privileges without
+ // prompting users.
if (Extension::IsExternalLocation(info.extension_location)) {
+ OnExtensionLoaded(extension, true);
BrowserThread::PostTask(
BrowserThread::FILE, FROM_HERE,
NewRunnableMethod(
@@ -1145,6 +1165,8 @@ void ExtensionsService::LoadInstalledExtension(const ExtensionInfo& info,
&ExtensionsServiceBackend::CheckExternalUninstall,
scoped_refptr<ExtensionsService>(this),
info.extension_id));
+ } else {
+ OnExtensionLoaded(extension, false);
}
}
@@ -1528,6 +1550,32 @@ void ExtensionsService::OnExtensionLoaded(const Extension* extension,
}
}
+ // For gracefully handling backwards compatibility, extensions are allowed
+ // to have unknown permissions in their manifest. We keep track of the last
+ // known set of permissions, so that we can prompt the user when unknown
Aaron Boodman 2010/11/12 00:05:24 It might be nice to include a little example here
jstritar 2010/11/19 21:38:36 I updated the comment to make more sense and added
+ // permissions become known.
+ if (extension->location() == Extension::INTERNAL) {
+ std::set<std::string> granted_apis;
+ std::set<std::string> granted_hosts;
+
+ // If the granted permissions list hasn't been initialized yet (such
+ // as when migrating from the old scheme) or privilege increases are
+ // allowed, then just grant all recognized permissions.
+ if (!extension_prefs_->GetGrantedPermissions(extension->id(),
+ &granted_apis,
+ &granted_hosts) ||
+ allow_privilege_increase) {
+ GrantPermissions(extension);
+
+ // Here, we disable the extension and prompt the user if the unknown
+ // permissions are now recognized.
+ } else if (Extension::IsPrivilegeIncrease(
+ &granted_apis, &granted_hosts, extension)) {
+ extension_prefs_->SetExtensionState(extension, Extension::DISABLED);
+ extension_prefs_->SetDidExtensionEscalatePermissions(extension, true);
+ }
+ }
+
switch (extension_prefs_->GetExtensionState(extension->id())) {
case Extension::ENABLED:
extensions_.push_back(scoped_extension);

Powered by Google App Engine
This is Rietveld 408576698