Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/extensions/location_bar_controller.h" | 5 #include "chrome/browser/extensions/location_bar_controller.h" |
| 6 | 6 |
| 7 #include "chrome/browser/extensions/active_script_controller.h" | 7 #include "chrome/browser/extensions/active_script_controller.h" |
| 8 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h" | 8 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h" |
| 9 #include "chrome/browser/extensions/extension_action_manager.h" | 9 #include "chrome/browser/extensions/extension_action_manager.h" |
| 10 #include "content/public/browser/web_contents.h" | 10 #include "content/public/browser/web_contents.h" |
| 11 #include "extensions/browser/extension_registry.h" | 11 #include "extensions/browser/extension_registry.h" |
| 12 #include "extensions/common/feature_switch.h" | |
| 12 | 13 |
| 13 namespace extensions { | 14 namespace extensions { |
| 14 | 15 |
| 15 LocationBarController::LocationBarController( | 16 LocationBarController::LocationBarController( |
| 16 content::WebContents* web_contents) | 17 content::WebContents* web_contents) |
| 17 : web_contents_(web_contents), | 18 : web_contents_(web_contents), |
| 18 browser_context_(web_contents->GetBrowserContext()), | 19 browser_context_(web_contents->GetBrowserContext()), |
| 20 should_show_page_actions_( | |
| 21 !FeatureSwitch::extension_action_redesign()->IsEnabled()), | |
| 19 active_script_controller_(new ActiveScriptController(web_contents_)), | 22 active_script_controller_(new ActiveScriptController(web_contents_)), |
| 20 extension_registry_observer_(this) { | 23 extension_registry_observer_(this) { |
| 21 extension_registry_observer_.Add(ExtensionRegistry::Get(browser_context_)); | 24 if (should_show_page_actions_) |
| 25 extension_registry_observer_.Add(ExtensionRegistry::Get(browser_context_)); | |
| 22 } | 26 } |
| 23 | 27 |
| 24 LocationBarController::~LocationBarController() { | 28 LocationBarController::~LocationBarController() { |
| 25 } | 29 } |
| 26 | 30 |
| 27 std::vector<ExtensionAction*> LocationBarController::GetCurrentActions() { | 31 std::vector<ExtensionAction*> LocationBarController::GetCurrentActions() { |
| 28 const ExtensionSet& extensions = | 32 const ExtensionSet& extensions = |
| 29 ExtensionRegistry::Get(browser_context_)->enabled_extensions(); | 33 ExtensionRegistry::Get(browser_context_)->enabled_extensions(); |
| 30 ExtensionActionManager* action_manager = | 34 ExtensionActionManager* action_manager = |
| 31 ExtensionActionManager::Get(browser_context_); | 35 ExtensionActionManager::Get(browser_context_); |
| 32 std::vector<ExtensionAction*> current_actions; | 36 std::vector<ExtensionAction*> current_actions; |
| 37 if (!should_show_page_actions_) | |
| 38 return current_actions; | |
| 39 | |
| 33 for (ExtensionSet::const_iterator iter = extensions.begin(); | 40 for (ExtensionSet::const_iterator iter = extensions.begin(); |
| 34 iter != extensions.end(); | 41 iter != extensions.end(); |
| 35 ++iter) { | 42 ++iter) { |
| 36 // Right now, we can consolidate these actions because we only want to show | 43 // Right now, we can consolidate these actions because we only want to show |
| 37 // one action per extension. If clicking on an active script action ever | 44 // one action per extension. If clicking on an active script action ever |
| 38 // has a response, then we will need to split the actions. | 45 // has a response, then we will need to split the actions. |
| 39 ExtensionAction* action = action_manager->GetPageAction(**iter); | 46 ExtensionAction* action = action_manager->GetPageAction(**iter); |
| 40 if (!action) | 47 if (!action) |
| 41 action = active_script_controller_->GetActionForExtension(iter->get()); | 48 action = active_script_controller_->GetActionForExtension(iter->get()); |
|
Finnur
2014/08/28 11:35:34
This of course also suppresses active scripts icon
Devlin
2014/08/28 18:08:53
Active script icons aren't being removed, but they
| |
| 42 if (action) | 49 if (action) |
| 43 current_actions.push_back(action); | 50 current_actions.push_back(action); |
| 44 } | 51 } |
| 45 | 52 |
| 46 return current_actions; | 53 return current_actions; |
| 47 } | 54 } |
| 48 | 55 |
| 49 void LocationBarController::OnExtensionUnloaded( | 56 void LocationBarController::OnExtensionUnloaded( |
| 50 content::BrowserContext* browser_context, | 57 content::BrowserContext* browser_context, |
| 51 const Extension* extension, | 58 const Extension* extension, |
| 52 UnloadedExtensionInfo::Reason reason) { | 59 UnloadedExtensionInfo::Reason reason) { |
| 53 bool should_update = false; | 60 bool should_update = false; |
| 54 if (ExtensionActionManager::Get(browser_context_)->GetPageAction(*extension)) | 61 if (ExtensionActionManager::Get(browser_context_)->GetPageAction(*extension)) |
| 55 should_update = true; | 62 should_update = true; |
| 56 | 63 |
| 57 if (active_script_controller_->GetActionForExtension(extension)) { | 64 if (active_script_controller_->GetActionForExtension(extension)) { |
| 58 active_script_controller_->OnExtensionUnloaded(extension); | 65 active_script_controller_->OnExtensionUnloaded(extension); |
|
Finnur
2014/08/28 11:35:34
Now that we're not adding ourselves as an observer
Devlin
2014/08/28 18:08:53
Ah, yes, we will. Fixed it by making ASC an obser
| |
| 59 should_update = true; | 66 should_update = true; |
| 60 } | 67 } |
| 61 | 68 |
| 62 if (should_update) { | 69 if (should_update) { |
| 63 ExtensionActionAPI::Get(browser_context)-> | 70 ExtensionActionAPI::Get(browser_context)-> |
| 64 NotifyPageActionsChanged(web_contents_); | 71 NotifyPageActionsChanged(web_contents_); |
| 65 } | 72 } |
| 66 } | 73 } |
| 67 | 74 |
| 68 } // namespace extensions | 75 } // namespace extensions |
|
Finnur
2014/08/28 11:35:35
It looks like we're not far off from killing this
Devlin
2014/08/28 18:08:53
Yep! :)
| |
| OLD | NEW |