Add link information to data transfer pasteboard for drag and drop links
authorwilander@apple.com <wilander@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 11 Nov 2016 04:15:41 +0000 (04:15 +0000)
committerwilander@apple.com <wilander@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 11 Nov 2016 04:15:41 +0000 (04:15 +0000)
https://bugs.webkit.org/show_bug.cgi?id=163468
<rdar://problem/20634630>

Reviewed by Brent Fulgham.

Source/WebCore:

Test: editing/pasteboard/drag-link-with-data-transfer-adds-trusted-link-to-pasteboard.html
This test ensures data transfers still work for types 'text' and 'url', i.e. that we don't
regress in-page use of the drag pasteboard.

* page/DragController.cpp:
(WebCore::DragController::startDrag):
    Now adds trustworthy link information to the drag pasteboard.
* platform/Pasteboard.h:
    New function declaration Pasteboard::writeTrustworthyWebURLsPboardType.
* platform/efl/PasteboardEfl.cpp:
(WebCore::Pasteboard::writeTrustworthyWebURLsPboardType):
    Empty, i.e. not implemented.
* platform/gtk/PasteboardGtk.cpp:
(WebCore::Pasteboard::writeTrustworthyWebURLsPboardType):
    Empty, i.e. not implemented.
* platform/ios/PasteboardIOS.mm:
(WebCore::Pasteboard::writeTrustworthyWebURLsPboardType):
    Calls ASSERT_NOT_REACHED() to make sure we don't use this function before we have
    decided on a trustrworthy URL pasteboard type on iOS. Currently not used since we
    don't support drag & drop on iOS.
* platform/mac/PasteboardMac.mm:
(WebCore::Pasteboard::writeTrustworthyWebURLsPboardType):
    Writes the given URL to the WebURLsWithTitlesPboardType. This pasteboard type
    serves as a trusted drop source.
* platform/win/PasteboardWin.cpp:
(WebCore::Pasteboard::writeTrustworthyWebURLsPboardType):
    Empty, i.e. not implemented.

LayoutTests:

* editing/pasteboard/drag-link-with-data-transfer-adds-trusted-link-to-pasteboard-expected.txt: Added.
* editing/pasteboard/drag-link-with-data-transfer-adds-trusted-link-to-pasteboard.html: Added.
    This test ensures data transfer is not deleted or overwritten for the types 'text' and 'url'.
* platform/ios-simulator/TestExpectations:
    Drag & drop is not supported on iOS.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208576 268f45cc-cd09-0410-ab3c-d52691b4dbfc

12 files changed:
LayoutTests/ChangeLog
LayoutTests/editing/pasteboard/drag-link-with-data-transfer-adds-trusted-link-to-pasteboard-expected.txt [new file with mode: 0644]
LayoutTests/editing/pasteboard/drag-link-with-data-transfer-adds-trusted-link-to-pasteboard.html [new file with mode: 0644]
LayoutTests/platform/ios-simulator/TestExpectations
Source/WebCore/ChangeLog
Source/WebCore/page/DragController.cpp
Source/WebCore/platform/Pasteboard.h
Source/WebCore/platform/efl/PasteboardEfl.cpp
Source/WebCore/platform/gtk/PasteboardGtk.cpp
Source/WebCore/platform/ios/PasteboardIOS.mm
Source/WebCore/platform/mac/PasteboardMac.mm
Source/WebCore/platform/win/PasteboardWin.cpp

