⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 267627 in webkit


Ignore:
Timestamp:
Sep 26, 2020, 2:08:20 PM (6 years ago)
Author:
Alan Coon
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

Location:
branches/safari-610-branch
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • branches/safari-610-branch/Source/WebKit/ChangeLog

    r267286 r267627  
     12020-09-25  Alan Coon  <alancoon@apple.com>
     2
     3        Cherry-pick r266798. rdar://problem/69583118
     4
     5    Make sure WKWebsiteDataStore operations reuse existing process pools even when all WKWebViews have closed.
     6    <rdar://problem/62978295> and https://bugs.webkit.org/show_bug.cgi?id=216317
     7   
     8    Reviewed by Geoffrey Garen.
     9   
     10    Source/WebKit:
     11   
     12    Covered by new API test.
     13   
     14    When WebsiteDataStores are gathering all the NetworkProcesses they might need to message, they miss some
     15    obvious candidates if there are no longer any related WKWebViews.
     16   
     17    Fix that by tracking which sessions a NetworkProcess knows about.
     18   
     19    * UIProcess/Network/NetworkProcessProxy.cpp:
     20    (WebKit::NetworkProcessProxy::addSession):
     21    (WebKit::NetworkProcessProxy::hasSession const):
     22    (WebKit::NetworkProcessProxy::removeSession):
     23    * UIProcess/Network/NetworkProcessProxy.h:
     24   
     25    * UIProcess/WebsiteData/WebsiteDataStore.cpp:
     26    (WebKit::WebsiteDataStore::isAssociatedProcessPool const):
     27   
     28    Tools:
     29   
     30    * TestWebKitAPI/Tests/WebKitCocoa/WKWebsiteDatastore.mm:
     31    (TestWebKitAPI::TEST):
     32   
     33   
     34    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@266798 268f45cc-cd09-0410-ab3c-d52691b4dbfc
     35
     36    2020-09-09  Brady Eidson  <beidson@apple.com>
     37
     38            Make sure WKWebsiteDataStore operations reuse existing process pools even when all WKWebViews have closed.
     39            <rdar://problem/62978295> and https://bugs.webkit.org/show_bug.cgi?id=216317
     40
     41            Reviewed by Geoffrey Garen.
     42
     43            Covered by new API test.
     44
     45            When WebsiteDataStores are gathering all the NetworkProcesses they might need to message, they miss some
     46            obvious candidates if there are no longer any related WKWebViews.
     47
     48            Fix that by tracking which sessions a NetworkProcess knows about.
     49
     50            * UIProcess/Network/NetworkProcessProxy.cpp:
     51            (WebKit::NetworkProcessProxy::addSession):
     52            (WebKit::NetworkProcessProxy::hasSession const):
     53            (WebKit::NetworkProcessProxy::removeSession):
     54            * UIProcess/Network/NetworkProcessProxy.h:
     55
     56            * UIProcess/WebsiteData/WebsiteDataStore.cpp:
     57            (WebKit::WebsiteDataStore::isAssociatedProcessPool const):
     58
    1592020-09-18  Alan Coon  <alancoon@apple.com>
    260
  • branches/safari-610-branch/Source/WebKit/UIProcess/Network/NetworkProcessProxy.cpp

    r265389 r267627  
    12741274void NetworkProcessProxy::addSession(Ref<WebsiteDataStore>&& store)
    12751275{
     1276    m_sessionIDs.add(store->sessionID());
     1277
    12761278    if (canSendMessage())
    12771279        send(Messages::NetworkProcess::AddWebsiteDataStore { store->parameters() }, 0);
     
    12841286}
    12851287
     1288bool NetworkProcessProxy::hasSession(PAL::SessionID sessionID) const
     1289{
     1290    return m_sessionIDs.contains(sessionID);
     1291}
     1292
    12861293void NetworkProcessProxy::removeSession(PAL::SessionID sessionID)
    12871294{
     1295    m_sessionIDs.remove(sessionID);
     1296
    12881297    if (canSendMessage())
    12891298        send(Messages::NetworkProcess::DestroySession { sessionID }, 0);
  • branches/safari-610-branch/Source/WebKit/UIProcess/Network/NetworkProcessProxy.h

    r265389 r267627  
    213213
    214214    void addSession(Ref<WebsiteDataStore>&&);
     215    bool hasSession(PAL::SessionID) const;
    215216    void removeSession(PAL::SessionID);
    216217   
     
    348349    };
    349350#endif
     351
     352    HashSet<PAL::SessionID> m_sessionIDs;
    350353};
    351354
  • branches/safari-610-branch/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.cpp

    r266433 r267627  
    19981998    if (auto* processPoolDataStore = processPool.websiteDataStore())
    19991999        return processPoolDataStore == this;
     2000    if (auto* networkProcessProxy = processPool.networkProcess())
     2001        return networkProcessProxy->hasSession(m_sessionID);
    20002002    return false;
    20012003}
  • branches/safari-610-branch/Tools/ChangeLog

    r267556 r267627  
     12020-09-25  Alan Coon  <alancoon@apple.com>
     2
     3        Cherry-pick r266798. rdar://problem/69583118
     4
     5    Make sure WKWebsiteDataStore operations reuse existing process pools even when all WKWebViews have closed.
     6    <rdar://problem/62978295> and https://bugs.webkit.org/show_bug.cgi?id=216317
     7   
     8    Reviewed by Geoffrey Garen.
     9   
     10    Source/WebKit:
     11   
     12    Covered by new API test.
     13   
     14    When WebsiteDataStores are gathering all the NetworkProcesses they might need to message, they miss some
     15    obvious candidates if there are no longer any related WKWebViews.
     16   
     17    Fix that by tracking which sessions a NetworkProcess knows about.
     18   
     19    * UIProcess/Network/NetworkProcessProxy.cpp:
     20    (WebKit::NetworkProcessProxy::addSession):
     21    (WebKit::NetworkProcessProxy::hasSession const):
     22    (WebKit::NetworkProcessProxy::removeSession):
     23    * UIProcess/Network/NetworkProcessProxy.h:
     24   
     25    * UIProcess/WebsiteData/WebsiteDataStore.cpp:
     26    (WebKit::WebsiteDataStore::isAssociatedProcessPool const):
     27   
     28    Tools:
     29   
     30    * TestWebKitAPI/Tests/WebKitCocoa/WKWebsiteDatastore.mm:
     31    (TestWebKitAPI::TEST):
     32   
     33   
     34    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@266798 268f45cc-cd09-0410-ab3c-d52691b4dbfc
     35
     36    2020-09-09  Brady Eidson  <beidson@apple.com>
     37
     38            Make sure WKWebsiteDataStore operations reuse existing process pools even when all WKWebViews have closed.
     39            <rdar://problem/62978295> and https://bugs.webkit.org/show_bug.cgi?id=216317
     40
     41            Reviewed by Geoffrey Garen.
     42
     43            * TestWebKitAPI/Tests/WebKitCocoa/WKWebsiteDatastore.mm:
     44            (TestWebKitAPI::TEST):
     45
    1462020-09-24  Ryan Haddad  <ryanhaddad@apple.com>
    247
  • branches/safari-610-branch/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebsiteDatastore.mm

    r262656 r267627  
    2626#import "config.h"
    2727
     28#import "HTTPServer.h"
    2829#import "PlatformUtilities.h"
    2930#import "TCPServer.h"
     
    3132#import "TestWKWebView.h"
    3233#import <WebKit/WKProcessPoolPrivate.h>
     34#import <WebKit/WKWebViewPrivate.h>
    3335#import <WebKit/WKWebsiteDataRecordPrivate.h>
    3436#import <WebKit/WKWebsiteDataStorePrivate.h>
     
    310312}
    311313
    312 }
     314TEST(WebKit, ClearCustomDataStoreNoWebViews)
     315{
     316    HTTPServer server([connectionCount = 0] (Connection connection) mutable {
     317        ++connectionCount;
     318        connection.receiveHTTPRequest([connection, connectionCount] (Vector<char>&& request) {
     319            switch (connectionCount) {
     320            case 1:
     321                connection.send(
     322                    "HTTP/1.1 200 OK\r\n"
     323                    "Content-Length: 5\r\n"
     324                    "Set-Cookie: a=b\r\n"
     325                    "Connection: close\r\n"
     326                    "\r\n"
     327                    "Hello");
     328                break;
     329            case 2:
     330                EXPECT_FALSE(strstr(request.data(), "Cookie: a=b\r\n"));
     331                connection.send(
     332                    "HTTP/1.1 200 OK\r\n"
     333                    "Content-Length: 5\r\n"
     334                    "Connection: close\r\n"
     335                    "\r\n"
     336                    "Hello");
     337                break;
     338            default:
     339                ASSERT_NOT_REACHED();
     340            }
     341        });
     342    });
     343
     344
     345    NSURL *fileURL = [NSURL fileURLWithPath:@"/tmp/testcookiefile.cookie"];
     346    auto configuration = adoptNS([[_WKWebsiteDataStoreConfiguration alloc] init]);
     347    [configuration _setCookieStorageFile:fileURL];
     348
     349    auto dataStore = adoptNS([[WKWebsiteDataStore alloc] _initWithConfiguration:configuration.get()]);
     350    auto viewConfiguration = adoptNS([WKWebViewConfiguration new]);
     351    [viewConfiguration setWebsiteDataStore:dataStore.get()];
     352    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 100, 100) configuration:viewConfiguration.get() addToWindow:YES]);
     353
     354    auto *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://127.0.0.1:%d/index.html", server.port()]];
     355
     356    [webView synchronouslyLoadRequest:[NSURLRequest requestWithURL:url]];
     357    [webView _close];
     358    webView = nil;
     359
     360    // Now that the WebView is closed, remove all website data.
     361    // Then recreate a WebView with the same configuration to confirm the website data was removed.
     362    static bool done;
     363    [dataStore removeDataOfTypes:[WKWebsiteDataStore allWebsiteDataTypes] modifiedSince:[NSDate distantPast] completionHandler:^{
     364        done = true;
     365    }];
     366    Util::run(&done);
     367    done = false;
     368
     369    webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 100, 100) configuration:viewConfiguration.get() addToWindow:YES]);
     370    [webView synchronouslyLoadRequest:[NSURLRequest requestWithURL:url]];
     371}
     372
     373} // namespace TestWebKitAPI
Note: See TracChangeset for help on using the changeset viewer.