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

Changeset 246097 in webkit


Ignore:
Timestamp:
Jun 4, 2019, 10:00:23 PM (7 years ago)
Author:
Chris Dumez
Message:

Cookies set via [WKHTTPCookieStore setCookie:] on store right after constructing WKWebView get lost
https://bugs.webkit.org/show_bug.cgi?id=198553
<rdar://problem/51317144>

Reviewed by Geoffrey Garen.

Source/WebKit:

If you call [WKHTTPCookieStore setCookie:] right after you construct the WKWebView and before the
WebContent process has finished launching, then WebsiteDataStore::processPoolForCookieStorageOperations()
would return null, even though there is already a view/page/WebProcessProxy/WebProcessPool for this data
store. As a result, the cookie would get added to the WebsiteDataStore's m_pendingCookies but it will
not be used since we've already previously launched a network process when we constructed the web view.

The reason processPoolForCookieStorageOperations() would return null is because WebsiteDataStore::processPools()
relies on WebProcessLifetimeObserver::processes() but processes only register themselves with the
WebProcessLifetimeObservers when they have pages *and* after they are finished launching.

This patch updates processPoolForCookieStorageOperations() to fallback to iterating over all process pools
and find a process pool with a process using the current data store and which has pages. This way, even if
the process is still launching, we'll properly find its associated process pool.

  • UIProcess/WebsiteData/WebsiteDataStore.cpp:

(WebKit::WebsiteDataStore::processPoolForCookieStorageOperations):

Tools:

Add API test coverage.

  • TestWebKitAPI/Tests/WebKitCocoa/WKHTTPCookieStore.mm:

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

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r246095 r246097  
     12019-06-04  Chris Dumez  <cdumez@apple.com>
     2
     3        Cookies set via [WKHTTPCookieStore setCookie:] on store right after constructing WKWebView get lost
     4        https://bugs.webkit.org/show_bug.cgi?id=198553
     5        <rdar://problem/51317144>
     6
     7        Reviewed by Geoffrey Garen.
     8
     9        If you call [WKHTTPCookieStore setCookie:] right after you construct the WKWebView and before the
     10        WebContent process has finished launching, then WebsiteDataStore::processPoolForCookieStorageOperations()
     11        would return null, even though there is already a view/page/WebProcessProxy/WebProcessPool for this data
     12        store. As a result, the cookie would get added to the WebsiteDataStore's m_pendingCookies but it will
     13        not be used since we've already previously launched a network process when we constructed the web view.
     14
     15        The reason processPoolForCookieStorageOperations() would return null is because WebsiteDataStore::processPools()
     16        relies on WebProcessLifetimeObserver::processes() but processes only register themselves with the
     17        WebProcessLifetimeObservers when they have pages *and* after they are finished launching.
     18
     19        This patch updates processPoolForCookieStorageOperations() to fallback to iterating over all process pools
     20        and find a process pool with a process using the current data store and which has pages. This way, even if
     21        the process is still launching, we'll properly find its associated process pool.
     22
     23        * UIProcess/WebsiteData/WebsiteDataStore.cpp:
     24        (WebKit::WebsiteDataStore::processPoolForCookieStorageOperations):
     25
    1262019-06-04  Michael Catanzaro  <mcatanzaro@igalia.com>
    227
  • trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.cpp

    r245801 r246097  
    167167{
    168168    auto pools = processPools(1, false);
    169     return pools.isEmpty() ? nullptr : pools.begin()->get();
     169    if (!pools.isEmpty())
     170        return pools.begin()->get();
     171
     172    for (auto* processPool : WebProcessPool::allProcessPools()) {
     173        for (auto& process : processPool->processes()) {
     174            if (process->pageCount() && &process->websiteDataStore() == this)
     175                return processPool;
     176        }
     177    }
     178
     179    return nullptr;
    170180}
    171181
  • trunk/Tools/ChangeLog

    r246095 r246097  
     12019-06-04  Chris Dumez  <cdumez@apple.com>
     2
     3        Cookies set via [WKHTTPCookieStore setCookie:] on store right after constructing WKWebView get lost
     4        https://bugs.webkit.org/show_bug.cgi?id=198553
     5        <rdar://problem/51317144>
     6
     7        Reviewed by Geoffrey Garen.
     8
     9        Add API test coverage.
     10
     11        * TestWebKitAPI/Tests/WebKitCocoa/WKHTTPCookieStore.mm:
     12        (-[CheckSessionCookieUIDelegate webView:runJavaScriptAlertPanelWithMessage:initiatedByFrame:completionHandler:]):
     13        (TEST):
     14
    1152019-06-04  Michael Catanzaro  <mcatanzaro@igalia.com>
    216
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKHTTPCookieStore.mm

    r242339 r246097  
    587587
    588588#endif // PLATFORM(MAC)
     589
     590@interface CheckSessionCookieUIDelegate : NSObject <WKUIDelegate>
     591@end
     592
     593@implementation CheckSessionCookieUIDelegate
     594- (void)webView:(WKWebView *)webView runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(void))completionHandler
     595{
     596    EXPECT_STREQ("SessionCookieName=CookieValue", message.UTF8String);
     597    finished = true;
     598    completionHandler();
     599}
     600@end
     601
     602TEST(WebKit, WKHTTPCookieStoreWithoutProcessPoolEphemeralSession)
     603{
     604    RetainPtr<WKWebsiteDataStore> ephemeralStoreWithCookies = [WKWebsiteDataStore nonPersistentDataStore];
     605   
     606    auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
     607    configuration.get().websiteDataStore = ephemeralStoreWithCookies.get();
     608   
     609    auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
     610    auto delegate = adoptNS([[CheckSessionCookieUIDelegate alloc] init]);
     611    webView.get().UIDelegate = delegate.get();
     612   
     613    RetainPtr<NSHTTPCookie> sessionCookie = [NSHTTPCookie cookieWithProperties:@{
     614        NSHTTPCookiePath: @"/",
     615        NSHTTPCookieName: @"SessionCookieName",
     616        NSHTTPCookieValue: @"CookieValue",
     617        NSHTTPCookieDomain: @"127.0.0.1",
     618    }];
     619   
     620    [ephemeralStoreWithCookies.get().httpCookieStore setCookie:sessionCookie.get() completionHandler:^{
     621        finished = true;
     622    }];
     623    TestWebKitAPI::Util::run(&finished);
     624    finished = false;
     625   
     626    NSString *alertCookieHTML = @"<script>var cookies = document.cookie.split(';'); for (let i = 0; i < cookies.length; i ++) { cookies[i] = cookies[i].trim(); } cookies.sort(); alert(cookies.join('; '));</script>";
     627    [webView loadHTMLString:alertCookieHTML baseURL:[NSURL URLWithString:@"http://127.0.0.1"]];
     628    TestWebKitAPI::Util::run(&finished);
     629}
Note: See TracChangeset for help on using the changeset viewer.