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 <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/scoped_observer.h" | 12 #include "base/scoped_observer.h" |
| 13 #include "chrome/browser/extensions/extension_action.h" |
13 #include "content/public/browser/web_contents_observer.h" | 14 #include "content/public/browser/web_contents_observer.h" |
14 #include "extensions/browser/extension_registry_observer.h" | 15 #include "extensions/browser/extension_registry_observer.h" |
15 | 16 |
16 namespace content { | 17 namespace content { |
17 class WebContents; | 18 class WebContents; |
18 } | 19 } |
19 | 20 |
20 class ExtensionAction; | |
21 | |
22 namespace extensions { | 21 namespace extensions { |
23 | 22 |
24 class ActiveScriptController; | 23 class ActiveScriptController; |
25 class Extension; | 24 class Extension; |
26 class ExtensionRegistry; | 25 class ExtensionRegistry; |
27 class PageActionController; | 26 class PageActionController; |
28 | 27 |
29 // Interface for a class that controls the the extension icons that show up in | 28 // 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 | 29 // the location bar. Depending on switches, these icons can have differing |
31 // behavior. | 30 // behavior. |
32 class LocationBarController : public content::WebContentsObserver, | 31 class LocationBarController : public content::WebContentsObserver, |
33 public ExtensionRegistryObserver { | 32 public ExtensionRegistryObserver { |
34 public: | 33 public: |
35 // The action that the UI should take after executing |OnClicked|. | |
36 enum Action { | |
37 ACTION_NONE, | |
38 ACTION_SHOW_POPUP, | |
39 ACTION_SHOW_CONTEXT_MENU, | |
40 }; | |
41 | |
42 class ActionProvider { | 34 class ActionProvider { |
43 public: | 35 public: |
44 // Returns the action for the given extension, or NULL if there isn't one. | 36 // Returns the action for the given extension, or NULL if there isn't one. |
45 virtual ExtensionAction* GetActionForExtension( | 37 virtual ExtensionAction* GetActionForExtension( |
46 const Extension* extension) = 0; | 38 const Extension* extension) = 0; |
47 | 39 |
48 // Handles a click on an extension action. | 40 // Handles a click on an extension action. |
49 virtual LocationBarController::Action OnClicked( | 41 virtual ExtensionAction::ShowAction OnClicked( |
50 const Extension* extension) = 0; | 42 const Extension* extension) = 0; |
51 | 43 |
52 // A notification that the WebContents has navigated in the main frame (and | 44 // 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 | 45 // not in page), so any state relating to the current page should likely be |
54 // reset. | 46 // reset. |
55 virtual void OnNavigated() = 0; | 47 virtual void OnNavigated() = 0; |
56 | 48 |
57 // A notification that the given |extension| has been unloaded, and any | 49 // A notification that the given |extension| has been unloaded, and any |
58 // actions associated with it should be removed. | 50 // actions associated with it should be removed. |
59 // The location bar controller will update itself after this if needed, so | 51 // The location bar controller will update itself after this if needed, so |
60 // Providers should not call NotifyChange(). | 52 // Providers should not call NotifyChange(). |
61 virtual void OnExtensionUnloaded(const Extension* extension) {} | 53 virtual void OnExtensionUnloaded(const Extension* extension) {} |
62 }; | 54 }; |
63 | 55 |
64 explicit LocationBarController(content::WebContents* web_contents); | 56 explicit LocationBarController(content::WebContents* web_contents); |
65 virtual ~LocationBarController(); | 57 virtual ~LocationBarController(); |
66 | 58 |
67 // Returns the actions which should be displayed in the location bar. | 59 // Returns the actions which should be displayed in the location bar. |
68 std::vector<ExtensionAction*> GetCurrentActions(); | 60 std::vector<ExtensionAction*> GetCurrentActions(); |
69 | 61 |
70 // Notifies this that an ExtensionAction has been clicked, and returns the | 62 // Notifies this that an ExtensionAction has been clicked, and returns the |
71 // action which should be taken in response (if any). | 63 // action which should be taken in response (if any). |
72 Action OnClicked(const ExtensionAction* action); | 64 ExtensionAction::ShowAction OnClicked(const ExtensionAction* action); |
73 | 65 |
74 // Notifies the window that the actions have changed. | 66 // Notifies the window that the actions have changed. |
75 static void NotifyChange(content::WebContents* web_contents); | 67 static void NotifyChange(content::WebContents* web_contents); |
76 | 68 |
77 ActiveScriptController* active_script_controller() { | 69 ActiveScriptController* active_script_controller() { |
78 return active_script_controller_.get(); | 70 return active_script_controller_.get(); |
79 } | 71 } |
80 | 72 |
81 private: | 73 private: |
82 // content::WebContentsObserver implementation. | 74 // content::WebContentsObserver implementation. |
(...skipping 20 matching lines...) Expand all Loading... |
103 | 95 |
104 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> | 96 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> |
105 extension_registry_observer_; | 97 extension_registry_observer_; |
106 | 98 |
107 DISALLOW_COPY_AND_ASSIGN(LocationBarController); | 99 DISALLOW_COPY_AND_ASSIGN(LocationBarController); |
108 }; | 100 }; |
109 | 101 |
110 } // namespace extensions | 102 } // namespace extensions |
111 | 103 |
112 #endif // CHROME_BROWSER_EXTENSIONS_LOCATION_BAR_CONTROLLER_H_ | 104 #endif // CHROME_BROWSER_EXTENSIONS_LOCATION_BAR_CONTROLLER_H_ |
OLD | NEW |