Title: [230221] trunk
Revision
230221
Author
[email protected]
Date
2018-04-03 13:40:12 -0700 (Tue, 03 Apr 2018)

Log Message

[Mac] Prioritize file promises over filenames during drag and drop
https://bugs.webkit.org/show_bug.cgi?id=184237
<rdar://problem/38278076>

Reviewed by Wenson Hsieh.

Source/WebCore:

When performing a drag operation where the pasteboard contains both a file path and a file
promise, we have historically preferred to accept the file path. Some versions of Photos.app
will provide both a low-resolution thumbnail as a file path and its high-resolution
counterpart as a file promise when dragging a photo, and our current logic leads us to
choose the low-quality thumbnail.

This patch changes our logic to prefer file promises over file paths. This matches the
behavior of Finder and ensures we accept high-resolution assets from Photos.app.

Covered by existing file promise drag tests. beginDragWithFilePromises() was updated to
write a bogus file path to the pasteboard along with the legitimate file promise.

* platform/mac/DragDataMac.mm:
(WebCore::DragData::asFilenames const):
* platform/mac/PasteboardMac.mm:
(WebCore::Pasteboard::read):
(WebCore::Pasteboard::readFilePaths):
* platform/mac/PlatformPasteboardMac.mm:
(WebCore::PlatformPasteboard::numberOfFiles const):

Source/WebKit:

* UIProcess/Cocoa/WebViewImpl.mm:
(WebKit::WebViewImpl::performDragOperation):

Source/WebKitLegacy/mac:

* WebView/WebView.mm:
(-[WebView performDragOperation:]):

Tools:

* DumpRenderTree/mac/EventSendingController.mm:
(-[EventSendingController beginDragWithFilePromises:]):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (230220 => 230221)


--- trunk/Source/WebCore/ChangeLog	2018-04-03 20:22:08 UTC (rev 230220)
+++ trunk/Source/WebCore/ChangeLog	2018-04-03 20:40:12 UTC (rev 230221)
@@ -1,3 +1,31 @@
+2018-04-03  Andy Estes  <[email protected]>
+
+        [Mac] Prioritize file promises over filenames during drag and drop
+        https://bugs.webkit.org/show_bug.cgi?id=184237
+        <rdar://problem/38278076>
+
+        Reviewed by Wenson Hsieh.
+
+        When performing a drag operation where the pasteboard contains both a file path and a file
+        promise, we have historically preferred to accept the file path. Some versions of Photos.app
+        will provide both a low-resolution thumbnail as a file path and its high-resolution
+        counterpart as a file promise when dragging a photo, and our current logic leads us to
+        choose the low-quality thumbnail.
+
+        This patch changes our logic to prefer file promises over file paths. This matches the
+        behavior of Finder and ensures we accept high-resolution assets from Photos.app.
+
+        Covered by existing file promise drag tests. beginDragWithFilePromises() was updated to
+        write a bogus file path to the pasteboard along with the legitimate file promise.
+
+        * platform/mac/DragDataMac.mm:
+        (WebCore::DragData::asFilenames const):
+        * platform/mac/PasteboardMac.mm:
+        (WebCore::Pasteboard::read):
+        (WebCore::Pasteboard::readFilePaths):
+        * platform/mac/PlatformPasteboardMac.mm:
+        (WebCore::PlatformPasteboard::numberOfFiles const):
+
 2018-04-03  Mark Lam  <[email protected]>
 
         Fix mis-application of WTF_PREPARE_VTBL_POINTER_FOR_INSPECTION macro.

Modified: trunk/Source/WebCore/platform/mac/DragDataMac.mm (230220 => 230221)


--- trunk/Source/WebCore/platform/mac/DragDataMac.mm	2018-04-03 20:22:08 UTC (rev 230220)
+++ trunk/Source/WebCore/platform/mac/DragDataMac.mm	2018-04-03 20:40:12 UTC (rev 230221)
@@ -173,12 +173,17 @@
 Vector<String> DragData::asFilenames() const
 {
 #if PLATFORM(MAC)
+    Vector<String> types;
+    platformStrategies()->pasteboardStrategy()->getTypes(types, m_pasteboardName);
+    if (types.contains(String(legacyFilesPromisePasteboardType())))
+        return fileNames();
+
     Vector<String> results;
     platformStrategies()->pasteboardStrategy()->getPathnamesForType(results, String(legacyFilenamesPasteboardType()), m_pasteboardName);
-    if (!results.isEmpty())
-        return results;
+    return results;
+#else
+    return fileNames();
 #endif
-    return fileNames();
 }
 
 bool DragData::containsPlainText() const

