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()-> |
164 function->profile(), | 157 CurrentWindowForFunction(function); |
165 ProfileMatchType(function->include_incognito())); | |
166 } | 158 } |
167 if (!(*controller)) { | 159 if (!(*controller)) { |
168 function->SetError(keys::kNoCurrentWindowError); | 160 function->SetError(keys::kNoCurrentWindowError); |
169 return false; | 161 return false; |
170 } | 162 } |
171 } else { | 163 } else { |
172 *controller = ExtensionWindowList::GetInstance()->FindWindowById( | 164 *controller = ExtensionWindowList::GetInstance()->FindWindowForFunctionById( |
173 function->profile(), | 165 function, window_id); |
174 ProfileMatchType(function->include_incognito()), | |
175 window_id); | |
176 if (!(*controller)) { | 166 if (!(*controller)) { |
177 function->SetError(ExtensionErrorUtils::FormatErrorMessage( | 167 function->SetError(ExtensionErrorUtils::FormatErrorMessage( |
178 keys::kWindowNotFoundError, base::IntToString(window_id))); | 168 keys::kWindowNotFoundError, base::IntToString(window_id))); |
179 return false; | 169 return false; |
180 } | 170 } |
181 } | 171 } |
182 return true; | 172 return true; |
183 } | 173 } |
184 // |error_message| can optionally be passed in and will be set with an | 174 // |error_message| can optionally be passed in and will be set with an |
185 // appropriate message if the tab cannot be found by id. | 175 // 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; | 294 bool populate_tabs = false; |
305 if (params->get_info.get() && params->get_info->populate.get()) | 295 if (params->get_info.get() && params->get_info->populate.get()) |
306 populate_tabs = *params->get_info->populate; | 296 populate_tabs = *params->get_info->populate; |
307 | 297 |
308 ListValue* window_list = new ListValue(); | 298 ListValue* window_list = new ListValue(); |
309 const ExtensionWindowList::WindowList& windows = | 299 const ExtensionWindowList::WindowList& windows = |
310 ExtensionWindowList::GetInstance()->windows(); | 300 ExtensionWindowList::GetInstance()->windows(); |
311 for (ExtensionWindowList::WindowList::const_iterator iter = | 301 for (ExtensionWindowList::WindowList::const_iterator iter = |
312 windows.begin(); | 302 windows.begin(); |
313 iter != windows.end(); ++iter) { | 303 iter != windows.end(); ++iter) { |
314 if (!(*iter)->MatchesProfile( | 304 if (!this->CanOperateOnWindow(*iter)) |
315 profile(), ProfileMatchType(include_incognito()))) | |
316 continue; | 305 continue; |
317 if (populate_tabs) | 306 if (populate_tabs) |
318 window_list->Append((*iter)->CreateWindowValueWithTabs()); | 307 window_list->Append((*iter)->CreateWindowValueWithTabs()); |
319 else | 308 else |
320 window_list->Append((*iter)->CreateWindowValue()); | 309 window_list->Append((*iter)->CreateWindowValue()); |
321 } | 310 } |
322 result_.reset(window_list); | 311 result_.reset(window_list); |
323 return true; | 312 return true; |
324 } | 313 } |
325 | 314 |
(...skipping 1471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1797 // called for every API call the extension made. | 1786 // called for every API call the extension made. |
1798 GotLanguage(language); | 1787 GotLanguage(language); |
1799 } | 1788 } |
1800 | 1789 |
1801 void DetectTabLanguageFunction::GotLanguage(const std::string& language) { | 1790 void DetectTabLanguageFunction::GotLanguage(const std::string& language) { |
1802 result_.reset(Value::CreateStringValue(language.c_str())); | 1791 result_.reset(Value::CreateStringValue(language.c_str())); |
1803 SendResponse(true); | 1792 SendResponse(true); |
1804 | 1793 |
1805 Release(); // Balanced in Run() | 1794 Release(); // Balanced in Run() |
1806 } | 1795 } |
OLD | NEW |