Title: [239053] trunk
Revision
239053
Author
wenson_hs...@apple.com
Date
2018-12-10 14:18:10 -0800 (Mon, 10 Dec 2018)

Log Message

[iOS] Unable to upload data that conforms to "public.item" but not "public.content"
https://bugs.webkit.org/show_bug.cgi?id=192555
<rdar://problem/35204990>

Reviewed by Tim Horton.

Source/WebCore:

Add support for uploading content that conforms to "public.item" via drag and drop. Currently, iOS WebKit only
supports data that conforms to "public.content", but there exist several types of files that conform to
"public.item" but not "public.content". See below for more detail.

Test: DragAndDropTests.ExternalSourcePKCS12ToSingleFileInput

* platform/ios/PasteboardIOS.mm:
(WebCore::Pasteboard::supportedFileUploadPasteboardTypes):

Update this to include "public.item", and remove "public.folder", which is now redundant because "public.folder"
conforms to "public.item".

* platform/ios/WebItemProviderPasteboard.mm:
(-[NSItemProvider web_containsFileURLAndFileUploadContent]):

Pull out the "contains content that is supported for file uploads" part of this helper method into a separate
method, and use it within `-web_containsFileURLAndFileUploadContent`. Note that this prevents "public.url"-
conformant data from being uploaded as files (i.e., we never want to upload a URL string *itself* as a file).
Drawing this distinction ensures that we don't confuse item providers that contain just a URL as files when
dropping into a file upload area or file input (see API test: ExternalSourceZIPArchiveAndURLToSingleFileInput
for an example of this corner case).

(-[NSItemProvider web_containsFileUploadContent]):
(-[WebItemProviderPasteboard numberOfFiles]):

Refactor this to use `-web_containsFileUploadContent`.

Tools:

Add a test to verify that `.p12` files may be uploaded as files via drag and drop. "com.rsa.pkcs-12" is an
example of a data type that conforms to "public.item", but not "public.content"; before this patch, we would
only support uploading "public.content", so files such as these would not be accepted when dropping into file
inputs, or be exposed as files on DataTransfer.

* TestWebKitAPI/Tests/ios/DragAndDropTestsIOS.mm:
(TestWebKitAPI::TEST):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (239052 => 239053)


--- trunk/Source/WebCore/ChangeLog	2018-12-10 22:10:48 UTC (rev 239052)
+++ trunk/Source/WebCore/ChangeLog	2018-12-10 22:18:10 UTC (rev 239053)
@@ -1,3 +1,38 @@
+2018-12-10  Wenson Hsieh  <wenson_hs...@apple.com>
+
+        [iOS] Unable to upload data that conforms to "public.item" but not "public.content"
+        https://bugs.webkit.org/show_bug.cgi?id=192555
+        <rdar://problem/35204990>
+
+        Reviewed by Tim Horton.
+
+        Add support for uploading content that conforms to "public.item" via drag and drop. Currently, iOS WebKit only
+        supports data that conforms to "public.content", but there exist several types of files that conform to
+        "public.item" but not "public.content". See below for more detail.
+
+        Test: DragAndDropTests.ExternalSourcePKCS12ToSingleFileInput
+
+        * platform/ios/PasteboardIOS.mm:
+        (WebCore::Pasteboard::supportedFileUploadPasteboardTypes):
+
+        Update this to include "public.item", and remove "public.folder", which is now redundant because "public.folder"
+        conforms to "public.item".
+
+        * platform/ios/WebItemProviderPasteboard.mm:
+        (-[NSItemProvider web_containsFileURLAndFileUploadContent]):
+
+        Pull out the "contains content that is supported for file uploads" part of this helper method into a separate
+        method, and use it within `-web_containsFileURLAndFileUploadContent`. Note that this prevents "public.url"-
+        conformant data from being uploaded as files (i.e., we never want to upload a URL string *itself* as a file).
+        Drawing this distinction ensures that we don't confuse item providers that contain just a URL as files when
+        dropping into a file upload area or file input (see API test: ExternalSourceZIPArchiveAndURLToSingleFileInput
+        for an example of this corner case).
+
+        (-[NSItemProvider web_containsFileUploadContent]):
+        (-[WebItemProviderPasteboard numberOfFiles]):
+
+        Refactor this to use `-web_containsFileUploadContent`.
+
 2018-12-10  Chris Dumez  <cdu...@apple.com>
 
         Add SPI to allow the client to set the user-agent at main frame level, from the UIProcess

Modified: trunk/Source/WebCore/platform/ios/PasteboardIOS.mm (239052 => 239053)


--- trunk/Source/WebCore/platform/ios/PasteboardIOS.mm	2018-12-10 22:10:48 UTC (rev 239052)
+++ trunk/Source/WebCore/platform/ios/PasteboardIOS.mm	2018-12-10 22:18:10 UTC (rev 239053)
@@ -345,7 +345,7 @@
 
 NSArray *Pasteboard::supportedFileUploadPasteboardTypes()
 {
-    return @[ (NSString *)kUTTypeContent, (NSString *)kUTTypeZipArchive, (NSString *)kUTTypeFolder ];
+    return @[ (__bridge NSString *)kUTTypeItem, (__bridge NSString *)kUTTypeContent, (__bridge NSString *)kUTTypeZipArchive ];
 }
 
 bool Pasteboard::hasData()

Modified: trunk/Source/WebCore/platform/ios/WebItemProviderPasteboard.mm (239052 => 239053)


