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

Side by Side Diff: chrome/browser/extensions/shell_window_registry.h

Issue 16702003: Move ShellWindow into apps component. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: yar Created 7 years, 5 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 (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 <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; 18 class Profile;
19
20 namespace apps {
19 class ShellWindow; 21 class ShellWindow;
22 }
20 23
21 namespace content { 24 namespace content {
22 class DevToolsAgentHost; 25 class DevToolsAgentHost;
23 class RenderViewHost; 26 class RenderViewHost;
24 } 27 }
25 28
26 namespace extensions { 29 namespace extensions {
27 30
28 // The ShellWindowRegistry tracks the ShellWindows for all platform apps for a 31 // The ShellWindowRegistry tracks the ShellWindows for all platform apps for a
29 // particular profile. 32 // particular profile.
30 // This class is planned to evolve into tracking all PlatformApps for a 33 // This class is planned to evolve into tracking all PlatformApps for a
31 // particular profile, with a PlatformApp encapsulating all views (background 34 // particular profile, with a PlatformApp encapsulating all views (background
32 // page, shell windows, tray view, panels etc.) and other app level behaviour 35 // page, shell windows, tray view, panels etc.) and other app level behaviour
33 // (e.g. notifications the app is interested in, lifetime of the background 36 // (e.g. notifications the app is interested in, lifetime of the background
34 // page). 37 // page).
35 class ShellWindowRegistry : public BrowserContextKeyedService { 38 class ShellWindowRegistry : public BrowserContextKeyedService {
36 public: 39 public:
37 class Observer { 40 class Observer {
38 public: 41 public:
39 // Called just after a shell window was added. 42 // Called just after a shell window was added.
40 virtual void OnShellWindowAdded(ShellWindow* shell_window) = 0; 43 virtual void OnShellWindowAdded(apps::ShellWindow* shell_window) = 0;
41 // Called when the window icon changes. 44 // Called when the window icon changes.
42 virtual void OnShellWindowIconChanged(ShellWindow* shell_window) = 0; 45 virtual void OnShellWindowIconChanged(apps::ShellWindow* shell_window) = 0;
43 // Called just after a shell window was removed. 46 // Called just after a shell window was removed.
44 virtual void OnShellWindowRemoved(ShellWindow* shell_window) = 0; 47 virtual void OnShellWindowRemoved(apps::ShellWindow* shell_window) = 0;
45 48
46 protected: 49 protected:
47 virtual ~Observer() {} 50 virtual ~Observer() {}
48 }; 51 };
49 52
50 typedef std::list<ShellWindow*> ShellWindowList; 53 typedef std::list<apps::ShellWindow*> ShellWindowList;
51 typedef ShellWindowList::const_iterator const_iterator; 54 typedef ShellWindowList::const_iterator const_iterator;
52 typedef std::set<std::string> InspectedWindowSet; 55 typedef std::set<std::string> InspectedWindowSet;
53 56
54 explicit ShellWindowRegistry(Profile* profile); 57 explicit ShellWindowRegistry(Profile* profile);
55 virtual ~ShellWindowRegistry(); 58 virtual ~ShellWindowRegistry();
56 59
57 // Returns the instance for the given profile, or NULL if none. This is 60 // Returns the instance for the given profile, or NULL if none. This is
58 // a convenience wrapper around ShellWindowRegistry::Factory::GetForProfile. 61 // a convenience wrapper around ShellWindowRegistry::Factory::GetForProfile.
59 static ShellWindowRegistry* Get(Profile* profile); 62 static ShellWindowRegistry* Get(Profile* profile);
60 63
61 void AddShellWindow(ShellWindow* shell_window); 64 void AddShellWindow(apps::ShellWindow* shell_window);
62 void ShellWindowIconChanged(ShellWindow* shell_window); 65 void ShellWindowIconChanged(apps::ShellWindow* shell_window);
63 // Called by |shell_window| when it is activated. 66 // Called by |shell_window| when it is activated.
64 void ShellWindowActivated(ShellWindow* shell_window); 67 void ShellWindowActivated(apps::ShellWindow* shell_window);
65 void RemoveShellWindow(ShellWindow* shell_window); 68 void RemoveShellWindow(apps::ShellWindow* shell_window);
66 69
67 void AddObserver(Observer* observer); 70 void AddObserver(Observer* observer);
68 void RemoveObserver(Observer* observer); 71 void RemoveObserver(Observer* observer);
69 72
70 // Returns a set of windows owned by the application identified by app_id. 73 // Returns a set of windows owned by the application identified by app_id.
71 ShellWindowList GetShellWindowsForApp(const std::string& app_id) const; 74 ShellWindowList GetShellWindowsForApp(const std::string& app_id) const;
72 const ShellWindowList& shell_windows() const { return shell_windows_; } 75 const ShellWindowList& shell_windows() const { return shell_windows_; }
73 76
74 // Helper functions to find shell windows with particular attributes. 77 // Helper functions to find shell windows with particular attributes.
75 ShellWindow* GetShellWindowForRenderViewHost( 78 apps::ShellWindow* GetShellWindowForRenderViewHost(
76 content::RenderViewHost* render_view_host) const; 79 content::RenderViewHost* render_view_host) const;
77 ShellWindow* GetShellWindowForNativeWindow(gfx::NativeWindow window) const; 80 apps::ShellWindow* GetShellWindowForNativeWindow(
81 gfx::NativeWindow window) const;
78 // Returns an app window for the given app, or NULL if no shell windows are 82 // 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 83 // 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. 84 // be returned, otherwise an arbitrary window will be returned.
81 ShellWindow* GetCurrentShellWindowForApp(const std::string& app_id) const; 85 apps::ShellWindow* GetCurrentShellWindowForApp(
86 const std::string& app_id) const;
82 // Returns an app window for the given app and window key, or NULL if no shell 87 // Returns an app window for the given app and window key, or NULL if no shell
83 // window with the key are open. If there is a window for the given app and 88 // window with the key are open. If there is a window for the given app and
84 // key that is active, that one will be returned, otherwise an arbitrary 89 // key that is active, that one will be returned, otherwise an arbitrary
85 // window will be returned. 90 // window will be returned.
86 ShellWindow* GetShellWindowForAppAndKey(const std::string& app_id, 91 apps::ShellWindow* GetShellWindowForAppAndKey(
87 const std::string& window_key) const; 92 const std::string& app_id,
93 const std::string& window_key) const;
88 94
89 // Returns whether a ShellWindow's ID was last known to have a DevToolsAgent 95 // Returns whether a ShellWindow's ID was last known to have a DevToolsAgent
90 // attached to it, which should be restored during a reload of a corresponding 96 // attached to it, which should be restored during a reload of a corresponding
91 // newly created |render_view_host|. 97 // newly created |render_view_host|.
92 bool HadDevToolsAttached(content::RenderViewHost* render_view_host) const; 98 bool HadDevToolsAttached(content::RenderViewHost* render_view_host) const;
93 99
94 // Returns the shell window for |window|, looking in all profiles. 100 // Returns the shell window for |window|, looking in all profiles.
95 static ShellWindow* GetShellWindowForNativeWindowAnyProfile( 101 static apps::ShellWindow* GetShellWindowForNativeWindowAnyProfile(
96 gfx::NativeWindow window); 102 gfx::NativeWindow window);
97 103
98 // Returns true if the number of shell windows registered across all profiles 104 // Returns true if the number of shell windows registered across all profiles
99 // is non-zero. |window_type_mask| is a bitwise OR filter of 105 // is non-zero. |window_type_mask| is a bitwise OR filter of
100 // ShellWindow::WindowType, or 0 for any window type. 106 // ShellWindow::WindowType, or 0 for any window type.
101 static bool IsShellWindowRegisteredInAnyProfile(int window_type_mask); 107 static bool IsShellWindowRegisteredInAnyProfile(int window_type_mask);
102 108
103 class Factory : public BrowserContextKeyedServiceFactory { 109 class Factory : public BrowserContextKeyedServiceFactory {
104 public: 110 public:
105 static ShellWindowRegistry* GetForProfile(Profile* profile, bool create); 111 static ShellWindowRegistry* GetForProfile(Profile* profile, bool create);
(...skipping 13 matching lines...) Expand all
119 virtual content::BrowserContext* GetBrowserContextToUse( 125 virtual content::BrowserContext* GetBrowserContextToUse(
120 content::BrowserContext* context) const OVERRIDE; 126 content::BrowserContext* context) const OVERRIDE;
121 }; 127 };
122 128
123 protected: 129 protected:
124 void OnDevToolsStateChanged(content::DevToolsAgentHost*, bool attached); 130 void OnDevToolsStateChanged(content::DevToolsAgentHost*, bool attached);
125 131
126 private: 132 private:
127 // Ensures the specified |shell_window| is included in |shell_windows_|. 133 // Ensures the specified |shell_window| is included in |shell_windows_|.
128 // Otherwise adds |shell_window| to the back of |shell_windows_|. 134 // Otherwise adds |shell_window| to the back of |shell_windows_|.
129 void AddShellWindowToList(ShellWindow* shell_window); 135 void AddShellWindowToList(apps::ShellWindow* shell_window);
130 136
131 // Bring |shell_window| to the front of |shell_windows_|. If it is not in the 137 // Bring |shell_window| to the front of |shell_windows_|. If it is not in the
132 // list, add it first. 138 // list, add it first.
133 void BringToFront(ShellWindow* shell_window); 139 void BringToFront(apps::ShellWindow* shell_window);
134 140
135 Profile* profile_; 141 Profile* profile_;
136 ShellWindowList shell_windows_; 142 ShellWindowList shell_windows_;
137 InspectedWindowSet inspected_windows_; 143 InspectedWindowSet inspected_windows_;
138 ObserverList<Observer> observers_; 144 ObserverList<Observer> observers_;
139 base::Callback<void(content::DevToolsAgentHost*, bool)> devtools_callback_; 145 base::Callback<void(content::DevToolsAgentHost*, bool)> devtools_callback_;
140 }; 146 };
141 147
142 } // namespace extensions 148 } // namespace extensions
143 149
144 #endif // CHROME_BROWSER_EXTENSIONS_SHELL_WINDOW_REGISTRY_H_ 150 #endif // CHROME_BROWSER_EXTENSIONS_SHELL_WINDOW_REGISTRY_H_
OLDNEW
« no previous file with comments | « chrome/browser/extensions/platform_app_browsertest_util.cc ('k') | chrome/browser/extensions/shell_window_registry.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698