diff options
author | avi@google.com <avi@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-29 20:26:20 +0000 |
---|---|---|
committer | avi@google.com <avi@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-29 20:26:20 +0000 |
commit | 36fe18f709825bc199f5eca66463a832e09638c5 (patch) | |
tree | 44ca8abec617033ba8741ef35f9cfc6f6a1bf3f8 /chrome | |
parent | 99fa8776b421e4c7ff24ef840907d0e1bea61f9b (diff) | |
download | chromium_src-36fe18f709825bc199f5eca66463a832e09638c5.zip chromium_src-36fe18f709825bc199f5eca66463a832e09638c5.tar.gz chromium_src-36fe18f709825bc199f5eca66463a832e09638c5.tar.bz2 |
Switch to a raw kAEOpenDocuments AppleEvent handler for opening dropped files to avoid crashes when Cocoa feeds us files specified on the command line.
Review URL: http://codereview.chromium.org/100142
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@14876 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/app_controller_mac.mm | 38 |
1 files changed, 33 insertions, 5 deletions
diff --git a/chrome/browser/app_controller_mac.mm b/chrome/browser/app_controller_mac.mm index d8a2738..5b804ba 100644 --- a/chrome/browser/app_controller_mac.mm +++ b/chrome/browser/app_controller_mac.mm @@ -21,6 +21,8 @@ - (void)initMenuState; - (void)getUrl:(NSAppleEventDescriptor*)event withReply:(NSAppleEventDescriptor*)reply; +- (void)openFiles:(NSAppleEventDescriptor*)event + withReply:(NSAppleEventDescriptor*)reply; @end @implementation AppController @@ -47,6 +49,10 @@ 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]; } - (void)dealloc { @@ -72,6 +78,8 @@ andEventID:kAEGetURL]; [em removeEventHandlerForEventClass:'WWW!' andEventID:'OURL']; + [em removeEventHandlerForEventClass:kCoreEventClass + andEventID:kAEOpenDocuments]; // TODO(pinkerton): Not sure where this should live, including it here // causes all sorts of asserts from the open renderers. On Windows, it @@ -190,13 +198,33 @@ void OpenURLs(const std::vector<GURL>& urls) { OpenURLs(gurlVector); } -- (void)application:(NSApplication*)sender - openFiles:(NSArray*)filenames { +- (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; std::vector<GURL> gurlVector; - for (NSString* filename in filenames) { - NSURL* fileURL = [NSURL fileURLWithPath:filename]; - GURL gurl(base::SysNSStringToUTF8([fileURL absoluteString])); + 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])); gurlVector.push_back(gurl); } |