--- trunk/Source/WebCore/platform/ios/WebItemProviderPasteboard.mm	2018-12-10 22:10:48 UTC (rev 239052)
+++ trunk/Source/WebCore/platform/ios/WebItemProviderPasteboard.mm	2018-12-10 22:18:10 UTC (rev 239053)
@@ -66,19 +66,20 @@
 
 - (BOOL)web_containsFileURLAndFileUploadContent
 {
-    BOOL containsFileURL = NO;
-    BOOL containsContentForFileUpload = NO;
     for (NSString *identifier in self.registeredTypeIdentifiers) {
-        if (UTTypeConformsTo((__bridge CFStringRef)identifier, kUTTypeFileURL)) {
-            containsFileURL = YES;
-            continue;
-        }
+        if (UTTypeConformsTo((__bridge CFStringRef)identifier, kUTTypeFileURL))
+            return self.web_containsFileUploadContent;
+    }
+    return NO;
+}
 
+- (BOOL)web_containsFileUploadContent
+{
+    for (NSString *identifier in self.registeredTypeIdentifiers) {
         if (UTTypeConformsTo((__bridge CFStringRef)identifier, kUTTypeURL))
             continue;
 
-        containsContentForFileUpload |= typeConformsToTypes(identifier, Pasteboard::supportedFileUploadPasteboardTypes());
-        if (containsContentForFileUpload && containsFileURL)
+        if (typeConformsToTypes(identifier, Pasteboard::supportedFileUploadPasteboardTypes()))
             return YES;
     }
     return NO;
@@ -670,20 +671,21 @@
 
 - (NSInteger)numberOfFiles
 {
-    NSArray *supportedFileTypes = Pasteboard::supportedFileUploadPasteboardTypes();
     NSInteger numberOfFiles = 0;
     for (NSItemProvider *itemProvider in _itemProviders.get()) {
 #if !PLATFORM(IOSMAC)
+        // First, check if the source has explicitly indicated that this item should or should not be treated as an attachment.
         if (itemProvider.preferredPresentationStyle == UIPreferredPresentationStyleInline)
             continue;
-#endif
 
-        for (NSString *identifier in itemProvider.registeredTypeIdentifiers) {
-            if (!typeConformsToTypes(identifier, supportedFileTypes))
-                continue;
+        if (itemProvider.preferredPresentationStyle == UIPreferredPresentationStyleAttachment) {
             ++numberOfFiles;
-            break;
+            continue;
         }
+#endif
+        // Otherwise, fall back to examining the item's registered type identifiers.
+        if (itemProvider.web_containsFileUploadContent)
+            ++numberOfFiles;
     }
     return numberOfFiles;
 }

Modified: trunk/Tools/ChangeLog (239052 => 239053)


--- trunk/Tools/ChangeLog	2018-12-10 22:10:48 UTC (rev 239052)
+++ trunk/Tools/ChangeLog	2018-12-10 22:18:10 UTC (rev 239053)
@@ -1,3 +1,19 @@
+2018-12-10  Wenson Hsieh  <wenson_hs...@apple.com>
+
+        [iOS] Unable to upload data that conforms to "public.item" but not "public.content"
+        https://bugs.webkit.org/show_bug.cgi?id=192555
+        <rdar://problem/35204990>
+
+        Reviewed by Tim Horton.
+
+        Add a test to verify that `.p12` files may be uploaded as files via drag and drop. "com.rsa.pkcs-12" is an
+        example of a data type that conforms to "public.item", but not "public.content"; before this patch, we would
+        only support uploading "public.content", so files such as these would not be accepted when dropping into file
+        inputs, or be exposed as files on DataTransfer.
+
+        * TestWebKitAPI/Tests/ios/DragAndDropTestsIOS.mm:
+        (TestWebKitAPI::TEST):
+
 2018-12-10  David Kilzer  <ddkil...@apple.com>
 
         Injected bundle for WebKitTestRunner leaks WKTypeRef objects

Modified: trunk/Tools/TestWebKitAPI/Tests/ios/DragAndDropTestsIOS.mm (239052 => 239053)


--- trunk/Tools/TestWebKitAPI/Tests/ios/DragAndDropTestsIOS.mm	2018-12-10 22:10:48 UTC (rev 239052)
+++ trunk/Tools/TestWebKitAPI/Tests/ios/DragAndDropTestsIOS.mm	2018-12-10 22:18:10 UTC (rev 239053)
@@ -710,6 +710,21 @@
     EXPECT_WK_STREQ("", [webView stringByEvaluatingJavaScript:@"output.value"]);
 }
 
+TEST(DragAndDropTests, ExternalSourcePKCS12ToSingleFileInput)
+{
+    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
+    [webView synchronouslyLoadTestPageNamed:@"file-uploading"];
+
+    auto item = adoptNS([[NSItemProvider alloc] init]);
+    [item registerDataRepresentationForTypeIdentifier:(__bridge NSString *)kUTTypePKCS12 withData:[@"Not a real p12 file." dataUsingEncoding:NSUTF8StringEncoding]];
+
+    auto simulator = adoptNS([[DragAndDropSimulator alloc] initWithWebView:webView.get()]);
+    [simulator setExternalItemProviders:@[ item.get() ]];
+    [simulator runFrom:CGPointMake(200, 100) to:CGPointMake(100, 100)];
+
+    EXPECT_WK_STREQ("application/x-pkcs12", [webView stringByEvaluatingJavaScript:@"output.value"]);
+}
+
 TEST(DragAndDropTests, ExternalSourceZIPArchiveAndURLToSingleFileInput)
 {
     auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to