Changeset 229503 in webkit


Ignore:
Timestamp:
Mar 10, 2018 3:33:20 AM (6 years ago)
Author:
Wenson Hsieh
Message:

[macOS] Copying a table from the Numbers app and pasting into iCloud Numbers fails
https://bugs.webkit.org/show_bug.cgi?id=183485
<rdar://problem/38041984>

Reviewed by Ryosuke Niwa.

Source/WebCore:

After r222656, WebKit now treats raw image data on the pasteboard as files for the purposes of computing
DataTransfer.files and DataTransfer.types. However, this is combined with existing policies that suppress
DataTransfer.getData and DataTransfer.setData when the pasteboard contains files (generalized to copy/paste in
r222688). This means we now don't allow web pages to access "text/plain" in the case where the user copies part
of a table from the native Numbers app since Numbers additionally writes a snapshot of the table to the platform
pasteboard.

This restriction on getData/setData was intended to prevent web pages from extracting users' file paths when
pasting or dropping, so it doesn't make sense to enforce this restriction even when there is only in-memory
image data on the pasteboard. To fix this bug, we make Pasteboard::fileContentState() differentiate between
cases where there are (real) files on the pasteboard, and cases where we've fallen back to treating image data
as files.

Rebaselined existing LayoutTests to match new behavior.
Also covered by 4 new API tests:

  • PasteMixedContent.ImageDataAndPlainText
  • PasteMixedContent.ImageDataAndPlainTextAndURL
  • PasteMixedContent.ImageDataAndPlainTextAndURLAndHTML
  • UIPasteboardTests.DataTransferGetDataWhenPastingImageAndText
  • dom/DataTransfer.cpp:

(WebCore::DataTransfer::shouldSuppressGetAndSetDataToAvoidExposingFilePaths const):

If custom pasteboard data is enabled, suppress getData and setData if and only if we might actually expose file
paths (see Pasteboard::fileContentState).

(WebCore::DataTransfer::types const):

Only allow "text/html" or "text/uri-list" in the case where there are actual files in the pasteboard. If there's
only image data, add all of the DOM-safe types back into the list of types.

  • platform/Pasteboard.h:
  • platform/StaticPasteboard.h:

Add an enum type to represent the result of Pasteboard::fileContentState.

  • NoFileOrImageData indicates that there was nothing on the pasteboard that could be considered a file

from the point of view of the page.

  • InMemoryImage indicates that there are no files on the pasteboard, but there is image data that we consider

to be files, exposed via DataTransfer API.

  • MayContainFilePaths indicates that there might be file paths on the pasteboard. This means that the source

has either written file paths to the pasteboard (for example, through NSFilenamesPboardType) or the source
has written image data along with a URL type of some sort that does not match one of the allowed URL schemes
that are safe to expose (currently, these are http-family, data, or blob).

  • platform/cocoa/PasteboardCocoa.mm:

(WebCore::Pasteboard::fileContentState):

Refactor to return one of the three enum types described above.

(WebCore::Pasteboard::containsFiles): Deleted.

  • platform/gtk/PasteboardGtk.cpp:

(WebCore::Pasteboard::fileContentState):
(WebCore::Pasteboard::containsFiles): Deleted.

  • platform/win/PasteboardWin.cpp:

(WebCore::Pasteboard::fileContentState):
(WebCore::Pasteboard::containsFiles): Deleted.

  • platform/wpe/PasteboardWPE.cpp:

(WebCore::Pasteboard::fileContentState):
(WebCore::Pasteboard::containsFiles): Deleted.

Adjust for Pasteboard::fileContentState() tweaks.

Tools:

Add new API tests to cover scenarios in which we paste image data alongside text data.

  • TestWebKitAPI/Tests/WebKitCocoa/PasteMixedContent.mm:

(TestWebKitAPI::TEST):

  • TestWebKitAPI/Tests/ios/UIPasteboardTests.mm:

(TestWebKitAPI::TEST):

LayoutTests:

Rebaseline some pasteboard-related layout tests, in which we now expose text/plain alongside files that were
written to the DataTransfer by the page itself.

  • 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:
