OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 #ifndef CHROME_BROWSER_EXTENSIONS_LOCATION_BAR_CONTROLLER_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_LOCATION_BAR_CONTROLLER_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_LOCATION_BAR_CONTROLLER_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_LOCATION_BAR_CONTROLLER_H_ |
7 | 7 |
8 #include <set> | |
9 #include <string> | |
10 #include <vector> | 8 #include <vector> |
11 | 9 |
| 10 #include "base/macros.h" |
| 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "content/public/browser/web_contents_observer.h" |
| 13 |
| 14 namespace content { |
| 15 class WebContents; |
| 16 } |
| 17 |
12 class ExtensionAction; | 18 class ExtensionAction; |
13 | 19 |
14 namespace extensions { | 20 namespace extensions { |
15 | 21 |
| 22 class ActiveScriptController; |
| 23 class Extension; |
| 24 class PageActionController; |
| 25 |
16 // Interface for a class that controls the the extension icons that show up in | 26 // Interface for a class that controls the the extension icons that show up in |
17 // the location bar. Depending on switches, these icons can have differing | 27 // the location bar. Depending on switches, these icons can have differing |
18 // behavior. | 28 // behavior. |
19 class LocationBarController { | 29 class LocationBarController : public content::WebContentsObserver { |
20 public: | 30 public: |
21 // The reaction that the UI should take after executing |OnClicked|. | 31 // The action that the UI should take after executing |OnClicked|. |
22 enum Action { | 32 enum Action { |
23 ACTION_NONE, | 33 ACTION_NONE, |
24 ACTION_SHOW_POPUP, | 34 ACTION_SHOW_POPUP, |
25 ACTION_SHOW_CONTEXT_MENU, | 35 ACTION_SHOW_CONTEXT_MENU, |
26 }; | 36 }; |
27 | 37 |
28 virtual ~LocationBarController() {} | 38 class ActionProvider { |
| 39 public: |
| 40 // Returns the action for the given extension, or NULL if there isn't one. |
| 41 virtual ExtensionAction* GetActionForExtension( |
| 42 const Extension* extension) = 0; |
29 | 43 |
30 // Gets the action data for all extensions. | 44 // Handles a click on an extension action. |
31 virtual std::vector<ExtensionAction*> GetCurrentActions() const = 0; | 45 virtual LocationBarController::Action OnClicked( |
| 46 const Extension* extension) = 0; |
32 | 47 |
33 // Notifies this that the badge for an extension has been clicked with some | 48 // A notification that the WebContents has navigated in the main frame (and |
34 // mouse button (1 for left, 2 for middle, and 3 for right click), and | 49 // not in page), so any state relating to the current page should likely be |
35 // returns the action that should be taken in response (if any). | 50 // reset. |
36 // TODO(kalman): make mouse_button an enum. | 51 virtual void OnNavigated() = 0; |
37 virtual Action OnClicked(const std::string& extension_id, | 52 }; |
38 int mouse_button) = 0; | |
39 | 53 |
40 // Notifies clients that the icons have changed. | 54 explicit LocationBarController(content::WebContents* web_contents); |
41 virtual void NotifyChange() = 0; | 55 virtual ~LocationBarController(); |
| 56 |
| 57 // Returns the actions which should be displayed in the location bar. |
| 58 std::vector<ExtensionAction*> GetCurrentActions(); |
| 59 |
| 60 // Notifies this that an ExtensionAction has been clicked, and returns the |
| 61 // action which should be taken in response (if any). |
| 62 Action OnClicked(const ExtensionAction* action); |
| 63 |
| 64 // Notifies the window that the actions have changed. |
| 65 static void NotifyChange(content::WebContents* web_contents); |
| 66 |
| 67 ActiveScriptController* active_script_controller() { |
| 68 return active_script_controller_.get(); |
| 69 } |
| 70 |
| 71 private: |
| 72 // content::WebContentsObserver implementation. |
| 73 virtual void DidNavigateMainFrame( |
| 74 const content::LoadCommittedDetails& details, |
| 75 const content::FrameNavigateParams& params) OVERRIDE; |
| 76 |
| 77 // The associated WebContents. |
| 78 content::WebContents* web_contents_; |
| 79 |
| 80 // The controllers for different sources of actions in the location bar. |
| 81 // Currently, this is only page actions and active script actions, so we |
| 82 // explicitly own and create both. If there are ever more, it will be worth |
| 83 // considering making this class own a list of LocationBarControllerProviders |
| 84 // instead. |
| 85 scoped_ptr<ActiveScriptController> active_script_controller_; |
| 86 scoped_ptr<PageActionController> page_action_controller_; |
| 87 |
| 88 DISALLOW_COPY_AND_ASSIGN(LocationBarController); |
42 }; | 89 }; |
43 | 90 |
44 } // namespace extensions | 91 } // namespace extensions |
45 | 92 |
46 #endif // CHROME_BROWSER_EXTENSIONS_LOCATION_BAR_CONTROLLER_H_ | 93 #endif // CHROME_BROWSER_EXTENSIONS_LOCATION_BAR_CONTROLLER_H_ |
OLD | NEW |