Data store should be readable in dragstart/copy/cut events
authordcheng@chromium.org <dcheng@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 22 Mar 2013 20:04:15 +0000 (20:04 +0000)
committerdcheng@chromium.org <dcheng@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 22 Mar 2013 20:04:15 +0000 (20:04 +0000)
https://bugs.webkit.org/show_bug.cgi?id=23695

Reviewed by Tony Chang.

Source/WebCore:

There were several events where data could be written but not read back due to the fact that
different Clipboard method implementations checked permissions inconsistently. This patch
adds helper methods to check if an operation is permitted on a Clipboard and refactors all
direct comparisons against Clipboard::m_policy to use the new helpers instead. This fixes
several bugs where Clipboard::types and Clipboard::getData are not usable inside the
aforementioned events.

Tests: editing/pasteboard/can-read-in-copy-and-cut-events.html
       editing/pasteboard/can-read-in-dragstart-event.html

* dom/Clipboard.cpp:
(WebCore::Clipboard::canReadTypes): Formerly restricted to ClipboardReadable and
                                    ClipboardTypesReadable; now allows ClipboardWritable as
                                    well.
(WebCore::Clipboard::canReadData): Formerly restricted to ClipboardReadable; now allows
                                   ClipboardWritable as well.
(WebCore::Clipboard::canWriteData):
(WebCore::Clipboard::canSetDragImage):
(WebCore::Clipboard::hasFileOfType):
(WebCore::Clipboard::hasStringOfType):
(WebCore::Clipboard::setDropEffect):
(WebCore::Clipboard::setEffectAllowed):
* dom/Clipboard.h:
(Clipboard):
* platform/blackberry/ClipboardBlackBerry.cpp:
(WebCore::ClipboardBlackBerry::clearData):
(WebCore::ClipboardBlackBerry::clearAllData):
(WebCore::ClipboardBlackBerry::getData):
(WebCore::ClipboardBlackBerry::setData):
(WebCore::ClipboardBlackBerry::types):
* platform/chromium/ClipboardChromium.cpp:
(WebCore::DataTransferItemPolicyWrapper::kind):
(WebCore::DataTransferItemPolicyWrapper::type):
(WebCore::DataTransferItemPolicyWrapper::getAsString):
(WebCore::DataTransferItemPolicyWrapper::getAsFile):
(WebCore::ClipboardChromium::clearData):
(WebCore::ClipboardChromium::clearAllData):
(WebCore::ClipboardChromium::getData):
(WebCore::ClipboardChromium::setData):
(WebCore::ClipboardChromium::types):
(WebCore::ClipboardChromium::files):
(WebCore::ClipboardChromium::setDragImage):
* platform/gtk/ClipboardGtk.cpp:
(WebCore::ClipboardGtk::clearData):
(WebCore::ClipboardGtk::clearAllData):
(WebCore::ClipboardGtk::getData):
(WebCore::ClipboardGtk::setData):
(WebCore::ClipboardGtk::types):
(WebCore::ClipboardGtk::files):
(WebCore::ClipboardGtk::setDragImage):
* platform/mac/ClipboardMac.mm:
(WebCore::ClipboardMac::clearData):
(WebCore::ClipboardMac::clearAllData):
(WebCore::ClipboardMac::getData):
(WebCore::ClipboardMac::setData):
(WebCore::ClipboardMac::types):
(WebCore::ClipboardMac::files):
(WebCore::ClipboardMac::setDragImage):
* platform/qt/ClipboardQt.cpp:
(WebCore::ClipboardQt::clearData):
(WebCore::ClipboardQt::clearAllData):
(WebCore::ClipboardQt::getData):
(WebCore::ClipboardQt::setData):
(WebCore::ClipboardQt::types):
(WebCore::ClipboardQt::files):
(WebCore::ClipboardQt::setDragImage):
(WebCore::ClipboardQt::items):
* platform/qt/DataTransferItemListQt.cpp:
(WebCore::DataTransferItemListQt::length):
(WebCore::DataTransferItemListQt::item):
(WebCore::DataTransferItemListQt::deleteItem):
(WebCore::DataTransferItemListQt::clear):
(WebCore::DataTransferItemListQt::add):
* platform/qt/DataTransferItemQt.cpp:
(WebCore::DataTransferItemQt::getAsString):
* platform/win/ClipboardWin.cpp:
(WebCore::ClipboardWin::clearData):
(WebCore::ClipboardWin::clearAllData):
(WebCore::ClipboardWin::getData):
(WebCore::ClipboardWin::setData):
(WebCore::ClipboardWin::types):
(WebCore::ClipboardWin::files):
(WebCore::ClipboardWin::setDragImage):

LayoutTests:

* editing/pasteboard/can-read-in-copy-and-cut-events-expected.txt: Added.
* editing/pasteboard/can-read-in-copy-and-cut-events.html: Added.
* editing/pasteboard/can-read-in-dragstart-event-expected.txt: Added.
* editing/pasteboard/can-read-in-dragstart-event.html: Added.

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

