summaryrefslogtreecommitdiffstats
path: root/chrome/browser/app_controller_mac.mm
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/app_controller_mac.mm')
-rw-r--r--chrome/browser/app_controller_mac.mm76
1 files changed, 25 insertions, 51 deletions
diff --git a/chrome/browser/app_controller_mac.mm b/chrome/browser/app_controller_mac.mm
index 08d61b8..f465b17 100644
--- a/chrome/browser/app_controller_mac.mm
+++ b/chrome/browser/app_controller_mac.mm
@@ -45,6 +45,7 @@
#include "chrome/common/temp_scaffolding_stubs.h"
#include "grit/chromium_strings.h"
#include "grit/generated_resources.h"
+#include "net/base/net_util.h"
// 10.6 adds a public API for the Spotlight-backed search menu item in the Help
// menu. Provide the declaration so it can be called below when building with
@@ -80,12 +81,12 @@ static bool g_is_opening_new_window = false;
@implementation AppController
+@synthesize startupComplete = startupComplete_;
+
// This method is called very early in application startup (ie, before
// the profile is loaded or any preferences have been registered). Defer any
// user-data initialization until -applicationDidFinishLaunching:.
- (void)awakeFromNib {
- 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
@@ -96,10 +97,6 @@ static bool g_is_opening_new_window = false;
andSelector:@selector(getUrl:withReply:)
forEventClass:'WWW!' // A particularly ancient AppleEvent that dates
andEventID:'OURL']; // back to the Spyglass days.
- [em setEventHandler:self
- andSelector:@selector(openFiles:withReply:)
- forEventClass:kCoreEventClass
- andEventID:kAEOpenDocuments];
// Register for various window layering changes. We use these to update
// various UI elements (command-key equivalents, etc) when the frontmost
@@ -353,12 +350,10 @@ static bool g_is_opening_new_window = false;
// Since Chrome is localized to more languages than the OS, tell Cocoa which
// menu is the Help so it can add the search item to it.
- if (helpMenu_ && [NSApp respondsToSelector:@selector(setHelpMenu:)]) {
+ if (helpMenu_ && [NSApp respondsToSelector:@selector(setHelpMenu:)])
[NSApp setHelpMenu:helpMenu_];
- }
- // Now that we're initialized we can open any URLs we've been holding onto.
- [self openPendingURLs];
+ startupComplete_ = YES;
}
// This is called after profiles have been loaded and preferences registered.
@@ -659,9 +654,9 @@ static bool g_is_opening_new_window = false;
// openings through that for uniform handling.
- (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());
+ // If the browser hasn't started yet, just queue up the URLs.
+ if (!startupComplete_) {
+ startupURLs_.insert(startupURLs_.end(), urls.begin(), urls.end());
return;
}
@@ -677,17 +672,6 @@ static bool g_is_opening_new_window = false;
launch.OpenURLsInBrowser(browser, false, urls);
}
-- (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 {
NSString* urlStr = [[event paramDescriptorForKeyword:keyDirectObject]
@@ -700,37 +684,19 @@ static bool g_is_opening_new_window = false;
[self openURLs:gurlVector];
}
-- (void)openFiles:(NSAppleEventDescriptor*)event
- withReply:(NSAppleEventDescriptor*)reply {
- // Ordinarily we'd use the NSApplication delegate method
- // -application:openFiles:, but Cocoa tries to be smart and it sends files
- // specified on the command line into that delegate method. That's too smart
- // for us (our setup isn't done by the time Cocoa triggers the delegate method
- // and we crash). Since all we want are files dropped on the app icon, and we
- // have cross-platform code to handle the command-line files anyway, an Apple
- // Event handler fits the bill just right.
- NSAppleEventDescriptor* fileList =
- [event paramDescriptorForKeyword:keyDirectObject];
- if (!fileList)
- return;
+- (void)application:(NSApplication*)sender
+ openFiles:(NSArray*)filenames {
std::vector<GURL> gurlVector;
-
- for (NSInteger i = 1; i <= [fileList numberOfItems]; ++i) {
- NSAppleEventDescriptor* fileAliasDesc = [fileList descriptorAtIndex:i];
- if (!fileAliasDesc)
- continue;
- NSAppleEventDescriptor* fileURLDesc =
- [fileAliasDesc coerceToDescriptorType:typeFileURL];
- if (!fileURLDesc)
- continue;
- NSData* fileURLData = [fileURLDesc data];
- if (!fileURLData)
- continue;
- GURL gurl(std::string((char*)[fileURLData bytes], [fileURLData length]));
+ for (NSString* file in filenames) {
+ GURL gurl = net::FilePathToFileURL(FilePath(base::SysNSStringToUTF8(file)));
gurlVector.push_back(gurl);
}
+ if (!gurlVector.empty())
+ [self openURLs:gurlVector];
+ else
+ NOTREACHED() << "Nothing to open!";
- [self openURLs:gurlVector];
+ [sender replyToOpenOrPrint:NSApplicationDelegateReplySuccess];
}
// Called when the preferences window is closed. We use this to release the
@@ -834,6 +800,14 @@ static bool g_is_opening_new_window = false;
return dockMenu;
}
+- (const std::vector<GURL>&)startupURLs {
+ return startupURLs_;
+}
+
+- (void)clearStartupURLs {
+ startupURLs_.clear();
+}
+
@end
//---------------------------------------------------------------------------