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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/extensions/api/tabs/tabs_api.cc
diff --git a/chrome/browser/extensions/api/tabs/tabs_api.cc b/chrome/browser/extensions/api/tabs/tabs_api.cc
index f2d0fd9daab8032058b3663bc8e7f703fe6e2c0e..5dc676258f1a6077f123ec6a4f25b924cd126884 100644
--- a/chrome/browser/extensions/api/tabs/tabs_api.cc
+++ b/chrome/browser/extensions/api/tabs/tabs_api.cc
@@ -459,19 +459,41 @@ bool WindowsCreateFunction::RunSync() {
}
}
+ // Decide whether we are opening a normal window or an incognito window.
+ bool is_error = true;
+ bool open_incognito_window =
+ ShouldOpenIncognitoWindow(create_data, &urls, &is_error);
+ if (is_error)
+ return false; // error_ member is set inside of ShouldOpenIncognitoWindow.
+
+ Profile* window_profile = GetProfile();
+ if (open_incognito_window)
+ window_profile = window_profile->GetOffTheRecordProfile();
+
// Look for optional tab id.
if (create_data && create_data->tab_id) {
// Find the tab. |source_tab_strip| and |tab_index| will later be used to
// move the tab into the created window.
+ Browser* source_browser = nullptr;
if (!GetTabById(*create_data->tab_id,
GetProfile(),
include_incognito(),
- NULL,
+ &source_browser,
&source_tab_strip,
- NULL,
+ nullptr,
&tab_index,
&error_))
return false;
+
+ if (!source_browser->window()->IsTabStripEditable()) {
+ error_ = keys::kTabStripNotEditableError;
+ return false;
+ }
+
+ if (source_browser->profile() != window_profile) {
+ error_ = keys::kCanOnlyMoveTabsWithinSameProfileError;
+ return false;
+ }
}
if (!IsValidStateForWindowsCreateFunction(create_data)) {
@@ -479,7 +501,6 @@ bool WindowsCreateFunction::RunSync() {
return false;
}
- Profile* window_profile = GetProfile();
Browser::Type window_type = Browser::TYPE_TABBED;
bool create_panel = false;
@@ -491,18 +512,6 @@ bool WindowsCreateFunction::RunSync() {
bool saw_focus_key = false;
std::string extension_id;
- // Decide whether we are opening a normal window or an incognito window.
- bool is_error = true;
- bool open_incognito_window = ShouldOpenIncognitoWindow(create_data, &urls,
- &is_error);
- if (is_error) {
- // error_ member variable is set inside of ShouldOpenIncognitoWindow.
- return false;
- }
- if (open_incognito_window) {
- window_profile = window_profile->GetOffTheRecordProfile();
- }
-
if (create_data) {
// Figure out window type before figuring out bounds so that default
// bounds can be set according to the window type.
« 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