index d37a35a..757a22a 100644 (file)
@@ -1,3 +1,17 @@
+2016-11-10  John Wilander  <wilander@apple.com>
+
+        Add link information to data transfer pasteboard for drag and drop links
+        https://bugs.webkit.org/show_bug.cgi?id=163468
+        <rdar://problem/20634630>
+
+        Reviewed by Brent Fulgham.
+
+        * editing/pasteboard/drag-link-with-data-transfer-adds-trusted-link-to-pasteboard-expected.txt: Added.
+        * editing/pasteboard/drag-link-with-data-transfer-adds-trusted-link-to-pasteboard.html: Added.
+            This test ensures data transfer is not deleted or overwritten for the types 'text' and 'url'.
+        * platform/ios-simulator/TestExpectations:
+            Drag & drop is not supported on iOS.
+
 2016-11-10  Chris Dumez  <cdumez@apple.com>
 
         REGRESSION (r208522): LayoutTest fast/loader/reload-zero-byte-plugin.html is a flaky failure
diff --git a/LayoutTests/editing/pasteboard/drag-link-with-data-transfer-adds-trusted-link-to-pasteboard-expected.txt b/LayoutTests/editing/pasteboard/drag-link-with-data-transfer-adds-trusted-link-to-pasteboard-expected.txt
new file mode 100644 (file)
index 0000000..f96c505
--- /dev/null
@@ -0,0 +1,14 @@
+PASS 'javascript:alert('Set by data transfer');' was set in the data transfer for firstAnchorSource and not overwritten.
+PASS 'http://webkit.org/setByDataTransfer' was set in the data transfer for secondAnchorSource and not overwritten.
+PASS 'javascript:alert('Set by data transfer');' was set in the data transfer for firstSvgSource and not overwritten.
+PASS 'http://webkit.org/setByDataTransfer' was set in the data transfer for secondSvgSource and not overwritten.
+
+This only has an ondragenter handler and is here to make sure dragging over it doesn't change the pasteboard.
+This only has an ondragover handler and is here to make sure dragging over it doesn't change the pasteboard.
+firstAnchorSource
+secondAnchorSource
+https://webkit.org
+
+https://webkit.org
+
+
diff --git a/LayoutTests/editing/pasteboard/drag-link-with-data-transfer-adds-trusted-link-to-pasteboard.html b/LayoutTests/editing/pasteboard/drag-link-with-data-transfer-adds-trusted-link-to-pasteboard.html
new file mode 100644 (file)
index 0000000..3c05ce8
--- /dev/null
@@ -0,0 +1,137 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
+<html>
+<head>
+    <script src="../../resources/js-test-pre.js"></script>
+</head>
+<body>
+<input id="destination" type="text" style="height: 256px; width: 256px; border: 1px dashed black;" />
+<hr>
+
+<div id="ondragenterElement" ondragenter='event.preventDefault(); event.dataTransfer.setData("url", "http://webkit.org/setByDragenter")'>
+    <a href="https://webkit.org">This only has an ondragenter handler and is here to make sure dragging over it doesn't change the pasteboard.</a>
+</div>
+
+<div id="ondragoverElement" ondragover='event.preventDefault(); event.dataTransfer.setData("text", "Text set by dragover.")'>
+    <a href="https://webkit.org">This only has an ondragover handler and is here to make sure dragging over it doesn't change the pasteboard.</a>
+</div>
+
+<a id="firstAnchorSource" draggable="true" href="https://webkit.org">firstAnchorSource</a><br>
+<a id="secondAnchorSource" draggable="true" href="https://webkit.org">secondAnchorSource</a><br>
+
+<svg id="firstSvgSource" draggable="true" width="140" height="30" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
+    <a xlink:href="https://webkit.org" target="_blank">
+        <rect height="30" width="120" y="0" x="0" rx="15"/>
+        <text fill="white" text-anchor="middle" y="21" x="60">https://webkit.org</text>
+    </a>
+</svg><br>
+<svg id="secondSvgSource" draggable="true" width="140" height="30" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
+    <a xlink:href="https://webkit.org" target="_blank">
+        <rect height="30" width="120" y="0" x="0" rx="15"/>
+        <text fill="blue" text-anchor="middle" y="21" x="60">https://webkit.org</text>
+    </a>
+</svg><br>
+
+<!-- Should be uncommented when https://bugs.webkit.org/show_bug.cgi?id=164280 is fixed
+
+<div draggable="true">
+    <math id="firstMathSource" style="padding: 0">
+        <mrow href="https://webkit.org">
+            <mrow>
+                <mrow>
+                    <mspace id="space1" width="150px" height="20px" mathbackground="yellow"></mspace>
+                </mrow>
+            </mrow>
+        </mrow>
+    </math>
+</div>
+<div draggable="true">
+    <math id="secondMathSource" style="padding: 0">
+        <mrow href="https://webkit.org">
+            <mrow>
+                <mrow>
+                    <mspace id="space2" width="150px" height="20px" mathbackground="red"></mspace>
+                </mrow>
+            </mrow>
+        </mrow>
+    </math>
+</div>
+
+-->
+<script>
+    var TEXT_TO_SET_IN_DATA_TRANSFER = "javascript:alert('Set by data transfer');";
+    var URL_TO_SET_IN_DATA_TRANSFER = "http://webkit.org/setByDataTransfer";
+
+    var testResults = [];
+
+    function addDragstartEventHander(elementId, dataTransferType) {
+        var intendedDataTransferContent = (dataTransferType === "text" ? TEXT_TO_SET_IN_DATA_TRANSFER : URL_TO_SET_IN_DATA_TRANSFER);
+        document.getElementById(elementId).addEventListener("dragstart", function (event) {
+            event.dataTransfer.setData(dataTransferType, intendedDataTransferContent);
+            var actualDataTransferContent = event.dataTransfer.getData(dataTransferType);
+            if (actualDataTransferContent === intendedDataTransferContent) {
+                testResults.push({
+                    passed : true,
+                    message : "'" + actualDataTransferContent + "' was set in the data transfer for " + elementId + " and not overwritten."
+                });
+            } else {
+                testResults.push({
+                    passed : false,
+                    message : (actualDataTransferContent ? "'" + actualDataTransferContent + "'" : "Nothing") + " was set in the data transfer for " + elementId + " or it was overwritten."
+                });
+            }
+        });
+    }
+
+    addDragstartEventHander("firstAnchorSource", "text");
+    addDragstartEventHander("secondAnchorSource", "url");
+    addDragstartEventHander("firstSvgSource", "text");
+    addDragstartEventHander("secondSvgSource", "url");
+    // Should be uncommented when https://bugs.webkit.org/show_bug.cgi?id=164280 is fixed
+    // addDragstartEventHander("firstMathSource", "text");
+    // addDragstartEventHander("secondMathSource", "url");
+
+    function moveMouseToCenterOfElement(elementId) {
+        var element = document.getElementById(elementId);
+        var centerX = element.offsetLeft + element.offsetWidth / 2;
+        var centerY = element.offsetTop + element.offsetHeight / 2;
+        eventSender.mouseMoveTo(centerX, centerY);
+    }
+
+    function dragAndDropElement (elementId) {
+        moveMouseToCenterOfElement(elementId);
+        eventSender.mouseDown();
+        eventSender.leapForward(200);
+        moveMouseToCenterOfElement("ondragoverElement");
+        eventSender.leapForward(100);
+        moveMouseToCenterOfElement("ondragenterElement");
+        eventSender.leapForward(100);
+        moveMouseToCenterOfElement("destination");
+        eventSender.leapForward(200);
+        eventSender.mouseUp();
+    }
+
+    if (window.testRunner && eventSender) {
+        testRunner.dumpAsText();
+        testRunner.waitUntilDone();
+
+        dragAndDropElement("firstAnchorSource");
+        dragAndDropElement("secondAnchorSource");
+        dragAndDropElement("firstSvgSource");
+        dragAndDropElement("secondSvgSource");
+        // Should be uncommented when https://bugs.webkit.org/show_bug.cgi?id=164280 is fixed
+        // dragAndDropElement("firstMathSource");
+        // dragAndDropElement("secondMathSource");
+
+        testResults.forEach(function(result) {
+            if (result.passed) {
+                testPassed(result.message);
+            } else {
+                testFailed(result.message);
+            }
+        });
+
+        testRunner.notifyDone();
+    }
+</script>
+</body>
+</html>
index 474ce6f..c3adedb 100644 (file)
@@ -229,6 +229,7 @@ fast/dom/DeviceOrientation
 fast/canvas/canvas-toDataURL-webp.html
 
 # Drag-and-drop is not supported:
