| 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_SHELL_WINDOW_REGISTRY_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_SHELL_WINDOW_REGISTRY_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_SHELL_WINDOW_REGISTRY_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_SHELL_WINDOW_REGISTRY_H_ |
| 7 | 7 |
| 8 #include <set> | 8 #include <set> |
| 9 | 9 |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 11 #include "base/memory/singleton.h" | 11 #include "base/memory/singleton.h" |
| 12 #include "base/observer_list.h" | 12 #include "base/observer_list.h" |
| 13 #include "chrome/browser/profiles/profile_keyed_service.h" | 13 #include "chrome/browser/profiles/profile_keyed_service.h" |
| 14 #include "chrome/browser/profiles/profile_keyed_service_factory.h" | 14 #include "chrome/browser/profiles/profile_keyed_service_factory.h" |
| 15 #include "content/public/browser/notification_observer.h" |
| 16 #include "content/public/browser/notification_registrar.h" |
| 15 #include "ui/gfx/native_widget_types.h" | 17 #include "ui/gfx/native_widget_types.h" |
| 16 | 18 |
| 17 class Profile; | 19 class Profile; |
| 18 class ShellWindow; | 20 class ShellWindow; |
| 19 | 21 |
| 20 namespace content { | 22 namespace content { |
| 21 class RenderViewHost; | 23 class RenderViewHost; |
| 22 } | 24 } |
| 23 | 25 |
| 24 namespace extensions { | 26 namespace extensions { |
| 25 | 27 |
| 26 // The ShellWindowRegistry tracks the ShellWindows for all platform apps for a | 28 // The ShellWindowRegistry tracks the ShellWindows for all platform apps for a |
| 27 // particular profile. | 29 // particular profile. |
| 28 // This class is planned to evolve into tracking all PlatformApps for a | 30 // This class is planned to evolve into tracking all PlatformApps for a |
| 29 // particular profile, with a PlatformApp encapsulating all views (background | 31 // particular profile, with a PlatformApp encapsulating all views (background |
| 30 // page, shell windows, tray view, panels etc.) and other app level behaviour | 32 // page, shell windows, tray view, panels etc.) and other app level behaviour |
| 31 // (e.g. notifications the app is interested in, lifetime of the background | 33 // (e.g. notifications the app is interested in, lifetime of the background |
| 32 // page). | 34 // page). |
| 33 class ShellWindowRegistry : public ProfileKeyedService { | 35 class ShellWindowRegistry : public ProfileKeyedService, |
| 36 public content::NotificationObserver { |
| 34 public: | 37 public: |
| 35 class Observer { | 38 class Observer { |
| 36 public: | 39 public: |
| 37 // Called just after a shell window was added. | 40 // Called just after a shell window was added. |
| 38 virtual void OnShellWindowAdded(ShellWindow* shell_window) = 0; | 41 virtual void OnShellWindowAdded(ShellWindow* shell_window) = 0; |
| 39 // Called just after a shell window was removed. | 42 // Called just after a shell window was removed. |
| 40 virtual void OnShellWindowRemoved(ShellWindow* shell_window) = 0; | 43 virtual void OnShellWindowRemoved(ShellWindow* shell_window) = 0; |
| 41 | 44 |
| 42 protected: | 45 protected: |
| 43 virtual ~Observer() {} | 46 virtual ~Observer() {} |
| 44 }; | 47 }; |
| 45 | 48 |
| 46 typedef std::set<ShellWindow*> ShellWindowSet; | 49 typedef std::set<ShellWindow*> ShellWindowSet; |
| 47 typedef ShellWindowSet::const_iterator const_iterator; | 50 typedef ShellWindowSet::const_iterator const_iterator; |
| 51 typedef std::set<std::string> InspectedWindowSet; |
| 48 | 52 |
| 49 ShellWindowRegistry(); | 53 explicit ShellWindowRegistry(Profile* profile); |
| 50 virtual ~ShellWindowRegistry(); | 54 virtual ~ShellWindowRegistry(); |
| 51 | 55 |
| 52 // Returns the instance for the given profile, or NULL if none. This is | 56 // Returns the instance for the given profile, or NULL if none. This is |
| 53 // a convenience wrapper around ShellWindowRegistry::Factory::GetForProfile. | 57 // a convenience wrapper around ShellWindowRegistry::Factory::GetForProfile. |
| 54 static ShellWindowRegistry* Get(Profile* profile); | 58 static ShellWindowRegistry* Get(Profile* profile); |
| 55 | 59 |
| 56 void AddShellWindow(ShellWindow* shell_window); | 60 void AddShellWindow(ShellWindow* shell_window); |
| 57 void RemoveShellWindow(ShellWindow* shell_window); | 61 void RemoveShellWindow(ShellWindow* shell_window); |
| 58 | 62 |
| 59 void AddObserver(Observer* observer); | 63 void AddObserver(Observer* observer); |
| 60 void RemoveObserver(Observer* observer); | 64 void RemoveObserver(Observer* observer); |
| 61 | 65 |
| 62 // Returns a set of windows owned by the application identified by app_id. | 66 // Returns a set of windows owned by the application identified by app_id. |
| 63 ShellWindowSet GetShellWindowsForApp(const std::string& app_id) const; | 67 ShellWindowSet GetShellWindowsForApp(const std::string& app_id) const; |
| 64 const ShellWindowSet& shell_windows() const { return shell_windows_; } | 68 const ShellWindowSet& shell_windows() const { return shell_windows_; } |
| 65 | 69 |
| 66 // Helper functions to find shell windows with particular attributes. | 70 // Helper functions to find shell windows with particular attributes. |
| 67 ShellWindow* GetShellWindowForRenderViewHost( | 71 ShellWindow* GetShellWindowForRenderViewHost( |
| 68 content::RenderViewHost* render_view_host) const; | 72 content::RenderViewHost* render_view_host) const; |
| 69 ShellWindow* GetShellWindowForNativeWindow(gfx::NativeWindow window) const; | 73 ShellWindow* GetShellWindowForNativeWindow(gfx::NativeWindow window) const; |
| 70 // Returns an app window for the given app, or NULL if no shell windows are | 74 // Returns an app window for the given app, or NULL if no shell windows are |
| 71 // open. If there is a window for the given app that is active, that one will | 75 // open. If there is a window for the given app that is active, that one will |
| 72 // be returned, otherwise an arbitrary window will be returned. | 76 // be returned, otherwise an arbitrary window will be returned. |
| 73 ShellWindow* GetCurrentShellWindowForApp(const std::string& app_id) const; | 77 ShellWindow* GetCurrentShellWindowForApp(const std::string& app_id) const; |
| 74 | 78 |
| 79 // Returns whether a ShellWindow's ID was last known to have a DevToolsAgent |
| 80 // attached to it, which should be restored during a reload of a corresponding |
| 81 // newly created |render_view_host|. |
| 82 bool HadDevToolsAttached(content::RenderViewHost* render_view_host) const; |
| 83 |
| 84 protected: |
| 85 // content::NotificationObserver: |
| 86 virtual void Observe(int type, |
| 87 const content::NotificationSource& source, |
| 88 const content::NotificationDetails& details) OVERRIDE; |
| 89 |
| 75 private: | 90 private: |
| 76 class Factory : public ProfileKeyedServiceFactory { | 91 class Factory : public ProfileKeyedServiceFactory { |
| 77 public: | 92 public: |
| 78 static ShellWindowRegistry* GetForProfile(Profile* profile); | 93 static ShellWindowRegistry* GetForProfile(Profile* profile); |
| 79 | 94 |
| 80 static Factory* GetInstance(); | 95 static Factory* GetInstance(); |
| 81 private: | 96 private: |
| 82 friend struct DefaultSingletonTraits<Factory>; | 97 friend struct DefaultSingletonTraits<Factory>; |
| 83 | 98 |
| 84 Factory(); | 99 Factory(); |
| 85 virtual ~Factory(); | 100 virtual ~Factory(); |
| 86 | 101 |
| 87 // ProfileKeyedServiceFactory | 102 // ProfileKeyedServiceFactory |
| 88 virtual ProfileKeyedService* BuildServiceInstanceFor( | 103 virtual ProfileKeyedService* BuildServiceInstanceFor( |
| 89 Profile* profile) const OVERRIDE; | 104 Profile* profile) const OVERRIDE; |
| 90 virtual bool ServiceHasOwnInstanceInIncognito() const OVERRIDE; | 105 virtual bool ServiceHasOwnInstanceInIncognito() const OVERRIDE; |
| 91 virtual bool ServiceIsCreatedWithProfile() const OVERRIDE; | 106 virtual bool ServiceIsCreatedWithProfile() const OVERRIDE; |
| 92 virtual bool ServiceIsNULLWhileTesting() const OVERRIDE; | 107 virtual bool ServiceIsNULLWhileTesting() const OVERRIDE; |
| 93 }; | 108 }; |
| 94 | 109 |
| 95 ShellWindowSet shell_windows_; | 110 ShellWindowSet shell_windows_; |
| 111 InspectedWindowSet inspected_windows_; |
| 96 ObserverList<Observer> observers_; | 112 ObserverList<Observer> observers_; |
| 113 content::NotificationRegistrar registrar_; |
| 97 }; | 114 }; |
| 98 | 115 |
| 99 } // namespace extensions | 116 } // namespace extensions |
| 100 | 117 |
| 101 #endif // CHROME_BROWSER_EXTENSIONS_SHELL_WINDOW_REGISTRY_H_ | 118 #endif // CHROME_BROWSER_EXTENSIONS_SHELL_WINDOW_REGISTRY_H_ |
| OLD | NEW |