Location:
trunk
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r229502 r229503  
     12018-03-10  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        [macOS] Copying a table from the Numbers app and pasting into iCloud Numbers fails
     4        https://bugs.webkit.org/show_bug.cgi?id=183485
     5        <rdar://problem/38041984>
     6
     7        Reviewed by Ryosuke Niwa.
     8
     9        Rebaseline some pasteboard-related layout tests, in which we now expose text/plain alongside files that were
     10        written to the DataTransfer by the page itself.
     11
     12        * editing/pasteboard/data-transfer-item-list-add-file-multiple-times-expected.txt:
     13        * editing/pasteboard/data-transfer-item-list-add-file-on-copy-expected.txt:
     14        * editing/pasteboard/data-transfer-item-list-add-file-on-drag-expected.txt:
     15
    1162018-03-09  Chris Dumez  <cdumez@apple.com>
    217
  • trunk/LayoutTests/editing/pasteboard/data-transfer-item-list-add-file-multiple-times-expected.txt

    r228340 r229503  
    1111    "data": {
    1212        "Files": "",
     13        "text/plain": "plain text string",
    1314        "text/uri-list": "https://webkit.org"
    1415    },
     
    8990    "data": {
    9091        "Files": "",
     92        "text/plain": "plain text string",
    9193        "text/uri-list": "https://webkit.org"
    9294    },
     
    154156    "data": {
    155157        "Files": "",
     158        "text/plain": "plain text string",
    156159        "text/uri-list": "https://webkit.org"
    157160    },
     
    205208    "data": {
    206209        "Files": "",
     210        "text/plain": "plain text string",
    207211        "text/uri-list": "https://webkit.org"
    208212    },
     
    249253    "data": {
    250254        "Files": "",
    251         "text/html": "<strong>some styled text</strong>"
     255        "text/html": "<strong>some styled text</strong>",
     256        "text/plain": "some plain text"
    252257    },
    253258    "items": [
  • trunk/LayoutTests/editing/pasteboard/data-transfer-item-list-add-file-on-copy-expected.txt

    r228340 r229503  
    2525{
    2626    "data": {
    27         "Files": ""
     27        "Files": "",
     28        "text/plain": "hello world"
    2829    },
    2930    "items": [
     
    5556{
    5657    "data": {
    57         "Files": ""
     58        "Files": "",
     59        "text/plain": "hello world"
    5860    },
    5961    "items": [
     
    99101{
    100102    "data": {
    101         "Files": ""
     103        "Files": "",
     104        "text/plain": "hello world"
    102105    },
    103106    "items": [
     
    131134    "data": {
    132135        "Files": "",
     136        "text/plain": "hello world",
    133137        "text/html": "<a>goodbye world</a>"
    134138    },
     
    167171    "data": {
    168172        "Files": "",
     173        "text/plain": "hello world",
    169174        "text/html": "<a>goodbye world</a>"
    170175    },
     
    217222    "data": {
    218223        "Files": "",
     224        "text/plain": "hello world",
    219225        "text/html": "<a>goodbye world</a>"
    220226    },
     
    253259{
    254260    "data": {
    255         "Files": ""
     261        "Files": "",
     262        "text/plain": "hello world"
    256263    },
    257264    "items": [
  • trunk/LayoutTests/editing/pasteboard/data-transfer-item-list-add-file-on-drag-expected.txt

    r228340 r229503  
    2525{
    2626    "data": {
    27         "Files": ""
     27        "Files": "",
     28        "text/plain": "hello world"
    2829    },
    2930    "items": [
     
    5556{
    5657    "data": {
    57         "Files": ""
     58        "Files": "",
     59        "text/plain": "hello world"
    5860    },
    5961    "items": [
     
    99101{
    100102    "data": {
    101         "Files": ""
     103        "Files": "",
     104        "text/plain": "hello world"
    102105    },
    103106    "items": [
     
    131134    "data": {
    132135        "Files": "",
     136        "text/plain": "hello world",
    133137        "text/html": "<a>goodbye world</a>"
    134138    },
     
    167171    "data": {
    168172        "Files": "",
     173        "text/plain": "hello world",
    169174        "text/html": "<a>goodbye world</a>"
    170175    },
     
    217222    "data": {
    218223        "Files": "",
     224        "text/plain": "hello world",
    219225        "text/html": "<a>goodbye world</a>"
    220226    },
     
    253259{
    254260    "data": {
    255         "Files": ""
     261        "Files": "",
     262        "text/plain": "hello world"
    256263    },
    257264    "items": [
  • trunk/Source/WebCore/ChangeLog

    r229500 r229503  
     12018-03-10  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        [macOS] Copying a table from the Numbers app and pasting into iCloud Numbers fails
     4        https://bugs.webkit.org/show_bug.cgi?id=183485
     5        <rdar://problem/38041984>
     6
     7        Reviewed by Ryosuke Niwa.
     8
     9        After r222656, WebKit now treats raw image data on the pasteboard as files for the purposes of computing
     10        DataTransfer.files and DataTransfer.types. However, this is combined with existing policies that suppress
     11        DataTransfer.getData and DataTransfer.setData when the pasteboard contains files (generalized to copy/paste in
     12        r222688). This means we now don't allow web pages to access "text/plain" in the case where the user copies part
     13        of a table from the native Numbers app since Numbers additionally writes a snapshot of the table to the platform
     14        pasteboard.
     15
     16        This restriction on getData/setData was intended to prevent web pages from extracting users' file paths when
     17        pasting or dropping, so it doesn't make sense to enforce this restriction even when there is only in-memory
     18        image data on the pasteboard. To fix this bug, we make Pasteboard::fileContentState() differentiate between
     19        cases where there are (real) files on the pasteboard, and cases where we've fallen back to treating image data
     20        as files.
     21
     22        Rebaselined existing LayoutTests to match new behavior.
     23        Also covered by 4 new API tests:
     24            - PasteMixedContent.ImageDataAndPlainText
     25            - PasteMixedContent.ImageDataAndPlainTextAndURL
     26            - PasteMixedContent.ImageDataAndPlainTextAndURLAndHTML
     27            - UIPasteboardTests.DataTransferGetDataWhenPastingImageAndText
     28
     29        * dom/DataTransfer.cpp:
     30        (WebCore::DataTransfer::shouldSuppressGetAndSetDataToAvoidExposingFilePaths const):
     31
     32        If custom pasteboard data is enabled, suppress getData and setData if and only if we might actually expose file
     33        paths (see Pasteboard::fileContentState).
     34
     35        (WebCore::DataTransfer::types const):
     36
     37        Only allow "text/html" or "text/uri-list" in the case where there are actual files in the pasteboard. If there's
     38        only image data, add all of the DOM-safe types back into the list of types.
     39
     40        * platform/Pasteboard.h:
     41        * platform/StaticPasteboard.h:
     42
     43        Add an enum type to represent the result of Pasteboard::fileContentState.
     44        -   NoFileOrImageData indicates that there was nothing on the pasteboard that could be considered a file
     45            from the point of view of the page.
     46        -   InMemoryImage indicates that there are no files on the pasteboard, but there is image data that we consider
     47            to be files, exposed via DataTransfer API.
     48        -   MayContainFilePaths indicates that there might be file paths on the pasteboard. This means that the source
     49            has either written file paths to the pasteboard (for example, through NSFilenamesPboardType) or the source
     50            has written image data along with a URL type of some sort that does not match one of the allowed URL schemes
     51            that are safe to expose (currently, these are http-family, data, or blob).
     52
     53        * platform/cocoa/PasteboardCocoa.mm:
     54        (WebCore::Pasteboard::fileContentState):
     55
     56        Refactor to return one of the three enum types described above.
     57
     58        (WebCore::Pasteboard::containsFiles): Deleted.
     59        * platform/gtk/PasteboardGtk.cpp:
     60        (WebCore::Pasteboard::fileContentState):
     61        (WebCore::Pasteboard::containsFiles): Deleted.
     62        * platform/win/PasteboardWin.cpp:
     63        (WebCore::Pasteboard::fileContentState):
     64        (WebCore::Pasteboard::containsFiles): Deleted.
     65        * platform/wpe/PasteboardWPE.cpp:
     66        (WebCore::Pasteboard::fileContentState):
     67        (WebCore::Pasteboard::containsFiles): Deleted.
     68
     69        Adjust for Pasteboard::fileContentState() tweaks.
     70
    1712018-03-09  Chris Fleizach  <cfleizach@apple.com>
    272
  • trunk/Source/WebCore/dom/DataTransfer.cpp

    r228340 r229503  
    205205    if (!forFileDrag() && !RuntimeEnabledFeatures::sharedFeatures().customPasteboardDataEnabled())
    206206        return false;
    207     return m_pasteboard->containsFiles();
     207    return m_pasteboard->fileContentState() == Pasteboard::FileContentState::MayContainFilePaths;
    208208}
    209209
     
    292292        auto types = m_pasteboard->typesForLegacyUnsafeBindings();
    293293        ASSERT(!types.contains("Files"));
    294         if (m_pasteboard->containsFiles() && addFilesType == AddFilesType::Yes)
     294        if (m_pasteboard->fileContentState() != Pasteboard::FileContentState::NoFileOrImageData && addFilesType == AddFilesType::Yes)
    295295            types.append("Files");
    296296        return types;
     
    302302    });
    303303
    304     if (hasFileBackedItem || m_pasteboard->containsFiles()) {
     304    auto fileContentState = m_pasteboard->fileContentState();
     305    if (hasFileBackedItem || fileContentState != Pasteboard::FileContentState::NoFileOrImageData) {
    305306        Vector<String> types;
    306307        if (addFilesType == AddFilesType::Yes)
    307308            types.append(ASCIILiteral("Files"));
     309
     310        if (fileContentState != Pasteboard::FileContentState::MayContainFilePaths) {
     311            types.appendVector(WTFMove(safeTypes));
     312            return types;
     313        }
     314
    308315        if (safeTypes.contains("text/uri-list"))
    309316            types.append(ASCIILiteral("text/uri-list"));
  • trunk/Source/WebCore/platform/Pasteboard.h

    r229297 r229503  
    221221    virtual WEBCORE_EXPORT void writeCustomData(const PasteboardCustomData&);
    222222
    223     virtual WEBCORE_EXPORT bool containsFiles();
     223    enum class FileContentState { NoFileOrImageData, InMemoryImage, MayContainFilePaths };
     224    virtual WEBCORE_EXPORT FileContentState fileContentState();
    224225    virtual WEBCORE_EXPORT bool canSmartReplace();
    225226
  • trunk/Source/WebCore/platform/StaticPasteboard.h

    r228340 r229503  
    6262    void writeCustomData(const PasteboardCustomData&) final { }
    6363
    64     bool containsFiles() final { return false; }
     64    Pasteboard::FileContentState fileContentState() final { return FileContentState::NoFileOrImageData; }
    6565    bool canSmartReplace() final { return false; }
    6666
  • trunk/Source/WebCore/platform/cocoa/PasteboardCocoa.mm

    r227552 r229503  
    135135}
    136136
    137 bool Pasteboard::containsFiles()
    138 {
    139     if (!platformStrategies()->pasteboardStrategy()->getNumberOfFiles(m_pasteboardName)) {
     137Pasteboard::FileContentState Pasteboard::fileContentState()
     138{
     139    bool mayContainFilePaths = platformStrategies()->pasteboardStrategy()->getNumberOfFiles(m_pasteboardName);
     140    if (!mayContainFilePaths) {
    140141        Vector<String> cocoaTypes;
    141142        platformStrategies()->pasteboardStrategy()->getTypes(cocoaTypes, m_pasteboardName);
    142143        if (cocoaTypes.findMatching([](const String& cocoaType) { return shouldTreatCocoaTypeAsFile(cocoaType); }) == notFound)
    143             return false;
    144     }
    145 
    146     // Enforce changeCount ourselves for security. We check after reading instead of before to be
    147     // sure it doesn't change between our testing the change count and accessing the data.
    148     if (m_changeCount != platformStrategies()->pasteboardStrategy()->changeCount(m_pasteboardName))
    149         return false;
    150 
    151     return true;
     144            return FileContentState::NoFileOrImageData;
     145
     146        bool containsURL = notFound != cocoaTypes.findMatching([] (auto& cocoaType) {
     147#if PLATFORM(MAC)
     148            if (cocoaType == String(legacyURLPasteboardType()))
     149                return true;
     150#endif
     151            return cocoaType == String(kUTTypeURL);
     152        });
     153        mayContainFilePaths = containsURL && !Pasteboard::canExposeURLToDOMWhenPasteboardContainsFiles(readString(ASCIILiteral("text/uri-list")));
     154    }
     155
     156    // Enforce changeCount ourselves for security. We check after reading instead of before to be
     157    // sure it doesn't change between our testing the change count and accessing the data.
     158    if (m_changeCount != platformStrategies()->pasteboardStrategy()->changeCount(m_pasteboardName))
     159        return FileContentState::NoFileOrImageData;
     160
     161    // Even when there's only image data in the pasteboard and no file representations, we still run the risk of exposing file paths
     162    // to the page if the app has written image data to the pasteboard with a corresponding file path as plain text. An example of
     163    // this is copying an image with a local `src` in Safari. To mitigate this, we additionally require that the app has not also
     164    // written URLs to the pasteboard, as this would suggest that the plain text data might contain file paths.
     165    return mayContainFilePaths ? FileContentState::MayContainFilePaths : FileContentState::InMemoryImage;
    152166}
    153167
  • trunk/Source/WebCore/platform/gtk/PasteboardGtk.cpp

    r228340 r229503  
    319319}
    320320
    321 bool Pasteboard::containsFiles()
    322 {
    323     readFromClipboard();
    324     return !m_selectionData->filenames().isEmpty();
     321Pasteboard::FileContentState Pasteboard::fileContentState()
     322{
     323    readFromClipboard();
     324    return m_selectionData->filenames().isEmpty() ? FileContentState::NoFileOrImageData : FileContentState::MayContainFilePaths;
    325325}
    326326
  • trunk/Source/WebCore/platform/win/PasteboardWin.cpp

    r228340 r229503  
    316316};
    317317
    318 bool Pasteboard::containsFiles()
     318Pasteboard::FileContentState Pasteboard::fileContentState()
    319319{
    320320    // FIXME: This implementation can be slightly more efficient by avoiding calls to DragQueryFileW.
    321321    PasteboardFileCounter reader;
    322322    read(reader);
    323     return reader.count;
     323    return reader.count ? FileContentState::MayContainFilePaths : FileContentState::NoFileOrImageData;
    324324}
    325325
  • trunk/Source/WebCore/platform/wpe/PasteboardWPE.cpp

    r228340 r229503  
    126126}
    127127
    128 bool Pasteboard::containsFiles()
     128Pasteboard::FileContentState Pasteboard::fileContentState()
    129129{
    130130    notImplemented();
    131     return false;
     131    return FileContentState::NoFileOrImageData;
    132132}
    133133
  • trunk/Tools/ChangeLog

    r229473 r229503  
     12018-03-10  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        [macOS] Copying a table from the Numbers app and pasting into iCloud Numbers fails
     4        https://bugs.webkit.org/show_bug.cgi?id=183485
     5        <rdar://problem/38041984>
     6
     7        Reviewed by Ryosuke Niwa.
     8
     9        Add new API tests to cover scenarios in which we paste image data alongside text data.
     10
     11        * TestWebKitAPI/Tests/WebKitCocoa/PasteMixedContent.mm:
     12        (TestWebKitAPI::TEST):
     13        * TestWebKitAPI/Tests/ios/UIPasteboardTests.mm:
     14        (TestWebKitAPI::TEST):
     15
    1162018-03-09  Zalan Bujtas  <zalan@apple.com>
    217
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/PasteMixedContent.mm

    r228340 r229503  
    195195}
    196196
     197TEST(PasteMixedContent, ImageDataAndPlainText)
     198{
     199    auto webView = setUpWebView();
     200    writeTypesAndDataToPasteboard(NSPasteboardTypeString, @"Hello world", NSPasteboardTypePNG, [NSData dataWithContentsOfFile:imagePath()], nil);
     201    [webView paste:nil];
     202
     203    EXPECT_WK_STREQ("Files, text/plain", [webView stringByEvaluatingJavaScript:@"types.textContent"]);
     204    EXPECT_WK_STREQ("(STRING, text/plain), (FILE, image/png)", [webView stringByEvaluatingJavaScript:@"items.textContent"]);
     205    EXPECT_WK_STREQ("('image.png', image/png)", [webView stringByEvaluatingJavaScript:@"files.textContent"]);
     206    EXPECT_WK_STREQ("", [webView stringByEvaluatingJavaScript:@"urlData.textContent"]);
     207    EXPECT_WK_STREQ("Hello world", [webView stringByEvaluatingJavaScript:@"textData.textContent"]);
     208    EXPECT_WK_STREQ("", [webView stringByEvaluatingJavaScript:@"htmlData.textContent"]);
     209}
     210
     211TEST(PasteMixedContent, ImageDataAndPlainTextAndURL)
     212{
     213    auto webView = setUpWebView();
     214    writeTypesAndDataToPasteboard(NSPasteboardTypeString, imagePath(), NSURLPboardType, imagePath(), NSPasteboardTypePNG, [NSData dataWithContentsOfFile:imagePath()], nil);
     215    [webView paste:nil];
     216
     217    EXPECT_WK_STREQ("Files", [webView stringByEvaluatingJavaScript:@"types.textContent"]);
     218    EXPECT_WK_STREQ("(FILE, image/png)", [webView stringByEvaluatingJavaScript:@"items.textContent"]);
     219    EXPECT_WK_STREQ("('image.png', image/png)", [webView stringByEvaluatingJavaScript:@"files.textContent"]);
     220    EXPECT_WK_STREQ("", [webView stringByEvaluatingJavaScript:@"urlData.textContent"]);
     221    EXPECT_WK_STREQ("", [webView stringByEvaluatingJavaScript:@"textData.textContent"]);
     222    EXPECT_WK_STREQ("", [webView stringByEvaluatingJavaScript:@"htmlData.textContent"]);
     223}
     224
     225TEST(PasteMixedContent, ImageDataAndPlainTextAndURLAndHTML)
     226{
     227    auto webView = setUpWebView();
     228    writeTypesAndDataToPasteboard(NSPasteboardTypeString, imagePath(), NSURLPboardType, imagePath(), NSPasteboardTypeHTML, markupString(), NSPasteboardTypePNG, [NSData dataWithContentsOfFile:imagePath()], nil);
     229    [webView paste:nil];
     230
     231    EXPECT_WK_STREQ("Files, text/html", [webView stringByEvaluatingJavaScript:@"types.textContent"]);
     232    EXPECT_WK_STREQ("(STRING, text/html), (FILE, image/png)", [webView stringByEvaluatingJavaScript:@"items.textContent"]);
     233    EXPECT_WK_STREQ("('image.png', image/png)", [webView stringByEvaluatingJavaScript:@"files.textContent"]);
     234    EXPECT_WK_STREQ("", [webView stringByEvaluatingJavaScript:@"urlData.textContent"]);
     235    EXPECT_WK_STREQ("", [webView stringByEvaluatingJavaScript:@"textData.textContent"]);
     236    EXPECT_WK_STREQ("HELLO WORLD", [webView stringByEvaluatingJavaScript:@"htmlData.textContent"]);
     237    EXPECT_FALSE([[webView stringByEvaluatingJavaScript:@"rawHTMLData.textContent"] containsString:@"script"]);
     238}
     239
    197240} // namespace TestWebKitAPI
    198241
  • trunk/Tools/TestWebKitAPI/Tests/ios/UIPasteboardTests.mm

    r227859 r229503  
    195195}
    196196
     197TEST(UIPasteboardTests, DataTransferGetDataWhenPastingImageAndText)
     198{
     199    auto webView = setUpWebViewForPasteboardTests(@"DataTransfer");
     200    auto copiedText = retainPtr(@"Apple Inc.");
     201    auto itemProvider = adoptNS([[NSItemProvider alloc] init]);
     202    [itemProvider registerDataRepresentationForTypeIdentifier:(NSString *)kUTTypePNG visibility:NSItemProviderRepresentationVisibilityAll loadHandler:[] (DataLoadCompletionBlock completionHandler) -> NSProgress * {
     203        completionHandler([NSData dataWithContentsOfURL:[[NSBundle mainBundle] URLForResource:@"icon" withExtension:@"png" subdirectory:@"TestWebKitAPI.resources"]], nil);
     204        return nil;
     205    }];
     206    [itemProvider registerDataRepresentationForTypeIdentifier:(NSString *)kUTTypeUTF8PlainText visibility:NSItemProviderRepresentationVisibilityAll loadHandler:[copiedText] (DataLoadCompletionBlock completionHandler) -> NSProgress * {
     207        completionHandler([copiedText dataUsingEncoding:NSUTF8StringEncoding], nil);
     208        return nil;
     209    }];
     210    [UIPasteboard generalPasteboard].itemProviders = @[ itemProvider.get() ];
     211    [webView paste:nil];
     212
     213    EXPECT_WK_STREQ("Files, text/plain", [webView stringByEvaluatingJavaScript:@"types.textContent"]);
     214    EXPECT_WK_STREQ("(STRING, text/plain), (FILE, image/png)", [webView stringByEvaluatingJavaScript:@"items.textContent"]);
     215    EXPECT_WK_STREQ("('image.png', image/png)", [webView stringByEvaluatingJavaScript:@"files.textContent"]);
     216    EXPECT_WK_STREQ("", [webView stringByEvaluatingJavaScript:@"urlData.textContent"]);
     217    EXPECT_WK_STREQ("Apple Inc.", [webView stringByEvaluatingJavaScript:@"textData.textContent"]);
     218    EXPECT_WK_STREQ("", [webView stringByEvaluatingJavaScript:@"htmlData.textContent"]);
     219}
     220
    197221TEST(UIPasteboardTests, DataTransferSetDataCannotWritePlatformTypes)
    198222{
Note: See TracChangeset for help on using the changeset viewer.