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 #include "chrome/browser/extensions/extension_window_list.h" | 5 #include "chrome/browser/extensions/extension_window_list.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "chrome/browser/extensions/extension_function.h" | |
9 #include "chrome/browser/sessions/session_id.h" | 10 #include "chrome/browser/sessions/session_id.h" |
10 #include "chrome/browser/ui/base_window.h" | 11 #include "chrome/browser/ui/base_window.h" |
11 | 12 |
12 /////////////////////////////////////////////////////////////////////////////// | 13 /////////////////////////////////////////////////////////////////////////////// |
13 // ExtensionWindowList | 14 // ExtensionWindowList |
14 | 15 |
15 // static | 16 // static |
16 ExtensionWindowList* ExtensionWindowList::GetInstance() { | 17 ExtensionWindowList* ExtensionWindowList::GetInstance() { |
17 return Singleton<ExtensionWindowList>::get(); | 18 return Singleton<ExtensionWindowList>::get(); |
18 } | 19 } |
(...skipping 11 matching lines...) Expand all Loading... | |
30 | 31 |
31 void ExtensionWindowList::RemoveExtensionWindow( | 32 void ExtensionWindowList::RemoveExtensionWindow( |
32 ExtensionWindowController* window) { | 33 ExtensionWindowController* window) { |
33 WindowList::iterator iter = std::find( | 34 WindowList::iterator iter = std::find( |
34 windows_.begin(), windows_.end(), window); | 35 windows_.begin(), windows_.end(), window); |
35 if (iter != windows_.end()) | 36 if (iter != windows_.end()) |
36 windows_.erase(iter); | 37 windows_.erase(iter); |
37 } | 38 } |
38 | 39 |
39 ExtensionWindowController* ExtensionWindowList::FindWindowById( | 40 ExtensionWindowController* ExtensionWindowList::FindWindowById( |
40 Profile* profile, | 41 const UIThreadExtensionFunction* function, |
stevenjb
2012/05/21 21:55:42
nit: Maybe we should rename this something like Fi
Mihai Parparita -not on Chrome
2012/05/21 22:05:29
Done.
| |
41 ProfileMatchType match_type, | |
42 int id) const { | 42 int id) const { |
43 for (WindowList::const_iterator iter = windows().begin(); | 43 for (WindowList::const_iterator iter = windows().begin(); |
44 iter != windows().end(); ++iter) { | 44 iter != windows().end(); ++iter) { |
45 if ((*iter)->MatchesProfile(profile, match_type)) { | 45 if (function->CanOperateOnWindow(*iter) && (*iter)->GetWindowId() == id) |
46 if ((*iter)->GetWindowId() == id) | 46 return *iter; |
47 return *iter; | |
48 } | |
49 } | 47 } |
50 return NULL; | 48 return NULL; |
51 } | 49 } |
52 | 50 |
53 ExtensionWindowController* ExtensionWindowList::CurrentWindow( | 51 ExtensionWindowController* ExtensionWindowList::CurrentWindow( |
54 Profile* profile, | 52 const UIThreadExtensionFunction* function) const { |
stevenjb
2012/05/21 21:55:42
nit: Maybe CurrentWindowForFunction?
Mihai Parparita -not on Chrome
2012/05/21 22:05:29
Done.
| |
55 ProfileMatchType match_type) const { | |
56 ExtensionWindowController* result = NULL; | 53 ExtensionWindowController* result = NULL; |
57 // Returns either the focused window (if any), or the last window in the list. | 54 // Returns either the focused window (if any), or the last window in the list. |
58 for (WindowList::const_iterator iter = windows().begin(); | 55 for (WindowList::const_iterator iter = windows().begin(); |
59 iter != windows().end(); ++iter) { | 56 iter != windows().end(); ++iter) { |
60 if ((*iter)->MatchesProfile(profile, match_type)) { | 57 if (function->CanOperateOnWindow(*iter)) { |
61 result = *iter; | 58 result = *iter; |
62 if (result->window()->IsActive()) | 59 if (result->window()->IsActive()) |
63 break; // use focused window | 60 break; // use focused window |
64 } | 61 } |
65 } | 62 } |
66 return result; | 63 return result; |
67 } | 64 } |
OLD | NEW |