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

Changeset 266798 in webkit


Ignore:
Timestamp:
Sep 9, 2020, 12:56:58 PM (6 years ago)
Author:
beidson@apple.com
Message:

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

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r266797 r266798  
     12020-09-09  Brady Eidson  <beidson@apple.com>
     2
     3        Make sure WKWebsiteDataStore operations reuse existing process pools even when all WKWebViews have closed.
     4        <rdar://problem/62978295> and https://bugs.webkit.org/show_bug.cgi?id=216317
     5
     6        Reviewed by Geoffrey Garen.
     7
     8        Covered by new API test.
     9       
     10        When WebsiteDataStores are gathering all the NetworkProcesses they might need to message, they miss some
     11        obvious candidates if there are no longer any related WKWebViews.
     12       
     13        Fix that by tracking which sessions a NetworkProcess knows about.
     14
     15        * UIProcess/Network/NetworkProcessProxy.cpp:
     16        (WebKit::NetworkProcessProxy::addSession):
     17        (WebKit::NetworkProcessProxy::hasSession const):
     18        (WebKit::NetworkProcessProxy::removeSession):
     19        * UIProcess/Network/NetworkProcessProxy.h:
     20
     21        * UIProcess/WebsiteData/WebsiteDataStore.cpp:
     22        (WebKit::WebsiteDataStore::isAssociatedProcessPool const):
     23
    1242020-09-09  Chris Dumez  <cdumez@apple.com>
    225
  • trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.cpp

    r265389 r266798  
    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);
  • trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.h

    r265389 r266798  
    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
  • trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.cpp

    r266268 r266798  
    20002000    if (auto* processPoolDataStore = processPool.websiteDataStore())
    20012001        return processPoolDataStore == this;
     2002    if (auto* networkProcessProxy = processPool.networkProcess())
     2003        return networkProcessProxy->hasSession(m_sessionID);
    20022004    return false;
    20032005}
  • trunk/Tools/ChangeLog

    r266796 r266798  
     12020-09-09  Brady Eidson  <beidson@apple.com>
     2
     3        Make sure WKWebsiteDataStore operations reuse existing process pools even when all WKWebViews have closed.
     4        <rdar://problem/62978295> and https://bugs.webkit.org/show_bug.cgi?id=216317
     5
     6        Reviewed by Geoffrey Garen.
     7
     8        * TestWebKitAPI/Tests/WebKitCocoa/WKWebsiteDatastore.mm:
     9        (TestWebKitAPI::TEST):
     10
    1112020-09-09  Angelos Oikonomopoulos  <angelos@igalia.com>
    212
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebsiteDatastore.mm

    r262656 r266798  
    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.