Changeset 228340 in webkit


Ignore:
Timestamp:
Feb 9, 2018 3:41:34 PM (6 years ago)
Author:
Wenson Hsieh
Message:

Pasting from Excel no longer provides text/html data
https://bugs.webkit.org/show_bug.cgi?id=182636
<rdar://problem/37087060>

Reviewed by Ryosuke Niwa.

Source/WebCore:

After r222656, we treat images on the pasteboard as files. However, we also have an existing policy which hides
text data ("text/uri-list", "text/html", "text/plain") from the page when files are present on the pasteboard.
When copying a table, Microsoft Excel writes a rendering of the table to the pasteboard as an image. This means
that we'll hide other data types (importantly, 'text/html') upon pasting, even though important clients (such as
Google Docs and Confluence) depend on the 'text/html' data in order to correctly handle the paste (rather than
paste as an image of a table).

To fix this, we add an exception to the DataTransfer.getData codepath when the pasteboard contains files.
Instead of always returning the empty string for text/html, we still allow pasteboard access, but only read
from a limited set of rich text types, i.e. web archive, RTF(D), and HTML markup. Importantly, this prevents
us from exposing any file paths that appear as plain text or URLs on the pasteboard. Just as in the regular
codepath for getData(), if the pasteboard data comes from the same origin, we allow unsanitized access;
otherwise, we use WebContentMarkupReader to extract markup from the pasteboard.

Tests: PasteMixedContent.ImageFileAndPlainText

PasteMixedContent.ImageFileAndWebArchive
PasteMixedContent.ImageFileAndHTML
PasteMixedContent.ImageFileAndRTF
PasteMixedContent.ImageFileAndURL
PasteMixedContent.ImageFileWithHTMLAndURL
DataInteractionTests.DataTransferGetDataWhenDroppingImageAndMarkup

Also rebaselined some layout tests, which cover changes in behavior when dropping on macOS and pasting on iOS.

  • dom/DataTransfer.cpp:

(WebCore::DataTransfer::getDataForItem const):

Augment the codepath handling the case where the pasteboard contains files, such that we allow reading
"text/html", but only from rich text types.

(WebCore::DataTransfer::readStringFromPasteboard const):

Factor out logic for reading from the pasteboard into a private helper. This is called in two places from
getDataForItem: in the normal (existing) path, and in the case where we allow 'text/html' to be read despite
files appearing in the pasteboard.

One important difference here is that this helper now takes a WebContentReadingPolicy, whose purpose is to
prevent reading from non-rich-text types when files appear in the pasteboard.

Another tweak here is that we now use lowercaseType instead of the original (unadjusted) type when reading
from the pasteboard. This doesn't seem to be intended in the first place.

(WebCore::DataTransfer::types const):

Tweak the implementation of DataTransfer.types() in the case where files exist on the pasteboard, such that we
also add "text/html" if it is present in the list of DOM-safe types.

  • dom/DataTransfer.h:
  • platform/Pasteboard.h:

Introduce WebContentReadingPolicy, which indicates whether or not we should limit web content reading from the
pasteboard to only rich text types upon paste or drop. Normally, we allow all types to be read as web content
(::AnyType), but when files appear on the pasteboard, we force OnlyRichTextTypes to ensure that no other types
can unintentionally be read back as web content.

  • platform/StaticPasteboard.h:
  • platform/gtk/PasteboardGtk.cpp:

(WebCore::Pasteboard::read):

  • platform/ios/PasteboardIOS.mm:

Teach Pasteboard (on iOS) to respect WebContentReadingPolicy.

(WebCore::isTypeAllowedByReadingPolicy):
(WebCore::Pasteboard::read):
(WebCore::Pasteboard::readRespectingUTIFidelities):

  • platform/mac/PasteboardMac.mm:

Teach Pasteboard (on macOS) to respect WebContentReadingPolicy.

(WebCore::Pasteboard::read):

  • platform/win/PasteboardWin.cpp:

(WebCore::Pasteboard::read):

  • platform/wpe/PasteboardWPE.cpp:

(WebCore::Pasteboard::read):

Adjust non-Cocoa Pasteboard implementations for an interface change.

Tools:

Add new API tests to exercise pasting images with various other content types on macOS, and when dropping images
and HTML markup on iOS. See the WebCore ChangeLog for more detail.

  • TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
  • TestWebKitAPI/Tests/WebKitCocoa/DataTransfer.html: Added.

