Title: [274631] releases/WebKitGTK/webkit-2.30
Revision
274631
Author
[email protected]
Date
2021-03-18 04:03:49 -0700 (Thu, 18 Mar 2021)

Log Message

Merge r266798 - Make sure WKWebsiteDataStore operations reuse existing process pools even when all WKWebViews have closed.
<rdar://problem/62978295> and https://bugs.webkit.org/show_bug.cgi?id=216317

Reviewed by Geoffrey Garen.

Source/WebKit:

Covered by new API test.

When WebsiteDataStores are gathering all the NetworkProcesses they might need to message, they miss some
obvious candidates if there are no longer any related WKWebViews.

Fix that by tracking which sessions a NetworkProcess knows about.

* UIProcess/Network/NetworkProcessProxy.cpp:
(WebKit::NetworkProcessProxy::addSession):
(WebKit::NetworkProcessProxy::hasSession const):
(WebKit::NetworkProcessProxy::removeSession):
* UIProcess/Network/NetworkProcessProxy.h:

* UIProcess/WebsiteData/WebsiteDataStore.cpp:
(WebKit::WebsiteDataStore::isAssociatedProcessPool const):

Tools:

* TestWebKitAPI/Tests/WebKitCocoa/WKWebsiteDatastore.mm:
(TestWebKitAPI::TEST):

Modified Paths

Diff

Modified: releases/WebKitGTK/webkit-2.30/Source/WebKit/ChangeLog (274630 => 274631)


--- releases/WebKitGTK/webkit-2.30/Source/WebKit/ChangeLog	2021-03-18 10:10:14 UTC (rev 274630)
+++ releases/WebKitGTK/webkit-2.30/Source/WebKit/ChangeLog	2021-03-18 11:03:49 UTC (rev 274631)
@@ -1,3 +1,26 @@
+2020-09-09  Brady Eidson  <[email protected]>
+
+        Make sure WKWebsiteDataStore operations reuse existing process pools even when all WKWebViews have closed.
+        <rdar://problem/62978295> and https://bugs.webkit.org/show_bug.cgi?id=216317
+
+        Reviewed by Geoffrey Garen.
+
+        Covered by new API test.
+        
+        When WebsiteDataStores are gathering all the NetworkProcesses they might need to message, they miss some
+        obvious candidates if there are no longer any related WKWebViews.
+        
+        Fix that by tracking which sessions a NetworkProcess knows about.
+
+        * UIProcess/Network/NetworkProcessProxy.cpp:
+        (WebKit::NetworkProcessProxy::addSession):
+        (WebKit::NetworkProcessProxy::hasSession const):
+        (WebKit::NetworkProcessProxy::removeSession):
+        * UIProcess/Network/NetworkProcessProxy.h:
+
+        * UIProcess/WebsiteData/WebsiteDataStore.cpp:
+        (WebKit::WebsiteDataStore::isAssociatedProcessPool const):
+
 2020-08-13  Chris Dumez  <[email protected]>
 
         REGRESSION (r260684): Messages YouTube inline video: after Multitasking away and Back, Audio is heard but icon indicates "muted"

Modified: releases/WebKitGTK/webkit-2.30/Source/WebKit/UIProcess/Network/NetworkProcessProxy.cpp (274630 => 274631)


--- releases/WebKitGTK/webkit-2.30/Source/WebKit/UIProcess/Network/NetworkProcessProxy.cpp	2021-03-18 10:10:14 UTC (rev 274630)
+++ releases/WebKitGTK/webkit-2.30/Source/WebKit/UIProcess/Network/NetworkProcessProxy.cpp	2021-03-18 11:03:49 UTC (rev 274631)
@@ -1273,6 +1273,8 @@
 
 void NetworkProcessProxy::addSession(Ref<WebsiteDataStore>&& store)
 {
+    m_sessionIDs.add(store->sessionID());
+
     if (canSendMessage())
         send(Messages::NetworkProcess::AddWebsiteDataStore { store->parameters() }, 0);
     auto sessionID = store->sessionID();
@@ -1283,8 +1285,15 @@
     }
 }
 
+bool NetworkProcessProxy::hasSession(PAL::SessionID sessionID) const
+{
+    return m_sessionIDs.contains(sessionID);
+}
+
 void NetworkProcessProxy::removeSession(PAL::SessionID sessionID)
 {
+    m_sessionIDs.remove(sessionID);
+
     if (canSendMessage())
         send(Messages::NetworkProcess::DestroySession { sessionID }, 0);
 }

Modified: releases/WebKitGTK/webkit-2.30/Source/WebKit/UIProcess/Network/NetworkProcessProxy.h (274630 => 274631)


--- releases/WebKitGTK/webkit-2.30/Source/WebKit/UIProcess/Network/NetworkProcessProxy.h	2021-03-18 10:10:14 UTC (rev 274630)
+++ releases/WebKitGTK/webkit-2.30/Source/WebKit/UIProcess/Network/NetworkProcessProxy.h	2021-03-18 11:03:49 UTC (rev 274631)
@@ -212,6 +212,7 @@
 #endif
 
     void addSession(Ref<WebsiteDataStore>&&);
+    bool hasSession(PAL::SessionID) const;
     void removeSession(PAL::SessionID);
     
 #if ENABLE(INDEXED_DATABASE)
@@ -347,6 +348,8 @@
         WeakPtr<NetworkProcessProxy> m_networkProcess;
     };
 #endif
