OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 APPS_SHELL_WINDOW_REGISTRY_H_ | 5 #ifndef APPS_SHELL_WINDOW_REGISTRY_H_ |
6 #define APPS_SHELL_WINDOW_REGISTRY_H_ | 6 #define APPS_SHELL_WINDOW_REGISTRY_H_ |
7 | 7 |
8 #include <list> | 8 #include <list> |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/memory/singleton.h" | 12 #include "base/memory/singleton.h" |
13 #include "base/observer_list.h" | 13 #include "base/observer_list.h" |
14 #include "components/browser_context_keyed_service/browser_context_keyed_service
.h" | 14 #include "components/browser_context_keyed_service/browser_context_keyed_service
.h" |
15 #include "components/browser_context_keyed_service/browser_context_keyed_service
_factory.h" | 15 #include "components/browser_context_keyed_service/browser_context_keyed_service
_factory.h" |
16 #include "ui/gfx/native_widget_types.h" | 16 #include "ui/gfx/native_widget_types.h" |
17 | 17 |
18 class Profile; | |
19 | |
20 namespace content { | 18 namespace content { |
| 19 class BrowserContext; |
21 class DevToolsAgentHost; | 20 class DevToolsAgentHost; |
22 class RenderViewHost; | 21 class RenderViewHost; |
23 } | 22 } |
24 | 23 |
25 namespace apps { | 24 namespace apps { |
26 | 25 |
27 class ShellWindow; | 26 class ShellWindow; |
28 | 27 |
29 // The ShellWindowRegistry tracks the ShellWindows for all platform apps for a | 28 // The ShellWindowRegistry tracks the ShellWindows for all platform apps for a |
30 // particular profile. | 29 // particular browser context. |
31 // This class is planned to evolve into tracking all PlatformApps for a | |
32 // particular profile, with a PlatformApp encapsulating all views (background | |
33 // page, shell windows, tray view, panels etc.) and other app level behaviour | |
34 // (e.g. notifications the app is interested in, lifetime of the background | |
35 // page). | |
36 class ShellWindowRegistry : public BrowserContextKeyedService { | 30 class ShellWindowRegistry : public BrowserContextKeyedService { |
37 public: | 31 public: |
38 class Observer { | 32 class Observer { |
39 public: | 33 public: |
40 // Called just after a shell window was added. | 34 // Called just after a shell window was added. |
41 virtual void OnShellWindowAdded(apps::ShellWindow* shell_window) = 0; | 35 virtual void OnShellWindowAdded(apps::ShellWindow* shell_window) = 0; |
42 // Called when the window icon changes. | 36 // Called when the window icon changes. |
43 virtual void OnShellWindowIconChanged(apps::ShellWindow* shell_window) = 0; | 37 virtual void OnShellWindowIconChanged(apps::ShellWindow* shell_window) = 0; |
44 // Called just after a shell window was removed. | 38 // Called just after a shell window was removed. |
45 virtual void OnShellWindowRemoved(apps::ShellWindow* shell_window) = 0; | 39 virtual void OnShellWindowRemoved(apps::ShellWindow* shell_window) = 0; |
46 | 40 |
47 protected: | 41 protected: |
48 virtual ~Observer() {} | 42 virtual ~Observer() {} |
49 }; | 43 }; |
50 | 44 |
51 typedef std::list<apps::ShellWindow*> ShellWindowList; | 45 typedef std::list<apps::ShellWindow*> ShellWindowList; |
52 typedef ShellWindowList::const_iterator const_iterator; | 46 typedef ShellWindowList::const_iterator const_iterator; |
53 typedef std::set<std::string> InspectedWindowSet; | 47 typedef std::set<std::string> InspectedWindowSet; |
54 | 48 |
55 explicit ShellWindowRegistry(Profile* profile); | 49 explicit ShellWindowRegistry(content::BrowserContext* context); |
56 virtual ~ShellWindowRegistry(); | 50 virtual ~ShellWindowRegistry(); |
57 | 51 |
58 // Returns the instance for the given profile, or NULL if none. This is | 52 // Returns the instance for the given browser context, or NULL if none. This |
59 // a convenience wrapper around ShellWindowRegistry::Factory::GetForProfile. | 53 // is a convenience wrapper around |
60 static ShellWindowRegistry* Get(Profile* profile); | 54 // ShellWindowRegistry::Factory::GetForBrowserContext(). |
| 55 static ShellWindowRegistry* Get(content::BrowserContext* context); |
61 | 56 |
62 void AddShellWindow(apps::ShellWindow* shell_window); | 57 void AddShellWindow(apps::ShellWindow* shell_window); |
63 void ShellWindowIconChanged(apps::ShellWindow* shell_window); | 58 void ShellWindowIconChanged(apps::ShellWindow* shell_window); |
64 // Called by |shell_window| when it is activated. | 59 // Called by |shell_window| when it is activated. |
65 void ShellWindowActivated(apps::ShellWindow* shell_window); | 60 void ShellWindowActivated(apps::ShellWindow* shell_window); |
66 void RemoveShellWindow(apps::ShellWindow* shell_window); | 61 void RemoveShellWindow(apps::ShellWindow* shell_window); |
67 | 62 |
68 void AddObserver(Observer* observer); | 63 void AddObserver(Observer* observer); |
69 void RemoveObserver(Observer* observer); | 64 void RemoveObserver(Observer* observer); |
70 | 65 |
(...skipping 20 matching lines...) Expand all Loading... |
91 // window will be returned. | 86 // window will be returned. |
92 apps::ShellWindow* GetShellWindowForAppAndKey( | 87 apps::ShellWindow* GetShellWindowForAppAndKey( |
93 const std::string& app_id, | 88 const std::string& app_id, |
94 const std::string& window_key) const; | 89 const std::string& window_key) const; |
95 | 90 |
96 // Returns whether a ShellWindow's ID was last known to have a DevToolsAgent | 91 // Returns whether a ShellWindow's ID was last known to have a DevToolsAgent |
97 // attached to it, which should be restored during a reload of a corresponding | 92 // attached to it, which should be restored during a reload of a corresponding |
98 // newly created |render_view_host|. | 93 // newly created |render_view_host|. |
99 bool HadDevToolsAttached(content::RenderViewHost* render_view_host) const; | 94 bool HadDevToolsAttached(content::RenderViewHost* render_view_host) const; |
100 | 95 |
101 // Returns the shell window for |window|, looking in all profiles. | 96 // Returns the shell window for |window|, looking in all browser contexts. |
102 static apps::ShellWindow* GetShellWindowForNativeWindowAnyProfile( | 97 static apps::ShellWindow* GetShellWindowForNativeWindowAnyProfile( |
103 gfx::NativeWindow window); | 98 gfx::NativeWindow window); |
104 | 99 |
105 // Returns true if the number of shell windows registered across all profiles | 100 // Returns true if the number of shell windows registered across all browser |
106 // is non-zero. |window_type_mask| is a bitwise OR filter of | 101 // contexts is non-zero. |window_type_mask| is a bitwise OR filter of |
107 // ShellWindow::WindowType, or 0 for any window type. | 102 // ShellWindow::WindowType, or 0 for any window type. |
108 static bool IsShellWindowRegisteredInAnyProfile(int window_type_mask); | 103 static bool IsShellWindowRegisteredInAnyProfile(int window_type_mask); |
109 | 104 |
110 class Factory : public BrowserContextKeyedServiceFactory { | 105 class Factory : public BrowserContextKeyedServiceFactory { |
111 public: | 106 public: |
112 static ShellWindowRegistry* GetForProfile(Profile* profile, bool create); | 107 static ShellWindowRegistry* GetForBrowserContext( |
| 108 content::BrowserContext* context, bool create); |
113 | 109 |
114 static Factory* GetInstance(); | 110 static Factory* GetInstance(); |
115 private: | 111 private: |
116 friend struct DefaultSingletonTraits<Factory>; | 112 friend struct DefaultSingletonTraits<Factory>; |
117 | 113 |
118 Factory(); | 114 Factory(); |
119 virtual ~Factory(); | 115 virtual ~Factory(); |
120 | 116 |
121 // BrowserContextKeyedServiceFactory | 117 // BrowserContextKeyedServiceFactory |
122 virtual BrowserContextKeyedService* BuildServiceInstanceFor( | 118 virtual BrowserContextKeyedService* BuildServiceInstanceFor( |
123 content::BrowserContext* profile) const OVERRIDE; | 119 content::BrowserContext* context) const OVERRIDE; |
124 virtual bool ServiceIsCreatedWithBrowserContext() const OVERRIDE; | 120 virtual bool ServiceIsCreatedWithBrowserContext() const OVERRIDE; |
125 virtual bool ServiceIsNULLWhileTesting() const OVERRIDE; | 121 virtual bool ServiceIsNULLWhileTesting() const OVERRIDE; |
126 virtual content::BrowserContext* GetBrowserContextToUse( | 122 virtual content::BrowserContext* GetBrowserContextToUse( |
127 content::BrowserContext* context) const OVERRIDE; | 123 content::BrowserContext* context) const OVERRIDE; |
128 }; | 124 }; |
129 | 125 |
130 protected: | 126 protected: |
131 void OnDevToolsStateChanged(content::DevToolsAgentHost*, bool attached); | 127 void OnDevToolsStateChanged(content::DevToolsAgentHost*, bool attached); |
132 | 128 |
133 private: | 129 private: |
134 // Ensures the specified |shell_window| is included in |shell_windows_|. | 130 // Ensures the specified |shell_window| is included in |shell_windows_|. |
135 // Otherwise adds |shell_window| to the back of |shell_windows_|. | 131 // Otherwise adds |shell_window| to the back of |shell_windows_|. |
136 void AddShellWindowToList(apps::ShellWindow* shell_window); | 132 void AddShellWindowToList(apps::ShellWindow* shell_window); |
137 | 133 |
138 // Bring |shell_window| to the front of |shell_windows_|. If it is not in the | 134 // Bring |shell_window| to the front of |shell_windows_|. If it is not in the |
139 // list, add it first. | 135 // list, add it first. |
140 void BringToFront(apps::ShellWindow* shell_window); | 136 void BringToFront(apps::ShellWindow* shell_window); |
141 | 137 |
142 Profile* profile_; | 138 content::BrowserContext* context_; |
143 ShellWindowList shell_windows_; | 139 ShellWindowList shell_windows_; |
144 InspectedWindowSet inspected_windows_; | 140 InspectedWindowSet inspected_windows_; |
145 ObserverList<Observer> observers_; | 141 ObserverList<Observer> observers_; |
146 base::Callback<void(content::DevToolsAgentHost*, bool)> devtools_callback_; | 142 base::Callback<void(content::DevToolsAgentHost*, bool)> devtools_callback_; |
147 }; | 143 }; |
148 | 144 |
149 } // namespace extensions | 145 } // namespace extensions |
150 | 146 |
151 #endif // APPS_SHELL_WINDOW_REGISTRY_H_ | 147 #endif // APPS_SHELL_WINDOW_REGISTRY_H_ |
OLD | NEW |