[email protected] | d72d3a6 | 2012-05-10 03:45:08 | [diff] [blame] | 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 | ||||
3 | // found in the LICENSE file. | ||||
4 | |||||
5 | #ifndef CHROME_BROWSER_EXTENSIONS_SHELL_WINDOW_REGISTRY_H_ | ||||
6 | #define CHROME_BROWSER_EXTENSIONS_SHELL_WINDOW_REGISTRY_H_ | ||||
[email protected] | d72d3a6 | 2012-05-10 03:45:08 | [diff] [blame] | 7 | |
8 | #include <set> | ||||
9 | |||||
10 | #include "base/compiler_specific.h" | ||||
11 | #include "base/memory/singleton.h" | ||||
[email protected] | 25977110 | 2012-05-31 16:52:20 | [diff] [blame] | 12 | #include "base/observer_list.h" |
[email protected] | d72d3a6 | 2012-05-10 03:45:08 | [diff] [blame] | 13 | #include "chrome/browser/profiles/profile_keyed_service.h" |
14 | #include "chrome/browser/profiles/profile_keyed_service_factory.h" | ||||
[email protected] | 763cb907 | 2012-06-25 21:39:51 | [diff] [blame] | 15 | #include "ui/gfx/native_widget_types.h" |
[email protected] | d72d3a6 | 2012-05-10 03:45:08 | [diff] [blame] | 16 | |
17 | class Profile; | ||||
18 | class ShellWindow; | ||||
19 | |||||
[email protected] | 7bc8299d | 2012-06-13 09:18:29 | [diff] [blame] | 20 | namespace content { |
21 | class RenderViewHost; | ||||
22 | } | ||||
23 | |||||
[email protected] | d9ede58 | 2012-08-14 19:21:38 | [diff] [blame^] | 24 | namespace extensions { |
25 | |||||
[email protected] | d72d3a6 | 2012-05-10 03:45:08 | [diff] [blame] | 26 | // The ShellWindowRegistry tracks the ShellWindows for all platform apps for a |
27 | // particular profile. | ||||
28 | // This class is planned to evolve into tracking all PlatformApps for a | ||||
29 | // particular profile, with a PlatformApp encapsulating all views (background | ||||
30 | // 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 | ||||
32 | // page). | ||||
33 | class ShellWindowRegistry : public ProfileKeyedService { | ||||
34 | public: | ||||
[email protected] | 25977110 | 2012-05-31 16:52:20 | [diff] [blame] | 35 | class Observer { |
36 | public: | ||||
37 | // Called just after a shell window was added. | ||||
38 | virtual void OnShellWindowAdded(ShellWindow* shell_window) = 0; | ||||
39 | // Called just after a shell window was removed. | ||||
40 | virtual void OnShellWindowRemoved(ShellWindow* shell_window) = 0; | ||||
41 | |||||
42 | protected: | ||||
43 | virtual ~Observer() {} | ||||
44 | }; | ||||
45 | |||||
[email protected] | d72d3a6 | 2012-05-10 03:45:08 | [diff] [blame] | 46 | typedef std::set<ShellWindow*> ShellWindowSet; |
47 | typedef ShellWindowSet::const_iterator const_iterator; | ||||
48 | |||||
49 | ShellWindowRegistry(); | ||||
50 | virtual ~ShellWindowRegistry(); | ||||
51 | |||||
52 | // Returns the instance for the given profile, or NULL if none. This is | ||||
53 | // a convenience wrapper around ShellWindowRegistryFactory::GetForProfile. | ||||
54 | static ShellWindowRegistry* Get(Profile* profile); | ||||
55 | |||||
56 | void AddShellWindow(ShellWindow* shell_window); | ||||
57 | void RemoveShellWindow(ShellWindow* shell_window); | ||||
58 | |||||
[email protected] | 25977110 | 2012-05-31 16:52:20 | [diff] [blame] | 59 | void AddObserver(Observer* observer); |
60 | void RemoveObserver(Observer* observer); | ||||
61 | |||||
62 | // Returns a set of windows owned by the application identified by app_id. | ||||
[email protected] | 6574d79e | 2012-07-25 22:48:27 | [diff] [blame] | 63 | ShellWindowSet GetShellWindowsForApp(const std::string& app_id) const; |
[email protected] | d72d3a6 | 2012-05-10 03:45:08 | [diff] [blame] | 64 | const ShellWindowSet& shell_windows() const { return shell_windows_; } |
65 | |||||
[email protected] | 763cb907 | 2012-06-25 21:39:51 | [diff] [blame] | 66 | // Helper functions to find shell windows with particular attributes. |
[email protected] | 7bc8299d | 2012-06-13 09:18:29 | [diff] [blame] | 67 | ShellWindow* GetShellWindowForRenderViewHost( |
68 | content::RenderViewHost* render_view_host) const; | ||||
[email protected] | 763cb907 | 2012-06-25 21:39:51 | [diff] [blame] | 69 | ShellWindow* GetShellWindowForNativeWindow(gfx::NativeWindow window) const; |
[email protected] | 7bc8299d | 2012-06-13 09:18:29 | [diff] [blame] | 70 | |
[email protected] | d72d3a6 | 2012-05-10 03:45:08 | [diff] [blame] | 71 | private: |
72 | class Factory : public ProfileKeyedServiceFactory { | ||||
73 | public: | ||||
74 | static ShellWindowRegistry* GetForProfile(Profile* profile); | ||||
75 | |||||
76 | static Factory* GetInstance(); | ||||
77 | private: | ||||
78 | friend struct DefaultSingletonTraits<Factory>; | ||||
79 | |||||
80 | Factory(); | ||||
81 | virtual ~Factory(); | ||||
82 | |||||
83 | // ProfileKeyedServiceFactory | ||||
84 | virtual ProfileKeyedService* BuildServiceInstanceFor( | ||||
85 | Profile* profile) const OVERRIDE; | ||||
86 | virtual bool ServiceIsCreatedWithProfile() OVERRIDE; | ||||
87 | virtual bool ServiceIsNULLWhileTesting() OVERRIDE; | ||||
88 | }; | ||||
89 | |||||
90 | ShellWindowSet shell_windows_; | ||||
[email protected] | 25977110 | 2012-05-31 16:52:20 | [diff] [blame] | 91 | ObserverList<Observer> observers_; |
[email protected] | d72d3a6 | 2012-05-10 03:45:08 | [diff] [blame] | 92 | }; |
93 | |||||
[email protected] | d9ede58 | 2012-08-14 19:21:38 | [diff] [blame^] | 94 | } // namespace extensions |
95 | |||||
[email protected] | d72d3a6 | 2012-05-10 03:45:08 | [diff] [blame] | 96 | #endif // CHROME_BROWSER_EXTENSIONS_SHELL_WINDOW_REGISTRY_H_ |