Title: [208576] trunk
Revision
208576
Author
wilan...@apple.com
Date
2016-11-10 20:15:41 -0800 (Thu, 10 Nov 2016)

Log Message

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.

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.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (208575 => 208576)


--- trunk/LayoutTests/ChangeLog	2016-11-11 02:20:48 UTC (rev 208575)
+++ trunk/LayoutTests/ChangeLog	2016-11-11 04:15:41 UTC (rev 208576)
@@ -1,3 +1,17 @@
+2016-11-10  John Wilander  <wilan...@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  <cdu...@apple.com>
 
         REGRESSION (r208522): LayoutTest fast/loader/reload-zero-byte-plugin.html is a flaky failure

Added: trunk/LayoutTests/editing/pasteboard/drag-link-with-data-transfer-adds-trusted-link-to-pasteboard-expected.txt (0 => 208576)


--- trunk/LayoutTests/editing/pasteboard/drag-link-with-data-transfer-adds-trusted-link-to-pasteboard-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/editing/pasteboard/drag-link-with-data-transfer-adds-trusted-link-to-pasteboard-expected.txt	2016-11-11 04:15:41 UTC (rev 208576)
@@ -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
+
+

Added: trunk/LayoutTests/editing/pasteboard/drag-link-with-data-transfer-adds-trusted-link-to-pasteboard.html (0 => 208576)


--- trunk/LayoutTests/editing/pasteboard/drag-link-with-data-transfer-adds-trusted-link-to-pasteboard.html	                        (rev 0)
+++ trunk/LayoutTests/editing/pasteboard/drag-link-with-data-transfer-adds-trusted-link-to-pasteboard.html	2016-11-11 04:15:41 UTC (rev 208576)
@@ -0,0 +1,137 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
+<html>
+<head>
+    <script src=""
+</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="" 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="" 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=""
+<a id="secondAnchorSource" draggable="true" href=""
+
+<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="" 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="" 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=""
+            <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=""
+            <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>

Modified: trunk/LayoutTests/platform/ios-simulator/TestExpectations (208575 => 208576)


--- trunk/LayoutTests/platform/ios-simulator/TestExpectations	2016-11-11 02:20:48 UTC (rev 208575)
+++ trunk/LayoutTests/platform/ios-simulator/TestExpectations	2016-11-11 04:15:41 UTC (rev 208576)
@@ -229,6 +229,7 @@
 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

Modified: trunk/Source/WebCore/ChangeLog (208575 => 208576)


--- trunk/Source/WebCore/ChangeLog	2016-11-11 02:20:48 UTC (rev 208575)
+++ trunk/Source/WebCore/ChangeLog	2016-11-11 04:15:41 UTC (rev 208576)
@@ -1,3 +1,39 @@
+2016-11-10  John Wilander  <wilan...@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  <sabouhall...@apple.com>
 
         REGRESSION(r207182): [iOS] Crash because of passing freed CFDictionaryRef to CG when decoding a sub-sampled large image

Modified: trunk/Source/WebCore/page/DragController.cpp (208575 => 208576)


--- trunk/Source/WebCore/page/DragController.cpp	2016-11-11 02:20:48 UTC (rev 208575)
+++ trunk/Source/WebCore/page/DragController.cpp	2016-11-11 04:15:41 UTC (rev 208576)
@@ -875,6 +875,13 @@
             // 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 = ""
+            pasteboardURL.title = hitTestResult.textContent();
+            dataTransfer.pasteboard().writeTrustworthyWebURLsPboardType(pasteboardURL);
         }
 
         const VisibleSelection& sourceSelection = src.selection().selection();

Modified: trunk/Source/WebCore/platform/Pasteboard.h (208575 => 208576)


--- trunk/Source/WebCore/platform/Pasteboard.h	2016-11-11 02:20:48 UTC (rev 208575)
+++ trunk/Source/WebCore/platform/Pasteboard.h	2016-11-11 04:15:41 UTC (rev 208576)
@@ -166,6 +166,7 @@
     virtual void read(PasteboardWebContentReader&);
 
     virtual void write(const PasteboardURL&);
+    virtual void writeTrustworthyWebURLsPboardType(const PasteboardURL&);
     virtual void write(const PasteboardImage&);
     virtual void write(const PasteboardWebContent&);
 

Modified: trunk/Source/WebCore/platform/efl/PasteboardEfl.cpp (208575 => 208576)


--- trunk/Source/WebCore/platform/efl/PasteboardEfl.cpp	2016-11-11 02:20:48 UTC (rev 208575)
+++ trunk/Source/WebCore/platform/efl/PasteboardEfl.cpp	2016-11-11 04:15:41 UTC (rev 208576)
@@ -96,6 +96,11 @@
     notImplemented();
 }
 
+void Pasteboard::writeTrustworthyWebURLsPboardType(const PasteboardURL&)
+{
+    notImplemented();
+}
+
 void Pasteboard::writeString(const String&, const String&)
 {
     notImplemented();

Modified: trunk/Source/WebCore/platform/gtk/PasteboardGtk.cpp (208575 => 208576)


--- trunk/Source/WebCore/platform/gtk/PasteboardGtk.cpp	2016-11-11 02:20:48 UTC (rev 208575)
+++ trunk/Source/WebCore/platform/gtk/PasteboardGtk.cpp	2016-11-11 04:15:41 UTC (rev 208576)
@@ -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 @@
     writeToClipboard();
 }
 
+void Pasteboard::writeTrustworthyWebURLsPboardType(const PasteboardURL&)
+{
+    notImplemented();
+}
+
 void Pasteboard::write(const PasteboardImage& pasteboardImage)
 {
     m_selectionData->clearAll();

Modified: trunk/Source/WebCore/platform/ios/PasteboardIOS.mm (208575 => 208576)


--- trunk/Source/WebCore/platform/ios/PasteboardIOS.mm	2016-11-11 02:20:48 UTC (rev 208575)
+++ trunk/Source/WebCore/platform/ios/PasteboardIOS.mm	2016-11-11 04:15:41 UTC (rev 208576)
@@ -127,6 +127,15 @@
     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&)
 {
 }

Modified: trunk/Source/WebCore/platform/mac/PasteboardMac.mm (208575 => 208576)


--- trunk/Source/WebCore/platform/mac/PasteboardMac.mm	2016-11-11 02:20:48 UTC (rev 208575)
+++ trunk/Source/WebCore/platform/mac/PasteboardMac.mm	2016-11-11 04:15:41 UTC (rev 208576)
@@ -234,6 +234,13 @@
     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];

Modified: trunk/Source/WebCore/platform/win/PasteboardWin.cpp (208575 => 208576)


--- trunk/Source/WebCore/platform/win/PasteboardWin.cpp	2016-11-11 02:20:48 UTC (rev 208575)
+++ trunk/Source/WebCore/platform/win/PasteboardWin.cpp	2016-11-11 04:15:41 UTC (rev 208576)
@@ -721,6 +721,11 @@
     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()))
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to