From: jpfau@apple.com Date: Mon, 9 Apr 2012 18:19:00 +0000 (+0000) Subject: Filter files from dataTransfer.getData on Mac X-Git-Tag: 070512121124~7541 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=da6d1b912e849bcf0f5d621f0c6701c038e76896;p=profile%2Fivi%2Fwebkit-efl.git 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. git-svn-id: http://svn.webkit.org/repository/webkit/trunk@113596 268f45cc-cd09-0410-ab3c-d52691b4dbfc --- diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog index ffdf7e3..ea3439b 100644 --- a/LayoutTests/ChangeLog +++ b/LayoutTests/ChangeLog @@ -1,3 +1,14 @@ +2012-04-09 Jeffrey Pfau + + 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 Fix layout test for r113584 on Qt and Mac diff --git a/LayoutTests/fast/events/drop-with-file-paths-expected.txt b/LayoutTests/fast/events/drop-with-file-paths-expected.txt new file mode 100644 index 0000000..7ef22e9 --- /dev/null +++ b/LayoutTests/fast/events/drop-with-file-paths-expected.txt @@ -0,0 +1 @@ +PASS diff --git a/LayoutTests/fast/events/drop-with-file-paths.html b/LayoutTests/fast/events/drop-with-file-paths.html new file mode 100644 index 0000000..a1ed04c --- /dev/null +++ b/LayoutTests/fast/events/drop-with-file-paths.html @@ -0,0 +1,39 @@ + + + +

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

+ + diff --git a/LayoutTests/fast/events/resources/file-for-drop-with-file-paths.html b/LayoutTests/fast/events/resources/file-for-drop-with-file-paths.html new file mode 100644 index 0000000..94e1707 --- /dev/null +++ b/LayoutTests/fast/events/resources/file-for-drop-with-file-paths.html @@ -0,0 +1 @@ +FAIL diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog index 00ce364..63fe4ac 100644 --- a/Source/WebCore/ChangeLog +++ b/Source/WebCore/ChangeLog @@ -1,3 +1,30 @@ +2012-04-09 Jeffrey Pfau + + 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 Unreviewed, rolling out r113561. diff --git a/Source/WebCore/editing/mac/EditorMac.mm b/Source/WebCore/editing/mac/EditorMac.mm index 85133dd..8eac82b 100644 --- a/Source/WebCore/editing/mac/EditorMac.mm +++ b/Source/WebCore/editing/mac/EditorMac.mm @@ -51,7 +51,7 @@ using namespace HTMLNames; PassRefPtr 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() diff --git a/Source/WebCore/page/mac/EventHandlerMac.mm b/Source/WebCore/page/mac/EventHandlerMac.mm index 55dd816..6dc5111 100644 --- a/Source/WebCore/page/mac/EventHandlerMac.mm +++ b/Source/WebCore/page/mac/EventHandlerMac.mm @@ -673,7 +673,7 @@ PassRefPtr EventHandler::createDraggingClipboard() const // 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 diff --git a/Source/WebCore/platform/mac/ClipboardMac.h b/Source/WebCore/platform/mac/ClipboardMac.h index 7f6ad85..1fe7398 100644 --- a/Source/WebCore/platform/mac/ClipboardMac.h +++ b/Source/WebCore/platform/mac/ClipboardMac.h @@ -40,9 +40,15 @@ class FileList; class ClipboardMac : public Clipboard, public CachedImageClient { WTF_MAKE_FAST_ALLOCATED; public: - static PassRefPtr create(ClipboardType clipboardType, const String& pasteboardName, ClipboardAccessPolicy policy, Frame* frame) + enum ClipboardContents { + DragAndDropData, + DragAndDropFiles, + CopyAndPasteGeneric + }; + + static PassRefPtr 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 @@ public: 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 }; diff --git a/Source/WebCore/platform/mac/ClipboardMac.mm b/Source/WebCore/platform/mac/ClipboardMac.mm index e006bdb..4d0b877 100644 --- a/Source/WebCore/platform/mac/ClipboardMac.mm +++ b/Source/WebCore/platform/mac/ClipboardMac.mm @@ -48,12 +48,13 @@ namespace WebCore { PassRefPtr 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 @@ static Vector absoluteURLsFromPasteboard(const String& pasteboardName, b 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 @@ String ClipboardMac::getData(const String& type) const 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 @@ HashSet ClipboardMac::types() const // clipboard are not reflected in any FileList objects the page has accessed and stored PassRefPtr ClipboardMac::files() const { - if (policy() != ClipboardReadable) + if (policy() != ClipboardReadable || m_clipboardContents == DragAndDropData) return FileList::create(); Vector absoluteURLs = absoluteURLsFromPasteboardFilenames(m_pasteboardName);