Chromium Code Reviews
[email protected] (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(555)

Side by Side Diff: chrome/browser/browser_init.cc

Issue 1026005: Makes pinned tab restore on startup if you haven't enabled session (Closed)
Patch Set: check Created 10 years, 9 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 | « chrome/browser/browser_init.h ('k') | chrome/browser/browser_list.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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/browser_init.h" 5 #include "chrome/browser/browser_init.h"
6 6
7 #include "app/l10n_util.h" 7 #include "app/l10n_util.h"
8 #include "app/resource_bundle.h" 8 #include "app/resource_bundle.h"
9 #include "base/event_recorder.h" 9 #include "base/event_recorder.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
(...skipping 10 matching lines...) Expand all
21 #include "chrome/browser/extensions/extensions_service.h" 21 #include "chrome/browser/extensions/extensions_service.h"
22 #include "chrome/browser/first_run.h" 22 #include "chrome/browser/first_run.h"
23 #include "chrome/browser/net/dns_global.h" 23 #include "chrome/browser/net/dns_global.h"
24 #include "chrome/browser/pref_service.h" 24 #include "chrome/browser/pref_service.h"
25 #include "chrome/browser/profile.h" 25 #include "chrome/browser/profile.h"
26 #include "chrome/browser/renderer_host/render_process_host.h" 26 #include "chrome/browser/renderer_host/render_process_host.h"
27 #include "chrome/browser/search_engines/template_url_model.h" 27 #include "chrome/browser/search_engines/template_url_model.h"
28 #include "chrome/browser/session_startup_pref.h" 28 #include "chrome/browser/session_startup_pref.h"
29 #include "chrome/browser/sessions/session_restore.h" 29 #include "chrome/browser/sessions/session_restore.h"
30 #include "chrome/browser/shell_integration.h" 30 #include "chrome/browser/shell_integration.h"
31 #include "chrome/browser/tabs/pinned_tab_codec.h"
31 #include "chrome/browser/tab_contents/infobar_delegate.h" 32 #include "chrome/browser/tab_contents/infobar_delegate.h"
32 #include "chrome/browser/tab_contents/navigation_controller.h" 33 #include "chrome/browser/tab_contents/navigation_controller.h"
33 #include "chrome/browser/tab_contents/tab_contents.h" 34 #include "chrome/browser/tab_contents/tab_contents.h"
34 #include "chrome/browser/tab_contents/tab_contents_view.h" 35 #include "chrome/browser/tab_contents/tab_contents_view.h"
35 #include "chrome/browser/net/url_fixer_upper.h" 36 #include "chrome/browser/net/url_fixer_upper.h"
36 #include "chrome/browser/status_icons/status_tray_manager.h" 37 #include "chrome/browser/status_icons/status_tray_manager.h"
37 #include "chrome/browser/user_data_manager.h" 38 #include "chrome/browser/user_data_manager.h"
38 #include "chrome/common/chrome_constants.h" 39 #include "chrome/common/chrome_constants.h"
39 #include "chrome/common/chrome_paths.h" 40 #include "chrome/common/chrome_paths.h"
40 #include "chrome/common/chrome_switches.h" 41 #include "chrome/common/chrome_switches.h"
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 #else 328 #else
328 // Just send caption & text to stdout on mac & linux. 329 // Just send caption & text to stdout on mac & linux.
329 std::string out_text = WideToASCII(caption); 330 std::string out_text = WideToASCII(caption);
330 out_text.append("\n\n"); 331 out_text.append("\n\n");
331 out_text.append(WideToASCII(message)); 332 out_text.append(WideToASCII(message));
332 out_text.append("\n"); 333 out_text.append("\n");
333 printf("%s", out_text.c_str()); 334 printf("%s", out_text.c_str());
334 #endif 335 #endif
335 } 336 }
336 337
338 void UrlsToTabs(const std::vector<GURL>& urls,
339 std::vector<BrowserInit::LaunchWithProfile::Tab>* tabs) {
340 for (size_t i = 0; i < urls.size(); ++i) {
341 BrowserInit::LaunchWithProfile::Tab tab;
342 tab.is_pinned = false;
343 tab.url = urls[i];
344 tabs->push_back(tab);
345 }
346 }
347
337 } // namespace 348 } // namespace
338 349
339 // static 350 // static
340 bool BrowserInit::InProcessStartup() { 351 bool BrowserInit::InProcessStartup() {
341 return in_startup; 352 return in_startup;
342 } 353 }
343 354
344 bool BrowserInit::LaunchBrowser( 355 bool BrowserInit::LaunchBrowser(
345 const CommandLine& command_line, Profile* profile, 356 const CommandLine& command_line, Profile* profile,
346 const std::wstring& cur_dir, bool process_startup, 357 const std::wstring& cur_dir, bool process_startup,
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 webkit_glue::SetUserAgent(command_line_.GetSwitchValueASCII( 469 webkit_glue::SetUserAgent(command_line_.GetSwitchValueASCII(
459 switches::kUserAgent)); 470 switches::kUserAgent));
460 } 471 }
461 472
462 // Open the required browser windows and tabs. 473 // Open the required browser windows and tabs.
463 // First, see if we're being run as an application window. 474 // First, see if we're being run as an application window.
464 if (!OpenApplicationWindow(profile)) { 475 if (!OpenApplicationWindow(profile)) {
465 std::vector<GURL> urls_to_open = GetURLsFromCommandLine(profile_); 476 std::vector<GURL> urls_to_open = GetURLsFromCommandLine(profile_);
466 RecordLaunchModeHistogram(urls_to_open.empty()? 477 RecordLaunchModeHistogram(urls_to_open.empty()?
467 LM_TO_BE_DECIDED : LM_WITH_URLS); 478 LM_TO_BE_DECIDED : LM_WITH_URLS);
468 // Always attempt to restore the last session. OpenStartupURLs only opens 479 if (!process_startup || !OpenStartupURLs(urls_to_open)) {
469 // the home pages if no additional URLs were passed on the command line.
470 if (!OpenStartupURLs(process_startup, urls_to_open)) {
471 // Add the home page and any special first run URLs. 480 // Add the home page and any special first run URLs.
472 Browser* browser = NULL; 481 Browser* browser = NULL;
473 if (urls_to_open.empty()) 482 if (urls_to_open.empty())
474 AddStartupURLs(&urls_to_open); 483 AddStartupURLs(&urls_to_open);
475 else if (!command_line_.HasSwitch(switches::kOpenInNewWindow)) 484 else if (!command_line_.HasSwitch(switches::kOpenInNewWindow))
476 browser = BrowserList::GetLastActive(); 485 browser = BrowserList::GetLastActive();
477 486
478 OpenURLsInBrowser(browser, process_startup, urls_to_open); 487 OpenURLsInBrowser(browser, process_startup, urls_to_open);
479 } 488 }
480 489
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
583 if (policy->IsWebSafeScheme(url.scheme()) || 592 if (policy->IsWebSafeScheme(url.scheme()) ||
584 url.SchemeIs(chrome::kFileScheme)) { 593 url.SchemeIs(chrome::kFileScheme)) {
585 Browser::OpenApplicationWindow(profile, url, false); 594 Browser::OpenApplicationWindow(profile, url, false);
586 return true; 595 return true;
587 } 596 }
588 } 597 }
589 return false; 598 return false;
590 } 599 }
591 600
592 bool BrowserInit::LaunchWithProfile::OpenStartupURLs( 601 bool BrowserInit::LaunchWithProfile::OpenStartupURLs(
593 bool is_process_startup,
594 const std::vector<GURL>& urls_to_open) { 602 const std::vector<GURL>& urls_to_open) {
595 SessionStartupPref pref = GetSessionStartupPref(command_line_, profile_); 603 SessionStartupPref pref = GetSessionStartupPref(command_line_, profile_);
596 if (is_process_startup && 604 if (command_line_.HasSwitch(switches::kTestingChannelID) &&
597 command_line_.HasSwitch(switches::kTestingChannelID) &&
598 !command_line_.HasSwitch(switches::kRestoreLastSession) && 605 !command_line_.HasSwitch(switches::kRestoreLastSession) &&
599 browser_defaults::kDefaultSessionStartupType != 606 browser_defaults::kDefaultSessionStartupType !=
600 SessionStartupPref::DEFAULT) { 607 SessionStartupPref::DEFAULT) {
601 // When we have non DEFAULT session start type, then we won't open up a 608 // When we have non DEFAULT session start type, then we won't open up a
602 // fresh session. But none of the tests are written with this in mind, so 609 // fresh session. But none of the tests are written with this in mind, so
603 // we explicitly ignore it during testing. 610 // we explicitly ignore it during testing.
604 return false; 611 return false;
605 } 612 }
606 switch (pref.type) {
607 case SessionStartupPref::LAST:
608 if (!is_process_startup)
609 return false;
610 613
611 if (!profile_->DidLastSessionExitCleanly() && 614 if (pref.type == SessionStartupPref::LAST) {
612 !command_line_.HasSwitch(switches::kRestoreLastSession)) { 615 if (!profile_->DidLastSessionExitCleanly() &&
613 // The last session crashed. It's possible automatically loading the 616 !command_line_.HasSwitch(switches::kRestoreLastSession)) {
614 // page will trigger another crash, locking the user out of chrome. 617 // The last session crashed. It's possible automatically loading the
615 // To avoid this, don't restore on startup but instead show the crashed 618 // page will trigger another crash, locking the user out of chrome.
616 // infobar. 619 // To avoid this, don't restore on startup but instead show the crashed
617 return false; 620 // infobar.
618 } 621 return false;
619 SessionRestore::RestoreSessionSynchronously(profile_, urls_to_open); 622 }
620 return true; 623 SessionRestore::RestoreSessionSynchronously(profile_, urls_to_open);
624 return true;
625 }
621 626
622 case SessionStartupPref::URLS: 627 std::vector<Tab> tabs = PinnedTabCodec::ReadPinnedTabs(profile_);
623 // When the user launches the app only open the default set of URLs if
624 // we aren't going to open any URLs on the command line.
625 if (urls_to_open.empty()) {
626 if (pref.urls.empty()) {
627 // Open a New Tab page.
628 std::vector<GURL> urls;
629 urls.push_back(GURL(chrome::kChromeUINewTabURL));
630 OpenURLsInBrowser(NULL, is_process_startup, urls);
631 return true;
632 }
633 OpenURLsInBrowser(NULL, is_process_startup, pref.urls);
634 return true;
635 }
636 return false;
637 628
638 default: 629 if (!urls_to_open.empty()) {
639 return false; 630 // If urls were specified on the command line, use them.
631 UrlsToTabs(urls_to_open, &tabs);
632 } else if (pref.type == SessionStartupPref::URLS && !pref.urls.empty()) {
633 // Only use the set of urls specified in preferences if nothing was
634 // specified on the command line.
635 UrlsToTabs(pref.urls, &tabs);
640 } 636 }
637
638 if (tabs.empty())
639 return false;
640
641 OpenTabsInBrowser(NULL, true, tabs);
642 return true;
641 } 643 }
642 644
643 Browser* BrowserInit::LaunchWithProfile::OpenURLsInBrowser( 645 Browser* BrowserInit::LaunchWithProfile::OpenURLsInBrowser(
644 Browser* browser, 646 Browser* browser,
645 bool process_startup, 647 bool process_startup,
646 const std::vector<GURL>& urls) { 648 const std::vector<GURL>& urls) {
647 DCHECK(!urls.empty()); 649 std::vector<Tab> tabs;
650 UrlsToTabs(urls, &tabs);
651 return OpenTabsInBrowser(browser, process_startup, tabs);
652 }
653
654 Browser* BrowserInit::LaunchWithProfile::OpenTabsInBrowser(
655 Browser* browser,
656 bool process_startup,
657 const std::vector<Tab>& tabs) {
658 DCHECK(!tabs.empty());
648 // If we don't yet have a profile, try to use the one we're given from 659 // If we don't yet have a profile, try to use the one we're given from
649 // |browser|. While we may not end up actually using |browser| (since it 660 // |browser|. While we may not end up actually using |browser| (since it
650 // could be a popup window), we can at least use the profile. 661 // could be a popup window), we can at least use the profile.
651 if (!profile_ && browser) 662 if (!profile_ && browser)
652 profile_ = browser->profile(); 663 profile_ = browser->profile();
653 664
654 if (!browser || browser->type() != Browser::TYPE_NORMAL) 665 if (!browser || browser->type() != Browser::TYPE_NORMAL)
655 browser = Browser::Create(profile_); 666 browser = Browser::Create(profile_);
656 667
657 #if !defined(OS_MACOSX) 668 #if !defined(OS_MACOSX)
658 // In kiosk mode, we want to always be fullscreen, so switch to that now. 669 // In kiosk mode, we want to always be fullscreen, so switch to that now.
659 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode)) 670 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode))
660 browser->ToggleFullscreenMode(); 671 browser->ToggleFullscreenMode();
661 #endif 672 #endif
662 673
663 for (size_t i = 0; i < urls.size(); ++i) { 674 bool first_tab = true;
675 for (size_t i = 0; i < tabs.size(); ++i) {
664 // We skip URLs that we'd have to launch an external protocol handler for. 676 // We skip URLs that we'd have to launch an external protocol handler for.
665 // This avoids us getting into an infinite loop asking ourselves to open 677 // This avoids us getting into an infinite loop asking ourselves to open
666 // a URL, should the handler be (incorrectly) configured to be us. Anyone 678 // a URL, should the handler be (incorrectly) configured to be us. Anyone
667 // asking us to open such a URL should really ask the handler directly. 679 // asking us to open such a URL should really ask the handler directly.
668 if (!process_startup && !URLRequest::IsHandledURL(urls[i])) 680 if (!process_startup && !URLRequest::IsHandledURL(tabs[i].url))
669 continue; 681 continue;
682
683 int add_types = first_tab ? Browser::ADD_SELECTED : 0;
684 if (tabs[i].is_pinned)
685 add_types |= Browser::ADD_PINNED;
686
670 TabContents* tab = browser->AddTabWithURL( 687 TabContents* tab = browser->AddTabWithURL(
671 urls[i], GURL(), PageTransition::START_PAGE, (i == 0), -1, false, NULL); 688 tabs[i].url, GURL(), PageTransition::START_PAGE, -1, add_types, NULL,
672 if (profile_ && i == 0 && process_startup) 689 tabs[i].app_id);
690
691 if (profile_ && first_tab && process_startup)
673 AddCrashedInfoBarIfNecessary(tab); 692 AddCrashedInfoBarIfNecessary(tab);
693
694 first_tab = false;
674 } 695 }
675 browser->window()->Show(); 696 browser->window()->Show();
676 // TODO(jcampan): http://crbug.com/8123 we should not need to set the initial 697 // TODO(jcampan): http://crbug.com/8123 we should not need to set the initial
677 // focus explicitly. 698 // focus explicitly.
678 browser->GetSelectedTabContents()->view()->SetInitialFocus(); 699 browser->GetSelectedTabContents()->view()->SetInitialFocus();
679 700
680 return browser; 701 return browser;
681 } 702 }
682 703
683 void BrowserInit::LaunchWithProfile::AddCrashedInfoBarIfNecessary( 704 void BrowserInit::LaunchWithProfile::AddCrashedInfoBarIfNecessary(
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
957 scoped_refptr<AutomationProviderClass> automation = 978 scoped_refptr<AutomationProviderClass> automation =
958 new AutomationProviderClass(profile); 979 new AutomationProviderClass(profile);
959 automation->ConnectToChannel(channel_id); 980 automation->ConnectToChannel(channel_id);
960 automation->SetExpectedTabCount(expected_tabs); 981 automation->SetExpectedTabCount(expected_tabs);
961 982
962 AutomationProviderList* list = 983 AutomationProviderList* list =
963 g_browser_process->InitAutomationProviderList(); 984 g_browser_process->InitAutomationProviderList();
964 DCHECK(list); 985 DCHECK(list);
965 list->AddProvider(automation); 986 list->AddProvider(automation);
966 } 987 }
OLDNEW
« no previous file with comments | « chrome/browser/browser_init.h ('k') | chrome/browser/browser_list.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698