blob: e3d2c7932610c3868ad9a5368ba1e620f692b476 [file] [log] [blame]
[email protected]d72d3a62012-05-10 03:45:081// 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]d72d3a62012-05-10 03:45:087
8#include <set>
9
10#include "base/compiler_specific.h"
11#include "base/memory/singleton.h"
[email protected]259771102012-05-31 16:52:2012#include "base/observer_list.h"
[email protected]d72d3a62012-05-10 03:45:0813#include "chrome/browser/profiles/profile_keyed_service.h"
14#include "chrome/browser/profiles/profile_keyed_service_factory.h"
[email protected]763cb9072012-06-25 21:39:5115#include "ui/gfx/native_widget_types.h"
[email protected]d72d3a62012-05-10 03:45:0816
17class Profile;
18class ShellWindow;
19
[email protected]7bc8299d2012-06-13 09:18:2920namespace content {
21class RenderViewHost;
22}
23
[email protected]d9ede582012-08-14 19:21:3824namespace extensions {
25
[email protected]d72d3a62012-05-10 03:45:0826// 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).
33class ShellWindowRegistry : public ProfileKeyedService {
34 public:
[email protected]259771102012-05-31 16:52:2035 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]d72d3a62012-05-10 03:45:0846 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]259771102012-05-31 16:52:2059 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]6574d79e2012-07-25 22:48:2763 ShellWindowSet GetShellWindowsForApp(const std::string& app_id) const;
[email protected]d72d3a62012-05-10 03:45:0864 const ShellWindowSet& shell_windows() const { return shell_windows_; }
65
[email protected]763cb9072012-06-25 21:39:5166 // Helper functions to find shell windows with particular attributes.
[email protected]7bc8299d2012-06-13 09:18:2967 ShellWindow* GetShellWindowForRenderViewHost(
68 content::RenderViewHost* render_view_host) const;
[email protected]763cb9072012-06-25 21:39:5169 ShellWindow* GetShellWindowForNativeWindow(gfx::NativeWindow window) const;
[email protected]7bc8299d2012-06-13 09:18:2970
[email protected]d72d3a62012-05-10 03:45:0871 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]259771102012-05-31 16:52:2091 ObserverList<Observer> observers_;
[email protected]d72d3a62012-05-10 03:45:0892};
93
[email protected]d9ede582012-08-14 19:21:3894} // namespace extensions
95
[email protected]d72d3a62012-05-10 03:45:0896#endif // CHROME_BROWSER_EXTENSIONS_SHELL_WINDOW_REGISTRY_H_