+
+    HashSet<PAL::SessionID> m_sessionIDs;
 };
 
 } // namespace WebKit

Modified: releases/WebKitGTK/webkit-2.30/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.cpp (274630 => 274631)


--- releases/WebKitGTK/webkit-2.30/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.cpp	2021-03-18 10:10:14 UTC (rev 274630)
+++ releases/WebKitGTK/webkit-2.30/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.cpp	2021-03-18 11:03:49 UTC (rev 274631)
@@ -1995,6 +1995,8 @@
 {
     if (auto* processPoolDataStore = processPool.websiteDataStore())
         return processPoolDataStore == this;
+    if (auto* networkProcessProxy = processPool.networkProcess())
+        return networkProcessProxy->hasSession(m_sessionID);
     return false;
 }
 

Modified: releases/WebKitGTK/webkit-2.30/Tools/ChangeLog (274630 => 274631)


--- releases/WebKitGTK/webkit-2.30/Tools/ChangeLog	2021-03-18 10:10:14 UTC (rev 274630)
+++ releases/WebKitGTK/webkit-2.30/Tools/ChangeLog	2021-03-18 11:03:49 UTC (rev 274631)
@@ -1,3 +1,13 @@
+2020-09-09  Brady Eidson  <[email protected]>
+
+        Make sure WKWebsiteDataStore operations reuse existing process pools even when all WKWebViews have closed.
+        <rdar://problem/62978295> and https://bugs.webkit.org/show_bug.cgi?id=216317
+
+        Reviewed by Geoffrey Garen.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/WKWebsiteDatastore.mm:
+        (TestWebKitAPI::TEST):
+
 2021-02-16  Michael Catanzaro  <[email protected]>
 
         [GTK] Need new user agent quirk for Google Docs and Google Drive

Modified: releases/WebKitGTK/webkit-2.30/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebsiteDatastore.mm (274630 => 274631)


--- releases/WebKitGTK/webkit-2.30/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebsiteDatastore.mm	2021-03-18 10:10:14 UTC (rev 274630)
+++ releases/WebKitGTK/webkit-2.30/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebsiteDatastore.mm	2021-03-18 11:03:49 UTC (rev 274631)
@@ -25,11 +25,13 @@
 
 #import "config.h"
 
+#import "HTTPServer.h"
 #import "PlatformUtilities.h"
 #import "TCPServer.h"
 #import "Test.h"
 #import "TestWKWebView.h"
 #import <WebKit/WKProcessPoolPrivate.h>
+#import <WebKit/WKWebViewPrivate.h>
 #import <WebKit/WKWebsiteDataRecordPrivate.h>
 #import <WebKit/WKWebsiteDataStorePrivate.h>
 #import <WebKit/WebKit.h>
@@ -309,4 +311,63 @@
     TestWebKitAPI::Util::run(&readyToContinue);
 }
 
+TEST(WebKit, ClearCustomDataStoreNoWebViews)
+{
+    HTTPServer server([connectionCount = 0] (Connection connection) mutable {
+        ++connectionCount;
+        connection.receiveHTTPRequest([connection, connectionCount] (Vector<char>&& request) {
+            switch (connectionCount) {
+            case 1:
+                connection.send(
+                    "HTTP/1.1 200 OK\r\n"
+                    "Content-Length: 5\r\n"
+                    "Set-Cookie: a=b\r\n"
+                    "Connection: close\r\n"
+                    "\r\n"
+                    "Hello");
+                break;
+            case 2:
+                EXPECT_FALSE(strstr(request.data(), "Cookie: a=b\r\n"));
+                connection.send(
+                    "HTTP/1.1 200 OK\r\n"
+                    "Content-Length: 5\r\n"
+                    "Connection: close\r\n"
+                    "\r\n"
+                    "Hello");
+                break;
+            default:
+                ASSERT_NOT_REACHED();
+            }
+        });
+    });
+
+
+    NSURL *fileURL = [NSURL fileURLWithPath:@"/tmp/testcookiefile.cookie"];
+    auto configuration = adoptNS([[_WKWebsiteDataStoreConfiguration alloc] init]);
+    [configuration _setCookieStorageFile:fileURL];
+
+    auto dataStore = adoptNS([[WKWebsiteDataStore alloc] _initWithConfiguration:configuration.get()]);
+    auto viewConfiguration = adoptNS([WKWebViewConfiguration new]);
+    [viewConfiguration setWebsiteDataStore:dataStore.get()];
+    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 100, 100) configuration:viewConfiguration.get() addToWindow:YES]);
+
+    auto *url = "" URLWithString:[NSString stringWithFormat:@"http://127.0.0.1:%d/index.html", server.port()]];
+
+    [webView synchronouslyLoadRequest:[NSURLRequest requestWithURL:url]];
+    [webView _close];
+    webView = nil;
+
+    // Now that the WebView is closed, remove all website data.
+    // Then recreate a WebView with the same configuration to confirm the website data was removed.
+    static bool done;
+    [dataStore removeDataOfTypes:[WKWebsiteDataStore allWebsiteDataTypes] modifiedSince:[NSDate distantPast] completionHandler:^{
+        done = true;
+    }];
+    Util::run(&done);
+    done = false;
+
+    webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 100, 100) configuration:viewConfiguration.get() addToWindow:YES]);
+    [webView synchronouslyLoadRequest:[NSURLRequest requestWithURL:url]];
 }
+
+} // namespace TestWebKitAPI
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to