16 files changed:
LayoutTests/ChangeLog
LayoutTests/editing/pasteboard/can-read-in-copy-and-cut-events-expected.txt [new file with mode: 0644]
LayoutTests/editing/pasteboard/can-read-in-copy-and-cut-events.html [new file with mode: 0644]
LayoutTests/editing/pasteboard/can-read-in-dragstart-event-expected.txt [new file with mode: 0644]
LayoutTests/editing/pasteboard/can-read-in-dragstart-event.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/dom/Clipboard.cpp
Source/WebCore/dom/Clipboard.h
Source/WebCore/platform/blackberry/ClipboardBlackBerry.cpp
Source/WebCore/platform/chromium/ClipboardChromium.cpp
Source/WebCore/platform/gtk/ClipboardGtk.cpp
Source/WebCore/platform/mac/ClipboardMac.mm
Source/WebCore/platform/qt/ClipboardQt.cpp
Source/WebCore/platform/qt/DataTransferItemListQt.cpp
Source/WebCore/platform/qt/DataTransferItemQt.cpp
Source/WebCore/platform/win/ClipboardWin.cpp

index e24b978..6776ba1 100644 (file)
@@ -1,3 +1,15 @@
+2013-03-22  Daniel Cheng  <dcheng@chromium.org>
+
+        Data store should be readable in dragstart/copy/cut events
+        https://bugs.webkit.org/show_bug.cgi?id=23695
+
+        Reviewed by Tony Chang.
+
+        * editing/pasteboard/can-read-in-copy-and-cut-events-expected.txt: Added.
+        * editing/pasteboard/can-read-in-copy-and-cut-events.html: Added.
+        * editing/pasteboard/can-read-in-dragstart-event-expected.txt: Added.
+        * editing/pasteboard/can-read-in-dragstart-event.html: Added.
+
 2013-03-22  Stephen Chenney  <schenney@chromium.org>
 
         [Chromium] Test expectation after Skia changes
