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
+2012-04-09 Jeffrey Pfau <jpfau@apple.com>
+
+ 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 <robert@webkit.org>
Fix layout test for r113584 on Qt and Mac
--- /dev/null
+<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 = e.dataTransfer.getData('text/uri-list');
+ 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>
+2012-04-09 Jeffrey Pfau <jpfau@apple.com>
+
+ 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 <webkit.review.bot@gmail.com>
Unreviewed, rolling out r113561.
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()
// 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
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();
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
};
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);
String ClipboardMac::getData(const String& type) const
{
- if (policy() != ClipboardReadable)
+ if (policy() != ClipboardReadable || m_clipboardContents == DragAndDropFiles)
return String();
const String& cocoaType = cocoaTypeFromHTMLClipboardType(type);
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
// 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);