WebKit Bugzilla
Attachment 357067 Details for
Bug 192598
: [iOS] Send the full list of file upload URLs and types in PasteboardItemInfo
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch
bug-192598-20181211115030.patch (text/plain), 14.54 KB, created by
Wenson Hsieh
on 2018-12-11 11:50:31 PST
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Wenson Hsieh
Created:
2018-12-11 11:50:31 PST
Size:
14.54 KB
patch
obsolete
>Subversion Revision: 239061 >diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog >index 477c69df84175ebba3059b89a92aec96ae63eee2..ce40be3952dfeca764dadce194fc1bd8d612829a 100644 >--- a/Source/WebCore/ChangeLog >+++ b/Source/WebCore/ChangeLog >@@ -1,3 +1,54 @@ >+2018-12-11 Wenson Hsieh <wenson_hsieh@apple.com> >+ >+ [iOS] Send the full list of file upload URLs and types in PasteboardItemInfo >+ https://bugs.webkit.org/show_bug.cgi?id=192598 >+ Work towards <rdar://problem/35626913> >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ Refactors PasteboardItemInfo to contain lists of file URLs and corresponding pasteboard types, instead of just >+ a "preferred" file upload URL and type. See below for more details. >+ >+ * platform/PasteboardItemInfo.h: >+ (WebCore::PasteboardItemInfo::pathForContentType const): >+ >+ Add a helper method to find a file upload URL corresponding to a given type. >+ >+ (WebCore::PasteboardItemInfo::encode const): >+ (WebCore::PasteboardItemInfo::decode): >+ >+ Change `pathForFileUpload` to `pathsForFileUpload`, and `contentTypeForFileUpload` to `contentTypesForFileUpload`. >+ >+ * platform/ios/AbstractPasteboard.h: >+ * platform/ios/PasteboardIOS.mm: >+ (WebCore::Pasteboard::readRespectingUTIFidelities): >+ >+ Adjust this to take the file path for the highest fidelity representation in `pathsForContentType`. >+ >+ (WebCore::Pasteboard::readFilePaths): >+ * platform/ios/PlatformPasteboardIOS.mm: >+ (WebCore::PlatformPasteboard::informationForItemAtIndex): >+ * platform/ios/WebItemProviderPasteboard.h: >+ * platform/ios/WebItemProviderPasteboard.mm: >+ (-[NSItemProvider web_containsFileURLAndFileUploadContent]): >+ (-[NSItemProvider web_fileUploadContentTypes]): >+ >+ Replace `web_containsFileUploadContent` with `web_fileUploadContentTypes`, which returns the full list of file >+ upload content types (rather than just a `BOOL` indicating whether one or more of these types exist). >+ >+ (-[WebItemProviderPasteboard fileUploadURLsAtIndex:fileTypes:]): >+ (-[WebItemProviderPasteboard numberOfFiles]): >+ (-[NSItemProvider web_containsFileUploadContent]): Deleted. >+ (-[WebItemProviderPasteboard preferredFileUploadURLAtIndex:fileType:]): Deleted. >+ >+ Replaced with `-fileUploadURLsAtIndex:fileTypes:`. This implementation currently just returns the highest >+ fidelity loaded type identifier, but this is wrong because it doesn't take into account inline data types that >+ shouldn't be represented as data for file uploads (for instance, it never makes sense to upload the internal >+ data serialization for an `NSURL` as a file on the web). >+ >+ Instead, use existing logic in `web_fileUploadContentTypes` to determine which file types can be treated as file >+ uploads, and return all of these file types that we've loaded. >+ > 2018-12-10 Antti Koivisto <antti@apple.com> > > Rename "forced style recalc" to "full style rebuild" >diff --git a/Source/WebCore/platform/PasteboardItemInfo.h b/Source/WebCore/platform/PasteboardItemInfo.h >index bd5996296541061ba766cc144ae6c246875d1087..3bc56848430c53541e3674ed1ddea126101eb9a5 100644 >--- a/Source/WebCore/platform/PasteboardItemInfo.h >+++ b/Source/WebCore/platform/PasteboardItemInfo.h >@@ -26,6 +26,7 @@ > #pragma once > > #include <wtf/Optional.h> >+#include <wtf/Vector.h> > #include <wtf/text/WTFString.h> > > namespace WebCore { >@@ -37,13 +38,23 @@ enum class PasteboardItemPresentationStyle { > }; > > struct PasteboardItemInfo { >- String pathForFileUpload; >- String contentTypeForFileUpload; >+ Vector<String> pathsForFileUpload; >+ Vector<String> contentTypesForFileUpload; > String suggestedFileName; > bool isNonTextType { false }; > bool containsFileURLAndFileUploadContent { false }; > PasteboardItemPresentationStyle preferredPresentationStyle { PasteboardItemPresentationStyle::Unspecified }; > >+ String pathForContentType(const String& type) const >+ { >+ ASSERT(pathsForFileUpload.size() == contentTypesForFileUpload.size()); >+ auto index = contentTypesForFileUpload.find(type); >+ if (index == notFound) >+ return { }; >+ >+ return pathsForFileUpload[index]; >+ } >+ > template<class Encoder> void encode(Encoder&) const; > template<class Decoder> static std::optional<PasteboardItemInfo> decode(Decoder&); > }; >@@ -51,7 +62,7 @@ struct PasteboardItemInfo { > template<class Encoder> > void PasteboardItemInfo::encode(Encoder& encoder) const > { >- encoder << pathForFileUpload << contentTypeForFileUpload << suggestedFileName << isNonTextType << containsFileURLAndFileUploadContent; >+ encoder << pathsForFileUpload << contentTypesForFileUpload << suggestedFileName << isNonTextType << containsFileURLAndFileUploadContent; > encoder.encodeEnum(preferredPresentationStyle); > } > >@@ -59,10 +70,10 @@ template<class Decoder> > std::optional<PasteboardItemInfo> PasteboardItemInfo::decode(Decoder& decoder) > { > PasteboardItemInfo result; >- if (!decoder.decode(result.pathForFileUpload)) >+ if (!decoder.decode(result.pathsForFileUpload)) > return std::nullopt; > >- if (!decoder.decode(result.contentTypeForFileUpload)) >+ if (!decoder.decode(result.contentTypesForFileUpload)) > return std::nullopt; > > if (!decoder.decode(result.suggestedFileName)) >diff --git a/Source/WebCore/platform/ios/AbstractPasteboard.h b/Source/WebCore/platform/ios/AbstractPasteboard.h >index 421018698e125586247888fbaf7a4bd69c6b2f89..8f2dd0a6e399aa31bc6ebb75bbae1133401ce54e 100644 >--- a/Source/WebCore/platform/ios/AbstractPasteboard.h >+++ b/Source/WebCore/platform/ios/AbstractPasteboard.h >@@ -57,7 +57,10 @@ NS_ASSUME_NONNULL_BEGIN > - (NSArray<NSString *> *)pasteboardTypesByFidelityForItemAtIndex:(NSUInteger)index; > @property (readonly, nonatomic) NSInteger numberOfFiles; > @property (readonly, nonatomic) NSArray<NSURL *> *allDroppedFileURLs; >-- (nullable NSURL *)preferredFileUploadURLAtIndex:(NSUInteger)index fileType:(NSString *_Nullable *_Nullable)outFileType; >+ >+// Computes lists of file URLs and types. Each file URL and type corresponds to a representation of the item provider at the given index. >+// In order from highest fidelity to lowest fidelity. >+- (NSArray<NSURL *> *)fileUploadURLsAtIndex:(NSUInteger)index fileTypes:(NSArray<NSString *> *_Nullable *_Nonnull)outFileTypes; > - (void)updateSupportedTypeIdentifiers:(NSArray<NSString *> *)types; > > @end >diff --git a/Source/WebCore/platform/ios/PasteboardIOS.mm b/Source/WebCore/platform/ios/PasteboardIOS.mm >index 05f0de49c45ddf11e5dfff2c2d9cb44abf2ca510..1d9b05788c6c6084b36e76e55026c751fe23e241 100644 >--- a/Source/WebCore/platform/ios/PasteboardIOS.mm >+++ b/Source/WebCore/platform/ios/PasteboardIOS.mm >@@ -294,9 +294,9 @@ void Pasteboard::readRespectingUTIFidelities(PasteboardWebContentReader& reader, > for (NSUInteger index = 0, numberOfItems = strategy.getPasteboardItemsCount(m_pasteboardName); index < numberOfItems; ++index) { > #if ENABLE(ATTACHMENT_ELEMENT) > auto info = strategy.informationForItemAtIndex(index, m_pasteboardName); >- bool canReadAttachment = policy == WebContentReadingPolicy::AnyType && RuntimeEnabledFeatures::sharedFeatures().attachmentElementEnabled() && !info.pathForFileUpload.isEmpty(); >+ bool canReadAttachment = policy == WebContentReadingPolicy::AnyType && RuntimeEnabledFeatures::sharedFeatures().attachmentElementEnabled() && !info.pathsForFileUpload.isEmpty(); > if (canReadAttachment && info.preferredPresentationStyle == PasteboardItemPresentationStyle::Attachment) { >- reader.readFilePaths({ info.pathForFileUpload }); >+ reader.readFilePaths({ info.pathsForFileUpload.first() }); > continue; > } > #endif >@@ -317,7 +317,7 @@ void Pasteboard::readRespectingUTIFidelities(PasteboardWebContentReader& reader, > } > #if ENABLE(ATTACHMENT_ELEMENT) > if (canReadAttachment && result == ReaderResult::DidNotReadType) >- reader.readFilePaths({ info.pathForFileUpload }); >+ reader.readFilePaths({ info.pathsForFileUpload.first() }); > #endif > } > } >@@ -459,7 +459,7 @@ Vector<String> Pasteboard::readFilePaths() > auto& strategy = *platformStrategies()->pasteboardStrategy(); > for (NSUInteger index = 0, numberOfItems = strategy.getPasteboardItemsCount(m_pasteboardName); index < numberOfItems; ++index) { > // Currently, drag and drop is the only case on iOS where the "pasteboard" may contain file paths. >- auto filePath = strategy.informationForItemAtIndex(index, m_pasteboardName).pathForFileUpload; >+ auto filePath = strategy.informationForItemAtIndex(index, m_pasteboardName).pathsForFileUpload.first(); > if (!filePath.isEmpty()) > filePaths.append(WTFMove(filePath)); > } >diff --git a/Source/WebCore/platform/ios/PlatformPasteboardIOS.mm b/Source/WebCore/platform/ios/PlatformPasteboardIOS.mm >index 58f0534abd4cbfae115eb129c53ed80d7af3f033..8d89bb3a8dd87f513d9ea0eaadf9f28459c6d976 100644 >--- a/Source/WebCore/platform/ios/PlatformPasteboardIOS.mm >+++ b/Source/WebCore/platform/ios/PlatformPasteboardIOS.mm >@@ -144,10 +144,18 @@ PasteboardItemInfo PlatformPasteboard::informationForItemAtIndex(int index) > return { }; > > PasteboardItemInfo info; >- if ([m_pasteboard respondsToSelector:@selector(preferredFileUploadURLAtIndex:fileType:)]) { >- NSString *fileType = nil; >- info.pathForFileUpload = [m_pasteboard preferredFileUploadURLAtIndex:index fileType:&fileType].path; >- info.contentTypeForFileUpload = fileType; >+ if ([m_pasteboard respondsToSelector:@selector(fileUploadURLsAtIndex:fileTypes:)]) { >+ NSArray<NSString *> *fileTypes = nil; >+ NSArray *urls = [m_pasteboard fileUploadURLsAtIndex:index fileTypes:&fileTypes]; >+ ASSERT(fileTypes.count == urls.count); >+ >+ info.pathsForFileUpload.reserveInitialCapacity(urls.count); >+ for (NSURL *url in urls) >+ info.pathsForFileUpload.uncheckedAppend(url.path); >+ >+ info.contentTypesForFileUpload.reserveInitialCapacity(fileTypes.count); >+ for (NSString *fileType : fileTypes) >+ info.contentTypesForFileUpload.uncheckedAppend(fileType); > } > > NSItemProvider *itemProvider = [[m_pasteboard itemProviders] objectAtIndex:index]; >diff --git a/Source/WebCore/platform/ios/WebItemProviderPasteboard.h b/Source/WebCore/platform/ios/WebItemProviderPasteboard.h >index e2a6c9a49eba6060d753430fd77c9abebf3e7a88..29f9a71d70f6ac487c640941beb6d41af19e1811 100644 >--- a/Source/WebCore/platform/ios/WebItemProviderPasteboard.h >+++ b/Source/WebCore/platform/ios/WebItemProviderPasteboard.h >@@ -97,9 +97,6 @@ WEBCORE_EXPORT @interface WebItemProviderPasteboard : NSObject<AbstractPasteboar > // This will only be non-empty when an operation is being performed. > @property (readonly, nonatomic) NSArray<NSURL *> *allDroppedFileURLs; > >-// The preferred file URL corresponds to the highest fidelity non-private UTI that was loaded. >-- (nullable NSURL *)preferredFileUploadURLAtIndex:(NSUInteger)index fileType:(NSString *_Nullable *_Nullable)outFileType; >- > @property (readonly, nonatomic) BOOL hasPendingOperation; > - (void)incrementPendingOperationCount; > - (void)decrementPendingOperationCount; >diff --git a/Source/WebCore/platform/ios/WebItemProviderPasteboard.mm b/Source/WebCore/platform/ios/WebItemProviderPasteboard.mm >index c3275359eff8548a42128cff1e0cbf89f0f61f58..a8cecf6f8972c1d614f6107c879892a54c90711b 100644 >--- a/Source/WebCore/platform/ios/WebItemProviderPasteboard.mm >+++ b/Source/WebCore/platform/ios/WebItemProviderPasteboard.mm >@@ -68,21 +68,23 @@ - (BOOL)web_containsFileURLAndFileUploadContent > { > for (NSString *identifier in self.registeredTypeIdentifiers) { > if (UTTypeConformsTo((__bridge CFStringRef)identifier, kUTTypeFileURL)) >- return self.web_containsFileUploadContent; >+ return self.web_fileUploadContentTypes.count; > } > return NO; > } > >-- (BOOL)web_containsFileUploadContent >+- (NSArray<NSString *> *)web_fileUploadContentTypes > { >+ auto types = adoptNS([NSMutableArray new]); > for (NSString *identifier in self.registeredTypeIdentifiers) { > if (UTTypeConformsTo((__bridge CFStringRef)identifier, kUTTypeURL)) > continue; > > if (typeConformsToTypes(identifier, Pasteboard::supportedFileUploadPasteboardTypes())) >- return YES; >+ [types addObject:identifier]; > } >- return NO; >+ >+ return types.autorelease(); > } > > @end >@@ -628,35 +630,27 @@ - (NSInteger)changeCount > return _changeCount; > } > >-- (NSURL *)preferredFileUploadURLAtIndex:(NSUInteger)index fileType:(NSString **)outFileType >+- (NSArray<NSURL *> *)fileUploadURLsAtIndex:(NSUInteger)index fileTypes:(NSArray<NSString *> **)outFileTypes > { >- if (outFileType) >- *outFileType = nil; >+ auto fileTypes = adoptNS([NSMutableArray new]); >+ auto fileURLs = adoptNS([NSMutableArray new]); > > if (index >= _loadResults.size()) >- return nil; >+ return @[ ]; > > auto result = _loadResults[index]; > if (![result canBeRepresentedAsFileUpload]) >- return nil; >- >- NSItemProvider *itemProvider = [result itemProvider]; >- for (NSString *registeredTypeIdentifier in itemProvider.registeredTypeIdentifiers) { >- // Search for the highest fidelity non-private type identifier we loaded from the item provider. >- if (!UTTypeIsDeclared((__bridge CFStringRef)registeredTypeIdentifier) && !UTTypeIsDynamic((__bridge CFStringRef)registeredTypeIdentifier)) >- continue; >- >- for (NSString *loadedTypeIdentifier in [result loadedTypeIdentifiers]) { >- if (!UTTypeConformsTo((__bridge CFStringRef)registeredTypeIdentifier, (__bridge CFStringRef)loadedTypeIdentifier)) >- continue; >+ return @[ ]; > >- if (outFileType) >- *outFileType = loadedTypeIdentifier; >- return [result fileURLForType:loadedTypeIdentifier]; >+ for (NSString *contentType in [result itemProvider].web_fileUploadContentTypes) { >+ if (NSURL *url = [result fileURLForType:contentType]) { >+ [fileTypes addObject:contentType]; >+ [fileURLs addObject:url]; > } > } > >- return nil; >+ *outFileTypes = fileTypes.autorelease(); >+ return fileURLs.autorelease(); > } > > - (NSArray<NSURL *> *)allDroppedFileURLs >@@ -684,7 +678,7 @@ - (NSInteger)numberOfFiles > } > #endif > // Otherwise, fall back to examining the item's registered type identifiers. >- if (itemProvider.web_containsFileUploadContent) >+ if (itemProvider.web_fileUploadContentTypes.count) > ++numberOfFiles; > } > return numberOfFiles;
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 192598
: 357067