Chromium Code Reviews| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <algorithm> | 8 #include <algorithm> |
| 9 #include <limits> | 9 #include <limits> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 452 } | 452 } |
| 453 // Don't let the extension crash the browser or renderers. | 453 // Don't let the extension crash the browser or renderers. |
| 454 if (ExtensionTabUtil::IsKillURL(url)) { | 454 if (ExtensionTabUtil::IsKillURL(url)) { |
| 455 error_ = keys::kNoCrashBrowserError; | 455 error_ = keys::kNoCrashBrowserError; |
| 456 return false; | 456 return false; |
| 457 } | 457 } |
| 458 urls.push_back(url); | 458 urls.push_back(url); |
| 459 } | 459 } |
| 460 } | 460 } |
| 461 | 461 |
| 462 // Decide whether we are opening a normal window or an incognito window. | |
| 463 bool is_error = true; | |
| 464 bool open_incognito_window = ShouldOpenIncognitoWindow(create_data, &urls, | |
| 465 &is_error); | |
| 466 if (is_error) | |
| 467 return false; // error_ member is set inside of ShouldOpenIncognitoWindow. | |
|
Finnur
2016/05/17 14:49:14
nit: This comment doesn't really add anything, I w
Devlin
2016/05/17 19:29:54
I disagree a little - it explains why we don't hav
Finnur
2016/05/18 14:06:32
Oh, error_member! Sorry, I read this as:
// is_er
| |
| 468 | |
| 462 // Look for optional tab id. | 469 // Look for optional tab id. |
| 463 if (create_data && create_data->tab_id) { | 470 if (create_data && create_data->tab_id) { |
| 464 // Find the tab. |source_tab_strip| and |tab_index| will later be used to | 471 // Find the tab. |source_tab_strip| and |tab_index| will later be used to |
| 465 // move the tab into the created window. | 472 // move the tab into the created window. |
| 473 Browser* source_browser = nullptr; | |
|
Devlin
2016/05/17 19:29:54
nit: source_browser, to me, implies that this is t
robwu
2016/05/17 21:14:24
source as in source of the tab. I'm using source_*
Devlin
2016/05/18 17:09:41
I still disagree with the naming, but fair point r
| |
| 466 if (!GetTabById(*create_data->tab_id, | 474 if (!GetTabById(*create_data->tab_id, |
| 467 GetProfile(), | 475 GetProfile(), |
| 468 include_incognito(), | 476 include_incognito(), |
| 469 NULL, | 477 &source_browser, |
| 470 &source_tab_strip, | 478 &source_tab_strip, |
| 471 NULL, | 479 nullptr, |
| 472 &tab_index, | 480 &tab_index, |
| 473 &error_)) | 481 &error_)) |
| 474 return false; | 482 return false; |
| 483 | |
| 484 if (!source_browser->window()->IsTabStripEditable()) { | |
| 485 error_ = keys::kTabStripNotEditableError; | |
| 486 return false; | |
| 487 } | |
| 488 | |
| 489 bool is_source_incognito = | |
| 490 source_browser->profile()->GetProfileType() == | |
| 491 Profile::INCOGNITO_PROFILE; | |
|
Devlin
2016/05/17 19:29:54
nit: I think we typically use BrowserContext::IsOf
| |
| 492 if (open_incognito_window != is_source_incognito) { | |
| 493 error_ = keys::kCanOnlyMoveTabsWithinSameProfileError; | |
|
Devlin
2016/05/17 19:29:54
I also wonder if there's some other tricky edge ca
robwu
2016/05/17 21:14:24
Done.
| |
| 494 return false; | |
| 495 } | |
| 475 } | 496 } |
| 476 | 497 |
| 477 if (!IsValidStateForWindowsCreateFunction(create_data)) { | 498 if (!IsValidStateForWindowsCreateFunction(create_data)) { |
| 478 error_ = keys::kInvalidWindowStateError; | 499 error_ = keys::kInvalidWindowStateError; |
| 479 return false; | 500 return false; |
| 480 } | 501 } |
| 481 | 502 |
| 482 Profile* window_profile = GetProfile(); | 503 Profile* window_profile = GetProfile(); |
| 483 Browser::Type window_type = Browser::TYPE_TABBED; | 504 Browser::Type window_type = Browser::TYPE_TABBED; |
| 484 bool create_panel = false; | 505 bool create_panel = false; |
| 485 | 506 |
| 486 // panel_create_mode only applies if create_panel = true | 507 // panel_create_mode only applies if create_panel = true |
| 487 PanelManager::CreateMode panel_create_mode = PanelManager::CREATE_AS_DOCKED; | 508 PanelManager::CreateMode panel_create_mode = PanelManager::CREATE_AS_DOCKED; |
| 488 | 509 |
| 489 gfx::Rect window_bounds; | 510 gfx::Rect window_bounds; |
| 490 bool focused = true; | 511 bool focused = true; |
| 491 bool saw_focus_key = false; | 512 bool saw_focus_key = false; |
| 492 std::string extension_id; | 513 std::string extension_id; |
| 493 | |
| 494 // Decide whether we are opening a normal window or an incognito window. | |
| 495 bool is_error = true; | |
| 496 bool open_incognito_window = ShouldOpenIncognitoWindow(create_data, &urls, | |
| 497 &is_error); | |
| 498 if (is_error) { | |
| 499 // error_ member variable is set inside of ShouldOpenIncognitoWindow. | |
| 500 return false; | |
| 501 } | |
| 502 if (open_incognito_window) { | 514 if (open_incognito_window) { |
| 503 window_profile = window_profile->GetOffTheRecordProfile(); | 515 window_profile = window_profile->GetOffTheRecordProfile(); |
| 504 } | 516 } |
| 505 | 517 |
| 506 if (create_data) { | 518 if (create_data) { |
| 507 // Figure out window type before figuring out bounds so that default | 519 // Figure out window type before figuring out bounds so that default |
| 508 // bounds can be set according to the window type. | 520 // bounds can be set according to the window type. |
| 509 switch (create_data->type) { | 521 switch (create_data->type) { |
| 510 case windows::CREATE_TYPE_POPUP: | 522 case windows::CREATE_TYPE_POPUP: |
| 511 window_type = Browser::TYPE_POPUP; | 523 window_type = Browser::TYPE_POPUP; |
| (...skipping 1634 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2146 ZoomModeToZoomSettings(zoom_mode, &zoom_settings); | 2158 ZoomModeToZoomSettings(zoom_mode, &zoom_settings); |
| 2147 zoom_settings.default_zoom_factor.reset(new double( | 2159 zoom_settings.default_zoom_factor.reset(new double( |
| 2148 content::ZoomLevelToZoomFactor(zoom_controller->GetDefaultZoomLevel()))); | 2160 content::ZoomLevelToZoomFactor(zoom_controller->GetDefaultZoomLevel()))); |
| 2149 | 2161 |
| 2150 results_ = api::tabs::GetZoomSettings::Results::Create(zoom_settings); | 2162 results_ = api::tabs::GetZoomSettings::Results::Create(zoom_settings); |
| 2151 SendResponse(true); | 2163 SendResponse(true); |
| 2152 return true; | 2164 return true; |
| 2153 } | 2165 } |
| 2154 | 2166 |
| 2155 } // namespace extensions | 2167 } // namespace extensions |
| OLD | NEW |