diff options
7 files changed, 103 insertions, 44 deletions
diff --git a/chrome/browser/app_controller_mac.mm b/chrome/browser/app_controller_mac.mm index feb0f95..26ea4fb 100644 --- a/chrome/browser/app_controller_mac.mm +++ b/chrome/browser/app_controller_mac.mm @@ -1122,7 +1122,7 @@ void RecordLastRunAppBundlePath() { chrome::startup::IsFirstRun first_run = first_run::IsChromeFirstRun() ? chrome::startup::IS_FIRST_RUN : chrome::startup::IS_NOT_FIRST_RUN; StartupBrowserCreatorImpl launch(base::FilePath(), dummy, first_run); - launch.OpenURLsInBrowser(browser, false, urls); + launch.OpenURLsInBrowser(browser, false, urls, browser->host_desktop_type()); } - (void)getUrl:(NSAppleEventDescriptor*)event diff --git a/chrome/browser/ui/ash/chrome_shell_delegate_views.cc b/chrome/browser/ui/ash/chrome_shell_delegate_views.cc index 136207f9..3cd2927 100644 --- a/chrome/browser/ui/ash/chrome_shell_delegate_views.cc +++ b/chrome/browser/ui/ash/chrome_shell_delegate_views.cc @@ -4,11 +4,18 @@ #include "chrome/browser/ui/ash/chrome_shell_delegate.h" +#include "base/command_line.h" #include "ash/magnifier/magnifier_constants.h" +#include "chrome/browser/prefs/session_startup_pref.h" +#include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/ui/ash/caps_lock_delegate_views.h" #include "chrome/browser/ui/ash/window_positioner.h" #include "chrome/browser/ui/browser.h" +#include "chrome/browser/ui/browser_list.h" +#include "chrome/browser/ui/browser_tabstrip.h" #include "chrome/browser/ui/browser_window.h" +#include "chrome/browser/ui/host_desktop.h" +#include "chrome/browser/ui/startup/startup_browser_creator_impl.h" #include "chrome/common/chrome_notification_types.h" #include "content/public/browser/notification_service.h" @@ -110,9 +117,34 @@ void ChromeShellDelegate::Observe(int type, const content::NotificationSource& source, const content::NotificationDetails& details) { switch (type) { - case chrome::NOTIFICATION_ASH_SESSION_STARTED: - GetTargetBrowser()->window()->Show(); + case chrome::NOTIFICATION_ASH_SESSION_STARTED: { + // If Chrome ASH is launched when no browser is open in the desktop, + // we should execute the startup code. + // If there are browsers open in the desktop, we create a browser window + // and open a new tab page, if session restore is not on. + BrowserList* desktop_list = BrowserList::GetInstance( + chrome::HOST_DESKTOP_TYPE_NATIVE); + if (desktop_list->empty()) { + // We pass a dummy command line here, because the browser is launched in + // silent-mode by the metro viewer process, which causes the + // StartupBrowserCreatorImpl class to not create any browsers which is + // not the behavior we want. + CommandLine dummy(CommandLine::NO_PROGRAM); + StartupBrowserCreatorImpl startup_impl( + base::FilePath(), + dummy, + chrome::startup::IS_NOT_FIRST_RUN); + startup_impl.Launch(ProfileManager::GetDefaultProfileOrOffTheRecord(), + std::vector<GURL>(), + true, + chrome::HOST_DESKTOP_TYPE_ASH); + } else { + Browser* browser = GetTargetBrowser(); + chrome::AddBlankTabAt(browser, -1, true); + browser->window()->Show(); + } break; + } case chrome::NOTIFICATION_ASH_SESSION_ENDED: break; default: diff --git a/chrome/browser/ui/browser_browsertest.cc b/chrome/browser/ui/browser_browsertest.cc index 64ff7aa..b46bbfc 100644 --- a/chrome/browser/ui/browser_browsertest.cc +++ b/chrome/browser/ui/browser_browsertest.cc @@ -1125,7 +1125,8 @@ IN_PROC_BROWSER_TEST_F(BrowserTest, RestorePinnedTabs) { chrome::startup::IS_FIRST_RUN : chrome::startup::IS_NOT_FIRST_RUN; StartupBrowserCreatorImpl launch(base::FilePath(), dummy, first_run); launch.profile_ = browser()->profile(); - launch.ProcessStartupURLs(std::vector<GURL>()); + launch.ProcessStartupURLs(std::vector<GURL>(), + browser()->host_desktop_type()); // The launch should have created a new browser. ASSERT_EQ(2u, chrome::GetBrowserCount(browser()->profile(), diff --git a/chrome/browser/ui/startup/startup_browser_creator.cc b/chrome/browser/ui/startup/startup_browser_creator.cc index 7fbeee3..84ccaf3 100644 --- a/chrome/browser/ui/startup/startup_browser_creator.cc +++ b/chrome/browser/ui/startup/startup_browser_creator.cc @@ -279,7 +279,8 @@ bool StartupBrowserCreator::LaunchBrowser( const std::vector<GURL> urls_to_launch = GetURLsFromCommandLine(command_line, cur_dir, profile); const bool launched = lwp.Launch(profile, urls_to_launch, - in_synchronous_profile_launch_); + in_synchronous_profile_launch_, + chrome::HOST_DESKTOP_TYPE_NATIVE); in_synchronous_profile_launch_ = false; if (!launched) { LOG(ERROR) << "launch error"; diff --git a/chrome/browser/ui/startup/startup_browser_creator_browsertest.cc b/chrome/browser/ui/startup/startup_browser_creator_browsertest.cc index 3bc3d6c..fe0300e 100644 --- a/chrome/browser/ui/startup/startup_browser_creator_browsertest.cc +++ b/chrome/browser/ui/startup/startup_browser_creator_browsertest.cc @@ -159,7 +159,8 @@ IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest, OpenURLsPopup) { StartupBrowserCreatorImpl launch(base::FilePath(), dummy, first_run); // This should create a new window, but re-use the profile from |popup|. If // it used a NULL or invalid profile, it would crash. - launch.OpenURLsInBrowser(popup, false, urls); + launch.OpenURLsInBrowser(popup, false, urls, + chrome::HOST_DESKTOP_TYPE_NATIVE); ASSERT_NE(popup, observer.added_browser_); BrowserList::RemoveObserver(&observer); } @@ -192,7 +193,8 @@ IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest, chrome::startup::IsFirstRun first_run = first_run::IsChromeFirstRun() ? chrome::startup::IS_FIRST_RUN : chrome::startup::IS_NOT_FIRST_RUN; StartupBrowserCreatorImpl launch(base::FilePath(), dummy, first_run); - ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false)); + ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false, + browser()->host_desktop_type())); // This should have created a new browser window. |browser()| is still // around at this point, even though we've closed its window. @@ -236,7 +238,8 @@ IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest, chrome::startup::IsFirstRun first_run = first_run::IsChromeFirstRun() ? chrome::startup::IS_FIRST_RUN : chrome::startup::IS_NOT_FIRST_RUN; StartupBrowserCreatorImpl launch(base::FilePath(), dummy, first_run); - ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false)); + ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false, + browser()->host_desktop_type())); // This should have created a new browser window. Browser* new_browser = FindOneOtherBrowser(browser()); @@ -260,7 +263,8 @@ IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest, OpenAppShortcutNoPref) { chrome::startup::IsFirstRun first_run = first_run::IsChromeFirstRun() ? chrome::startup::IS_FIRST_RUN : chrome::startup::IS_NOT_FIRST_RUN; StartupBrowserCreatorImpl launch(base::FilePath(), command_line, first_run); - ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false)); + ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false, + browser()->host_desktop_type())); // No pref was set, so the app should have opened in a window. // The launch should have created a new browser. @@ -289,7 +293,8 @@ IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest, OpenAppShortcutWindowPref) { chrome::startup::IsFirstRun first_run = first_run::IsChromeFirstRun() ? chrome::startup::IS_FIRST_RUN : chrome::startup::IS_NOT_FIRST_RUN; StartupBrowserCreatorImpl launch(base::FilePath(), command_line, first_run); - ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false)); + ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false, + browser()->host_desktop_type())); // Pref was set to open in a window, so the app should have opened in a // window. The launch should have created a new browser. Find the new @@ -320,7 +325,8 @@ IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest, OpenAppShortcutTabPref) { chrome::startup::IsFirstRun first_run = first_run::IsChromeFirstRun() ? chrome::startup::IS_FIRST_RUN : chrome::startup::IS_NOT_FIRST_RUN; StartupBrowserCreatorImpl launch(base::FilePath(), command_line, first_run); - ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false)); + ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false, + browser()->host_desktop_type())); // When an app shortcut is open and the pref indicates a tab should // open, the tab is open in a new browser window. Expect a new window. @@ -377,7 +383,8 @@ IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest, AddFirstRunTab) { CommandLine dummy(CommandLine::NO_PROGRAM); StartupBrowserCreatorImpl launch(base::FilePath(), dummy, &browser_creator, chrome::startup::IS_FIRST_RUN); - ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false)); + ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false, + browser()->host_desktop_type())); // This should have created a new browser window. Browser* new_browser = FindOneOtherBrowser(browser()); @@ -405,7 +412,8 @@ IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest, AddCustomFirstRunTab) { CommandLine dummy(CommandLine::NO_PROGRAM); StartupBrowserCreatorImpl launch(base::FilePath(), dummy, &browser_creator, chrome::startup::IS_FIRST_RUN); - ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false)); + ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false, + browser()->host_desktop_type())); // This should have created a new browser window. Browser* new_browser = FindOneOtherBrowser(browser()); @@ -434,7 +442,8 @@ IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest, SyncPromoNoWelcomePage) { CommandLine dummy(CommandLine::NO_PROGRAM); StartupBrowserCreatorImpl launch(base::FilePath(), dummy, chrome::startup::IS_FIRST_RUN); - ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false)); + ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false, + browser()->host_desktop_type())); // This should have created a new browser window. Browser* new_browser = FindOneOtherBrowser(browser()); @@ -462,7 +471,8 @@ IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest, SyncPromoWithWelcomePage) { CommandLine dummy(CommandLine::NO_PROGRAM); StartupBrowserCreatorImpl launch(base::FilePath(), dummy, chrome::startup::IS_FIRST_RUN); - ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false)); + ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false, + browser()->host_desktop_type())); // This should have created a new browser window. Browser* new_browser = FindOneOtherBrowser(browser()); @@ -499,7 +509,8 @@ IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest, SyncPromoWithFirstRunTabs) { CommandLine dummy(CommandLine::NO_PROGRAM); StartupBrowserCreatorImpl launch(base::FilePath(), dummy, &browser_creator, chrome::startup::IS_FIRST_RUN); - ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false)); + ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false, + browser()->host_desktop_type())); // This should have created a new browser window. Browser* new_browser = FindOneOtherBrowser(browser()); @@ -535,7 +546,8 @@ IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest, CommandLine dummy(CommandLine::NO_PROGRAM); StartupBrowserCreatorImpl launch(base::FilePath(), dummy, &browser_creator, chrome::startup::IS_FIRST_RUN); - ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false)); + ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false, + browser()->host_desktop_type())); // This should have created a new browser window. Browser* new_browser = FindOneOtherBrowser(browser()); @@ -945,7 +957,8 @@ IN_PROC_BROWSER_TEST_F(ManagedModeBrowserCreatorTest, content::WindowedNotificationObserver observer( content::NOTIFICATION_LOAD_STOP, content::NotificationService::AllSources()); - ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false)); + ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false, + browser()->host_desktop_type())); // This should have created a new browser window. Browser* new_browser = FindOneOtherBrowser(browser()); diff --git a/chrome/browser/ui/startup/startup_browser_creator_impl.cc b/chrome/browser/ui/startup/startup_browser_creator_impl.cc index 7e10617..594b4a1 100644 --- a/chrome/browser/ui/startup/startup_browser_creator_impl.cc +++ b/chrome/browser/ui/startup/startup_browser_creator_impl.cc @@ -369,7 +369,8 @@ StartupBrowserCreatorImpl::~StartupBrowserCreatorImpl() { bool StartupBrowserCreatorImpl::Launch(Profile* profile, const std::vector<GURL>& urls_to_open, - bool process_startup) { + bool process_startup, + chrome::HostDesktopType desktop_type) { DCHECK(profile); profile_ = profile; @@ -401,7 +402,7 @@ bool StartupBrowserCreatorImpl::Launch(Profile* profile, RecordLaunchModeHistogram(urls_to_open.empty() ? LM_TO_BE_DECIDED : LM_WITH_URLS); - ProcessLaunchURLs(process_startup, urls_to_open); + ProcessLaunchURLs(process_startup, urls_to_open, desktop_type); // If this is an app launch, but we didn't open an app window, it may // be an app tab. @@ -571,7 +572,8 @@ bool StartupBrowserCreatorImpl::OpenApplicationWindow( void StartupBrowserCreatorImpl::ProcessLaunchURLs( bool process_startup, - const std::vector<GURL>& urls_to_open) { + const std::vector<GURL>& urls_to_open, + chrome::HostDesktopType desktop_type) { // If we're starting up in "background mode" (no open browser window) then // don't open any browser windows, unless kAutoLaunchAtStartup is also // specified. @@ -590,7 +592,7 @@ void StartupBrowserCreatorImpl::ProcessLaunchURLs( } #endif - if (process_startup && ProcessStartupURLs(urls_to_open)) { + if (process_startup && ProcessStartupURLs(urls_to_open, desktop_type)) { // ProcessStartupURLs processed the urls, nothing else to do. return; } @@ -612,7 +614,7 @@ void StartupBrowserCreatorImpl::ProcessLaunchURLs( return; } // Open user-specified URLs like pinned tabs and startup tabs. - Browser* browser = ProcessSpecifiedURLs(urls_to_open); + Browser* browser = ProcessSpecifiedURLs(urls_to_open, desktop_type); if (browser) { AddInfoBarsIfNecessary(browser, is_process_startup); return; @@ -635,13 +637,15 @@ void StartupBrowserCreatorImpl::ProcessLaunchURLs( } // This will launch a browser; prevent session restore. StartupBrowserCreator::in_synchronous_profile_launch_ = true; - browser = OpenURLsInBrowser(browser, process_startup, adjust_urls); + browser = OpenURLsInBrowser(browser, process_startup, adjust_urls, + desktop_type); StartupBrowserCreator::in_synchronous_profile_launch_ = false; AddInfoBarsIfNecessary(browser, is_process_startup); } bool StartupBrowserCreatorImpl::ProcessStartupURLs( - const std::vector<GURL>& urls_to_open) { + const std::vector<GURL>& urls_to_open, + chrome::HostDesktopType desktop_type) { VLOG(1) << "StartupBrowserCreatorImpl::ProcessStartupURLs"; SessionStartupPref pref = StartupBrowserCreator::GetSessionStartupPref(command_line_, profile_); @@ -696,7 +700,7 @@ bool StartupBrowserCreatorImpl::ProcessStartupURLs( // The startup code only executes for browsers launched in desktop mode. // i.e. HOST_DESKTOP_TYPE_NATIVE. Ash should never get here. Browser* browser = SessionRestore::RestoreSession( - profile_, NULL, chrome::HOST_DESKTOP_TYPE_NATIVE, restore_behavior, + profile_, NULL, desktop_type, restore_behavior, urls_to_open); performance_monitor::StartupTimer::UnpauseTimer(); @@ -705,7 +709,7 @@ bool StartupBrowserCreatorImpl::ProcessStartupURLs( return true; } - Browser* browser = ProcessSpecifiedURLs(urls_to_open); + Browser* browser = ProcessSpecifiedURLs(urls_to_open, desktop_type); if (!browser) return false; @@ -724,7 +728,8 @@ bool StartupBrowserCreatorImpl::ProcessStartupURLs( } Browser* StartupBrowserCreatorImpl::ProcessSpecifiedURLs( - const std::vector<GURL>& urls_to_open) { + const std::vector<GURL>& urls_to_open, + chrome::HostDesktopType desktop_type) { SessionStartupPref pref = StartupBrowserCreator::GetSessionStartupPref(command_line_, profile_); StartupTabs tabs; @@ -769,7 +774,7 @@ Browser* StartupBrowserCreatorImpl::ProcessSpecifiedURLs( if (tabs.empty()) return NULL; - Browser* browser = OpenTabsInBrowser(NULL, true, tabs); + Browser* browser = OpenTabsInBrowser(NULL, true, tabs, desktop_type); return browser; } @@ -796,15 +801,18 @@ void StartupBrowserCreatorImpl::AddUniqueURLs(const std::vector<GURL>& urls, Browser* StartupBrowserCreatorImpl::OpenURLsInBrowser( Browser* browser, bool process_startup, - const std::vector<GURL>& urls) { + const std::vector<GURL>& urls, + chrome::HostDesktopType desktop_type) { StartupTabs tabs; UrlsToTabs(urls, &tabs); - return OpenTabsInBrowser(browser, process_startup, tabs); + return OpenTabsInBrowser(browser, process_startup, tabs, desktop_type); } -Browser* StartupBrowserCreatorImpl::OpenTabsInBrowser(Browser* browser, - bool process_startup, - const StartupTabs& tabs) { +Browser* StartupBrowserCreatorImpl::OpenTabsInBrowser( + Browser* browser, + bool process_startup, + const StartupTabs& tabs, + chrome::HostDesktopType desktop_type) { DCHECK(!tabs.empty()); // If we don't yet have a profile, try to use the one we're given from @@ -814,10 +822,7 @@ Browser* StartupBrowserCreatorImpl::OpenTabsInBrowser(Browser* browser, profile_ = browser->profile(); if (!browser || !browser->is_type_tabbed()) { - // The startup code only executes for browsers launched in desktop mode. - // i.e. HOST_DESKTOP_TYPE_NATIVE. Ash should never get here. - browser = new Browser(Browser::CreateParams( - profile_, chrome::HOST_DESKTOP_TYPE_NATIVE)); + browser = new Browser(Browser::CreateParams(profile_, desktop_type)); } else { #if defined(TOOLKIT_GTK) // Setting the time of the last action on the window here allows us to steal diff --git a/chrome/browser/ui/startup/startup_browser_creator_impl.h b/chrome/browser/ui/startup/startup_browser_creator_impl.h index c44f06f..f27a18e 100644 --- a/chrome/browser/ui/startup/startup_browser_creator_impl.h +++ b/chrome/browser/ui/startup/startup_browser_creator_impl.h @@ -10,6 +10,7 @@ #include "base/files/file_path.h" #include "base/gtest_prod_util.h" +#include "chrome/browser/ui/host_desktop.h" #include "chrome/browser/ui/startup/startup_tab.h" #include "chrome/browser/ui/startup/startup_types.h" #include "googleurl/src/gurl.h" @@ -58,13 +59,15 @@ class StartupBrowserCreatorImpl { // already running and the user wants to launch another instance. bool Launch(Profile* profile, const std::vector<GURL>& urls_to_open, - bool process_startup); + bool process_startup, + chrome::HostDesktopType desktop_type); // Convenience for OpenTabsInBrowser that converts |urls| into a set of // Tabs. Browser* OpenURLsInBrowser(Browser* browser, bool process_startup, - const std::vector<GURL>& urls); + const std::vector<GURL>& urls, + chrome::HostDesktopType desktop_type); // Creates a tab for each of the Tabs in |tabs|. If browser is non-null // and a tabbed browser, the tabs are added to it. Otherwise a new tabbed @@ -73,7 +76,8 @@ class StartupBrowserCreatorImpl { // browser. Browser* OpenTabsInBrowser(Browser* browser, bool process_startup, - const StartupTabs& tabs); + const StartupTabs& tabs, + chrome::HostDesktopType desktop_type); private: FRIEND_TEST_ALL_PREFIXES(BrowserTest, RestorePinnedTabs); @@ -105,7 +109,8 @@ class StartupBrowserCreatorImpl { // or invoke ProcessSpecifiedURLs. // . Open the urls directly. void ProcessLaunchURLs(bool process_startup, - const std::vector<GURL>& urls_to_open); + const std::vector<GURL>& urls_to_open, + chrome::HostDesktopType desktop_type); // Does the following: // . If the user's startup pref is to restore the last session (or the @@ -114,7 +119,8 @@ class StartupBrowserCreatorImpl { // . Otherwise invoke ProcessSpecifiedURLs // If a browser was created, true is returned. Otherwise returns false and // the caller must create a new browser. - bool ProcessStartupURLs(const std::vector<GURL>& urls_to_open); + bool ProcessStartupURLs(const std::vector<GURL>& urls_to_open, + chrome::HostDesktopType desktop_type); // Invoked from either ProcessLaunchURLs or ProcessStartupURLs to handle // processing of URLs where the behavior is common between process startup @@ -127,7 +133,8 @@ class StartupBrowserCreatorImpl { // // If any tabs were opened, the Browser which was created is returned. // Otherwise null is returned and the caller must create a new browser. - Browser* ProcessSpecifiedURLs(const std::vector<GURL>& urls_to_open); + Browser* ProcessSpecifiedURLs(const std::vector<GURL>& urls_to_open, + chrome::HostDesktopType desktop_type); // Adds a Tab to |tabs| for each url in |urls| that doesn't already exist // in |tabs|. |