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

Side by Side Diff: chrome/browser/ui/browser_commands.cc

Issue 2685333005: ash: fix regression where ctrl+n put new window on wrong desktop (Closed)
Patch Set: Rebase to ToT Created 3 years, 10 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
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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/ui/browser_commands.h" 5 #include "chrome/browser/ui/browser_commands.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/metrics/histogram_macros.h" 8 #include "base/metrics/histogram_macros.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "build/build_config.h" 10 #include "build/build_config.h"
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 browser->tab_strip_model()->AddWebContents( 227 browser->tab_strip_model()->AddWebContents(
228 new_tab, -1, ui::PAGE_TRANSITION_LINK, 228 new_tab, -1, ui::PAGE_TRANSITION_LINK,
229 (disposition == WindowOpenDisposition::NEW_FOREGROUND_TAB) 229 (disposition == WindowOpenDisposition::NEW_FOREGROUND_TAB)
230 ? TabStripModel::ADD_ACTIVE 230 ? TabStripModel::ADD_ACTIVE
231 : TabStripModel::ADD_NONE); 231 : TabStripModel::ADD_NONE);
232 return new_tab; 232 return new_tab;
233 } 233 }
234 case WindowOpenDisposition::NEW_WINDOW: { 234 case WindowOpenDisposition::NEW_WINDOW: {
235 WebContents* new_tab = current_tab->Clone(); 235 WebContents* new_tab = current_tab->Clone();
236 Browser* new_browser = 236 Browser* new_browser =
237 new Browser(Browser::CreateParams(browser->profile())); 237 new Browser(Browser::CreateParams(browser->profile(), true));
238 new_browser->tab_strip_model()->AddWebContents( 238 new_browser->tab_strip_model()->AddWebContents(
239 new_tab, -1, ui::PAGE_TRANSITION_LINK, 239 new_tab, -1, ui::PAGE_TRANSITION_LINK,
240 TabStripModel::ADD_ACTIVE); 240 TabStripModel::ADD_ACTIVE);
241 new_browser->window()->Show(); 241 new_browser->window()->Show();
242 return new_tab; 242 return new_tab;
243 } 243 }
244 default: 244 default:
245 browser->window()->GetLocationBar()->Revert(); 245 browser->window()->GetLocationBar()->Revert();
246 return current_tab; 246 return current_tab;
247 } 247 }
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 profile->GetOriginalProfile()); 386 profile->GetOriginalProfile());
387 if (!session_service || 387 if (!session_service ||
388 !session_service->RestoreIfNecessary(std::vector<GURL>())) { 388 !session_service->RestoreIfNecessary(std::vector<GURL>())) {
389 OpenEmptyWindow(profile->GetOriginalProfile()); 389 OpenEmptyWindow(profile->GetOriginalProfile());
390 } 390 }
391 } 391 }
392 } 392 }
393 393
394 Browser* OpenEmptyWindow(Profile* profile) { 394 Browser* OpenEmptyWindow(Profile* profile) {
395 Browser* browser = 395 Browser* browser =
396 new Browser(Browser::CreateParams(Browser::TYPE_TABBED, profile)); 396 new Browser(Browser::CreateParams(Browser::TYPE_TABBED, profile, true));
397 AddTabAt(browser, GURL(), -1, true); 397 AddTabAt(browser, GURL(), -1, true);
398 browser->window()->Show(); 398 browser->window()->Show();
399 return browser; 399 return browser;
400 } 400 }
401 401
402 void OpenWindowWithRestoredTabs(Profile* profile) { 402 void OpenWindowWithRestoredTabs(Profile* profile) {
403 sessions::TabRestoreService* service = 403 sessions::TabRestoreService* service =
404 TabRestoreServiceFactory::GetForProfile(profile); 404 TabRestoreServiceFactory::GetForProfile(profile);
405 if (service) 405 if (service)
406 service->RestoreMostRecentEntry(nullptr); 406 service->RestoreMostRecentEntry(nullptr);
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
698 int add_types = TabStripModel::ADD_ACTIVE | 698 int add_types = TabStripModel::ADD_ACTIVE |
699 TabStripModel::ADD_INHERIT_GROUP | 699 TabStripModel::ADD_INHERIT_GROUP |
700 (pinned ? TabStripModel::ADD_PINNED : 0); 700 (pinned ? TabStripModel::ADD_PINNED : 0);
701 browser->tab_strip_model()->InsertWebContentsAt( 701 browser->tab_strip_model()->InsertWebContentsAt(
702 index + 1, contents_dupe, add_types); 702 index + 1, contents_dupe, add_types);
703 } else { 703 } else {
704 Browser* new_browser = NULL; 704 Browser* new_browser = NULL;
705 if (browser->is_app() && !browser->is_type_popup()) { 705 if (browser->is_app() && !browser->is_type_popup()) {
706 new_browser = new Browser(Browser::CreateParams::CreateForApp( 706 new_browser = new Browser(Browser::CreateParams::CreateForApp(
707 browser->app_name(), browser->is_trusted_source(), gfx::Rect(), 707 browser->app_name(), browser->is_trusted_source(), gfx::Rect(),
708 browser->profile())); 708 browser->profile(), true));
709 } else { 709 } else {
710 new_browser = new Browser( 710 new_browser = new Browser(
711 Browser::CreateParams(browser->type(), browser->profile())); 711 Browser::CreateParams(browser->type(), browser->profile(), true));
712 } 712 }
713 // Preserve the size of the original window. The new window has already 713 // Preserve the size of the original window. The new window has already
714 // been given an offset by the OS, so we shouldn't copy the old bounds. 714 // been given an offset by the OS, so we shouldn't copy the old bounds.
715 BrowserWindow* new_window = new_browser->window(); 715 BrowserWindow* new_window = new_browser->window();
716 new_window->SetBounds(gfx::Rect(new_window->GetRestoredBounds().origin(), 716 new_window->SetBounds(gfx::Rect(new_window->GetRestoredBounds().origin(),
717 browser->window()->GetRestoredBounds().size())); 717 browser->window()->GetRestoredBounds().size()));
718 718
719 // We need to show the browser now. Otherwise ContainerWin assumes the 719 // We need to show the browser now. Otherwise ContainerWin assumes the
720 // WebContents is invisible and won't size it. 720 // WebContents is invisible and won't size it.
721 new_browser->window()->Show(); 721 new_browser->window()->Show();
(...skipping 19 matching lines...) Expand all
741 // what the user expects to duplicate. 741 // what the user expects to duplicate.
742 return contents && !contents->ShowingInterstitialPage() && 742 return contents && !contents->ShowingInterstitialPage() &&
743 contents->GetController().GetLastCommittedEntry(); 743 contents->GetController().GetLastCommittedEntry();
744 } 744 }
745 745
746 void ConvertPopupToTabbedBrowser(Browser* browser) { 746 void ConvertPopupToTabbedBrowser(Browser* browser) {
747 content::RecordAction(UserMetricsAction("ShowAsTab")); 747 content::RecordAction(UserMetricsAction("ShowAsTab"));
748 TabStripModel* tab_strip = browser->tab_strip_model(); 748 TabStripModel* tab_strip = browser->tab_strip_model();
749 WebContents* contents = 749 WebContents* contents =
750 tab_strip->DetachWebContentsAt(tab_strip->active_index()); 750 tab_strip->DetachWebContentsAt(tab_strip->active_index());
751 Browser* b = new Browser(Browser::CreateParams(browser->profile())); 751 Browser* b = new Browser(Browser::CreateParams(browser->profile(), true));
752 b->tab_strip_model()->AppendWebContents(contents, true); 752 b->tab_strip_model()->AppendWebContents(contents, true);
753 b->window()->Show(); 753 b->window()->Show();
754 } 754 }
755 755
756 void Exit() { 756 void Exit() {
757 content::RecordAction(UserMetricsAction("Exit")); 757 content::RecordAction(UserMetricsAction("Exit"));
758 chrome::AttemptUserExit(); 758 chrome::AttemptUserExit();
759 } 759 }
760 760
761 void BookmarkCurrentPageIgnoringExtensionOverrides(Browser* browser) { 761 void BookmarkCurrentPageIgnoringExtensionOverrides(Browser* browser) {
(...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after
1258 // window next to the tab being duplicated. 1258 // window next to the tab being duplicated.
1259 int index = browser->tab_strip_model()->GetIndexOfWebContents(contents); 1259 int index = browser->tab_strip_model()->GetIndexOfWebContents(contents);
1260 int add_types = TabStripModel::ADD_ACTIVE | 1260 int add_types = TabStripModel::ADD_ACTIVE |
1261 TabStripModel::ADD_INHERIT_GROUP; 1261 TabStripModel::ADD_INHERIT_GROUP;
1262 browser->tab_strip_model()->InsertWebContentsAt( 1262 browser->tab_strip_model()->InsertWebContentsAt(
1263 index + 1, 1263 index + 1,
1264 view_source_contents, 1264 view_source_contents,
1265 add_types); 1265 add_types);
1266 } else { 1266 } else {
1267 Browser* b = new Browser( 1267 Browser* b = new Browser(
1268 Browser::CreateParams(Browser::TYPE_TABBED, browser->profile())); 1268 Browser::CreateParams(Browser::TYPE_TABBED, browser->profile(), true));
1269 1269
1270 // Preserve the size of the original window. The new window has already 1270 // Preserve the size of the original window. The new window has already
1271 // been given an offset by the OS, so we shouldn't copy the old bounds. 1271 // been given an offset by the OS, so we shouldn't copy the old bounds.
1272 BrowserWindow* new_window = b->window(); 1272 BrowserWindow* new_window = b->window();
1273 new_window->SetBounds(gfx::Rect(new_window->GetRestoredBounds().origin(), 1273 new_window->SetBounds(gfx::Rect(new_window->GetRestoredBounds().origin(),
1274 browser->window()->GetRestoredBounds().size())); 1274 browser->window()->GetRestoredBounds().size()));
1275 1275
1276 // We need to show the browser now. Otherwise ContainerWin assumes the 1276 // We need to show the browser now. Otherwise ContainerWin assumes the
1277 // WebContents is invisible and won't size it. 1277 // WebContents is invisible and won't size it.
1278 b->window()->Show(); 1278 b->window()->Show();
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
1329 void ConvertTabToAppWindow(Browser* browser, 1329 void ConvertTabToAppWindow(Browser* browser,
1330 content::WebContents* contents) { 1330 content::WebContents* contents) {
1331 const GURL& url = contents->GetController().GetLastCommittedEntry()->GetURL(); 1331 const GURL& url = contents->GetController().GetLastCommittedEntry()->GetURL();
1332 std::string app_name = web_app::GenerateApplicationNameFromURL(url); 1332 std::string app_name = web_app::GenerateApplicationNameFromURL(url);
1333 1333
1334 int index = browser->tab_strip_model()->GetIndexOfWebContents(contents); 1334 int index = browser->tab_strip_model()->GetIndexOfWebContents(contents);
1335 if (index >= 0) 1335 if (index >= 0)
1336 browser->tab_strip_model()->DetachWebContentsAt(index); 1336 browser->tab_strip_model()->DetachWebContentsAt(index);
1337 1337
1338 Browser* app_browser = new Browser(Browser::CreateParams::CreateForApp( 1338 Browser* app_browser = new Browser(Browser::CreateParams::CreateForApp(
1339 app_name, true /* trusted_source */, gfx::Rect(), browser->profile())); 1339 app_name, true /* trusted_source */, gfx::Rect(), browser->profile(),
1340 true));
1340 app_browser->tab_strip_model()->AppendWebContents(contents, true); 1341 app_browser->tab_strip_model()->AppendWebContents(contents, true);
1341 1342
1342 contents->GetMutableRendererPrefs()->can_accept_load_drops = false; 1343 contents->GetMutableRendererPrefs()->can_accept_load_drops = false;
1343 contents->GetRenderViewHost()->SyncRendererPrefs(); 1344 contents->GetRenderViewHost()->SyncRendererPrefs();
1344 app_browser->window()->Show(); 1345 app_browser->window()->Show();
1345 } 1346 }
1346 #endif // BUILDFLAG(ENABLE_EXTENSIONS) 1347 #endif // BUILDFLAG(ENABLE_EXTENSIONS)
1347 1348
1348 } // namespace chrome 1349 } // namespace chrome
OLDNEW
« no previous file with comments | « chrome/browser/ui/browser_command_controller_unittest.cc ('k') | chrome/browser/ui/browser_finder_chromeos_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698