Changeset 218508 in webkit
- Timestamp:
- Jun 19, 2017 2:12:28 PM (7 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r218507 r218508 1 2017-06-19 Wenson Hsieh <wenson_hsieh@apple.com> 2 3 [iOS DnD] Support .zip archives for file uploads via drag and drop 4 https://bugs.webkit.org/show_bug.cgi?id=173511 5 <rdar://problem/32521025> 6 7 Reviewed by Tim Horton. 8 9 Allows dropped .zip archives to be uploaded as files by accepting types conforming to either 10 "public.zip-archive" or "public.content" as potential file types. Initially, I opted to accept the more general 11 "public.data" type; however, this includes UTIs such as "public.url" that should not be represented as files, so 12 this is a more targeted fix that allows us to very easily add additional content types in the future by adding 13 more types to supportedFileUploadPasteboardTypes. 14 15 Tests: 16 DataInteractionTests.ExternalSourceZIPArchiveToUploadArea 17 DataInteractionTests.ExternalSourceZIPArchiveAndURLToSingleFileInput 18 19 * page/mac/DragControllerMac.mm: 20 (WebCore::DragController::updateSupportedTypeIdentifiersForDragHandlingMethod): 21 * platform/Pasteboard.h: 22 * platform/ios/PasteboardIOS.mm: 23 (WebCore::Pasteboard::read): 24 (WebCore::Pasteboard::supportedWebContentPasteboardTypes): 25 (WebCore::Pasteboard::supportedFileUploadPasteboardTypes): 26 27 Rename supportedPasteboardTypes to supportedWebContentPasteboardTypes, and also introduce 28 supportedFileUploadPasteboardTypes which returns an list of types, such that if a type conforms to any type in 29 this array, that type may be represented as a file. So far, this list contains "public.content" and 30 "public.zip-archive". 31 32 (WebCore::Pasteboard::types): 33 (WebCore::Pasteboard::supportedPasteboardTypes): Deleted. 34 * platform/ios/WebItemProviderPasteboard.mm: 35 (typeConformsToTypes): 36 37 Remove -typeIsAppropriateForSupportedTypes: and replace it with typeConformsToTypes. Use this both when 38 determining the number of files on the pasteboard, and when determining preferred UTIs to load when dropping. 39 40 (-[WebItemProviderPasteboard numberOfFiles]): 41 (-[WebItemProviderPasteboard typeIdentifierToLoadForRegisteredTypeIdentfiers:]): 42 (-[WebItemProviderPasteboard typeIsAppropriateForSupportedTypes:]): Deleted. 43 * platform/mac/DragDataMac.mm: 44 (WebCore::DragData::containsFiles): 45 * platform/mac/PasteboardMac.mm: 46 (WebCore::Pasteboard::supportedFileUploadPasteboardTypes): 47 1 48 2017-06-19 Sam Weinig <sam@webkit.org> 2 49 -
trunk/Source/WebCore/page/mac/DragControllerMac.mm
r218343 r218508 119 119 break; 120 120 case DragHandlingMethod::EditRichText: 121 for (NSString *type in Pasteboard::supported PasteboardTypes())121 for (NSString *type in Pasteboard::supportedWebContentPasteboardTypes()) 122 122 supportedTypes.append(type); 123 123 break; 124 124 default: 125 supportedTypes.append(kUTTypeContent); 125 for (NSString *type in Pasteboard::supportedFileUploadPasteboardTypes()) 126 supportedTypes.append(type); 126 127 break; 127 128 } -
trunk/Source/WebCore/platform/Pasteboard.h
r218128 r218508 33 33 34 34 #if PLATFORM(IOS) 35 OBJC_CLASS NSString; 36 #endif 37 38 #if PLATFORM(COCOA) 35 39 OBJC_CLASS NSArray; 36 OBJC_CLASS NSString;37 40 #endif 38 41 … … 207 210 explicit Pasteboard(long changeCount); 208 211 209 static NSArray * supportedPasteboardTypes();212 static NSArray *supportedWebContentPasteboardTypes(); 210 213 static String resourceMIMEType(const NSString *mimeType); 211 214 #endif … … 214 217 explicit Pasteboard(const String& pasteboardName); 215 218 219 WEBCORE_EXPORT static NSArray *supportedFileUploadPasteboardTypes(); 216 220 const String& name() const { return m_pasteboardName; } 217 221 #endif -
trunk/Source/WebCore/platform/ios/PasteboardIOS.mm
r218433 r218508 264 264 return; 265 265 266 NSArray *types = supported PasteboardTypes();266 NSArray *types = supportedWebContentPasteboardTypes(); 267 267 int numberOfTypes = [types count]; 268 268 … … 299 299 } 300 300 301 NSArray * Pasteboard::supportedPasteboardTypes()301 NSArray *Pasteboard::supportedWebContentPasteboardTypes() 302 302 { 303 303 return @[(id)WebArchivePboardType, (id)kUTTypeFlatRTFD, (id)kUTTypeRTF, (id)kUTTypeHTML, (id)kUTTypePNG, (id)kUTTypeTIFF, (id)kUTTypeJPEG, (id)kUTTypeGIF, (id)kUTTypeURL, (id)kUTTypeText]; 304 } 305 306 NSArray *Pasteboard::supportedFileUploadPasteboardTypes() 307 { 308 return @[ (NSString *)kUTTypeContent, (NSString *)kUTTypeZipArchive ]; 304 309 } 305 310 … … 425 430 Vector<String> Pasteboard::types() 426 431 { 427 NSArray * types = supportedPasteboardTypes();432 NSArray *types = supportedWebContentPasteboardTypes(); 428 433 429 434 // Enforce changeCount ourselves for security. We check after reading instead of before to be -
trunk/Source/WebCore/platform/ios/WebItemProviderPasteboard.mm
r218343 r218508 40 40 #import <UIKit/UIItemProviderWriting.h> 41 41 #import <WebCore/FileSystemIOS.h> 42 #import <WebCore/Pasteboard.h> 42 43 #import <wtf/BlockPtr.h> 43 44 #import <wtf/OSObjectPtr.h> … … 48 49 SOFT_LINK_CLASS(UIKit, UIImage) 49 50 SOFT_LINK_CLASS(UIKit, UIItemProvider) 51 52 using namespace WebCore; 50 53 51 54 typedef void(^ItemProviderDataLoadCompletionHandler)(NSData *, NSError *); … … 374 377 } 375 378 379 static BOOL typeConformsToTypes(NSString *type, NSArray *conformsToTypes) 380 { 381 // A type is considered appropriate to load if it conforms to one or more supported types. 382 for (NSString *conformsToType in conformsToTypes) { 383 if (UTTypeConformsTo((CFStringRef)type, (CFStringRef)conformsToType)) 384 return YES; 385 } 386 return NO; 387 } 388 376 389 - (NSInteger)numberOfFiles 377 390 { 391 NSArray *supportedFileTypes = Pasteboard::supportedFileUploadPasteboardTypes(); 378 392 NSInteger numberOfFiles = 0; 379 393 for (UIItemProvider *itemProvider in _itemProviders.get()) { 380 394 for (NSString *identifier in itemProvider.registeredTypeIdentifiers) { 381 if (! UTTypeConformsTo((__bridge CFStringRef)identifier, kUTTypeContent))395 if (!typeConformsToTypes(identifier, supportedFileTypes)) 382 396 continue; 383 397 ++numberOfFiles; … … 406 420 } 407 421 408 - (BOOL)typeIsAppropriateForSupportedTypes:(NSString *)type409 {410 // A type is considered appropriate to load if it conforms to one or more supported types.411 for (NSString *supportedTypeIdentifier in _supportedTypeIdentifiers.get()) {412 if (UTTypeConformsTo((CFStringRef)type, (CFStringRef)supportedTypeIdentifier))413 return YES;414 }415 return NO;416 }417 418 422 - (NSString *)typeIdentifierToLoadForRegisteredTypeIdentfiers:(NSArray<NSString *> *)registeredTypeIdentifiers 419 423 { 420 424 NSString *highestFidelityContentType = nil; 421 425 for (NSString *registeredTypeIdentifier in registeredTypeIdentifiers) { 422 if ( [self typeIsAppropriateForSupportedTypes:registeredTypeIdentifier])426 if (typeConformsToTypes(registeredTypeIdentifier, _supportedTypeIdentifiers.get())) 423 427 return registeredTypeIdentifier; 424 428 -
trunk/Source/WebCore/platform/mac/DragDataMac.mm
r218433 r218508 161 161 bool DragData::containsFiles() const 162 162 { 163 NSArray *supportedFileTypes = Pasteboard::supportedFileUploadPasteboardTypes(); 163 164 Vector<String> types; 164 165 platformStrategies()->pasteboardStrategy()->getTypes(types, m_pasteboardName); 165 166 for (auto& type : types) { 166 #if PLATFORM(MAC) 167 if (type == String(NSFilesPromisePboardType) || type == String(NSFilenamesPboardType)) 168 return true; 169 #else 170 if (UTTypeConformsTo(type.createCFString().autorelease(), kUTTypeContent)) 171 return true; 172 #endif 167 auto cfType = type.createCFString(); 168 for (NSString *fileType in supportedFileTypes) { 169 if (UTTypeConformsTo(cfType.get(), (CFStringRef)fileType)) 170 return true; 171 } 173 172 } 174 173 return false; -
trunk/Source/WebCore/platform/mac/PasteboardMac.mm
r217893 r218508 105 105 } 106 106 107 NSArray *Pasteboard::supportedFileUploadPasteboardTypes() 108 { 109 return @[ (NSString *)NSFilesPromisePboardType, (NSString *)NSFilenamesPboardType ]; 110 } 111 107 112 Pasteboard::Pasteboard() 108 113 : m_pasteboardName(emptyString()) -
trunk/Tools/ChangeLog
r218496 r218508 1 2017-06-19 Wenson Hsieh <wenson_hsieh@apple.com> 2 3 [iOS DnD] Support .zip archives for file uploads via drag and drop 4 https://bugs.webkit.org/show_bug.cgi?id=173511 5 <rdar://problem/32521025> 6 7 Reviewed by Tim Horton. 8 9 Adds tests for dropping .zip archives into a JavaScript-based file upload area, as well as into a file input. 10 Also verifies that URLs are not handled as file drops. See WebCore ChangeLog for more details. 11 12 * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: 13 * TestWebKitAPI/Tests/WebKit2Cocoa/compressed-files.zip: Added. 14 * TestWebKitAPI/Tests/ios/DataInteractionTests.mm: 15 (testZIPArchive): 16 (TestWebKitAPI::TEST): 17 1 18 2017-06-18 Darin Adler <darin@apple.com> 2 19 -
trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
r218496 r218508 647 647 F47728991E4AE3C1007ABF6A /* full-page-contenteditable.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F47728981E4AE3AD007ABF6A /* full-page-contenteditable.html */; }; 648 648 F4856CA31E649EA8009D7EE7 /* attachment-element.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F4856CA21E6498A8009D7EE7 /* attachment-element.html */; }; 649 F4B825D81EF4DBFB006E417F /* compressed-files.zip in Copy Resources */ = {isa = PBXBuildFile; fileRef = F4B825D61EF4DBD4006E417F /* compressed-files.zip */; }; 649 650 F4BFA68E1E4AD08000154298 /* DragAndDropPasteboardTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = F4BFA68C1E4AD08000154298 /* DragAndDropPasteboardTests.mm */; }; 650 651 F4C2AB221DD6D95E00E06D5B /* enormous-video-with-sound.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F4C2AB211DD6D94100E06D5B /* enormous-video-with-sound.html */; }; … … 727 728 dstSubfolderSpec = 7; 728 729 files = ( 730 F4B825D81EF4DBFB006E417F /* compressed-files.zip in Copy Resources */, 729 731 F41AB99F1EF4696B0083FA08 /* autofocus-contenteditable.html in Copy Resources */, 730 732 F41AB9A01EF4696B0083FA08 /* background-image-link-and-input.html in Copy Resources */, … … 1612 1614 F47D30ED1ED28A6C000482E1 /* gif-and-file-input.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = "gif-and-file-input.html"; sourceTree = "<group>"; }; 1613 1615 F4856CA21E6498A8009D7EE7 /* attachment-element.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "attachment-element.html"; sourceTree = "<group>"; }; 1616 F4B825D61EF4DBD4006E417F /* compressed-files.zip */ = {isa = PBXFileReference; lastKnownFileType = archive.zip; path = "compressed-files.zip"; sourceTree = "<group>"; }; 1614 1617 F4BFA68C1E4AD08000154298 /* DragAndDropPasteboardTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DragAndDropPasteboardTests.mm; sourceTree = "<group>"; }; 1615 1618 F4C2AB211DD6D94100E06D5B /* enormous-video-with-sound.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "enormous-video-with-sound.html"; sourceTree = "<group>"; }; … … 2003 2006 isa = PBXGroup; 2004 2007 children = ( 2008 F4B825D61EF4DBD4006E417F /* compressed-files.zip */, 2005 2009 F41AB9981EF4692C0083FA08 /* autofocus-contenteditable.html */, 2006 2010 F41AB9971EF4692C0083FA08 /* background-image-link-and-input.html */, -
trunk/Tools/TestWebKitAPI/Tests/ios/DataInteractionTests.mm
r218343 r218508 53 53 } 54 54 55 static NSData *testZIPArchive() 56 { 57 NSURL *zipFileURL = [[NSBundle mainBundle] URLForResource:@"compressed-files" withExtension:@"zip" subdirectory:@"TestWebKitAPI.resources"]; 58 return [NSData dataWithContentsOfURL:zipFileURL]; 59 } 60 55 61 @implementation UIItemProvider (DataInteractionTests) 56 62 … … 454 460 NSString *outputValue = [webView stringByEvaluatingJavaScript:@"output.value"]; 455 461 EXPECT_WK_STREQ("text/html", outputValue.UTF8String); 462 } 463 464 TEST(DataInteractionTests, ExternalSourceZIPArchiveAndURLToSingleFileInput) 465 { 466 auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]); 467 [webView synchronouslyLoadTestPageNamed:@"file-uploading"]; 468 469 auto archiveProvider = adoptNS([[UIItemProvider alloc] init]); 470 [archiveProvider registerDataRepresentationForTypeIdentifier:(NSString *)kUTTypeZipArchive withData:testZIPArchive()]; 471 472 auto urlProvider = adoptNS([[UIItemProvider alloc] init]); 473 [urlProvider registerObject:[NSURL URLWithString:@"https://webkit.org"] visibility:UIItemProviderRepresentationOptionsVisibilityAll]; 474 475 auto dataInteractionSimulator = adoptNS([[DataInteractionSimulator alloc] initWithWebView:webView.get()]); 476 [dataInteractionSimulator setExternalItemProviders:@[ archiveProvider.get(), urlProvider.get() ]]; 477 [dataInteractionSimulator runFrom:CGPointMake(200, 100) to:CGPointMake(100, 100)]; 478 479 NSString *outputValue = [webView stringByEvaluatingJavaScript:@"output.value"]; 480 EXPECT_WK_STREQ("application/zip", outputValue.UTF8String); 481 } 482 483 TEST(DataInteractionTests, ExternalSourceZIPArchiveToUploadArea) 484 { 485 auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]); 486 [webView synchronouslyLoadTestPageNamed:@"file-uploading"]; 487 488 auto itemProvider = adoptNS([[UIItemProvider alloc] init]); 489 [itemProvider registerDataRepresentationForTypeIdentifier:(NSString *)kUTTypeZipArchive withData:testZIPArchive()]; 490 491 auto dataInteractionSimulator = adoptNS([[DataInteractionSimulator alloc] initWithWebView:webView.get()]); 492 [dataInteractionSimulator setExternalItemProviders:@[ itemProvider.get() ]]; 493 [dataInteractionSimulator runFrom:CGPointMake(200, 300) to:CGPointMake(100, 300)]; 494 495 NSString *outputValue = [webView stringByEvaluatingJavaScript:@"output.value"]; 496 EXPECT_WK_STREQ("application/zip", outputValue.UTF8String); 456 497 } 457 498
Note: See TracChangeset
for help on using the changeset viewer.