REGRESSION(r226396): File paths are inserted when dropping image files
authorwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 7 Feb 2018 21:31:15 +0000 (21:31 +0000)
committerwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 7 Feb 2018 21:31:15 +0000 (21:31 +0000)
commite854999e0e9406cf3a04f1527542ddf8655d0428
treebc434290d3f895251e598dc51536e69a89414807
parentb61940d911bd91a2ae6dfb397021da99bd4b9eee
REGRESSION(r226396): File paths are inserted when dropping image files
https://bugs.webkit.org/show_bug.cgi?id=182557
<rdar://problem/37294120>

Reviewed by Ryosuke Niwa.

Source/WebCore:

Reverts unintended changes in <http://trac.webkit.org/r226396>. Before r226396, WebContentReader::readFilenames
(a helper function in macOS-specific code) contained logic to create and insert attachment elements if
ENABLE(ATTACHMENT_ELEMENT); otherwise, it would fall back to inserting the visible URL as a text node. Since we
enable the attachment element on all Cocoa platforms via xcconfig files, this was effectively dead code.

However, when r226396 (which moved this out from macOS to Cocoa platform code) refactored this helper function,
it also moved this chunk of code out of the !ENABLE(ATTACHMENT) conditional and into a PLATFORM(MAC) guard,
which means that we now fall back to inserting file paths as text when attachment elements are disabled. To fix
this, we simply remove the (previously) dead code.

A more subtle difference is that we no longer always return true from WebContentReader::readFilePaths. This
means that when we drop files, we no longer skip over the early return in documentFragmentFromDragData when
we've made a fragment, so we read the file path as a URL. To address this, we just restore the pre-macOS 10.13.4
behavior of initializing the document fragment.

Test: modified editing/pasteboard/drag-files-to-editable-element-as-URLs.html.

* editing/WebContentReader.cpp:
(WebCore::WebContentReader::ensureFragment): Deleted.

Remove this helper, as it was only used in WebContentReader::readFilePaths.

* editing/WebContentReader.h:
* editing/cocoa/WebContentReaderCocoa.mm:
(WebCore::WebContentReader::readFilePaths):

Tools:

Tweak some image pasting API tests to ensure that file paths are not inserted when pasting images backed by
file paths on disk.

* TestWebKitAPI/Tests/WebKitCocoa/PasteImage.mm:
(TEST):

LayoutTests:

Tweak an existing layout test that drops a file into a contenteditable, to check that no text is inserted into
the editable element after dropping.

* editing/pasteboard/drag-files-to-editable-element-as-URLs-expected.txt:
* editing/pasteboard/drag-files-to-editable-element-as-URLs.html:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@228240 268f45cc-cd09-0410-ab3c-d52691b4dbfc
LayoutTests/ChangeLog
LayoutTests/editing/pasteboard/drag-files-to-editable-element-as-URLs-expected.txt
LayoutTests/editing/pasteboard/drag-files-to-editable-element-as-URLs.html
Source/WebCore/ChangeLog
Source/WebCore/editing/WebContentReader.cpp
Source/WebCore/editing/WebContentReader.h
Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm
Tools/ChangeLog
Tools/TestWebKitAPI/Tests/WebKitCocoa/PasteImage.mm