Changeset 231850 in webkit


Ignore:
Timestamp:
May 16, 2018 10:19:17 AM (6 years ago)
Author:
commit-queue@webkit.org
Message:

Session cookies aren't reliably set when using default WKWebSiteDataStore
https://bugs.webkit.org/show_bug.cgi?id=185624
<rdar://problem/39111626>

Patch by Sihui Liu <sihui_liu@apple.com> on 2018-05-16
Reviewed by Geoffrey Garen.

Source/WebKit:

Session cookies of default session were set in UI Process when there was no process pool,
but they were not synced (or synced slowly to) Network Process. To make these cookies visible
as soon as they were set through API, we could manually set those cookies in Network Process
during its initilization.

  • NetworkProcess/mac/RemoteNetworkingContext.mm:

(WebKit::RemoteNetworkingContext::ensureWebsiteDataStoreSession):

  • UIProcess/API/APIHTTPCookieStore.cpp:

(API::HTTPCookieStore::cookies):
(API::HTTPCookieStore::setCookie):
(API::HTTPCookieStore::deleteCookie):

  • UIProcess/WebProcessPool.cpp:

(WebKit::WebProcessPool::ensureNetworkProcess):
(WebKit::WebProcessPool::pageBeginUsingWebsiteDataStore):

  • UIProcess/WebsiteData/WebsiteDataStore.cpp:

(WebKit::WebsiteDataStore::clearPendingCookies):

  • UIProcess/WebsiteData/WebsiteDataStore.h:

Tools:

Modified and enabled WebKit.WKHTTPCookieStoreWithoutProcessPool.

  • TestWebKitAPI/Tests/WebKitCocoa/WKHTTPCookieStore.mm:

