 Chromium Code Reviews
 Chromium Code Reviews Issue 2798143004:
  Fix for URL opening code  (Closed)
    
  
    Issue 2798143004:
  Fix for URL opening code  (Closed) 
  | Index: chrome/browser/app_controller_mac.mm | 
| diff --git a/chrome/browser/app_controller_mac.mm b/chrome/browser/app_controller_mac.mm | 
| index 844f15f614348480b0320db9fed4ae8fadce61d1..a92cf0467c2949d9c6a0c3491cbb8ec877e77311 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 | 
| @@ -1278,6 +1282,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 | 
| @@ -1288,18 +1302,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]; | 
| + 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)); | 
| 
Avi (use Gerrit)
2017/06/01 19:54:31
I just learned this, but you need to use [self saf
 
eugenebng
2017/06/07 10:42:11
Done. Thank you for sharing that!
 | 
| + 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)); | 
| 
Avi (use Gerrit)
2017/06/01 19:54:31
Same here.
 
eugenebng
2017/06/07 10:42:11
Done
 | 
| + 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 |