From be66d254eebe76c1ff1caab3d63a63f311f93d6b Mon Sep 17 00:00:00 2001 From: Stephen A Pohl Date: Tue, 23 May 2017 00:23:47 -0400 Subject: [PATCH] Bug 1330470: Restore ability to drag & drop entries from the download list to Finder on OSX. r=mstange --- widget/cocoa/nsChildView.mm | 19 ++++++++++++------- widget/cocoa/nsClipboard.mm | 24 +++++++++++++++--------- widget/cocoa/nsDragService.h | 5 +++-- widget/cocoa/nsDragService.mm | 15 +++++++++------ 4 files changed, 39 insertions(+), 24 deletions(-) diff --git a/widget/cocoa/nsChildView.mm b/widget/cocoa/nsChildView.mm index 1604a336b00c2..4ca9ce32cf99b 100644 --- a/widget/cocoa/nsChildView.mm +++ b/widget/cocoa/nsChildView.mm @@ -3269,10 +3269,11 @@ + (void)registerViewForDraggedTypes:(NSView*)aView [aView registerForDraggedTypes: [NSArray arrayWithObjects: [UTIHelper stringFromPboardType:NSFilenamesPboardType], + [UTIHelper stringFromPboardType:kMozFileUrlsPboardType], [UTIHelper stringFromPboardType:NSPasteboardTypeString], [UTIHelper stringFromPboardType:NSPasteboardTypeHTML], [UTIHelper stringFromPboardType:(NSString*)kPasteboardTypeFileURLPromise], - [UTIHelper stringFromPboardType:kWildcardPboardType], + [UTIHelper stringFromPboardType:kMozWildcardPboardType], [UTIHelper stringFromPboardType:kPublicUrlPboardType], [UTIHelper stringFromPboardType:kPublicUrlNamePboardType], [UTIHelper stringFromPboardType:kUrlsWithTitlesPboardType], @@ -6100,7 +6101,7 @@ - (void)pasteboard:(NSPasteboard*)aPasteboard unsigned int typeCount = [pasteboardOutputDict count]; NSMutableArray* types = [NSMutableArray arrayWithCapacity:typeCount + 1]; [types addObjectsFromArray:[pasteboardOutputDict allKeys]]; - [types addObject:[UTIHelper stringFromPboardType:kWildcardPboardType]]; + [types addObject:[UTIHelper stringFromPboardType:kMozWildcardPboardType]]; for (unsigned int k = 0; k < typeCount; k++) { NSString* curType = [types objectAtIndex:k]; if ([curType isEqualToString: @@ -6108,7 +6109,9 @@ - (void)pasteboard:(NSPasteboard*)aPasteboard [curType isEqualToString: [UTIHelper stringFromPboardType:kPublicUrlPboardType]] || [curType isEqualToString: - [UTIHelper stringFromPboardType:kPublicUrlNamePboardType]]) { + [UTIHelper stringFromPboardType:kPublicUrlNamePboardType]] || + [curType isEqualToString: + [UTIHelper stringFromPboardType:(NSString*)kUTTypeFileURL]]) { [aPasteboard setString:[pasteboardOutputDict valueForKey:curType] forType:curType]; } else if ([curType isEqualToString: @@ -6125,14 +6128,16 @@ - (void)pasteboard:(NSPasteboard*)aPasteboard } else if ([curType isEqualToString: [UTIHelper stringFromPboardType:NSPasteboardTypeTIFF]] || [curType isEqualToString: - [UTIHelper stringFromPboardType:kCustomTypesPboardType]]) { + [UTIHelper stringFromPboardType:kMozCustomTypesPboardType]]) { [aPasteboard setData:[pasteboardOutputDict valueForKey:curType] forType:curType]; + } else if ([curType isEqualToString: + [UTIHelper stringFromPboardType:kMozFileUrlsPboardType]]) { + [aPasteboard writeObjects:[pasteboardOutputDict valueForKey:curType]]; } else if ([curType isEqualToString: [UTIHelper stringFromPboardType: - (NSString*)kPasteboardTypeFileURLPromise]] || - [curType isEqualToString: - [UTIHelper stringFromPboardType:NSFilenamesPboardType]]) { + (NSString*)kPasteboardTypeFileURLPromise]]) { + nsCOMPtr targFile; NS_NewLocalFile(EmptyString(), true, getter_AddRefs(targFile)); diff --git a/widget/cocoa/nsClipboard.mm b/widget/cocoa/nsClipboard.mm index d12e4dd74597f..b9029327dfdd2 100644 --- a/widget/cocoa/nsClipboard.mm +++ b/widget/cocoa/nsClipboard.mm @@ -39,12 +39,14 @@ @implementation UTIHelper + (NSString*)stringFromPboardType:(NSString*)aType { - if ([aType isEqualToString:kWildcardPboardType] || - [aType isEqualToString:kCustomTypesPboardType] || + if ([aType isEqualToString:kMozWildcardPboardType] || + [aType isEqualToString:kMozCustomTypesPboardType] || [aType isEqualToString:kPublicUrlPboardType] || [aType isEqualToString:kPublicUrlNamePboardType] || + [aType isEqualToString:kMozFileUrlsPboardType] || [aType isEqualToString:(NSString*)kPasteboardTypeFileURLPromise] || [aType isEqualToString:(NSString*)kPasteboardTypeFilePromiseContent] || + [aType isEqualToString:(NSString*)kUTTypeFileURL] || [aType isEqualToString:NSPasteboardTypeString] || [aType isEqualToString:NSPasteboardTypeHTML] || [aType isEqualToString:NSPasteboardTypeRTF] || @@ -164,6 +166,9 @@ + (NSString*)stringFromPboardType:(NSString*)aType [UTIHelper stringFromPboardType:NSPasteboardTypeHTML]]) { [cocoaPasteboard setString:(nsClipboard::WrapHtmlForSystemPasteboard(currentValue)) forType:currentKey]; + } else if ([currentKey isEqualToString: + [UTIHelper stringFromPboardType:kMozFileUrlsPboardType]]) { + [cocoaPasteboard writeObjects:currentValue]; } else { [cocoaPasteboard setData:currentValue forType:currentKey]; } @@ -250,7 +255,7 @@ + (NSString*)stringFromPboardType:(NSString*)aType NSString* type = [cocoaPasteboard availableTypeFromArray: [NSArray arrayWithObject: - [UTIHelper stringFromPboardType:kCustomTypesPboardType]]]; + [UTIHelper stringFromPboardType:kMozCustomTypesPboardType]]]; if (!type) { continue; } @@ -467,7 +472,7 @@ + (NSString*)stringFromPboardType:(NSString*)aType NSString* availableType = [generalPBoard availableTypeFromArray: [NSArray arrayWithObject: - [UTIHelper stringFromPboardType:kCustomTypesPboardType]]]; + [UTIHelper stringFromPboardType:kMozCustomTypesPboardType]]]; if (availableType) { *outResult = true; break; @@ -565,7 +570,7 @@ + (NSString*)stringFromPboardType:(NSString*)aType if (data) { NSData* nativeData = [NSData dataWithBytes:data length:dataSize]; NSString* customType = - [UTIHelper stringFromPboardType:kCustomTypesPboardType]; + [UTIHelper stringFromPboardType:kMozCustomTypesPboardType]; [pasteboardOutputDict setObject:nativeData forKey:customType]; free(data); } @@ -656,10 +661,11 @@ + (NSString*)stringFromPboardType:(NSString*)aType } NSString* str = nsCocoaUtils::ToNSString(fileURI); - NSArray* fileList = [NSArray arrayWithObjects:str, nil]; - NSString* filenamesType = - [UTIHelper stringFromPboardType:NSFilenamesPboardType]; - [pasteboardOutputDict setObject:fileList forKey:filenamesType]; + NSURL* url = [NSURL fileURLWithPath:str isDirectory:NO]; + NSString* fileUTType = + [UTIHelper stringFromPboardType:(NSString*)kUTTypeFileURL]; + [pasteboardOutputDict setObject:[url absoluteString] + forKey:fileUTType]; } else if (flavorStr.EqualsLiteral(kFilePromiseMime)) { NSString* urlPromise = diff --git a/widget/cocoa/nsDragService.h b/widget/cocoa/nsDragService.h index 0f0317910a9d7..64be581364911 100644 --- a/widget/cocoa/nsDragService.h +++ b/widget/cocoa/nsDragService.h @@ -11,11 +11,12 @@ #include -extern NSString* const kWildcardPboardType; extern NSString* const kPublicUrlPboardType; extern NSString* const kPublicUrlNamePboardType; extern NSString* const kUrlsWithTitlesPboardType; -extern NSString* const kCustomTypesPboardType; +extern NSString* const kMozWildcardPboardType; +extern NSString* const kMozCustomTypesPboardType; +extern NSString* const kMozFileUrlsPboardType; class nsDragService : public nsBaseDragService { diff --git a/widget/cocoa/nsDragService.mm b/widget/cocoa/nsDragService.mm index 3086b83e185f6..51030c69a2025 100644 --- a/widget/cocoa/nsDragService.mm +++ b/widget/cocoa/nsDragService.mm @@ -47,11 +47,12 @@ // file destination callback. nsIArray *gDraggedTransferables = nullptr; -NSString* const kWildcardPboardType = @"org.mozilla.MozillaWildcard"; NSString* const kPublicUrlPboardType = @"public.url"; NSString* const kPublicUrlNamePboardType = @"public.url-name"; NSString* const kUrlsWithTitlesPboardType = @"WebURLsWithTitlesPboardType"; -NSString* const kCustomTypesPboardType = @"org.mozilla.custom-clipdata"; +NSString* const kMozWildcardPboardType = @"org.mozilla.MozillaWildcard"; +NSString* const kMozCustomTypesPboardType = @"org.mozilla.custom-clipdata"; +NSString* const kMozFileUrlsPboardType = @"org.mozilla.file-urls"; nsDragService::nsDragService() : mNativeDragView(nil), mNativeDragEvent(nil), mDragImageChanged(false) @@ -337,7 +338,7 @@ // Gecko is initiating this drag so we always want its own views to // consider it. Add our wildcard type to the pasteboard to accomplish // this. - [types addObject:[UTIHelper stringFromPboardType:kWildcardPboardType]]; + [types addObject:[UTIHelper stringFromPboardType:kMozWildcardPboardType]]; } } [pbItem setDataProvider:mNativeDragView forTypes:types]; @@ -459,7 +460,9 @@ break; } else if (flavorStr.EqualsLiteral(kCustomTypesMime)) { - NSString* availableType = [item availableTypeFromArray:[NSArray arrayWithObject:kCustomTypesPboardType]]; + NSString* availableType = + [item availableTypeFromArray: + [NSArray arrayWithObject:kMozCustomTypesPboardType]]; if (!availableType || !IsValidType(availableType, false)) { continue; } @@ -609,7 +612,7 @@ const NSString* type = nil; bool allowFileURL = false; if (dataFlavor.EqualsLiteral(kFileMime)) { - type = [UTIHelper stringFromPboardType:NSFilenamesPboardType]; + type = [UTIHelper stringFromPboardType:kMozFileUrlsPboardType]; allowFileURL = true; } else if (dataFlavor.EqualsLiteral(kUnicodeMime)) { type = [UTIHelper stringFromPboardType:NSPasteboardTypeString]; @@ -623,7 +626,7 @@ } else if (dataFlavor.EqualsLiteral(kRTFMime)) { type = [UTIHelper stringFromPboardType:NSPasteboardTypeRTF]; } else if (dataFlavor.EqualsLiteral(kCustomTypesMime)) { - type = [UTIHelper stringFromPboardType:kCustomTypesPboardType]; + type = [UTIHelper stringFromPboardType:kMozCustomTypesPboardType]; } NSString* availableType =