Add a new API test harness that dumps various bits of information about a DataTransfer upon paste and drop.
While somewhat similar to some existing harnesses, this makes a distinction between the raw HTML data on the
pasteboard and the actual result of inserting said HTML into the DOM. This allows us to check that the HTML has
been sanitized, while making checks for the actual content of the HTML robust against inline style changes.

  • TestWebKitAPI/Tests/WebKitCocoa/PasteImage.mm:
  • TestWebKitAPI/Tests/WebKitCocoa/PasteMixedContent.mm: Added.

Add a new test suite to exercise pasting mixed content types. In these test cases, the pasteboard contains a
file, with some combination of plain text, rich text, and URLs.

(imagePath):
(writeTypesAndDataToPasteboard):

Add a helper to write a var-arg list of content types and data to the general NSPasteboard.

(setUpWebView):
(markupString):
(TestWebKitAPI::TEST):

  • TestWebKitAPI/Tests/ios/DataInteractionTests.mm:

(TestWebKitAPI::testIconImageData):
(TestWebKitAPI::TEST):

  • TestWebKitAPI/cocoa/TestWKWebView.h:

Move a private declaration of -[WKWebView paste:] out to TestWKWebView.h, so that it can be shared across
multiple tests. Currently, it only resides in PasteImage.mm, but I need it in PasteMixedContent.mm as well.

LayoutTests:

Rebaseline some existing layout tests. We now expose "text/html" alongside "Files" on DataTransfer.types() in
some circumstances. This also provides some test coverage for ensuring that the paste codepath iOS allows the
page to request HTML, even if there are files on the pasteboard. See the WebCore ChangeLog for more detail.

  • editing/pasteboard/data-transfer-item-list-add-file-multiple-times-expected.txt:
  • editing/pasteboard/data-transfer-item-list-add-file-on-copy-expected.txt:
  • editing/pasteboard/data-transfer-item-list-add-file-on-drag-expected.txt:

Adjust test expectations for the additional "text/html" type.

  • editing/pasteboard/paste-image-does-not-reveal-file-url-expected.txt:
  • editing/pasteboard/paste-image-does-not-reveal-file-url.html:

Instead of checking that types is [ "Files" ], just check that types contains "Files". On iOS, copying a
selected image does not also copy HTML, but on macOS it does; this covers both cases.

