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

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

Issue 527963003: Uncouple ActiveScriptController from LocationBarController (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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/location_bar_controller.cc
diff --git a/chrome/browser/extensions/location_bar_controller.cc b/chrome/browser/extensions/location_bar_controller.cc
index 488983f53127621b00b3662d8b56da26f9d352b9..dcb8a1142fb5cb844b306a15022920e3ebaf67a5 100644
--- a/chrome/browser/extensions/location_bar_controller.cc
+++ b/chrome/browser/extensions/location_bar_controller.cc
@@ -20,7 +20,6 @@ LocationBarController::LocationBarController(
action_manager_(ExtensionActionManager::Get(browser_context_)),
should_show_page_actions_(
!FeatureSwitch::extension_action_redesign()->IsEnabled()),
- active_script_controller_(new ActiveScriptController(web_contents_)),
extension_registry_observer_(this) {
if (should_show_page_actions_)
extension_registry_observer_.Add(ExtensionRegistry::Get(browser_context_));
@@ -36,6 +35,8 @@ std::vector<ExtensionAction*> LocationBarController::GetCurrentActions() {
if (!should_show_page_actions_)
return current_actions;
+ ActiveScriptController* active_script_controller =
+ ActiveScriptController::GetForWebContents(web_contents_);
for (ExtensionSet::const_iterator iter = extensions.begin();
iter != extensions.end();
++iter) {
@@ -43,8 +44,22 @@ std::vector<ExtensionAction*> LocationBarController::GetCurrentActions() {
// one action per extension. If clicking on an active script action ever
// has a response, then we will need to split the actions.
ExtensionAction* action = action_manager_->GetPageAction(**iter);
- if (!action)
- action = active_script_controller_->GetActionForExtension(iter->get());
+ if (!action && active_script_controller->WantsToRun(*iter)) {
+ ExtensionActionMap::iterator existing =
+ active_script_actions_.find((*iter)->id());
+ if (existing != active_script_actions_.end()) {
+ action = existing->second.get();
+ } else {
+ linked_ptr<ExtensionAction> active_script_action(
+ ExtensionActionManager::Get(browser_context_)->
+ GetBestFitAction(**iter, ActionInfo::TYPE_PAGE).release());
+ active_script_action->SetIsVisible(
+ ExtensionAction::kDefaultTabId, true);
+ active_script_actions_[(*iter)->id()] = active_script_action;
+ action = active_script_action.get();
+ }
+ }
+
if (action)
current_actions.push_back(action);
}
@@ -55,8 +70,7 @@ std::vector<ExtensionAction*> LocationBarController::GetCurrentActions() {
void LocationBarController::OnExtensionLoaded(
content::BrowserContext* browser_context,
const Extension* extension) {
- if (action_manager_->GetPageAction(*extension) ||
- active_script_controller_->GetActionForExtension(extension)) {
+ if (action_manager_->GetPageAction(*extension)) {
ExtensionActionAPI::Get(browser_context)->
NotifyPageActionsChanged(web_contents_);
}

Powered by Google App Engine
This is Rietveld 408576698