Changeset 221343 in webkit


Ignore:
Timestamp:
Aug 29, 2017, 10:09:23 PM (8 years ago)
Author:
Wenson Hsieh
Message:

REGRESSION(r210287) On drop, event.dataTransfer.getData("text") returns an empty string when dragging an image
https://bugs.webkit.org/show_bug.cgi?id=170637
<rdar://problem/31347248>

Reviewed by Ryosuke Niwa.

Source/WebCore:

In r210287, the behavior of DragData::containsFiles was changed to return true if NSFilesPromisePboardType is
present in the pasteboard. This means that we will consider images dragged from web content, for which we add
the NSFilesPromisePboardType UTI, as containing files on the pasteboard; this, in turn, means we'll initialize
the DataTransfer upon drop with m_forFileDrag set to true. Due to early returns in getData() and setData() to
deny data access when dropping a dragged file, this means the page won't ever get access to the URL in the
pasteboard due to the presence of the NSFilesPromisePboardType UTI.

To fix this, we replace the early m_forFileDrag returns in getData and setData, instead early returning the null
string if there are any file URLs present on the pasteboard (determined via readFilenames() retrieving a non-
empty result).

Test: editing/pasteboard/drag-drop-href-as-text-data.html

  • dom/DataTransfer.cpp:

(WebCore::DataTransfer::DataTransfer):
(WebCore::DataTransfer::getData const):
(WebCore::DataTransfer::setData):

Rather than bail upon forFileDrag() (formerly, m_forFileDrag) being true, bail if there are any file URLs
present on the pasteboard. It seems like this was the intention of the early return in the first place, to
prevent the page from being able to ask for a real file URL when dragging a file.

(WebCore::DataTransfer::files const):
(WebCore::DataTransfer::setDragImage):
(WebCore::DataTransfer::setDropEffect):
(WebCore::DataTransfer::setEffectAllowed):

Swap m_forDrag and m_forFileDrag with forDrag() and forFileDrag(), respectively.

  • dom/DataTransfer.h:

(WebCore::DataTransfer::forDrag const):
(WebCore::DataTransfer::forFileDrag const):

Instead of caching two bools to represent state (m_forDrag and m_forFileDrag), just remember the DataTransfer's
m_type and turn the flags into const helpers that check for the value of m_type.

LayoutTests:

Adds a new test to verify that upon dropping an image enclosed within an anchor, DataTransfer.getData() can be
used to grab the href of the enclosing anchor.

  • TestExpectations:
  • editing/pasteboard/drag-drop-href-as-text-data-expected.txt: Added.
  • editing/pasteboard/drag-drop-href-as-text-data.html: Added.
  • platform/mac-wk1/TestExpectations:
