Skip to content
This repository was archived by the owner on Jun 24, 2022. It is now read-only.

Commit a9ad782

Browse files
Discard cached processes when clearing website data store
https://bugs.webkit.org/show_bug.cgi?id=194894 Reviewed by Chris Dumez. Source/WebKit: 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): Tools: Added a test case. * TestWebKitAPI/Tests/WebKitCocoa/ProcessSwapOnNavigation.mm: (TestWebKitAPI.ProcessSwap.NumberOfCachedProcesses): Added. git-svn-id: http://svn.webkit.org/repository/webkit/trunk@241928 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent 8eafba5 commit a9ad782

File tree

10 files changed

+130
-3
lines changed

10 files changed

+130
-3
lines changed

Source/WebKit/ChangeLog

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,35 @@
1+
2019-02-21 Ryosuke Niwa <[email protected]>
2+
3+
Discard cached processes when clearing website data store
4+
https://bugs.webkit.org/show_bug.cgi?id=194894
5+
6+
Reviewed by Chris Dumez.
7+
8+
Clear the process cache when clearing the website data store so that there is no way to infer
9+
which site the user had visited by observing for which sites WebContent processes had been cached.
10+
11+
There is one sublty in WebsiteDataStore::removeData that we have to delay the clearing of
12+
the web process cache until the next run loop because SuspendedPageProxy::~SuspendedPageProxy
13+
invokes WebProcessProxy::maybeShutDown in the next run loop. We also have to disable the process
14+
cache during this time as it would otherwise trigger the responsiveness check of WebContent process
15+
can take arbitrarily long time.
16+
17+
* UIProcess/API/Cocoa/WKProcessPool.mm:
18+
(-[WKProcessPool _processCacheCapacity]): Added for testing.
19+
* UIProcess/API/Cocoa/WKProcessPoolPrivate.h:
20+
* UIProcess/WebProcessCache.cpp:
21+
(WebKit::WebProcessCache::addProcess): Avoid adding web processes to the cache while the suspended
22+
pages are being cleared.
23+
* UIProcess/WebProcessCache.h:
24+
(WebKit::WebProcessCache::disabled const): Added.
25+
(WebKit::WebProcessCache::setDisabled): Added.
26+
* UIProcess/WebProcessPool.cpp:
27+
(WebKit::WebProcessPool::handleMemoryPressureWarning):
28+
(WebKit::WebProcessPool::clearSuspendedPages): Added.
29+
* UIProcess/WebProcessPool.h:
30+
* UIProcess/WebsiteData/WebsiteDataStore.cpp:
31+
(WebKit::WebsiteDataStore::removeData):
32+
133
2019-02-21 Alex Christensen <[email protected]>
234

335
Clicking "Go Back" on a safe browsing warning before a WKWebView has loaded any page should request to close the WKWebView

Source/WebKit/UIProcess/API/Cocoa/WKProcessPool.mm

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,11 @@ - (NSUInteger)_maximumSuspendedPageCount
514514
return _processPool->maxSuspendedPageCount();
515515
}
516516

