Bug 207593

Summary: [WK2][Cocoa] Implement in-WebProcess cookie cache to avoid sync IPC for document.cookie in most cases
Product: WebKit Reporter: Chris Dumez <cdumez>
Component: WebKit2Assignee: Chris Dumez <cdumez>
Status: RESOLVED FIXED    
Severity: Normal CC: achristensen, beidson, benjamin, cmarcelo, commit-queue, dbates, esprehn+autocc, ews-watchlist, ggaren, japhet, kangil.han, koivisto, tsavell, webkit-bug-importer, youennf
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
See Also: https://bugs.webkit.org/show_bug.cgi?id=208165
Attachments:
Description Flags
WIP Patch
none
WIP Patch
none
WIP Patch
none
WIP Patch
none
WIP Patch
none
WIP Patch
none
WIP Patch
none
WIP Patch
none
Patch
none
Patch
none
Patch
none
Patch
none
Patch
none
Patch
none
Patch
none
Patch
none
Patch none

Description Chris Dumez 2020-02-11 15:46:06 PST
Implement in-WebProcess cookie cache to avoid sync IPC for document.cookie in most cases.
Comment 1 Chris Dumez 2020-02-11 15:46:22 PST
<rdar://problem/56027027>
Comment 2 Chris Dumez 2020-02-11 15:48:55 PST
Created attachment 390450 [details]
WIP Patch
Comment 3 Chris Dumez 2020-02-11 16:37:04 PST
Created attachment 390462 [details]
WIP Patch
Comment 4 Chris Dumez 2020-02-12 10:24:03 PST
Created attachment 390533 [details]
WIP Patch
Comment 5 Chris Dumez 2020-02-12 10:46:34 PST
Created attachment 390536 [details]
WIP Patch
Comment 6 Chris Dumez 2020-02-12 10:58:11 PST
Created attachment 390539 [details]
WIP Patch
Comment 7 Chris Dumez 2020-02-12 13:02:08 PST
Created attachment 390549 [details]
WIP Patch

Now passing layout tests locally.
Comment 8 Chris Dumez 2020-02-12 14:30:50 PST
Created attachment 390561 [details]
WIP Patch
Comment 9 Chris Dumez 2020-02-12 15:02:49 PST
Created attachment 390567 [details]
WIP Patch

With more layout tests.
Comment 10 Chris Dumez 2020-02-12 16:00:08 PST
Created attachment 390575 [details]
Patch
Comment 11 Antti Koivisto 2020-02-13 12:44:36 PST
Comment on attachment 390575 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=390575&action=review

> Source/WTF/wtf/PlatformEnable.h:802
> +#if !defined(ENABLE_COOKIE_CACHE) && PLATFORM(COCOA) && HAVE(CFNETWORK_COOKIE_CHANGE_LISTENER_API)
> +#define ENABLE_COOKIE_CACHE 1
> +#endif

Couldn't this just be a runtime no-op without CFNETWORK_COOKIE_CHANGE_LISTENER_API and avoid most #ifs?

> Source/WebCore/platform/network/cocoa/NetworkStorageSessionCocoa.mm:617
> +    ASSERT(observers.add(&observer).isNewEntry);

Why is observer only added in debug build?

> Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.cpp:131
> +    if (!m_hostsWithCookieListeners.isEmpty()) {
> +        auto hostsWithCookieListeners = copyToVector(m_hostsWithCookieListeners);
> +        unsubscribeFromCookieChangeNotifications(hostsWithCookieListeners);
> +    }

I think it would be nicer to have a separate function or just loop over m_hostsWithCookieListeners here (avoiding the vector copy). It is just call to stopListeningForCookieChangeNotifications for each.

> Source/WebKit/WebProcess/WebPage/WebCookieCache.h:44
> +    bool isFunctional();

isEnabled/isSupported?
Comment 12 Chris Dumez 2020-02-13 12:47:58 PST
Comment on attachment 390575 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=390575&action=review

>> Source/WebCore/platform/network/cocoa/NetworkStorageSessionCocoa.mm:617
>> +    ASSERT(observers.add(&observer).isNewEntry);
> 
> Why is observer only added in debug build?

ouch, last minute clean up I made :/ Thanks for catching.
Comment 13 Antti Koivisto 2020-02-13 12:50:59 PST
> ouch, last minute clean up I made :/ Thanks for catching.

Observers don't seem to have much test coverage.
Comment 14 Chris Dumez 2020-02-13 13:07:21 PST
(In reply to Antti Koivisto from comment #13)
> > ouch, last minute clean up I made :/ Thanks for catching.
> 
> Observers don't seem to have much test coverage.

EWS does not have the CFNetwork SPI needed and thus does not cover my change. Actual layout test bots will run the tests with the cookie cache enabled (at least some of the bots will).
Comment 15 Chris Dumez 2020-02-13 14:33:35 PST
Created attachment 390687 [details]
Patch
Comment 16 Chris Dumez 2020-02-13 14:37:32 PST
Created attachment 390688 [details]
Patch
Comment 17 Chris Dumez 2020-02-13 15:00:29 PST
Created attachment 390691 [details]
Patch
Comment 18 Chris Dumez 2020-02-13 15:26:52 PST
Created attachment 390695 [details]
Patch
Comment 19 Chris Dumez 2020-02-17 09:57:04 PST
Created attachment 390925 [details]
Patch
Comment 20 Chris Dumez 2020-02-17 09:58:13 PST
Created attachment 390926 [details]
Patch
Comment 21 Chris Dumez 2020-02-17 14:53:38 PST
Created attachment 390988 [details]
Patch
Comment 22 Chris Dumez 2020-02-17 16:59:00 PST
Created attachment 391004 [details]
Patch
Comment 23 WebKit Commit Bot 2020-02-17 22:32:49 PST
Comment on attachment 391004 [details]
Patch

Clearing flags on attachment: 391004

Committed r256820: <https://trac.webkit.org/changeset/256820>
Comment 24 WebKit Commit Bot 2020-02-17 22:32:51 PST
All reviewed patches have been landed.  Closing bug.
Comment 25 Truitt Savell 2020-02-24 16:23:01 PST
The new test http/tests/cookies/document-cookie-after-showModalDialog.html

is a flaky failure. tracking in https://bugs.webkit.org/show_bug.cgi?id=208165