Modified: trunk/Source/WebCore/platform/mac/PasteboardMac.mm (230220 => 230221)


--- trunk/Source/WebCore/platform/mac/PasteboardMac.mm	2018-04-03 20:22:08 UTC (rev 230220)
+++ trunk/Source/WebCore/platform/mac/PasteboardMac.mm	2018-04-03 20:40:12 UTC (rev 230221)
@@ -329,6 +329,12 @@
         }
     }
 
+    if (types.contains(String(legacyFilesPromisePasteboardType()))) {
+        text.text = joinPathnames(m_promisedFilePaths);
+        text.isURL = false;
+        return;
+    }
+
     if (types.contains(String(legacyFilenamesPasteboardType()))) {
         Vector<String> pathnames;
         strategy.getPathnamesForType(pathnames, legacyFilenamesPasteboardType(), m_pasteboardName);
@@ -337,12 +343,6 @@
         return;
     }
 
-    if (types.contains(String(legacyFilesPromisePasteboardType()))) {
-        text.text = joinPathnames(m_promisedFilePaths);
-        text.isURL = false;
-        return;
-    }
-
     // FIXME: The code above looks at the types vector first, but this just gets the string without checking. Why the difference?
     text.text = strategy.stringForType(legacyURLPasteboardType(), m_pasteboardName);
     text.isURL = !text.text.isNull();
@@ -364,6 +364,11 @@
         }
     }
 
+    if (policy == WebContentReadingPolicy::AnyType && types.contains(String(legacyFilesPromisePasteboardType()))) {
+        if (m_changeCount != changeCount() || reader.readFilePaths(m_promisedFilePaths))
+            return;
+    }
+
     if (policy == WebContentReadingPolicy::AnyType && types.contains(String(legacyFilenamesPasteboardType()))) {
         Vector<String> paths;
         strategy.getPathnamesForType(paths, legacyFilenamesPasteboardType(), m_pasteboardName);
@@ -371,11 +376,6 @@
             return;
     }
 
-    if (policy == WebContentReadingPolicy::AnyType && types.contains(String(legacyFilesPromisePasteboardType()))) {
-        if (m_changeCount != changeCount() || reader.readFilePaths(m_promisedFilePaths))
-            return;
-    }
-
     if (types.contains(String(legacyHTMLPasteboardType()))) {
         String string = strategy.stringForType(legacyHTMLPasteboardType(), m_pasteboardName);
         if (m_changeCount != changeCount() || (!string.isNull() && reader.readHTML(string)))
@@ -569,6 +569,9 @@
     Vector<String> types;
     strategy.getTypes(types, m_pasteboardName);
 
+    if (types.contains(String(legacyFilesPromisePasteboardType())))
+        return m_promisedFilePaths;
+
     if (types.contains(String(legacyFilenamesPasteboardType()))) {
         Vector<String> filePaths;
         strategy.getPathnamesForType(filePaths, legacyFilenamesPasteboardType(), m_pasteboardName);
@@ -575,9 +578,6 @@
         return filePaths;
     }
 
-    if (types.contains(String(legacyFilesPromisePasteboardType())))
-        return m_promisedFilePaths;
-    
     return { };
 }
 

Modified: trunk/Source/WebCore/platform/mac/PlatformPasteboardMac.mm (230220 => 230221)


