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