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..6ef72176fd339a06bf7c1c513a35f8e9313527c8 100644 |
--- a/chrome/browser/extensions/active_script_controller.cc |
+++ b/chrome/browser/extensions/active_script_controller.cc |
@@ -37,31 +37,11 @@ |
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()), |
+ was_used_on_page_(false), |
extension_registry_observer_(this) { |
CHECK(web_contents); |
extension_registry_observer_.Add(ExtensionRegistry::Get(browser_context_)); |
@@ -143,7 +123,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 +132,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; |
@@ -187,6 +162,8 @@ void ActiveScriptController::RequestScriptInjection( |
// to run. |
if (list.size() == 1u) |
NotifyChange(extension); |
+ |
+ was_used_on_page_ = true; |
} |
void ActiveScriptController::RunPendingForExtension( |
@@ -253,8 +230,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().get())) { |
permitted_extensions_.insert(extension->id()); |
} |
return; |
@@ -313,9 +291,9 @@ void ActiveScriptController::LogUMA() const { |
"Extensions.ActiveScriptController.ShownActiveScriptsOnPage", |
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_) { |
+ // We only log the permitted extensions metric if the feature was used at all |
+ // on the page, because otherwise the data will be boring. |
+ if (was_used_on_page_) { |
UMA_HISTOGRAM_COUNTS_100( |
"Extensions.ActiveScriptController.PermittedExtensions", |
permitted_extensions_.size()); |
@@ -344,6 +322,7 @@ void ActiveScriptController::DidNavigateMainFrame( |
LogUMA(); |
permitted_extensions_.clear(); |
pending_requests_.clear(); |
+ was_used_on_page_ = false; |
} |
void ActiveScriptController::OnExtensionUnloaded( |