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_tabs_module.h" | 5 #include "chrome/browser/extensions/extension_tabs_module.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 *browser = GetBrowserInProfileWithId( | 135 *browser = GetBrowserInProfileWithId( |
136 function->profile(), window_id, function->include_incognito(), &error); | 136 function->profile(), window_id, function->include_incognito(), &error); |
137 if (!*browser) { | 137 if (!*browser) { |
138 function->SetError(error); | 138 function->SetError(error); |
139 return false; | 139 return false; |
140 } | 140 } |
141 } | 141 } |
142 return true; | 142 return true; |
143 } | 143 } |
144 | 144 |
145 ExtensionWindowController::ProfileMatchType ProfileMatchType( | |
146 bool include_incognito) { | |
147 return include_incognito ? | |
148 ExtensionWindowController::MATCH_INCOGNITO | |
149 : ExtensionWindowController::MATCH_NORMAL_ONLY; | |
150 } | |
151 | |
152 bool GetWindowFromWindowID(UIThreadExtensionFunction* function, | 145 bool GetWindowFromWindowID(UIThreadExtensionFunction* function, |
153 int window_id, | 146 int window_id, |
154 ExtensionWindowController** controller) { | 147 ExtensionWindowController** controller) { |
155 if (window_id == extension_misc::kCurrentWindowId) { | 148 if (window_id == extension_misc::kCurrentWindowId) { |
156 ExtensionWindowController* extension_window_controller = | 149 ExtensionWindowController* extension_window_controller = |
157 function->dispatcher()->delegate()->GetExtensionWindowController(); | 150 function->dispatcher()->delegate()->GetExtensionWindowController(); |
158 // If there is a window controller associated with this extension, use that. | 151 // If there is a window controller associated with this extension, use that. |
159 if (extension_window_controller) { | 152 if (extension_window_controller) { |
160 *controller = extension_window_controller; | 153 *controller = extension_window_controller; |
161 } else { | 154 } else { |
162 // Otherwise get the focused or most recently added window. | 155 // Otherwise get the focused or most recently added window. |
163 *controller = ExtensionWindowList::GetInstance()->CurrentWindow( | 156 *controller = ExtensionWindowList::GetInstance()->CurrentWindow(function); |
164 function->profile(), | |
165 ProfileMatchType(function->include_incognito())); | |
166 } | 157 } |
167 if (!(*controller)) { | 158 if (!(*controller)) { |
168 function->SetError(keys::kNoCurrentWindowError); | 159 function->SetError(keys::kNoCurrentWindowError); |
169 return false; | 160 return false; |
170 } | 161 } |
171 } else { | 162 } else { |
172 *controller = ExtensionWindowList::GetInstance()->FindWindowById( | 163 *controller = ExtensionWindowList::GetInstance()->FindWindowById( |
173 function->profile(), | 164 function, window_id); |
174 ProfileMatchType(function->include_incognito()), | |
175 window_id); | |
176 if (!(*controller)) { | 165 if (!(*controller)) { |
177 function->SetError(ExtensionErrorUtils::FormatErrorMessage( | 166 function->SetError(ExtensionErrorUtils::FormatErrorMessage( |
178 keys::kWindowNotFoundError, base::IntToString(window_id))); | 167 keys::kWindowNotFoundError, base::IntToString(window_id))); |
179 return false; | 168 return false; |
180 } | 169 } |
181 } | 170 } |
182 return true; | 171 return true; |
183 } | 172 } |
184 // |error_message| can optionally be passed in and will be set with an | 173 // |error_message| can optionally be passed in and will be set with an |
185 // appropriate message if the tab cannot be found by id. | 174 // appropriate message if the tab cannot be found by id. |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 bool populate_tabs = false; | 293 bool populate_tabs = false; |
305 if (params->get_info.get() && params->get_info->populate.get()) | 294 if (params->get_info.get() && params->get_info->populate.get()) |
306 populate_tabs = *params->get_info->populate; | 295 populate_tabs = *params->get_info->populate; |
307 | 296 |
308 ListValue* window_list = new ListValue(); | 297 ListValue* window_list = new ListValue(); |
309 const ExtensionWindowList::WindowList& windows = | 298 const ExtensionWindowList::WindowList& windows = |
310 ExtensionWindowList::GetInstance()->windows(); | 299 ExtensionWindowList::GetInstance()->windows(); |
311 for (ExtensionWindowList::WindowList::const_iterator iter = | 300 for (ExtensionWindowList::WindowList::const_iterator iter = |
312 windows.begin(); | 301 windows.begin(); |
313 iter != windows.end(); ++iter) { | 302 iter != windows.end(); ++iter) { |
314 if (!(*iter)->MatchesProfile( | 303 if (!(*iter)->IsVisibleToFunction(this)) |
315 profile(), ProfileMatchType(include_incognito()))) | |
316 continue; | 304 continue; |
317 if (populate_tabs) | 305 if (populate_tabs) |
318 window_list->Append((*iter)->CreateWindowValueWithTabs()); | 306 window_list->Append((*iter)->CreateWindowValueWithTabs()); |
319 else | 307 else |
320 window_list->Append((*iter)->CreateWindowValue()); | 308 window_list->Append((*iter)->CreateWindowValue()); |
321 } | 309 } |
322 result_.reset(window_list); | 310 result_.reset(window_list); |
323 return true; | 311 return true; |
324 } | 312 } |
325 | 313 |
(...skipping 1471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1797 // called for every API call the extension made. | 1785 // called for every API call the extension made. |
1798 GotLanguage(language); | 1786 GotLanguage(language); |
1799 } | 1787 } |
1800 | 1788 |
1801 void DetectTabLanguageFunction::GotLanguage(const std::string& language) { | 1789 void DetectTabLanguageFunction::GotLanguage(const std::string& language) { |
1802 result_.reset(Value::CreateStringValue(language.c_str())); | 1790 result_.reset(Value::CreateStringValue(language.c_str())); |
1803 SendResponse(true); | 1791 SendResponse(true); |
1804 | 1792 |
1805 Release(); // Balanced in Run() | 1793 Release(); // Balanced in Run() |
1806 } | 1794 } |
OLD | NEW |