Index: chrome/browser/app_controller_mac.mm |
diff --git a/chrome/browser/app_controller_mac.mm b/chrome/browser/app_controller_mac.mm |
index 434e3e72ba261b284c2b3360666dd258e6be8b6e..4b5dcc6bb431c0eac8ae684815ad9cd45f1a0ae3 100644 |
--- a/chrome/browser/app_controller_mac.mm |
+++ b/chrome/browser/app_controller_mac.mm |
@@ -213,7 +213,6 @@ bool IsProfileSignedOut(Profile* profile) { |
- (void)updateConfirmToQuitPrefMenuItem:(NSMenuItem*)item; |
- (void)updateDisplayMessageCenterPrefMenuItem:(NSMenuItem*)item; |
- (void)registerServicesMenuTypesTo:(NSApplication*)app; |
-- (void)openUrls:(const std::vector<GURL>&)urls; |
- (void)getUrl:(NSAppleEventDescriptor*)event |
withReply:(NSAppleEventDescriptor*)reply; |
- (void)windowLayeringDidChange:(NSNotification*)inNotification; |
@@ -223,6 +222,20 @@ bool IsProfileSignedOut(Profile* profile) { |
- (BOOL)shouldQuitWithInProgressDownloads; |
- (void)executeApplication:(id)sender; |
- (void)profileWasRemoved:(const base::FilePath&)profilePath; |
+ |
+// Opens a tab for each GURL in |urls|. |
+- (void)openUrls:(const std::vector<GURL>&)urls; |
+ |
+// 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 |
+// clears |startupUrls_|. |
+- (void)openStartupUrls; |
+ |
+// Opens a tab for each GURL in |urls|. If there is exactly one tab open before |
+// this method is called, and that tab is the NTP, then this method closes the |
+// NTP after all the |urls| have been opened. |
+- (void)openUrlsReplacingNTP:(const std::vector<GURL>&)urls; |
@end |
class AppControllerProfileObserver : public ProfileInfoCacheObserver { |
@@ -660,6 +673,15 @@ class AppControllerProfileObserver : public ProfileInfoCacheObserver { |
} |
- (void)openStartupUrls { |
+ DCHECK(startupComplete_); |
+ [self openUrlsReplacingNTP:startupUrls_]; |
+ startupUrls_.clear(); |
+} |
+ |
+- (void)openUrlsReplacingNTP:(const std::vector<GURL>&)urls { |
+ if (urls.empty()) |
+ return; |
+ |
// On Mac, the URLs are passed in via Cocoa, not command line. The Chrome |
// NSApplication is created in MainMessageLoop, and then the shortcut urls |
// are passed in via Apple events. At this point, the first browser is |
@@ -667,8 +689,12 @@ class AppControllerProfileObserver : public ProfileInfoCacheObserver { |
// before PreMainMessageLoop to capture shortcut URL events, it may cause |
// more problems because it relies on things created in PreMainMessageLoop |
// and may break existing message loop design. |
- if (startupUrls_.empty()) |
+ |
+ // If the browser hasn't started yet, just queue up the URLs. |
+ if (!startupComplete_) { |
+ startupUrls_.insert(startupUrls_.end(), urls.begin(), urls.end()); |
return; |
+ } |
// If there's only 1 tab and the tab is NTP, close this NTP tab and open all |
// startup urls in new tabs, because the omnibox will stay focused if we |
@@ -682,10 +708,7 @@ class AppControllerProfileObserver : public ProfileInfoCacheObserver { |
startupContent = browser->tab_strip_model()->GetActiveWebContents(); |
} |
- if (startupUrls_.size()) { |
- [self openUrls:startupUrls_]; |
- startupUrls_.clear(); |
- } |
+ [self openUrls:urls]; |
if (startupIndex != TabStripModel::kNoTab && |
startupContent->GetVisibleURL() == GURL(chrome::kChromeUINewTabURL)) { |
@@ -1315,9 +1338,7 @@ class AppControllerProfileObserver : public ProfileInfoCacheObserver { |
// StartupBrowserCreator here because on the other platforms, URLs to open come |
// through the ProcessSingleton, and it calls StartupBrowserCreator. It's best |
// to bottleneck the openings through that for uniform handling. |
- |
- (void)openUrls:(const std::vector<GURL>&)urls { |
- // If the browser hasn't started yet, just queue up the URLs. |
if (!startupComplete_) { |
startupUrls_.insert(startupUrls_.end(), urls.begin(), urls.end()); |
return; |
@@ -1347,7 +1368,7 @@ class AppControllerProfileObserver : public ProfileInfoCacheObserver { |
std::vector<GURL> gurlVector; |
gurlVector.push_back(gurl); |
- [self openUrls:gurlVector]; |
+ [self openUrlsReplacingNTP:gurlVector]; |
} |
- (void)application:(NSApplication*)sender |
@@ -1359,7 +1380,7 @@ class AppControllerProfileObserver : public ProfileInfoCacheObserver { |
gurlVector.push_back(gurl); |
} |
if (!gurlVector.empty()) |
- [self openUrls:gurlVector]; |
+ [self openUrlsReplacingNTP:gurlVector]; |
else |
NOTREACHED() << "Nothing to open!"; |
@@ -1559,7 +1580,7 @@ class AppControllerProfileObserver : public ProfileInfoCacheObserver { |
std::vector<GURL> gurlVector; |
gurlVector.push_back(gurl); |
- [self openUrls:gurlVector]; |
+ [self openUrlsReplacingNTP:gurlVector]; |
return YES; |
} |