diff --git a/LayoutTests/editing/pasteboard/can-read-in-copy-and-cut-events-expected.txt b/LayoutTests/editing/pasteboard/can-read-in-copy-and-cut-events-expected.txt
new file mode 100644 (file)
index 0000000..88c4aec
--- /dev/null
@@ -0,0 +1,5 @@
+Simple test that data set during a copy/cut event can be read back. To run the test manually, simply select any text and initiate a copy/cut operation.
+
+copy: SUCCESS
+cut: SUCCESS
+
diff --git a/LayoutTests/editing/pasteboard/can-read-in-copy-and-cut-events.html b/LayoutTests/editing/pasteboard/can-read-in-copy-and-cut-events.html
new file mode 100644 (file)
index 0000000..8694832
--- /dev/null
@@ -0,0 +1,42 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script>
+function log(text) {
+    var log = document.getElementById('log');
+    log.appendChild(document.createTextNode(text));
+    log.appendChild(document.createElement('br'));
+}
+
+function copyTest(e) {
+    e.clipboardData.setData('text/plain', 'copy test');
+    if (event.clipboardData.types.indexOf('text/plain') < 0 ||
+        event.clipboardData.getData('text/plain') != 'copy test')
+        log('copy: FAILED');
+    else
+        log('copy: SUCCESS');
+}
+
+function cutTest(e) {
+    e.clipboardData.setData('text/plain', 'cut test');
+    if (event.clipboardData.types.indexOf('text/plain') < 0 ||
+        event.clipboardData.getData('text/plain') != 'cut test')
+        log('cut: FAILED');
+    else
+        log('cut: SUCCESS');
+}
+
+function runTest() {
+    if (!window.testRunner)
+        return;
+    testRunner.dumpAsText();
+    document.execCommand('copy');
+    document.execCommand('cut');
+}
+</script>
+</head>
+<body onload="runTest()" oncopy="copyTest(event)" oncut="cutTest(event)">
+<p>Simple test that data set during a copy/cut event can be read back. To run
+the test manually, simply select any text and initiate a copy/cut operation.
+<div id="log"></div>
+</html>
diff --git a/LayoutTests/editing/pasteboard/can-read-in-dragstart-event-expected.txt b/LayoutTests/editing/pasteboard/can-read-in-dragstart-event-expected.txt
new file mode 100644 (file)
index 0000000..c2403e0
--- /dev/null
@@ -0,0 +1,5 @@
+Simple test that data set during a dragstart event can be read back. To run the test manually, simply start dragging the 'Drag Me' element below.
+
+Drag Me
+dragstart: SUCCESS
+
diff --git a/LayoutTests/editing/pasteboard/can-read-in-dragstart-event.html b/LayoutTests/editing/pasteboard/can-read-in-dragstart-event.html
new file mode 100644 (file)
index 0000000..961e5e8
--- /dev/null
@@ -0,0 +1,42 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script>
+function log(text) {
+    var log = document.getElementById('log');
+    log.appendChild(document.createTextNode(text));
+    log.appendChild(document.createElement('br'));
+}
+
+function dragStartTest(e) {
+    e.dataTransfer.setData('text/plain', 'dragstart test');
+    if (event.dataTransfer.types.indexOf('text/plain') < 0 ||
+        event.dataTransfer.getData('text/plain') != 'dragstart test')
+        log('dragstart: FAILED');
+    else
+        log('dragstart: SUCCESS');
+}
+
+function runTest() {
+    if (!window.testRunner)
+        return;
+    testRunner.dumpAsText();
+
+    var draggedElement = document.getElementById('draggedElement');
+    var x = draggedElement.offsetLeft + draggedElement.offsetWidth / 2;
+    var y = draggedElement.offsetTop + draggedElement.offsetHeight / 2;
+
+    eventSender.mouseMoveTo(x, y);
+    eventSender.mouseDown();
+    eventSender.leapForward(100);
+    eventSender.mouseMoveTo(x + 100, y + 100);
+    eventSender.mouseUp();
+}
+</script>
+</head>
+<body onload="runTest()">
+<p>Simple test that data set during a dragstart event can be read back. To run
+the test manually, simply start dragging the 'Drag Me' element below.
+<div id="draggedElement" draggable="true" ondragstart="dragStartTest(event)">Drag Me</div>
+<div id="log"></div>
+</html>
index 14cf099..57b154a 100644 (file)
@@ -1,3 +1,94 @@
+2013-03-22  Daniel Cheng  <dcheng@chromium.org>
+
+        Data store should be readable in dragstart/copy/cut events
+        https://bugs.webkit.org/show_bug.cgi?id=23695
+
+        Reviewed by Tony Chang.
+
+        There were several events where data could be written but not read back due to the fact that
+        different Clipboard method implementations checked permissions inconsistently. This patch
+        adds helper methods to check if an operation is permitted on a Clipboard and refactors all
+        direct comparisons against Clipboard::m_policy to use the new helpers instead. This fixes
+        several bugs where Clipboard::types and Clipboard::getData are not usable inside the
+        aforementioned events.
+
+        Tests: editing/pasteboard/can-read-in-copy-and-cut-events.html
+               editing/pasteboard/can-read-in-dragstart-event.html
+
+        * dom/Clipboard.cpp:
+        (WebCore::Clipboard::canReadTypes): Formerly restricted to ClipboardReadable and
+                                            ClipboardTypesReadable; now allows ClipboardWritable as
+                                            well.
+        (WebCore::Clipboard::canReadData): Formerly restricted to ClipboardReadable; now allows
+                                           ClipboardWritable as well.
+        (WebCore::Clipboard::canWriteData):
+        (WebCore::Clipboard::canSetDragImage):
+        (WebCore::Clipboard::hasFileOfType):
+        (WebCore::Clipboard::hasStringOfType):
+        (WebCore::Clipboard::setDropEffect):
+        (WebCore::Clipboard::setEffectAllowed):
+        * dom/Clipboard.h:
+        (Clipboard):
+        * platform/blackberry/ClipboardBlackBerry.cpp:
+        (WebCore::ClipboardBlackBerry::clearData):
+        (WebCore::ClipboardBlackBerry::clearAllData):
+        (WebCore::ClipboardBlackBerry::getData):
+        (WebCore::ClipboardBlackBerry::setData):
+        (WebCore::ClipboardBlackBerry::types):
+        * platform/chromium/ClipboardChromium.cpp:
+        (WebCore::DataTransferItemPolicyWrapper::kind):
+        (WebCore::DataTransferItemPolicyWrapper::type):
+        (WebCore::DataTransferItemPolicyWrapper::getAsString):
+        (WebCore::DataTransferItemPolicyWrapper::getAsFile):
+        (WebCore::ClipboardChromium::clearData):
+        (WebCore::ClipboardChromium::clearAllData):
+        (WebCore::ClipboardChromium::getData):
+        (WebCore::ClipboardChromium::setData):
+        (WebCore::ClipboardChromium::types):
+        (WebCore::ClipboardChromium::files):
+        (WebCore::ClipboardChromium::setDragImage):
+        * platform/gtk/ClipboardGtk.cpp:
+        (WebCore::ClipboardGtk::clearData):
+        (WebCore::ClipboardGtk::clearAllData):
+        (WebCore::ClipboardGtk::getData):
+        (WebCore::ClipboardGtk::setData):
+        (WebCore::ClipboardGtk::types):
+        (WebCore::ClipboardGtk::files):
+        (WebCore::ClipboardGtk::setDragImage):
+        * platform/mac/ClipboardMac.mm:
+        (WebCore::ClipboardMac::clearData):
+        (WebCore::ClipboardMac::clearAllData):
+        (WebCore::ClipboardMac::getData):
+        (WebCore::ClipboardMac::setData):
+        (WebCore::ClipboardMac::types):
+        (WebCore::ClipboardMac::files):
+        (WebCore::ClipboardMac::setDragImage):
+        * platform/qt/ClipboardQt.cpp:
+        (WebCore::ClipboardQt::clearData):
+        (WebCore::ClipboardQt::clearAllData):
+        (WebCore::ClipboardQt::getData):
+        (WebCore::ClipboardQt::setData):
+        (WebCore::ClipboardQt::types):
+        (WebCore::ClipboardQt::files):
+        (WebCore::ClipboardQt::setDragImage):
+        (WebCore::ClipboardQt::items):
+        * platform/qt/DataTransferItemListQt.cpp:
+        (WebCore::DataTransferItemListQt::length):
+        (WebCore::DataTransferItemListQt::item):
+        (WebCore::DataTransferItemListQt::deleteItem):
+        (WebCore::DataTransferItemListQt::clear):
+        (WebCore::DataTransferItemListQt::add):
+        * platform/qt/DataTransferItemQt.cpp:
+        (WebCore::DataTransferItemQt::getAsString):
+        * platform/win/ClipboardWin.cpp:
+        (WebCore::ClipboardWin::clearData):
+        (WebCore::ClipboardWin::clearAllData):
+        (WebCore::ClipboardWin::getData):
+        (WebCore::ClipboardWin::setData):
+        (WebCore::ClipboardWin::types):
+        (WebCore::ClipboardWin::files):
+        (WebCore::ClipboardWin::setDragImage):
+
 2013-03-22  Andrei Bucur  <abucur@adobe.com>
 
         [CSS Regions] Remove pushLayoutState(RenderFlowThread*) from RenderView