517+
- (NSUInteger)_processCacheCapacity
518+
{
519+
return _processPool->webProcessCache().capacity();
520+
}
521+
517522
- (size_t)_serviceWorkerProcessCount
518523
{
519524
#if ENABLE(SERVICE_WORKER)

Source/WebKit/UIProcess/API/Cocoa/WKProcessPoolPrivate.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@
103103
- (void)_makeNextWebProcessLaunchFailForTesting WK_API_AVAILABLE(macosx(10.14), ios(12.0));
104104
- (void)_makeNextNetworkProcessLaunchFailForTesting WK_API_AVAILABLE(macosx(10.14), ios(12.0));
105105
- (NSUInteger)_maximumSuspendedPageCount WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
106+
- (NSUInteger)_processCacheCapacity WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
106107

107108
// Test only. Returns web processes running web pages (does not include web processes running service workers)
108109
- (size_t)_webPageContentProcessCount WK_API_AVAILABLE(macosx(10.13.4), ios(11.3));

Source/WebKit/UIProcess/WebProcessCache.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ bool WebProcessCache::addProcessIfPossible(const String& registrableDomain, Ref<
5151
ASSERT(!process->provisionalPageCount());
5252
ASSERT(!process->processPool().hasSuspendedPageFor(process));
5353

54-
if (!capacity())
54+
if (!capacity() || m_isDisabled)
5555
return false;
5656

5757
if (MemoryPressureHandler::singleton().isUnderMemoryPressure()) {
@@ -85,7 +85,7 @@ bool WebProcessCache::addProcess(const String& registrableDomain, Ref<WebProcess
8585
ASSERT(!process->provisionalPageCount());
8686
ASSERT(!process->processPool().hasSuspendedPageFor(process));
8787

88-
if (!capacity())
88+
if (!capacity() || m_isDisabled)
8989
return false;
9090

9191
if (MemoryPressureHandler::singleton().isUnderMemoryPressure()) {

Source/WebKit/UIProcess/WebProcessCache.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ class WebProcessCache {
4949

5050
unsigned size() const { return m_processesPerRegistrableDomain.size(); }
5151

52+
void setIsDisabled(bool isDisabled) { m_isDisabled = isDisabled; }
53+
5254
void clear();
5355
void setApplicationIsActive(bool);
5456

@@ -61,6 +63,7 @@ class WebProcessCache {
6163
bool addProcess(const String& registrableDomain, Ref<WebProcessProxy>&&);
6264

6365
unsigned m_capacity { 0 };
66+
bool m_isDisabled { false };
6467

6568
class CachedProcess {
6669
WTF_MAKE_FAST_ALLOCATED;

Source/WebKit/UIProcess/WebProcessPool.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1340,7 +1340,7 @@ void WebProcessPool::handleMemoryPressureWarning(Critical)
13401340
m_prewarmedProcess->shutDown();
13411341
ASSERT(!m_prewarmedProcess);
13421342

1343-
m_suspendedPages.clear();
1343+
clearSuspendedPages();
13441344
}
13451345

13461346
#if ENABLE(NETSCAPE_PLUGIN_API)
@@ -2352,6 +2352,11 @@ bool WebProcessPool::hasSuspendedPageFor(WebProcessProxy& process, WebPageProxy*
23522352
}) != m_suspendedPages.end();
23532353
}
23542354

2355+
void WebProcessPool::clearSuspendedPages()
2356+
{
2357+
m_suspendedPages.clear();
2358+
}
2359+
23552360
void WebProcessPool::addMockMediaDevice(const MockMediaDevice& device)
23562361
{
23572362
#if ENABLE(MEDIA_STREAM)

Source/WebKit/UIProcess/WebProcessPool.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,7 @@ class WebProcessPool final : public API::ObjectImpl<API::Object::Type::ProcessPo
468468
bool hasSuspendedPageFor(WebProcessProxy&, WebPageProxy* = nullptr) const;
469469
unsigned maxSuspendedPageCount() const { return m_maxSuspendedPageCount; }
470470
RefPtr<WebProcessProxy> findReusableSuspendedPageProcess(const String&, WebPageProxy&);
471+
void clearSuspendedPages();
471472

472473
void didReachGoodTimeToPrewarm();
473474

Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include "ShouldGrandfatherStatistics.h"
3737
#include "StorageAccessStatus.h"
3838
#include "StorageManager.h"
39+
#include "WebProcessCache.h"
3940
#include "WebProcessMessages.h"
4041
#include "WebProcessPool.h"
4142
#include "WebResourceLoadStatisticsStore.h"
@@ -778,6 +779,16 @@ void WebsiteDataStore::removeData(OptionSet<WebsiteDataType> dataTypes, WallTime
778779

779780
auto webProcessAccessType = computeWebProcessAccessTypeForDataRemoval(dataTypes, !isPersistent());
780781
if (webProcessAccessType != ProcessAccessType::None) {
782+
for (auto& processPool : processPools()) {
783+
processPool->webProcessCache().setIsDisabled(true);
784+
processPool->clearSuspendedPages();
785+
// FIXME: We need to delay the clearing of the process cache because ~SuspendedPageProxy() calls maybeShutDown asynchronously.
786+
RunLoop::main().dispatch([pool = makeRef(*processPool)] {
787+
pool->webProcessCache().clear();
788+
pool->webProcessCache().setIsDisabled(false);
789+
});
790+
}
791+
781792
for (auto& process : processes()) {
782793
switch (webProcessAccessType) {
783794
case ProcessAccessType::OnlyIfLaunched:

Tools/ChangeLog

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
2019-02-21 Ryosuke Niwa <[email protected]>
2+
3+
Discard cached processes when clearing website data store
4+
https://bugs.webkit.org/show_bug.cgi?id=194894
5+
6+
Reviewed by Chris Dumez.
7+
8+
Added a test case.
9+
10+
* TestWebKitAPI/Tests/WebKitCocoa/ProcessSwapOnNavigation.mm:
11+
(TestWebKitAPI.ProcessSwap.NumberOfCachedProcesses): Added.
12+
113
2019-02-21 Alex Christensen <[email protected]>
214

315
Clicking "Go Back" on a safe browsing warning before a WKWebView has loaded any page should request to close the WKWebView

Tools/TestWebKitAPI/Tests/WebKitCocoa/ProcessSwapOnNavigation.mm

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
#import <wtf/HashSet.h>
5353
#import <wtf/RetainPtr.h>
5454
#import <wtf/Vector.h>
55+
#import <wtf/text/StringConcatenateNumbers.h>
5556
#import <wtf/text/StringHash.h>
5657
#import <wtf/text/WTFString.h>
5758

@@ -3058,6 +3059,62 @@ function loaded() {
30583059
EXPECT_TRUE([processPool _hasPrewarmedWebProcess]);
30593060
}
30603061

3062+
TEST(ProcessSwap, NumberOfCachedProcesses)
3063+
{
3064+
auto processPoolConfiguration = adoptNS([[_WKProcessPoolConfiguration alloc] init]);
3065+
processPoolConfiguration.get().processSwapsOnNavigation = YES;
3066+
processPoolConfiguration.get().usesWebProcessCache = YES;
3067+
processPoolConfiguration.get().prewarmsProcessesAutomatically = NO;
3068+
auto processPool = adoptNS([[WKProcessPool alloc] _initWithConfiguration:processPoolConfiguration.get()]);
3069+
3070+
EXPECT_GT([processPool _maximumSuspendedPageCount], 0u);
3071+
EXPECT_GT([processPool _processCacheCapacity], 0u);
3072+
3073+
auto webViewConfiguration = adoptNS([[WKWebViewConfiguration alloc] init]);
3074+
[webViewConfiguration setProcessPool:processPool.get()];
3075+
auto handler = adoptNS([[PSONScheme alloc] init]);
3076+
3077+
const unsigned maxSuspendedPageCount = [processPool _maximumSuspendedPageCount];
3078+
for (unsigned i = 0; i < maxSuspendedPageCount + 2; i++)
3079+
[handler addMappingFromURLString:makeString("pson://www.domain-", i, ".com") toData:pageCache1Bytes];
3080+
[webViewConfiguration setURLSchemeHandler:handler.get() forURLScheme:@"PSON"];
3081+
3082+
auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:webViewConfiguration.get()]);
3083+
auto delegate = adoptNS([[PSONNavigationDelegate alloc] init]);
3084+
[webView setNavigationDelegate:delegate.get()];
3085+
3086+
for (unsigned i = 0; i < maxSuspendedPageCount + 1; i++) {
3087+
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:makeString("pson://www.domain-", i, ".com")]];
3088+
[webView loadRequest:request];
3089+
TestWebKitAPI::Util::run(&done);
3090+
done = false;
3091+
3092+
EXPECT_EQ(i + 1, [processPool _webProcessCount]);
3093+
EXPECT_EQ(i + 1, [processPool _webProcessCountIgnoringPrewarmedAndCached]);
3094+
EXPECT_FALSE([processPool _hasPrewarmedWebProcess]);
3095+
}
3096+
3097+
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:makeString("pson://www.domain-", maxSuspendedPageCount + 1, ".com")]];
3098+
[webView loadRequest:request];
3099+
TestWebKitAPI::Util::run(&done);
3100+
done = false;
3101+
3102+
EXPECT_EQ(maxSuspendedPageCount + 2, [processPool _webProcessCount]);
3103+
EXPECT_EQ(maxSuspendedPageCount + 1, [processPool _webProcessCountIgnoringPrewarmedAndCached]);
3104+
EXPECT_FALSE([processPool _hasPrewarmedWebProcess]);
3105+
3106+
static bool readyToContinue = false;
3107+
[[WKWebsiteDataStore defaultDataStore] removeDataOfTypes:[WKWebsiteDataStore _allWebsiteDataTypesIncludingPrivate] modifiedSince:[NSDate distantPast] completionHandler:^() {
3108+
readyToContinue = true;
3109+
}];
3110+
TestWebKitAPI::Util::run(&readyToContinue);
3111+
3112+
EXPECT_EQ(1u, [processPool _webProcessCount]);
3113+
EXPECT_EQ(1u, [processPool _webProcessCountIgnoringPrewarmedAndCached]);
3114+
EXPECT_FALSE([processPool _hasPrewarmedWebProcess]);
3115+
3116+
}
3117+
30613118
static const char* visibilityBytes = R"PSONRESOURCE(
30623119
<script>
30633120
window.addEventListener('pageshow', function(event) {

0 commit comments

Comments
 (0)