1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_EXTENSIONS_LOCATION_BAR_CONTROLLER_H_
6 #define CHROME_BROWSER_EXTENSIONS_LOCATION_BAR_CONTROLLER_H_
10 #include "base/macros.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/scoped_observer.h"
13 #include "content/public/browser/web_contents_observer.h"
14 #include "extensions/browser/extension_registry_observer.h"
20 class ExtensionAction;
22 namespace extensions {
24 class ActiveScriptController;
26 class ExtensionRegistry;
27 class PageActionController;
29 // Interface for a class that controls the the extension icons that show up in
30 // the location bar. Depending on switches, these icons can have differing
32 class LocationBarController : public content::WebContentsObserver,
33 public ExtensionRegistryObserver {
35 // The action that the UI should take after executing |OnClicked|.
39 ACTION_SHOW_CONTEXT_MENU,
42 class ActionProvider {
44 // Returns the action for the given extension, or NULL if there isn't one.
45 virtual ExtensionAction* GetActionForExtension(
46 const Extension* extension) = 0;
48 // Handles a click on an extension action.
49 virtual LocationBarController::Action OnClicked(
50 const Extension* extension) = 0;
52 // A notification that the WebContents has navigated in the main frame (and
53 // not in page), so any state relating to the current page should likely be
55 virtual void OnNavigated() = 0;
57 // A notification that the given |extension| has been unloaded, and any
58 // actions associated with it should be removed.
59 // The location bar controller will update itself after this if needed, so
60 // Providers should not call NotifyChange().
61 virtual void OnExtensionUnloaded(const Extension* extension) {}
64 explicit LocationBarController(content::WebContents* web_contents);
65 virtual ~LocationBarController();
67 // Returns the actions which should be displayed in the location bar.
68 std::vector<ExtensionAction*> GetCurrentActions();
70 // Notifies this that an ExtensionAction has been clicked, and returns the
71 // action which should be taken in response (if any).
72 Action OnClicked(const ExtensionAction* action);
74 // Notifies the window that the actions have changed.
75 static void NotifyChange(content::WebContents* web_contents);
77 ActiveScriptController* active_script_controller() {
78 return active_script_controller_.get();
82 // content::WebContentsObserver implementation.
83 virtual void DidNavigateMainFrame(
84 const content::LoadCommittedDetails& details,
85 const content::FrameNavigateParams& params) OVERRIDE;
87 // ExtensionRegistryObserver implementation.
88 virtual void OnExtensionUnloaded(
89 content::BrowserContext* browser_context,
90 const Extension* extension,
91 UnloadedExtensionInfo::Reason reason) OVERRIDE;
93 // The associated WebContents.
94 content::WebContents* web_contents_;
96 // The controllers for different sources of actions in the location bar.
97 // Currently, this is only page actions and active script actions, so we
98 // explicitly own and create both. If there are ever more, it will be worth
99 // considering making this class own a list of LocationBarControllerProviders
101 scoped_ptr<ActiveScriptController> active_script_controller_;
102 scoped_ptr<PageActionController> page_action_controller_;
104 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver>
105 extension_registry_observer_;
107 DISALLOW_COPY_AND_ASSIGN(LocationBarController);
110 } // namespace extensions
112 #endif // CHROME_BROWSER_EXTENSIONS_LOCATION_BAR_CONTROLLER_H_