Changeset 223140 in webkit


Ignore:
Timestamp:
Oct 10, 2017 1:50:20 PM (7 years ago)
Author:
rniwa@webkit.org
Message:

Loading should be disabled while constructing the fragment in WebContentReader::readWebArchive
https://bugs.webkit.org/show_bug.cgi?id=178118

Reviewed by Antti Koivisto.

Source/WebCore:

Disable image loading while constructing the document fragment in WebContentReader::readWebArchive
as we do in createFragmentAndAddResources for RTF/RTFD. This refactoring is needed to start using
blob URL in the pasted document fragment for webkit.org/b/124391.

Also modified WebContentReader::readWebArchive to take a reference to SharedBuffer instead of a pointer.

No new tests since existing tests have been updated to cover this behavior change.

  • editing/WebContentReader.h:
  • editing/cocoa/WebContentReaderCocoa.mm:

(WebCore::WebContentReader::readWebArchive): Use DeferredLoadingScope to disable the loader and images
while constructing the document fragment.

  • platform/Pasteboard.h:
  • platform/ios/PasteboardIOS.mm:

(WebCore::readPasteboardWebContentDataForType):

  • platform/mac/PasteboardMac.mm:

(WebCore::Pasteboard::read):

LayoutTests:

Updated the existing tests to wait for images to load in each step explicitly instead of relying on
them being loaded synchronously or that it's loaded within 100-200ms.

  • editing/pasteboard/4641033.html:
  • editing/pasteboard/4947130.html:
  • editing/pasteboard/4989774.html:
  • editing/pasteboard/drag-selected-image-to-contenteditable.html:
  • editing/selection/drag-to-contenteditable-iframe.html:
  • platform/ios/TestExpectations: Skipped editing/selection/drag-to-contenteditable-iframe.html on iOS

since we don't support testing drag & drop on iOS. Also added [ Skip ] to other entires there.

