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

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

Issue 1662783002: Remove HostDesktopType from Browser::CreateParams (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@metro-mode-12
Patch Set: remove desktop_type_ in bookmark_bubble_sign_in_delegate Created 4 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.h" 8 #include "base/metrics/histogram.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 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 if (disposition == NEW_BACKGROUND_TAB) 191 if (disposition == NEW_BACKGROUND_TAB)
192 new_tab->WasHidden(); 192 new_tab->WasHidden();
193 browser->tab_strip_model()->AddWebContents( 193 browser->tab_strip_model()->AddWebContents(
194 new_tab, -1, ui::PAGE_TRANSITION_LINK, 194 new_tab, -1, ui::PAGE_TRANSITION_LINK,
195 (disposition == NEW_FOREGROUND_TAB) ? 195 (disposition == NEW_FOREGROUND_TAB) ?
196 TabStripModel::ADD_ACTIVE : TabStripModel::ADD_NONE); 196 TabStripModel::ADD_ACTIVE : TabStripModel::ADD_NONE);
197 return new_tab; 197 return new_tab;
198 } 198 }
199 case NEW_WINDOW: { 199 case NEW_WINDOW: {
200 WebContents* new_tab = current_tab->Clone(); 200 WebContents* new_tab = current_tab->Clone();
201 Browser* new_browser = new Browser(Browser::CreateParams( 201 Browser* new_browser =
202 browser->profile(), browser->host_desktop_type())); 202 new Browser(Browser::CreateParams(browser->profile()));
203 new_browser->tab_strip_model()->AddWebContents( 203 new_browser->tab_strip_model()->AddWebContents(
204 new_tab, -1, ui::PAGE_TRANSITION_LINK, 204 new_tab, -1, ui::PAGE_TRANSITION_LINK,
205 TabStripModel::ADD_ACTIVE); 205 TabStripModel::ADD_ACTIVE);
206 new_browser->window()->Show(); 206 new_browser->window()->Show();
207 return new_tab; 207 return new_tab;
208 } 208 }
209 default: 209 default:
210 browser->window()->GetLocationBar()->Revert(); 210 browser->window()->GetLocationBar()->Revert();
211 return current_tab; 211 return current_tab;
212 } 212 }
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 if (!content::IsSavableURL( 319 if (!content::IsSavableURL(
320 last_committed_entry ? last_committed_entry->GetURL() : GURL()) || 320 last_committed_entry ? last_committed_entry->GetURL() : GURL()) ||
321 current_tab->ShowingInterstitialPage()) 321 current_tab->ShowingInterstitialPage())
322 content_restrictions |= CONTENT_RESTRICTION_SAVE; 322 content_restrictions |= CONTENT_RESTRICTION_SAVE;
323 if (current_tab->ShowingInterstitialPage()) 323 if (current_tab->ShowingInterstitialPage())
324 content_restrictions |= CONTENT_RESTRICTION_PRINT; 324 content_restrictions |= CONTENT_RESTRICTION_PRINT;
325 } 325 }
326 return content_restrictions; 326 return content_restrictions;
327 } 327 }
328 328
329 void NewEmptyWindow(Profile* profile, HostDesktopType desktop_type) { 329 void NewEmptyWindow(Profile* profile) {
330 bool incognito = profile->IsOffTheRecord(); 330 bool incognito = profile->IsOffTheRecord();
331 PrefService* prefs = profile->GetPrefs(); 331 PrefService* prefs = profile->GetPrefs();
332 if (incognito) { 332 if (incognito) {
333 if (IncognitoModePrefs::GetAvailability(prefs) == 333 if (IncognitoModePrefs::GetAvailability(prefs) ==
334 IncognitoModePrefs::DISABLED) { 334 IncognitoModePrefs::DISABLED) {
335 incognito = false; 335 incognito = false;
336 } 336 }
337 } else if (profile->IsGuestSession() || 337 } else if (profile->IsGuestSession() ||
338 (browser_defaults::kAlwaysOpenIncognitoWindow && 338 (browser_defaults::kAlwaysOpenIncognitoWindow &&
339 IncognitoModePrefs::ShouldLaunchIncognito( 339 IncognitoModePrefs::ShouldLaunchIncognito(
340 *base::CommandLine::ForCurrentProcess(), prefs))) { 340 *base::CommandLine::ForCurrentProcess(), prefs))) {
341 incognito = true; 341 incognito = true;
342 } 342 }
343 343
344 if (incognito) { 344 if (incognito) {
345 content::RecordAction(UserMetricsAction("NewIncognitoWindow")); 345 content::RecordAction(UserMetricsAction("NewIncognitoWindow"));
346 OpenEmptyWindow(profile->GetOffTheRecordProfile(), desktop_type); 346 OpenEmptyWindow(profile->GetOffTheRecordProfile());
347 } else { 347 } else {
348 content::RecordAction(UserMetricsAction("NewWindow")); 348 content::RecordAction(UserMetricsAction("NewWindow"));
349 SessionService* session_service = 349 SessionService* session_service =
350 SessionServiceFactory::GetForProfileForSessionRestore( 350 SessionServiceFactory::GetForProfileForSessionRestore(
351 profile->GetOriginalProfile()); 351 profile->GetOriginalProfile());
352 if (!session_service || 352 if (!session_service ||
353 !session_service->RestoreIfNecessary(std::vector<GURL>())) { 353 !session_service->RestoreIfNecessary(std::vector<GURL>())) {
354 OpenEmptyWindow(profile->GetOriginalProfile(), desktop_type); 354 OpenEmptyWindow(profile->GetOriginalProfile());
355 } 355 }
356 } 356 }
357 } 357 }
358 358
359 Browser* OpenEmptyWindow(Profile* profile, HostDesktopType desktop_type) { 359 Browser* OpenEmptyWindow(Profile* profile) {
360 Browser* browser = new Browser( 360 Browser* browser =
361 Browser::CreateParams(Browser::TYPE_TABBED, profile, desktop_type)); 361 new Browser(Browser::CreateParams(Browser::TYPE_TABBED, profile));
362 AddTabAt(browser, GURL(), -1, true); 362 AddTabAt(browser, GURL(), -1, true);
363 browser->window()->Show(); 363 browser->window()->Show();
364 return browser; 364 return browser;
365 } 365 }
366 366
367 void OpenWindowWithRestoredTabs(Profile* profile, 367 void OpenWindowWithRestoredTabs(Profile* profile,
368 HostDesktopType host_desktop_type) { 368 HostDesktopType host_desktop_type) {
369 sessions::TabRestoreService* service = 369 sessions::TabRestoreService* service =
370 TabRestoreServiceFactory::GetForProfile(profile); 370 TabRestoreServiceFactory::GetForProfile(profile);
371 if (service) 371 if (service)
372 service->RestoreMostRecentEntry(NULL, host_desktop_type); 372 service->RestoreMostRecentEntry(NULL, host_desktop_type);
373 } 373 }
374 374
375 void OpenURLOffTheRecord(Profile* profile, 375 void OpenURLOffTheRecord(Profile* profile,
376 const GURL& url, 376 const GURL& url) {
377 chrome::HostDesktopType desktop_type) { 377 ScopedTabbedBrowserDisplayer displayer(profile->GetOffTheRecordProfile());
378 ScopedTabbedBrowserDisplayer displayer(profile->GetOffTheRecordProfile(),
379 desktop_type);
380 AddSelectedTabWithURL(displayer.browser(), url, 378 AddSelectedTabWithURL(displayer.browser(), url,
381 ui::PAGE_TRANSITION_LINK); 379 ui::PAGE_TRANSITION_LINK);
382 } 380 }
383 381
384 bool CanGoBack(const Browser* browser) { 382 bool CanGoBack(const Browser* browser) {
385 return browser->tab_strip_model()->GetActiveWebContents()-> 383 return browser->tab_strip_model()->GetActiveWebContents()->
386 GetController().CanGoBack(); 384 GetController().CanGoBack();
387 } 385 }
388 386
389 void GoBack(Browser* browser, WindowOpenDisposition disposition) { 387 void GoBack(Browser* browser, WindowOpenDisposition disposition) {
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 } 528 }
531 #endif 529 #endif
532 } 530 }
533 531
534 void Stop(Browser* browser) { 532 void Stop(Browser* browser) {
535 content::RecordAction(UserMetricsAction("Stop")); 533 content::RecordAction(UserMetricsAction("Stop"));
536 browser->tab_strip_model()->GetActiveWebContents()->Stop(); 534 browser->tab_strip_model()->GetActiveWebContents()->Stop();
537 } 535 }
538 536
539 void NewWindow(Browser* browser) { 537 void NewWindow(Browser* browser) {
540 NewEmptyWindow(browser->profile()->GetOriginalProfile(), 538 NewEmptyWindow(browser->profile()->GetOriginalProfile());
541 browser->host_desktop_type());
542 } 539 }
543 540
544 void NewIncognitoWindow(Browser* browser) { 541 void NewIncognitoWindow(Browser* browser) {
545 NewEmptyWindow(browser->profile()->GetOffTheRecordProfile(), 542 NewEmptyWindow(browser->profile()->GetOffTheRecordProfile());
546 browser->host_desktop_type());
547 } 543 }
548 544
549 void CloseWindow(Browser* browser) { 545 void CloseWindow(Browser* browser) {
550 content::RecordAction(UserMetricsAction("CloseWindow")); 546 content::RecordAction(UserMetricsAction("CloseWindow"));
551 browser->window()->Close(); 547 browser->window()->Close();
552 } 548 }
553 549
554 void NewTab(Browser* browser) { 550 void NewTab(Browser* browser) {
555 content::RecordAction(UserMetricsAction("NewTab")); 551 content::RecordAction(UserMetricsAction("NewTab"));
556 // TODO(asvitkine): This is invoked programmatically from several places. 552 // TODO(asvitkine): This is invoked programmatically from several places.
557 // Audit the code and change it so that the histogram only gets collected for 553 // Audit the code and change it so that the histogram only gets collected for
558 // user-initiated commands. 554 // user-initiated commands.
559 UMA_HISTOGRAM_ENUMERATION("Tab.NewTab", TabStripModel::NEW_TAB_COMMAND, 555 UMA_HISTOGRAM_ENUMERATION("Tab.NewTab", TabStripModel::NEW_TAB_COMMAND,
560 TabStripModel::NEW_TAB_ENUM_COUNT); 556 TabStripModel::NEW_TAB_ENUM_COUNT);
561 557
562 if (browser->is_type_tabbed()) { 558 if (browser->is_type_tabbed()) {
563 AddTabAt(browser, GURL(), -1, true); 559 AddTabAt(browser, GURL(), -1, true);
564 browser->tab_strip_model()->GetActiveWebContents()->RestoreFocus(); 560 browser->tab_strip_model()->GetActiveWebContents()->RestoreFocus();
565 } else { 561 } else {
566 ScopedTabbedBrowserDisplayer displayer(browser->profile(), 562 ScopedTabbedBrowserDisplayer displayer(browser->profile());
567 browser->host_desktop_type());
568 Browser* b = displayer.browser(); 563 Browser* b = displayer.browser();
569 AddTabAt(b, GURL(), -1, true); 564 AddTabAt(b, GURL(), -1, true);
570 b->window()->Show(); 565 b->window()->Show();
571 // The call to AddBlankTabAt above did not set the focus to the tab as its 566 // The call to AddBlankTabAt above did not set the focus to the tab as its
572 // window was not active, so we have to do it explicitly. 567 // window was not active, so we have to do it explicitly.
573 // See http://crbug.com/6380. 568 // See http://crbug.com/6380.
574 b->tab_strip_model()->GetActiveWebContents()->RestoreFocus(); 569 b->tab_strip_model()->GetActiveWebContents()->RestoreFocus();
575 } 570 }
576 } 571 }
577 572
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
664 int index = browser->tab_strip_model()->GetIndexOfWebContents(contents); 659 int index = browser->tab_strip_model()->GetIndexOfWebContents(contents);
665 pinned = browser->tab_strip_model()->IsTabPinned(index); 660 pinned = browser->tab_strip_model()->IsTabPinned(index);
666 int add_types = TabStripModel::ADD_ACTIVE | 661 int add_types = TabStripModel::ADD_ACTIVE |
667 TabStripModel::ADD_INHERIT_GROUP | 662 TabStripModel::ADD_INHERIT_GROUP |
668 (pinned ? TabStripModel::ADD_PINNED : 0); 663 (pinned ? TabStripModel::ADD_PINNED : 0);
669 browser->tab_strip_model()->InsertWebContentsAt( 664 browser->tab_strip_model()->InsertWebContentsAt(
670 index + 1, contents_dupe, add_types); 665 index + 1, contents_dupe, add_types);
671 } else { 666 } else {
672 Browser* new_browser = NULL; 667 Browser* new_browser = NULL;
673 if (browser->is_app() && !browser->is_type_popup()) { 668 if (browser->is_app() && !browser->is_type_popup()) {
674 new_browser = new Browser( 669 new_browser = new Browser(Browser::CreateParams::CreateForApp(
675 Browser::CreateParams::CreateForApp(browser->app_name(), 670 browser->app_name(), browser->is_trusted_source(), gfx::Rect(),
676 browser->is_trusted_source(), 671 browser->profile()));
677 gfx::Rect(),
678 browser->profile(),
679 browser->host_desktop_type()));
680 } else { 672 } else {
681 new_browser = new Browser( 673 new_browser = new Browser(
682 Browser::CreateParams(browser->type(), browser->profile(), 674 Browser::CreateParams(browser->type(), browser->profile()));
683 browser->host_desktop_type()));
684 } 675 }
685 // Preserve the size of the original window. The new window has already 676 // Preserve the size of the original window. The new window has already
686 // been given an offset by the OS, so we shouldn't copy the old bounds. 677 // been given an offset by the OS, so we shouldn't copy the old bounds.
687 BrowserWindow* new_window = new_browser->window(); 678 BrowserWindow* new_window = new_browser->window();
688 new_window->SetBounds(gfx::Rect(new_window->GetRestoredBounds().origin(), 679 new_window->SetBounds(gfx::Rect(new_window->GetRestoredBounds().origin(),
689 browser->window()->GetRestoredBounds().size())); 680 browser->window()->GetRestoredBounds().size()));
690 681
691 // We need to show the browser now. Otherwise ContainerWin assumes the 682 // We need to show the browser now. Otherwise ContainerWin assumes the
692 // WebContents is invisible and won't size it. 683 // WebContents is invisible and won't size it.
693 new_browser->window()->Show(); 684 new_browser->window()->Show();
(...skipping 19 matching lines...) Expand all
713 // what the user expects to duplicate. 704 // what the user expects to duplicate.
714 return contents && !contents->ShowingInterstitialPage() && 705 return contents && !contents->ShowingInterstitialPage() &&
715 contents->GetController().GetLastCommittedEntry(); 706 contents->GetController().GetLastCommittedEntry();
716 } 707 }
717 708
718 void ConvertPopupToTabbedBrowser(Browser* browser) { 709 void ConvertPopupToTabbedBrowser(Browser* browser) {
719 content::RecordAction(UserMetricsAction("ShowAsTab")); 710 content::RecordAction(UserMetricsAction("ShowAsTab"));
720 TabStripModel* tab_strip = browser->tab_strip_model(); 711 TabStripModel* tab_strip = browser->tab_strip_model();
721 WebContents* contents = 712 WebContents* contents =
722 tab_strip->DetachWebContentsAt(tab_strip->active_index()); 713 tab_strip->DetachWebContentsAt(tab_strip->active_index());
723 Browser* b = new Browser(Browser::CreateParams(browser->profile(), 714 Browser* b = new Browser(Browser::CreateParams(browser->profile()));
724 browser->host_desktop_type()));
725 b->tab_strip_model()->AppendWebContents(contents, true); 715 b->tab_strip_model()->AppendWebContents(contents, true);
726 b->window()->Show(); 716 b->window()->Show();
727 } 717 }
728 718
729 void Exit() { 719 void Exit() {
730 content::RecordAction(UserMetricsAction("Exit")); 720 content::RecordAction(UserMetricsAction("Exit"));
731 chrome::AttemptUserExit(); 721 chrome::AttemptUserExit();
732 } 722 }
733 723
734 void BookmarkCurrentPageIgnoringExtensionOverrides(Browser* browser) { 724 void BookmarkCurrentPageIgnoringExtensionOverrides(Browser* browser) {
(...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after
1223 // window next to the tab being duplicated. 1213 // window next to the tab being duplicated.
1224 int index = browser->tab_strip_model()->GetIndexOfWebContents(contents); 1214 int index = browser->tab_strip_model()->GetIndexOfWebContents(contents);
1225 int add_types = TabStripModel::ADD_ACTIVE | 1215 int add_types = TabStripModel::ADD_ACTIVE |
1226 TabStripModel::ADD_INHERIT_GROUP; 1216 TabStripModel::ADD_INHERIT_GROUP;
1227 browser->tab_strip_model()->InsertWebContentsAt( 1217 browser->tab_strip_model()->InsertWebContentsAt(
1228 index + 1, 1218 index + 1,
1229 view_source_contents, 1219 view_source_contents,
1230 add_types); 1220 add_types);
1231 } else { 1221 } else {
1232 Browser* b = new Browser( 1222 Browser* b = new Browser(
1233 Browser::CreateParams(Browser::TYPE_TABBED, browser->profile(), 1223 Browser::CreateParams(Browser::TYPE_TABBED, browser->profile()));
1234 browser->host_desktop_type()));
1235 1224
1236 // Preserve the size of the original window. The new window has already 1225 // Preserve the size of the original window. The new window has already
1237 // been given an offset by the OS, so we shouldn't copy the old bounds. 1226 // been given an offset by the OS, so we shouldn't copy the old bounds.
1238 BrowserWindow* new_window = b->window(); 1227 BrowserWindow* new_window = b->window();
1239 new_window->SetBounds(gfx::Rect(new_window->GetRestoredBounds().origin(), 1228 new_window->SetBounds(gfx::Rect(new_window->GetRestoredBounds().origin(),
1240 browser->window()->GetRestoredBounds().size())); 1229 browser->window()->GetRestoredBounds().size()));
1241 1230
1242 // We need to show the browser now. Otherwise ContainerWin assumes the 1231 // We need to show the browser now. Otherwise ContainerWin assumes the
1243 // WebContents is invisible and won't size it. 1232 // WebContents is invisible and won't size it.
1244 b->window()->Show(); 1233 b->window()->Show();
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1294 1283
1295 void ConvertTabToAppWindow(Browser* browser, 1284 void ConvertTabToAppWindow(Browser* browser,
1296 content::WebContents* contents) { 1285 content::WebContents* contents) {
1297 const GURL& url = contents->GetController().GetLastCommittedEntry()->GetURL(); 1286 const GURL& url = contents->GetController().GetLastCommittedEntry()->GetURL();
1298 std::string app_name = web_app::GenerateApplicationNameFromURL(url); 1287 std::string app_name = web_app::GenerateApplicationNameFromURL(url);
1299 1288
1300 int index = browser->tab_strip_model()->GetIndexOfWebContents(contents); 1289 int index = browser->tab_strip_model()->GetIndexOfWebContents(contents);
1301 if (index >= 0) 1290 if (index >= 0)
1302 browser->tab_strip_model()->DetachWebContentsAt(index); 1291 browser->tab_strip_model()->DetachWebContentsAt(index);
1303 1292
1304 Browser* app_browser = new Browser( 1293 Browser* app_browser = new Browser(Browser::CreateParams::CreateForApp(
1305 Browser::CreateParams::CreateForApp(app_name, 1294 app_name, true /* trusted_source */, gfx::Rect(), browser->profile()));
1306 true /* trusted_source */,
1307 gfx::Rect(),
1308 browser->profile(),
1309 browser->host_desktop_type()));
1310 app_browser->tab_strip_model()->AppendWebContents(contents, true); 1295 app_browser->tab_strip_model()->AppendWebContents(contents, true);
1311 1296
1312 contents->GetMutableRendererPrefs()->can_accept_load_drops = false; 1297 contents->GetMutableRendererPrefs()->can_accept_load_drops = false;
1313 contents->GetRenderViewHost()->SyncRendererPrefs(); 1298 contents->GetRenderViewHost()->SyncRendererPrefs();
1314 app_browser->window()->Show(); 1299 app_browser->window()->Show();
1315 } 1300 }
1316 #endif // defined(ENABLE_EXTENSIONS) 1301 #endif // defined(ENABLE_EXTENSIONS)
1317 1302
1318 } // namespace chrome 1303 } // namespace chrome
OLDNEW
« no previous file with comments | « chrome/browser/ui/browser_commands.h ('k') | chrome/browser/ui/browser_finder_chromeos_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698