- Revision
- 244502
- Author
- cdu...@apple.com
- Date
- 2019-04-22 11:03:47 -0700 (Mon, 22 Apr 2019)
Log 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:
Modified Paths
Diff
Modified: trunk/Source/WebKit/ChangeLog (244501 => 244502)
--- trunk/Source/WebKit/ChangeLog 2019-04-22 16:38:11 UTC (rev 244501)
+++ trunk/Source/WebKit/ChangeLog 2019-04-22 18:03:47 UTC (rev 244502)
@@ -1,3 +1,24 @@
+2019-04-22 Chris Dumez <cdu...@apple.com>
+
+ Delayed WebProcessLaunch may break the _relatedWebView SPI
+ https://bugs.webkit.org/show_bug.cgi?id=197160
+
+ Reviewed by Alex Christensen.
+
+ 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):
+
2019-04-22 Ludovico de Nittis <ludovico.denit...@collabora.com>
[GTK] fix gtk_style_context_set_background deprecation
Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.cpp (244501 => 244502)
--- trunk/Source/WebKit/UIProcess/WebPageProxy.cpp 2019-04-22 16:38:11 UTC (rev 244501)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.cpp 2019-04-22 18:03:47 UTC (rev 244502)
@@ -727,7 +727,11 @@
m_process->removeMessageReceiver(Messages::WebPageProxy::messageReceiverName(), m_pageID);
auto& processPool = m_process->processPool();
- m_process = processPool.processForRegistrableDomain(m_websiteDataStore.get(), this, registrableDomain);
+
+ if (auto* relatedPage = m_configuration->relatedPage())
+ m_process = relatedPage->ensureRunningProcess();
+ else
+ m_process = processPool.processForRegistrableDomain(m_websiteDataStore.get(), this, registrableDomain);
m_hasRunningProcess = true;
m_process->addExistingWebPage(*this, WebProcessProxy::BeginsUsingDataStore::Yes);
@@ -1072,6 +1076,14 @@
}
#endif
+WebProcessProxy& WebPageProxy::ensureRunningProcess()
+{
+ if (!hasRunningProcess())
+ launchProcess({ });
+
+ return m_process;
+}
+
RefPtr<API::Navigation> WebPageProxy::loadRequest(ResourceRequest&& request, ShouldOpenExternalURLsPolicy shouldOpenExternalURLsPolicy, API::Object* userData)
{
if (m_isClosed)
Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.h (244501 => 244502)
--- trunk/Source/WebKit/UIProcess/WebPageProxy.h 2019-04-22 16:38:11 UTC (rev 244501)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.h 2019-04-22 18:03:47 UTC (rev 244502)
@@ -1083,6 +1083,7 @@
bool isValidKeypressCommandName(const String& name) const { return m_knownKeypressCommandNames.contains(name); }
#endif
+ WebProcessProxy& ensureRunningProcess();
WebProcessProxy& process() { return m_process; }
ProcessID processIdentifier() const;
Modified: trunk/Source/WebKit/UIProcess/WebProcessPool.cpp (244501 => 244502)
--- trunk/Source/WebKit/UIProcess/WebProcessPool.cpp 2019-04-22 16:38:11 UTC (rev 244501)
+++ trunk/Source/WebKit/UIProcess/WebProcessPool.cpp 2019-04-22 18:03:47 UTC (rev 244502)
@@ -1210,13 +1210,18 @@
}
RefPtr<WebProcessProxy> process;
- if (pageConfiguration->relatedPage()) {
- // Sharing processes, e.g. when creating the page via window.open().
- process = &pageConfiguration->relatedPage()->process();
- // We do not support several WebsiteDataStores sharing a single process.
- ASSERT(process.get() == m_dummyProcessProxy || &pageConfiguration->websiteDataStore()->websiteDataStore() == &process->websiteDataStore());
- ASSERT(&pageConfiguration->relatedPage()->websiteDataStore() == &pageConfiguration->websiteDataStore()->websiteDataStore());
- } else if (!m_isDelayedWebProcessLaunchDisabled) {
+
+ if (m_isDelayedWebProcessLaunchDisabled) {
+ if (pageConfiguration->relatedPage()) {
+ // Sharing processes, e.g. when creating the page via window.open().
+ // Make sure the related page's process is not the dummy one.
+ process = &pageConfiguration->relatedPage()->ensureRunningProcess();
+ // We do not support several WebsiteDataStores sharing a single process.
+ ASSERT(process.get() == m_dummyProcessProxy || &pageConfiguration->websiteDataStore()->websiteDataStore() == &process->websiteDataStore());
+ ASSERT(&pageConfiguration->relatedPage()->websiteDataStore() == &pageConfiguration->websiteDataStore()->websiteDataStore());
+ } else
+ process = &processForRegistrableDomain(pageConfiguration->websiteDataStore()->websiteDataStore(), nullptr, { });
+ } else {
// In the common case, we delay process launch until something is actually loaded in the page.
if (!m_dummyProcessProxy) {
auto dummyProcessProxy = WebProcessProxy::create(*this, nullptr, WebProcessProxy::IsPrewarmed::No, WebProcessProxy::ShouldLaunchProcess::No);
@@ -1224,8 +1229,7 @@
m_processes.append(WTFMove(dummyProcessProxy));
}
process = m_dummyProcessProxy;
- } else
- process = &processForRegistrableDomain(pageConfiguration->websiteDataStore()->websiteDataStore(), nullptr, { });
+ }
ASSERT(process);
Modified: trunk/Tools/ChangeLog (244501 => 244502)
--- trunk/Tools/ChangeLog 2019-04-22 16:38:11 UTC (rev 244501)
+++ trunk/Tools/ChangeLog 2019-04-22 18:03:47 UTC (rev 244502)
@@ -1,3 +1,14 @@
+2019-04-22 Chris Dumez <cdu...@apple.com>
+
+ Delayed WebProcessLaunch may break the _relatedWebView SPI
+ https://bugs.webkit.org/show_bug.cgi?id=197160
+
+ Reviewed by Alex Christensen.
+
+ Add API test coverage.
+
+ * TestWebKitAPI/Tests/WebKitCocoa/ProcessSwapOnNavigation.mm:
+
2019-04-22 Carlos Garcia Campos <cgar...@igalia.com>
REGRESSION(r241289): [GTK] accessibility/removed-continuation-element-causes-crash.html and accessibility/removed-anonymous-block-child-causes-crash.html crashes
Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ProcessSwapOnNavigation.mm (244501 => 244502)
--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ProcessSwapOnNavigation.mm 2019-04-22 16:38:11 UTC (rev 244501)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ProcessSwapOnNavigation.mm 2019-04-22 18:03:47 UTC (rev 244502)
@@ -4598,6 +4598,46 @@
runProcessSwapDueToRelatedWebViewTest([NSURL URLWithString:@"pson://www.webkit.org/main1.html"], [NSURL URLWithString:@"pson://www.webkit.org/main2.html"], ExpectSwap::No);
}
+TEST(ProcessSwap, RelatedWebViewBeforeWebProcessLaunch)
+{
+ auto processPoolConfiguration = psonProcessPoolConfiguration();
+ auto processPool = adoptNS([[WKProcessPool alloc] _initWithConfiguration:processPoolConfiguration.get()]);
+
+ auto webView1Configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+ [webView1Configuration setProcessPool:processPool.get()];
+ auto handler = adoptNS([[PSONScheme alloc] init]);
+ [webView1Configuration setURLSchemeHandler:handler.get() forURLScheme:@"PSON"];
+
+ auto webView1 = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:webView1Configuration.get()]);
+ auto delegate = adoptNS([[PSONNavigationDelegate alloc] init]);
+ [webView1 setNavigationDelegate:delegate.get()];
+
+ auto webView2Configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+ [webView2Configuration setProcessPool:processPool.get()];
+ [webView2Configuration setURLSchemeHandler:handler.get() forURLScheme:@"PSON"];
+ webView2Configuration.get()._relatedWebView = webView1.get(); // webView2 will be related to webView1 and webView1's URL will be used for process swap decision.
+ auto webView2 = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:webView2Configuration.get()]);
+ [webView2 setNavigationDelegate:delegate.get()];
+
+ NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"pson://www.webkit.org/main1.html"]];
+ [webView1 loadRequest:request];
+
+ TestWebKitAPI::Util::run(&done);
+ done = false;
+
+ auto pid1 = [webView1 _webProcessIdentifier];
+
+ request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"pson://www.webkit.org/main2.html"]];
+ [webView2 loadRequest:request];
+
+ TestWebKitAPI::Util::run(&done);
+ done = false;
+
+ auto pid2 = [webView2 _webProcessIdentifier];
+
+ EXPECT_EQ(pid1, pid2); // WebViews are related so they should share the same process.
+}
+
TEST(ProcessSwap, TerminatedSuspendedPageProcess)
{
auto processPoolConfiguration = psonProcessPoolConfiguration();