+editing/pasteboard/drag-link-with-data-transfer-adds-trusted-link-to-pasteboard.html
 fast/events/bogus-dropEffect-effectAllowed.html
 fast/events/clear-drag-state.html
 fast/events/clear-edit-drag-state.html
index 22d980f..1f3a098 100644 (file)
@@ -1,3 +1,39 @@
+2016-11-10  John Wilander  <wilander@apple.com>
+
+        Add link information to data transfer pasteboard for drag and drop links
+        https://bugs.webkit.org/show_bug.cgi?id=163468
+        <rdar://problem/20634630>
+
+        Reviewed by Brent Fulgham.
+
+        Test: editing/pasteboard/drag-link-with-data-transfer-adds-trusted-link-to-pasteboard.html
+        This test ensures data transfers still work for types 'text' and 'url', i.e. that we don't
+        regress in-page use of the drag pasteboard.
+
+        * page/DragController.cpp:
+        (WebCore::DragController::startDrag):
+            Now adds trustworthy link information to the drag pasteboard.
+        * platform/Pasteboard.h:
+            New function declaration Pasteboard::writeTrustworthyWebURLsPboardType.
+        * platform/efl/PasteboardEfl.cpp:
+        (WebCore::Pasteboard::writeTrustworthyWebURLsPboardType):
+            Empty, i.e. not implemented.
+        * platform/gtk/PasteboardGtk.cpp:
+        (WebCore::Pasteboard::writeTrustworthyWebURLsPboardType):
+            Empty, i.e. not implemented.
+        * platform/ios/PasteboardIOS.mm:
+        (WebCore::Pasteboard::writeTrustworthyWebURLsPboardType):
+            Calls ASSERT_NOT_REACHED() to make sure we don't use this function before we have
+            decided on a trustrworthy URL pasteboard type on iOS. Currently not used since we
+            don't support drag & drop on iOS.
+        * platform/mac/PasteboardMac.mm:
+        (WebCore::Pasteboard::writeTrustworthyWebURLsPboardType):
+            Writes the given URL to the WebURLsWithTitlesPboardType. This pasteboard type
+            serves as a trusted drop source.
+        * platform/win/PasteboardWin.cpp:
+        (WebCore::Pasteboard::writeTrustworthyWebURLsPboardType):
+            Empty, i.e. not implemented.
+
 2016-11-10  Said Abou-Hallawa  <sabouhallawa@apple.com>
 
         REGRESSION(r207182): [iOS] Crash because of passing freed CFDictionaryRef to CG when decoding a sub-sampled large image
