Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4461)

Unified Diff: chrome/browser/app_controller_mac.mm

Issue 240273002: Close the ntp during startup when opening a link on Mac. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/app_controller_mac.mm
diff --git a/chrome/browser/app_controller_mac.mm b/chrome/browser/app_controller_mac.mm
index a4fa0f59a09f22d3b303c47fef6d1635af2c2134..f38d6b08b402c5b2d46cc0468443571f7f0ae385 100644
--- a/chrome/browser/app_controller_mac.mm
+++ b/chrome/browser/app_controller_mac.mm
@@ -681,6 +681,41 @@ class AppControllerProfileObserver : public ProfileInfoCacheObserver {
#endif
}
+- (void)openStartupUrls {
+ // On Mac, the URLs are passed in via cocoa, not command line. The chrome
Alexei Svitkine (slow) 2014/04/24 21:39:24 Nit: Capitalize Cocoa and Chrome.
+ // NSApplication is created in MainMessageLoop, and then the shortcut urls
+ // are passed in via apple events. At this point, the first browser is
Alexei Svitkine (slow) 2014/04/24 21:39:24 Nit: Apple events
+ // already loaded in PreMainMessageLoop. If we initialize NSApplication
+ // 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())
+ 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
+ // load url in NTP tab.
+ Browser* browser = chrome::GetLastActiveBrowser();
+ int startupIndex = TabStripModel::kNoTab;
+ content::WebContents* startupContent = NULL;
+
+ if (browser && browser->tab_strip_model()->count() == 1) {
+ startupIndex = browser->tab_strip_model()->active_index();
+ startupContent = browser->tab_strip_model()->GetActiveWebContents();
+ }
+
+ if (startupUrls_.size()) {
+ [self openUrls:startupUrls_];
+ startupUrls_.clear();
+ }
+
+ if (startupIndex != TabStripModel::kNoTab &&
+ startupContent->GetVisibleURL() == GURL(chrome::kChromeUINewTabURL)) {
+ browser->tab_strip_model()->CloseWebContentsAt(startupIndex,
+ TabStripModel::CLOSE_NONE);
+ }
+}
+
// This is called after profiles have been loaded and preferences registered.
// It is safe to access the default profile here.
- (void)applicationDidFinishLaunching:(NSNotification*)notify {
@@ -725,13 +760,7 @@ class AppControllerProfileObserver : public ProfileInfoCacheObserver {
startupComplete_ = YES;
- // TODO(viettrungluu): This is very temporary, since this should be done "in"
- // |BrowserMain()|, i.e., this list of startup URLs should be appended to the
- // (probably-empty) list of URLs from the command line.
- if (startupUrls_.size()) {
- [self openUrls:startupUrls_];
- [self clearStartupUrls];
- }
+ [self openStartupUrls];
PrefService* localState = g_browser_process->local_state();
if (localState) {
@@ -1458,10 +1487,6 @@ class AppControllerProfileObserver : public ProfileInfoCacheObserver {
return startupUrls_;
}
-- (void)clearStartupUrls {
- startupUrls_.clear();
-}
-
- (BookmarkMenuBridge*)bookmarkMenuBridge {
return bookmarkMenuBridge_.get();
}

Powered by Google App Engine
This is Rietveld 408576698