Changeset 244502 in webkit


Ignore:
Timestamp:
Apr 22, 2019 11:03:47 AM (5 years ago)
Author:
Chris Dumez
Message:

Delayed WebProcessLaunch may break the _relatedWebView SPI
https://bugs.webkit.org/show_bug.cgi?id=197160

Reviewed by Alex Christensen.

Source/WebKit:

Delayed WebProcessLaunch may break the _relatedWebView SPI. The breakage would happen if the client
would relate a WebView to another which has not launched its initial process yet.

To address the issue, when we need a running process for a WebView which has a related view, we need
to make sure the related view has a running process and use that process. Previously, we would share
the "dummy" process instead.

  • UIProcess/WebPageProxy.cpp:

(WebKit::WebPageProxy::launchProcess):
(WebKit::WebPageProxy::ensureRunningProcess):

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

(WebKit::WebProcessPool::createWebPage):

Tools:

Add API test coverage.

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

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r244500 r244502  
     12019-04-22  Chris Dumez  <cdumez@apple.com>
     2
     3        Delayed WebProcessLaunch may break the _relatedWebView SPI
     4        https://bugs.webkit.org/show_bug.cgi?id=197160
     5
     6        Reviewed by Alex Christensen.
     7
     8        Delayed WebProcessLaunch may break the _relatedWebView SPI. The breakage would happen if the client
     9        would relate a WebView to another which has not launched its initial process yet.
     10
     11        To address the issue, when we need a running process for a WebView which has a related view, we need
     12        to make sure the related view has a running process and use that process. Previously, we would share
     13        the "dummy" process instead.
     14
     15        * UIProcess/WebPageProxy.cpp:
     16        (WebKit::WebPageProxy::launchProcess):
     17        (WebKit::WebPageProxy::ensureRunningProcess):
     18        * UIProcess/WebPageProxy.h:
     19        * UIProcess/WebProcessPool.cpp:
     20        (WebKit::WebProcessPool::createWebPage):
     21
    1222019-04-22  Ludovico de Nittis  <ludovico.denittis@collabora.com>
    223
  • trunk/Source/WebKit/UIProcess/WebPageProxy.cpp

    r244493 r244502  
    728728
    729729    auto& processPool = m_process->processPool();
    730     m_process = processPool.processForRegistrableDomain(m_websiteDataStore.get(), this, registrableDomain);
     730
     731    if (auto* relatedPage = m_configuration->relatedPage())
     732        m_process = relatedPage->ensureRunningProcess();
     733    else
     734        m_process = processPool.processForRegistrableDomain(m_websiteDataStore.get(), this, registrableDomain);
    731735    m_hasRunningProcess = true;
    732736
     
    10721076}
    10731077#endif
     1078
     1079WebProcessProxy& WebPageProxy::ensureRunningProcess()
     1080{
     1081    if (!hasRunningProcess())
     1082        launchProcess({ });
     1083
     1084    return m_process;
     1085}
    10741086
    10751087RefPtr<API::Navigation> WebPageProxy::loadRequest(ResourceRequest&& request, ShouldOpenExternalURLsPolicy shouldOpenExternalURLsPolicy, API::Object* userData)
  • trunk/Source/WebKit/UIProcess/WebPageProxy.h

    r244446 r244502  
    10841084#endif
    10851085
     1086    WebProcessProxy& ensureRunningProcess();
    10861087    WebProcessProxy& process() { return m_process; }
    10871088    ProcessID processIdentifier() const;
  • trunk/Source/WebKit/UIProcess/WebProcessPool.cpp

    r244288 r244502  
    12111211
    12121212    RefPtr<WebProcessProxy> process;
    1213     if (pageConfiguration->relatedPage()) {
    1214         // Sharing processes, e.g. when creating the page via window.open().
    1215         process = &pageConfiguration->relatedPage()->process();
    1216         // We do not support several WebsiteDataStores sharing a single process.
    1217         ASSERT(process.get() == m_dummyProcessProxy || &pageConfiguration->websiteDataStore()->websiteDataStore() == &process->websiteDataStore());
    1218         ASSERT(&pageConfiguration->relatedPage()->websiteDataStore() == &pageConfiguration->websiteDataStore()->websiteDataStore());
    1219     } else if (!m_isDelayedWebProcessLaunchDisabled) {
     1213
     1214    if (m_isDelayedWebProcessLaunchDisabled) {
     1215        if (pageConfiguration->relatedPage()) {
     1216            // Sharing processes, e.g. when creating the page via window.open().
     1217            // Make sure the related page's process is not the dummy one.
     1218            process = &pageConfiguration->relatedPage()->ensureRunningProcess();
     1219            // We do not support several WebsiteDataStores sharing a single process.
     1220            ASSERT(process.get() == m_dummyProcessProxy || &pageConfiguration->websiteDataStore()->websiteDataStore() == &process->websiteDataStore());
     1221            ASSERT(&pageConfiguration->relatedPage()->websiteDataStore() == &pageConfiguration->websiteDataStore()->websiteDataStore());
     1222        } else
     1223            process = &processForRegistrableDomain(pageConfiguration->websiteDataStore()->websiteDataStore(), nullptr, { });
     1224    } else {
    12201225        // In the common case, we delay process launch until something is actually loaded in the page.
    12211226        if (!m_dummyProcessProxy) {
     
    12251230        }
    12261231        process = m_dummyProcessProxy;
    1227     } else
    1228         process = &processForRegistrableDomain(pageConfiguration->websiteDataStore()->websiteDataStore(), nullptr, { });
     1232    }
    12291233
    12301234    ASSERT(process);
  • trunk/Tools/ChangeLog

    r244498 r244502  
     12019-04-22  Chris Dumez  <cdumez@apple.com>
     2
     3        Delayed WebProcessLaunch may break the _relatedWebView SPI
     4        https://bugs.webkit.org/show_bug.cgi?id=197160
     5
     6        Reviewed by Alex Christensen.
     7
     8        Add API test coverage.
     9
     10        * TestWebKitAPI/Tests/WebKitCocoa/ProcessSwapOnNavigation.mm:
     11
    1122019-04-22  Carlos Garcia Campos  <cgarcia@igalia.com>
    213
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ProcessSwapOnNavigation.mm

    r244075 r244502  
    45994599}
    46004600
     4601TEST(ProcessSwap, RelatedWebViewBeforeWebProcessLaunch)
     4602{
     4603    auto processPoolConfiguration = psonProcessPoolConfiguration();
     4604    auto processPool = adoptNS([[WKProcessPool alloc] _initWithConfiguration:processPoolConfiguration.get()]);
     4605
     4606    auto webView1Configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
     4607    [webView1Configuration setProcessPool:processPool.get()];
     4608    auto handler = adoptNS([[PSONScheme alloc] init]);
     4609    [webView1Configuration setURLSchemeHandler:handler.get() forURLScheme:@"PSON"];
     4610
     4611    auto webView1 = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:webView1Configuration.get()]);
     4612    auto delegate = adoptNS([[PSONNavigationDelegate alloc] init]);
     4613    [webView1 setNavigationDelegate:delegate.get()];
     4614
     4615    auto webView2Configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
     4616    [webView2Configuration setProcessPool:processPool.get()];
     4617    [webView2Configuration setURLSchemeHandler:handler.get() forURLScheme:@"PSON"];
     4618    webView2Configuration.get()._relatedWebView = webView1.get(); // webView2 will be related to webView1 and webView1's URL will be used for process swap decision.
     4619    auto webView2 = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:webView2Configuration.get()]);
     4620    [webView2 setNavigationDelegate:delegate.get()];
     4621
     4622    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"pson://www.webkit.org/main1.html"]];
     4623    [webView1 loadRequest:request];
     4624
     4625    TestWebKitAPI::Util::run(&done);
     4626    done = false;
     4627
     4628    auto pid1 = [webView1 _webProcessIdentifier];
     4629
     4630    request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"pson://www.webkit.org/main2.html"]];
     4631    [webView2 loadRequest:request];
     4632
     4633    TestWebKitAPI::Util::run(&done);
     4634    done = false;
     4635
     4636    auto pid2 = [webView2 _webProcessIdentifier];
     4637
     4638    EXPECT_EQ(pid1, pid2); // WebViews are related so they should share the same process.
     4639}
     4640
    46014641TEST(ProcessSwap, TerminatedSuspendedPageProcess)
    46024642{
Note: See TracChangeset for help on using the changeset viewer.