index 8fc82d8..20d70ac 100644 (file)
@@ -875,6 +875,13 @@ bool DragController::startDrag(Frame& src, const DragState& state, DragOperation
             // Simplify whitespace so the title put on the dataTransfer resembles what the user sees
             // on the web page. This includes replacing newlines with spaces.
             src.editor().copyURL(linkURL, hitTestResult.textContent().simplifyWhiteSpace(), dataTransfer.pasteboard());
+        } else {
+            // Make sure the pasteboard also contains trustworthy link data
+            // but don't overwrite more general pasteboard types.
+            PasteboardURL pasteboardURL;
+            pasteboardURL.url = linkURL;
+            pasteboardURL.title = hitTestResult.textContent();
+            dataTransfer.pasteboard().writeTrustworthyWebURLsPboardType(pasteboardURL);
         }
 
         const VisibleSelection& sourceSelection = src.selection().selection();
index 16c4b59..807d4d6 100644 (file)
@@ -166,6 +166,7 @@ public:
     virtual void read(PasteboardWebContentReader&);
 
     virtual void write(const PasteboardURL&);
+    virtual void writeTrustworthyWebURLsPboardType(const PasteboardURL&);
     virtual void write(const PasteboardImage&);
     virtual void write(const PasteboardWebContent&);
 
