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

Unified Diff: chrome/browser/extensions/active_script_controller.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: 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
Index: chrome/browser/extensions/active_script_controller.cc
diff --git a/chrome/browser/extensions/active_script_controller.cc b/chrome/browser/extensions/active_script_controller.cc
index f3b73b933f6c266192b7e870578f072b3ef13e7f..58307b3408dc8c13242248560afd00acf1a329d2 100644
--- a/chrome/browser/extensions/active_script_controller.cc
+++ b/chrome/browser/extensions/active_script_controller.cc
@@ -37,31 +37,10 @@
namespace extensions {
-namespace {
-
-// Returns true if the extension should be regarded as a "permitted" extension
-// for the case of metrics. We need this because we only actually withhold
-// permissions if the switch is enabled, but want to record metrics in all
-// cases.
-// "ExtensionWouldHaveHadHostPermissionsWithheldIfSwitchWasOn()" would be
-// more accurate, but too long.
-bool ShouldRecordExtension(const Extension* extension) {
- return extension->ShouldDisplayInExtensionSettings() &&
- !Manifest::IsPolicyLocation(extension->location()) &&
- !Manifest::IsComponentLocation(extension->location()) &&
- !PermissionsData::CanExecuteScriptEverywhere(extension) &&
- extension->permissions_data()
- ->active_permissions()
- ->ShouldWarnAllHosts();
-}
-
-} // namespace
-
ActiveScriptController::ActiveScriptController(
content::WebContents* web_contents)
: content::WebContentsObserver(web_contents),
browser_context_(web_contents->GetBrowserContext()),
- enabled_(FeatureSwitch::scripts_require_action()->IsEnabled()),
extension_registry_observer_(this) {
CHECK(web_contents);
extension_registry_observer_.Add(ExtensionRegistry::Get(browser_context_));
@@ -143,7 +122,7 @@ void ActiveScriptController::OnClicked(const Extension* extension) {
}
bool ActiveScriptController::WantsToRun(const Extension* extension) {
- return enabled_ && pending_requests_.count(extension->id()) > 0;
+ return pending_requests_.count(extension->id()) > 0;
}
PermissionsData::AccessType
@@ -152,11 +131,6 @@ ActiveScriptController::RequiresUserConsentForScriptInjection(
UserScript::InjectionType type) {
CHECK(extension);
- // If the feature is not enabled, we automatically allow all extensions to
- // run scripts.
- if (!enabled_)
- permitted_extensions_.insert(extension->id());
-
// Allow the extension if it's been explicitly granted permission.
if (permitted_extensions_.count(extension->id()) > 0)
return PermissionsData::ACCESS_ALLOWED;
@@ -253,8 +227,9 @@ void ActiveScriptController::OnRequestScriptInjectionPermission(
// ran (because this feature is not enabled). Add the extension to the list of
// permitted extensions (for metrics), and return immediately.
if (request_id == -1) {
- if (ShouldRecordExtension(extension)) {
- DCHECK(!enabled_);
+ if (util::ScriptsMayRequireActionForExtension(
+ extension,
+ extension->permissions_data()->active_permissions())) {
permitted_extensions_.insert(extension->id());
}
return;
@@ -314,8 +289,8 @@ void ActiveScriptController::LogUMA() const {
pending_requests_.size());
// We only log the permitted extensions metric if the feature is enabled,
- // because otherwise the data will be boring (100% allowed).
- if (enabled_) {
+ // because otherwise the data will likely be boring (100% allowed).
+ if (extensions::FeatureSwitch::scripts_require_action()->IsEnabled()) {
not at google - send to devlin 2015/02/06 00:26:55 This isn't very useful with this change, since the
Devlin 2015/02/06 18:58:43 To say there's no longer a correlation between the
not at google - send to devlin 2015/02/06 19:38:43 I think that ultimately whether or not there's use
Devlin 2015/02/06 23:18:49 Added the "something_interesting_happened" ;)
UMA_HISTOGRAM_COUNTS_100(
"Extensions.ActiveScriptController.PermittedExtensions",
permitted_extensions_.size());

Powered by Google App Engine
This is Rietveld 408576698