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()), |
19 action_manager_(ExtensionActionManager::Get(browser_context_)), | 20 action_manager_(ExtensionActionManager::Get(browser_context_)), |
| 21 should_show_page_actions_( |
| 22 !FeatureSwitch::extension_action_redesign()->IsEnabled()), |
20 active_script_controller_(new ActiveScriptController(web_contents_)), | 23 active_script_controller_(new ActiveScriptController(web_contents_)), |
21 extension_registry_observer_(this) { | 24 extension_registry_observer_(this) { |
22 extension_registry_observer_.Add(ExtensionRegistry::Get(browser_context_)); | 25 if (should_show_page_actions_) |
| 26 extension_registry_observer_.Add(ExtensionRegistry::Get(browser_context_)); |
23 } | 27 } |
24 | 28 |
25 LocationBarController::~LocationBarController() { | 29 LocationBarController::~LocationBarController() { |
26 } | 30 } |
27 | 31 |
28 std::vector<ExtensionAction*> LocationBarController::GetCurrentActions() { | 32 std::vector<ExtensionAction*> LocationBarController::GetCurrentActions() { |
29 const ExtensionSet& extensions = | 33 const ExtensionSet& extensions = |
30 ExtensionRegistry::Get(browser_context_)->enabled_extensions(); | 34 ExtensionRegistry::Get(browser_context_)->enabled_extensions(); |
31 std::vector<ExtensionAction*> current_actions; | 35 std::vector<ExtensionAction*> current_actions; |
| 36 if (!should_show_page_actions_) |
| 37 return current_actions; |
| 38 |
32 for (ExtensionSet::const_iterator iter = extensions.begin(); | 39 for (ExtensionSet::const_iterator iter = extensions.begin(); |
33 iter != extensions.end(); | 40 iter != extensions.end(); |
34 ++iter) { | 41 ++iter) { |
35 // Right now, we can consolidate these actions because we only want to show | 42 // Right now, we can consolidate these actions because we only want to show |
36 // one action per extension. If clicking on an active script action ever | 43 // one action per extension. If clicking on an active script action ever |
37 // has a response, then we will need to split the actions. | 44 // has a response, then we will need to split the actions. |
38 ExtensionAction* action = action_manager_->GetPageAction(**iter); | 45 ExtensionAction* action = action_manager_->GetPageAction(**iter); |
39 if (!action) | 46 if (!action) |
40 action = active_script_controller_->GetActionForExtension(iter->get()); | 47 action = active_script_controller_->GetActionForExtension(iter->get()); |
41 if (action) | 48 if (action) |
(...skipping 10 matching lines...) Expand all Loading... |
52 active_script_controller_->GetActionForExtension(extension)) { | 59 active_script_controller_->GetActionForExtension(extension)) { |
53 ExtensionActionAPI::Get(browser_context)-> | 60 ExtensionActionAPI::Get(browser_context)-> |
54 NotifyPageActionsChanged(web_contents_); | 61 NotifyPageActionsChanged(web_contents_); |
55 } | 62 } |
56 } | 63 } |
57 | 64 |
58 void LocationBarController::OnExtensionUnloaded( | 65 void LocationBarController::OnExtensionUnloaded( |
59 content::BrowserContext* browser_context, | 66 content::BrowserContext* browser_context, |
60 const Extension* extension, | 67 const Extension* extension, |
61 UnloadedExtensionInfo::Reason reason) { | 68 UnloadedExtensionInfo::Reason reason) { |
62 bool should_update = false; | 69 if (action_manager_->GetPageAction(*extension)) { |
63 if (action_manager_->GetPageAction(*extension)) | |
64 should_update = true; | |
65 | |
66 if (active_script_controller_->GetActionForExtension(extension)) { | |
67 active_script_controller_->OnExtensionUnloaded(extension); | |
68 should_update = true; | |
69 } | |
70 | |
71 if (should_update) { | |
72 ExtensionActionAPI::Get(browser_context)-> | 70 ExtensionActionAPI::Get(browser_context)-> |
73 NotifyPageActionsChanged(web_contents_); | 71 NotifyPageActionsChanged(web_contents_); |
74 } | 72 } |
75 } | 73 } |
76 | 74 |
77 } // namespace extensions | 75 } // namespace extensions |
OLD | NEW |