Chromium Code Reviews| 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 |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..c257b7c2e2d968612007d260a7b1aeeaa5682939 |
| --- /dev/null |
| +++ b/chrome/browser/extensions/location_bar_controller.cc |
| @@ -0,0 +1,88 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/extensions/location_bar_controller.h" |
| + |
| +#include "base/logging.h" |
| +#include "chrome/browser/extensions/active_script_controller.h" |
| +#include "chrome/browser/extensions/extension_action.h" |
| +#include "chrome/browser/extensions/page_action_controller.h" |
| +#include "chrome/common/extensions/api/extension_action/action_info.h" |
| +#include "content/public/browser/invalidate_type.h" |
| +#include "content/public/browser/navigation_details.h" |
| +#include "content/public/browser/web_contents.h" |
| +#include "extensions/browser/extension_registry.h" |
| + |
| +namespace extensions { |
| + |
| +LocationBarController::LocationBarController( |
| + content::WebContents* web_contents) |
| + : WebContentsObserver(web_contents), |
| + web_contents_(web_contents), |
| + active_script_controller_(new ActiveScriptController(web_contents_)), |
| + page_action_controller_(new PageActionController(web_contents_)) { |
| +} |
| + |
| +LocationBarController::~LocationBarController() { |
| +} |
| + |
| +std::vector<ExtensionAction*> LocationBarController::GetCurrentActions() { |
| + const ExtensionSet& extensions = |
| + ExtensionRegistry::Get(web_contents_->GetBrowserContext()) |
| + ->enabled_extensions(); |
| + std::vector<ExtensionAction*> current_actions; |
| + for (ExtensionSet::const_iterator iter = extensions.begin(); |
| + iter != extensions.end(); |
| + ++iter) { |
| + // Right now, we can consolidate these actions because we only want to show |
| + // 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 = |
| + page_action_controller_->GetActionForExtension(*iter); |
| + if (!action) |
| + action = active_script_controller_->GetActionForExtension(*iter); |
| + if (action) |
| + current_actions.push_back(action); |
| + } |
| + |
| + return current_actions; |
| +} |
| + |
| +LocationBarController::Action LocationBarController::OnClicked( |
| + const ExtensionAction* action) { |
| + const Extension* extension = |
| + ExtensionRegistry::Get(web_contents_->GetBrowserContext()) |
| + ->enabled_extensions().GetByID(action->extension_id()); |
| + CHECK(extension); |
|
not at google - send to devlin
2014/05/08 23:33:19
<< action->extension_id();
Devlin
2014/05/09 00:15:32
Done.
|
| + |
| + Action page_action = |
| + page_action_controller_->GetActionForExtension(extension) ? |
| + page_action_controller_->OnClicked(extension) : |
| + ACTION_NONE; |
| + Action active_script_action = |
| + active_script_controller_->GetActionForExtension(extension) ? |
| + active_script_controller_->OnClicked(extension) : |
| + ACTION_NONE; |
| + |
| + // PageAction response takes priority. |
| + return page_action != ACTION_NONE ? page_action : active_script_action; |
| +} |
| + |
| +// static |
| +void LocationBarController::NotifyChange(content::WebContents* web_contents) { |
| + web_contents->NotifyNavigationStateChanged( |
| + content::INVALIDATE_TYPE_PAGE_ACTIONS); |
| +} |
| + |
| +void LocationBarController::DidNavigateMainFrame( |
| + const content::LoadCommittedDetails& details, |
| + const content::FrameNavigateParams& params) { |
| + if (details.is_in_page) |
| + return; |
| + |
| + page_action_controller_->OnNavigated(); |
| + active_script_controller_->OnNavigated(); |
| +} |
| + |
| +} // namespace extensions |