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

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

Issue 874683005: [Extensions] Enable the scripts-require-action feature based on all-urls pref (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Updated metrics Created 5 years, 10 months 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
« no previous file with comments | « chrome/browser/extensions/extension_util.h ('k') | chrome/browser/extensions/permissions_updater.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/extensions/extension_util.cc
diff --git a/chrome/browser/extensions/extension_util.cc b/chrome/browser/extensions/extension_util.cc
index b07ab1ca1aacc30643ac3faecddc0baa1e75c4e3..845a4db8fa7b791c4fb11020bf33af89ed4fc60b 100644
--- a/chrome/browser/extensions/extension_util.cc
+++ b/chrome/browser/extensions/extension_util.cc
@@ -70,6 +70,35 @@ std::string ReloadExtensionIfEnabled(const std::string& extension_id,
return id;
}
+// Sets the preference for scripting on all urls to |allowed|, optionally
+// updating the extension's active permissions (based on |update_permissions|).
+void SetAllowedScriptingOnAllUrlsHelper(
+ content::BrowserContext* context,
+ const std::string& extension_id,
+ bool allowed,
+ bool update_permissions) {
+ // TODO(devlin): Right now, we always need to have a value for this pref.
+ // Once the scripts-require-action feature launches, we can change the set
+ // to be null if false.
+ ExtensionPrefs::Get(context)->UpdateExtensionPref(
+ extension_id,
+ kExtensionAllowedOnAllUrlsPrefName,
+ new base::FundamentalValue(allowed));
+
+ if (update_permissions) {
+ const Extension* extension =
+ ExtensionRegistry::Get(context)->enabled_extensions().GetByID(
+ extension_id);
+ if (extension) {
+ PermissionsUpdater updater(context);
+ if (allowed)
+ updater.GrantWithheldImpliedAllHosts(extension);
+ else
+ updater.WithholdImpliedAllHosts(extension);
+ }
+ }
+}
+
} // namespace
bool IsIncognitoEnabled(const std::string& extension_id,
@@ -176,46 +205,42 @@ void SetAllowFileAccess(const std::string& extension_id,
bool AllowedScriptingOnAllUrls(const std::string& extension_id,
content::BrowserContext* context) {
bool allowed = false;
- return ExtensionPrefs::Get(context)->ReadPrefAsBoolean(
- extension_id,
- kExtensionAllowedOnAllUrlsPrefName,
- &allowed) &&
- allowed;
+ ExtensionPrefs* prefs = ExtensionPrefs::Get(context);
+ if (!prefs->ReadPrefAsBoolean(extension_id,
+ kExtensionAllowedOnAllUrlsPrefName,
+ &allowed)) {
+ // If there is no value present, we make one, defaulting it to the value of
+ // the 'scripts require action' flag. If the flag is on, then the extension
+ // does not have permission to script on all urls by default.
+ allowed = DefaultAllowedScriptingOnAllUrls();
+ SetAllowedScriptingOnAllUrlsHelper(context, extension_id, allowed, false);
+ }
+ return allowed;
}
void SetAllowedScriptingOnAllUrls(const std::string& extension_id,
content::BrowserContext* context,
bool allowed) {
- if (allowed == AllowedScriptingOnAllUrls(extension_id, context))
- return; // Nothing to do here.
-
- ExtensionPrefs::Get(context)->UpdateExtensionPref(
- extension_id,
- kExtensionAllowedOnAllUrlsPrefName,
- allowed ? new base::FundamentalValue(true) : NULL);
+ if (allowed != AllowedScriptingOnAllUrls(extension_id, context))
+ SetAllowedScriptingOnAllUrlsHelper(context, extension_id, allowed, true);
+}
- const Extension* extension =
- ExtensionRegistry::Get(context)->enabled_extensions().GetByID(
- extension_id);
- if (extension) {
- PermissionsUpdater updater(context);
- if (allowed)
- updater.GrantWithheldImpliedAllHosts(extension);
- else
- updater.WithholdImpliedAllHosts(extension);
- }
+bool DefaultAllowedScriptingOnAllUrls() {
+ return !FeatureSwitch::scripts_require_action()->IsEnabled();
}
-bool ScriptsMayRequireActionForExtension(const Extension* extension) {
- // An extension requires user action to execute scripts iff the switch to do
- // so is enabled, the extension shows up in chrome:extensions (so the user can
- // grant withheld permissions), the extension is not part of chrome or
- // corporate policy, and also not on the scripting whitelist.
- return FeatureSwitch::scripts_require_action()->IsEnabled() &&
- extension->ShouldDisplayInExtensionSettings() &&
+bool ScriptsMayRequireActionForExtension(
+ const Extension* extension,
+ const PermissionSet* permissions) {
+ // An extension may require user action to execute scripts iff the extension
+ // shows up in chrome:extensions (so the user can grant withheld permissions),
+ // is not part of chrome or corporate policy, not on the scripting whitelist,
+ // and requires enough permissions that we should withhold them.
+ return extension->ShouldDisplayInExtensionSettings() &&
!Manifest::IsPolicyLocation(extension->location()) &&
!Manifest::IsComponentLocation(extension->location()) &&
- !PermissionsData::CanExecuteScriptEverywhere(extension);
+ !PermissionsData::CanExecuteScriptEverywhere(extension) &&
+ permissions->ShouldWarnAllHosts();
}
bool IsAppLaunchable(const std::string& extension_id,
« no previous file with comments | « chrome/browser/extensions/extension_util.h ('k') | chrome/browser/extensions/permissions_updater.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698