#ifndef CHROME_BROWSER_EXTENSIONS_LOCATION_BAR_CONTROLLER_H_
#define CHROME_BROWSER_EXTENSIONS_LOCATION_BAR_CONTROLLER_H_
+#include <map>
#include <vector>
#include "base/macros.h"
-#include "base/memory/scoped_ptr.h"
+#include "base/memory/linked_ptr.h"
#include "base/scoped_observer.h"
-#include "chrome/browser/extensions/extension_action.h"
-#include "content/public/browser/web_contents_observer.h"
#include "extensions/browser/extension_registry_observer.h"
+class ExtensionAction;
+
namespace content {
class WebContents;
+class BrowserContext;
}
namespace extensions {
-
-class ActiveScriptController;
class Extension;
+class ExtensionActionManager;
class ExtensionRegistry;
-class PageActionController;
-// Interface for a class that controls the the extension icons that show up in
-// the location bar. Depending on switches, these icons can have differing
-// behavior.
-class LocationBarController : public content::WebContentsObserver,
- public ExtensionRegistryObserver {
+// Provides the UI with the current page actions for extensions. The execution
+// of these actions is handled in the ExtensionActionAPI.
+class LocationBarController : public ExtensionRegistryObserver {
public:
- class ActionProvider {
- public:
- // Returns the action for the given extension, or NULL if there isn't one.
- virtual ExtensionAction* GetActionForExtension(
- const Extension* extension) = 0;
-
- // Handles a click on an extension action.
- virtual ExtensionAction::ShowAction OnClicked(
- const Extension* extension) = 0;
-
- // A notification that the WebContents has navigated in the main frame (and
- // not in page), so any state relating to the current page should likely be
- // reset.
- virtual void OnNavigated() = 0;
-
- // A notification that the given |extension| has been unloaded, and any
- // actions associated with it should be removed.
- // The location bar controller will update itself after this if needed, so
- // Providers should not call NotifyChange().
- virtual void OnExtensionUnloaded(const Extension* extension) {}
- };
-
explicit LocationBarController(content::WebContents* web_contents);
virtual ~LocationBarController();
// Returns the actions which should be displayed in the location bar.
std::vector<ExtensionAction*> GetCurrentActions();
- // Notifies this that an ExtensionAction has been clicked, and returns the
- // action which should be taken in response (if any).
- ExtensionAction::ShowAction OnClicked(const ExtensionAction* action);
-
- // Notifies the window that the actions have changed.
- static void NotifyChange(content::WebContents* web_contents);
-
- ActiveScriptController* active_script_controller() {
- return active_script_controller_.get();
- }
-
private:
- // content::WebContentsObserver implementation.
- virtual void DidNavigateMainFrame(
- const content::LoadCommittedDetails& details,
- const content::FrameNavigateParams& params) OVERRIDE;
-
// ExtensionRegistryObserver implementation.
+ virtual void OnExtensionLoaded(
+ content::BrowserContext* browser_context,
+ const Extension* extension) OVERRIDE;
virtual void OnExtensionUnloaded(
content::BrowserContext* browser_context,
const Extension* extension,
// The associated WebContents.
content::WebContents* web_contents_;
- // The controllers for different sources of actions in the location bar.
- // Currently, this is only page actions and active script actions, so we
- // explicitly own and create both. If there are ever more, it will be worth
- // considering making this class own a list of LocationBarControllerProviders
- // instead.
- scoped_ptr<ActiveScriptController> active_script_controller_;
- scoped_ptr<PageActionController> page_action_controller_;
+ // The associated BrowserContext.
+ content::BrowserContext* browser_context_;
+
+ // The ExtensionActionManager to provide page actions.
+ ExtensionActionManager* action_manager_;
+
+ // Whether or not to show page actions in the location bar at all. (This is
+ // false with the toolbar redesign enabled.)
+ bool should_show_page_actions_;
+
+ // Manufactured page actions that have been generated for extensions that want
+ // to run a script, but were blocked.
+ typedef std::map<std::string, linked_ptr<ExtensionAction> >
+ ExtensionActionMap;
+ ExtensionActionMap active_script_actions_;
ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver>
extension_registry_observer_;