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/api/tabs/tabs_api.h" | 5 #include "chrome/browser/extensions/api/tabs/tabs_api.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
259 } | 259 } |
260 } | 260 } |
261 | 261 |
262 // Windows --------------------------------------------------------------------- | 262 // Windows --------------------------------------------------------------------- |
263 | 263 |
264 bool WindowsGetFunction::RunSync() { | 264 bool WindowsGetFunction::RunSync() { |
265 scoped_ptr<windows::Get::Params> params(windows::Get::Params::Create(*args_)); | 265 scoped_ptr<windows::Get::Params> params(windows::Get::Params::Create(*args_)); |
266 EXTENSION_FUNCTION_VALIDATE(params.get()); | 266 EXTENSION_FUNCTION_VALIDATE(params.get()); |
267 | 267 |
268 bool populate_tabs = false; | 268 bool populate_tabs = false; |
269 if (params->get_info.get() && params->get_info->populate.get()) | 269 std::vector<api::windows::WindowType>* type_filter = nullptr; |
270 populate_tabs = *params->get_info->populate; | 270 if (params->get_info.get()) { |
271 if (params->get_info->populate.get()) | |
272 populate_tabs = *params->get_info->populate; | |
273 type_filter = params->get_info->window_types.get(); | |
274 } | |
271 | 275 |
272 WindowController* controller; | 276 WindowController* controller; |
273 if (!windows_util::GetWindowFromWindowID(this, | 277 if (!windows_util::GetWindowFromWindowID( |
274 params->window_id, | 278 this, params->window_id, |
275 &controller)) { | 279 type_filter ? *type_filter |
280 : windows_util::GetDefaultWindowTypeFilters(), | |
281 &controller)) { | |
276 return false; | 282 return false; |
277 } | 283 } |
278 | 284 |
279 if (populate_tabs) | 285 if (populate_tabs) |
280 SetResult(controller->CreateWindowValueWithTabs(extension())); | 286 SetResult(controller->CreateWindowValueWithTabs(extension())); |
281 else | 287 else |
282 SetResult(controller->CreateWindowValue()); | 288 SetResult(controller->CreateWindowValue()); |
283 return true; | 289 return true; |
284 } | 290 } |
285 | 291 |
286 bool WindowsGetCurrentFunction::RunSync() { | 292 bool WindowsGetCurrentFunction::RunSync() { |
287 scoped_ptr<windows::GetCurrent::Params> params( | 293 scoped_ptr<windows::GetCurrent::Params> params( |
288 windows::GetCurrent::Params::Create(*args_)); | 294 windows::GetCurrent::Params::Create(*args_)); |
289 EXTENSION_FUNCTION_VALIDATE(params.get()); | 295 EXTENSION_FUNCTION_VALIDATE(params.get()); |
290 | 296 |
291 bool populate_tabs = false; | 297 bool populate_tabs = false; |
292 if (params->get_info.get() && params->get_info->populate.get()) | 298 std::vector<api::windows::WindowType>* type_filter = nullptr; |
293 populate_tabs = *params->get_info->populate; | 299 if (params->get_info.get()) { |
300 if (params->get_info->populate.get()) | |
301 populate_tabs = *params->get_info->populate; | |
302 type_filter = params->get_info->window_types.get(); | |
303 } | |
294 | 304 |
295 WindowController* controller; | 305 WindowController* controller; |
296 if (!windows_util::GetWindowFromWindowID(this, | 306 if (!windows_util::GetWindowFromWindowID( |
297 extension_misc::kCurrentWindowId, | 307 this, extension_misc::kCurrentWindowId, |
298 &controller)) { | 308 type_filter ? *type_filter |
309 : windows_util::GetDefaultWindowTypeFilters(), | |
310 &controller)) { | |
299 return false; | 311 return false; |
300 } | 312 } |
301 if (populate_tabs) | 313 if (populate_tabs) |
302 SetResult(controller->CreateWindowValueWithTabs(extension())); | 314 SetResult(controller->CreateWindowValueWithTabs(extension())); |
303 else | 315 else |
304 SetResult(controller->CreateWindowValue()); | 316 SetResult(controller->CreateWindowValue()); |
305 return true; | 317 return true; |
306 } | 318 } |
307 | 319 |
308 bool WindowsGetLastFocusedFunction::RunSync() { | 320 bool WindowsGetLastFocusedFunction::RunSync() { |
309 scoped_ptr<windows::GetLastFocused::Params> params( | 321 scoped_ptr<windows::GetLastFocused::Params> params( |
310 windows::GetLastFocused::Params::Create(*args_)); | 322 windows::GetLastFocused::Params::Create(*args_)); |
311 EXTENSION_FUNCTION_VALIDATE(params.get()); | 323 EXTENSION_FUNCTION_VALIDATE(params.get()); |
312 | 324 |
313 bool populate_tabs = false; | 325 bool populate_tabs = false; |
314 if (params->get_info.get() && params->get_info->populate.get()) | 326 std::vector<api::windows::WindowType>* type_filter = nullptr; |
315 populate_tabs = *params->get_info->populate; | 327 if (params->get_info.get()) { |
328 if (params->get_info->populate.get()) | |
329 populate_tabs = *params->get_info->populate; | |
330 type_filter = params->get_info->window_types.get(); | |
331 } | |
stevenjb
2015/07/30 19:00:37
Given that we seem to copy/paste the same code thr
llandwerlin-old
2015/07/31 13:58:32
I can't really use a helper function because the p
stevenjb
2015/07/31 17:27:16
Ugh, you're right, I missed that. It's too bad we
| |
316 | 332 |
317 // Note: currently this returns the last active browser. If we decide to | 333 // The WindowControllerList should contain a list of application, |
318 // include other window types (e.g. panels), we will need to add logic to | 334 // browser and devtools windows. |
319 // WindowControllerList that mirrors the active behavior of BrowserList. | 335 WindowController* controller = nullptr; |
320 Browser* browser = chrome::FindAnyBrowser( | 336 for (auto iter : WindowControllerList::GetInstance()->windows()) { |
321 GetProfile(), include_incognito(), chrome::GetActiveDesktop()); | 337 if (windows_util::CanOperateOnWindow( |
322 if (!browser || !browser->window()) { | 338 this, iter, type_filter |
339 ? *type_filter | |
340 : windows_util::GetDefaultWindowTypeFilters())) { | |
341 controller = iter; | |
342 if (controller->window()->IsActive()) | |
343 break; // Use focused window. | |
344 } | |
345 } | |
346 if (!controller) { | |
323 error_ = keys::kNoLastFocusedWindowError; | 347 error_ = keys::kNoLastFocusedWindowError; |
324 return false; | 348 return false; |
325 } | 349 } |
326 WindowController* controller = | |
327 browser->extension_window_controller(); | |
328 if (populate_tabs) | 350 if (populate_tabs) |
329 SetResult(controller->CreateWindowValueWithTabs(extension())); | 351 SetResult(controller->CreateWindowValueWithTabs(extension())); |
330 else | 352 else |
331 SetResult(controller->CreateWindowValue()); | 353 SetResult(controller->CreateWindowValue()); |
332 return true; | 354 return true; |
333 } | 355 } |
334 | 356 |
335 bool WindowsGetAllFunction::RunSync() { | 357 bool WindowsGetAllFunction::RunSync() { |
336 scoped_ptr<windows::GetAll::Params> params( | 358 scoped_ptr<windows::GetAll::Params> params( |
337 windows::GetAll::Params::Create(*args_)); | 359 windows::GetAll::Params::Create(*args_)); |
338 EXTENSION_FUNCTION_VALIDATE(params.get()); | 360 EXTENSION_FUNCTION_VALIDATE(params.get()); |
339 | 361 |
340 bool populate_tabs = false; | 362 bool populate_tabs = false; |
341 if (params->get_info.get() && params->get_info->populate.get()) | 363 std::vector<api::windows::WindowType>* type_filter = nullptr; |
342 populate_tabs = *params->get_info->populate; | 364 if (params->get_info.get()) { |
365 if (params->get_info->populate.get()) | |
366 populate_tabs = *params->get_info->populate; | |
367 type_filter = params->get_info->window_types.get(); | |
368 } | |
stevenjb
2015/07/30 19:00:37
Four times... :)
llandwerlin-old
2015/07/31 13:58:32
Done.
| |
343 | 369 |
344 base::ListValue* window_list = new base::ListValue(); | 370 base::ListValue* window_list = new base::ListValue(); |
345 const WindowControllerList::ControllerList& windows = | 371 const WindowControllerList::ControllerList& windows = |
346 WindowControllerList::GetInstance()->windows(); | 372 WindowControllerList::GetInstance()->windows(); |
347 for (WindowControllerList::ControllerList::const_iterator iter = | 373 for (WindowControllerList::ControllerList::const_iterator iter = |
348 windows.begin(); | 374 windows.begin(); |
349 iter != windows.end(); ++iter) { | 375 iter != windows.end(); ++iter) { |
350 if (!windows_util::CanOperateOnWindow(this, *iter)) | 376 if (!windows_util::CanOperateOnWindow( |
377 this, *iter, type_filter | |
378 ? *type_filter | |
379 : windows_util::GetDefaultWindowTypeFilters())) | |
351 continue; | 380 continue; |
352 if (populate_tabs) | 381 if (populate_tabs) |
353 window_list->Append((*iter)->CreateWindowValueWithTabs(extension())); | 382 window_list->Append((*iter)->CreateWindowValueWithTabs(extension())); |
354 else | 383 else |
355 window_list->Append((*iter)->CreateWindowValue()); | 384 window_list->Append((*iter)->CreateWindowValue()); |
356 } | 385 } |
357 SetResult(window_list); | 386 SetResult(window_list); |
358 return true; | 387 return true; |
359 } | 388 } |
360 | 389 |
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
686 | 715 |
687 return true; | 716 return true; |
688 } | 717 } |
689 | 718 |
690 bool WindowsUpdateFunction::RunSync() { | 719 bool WindowsUpdateFunction::RunSync() { |
691 scoped_ptr<windows::Update::Params> params( | 720 scoped_ptr<windows::Update::Params> params( |
692 windows::Update::Params::Create(*args_)); | 721 windows::Update::Params::Create(*args_)); |
693 EXTENSION_FUNCTION_VALIDATE(params); | 722 EXTENSION_FUNCTION_VALIDATE(params); |
694 | 723 |
695 WindowController* controller; | 724 WindowController* controller; |
696 if (!windows_util::GetWindowFromWindowID(this, params->window_id, | 725 if (!windows_util::GetWindowFromWindowID( |
697 &controller)) | 726 this, params->window_id, windows_util::GetNoWindowTypeFilters(), |
727 &controller)) | |
698 return false; | 728 return false; |
699 | 729 |
700 ui::WindowShowState show_state = | 730 ui::WindowShowState show_state = |
701 ConvertToWindowShowState(params->update_info.state); | 731 ConvertToWindowShowState(params->update_info.state); |
702 | 732 |
703 if (show_state != ui::SHOW_STATE_FULLSCREEN && | 733 if (show_state != ui::SHOW_STATE_FULLSCREEN && |
704 show_state != ui::SHOW_STATE_DEFAULT) | 734 show_state != ui::SHOW_STATE_DEFAULT) |
705 controller->SetFullscreenMode(false, extension()->url()); | 735 controller->SetFullscreenMode(false, extension()->url()); |
706 | 736 |
707 switch (show_state) { | 737 switch (show_state) { |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
788 | 818 |
789 return true; | 819 return true; |
790 } | 820 } |
791 | 821 |
792 bool WindowsRemoveFunction::RunSync() { | 822 bool WindowsRemoveFunction::RunSync() { |
793 scoped_ptr<windows::Remove::Params> params( | 823 scoped_ptr<windows::Remove::Params> params( |
794 windows::Remove::Params::Create(*args_)); | 824 windows::Remove::Params::Create(*args_)); |
795 EXTENSION_FUNCTION_VALIDATE(params); | 825 EXTENSION_FUNCTION_VALIDATE(params); |
796 | 826 |
797 WindowController* controller; | 827 WindowController* controller; |
798 if (!windows_util::GetWindowFromWindowID(this, params->window_id, | 828 if (!windows_util::GetWindowFromWindowID( |
799 &controller)) | 829 this, params->window_id, windows_util::GetDefaultWindowTypeFilters(), |
830 &controller)) | |
800 return false; | 831 return false; |
801 | 832 |
802 WindowController::Reason reason; | 833 WindowController::Reason reason; |
803 if (!controller->CanClose(&reason)) { | 834 if (!controller->CanClose(&reason)) { |
804 if (reason == WindowController::REASON_NOT_EDITABLE) | 835 if (reason == WindowController::REASON_NOT_EDITABLE) |
805 error_ = keys::kTabStripNotEditableError; | 836 error_ = keys::kTabStripNotEditableError; |
806 return false; | 837 return false; |
807 } | 838 } |
808 controller->window()->Close(); | 839 controller->window()->Close(); |
809 return true; | 840 return true; |
(...skipping 1218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2028 ZoomModeToZoomSettings(zoom_mode, &zoom_settings); | 2059 ZoomModeToZoomSettings(zoom_mode, &zoom_settings); |
2029 zoom_settings.default_zoom_factor.reset(new double( | 2060 zoom_settings.default_zoom_factor.reset(new double( |
2030 content::ZoomLevelToZoomFactor(zoom_controller->GetDefaultZoomLevel()))); | 2061 content::ZoomLevelToZoomFactor(zoom_controller->GetDefaultZoomLevel()))); |
2031 | 2062 |
2032 results_ = api::tabs::GetZoomSettings::Results::Create(zoom_settings); | 2063 results_ = api::tabs::GetZoomSettings::Results::Create(zoom_settings); |
2033 SendResponse(true); | 2064 SendResponse(true); |
2034 return true; | 2065 return true; |
2035 } | 2066 } |
2036 | 2067 |
2037 } // namespace extensions | 2068 } // namespace extensions |
OLD | NEW |