summaryrefslogtreecommitdiffstats
path: root/chrome/browser/app_controller_mac.mm
diff options
context:
space:
mode:
authorerikchen <erikchen@chromium.org>2014-10-31 12:14:22 -0700
committerCommit bot <commit-bot@chromium.org>2014-10-31 19:14:33 +0000
commit19ee3922f7438d37833ae5ec58af10518b4a6c47 (patch)
tree0a1d870558590bdd65ac5161e2a63b94b25ca923 /chrome/browser/app_controller_mac.mm
parent057f7a69dd40c93550b375b4287dba70d719316a (diff)
downloadchromium_src-19ee3922f7438d37833ae5ec58af10518b4a6c47.zip
chromium_src-19ee3922f7438d37833ae5ec58af10518b4a6c47.tar.gz
chromium_src-19ee3922f7438d37833ae5ec58af10518b4a6c47.tar.bz2
mac: Opening a URL should replace the NTP.
When a browser window is instructed to open a URL, if the only existing tab is the NTP, the NTP should be replaced with a tab with the given URL. This was partially fixed by https://codereview.chromium.org/240273002, but that only tackled the case where Chrome was launched as a result of an open URL Apple Event. This CL replicates the behavior for Chrome receiving a URL from Handoff, and for Chrome receiving an open URL Apple Event while Chrome is already running. BUG=428081, 43520 Review URL: https://codereview.chromium.org/678423003 Cr-Commit-Position: refs/heads/master@{#302304}
Diffstat (limited to 'chrome/browser/app_controller_mac.mm')
-rw-r--r--chrome/browser/app_controller_mac.mm43
1 files changed, 32 insertions, 11 deletions
diff --git a/chrome/browser/app_controller_mac.mm b/chrome/browser/app_controller_mac.mm
index 87646b4..3a433d7 100644
--- a/chrome/browser/app_controller_mac.mm
+++ b/chrome/browser/app_controller_mac.mm
@@ -215,7 +215,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;
@@ -225,6 +224,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 {
@@ -662,6 +675,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
@@ -669,8 +691,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
@@ -684,10 +710,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)) {
@@ -1325,9 +1348,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;
@@ -1357,7 +1378,7 @@ class AppControllerProfileObserver : public ProfileInfoCacheObserver {
std::vector<GURL> gurlVector;
gurlVector.push_back(gurl);
- [self openUrls:gurlVector];
+ [self openUrlsReplacingNTP:gurlVector];
}
- (void)application:(NSApplication*)sender
@@ -1369,7 +1390,7 @@ class AppControllerProfileObserver : public ProfileInfoCacheObserver {
gurlVector.push_back(gurl);
}
if (!gurlVector.empty())
- [self openUrls:gurlVector];
+ [self openUrlsReplacingNTP:gurlVector];
else
NOTREACHED() << "Nothing to open!";
@@ -1585,7 +1606,7 @@ class AppControllerProfileObserver : public ProfileInfoCacheObserver {
std::vector<GURL> gurlVector;
gurlVector.push_back(gurl);
- [self openUrls:gurlVector];
+ [self openUrlsReplacingNTP:gurlVector];
return YES;
}