Changeset 241928 in webkit


Ignore:
Timestamp:
Feb 21, 2019 6:58:40 PM (5 years ago)
Author:
rniwa@webkit.org
Message:

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.

Location:
trunk
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r241926 r241928  
     12019-02-21  Ryosuke Niwa  <rniwa@webkit.org>
     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
    1332019-02-21  Alex Christensen  <achristensen@webkit.org>
    234
  • trunk/Source/WebKit/UIProcess/API/Cocoa/WKProcessPool.mm

    r241556 r241928  
    515515}
    516516
     517- (NSUInteger)_processCacheCapacity
     518{
     519    return _processPool->webProcessCache().capacity();
     520}
     521
    517522- (size_t)_serviceWorkerProcessCount
    518523{
  • trunk/Source/WebKit/UIProcess/API/Cocoa/WKProcessPoolPrivate.h

    r241556 r241928  
    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)
  • trunk/Source/WebKit/UIProcess/WebProcessCache.cpp

    r241919 r241928  
    5252    ASSERT(!process->processPool().hasSuspendedPageFor(process));
    5353
    54     if (!capacity())
     54    if (!capacity() || m_isDisabled)
    5555        return false;
    5656
     
    8686    ASSERT(!process->processPool().hasSuspendedPageFor(process));
    8787
    88     if (!capacity())
     88    if (!capacity() || m_isDisabled)
    8989        return false;
    9090
  • trunk/Source/WebKit/UIProcess/WebProcessCache.h

    r241855 r241928  
    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);
     
    6264
    6365    unsigned m_capacity { 0 };
     66    bool m_isDisabled { false };
    6467
    6568    class CachedProcess {
  • trunk/Source/WebKit/UIProcess/WebProcessPool.cpp

    r241778 r241928  
    13411341    ASSERT(!m_prewarmedProcess);
    13421342
    1343     m_suspendedPages.clear();
     1343    clearSuspendedPages();
    13441344}
    13451345
     
    23532353}
    23542354
     2355void WebProcessPool::clearSuspendedPages()
     2356{
     2357    m_suspendedPages.clear();
     2358}
     2359
    23552360void WebProcessPool::addMockMediaDevice(const MockMediaDevice& device)
    23562361{
  • trunk/Source/WebKit/UIProcess/WebProcessPool.h

    r241778 r241928  
    469469    unsigned maxSuspendedPageCount() const { return m_maxSuspendedPageCount; }
    470470    RefPtr<WebProcessProxy> findReusableSuspendedPageProcess(const String&, WebPageProxy&);
     471    void clearSuspendedPages();
    471472
    472473    void didReachGoodTimeToPrewarm();
  • trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.cpp

    r241826 r241928  
    3737#include "StorageAccessStatus.h"
    3838#include "StorageManager.h"
     39#include "WebProcessCache.h"
    3940#include "WebProcessMessages.h"
    4041#include "WebProcessPool.h"
     
    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) {
  • trunk/Tools/ChangeLog

    r241926 r241928  
     12019-02-21  Ryosuke Niwa  <rniwa@webkit.org>
     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
    1132019-02-21  Alex Christensen  <achristensen@webkit.org>
    214
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ProcessSwapOnNavigation.mm

    r241917 r241928  
    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>
     
    30573058    EXPECT_EQ(2u, [processPool _webProcessCountIgnoringPrewarmedAndCached]);
    30583059    EXPECT_TRUE([processPool _hasPrewarmedWebProcess]);
     3060}
     3061
     3062TEST(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
    30593116}
    30603117
Note: See TracChangeset for help on using the changeset viewer.