Title: [267627] branches/safari-610-branch
Revision
267627
Author
[email protected]
Date
2020-09-26 14:08:20 -0700 (Sat, 26 Sep 2020)

Log Message

Cherry-pick r266798. rdar://problem/69583118

    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):

    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@266798 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Modified Paths

Diff

Modified: branches/safari-610-branch/Source/WebKit/ChangeLog (267626 => 267627)


--- branches/safari-610-branch/Source/WebKit/ChangeLog	2020-09-26 21:08:15 UTC (rev 267626)
+++ branches/safari-610-branch/Source/WebKit/ChangeLog	2020-09-26 21:08:20 UTC (rev 267627)
@@ -1,3 +1,61 @@
+2020-09-25  Alan Coon  <[email protected]>
+
+        Cherry-pick r266798. rdar://problem/69583118
+
+    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):
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@266798 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    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-09-18  Alan Coon  <[email protected]>
 
         Cherry-pick r267208. rdar://problem/69178138

Modified: branches/safari-610-branch/Source/WebKit/UIProcess/Network/NetworkProcessProxy.cpp (267626 => 267627)


--- branches/safari-610-branch/Source/WebKit/UIProcess/Network/NetworkProcessProxy.cpp	2020-09-26 21:08:15 UTC (rev 267626)
+++ branches/safari-610-branch/Source/WebKit/UIProcess/Network/NetworkProcessProxy.cpp	2020-09-26 21:08:20 UTC (rev 267627)
@@ -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: branches/safari-610-branch/Source/WebKit/UIProcess/Network/NetworkProcessProxy.h (267626 => 267627)


--- branches/safari-610-branch/Source/WebKit/UIProcess/Network/NetworkProcessProxy.h	2020-09-26 21:08:15 UTC (rev 267626)
+++ branches/safari-610-branch/Source/WebKit/UIProcess/Network/NetworkProcessProxy.h	2020-09-26 21:08:20 UTC (rev 267627)
@@ -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: branches/safari-610-branch/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.cpp (267626 => 267627)


--- branches/safari-610-branch/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.cpp	2020-09-26 21:08:15 UTC (rev 267626)
+++ branches/safari-610-branch/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.cpp	2020-09-26 21:08:20 UTC (rev 267627)
@@ -1997,6 +1997,8 @@
 {
     if (auto* processPoolDataStore = processPool.websiteDataStore())
         return processPoolDataStore == this;
+    if (auto* networkProcessProxy = processPool.networkProcess())
+        return networkProcessProxy->hasSession(m_sessionID);
     return false;
 }
 

Modified: branches/safari-610-branch/Tools/ChangeLog (267626 => 267627)


--- branches/safari-610-branch/Tools/ChangeLog	2020-09-26 21:08:15 UTC (rev 267626)
+++ branches/safari-610-branch/Tools/ChangeLog	2020-09-26 21:08:20 UTC (rev 267627)
@@ -1,3 +1,48 @@
+2020-09-25  Alan Coon  <[email protected]>
+
+        Cherry-pick r266798. rdar://problem/69583118
+
+    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):
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@266798 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    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):
+
 2020-09-24  Ryan Haddad  <[email protected]>
 
         Cherry-pick r267501. rdar://problem/69454393

Modified: branches/safari-610-branch/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebsiteDatastore.mm (267626 => 267627)


--- branches/safari-610-branch/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebsiteDatastore.mm	2020-09-26 21:08:15 UTC (rev 267626)
+++ branches/safari-610-branch/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebsiteDatastore.mm	2020-09-26 21:08:20 UTC (rev 267627)
@@ -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