Changeset 252627 in webkit


Ignore:
Timestamp:
Nov 19, 2019 7:26:13 AM (4 years ago)
Author:
Wenson Hsieh
Message:

[Clipboard API] Add support for Clipboard.readText()
https://bugs.webkit.org/show_bug.cgi?id=204310
<rdar://problem/57292754>

Reviewed by Ryosuke Niwa.

LayoutTests/imported/w3c:

Rebaseline a couple of imported web platform tests.

  • web-platform-tests/clipboard-apis/async-navigator-clipboard-basics.https-expected.txt:
  • web-platform-tests/clipboard-apis/async-write-text-read-text-manual.https-expected.txt:

Source/WebCore:

Implements readText; see below for more detail.

Tests: editing/async-clipboard/clipboard-do-not-read-text-from-platform-if-text-changes.html

editing/async-clipboard/clipboard-read-text-from-platform.html
editing/async-clipboard/clipboard-read-text-same-origin.html
editing/async-clipboard/clipboard-read-text.html

  • Modules/async-clipboard/Clipboard.cpp:

(WebCore::Clipboard::readText):

Implement the method. This works similarly to Clipboard::read, but immediately reads text data for the first
clipboard item with data for "text/plain", instead of exposing a list of clipboard items.

  • dom/DataTransfer.cpp:

(WebCore::DataTransfer::commitToPasteboard):

If the custom pasteboard data object is empty, then don't bother trying to write it to the platform pasteboard.
This avoids hitting an assertion in WebDragClient::beginDrag that checks to make sure there's no data on the
pasteboard right before beginning a drag in the UI process which was getting hit because we'd otherwise end up
writing just the pasteboard data origin; it also has an added bonus of avoiding an unnecessary sync IPC message.

  • platform/mac/PlatformPasteboardMac.mm:

(WebCore::PlatformPasteboard::write):

Write the custom data type ("com.apple.WebKit.custom-pasteboard-data") when writing PasteboardCustomData to the
pasteboard on macOS, even when the custom pasteboard data only contains an origin. This allows DOM paste
requests to automatically accept when exchanging text data between the same origin via the async clipboard API.

LayoutTests:

Add several new layout tests.

  • editing/async-clipboard/clipboard-do-not-read-text-from-platform-if-text-changes-expected.txt: Added.
  • editing/async-clipboard/clipboard-do-not-read-text-from-platform-if-text-changes.html: Added.

Add a test to verify that if the clipboard changes content in the middle of a call to clipboard.readText, we
will reject the readText() promise and avoid exposing any text to the page.

  • editing/async-clipboard/clipboard-read-text-expected.txt: Added.
  • editing/async-clipboard/clipboard-read-text-from-platform-expected.txt: Added.
  • editing/async-clipboard/clipboard-read-text-from-platform.html: Added.

Add a test to verify that we display DOM paste UI when reading text that was written to the pasteboard directly
via platform API.

  • editing/async-clipboard/clipboard-read-text-same-origin-expected.txt: Added.
  • editing/async-clipboard/clipboard-read-text-same-origin.html: Added.

Add a test to verify that we allow the page to access same origin text data on the pasteboard using readText,
during a user gesture.

  • editing/async-clipboard/clipboard-read-text.html: Added.

Add a basic test to verify that readText works when the page writes text to the clipboard using DataTransfer and
document.execCommand.

  • platform/gtk/TestExpectations:
  • platform/mac-wk1/TestExpectations:
  • platform/win/TestExpectations:
  • platform/wpe/TestExpectations:
