OLD | NEW |
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_WINDOW_CONTROLLER_LIST_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_WINDOW_CONTROLLER_LIST_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_WINDOW_CONTROLLER_LIST_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_WINDOW_CONTROLLER_LIST_H_ |
7 | 7 |
8 #include <list> | 8 #include <list> |
9 | 9 |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
11 #include "base/memory/singleton.h" | 11 #include "base/memory/singleton.h" |
12 #include "base/observer_list.h" | 12 #include "base/observer_list.h" |
13 #include "chrome/browser/extensions/window_controller.h" | 13 #include "chrome/browser/extensions/window_controller.h" |
| 14 #include "chrome/common/extensions/api/windows.h" |
14 | 15 |
15 class Profile; | 16 class Profile; |
16 class UIThreadExtensionFunction; | 17 class UIThreadExtensionFunction; |
17 | 18 |
18 namespace extensions { | 19 namespace extensions { |
19 | 20 |
| 21 typedef std::vector<api::windows::WindowType> WindowTypeFilter; |
| 22 |
20 class WindowControllerListObserver; | 23 class WindowControllerListObserver; |
21 | 24 |
22 // Class to maintain a list of WindowControllers. | 25 // Class to maintain a list of WindowControllers. |
23 class WindowControllerList { | 26 class WindowControllerList { |
24 public: | 27 public: |
25 typedef std::list<WindowController*> ControllerList; | 28 typedef std::list<WindowController*> ControllerList; |
26 | 29 |
27 WindowControllerList(); | 30 WindowControllerList(); |
28 ~WindowControllerList(); | 31 ~WindowControllerList(); |
29 | 32 |
30 void AddExtensionWindow(WindowController* window); | 33 void AddExtensionWindow(WindowController* window); |
31 void RemoveExtensionWindow(WindowController* window); | 34 void RemoveExtensionWindow(WindowController* window); |
32 | 35 |
33 void AddObserver(WindowControllerListObserver* observer); | 36 void AddObserver(WindowControllerListObserver* observer); |
34 void RemoveObserver(WindowControllerListObserver* observer); | 37 void RemoveObserver(WindowControllerListObserver* observer); |
35 | 38 |
36 // Returns a window matching |id|. | 39 // Returns a window matching |id|. |
37 WindowController* FindWindowById(int id) const; | 40 WindowController* FindWindowById(int id) const; |
38 | 41 |
| 42 // Returns a window matching |id| using |filter|. |
| 43 WindowController* FindWindowByIdWithFilter( |
| 44 int id, |
| 45 const WindowTypeFilter& filter) const; |
| 46 |
39 // Returns a window matching the context the function was invoked in. | 47 // Returns a window matching the context the function was invoked in. |
40 WindowController* FindWindowForFunctionById( | 48 WindowController* FindWindowForFunctionById( |
41 const UIThreadExtensionFunction* function, | 49 const UIThreadExtensionFunction* function, |
42 int id) const; | 50 int id) const; |
43 | 51 |
| 52 // Returns a window matching the context the function was invoked in |
| 53 // using |filter|. |
| 54 WindowController* FindWindowForFunctionByIdWithFilter( |
| 55 const UIThreadExtensionFunction* function, |
| 56 int id, |
| 57 const WindowTypeFilter& filter) const; |
| 58 |
44 // Returns the focused or last added window matching the context the function | 59 // Returns the focused or last added window matching the context the function |
45 // was invoked in. | 60 // was invoked in. |
46 WindowController* CurrentWindowForFunction( | 61 WindowController* CurrentWindowForFunction( |
47 const UIThreadExtensionFunction* function) const; | 62 const UIThreadExtensionFunction* function) const; |
48 | 63 |
| 64 // Returns the focused or last added window matching the context the function |
| 65 // was invoked in using |filter|. |
| 66 WindowController* CurrentWindowForFunctionWithFilter( |
| 67 const UIThreadExtensionFunction* function, |
| 68 const WindowTypeFilter& filter) const; |
| 69 |
49 const ControllerList& windows() const { return windows_; } | 70 const ControllerList& windows() const { return windows_; } |
50 | 71 |
51 static WindowControllerList* GetInstance(); | 72 static WindowControllerList* GetInstance(); |
52 | 73 |
53 private: | 74 private: |
54 friend struct DefaultSingletonTraits<WindowControllerList>; | 75 friend struct DefaultSingletonTraits<WindowControllerList>; |
55 | 76 |
56 // Entries are not owned by this class and must be removed when destroyed. | 77 // Entries are not owned by this class and must be removed when destroyed. |
57 ControllerList windows_; | 78 ControllerList windows_; |
58 | 79 |
59 base::ObserverList<WindowControllerListObserver> observers_; | 80 base::ObserverList<WindowControllerListObserver> observers_; |
60 | 81 |
61 DISALLOW_COPY_AND_ASSIGN(WindowControllerList); | 82 DISALLOW_COPY_AND_ASSIGN(WindowControllerList); |
62 }; | 83 }; |
63 | 84 |
64 } // namespace extensions | 85 } // namespace extensions |
65 | 86 |
66 #endif // CHROME_BROWSER_EXTENSIONS_WINDOW_CONTROLLER_LIST_H_ | 87 #endif // CHROME_BROWSER_EXTENSIONS_WINDOW_CONTROLLER_LIST_H_ |
OLD | NEW |