Title: [113596] trunk
Revision
113596
Author
[email protected]
Date
2012-04-09 11:19:00 -0700 (Mon, 09 Apr 2012)

Log Message

Filter files from dataTransfer.getData on Mac
https://bugs.webkit.org/show_bug.cgi?id=38876

Reviewed by Enrica Casucci.

Source/WebCore:

The ClipboardMac class now keeps track of whether it was created for copy and paste, dragging and dropping
files or dragging and dropping generic data. This enables the class to block calls to set-/getData when the
clipboard is not operating on generic data, and vice-versa.

Test: fast/events/drop-with-file-paths.html

* editing/mac/EditorMac.mm:
(WebCore::Editor::newGeneralClipboard):
* page/mac/EventHandlerMac.mm:
(WebCore::EventHandler::createDraggingClipboard):
* platform/mac/ClipboardMac.h:
(WebCore::ClipboardMac::create):
(ClipboardMac):
* platform/mac/ClipboardMac.mm:
(WebCore::Clipboard::create):
(WebCore::ClipboardMac::ClipboardMac):
(WebCore::ClipboardMac::getData):
(WebCore::ClipboardMac::setData):
(WebCore::ClipboardMac::files):

LayoutTests:

* fast/events/drop-with-file-paths-expected.txt: Added.
* fast/events/drop-with-file-paths.html: Added.
* fast/events/resources/file-for-drop-with-file-paths.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (113595 => 113596)


--- trunk/LayoutTests/ChangeLog	2012-04-09 18:13:44 UTC (rev 113595)
+++ trunk/LayoutTests/ChangeLog	2012-04-09 18:19:00 UTC (rev 113596)
@@ -1,3 +1,14 @@
+2012-04-09  Jeffrey Pfau  <[email protected]>
+
+        Filter files from dataTransfer.getData on Mac
+        https://bugs.webkit.org/show_bug.cgi?id=38876
+
+        Reviewed by Enrica Casucci.
+
+        * fast/events/drop-with-file-paths-expected.txt: Added.
+        * fast/events/drop-with-file-paths.html: Added.
+        * fast/events/resources/file-for-drop-with-file-paths.html: Added.
+
 2012-04-09  Robert Hogan  <[email protected]>
 
         Fix layout test for r113584 on Qt and Mac

Added: trunk/LayoutTests/fast/events/drop-with-file-paths-expected.txt (0 => 113596)


--- trunk/LayoutTests/fast/events/drop-with-file-paths-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/events/drop-with-file-paths-expected.txt	2012-04-09 18:19:00 UTC (rev 113596)
@@ -0,0 +1 @@
+PASS

Added: trunk/LayoutTests/fast/events/drop-with-file-paths.html (0 => 113596)


--- trunk/LayoutTests/fast/events/drop-with-file-paths.html	                        (rev 0)
+++ trunk/LayoutTests/fast/events/drop-with-file-paths.html	2012-04-09 18:19:00 UTC (rev 113596)
@@ -0,0 +1,39 @@
+<html>
+<body>
+<script>
+
+function runTest() {
+    if (!window.layoutTestController)
+        return;
+
+    window.layoutTestController.dumpAsText();
+
+    eventSender.beginDragWithFiles(['resources/file-for-drop-with-file-paths.html']);
+    eventSender.mouseMoveTo(10, 10);
+    eventSender.mouseUp();
+}
+
+document.body.addEventListener('dragenter',
+    function (e) {
+      e.preventDefault();
+    });
+document.body.addEventListener('dragover',
+    function (e) {
+      e.preventDefault();
+    });
+document.body.addEventListener('drop',
+    function (e) {
+      data = ""
+      if (data) {
+        document.body.innerHTML += '<p>Dropped file: ' + data + '</p>';
+        document.body.innerHTML += 'Dropped types: ' + e.dataTransfer.types;
+      } else
+        document.body.innerHTML = 'PASS';
+      e.preventDefault();
+    });
+
+window._onload_ = runTest;
+</script>
+<p>Drop files anywhere on this page. The page will try to intercept the drop--it should succeed but not be able to use dataTransfer.getData</p>
+</body>
+</html>

Added: trunk/LayoutTests/fast/events/resources/file-for-drop-with-file-paths.html (0 => 113596)