Location:
trunk
Files:
8 added
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r252623 r252627  
     12019-11-19  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        [Clipboard API] Add support for Clipboard.readText()
     4        https://bugs.webkit.org/show_bug.cgi?id=204310
     5        <rdar://problem/57292754>
     6
     7        Reviewed by Ryosuke Niwa.
     8
     9        Add several new layout tests.
     10
     11        * editing/async-clipboard/clipboard-do-not-read-text-from-platform-if-text-changes-expected.txt: Added.
     12        * editing/async-clipboard/clipboard-do-not-read-text-from-platform-if-text-changes.html: Added.
     13
     14        Add a test to verify that if the clipboard changes content in the middle of a call to clipboard.readText, we
     15        will reject the readText() promise and avoid exposing any text to the page.
     16
     17        * editing/async-clipboard/clipboard-read-text-expected.txt: Added.
     18        * editing/async-clipboard/clipboard-read-text-from-platform-expected.txt: Added.
     19        * editing/async-clipboard/clipboard-read-text-from-platform.html: Added.
     20
     21        Add a test to verify that we display DOM paste UI when reading text that was written to the pasteboard directly
     22        via platform API.
     23
     24        * editing/async-clipboard/clipboard-read-text-same-origin-expected.txt: Added.
     25        * editing/async-clipboard/clipboard-read-text-same-origin.html: Added.
     26
     27        Add a test to verify that we allow the page to access same origin text data on the pasteboard using readText,
     28        during a user gesture.
     29
     30        * editing/async-clipboard/clipboard-read-text.html: Added.
     31
     32        Add a basic test to verify that readText works when the page writes text to the clipboard using DataTransfer and
     33        document.execCommand.
     34
     35        * platform/gtk/TestExpectations:
     36        * platform/mac-wk1/TestExpectations:
     37        * platform/win/TestExpectations:
     38        * platform/wpe/TestExpectations:
     39
    1402019-11-18  John Wilander  <wilander@apple.com>
    241
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r252598 r252627  
     12019-11-19  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        [Clipboard API] Add support for Clipboard.readText()
     4        https://bugs.webkit.org/show_bug.cgi?id=204310
     5        <rdar://problem/57292754>
     6
     7        Reviewed by Ryosuke Niwa.
     8
     9        Rebaseline a couple of imported web platform tests.
     10
     11        * web-platform-tests/clipboard-apis/async-navigator-clipboard-basics.https-expected.txt:
     12        * web-platform-tests/clipboard-apis/async-write-text-read-text-manual.https-expected.txt:
     13
    1142019-11-18  Said Abou-Hallawa  <sabouhallawa@apple.com>
    215
  • trunk/LayoutTests/imported/w3c/web-platform-tests/clipboard-apis/async-navigator-clipboard-basics.https-expected.txt

    r252561 r252627  
    88PASS navigator.clipboard.writeText() fails (expect DOMString)
    99FAIL navigator.clipboard.read() succeeds assert_true: expected true got false
    10 FAIL navigator.clipboard.readText() succeeds promise_test: Unhandled rejection with value: object "NotSupportedError: The operation is not supported."
     10PASS navigator.clipboard.readText() succeeds
    1111
  • trunk/LayoutTests/imported/w3c/web-platform-tests/clipboard-apis/async-write-text-read-text-manual.https-expected.txt

    r250856 r252627  
    11Note: This is a manual test because it writes/reads to the shared system clipboard and thus cannot be run async with other tests that might interact with the clipboard.
    22
    3 Harness Error (TIMEOUT), message = null
     3PASS Verify write and read clipboard (DOMString)
    44
    5 TIMEOUT Verify write and read clipboard (DOMString) Test timed out
    6 
  • trunk/LayoutTests/platform/gtk/TestExpectations

    r252498 r252627  
    12961296webkit.org/b/204112 editing/async-clipboard/clipboard-change-data-while-reading.html [ Crash ]
    12971297webkit.org/b/204112 editing/async-clipboard/clipboard-get-type-with-old-items.html [ Crash ]
     1298webkit.org/b/204112 editing/async-clipboard/clipboard-read-text-from-platform.html [ Crash ]
     1299webkit.org/b/204112 editing/async-clipboard/clipboard-do-not-read-text-from-platform-if-text-changes.html [ Crash ]
    12981300
    12991301#////////////////////////////////////////////////////////////////////////////////////////
  • trunk/LayoutTests/platform/mac-wk1/TestExpectations

    r252397 r252627  
    7070# DOM paste access requests are not implemented in WebKit1.
    7171editing/async-clipboard/clipboard-change-data-while-reading.html [ Skip ]
     72editing/async-clipboard/clipboard-do-not-read-text-from-platform-if-text-changes.html [ Skip ]
     73editing/async-clipboard/clipboard-read-text-from-platform.html [ Skip ]
     74editing/async-clipboard/clipboard-read-text-same-origin.html [ Skip ]
    7275
    7376imported/w3c/web-platform-tests/websockets/Close-1000-reason.any.html [ Pass Failure ]
  • trunk/LayoutTests/platform/win/TestExpectations

    r252598 r252627  
    11951195webkit.org/b/203100 editing/async-clipboard/clipboard-write-items-twice.html [ Skip ]
    11961196webkit.org/b/203100 editing/async-clipboard/clipboard-write-text.html [ Skip ]
     1197webkit.org/b/203100 editing/async-clipboard/clipboard-do-not-read-text-from-platform-if-text-changes.html [ Skip ]
     1198webkit.org/b/203100 editing/async-clipboard/clipboard-read-text-from-platform.html [ Skip ]
     1199webkit.org/b/203100 editing/async-clipboard/clipboard-read-text-same-origin.html [ Skip ]
     1200webkit.org/b/203100 editing/async-clipboard/clipboard-read-text.html [ Skip ]
    11971201
    11981202webkit.org/b/140783 [ Release ] editing/pasteboard/copy-standalone-image.html [ Failure ImageOnlyFailure ]
  • trunk/LayoutTests/platform/wpe/TestExpectations

    r252366 r252627  
    790790webkit.org/b/204112 editing/async-clipboard/clipboard-change-data-while-reading.html [ Crash ]
    791791webkit.org/b/204112 editing/async-clipboard/clipboard-get-type-with-old-items.html [ Crash ]
     792webkit.org/b/204112 editing/async-clipboard/clipboard-read-text-from-platform.html [ Crash ]
     793webkit.org/b/204112 editing/async-clipboard/clipboard-do-not-read-text-from-platform-if-text-changes.html [ Crash ]
    792794
    793795#////////////////////////////////////////////////////////////////////////////////////////
  • trunk/Source/WebCore/ChangeLog

    r252626 r252627  
     12019-11-19  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        [Clipboard API] Add support for Clipboard.readText()
     4        https://bugs.webkit.org/show_bug.cgi?id=204310
     5        <rdar://problem/57292754>
     6
     7        Reviewed by Ryosuke Niwa.
     8
     9        Implements readText; see below for more detail.
     10
     11        Tests: editing/async-clipboard/clipboard-do-not-read-text-from-platform-if-text-changes.html
     12               editing/async-clipboard/clipboard-read-text-from-platform.html
     13               editing/async-clipboard/clipboard-read-text-same-origin.html
     14               editing/async-clipboard/clipboard-read-text.html
     15
     16        * Modules/async-clipboard/Clipboard.cpp:
     17        (WebCore::Clipboard::readText):
     18
     19        Implement the method. This works similarly to Clipboard::read, but immediately reads text data for the first
     20        clipboard item with data for "text/plain", instead of exposing a list of clipboard items.
     21
     22        * dom/DataTransfer.cpp:
     23        (WebCore::DataTransfer::commitToPasteboard):
     24
     25        If the custom pasteboard data object is empty, then don't bother trying to write it to the platform pasteboard.
     26        This avoids hitting an assertion in WebDragClient::beginDrag that checks to make sure there's no data on the
     27        pasteboard right before beginning a drag in the UI process which was getting hit because we'd otherwise end up
     28        writing just the pasteboard data origin; it also has an added bonus of avoiding an unnecessary sync IPC message.
     29
     30        * platform/mac/PlatformPasteboardMac.mm:
     31        (WebCore::PlatformPasteboard::write):
     32
     33        Write the custom data type ("com.apple.WebKit.custom-pasteboard-data") when writing PasteboardCustomData to the
     34        pasteboard on macOS, even when the custom pasteboard data only contains an origin. This allows DOM paste
     35        requests to automatically accept when exchanging text data between the same origin via the async clipboard API.
     36
    1372019-11-19  Chris Dumez  <cdumez@apple.com>
    238
  • trunk/Source/WebCore/Modules/async-clipboard/Clipboard.cpp

    r252561 r252627  
    9898void Clipboard::readText(Ref<DeferredPromise>&& promise)
    9999{
    100     promise->reject(NotSupportedError);
     100    auto frame = makeRefPtr(this->frame());
     101    if (!frame) {
     102        promise->reject(NotAllowedError);
     103        return;
     104    }
     105
     106    auto pasteboard = Pasteboard::createForCopyAndPaste();
     107    auto changeCountAtStart = pasteboard->changeCount();
     108    if (!frame->requestDOMPasteAccess()) {
     109        promise->reject(NotAllowedError);
     110        return;
     111    }
     112
     113    auto allInfo = pasteboard->allPasteboardItemInfo();
     114    if (!allInfo) {
     115        promise->reject(NotAllowedError);
     116        return;
     117    }
     118
     119    String text;
     120    for (size_t index = 0; index < allInfo->size(); ++index) {
     121        if (allInfo->at(index).webSafeTypesByFidelity.contains("text/plain"_s)) {
     122            PasteboardPlainText plainTextReader;
     123            pasteboard->read(plainTextReader, PlainTextURLReadingPolicy::IgnoreURL, index);
     124            text = WTFMove(plainTextReader.text);
     125            break;
     126        }
     127    }
     128
     129    if (changeCountAtStart == pasteboard->changeCount())
     130        promise->resolve<IDLDOMString>(WTFMove(text));
     131    else
     132        promise->reject(NotAllowedError);
    101133}
    102134
  • trunk/Source/WebCore/dom/DataTransfer.cpp

    r251117 r252627  
    426426    ASSERT(is<StaticPasteboard>(*m_pasteboard) && !is<StaticPasteboard>(nativePasteboard));
    427427    PasteboardCustomData customData = downcast<StaticPasteboard>(*m_pasteboard).takeCustomData();
     428    if (!customData.hasData())
     429        return;
     430
    428431    if (RuntimeEnabledFeatures::sharedFeatures().customPasteboardDataEnabled()) {
    429432        customData.setOrigin(m_originIdentifier);
  • trunk/Source/WebCore/platform/mac/PlatformPasteboardMac.mm

    r252450 r252627  
    232232    });
    233233
    234     bool hasSameOriginCustomData = data.hasSameOriginCustomData();
    235     if (hasSameOriginCustomData)
     234    bool shouldWriteCustomData = data.hasSameOriginCustomData() || !data.origin().isEmpty();
     235    if (shouldWriteCustomData)
    236236        [types addObject:@(PasteboardCustomData::cocoaType())];
    237237
     
    245245    });
    246246
    247     if (hasSameOriginCustomData) {
     247    if (shouldWriteCustomData) {
    248248        if (auto serializedCustomData = data.createSharedBuffer()->createNSData())
    249249            [m_pasteboard setData:serializedCustomData.get() forType:@(PasteboardCustomData::cocoaType())];
Note: See TracChangeset for help on using the changeset viewer.