If setting cookie using defaultDataStore before creating a WebView, the app would run into this assertion failure, because the privilege of UI process to access cookie API is not granted yet.
Created attachment 339463 [details] Patch
Comment on attachment 339463 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=339463&action=review > Source/WebKit/ChangeLog:3 > + Assertion failure in NetworkStorageSession::setCookie: privilege of UI process is not set What assertion? Could you please provide the crash trace on the bug? > Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataStore.mm:50 > + WTF::setProcessPrivileges(allPrivileges()); This should probably inside WebKit::WebSiteDataStore constructor so it works for C API clients as well, and other APIs that defaultDataStore.
(In reply to Chris Dumez from comment #2) > Comment on attachment 339463 [details] > Patch > > View in context: > https://bugs.webkit.org/attachment.cgi?id=339463&action=review > > > Source/WebKit/ChangeLog:3 > > + Assertion failure in NetworkStorageSession::setCookie: privilege of UI process is not set > > What assertion? Could you please provide the crash trace on the bug? > Crash trace: default 16:36:00.400052 -0700 WKCookieMonster ASSERTION FAILED: hasProcessPrivilege(ProcessPrivilege::CanAccessRawCookies) default 16:36:00.400101 -0700 WKCookieMonster platform/network/cocoa/NetworkStorageSessionCocoa.mm(40) : void WebCore::NetworkStorageSession::setCookie(const WebCore::Cookie &) default 16:36:00.406075 -0700 WKCookieMonster 1 0x115ffc259 WTFCrash default 16:36:00.423040 -0700 WKCookieMonster 2 0x106fcaa9e WebCore::NetworkStorageSession::setCookie(WebCore::Cookie const&) default 16:36:00.428838 -0700 WKCookieMonster 3 0x100399f55 API::HTTPCookieStore::setCookie(WebCore::Cookie const&, WTF::Function<void ()>&&) default 16:36:00.430665 -0700 WKCookieMonster 4 0x10135ea23 -[WKHTTPCookieStore setCookie:completionHandler:] default 16:36:00.430741 -0700 WKCookieMonster 5 0x100008260 _T015WKCookieMonster14ViewControllerC04loadC0yyF default 16:36:00.430766 -0700 WKCookieMonster 6 0x100009144 _T015WKCookieMonster14ViewControllerC04loadC0yyFTo default 16:36:00.430979 -0700 WKCookieMonster 7 0x7fff514ecb96 -[NSViewController _loadViewIfRequired] default 16:36:00.431139 -0700 WKCookieMonster 8 0x7fff514ecb01 -[NSViewController view] default 16:36:00.431268 -0700 WKCookieMonster 9 0x7fff5166b43d -[NSWindow _contentViewControllerChanged] default 16:36:00.431346 -0700 WKCookieMonster 10 0x7fff56025e8e -[NSObject(NSKeyValueCoding) setValue:forKey:] default 16:36:00.431473 -0700 WKCookieMonster 11 0x7fff516ae189 -[NSWindow setValue:forKey:] default 16:36:00.431601 -0700 WKCookieMonster 12 0x7fff516ae0ed -[NSIBUserDefinedRuntimeAttributesConnector establishConnection] default 16:36:00.431722 -0700 WKCookieMonster 13 0x7fff5147a7e5 -[NSIBObjectData nibInstantiateWithOwner:options:topLevelObjects:] default 16:36:00.431846 -0700 WKCookieMonster 14 0x7fff51575e0e -[NSNib _instantiateNibWithExternalNameTable:options:] default 16:36:00.431970 -0700 WKCookieMonster 15 0x7fff51575a6a -[NSNib _instantiateWithOwner:options:topLevelObjects:] default 16:36:00.432128 -0700 WKCookieMonster 16 0x7fff51ccc4e8 -[NSStoryboard instantiateControllerWithIdentifier:] default 16:36:00.432247 -0700 WKCookieMonster 17 0x7fff5146eaf3 NSApplicationMain default 16:36:00.432288 -0700 WKCookieMonster 18 0x10000e41d main default 16:36:00.432314 -0700 WKCookieMonster 19 0x7fff7c39f015 start --------------- In loadView(): let cookieStore = WKWebsiteDataStore.default().httpCookieStore cookieStore.setCookie(cookie) {...}
Created attachment 339490 [details] Patch
Comment on attachment 339490 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=339490&action=review > Source/WebKit/UIProcess/API/APIWebsiteDataStore.cpp:70 > + WTF::setProcessPrivileges(allPrivileges()); I said WebKit::WebsiteDataStore not the API one :) the existing call in in ProcessPool, not its API object.
Created attachment 339511 [details] Patch
Comment on attachment 339511 [details] Patch Clearing flags on attachment: 339511 Committed r231356: <https://trac.webkit.org/changeset/231356>
All reviewed patches have been landed. Closing bug.
<rdar://problem/39979381>
It should be possible to test this with an API test that sets a cookie before creating a WebView. Subtle cases like this are extra valuable to test.
(In reply to Geoffrey Garen from comment #10) > It should be possible to test this with an API test that sets a cookie > before creating a WebView. Subtle cases like this are extra valuable to test. Yes, a reason we bypassed this case with API test is that process privileges were granted to TestController in initialization. I added an API test for this case: https://bugs.webkit.org/show_bug.cgi?id=185406.