Changeset 238179 in webkit


Ignore:
Timestamp:
Nov 14, 2018 8:58:17 AM (5 years ago)
Author:
Chris Dumez
Message:

WebKit.ApplicationManifestBasic API test is failing when enabling PSON
https://bugs.webkit.org/show_bug.cgi?id=191602

Reviewed by Alex Christensen.

Source/WebKit:

Add support for process swapping for a [WKWebView loadHTML:] load by storing
the necessary data on the API::Navigation and doing a loadData() instead of
a loadRequest() after process swapping when this data is present on the
navigation.

  • UIProcess/API/APINavigation.cpp:

(API::Navigation::Navigation):

  • UIProcess/API/APINavigation.h:

(API::Navigation::create):
(API::Navigation::substituteData const):

  • UIProcess/WebNavigationState.cpp:

(WebKit::WebNavigationState::createLoadDataNavigation):

  • UIProcess/WebNavigationState.h:
  • UIProcess/WebPageProxy.cpp:

(WebKit::WebPageProxy::loadData):
(WebKit::WebPageProxy::continueNavigationInNewProcess):

Tools:

Add API test coverage.

  • TestWebKitAPI/Tests/WebKitCocoa/ProcessSwapOnNavigation.mm:
Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r238178 r238179  
     12018-11-14  Chris Dumez  <cdumez@apple.com>
     2
     3        WebKit.ApplicationManifestBasic API test is failing when enabling PSON
     4        https://bugs.webkit.org/show_bug.cgi?id=191602
     5
     6        Reviewed by Alex Christensen.
     7
     8        Add support for process swapping for a [WKWebView loadHTML:] load by storing
     9        the necessary data on the API::Navigation and doing a loadData() instead of
     10        a loadRequest() after process swapping when this data is present on the
     11        navigation.
     12
     13        * UIProcess/API/APINavigation.cpp:
     14        (API::Navigation::Navigation):
     15        * UIProcess/API/APINavigation.h:
     16        (API::Navigation::create):
     17        (API::Navigation::substituteData const):
     18        * UIProcess/WebNavigationState.cpp:
     19        (WebKit::WebNavigationState::createLoadDataNavigation):
     20        * UIProcess/WebNavigationState.h:
     21        * UIProcess/WebPageProxy.cpp:
     22        (WebKit::WebPageProxy::loadData):
     23        (WebKit::WebPageProxy::continueNavigationInNewProcess):
     24
    1252018-11-14  Antti Koivisto  <antti@apple.com>
    226
  • trunk/Source/WebKit/UIProcess/API/APINavigation.cpp

    r235823 r238179  
    6060}
    6161
     62Navigation::Navigation(WebKit::WebNavigationState& state, std::unique_ptr<SubstituteData>&& substituteData)
     63    : Navigation(state)
     64{
     65    ASSERT(substituteData);
     66    m_substituteData = WTFMove(substituteData);
     67}
     68
    6269Navigation::~Navigation()
    6370{
  • trunk/Source/WebKit/UIProcess/API/APINavigation.h

    r237355 r238179  
    2727
    2828#include "APIObject.h"
     29#include "DataReference.h"
    2930#include "WebBackForwardListItem.h"
    3031#include <WebCore/Process.h>
     
    4243
    4344namespace API {
     45
     46struct SubstituteData {
     47    WTF_MAKE_FAST_ALLOCATED;
     48public:
     49    SubstituteData(Vector<uint8_t>&& content, const WTF::String& MIMEType, const WTF::String& encoding, const WTF::String& baseURL, API::Object* userData)
     50        : content(WTFMove(content))
     51        , MIMEType(MIMEType)
     52        , encoding(encoding)
     53        , baseURL(baseURL)
     54        , userData(userData)
     55    { }
     56
     57    Vector<uint8_t> content;
     58    WTF::String MIMEType;
     59    WTF::String encoding;
     60    WTF::String baseURL;
     61    RefPtr<API::Object> userData;
     62};
    4463
    4564class Navigation : public ObjectImpl<Object::Type::Navigation> {
     
    5978    {
    6079        return adoptRef(*new Navigation(state, WTFMove(request), fromItem));
     80    }
     81
     82    static Ref<Navigation> create(WebKit::WebNavigationState& state, std::unique_ptr<SubstituteData>&& substituteData)
     83    {
     84        return adoptRef(*new Navigation(state, WTFMove(substituteData)));
    6185    }
    6286
     
    115139#endif
    116140
     141    const std::unique_ptr<SubstituteData>& substituteData() const { return m_substituteData; }
     142
    117143private:
    118144    explicit Navigation(WebKit::WebNavigationState&);
    119145    Navigation(WebKit::WebNavigationState&, WebCore::ResourceRequest&&, WebKit::WebBackForwardListItem* fromItem);
    120146    Navigation(WebKit::WebNavigationState&, WebKit::WebBackForwardListItem& targetItem, WebKit::WebBackForwardListItem* fromItem, WebCore::FrameLoadType);
     147    Navigation(WebKit::WebNavigationState&, std::unique_ptr<SubstituteData>&&);
    121148
    122149    uint64_t m_navigationID;
     
    140167    WebCore::LockBackForwardList m_lockBackForwardList;
    141168    WTF::String m_clientRedirectSourceForHistory;
     169    std::unique_ptr<SubstituteData> m_substituteData;
    142170};
    143171
  • trunk/Source/WebKit/UIProcess/WebNavigationState.cpp

    r236227 r238179  
    6969}
    7070
    71 Ref<API::Navigation> WebNavigationState::createLoadDataNavigation()
     71Ref<API::Navigation> WebNavigationState::createLoadDataNavigation(std::unique_ptr<API::SubstituteData>&& substituteData)
    7272{
    73     auto navigation = API::Navigation::create(*this);
     73    auto navigation = API::Navigation::create(*this, WTFMove(substituteData));
    7474
    7575    m_navigations.set(navigation->navigationID(), navigation.ptr());
  • trunk/Source/WebKit/UIProcess/WebNavigationState.h

    r237074 r238179  
    3131namespace API {
    3232class Navigation;
     33struct SubstituteData;
    3334}
    3435
     
    5253    Ref<API::Navigation> createLoadRequestNavigation(WebCore::ResourceRequest&&, WebBackForwardListItem* currentItem);
    5354    Ref<API::Navigation> createReloadNavigation();
    54     Ref<API::Navigation> createLoadDataNavigation();
     55    Ref<API::Navigation> createLoadDataNavigation(std::unique_ptr<API::SubstituteData>&&);
    5556
    5657    API::Navigation* navigation(uint64_t navigationID);
  • trunk/Source/WebKit/UIProcess/WebPageProxy.cpp

    r238078 r238179  
    10881088        return nullptr;
    10891089
    1090     auto navigation = m_navigationState->createLoadDataNavigation();
     1090    auto navigation = m_navigationState->createLoadDataNavigation(std::make_unique<API::SubstituteData>(data.vector(), MIMEType, encoding, baseURL, userData));
     1091    loadDataWithNavigation(navigation, data, MIMEType, encoding, baseURL, userData);
     1092    return WTFMove(navigation);
     1093}
     1094
     1095void WebPageProxy::loadDataWithNavigation(API::Navigation& navigation, const IPC::DataReference& data, const String& MIMEType, const String& encoding, const String& baseURL, API::Object* userData)
     1096{
     1097    ASSERT(!m_isClosed);
    10911098
    10921099    auto transaction = m_pageLoadState.transaction();
     
    10981105
    10991106    LoadParameters loadParameters;
    1100     loadParameters.navigationID = navigation->navigationID();
     1107    loadParameters.navigationID = navigation.navigationID();
    11011108    loadParameters.data = data;
    11021109    loadParameters.MIMEType = MIMEType;
     
    11091116    m_process->send(Messages::WebPage::LoadData(loadParameters), m_pageID);
    11101117    m_process->responsivenessTimer().start();
    1111 
    1112     return WTFMove(navigation);
    11131118}
    11141119
     
    26172622    // FIXME: Work out timing of responding with the last policy delegate, etc
    26182623    ASSERT(!navigation.currentRequest().isEmpty());
    2619     loadRequestWithNavigation(navigation, ResourceRequest { navigation.currentRequest() }, WebCore::ShouldOpenExternalURLsPolicy::ShouldAllowExternalSchemes, nullptr, ShouldTreatAsContinuingLoad::Yes);
     2624    if (auto& substituteData = navigation.substituteData())
     2625        loadDataWithNavigation(navigation, { substituteData->content.data(), substituteData->content.size() }, substituteData->MIMEType, substituteData->encoding, substituteData->baseURL, substituteData->userData.get());
     2626    else
     2627        loadRequestWithNavigation(navigation, ResourceRequest { navigation.currentRequest() }, WebCore::ShouldOpenExternalURLsPolicy::ShouldAllowExternalSchemes, nullptr, ShouldTreatAsContinuingLoad::Yes);
    26202628
    26212629    ASSERT(!m_mainFrame);
  • trunk/Source/WebKit/UIProcess/WebPageProxy.h

    r238078 r238179  
    15401540    RefPtr<API::Navigation> reattachToWebProcessWithItem(WebBackForwardListItem&);
    15411541
     1542    void loadDataWithNavigation(API::Navigation&, const IPC::DataReference&, const String& MIMEType, const String& encoding, const String& baseURL, API::Object* userData = nullptr);
    15421543    void loadRequestWithNavigation(API::Navigation&, WebCore::ResourceRequest&&, WebCore::ShouldOpenExternalURLsPolicy, API::Object* userData, WebCore::ShouldTreatAsContinuingLoad);
    15431544
  • trunk/Tools/ChangeLog

    r238177 r238179  
     12018-11-14  Chris Dumez  <cdumez@apple.com>
     2
     3        WebKit.ApplicationManifestBasic API test is failing when enabling PSON
     4        https://bugs.webkit.org/show_bug.cgi?id=191602
     5
     6        Reviewed by Alex Christensen.
     7
     8        Add API test coverage.
     9
     10        * TestWebKitAPI/Tests/WebKitCocoa/ProcessSwapOnNavigation.mm:
     11
    1122018-11-14  Jonathan Bedard  <jbedard@apple.com>
    213
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ProcessSwapOnNavigation.mm

    r238061 r238179  
    26482648}
    26492649
     2650TEST(ProcessSwap, SwapOnLoadHTMLString)
     2651{
     2652    auto processPoolConfiguration = adoptNS([[_WKProcessPoolConfiguration alloc] init]);
     2653    processPoolConfiguration.get().processSwapsOnNavigation = YES;
     2654    auto processPool = adoptNS([[WKProcessPool alloc] _initWithConfiguration:processPoolConfiguration.get()]);
     2655
     2656    auto webViewConfiguration = adoptNS([[WKWebViewConfiguration alloc] init]);
     2657    [webViewConfiguration setProcessPool:processPool.get()];
     2658    auto handler = adoptNS([[PSONScheme alloc] init]);
     2659    [webViewConfiguration setURLSchemeHandler:handler.get() forURLScheme:@"pson"];
     2660
     2661    auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:webViewConfiguration.get()]);
     2662    auto delegate = adoptNS([[PSONNavigationDelegate alloc] init]);
     2663    [webView setNavigationDelegate:delegate.get()];
     2664
     2665    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"pson://www.webkit.org/main.html"]];
     2666    [webView loadRequest:request];
     2667
     2668    TestWebKitAPI::Util::run(&done);
     2669    done = false;
     2670
     2671    auto pid1 = [webView _webProcessIdentifier];
     2672
     2673    NSString *htmlString = @"<html><body>substituteData</body></html>";
     2674    [webView loadHTMLString:htmlString baseURL:[NSURL URLWithString:@"http://example.com"]];
     2675
     2676    TestWebKitAPI::Util::run(&done);
     2677    done = false;
     2678
     2679    auto pid2 = [webView _webProcessIdentifier];
     2680    EXPECT_NE(pid1, pid2);
     2681
     2682    [webView evaluateJavaScript:@"document.body.innerText" completionHandler:^(id innerText, NSError *error) {
     2683        EXPECT_WK_STREQ(@"substituteData", (NSString *)innerText);
     2684        done = true;
     2685    }];
     2686    TestWebKitAPI::Util::run(&done);
     2687    done = false;
     2688}
     2689
    26502690#if PLATFORM(MAC)
    26512691
Note: See TracChangeset for help on using the changeset viewer.