OLD | NEW |
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/startup/startup_browser_creator_impl.h" | 5 #include "chrome/browser/ui/startup/startup_browser_creator_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "apps/app_restore_service.h" | 10 #include "apps/app_restore_service.h" |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 is_first_run_(is_first_run == chrome::startup::IS_FIRST_RUN), | 286 is_first_run_(is_first_run == chrome::startup::IS_FIRST_RUN), |
287 welcome_run_type_(WelcomeRunType::NONE) { | 287 welcome_run_type_(WelcomeRunType::NONE) { |
288 } | 288 } |
289 | 289 |
290 StartupBrowserCreatorImpl::~StartupBrowserCreatorImpl() { | 290 StartupBrowserCreatorImpl::~StartupBrowserCreatorImpl() { |
291 } | 291 } |
292 | 292 |
293 bool StartupBrowserCreatorImpl::Launch(Profile* profile, | 293 bool StartupBrowserCreatorImpl::Launch(Profile* profile, |
294 const std::vector<GURL>& urls_to_open, | 294 const std::vector<GURL>& urls_to_open, |
295 bool process_startup, | 295 bool process_startup, |
296 chrome::HostDesktopType desktop_type) { | 296 ui::HostDesktopType desktop_type) { |
297 UMA_HISTOGRAM_COUNTS_100("Startup.BrowserLaunchURLCount", | 297 UMA_HISTOGRAM_COUNTS_100("Startup.BrowserLaunchURLCount", |
298 static_cast<base::HistogramBase::Sample>(urls_to_open.size())); | 298 static_cast<base::HistogramBase::Sample>(urls_to_open.size())); |
299 RecordRapporOnStartupURLs(urls_to_open); | 299 RecordRapporOnStartupURLs(urls_to_open); |
300 | 300 |
301 DCHECK(profile); | 301 DCHECK(profile); |
302 profile_ = profile; | 302 profile_ = profile; |
303 | 303 |
304 if (AppListService::HandleLaunchCommandLine(command_line_, profile)) | 304 if (AppListService::HandleLaunchCommandLine(command_line_, profile)) |
305 return true; | 305 return true; |
306 | 306 |
307 if (command_line_.HasSwitch(switches::kAppId)) { | 307 if (command_line_.HasSwitch(switches::kAppId)) { |
308 std::string app_id = command_line_.GetSwitchValueASCII(switches::kAppId); | 308 std::string app_id = command_line_.GetSwitchValueASCII(switches::kAppId); |
309 const Extension* extension = GetPlatformApp(profile, app_id); | 309 const Extension* extension = GetPlatformApp(profile, app_id); |
310 // If |app_id| is a disabled or terminated platform app we handle it | 310 // If |app_id| is a disabled or terminated platform app we handle it |
311 // specially here, otherwise it will be handled below. | 311 // specially here, otherwise it will be handled below. |
312 if (extension) { | 312 if (extension) { |
313 RecordCmdLineAppHistogram(extensions::Manifest::TYPE_PLATFORM_APP); | 313 RecordCmdLineAppHistogram(extensions::Manifest::TYPE_PLATFORM_APP); |
314 AppLaunchParams params(profile, extension, | 314 AppLaunchParams params(profile, extension, |
315 extensions::LAUNCH_CONTAINER_NONE, NEW_WINDOW, | 315 extensions::LAUNCH_CONTAINER_NONE, NEW_WINDOW, |
316 extensions::SOURCE_COMMAND_LINE); | 316 extensions::SOURCE_COMMAND_LINE); |
317 params.command_line = command_line_; | 317 params.command_line = command_line_; |
318 params.current_directory = cur_dir_; | 318 params.current_directory = cur_dir_; |
319 // If we are being launched from the command line, default to native | 319 // If we are being launched from the command line, default to native |
320 // desktop. | 320 // desktop. |
321 params.desktop_type = chrome::HOST_DESKTOP_TYPE_NATIVE; | 321 params.desktop_type = ui::HOST_DESKTOP_TYPE_NATIVE; |
322 ::OpenApplicationWithReenablePrompt(params); | 322 ::OpenApplicationWithReenablePrompt(params); |
323 return true; | 323 return true; |
324 } | 324 } |
325 } | 325 } |
326 | 326 |
327 // Open the required browser windows and tabs. First, see if | 327 // Open the required browser windows and tabs. First, see if |
328 // we're being run as an application window. If so, the user | 328 // we're being run as an application window. If so, the user |
329 // opened an app shortcut. Don't restore tabs or open initial | 329 // opened an app shortcut. Don't restore tabs or open initial |
330 // URLs in that case. The user should see the window as an app, | 330 // URLs in that case. The user should see the window as an app, |
331 // not as chrome. | 331 // not as chrome. |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
480 WebContents* app_tab = ::OpenAppShortcutWindow(profile, url); | 480 WebContents* app_tab = ::OpenAppShortcutWindow(profile, url); |
481 return (app_tab != NULL); | 481 return (app_tab != NULL); |
482 } | 482 } |
483 } | 483 } |
484 return false; | 484 return false; |
485 } | 485 } |
486 | 486 |
487 void StartupBrowserCreatorImpl::ProcessLaunchURLs( | 487 void StartupBrowserCreatorImpl::ProcessLaunchURLs( |
488 bool process_startup, | 488 bool process_startup, |
489 const std::vector<GURL>& urls_to_open, | 489 const std::vector<GURL>& urls_to_open, |
490 chrome::HostDesktopType desktop_type) { | 490 ui::HostDesktopType desktop_type) { |
491 // If we're starting up in "background mode" (no open browser window) then | 491 // If we're starting up in "background mode" (no open browser window) then |
492 // don't open any browser windows, unless kAutoLaunchAtStartup is also | 492 // don't open any browser windows, unless kAutoLaunchAtStartup is also |
493 // specified. | 493 // specified. |
494 if (process_startup && | 494 if (process_startup && |
495 command_line_.HasSwitch(switches::kNoStartupWindow) && | 495 command_line_.HasSwitch(switches::kNoStartupWindow) && |
496 !command_line_.HasSwitch(switches::kAutoLaunchAtStartup)) { | 496 !command_line_.HasSwitch(switches::kAutoLaunchAtStartup)) { |
497 return; | 497 return; |
498 } | 498 } |
499 | 499 |
500 // Determine whether or not this launch must include the welcome page. | 500 // Determine whether or not this launch must include the welcome page. |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
548 } | 548 } |
549 | 549 |
550 // Session startup didn't occur, open the urls. | 550 // Session startup didn't occur, open the urls. |
551 Browser* browser = NULL; | 551 Browser* browser = NULL; |
552 std::vector<GURL> adjusted_urls = urls_to_open; | 552 std::vector<GURL> adjusted_urls = urls_to_open; |
553 if (adjusted_urls.empty()) { | 553 if (adjusted_urls.empty()) { |
554 AddStartupURLs(&adjusted_urls); | 554 AddStartupURLs(&adjusted_urls); |
555 } else if (!command_line_.HasSwitch(switches::kOpenInNewWindow)) { | 555 } else if (!command_line_.HasSwitch(switches::kOpenInNewWindow)) { |
556 // Always open a list of urls in a window on the native desktop. | 556 // Always open a list of urls in a window on the native desktop. |
557 browser = chrome::FindTabbedBrowser(profile_, false, | 557 browser = chrome::FindTabbedBrowser(profile_, false, |
558 chrome::HOST_DESKTOP_TYPE_NATIVE); | 558 ui::HOST_DESKTOP_TYPE_NATIVE); |
559 } | 559 } |
560 // This will launch a browser; prevent session restore. | 560 // This will launch a browser; prevent session restore. |
561 StartupBrowserCreator::in_synchronous_profile_launch_ = true; | 561 StartupBrowserCreator::in_synchronous_profile_launch_ = true; |
562 browser = | 562 browser = |
563 OpenURLsInBrowser(browser, process_startup, adjusted_urls, desktop_type); | 563 OpenURLsInBrowser(browser, process_startup, adjusted_urls, desktop_type); |
564 StartupBrowserCreator::in_synchronous_profile_launch_ = false; | 564 StartupBrowserCreator::in_synchronous_profile_launch_ = false; |
565 AddInfoBarsIfNecessary(browser, is_process_startup); | 565 AddInfoBarsIfNecessary(browser, is_process_startup); |
566 } | 566 } |
567 | 567 |
568 bool StartupBrowserCreatorImpl::ProcessStartupURLs( | 568 bool StartupBrowserCreatorImpl::ProcessStartupURLs( |
569 const std::vector<GURL>& urls_to_open, | 569 const std::vector<GURL>& urls_to_open, |
570 chrome::HostDesktopType desktop_type) { | 570 ui::HostDesktopType desktop_type) { |
571 VLOG(1) << "StartupBrowserCreatorImpl::ProcessStartupURLs"; | 571 VLOG(1) << "StartupBrowserCreatorImpl::ProcessStartupURLs"; |
572 SessionStartupPref pref = | 572 SessionStartupPref pref = |
573 StartupBrowserCreator::GetSessionStartupPref(command_line_, profile_); | 573 StartupBrowserCreator::GetSessionStartupPref(command_line_, profile_); |
574 if (pref.type == SessionStartupPref::LAST) | 574 if (pref.type == SessionStartupPref::LAST) |
575 VLOG(1) << "Pref: last"; | 575 VLOG(1) << "Pref: last"; |
576 else if (pref.type == SessionStartupPref::URLS) | 576 else if (pref.type == SessionStartupPref::URLS) |
577 VLOG(1) << "Pref: urls"; | 577 VLOG(1) << "Pref: urls"; |
578 else if (pref.type == SessionStartupPref::DEFAULT) | 578 else if (pref.type == SessionStartupPref::DEFAULT) |
579 VLOG(1) << "Pref: default"; | 579 VLOG(1) << "Pref: default"; |
580 | 580 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
615 #endif | 615 #endif |
616 | 616 |
617 // Optionally include the welcome page. | 617 // Optionally include the welcome page. |
618 std::vector<GURL> adjusted_urls(urls_to_open); | 618 std::vector<GURL> adjusted_urls(urls_to_open); |
619 if (welcome_run_type_ == WelcomeRunType::FIRST_TAB) { | 619 if (welcome_run_type_ == WelcomeRunType::FIRST_TAB) { |
620 adjusted_urls.insert(adjusted_urls.begin(), | 620 adjusted_urls.insert(adjusted_urls.begin(), |
621 internals::GetWelcomePageURL()); | 621 internals::GetWelcomePageURL()); |
622 } | 622 } |
623 | 623 |
624 // The startup code only executes for browsers launched in desktop mode. | 624 // The startup code only executes for browsers launched in desktop mode. |
625 // i.e. HOST_DESKTOP_TYPE_NATIVE. Ash should never get here. | 625 // i.e. ui::HOST_DESKTOP_TYPE_NATIVE. Ash should never get here. |
626 Browser* browser = SessionRestore::RestoreSession( | 626 Browser* browser = SessionRestore::RestoreSession( |
627 profile_, NULL, desktop_type, restore_behavior, adjusted_urls); | 627 profile_, NULL, desktop_type, restore_behavior, adjusted_urls); |
628 | 628 |
629 AddInfoBarsIfNecessary(browser, chrome::startup::IS_PROCESS_STARTUP); | 629 AddInfoBarsIfNecessary(browser, chrome::startup::IS_PROCESS_STARTUP); |
630 return true; | 630 return true; |
631 } | 631 } |
632 | 632 |
633 Browser* browser = ProcessSpecifiedURLs(urls_to_open, desktop_type); | 633 Browser* browser = ProcessSpecifiedURLs(urls_to_open, desktop_type); |
634 if (!browser) | 634 if (!browser) |
635 return false; | 635 return false; |
636 | 636 |
637 AddInfoBarsIfNecessary(browser, chrome::startup::IS_PROCESS_STARTUP); | 637 AddInfoBarsIfNecessary(browser, chrome::startup::IS_PROCESS_STARTUP); |
638 | 638 |
639 // Session restore may occur if the startup preference is "last" or if the | 639 // Session restore may occur if the startup preference is "last" or if the |
640 // crash infobar is displayed. Otherwise, it's safe for the DOM storage system | 640 // crash infobar is displayed. Otherwise, it's safe for the DOM storage system |
641 // to start deleting leftover data. | 641 // to start deleting leftover data. |
642 if (pref.type != SessionStartupPref::LAST && | 642 if (pref.type != SessionStartupPref::LAST && |
643 !HasPendingUncleanExit(profile_)) { | 643 !HasPendingUncleanExit(profile_)) { |
644 content::BrowserContext::GetDefaultStoragePartition(profile_)-> | 644 content::BrowserContext::GetDefaultStoragePartition(profile_)-> |
645 GetDOMStorageContext()->StartScavengingUnusedSessionStorage(); | 645 GetDOMStorageContext()->StartScavengingUnusedSessionStorage(); |
646 } | 646 } |
647 | 647 |
648 return true; | 648 return true; |
649 } | 649 } |
650 | 650 |
651 Browser* StartupBrowserCreatorImpl::ProcessSpecifiedURLs( | 651 Browser* StartupBrowserCreatorImpl::ProcessSpecifiedURLs( |
652 const std::vector<GURL>& urls_to_open, | 652 const std::vector<GURL>& urls_to_open, |
653 chrome::HostDesktopType desktop_type) { | 653 ui::HostDesktopType desktop_type) { |
654 SessionStartupPref pref = | 654 SessionStartupPref pref = |
655 StartupBrowserCreator::GetSessionStartupPref(command_line_, profile_); | 655 StartupBrowserCreator::GetSessionStartupPref(command_line_, profile_); |
656 StartupTabs tabs; | 656 StartupTabs tabs; |
657 // Pinned tabs should not be displayed when chrome is launched in incognito | 657 // Pinned tabs should not be displayed when chrome is launched in incognito |
658 // mode. Also, no pages should be opened automatically if the session | 658 // mode. Also, no pages should be opened automatically if the session |
659 // crashed. Otherwise it might trigger another crash, locking the user out of | 659 // crashed. Otherwise it might trigger another crash, locking the user out of |
660 // chrome. The crash infobar is shown in this case. | 660 // chrome. The crash infobar is shown in this case. |
661 if (!IncognitoModePrefs::ShouldLaunchIncognito(command_line_, | 661 if (!IncognitoModePrefs::ShouldLaunchIncognito(command_line_, |
662 profile_->GetPrefs()) && | 662 profile_->GetPrefs()) && |
663 !HasPendingUncleanExit(profile_)) { | 663 !HasPendingUncleanExit(profile_)) { |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
714 tab.url = urls[i]; | 714 tab.url = urls[i]; |
715 tabs->push_back(tab); | 715 tabs->push_back(tab); |
716 } | 716 } |
717 } | 717 } |
718 } | 718 } |
719 | 719 |
720 Browser* StartupBrowserCreatorImpl::OpenURLsInBrowser( | 720 Browser* StartupBrowserCreatorImpl::OpenURLsInBrowser( |
721 Browser* browser, | 721 Browser* browser, |
722 bool process_startup, | 722 bool process_startup, |
723 const std::vector<GURL>& urls, | 723 const std::vector<GURL>& urls, |
724 chrome::HostDesktopType desktop_type) { | 724 ui::HostDesktopType desktop_type) { |
725 StartupTabs tabs; | 725 StartupTabs tabs; |
726 UrlsToTabs(urls, &tabs); | 726 UrlsToTabs(urls, &tabs); |
727 return OpenTabsInBrowser(browser, process_startup, tabs, desktop_type); | 727 return OpenTabsInBrowser(browser, process_startup, tabs, desktop_type); |
728 } | 728 } |
729 | 729 |
730 Browser* StartupBrowserCreatorImpl::OpenTabsInBrowser( | 730 Browser* StartupBrowserCreatorImpl::OpenTabsInBrowser( |
731 Browser* browser, | 731 Browser* browser, |
732 bool process_startup, | 732 bool process_startup, |
733 const StartupTabs& tabs, | 733 const StartupTabs& tabs, |
734 chrome::HostDesktopType desktop_type) { | 734 ui::HostDesktopType desktop_type) { |
735 DCHECK(!tabs.empty()); | 735 DCHECK(!tabs.empty()); |
736 | 736 |
737 // If we don't yet have a profile, try to use the one we're given from | 737 // If we don't yet have a profile, try to use the one we're given from |
738 // |browser|. While we may not end up actually using |browser| (since it | 738 // |browser|. While we may not end up actually using |browser| (since it |
739 // could be a popup window), we can at least use the profile. | 739 // could be a popup window), we can at least use the profile. |
740 if (!profile_ && browser) | 740 if (!profile_ && browser) |
741 profile_ = browser->profile(); | 741 profile_ = browser->profile(); |
742 | 742 |
743 if (!browser || !browser->is_type_tabbed()) | 743 if (!browser || !browser->is_type_tabbed()) |
744 browser = new Browser(Browser::CreateParams(profile_, desktop_type)); | 744 browser = new Browser(Browser::CreateParams(profile_, desktop_type)); |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
972 #endif // !OS_WIN | 972 #endif // !OS_WIN |
973 } | 973 } |
974 | 974 |
975 void StartupBrowserCreatorImpl::RecordRapporOnStartupURLs( | 975 void StartupBrowserCreatorImpl::RecordRapporOnStartupURLs( |
976 const std::vector<GURL>& urls_to_open) { | 976 const std::vector<GURL>& urls_to_open) { |
977 for (const GURL& url : urls_to_open) { | 977 for (const GURL& url : urls_to_open) { |
978 rappor::SampleDomainAndRegistryFromGURL(g_browser_process->rappor_service(), | 978 rappor::SampleDomainAndRegistryFromGURL(g_browser_process->rappor_service(), |
979 "Startup.BrowserLaunchURL", url); | 979 "Startup.BrowserLaunchURL", url); |
980 } | 980 } |
981 } | 981 } |
OLD | NEW |