Location:
trunk
Files:
2 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r221336 r221343  
     12017-08-29  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        REGRESSION(r210287) On drop, event.dataTransfer.getData("text") returns an empty string when dragging an image
     4        https://bugs.webkit.org/show_bug.cgi?id=170637
     5        <rdar://problem/31347248>
     6
     7        Reviewed by Ryosuke Niwa.
     8
     9        Adds a new test to verify that upon dropping an image enclosed within an anchor, DataTransfer.getData() can be
     10        used to grab the href of the enclosing anchor.
     11
     12        * TestExpectations:
     13        * editing/pasteboard/drag-drop-href-as-text-data-expected.txt: Added.
     14        * editing/pasteboard/drag-drop-href-as-text-data.html: Added.
     15        * platform/mac-wk1/TestExpectations:
     16
    1172017-08-29  Devin Rousso  <webkit@devinrousso.com>
    218
  • trunk/LayoutTests/TestExpectations

    r221170 r221343  
    6464fast/events/autoscroll-when-zoomed.html [ Skip ]
    6565fast/events/autoscroll-main-document.html [ Skip ]
     66
     67# Drag and drop via EventSender is only supported on Mac WK1
     68editing/pasteboard/drag-drop-href-as-text-data.html [ Skip ]
    6669
    6770# Only iOS supports QuickLook
  • trunk/LayoutTests/platform/mac-wk1/TestExpectations

    r221234 r221343  
    77
    88fast/forms/attributed-strings.html [ Pass ]
     9editing/pasteboard/drag-drop-href-as-text-data.html [ Pass ]
    910
    1011#//////////////////////////////////////////////////////////////////////////////////////////
  • trunk/Source/WebCore/ChangeLog

    r221342 r221343  
     12017-08-29  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        REGRESSION(r210287) On drop, event.dataTransfer.getData("text") returns an empty string when dragging an image
     4        https://bugs.webkit.org/show_bug.cgi?id=170637
     5        <rdar://problem/31347248>
     6
     7        Reviewed by Ryosuke Niwa.
     8
     9        In r210287, the behavior of DragData::containsFiles was changed to return true if NSFilesPromisePboardType is
     10        present in the pasteboard. This means that we will consider images dragged from web content, for which we add
     11        the NSFilesPromisePboardType UTI, as containing files on the pasteboard; this, in turn, means we'll initialize
     12        the DataTransfer upon drop with m_forFileDrag set to true. Due to early returns in getData() and setData() to
     13        deny data access when dropping a dragged file, this means the page won't ever get access to the URL in the
     14        pasteboard due to the presence of the NSFilesPromisePboardType UTI.
     15
     16        To fix this, we replace the early m_forFileDrag returns in getData and setData, instead early returning the null
     17        string if there are any file URLs present on the pasteboard (determined via readFilenames() retrieving a non-
     18        empty result).
     19
     20        Test: editing/pasteboard/drag-drop-href-as-text-data.html
     21
     22        * dom/DataTransfer.cpp:
     23        (WebCore::DataTransfer::DataTransfer):
     24        (WebCore::DataTransfer::getData const):
     25        (WebCore::DataTransfer::setData):
     26
     27        Rather than bail upon forFileDrag() (formerly, m_forFileDrag) being true, bail if there are any file URLs
     28        present on the pasteboard. It seems like this was the intention of the early return in the first place, to
     29        prevent the page from being able to ask for a real file URL when dragging a file.
     30
     31        (WebCore::DataTransfer::files const):
     32        (WebCore::DataTransfer::setDragImage):
     33        (WebCore::DataTransfer::setDropEffect):
     34        (WebCore::DataTransfer::setEffectAllowed):
     35
     36        Swap m_forDrag and m_forFileDrag with forDrag() and forFileDrag(), respectively.
     37
     38        * dom/DataTransfer.h:
     39        (WebCore::DataTransfer::forDrag const):
     40        (WebCore::DataTransfer::forFileDrag const):
     41
     42        Instead of caching two bools to represent state (m_forDrag and m_forFileDrag), just remember the DataTransfer's
     43        m_type and turn the flags into const helpers that check for the value of m_type.
     44
    1452017-08-29  Youenn Fablet  <youenn@apple.com>
    246
  • trunk/Source/WebCore/dom/DataTransfer.cpp

    r221067 r221343  
    6262    , m_pasteboard(WTFMove(pasteboard))
    6363#if ENABLE(DRAG_SUPPORT)
    64     , m_forDrag(type == Type::DragAndDropData || type == Type::DragAndDropFiles)
    65     , m_forFileDrag(type == Type::DragAndDropFiles)
     64    , m_type(type)
    6665    , m_dropEffect(ASCIILiteral("uninitialized"))
    6766    , m_effectAllowed(ASCIILiteral("uninitialized"))
     
    138137
    139138#if ENABLE(DRAG_SUPPORT)
    140     if (m_forFileDrag)
    141         return String();
     139    if (forFileDrag() && m_pasteboard->readFilenames().size())
     140        return { };
    142141#endif
    143142
     
    151150
    152151#if ENABLE(DRAG_SUPPORT)
    153     if (m_forFileDrag)
     152    if (forFileDrag() && m_pasteboard->readFilenames().size())
    154153        return;
    155154#endif
     
    188187
    189188#if ENABLE(DRAG_SUPPORT)
    190     if (m_forDrag && !m_forFileDrag) {
     189    if (forDrag() && !forFileDrag()) {
    191190        ASSERT(m_fileList->isEmpty());
    192191        return *m_fileList;
     
    267266void DataTransfer::setDragImage(Element* element, int x, int y)
    268267{
    269     if (!m_forDrag || !canWriteData())
     268    if (!forDrag() || !canWriteData())
    270269        return;
    271270
     
    423422void DataTransfer::setDropEffect(const String& effect)
    424423{
    425     if (!m_forDrag)
     424    if (!forDrag())
    426425        return;
    427426
     
    444443void DataTransfer::setEffectAllowed(const String& effect)
    445444{
    446     if (!m_forDrag)
     445    if (!forDrag())
    447446        return;
    448447
  • trunk/Source/WebCore/dom/DataTransfer.h

    r220951 r221343  
    9999    DataTransfer(StoreMode, std::unique_ptr<Pasteboard>, Type = Type::CopyAndPaste);
    100100
     101#if ENABLE(DRAG_SUPPORT)
     102    bool forDrag() const { return m_type == Type::DragAndDropData || m_type == Type::DragAndDropFiles; }
     103    bool forFileDrag() const { return m_type == Type::DragAndDropFiles; }
     104#endif
     105
    101106    StoreMode m_storeMode;
    102107    std::unique_ptr<Pasteboard> m_pasteboard;
     
    106111
    107112#if ENABLE(DRAG_SUPPORT)
    108     bool m_forDrag;
    109     bool m_forFileDrag;
     113    Type m_type;
    110114    String m_dropEffect;
    111115    String m_effectAllowed;
Note: See TracChangeset for help on using the changeset viewer.