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

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

Issue 597413003: Introduce an "ExtensionWantsToAct" method (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Latest master for CQ Created 6 years, 3 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 31574c9c22493e820bcdc178e795fd8a5848cfd7..f3b73b933f6c266192b7e870578f072b3ef13e7f 100644
--- a/chrome/browser/extensions/active_script_controller.cc
+++ b/chrome/browser/extensions/active_script_controller.cc
@@ -60,11 +60,11 @@ bool ShouldRecordExtension(const Extension* extension) {
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(web_contents->GetBrowserContext()));
+ extension_registry_observer_.Add(ExtensionRegistry::Get(browser_context_));
}
ActiveScriptController::~ActiveScriptController() {
@@ -130,8 +130,8 @@ void ActiveScriptController::AlwaysRunOnVisibleOrigin(
// permissions and granted permissions.
// TODO(devlin): Make sure that the permission is removed from
// withheld_permissions if appropriate.
- PermissionsUpdater(web_contents()->GetBrowserContext())
- .AddPermissions(extension, new_permissions.get());
+ PermissionsUpdater(browser_context_).AddPermissions(extension,
+ new_permissions.get());
// Allow current tab to run injection.
OnClicked(extension);
@@ -183,12 +183,10 @@ void ActiveScriptController::RequestScriptInjection(
PendingRequestList& list = pending_requests_[extension->id()];
list.push_back(callback);
- // If this was the first entry, notify the location bar that there's a new
- // icon.
- if (list.size() == 1u) {
- ExtensionActionAPI::Get(web_contents()->GetBrowserContext())->
- NotifyPageActionsChanged(web_contents());
- }
+ // If this was the first entry, we need to notify that a new extension wants
+ // to run.
+ if (list.size() == 1u)
+ NotifyChange(extension);
}
void ActiveScriptController::RunPendingForExtension(
@@ -229,9 +227,9 @@ void ActiveScriptController::RunPendingForExtension(
request->Run();
}
- // Inform the location bar that the action is now gone.
- ExtensionActionAPI::Get(web_contents()->GetBrowserContext())->
- NotifyPageActionsChanged(web_contents());
+ // The extension ran, so we need to update the ExtensionActionAPI that we no
+ // longer want to act.
+ NotifyChange(extension);
}
void ActiveScriptController::OnRequestScriptInjectionPermission(
@@ -244,7 +242,7 @@ void ActiveScriptController::OnRequestScriptInjectionPermission(
}
const Extension* extension =
- ExtensionRegistry::Get(web_contents()->GetBrowserContext())
+ ExtensionRegistry::Get(browser_context_)
->enabled_extensions().GetByID(extension_id);
// We shouldn't allow extensions which are no longer enabled to run any
// scripts. Ignore the request.
@@ -294,6 +292,22 @@ void ActiveScriptController::PermitScriptInjection(int64 request_id) {
}
}
+void ActiveScriptController::NotifyChange(const Extension* extension) {
+ ExtensionActionAPI* extension_action_api =
+ ExtensionActionAPI::Get(browser_context_);
+ ExtensionAction* extension_action =
+ ExtensionActionManager::Get(browser_context_)->
+ GetExtensionAction(*extension);
+ // If the extension has an action, we need to notify that it's updated.
+ if (extension_action) {
+ extension_action_api->NotifyChange(
+ extension_action, web_contents(), browser_context_);
+ }
+
+ // We also notify that page actions may have changed.
+ extension_action_api->NotifyPageActionsChanged(web_contents());
+}
+
void ActiveScriptController::LogUMA() const {
UMA_HISTOGRAM_COUNTS_100(
"Extensions.ActiveScriptController.ShownActiveScriptsOnPage",
@@ -339,7 +353,7 @@ void ActiveScriptController::OnExtensionUnloaded(
PendingRequestMap::iterator iter = pending_requests_.find(extension->id());
if (iter != pending_requests_.end()) {
pending_requests_.erase(iter);
- ExtensionActionAPI::Get(web_contents()->GetBrowserContext())->
+ ExtensionActionAPI::Get(browser_context_)->
NotifyPageActionsChanged(web_contents());
}
}
« no previous file with comments | « chrome/browser/extensions/active_script_controller.h ('k') | chrome/browser/extensions/active_script_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698