Chromium Code Reviews| Index: chrome/browser/app_controller_mac.mm |
| diff --git a/chrome/browser/app_controller_mac.mm b/chrome/browser/app_controller_mac.mm |
| index f6e6ec5789882d8e481490891267886b5720e671..002624bb699662404d592f875107c5086bc3f72c 100644 |
| --- a/chrome/browser/app_controller_mac.mm |
| +++ b/chrome/browser/app_controller_mac.mm |
| @@ -209,6 +209,10 @@ - (void)profileWasRemoved:(const base::FilePath&)profilePath; |
| // Opens a tab for each GURL in |urls|. |
| - (void)openUrls:(const std::vector<GURL>&)urls; |
| +// Creates StartupBrowserCreator and opens |urls| with it. |
| +- (void)openUrlsViaStartupBrowserCreator:(const std::vector<GURL>&)urls |
| + inBrowser:(Browser*)browser; |
| + |
| // This class cannot open urls until startup has finished. The urls that cannot |
| // be opened are cached in |startupUrls_|. This method must be called exactly |
| // once after startup has completed. It opens the urls in |startupUrls_|, and |
| @@ -1270,6 +1274,16 @@ - (bool)canOpenNewBrowser { |
| prefs->GetBoolean(prefs::kBrowserGuestModeEnabled); |
| } |
| +- (void)openUrlsViaStartupBrowserCreator:(const std::vector<GURL>&)urls |
| + inBrowser:(Browser*)browser { |
| + base::CommandLine dummy(base::CommandLine::NO_PROGRAM); |
| + 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); |
| +} |
| + |
| // Various methods to open URLs that we get in a native fashion. We use |
| // StartupBrowserCreator here because on the other platforms, URLs to open come |
| // through the ProcessSingleton, and it calls StartupBrowserCreator. It's best |
| @@ -1280,18 +1294,36 @@ - (void)openUrls:(const std::vector<GURL>&)urls { |
| return; |
| } |
| - Browser* browser = chrome::GetLastActiveBrowser(); |
| - // if no browser window exists then create one with no tabs to be filled in |
| - if (!browser) { |
| - browser = new Browser(Browser::CreateParams([self lastProfile], true)); |
| - browser->window()->Show(); |
| + Profile* profile = [self lastProfile]; |
|
Avi (use Gerrit)
2017/05/17 15:51:09
You've tested this with multiple profile setups?
|
| + SessionStartupPref pref = StartupBrowserCreator::GetSessionStartupPref( |
| + *base::CommandLine::ForCurrentProcess(), profile); |
| + |
| + if (pref.type == SessionStartupPref::LAST) { |
| + if (SessionRestore::IsRestoring(profile)) { |
| + // In case of session restore, remember |urls|, so they will be opened |
| + // after session is resored, in the tabs next to it. |
| + SessionRestore::AddURLsToOpen(profile, urls); |
| + } else { |
| + Browser* browser = chrome::GetLastActiveBrowser(); |
| + if (!browser) { |
| + // This behavior is needed for the case when chromium app is launched, |
| + // but there are no open indows. |
| + browser = new Browser(Browser::CreateParams([self lastProfile], true)); |
| + browser->window()->Show(); |
| + SessionRestore::AddURLsToOpen(profile, urls); |
| + } else { |
| + [self openUrlsViaStartupBrowserCreator:urls inBrowser:browser]; |
| + } |
| + } |
| + } else { |
| + Browser* browser = chrome::GetLastActiveBrowser(); |
| + // If no browser window exists then create one with no tabs to be filled in. |
| + if (!browser) { |
| + browser = new Browser(Browser::CreateParams([self lastProfile], true)); |
| + browser->window()->Show(); |
| + } |
| + [self openUrlsViaStartupBrowserCreator:urls inBrowser:browser]; |
| } |
| - |
| - base::CommandLine dummy(base::CommandLine::NO_PROGRAM); |
| - 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); |
| } |
| - (void)getUrl:(NSAppleEventDescriptor*)event |