Changeset 229177 in webkit


Ignore:
Timestamp:
Mar 2, 2018 9:41:07 AM (6 years ago)
Author:
Chris Dumez
Message:

Converting a load to a download does not work with async policy delegates
https://bugs.webkit.org/show_bug.cgi?id=183254
<rdar://problem/38035334>

Reviewed by Youenn Fablet.

Source/WebCore:

Update DocumentLoader::responseReceived() to call didReceiveResponsePolicy()
on the mainResourceLoader *after* calling continueAfterContentPolicy(),
not *before*. This makes sure that the WebResourceLoader sends the
NetworkResourceLoader::ContinueDidReceiveResponse IPC back to the Network
Process *after* the policy decision has been processed, which restores the
pre-r228852 order.

Test: fast/dom/HTMLAnchorElement/anchor-file-blob-convert-to-download-async-delegate.html

  • loader/DocumentLoader.cpp:

(WebCore::DocumentLoader::responseReceived):

Tools:

Add layout test infrastructure for responding to the decidePolicyForNavigationResponse
delegate asynchronously.

  • WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl:
  • WebKitTestRunner/InjectedBundle/InjectedBundlePage.cpp:

(WTR::InjectedBundlePage::decidePolicyForResponse):

  • WebKitTestRunner/InjectedBundle/TestRunner.cpp:

(WTR::TestRunner::setShouldDecideResponsePolicyAfterDelay):

  • WebKitTestRunner/InjectedBundle/TestRunner.h:

(WTR::TestRunner::shouldDecideResponsePolicyAfterDelay const):

  • WebKitTestRunner/TestController.cpp:

(WTR::TestController::resetStateToConsistentValues):
(WTR::TestController::decidePolicyForNavigationResponse):

  • WebKitTestRunner/TestController.h:

(WTR::TestController::setShouldDecideResponsePolicyAfterDelay):

  • WebKitTestRunner/TestInvocation.cpp:

(WTR::TestInvocation::didReceiveMessageFromInjectedBundle):

LayoutTests:

Add layout test coverage.

  • fast/dom/HTMLAnchorElement/anchor-file-blob-convert-to-download-async-delegate-expected.txt: Added.
  • fast/dom/HTMLAnchorElement/anchor-file-blob-convert-to-download-async-delegate.html: Added.