--- trunk/LayoutTests/fast/events/resources/file-for-drop-with-file-paths.html	                        (rev 0)
+++ trunk/LayoutTests/fast/events/resources/file-for-drop-with-file-paths.html	2012-04-09 18:19:00 UTC (rev 113596)
@@ -0,0 +1 @@
+FAIL

Modified: trunk/Source/WebCore/ChangeLog (113595 => 113596)


--- trunk/Source/WebCore/ChangeLog	2012-04-09 18:13:44 UTC (rev 113595)
+++ trunk/Source/WebCore/ChangeLog	2012-04-09 18:19:00 UTC (rev 113596)
@@ -1,3 +1,30 @@
+2012-04-09  Jeffrey Pfau  <[email protected]>
+
+        Filter files from dataTransfer.getData on Mac
+        https://bugs.webkit.org/show_bug.cgi?id=38876
+
+        Reviewed by Enrica Casucci.
+
+        The ClipboardMac class now keeps track of whether it was created for copy and paste, dragging and dropping
+        files or dragging and dropping generic data. This enables the class to block calls to set-/getData when the
+        clipboard is not operating on generic data, and vice-versa.
+
+        Test: fast/events/drop-with-file-paths.html
+
+        * editing/mac/EditorMac.mm:
+        (WebCore::Editor::newGeneralClipboard):
+        * page/mac/EventHandlerMac.mm:
+        (WebCore::EventHandler::createDraggingClipboard):
+        * platform/mac/ClipboardMac.h:
+        (WebCore::ClipboardMac::create):
+        (ClipboardMac):
+        * platform/mac/ClipboardMac.mm:
+        (WebCore::Clipboard::create):
+        (WebCore::ClipboardMac::ClipboardMac):
+        (WebCore::ClipboardMac::getData):
+        (WebCore::ClipboardMac::setData):
+        (WebCore::ClipboardMac::files):
+
 2012-04-09  Sheriff Bot  <[email protected]>
 
         Unreviewed, rolling out r113561.

Modified: trunk/Source/WebCore/editing/mac/EditorMac.mm (113595 => 113596)


--- trunk/Source/WebCore/editing/mac/EditorMac.mm	2012-04-09 18:13:44 UTC (rev 113595)
+++ trunk/Source/WebCore/editing/mac/EditorMac.mm	2012-04-09 18:19:00 UTC (rev 113596)
@@ -51,7 +51,7 @@
 PassRefPtr<Clipboard> Editor::newGeneralClipboard(ClipboardAccessPolicy policy, Frame* frame)
 {
     return ClipboardMac::create(Clipboard::CopyAndPaste,
-        policy == ClipboardWritable ? platformStrategies()->pasteboardStrategy()->uniqueName() : String(NSGeneralPboard), policy, frame);
+        policy == ClipboardWritable ? platformStrategies()->pasteboardStrategy()->uniqueName() : String(NSGeneralPboard), policy, ClipboardMac::CopyAndPasteGeneric, frame);
 }
 
 void Editor::showFontPanel()

Modified: trunk/Source/WebCore/page/mac/EventHandlerMac.mm (113595 => 113596)


--- trunk/Source/WebCore/page/mac/EventHandlerMac.mm	2012-04-09 18:13:44 UTC (rev 113595)
+++ trunk/Source/WebCore/page/mac/EventHandlerMac.mm	2012-04-09 18:19:00 UTC (rev 113596)
@@ -673,7 +673,7 @@
     // also done for security, as it erases data from the last drag
     Pasteboard pasteboard(NSDragPboard);
     pasteboard.clear();
-    return ClipboardMac::create(Clipboard::DragAndDrop, String(NSDragPboard), ClipboardWritable, m_frame);
+    return ClipboardMac::create(Clipboard::DragAndDrop, String(NSDragPboard), ClipboardWritable, ClipboardMac::DragAndDropData, m_frame);
 }
 
 #endif

Modified: trunk/Source/WebCore/platform/mac/ClipboardMac.h (113595 => 113596)


