OLD | NEW |
| (Empty) |
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 #include "chrome/browser/extensions/extension_window_list.h" | |
6 | |
7 #include <algorithm> | |
8 | |
9 #include "chrome/browser/extensions/extension_function.h" | |
10 #include "chrome/browser/sessions/session_id.h" | |
11 #include "chrome/browser/ui/base_window.h" | |
12 | |
13 /////////////////////////////////////////////////////////////////////////////// | |
14 // ExtensionWindowList | |
15 | |
16 // static | |
17 ExtensionWindowList* ExtensionWindowList::GetInstance() { | |
18 return Singleton<ExtensionWindowList>::get(); | |
19 } | |
20 | |
21 ExtensionWindowList::ExtensionWindowList() { | |
22 } | |
23 | |
24 ExtensionWindowList::~ExtensionWindowList() { | |
25 } | |
26 | |
27 void ExtensionWindowList::AddExtensionWindow( | |
28 ExtensionWindowController* window) { | |
29 windows_.push_back(window); | |
30 } | |
31 | |
32 void ExtensionWindowList::RemoveExtensionWindow( | |
33 ExtensionWindowController* window) { | |
34 WindowList::iterator iter = std::find( | |
35 windows_.begin(), windows_.end(), window); | |
36 if (iter != windows_.end()) | |
37 windows_.erase(iter); | |
38 } | |
39 | |
40 ExtensionWindowController* ExtensionWindowList::FindWindowForFunctionById( | |
41 const UIThreadExtensionFunction* function, | |
42 int id) const { | |
43 for (WindowList::const_iterator iter = windows().begin(); | |
44 iter != windows().end(); ++iter) { | |
45 if (function->CanOperateOnWindow(*iter) && (*iter)->GetWindowId() == id) | |
46 return *iter; | |
47 } | |
48 return NULL; | |
49 } | |
50 | |
51 ExtensionWindowController* ExtensionWindowList::CurrentWindowForFunction( | |
52 const UIThreadExtensionFunction* function) const { | |
53 ExtensionWindowController* result = NULL; | |
54 // Returns either the focused window (if any), or the last window in the list. | |
55 for (WindowList::const_iterator iter = windows().begin(); | |
56 iter != windows().end(); ++iter) { | |
57 if (function->CanOperateOnWindow(*iter)) { | |
58 result = *iter; | |
59 if (result->window()->IsActive()) | |
60 break; // use focused window | |
61 } | |
62 } | |
63 return result; | |
64 } | |
OLD | NEW |