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