Location:
trunk
Files:
2 added
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r229171 r229177  
     12018-03-02  Chris Dumez  <cdumez@apple.com>
     2
     3        Converting a load to a download does not work with async policy delegates
     4        https://bugs.webkit.org/show_bug.cgi?id=183254
     5        <rdar://problem/38035334>
     6
     7        Reviewed by Youenn Fablet.
     8
     9        Add layout test coverage.
     10
     11        * fast/dom/HTMLAnchorElement/anchor-file-blob-convert-to-download-async-delegate-expected.txt: Added.
     12        * fast/dom/HTMLAnchorElement/anchor-file-blob-convert-to-download-async-delegate.html: Added.
     13
    1142018-03-02  Claudio Saavedra  <csaavedra@igalia.com>
    215
  • trunk/LayoutTests/platform/ios-wk1/TestExpectations

    r228587 r229177  
    13351335# testRunner.setShouldDownloadUndisplayableMIMETypes() is not supported on WK1.
    13361336fast/dom/HTMLAnchorElement/anchor-file-blob-convert-to-download.html [ Skip ]
     1337fast/dom/HTMLAnchorElement/anchor-file-blob-convert-to-download-async-delegate.html [ Skip ]
    13371338
    13381339webkit.org/b/137572 scrollbars/scrollbar-iframe-click-does-not-blur-content.html [ Failure ]
  • trunk/LayoutTests/platform/ios-wk2/TestExpectations

    r228984 r229177  
    11301130webkit.org/b/156067 fast/dom/HTMLAnchorElement/anchor-download.html [ Skip ]
    11311131webkit.org/b/156067 fast/dom/HTMLAnchorElement/anchor-file-blob-convert-to-download.html [ Skip ]
     1132webkit.org/b/156067 fast/dom/HTMLAnchorElement/anchor-file-blob-convert-to-download-async-delegate.html [ Skip ]
    11321133webkit.org/b/156067 fast/dom/HTMLAnchorElement/anchor-file-blob-download.html [ Skip ]
    11331134webkit.org/b/156067 fast/dom/HTMLAnchorElement/anchor-file-blob-download-includes-backslash.html [ Skip ]
  • trunk/LayoutTests/platform/mac-wk1/TestExpectations

    r229086 r229177  
    304304# testRunner.setShouldDownloadUndisplayableMIMETypes() is not supported on WK1.
    305305fast/dom/HTMLAnchorElement/anchor-file-blob-convert-to-download.html [ Skip ]
     306fast/dom/HTMLAnchorElement/anchor-file-blob-convert-to-download-async-delegate.html [ Skip ]
    306307
    307308webkit.org/b/156629 imported/w3c/web-platform-tests/html/semantics/embedded-content/the-img-element/sizes/parse-a-sizes-attribute.html [ Pass Failure ]
  • trunk/LayoutTests/platform/win/TestExpectations

    r229147 r229177  
    442442# testRunner.setShouldDownloadUndisplayableMIMETypes() is not supported on WK1.
    443443fast/dom/HTMLAnchorElement/anchor-file-blob-convert-to-download.html [ Skip ]
     444fast/dom/HTMLAnchorElement/anchor-file-blob-convert-to-download-async-delegate.html [ Skip ]
    444445
    445446# TODO Expose title direction in WebKit API (Chromium Only)
  • trunk/Source/WebCore/ChangeLog

    r229176 r229177  
     12018-03-02  Chris Dumez  <cdumez@apple.com>
     2
     3        Converting a load to a download does not work with async policy delegates
     4        https://bugs.webkit.org/show_bug.cgi?id=183254
     5        <rdar://problem/38035334>
     6
     7        Reviewed by Youenn Fablet.
     8
     9        Update DocumentLoader::responseReceived() to call didReceiveResponsePolicy()
     10        on the mainResourceLoader *after* calling continueAfterContentPolicy(),
     11        not *before*. This makes sure that the WebResourceLoader sends the
     12        NetworkResourceLoader::ContinueDidReceiveResponse IPC back to the Network
     13        Process *after* the policy decision has been processed, which restores the
     14        pre-r228852 order.
     15
     16        Test: fast/dom/HTMLAnchorElement/anchor-file-blob-convert-to-download-async-delegate.html
     17
     18        * loader/DocumentLoader.cpp:
     19        (WebCore::DocumentLoader::responseReceived):
     20
    1212018-03-02  Youenn Fablet  <youenn@apple.com>
    222
  • trunk/Source/WebCore/loader/DocumentLoader.cpp

    r229086 r229177  
    784784#endif
    785785
    786     if (auto* mainResourceLoader = this->mainResourceLoader())
     786    RefPtr<SubresourceLoader> mainResourceLoader = this->mainResourceLoader();
     787    if (mainResourceLoader)
    787788        mainResourceLoader->markInAsyncResponsePolicyCheck();
    788     frameLoader()->checkContentPolicy(m_response, [this, protectedThis = makeRef(*this)](PolicyAction policy) {
    789         if (auto* mainResourceLoader = this->mainResourceLoader())
     789    frameLoader()->checkContentPolicy(m_response, [this, protectedThis = makeRef(*this), mainResourceLoader = WTFMove(mainResourceLoader)](PolicyAction policy) {
     790        continueAfterContentPolicy(policy);
     791        if (mainResourceLoader)
    790792            mainResourceLoader->didReceiveResponsePolicy();
    791 
    792         continueAfterContentPolicy(policy);
    793793    });
    794794}
  • trunk/Tools/ChangeLog

    r229150 r229177  
     12018-03-02  Chris Dumez  <cdumez@apple.com>
     2
     3        Converting a load to a download does not work with async policy delegates
     4        https://bugs.webkit.org/show_bug.cgi?id=183254
     5        <rdar://problem/38035334>
     6
     7        Reviewed by Youenn Fablet.
     8
     9        Add layout test infrastructure for responding to the decidePolicyForNavigationResponse
     10        delegate asynchronously.
     11
     12        * WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl:
     13        * WebKitTestRunner/InjectedBundle/InjectedBundlePage.cpp:
     14        (WTR::InjectedBundlePage::decidePolicyForResponse):
     15        * WebKitTestRunner/InjectedBundle/TestRunner.cpp:
     16        (WTR::TestRunner::setShouldDecideResponsePolicyAfterDelay):
     17        * WebKitTestRunner/InjectedBundle/TestRunner.h:
     18        (WTR::TestRunner::shouldDecideResponsePolicyAfterDelay const):
     19        * WebKitTestRunner/TestController.cpp:
     20        (WTR::TestController::resetStateToConsistentValues):
     21        (WTR::TestController::decidePolicyForNavigationResponse):
     22        * WebKitTestRunner/TestController.h:
     23        (WTR::TestController::setShouldDecideResponsePolicyAfterDelay):
     24        * WebKitTestRunner/TestInvocation.cpp:
     25        (WTR::TestInvocation::didReceiveMessageFromInjectedBundle):
     26
    1272018-03-01  Youenn Fablet  <youenn@apple.com>
    228
  • trunk/Tools/WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl

    r229106 r229177  
    9191    void setPrinting();
    9292    void setShouldDecideNavigationPolicyAfterDelay(boolean value);
     93    void setShouldDecideResponsePolicyAfterDelay(boolean value);
    9394    void setNavigationGesturesEnabled(boolean value);
    9495    void setIgnoresViewportScaleLimits(boolean value);
  • trunk/Tools/WebKitTestRunner/InjectedBundle/InjectedBundlePage.cpp

    r228984 r229177  
    13681368WKBundlePagePolicyAction InjectedBundlePage::decidePolicyForResponse(WKBundlePageRef page, WKBundleFrameRef, WKURLResponseRef response, WKURLRequestRef, WKTypeRef*)
    13691369{
    1370     if (InjectedBundle::singleton().testRunner()->isPolicyDelegateEnabled() && WKURLResponseIsAttachment(response)) {
     1370    auto& injectedBundle = InjectedBundle::singleton();
     1371    if (injectedBundle.testRunner()->isPolicyDelegateEnabled() && WKURLResponseIsAttachment(response)) {
    13711372        StringBuilder stringBuilder;
    13721373        WKRetainPtr<WKStringRef> filename = adoptWK(WKURLResponseCopySuggestedFilename(response));
     
    13761377        InjectedBundle::singleton().outputText(stringBuilder.toString());
    13771378    }
     1379
     1380    if (injectedBundle.testRunner()->shouldDecideResponsePolicyAfterDelay())
     1381        return WKBundlePagePolicyActionPassThrough;
    13781382
    13791383    WKRetainPtr<WKStringRef> mimeType = adoptWK(WKURLResponseCopyMIMEType(response));
  • trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.cpp

    r229106 r229177  
    11121112}
    11131113
     1114void TestRunner::setShouldDecideResponsePolicyAfterDelay(bool value)
     1115{
     1116    m_shouldDecideResponsePolicyAfterDelay = value;
     1117    WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("SetShouldDecideResponsePolicyAfterDelay"));
     1118    WKRetainPtr<WKBooleanRef> messageBody(AdoptWK, WKBooleanCreate(value));
     1119    WKBundlePagePostMessage(InjectedBundle::singleton().page()->page(), messageName.get(), messageBody.get());
     1120}
     1121
    11141122void TestRunner::setNavigationGesturesEnabled(bool value)
    11151123{
  • trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.h

    r229106 r229177  
    330330    bool shouldDecideNavigationPolicyAfterDelay() const { return m_shouldDecideNavigationPolicyAfterDelay; }
    331331    void setShouldDecideNavigationPolicyAfterDelay(bool);
     332    bool shouldDecideResponsePolicyAfterDelay() const { return m_shouldDecideResponsePolicyAfterDelay; }
     333    void setShouldDecideResponsePolicyAfterDelay(bool);
    332334    void setNavigationGesturesEnabled(bool);
    333335    void setIgnoresViewportScaleLimits(bool);
     
    476478
    477479    bool m_shouldDecideNavigationPolicyAfterDelay { false };
     480    bool m_shouldDecideResponsePolicyAfterDelay { false };
    478481    bool m_shouldFinishAfterDownload { false };
    479482
  • trunk/Tools/WebKitTestRunner/TestController.cpp

    r229106 r229177  
    855855
    856856    m_shouldDecideNavigationPolicyAfterDelay = false;
     857    m_shouldDecideResponsePolicyAfterDelay = false;
    857858
    858859    setNavigationGesturesEnabled(false);
     
    22292230void TestController::decidePolicyForNavigationResponse(WKNavigationResponseRef navigationResponse, WKFramePolicyListenerRef listener)
    22302231{
    2231     // Even though Response was already checked by WKBundlePagePolicyClient, the check did not include plugins
    2232     // so we have to re-check again.
    2233     if (WKNavigationResponseCanShowMIMEType(navigationResponse)) {
    2234         WKFramePolicyListenerUse(listener);
    2235         return;
    2236     }
    2237 
    2238     if (m_shouldDownloadUndisplayableMIMETypes)
    2239         WKFramePolicyListenerDownload(listener);
     2232    WKRetainPtr<WKNavigationResponseRef> retainedNavigationResponse { navigationResponse };
     2233    WKRetainPtr<WKFramePolicyListenerRef> retainedListener { listener };
     2234
     2235    bool shouldDownloadUndisplayableMIMETypes = m_shouldDownloadUndisplayableMIMETypes;
     2236    auto decisionFunction = [shouldDownloadUndisplayableMIMETypes, retainedNavigationResponse, retainedListener]() {
     2237        // Even though Response was already checked by WKBundlePagePolicyClient, the check did not include plugins
     2238        // so we have to re-check again.
     2239        if (WKNavigationResponseCanShowMIMEType(retainedNavigationResponse.get())) {
     2240            WKFramePolicyListenerUse(retainedListener.get());
     2241            return;
     2242        }
     2243
     2244        if (shouldDownloadUndisplayableMIMETypes)
     2245            WKFramePolicyListenerDownload(retainedListener.get());
     2246        else
     2247            WKFramePolicyListenerIgnore(retainedListener.get());
     2248    };
     2249
     2250    if (m_shouldDecideResponsePolicyAfterDelay)
     2251        RunLoop::main().dispatch(WTFMove(decisionFunction));
    22402252    else
    2241         WKFramePolicyListenerIgnore(listener);
     2253        decisionFunction();
    22422254}
    22432255
  • trunk/Tools/WebKitTestRunner/TestController.h

    r229106 r229177  
    149149
    150150    void setShouldDecideNavigationPolicyAfterDelay(bool value) { m_shouldDecideNavigationPolicyAfterDelay = value; }
     151    void setShouldDecideResponsePolicyAfterDelay(bool value) { m_shouldDecideResponsePolicyAfterDelay = value; }
    151152
    152153    void setNavigationGesturesEnabled(bool value);
     
    416417   
    417418    bool m_shouldDecideNavigationPolicyAfterDelay { false };
     419    bool m_shouldDecideResponsePolicyAfterDelay { false };
    418420
    419421    WKRetainPtr<WKArrayRef> m_openPanelFileURLs;
  • trunk/Tools/WebKitTestRunner/TestInvocation.cpp

    r229106 r229177  
    706706    }
    707707
     708    if (WKStringIsEqualToUTF8CString(messageName, "SetShouldDecideResponsePolicyAfterDelay")) {
     709        ASSERT(WKGetTypeID(messageBody) == WKBooleanGetTypeID());
     710        WKBooleanRef value = static_cast<WKBooleanRef>(messageBody);
     711        TestController::singleton().setShouldDecideResponsePolicyAfterDelay(WKBooleanGetValue(value));
     712        return;
     713    }
     714
    708715    if (WKStringIsEqualToUTF8CString(messageName, "SetNavigationGesturesEnabled")) {
    709716        ASSERT(WKGetTypeID(messageBody) == WKBooleanGetTypeID());
Note: See TracChangeset for help on using the changeset viewer.