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

Unified Diff: chrome/browser/app_controller_mac.mm

Issue 100142: Switch to a raw kAEOpenDocuments AppleEvent handler for opening dropped files... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/app_controller_mac.mm
===================================================================
--- chrome/browser/app_controller_mac.mm (revision 14737)
+++ chrome/browser/app_controller_mac.mm (working copy)
@@ -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 @@
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);
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698