diff options
author | avi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-19 13:58:25 +0000 |
---|---|---|
committer | avi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-19 13:58:25 +0000 |
commit | 136140cbfa6adc9caed9692eb664ff9c4a73482d (patch) | |
tree | d0ab5827ad750ec0c0675af3474be0ac12fea46a | |
parent | 74f9b2c89220aa8c716b14ae81a399f07fce355b (diff) | |
download | chromium_src-136140cbfa6adc9caed9692eb664ff9c4a73482d.zip chromium_src-136140cbfa6adc9caed9692eb664ff9c4a73482d.tar.gz chromium_src-136140cbfa6adc9caed9692eb664ff9c4a73482d.tar.bz2 |
Must register the AE handler earlier to catch the open url on a launch.
BUG=http://crbug.com/11996
Review URL: http://codereview.chromium.org/113543
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@16371 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/app_controller_mac.h | 7 | ||||
-rw-r--r-- | chrome/browser/app_controller_mac.mm | 54 |
2 files changed, 44 insertions, 17 deletions
diff --git a/chrome/browser/app_controller_mac.h b/chrome/browser/app_controller_mac.h index dc27005..d916abf 100644 --- a/chrome/browser/app_controller_mac.h +++ b/chrome/browser/app_controller_mac.h @@ -6,12 +6,14 @@ #define CHROME_BROWSER_APP_CONTROLLER_MAC_H_ #import <Cocoa/Cocoa.h> +#include <vector> #include "base/scoped_nsobject.h" #include "base/scoped_ptr.h" class BookmarkMenuBridge; class CommandUpdater; +class GURL; @class PreferencesWindowController; class Profile; @@ -25,6 +27,11 @@ class Profile; // (and Browser*s). scoped_ptr<BookmarkMenuBridge> bookmarkMenuBridge_; scoped_nsobject<PreferencesWindowController> prefsController_; + + // URLs that need to be opened when the app is fully initialized. Because it's + // only needed during early startup, it points to a valid vector during early + // startup and is NULL during the rest of app execution. + scoped_ptr<std::vector<GURL> > pendingURLs_; } - (IBAction)quit:(id)sender; diff --git a/chrome/browser/app_controller_mac.mm b/chrome/browser/app_controller_mac.mm index 7632024..859840f 100644 --- a/chrome/browser/app_controller_mac.mm +++ b/chrome/browser/app_controller_mac.mm @@ -23,6 +23,8 @@ @interface AppController(PRIVATE) - (void)initMenuState; +- (void)openURLs:(const std::vector<GURL>&)urls; +- (void)openPendingURLs; - (void)getUrl:(NSAppleEventDescriptor*)event withReply:(NSAppleEventDescriptor*)reply; - (void)openFiles:(NSAppleEventDescriptor*)event @@ -35,19 +37,9 @@ // the profile is loaded or any preferences have been registered). Defer any // user-data initialization until -applicationDidFinishLaunching:. - (void)awakeFromNib { - // Set up the command updater for when there are no windows open - [self initMenuState]; -} - -// This is called after profiles have been loaded and preferences registered. -// It is safe to access the default profile here. -- (void)applicationDidFinishLaunching:(NSNotification*)notify { - // Hold an extra ref to the BrowserProcess singleton so it doesn't go away - // when all the browser windows get closed. We'll release it on quit which - // will be the signal to exit. - DCHECK(g_browser_process); - g_browser_process->AddRefModule(); + pendingURLs_.reset(new std::vector<GURL>()); + // We need to register the handlers early to catch events fired on launch. NSAppleEventManager* em = [NSAppleEventManager sharedAppleEventManager]; [em setEventHandler:self andSelector:@selector(getUrl:withReply:) @@ -62,6 +54,19 @@ forEventClass:kCoreEventClass andEventID:kAEOpenDocuments]; + // Set up the command updater for when there are no windows open + [self initMenuState]; +} + +// This is called after profiles have been loaded and preferences registered. +// It is safe to access the default profile here. +- (void)applicationDidFinishLaunching:(NSNotification*)notify { + // Hold an extra ref to the BrowserProcess singleton so it doesn't go away + // when all the browser windows get closed. We'll release it on quit which + // will be the signal to exit. + DCHECK(g_browser_process); + g_browser_process->AddRefModule(); + bookmarkMenuBridge_.reset(new BookmarkMenuBridge()); // Register any Mac-specific preferences. @@ -74,6 +79,8 @@ // call this from awakeFromNib. EncodingMenuControllerDelegate::BuildEncodingMenu([self defaultProfile]); + // Now that we're initialized we can open any URLs we've been holding onto. + [self openPendingURLs]; } - (void)dealloc { @@ -197,15 +204,28 @@ // the ProcessSingleton, and it calls BrowserInit. It's best to bottleneck the // openings through that for uniform handling. -namespace { +- (void)openURLs:(const std::vector<GURL>&)urls { + if (pendingURLs_.get()) { + // too early to open; save for later + pendingURLs_->insert(pendingURLs_->end(), urls.begin(), urls.end()); + return; + } -void OpenURLs(const std::vector<GURL>& urls) { CommandLine dummy((std::wstring())); BrowserInit::LaunchWithProfile launch(std::wstring(), dummy); launch.OpenURLsInBrowser(BrowserList::GetLastActive(), false, urls); } -} // namespace +- (void)openPendingURLs { + // Since the existence of pendingURLs_ is a flag that it's too early to + // open URLs, we need to reset pendingURLs_. + std::vector<GURL> urls; + swap(urls, *pendingURLs_); + pendingURLs_.reset(); + + if (urls.size()) + [self openURLs:urls]; +} - (void)getUrl:(NSAppleEventDescriptor*)event withReply:(NSAppleEventDescriptor*)reply { @@ -216,7 +236,7 @@ void OpenURLs(const std::vector<GURL>& urls) { std::vector<GURL> gurlVector; gurlVector.push_back(gurl); - OpenURLs(gurlVector); + [self openURLs:gurlVector]; } - (void)openFiles:(NSAppleEventDescriptor*)event @@ -249,7 +269,7 @@ void OpenURLs(const std::vector<GURL>& urls) { gurlVector.push_back(gurl); } - OpenURLs(gurlVector); + [self openURLs:gurlVector]; } // Called when the preferences window is closed. We use this to release the |