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_APP_WINDOW_REGISTRY_H_ |
6 #define APPS_SHELL_WINDOW_REGISTRY_H_ | 6 #define APPS_APP_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 namespace content { | 18 namespace content { |
19 class BrowserContext; | 19 class BrowserContext; |
20 class DevToolsAgentHost; | 20 class DevToolsAgentHost; |
21 class RenderViewHost; | 21 class RenderViewHost; |
22 } | 22 } |
23 | 23 |
24 namespace apps { | 24 namespace apps { |
25 | 25 |
26 class ShellWindow; | 26 class AppWindow; |
27 | 27 |
28 // The ShellWindowRegistry tracks the ShellWindows for all platform apps for a | 28 // The AppWindowRegistry tracks the AppWindows for all platform apps for a |
29 // particular browser context. | 29 // particular browser context. |
30 class ShellWindowRegistry : public BrowserContextKeyedService { | 30 class AppWindowRegistry : public BrowserContextKeyedService { |
31 public: | 31 public: |
32 class Observer { | 32 class Observer { |
33 public: | 33 public: |
34 // Called just after a shell window was added. | 34 // Called just after a app window was added. |
35 virtual void OnShellWindowAdded(apps::ShellWindow* shell_window) = 0; | 35 virtual void OnAppWindowAdded(apps::AppWindow* app_window) = 0; |
36 // Called when the window icon changes. | 36 // Called when the window icon changes. |
37 virtual void OnShellWindowIconChanged(apps::ShellWindow* shell_window) = 0; | 37 virtual void OnAppWindowIconChanged(apps::AppWindow* app_window) = 0; |
38 // Called just after a shell window was removed. | 38 // Called just after a app window was removed. |
39 virtual void OnShellWindowRemoved(apps::ShellWindow* shell_window) = 0; | 39 virtual void OnAppWindowRemoved(apps::AppWindow* app_window) = 0; |
40 | 40 |
41 protected: | 41 protected: |
42 virtual ~Observer() {} | 42 virtual ~Observer() {} |
43 }; | 43 }; |
44 | 44 |
45 typedef std::list<apps::ShellWindow*> ShellWindowList; | 45 typedef std::list<apps::AppWindow*> AppWindowList; |
46 typedef ShellWindowList::const_iterator const_iterator; | 46 typedef AppWindowList::const_iterator const_iterator; |
47 typedef std::set<std::string> InspectedWindowSet; | 47 typedef std::set<std::string> InspectedWindowSet; |
48 | 48 |
49 explicit ShellWindowRegistry(content::BrowserContext* context); | 49 explicit AppWindowRegistry(content::BrowserContext* context); |
50 virtual ~ShellWindowRegistry(); | 50 virtual ~AppWindowRegistry(); |
51 | 51 |
52 // Returns the instance for the given browser context, or NULL if none. This | 52 // Returns the instance for the given browser context, or NULL if none. This |
53 // is a convenience wrapper around | 53 // is a convenience wrapper around |
54 // ShellWindowRegistry::Factory::GetForBrowserContext(). | 54 // AppWindowRegistry::Factory::GetForBrowserContext(). |
55 static ShellWindowRegistry* Get(content::BrowserContext* context); | 55 static AppWindowRegistry* Get(content::BrowserContext* context); |
56 | 56 |
57 void AddShellWindow(apps::ShellWindow* shell_window); | 57 void AddAppWindow(apps::AppWindow* app_window); |
58 void ShellWindowIconChanged(apps::ShellWindow* shell_window); | 58 void AppWindowIconChanged(apps::AppWindow* app_window); |
59 // Called by |shell_window| when it is activated. | 59 // Called by |app_window| when it is activated. |
60 void ShellWindowActivated(apps::ShellWindow* shell_window); | 60 void AppWindowActivated(apps::AppWindow* app_window); |
61 void RemoveShellWindow(apps::ShellWindow* shell_window); | 61 void RemoveAppWindow(apps::AppWindow* app_window); |
62 | 62 |
63 void AddObserver(Observer* observer); | 63 void AddObserver(Observer* observer); |
64 void RemoveObserver(Observer* observer); | 64 void RemoveObserver(Observer* observer); |
65 | 65 |
66 // 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. |
67 ShellWindowList GetShellWindowsForApp(const std::string& app_id) const; | 67 AppWindowList GetAppWindowsForApp(const std::string& app_id) const; |
68 const ShellWindowList& shell_windows() const { return shell_windows_; } | 68 const AppWindowList& app_windows() const { return app_windows_; } |
69 | 69 |
70 // Close all shell windows associated with an app. | 70 // Close all app windows associated with an app. |
71 void CloseAllShellWindowsForApp(const std::string& app_id); | 71 void CloseAllAppWindowsForApp(const std::string& app_id); |
72 | 72 |
73 // Helper functions to find shell windows with particular attributes. | 73 // Helper functions to find app windows with particular attributes. |
74 apps::ShellWindow* GetShellWindowForRenderViewHost( | 74 apps::AppWindow* GetAppWindowForRenderViewHost( |
75 content::RenderViewHost* render_view_host) const; | 75 content::RenderViewHost* render_view_host) const; |
76 apps::ShellWindow* GetShellWindowForNativeWindow( | 76 apps::AppWindow* GetAppWindowForNativeWindow(gfx::NativeWindow window) const; |
77 gfx::NativeWindow window) const; | 77 // Returns an app window for the given app, or NULL if no app windows are |
78 // Returns an app window for the given app, or NULL if no shell windows are | |
79 // open. If there is a window for the given app that is active, that one will | 78 // open. If there is a window for the given app that is active, that one will |
80 // be returned, otherwise an arbitrary window will be returned. | 79 // be returned, otherwise an arbitrary window will be returned. |
81 apps::ShellWindow* GetCurrentShellWindowForApp( | 80 apps::AppWindow* GetCurrentAppWindowForApp(const std::string& app_id) const; |
82 const std::string& app_id) const; | 81 // Returns an app window for the given app and window key, or NULL if no app |
83 // Returns an app window for the given app and window key, or NULL if no shell | |
84 // window with the key are open. If there is a window for the given app and | 82 // window with the key are open. If there is a window for the given app and |
85 // key that is active, that one will be returned, otherwise an arbitrary | 83 // key that is active, that one will be returned, otherwise an arbitrary |
86 // window will be returned. | 84 // window will be returned. |
87 apps::ShellWindow* GetShellWindowForAppAndKey( | 85 apps::AppWindow* GetAppWindowForAppAndKey(const std::string& app_id, |
88 const std::string& app_id, | 86 const std::string& window_key) |
89 const std::string& window_key) const; | 87 const; |
90 | 88 |
91 // Returns whether a ShellWindow's ID was last known to have a DevToolsAgent | 89 // Returns whether a AppWindow's ID was last known to have a DevToolsAgent |
92 // attached to it, which should be restored during a reload of a corresponding | 90 // attached to it, which should be restored during a reload of a corresponding |
93 // newly created |render_view_host|. | 91 // newly created |render_view_host|. |
94 bool HadDevToolsAttached(content::RenderViewHost* render_view_host) const; | 92 bool HadDevToolsAttached(content::RenderViewHost* render_view_host) const; |
95 | 93 |
96 // Returns the shell window for |window|, looking in all browser contexts. | 94 // Returns the app window for |window|, looking in all browser contexts. |
97 static apps::ShellWindow* GetShellWindowForNativeWindowAnyProfile( | 95 static apps::AppWindow* GetAppWindowForNativeWindowAnyProfile( |
98 gfx::NativeWindow window); | 96 gfx::NativeWindow window); |
99 | 97 |
100 // Returns true if the number of shell windows registered across all browser | 98 // Returns true if the number of app windows registered across all browser |
101 // contexts is non-zero. |window_type_mask| is a bitwise OR filter of | 99 // contexts is non-zero. |window_type_mask| is a bitwise OR filter of |
102 // ShellWindow::WindowType, or 0 for any window type. | 100 // AppWindow::WindowType, or 0 for any window type. |
103 static bool IsShellWindowRegisteredInAnyProfile(int window_type_mask); | 101 static bool IsAppWindowRegisteredInAnyProfile(int window_type_mask); |
104 | 102 |
105 class Factory : public BrowserContextKeyedServiceFactory { | 103 class Factory : public BrowserContextKeyedServiceFactory { |
106 public: | 104 public: |
107 static ShellWindowRegistry* GetForBrowserContext( | 105 static AppWindowRegistry* GetForBrowserContext( |
108 content::BrowserContext* context, bool create); | 106 content::BrowserContext* context, |
| 107 bool create); |
109 | 108 |
110 static Factory* GetInstance(); | 109 static Factory* GetInstance(); |
| 110 |
111 private: | 111 private: |
112 friend struct DefaultSingletonTraits<Factory>; | 112 friend struct DefaultSingletonTraits<Factory>; |
113 | 113 |
114 Factory(); | 114 Factory(); |
115 virtual ~Factory(); | 115 virtual ~Factory(); |
116 | 116 |
117 // BrowserContextKeyedServiceFactory | 117 // BrowserContextKeyedServiceFactory |
118 virtual BrowserContextKeyedService* BuildServiceInstanceFor( | 118 virtual BrowserContextKeyedService* BuildServiceInstanceFor( |
119 content::BrowserContext* context) const OVERRIDE; | 119 content::BrowserContext* context) const OVERRIDE; |
120 virtual bool ServiceIsCreatedWithBrowserContext() const OVERRIDE; | 120 virtual bool ServiceIsCreatedWithBrowserContext() const OVERRIDE; |
121 virtual bool ServiceIsNULLWhileTesting() const OVERRIDE; | 121 virtual bool ServiceIsNULLWhileTesting() const OVERRIDE; |
122 virtual content::BrowserContext* GetBrowserContextToUse( | 122 virtual content::BrowserContext* GetBrowserContextToUse( |
123 content::BrowserContext* context) const OVERRIDE; | 123 content::BrowserContext* context) const OVERRIDE; |
124 }; | 124 }; |
125 | 125 |
126 protected: | 126 protected: |
127 void OnDevToolsStateChanged(content::DevToolsAgentHost*, bool attached); | 127 void OnDevToolsStateChanged(content::DevToolsAgentHost*, bool attached); |
128 | 128 |
129 private: | 129 private: |
130 // Ensures the specified |shell_window| is included in |shell_windows_|. | 130 // Ensures the specified |app_window| is included in |app_windows_|. |
131 // Otherwise adds |shell_window| to the back of |shell_windows_|. | 131 // Otherwise adds |app_window| to the back of |app_windows_|. |
132 void AddShellWindowToList(apps::ShellWindow* shell_window); | 132 void AddAppWindowToList(apps::AppWindow* app_window); |
133 | 133 |
134 // Bring |shell_window| to the front of |shell_windows_|. If it is not in the | 134 // Bring |app_window| to the front of |app_windows_|. If it is not in the |
135 // list, add it first. | 135 // list, add it first. |
136 void BringToFront(apps::ShellWindow* shell_window); | 136 void BringToFront(apps::AppWindow* app_window); |
137 | 137 |
138 content::BrowserContext* context_; | 138 content::BrowserContext* context_; |
139 ShellWindowList shell_windows_; | 139 AppWindowList app_windows_; |
140 InspectedWindowSet inspected_windows_; | 140 InspectedWindowSet inspected_windows_; |
141 ObserverList<Observer> observers_; | 141 ObserverList<Observer> observers_; |
142 base::Callback<void(content::DevToolsAgentHost*, bool)> devtools_callback_; | 142 base::Callback<void(content::DevToolsAgentHost*, bool)> devtools_callback_; |
143 }; | 143 }; |
144 | 144 |
145 } // namespace extensions | 145 } // namespace extensions |
146 | 146 |
147 #endif // APPS_SHELL_WINDOW_REGISTRY_H_ | 147 #endif // APPS_APP_WINDOW_REGISTRY_H_ |
OLD | NEW |