Location:
trunk
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r223135 r223140  
     12017-10-10  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Loading should be disabled while constructing the fragment in WebContentReader::readWebArchive
     4        https://bugs.webkit.org/show_bug.cgi?id=178118
     5
     6        Reviewed by Antti Koivisto.
     7
     8        Updated the existing tests to wait for images to load in each step explicitly instead of relying on
     9        them being loaded synchronously or that it's loaded within 100-200ms.
     10
     11        * editing/pasteboard/4641033.html:
     12        * editing/pasteboard/4947130.html:
     13        * editing/pasteboard/4989774.html:
     14        * editing/pasteboard/drag-selected-image-to-contenteditable.html:
     15        * editing/selection/drag-to-contenteditable-iframe.html:
     16        * platform/ios/TestExpectations: Skipped editing/selection/drag-to-contenteditable-iframe.html on iOS
     17        since we don't support testing drag & drop on iOS. Also added [ Skip ] to other entires there.
     18
    1192017-10-10  Chris Dumez  <cdumez@apple.com>
    220
  • trunk/LayoutTests/editing/pasteboard/4641033.html

    r120173 r223140  
    1313    var start = document.getElementById("start");
    1414    var end = document.getElementById("end");
    15    
     15
    1616    var s = window.getSelection();
    1717    s.setBaseAndExtent(start, 0, end, end.childNodes.length);
    18    
     18
    1919    document.execCommand("Copy");
    20    
     20
    2121    s.setPosition(document.getElementById("paste"), 0);
    2222    document.execCommand("Paste");
    23    
     23
     24    const pastedImageElement = document.querySelector('#paste img');
     25    if (pastedImageElement.complete)
     26        finish();
     27    else
     28        pastedImageElement.onload = finish;
     29}
     30function finish() {
    2431    if (window.testRunner)
    25         window.testRunner.notifyDone();   
    26    
     32        window.testRunner.notifyDone();
    2733}
    2834if (window.testRunner)
    2935    window.testRunner.waitUntilDone();
    30 window.setTimeout(runTest, 100);
     36window.onload = runTest;
    3137
    3238</script>
  • trunk/LayoutTests/editing/pasteboard/4947130.html

    r120173 r223140  
    66<script>
    77
     8if (window.testRunner)
     9    testRunner.waitUntilDone();
     10
    811function runTest() {
    912    if (!window.testRunner)
    1013        return;
    11    
    12     window.testRunner.waitUntilDone(); 
    13    
    14     window.setTimeout(step2, 200);
    15 }
    16 
    17 function step2() {
    1814
    1915    var img = document.getElementById("img");
     
    2218    var x = left + img.offsetWidth / 2;
    2319    var y = top + img.offsetHeight / 2;
    24    
     20
    2521    eventSender.mouseMoveTo(x, y);
    2622    eventSender.mouseDown();
     
    3026    eventSender.mouseUp();
    3127
    32     window.testRunner.notifyDone();
     28    if (img.complete)
     29        testRunner.notifyDone();
     30    else
     31        img.onload = () => testRunner.notifyDone();
    3332}
    3433
    35 runTest();
     34window.onload = runTest;
    3635</script>
  • trunk/LayoutTests/editing/pasteboard/4989774.html

    r120173 r223140  
    22
    33<script>
    4 function partTwo() {
     4function runTest()
     5{
    56    sel.setBaseAndExtent(body, 0, body, body.childNodes.length);
    67    document.execCommand("Copy");
     
    1011    document.execCommand("InsertLineBreak");
    1112    document.execCommand("InsertText", false, "This tests for a bug where an images pasted on the same line would appear on different lines.  You should see several pictures above all in the same line/paragraph.");
    12     window.testRunner.notifyDone();   
     13    Promise.all(Array.from(document.querySelectorAll('img')).map((img) => {
     14        if (img.complete)
     15            return;
     16        return new Promise((resolve) => img.onload = resolve);
     17    })).then(() => testRunner.notifyDone());
    1318}
    1419
     
    1823    window.testRunner.waitUntilDone();
    1924   
    20     window.setTimeout(partTwo, 200);
     25    window.onload = runTest;
    2126} else {
    2227    document.execCommand("SelectAll")
  • trunk/LayoutTests/editing/pasteboard/drag-selected-image-to-contenteditable.html

    r120173 r223140  
    2020    if (window.testRunner)
    2121        testRunner.waitUntilDone();
    22     // Let the subframe come into being.
    23     window.setTimeout(step2, 100);
    2422    e = document.getElementById("dragme");
    2523    setSelectionCommand(e, 0, e, 1);
    26 }
    2724
    28 function step2()
    29 {
    3025    if (!window.testRunner) {
    3126        log("This test uses the eventSender.  To run it manually, drag the selected image into the editable div and drop it.  It should appear inside the editable div.");
     
    4742    eventSender.mouseMoveTo(x, y);
    4843    eventSender.mouseUp();
    49    
    50     testRunner.notifyDone();
     44
     45    Promise.all(Array.from(document.querySelectorAll('img')).map((img) => {
     46        if (img.complete)
     47            return;
     48        return new Promise((resolve) => img.onload = resolve);
     49    })).then(() => testRunner.notifyDone());
    5150}
     51
    5252</script>
    5353</head>
  • trunk/LayoutTests/editing/selection/drag-to-contenteditable-iframe.html

    r120173 r223140  
    3232    eventSender.leapForward(1000);
    3333   
    34     e = document.getElementById("frame");
    35     x = e.offsetLeft + e.offsetWidth / 2;
    36     y = e.offsetTop + e.offsetHeight / 2;
     34    const frame = document.getElementById("frame");
     35    x = frame.offsetLeft + frame.offsetWidth / 2;
     36    y = frame.offsetTop + frame.offsetHeight / 2;
    3737   
    3838    eventSender.mouseMoveTo(x, y);
    3939    eventSender.mouseUp();
    40    
    41     testRunner.notifyDone();
     40
     41    const img = frame.contentDocument.querySelector('img');
     42    if (img.complete)
     43        testRunner.notifyDone();
     44    else
     45        img.onload = () => testRunner.notifyDone();
    4246}
    4347
  • trunk/LayoutTests/platform/ios/TestExpectations

    r223016 r223140  
    237237
    238238# Drag-and-drop is not supported:
    239 editing/pasteboard/datatransfer-items-drop-plaintext-file.html
    240 editing/pasteboard/drag-link-with-data-transfer-adds-trusted-link-to-pasteboard.html
    241 fast/events/bogus-dropEffect-effectAllowed.html
    242 fast/events/clear-drag-state.html
    243 fast/events/clear-edit-drag-state.html
    244 fast/events/content-changed-during-drop.html
    245 fast/events/crash-on-mutate-during-drop.html
    246 fast/events/drag-and-drop-link-fast-multiple-times-does-not-crash.html
    247 fast/events/drag-and-drop-link-containing-block.html
    248 fast/events/drag-and-drop-autoscroll-inner-frame.html
    249 fast/events/drag-and-drop-autoscroll.html
    250 fast/events/drag-and-drop-dataTransfer-types-nocrash.html
    251 fast/events/drag-and-drop-fire-drag-dragover.html
    252 fast/events/drag-and-drop-set-drag-data-arguments.html
    253 fast/events/drag-and-drop-subframe-dataTransfer.html
    254 fast/events/drag-and-drop.html
    255 fast/events/drag-customData.html
    256 fast/events/drag-dataTransferItemList-file-handling.html
    257 fast/events/drag-dataTransferItemList.html
    258 fast/events/drag-display-none-element.html
    259 fast/events/drag-file-crash.html
    260 fast/events/drag-image-filename.html
    261 fast/events/drag-in-frames.html
    262 fast/events/drag-and-drop-link.html
    263 fast/events/drag-and-drop-link-into-focused-contenteditable.html
    264 fast/events/drag-outside-window.html
    265 fast/events/drag-parent-node.html
    266 fast/events/drag-selects-image.html
    267 fast/events/drag-to-navigate.html
    268 fast/events/draggable-div-nodata.html
    269 fast/events/draggable-div-customdata.html
    270 fast/events/drop-handler-should-not-stop-navigate.html
    271 fast/events/drop-with-file-paths.html
    272 fast/events/dropzone-001.html
    273 fast/events/dropzone-002.html
    274 fast/events/dropzone-003.html
    275 fast/events/dropzone-004.html
    276 fast/events/dropzone-005.html
    277 fast/events/file-input-hidden-in-ondrop.html
    278 fast/events/input-element-display-none-in-dragleave-crash.html
    279 fast/events/moving-text-should-fire-drop-and-dragend-events-2.html
    280 fast/events/moving-text-should-fire-drop-and-dragend-events.html
    281 fast/events/only-valid-drop-targets-receive-file-drop.html
    282 fast/events/prevent-drag-to-navigate.html
    283 fast/events/standalone-image-drag-to-editable.html
    284 fast/files/local-file-drag-security.html
     239editing/pasteboard/datatransfer-items-drop-plaintext-file.html [ Skip ]
     240editing/pasteboard/drag-link-with-data-transfer-adds-trusted-link-to-pasteboard.html [ Skip ]
     241editing/selection/drag-to-contenteditable-iframe.html [ Skip ]
     242fast/events/bogus-dropEffect-effectAllowed.html [ Skip ]
     243fast/events/clear-drag-state.html [ Skip ]
     244fast/events/clear-edit-drag-state.html [ Skip ]
     245fast/events/content-changed-during-drop.html [ Skip ]
     246fast/events/crash-on-mutate-during-drop.html [ Skip ]
     247fast/events/drag-and-drop-link-fast-multiple-times-does-not-crash.html [ Skip ]
     248fast/events/drag-and-drop-link-containing-block.html [ Skip ]
     249fast/events/drag-and-drop-autoscroll-inner-frame.html [ Skip ]
     250fast/events/drag-and-drop-autoscroll.html [ Skip ]
     251fast/events/drag-and-drop-dataTransfer-types-nocrash.html [ Skip ]
     252fast/events/drag-and-drop-fire-drag-dragover.html [ Skip ]
     253fast/events/drag-and-drop-set-drag-data-arguments.html [ Skip ]
     254fast/events/drag-and-drop-subframe-dataTransfer.html [ Skip ]
     255fast/events/drag-and-drop.html [ Skip ]
     256fast/events/drag-customData.html [ Skip ]
     257fast/events/drag-dataTransferItemList-file-handling.html [ Skip ]
     258fast/events/drag-dataTransferItemList.html [ Skip ]
     259fast/events/drag-display-none-element.html [ Skip ]
     260fast/events/drag-file-crash.html [ Skip ]
     261fast/events/drag-image-filename.html [ Skip ]
     262fast/events/drag-in-frames.html [ Skip ]
     263fast/events/drag-and-drop-link.html [ Skip ]
     264fast/events/drag-and-drop-link-into-focused-contenteditable.html [ Skip ]
     265fast/events/drag-outside-window.html [ Skip ]
     266fast/events/drag-parent-node.html [ Skip ]
     267fast/events/drag-selects-image.html [ Skip ]
     268fast/events/drag-to-navigate.html [ Skip ]
     269fast/events/draggable-div-nodata.html [ Skip ]
     270fast/events/draggable-div-customdata.html [ Skip ]
     271fast/events/drop-handler-should-not-stop-navigate.html [ Skip ]
     272fast/events/drop-with-file-paths.html [ Skip ]
     273fast/events/dropzone-001.html [ Skip ]
     274fast/events/dropzone-002.html [ Skip ]
     275fast/events/dropzone-003.html [ Skip ]
     276fast/events/dropzone-004.html [ Skip ]
     277fast/events/dropzone-005.html [ Skip ]
     278fast/events/file-input-hidden-in-ondrop.html [ Skip ]
     279fast/events/input-element-display-none-in-dragleave-crash.html [ Skip ]
     280fast/events/moving-text-should-fire-drop-and-dragend-events-2.html [ Skip ]
     281fast/events/moving-text-should-fire-drop-and-dragend-events.html [ Skip ]
     282fast/events/only-valid-drop-targets-receive-file-drop.html [ Skip ]
     283fast/events/prevent-drag-to-navigate.html [ Skip ]
     284fast/events/standalone-image-drag-to-editable.html [ Skip ]
     285fast/files/local-file-drag-security.html [ Skip ]
    285286fast/history/page-cache-createObjectURL.html [ Skip ]
    286 http/tests/local/drag-over-remote-content.html
    287 http/tests/local/fileapi/send-dragged-file.html
    288 http/tests/local/fileapi/send-sliced-dragged-file.html
    289 http/tests/misc/bubble-drag-events.html
    290 http/tests/security/drag-drop-local-file.html
    291 http/tests/security/drag-drop-same-unique-origin.html
    292 http/tests/security/drag-over-remote-content-iframe.html
     287http/tests/local/drag-over-remote-content.html [ Skip ]
     288http/tests/local/fileapi/send-dragged-file.html [ Skip ]
     289http/tests/local/fileapi/send-sliced-dragged-file.html [ Skip ]
     290http/tests/misc/bubble-drag-events.html [ Skip ]
     291http/tests/security/drag-drop-local-file.html [ Skip ]
     292http/tests/security/drag-drop-same-unique-origin.html [ Skip ]
     293http/tests/security/drag-over-remote-content-iframe.html [ Skip ]
    293294
    294295# No support for force events
  • trunk/Source/WebCore/ChangeLog

    r223139 r223140  
     12017-10-10  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Loading should be disabled while constructing the fragment in WebContentReader::readWebArchive
     4        https://bugs.webkit.org/show_bug.cgi?id=178118
     5
     6        Reviewed by Antti Koivisto.
     7
     8        Disable image loading while constructing the document fragment in WebContentReader::readWebArchive
     9        as we do in createFragmentAndAddResources for RTF/RTFD. This refactoring is needed to start using
     10        blob URL in the pasted document fragment for webkit.org/b/124391.
     11
     12        Also modified WebContentReader::readWebArchive to take a reference to SharedBuffer instead of a pointer.
     13
     14        No new tests since existing tests have been updated to cover this behavior change.
     15
     16        * editing/WebContentReader.h:
     17        * editing/cocoa/WebContentReaderCocoa.mm:
     18        (WebCore::WebContentReader::readWebArchive): Use DeferredLoadingScope to disable the loader and images
     19        while constructing the document fragment.
     20        * platform/Pasteboard.h:
     21        * platform/ios/PasteboardIOS.mm:
     22        (WebCore::readPasteboardWebContentDataForType):
     23        * platform/mac/PasteboardMac.mm:
     24        (WebCore::Pasteboard::read):
     25
    1262017-10-10  Antti Koivisto  <antti@apple.com>
    227
  • trunk/Source/WebCore/editing/WebContentReader.h

    r222062 r223140  
    5555private:
    5656#if PLATFORM(COCOA)
    57     bool readWebArchive(SharedBuffer*) override;
     57    bool readWebArchive(SharedBuffer&) override;
    5858    bool readFilenames(const Vector<String>&) override;
    5959    bool readHTML(const String&) override;
  • trunk/Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm

    r223020 r223140  
    180180}
    181181
    182 bool WebContentReader::readWebArchive(SharedBuffer* buffer)
    183 {
    184     if (frame.settings().preferMIMETypeForImages())
    185         return false;
    186 
    187     if (!frame.document())
    188         return false;
    189 
    190     if (!buffer)
    191         return false;
    192 
    193     auto archive = LegacyWebArchive::create(URL(), *buffer);
     182bool WebContentReader::readWebArchive(SharedBuffer& buffer)
     183{
     184    if (frame.settings().preferMIMETypeForImages() || !frame.document())
     185        return false;
     186
     187    auto archive = LegacyWebArchive::create(URL(), buffer);
    194188    if (!archive)
    195189        return false;
     
    203197        return false;
    204198
    205     // FIXME: The code in createFragmentAndAddResources calls setDefersLoading(true). Don't we need that here?
     199    DeferredLoadingScope scope(frame);
     200    auto markupString = String::fromUTF8(mainResource->data().data(), mainResource->data().size());
     201    addFragment(createFragmentFromMarkup(*frame.document(), markupString, mainResource->url(), DisallowScriptingAndPluginContent));
     202
    206203    if (DocumentLoader* loader = frame.loader().documentLoader())
    207204        loader->addAllArchiveResources(*archive);
    208205
    209     auto markupString = String::fromUTF8(mainResource->data().data(), mainResource->data().size());
    210     addFragment(createFragmentFromMarkup(*frame.document(), markupString, mainResource->url(), DisallowScriptingAndPluginContent));
    211206    return true;
    212207}
  • trunk/Source/WebCore/platform/Pasteboard.h

    r222761 r223140  
    131131
    132132#if !(PLATFORM(GTK) || PLATFORM(WIN))
    133     virtual bool readWebArchive(SharedBuffer*) = 0;
     133    virtual bool readWebArchive(SharedBuffer&) = 0;
    134134    virtual bool readFilenames(const Vector<String>&) = 0;
    135135    virtual bool readHTML(const String&) = 0;
  • trunk/Source/WebCore/platform/ios/PasteboardIOS.mm

    r222956 r223140  
    166166{
    167167    if ([type isEqualToString:WebArchivePboardType]) {
    168         RefPtr<SharedBuffer> buffer = strategy.readBufferFromPasteboard(itemIndex, WebArchivePboardType, pasteboardName);
    169         return reader.readWebArchive(buffer.get());
     168        auto buffer = strategy.readBufferFromPasteboard(itemIndex, WebArchivePboardType, pasteboardName);
     169        return buffer && reader.readWebArchive(*buffer);
    170170    }
    171171
  • trunk/Source/WebCore/platform/mac/PasteboardMac.mm

    r222702 r223140  
    334334
    335335    if (types.contains(WebArchivePboardType)) {
    336         if (RefPtr<SharedBuffer> buffer = strategy.bufferForType(WebArchivePboardType, m_pasteboardName)) {
    337             if (reader.readWebArchive(buffer.get()))
     336        if (auto buffer = strategy.bufferForType(WebArchivePboardType, m_pasteboardName)) {
     337            if (reader.readWebArchive(*buffer))
    338338                return;
    339339        }
Note: See TracChangeset for help on using the changeset viewer.