Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(148)

Side by Side Diff: chrome/browser/extensions/api/tabs/tabs_api.cc

Issue 1984573002: Prevent chrome.windows.create from moving a tab to another profile (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Devlin's nits Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/test/data/extensions/api_test/incognito/apis/background.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 =
465 ShouldOpenIncognitoWindow(create_data, &urls, &is_error);
466 if (is_error)
467 return false; // error_ member is set inside of ShouldOpenIncognitoWindow.
468
469 Profile* window_profile = GetProfile();
470 if (open_incognito_window)
471 window_profile = window_profile->GetOffTheRecordProfile();
472
462 // Look for optional tab id. 473 // Look for optional tab id.
463 if (create_data && create_data->tab_id) { 474 if (create_data && create_data->tab_id) {
464 // Find the tab. |source_tab_strip| and |tab_index| will later be used to 475 // Find the tab. |source_tab_strip| and |tab_index| will later be used to
465 // move the tab into the created window. 476 // move the tab into the created window.
477 Browser* source_browser = nullptr;
466 if (!GetTabById(*create_data->tab_id, 478 if (!GetTabById(*create_data->tab_id,
467 GetProfile(), 479 GetProfile(),
468 include_incognito(), 480 include_incognito(),
469 NULL, 481 &source_browser,
470 &source_tab_strip, 482 &source_tab_strip,
471 NULL, 483 nullptr,
472 &tab_index, 484 &tab_index,
473 &error_)) 485 &error_))
474 return false; 486 return false;
487
488 if (!source_browser->window()->IsTabStripEditable()) {
489 error_ = keys::kTabStripNotEditableError;
490 return false;
491 }
492
493 if (source_browser->profile() != window_profile) {
494 error_ = keys::kCanOnlyMoveTabsWithinSameProfileError;
495 return false;
496 }
475 } 497 }
476 498
477 if (!IsValidStateForWindowsCreateFunction(create_data)) { 499 if (!IsValidStateForWindowsCreateFunction(create_data)) {
478 error_ = keys::kInvalidWindowStateError; 500 error_ = keys::kInvalidWindowStateError;
479 return false; 501 return false;
480 } 502 }
481 503
482 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 514
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) {
503 window_profile = window_profile->GetOffTheRecordProfile();
504 }
505
506 if (create_data) { 515 if (create_data) {
507 // Figure out window type before figuring out bounds so that default 516 // Figure out window type before figuring out bounds so that default
508 // bounds can be set according to the window type. 517 // bounds can be set according to the window type.
509 switch (create_data->type) { 518 switch (create_data->type) {
510 case windows::CREATE_TYPE_POPUP: 519 case windows::CREATE_TYPE_POPUP:
511 window_type = Browser::TYPE_POPUP; 520 window_type = Browser::TYPE_POPUP;
512 extension_id = extension()->id(); 521 extension_id = extension()->id();
513 break; 522 break;
514 case windows::CREATE_TYPE_PANEL: 523 case windows::CREATE_TYPE_PANEL:
515 case windows::CREATE_TYPE_DETACHED_PANEL: { 524 case windows::CREATE_TYPE_DETACHED_PANEL: {
(...skipping 1630 matching lines...) Expand 10 before | Expand all | Expand 10 after
2146 ZoomModeToZoomSettings(zoom_mode, &zoom_settings); 2155 ZoomModeToZoomSettings(zoom_mode, &zoom_settings);
2147 zoom_settings.default_zoom_factor.reset(new double( 2156 zoom_settings.default_zoom_factor.reset(new double(
2148 content::ZoomLevelToZoomFactor(zoom_controller->GetDefaultZoomLevel()))); 2157 content::ZoomLevelToZoomFactor(zoom_controller->GetDefaultZoomLevel())));
2149 2158
2150 results_ = api::tabs::GetZoomSettings::Results::Create(zoom_settings); 2159 results_ = api::tabs::GetZoomSettings::Results::Create(zoom_settings);
2151 SendResponse(true); 2160 SendResponse(true);
2152 return true; 2161 return true;
2153 } 2162 }
2154 2163
2155 } // namespace extensions 2164 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | chrome/test/data/extensions/api_test/incognito/apis/background.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698