Diff
Modified: trunk/Source/WebKit/ChangeLog (241927 => 241928)
--- trunk/Source/WebKit/ChangeLog 2019-02-22 02:02:32 UTC (rev 241927)
+++ trunk/Source/WebKit/ChangeLog 2019-02-22 02:58:40 UTC (rev 241928)
@@ -1,3 +1,35 @@
+2019-02-21 Ryosuke Niwa <[email protected]>
+
+ Discard cached processes when clearing website data store
+ https://bugs.webkit.org/show_bug.cgi?id=194894
+
+ Reviewed by Chris Dumez.
+
+ Clear the process cache when clearing the website data store so that there is no way to infer
+ which site the user had visited by observing for which sites WebContent processes had been cached.
+
+ There is one sublty in WebsiteDataStore::removeData that we have to delay the clearing of
+ the web process cache until the next run loop because SuspendedPageProxy::~SuspendedPageProxy
+ invokes WebProcessProxy::maybeShutDown in the next run loop. We also have to disable the process
+ cache during this time as it would otherwise trigger the responsiveness check of WebContent process
+ can take arbitrarily long time.
+
+ * UIProcess/API/Cocoa/WKProcessPool.mm:
+ (-[WKProcessPool _processCacheCapacity]): Added for testing.
+ * UIProcess/API/Cocoa/WKProcessPoolPrivate.h:
+ * UIProcess/WebProcessCache.cpp:
+ (WebKit::WebProcessCache::addProcess): Avoid adding web processes to the cache while the suspended
+ pages are being cleared.
+ * UIProcess/WebProcessCache.h:
+ (WebKit::WebProcessCache::disabled const): Added.
+ (WebKit::WebProcessCache::setDisabled): Added.
+ * UIProcess/WebProcessPool.cpp:
+ (WebKit::WebProcessPool::handleMemoryPressureWarning):
+ (WebKit::WebProcessPool::clearSuspendedPages): Added.
+ * UIProcess/WebProcessPool.h:
+ * UIProcess/WebsiteData/WebsiteDataStore.cpp:
+ (WebKit::WebsiteDataStore::removeData):
+
2019-02-21 Alex Christensen <[email protected]>
Clicking "Go Back" on a safe browsing warning before a WKWebView has loaded any page should request to close the WKWebView
Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKProcessPool.mm (241927 => 241928)
--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKProcessPool.mm 2019-02-22 02:02:32 UTC (rev 241927)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKProcessPool.mm 2019-02-22 02:58:40 UTC (rev 241928)
@@ -514,6 +514,11 @@
return _processPool->maxSuspendedPageCount();
}
+- (NSUInteger)_processCacheCapacity
+{
+ return _processPool->webProcessCache().capacity();
+}
+
- (size_t)_serviceWorkerProcessCount
{
#if ENABLE(SERVICE_WORKER)
Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKProcessPoolPrivate.h (241927 => 241928)
--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKProcessPoolPrivate.h 2019-02-22 02:02:32 UTC (rev 241927)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKProcessPoolPrivate.h 2019-02-22 02:58:40 UTC (rev 241928)
@@ -103,6 +103,7 @@
- (void)_makeNextWebProcessLaunchFailForTesting WK_API_AVAILABLE(macosx(10.14), ios(12.0));
- (void)_makeNextNetworkProcessLaunchFailForTesting WK_API_AVAILABLE(macosx(10.14), ios(12.0));
- (NSUInteger)_maximumSuspendedPageCount WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
+- (NSUInteger)_processCacheCapacity WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
// Test only. Returns web processes running web pages (does not include web processes running service workers)
- (size_t)_webPageContentProcessCount WK_API_AVAILABLE(macosx(10.13.4), ios(11.3));
Modified: trunk/Source/WebKit/UIProcess/WebProcessCache.cpp (241927 => 241928)
--- trunk/Source/WebKit/UIProcess/WebProcessCache.cpp 2019-02-22 02:02:32 UTC (rev 241927)
+++ trunk/Source/WebKit/UIProcess/WebProcessCache.cpp 2019-02-22 02:58:40 UTC (rev 241928)
@@ -51,7 +51,7 @@
ASSERT(!process->provisionalPageCount());
ASSERT(!process->processPool().hasSuspendedPageFor(process));
- if (!capacity())
+ if (!capacity() || m_isDisabled)
return false;
if (MemoryPressureHandler::singleton().isUnderMemoryPressure()) {
@@ -85,7 +85,7 @@
ASSERT(!process->provisionalPageCount());
ASSERT(!process->processPool().hasSuspendedPageFor(process));
- if (!capacity())
+ if (!capacity() || m_isDisabled)
return false;
if (MemoryPressureHandler::singleton().isUnderMemoryPressure()) {
Modified: trunk/Source/WebKit/UIProcess/WebProcessCache.h (241927 => 241928)
--- trunk/Source/WebKit/UIProcess/WebProcessCache.h 2019-02-22 02:02:32 UTC (rev 241927)
+++ trunk/Source/WebKit/UIProcess/WebProcessCache.h 2019-02-22 02:58:40 UTC (rev 241928)
@@ -49,6 +49,8 @@
unsigned size() const { return m_processesPerRegistrableDomain.size(); }
+ void setIsDisabled(bool isDisabled) { m_isDisabled = isDisabled; }
+
void clear();
void setApplicationIsActive(bool);
@@ -61,6 +63,7 @@
bool addProcess(const String& registrableDomain, Ref<WebProcessProxy>&&);
unsigned m_capacity { 0 };
+ bool m_isDisabled { false };
class CachedProcess {
WTF_MAKE_FAST_ALLOCATED;
Modified: trunk/Source/WebKit/UIProcess/WebProcessPool.cpp (241927 => 241928)
--- trunk/Source/WebKit/UIProcess/WebProcessPool.cpp 2019-02-22 02:02:32 UTC (rev 241927)
+++ trunk/Source/WebKit/UIProcess/WebProcessPool.cpp 2019-02-22 02:58:40 UTC (rev 241928)
@@ -1340,7 +1340,7 @@
m_prewarmedProcess->shutDown();
ASSERT(!m_prewarmedProcess);
- m_suspendedPages.clear();
+ clearSuspendedPages();
}
#if ENABLE(NETSCAPE_PLUGIN_API)
@@ -2352,6 +2352,11 @@
}) != m_suspendedPages.end();
}
+void WebProcessPool::clearSuspendedPages()
+{
+ m_suspendedPages.clear();
+}
+
void WebProcessPool::addMockMediaDevice(const MockMediaDevice& device)
{
#if ENABLE(MEDIA_STREAM)
Modified: trunk/Source/WebKit/UIProcess/WebProcessPool.h (241927 => 241928)
--- trunk/Source/WebKit/UIProcess/WebProcessPool.h 2019-02-22 02:02:32 UTC (rev 241927)
+++ trunk/Source/WebKit/UIProcess/WebProcessPool.h 2019-02-22 02:58:40 UTC (rev 241928)
@@ -468,6 +468,7 @@
bool hasSuspendedPageFor(WebProcessProxy&, WebPageProxy* = nullptr) const;
unsigned maxSuspendedPageCount() const { return m_maxSuspendedPageCount; }
RefPtr<WebProcessProxy> findReusableSuspendedPageProcess(const String&, WebPageProxy&);
+ void clearSuspendedPages();
void didReachGoodTimeToPrewarm();
Modified: trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.cpp (241927 => 241928)
--- trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.cpp 2019-02-22 02:02:32 UTC (rev 241927)
+++ trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.cpp 2019-02-22 02:58:40 UTC (rev 241928)
@@ -36,6 +36,7 @@
#include "ShouldGrandfatherStatistics.h"
#include "StorageAccessStatus.h"
#include "StorageManager.h"
+#include "WebProcessCache.h"
#include "WebProcessMessages.h"
#include "WebProcessPool.h"
#include "WebResourceLoadStatisticsStore.h"
@@ -778,6 +779,16 @@
auto webProcessAccessType = computeWebProcessAccessTypeForDataRemoval(dataTypes, !isPersistent());
if (webProcessAccessType != ProcessAccessType::None) {
+ for (auto& processPool : processPools()) {
+ processPool->webProcessCache().setIsDisabled(true);
+ processPool->clearSuspendedPages();
+ // FIXME: We need to delay the clearing of the process cache because ~SuspendedPageProxy() calls maybeShutDown asynchronously.
+ RunLoop::main().dispatch([pool = makeRef(*processPool)] {
+ pool->webProcessCache().clear();
+ pool->webProcessCache().setIsDisabled(false);
+ });
+ }
+
for (auto& process : processes()) {
switch (webProcessAccessType) {
case ProcessAccessType::OnlyIfLaunched:
Modified: trunk/Tools/ChangeLog (241927 => 241928)
--- trunk/Tools/ChangeLog 2019-02-22 02:02:32 UTC (rev 241927)
+++ trunk/Tools/ChangeLog 2019-02-22 02:58:40 UTC (rev 241928)
@@ -1,3 +1,15 @@
+2019-02-21 Ryosuke Niwa <[email protected]>
+
+ Discard cached processes when clearing website data store
+ https://bugs.webkit.org/show_bug.cgi?id=194894
+
+ Reviewed by Chris Dumez.
+
+ Added a test case.
+
+ * TestWebKitAPI/Tests/WebKitCocoa/ProcessSwapOnNavigation.mm:
+ (TestWebKitAPI.ProcessSwap.NumberOfCachedProcesses): Added.
+
2019-02-21 Alex Christensen <[email protected]>
Clicking "Go Back" on a safe browsing warning before a WKWebView has loaded any page should request to close the WKWebView
Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ProcessSwapOnNavigation.mm (241927 => 241928)
--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ProcessSwapOnNavigation.mm 2019-02-22 02:02:32 UTC (rev 241927)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ProcessSwapOnNavigation.mm 2019-02-22 02:58:40 UTC (rev 241928)
@@ -52,6 +52,7 @@
#import <wtf/HashSet.h>
#import <wtf/RetainPtr.h>
#import <wtf/Vector.h>
+#import <wtf/text/StringConcatenateNumbers.h>
#import <wtf/text/StringHash.h>
#import <wtf/text/WTFString.h>
@@ -3058,6 +3059,62 @@
EXPECT_TRUE([processPool _hasPrewarmedWebProcess]);
}
+TEST(ProcessSwap, NumberOfCachedProcesses)
+{
+ auto processPoolConfiguration = adoptNS([[_WKProcessPoolConfiguration alloc] init]);
+ processPoolConfiguration.get().processSwapsOnNavigation = YES;
+ processPoolConfiguration.get().usesWebProcessCache = YES;
+ processPoolConfiguration.get().prewarmsProcessesAutomatically = NO;
+ auto processPool = adoptNS([[WKProcessPool alloc] _initWithConfiguration:processPoolConfiguration.get()]);
+
+ EXPECT_GT([processPool _maximumSuspendedPageCount], 0u);
+ EXPECT_GT([processPool _processCacheCapacity], 0u);
+
+ auto webViewConfiguration = adoptNS([[WKWebViewConfiguration alloc] init]);
+ [webViewConfiguration setProcessPool:processPool.get()];
+ auto handler = adoptNS([[PSONScheme alloc] init]);
+
+ const unsigned maxSuspendedPageCount = [processPool _maximumSuspendedPageCount];
+ for (unsigned i = 0; i < maxSuspendedPageCount + 2; i++)
+ [handler addMappingFromURLString:makeString("pson://www.domain-", i, ".com") toData:pageCache1Bytes];
+ [webViewConfiguration setURLSchemeHandler:handler.get() forURLScheme:@"PSON"];
+
+ auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:webViewConfiguration.get()]);
+ auto delegate = adoptNS([[PSONNavigationDelegate alloc] init]);
+ [webView setNavigationDelegate:delegate.get()];
+
+ for (unsigned i = 0; i < maxSuspendedPageCount + 1; i++) {
+ NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:makeString("pson://www.domain-", i, ".com")]];
+ [webView loadRequest:request];
+ TestWebKitAPI::Util::run(&done);
+ done = false;
+
+ EXPECT_EQ(i + 1, [processPool _webProcessCount]);
+ EXPECT_EQ(i + 1, [processPool _webProcessCountIgnoringPrewarmedAndCached]);
+ EXPECT_FALSE([processPool _hasPrewarmedWebProcess]);
+ }
+
+ NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:makeString("pson://www.domain-", maxSuspendedPageCount + 1, ".com")]];
+ [webView loadRequest:request];
+ TestWebKitAPI::Util::run(&done);
+ done = false;
+
+ EXPECT_EQ(maxSuspendedPageCount + 2, [processPool _webProcessCount]);
+ EXPECT_EQ(maxSuspendedPageCount + 1, [processPool _webProcessCountIgnoringPrewarmedAndCached]);
+ EXPECT_FALSE([processPool _hasPrewarmedWebProcess]);
+
+ static bool readyToContinue = false;
+ [[WKWebsiteDataStore defaultDataStore] removeDataOfTypes:[WKWebsiteDataStore _allWebsiteDataTypesIncludingPrivate] modifiedSince:[NSDate distantPast] completionHandler:^() {
+ readyToContinue = true;
+ }];
+ TestWebKitAPI::Util::run(&readyToContinue);
+
+ EXPECT_EQ(1u, [processPool _webProcessCount]);
+ EXPECT_EQ(1u, [processPool _webProcessCountIgnoringPrewarmedAndCached]);
+ EXPECT_FALSE([processPool _hasPrewarmedWebProcess]);
+
+}
+
static const char* visibilityBytes = R"PSONRESOURCE(
<script>
window.addEventListener('pageshow', function(event) {