Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(812)

Side by Side Diff: extensions/browser/app_window/app_window_registry.h

Issue 494033002: Move AppWindow to extensions (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove unneeded include in chrome_shell_delegate.cc Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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_APP_WINDOW_REGISTRY_H_ 5 #ifndef EXTENSIONS_BROWSER_APP_WINDOW_APP_WINDOW_REGISTRY_H_
6 #define APPS_APP_WINDOW_REGISTRY_H_ 6 #define EXTENSIONS_BROWSER_APP_WINDOW_APP_WINDOW_REGISTRY_H_
7 7
8 #include <list> 8 #include <list>
9 #include <set>
9 #include <string> 10 #include <string>
10 #include <set>
11 11
12 #include "base/callback.h" 12 #include "base/callback.h"
13 #include "base/compiler_specific.h" 13 #include "base/compiler_specific.h"
14 #include "base/memory/singleton.h" 14 #include "base/memory/singleton.h"
15 #include "base/observer_list.h" 15 #include "base/observer_list.h"
16 #include "components/keyed_service/content/browser_context_keyed_service_factory .h" 16 #include "components/keyed_service/content/browser_context_keyed_service_factory .h"
17 #include "components/keyed_service/core/keyed_service.h" 17 #include "components/keyed_service/core/keyed_service.h"
18 #include "ui/gfx/native_widget_types.h" 18 #include "ui/gfx/native_widget_types.h"
19 19
20 namespace content { 20 namespace content {
21 class BrowserContext; 21 class BrowserContext;
22 class DevToolsAgentHost; 22 class DevToolsAgentHost;
23 class RenderViewHost; 23 class RenderViewHost;
24 } 24 }
25 25
26 namespace apps { 26 namespace extensions {
27 27
28 class AppWindow; 28 class AppWindow;
29 29
30 // The AppWindowRegistry tracks the AppWindows for all platform apps for a 30 // The AppWindowRegistry tracks the AppWindows for all platform apps for a
31 // particular browser context. 31 // particular browser context.
32 class AppWindowRegistry : public KeyedService { 32 class AppWindowRegistry : public KeyedService {
33 public: 33 public:
34 class Observer { 34 class Observer {
35 public: 35 public:
36 // Called just after a app window was added. 36 // Called just after a app window was added.
37 virtual void OnAppWindowAdded(apps::AppWindow* app_window); 37 virtual void OnAppWindowAdded(AppWindow* app_window);
38 // Called when the window icon changes. 38 // Called when the window icon changes.
39 virtual void OnAppWindowIconChanged(apps::AppWindow* app_window); 39 virtual void OnAppWindowIconChanged(AppWindow* app_window);
40 // Called just after a app window was removed. 40 // Called just after a app window was removed.
41 virtual void OnAppWindowRemoved(apps::AppWindow* app_window); 41 virtual void OnAppWindowRemoved(AppWindow* app_window);
42 // Called just after a app window was hidden. This is different from 42 // Called just after a app window was hidden. This is different from
43 // window visibility as a minimize does not hide a window, but does make 43 // window visibility as a minimize does not hide a window, but does make
44 // it not visible. 44 // it not visible.
45 virtual void OnAppWindowHidden(apps::AppWindow* app_window); 45 virtual void OnAppWindowHidden(AppWindow* app_window);
46 // Called just after a app window was shown. 46 // Called just after a app window was shown.
47 virtual void OnAppWindowShown(apps::AppWindow* app_window); 47 virtual void OnAppWindowShown(AppWindow* app_window);
48 48
49 protected: 49 protected:
50 virtual ~Observer(); 50 virtual ~Observer();
51 }; 51 };
52 52
53 typedef std::list<apps::AppWindow*> AppWindowList; 53 typedef std::list<AppWindow*> AppWindowList;
54 typedef AppWindowList::const_iterator const_iterator; 54 typedef AppWindowList::const_iterator const_iterator;
55 typedef std::set<std::string> InspectedWindowSet; 55 typedef std::set<std::string> InspectedWindowSet;
56 56
57 explicit AppWindowRegistry(content::BrowserContext* context); 57 explicit AppWindowRegistry(content::BrowserContext* context);
58 virtual ~AppWindowRegistry(); 58 virtual ~AppWindowRegistry();
59 59
60 // Returns the instance for the given browser context, or NULL if none. This 60 // Returns the instance for the given browser context, or NULL if none. This
61 // is a convenience wrapper around 61 // is a convenience wrapper around
62 // AppWindowRegistry::Factory::GetForBrowserContext(). 62 // AppWindowRegistry::Factory::GetForBrowserContext().
63 static AppWindowRegistry* Get(content::BrowserContext* context); 63 static AppWindowRegistry* Get(content::BrowserContext* context);
64 64
65 void AddAppWindow(apps::AppWindow* app_window); 65 void AddAppWindow(AppWindow* app_window);
66 void AppWindowIconChanged(apps::AppWindow* app_window); 66 void AppWindowIconChanged(AppWindow* app_window);
67 // Called by |app_window| when it is activated. 67 // Called by |app_window| when it is activated.
68 void AppWindowActivated(apps::AppWindow* app_window); 68 void AppWindowActivated(AppWindow* app_window);
69 void AppWindowHidden(apps::AppWindow* app_window); 69 void AppWindowHidden(AppWindow* app_window);
70 void AppWindowShown(apps::AppWindow* app_window); 70 void AppWindowShown(AppWindow* app_window);
71 void RemoveAppWindow(apps::AppWindow* app_window); 71 void RemoveAppWindow(AppWindow* app_window);
72 72
73 void AddObserver(Observer* observer); 73 void AddObserver(Observer* observer);
74 void RemoveObserver(Observer* observer); 74 void RemoveObserver(Observer* observer);
75 75
76 // Returns a set of windows owned by the application identified by app_id. 76 // Returns a set of windows owned by the application identified by app_id.
77 AppWindowList GetAppWindowsForApp(const std::string& app_id) const; 77 AppWindowList GetAppWindowsForApp(const std::string& app_id) const;
78 const AppWindowList& app_windows() const { return app_windows_; } 78 const AppWindowList& app_windows() const { return app_windows_; }
79 79
80 // Close all app windows associated with an app. 80 // Close all app windows associated with an app.
81 void CloseAllAppWindowsForApp(const std::string& app_id); 81 void CloseAllAppWindowsForApp(const std::string& app_id);
82 82
83 // Helper functions to find app windows with particular attributes. 83 // Helper functions to find app windows with particular attributes.
84 apps::AppWindow* GetAppWindowForRenderViewHost( 84 AppWindow* GetAppWindowForRenderViewHost(
85 content::RenderViewHost* render_view_host) const; 85 content::RenderViewHost* render_view_host) const;
86 apps::AppWindow* GetAppWindowForNativeWindow(gfx::NativeWindow window) const; 86 AppWindow* GetAppWindowForNativeWindow(gfx::NativeWindow window) const;
87 // Returns an app window for the given app, or NULL if no app windows are 87 // Returns an app window for the given app, or NULL if no app windows are
88 // open. If there is a window for the given app that is active, that one will 88 // open. If there is a window for the given app that is active, that one will
89 // be returned, otherwise an arbitrary window will be returned. 89 // be returned, otherwise an arbitrary window will be returned.
90 apps::AppWindow* GetCurrentAppWindowForApp(const std::string& app_id) const; 90 AppWindow* GetCurrentAppWindowForApp(const std::string& app_id) const;
91 // Returns an app window for the given app and window key, or NULL if no app 91 // Returns an app window for the given app and window key, or NULL if no app
92 // window with the key are open. If there is a window for the given app and 92 // window with the key are open. If there is a window for the given app and
93 // key that is active, that one will be returned, otherwise an arbitrary 93 // key that is active, that one will be returned, otherwise an arbitrary
94 // window will be returned. 94 // window will be returned.
95 apps::AppWindow* GetAppWindowForAppAndKey(const std::string& app_id, 95 AppWindow* GetAppWindowForAppAndKey(const std::string& app_id,
96 const std::string& window_key) 96 const std::string& window_key) const;
97 const;
98 97
99 // Returns whether a AppWindow's ID was last known to have a DevToolsAgent 98 // Returns whether a AppWindow's ID was last known to have a DevToolsAgent
100 // attached to it, which should be restored during a reload of a corresponding 99 // attached to it, which should be restored during a reload of a corresponding
101 // newly created |render_view_host|. 100 // newly created |render_view_host|.
102 bool HadDevToolsAttached(content::RenderViewHost* render_view_host) const; 101 bool HadDevToolsAttached(content::RenderViewHost* render_view_host) const;
103 102
104 // Returns the app window for |window|, looking in all browser contexts. 103 // Returns the app window for |window|, looking in all browser contexts.
105 static apps::AppWindow* GetAppWindowForNativeWindowAnyProfile( 104 static AppWindow* GetAppWindowForNativeWindowAnyProfile(
106 gfx::NativeWindow window); 105 gfx::NativeWindow window);
107 106
108 // Returns true if the number of app windows registered across all browser 107 // Returns true if the number of app windows registered across all browser
109 // contexts is non-zero. |window_type_mask| is a bitwise OR filter of 108 // contexts is non-zero. |window_type_mask| is a bitwise OR filter of
110 // AppWindow::WindowType, or 0 for any window type. 109 // AppWindow::WindowType, or 0 for any window type.
111 static bool IsAppWindowRegisteredInAnyProfile(int window_type_mask); 110 static bool IsAppWindowRegisteredInAnyProfile(int window_type_mask);
112 111
113 // Close all app windows in all profiles. 112 // Close all app windows in all profiles.
114 static void CloseAllAppWindows(); 113 static void CloseAllAppWindows();
115 114
(...skipping 19 matching lines...) Expand all
135 virtual content::BrowserContext* GetBrowserContextToUse( 134 virtual content::BrowserContext* GetBrowserContextToUse(
136 content::BrowserContext* context) const OVERRIDE; 135 content::BrowserContext* context) const OVERRIDE;
137 }; 136 };
138 137
139 protected: 138 protected:
140 void OnDevToolsStateChanged(content::DevToolsAgentHost*, bool attached); 139 void OnDevToolsStateChanged(content::DevToolsAgentHost*, bool attached);
141 140
142 private: 141 private:
143 // Ensures the specified |app_window| is included in |app_windows_|. 142 // Ensures the specified |app_window| is included in |app_windows_|.
144 // Otherwise adds |app_window| to the back of |app_windows_|. 143 // Otherwise adds |app_window| to the back of |app_windows_|.
145 void AddAppWindowToList(apps::AppWindow* app_window); 144 void AddAppWindowToList(AppWindow* app_window);
146 145
147 // Bring |app_window| to the front of |app_windows_|. If it is not in the 146 // Bring |app_window| to the front of |app_windows_|. If it is not in the
148 // list, add it first. 147 // list, add it first.
149 void BringToFront(apps::AppWindow* app_window); 148 void BringToFront(AppWindow* app_window);
150 149
151 content::BrowserContext* context_; 150 content::BrowserContext* context_;
152 AppWindowList app_windows_; 151 AppWindowList app_windows_;
153 InspectedWindowSet inspected_windows_; 152 InspectedWindowSet inspected_windows_;
154 ObserverList<Observer> observers_; 153 ObserverList<Observer> observers_;
155 base::Callback<void(content::DevToolsAgentHost*, bool)> devtools_callback_; 154 base::Callback<void(content::DevToolsAgentHost*, bool)> devtools_callback_;
156 }; 155 };
157 156
158 } // namespace apps 157 } // namespace extensions
159 158
160 #endif // APPS_APP_WINDOW_REGISTRY_H_ 159 #endif // EXTENSIONS_BROWSER_APP_WINDOW_APP_WINDOW_REGISTRY_H_
OLDNEW
« no previous file with comments | « extensions/browser/app_window/app_window_interactive_uitest.cc ('k') | extensions/browser/app_window/app_window_registry.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698