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

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

Issue 10692195: Consolidate Browser Creation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/browser_close_browsertest.cc ('k') | chrome/browser/ui/browser_finder.cc » ('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/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.h" 8 #include "base/metrics/histogram.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "chrome/browser/bookmarks/bookmark_editor.h" 10 #include "chrome/browser/bookmarks/bookmark_editor.h"
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 case NEW_BACKGROUND_TAB: { 94 case NEW_BACKGROUND_TAB: {
95 current_tab = current_tab->Clone(); 95 current_tab = current_tab->Clone();
96 browser->tab_strip_model()->AddTabContents( 96 browser->tab_strip_model()->AddTabContents(
97 current_tab, -1, content::PAGE_TRANSITION_LINK, 97 current_tab, -1, content::PAGE_TRANSITION_LINK,
98 disposition == NEW_FOREGROUND_TAB ? TabStripModel::ADD_ACTIVE : 98 disposition == NEW_FOREGROUND_TAB ? TabStripModel::ADD_ACTIVE :
99 TabStripModel::ADD_NONE); 99 TabStripModel::ADD_NONE);
100 break; 100 break;
101 } 101 }
102 case NEW_WINDOW: { 102 case NEW_WINDOW: {
103 current_tab = current_tab->Clone(); 103 current_tab = current_tab->Clone();
104 Browser* b = Browser::Create(browser->profile()); 104 Browser* b = new Browser(Browser::CreateParams(browser->profile()));
105 b->tab_strip_model()->AddTabContents( 105 b->tab_strip_model()->AddTabContents(
106 current_tab, -1, content::PAGE_TRANSITION_LINK, 106 current_tab, -1, content::PAGE_TRANSITION_LINK,
107 TabStripModel::ADD_ACTIVE); 107 TabStripModel::ADD_ACTIVE);
108 b->window()->Show(); 108 b->window()->Show();
109 break; 109 break;
110 } 110 }
111 default: 111 default:
112 break; 112 break;
113 } 113 }
114 return current_tab->web_contents(); 114 return current_tab->web_contents();
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 SessionService* session_service = 247 SessionService* session_service =
248 SessionServiceFactory::GetForProfile(profile->GetOriginalProfile()); 248 SessionServiceFactory::GetForProfile(profile->GetOriginalProfile());
249 if (!session_service || 249 if (!session_service ||
250 !session_service->RestoreIfNecessary(std::vector<GURL>())) { 250 !session_service->RestoreIfNecessary(std::vector<GURL>())) {
251 OpenEmptyWindow(profile->GetOriginalProfile()); 251 OpenEmptyWindow(profile->GetOriginalProfile());
252 } 252 }
253 } 253 }
254 } 254 }
255 255
256 Browser* OpenEmptyWindow(Profile* profile) { 256 Browser* OpenEmptyWindow(Profile* profile) {
257 Browser* browser = Browser::Create(profile); 257 Browser* browser = new Browser(Browser::CreateParams(profile));
258 AddBlankTab(browser, true); 258 AddBlankTab(browser, true);
259 browser->window()->Show(); 259 browser->window()->Show();
260 return browser; 260 return browser;
261 } 261 }
262 262
263 void OpenWindowWithRestoredTabs(Profile* profile) { 263 void OpenWindowWithRestoredTabs(Profile* profile) {
264 TabRestoreService* service = TabRestoreServiceFactory::GetForProfile(profile); 264 TabRestoreService* service = TabRestoreServiceFactory::GetForProfile(profile);
265 if (service) 265 if (service)
266 service->RestoreMostRecentEntry(NULL); 266 service->RestoreMostRecentEntry(NULL);
267 } 267 }
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
500 int add_types = TabStripModel::ADD_ACTIVE | 500 int add_types = TabStripModel::ADD_ACTIVE |
501 TabStripModel::ADD_INHERIT_GROUP | 501 TabStripModel::ADD_INHERIT_GROUP |
502 (pinned ? TabStripModel::ADD_PINNED : 0); 502 (pinned ? TabStripModel::ADD_PINNED : 0);
503 browser->tab_strip_model()->InsertTabContentsAt( 503 browser->tab_strip_model()->InsertTabContentsAt(
504 index + 1, contents_dupe, add_types); 504 index + 1, contents_dupe, add_types);
505 } else { 505 } else {
506 Browser* browser = NULL; 506 Browser* browser = NULL;
507 if (browser->is_app()) { 507 if (browser->is_app()) {
508 CHECK(!browser->is_type_popup()); 508 CHECK(!browser->is_type_popup());
509 CHECK(!browser->is_type_panel()); 509 CHECK(!browser->is_type_panel());
510 browser = Browser::CreateWithParams( 510 browser = new Browser(
511 Browser::CreateParams::CreateForApp(Browser::TYPE_POPUP, 511 Browser::CreateParams::CreateForApp(Browser::TYPE_POPUP,
512 browser->app_name(), 512 browser->app_name(),
513 gfx::Rect(), 513 gfx::Rect(),
514 browser->profile())); 514 browser->profile()));
515 } else if (browser->is_type_popup()) { 515 } else if (browser->is_type_popup()) {
516 browser = Browser::CreateWithParams( 516 browser = new Browser(
517 Browser::CreateParams(Browser::TYPE_POPUP, browser->profile())); 517 Browser::CreateParams(Browser::TYPE_POPUP, browser->profile()));
518 } 518 }
519 519
520 // Preserve the size of the original window. The new window has already 520 // Preserve the size of the original window. The new window has already
521 // been given an offset by the OS, so we shouldn't copy the old bounds. 521 // been given an offset by the OS, so we shouldn't copy the old bounds.
522 BrowserWindow* new_window = browser->window(); 522 BrowserWindow* new_window = browser->window();
523 new_window->SetBounds(gfx::Rect(new_window->GetRestoredBounds().origin(), 523 new_window->SetBounds(gfx::Rect(new_window->GetRestoredBounds().origin(),
524 browser->window()->GetRestoredBounds().size())); 524 browser->window()->GetRestoredBounds().size()));
525 525
526 // We need to show the browser now. Otherwise ContainerWin assumes the 526 // We need to show the browser now. Otherwise ContainerWin assumes the
(...skipping 13 matching lines...) Expand all
540 bool CanDuplicateTabAt(Browser* browser, int index) { 540 bool CanDuplicateTabAt(Browser* browser, int index) {
541 content::NavigationController& nc = 541 content::NavigationController& nc =
542 GetWebContentsAt(browser, index)->GetController(); 542 GetWebContentsAt(browser, index)->GetController();
543 return nc.GetWebContents() && nc.GetLastCommittedEntry(); 543 return nc.GetWebContents() && nc.GetLastCommittedEntry();
544 } 544 }
545 545
546 void ConvertPopupToTabbedBrowser(Browser* browser) { 546 void ConvertPopupToTabbedBrowser(Browser* browser) {
547 content::RecordAction(UserMetricsAction("ShowAsTab")); 547 content::RecordAction(UserMetricsAction("ShowAsTab"));
548 TabContents* contents = 548 TabContents* contents =
549 browser->tab_strip_model()->DetachTabContentsAt(browser->active_index()); 549 browser->tab_strip_model()->DetachTabContentsAt(browser->active_index());
550 Browser* b = Browser::Create(browser->profile()); 550 Browser* b = new Browser(Browser::CreateParams(browser->profile()));
551 b->tab_strip_model()->AppendTabContents(contents, true); 551 b->tab_strip_model()->AppendTabContents(contents, true);
552 b->window()->Show(); 552 b->window()->Show();
553 } 553 }
554 554
555 void Exit() { 555 void Exit() {
556 content::RecordAction(UserMetricsAction("Exit")); 556 content::RecordAction(UserMetricsAction("Exit"));
557 browser::AttemptUserExit(); 557 browser::AttemptUserExit();
558 } 558 }
559 559
560 void BookmarkCurrentPage(Browser* browser) { 560 void BookmarkCurrentPage(Browser* browser) {
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after
919 if (browser->CanSupportWindowFeature(Browser::FEATURE_TABSTRIP)) { 919 if (browser->CanSupportWindowFeature(Browser::FEATURE_TABSTRIP)) {
920 // If this is a tabbed browser, just create a duplicate tab inside the same 920 // If this is a tabbed browser, just create a duplicate tab inside the same
921 // window next to the tab being duplicated. 921 // window next to the tab being duplicated.
922 int index = browser->tab_strip_model()->GetIndexOfTabContents(contents); 922 int index = browser->tab_strip_model()->GetIndexOfTabContents(contents);
923 int add_types = TabStripModel::ADD_ACTIVE | 923 int add_types = TabStripModel::ADD_ACTIVE |
924 TabStripModel::ADD_INHERIT_GROUP; 924 TabStripModel::ADD_INHERIT_GROUP;
925 browser->tab_strip_model()->InsertTabContentsAt(index + 1, 925 browser->tab_strip_model()->InsertTabContentsAt(index + 1,
926 view_source_contents, 926 view_source_contents,
927 add_types); 927 add_types);
928 } else { 928 } else {
929 Browser* b = Browser::CreateWithParams( 929 Browser* b = new Browser(
930 Browser::CreateParams(Browser::TYPE_TABBED, browser->profile())); 930 Browser::CreateParams(Browser::TYPE_TABBED, browser->profile()));
931 931
932 // Preserve the size of the original window. The new window has already 932 // Preserve the size of the original window. The new window has already
933 // been given an offset by the OS, so we shouldn't copy the old bounds. 933 // been given an offset by the OS, so we shouldn't copy the old bounds.
934 BrowserWindow* new_window = b->window(); 934 BrowserWindow* new_window = b->window();
935 new_window->SetBounds(gfx::Rect(new_window->GetRestoredBounds().origin(), 935 new_window->SetBounds(gfx::Rect(new_window->GetRestoredBounds().origin(),
936 browser->window()->GetRestoredBounds().size())); 936 browser->window()->GetRestoredBounds().size()));
937 937
938 // We need to show the browser now. Otherwise ContainerWin assumes the 938 // We need to show the browser now. Otherwise ContainerWin assumes the
939 // WebContents is invisible and won't size it. 939 // WebContents is invisible and won't size it.
(...skipping 30 matching lines...) Expand all
970 970
971 void ConvertTabToAppWindow(Browser* browser, 971 void ConvertTabToAppWindow(Browser* browser,
972 content::WebContents* contents) { 972 content::WebContents* contents) {
973 const GURL& url = contents->GetController().GetActiveEntry()->GetURL(); 973 const GURL& url = contents->GetController().GetActiveEntry()->GetURL();
974 std::string app_name = web_app::GenerateApplicationNameFromURL(url); 974 std::string app_name = web_app::GenerateApplicationNameFromURL(url);
975 975
976 int index = browser->tab_strip_model()->GetIndexOfWebContents(contents); 976 int index = browser->tab_strip_model()->GetIndexOfWebContents(contents);
977 if (index >= 0) 977 if (index >= 0)
978 browser->tab_strip_model()->DetachTabContentsAt(index); 978 browser->tab_strip_model()->DetachTabContentsAt(index);
979 979
980 Browser* app_browser = Browser::CreateWithParams( 980 Browser* app_browser = new Browser(
981 Browser::CreateParams::CreateForApp( 981 Browser::CreateParams::CreateForApp(
982 Browser::TYPE_POPUP, app_name, gfx::Rect(), browser->profile())); 982 Browser::TYPE_POPUP, app_name, gfx::Rect(), browser->profile()));
983 TabContents* tab_contents = TabContents::FromWebContents(contents); 983 TabContents* tab_contents = TabContents::FromWebContents(contents);
984 if (!tab_contents) 984 if (!tab_contents)
985 tab_contents = new TabContents(contents); 985 tab_contents = new TabContents(contents);
986 app_browser->tab_strip_model()->AppendTabContents(tab_contents, true); 986 app_browser->tab_strip_model()->AppendTabContents(tab_contents, true);
987 987
988 contents->GetMutableRendererPrefs()->can_accept_load_drops = false; 988 contents->GetMutableRendererPrefs()->can_accept_load_drops = false;
989 contents->GetRenderViewHost()->SyncRendererPrefs(); 989 contents->GetRenderViewHost()->SyncRendererPrefs();
990 app_browser->window()->Show(); 990 app_browser->window()->Show();
991 } 991 }
992 992
993 } // namespace chrome 993 } // namespace chrome
OLDNEW
« no previous file with comments | « chrome/browser/ui/browser_close_browsertest.cc ('k') | chrome/browser/ui/browser_finder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698