Location:
trunk
Files:
2 added
21 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r228336 r228340  
     12018-02-08  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        Pasting from Excel no longer provides text/html data
     4        https://bugs.webkit.org/show_bug.cgi?id=182636
     5        <rdar://problem/37087060>
     6
     7        Reviewed by Ryosuke Niwa.
     8
     9        Rebaseline some existing layout tests. We now expose "text/html" alongside "Files" on DataTransfer.types() in
     10        some circumstances. This also provides some test coverage for ensuring that the paste codepath iOS allows the
     11        page to request HTML, even if there are files on the pasteboard. See the WebCore ChangeLog for more detail.
     12
     13        * editing/pasteboard/data-transfer-item-list-add-file-multiple-times-expected.txt:
     14        * editing/pasteboard/data-transfer-item-list-add-file-on-copy-expected.txt:
     15        * editing/pasteboard/data-transfer-item-list-add-file-on-drag-expected.txt:
     16
     17        Adjust test expectations for the additional "text/html" type.
     18
     19        * editing/pasteboard/paste-image-does-not-reveal-file-url-expected.txt:
     20        * editing/pasteboard/paste-image-does-not-reveal-file-url.html:
     21
     22        Instead of checking that types is [ "Files" ], just check that types contains "Files". On iOS, copying a
     23        selected image does not also copy HTML, but on macOS it does; this covers both cases.
     24
    1252018-02-09  Matt Baker  <mattbaker@apple.com>
    226
  • trunk/LayoutTests/editing/pasteboard/data-transfer-item-list-add-file-multiple-times-expected.txt

    r223340 r228340  
    248248{
    249249    "data": {
    250         "Files": ""
     250        "Files": "",
     251        "text/html": "<strong>some styled text</strong>"
    251252    },
    252253    "items": [
     
    297298{
    298299    "data": {
    299         "Files": ""
     300        "Files": "",
     301        "text/html": "<strong>some styled text</strong>"
    300302    },
    301303    "items": [
     
    342344{
    343345    "data": {
    344         "Files": ""
     346        "Files": "",
     347        "text/html": "<strong>some styled text</strong>"
    345348    },
    346349    "items": [
  • trunk/LayoutTests/editing/pasteboard/data-transfer-item-list-add-file-on-copy-expected.txt

    r222885 r228340  
    130130{
    131131    "data": {
    132         "Files": ""
     132        "Files": "",
     133        "text/html": "<a>goodbye world</a>"
    133134    },
    134135    "items": [
     
    165166{
    166167    "data": {
    167         "Files": ""
     168        "Files": "",
     169        "text/html": "<a>goodbye world</a>"
    168170    },
    169171    "items": [
     
    214216{
    215217    "data": {
    216         "Files": ""
     218        "Files": "",
     219        "text/html": "<a>goodbye world</a>"
    217220    },
    218221    "items": [
  • trunk/LayoutTests/editing/pasteboard/data-transfer-item-list-add-file-on-drag-expected.txt

    r222885 r228340  
    130130{
    131131    "data": {
    132         "Files": ""
     132        "Files": "",
     133        "text/html": "<a>goodbye world</a>"
    133134    },
    134135    "items": [
     
    165166{
    166167    "data": {
    167         "Files": ""
     168        "Files": "",
     169        "text/html": "<a>goodbye world</a>"
    168170    },
    169171    "items": [
     
    214216{
    215217    "data": {
    216         "Files": ""
     218        "Files": "",
     219        "text/html": "<a>goodbye world</a>"
    217220    },
    218221    "items": [
  • trunk/LayoutTests/editing/pasteboard/paste-image-does-not-reveal-file-url-expected.txt

    r222688 r228340  
    44
    55
    6 PASS JSON.stringify(event.clipboardData.types) is "[\"Files\"]"
     6PASS event.clipboardData.types.includes("Files") is true
    77PASS event.clipboardData.getData("url") is ""
    88PASS event.clipboardData.getData("text/plain") is ""
  • trunk/LayoutTests/editing/pasteboard/paste-image-does-not-reveal-file-url.html

    r222688 r228340  
    3232function check(event)
    3333{
    34     shouldBeEqualToString('JSON.stringify(event.clipboardData.types)', '["Files"]');
     34    shouldBeTrue('event.clipboardData.types.includes("Files")');
    3535    shouldBeEqualToString('event.clipboardData.getData("url")', '');
    3636    shouldBeEqualToString('event.clipboardData.getData("text/plain")', '');
  • trunk/Source/WebCore/ChangeLog

    r228339 r228340  
     12018-02-09  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        Pasting from Excel no longer provides text/html data
     4        https://bugs.webkit.org/show_bug.cgi?id=182636
     5        <rdar://problem/37087060>
     6
     7        Reviewed by Ryosuke Niwa.
     8
     9        After r222656, we treat images on the pasteboard as files. However, we also have an existing policy which hides
     10        text data ("text/uri-list", "text/html", "text/plain") from the page when files are present on the pasteboard.
     11        When copying a table, Microsoft Excel writes a rendering of the table to the pasteboard as an image. This means
     12        that we'll hide other data types (importantly, 'text/html') upon pasting, even though important clients (such as
     13        Google Docs and Confluence) depend on the 'text/html' data in order to correctly handle the paste (rather than
     14        paste as an image of a table).
     15
     16        To fix this, we add an exception to the DataTransfer.getData codepath when the pasteboard contains files.
     17        Instead of always returning the empty string for text/html, we still allow pasteboard access, but only read
     18        from a limited set of rich text types, i.e. web archive, RTF(D), and HTML markup. Importantly, this prevents
     19        us from exposing any file paths that appear as plain text or URLs on the pasteboard. Just as in the regular
     20        codepath for getData(), if the pasteboard data comes from the same origin, we allow unsanitized access;
     21        otherwise, we use WebContentMarkupReader to extract markup from the pasteboard.
     22
     23        Tests:  PasteMixedContent.ImageFileAndPlainText
     24                PasteMixedContent.ImageFileAndWebArchive
     25                PasteMixedContent.ImageFileAndHTML
     26                PasteMixedContent.ImageFileAndRTF
     27                PasteMixedContent.ImageFileAndURL
     28                PasteMixedContent.ImageFileWithHTMLAndURL
     29                DataInteractionTests.DataTransferGetDataWhenDroppingImageAndMarkup
     30
     31        Also rebaselined some layout tests, which cover changes in behavior when dropping on macOS and pasting on iOS.
     32
     33        * dom/DataTransfer.cpp:
     34        (WebCore::DataTransfer::getDataForItem const):
     35
     36        Augment the codepath handling the case where the pasteboard contains files, such that we allow reading
     37        "text/html", but only from rich text types.
     38
     39        (WebCore::DataTransfer::readStringFromPasteboard const):
     40
     41        Factor out logic for reading from the pasteboard into a private helper. This is called in two places from
     42        getDataForItem: in the normal (existing) path, and in the case where we allow 'text/html' to be read despite
     43        files appearing in the pasteboard.
     44
     45        One important difference here is that this helper now takes a WebContentReadingPolicy, whose purpose is to
     46        prevent reading from non-rich-text types when files appear in the pasteboard.
     47
     48        Another tweak here is that we now use `lowercaseType` instead of the original (unadjusted) `type` when reading
     49        from the pasteboard. This doesn't seem to be intended in the first place.
     50
     51        (WebCore::DataTransfer::types const):
     52
     53        Tweak the implementation of DataTransfer.types() in the case where files exist on the pasteboard, such that we
     54        also add "text/html" if it is present in the list of DOM-safe types.
     55
     56        * dom/DataTransfer.h:
     57        * platform/Pasteboard.h:
     58
     59        Introduce WebContentReadingPolicy, which indicates whether or not we should limit web content reading from the
     60        pasteboard to only rich text types upon paste or drop. Normally, we allow all types to be read as web content
     61        (::AnyType), but when files appear on the pasteboard, we force OnlyRichTextTypes to ensure that no other types
     62        can unintentionally be read back as web content.
     63
     64        * platform/StaticPasteboard.h:
     65        * platform/gtk/PasteboardGtk.cpp:
     66        (WebCore::Pasteboard::read):
     67        * platform/ios/PasteboardIOS.mm:
     68
     69        Teach Pasteboard (on iOS) to respect WebContentReadingPolicy.
     70
     71        (WebCore::isTypeAllowedByReadingPolicy):
     72        (WebCore::Pasteboard::read):
     73        (WebCore::Pasteboard::readRespectingUTIFidelities):
     74        * platform/mac/PasteboardMac.mm:
     75
     76        Teach Pasteboard (on macOS) to respect WebContentReadingPolicy.
     77
     78        (WebCore::Pasteboard::read):
     79        * platform/win/PasteboardWin.cpp:
     80        (WebCore::Pasteboard::read):
     81        * platform/wpe/PasteboardWPE.cpp:
     82        (WebCore::Pasteboard::read):
     83
     84        Adjust non-Cocoa Pasteboard implementations for an interface change.
     85
    1862018-02-09  Zalan Bujtas  <zalan@apple.com>
    287
  • trunk/Source/WebCore/dom/DataTransfer.cpp

    r227282 r228340  
    155155                return urlString;
    156156        }
     157
     158        if (lowercaseType == "text/html" && RuntimeEnabledFeatures::sharedFeatures().customPasteboardDataEnabled()) {
     159            // If the pasteboard contains files and the page requests 'text/html', we only read from rich text types to prevent file
     160            // paths from leaking (e.g. from plain text data on the pasteboard) since we sanitize cross-origin markup. However, if
     161            // custom pasteboard data is disabled, then we can't ensure that the markup we deliver is sanitized, so we fall back to
     162            // current behavior and return an empty string.
     163            return readStringFromPasteboard(document, lowercaseType, WebContentReadingPolicy::OnlyRichTextTypes);
     164        }
     165
    157166        return { };
    158167    }
    159168
     169    return readStringFromPasteboard(document, lowercaseType, WebContentReadingPolicy::AnyType);
     170}
     171
     172String DataTransfer::readStringFromPasteboard(Document& document, const String& lowercaseType, WebContentReadingPolicy policy) const
     173{
    160174    if (!RuntimeEnabledFeatures::sharedFeatures().customPasteboardDataEnabled())
    161175        return m_pasteboard->readString(lowercaseType);
     
    171185        return { };
    172186
    173     if (!is<StaticPasteboard>(*m_pasteboard) && type == "text/html") {
     187    if (!is<StaticPasteboard>(*m_pasteboard) && lowercaseType == "text/html") {
    174188        if (!document.frame())
    175189            return { };
    176190        WebContentMarkupReader reader { *document.frame() };
    177         m_pasteboard->read(reader);
     191        m_pasteboard->read(reader, policy);
    178192        return reader.markup;
    179193    }
    180194
    181     return m_pasteboard->readString(type);
     195    return m_pasteboard->readString(lowercaseType);
    182196}
    183197
     
    294308        if (safeTypes.contains("text/uri-list"))
    295309            types.append(ASCIILiteral("text/uri-list"));
     310        if (safeTypes.contains("text/html") && RuntimeEnabledFeatures::sharedFeatures().customPasteboardDataEnabled())
     311            types.append(ASCIILiteral("text/html"));
    296312        return types;
    297313    }
  • trunk/Source/WebCore/dom/DataTransfer.h

    r223440 r228340  
    4040class File;
    4141class Pasteboard;
     42enum class WebContentReadingPolicy;
    4243
    4344class DataTransfer : public RefCounted<DataTransfer> {
     
    122123#endif
    123124
     125    String readStringFromPasteboard(Document&, const String& lowercaseType, WebContentReadingPolicy) const;
    124126    bool shouldSuppressGetAndSetDataToAvoidExposingFilePaths() const;
    125127
  • trunk/Source/WebCore/platform/Pasteboard.h

    r226657 r228340  
    6565class SharedBuffer;
    6666
     67enum class WebContentReadingPolicy { AnyType, OnlyRichTextTypes };
    6768enum ShouldSerializeSelectedTextForDataTransfer { DefaultSelectedTextType, IncludeImageAltTextForDataTransfer };
    6869
     
    210211
    211212    virtual WEBCORE_EXPORT void read(PasteboardPlainText&);
    212     virtual WEBCORE_EXPORT void read(PasteboardWebContentReader&);
     213    virtual WEBCORE_EXPORT void read(PasteboardWebContentReader&, WebContentReadingPolicy = WebContentReadingPolicy::AnyType);
    213214    virtual WEBCORE_EXPORT void read(PasteboardFileReader&);
    214215
     
    274275#if PLATFORM(IOS)
    275276    bool respectsUTIFidelities() const;
    276     void readRespectingUTIFidelities(PasteboardWebContentReader&);
     277    void readRespectingUTIFidelities(PasteboardWebContentReader&, WebContentReadingPolicy);
    277278
    278279    enum class ReaderResult {
  • trunk/Source/WebCore/platform/StaticPasteboard.h

    r223195 r228340  
    5454
    5555    void read(PasteboardPlainText&) final { }
    56     void read(PasteboardWebContentReader&) final { }
     56    void read(PasteboardWebContentReader&, WebContentReadingPolicy) final { }
    5757
    5858    void write(const PasteboardURL&) final { }
  • trunk/Source/WebCore/platform/gtk/PasteboardGtk.cpp

    r223728 r228340  
    237237}
    238238
    239 void Pasteboard::read(PasteboardWebContentReader&)
     239void Pasteboard::read(PasteboardWebContentReader&, WebContentReadingPolicy)
    240240{
    241241}
  • trunk/Source/WebCore/platform/ios/PasteboardIOS.mm

    r226396 r228340  
    164164}
    165165
     166static bool isTypeAllowedByReadingPolicy(NSString *type, WebContentReadingPolicy policy)
     167{
     168    return policy == WebContentReadingPolicy::AnyType
     169        || [type isEqualToString:WebArchivePboardType]
     170        || [type isEqualToString:(NSString *)kUTTypeHTML]
     171        || [type isEqualToString:(NSString *)kUTTypeRTF]
     172        || [type isEqualToString:(NSString *)kUTTypeFlatRTFD];
     173}
     174
    166175Pasteboard::ReaderResult Pasteboard::readPasteboardWebContentDataForType(PasteboardWebContentReader& reader, PasteboardStrategy& strategy, NSString *type, int itemIndex)
    167176{
     
    226235}
    227236
    228 void Pasteboard::read(PasteboardWebContentReader& reader)
     237void Pasteboard::read(PasteboardWebContentReader& reader, WebContentReadingPolicy policy)
    229238{
    230239    reader.contentOrigin = readOrigin();
    231240    if (respectsUTIFidelities()) {
    232         readRespectingUTIFidelities(reader);
     241        readRespectingUTIFidelities(reader, policy);
    233242        return;
    234243    }
     
    246255    for (int i = 0; i < numberOfItems; i++) {
    247256        for (int typeIndex = 0; typeIndex < numberOfTypes; typeIndex++) {
    248             auto itemResult = readPasteboardWebContentDataForType(reader, strategy, [types objectAtIndex:typeIndex], i);
     257            NSString *type = [types objectAtIndex:typeIndex];
     258            if (!isTypeAllowedByReadingPolicy(type, policy))
     259                continue;
     260
     261            auto itemResult = readPasteboardWebContentDataForType(reader, strategy, type, i);
    249262            if (itemResult == ReaderResult::PasteboardWasChangedExternally)
    250263                return;
     264
    251265            if (itemResult == ReaderResult::ReadType)
    252266                break;
     
    263277}
    264278
    265 void Pasteboard::readRespectingUTIFidelities(PasteboardWebContentReader& reader)
     279void Pasteboard::readRespectingUTIFidelities(PasteboardWebContentReader& reader, WebContentReadingPolicy policy)
    266280{
    267281    ASSERT(respectsUTIFidelities());
     
    270284#if ENABLE(ATTACHMENT_ELEMENT)
    271285        auto info = strategy.informationForItemAtIndex(index, m_pasteboardName);
    272         bool canReadAttachment = RuntimeEnabledFeatures::sharedFeatures().attachmentElementEnabled() && !info.pathForFileUpload.isEmpty();
     286        bool canReadAttachment = policy == WebContentReadingPolicy::AnyType && RuntimeEnabledFeatures::sharedFeatures().attachmentElementEnabled() && !info.pathForFileUpload.isEmpty();
    273287        if (canReadAttachment && info.preferredPresentationStyle == PasteboardItemPresentationStyle::Attachment) {
    274288            reader.readFilePaths({ info.pathForFileUpload });
     
    282296        ReaderResult result = ReaderResult::DidNotReadType;
    283297        for (auto& type : typesForItemInOrderOfFidelity) {
     298            if (!isTypeAllowedByReadingPolicy(type, policy))
     299                continue;
     300
    284301            result = readPasteboardWebContentDataForType(reader, strategy, type, index);
    285302            if (result == ReaderResult::PasteboardWasChangedExternally)
  • trunk/Source/WebCore/platform/mac/PasteboardMac.mm

    r228338 r228340  
    332332}
    333333
    334 void Pasteboard::read(PasteboardWebContentReader& reader)
     334void Pasteboard::read(PasteboardWebContentReader& reader, WebContentReadingPolicy policy)
    335335{
    336336    PasteboardStrategy& strategy = *platformStrategies()->pasteboardStrategy();
     
    348348    }
    349349
    350     if (types.contains(String(legacyFilenamesPasteboardType()))) {
     350    if (policy == WebContentReadingPolicy::AnyType && types.contains(String(legacyFilenamesPasteboardType()))) {
    351351        Vector<String> paths;
    352352        strategy.getPathnamesForType(paths, legacyFilenamesPasteboardType(), m_pasteboardName);
     
    374374        }
    375375    }
     376
     377    if (policy == WebContentReadingPolicy::OnlyRichTextTypes)
     378        return;
    376379
    377380    if (types.contains(String(legacyTIFFPasteboardType()))) {
  • trunk/Source/WebCore/platform/win/PasteboardWin.cpp

    r226205 r228340  
    10741074}
    10751075
    1076 void Pasteboard::read(PasteboardWebContentReader&)
     1076void Pasteboard::read(PasteboardWebContentReader&, WebContentReadingPolicy)
    10771077{
    10781078}
  • trunk/Source/WebCore/platform/wpe/PasteboardWPE.cpp

    r223195 r228340  
    9898}
    9999
    100 void Pasteboard::read(PasteboardWebContentReader&)
     100void Pasteboard::read(PasteboardWebContentReader&, WebContentReadingPolicy)
    101101{
    102102    notImplemented();
  • trunk/Tools/ChangeLog

    r228323 r228340  
     12018-02-08  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        Pasting from Excel no longer provides text/html data
     4        https://bugs.webkit.org/show_bug.cgi?id=182636
     5        <rdar://problem/37087060>
     6
     7        Reviewed by Ryosuke Niwa.
     8
     9        Add new API tests to exercise pasting images with various other content types on macOS, and when dropping images
     10        and HTML markup on iOS. See the WebCore ChangeLog for more detail.
     11
     12        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
     13        * TestWebKitAPI/Tests/WebKitCocoa/DataTransfer.html: Added.
     14
     15        Add a new API test harness that dumps various bits of information about a DataTransfer upon paste and drop.
     16        While somewhat similar to some existing harnesses, this makes a distinction between the raw HTML data on the
     17        pasteboard and the actual result of inserting said HTML into the DOM. This allows us to check that the HTML has
     18        been sanitized, while making checks for the actual content of the HTML robust against inline style changes.
     19
     20        * TestWebKitAPI/Tests/WebKitCocoa/PasteImage.mm:
     21        * TestWebKitAPI/Tests/WebKitCocoa/PasteMixedContent.mm: Added.
     22
     23        Add a new test suite to exercise pasting mixed content types. In these test cases, the pasteboard contains a
     24        file, with some combination of plain text, rich text, and URLs.
     25
     26        (imagePath):
     27        (writeTypesAndDataToPasteboard):
     28
     29        Add a helper to write a var-arg list of content types and data to the general NSPasteboard.
     30
     31        (setUpWebView):
     32        (markupString):
     33        (TestWebKitAPI::TEST):
     34        * TestWebKitAPI/Tests/ios/DataInteractionTests.mm:
     35        (TestWebKitAPI::testIconImageData):
     36        (TestWebKitAPI::TEST):
     37        * TestWebKitAPI/cocoa/TestWKWebView.h:
     38
     39        Move a private declaration of -[WKWebView paste:] out to TestWKWebView.h, so that it can be shared across
     40        multiple tests. Currently, it only resides in PasteImage.mm, but I need it in PasteMixedContent.mm as well.
     41
    1422018-02-09  Carlos Garcia Campos  <cgarcia@igalia.com>
    243
  • trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj

    r228309 r228340  
    742742                F4512E131F60C44600BB369E /* DataTransferItem-getAsEntry.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F4512E121F60C43400BB369E /* DataTransferItem-getAsEntry.html */; };
    743743                F4538EF71E8473E600B5C953 /* large-red-square.png in Copy Resources */ = {isa = PBXBuildFile; fileRef = F4538EF01E846B4100B5C953 /* large-red-square.png */; };
     744                F457A9B8202D5CDC00F7E9D5 /* PasteMixedContent.mm in Sources */ = {isa = PBXBuildFile; fileRef = F457A9B6202D5CDC00F7E9D5 /* PasteMixedContent.mm */; };
     745                F457A9D6202D68AF00F7E9D5 /* DataTransfer.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F457A9B3202D535300F7E9D5 /* DataTransfer.html */; };
    744746                F45B63FB1F197F4A009D38B9 /* image-map.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F45B63FA1F197F33009D38B9 /* image-map.html */; };
    745747                F45B63FE1F19D410009D38B9 /* ActionSheetTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = F45B63FC1F19D410009D38B9 /* ActionSheetTests.mm */; };
     
    895897                                290F4275172A221C00939FF0 /* custom-protocol-sync-xhr.html in Copy Resources */,
    896898                                F486B1D01F67952300F34BDD /* DataTransfer-setDragImage.html in Copy Resources */,
     899                                F457A9D6202D68AF00F7E9D5 /* DataTransfer.html in Copy Resources */,
    897900                                F4512E131F60C44600BB369E /* DataTransferItem-getAsEntry.html in Copy Resources */,
    898901                                C07E6CB213FD73930038B22B /* devicePixelRatio.html in Copy Resources */,
     
    18631866                F4512E121F60C43400BB369E /* DataTransferItem-getAsEntry.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "DataTransferItem-getAsEntry.html"; sourceTree = "<group>"; };
    18641867                F4538EF01E846B4100B5C953 /* large-red-square.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "large-red-square.png"; sourceTree = "<group>"; };
     1868                F457A9B3202D535300F7E9D5 /* DataTransfer.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = DataTransfer.html; sourceTree = "<group>"; };
     1869                F457A9B6202D5CDC00F7E9D5 /* PasteMixedContent.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = PasteMixedContent.mm; sourceTree = "<group>"; };
    18651870                F45B63FA1F197F33009D38B9 /* image-map.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = "image-map.html"; sourceTree = "<group>"; };
    18661871                F45B63FC1F19D410009D38B9 /* ActionSheetTests.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = ActionSheetTests.mm; sourceTree = "<group>"; };
     
    21312136                                9BCB7C2620130600003E7C0C /* PasteHTML.mm */,
    21322137                                9BDCCD851F7D0B0700009A18 /* PasteImage.mm */,
     2138                                F457A9B6202D5CDC00F7E9D5 /* PasteMixedContent.mm */,
    21332139                                9BDD95561F83683600D20C60 /* PasteRTFD.mm */,
    21342140                                9B2346411F943A2400DB1D23 /* PasteWebArchive.mm */,
     
    23652371                                F4AB57891F65164B00DB0DA1 /* custom-draggable-div.html */,
    23662372                                F486B1CF1F6794FF00F34BDD /* DataTransfer-setDragImage.html */,
     2373                                F457A9B3202D535300F7E9D5 /* DataTransfer.html */,
    23672374                                F4512E121F60C43400BB369E /* DataTransferItem-getAsEntry.html */,
    23682375                                0799C34A1EBA32F4003B7532 /* disableGetUserMedia.html */,
     
    35563563                                9BCB7C2820130600003E7C0C /* PasteHTML.mm in Sources */,
    35573564                                9BDCCD871F7D0B0700009A18 /* PasteImage.mm in Sources */,
     3565                                F457A9B8202D5CDC00F7E9D5 /* PasteMixedContent.mm in Sources */,
    35583566                                9BDD95581F83683600D20C60 /* PasteRTFD.mm in Sources */,
    35593567                                9B2346421F943E2700DB1D23 /* PasteWebArchive.mm in Sources */,
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/PasteImage.mm

    r228240 r228340  
    3737#endif
    3838
    39 @interface WKWebView ()
    40 - (void)paste:(id)sender;
    41 @end
    42 
    4339#if PLATFORM(MAC)
    4440void writeImageDataToPasteboard(NSString *type, NSData *data)
  • trunk/Tools/TestWebKitAPI/Tests/ios/DataInteractionTests.mm

    r227910 r228340  
    15001500#if __IPHONE_OS_VERSION_MIN_REQUIRED >= 110300
    15011501
     1502static NSData *testIconImageData()
     1503{
     1504    return [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"icon" ofType:@"png" inDirectory:@"TestWebKitAPI.resources"]];
     1505}
     1506
     1507TEST(DataInteractionTests, DataTransferGetDataWhenDroppingImageAndMarkup)
     1508{
     1509    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
     1510    WKPreferencesSetCustomPasteboardDataEnabled((WKPreferencesRef)[webView configuration].preferences, true);
     1511    [webView synchronouslyLoadTestPageNamed:@"DataTransfer"];
     1512
     1513    auto simulator = adoptNS([[DataInteractionSimulator alloc] initWithWebView:webView.get()]);
     1514    auto itemProvider = adoptNS([[UIItemProvider alloc] init]);
     1515    [itemProvider registerDataRepresentationForTypeIdentifier:(NSString *)kUTTypePNG withData:testIconImageData()];
     1516    NSString *markupString = @"<script>bar()</script><strong onmousedown=javascript:void(0)>HELLO WORLD</strong>";
     1517    [itemProvider registerDataRepresentationForTypeIdentifier:(NSString *)kUTTypeHTML withData:[markupString dataUsingEncoding:NSUTF8StringEncoding]];
     1518    [itemProvider setSuggestedName:@"icon"];
     1519    [simulator setExternalItemProviders:@[ itemProvider.get() ]];
     1520    [simulator runFrom:CGPointZero to:CGPointMake(50, 100)];
     1521
     1522    EXPECT_WK_STREQ("Files, text/html", [webView stringByEvaluatingJavaScript:@"types.textContent"]);
     1523    EXPECT_WK_STREQ("(STRING, text/html), (FILE, image/png)", [webView stringByEvaluatingJavaScript:@"items.textContent"]);
     1524    EXPECT_WK_STREQ("('icon.png', image/png)", [webView stringByEvaluatingJavaScript:@"files.textContent"]);
     1525    EXPECT_WK_STREQ("", [webView stringByEvaluatingJavaScript:@"urlData.textContent"]);
     1526    EXPECT_WK_STREQ("", [webView stringByEvaluatingJavaScript:@"textData.textContent"]);
     1527    EXPECT_WK_STREQ("HELLO WORLD", [webView stringByEvaluatingJavaScript:@"htmlData.textContent"]);
     1528    EXPECT_FALSE([[webView stringByEvaluatingJavaScript:@"rawHTMLData.textContent"] containsString:@"script"]);
     1529}
     1530
    15021531TEST(DataInteractionTests, DataTransferGetDataWhenDroppingPlainText)
    15031532{
  • trunk/Tools/TestWebKitAPI/cocoa/TestWKWebView.h

    r226396 r228340  
    3434@class _WKActivatedElementInfo;
    3535#endif
     36
     37@interface WKWebView (AdditionalDeclarations)
     38#if PLATFORM(MAC)
     39- (void)paste:(id)sender;
     40#endif
     41@end
    3642
    3743@interface TestMessageHandler : NSObject <WKScriptMessageHandler>
Note: See TracChangeset for help on using the changeset viewer.