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