--- trunk/Source/WebCore/platform/mac/PlatformPasteboardMac.mm	2018-04-03 20:22:08 UTC (rev 230220)
+++ trunk/Source/WebCore/platform/mac/PlatformPasteboardMac.mm	2018-04-03 20:40:12 UTC (rev 230221)
@@ -65,14 +65,23 @@
 int PlatformPasteboard::numberOfFiles() const
 {
     Vector<String> files;
-    getPathnamesForType(files, String(legacyFilenamesPasteboardType()));
 
-    // FIXME: legacyFilesPromisePasteboardType() contains UTIs, not path names. Also, it's not
-    // guaranteed that the count of UTIs equals the count of files, since some clients only write
-    // unique UTIs.
-    if (!files.size())
+    NSArray *pasteboardTypes = [m_pasteboard types];
+    if ([pasteboardTypes containsObject:legacyFilesPromisePasteboardType()]) {
+        // FIXME: legacyFilesPromisePasteboardType() contains file types, not path names, but in
+        // this case we are only concerned with the count of them. The count of types should equal
+        // the count of files, but this isn't guaranteed as some legacy providers might only write
+        // unique file types.
         getPathnamesForType(files, String(legacyFilesPromisePasteboardType()));
-    return files.size();
+        return files.size();
+    }
+
+    if ([pasteboardTypes containsObject:legacyFilenamesPasteboardType()]) {
+        getPathnamesForType(files, String(legacyFilenamesPasteboardType()));
+        return files.size();
+    }
+
+    return 0;
 }
 
 void PlatformPasteboard::getPathnamesForType(Vector<String>& pathnames, const String& pasteboardType) const

Modified: trunk/Source/WebKit/ChangeLog (230220 => 230221)


--- trunk/Source/WebKit/ChangeLog	2018-04-03 20:22:08 UTC (rev 230220)
+++ trunk/Source/WebKit/ChangeLog	2018-04-03 20:40:12 UTC (rev 230221)
@@ -1,3 +1,14 @@
+2018-04-03  Andy Estes  <[email protected]>
+
+        [Mac] Prioritize file promises over filenames during drag and drop
+        https://bugs.webkit.org/show_bug.cgi?id=184237
+        <rdar://problem/38278076>
+
+        Reviewed by Wenson Hsieh.
+
+        * UIProcess/Cocoa/WebViewImpl.mm:
+        (WebKit::WebViewImpl::performDragOperation):
+
 2018-04-03  Brady Eidson  <[email protected]>
 
         Make SessionStorage work with process swapping.

Modified: trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm (230220 => 230221)


--- trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm	2018-04-03 20:22:08 UTC (rev 230220)
+++ trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm	2018-04-03 20:40:12 UTC (rev 230221)
@@ -3699,19 +3699,7 @@
     SandboxExtension::Handle sandboxExtensionHandle;
     SandboxExtension::HandleArray sandboxExtensionForUpload;
 
