Title: [242025] branches/safari-607-branch
Revision
242025
Author
[email protected]
Date
2019-02-24 20:47:17 -0800 (Sun, 24 Feb 2019)

Log Message

Cherry-pick r241928. rdar://problem/48317429

    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: https://svn.webkit.org/repository/webkit/trunk@241928 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Modified Paths

Diff

Modified: branches/safari-607-branch/Source/WebKit/ChangeLog (242024 => 242025)


--- branches/safari-607-branch/Source/WebKit/ChangeLog	2019-02-25 04:47:12 UTC (rev 242024)
+++ branches/safari-607-branch/Source/WebKit/ChangeLog	2019-02-25 04:47:17 UTC (rev 242025)
@@ -1,5 +1,82 @@
 2019-02-24  Babak Shafiei  <[email protected]>
 
+        Cherry-pick r241928. rdar://problem/48317429
+
+    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: https://svn.webkit.org/repository/webkit/trunk@241928 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    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-24  Babak Shafiei  <[email protected]>
+
         Cherry-pick r241899. rdar://problem/48317463
 
     Crash under RemoteLayerTreePropertyApplier::applyProperties when reattaching to old process

Modified: branches/safari-607-branch/Source/WebKit/UIProcess/API/Cocoa/WKProcessPool.mm (242024 => 242025)


--- branches/safari-607-branch/Source/WebKit/UIProcess/API/Cocoa/WKProcessPool.mm	2019-02-25 04:47:12 UTC (rev 242024)
+++ branches/safari-607-branch/Source/WebKit/UIProcess/API/Cocoa/WKProcessPool.mm	2019-02-25 04:47:17 UTC (rev 242025)
@@ -519,6 +519,11 @@
     return _processPool->maxSuspendedPageCount();
 }
 
+- (NSUInteger)_processCacheCapacity
+{
+    return _processPool->webProcessCache().capacity();
+}
+
 - (size_t)_serviceWorkerProcessCount
 {
 #if ENABLE(SERVICE_WORKER)

Modified: branches/safari-607-branch/Source/WebKit/UIProcess/API/Cocoa/WKProcessPoolPrivate.h (242024 => 242025)


--- branches/safari-607-branch/Source/WebKit/UIProcess/API/Cocoa/WKProcessPoolPrivate.h	2019-02-25 04:47:12 UTC (rev 242024)
+++ branches/safari-607-branch/Source/WebKit/UIProcess/API/Cocoa/WKProcessPoolPrivate.h	2019-02-25 04:47:17 UTC (rev 242025)
@@ -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: branches/safari-607-branch/Source/WebKit/UIProcess/WebProcessCache.cpp (242024 => 242025)


--- branches/safari-607-branch/Source/WebKit/UIProcess/WebProcessCache.cpp	2019-02-25 04:47:12 UTC (rev 242024)
+++ branches/safari-607-branch/Source/WebKit/UIProcess/WebProcessCache.cpp	2019-02-25 04:47:17 UTC (rev 242025)
@@ -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: branches/safari-607-branch/Source/WebKit/UIProcess/WebProcessCache.h (242024 => 242025)


--- branches/safari-607-branch/Source/WebKit/UIProcess/WebProcessCache.h	2019-02-25 04:47:12 UTC (rev 242024)
+++ branches/safari-607-branch/Source/WebKit/UIProcess/WebProcessCache.h	2019-02-25 04:47:17 UTC (rev 242025)
@@ -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: branches/safari-607-branch/Source/WebKit/UIProcess/WebProcessPool.cpp (242024 => 242025)


--- branches/safari-607-branch/Source/WebKit/UIProcess/WebProcessPool.cpp	2019-02-25 04:47:12 UTC (rev 242024)
+++ branches/safari-607-branch/Source/WebKit/UIProcess/WebProcessPool.cpp	2019-02-25 04:47:17 UTC (rev 242025)
@@ -1343,7 +1343,7 @@
         m_prewarmedProcess->shutDown();
     ASSERT(!m_prewarmedProcess);
 
-    m_suspendedPages.clear();
+    clearSuspendedPages();
 }
 
 #if ENABLE(NETSCAPE_PLUGIN_API)
@@ -2343,6 +2343,11 @@
     }) != m_suspendedPages.end();
 }
 
+void WebProcessPool::clearSuspendedPages()
+{
+    m_suspendedPages.clear();
+}
+
 void WebProcessPool::addMockMediaDevice(const MockMediaDevice& device)
 {
 #if ENABLE(MEDIA_STREAM)

Modified: branches/safari-607-branch/Source/WebKit/UIProcess/WebProcessPool.h (242024 => 242025)


--- branches/safari-607-branch/Source/WebKit/UIProcess/WebProcessPool.h	2019-02-25 04:47:12 UTC (rev 242024)
+++ branches/safari-607-branch/Source/WebKit/UIProcess/WebProcessPool.h	2019-02-25 04:47:17 UTC (rev 242025)
@@ -459,6 +459,7 @@
     bool hasSuspendedPageFor(WebProcessProxy&, WebPageProxy* = nullptr) const;
     unsigned maxSuspendedPageCount() const { return m_maxSuspendedPageCount; }
     RefPtr<WebProcessProxy> findReusableSuspendedPageProcess(const String&, WebPageProxy&);
+    void clearSuspendedPages();
 
     void didReachGoodTimeToPrewarm();
 

Modified: branches/safari-607-branch/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.cpp (242024 => 242025)


--- branches/safari-607-branch/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.cpp	2019-02-25 04:47:12 UTC (rev 242024)
+++ branches/safari-607-branch/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.cpp	2019-02-25 04:47:17 UTC (rev 242025)
@@ -35,6 +35,7 @@
 #include "NetworkProcessMessages.h"
 #include "StorageManager.h"
 #include "WebCookieManagerProxy.h"
+#include "WebProcessCache.h"
 #include "WebProcessMessages.h"
 #include "WebProcessPool.h"
 #include "WebResourceLoadStatisticsStore.h"
@@ -776,6 +777,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: branches/safari-607-branch/Tools/ChangeLog (242024 => 242025)


--- branches/safari-607-branch/Tools/ChangeLog	2019-02-25 04:47:12 UTC (rev 242024)
+++ branches/safari-607-branch/Tools/ChangeLog	2019-02-25 04:47:17 UTC (rev 242025)
@@ -1,5 +1,62 @@
 2019-02-24  Babak Shafiei  <[email protected]>
 
+        Cherry-pick r241928. rdar://problem/48317429
+
+    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: https://svn.webkit.org/repository/webkit/trunk@241928 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    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-24  Babak Shafiei  <[email protected]>
+
         Cherry-pick r241899. rdar://problem/48317463
 
     Crash under RemoteLayerTreePropertyApplier::applyProperties when reattaching to old process

Modified: branches/safari-607-branch/Tools/TestWebKitAPI/Tests/WebKitCocoa/ProcessSwapOnNavigation.mm (242024 => 242025)


--- branches/safari-607-branch/Tools/TestWebKitAPI/Tests/WebKitCocoa/ProcessSwapOnNavigation.mm	2019-02-25 04:47:12 UTC (rev 242024)
+++ branches/safari-607-branch/Tools/TestWebKitAPI/Tests/WebKitCocoa/ProcessSwapOnNavigation.mm	2019-02-25 04:47:17 UTC (rev 242025)
@@ -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>
 
@@ -3050,6 +3051,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) {
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to