index e12dc9a..b5b5c29 100644 (file)
@@ -96,6 +96,11 @@ void Pasteboard::write(const PasteboardURL&)
     notImplemented();
 }
 
+void Pasteboard::writeTrustworthyWebURLsPboardType(const PasteboardURL&)
+{
+    notImplemented();
+}
+
 void Pasteboard::writeString(const String&, const String&)
 {
     notImplemented();
index 9b04bb0..387dbee 100644 (file)
@@ -22,6 +22,7 @@
 
 #include "DragData.h"
 #include "Image.h"
+#include "NotImplemented.h"
 #include "PasteboardStrategy.h"
 #include "PlatformStrategies.h"
 #include "SelectionData.h"
@@ -179,6 +180,11 @@ void Pasteboard::write(const PasteboardURL& pasteboardURL)
     writeToClipboard();
 }
 
+void Pasteboard::writeTrustworthyWebURLsPboardType(const PasteboardURL&)
+{
+    notImplemented();
+}
+
 void Pasteboard::write(const PasteboardImage& pasteboardImage)
 {
     m_selectionData->clearAll();
index e2761f9..cf105f5 100644 (file)
@@ -127,6 +127,15 @@ void Pasteboard::write(const PasteboardURL& pasteboardURL)
     platformStrategies()->pasteboardStrategy()->writeToPasteboard(kUTTypeURL, pasteboardURL.url.string());
 }
 
+void Pasteboard::writeTrustworthyWebURLsPboardType(const PasteboardURL& pasteboardURL)
+{
+    // A trustworthy URL pasteboard type needs to be decided on
+    // before we allow calls to this function. A page data transfer
+    // should not use the same pasteboard type as this function for
+    // URLs.
+    ASSERT_NOT_REACHED();
+}
+
 void Pasteboard::writePasteboard(const Pasteboard&)
 {
 }
index 929bb30..3657d4b 100644 (file)
@@ -234,6 +234,13 @@ void Pasteboard::write(const PasteboardURL& pasteboardURL)
     m_changeCount = writeURLForTypes(writableTypesForURL(), m_pasteboardName, pasteboardURL);
 }
 
+void Pasteboard::writeTrustworthyWebURLsPboardType(const PasteboardURL& pasteboardURL)
+{
+    NSURL *cocoaURL = pasteboardURL.url;
+    Vector<String> paths = { [cocoaURL absoluteString], pasteboardURL.title.stripWhiteSpace() };
+    m_changeCount = platformStrategies()->pasteboardStrategy()->setPathnamesForType(paths, WebURLsWithTitlesPboardType, m_pasteboardName);
+}
+
 static NSFileWrapper* fileWrapper(const PasteboardImage& pasteboardImage)
 {
     NSFileWrapper *wrapper = [[[NSFileWrapper alloc] initRegularFileWithContents:pasteboardImage.resourceData->createNSData().get()] autorelease];
index c3d587a..95d0e36 100644 (file)
@@ -721,6 +721,11 @@ void Pasteboard::write(const PasteboardURL& pasteboardURL)
     writeURLToDataObject(pasteboardURL.url, pasteboardURL.title);
 }
 
+void Pasteboard::writeTrustworthyWebURLsPboardType(const PasteboardURL&)
+{
+    notImplemented();
+}
+
 void Pasteboard::writeImage(Element& element, const URL&, const String&)
 {
     if (!is<RenderImage>(element.renderer()))