-    if ([types containsObject:WebCore::legacyFilenamesPasteboardType()]) {
-        NSArray *files = [draggingInfo.draggingPasteboard propertyListForType:WebCore::legacyFilenamesPasteboardType()];
-        if (![files isKindOfClass:[NSArray class]]) {
-            delete dragData;
-            return false;
-        }
-
-        Vector<String> fileNames;
-
-        for (NSString *file in files)
-            fileNames.append(file);
-        m_page->createSandboxExtensionsIfNeeded(fileNames, sandboxExtensionHandle, sandboxExtensionForUpload);
-    } else if (![types containsObject:PasteboardTypes::WebArchivePboardType] && [types containsObject:WebCore::legacyFilesPromisePasteboardType()]) {
+    if (![types containsObject:PasteboardTypes::WebArchivePboardType] && [types containsObject:WebCore::legacyFilesPromisePasteboardType()]) {
         
         // FIXME: legacyFilesPromisePasteboardType() contains UTIs, not path names. Also, it's not
         // guaranteed that the count of UTIs equals the count of files, since some clients only write
@@ -3760,6 +3748,20 @@
         return true;
     }
 
+    if ([types containsObject:WebCore::legacyFilenamesPasteboardType()]) {
+        NSArray *files = [draggingInfo.draggingPasteboard propertyListForType:WebCore::legacyFilenamesPasteboardType()];
+        if (![files isKindOfClass:[NSArray class]]) {
+            delete dragData;
+            return false;
+        }
+        
+        Vector<String> fileNames;
+        
+        for (NSString *file in files)
+            fileNames.append(file);
+        m_page->createSandboxExtensionsIfNeeded(fileNames, sandboxExtensionHandle, sandboxExtensionForUpload);
+    }
+
     m_page->performDragOperation(*dragData, draggingInfo.draggingPasteboard.name, WTFMove(sandboxExtensionHandle), WTFMove(sandboxExtensionForUpload));
     delete dragData;
 

Modified: trunk/Source/WebKitLegacy/mac/ChangeLog (230220 => 230221)


--- trunk/Source/WebKitLegacy/mac/ChangeLog	2018-04-03 20:22:08 UTC (rev 230220)
+++ trunk/Source/WebKitLegacy/mac/ChangeLog	2018-04-03 20:40:12 UTC (rev 230221)
@@ -1,3 +1,14 @@
+2018-04-03  Andy Estes  <[email protected]>
+
+        [Mac] Prioritize file promises over filenames during drag and drop
+        https://bugs.webkit.org/show_bug.cgi?id=184237
+        <rdar://problem/38278076>
+
+        Reviewed by Wenson Hsieh.
+
+        * WebView/WebView.mm:
+        (-[WebView performDragOperation:]):
+
 2018-04-03  Chris Dumez  <[email protected]>
 
         Drop MainFrame class

Modified: trunk/Source/WebKitLegacy/mac/WebView/WebView.mm (230220 => 230221)


--- trunk/Source/WebKitLegacy/mac/WebView/WebView.mm	2018-04-03 20:22:08 UTC (rev 230220)
+++ trunk/Source/WebKitLegacy/mac/WebView/WebView.mm	2018-04-03 20:40:12 UTC (rev 230221)
@@ -6831,7 +6831,7 @@
 
 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101200
     NSArray* types = draggingInfo.draggingPasteboard.types;
-    if (![types containsObject:WebArchivePboardType] && ![types containsObject:legacyFilenamesPasteboardType()] && [types containsObject:legacyFilesPromisePasteboardType()]) {
+    if (![types containsObject:WebArchivePboardType] && [types containsObject:legacyFilesPromisePasteboardType()]) {
         
         // FIXME: legacyFilesPromisePasteboardType() contains UTIs, not path names. Also, it's not
         // guaranteed that the count of UTIs equals the count of files, since some clients only write

Modified: trunk/Tools/ChangeLog (230220 => 230221)


--- trunk/Tools/ChangeLog	2018-04-03 20:22:08 UTC (rev 230220)
+++ trunk/Tools/ChangeLog	2018-04-03 20:40:12 UTC (rev 230221)
@@ -1,3 +1,14 @@
+2018-04-03  Andy Estes  <[email protected]>
+
+        [Mac] Prioritize file promises over filenames during drag and drop
+        https://bugs.webkit.org/show_bug.cgi?id=184237
+        <rdar://problem/38278076>
+
+        Reviewed by Wenson Hsieh.
+
+        * DumpRenderTree/mac/EventSendingController.mm:
+        (-[EventSendingController beginDragWithFilePromises:]):
+
 2018-04-03  Brady Eidson  <[email protected]>
 
         Make SessionStorage work with process swapping.

Modified: trunk/Tools/DumpRenderTree/mac/EventSendingController.mm (230220 => 230221)


--- trunk/Tools/DumpRenderTree/mac/EventSendingController.mm	2018-04-03 20:22:08 UTC (rev 230220)
+++ trunk/Tools/DumpRenderTree/mac/EventSendingController.mm	2018-04-03 20:40:12 UTC (rev 230221)
@@ -469,7 +469,7 @@
     assert(!draggingInfo);
 
     NSPasteboard *pasteboard = [NSPasteboard pasteboardWithUniqueName];
-    [pasteboard declareTypes:@[NSFilesPromisePboardType] owner:nil];
+    [pasteboard declareTypes:@[NSFilesPromisePboardType, NSFilenamesPboardType] owner:nil];
 
     NSURL *currentTestURL = [NSURL URLWithString:mainFrame.webView.mainFrameURL];
 
@@ -493,6 +493,9 @@
     [pasteboard setPropertyList:fileUTIs forType:NSFilesPromisePboardType];
     assert([pasteboard propertyListForType:NSFilesPromisePboardType]);
 
+    [pasteboard setPropertyList:@[@"file-name-should-not-be-used"] forType:NSFilenamesPboardType];
+    assert([pasteboard propertyListForType:NSFilenamesPboardType]);
+
     auto source = adoptNS([[DumpRenderTreeFileDraggingSource alloc] initWithPromisedFileURLs:fileURLs]);
     draggingInfo = [[DumpRenderTreeDraggingInfo alloc] initWithImage:nil offset:NSZeroSize pasteboard:pasteboard source:source.get()];
     [mainFrame.webView draggingEntered:draggingInfo];
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to