(-[CookieUIDelegate webView:runJavaScriptAlertPanelWithMessage:initiatedByFrame:completionHandler:]):
(TEST):

Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r231849 r231850  
     12018-05-16  Sihui Liu  <sihui_liu@apple.com>
     2
     3        Session cookies aren't reliably set when using default WKWebSiteDataStore
     4        https://bugs.webkit.org/show_bug.cgi?id=185624
     5        <rdar://problem/39111626>
     6
     7        Reviewed by Geoffrey Garen.
     8
     9        Session cookies of default session were set in UI Process when there was no process pool,
     10        but they were not synced (or synced slowly to) Network Process. To make these cookies visible
     11        as soon as they were set through API, we could manually set those cookies in Network Process
     12        during its initilization.
     13
     14        * NetworkProcess/mac/RemoteNetworkingContext.mm:
     15        (WebKit::RemoteNetworkingContext::ensureWebsiteDataStoreSession):
     16        * UIProcess/API/APIHTTPCookieStore.cpp:
     17        (API::HTTPCookieStore::cookies):
     18        (API::HTTPCookieStore::setCookie):
     19        (API::HTTPCookieStore::deleteCookie):
     20        * UIProcess/WebProcessPool.cpp:
     21        (WebKit::WebProcessPool::ensureNetworkProcess):
     22        (WebKit::WebProcessPool::pageBeginUsingWebsiteDataStore):
     23        * UIProcess/WebsiteData/WebsiteDataStore.cpp:
     24        (WebKit::WebsiteDataStore::clearPendingCookies):
     25        * UIProcess/WebsiteData/WebsiteDataStore.h:
     26
    1272018-05-16  Chris Nardi  <cnardi@chromium.org>
    228
  • trunk/Source/WebKit/NetworkProcess/mac/RemoteNetworkingContext.mm

    r230280 r231850  
    3737#import <WebCore/NetworkStorageSession.h>
    3838#import <WebCore/ResourceError.h>
     39#import <pal/SessionID.h>
    3940#import <wtf/MainThread.h>
    4041
     
    4647{
    4748    auto sessionID = parameters.networkSessionParameters.sessionID;
    48     if (NetworkStorageSession::storageSession(sessionID))
     49    if (auto* session = NetworkStorageSession::storageSession(sessionID)) {
     50        ASSERT(parameters.pendingCookies.isEmpty() || sessionID == PAL::SessionID::defaultSessionID());
     51        for (const auto& cookie : parameters.pendingCookies)
     52            session->setCookie(cookie);
    4953        return;
     54    }
    5055
    5156    String base;
  • trunk/Source/WebKit/UIProcess/API/APIHTTPCookieStore.cpp

    r221834 r231850  
    5353}
    5454
    55 void HTTPCookieStore::cookies(Function<void (const Vector<WebCore::Cookie>&)>&& completionHandler)
     55void HTTPCookieStore::cookies(Function<void(const Vector<WebCore::Cookie>&)>&& completionHandler)
    5656{
    5757    auto* pool = m_owningDataStore->processPoolForCookieStorageOperations();
     
    6060        if (m_owningDataStore->sessionID() == PAL::SessionID::defaultSessionID())
    6161            allCookies = WebCore::NetworkStorageSession::defaultStorageSession().getAllCookies();
    62         else
    63             allCookies = m_owningDataStore->pendingCookies();
     62        allCookies.appendVector(m_owningDataStore->pendingCookies());
    6463
    6564        callOnMainThread([completionHandler = WTFMove(completionHandler), allCookies]() {
     
    7978    auto* pool = m_owningDataStore->processPoolForCookieStorageOperations();
    8079    if (!pool) {
    81         if (m_owningDataStore->sessionID() == PAL::SessionID::defaultSessionID())
     80        // FIXME: pendingCookies used for defaultSession because session cookies cannot be propagated to Network Process with uiProcessCookieStorageIdentifier.
     81        if (m_owningDataStore->sessionID() == PAL::SessionID::defaultSessionID() && !cookie.session)
    8282            WebCore::NetworkStorageSession::defaultStorageSession().setCookie(cookie);
    8383        else
     
    100100    auto* pool = m_owningDataStore->processPoolForCookieStorageOperations();
    101101    if (!pool) {
    102         if (m_owningDataStore->sessionID() == PAL::SessionID::defaultSessionID())
     102        if (m_owningDataStore->sessionID() == PAL::SessionID::defaultSessionID() && !cookie.session)
    103103            WebCore::NetworkStorageSession::defaultStorageSession().deleteCookie(cookie);
    104104        else
    105105            m_owningDataStore->removePendingCookie(cookie);
     106
    106107        callOnMainThread([completionHandler = WTFMove(completionHandler)]() {
    107108            completionHandler();
  • trunk/Source/WebKit/UIProcess/WebProcessPool.cpp

    r231723 r231850  
    430430{
    431431    if (m_networkProcess) {
    432         if (withWebsiteDataStore)
     432        if (withWebsiteDataStore) {
    433433            m_networkProcess->send(Messages::NetworkProcess::AddWebsiteDataStore(withWebsiteDataStore->parameters()), 0);
     434            withWebsiteDataStore->clearPendingCookies();
     435        }
    434436        return *m_networkProcess;
    435437    }
     
    524526    }
    525527
    526     if (withWebsiteDataStore)
     528    if (m_websiteDataStore) {
     529        m_networkProcess->send(Messages::NetworkProcess::AddWebsiteDataStore(m_websiteDataStore->websiteDataStore().parameters()), 0);
     530        m_websiteDataStore->websiteDataStore().clearPendingCookies();
     531    }
     532   
     533    if (withWebsiteDataStore) {
    527534        m_networkProcess->send(Messages::NetworkProcess::AddWebsiteDataStore(withWebsiteDataStore->parameters()), 0);
     535        withWebsiteDataStore->clearPendingCookies();
     536    }
    528537
    529538    return *m_networkProcess;
     
    11691178        sendToNetworkingProcess(Messages::NetworkProcess::AddWebsiteDataStore(page.websiteDataStore().parameters()));
    11701179        page.process().send(Messages::WebProcess::AddWebsiteDataStore(WebsiteDataStoreParameters::privateSessionParameters(sessionID)), 0);
     1180        page.websiteDataStore().clearPendingCookies();
    11711181    } else if (sessionID != PAL::SessionID::defaultSessionID()) {
    11721182        sendToNetworkingProcess(Messages::NetworkProcess::AddWebsiteDataStore(page.websiteDataStore().parameters()));
    11731183        page.process().send(Messages::WebProcess::AddWebsiteDataStore(page.websiteDataStore().parameters()), 0);
     1184        page.websiteDataStore().clearPendingCookies();
    11741185
    11751186#if ENABLE(INDEXED_DATABASE)
  • trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.cpp

    r231501 r231850  
    15241524    m_pendingCookies.remove(cookie);
    15251525}
     1526   
     1527void WebsiteDataStore::clearPendingCookies()
     1528{
     1529    m_pendingCookies.clear();
     1530}
    15261531
    15271532#if !PLATFORM(COCOA)
  • trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.h

    r231501 r231850  
    161161    void addPendingCookie(const WebCore::Cookie&);
    162162    void removePendingCookie(const WebCore::Cookie&);
     163    void clearPendingCookies();
    163164
    164165    void enableResourceLoadStatisticsAndSetTestingCallback(Function<void (const String&)>&& callback);
  • trunk/Tools/ChangeLog

    r231848 r231850  
     12018-05-16  Sihui Liu  <sihui_liu@apple.com>
     2
     3        Session cookies aren't reliably set when using default WKWebSiteDataStore
     4        https://bugs.webkit.org/show_bug.cgi?id=185624
     5        <rdar://problem/39111626>
     6
     7        Reviewed by Geoffrey Garen.
     8
     9        Modified and enabled WebKit.WKHTTPCookieStoreWithoutProcessPool.
     10
     11        * TestWebKitAPI/Tests/WebKitCocoa/WKHTTPCookieStore.mm:
     12        (-[CookieUIDelegate webView:runJavaScriptAlertPanelWithMessage:initiatedByFrame:completionHandler:]):
     13        (TEST):
     14
    1152018-05-16  Valerie R Young  <valerie@bocoup.com>
    216
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKHTTPCookieStore.mm

    r231495 r231850  
    377377- (void)webView:(WKWebView *)webView runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(void))completionHandler
    378378{
    379     EXPECT_STREQ("cookie:cookiename=cookievalue", message.UTF8String);
     379    EXPECT_STREQ("cookie:PersistentCookieName=CookieValue; SessionCookieName=CookieValue", message.UTF8String);
    380380    finished = true;
    381381    completionHandler();
     
    383383@end
    384384
    385 // FIXME: This should be removed once <rdar://problem/35344202> is resolved and bots are updated.
    386 #if (PLATFORM(MAC) && __MAC_OS_X_VERSION_MAX_ALLOWED <= 101301) || (PLATFORM(IOS) && __IPHONE_OS_VERSION_MAX_ALLOWED <= 110102)
    387385TEST(WebKit, WKHTTPCookieStoreWithoutProcessPool)
    388386{
    389     NSHTTPCookie *cookie = [NSHTTPCookie cookieWithProperties:[NSDictionary dictionaryWithObjectsAndKeys:@"127.0.0.1", NSHTTPCookieDomain, @"/", NSHTTPCookiePath, @"cookiename", NSHTTPCookieName, @"cookievalue", NSHTTPCookieValue, [NSDate distantFuture], NSHTTPCookieExpires, nil]];
     387    RetainPtr<NSHTTPCookie> sessionCookie = [NSHTTPCookie cookieWithProperties:@{
     388        NSHTTPCookiePath: @"/",
     389        NSHTTPCookieName: @"SessionCookieName",
     390        NSHTTPCookieValue: @"CookieValue",
     391        NSHTTPCookieDomain: @"127.0.0.1",
     392    }];
     393    RetainPtr<NSHTTPCookie> persistentCookie = [NSHTTPCookie cookieWithProperties:@{
     394        NSHTTPCookiePath: @"/",
     395        NSHTTPCookieName: @"PersistentCookieName",
     396        NSHTTPCookieValue: @"CookieValue",
     397        NSHTTPCookieDomain: @"127.0.0.1",
     398        NSHTTPCookieExpires: [NSDate distantFuture],
     399    }];
    390400    NSString *alertCookieHTML = @"<script>alert('cookie:'+document.cookie);</script>";
    391    
    392     finished = false;
    393     WKWebsiteDataStore *ephemeralStoreWithCookies = [WKWebsiteDataStore nonPersistentDataStore];
    394     [ephemeralStoreWithCookies.httpCookieStore setCookie:cookie completionHandler:^ {
     401
     402    // NonPersistentDataStore
     403    RetainPtr<WKWebsiteDataStore> ephemeralStoreWithCookies = [WKWebsiteDataStore nonPersistentDataStore];
     404
     405    finished = false;
     406    [ephemeralStoreWithCookies.get().httpCookieStore setCookie:persistentCookie.get() completionHandler:^{
    395407        WKWebsiteDataStore *ephemeralStoreWithIndependentCookieStorage = [WKWebsiteDataStore nonPersistentDataStore];
    396408        [ephemeralStoreWithIndependentCookieStorage.httpCookieStore getAllCookies:^(NSArray<NSHTTPCookie *> *cookies) {
    397             ASSERT_EQ(cookies.count, 0u);
    398            
    399             WKWebViewConfiguration *configuration = [[WKWebViewConfiguration alloc] init];
    400             configuration.websiteDataStore = ephemeralStoreWithCookies;
    401             WKWebView *view = [[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration];
    402             view.UIDelegate = [[CookieUIDelegate alloc] init];
    403 
    404             [view loadHTMLString:alertCookieHTML baseURL:[NSURL URLWithString:@"http://127.0.0.1/"]];
    405         }];
    406     }];
    407     TestWebKitAPI::Util::run(&finished);
    408    
    409     // FIXME: Get this to work on iOS. <rdar://problem/32260156>
    410 #if !PLATFORM(IOS)
    411     finished = false;
    412     WKWebsiteDataStore *defaultStore = [WKWebsiteDataStore defaultDataStore];
    413     [defaultStore.httpCookieStore setCookie:cookie completionHandler:^ {
    414         [defaultStore.httpCookieStore getAllCookies:^(NSArray<NSHTTPCookie *> *cookies) {
    415             ASSERT_EQ(cookies.count, 1u);
    416            
    417             WKWebViewConfiguration *configuration = [[WKWebViewConfiguration alloc] init];
    418             configuration.websiteDataStore = defaultStore;
    419             WKWebView *view = [[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration];
    420             view.UIDelegate = [[CookieUIDelegate alloc] init];
    421            
    422             [view loadHTMLString:alertCookieHTML baseURL:[NSURL URLWithString:@"http://127.0.0.1/"]];
    423         }];
    424     }];
    425     TestWebKitAPI::Util::run(&finished);
    426    
    427     [defaultStore.httpCookieStore deleteCookie:cookie completionHandler:^ {
    428         [defaultStore.httpCookieStore getAllCookies:^(NSArray<NSHTTPCookie *> *cookies) {
    429             ASSERT_EQ(cookies.count, 0u);
     409            ASSERT_EQ(0u, cookies.count);
    430410            finished = true;
    431411        }];
    432412    }];
    433413    TestWebKitAPI::Util::run(&finished);
     414
     415    finished = false;
     416    [ephemeralStoreWithCookies.get().httpCookieStore setCookie:sessionCookie.get() completionHandler:^{
     417        [ephemeralStoreWithCookies.get().httpCookieStore getAllCookies:^(NSArray<NSHTTPCookie *> *cookies) {
     418            ASSERT_EQ(2u, cookies.count);
     419            finished = true;
     420        }];
     421    }];
     422    TestWebKitAPI::Util::run(&finished);
     423
     424    finished = false;
     425    auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
     426    configuration.get().websiteDataStore = ephemeralStoreWithCookies.get();
     427    auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
     428    auto delegate = adoptNS([[CookieUIDelegate alloc] init]);
     429    webView.get().UIDelegate = delegate.get();
     430    [webView loadHTMLString:alertCookieHTML baseURL:[NSURL URLWithString:@"http://127.0.0.1"]];
     431    TestWebKitAPI::Util::run(&finished);
     432
     433    finished = false;
     434    [ephemeralStoreWithCookies.get().httpCookieStore deleteCookie:sessionCookie.get() completionHandler:^{
     435        [ephemeralStoreWithCookies.get().httpCookieStore getAllCookies:^(NSArray<NSHTTPCookie *> *cookies) {
     436            ASSERT_EQ(1u, cookies.count);
     437            finished = true;
     438        }];
     439    }];
     440    TestWebKitAPI::Util::run(&finished);
     441   
     442    // DefaultDataStore
     443    auto defaultStore = [WKWebsiteDataStore defaultDataStore];
     444    finished = false;
     445    [defaultStore removeDataOfTypes:[WKWebsiteDataStore allWebsiteDataTypes] modifiedSince:[NSDate distantPast] completionHandler:[] {
     446        finished = true;
     447    }];
     448    TestWebKitAPI::Util::run(&finished);
     449
     450    finished = false;
     451    [defaultStore.httpCookieStore setCookie:persistentCookie.get() completionHandler:^{
     452        [defaultStore.httpCookieStore getAllCookies:^(NSArray<NSHTTPCookie *> *cookies) {
     453            ASSERT_EQ(1u, cookies.count);
     454            finished = true;
     455        }];
     456    }];
     457    TestWebKitAPI::Util::run(&finished);
     458
     459    finished = false;
     460    [defaultStore.httpCookieStore setCookie:sessionCookie.get() completionHandler:^{
     461        [defaultStore.httpCookieStore getAllCookies:^(NSArray<NSHTTPCookie *> *cookies) {
     462            ASSERT_EQ(2u, cookies.count);
     463            finished = true;
     464        }];
     465    }];
     466    TestWebKitAPI::Util::run(&finished);
     467
     468    finished = false;
     469    configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
     470    configuration.get().websiteDataStore = defaultStore;
     471    webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
     472    webView.get().UIDelegate = delegate.get();
     473    [webView loadHTMLString:alertCookieHTML baseURL:[NSURL URLWithString:@"http://127.0.0.1"]];
     474    TestWebKitAPI::Util::run(&finished);
     475}
    434476#endif
    435 }
    436 #endif // (PLATFORM(MAC) && __MAC_OS_X_VERSION_MAX_ALLOWED <= 101301) || (PLATFORM(IOS) && __IPHONE_OS_VERSION_MAX_ALLOWED <= 110102)
    437 #endif
Note: See TracChangeset for help on using the changeset viewer.