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/window_controller_list.h" | 5 #include "chrome/browser/extensions/window_controller_list.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "chrome/browser/extensions/api/tabs/windows_util.h" | 9 #include "chrome/browser/extensions/api/tabs/windows_util.h" |
10 #include "chrome/browser/extensions/chrome_extension_function_details.h" | 10 #include "chrome/browser/extensions/chrome_extension_function_details.h" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
56 | 56 |
57 WindowController* WindowControllerList::FindWindowById(int id) const { | 57 WindowController* WindowControllerList::FindWindowById(int id) const { |
58 for (ControllerList::const_iterator iter = windows().begin(); | 58 for (ControllerList::const_iterator iter = windows().begin(); |
59 iter != windows().end(); ++iter) { | 59 iter != windows().end(); ++iter) { |
60 if ((*iter)->GetWindowId() == id) | 60 if ((*iter)->GetWindowId() == id) |
61 return *iter; | 61 return *iter; |
62 } | 62 } |
63 return NULL; | 63 return NULL; |
64 } | 64 } |
65 | 65 |
66 WindowController* WindowControllerList::FindWindowByIdWithFilter( | |
67 int id, | |
68 const WindowTypeFilter& filter) const { | |
69 for (ControllerList::const_iterator iter = windows().begin(); | |
70 iter != windows().end(); ++iter) { | |
71 if ((*iter)->GetWindowId() == id && | |
72 windows_util::WindowMatchesTypeFilter(*iter, filter)) | |
not at google - send to devlin
2015/07/31 21:48:03
To share code with this and FindWindowById, and on
llandwerlin-old
2015/08/03 10:11:54
Done.
| |
73 return *iter; | |
74 } | |
75 return NULL; | |
not at google - send to devlin
2015/07/31 21:48:03
NULL --> nullptr
llandwerlin-old
2015/08/03 10:11:54
Done.
| |
76 } | |
77 | |
66 WindowController* WindowControllerList::FindWindowForFunctionById( | 78 WindowController* WindowControllerList::FindWindowForFunctionById( |
67 const UIThreadExtensionFunction* function, | 79 const UIThreadExtensionFunction* function, |
68 int id) const { | 80 int id) const { |
69 WindowController* controller = FindWindowById(id); | 81 return FindWindowForFunctionByIdWithFilter( |
70 if (controller && windows_util::CanOperateOnWindow(function, controller)) | 82 function, id, windows_util::GetDefaultWindowTypeFilters()); |
83 } | |
84 | |
85 WindowController* WindowControllerList::FindWindowForFunctionByIdWithFilter( | |
86 const UIThreadExtensionFunction* function, | |
87 int id, | |
88 const WindowTypeFilter& filter) const { | |
89 WindowController* controller = FindWindowByIdWithFilter(id, filter); | |
90 if (controller && | |
91 windows_util::CanOperateOnWindow(function, controller, filter)) | |
71 return controller; | 92 return controller; |
72 return NULL; | 93 return NULL; |
73 } | 94 } |
74 | 95 |
75 WindowController* WindowControllerList::CurrentWindowForFunction( | 96 WindowController* WindowControllerList::CurrentWindowForFunction( |
76 const UIThreadExtensionFunction* function) const { | 97 const UIThreadExtensionFunction* function) const { |
98 return CurrentWindowForFunctionWithFilter( | |
99 function, windows_util::GetDefaultWindowTypeFilters()); | |
100 } | |
101 | |
102 WindowController* WindowControllerList::CurrentWindowForFunctionWithFilter( | |
103 const UIThreadExtensionFunction* function, | |
104 const WindowTypeFilter& filter) const { | |
77 WindowController* result = NULL; | 105 WindowController* result = NULL; |
78 // Returns either the focused window (if any), or the last window in the list. | 106 // Returns either the focused window (if any), or the last window in the list. |
79 for (ControllerList::const_iterator iter = windows().begin(); | 107 for (ControllerList::const_iterator iter = windows().begin(); |
80 iter != windows().end(); ++iter) { | 108 iter != windows().end(); ++iter) { |
81 if (windows_util::CanOperateOnWindow(function, *iter)) { | 109 if (windows_util::CanOperateOnWindow(function, *iter, filter)) { |
82 result = *iter; | 110 result = *iter; |
83 if (result->window()->IsActive()) | 111 if (result->window()->IsActive()) |
84 break; // use focused window | 112 break; // use focused window |
85 } | 113 } |
86 } | 114 } |
87 return result; | 115 return result; |
88 } | 116 } |
89 | 117 |
90 } // namespace extensions | 118 } // namespace extensions |
OLD | NEW |