--- trunk/Source/WebCore/platform/mac/ClipboardMac.h	2012-04-09 18:13:44 UTC (rev 113595)
+++ trunk/Source/WebCore/platform/mac/ClipboardMac.h	2012-04-09 18:19:00 UTC (rev 113596)
@@ -40,9 +40,15 @@
 class ClipboardMac : public Clipboard, public CachedImageClient {
     WTF_MAKE_FAST_ALLOCATED;
 public:
-    static PassRefPtr<ClipboardMac> create(ClipboardType clipboardType, const String& pasteboardName, ClipboardAccessPolicy policy, Frame* frame)
+    enum ClipboardContents {
+        DragAndDropData,
+        DragAndDropFiles,
+        CopyAndPasteGeneric
+    };
+
+    static PassRefPtr<ClipboardMac> create(ClipboardType clipboardType, const String& pasteboardName, ClipboardAccessPolicy policy, ClipboardContents clipboardContents, Frame* frame)
     {
-        return adoptRef(new ClipboardMac(clipboardType, pasteboardName, policy, frame));
+        return adoptRef(new ClipboardMac(clipboardType, pasteboardName, policy, clipboardContents, frame));
     }
 
     virtual ~ClipboardMac();
@@ -74,12 +80,13 @@
     const String& pasteboardName() { return m_pasteboardName; }
 
 private:
-    ClipboardMac(ClipboardType, const String& pasteboardName, ClipboardAccessPolicy, Frame*);
+    ClipboardMac(ClipboardType, const String& pasteboardName, ClipboardAccessPolicy, ClipboardContents, Frame*);
 
     void setDragImage(CachedImage*, Node*, const IntPoint&);
 
     String m_pasteboardName;
     int m_changeCount;
+    ClipboardContents m_clipboardContents;
     Frame* m_frame; // used on the source side to generate dragging images
 };
 

Modified: trunk/Source/WebCore/platform/mac/ClipboardMac.mm (113595 => 113596)


--- trunk/Source/WebCore/platform/mac/ClipboardMac.mm	2012-04-09 18:13:44 UTC (rev 113595)
+++ trunk/Source/WebCore/platform/mac/ClipboardMac.mm	2012-04-09 18:19:00 UTC (rev 113596)
@@ -48,12 +48,13 @@
 
 PassRefPtr<Clipboard> Clipboard::create(ClipboardAccessPolicy policy, DragData* dragData, Frame* frame)
 {
-    return ClipboardMac::create(DragAndDrop, dragData->pasteboardName(), policy, frame);
+    return ClipboardMac::create(DragAndDrop, dragData->pasteboardName(), policy, dragData->containsFiles() ? ClipboardMac::DragAndDropFiles : ClipboardMac::DragAndDropData, frame);
 }
 
-ClipboardMac::ClipboardMac(ClipboardType clipboardType, const String& pasteboardName, ClipboardAccessPolicy policy, Frame *frame)
+ClipboardMac::ClipboardMac(ClipboardType clipboardType, const String& pasteboardName, ClipboardAccessPolicy policy, ClipboardContents clipboardContents, Frame *frame)
     : Clipboard(policy, clipboardType)
     , m_pasteboardName(pasteboardName)
+    , m_clipboardContents(clipboardContents)
     , m_frame(frame)
 {
     m_changeCount = platformStrategies()->pasteboardStrategy()->changeCount(m_pasteboardName);
@@ -212,7 +213,7 @@
 
 String ClipboardMac::getData(const String& type) const
 {
-    if (policy() != ClipboardReadable)
+    if (policy() != ClipboardReadable || m_clipboardContents == DragAndDropFiles)
         return String();
 
     const String& cocoaType = cocoaTypeFromHTMLClipboardType(type);
@@ -241,7 +242,7 @@
 
 bool ClipboardMac::setData(const String &type, const String &data)
 {
-    if (policy() != ClipboardWritable)
+    if (policy() != ClipboardWritable || m_clipboardContents == DragAndDropFiles)
         return false;
     // note NSPasteboard enforces changeCount itself on writing - can't write if not the owner
 
@@ -311,7 +312,7 @@
 // clipboard are not reflected in any FileList objects the page has accessed and stored
 PassRefPtr<FileList> ClipboardMac::files() const
 {
-    if (policy() != ClipboardReadable)
+    if (policy() != ClipboardReadable || m_clipboardContents == DragAndDropData)
         return FileList::create();
 
     Vector<String> absoluteURLs = absoluteURLsFromPasteboardFilenames(m_pasteboardName);
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to