index 0279925..6910f95 100644 (file)
@@ -51,6 +51,26 @@ void Clipboard::setAccessPolicy(ClipboardAccessPolicy policy)
     m_policy = policy;
 }
 
+bool Clipboard::canReadTypes() const
+{
+    return m_policy == ClipboardReadable || m_policy == ClipboardTypesReadable || m_policy == ClipboardWritable;
+}
+
+bool Clipboard::canReadData() const
+{
+    return m_policy == ClipboardReadable || m_policy == ClipboardWritable;
+}
+
+bool Clipboard::canWriteData() const
+{
+    return m_policy == ClipboardWritable;
+}
+
+bool Clipboard::canSetDragImage() const
+{
+    return m_policy == ClipboardImageWritable || m_policy == ClipboardWritable;
+}
+
 // These "conversion" methods are called by both WebCore and WebKit, and never make sense to JS, so we don't
 // worry about security for these. They don't allow access to the pasteboard anyway.
 
@@ -128,7 +148,7 @@ void Clipboard::setDestinationOperation(DragOperation op)
 
 bool Clipboard::hasFileOfType(const String& type) const
 {
-    if (m_policy != ClipboardReadable && m_policy != ClipboardTypesReadable)
+    if (!canReadTypes())
         return false;
     
     RefPtr<FileList> fileList = files();
@@ -144,7 +164,7 @@ bool Clipboard::hasFileOfType(const String& type) const
 
 bool Clipboard::hasStringOfType(const String& type) const
 {
-    if (m_policy != ClipboardReadable && m_policy != ClipboardTypesReadable)
+    if (!canReadTypes())
         return false;
     
     return types().contains(type); 
@@ -159,7 +179,9 @@ void Clipboard::setDropEffect(const String &effect)
     if (effect != "none" && effect != "copy"  && effect != "link" && effect != "move")
         return;
 
-    if (m_policy == ClipboardReadable || m_policy == ClipboardTypesReadable)
+    // FIXME: The spec actually allows this in all circumstances, even though there's no point in
+    // setting the drop effect when this condition is not true.
+    if (canReadTypes())
         m_dropEffect = effect;
 }
 
@@ -179,7 +201,7 @@ void Clipboard::setEffectAllowed(const String &effect)
     }
 
 
-    if (m_policy == ClipboardWritable)
+    if (canWriteData())
         m_effectAllowed = effect;
 }
     
