Changeset 239086 in webkit
- Timestamp:
- Dec 11, 2018 1:13:32 PM (5 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r239081 r239086 1 2018-12-11 Wenson Hsieh <wenson_hsieh@apple.com> 2 3 [iOS] Send the full list of file upload URLs and types in PasteboardItemInfo 4 https://bugs.webkit.org/show_bug.cgi?id=192598 5 Work towards <rdar://problem/35626913> 6 7 Reviewed by Tim Horton. 8 9 Refactors PasteboardItemInfo to contain lists of file URLs and corresponding pasteboard types, instead of just 10 a "preferred" file upload URL and type. See below for more details. 11 12 * platform/PasteboardItemInfo.h: 13 (WebCore::PasteboardItemInfo::pathForContentType const): 14 15 Add a helper method to find a file upload URL corresponding to a given type. 16 17 (WebCore::PasteboardItemInfo::encode const): 18 (WebCore::PasteboardItemInfo::decode): 19 20 Change `pathForFileUpload` to `pathsForFileUpload`, and `contentTypeForFileUpload` to `contentTypesForFileUpload`. 21 22 * platform/ios/AbstractPasteboard.h: 23 * platform/ios/PasteboardIOS.mm: 24 (WebCore::Pasteboard::readRespectingUTIFidelities): 25 26 Adjust this to take the file path for the highest fidelity representation in `pathsForContentType`. 27 28 (WebCore::Pasteboard::readFilePaths): 29 * platform/ios/PlatformPasteboardIOS.mm: 30 (WebCore::PlatformPasteboard::informationForItemAtIndex): 31 * platform/ios/WebItemProviderPasteboard.h: 32 * platform/ios/WebItemProviderPasteboard.mm: 33 (-[NSItemProvider web_containsFileURLAndFileUploadContent]): 34 (-[NSItemProvider web_fileUploadContentTypes]): 35 36 Replace `web_containsFileUploadContent` with `web_fileUploadContentTypes`, which returns the full list of file 37 upload content types (rather than just a `BOOL` indicating whether one or more of these types exist). 38 39 (-[WebItemProviderPasteboard fileUploadURLsAtIndex:fileTypes:]): 40 (-[WebItemProviderPasteboard numberOfFiles]): 41 (-[NSItemProvider web_containsFileUploadContent]): Deleted. 42 (-[WebItemProviderPasteboard preferredFileUploadURLAtIndex:fileType:]): Deleted. 43 44 Replaced with `-fileUploadURLsAtIndex:fileTypes:`. This implementation currently just returns the highest 45 fidelity loaded type identifier, but this is wrong because it doesn't take into account inline data types that 46 shouldn't be represented as data for file uploads (for instance, it never makes sense to upload the internal 47 data serialization for an `NSURL` as a file on the web). 48 49 Instead, use existing logic in `web_fileUploadContentTypes` to determine which file types can be treated as file 50 uploads, and return all of these file types that we've loaded. 51 1 52 2018-12-11 Don Olmstead <don.olmstead@sony.com> 2 53 -
trunk/Source/WebCore/platform/PasteboardItemInfo.h
r238795 r239086 27 27 28 28 #include <wtf/Optional.h> 29 #include <wtf/Vector.h> 29 30 #include <wtf/text/WTFString.h> 30 31 … … 38 39 39 40 struct PasteboardItemInfo { 40 String pathForFileUpload;41 String contentTypeForFileUpload;41 Vector<String> pathsForFileUpload; 42 Vector<String> contentTypesForFileUpload; 42 43 String suggestedFileName; 43 44 bool isNonTextType { false }; 44 45 bool containsFileURLAndFileUploadContent { false }; 45 46 PasteboardItemPresentationStyle preferredPresentationStyle { PasteboardItemPresentationStyle::Unspecified }; 47 48 String pathForContentType(const String& type) const 49 { 50 ASSERT(pathsForFileUpload.size() == contentTypesForFileUpload.size()); 51 auto index = contentTypesForFileUpload.find(type); 52 if (index == notFound) 53 return { }; 54 55 return pathsForFileUpload[index]; 56 } 46 57 47 58 template<class Encoder> void encode(Encoder&) const; … … 52 63 void PasteboardItemInfo::encode(Encoder& encoder) const 53 64 { 54 encoder << path ForFileUpload << contentTypeForFileUpload << suggestedFileName << isNonTextType << containsFileURLAndFileUploadContent;65 encoder << pathsForFileUpload << contentTypesForFileUpload << suggestedFileName << isNonTextType << containsFileURLAndFileUploadContent; 55 66 encoder.encodeEnum(preferredPresentationStyle); 56 67 } … … 60 71 { 61 72 PasteboardItemInfo result; 62 if (!decoder.decode(result.path ForFileUpload))73 if (!decoder.decode(result.pathsForFileUpload)) 63 74 return std::nullopt; 64 75 65 if (!decoder.decode(result.contentType ForFileUpload))76 if (!decoder.decode(result.contentTypesForFileUpload)) 66 77 return std::nullopt; 67 78 -
trunk/Source/WebCore/platform/ios/AbstractPasteboard.h
r226396 r239086 58 58 @property (readonly, nonatomic) NSInteger numberOfFiles; 59 59 @property (readonly, nonatomic) NSArray<NSURL *> *allDroppedFileURLs; 60 - (nullable NSURL *)preferredFileUploadURLAtIndex:(NSUInteger)index fileType:(NSString *_Nullable *_Nullable)outFileType; 60 61 // Computes lists of file URLs and types. Each file URL and type corresponds to a representation of the item provider at the given index. 62 // In order from highest fidelity to lowest fidelity. 63 - (NSArray<NSURL *> *)fileUploadURLsAtIndex:(NSUInteger)index fileTypes:(NSArray<NSString *> *_Nullable *_Nonnull)outFileTypes; 61 64 - (void)updateSupportedTypeIdentifiers:(NSArray<NSString *> *)types; 62 65 -
trunk/Source/WebCore/platform/ios/PasteboardIOS.mm
r239053 r239086 295 295 #if ENABLE(ATTACHMENT_ELEMENT) 296 296 auto info = strategy.informationForItemAtIndex(index, m_pasteboardName); 297 bool canReadAttachment = policy == WebContentReadingPolicy::AnyType && RuntimeEnabledFeatures::sharedFeatures().attachmentElementEnabled() && !info.path ForFileUpload.isEmpty();297 bool canReadAttachment = policy == WebContentReadingPolicy::AnyType && RuntimeEnabledFeatures::sharedFeatures().attachmentElementEnabled() && !info.pathsForFileUpload.isEmpty(); 298 298 if (canReadAttachment && info.preferredPresentationStyle == PasteboardItemPresentationStyle::Attachment) { 299 reader.readFilePaths({ info.path ForFileUpload});299 reader.readFilePaths({ info.pathsForFileUpload.first() }); 300 300 continue; 301 301 } … … 318 318 #if ENABLE(ATTACHMENT_ELEMENT) 319 319 if (canReadAttachment && result == ReaderResult::DidNotReadType) 320 reader.readFilePaths({ info.path ForFileUpload});320 reader.readFilePaths({ info.pathsForFileUpload.first() }); 321 321 #endif 322 322 } … … 460 460 for (NSUInteger index = 0, numberOfItems = strategy.getPasteboardItemsCount(m_pasteboardName); index < numberOfItems; ++index) { 461 461 // Currently, drag and drop is the only case on iOS where the "pasteboard" may contain file paths. 462 auto filePath = strategy.informationForItemAtIndex(index, m_pasteboardName).path ForFileUpload;462 auto filePath = strategy.informationForItemAtIndex(index, m_pasteboardName).pathsForFileUpload.first(); 463 463 if (!filePath.isEmpty()) 464 464 filePaths.append(WTFMove(filePath)); -
trunk/Source/WebCore/platform/ios/PlatformPasteboardIOS.mm
r238795 r239086 145 145 146 146 PasteboardItemInfo info; 147 if ([m_pasteboard respondsToSelector:@selector(preferredFileUploadURLAtIndex:fileType:)]) { 148 NSString *fileType = nil; 149 info.pathForFileUpload = [m_pasteboard preferredFileUploadURLAtIndex:index fileType:&fileType].path; 150 info.contentTypeForFileUpload = fileType; 147 if ([m_pasteboard respondsToSelector:@selector(fileUploadURLsAtIndex:fileTypes:)]) { 148 NSArray<NSString *> *fileTypes = nil; 149 NSArray *urls = [m_pasteboard fileUploadURLsAtIndex:index fileTypes:&fileTypes]; 150 ASSERT(fileTypes.count == urls.count); 151 152 info.pathsForFileUpload.reserveInitialCapacity(urls.count); 153 for (NSURL *url in urls) 154 info.pathsForFileUpload.uncheckedAppend(url.path); 155 156 info.contentTypesForFileUpload.reserveInitialCapacity(fileTypes.count); 157 for (NSString *fileType : fileTypes) 158 info.contentTypesForFileUpload.uncheckedAppend(fileType); 151 159 } 152 160 -
trunk/Source/WebCore/platform/ios/WebItemProviderPasteboard.h
r238795 r239086 98 98 @property (readonly, nonatomic) NSArray<NSURL *> *allDroppedFileURLs; 99 99 100 // The preferred file URL corresponds to the highest fidelity non-private UTI that was loaded.101 - (nullable NSURL *)preferredFileUploadURLAtIndex:(NSUInteger)index fileType:(NSString *_Nullable *_Nullable)outFileType;102 103 100 @property (readonly, nonatomic) BOOL hasPendingOperation; 104 101 - (void)incrementPendingOperationCount; -
trunk/Source/WebCore/platform/ios/WebItemProviderPasteboard.mm
r239053 r239086 69 69 for (NSString *identifier in self.registeredTypeIdentifiers) { 70 70 if (UTTypeConformsTo((__bridge CFStringRef)identifier, kUTTypeFileURL)) 71 return self.web_ containsFileUploadContent;71 return self.web_fileUploadContentTypes.count; 72 72 } 73 73 return NO; 74 74 } 75 75 76 - (BOOL)web_containsFileUploadContent 77 { 76 - (NSArray<NSString *> *)web_fileUploadContentTypes 77 { 78 auto types = adoptNS([NSMutableArray new]); 78 79 for (NSString *identifier in self.registeredTypeIdentifiers) { 79 80 if (UTTypeConformsTo((__bridge CFStringRef)identifier, kUTTypeURL)) … … 81 82 82 83 if (typeConformsToTypes(identifier, Pasteboard::supportedFileUploadPasteboardTypes())) 83 return YES; 84 } 85 return NO; 84 [types addObject:identifier]; 85 } 86 87 return types.autorelease(); 86 88 } 87 89 … … 629 631 } 630 632 631 - (NS URL *)preferredFileUploadURLAtIndex:(NSUInteger)index fileType:(NSString **)outFileType632 { 633 if (outFileType)634 *outFileType = nil;633 - (NSArray<NSURL *> *)fileUploadURLsAtIndex:(NSUInteger)index fileTypes:(NSArray<NSString *> **)outFileTypes 634 { 635 auto fileTypes = adoptNS([NSMutableArray new]); 636 auto fileURLs = adoptNS([NSMutableArray new]); 635 637 636 638 if (index >= _loadResults.size()) 637 return nil;639 return @[ ]; 638 640 639 641 auto result = _loadResults[index]; 640 642 if (![result canBeRepresentedAsFileUpload]) 641 return nil; 642 643 NSItemProvider *itemProvider = [result itemProvider]; 644 for (NSString *registeredTypeIdentifier in itemProvider.registeredTypeIdentifiers) { 645 // Search for the highest fidelity non-private type identifier we loaded from the item provider. 646 if (!UTTypeIsDeclared((__bridge CFStringRef)registeredTypeIdentifier) && !UTTypeIsDynamic((__bridge CFStringRef)registeredTypeIdentifier)) 647 continue; 648 649 for (NSString *loadedTypeIdentifier in [result loadedTypeIdentifiers]) { 650 if (!UTTypeConformsTo((__bridge CFStringRef)registeredTypeIdentifier, (__bridge CFStringRef)loadedTypeIdentifier)) 651 continue; 652 653 if (outFileType) 654 *outFileType = loadedTypeIdentifier; 655 return [result fileURLForType:loadedTypeIdentifier]; 643 return @[ ]; 644 645 for (NSString *contentType in [result itemProvider].web_fileUploadContentTypes) { 646 if (NSURL *url = [result fileURLForType:contentType]) { 647 [fileTypes addObject:contentType]; 648 [fileURLs addObject:url]; 656 649 } 657 650 } 658 651 659 return nil; 652 *outFileTypes = fileTypes.autorelease(); 653 return fileURLs.autorelease(); 660 654 } 661 655 … … 685 679 #endif 686 680 // Otherwise, fall back to examining the item's registered type identifiers. 687 if (itemProvider.web_ containsFileUploadContent)681 if (itemProvider.web_fileUploadContentTypes.count) 688 682 ++numberOfFiles; 689 683 }
Note: See TracChangeset
for help on using the changeset viewer.