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 "content/public/browser/web_contents_observer.h" | 13 #include "content/public/browser/web_contents_observer.h" |
| 14 #include "extensions/browser/extension_registry_observer.h" |
13 | 15 |
14 namespace content { | 16 namespace content { |
15 class WebContents; | 17 class WebContents; |
16 } | 18 } |
17 | 19 |
18 class ExtensionAction; | 20 class ExtensionAction; |
19 | 21 |
20 namespace extensions { | 22 namespace extensions { |
21 | 23 |
22 class ActiveScriptController; | 24 class ActiveScriptController; |
23 class Extension; | 25 class Extension; |
| 26 class ExtensionRegistry; |
24 class PageActionController; | 27 class PageActionController; |
25 | 28 |
26 // Interface for a class that controls the the extension icons that show up in | 29 // Interface for a class that controls the the extension icons that show up in |
27 // the location bar. Depending on switches, these icons can have differing | 30 // the location bar. Depending on switches, these icons can have differing |
28 // behavior. | 31 // behavior. |
29 class LocationBarController : public content::WebContentsObserver { | 32 class LocationBarController : public content::WebContentsObserver, |
| 33 public ExtensionRegistryObserver { |
30 public: | 34 public: |
31 // The action that the UI should take after executing |OnClicked|. | 35 // The action that the UI should take after executing |OnClicked|. |
32 enum Action { | 36 enum Action { |
33 ACTION_NONE, | 37 ACTION_NONE, |
34 ACTION_SHOW_POPUP, | 38 ACTION_SHOW_POPUP, |
35 ACTION_SHOW_CONTEXT_MENU, | 39 ACTION_SHOW_CONTEXT_MENU, |
36 }; | 40 }; |
37 | 41 |
38 class ActionProvider { | 42 class ActionProvider { |
39 public: | 43 public: |
40 // Returns the action for the given extension, or NULL if there isn't one. | 44 // Returns the action for the given extension, or NULL if there isn't one. |
41 virtual ExtensionAction* GetActionForExtension( | 45 virtual ExtensionAction* GetActionForExtension( |
42 const Extension* extension) = 0; | 46 const Extension* extension) = 0; |
43 | 47 |
44 // Handles a click on an extension action. | 48 // Handles a click on an extension action. |
45 virtual LocationBarController::Action OnClicked( | 49 virtual LocationBarController::Action OnClicked( |
46 const Extension* extension) = 0; | 50 const Extension* extension) = 0; |
47 | 51 |
48 // A notification that the WebContents has navigated in the main frame (and | 52 // A notification that the WebContents has navigated in the main frame (and |
49 // not in page), so any state relating to the current page should likely be | 53 // not in page), so any state relating to the current page should likely be |
50 // reset. | 54 // reset. |
51 virtual void OnNavigated() = 0; | 55 virtual void OnNavigated() = 0; |
| 56 |
| 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) {} |
52 }; | 62 }; |
53 | 63 |
54 explicit LocationBarController(content::WebContents* web_contents); | 64 explicit LocationBarController(content::WebContents* web_contents); |
55 virtual ~LocationBarController(); | 65 virtual ~LocationBarController(); |
56 | 66 |
57 // Returns the actions which should be displayed in the location bar. | 67 // Returns the actions which should be displayed in the location bar. |
58 std::vector<ExtensionAction*> GetCurrentActions(); | 68 std::vector<ExtensionAction*> GetCurrentActions(); |
59 | 69 |
60 // Notifies this that an ExtensionAction has been clicked, and returns the | 70 // Notifies this that an ExtensionAction has been clicked, and returns the |
61 // action which should be taken in response (if any). | 71 // action which should be taken in response (if any). |
62 Action OnClicked(const ExtensionAction* action); | 72 Action OnClicked(const ExtensionAction* action); |
63 | 73 |
64 // Notifies the window that the actions have changed. | 74 // Notifies the window that the actions have changed. |
65 static void NotifyChange(content::WebContents* web_contents); | 75 static void NotifyChange(content::WebContents* web_contents); |
66 | 76 |
67 ActiveScriptController* active_script_controller() { | 77 ActiveScriptController* active_script_controller() { |
68 return active_script_controller_.get(); | 78 return active_script_controller_.get(); |
69 } | 79 } |
70 | 80 |
71 private: | 81 private: |
72 // content::WebContentsObserver implementation. | 82 // content::WebContentsObserver implementation. |
73 virtual void DidNavigateMainFrame( | 83 virtual void DidNavigateMainFrame( |
74 const content::LoadCommittedDetails& details, | 84 const content::LoadCommittedDetails& details, |
75 const content::FrameNavigateParams& params) OVERRIDE; | 85 const content::FrameNavigateParams& params) OVERRIDE; |
76 | 86 |
| 87 // ExtensionRegistryObserver implementation. |
| 88 virtual void OnExtensionUnloaded( |
| 89 content::BrowserContext* browser_context, |
| 90 const Extension* extension, |
| 91 UnloadedExtensionInfo::Reason reason) OVERRIDE; |
| 92 |
77 // The associated WebContents. | 93 // The associated WebContents. |
78 content::WebContents* web_contents_; | 94 content::WebContents* web_contents_; |
79 | 95 |
80 // The controllers for different sources of actions in the location bar. | 96 // The controllers for different sources of actions in the location bar. |
81 // Currently, this is only page actions and active script actions, so we | 97 // 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 | 98 // explicitly own and create both. If there are ever more, it will be worth |
83 // considering making this class own a list of LocationBarControllerProviders | 99 // considering making this class own a list of LocationBarControllerProviders |
84 // instead. | 100 // instead. |
85 scoped_ptr<ActiveScriptController> active_script_controller_; | 101 scoped_ptr<ActiveScriptController> active_script_controller_; |
86 scoped_ptr<PageActionController> page_action_controller_; | 102 scoped_ptr<PageActionController> page_action_controller_; |
87 | 103 |
| 104 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> |
| 105 extension_registry_observer_; |
| 106 |
88 DISALLOW_COPY_AND_ASSIGN(LocationBarController); | 107 DISALLOW_COPY_AND_ASSIGN(LocationBarController); |
89 }; | 108 }; |
90 | 109 |
91 } // namespace extensions | 110 } // namespace extensions |
92 | 111 |
93 #endif // CHROME_BROWSER_EXTENSIONS_LOCATION_BAR_CONTROLLER_H_ | 112 #endif // CHROME_BROWSER_EXTENSIONS_LOCATION_BAR_CONTROLLER_H_ |
OLD | NEW |