index d11b652..8864584 100644 (file)
@@ -86,7 +86,14 @@ namespace WebCore {
         virtual bool hasData() = 0;
         
         void setAccessPolicy(ClipboardAccessPolicy);
-        ClipboardAccessPolicy policy() const { return m_policy; }
+        bool canReadTypes() const;
+        bool canReadData() const;
+        bool canWriteData() const;
+        // Note that the spec doesn't actually allow drag image modification outside the dragstart
+        // event. This capability is maintained for backwards compatiblity for ports that have
+        // supported this in the past. On many ports, attempting to set a drag image outside the
+        // dragstart operation is a no-op anyway.
+        bool canSetDragImage() const;
 
         DragOperation sourceOperation() const;
         DragOperation destinationOperation() const;
@@ -109,7 +116,8 @@ namespace WebCore {
     private:
         bool hasFileOfType(const String&) const;
         bool hasStringOfType(const String&) const;
-        
+
+        // Instead of using this member directly, prefer to use the can*() methods above.
         ClipboardAccessPolicy m_policy;
         String m_dropEffect;
         String m_effectAllowed;
index ade22ef..60a44b2 100644 (file)
@@ -42,7 +42,7 @@ ClipboardBlackBerry::~ClipboardBlackBerry()
 
 void ClipboardBlackBerry::clearData(const String& type)
 {
-    if (policy() != ClipboardWritable)
+    if (!canWriteData())
         return;
 
     BlackBerry::Platform::Clipboard::clearClipboardByType(type.utf8().data());
@@ -50,7 +50,7 @@ void ClipboardBlackBerry::clearData(const String& type)
 
 void ClipboardBlackBerry::clearAllData()
 {
-    if (policy() != ClipboardWritable)
+    if (!canWriteData())
         return;
 
     BlackBerry::Platform::Clipboard::clearClipboard();
@@ -58,7 +58,7 @@ void ClipboardBlackBerry::clearAllData()
 
 String ClipboardBlackBerry::getData(const String& type) const
 {
-    if (policy() != ClipboardReadable)
+    if (!canReadData())
         return String();
 
     return String::fromUTF8(BlackBerry::Platform::Clipboard::readClipboardByType(type.utf8().data()).c_str());
@@ -66,7 +66,7 @@ String ClipboardBlackBerry::getData(const String& type) const
 
 bool ClipboardBlackBerry::setData(const String& type, const String& text)
 {
-    if (policy() != ClipboardWritable)
+    if (!canWriteData())
         return false;
 
     if (type == "text/plain")
@@ -80,7 +80,7 @@ bool ClipboardBlackBerry::setData(const String& type, const String& text)
 
 ListHashSet<String> ClipboardBlackBerry::types() const
 {
-    if (policy() != ClipboardReadable && policy() != ClipboardTypesReadable)
+    if (!canReadTypes())
         return ListHashSet<String>();
 
     // We use hardcoded list here since there seems to be no API to get the list.
index fc37278..d0905f2 100644 (file)
@@ -89,14 +89,14 @@ DataTransferItemListPolicyWrapper::~DataTransferItemListPolicyWrapper()
 
 size_t DataTransferItemListPolicyWrapper::length() const
 {
-    if (m_clipboard->policy() == ClipboardNumb)
+    if (!m_clipboard->canReadTypes())
         return 0;
     return m_dataObject->length();
 }
 
 PassRefPtr<DataTransferItem> DataTransferItemListPolicyWrapper::item(unsigned long index)
 {
-    if (m_clipboard->policy() == ClipboardNumb)
+    if (!m_clipboard->canReadTypes())
         return 0;
     RefPtr<ChromiumDataObjectItem> item = m_dataObject->item(index);
     if (!item)
@@ -107,7 +107,7 @@ PassRefPtr<DataTransferItem> DataTransferItemListPolicyWrapper::item(unsigned lo
 
 void DataTransferItemListPolicyWrapper::deleteItem(unsigned long index, ExceptionCode& ec)
 {
-    if (m_clipboard->policy() != ClipboardWritable) {
+    if (!m_clipboard->canWriteData()) {
         ec = INVALID_STATE_ERR;
         return;
     }
@@ -116,21 +116,21 @@ void DataTransferItemListPolicyWrapper::deleteItem(unsigned long index, Exceptio
 
 void DataTransferItemListPolicyWrapper::clear()
 {
-    if (m_clipboard->policy() != ClipboardWritable)
+    if (!m_clipboard->canWriteData())
         return;
     m_dataObject->clearAll();
 }
 
 void DataTransferItemListPolicyWrapper::add(const String& data, const String& type, ExceptionCode& ec)
 {
-    if (m_clipboard->policy() != ClipboardWritable)
+    if (!m_clipboard->canWriteData())
         return;
     m_dataObject->add(data, type, ec);
 }
 
 void DataTransferItemListPolicyWrapper::add(PassRefPtr<File> file)
 {
-    if (m_clipboard->policy() != ClipboardWritable)
+    if (!m_clipboard->canWriteData())
         return;
     m_dataObject->add(file, m_clipboard->frame()->document()->scriptExecutionContext());
 }
@@ -156,21 +156,21 @@ DataTransferItemPolicyWrapper::~DataTransferItemPolicyWrapper()
 
 String DataTransferItemPolicyWrapper::kind() const
 {
-    if (m_clipboard->policy() == ClipboardNumb)
+    if (!m_clipboard->canReadTypes())
         return String();
     return m_item->kind();
 }
 
 String DataTransferItemPolicyWrapper::type() const
 {
-    if (m_clipboard->policy() == ClipboardNumb)
+    if (!m_clipboard->canReadTypes())
         return String();
     return m_item->type();
 }
 
 void DataTransferItemPolicyWrapper::getAsString(PassRefPtr<StringCallback> callback) const
 {
-    if (m_clipboard->policy() != ClipboardReadable && m_clipboard->policy() != ClipboardWritable)
+    if (!m_clipboard->canReadData())
         return;
 
     m_item->getAsString(callback, m_clipboard->frame()->document()->scriptExecutionContext());
@@ -178,7 +178,7 @@ void DataTransferItemPolicyWrapper::getAsString(PassRefPtr<StringCallback> callb
 
 PassRefPtr<Blob> DataTransferItemPolicyWrapper::getAsFile() const
 {
-    if (m_clipboard->policy() != ClipboardReadable && m_clipboard->policy() != ClipboardWritable)
+    if (!m_clipboard->canReadData())
         return 0;
 
     return m_item->getAsFile();
@@ -238,7 +238,7 @@ PassRefPtr<ClipboardChromium> ClipboardChromium::create(ClipboardType clipboardT
 
 void ClipboardChromium::clearData(const String& type)
 {
-    if (policy() != ClipboardWritable)
+    if (!canWriteData())
         return;
 
     m_dataObject->clearData(normalizeType(type));
@@ -248,7 +248,7 @@ void ClipboardChromium::clearData(const String& type)
 
 void ClipboardChromium::clearAllData()
 {
-    if (policy() != ClipboardWritable)
+    if (!canWriteData())
         return;
 
     m_dataObject->clearAll();
@@ -256,7 +256,7 @@ void ClipboardChromium::clearAllData()
 
 String ClipboardChromium::getData(const String& type) const
 {
-    if (policy() != ClipboardReadable)
+    if (!canReadData())
         return String();
 
     bool convertToURL = false;
@@ -268,7 +268,7 @@ String ClipboardChromium::getData(const String& type) const
 
 bool ClipboardChromium::setData(const String& type, const String& data)
 {
-    if (policy() != ClipboardWritable)
+    if (!canWriteData())
         return false;
 
     return m_dataObject->setData(normalizeType(type), data);
@@ -277,7 +277,7 @@ bool ClipboardChromium::setData(const String& type, const String& data)
 // extensions beyond IE's API
 ListHashSet<String> ClipboardChromium::types() const
 {
-    if (policy() != ClipboardReadable && policy() != ClipboardTypesReadable)
+    if (!canReadTypes())
         return ListHashSet<String>();
 
     return m_dataObject->types();
@@ -286,7 +286,7 @@ ListHashSet<String> ClipboardChromium::types() const
 PassRefPtr<FileList> ClipboardChromium::files() const
 {
     RefPtr<FileList> files = FileList::create();
-    if (policy() != ClipboardReadable)
+    if (!canReadData())
         return files.release();
 
     for (size_t i = 0; i < m_dataObject->length(); ++i) {
@@ -302,7 +302,7 @@ PassRefPtr<FileList> ClipboardChromium::files() const
 
 void ClipboardChromium::setDragImage(CachedImage* image, Node* node, const IntPoint& loc)
 {
-    if (policy() != ClipboardImageWritable && policy() != ClipboardWritable)
+    if (!canSetDragImage())
         return;
 
     if (m_dragImage)
index 263b6cf..f50460a 100644 (file)
@@ -103,7 +103,7 @@ static ClipboardDataType dataObjectTypeFromHTMLClipboardType(const String& rawTy
 
 void ClipboardGtk::clearData(const String& typeString)
 {
-    if (policy() != ClipboardWritable)
+    if (!canWriteData())
         return;
 
     ClipboardDataType type = dataObjectTypeFromHTMLClipboardType(typeString);
@@ -133,7 +133,7 @@ void ClipboardGtk::clearData(const String& typeString)
 
 void ClipboardGtk::clearAllData()
 {
-    if (policy() != ClipboardWritable)
+    if (!canWriteData())
         return;
 
     // We do not clear filenames. According to the spec: "The clearData() method
@@ -148,7 +148,7 @@ void ClipboardGtk::clearAllData()
 
 String ClipboardGtk::getData(const String& typeString) const
 {
-    if (policy() != ClipboardReadable || !m_dataObject)
+    if (!canReadData() || !m_dataObject)
         return String();
 
     if (m_clipboard)
@@ -169,7 +169,7 @@ String ClipboardGtk::getData(const String& typeString) const
 
 bool ClipboardGtk::setData(const String& typeString, const String& data)
 {
-    if (policy() != ClipboardWritable)
+    if (!canWriteData())
         return false;
 
     bool success = false;
@@ -190,7 +190,7 @@ bool ClipboardGtk::setData(const String& typeString, const String& data)
 
 ListHashSet<String> ClipboardGtk::types() const
 {
-    if (policy() != ClipboardReadable && policy() != ClipboardTypesReadable)
+    if (!canReadTypes())
         return ListHashSet<String>();
 
     if (m_clipboard)
@@ -219,7 +219,7 @@ ListHashSet<String> ClipboardGtk::types() const
 
 PassRefPtr<FileList> ClipboardGtk::files() const
 {
-    if (policy() != ClipboardReadable)
+    if (!canReadData())
         return FileList::create();
 
     if (m_clipboard)
@@ -244,7 +244,7 @@ void ClipboardGtk::setDragImageElement(Node* element, const IntPoint& location)
 
 void ClipboardGtk::setDragImage(CachedImage* image, Node* element, const IntPoint& location)
 {
-    if (policy() != ClipboardImageWritable && policy() != ClipboardWritable)
+    if (!canSetDragImage())
         return;
 
     if (m_dragImage)
index a5b29d9..36a4d8e 100644 (file)
@@ -155,7 +155,7 @@ static void addHTMLClipboardTypesForCocoaType(ListHashSet<String>& resultTypes,
 
 void ClipboardMac::clearData(const String& type)
 {
-    if (policy() != ClipboardWritable)
+    if (!canWriteData())
         return;
 
     // note NSPasteboard enforces changeCount itself on writing - can't write if not the owner
@@ -167,7 +167,7 @@ void ClipboardMac::clearData(const String& type)
 
 void ClipboardMac::clearAllData()
 {
-    if (policy() != ClipboardWritable)
+    if (!canWriteData())
         return;
 
     // note NSPasteboard enforces changeCount itself on writing - can't write if not the owner
@@ -220,7 +220,7 @@ static Vector<String> absoluteURLsFromPasteboard(const String& pasteboardName, b
 
 String ClipboardMac::getData(const String& type) const
 {
-    if (policy() != ClipboardReadable || m_clipboardContents == DragAndDropFiles)
+    if (!canReadData() || m_clipboardContents == DragAndDropFiles)
         return String();
 
     const String& cocoaType = cocoaTypeFromHTMLClipboardType(type);
@@ -249,7 +249,7 @@ String ClipboardMac::getData(const String& type) const
 
 bool ClipboardMac::setData(const String &type, const String &data)
 {
-    if (policy() != ClipboardWritable || m_clipboardContents == DragAndDropFiles)
+    if (!canWriteData() || m_clipboardContents == DragAndDropFiles)
         return false;
     // note NSPasteboard enforces changeCount itself on writing - can't write if not the owner
 
@@ -283,7 +283,7 @@ bool ClipboardMac::setData(const String &type, const String &data)
 
 ListHashSet<String> ClipboardMac::types() const
 {
-    if (policy() != ClipboardReadable && policy() != ClipboardTypesReadable)
+    if (!canReadTypes())
         return ListHashSet<String>();
 
     Vector<String> types;
@@ -312,7 +312,7 @@ ListHashSet<String> ClipboardMac::types() const
 // clipboard are not reflected in any FileList objects the page has accessed and stored
 PassRefPtr<FileList> ClipboardMac::files() const
 {
-    if (policy() != ClipboardReadable || m_clipboardContents == DragAndDropData)
+    if (!canReadData() || m_clipboardContents == DragAndDropData)
         return FileList::create();
 
     Vector<String> absoluteURLs = absoluteURLsFromPasteboardFilenames(m_pasteboardName);
@@ -340,7 +340,7 @@ void ClipboardMac::setDragImageElement(Node *node, const IntPoint &loc)
 
 void ClipboardMac::setDragImage(CachedImage* image, Node *node, const IntPoint &loc)
 {
-    if (policy() == ClipboardImageWritable || policy() == ClipboardWritable) {
+    if (canSetDragImage()) {
         if (m_dragImage)
             m_dragImage->removeClient(this);
         m_dragImage = image;
index 71c91cb..aefef77 100644 (file)
@@ -112,7 +112,7 @@ ClipboardQt::~ClipboardQt()
 
 void ClipboardQt::clearData(const String& type)
 {
-    if (policy() != ClipboardWritable)
+    if (!canWriteData())
         return;
 
     if (m_writableData) {
@@ -131,7 +131,7 @@ void ClipboardQt::clearData(const String& type)
 
 void ClipboardQt::clearAllData()
 {
-    if (policy() != ClipboardWritable)
+    if (!canWriteData())
         return;
 
 #ifndef QT_NO_CLIPBOARD
@@ -146,7 +146,7 @@ void ClipboardQt::clearAllData()
 String ClipboardQt::getData(const String& type) const
 {
 
-    if (policy() != ClipboardReadable)
+    if (!canReadData())
         return String();
 
     if (isHtmlMimeType(type) && m_readableData->hasHtml())
@@ -163,7 +163,7 @@ String ClipboardQt::getData(const String& type) const
 
 bool ClipboardQt::setData(const String& type, const String& data)
 {
-    if (policy() != ClipboardWritable)
+    if (!canWriteData())
         return false;
 
     if (!m_writableData)
@@ -184,7 +184,7 @@ bool ClipboardQt::setData(const String& type, const String& data)
 // extensions beyond IE's API
 ListHashSet<String> ClipboardQt::types() const
 {
-    if (policy() != ClipboardReadable && policy() != ClipboardTypesReadable)
+    if (!canReadTypes())
         return ListHashSet<String>();
 
     ASSERT(m_readableData);
@@ -197,7 +197,7 @@ ListHashSet<String> ClipboardQt::types() const
 
 PassRefPtr<FileList> ClipboardQt::files() const
 {
-    if (policy() != ClipboardReadable || !m_readableData->hasUrls())
+    if (!canReadData() || !m_readableData->hasUrls())
         return FileList::create();
 
     RefPtr<FileList> fileList = FileList::create();
@@ -225,7 +225,7 @@ void ClipboardQt::setDragImageElement(Node* node, const IntPoint& point)
 
 void ClipboardQt::setDragImage(CachedImage* image, Node *node, const IntPoint &loc)
 {
-    if (policy() != ClipboardImageWritable && policy() != ClipboardWritable)
+    if (!canSetDragImage())
         return;
 
     if (m_dragImage)
@@ -359,7 +359,7 @@ PassRefPtr<DataTransferItemList> ClipboardQt::items()
     if (!m_readableData)
         return items;
 
-    if (isForCopyAndPaste() && policy() == ClipboardReadable) {
+    if (isForCopyAndPaste() && canReadData()) {
         const QStringList types = m_readableData->formats();
         for (int i = 0; i < types.count(); ++i)
             items->addPasteboardItem(types.at(i));
index 1806a7f..c4355a8 100644 (file)
@@ -47,7 +47,7 @@ DataTransferItemListQt::DataTransferItemListQt(PassRefPtr<Clipboard> owner, Scri
 
 size_t DataTransferItemListQt::length() const
 {
-    if (m_owner->policy() == ClipboardNumb)
+    if (!m_owner->canReadTypes())
         return 0;
 
     return m_items.size();
@@ -55,7 +55,7 @@ size_t DataTransferItemListQt::length() const
 
 PassRefPtr<DataTransferItem> DataTransferItemListQt::item(unsigned long index)
 {
-    if (m_owner->policy() == ClipboardNumb || index >= length())
+    if (!m_owner->canReadTypes() || index >= length())
         return 0;
 
     return m_items[index];
@@ -63,7 +63,7 @@ PassRefPtr<DataTransferItem> DataTransferItemListQt::item(unsigned long index)
 
 void DataTransferItemListQt::deleteItem(unsigned long index, ExceptionCode& ec)
 {
-    if (m_owner->policy() != ClipboardWritable) {
+    if (!m_owner->canWriteData()) {
         ec = INVALID_STATE_ERR;
         return;
     }
@@ -76,7 +76,7 @@ void DataTransferItemListQt::deleteItem(unsigned long index, ExceptionCode& ec)
 
 void DataTransferItemListQt::clear()
 {
-    if (m_owner->policy() != ClipboardWritable)
+    if (!m_owner->canWriteData())
         return;
 
     m_items.clear();
@@ -85,7 +85,7 @@ void DataTransferItemListQt::clear()
 
 void DataTransferItemListQt::add(const String& data, const String& type, ExceptionCode& ec)
 {
-    if (m_owner->policy() != ClipboardWritable)
+    if (!m_owner->canWriteData())
         return;
 
     // Only one 'string' item with a given type is allowed in the collection.
@@ -101,7 +101,7 @@ void DataTransferItemListQt::add(const String& data, const String& type, Excepti
 
 void DataTransferItemListQt::add(PassRefPtr<File> file)
 {
-    if (m_owner->policy() != ClipboardWritable || !file)
+    if (!m_owner->canWriteData() || !file)
         return;
 
     m_items.append(DataTransferItem::create(m_owner, m_context, file));
index 9ff621e..d7e9b77 100644 (file)
@@ -95,8 +95,7 @@ DataTransferItemQt::DataTransferItemQt(PassRefPtr<Clipboard> owner,
 
 void DataTransferItemQt::getAsString(PassRefPtr<StringCallback> callback) const
 {
-    if ((owner()->policy() != ClipboardReadable && owner()->policy() != ClipboardWritable)
-        || kind() != kindString)
+    if (!owner()->policy()->canReadData() || kind() != kindString)
         return;
 
     if (m_dataSource == InternalSource) {
index c2f9964..7ca3165 100644 (file)
@@ -407,7 +407,7 @@ void ClipboardWin::clearData(const String& type)
 {
     // FIXME: Need to be able to write to the system clipboard <rdar://problem/5015941>
     ASSERT(isForDragAndDrop());
-    if (policy() != ClipboardWritable || !m_writableDataObject)
+    if (!canWriteData() || !m_writableDataObject)
         return;
 
     ClipboardDataType dataType = clipboardTypeFromMIMEType(type);
@@ -427,7 +427,7 @@ void ClipboardWin::clearAllData()
 {
     // FIXME: Need to be able to write to the system clipboard <rdar://problem/5015941>
     ASSERT(isForDragAndDrop());
-    if (policy() != ClipboardWritable)
+    if (!canWriteData())
         return;
     
     m_writableDataObject = 0;
@@ -437,7 +437,7 @@ void ClipboardWin::clearAllData()
 
 String ClipboardWin::getData(const String& type) const
 {     
-    if (policy() != ClipboardReadable || (!m_dataObject && m_dragDataMap.isEmpty()))
+    if (!canReadData() || (!m_dataObject && m_dragDataMap.isEmpty()))
         return "";
 
     ClipboardDataType dataType = clipboardTypeFromMIMEType(type);
@@ -459,7 +459,7 @@ bool ClipboardWin::setData(const String& type, const String& data)
 {
     // FIXME: Need to be able to write to the system clipboard <rdar://problem/5015941>
     ASSERT(isForDragAndDrop());
-    if (policy() != ClipboardWritable || !m_writableDataObject)
+    if (!canWriteData() || !m_writableDataObject)
         return false;
 
     ClipboardDataType winType = clipboardTypeFromMIMEType(type);
@@ -502,7 +502,7 @@ static void addMimeTypesForFormat(ListHashSet<String>& results, const FORMATETC&
 ListHashSet<String> ClipboardWin::types() const
 { 
     ListHashSet<String> results;
-    if (policy() != ClipboardReadable && policy() != ClipboardTypesReadable)
+    if (!canReadTypes())
         return results;
 
     if (!m_dataObject && m_dragDataMap.isEmpty())
@@ -540,7 +540,7 @@ PassRefPtr<FileList> ClipboardWin::files() const
     return 0;
 #else
     RefPtr<FileList> files = FileList::create();
-    if (policy() != ClipboardReadable && policy() != ClipboardTypesReadable)
+    if (!canReadData())
         return files.release();
 
     if (!m_dataObject && m_dragDataMap.isEmpty())
@@ -578,7 +578,7 @@ PassRefPtr<FileList> ClipboardWin::files() const
 
 void ClipboardWin::setDragImage(CachedImage* image, Node *node, const IntPoint &loc)
 {
-    if (policy() != ClipboardImageWritable && policy() != ClipboardWritable) 
+    if (!canSetDragImage())
         return;
         
     if (m_dragImage)