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