Source/WebCore:
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 30 Jul 2018 19:37:42 +0000 (19:37 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 30 Jul 2018 19:37:42 +0000 (19:37 +0000)
Merge PlatformCookieJar functions into NetworkStorageSession
https://bugs.webkit.org/show_bug.cgi?id=188137

Patch by Rob Buis <rbuis@igalia.com> on 2018-07-30
Reviewed by Alex Christensen.

No new tests -- no change in WebKit functionality.

* PlatformMac.cmake: Remove CookieJarMac.mm reference
* SourcesCocoa.txt: Remove CookieJarMac.mm reference
* WebCore.xcodeproj/project.pbxproj:
* loader/CookieJar.cpp: Remove PlatformCookieJar.h reference.
* platform/Curl.cmake: Remove CookieJarCurl.cpp reference.
* platform/SourcesSoup.txt: Remove CookieJarSoup.cpp reference.
* platform/network/CacheValidation.cpp: Adapt callsites to use
NetworkStorageSession instead of CookieJar functions.

(WebCore::headerValueForVary):
* platform/network/NetworkStorageSession.h: Add PlatformCookieJar
functions.

* platform/network/PlatformCookieJar.h: Removed.
* platform/network/SocketStreamHandleImpl.cpp: Adapt callsites to
use NetworkStorageSession instead of CookieJar functions.
(WebCore::cookieDataForHandshake):
* platform/network/cf/CookieJarCFNet.cpp: Removed.
* platform/network/cf/NetworkStorageSessionCFNet.cpp: Move functions
from CookieJarCFNet.cpp.
(WebCore::cookieDomain):
(WebCore::canonicalCookieTime):
(WebCore::cookieCreatedTime):
(WebCore::cookieExpirationTime):
(WebCore::cookieName):
(WebCore::cookiePath):
(WebCore::cookieValue):
(WebCore::filterCookies):
(WebCore::copyCookiesForURLWithFirstPartyURL):
(WebCore::createCookies):
(WebCore::NetworkStorageSession::setCookiesFromDOM const):
(WebCore::containsSecureCookies):
(WebCore::NetworkStorageSession::cookiesForDOM const):
(WebCore::NetworkStorageSession::cookieRequestHeaderFieldValue const):
(WebCore::NetworkStorageSession::cookiesEnabled const):
(WebCore::NetworkStorageSession::getRawCookies const):
(WebCore::NetworkStorageSession::deleteCookie const):
(WebCore::NetworkStorageSession::getHostnamesWithCookies):
(WebCore::NetworkStorageSession::deleteAllCookies):
(WebCore::NetworkStorageSession::deleteCookiesForHostnames):
(WebCore::NetworkStorageSession::deleteAllCookiesModifiedSince):
* platform/network/cocoa/NetworkStorageSessionCocoa.mm: Move functions
from CookieJarMac.mm.
(WebCore::httpCookies):
(WebCore::deleteHTTPCookie):
(WebCore::policyProperties):
(WebCore::cookiesForURL):
(WebCore::setHTTPCookiesForURL):
(WebCore::httpCookiesForURL):
(WebCore::filterCookies):
(WebCore::applyPartitionToCookies):
(WebCore::cookiesAreBlockedForURL):
(WebCore::cookiesInPartitionForURL):
(WebCore::cookiesForSession):
(WebCore::deleteAllHTTPCookies):
(WebCore::NetworkStorageSession::cookiesForDOM const):
(WebCore::NetworkStorageSession::cookieRequestHeaderFieldValue const):
(WebCore::NetworkStorageSession::setCookiesFromDOM const):
(WebCore::httpCookieAcceptPolicy):
(WebCore::NetworkStorageSession::cookiesEnabled const):
(WebCore::NetworkStorageSession::getRawCookies const):
(WebCore::NetworkStorageSession::deleteCookie const):
(WebCore::NetworkStorageSession::getHostnamesWithCookies):
(WebCore::NetworkStorageSession::deleteAllCookies):
(WebCore::NetworkStorageSession::deleteCookiesForHostnames):
(WebCore::NetworkStorageSession::deleteAllCookiesModifiedSince):
* platform/network/curl/CookieJarCurl.cpp: Removed.
* platform/network/curl/CookieJarCurl.h:
* platform/network/curl/NetworkStorageSessionCurl.cpp: Merge functions
from CookieJarCurl.cpp.
(WebCore::NetworkStorageSession::setCookiesFromDOM const):
(WebCore::NetworkStorageSession::cookiesEnabled const):
(WebCore::NetworkStorageSession::cookiesForDOM const):
(WebCore::NetworkStorageSession::deleteCookie const):
(WebCore::NetworkStorageSession::deleteAllCookies):
(WebCore::NetworkStorageSession::deleteAllCookiesModifiedSince):
(WebCore::NetworkStorageSession::deleteCookiesForHostnames):
(WebCore::NetworkStorageSession::getHostnamesWithCookies):
(WebCore::NetworkStorageSession::getRawCookies const):
(WebCore::NetworkStorageSession::cookieRequestHeaderFieldValue const):
* platform/network/mac/CookieJarMac.mm: Removed.
* platform/network/mac/WebCoreResourceHandleAsOperationQueueDelegate.mm:
* platform/network/soup/CookieJarSoup.cpp: Removed.
* platform/network/soup/NetworkStorageSessionSoup.cpp: Merge functions
from CookieJarSoup.cpp.
(WebCore::NetworkStorageSession::cookiesEnabled const):
(WebCore::httpOnlyCookieExists):
(WebCore::NetworkStorageSession::setCookiesFromDOM const):
(WebCore::NetworkStorageSession::deleteCookie const):
(WebCore::NetworkStorageSession::deleteAllCookies):
(WebCore::NetworkStorageSession::deleteAllCookiesModifiedSince):
(WebCore::NetworkStorageSession::deleteCookiesForHostnames):
(WebCore::NetworkStorageSession::getHostnamesWithCookies):
(WebCore::NetworkStorageSession::getRawCookies const):
(WebCore::cookiesForSession):
(WebCore::NetworkStorageSession::cookiesForDOM const):
(WebCore::NetworkStorageSession::cookieRequestHeaderFieldValue const):

Source/WebKit:
https://bugs.webkit.org/show_bug.cgi?id=188137
Merge PlatformCookieJar functions into NetworkStorageSession

Adapt callsites to use NetworkStorageSession instead of CookieJar functions.

Patch by Rob Buis <rbuis@igalia.com> on 2018-07-30
Reviewed by Alex Christensen.

* NetworkProcess/Cookies/WebCookieManager.cpp:
(WebKit::WebCookieManager::getHostnamesWithCookies):
(WebKit::WebCookieManager::deleteCookiesForHostname):
(WebKit::WebCookieManager::deleteAllCookies):
(WebKit::WebCookieManager::deleteAllCookiesModifiedSince):
* NetworkProcess/NetworkConnectionToWebProcess.cpp:
(WebKit::NetworkConnectionToWebProcess::cookiesForDOM):
(WebKit::NetworkConnectionToWebProcess::setCookiesFromDOM):
(WebKit::NetworkConnectionToWebProcess::cookiesEnabled):
(WebKit::NetworkConnectionToWebProcess::cookieRequestHeaderFieldValue):
(WebKit::NetworkConnectionToWebProcess::getRawCookies):
(WebKit::NetworkConnectionToWebProcess::deleteCookie):
* NetworkProcess/NetworkProcess.cpp:
(WebKit::NetworkProcess::fetchWebsiteData):
(WebKit::NetworkProcess::deleteWebsiteData):
(WebKit::NetworkProcess::deleteWebsiteDataForOrigins):
* NetworkProcess/NetworkResourceLoader.cpp:
(WebKit::logCookieInformationInternal):
* NetworkProcess/cache/NetworkCache.cpp:
* WebProcess/WebCoreSupport/WebPlatformStrategies.cpp:

Source/WebKitLegacy/mac:
Merge PlatformCookieJar functions into NetworkStorageSession
https://bugs.webkit.org/show_bug.cgi?id=188137

Adapt callsites to use NetworkStorageSession instead of CookieJar functions.

Patch by Rob Buis <rbuis@igalia.com> on 2018-07-30
Reviewed by Alex Christensen.

* WebCoreSupport/WebPlatformStrategies.mm:
(WebPlatformStrategies::cookiesForDOM):
(WebPlatformStrategies::setCookiesFromDOM):
(WebPlatformStrategies::cookiesEnabled):
(WebPlatformStrategies::cookieRequestHeaderFieldValue):
(WebPlatformStrategies::getRawCookies):
(WebPlatformStrategies::deleteCookie):
* WebView/WebPreferences.mm:
(+[WebPreferences _clearNetworkLoaderSession]):

Source/WebKitLegacy/win:
https://bugs.webkit.org/show_bug.cgi?id=188137
Merge PlatformCookieJar functions into NetworkStorageSession

Adapt callsites to use NetworkStorageSession instead of CookieJar functions.

Patch by Rob Buis <rbuis@igalia.com> on 2018-07-30
Reviewed by Alex Christensen.

* WebCoreSupport/WebPlatformStrategies.cpp:
(WebPlatformStrategies::cookiesForDOM):
(WebPlatformStrategies::setCookiesFromDOM):
(WebPlatformStrategies::cookiesEnabled):
(WebPlatformStrategies::cookieRequestHeaderFieldValue):
(WebPlatformStrategies::getRawCookies):
(WebPlatformStrategies::deleteCookie):
* WebPreferences.cpp:
(WebPreferences::clearNetworkLoaderSession):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@234376 268f45cc-cd09-0410-ab3c-d52691b4dbfc

35 files changed:
Source/WebCore/ChangeLog
Source/WebCore/PlatformAppleWin.cmake
Source/WebCore/PlatformMac.cmake
Source/WebCore/SourcesCocoa.txt
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/loader/CookieJar.cpp
Source/WebCore/platform/Curl.cmake
Source/WebCore/platform/SourcesSoup.txt
Source/WebCore/platform/network/CacheValidation.cpp
Source/WebCore/platform/network/NetworkStorageSession.h
Source/WebCore/platform/network/PlatformCookieJar.h [deleted file]
Source/WebCore/platform/network/SocketStreamHandleImpl.cpp
Source/WebCore/platform/network/cf/CookieJarCFNet.cpp [deleted file]
Source/WebCore/platform/network/cf/NetworkStorageSessionCFNet.cpp
Source/WebCore/platform/network/cocoa/NetworkStorageSessionCocoa.mm
Source/WebCore/platform/network/curl/CookieJarCurl.cpp [deleted file]
Source/WebCore/platform/network/curl/CookieJarCurl.h
Source/WebCore/platform/network/curl/NetworkStorageSessionCurl.cpp
Source/WebCore/platform/network/mac/CookieJarMac.mm [deleted file]
Source/WebCore/platform/network/mac/WebCoreResourceHandleAsOperationQueueDelegate.mm
Source/WebCore/platform/network/soup/CookieJarSoup.cpp [deleted file]
Source/WebCore/platform/network/soup/NetworkStorageSessionSoup.cpp
Source/WebKit/ChangeLog
Source/WebKit/NetworkProcess/Cookies/WebCookieManager.cpp
Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.cpp
Source/WebKit/NetworkProcess/NetworkProcess.cpp
Source/WebKit/NetworkProcess/NetworkResourceLoader.cpp
Source/WebKit/NetworkProcess/cache/NetworkCache.cpp
Source/WebKit/WebProcess/WebCoreSupport/WebPlatformStrategies.cpp
Source/WebKitLegacy/mac/ChangeLog
Source/WebKitLegacy/mac/WebCoreSupport/WebPlatformStrategies.mm
Source/WebKitLegacy/mac/WebView/WebPreferences.mm
Source/WebKitLegacy/win/ChangeLog
Source/WebKitLegacy/win/WebCoreSupport/WebPlatformStrategies.cpp
Source/WebKitLegacy/win/WebPreferences.cpp

index 59e07b4..cfaf42b 100644 (file)
@@ -1,3 +1,110 @@
+2018-07-30  Rob Buis  <rbuis@igalia.com>
+
+        Merge PlatformCookieJar functions into NetworkStorageSession
+        https://bugs.webkit.org/show_bug.cgi?id=188137
+
+        Reviewed by Alex Christensen.
+
+        No new tests -- no change in WebKit functionality.
+
+        * PlatformMac.cmake: Remove CookieJarMac.mm reference
+        * SourcesCocoa.txt: Remove CookieJarMac.mm reference
+        * WebCore.xcodeproj/project.pbxproj:
+        * loader/CookieJar.cpp: Remove PlatformCookieJar.h reference.
+        * platform/Curl.cmake: Remove CookieJarCurl.cpp reference.
+        * platform/SourcesSoup.txt: Remove CookieJarSoup.cpp reference.
+        * platform/network/CacheValidation.cpp: Adapt callsites to use
+        NetworkStorageSession instead of CookieJar functions.
+
+        (WebCore::headerValueForVary):
+        * platform/network/NetworkStorageSession.h: Add PlatformCookieJar
+        functions.
+
+        * platform/network/PlatformCookieJar.h: Removed.
+        * platform/network/SocketStreamHandleImpl.cpp: Adapt callsites to
+        use NetworkStorageSession instead of CookieJar functions.
+        (WebCore::cookieDataForHandshake):
+        * platform/network/cf/CookieJarCFNet.cpp: Removed.
+        * platform/network/cf/NetworkStorageSessionCFNet.cpp: Move functions
+        from CookieJarCFNet.cpp.
+        (WebCore::cookieDomain):
+        (WebCore::canonicalCookieTime):
+        (WebCore::cookieCreatedTime):
+        (WebCore::cookieExpirationTime):
+        (WebCore::cookieName):
+        (WebCore::cookiePath):
+        (WebCore::cookieValue):
+        (WebCore::filterCookies):
+        (WebCore::copyCookiesForURLWithFirstPartyURL):
+        (WebCore::createCookies):
+        (WebCore::NetworkStorageSession::setCookiesFromDOM const):
+        (WebCore::containsSecureCookies):
+        (WebCore::NetworkStorageSession::cookiesForDOM const):
+        (WebCore::NetworkStorageSession::cookieRequestHeaderFieldValue const):
+        (WebCore::NetworkStorageSession::cookiesEnabled const):
+        (WebCore::NetworkStorageSession::getRawCookies const):
+        (WebCore::NetworkStorageSession::deleteCookie const):
+        (WebCore::NetworkStorageSession::getHostnamesWithCookies):
+        (WebCore::NetworkStorageSession::deleteAllCookies):
+        (WebCore::NetworkStorageSession::deleteCookiesForHostnames):
+        (WebCore::NetworkStorageSession::deleteAllCookiesModifiedSince):
+        * platform/network/cocoa/NetworkStorageSessionCocoa.mm: Move functions
+        from CookieJarMac.mm.
+        (WebCore::httpCookies):
+        (WebCore::deleteHTTPCookie):
+        (WebCore::policyProperties):
+        (WebCore::cookiesForURL):
+        (WebCore::setHTTPCookiesForURL):
+        (WebCore::httpCookiesForURL):
+        (WebCore::filterCookies):
+        (WebCore::applyPartitionToCookies):
+        (WebCore::cookiesAreBlockedForURL):
+        (WebCore::cookiesInPartitionForURL):
+        (WebCore::cookiesForSession):
+        (WebCore::deleteAllHTTPCookies):
+        (WebCore::NetworkStorageSession::cookiesForDOM const):
+        (WebCore::NetworkStorageSession::cookieRequestHeaderFieldValue const):
+        (WebCore::NetworkStorageSession::setCookiesFromDOM const):
+        (WebCore::httpCookieAcceptPolicy):
+        (WebCore::NetworkStorageSession::cookiesEnabled const):
+        (WebCore::NetworkStorageSession::getRawCookies const):
+        (WebCore::NetworkStorageSession::deleteCookie const):
+        (WebCore::NetworkStorageSession::getHostnamesWithCookies):
+        (WebCore::NetworkStorageSession::deleteAllCookies):
+        (WebCore::NetworkStorageSession::deleteCookiesForHostnames):
+        (WebCore::NetworkStorageSession::deleteAllCookiesModifiedSince):
+        * platform/network/curl/CookieJarCurl.cpp: Removed.
+        * platform/network/curl/CookieJarCurl.h:
+        * platform/network/curl/NetworkStorageSessionCurl.cpp: Merge functions
+        from CookieJarCurl.cpp.
+        (WebCore::NetworkStorageSession::setCookiesFromDOM const):
+        (WebCore::NetworkStorageSession::cookiesEnabled const):
+        (WebCore::NetworkStorageSession::cookiesForDOM const):
+        (WebCore::NetworkStorageSession::deleteCookie const):
+        (WebCore::NetworkStorageSession::deleteAllCookies):
+        (WebCore::NetworkStorageSession::deleteAllCookiesModifiedSince):
+        (WebCore::NetworkStorageSession::deleteCookiesForHostnames):
+        (WebCore::NetworkStorageSession::getHostnamesWithCookies):
+        (WebCore::NetworkStorageSession::getRawCookies const):
+        (WebCore::NetworkStorageSession::cookieRequestHeaderFieldValue const):
+        * platform/network/mac/CookieJarMac.mm: Removed.
+        * platform/network/mac/WebCoreResourceHandleAsOperationQueueDelegate.mm:
+        * platform/network/soup/CookieJarSoup.cpp: Removed.
+        * platform/network/soup/NetworkStorageSessionSoup.cpp: Merge functions
+        from CookieJarSoup.cpp.
+        (WebCore::NetworkStorageSession::cookiesEnabled const):
+        (WebCore::httpOnlyCookieExists):
+        (WebCore::NetworkStorageSession::setCookiesFromDOM const):
+        (WebCore::NetworkStorageSession::deleteCookie const):
+        (WebCore::NetworkStorageSession::deleteAllCookies):
+        (WebCore::NetworkStorageSession::deleteAllCookiesModifiedSince):
+        (WebCore::NetworkStorageSession::deleteCookiesForHostnames):
+        (WebCore::NetworkStorageSession::getHostnamesWithCookies):
+        (WebCore::NetworkStorageSession::getRawCookies const):
+        (WebCore::cookiesForSession):
+        (WebCore::NetworkStorageSession::cookiesForDOM const):
+        (WebCore::NetworkStorageSession::cookieRequestHeaderFieldValue const):
+
 2018-07-30  Chris Dumez  <cdumez@apple.com>
 
         Nullptr crash accessing Document in GenericEventQueue::dispatchOneEvent()
index 2c07f3a..b86029b 100644 (file)
@@ -47,7 +47,6 @@ list(APPEND WebCore_SOURCES
     platform/graphics/win/FontCustomPlatformData.cpp
 
     platform/network/cf/AuthenticationCF.cpp
-    platform/network/cf/CookieJarCFNet.cpp
     platform/network/cf/CookieStorageCFNet.cpp
     platform/network/cf/CredentialStorageCFNet.cpp
     platform/network/cf/DNSResolveQueueCFNet.cpp
index f3d8d02..5dfe74c 100644 (file)
@@ -434,7 +434,6 @@ list(APPEND WebCore_SOURCES
     platform/network/mac/AuthenticationMac.mm
     platform/network/mac/BlobDataFileReferenceMac.mm
     platform/network/mac/CertificateInfoMac.mm
-    platform/network/mac/CookieJarMac.mm
     platform/network/mac/CookieStorageMac.mm
     platform/network/mac/CredentialStorageMac.mm
     platform/network/mac/FormDataStreamMac.mm
index e352e53..ee9e8b0 100644 (file)
@@ -507,7 +507,6 @@ platform/network/ios/WebCoreURLResponseIOS.mm
 platform/network/mac/AuthenticationMac.mm
 platform/network/mac/BlobDataFileReferenceMac.mm
 platform/network/mac/CertificateInfoMac.mm
-platform/network/mac/CookieJarMac.mm
 platform/network/mac/CookieStorageMac.mm
 platform/network/mac/CredentialStorageMac.mm
 platform/network/mac/FormDataStreamMac.mm
index fc1fa1d..787dcfa 100644 (file)
                E134F5AB12EE343F004EC58D /* IntRectHash.h in Headers */ = {isa = PBXBuildFile; fileRef = E134F5AA12EE343F004EC58D /* IntRectHash.h */; settings = {ATTRIBUTES = (Private, ); }; };
                E139866415478474001E3F65 /* StyleResolver.h in Headers */ = {isa = PBXBuildFile; fileRef = E139866215478474001E3F65 /* StyleResolver.h */; };
                E13EF3441684ECF40034C83F /* NetworkStorageSession.h in Headers */ = {isa = PBXBuildFile; fileRef = E13EF3421684ECF40034C83F /* NetworkStorageSession.h */; settings = {ATTRIBUTES = (Private, ); }; };
-               E1424C8A164B3B4E00F32D40 /* PlatformCookieJar.h in Headers */ = {isa = PBXBuildFile; fileRef = E1424C89164B3B4E00F32D40 /* PlatformCookieJar.h */; settings = {ATTRIBUTES = (Private, ); }; };
                E1424C94164B52C800F32D40 /* CookieJar.h in Headers */ = {isa = PBXBuildFile; fileRef = E1424C92164B52C800F32D40 /* CookieJar.h */; settings = {ATTRIBUTES = (Private, ); }; };
                E14F1C4514B5DAC600EA9009 /* HTMLFormControlElementWithState.h in Headers */ = {isa = PBXBuildFile; fileRef = E14F1C4314B5DAC600EA9009 /* HTMLFormControlElementWithState.h */; settings = {ATTRIBUTES = (Private, ); }; };
                E152551516FD2350003D7ADB /* WebCoreResourceHandleAsOperationQueueDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = E152551316FD234F003D7ADB /* WebCoreResourceHandleAsOperationQueueDelegate.h */; };
                E13EF34716850C470034C83F /* NetworkStorageSessionCFNet.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NetworkStorageSessionCFNet.cpp; sourceTree = "<group>"; };
                E13F01EA1270E10D00DFBA71 /* CookieStorage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CookieStorage.h; sourceTree = "<group>"; };
                E13F01F01270E19000DFBA71 /* CookieStorageMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = CookieStorageMac.mm; sourceTree = "<group>"; };
-               E1424C89164B3B4E00F32D40 /* PlatformCookieJar.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PlatformCookieJar.h; sourceTree = "<group>"; };
-               E1424C8F164B460B00F32D40 /* CookieJarMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = CookieJarMac.mm; sourceTree = "<group>"; };
                E1424C91164B52C800F32D40 /* CookieJar.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CookieJar.cpp; sourceTree = "<group>"; };
                E1424C92164B52C800F32D40 /* CookieJar.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CookieJar.h; sourceTree = "<group>"; };
                E14A94D616DFDF950068DE82 /* BlobRegistry.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = BlobRegistry.cpp; sourceTree = "<group>"; };
                                CDCD41E61C3DDB0900965D99 /* ParsedContentRange.h */,
                                447958021643B47B001E0A7F /* ParsedContentType.cpp */,
                                447958031643B47B001E0A7F /* ParsedContentType.h */,
-                               E1424C89164B3B4E00F32D40 /* PlatformCookieJar.h */,
                                37BAAE571980D1DD005DFE71 /* ProtectionSpace.h */,
                                514C765F0CE923A1007EF3CD /* ProtectionSpaceBase.cpp */,
                                514C76600CE923A1007EF3CD /* ProtectionSpaceBase.h */,
                                514C76430CE9234E007EF3CD /* AuthenticationMac.mm */,
                                E164A2EB191AE6350010737D /* BlobDataFileReferenceMac.mm */,
                                5F2DBBE7178E332D00141486 /* CertificateInfoMac.mm */,
-                               E1424C8F164B460B00F32D40 /* CookieJarMac.mm */,
                                E13F01F01270E19000DFBA71 /* CookieStorageMac.mm */,
                                E1B4CD2410B322E200BFFD7E /* CredentialStorageMac.mm */,
                                514C76440CE9234E007EF3CD /* FormDataStreamMac.h */,
                                493E5E0912D6420500020081 /* PlatformCALayerClient.h in Headers */,
                                2D70BA1318074DDF0001908A /* PlatformCALayerCocoa.h in Headers */,
                                A14978711ABAF3A500CEF7E4 /* PlatformContentFilter.h in Headers */,
-                               E1424C8A164B3B4E00F32D40 /* PlatformCookieJar.h in Headers */,
                                BC5C762B1497FE1400BC4775 /* PlatformEvent.h in Headers */,
                                26601EBF14B3B9AD0012C0FE /* PlatformEventFactoryIOS.h in Headers */,
                                BCAA487014A052530088FAC4 /* PlatformEventFactoryMac.h in Headers */,
                                3C244FEAA375AC633F88BE6F /* RenderLayerModelObject.h in Headers */,
                                0BE030A20F3112FB003C1A46 /* RenderLineBoxList.h in Headers */,
                                BCEA4864097D93020094C9E4 /* RenderLineBreak.h in Headers */,
-                               94CFD60A1FE9867E002488AD /* RenderLinesClampFlow.h in Headers */,
-                               94CFD60D1FEACEFE002488AD /* RenderLinesClampSet.h in Headers */,
                                ABB5419F0ACDDFE4002820EB /* RenderListBox.h in Headers */,
                                A8EA7A520A191A5200A8EF5F /* RenderListItem.h in Headers */,
                                A8EA7A500A191A5200A8EF5F /* RenderListMarker.h in Headers */,
index 49b798d..0683067 100644 (file)
@@ -35,7 +35,6 @@
 #include "FrameLoaderClient.h"
 #include "NetworkStorageSession.h"
 #include "NetworkingContext.h"
-#include "PlatformCookieJar.h"
 #include "PlatformStrategies.h"
 #include "SameSiteInfo.h"
 #include <wtf/SystemTracing.h>
index 1051130..1603ef8 100644 (file)
@@ -5,7 +5,6 @@ list(APPEND WebCore_INCLUDE_DIRECTORIES
 list(APPEND WebCore_SOURCES
     platform/network/curl/AuthenticationChallengeCurl.cpp
     platform/network/curl/CertificateInfo.cpp
-    platform/network/curl/CookieJarCurl.cpp
     platform/network/curl/CookieJarCurlDatabase.cpp
     platform/network/curl/CookieJarDB.cpp
     platform/network/curl/CookieStorageCurl.cpp
index d64fcfb..c02e49e 100644 (file)
@@ -23,7 +23,6 @@
 
 platform/network/soup/AuthenticationChallengeSoup.cpp
 platform/network/soup/CertificateInfo.cpp
-platform/network/soup/CookieJarSoup.cpp
 platform/network/soup/CookieSoup.cpp
 platform/network/soup/CookieStorageSoup.cpp
 platform/network/soup/CredentialStorageSoup.cpp
index 302a8d6..910fbf9 100644 (file)
@@ -29,7 +29,6 @@
 #include "CookiesStrategy.h"
 #include "HTTPHeaderMap.h"
 #include "NetworkStorageSession.h"
-#include "PlatformCookieJar.h"
 #include "PlatformStrategies.h"
 #include "ResourceRequest.h"
 #include "ResourceResponse.h"
@@ -338,7 +337,7 @@ static String headerValueForVary(const ResourceRequest& request, const String& h
         auto* cookieStrategy = platformStrategies() ? platformStrategies()->cookiesStrategy() : nullptr;
         if (!cookieStrategy) {
             ASSERT(sessionID == PAL::SessionID::defaultSessionID());
-            return cookieRequestHeaderFieldValue(NetworkStorageSession::defaultStorageSession(), request.firstPartyForCookies(), SameSiteInfo::create(request), request.url(), std::nullopt, std::nullopt, includeSecureCookies).first;
+            return NetworkStorageSession::defaultStorageSession().cookieRequestHeaderFieldValue(request.firstPartyForCookies(), SameSiteInfo::create(request), request.url(), std::nullopt, std::nullopt, includeSecureCookies).first;
         }
         return cookieStrategy->cookieRequestHeaderFieldValue(sessionID, request.firstPartyForCookies(), SameSiteInfo::create(request), request.url(), std::nullopt, std::nullopt, includeSecureCookies).first;
     }
index 6e99393..08a82dd 100644 (file)
@@ -30,6 +30,7 @@
 #include <wtf/Function.h>
 #include <wtf/HashMap.h>
 #include <wtf/HashSet.h>
+#include <wtf/WallTime.h>
 #include <wtf/text/WTFString.h>
 
 #if PLATFORM(COCOA) || USE(CFURLCONNECTION)
@@ -64,6 +65,10 @@ class ResourceRequest;
 class SoupNetworkSession;
 
 struct Cookie;
+struct CookieRequestHeaderFieldProxy;
+struct SameSiteInfo;
+
+enum class IncludeSecureCookies;
 
 class NetworkStorageSession {
     WTF_MAKE_NONCOPYABLE(NetworkStorageSession); WTF_MAKE_FAST_ALLOCATED;
@@ -137,12 +142,24 @@ public:
     NetworkingContext* context() const;
 #endif
 
+    WEBCORE_EXPORT bool cookiesEnabled() const;
     WEBCORE_EXPORT void setCookie(const Cookie&);
     WEBCORE_EXPORT void setCookies(const Vector<Cookie>&, const URL&, const URL& mainDocumentURL);
+    WEBCORE_EXPORT void setCookiesFromDOM(const URL& firstParty, const SameSiteInfo&, const URL&, std::optional<uint64_t> frameID, std::optional<uint64_t> pageID, const String&) const;
     WEBCORE_EXPORT void deleteCookie(const Cookie&);
+    WEBCORE_EXPORT void deleteCookie(const URL&, const String&) const;
+    WEBCORE_EXPORT void deleteAllCookies();
+    WEBCORE_EXPORT void deleteAllCookiesModifiedSince(WallTime);
+    WEBCORE_EXPORT void deleteCookiesForHostnames(const Vector<String>& cookieHostNames);
     WEBCORE_EXPORT Vector<Cookie> getAllCookies();
     WEBCORE_EXPORT Vector<Cookie> getCookies(const URL&);
+    WEBCORE_EXPORT bool getRawCookies(const URL& firstParty, const SameSiteInfo&, const URL&, std::optional<uint64_t> frameID, std::optional<uint64_t> pageID, Vector<Cookie>&) const;
     WEBCORE_EXPORT void flushCookieStore();
+    WEBCORE_EXPORT void getHostnamesWithCookies(HashSet<String>& hostnames);
+    WEBCORE_EXPORT std::pair<String, bool> cookiesForDOM(const URL& firstParty, const SameSiteInfo&, const URL&, std::optional<uint64_t> frameID, std::optional<uint64_t> pageID, IncludeSecureCookies) const;
+    WEBCORE_EXPORT std::pair<String, bool> cookieRequestHeaderFieldValue(const URL& firstParty, const SameSiteInfo&, const URL&, std::optional<uint64_t> frameID, std::optional<uint64_t> pageID, IncludeSecureCookies) const;
+    WEBCORE_EXPORT std::pair<String, bool> cookieRequestHeaderFieldValue(const CookieRequestHeaderFieldProxy&) const;
+
 
 private:
     static HashMap<PAL::SessionID, std::unique_ptr<NetworkStorageSession>>& globalSessionMap();
diff --git a/Source/WebCore/platform/network/PlatformCookieJar.h b/Source/WebCore/platform/network/PlatformCookieJar.h
deleted file mode 100644 (file)
index 78943d9..0000000
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Copyright (C) 2003-2017 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#pragma once
-
-#include <wtf/Forward.h>
-#include <wtf/HashSet.h>
-#include <wtf/WallTime.h>
-#include <wtf/text/WTFString.h>
-
-namespace WebCore {
-
-class URL;
-class NetworkStorageSession;
-
-struct Cookie;
-struct CookieRequestHeaderFieldProxy;
-struct SameSiteInfo;
-
-enum class IncludeSecureCookies;
-
-// FIXME: These should probably be NetworkStorageSession member functions.
-
-WEBCORE_EXPORT std::pair<String, bool> cookiesForDOM(const NetworkStorageSession&, const URL& firstParty, const SameSiteInfo&, const URL&, std::optional<uint64_t> frameID, std::optional<uint64_t> pageID, IncludeSecureCookies);
-WEBCORE_EXPORT void setCookiesFromDOM(const NetworkStorageSession&, const URL& firstParty, const SameSiteInfo&, const URL&, std::optional<uint64_t> frameID, std::optional<uint64_t> pageID, const String&);
-WEBCORE_EXPORT bool cookiesEnabled(const NetworkStorageSession&);
-WEBCORE_EXPORT std::pair<String, bool> cookieRequestHeaderFieldValue(const NetworkStorageSession&, const URL& firstParty, const SameSiteInfo&, const URL&, std::optional<uint64_t> frameID, std::optional<uint64_t> pageID, IncludeSecureCookies);
-WEBCORE_EXPORT std::pair<String, bool> cookieRequestHeaderFieldValue(const NetworkStorageSession&, const CookieRequestHeaderFieldProxy&);
-WEBCORE_EXPORT bool getRawCookies(const NetworkStorageSession&, const URL& firstParty, const SameSiteInfo&, const URL&, std::optional<uint64_t> frameID, std::optional<uint64_t> pageID, Vector<Cookie>&);
-WEBCORE_EXPORT void deleteCookie(const NetworkStorageSession&, const URL&, const String&);
-WEBCORE_EXPORT void getHostnamesWithCookies(const NetworkStorageSession&, HashSet<String>& hostnames);
-WEBCORE_EXPORT void deleteCookiesForHostnames(const NetworkStorageSession&, const Vector<String>& cookieHostNames);
-WEBCORE_EXPORT void deleteAllCookies(const NetworkStorageSession&);
-WEBCORE_EXPORT void deleteAllCookiesModifiedSince(const NetworkStorageSession&, WallTime);
-
-}
index 759d63a..389b6ea 100644 (file)
@@ -28,7 +28,6 @@
 
 #include "CookieRequestHeaderFieldProxy.h"
 #include "NetworkStorageSession.h"
-#include "PlatformCookieJar.h"
 #include "SocketStreamHandleClient.h"
 #include <wtf/Function.h>
 
@@ -85,7 +84,7 @@ static std::optional<std::pair<Vector<uint8_t>, bool>> cookieDataForHandshake(co
     
     String cookieDataString;
     bool secureCookiesAccessed = false;
-    std::tie(cookieDataString, secureCookiesAccessed) = WebCore::cookieRequestHeaderFieldValue(*networkStorageSession, headerFieldProxy);
+    std::tie(cookieDataString, secureCookiesAccessed) = networkStorageSession->cookieRequestHeaderFieldValue(headerFieldProxy);
     if (cookieDataString.isEmpty())
         return std::pair<Vector<uint8_t>, bool> { { }, secureCookiesAccessed };
 
diff --git a/Source/WebCore/platform/network/cf/CookieJarCFNet.cpp b/Source/WebCore/platform/network/cf/CookieJarCFNet.cpp
deleted file mode 100644 (file)
index 1e0c74a..0000000
+++ /dev/null
@@ -1,325 +0,0 @@
-/*
- * Copyright (C) 2006-2017 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
- */
-
-#include "config.h"
-#include "PlatformCookieJar.h"
-
-#if USE(CFURLCONNECTION)
-
-#include "Cookie.h"
-#include "CookieRequestHeaderFieldProxy.h"
-#include "CookiesStrategy.h"
-#include "NetworkStorageSession.h"
-#include "NotImplemented.h"
-#include "URL.h"
-#include <CFNetwork/CFHTTPCookiesPriv.h>
-#include <CoreFoundation/CoreFoundation.h>
-#include <WebKitSystemInterface/WebKitSystemInterface.h>
-#include <pal/spi/cf/CFNetworkSPI.h>
-#include <windows.h>
-#include <wtf/SoftLinking.h>
-#include <wtf/cf/TypeCastsCF.h>
-#include <wtf/text/WTFString.h>
-
-enum {
-    CFHTTPCookieStorageAcceptPolicyExclusivelyFromMainDocumentDomain = 3
-};
-
-namespace WTF {
-
-#define DECLARE_CF_TYPE_TRAIT(ClassName) \
-template <> \
-struct CFTypeTrait<ClassName##Ref> { \
-static inline CFTypeID typeID() { return ClassName##GetTypeID(); } \
-};
-
-#if COMPILER(CLANG)
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wdeprecated-declarations"
-#endif
-DECLARE_CF_TYPE_TRAIT(CFHTTPCookie);
-#if COMPILER(CLANG)
-#pragma clang diagnostic pop
-#endif
-
-#undef DECLARE_CF_TYPE_TRAIT
-} // namespace WTF
-
-namespace WebCore {
-
-static const CFStringRef s_setCookieKeyCF = CFSTR("Set-Cookie");
-static const CFStringRef s_cookieCF = CFSTR("Cookie");
-static const CFStringRef s_createdCF = CFSTR("Created");
-
-static inline RetainPtr<CFStringRef> cookieDomain(CFHTTPCookieRef cookie)
-{
-    return adoptCF(CFHTTPCookieCopyDomain(cookie));
-}
-
-static double canonicalCookieTime(double time)
-{
-    if (!time)
-        return time;
-
-    return (time + kCFAbsoluteTimeIntervalSince1970) * 1000;
-}
-
-static double cookieCreatedTime(CFHTTPCookieRef cookie)
-{
-    RetainPtr<CFDictionaryRef> props = adoptCF(CFHTTPCookieCopyProperties(cookie));
-    auto value = CFDictionaryGetValue(props.get(), s_createdCF);
-
-    auto asNumber = dynamic_cf_cast<CFNumberRef>(value);
-    if (asNumber) {
-        double asDouble;
-        if (CFNumberGetValue(asNumber, kCFNumberFloat64Type, &asDouble))
-            return canonicalCookieTime(asDouble);
-        return 0.0;
-    }
-
-    auto asString = dynamic_cf_cast<CFStringRef>(value);
-    if (asString)
-        return canonicalCookieTime(CFStringGetDoubleValue(asString));
-
-    return 0.0;
-}
-
-static inline CFAbsoluteTime cookieExpirationTime(CFHTTPCookieRef cookie)
-{
-    return canonicalCookieTime(CFHTTPCookieGetExpirationTime(cookie));
-}
-
-static inline RetainPtr<CFStringRef> cookieName(CFHTTPCookieRef cookie)
-{
-    return adoptCF(CFHTTPCookieCopyName(cookie));
-}
-
-static inline RetainPtr<CFStringRef> cookiePath(CFHTTPCookieRef cookie)
-{
-    return adoptCF(CFHTTPCookieCopyPath(cookie));
-}
-
-static inline RetainPtr<CFStringRef> cookieValue(CFHTTPCookieRef cookie)
-{
-    return adoptCF(CFHTTPCookieCopyValue(cookie));
-}
-
-static RetainPtr<CFArrayRef> filterCookies(CFArrayRef unfilteredCookies)
-{
-    ASSERT(unfilteredCookies);
-    CFIndex count = CFArrayGetCount(unfilteredCookies);
-    RetainPtr<CFMutableArrayRef> filteredCookies = adoptCF(CFArrayCreateMutable(0, count, &kCFTypeArrayCallBacks));
-    for (CFIndex i = 0; i < count; ++i) {
-        CFHTTPCookieRef cookie = (CFHTTPCookieRef)CFArrayGetValueAtIndex(unfilteredCookies, i);
-
-        // <rdar://problem/5632883> CFHTTPCookieStorage would store an empty cookie,
-        // which would be sent as "Cookie: =". We have a workaround in setCookies() to prevent
-        // that, but we also need to avoid sending cookies that were previously stored, and
-        // there's no harm to doing this check because such a cookie is never valid.
-        if (!CFStringGetLength(cookieName(cookie).get()))
-            continue;
-
-        if (CFHTTPCookieIsHTTPOnly(cookie))
-            continue;
-
-        CFArrayAppendValue(filteredCookies.get(), cookie);
-    }
-    return filteredCookies;
-}
-
-static RetainPtr<CFArrayRef> copyCookiesForURLWithFirstPartyURL(const NetworkStorageSession& session, const URL& firstParty, const URL& url, IncludeSecureCookies includeSecureCookies)
-{
-    bool secure = includeSecureCookies == IncludeSecureCookies::Yes;
-
-    ASSERT(!secure || (secure && url.protocolIs("https")));
-
-    UNUSED_PARAM(firstParty);
-    return adoptCF(CFHTTPCookieStorageCopyCookiesForURL(session.cookieStorage().get(), url.createCFURL().get(), secure));
-}
-
-static CFArrayRef createCookies(CFDictionaryRef headerFields, CFURLRef url)
-{
-    CFArrayRef parsedCookies = CFHTTPCookieCreateWithResponseHeaderFields(kCFAllocatorDefault, headerFields, url);
-    if (!parsedCookies)
-        parsedCookies = CFArrayCreate(kCFAllocatorDefault, 0, 0, &kCFTypeArrayCallBacks);
-
-    return parsedCookies;
-}
-
-void setCookiesFromDOM(const NetworkStorageSession& session, const URL& firstParty, const SameSiteInfo&, const URL& url, std::optional<uint64_t> frameID, std::optional<uint64_t> pageID, const String& value)
-{
-    UNUSED_PARAM(frameID);
-    UNUSED_PARAM(pageID);
-    // <rdar://problem/5632883> CFHTTPCookieStorage stores an empty cookie, which would be sent as "Cookie: =".
-    if (value.isEmpty())
-        return;
-
-    RetainPtr<CFURLRef> urlCF = url.createCFURL();
-    RetainPtr<CFURLRef> firstPartyForCookiesCF = firstParty.createCFURL();
-
-    // <http://bugs.webkit.org/show_bug.cgi?id=6531>, <rdar://4409034>
-    // cookiesWithResponseHeaderFields doesn't parse cookies without a value
-    String cookieString = value.contains('=') ? value : value + "=";
-
-    RetainPtr<CFStringRef> cookieStringCF = cookieString.createCFString();
-    auto cookieStringCFPtr = cookieStringCF.get();
-    RetainPtr<CFDictionaryRef> headerFieldsCF = adoptCF(CFDictionaryCreate(kCFAllocatorDefault,
-        (const void**)&s_setCookieKeyCF, (const void**)&cookieStringCFPtr, 1,
-        &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));
-
-    RetainPtr<CFArrayRef> unfilteredCookies = adoptCF(createCookies(headerFieldsCF.get(), urlCF.get()));
-    CFHTTPCookieStorageSetCookies(session.cookieStorage().get(), filterCookies(unfilteredCookies.get()).get(), urlCF.get(), firstPartyForCookiesCF.get());
-}
-
-static bool containsSecureCookies(CFArrayRef cookies)
-{
-    CFIndex cookieCount = CFArrayGetCount(cookies);
-    while (cookieCount--) {
-        if (CFHTTPCookieIsSecure(checked_cf_cast<CFHTTPCookieRef>(CFArrayGetValueAtIndex(cookies, cookieCount))))
-            return true;
-    }
-
-    return false;
-}
-
-std::pair<String, bool> cookiesForDOM(const NetworkStorageSession& session, const URL& firstParty, const SameSiteInfo&, const URL& url, std::optional<uint64_t> frameID, std::optional<uint64_t> pageID, IncludeSecureCookies includeSecureCookies)
-{
-    UNUSED_PARAM(frameID);
-    UNUSED_PARAM(pageID);
-    RetainPtr<CFArrayRef> cookiesCF = copyCookiesForURLWithFirstPartyURL(session, firstParty, url, includeSecureCookies);
-
-    auto filteredCookies = filterCookies(cookiesCF.get());
-
-    bool didAccessSecureCookies = containsSecureCookies(filteredCookies.get());
-
-    RetainPtr<CFDictionaryRef> headerCF = adoptCF(CFHTTPCookieCopyRequestHeaderFields(kCFAllocatorDefault, filteredCookies.get()));
-    String cookieString = checked_cf_cast<CFStringRef>(CFDictionaryGetValue(headerCF.get(), s_cookieCF));
-    return { cookieString, didAccessSecureCookies };
-}
-
-std::pair<String, bool> cookieRequestHeaderFieldValue(const NetworkStorageSession& session, const URL& firstParty, const SameSiteInfo&, const URL& url, std::optional<uint64_t> frameID, std::optional<uint64_t> pageID, IncludeSecureCookies includeSecureCookies)
-{
-    UNUSED_PARAM(frameID);
-    UNUSED_PARAM(pageID);
-    RetainPtr<CFArrayRef> cookiesCF = copyCookiesForURLWithFirstPartyURL(session, firstParty, url, includeSecureCookies);
-
-    bool didAccessSecureCookies = containsSecureCookies(cookiesCF.get());
-
-    RetainPtr<CFDictionaryRef> headerCF = adoptCF(CFHTTPCookieCopyRequestHeaderFields(kCFAllocatorDefault, cookiesCF.get()));
-    String cookieString = checked_cf_cast<CFStringRef>(CFDictionaryGetValue(headerCF.get(), s_cookieCF));
-    return { cookieString, didAccessSecureCookies };
-}
-
-std::pair<String, bool> cookieRequestHeaderFieldValue(const NetworkStorageSession& session, const CookieRequestHeaderFieldProxy& headerFieldProxy)
-{
-    return cookieRequestHeaderFieldValue(session, headerFieldProxy.firstParty, headerFieldProxy.sameSiteInfo, headerFieldProxy.url, headerFieldProxy.frameID, headerFieldProxy.pageID, headerFieldProxy.includeSecureCookies);
-}
-
-bool cookiesEnabled(const NetworkStorageSession& session)
-{
-    CFHTTPCookieStorageAcceptPolicy policy = CFHTTPCookieStorageGetCookieAcceptPolicy(session.cookieStorage().get());
-    return policy == CFHTTPCookieStorageAcceptPolicyOnlyFromMainDocumentDomain || policy == CFHTTPCookieStorageAcceptPolicyExclusivelyFromMainDocumentDomain || policy == CFHTTPCookieStorageAcceptPolicyAlways;
-}
-
-bool getRawCookies(const NetworkStorageSession& session, const URL& firstParty, const SameSiteInfo&, const URL& url, std::optional<uint64_t> frameID, std::optional<uint64_t> pageID, Vector<Cookie>& rawCookies)
-{
-    UNUSED_PARAM(frameID);
-    UNUSED_PARAM(pageID);
-    rawCookies.clear();
-
-    auto includeSecureCookies = url.protocolIs("https") ? IncludeSecureCookies::Yes : IncludeSecureCookies::No;
-
-    RetainPtr<CFArrayRef> cookiesCF = copyCookiesForURLWithFirstPartyURL(session, firstParty, url, includeSecureCookies);
-
-    CFIndex count = CFArrayGetCount(cookiesCF.get());
-    rawCookies.reserveCapacity(count);
-
-    for (CFIndex i = 0; i < count; i++) {
-        CFHTTPCookieRef cfCookie = checked_cf_cast<CFHTTPCookieRef>(CFArrayGetValueAtIndex(cookiesCF.get(), i));
-        Cookie cookie;
-        cookie.name = cookieName(cfCookie).get();
-        cookie.value = cookieValue(cfCookie).get();
-        cookie.domain = cookieDomain(cfCookie).get();
-        cookie.path = cookiePath(cfCookie).get();
-        cookie.created = cookieCreatedTime(cfCookie);
-        cookie.expires = cookieExpirationTime(cfCookie);
-        cookie.httpOnly = CFHTTPCookieIsHTTPOnly(cfCookie);
-        cookie.secure = CFHTTPCookieIsSecure(cfCookie);
-        cookie.session = false; // FIXME: Need API for if a cookie is a session cookie.
-        rawCookies.uncheckedAppend(WTFMove(cookie));
-    }
-
-    return true;
-}
-
-void deleteCookie(const NetworkStorageSession& session, const URL& url, const String& name)
-{
-    RetainPtr<CFHTTPCookieStorageRef> cookieStorage = session.cookieStorage();
-
-    RetainPtr<CFURLRef> urlCF = url.createCFURL();
-
-    bool sendSecureCookies = url.protocolIs("https");
-    RetainPtr<CFArrayRef> cookiesCF = adoptCF(CFHTTPCookieStorageCopyCookiesForURL(cookieStorage.get(), urlCF.get(), sendSecureCookies));
-
-    CFIndex count = CFArrayGetCount(cookiesCF.get());
-    for (CFIndex i = 0; i < count; i++) {
-        CFHTTPCookieRef cookie = checked_cf_cast<CFHTTPCookieRef>(CFArrayGetValueAtIndex(cookiesCF.get(), i));
-        if (String(cookieName(cookie).get()) == name) {
-            CFHTTPCookieStorageDeleteCookie(cookieStorage.get(), cookie);
-            break;
-        }
-    }
-}
-
-void getHostnamesWithCookies(const NetworkStorageSession& session, HashSet<String>& hostnames)
-{
-    RetainPtr<CFArrayRef> cookiesCF = adoptCF(CFHTTPCookieStorageCopyCookies(session.cookieStorage().get()));
-    if (!cookiesCF)
-        return;
-
-    CFIndex count = CFArrayGetCount(cookiesCF.get());
-    for (CFIndex i = 0; i < count; ++i) {
-        CFHTTPCookieRef cookie = checked_cf_cast<CFHTTPCookieRef>(CFArrayGetValueAtIndex(cookiesCF.get(), i));
-        RetainPtr<CFStringRef> domain = cookieDomain(cookie);
-        hostnames.add(domain.get());
-    }
-}
-
-void deleteAllCookies(const NetworkStorageSession& session)
-{
-    CFHTTPCookieStorageDeleteAllCookies(session.cookieStorage().get());
-}
-
-void deleteCookiesForHostnames(const NetworkStorageSession& session, const Vector<String>& hostnames)
-{
-}
-
-void deleteAllCookiesModifiedSince(const NetworkStorageSession&, WallTime)
-{
-}
-
-} // namespace WebCore
-
-#endif // USE(CFURLCONNECTION)
index 4e31056..f942ec9 100644 (file)
 #else
 #include <WebKitSystemInterface/WebKitSystemInterface.h>
 #endif
+#if USE(CFURLCONNECTION)
+#include "Cookie.h"
+#include "CookieRequestHeaderFieldProxy.h"
+#include "CookiesStrategy.h"
+#include "NotImplemented.h"
+#include "URL.h"
+#include <CFNetwork/CFHTTPCookiesPriv.h>
+#include <CoreFoundation/CoreFoundation.h>
+#include <pal/spi/cf/CFNetworkSPI.h>
+#include <windows.h>
+#include <wtf/SoftLinking.h>
+#include <wtf/cf/TypeCastsCF.h>
+#include <wtf/text/WTFString.h>
+
+enum {
+    CFHTTPCookieStorageAcceptPolicyExclusivelyFromMainDocumentDomain = 3
+};
+
+namespace WTF {
+
+#define DECLARE_CF_TYPE_TRAIT(ClassName) \
+template <> \
+struct CFTypeTrait<ClassName##Ref> { \
+static inline CFTypeID typeID() { return ClassName##GetTypeID(); } \
+};
+
+#if COMPILER(CLANG)
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+#endif
+DECLARE_CF_TYPE_TRAIT(CFHTTPCookie);
+#if COMPILER(CLANG)
+#pragma clang diagnostic pop
+#endif
+
+#undef DECLARE_CF_TYPE_TRAIT
+} // namespace WTF
+
+#endif
 
 namespace WebCore {
 
@@ -402,4 +441,263 @@ void NetworkStorageSession::setCookies(const Vector<Cookie>&, const URL&, const
 }
 #endif
 
+} // namespace WebCore
+
+#if USE(CFURLCONNECTION)
+
+namespace WebCore {
+
+static const CFStringRef s_setCookieKeyCF = CFSTR("Set-Cookie");
+static const CFStringRef s_cookieCF = CFSTR("Cookie");
+static const CFStringRef s_createdCF = CFSTR("Created");
+
+static inline RetainPtr<CFStringRef> cookieDomain(CFHTTPCookieRef cookie)
+{
+    return adoptCF(CFHTTPCookieCopyDomain(cookie));
+}
+
+static double canonicalCookieTime(double time)
+{
+    if (!time)
+        return time;
+
+    return (time + kCFAbsoluteTimeIntervalSince1970) * 1000;
+}
+
+static double cookieCreatedTime(CFHTTPCookieRef cookie)
+{
+    RetainPtr<CFDictionaryRef> props = adoptCF(CFHTTPCookieCopyProperties(cookie));
+    auto value = CFDictionaryGetValue(props.get(), s_createdCF);
+
+    auto asNumber = dynamic_cf_cast<CFNumberRef>(value);
+    if (asNumber) {
+        double asDouble;
+        if (CFNumberGetValue(asNumber, kCFNumberFloat64Type, &asDouble))
+            return canonicalCookieTime(asDouble);
+        return 0.0;
+    }
+
+    auto asString = dynamic_cf_cast<CFStringRef>(value);
+    if (asString)
+        return canonicalCookieTime(CFStringGetDoubleValue(asString));
+
+    return 0.0;
 }
+
+static inline CFAbsoluteTime cookieExpirationTime(CFHTTPCookieRef cookie)
+{
+    return canonicalCookieTime(CFHTTPCookieGetExpirationTime(cookie));
+}
+
+static inline RetainPtr<CFStringRef> cookieName(CFHTTPCookieRef cookie)
+{
+    return adoptCF(CFHTTPCookieCopyName(cookie));
+}
+
+static inline RetainPtr<CFStringRef> cookiePath(CFHTTPCookieRef cookie)
+{
+    return adoptCF(CFHTTPCookieCopyPath(cookie));
+}
+
+static inline RetainPtr<CFStringRef> cookieValue(CFHTTPCookieRef cookie)
+{
+    return adoptCF(CFHTTPCookieCopyValue(cookie));
+}
+
+static RetainPtr<CFArrayRef> filterCookies(CFArrayRef unfilteredCookies)
+{
+    ASSERT(unfilteredCookies);
+    CFIndex count = CFArrayGetCount(unfilteredCookies);
+    RetainPtr<CFMutableArrayRef> filteredCookies = adoptCF(CFArrayCreateMutable(0, count, &kCFTypeArrayCallBacks));
+    for (CFIndex i = 0; i < count; ++i) {
+        CFHTTPCookieRef cookie = (CFHTTPCookieRef)CFArrayGetValueAtIndex(unfilteredCookies, i);
+
+        // <rdar://problem/5632883> CFHTTPCookieStorage would store an empty cookie,
+        // which would be sent as "Cookie: =". We have a workaround in setCookies() to prevent
+        // that, but we also need to avoid sending cookies that were previously stored, and
+        // there's no harm to doing this check because such a cookie is never valid.
+        if (!CFStringGetLength(cookieName(cookie).get()))
+            continue;
+
+        if (CFHTTPCookieIsHTTPOnly(cookie))
+            continue;
+
+        CFArrayAppendValue(filteredCookies.get(), cookie);
+    }
+    return filteredCookies;
+}
+
+static RetainPtr<CFArrayRef> copyCookiesForURLWithFirstPartyURL(const NetworkStorageSession& session, const URL& firstParty, const URL& url, IncludeSecureCookies includeSecureCookies)
+{
+    bool secure = includeSecureCookies == IncludeSecureCookies::Yes;
+
+    ASSERT(!secure || (secure && url.protocolIs("https")));
+
+    UNUSED_PARAM(firstParty);
+    return adoptCF(CFHTTPCookieStorageCopyCookiesForURL(session.cookieStorage().get(), url.createCFURL().get(), secure));
+}
+
+static CFArrayRef createCookies(CFDictionaryRef headerFields, CFURLRef url)
+{
+    CFArrayRef parsedCookies = CFHTTPCookieCreateWithResponseHeaderFields(kCFAllocatorDefault, headerFields, url);
+    if (!parsedCookies)
+        parsedCookies = CFArrayCreate(kCFAllocatorDefault, 0, 0, &kCFTypeArrayCallBacks);
+
+    return parsedCookies;
+}
+
+void NetworkStorageSession::setCookiesFromDOM(const URL& firstParty, const SameSiteInfo&, const URL& url, std::optional<uint64_t> frameID, std::optional<uint64_t> pageID, const String& value) const
+{
+    UNUSED_PARAM(frameID);
+    UNUSED_PARAM(pageID);
+    // <rdar://problem/5632883> CFHTTPCookieStorage stores an empty cookie, which would be sent as "Cookie: =".
+    if (value.isEmpty())
+        return;
+
+    RetainPtr<CFURLRef> urlCF = url.createCFURL();
+    RetainPtr<CFURLRef> firstPartyForCookiesCF = firstParty.createCFURL();
+
+    // <http://bugs.webkit.org/show_bug.cgi?id=6531>, <rdar://4409034>
+    // cookiesWithResponseHeaderFields doesn't parse cookies without a value
+    String cookieString = value.contains('=') ? value : value + "=";
+
+    RetainPtr<CFStringRef> cookieStringCF = cookieString.createCFString();
+    auto cookieStringCFPtr = cookieStringCF.get();
+    RetainPtr<CFDictionaryRef> headerFieldsCF = adoptCF(CFDictionaryCreate(kCFAllocatorDefault,
+        (const void**)&s_setCookieKeyCF, (const void**)&cookieStringCFPtr, 1,
+        &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));
+
+    RetainPtr<CFArrayRef> unfilteredCookies = adoptCF(createCookies(headerFieldsCF.get(), urlCF.get()));
+    CFHTTPCookieStorageSetCookies(cookieStorage().get(), filterCookies(unfilteredCookies.get()).get(), urlCF.get(), firstPartyForCookiesCF.get());
+}
+
+static bool containsSecureCookies(CFArrayRef cookies)
+{
+    CFIndex cookieCount = CFArrayGetCount(cookies);
+    while (cookieCount--) {
+        if (CFHTTPCookieIsSecure(checked_cf_cast<CFHTTPCookieRef>(CFArrayGetValueAtIndex(cookies, cookieCount))))
+            return true;
+    }
+
+    return false;
+}
+
+std::pair<String, bool> NetworkStorageSession::cookiesForDOM(const URL& firstParty, const SameSiteInfo&, const URL& url, std::optional<uint64_t> frameID, std::optional<uint64_t> pageID, IncludeSecureCookies includeSecureCookies) const
+{
+    UNUSED_PARAM(frameID);
+    UNUSED_PARAM(pageID);
+    RetainPtr<CFArrayRef> cookiesCF = copyCookiesForURLWithFirstPartyURL(*this, firstParty, url, includeSecureCookies);
+
+    auto filteredCookies = filterCookies(cookiesCF.get());
+
+    bool didAccessSecureCookies = containsSecureCookies(filteredCookies.get());
+
+    RetainPtr<CFDictionaryRef> headerCF = adoptCF(CFHTTPCookieCopyRequestHeaderFields(kCFAllocatorDefault, filteredCookies.get()));
+    String cookieString = checked_cf_cast<CFStringRef>(CFDictionaryGetValue(headerCF.get(), s_cookieCF));
+    return { cookieString, didAccessSecureCookies };
+}
+
+std::pair<String, bool> NetworkStorageSession::cookieRequestHeaderFieldValue(const URL& firstParty, const SameSiteInfo&, const URL& url, std::optional<uint64_t> frameID, std::optional<uint64_t> pageID, IncludeSecureCookies includeSecureCookies) const
+{
+    UNUSED_PARAM(frameID);
+    UNUSED_PARAM(pageID);
+    RetainPtr<CFArrayRef> cookiesCF = copyCookiesForURLWithFirstPartyURL(*this, firstParty, url, includeSecureCookies);
+
+    bool didAccessSecureCookies = containsSecureCookies(cookiesCF.get());
+
+    RetainPtr<CFDictionaryRef> headerCF = adoptCF(CFHTTPCookieCopyRequestHeaderFields(kCFAllocatorDefault, cookiesCF.get()));
+    String cookieString = checked_cf_cast<CFStringRef>(CFDictionaryGetValue(headerCF.get(), s_cookieCF));
+    return { cookieString, didAccessSecureCookies };
+}
+
+std::pair<String, bool> NetworkStorageSession::cookieRequestHeaderFieldValue(const CookieRequestHeaderFieldProxy& headerFieldProxy) const
+{
+    return cookieRequestHeaderFieldValue(headerFieldProxy.firstParty, headerFieldProxy.sameSiteInfo, headerFieldProxy.url, headerFieldProxy.frameID, headerFieldProxy.pageID, headerFieldProxy.includeSecureCookies);
+}
+
+bool NetworkStorageSession::cookiesEnabled() const
+{
+    CFHTTPCookieStorageAcceptPolicy policy = CFHTTPCookieStorageGetCookieAcceptPolicy(cookieStorage().get());
+    return policy == CFHTTPCookieStorageAcceptPolicyOnlyFromMainDocumentDomain || policy == CFHTTPCookieStorageAcceptPolicyExclusivelyFromMainDocumentDomain || policy == CFHTTPCookieStorageAcceptPolicyAlways;
+}
+
+bool NetworkStorageSession::getRawCookies(const URL& firstParty, const SameSiteInfo&, const URL& url, std::optional<uint64_t> frameID, std::optional<uint64_t> pageID, Vector<Cookie>& rawCookies) const
+{
+    UNUSED_PARAM(frameID);
+    UNUSED_PARAM(pageID);
+    rawCookies.clear();
+
+    auto includeSecureCookies = url.protocolIs("https") ? IncludeSecureCookies::Yes : IncludeSecureCookies::No;
+
+    RetainPtr<CFArrayRef> cookiesCF = copyCookiesForURLWithFirstPartyURL(*this, firstParty, url, includeSecureCookies);
+
+    CFIndex count = CFArrayGetCount(cookiesCF.get());
+    rawCookies.reserveCapacity(count);
+
+    for (CFIndex i = 0; i < count; i++) {
+        CFHTTPCookieRef cfCookie = checked_cf_cast<CFHTTPCookieRef>(CFArrayGetValueAtIndex(cookiesCF.get(), i));
+        Cookie cookie;
+        cookie.name = cookieName(cfCookie).get();
+        cookie.value = cookieValue(cfCookie).get();
+        cookie.domain = cookieDomain(cfCookie).get();
+        cookie.path = cookiePath(cfCookie).get();
+        cookie.created = cookieCreatedTime(cfCookie);
+        cookie.expires = cookieExpirationTime(cfCookie);
+        cookie.httpOnly = CFHTTPCookieIsHTTPOnly(cfCookie);
+        cookie.secure = CFHTTPCookieIsSecure(cfCookie);
+        cookie.session = false; // FIXME: Need API for if a cookie is a session cookie.
+        rawCookies.uncheckedAppend(WTFMove(cookie));
+    }
+
+    return true;
+}
+
+void NetworkStorageSession::deleteCookie(const URL& url, const String& name) const
+{
+    RetainPtr<CFHTTPCookieStorageRef> cookieStorage = this->cookieStorage();
+
+    RetainPtr<CFURLRef> urlCF = url.createCFURL();
+
+    bool sendSecureCookies = url.protocolIs("https");
+    RetainPtr<CFArrayRef> cookiesCF = adoptCF(CFHTTPCookieStorageCopyCookiesForURL(cookieStorage.get(), urlCF.get(), sendSecureCookies));
+
+    CFIndex count = CFArrayGetCount(cookiesCF.get());
+    for (CFIndex i = 0; i < count; i++) {
+        CFHTTPCookieRef cookie = checked_cf_cast<CFHTTPCookieRef>(CFArrayGetValueAtIndex(cookiesCF.get(), i));
+        if (String(cookieName(cookie).get()) == name) {
+            CFHTTPCookieStorageDeleteCookie(cookieStorage.get(), cookie);
+            break;
+        }
+    }
+}
+
+void NetworkStorageSession::getHostnamesWithCookies(HashSet<String>& hostnames)
+{
+    RetainPtr<CFArrayRef> cookiesCF = adoptCF(CFHTTPCookieStorageCopyCookies(cookieStorage().get()));
+    if (!cookiesCF)
+        return;
+
+    CFIndex count = CFArrayGetCount(cookiesCF.get());
+    for (CFIndex i = 0; i < count; ++i) {
+        CFHTTPCookieRef cookie = checked_cf_cast<CFHTTPCookieRef>(CFArrayGetValueAtIndex(cookiesCF.get(), i));
+        RetainPtr<CFStringRef> domain = cookieDomain(cookie);
+        hostnames.add(domain.get());
+    }
+}
+
+void NetworkStorageSession::deleteAllCookies()
+{
+    CFHTTPCookieStorageDeleteAllCookies(cookieStorage().get());
+}
+
+void NetworkStorageSession::deleteCookiesForHostnames(const Vector<String>& hostnames)
+{
+}
+
+void NetworkStorageSession::deleteAllCookiesModifiedSince(WallTime)
+{
+}
+
+} // namespace WebCore
+
+#endif // USE(CFURLCONNECTION)
index 3a3df0f..385c44b 100644 (file)
 #import "NetworkStorageSession.h"
 
 #import "Cookie.h"
+#import "CookieRequestHeaderFieldProxy.h"
 #import "CookieStorageObserver.h"
+#import "CookiesStrategy.h"
+#import "SameSiteInfo.h"
 #import "URL.h"
 #import <pal/spi/cf/CFNetworkSPI.h>
 #import <wtf/BlockObjCExceptions.h>
+#import <wtf/Optional.h>
 #import <wtf/ProcessPrivilege.h>
+#import <wtf/text/StringBuilder.h>
+
+@interface NSURL ()
+- (CFURLRef)_cfurl;
+@end
+
+#if (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101400) || (PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 120000)
+@interface NSHTTPCookieStorage (Staging)
+- (void)_getCookiesForURL:(NSURL *)url mainDocumentURL:(NSURL *)mainDocumentURL partition:(NSString *)partition policyProperties:(NSDictionary*)props completionHandler:(void (^)(NSArray *))completionHandler;
+- (void)_setCookies:(NSArray *)cookies forURL:(NSURL *)URL mainDocumentURL:(NSURL *)mainDocumentURL policyProperties:(NSDictionary*) props;
+@end
+#endif
 
 namespace WebCore {
 
@@ -150,4 +166,420 @@ CFURLStorageSessionRef createPrivateStorageSession(CFStringRef identifier)
     return storageSession.leakRef();
 }
 
+static NSArray *httpCookies(CFHTTPCookieStorageRef cookieStorage)
+{
+    ASSERT(hasProcessPrivilege(ProcessPrivilege::CanAccessRawCookies));
+    if (!cookieStorage)
+        return [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookies];
+    
+    auto cookies = adoptCF(CFHTTPCookieStorageCopyCookies(cookieStorage));
+    return [NSHTTPCookie _cf2nsCookies:cookies.get()];
+}
+
+static void deleteHTTPCookie(CFHTTPCookieStorageRef cookieStorage, NSHTTPCookie *cookie)
+{
+    ASSERT(hasProcessPrivilege(ProcessPrivilege::CanAccessRawCookies));
+    if (!cookieStorage) {
+        [[NSHTTPCookieStorage sharedHTTPCookieStorage] deleteCookie:cookie];
+        return;
+    }
+    
+    CFHTTPCookieStorageDeleteCookie(cookieStorage, [cookie _GetInternalCFHTTPCookie]);
+}
+
+#if (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101400) || (PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 120000)
+static RetainPtr<NSDictionary> policyProperties(const SameSiteInfo& sameSiteInfo, NSURL *url)
+{
+    static NSURL *emptyURL = [[NSURL alloc] initWithString:@""];
+    NSDictionary *policyProperties = @{
+        @"_kCFHTTPCookiePolicyPropertySiteForCookies": sameSiteInfo.isSameSite ? url : emptyURL,
+        @"_kCFHTTPCookiePolicyPropertyIsTopLevelNavigation": [NSNumber numberWithBool:sameSiteInfo.isTopSite],
+    };
+    return policyProperties;
+}
+#endif
+
+static NSArray *cookiesForURL(NSHTTPCookieStorage *storage, NSURL *url, NSURL *mainDocumentURL, const std::optional<SameSiteInfo>& sameSiteInfo, NSString *partition = nullptr)
+{
+    // The _getCookiesForURL: method calls the completionHandler synchronously. We use std::optional<> to ensure this invariant.
+    std::optional<RetainPtr<NSArray *>> cookiesPtr;
+    auto completionHandler = [&cookiesPtr] (NSArray *cookies) {
+        cookiesPtr = retainPtr(cookies);
+    };
+#if (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101400) || (PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 120000)
+    if ([storage respondsToSelector:@selector(_getCookiesForURL:mainDocumentURL:partition:policyProperties:completionHandler:)])
+        [storage _getCookiesForURL:url mainDocumentURL:mainDocumentURL partition:partition policyProperties:sameSiteInfo ? policyProperties(sameSiteInfo.value(), url).get() : nullptr completionHandler:completionHandler];
+    else
+        [storage _getCookiesForURL:url mainDocumentURL:mainDocumentURL partition:partition completionHandler:completionHandler];
+#else
+    [storage _getCookiesForURL:url mainDocumentURL:mainDocumentURL partition:partition completionHandler:completionHandler];
+    UNUSED_PARAM(sameSiteInfo);
+#endif
+    ASSERT(!!cookiesPtr);
+    return cookiesPtr->autorelease();
+}
+
+static void setHTTPCookiesForURL(CFHTTPCookieStorageRef cookieStorage, NSArray *cookies, NSURL *url, NSURL *mainDocumentURL, const SameSiteInfo& sameSiteInfo)
+{
+    ASSERT(hasProcessPrivilege(ProcessPrivilege::CanAccessRawCookies));
+    if (!cookieStorage) {
+#if (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101400) || (PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 120000)
+        if ([NSHTTPCookieStorage instancesRespondToSelector:@selector(_setCookies:forURL:mainDocumentURL:policyProperties:)])
+            [[NSHTTPCookieStorage sharedHTTPCookieStorage] _setCookies:cookies forURL:url mainDocumentURL:mainDocumentURL policyProperties:policyProperties(sameSiteInfo, url).get()];
+        else
+#endif
+            [[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookies:cookies forURL:url mainDocumentURL:mainDocumentURL];
+        return;
+    }
+#if (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101400) || (PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 120000)
+    if ([NSHTTPCookieStorage instancesRespondToSelector:@selector(_setCookies:forURL:mainDocumentURL:policyProperties:)]) {
+        // FIXME: Stop creating a new NSHTTPCookieStorage object each time we want to query the cookie jar.
+        // NetworkStorageSession could instead keep a NSHTTPCookieStorage object for us.
+        RetainPtr<NSHTTPCookieStorage> nsCookieStorage = adoptNS([[NSHTTPCookieStorage alloc] _initWithCFHTTPCookieStorage:cookieStorage]);
+        [nsCookieStorage _setCookies:cookies forURL:url mainDocumentURL:mainDocumentURL policyProperties:policyProperties(sameSiteInfo, url).get()];
+    } else {
+#endif
+        auto cfCookies = adoptCF([NSHTTPCookie _ns2cfCookies:cookies]);
+        CFHTTPCookieStorageSetCookies(cookieStorage, cfCookies.get(), [url _cfurl], [mainDocumentURL _cfurl]);
+#if (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101400) || (PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 120000)
+    }
+#else
+    UNUSED_PARAM(sameSiteInfo);
+#endif
+}
+
+static NSArray *httpCookiesForURL(CFHTTPCookieStorageRef cookieStorage, NSURL *firstParty, const std::optional<SameSiteInfo>& sameSiteInfo, NSURL *url)
+{
+    ASSERT(hasProcessPrivilege(ProcessPrivilege::CanAccessRawCookies));
+    if (!cookieStorage)
+        cookieStorage = _CFHTTPCookieStorageGetDefault(kCFAllocatorDefault);
+
+    // FIXME: Stop creating a new NSHTTPCookieStorage object each time we want to query the cookie jar.
+    // NetworkStorageSession could instead keep a NSHTTPCookieStorage object for us.
+    RetainPtr<NSHTTPCookieStorage> nsCookieStorage = adoptNS([[NSHTTPCookieStorage alloc] _initWithCFHTTPCookieStorage:cookieStorage]);
+    return cookiesForURL(nsCookieStorage.get(), url, firstParty, sameSiteInfo);
+}
+
+static RetainPtr<NSArray> filterCookies(NSArray *unfilteredCookies)
+{
+    ASSERT(hasProcessPrivilege(ProcessPrivilege::CanAccessRawCookies));
+    NSUInteger count = [unfilteredCookies count];
+    RetainPtr<NSMutableArray> filteredCookies = adoptNS([[NSMutableArray alloc] initWithCapacity:count]);
+
+    for (NSUInteger i = 0; i < count; ++i) {
+        NSHTTPCookie *cookie = (NSHTTPCookie *)[unfilteredCookies objectAtIndex:i];
+
+        // <rdar://problem/5632883> On 10.5, NSHTTPCookieStorage would store an empty cookie,
+        // which would be sent as "Cookie: =". We have a workaround in setCookies() to prevent
+        // that, but we also need to avoid sending cookies that were previously stored, and
+        // there's no harm to doing this check because such a cookie is never valid.
+        if (![[cookie name] length])
+            continue;
+
+        if ([cookie isHTTPOnly])
+            continue;
+
+        [filteredCookies.get() addObject:cookie];
+    }
+
+    return filteredCookies;
+}
+
+#if HAVE(CFNETWORK_STORAGE_PARTITIONING)
+
+static NSArray *applyPartitionToCookies(NSString *partition, NSArray *cookies)
+{
+    ASSERT(hasProcessPrivilege(ProcessPrivilege::CanAccessRawCookies));
+
+    // FIXME 24747739: CFNetwork should expose this key as SPI
+    static NSString * const partitionKey = @"StoragePartition";
+
+    NSMutableArray *partitionedCookies = [NSMutableArray arrayWithCapacity:cookies.count];
+    for (NSHTTPCookie *cookie in cookies) {
+        RetainPtr<NSMutableDictionary> properties = adoptNS([cookie.properties mutableCopy]);
+        [properties setObject:partition forKey:partitionKey];
+        [partitionedCookies addObject:[NSHTTPCookie cookieWithProperties:properties.get()]];
+    }
+
+    return partitionedCookies;
+}
+
+static bool cookiesAreBlockedForURL(const NetworkStorageSession& session, const URL& firstParty, const URL& url)
+{
+    return session.shouldBlockCookies(firstParty, url);
+}
+
+static NSArray *cookiesInPartitionForURL(const NetworkStorageSession& session, const URL& firstParty, const SameSiteInfo& sameSiteInfo, const URL& url, std::optional<uint64_t> frameID, std::optional<uint64_t> pageID)
+{
+    ASSERT(hasProcessPrivilege(ProcessPrivilege::CanAccessRawCookies));
+    String partition = session.cookieStoragePartition(firstParty, url, frameID, pageID);
+    if (partition.isEmpty())
+        return nil;
+
+    // FIXME: Stop creating a new NSHTTPCookieStorage object each time we want to query the cookie jar.
+    // NetworkStorageSession could instead keep a NSHTTPCookieStorage object for us.
+    RetainPtr<NSHTTPCookieStorage> cookieStorage;
+    if (auto storage = session.cookieStorage())
+        cookieStorage = adoptNS([[NSHTTPCookieStorage alloc] _initWithCFHTTPCookieStorage:storage.get()]);
+    else
+        cookieStorage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
+    return cookiesForURL(cookieStorage.get(), url, firstParty, sameSiteInfo, partition);
+}
+
+#endif // HAVE(CFNETWORK_STORAGE_PARTITIONING)
+    
+static NSArray *cookiesForURL(const NetworkStorageSession& session, const URL& firstParty, const SameSiteInfo& sameSiteInfo, const URL& url, std::optional<uint64_t> frameID, std::optional<uint64_t> pageID)
+{
+#if HAVE(CFNETWORK_STORAGE_PARTITIONING)
+    if (cookiesAreBlockedForURL(session, firstParty, url))
+        return nil;
+    
+    if (NSArray *cookies = cookiesInPartitionForURL(session, firstParty, sameSiteInfo, url, frameID, pageID))
+        return cookies;
+#else
+    UNUSED_PARAM(frameID);
+    UNUSED_PARAM(pageID);
+#endif
+    return httpCookiesForURL(session.cookieStorage().get(), firstParty, sameSiteInfo, url);
+}
+
+enum IncludeHTTPOnlyOrNot { DoNotIncludeHTTPOnly, IncludeHTTPOnly };
+static std::pair<String, bool> cookiesForSession(const NetworkStorageSession& session, const URL& firstParty, const SameSiteInfo& sameSiteInfo, const URL& url, std::optional<uint64_t> frameID, std::optional<uint64_t> pageID, IncludeHTTPOnlyOrNot includeHTTPOnly, IncludeSecureCookies includeSecureCookies)
+{
+    ASSERT(hasProcessPrivilege(ProcessPrivilege::CanAccessRawCookies));
+
+    BEGIN_BLOCK_OBJC_EXCEPTIONS;
+
+    NSArray *cookies = cookiesForURL(session, firstParty, sameSiteInfo, url, frameID, pageID);
+    if (![cookies count])
+        return { String(), false }; // Return a null string, not an empty one that StringBuilder would create below.
+
+    StringBuilder cookiesBuilder;
+    bool didAccessSecureCookies = false;
+    for (NSHTTPCookie *cookie in cookies) {
+        if (![[cookie name] length])
+            continue;
+
+        if (!includeHTTPOnly && [cookie isHTTPOnly])
+            continue;
+
+        if ([cookie isSecure]) {
+            didAccessSecureCookies = true;
+            if (includeSecureCookies == IncludeSecureCookies::No)
+                continue;
+        }
+
+        if (!cookiesBuilder.isEmpty())
+            cookiesBuilder.appendLiteral("; ");
+
+        cookiesBuilder.append([cookie name]);
+        cookiesBuilder.append('=');
+        cookiesBuilder.append([cookie value]);
+    }
+    return { cookiesBuilder.toString(), didAccessSecureCookies };
+
+    END_BLOCK_OBJC_EXCEPTIONS;
+    return { String(), false };
+}
+
+static void deleteAllHTTPCookies(CFHTTPCookieStorageRef cookieStorage)
+{
+    ASSERT(hasProcessPrivilege(ProcessPrivilege::CanAccessRawCookies));
+
+    if (!cookieStorage) {
+        NSHTTPCookieStorage *cookieStorage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
+        NSArray *cookies = [cookieStorage cookies];
+        if (!cookies)
+            return;
+
+        for (NSHTTPCookie *cookie in cookies)
+            [cookieStorage deleteCookie:cookie];
+        return;
+    }
+
+    CFHTTPCookieStorageDeleteAllCookies(cookieStorage);
+}
+
+std::pair<String, bool> NetworkStorageSession::cookiesForDOM(const URL& firstParty, const SameSiteInfo& sameSiteInfo, const URL& url, std::optional<uint64_t> frameID, std::optional<uint64_t> pageID, IncludeSecureCookies includeSecureCookies) const
+{
+    return cookiesForSession(*this, firstParty, sameSiteInfo, url, frameID, pageID, DoNotIncludeHTTPOnly, includeSecureCookies);
+}
+
+std::pair<String, bool> NetworkStorageSession::cookieRequestHeaderFieldValue(const URL& firstParty, const SameSiteInfo& sameSiteInfo, const URL& url, std::optional<uint64_t> frameID, std::optional<uint64_t> pageID, IncludeSecureCookies includeSecureCookies) const
+{
+    return cookiesForSession(*this, firstParty, sameSiteInfo, url, frameID, pageID, IncludeHTTPOnly, includeSecureCookies);
+}
+
+std::pair<String, bool> NetworkStorageSession::cookieRequestHeaderFieldValue(const CookieRequestHeaderFieldProxy& headerFieldProxy) const
+{
+    return cookiesForSession(*this, headerFieldProxy.firstParty, headerFieldProxy.sameSiteInfo, headerFieldProxy.url, headerFieldProxy.frameID, headerFieldProxy.pageID, IncludeHTTPOnly, headerFieldProxy.includeSecureCookies);
+}
+
+void NetworkStorageSession::setCookiesFromDOM(const URL& firstParty, const SameSiteInfo& sameSiteInfo, const URL& url, std::optional<uint64_t> frameID, std::optional<uint64_t> pageID, const String& cookieStr) const
+{
+    ASSERT(hasProcessPrivilege(ProcessPrivilege::CanAccessRawCookies));
+
+    BEGIN_BLOCK_OBJC_EXCEPTIONS;
+
+    // <rdar://problem/5632883> On 10.5, NSHTTPCookieStorage would store an empty cookie,
+    // which would be sent as "Cookie: =".
+    if (cookieStr.isEmpty())
+        return;
+
+    // <http://bugs.webkit.org/show_bug.cgi?id=6531>, <rdar://4409034>
+    // cookiesWithResponseHeaderFields doesn't parse cookies without a value
+    String cookieString = cookieStr.contains('=') ? cookieStr : cookieStr + "=";
+
+    NSURL *cookieURL = url;
+    NSDictionary *headerFields = [NSDictionary dictionaryWithObject:cookieString forKey:@"Set-Cookie"];
+
+#if PLATFORM(MAC)
+    NSArray *unfilteredCookies = [NSHTTPCookie _parsedCookiesWithResponseHeaderFields:headerFields forURL:cookieURL];
+#else
+    NSArray *unfilteredCookies = [NSHTTPCookie cookiesWithResponseHeaderFields:headerFields forURL:cookieURL];
+#endif
+
+    RetainPtr<NSArray> filteredCookies = filterCookies(unfilteredCookies);
+    ASSERT([filteredCookies.get() count] <= 1);
+
+#if HAVE(CFNETWORK_STORAGE_PARTITIONING)
+    if (shouldBlockCookies(firstParty, url))
+        return;
+
+    String partition = cookieStoragePartition(firstParty, url, frameID, pageID);
+    if (!partition.isEmpty())
+        filteredCookies = applyPartitionToCookies(partition, filteredCookies.get());
+#else
+    UNUSED_PARAM(frameID);
+    UNUSED_PARAM(pageID);
+#endif
+
+    setHTTPCookiesForURL(cookieStorage().get(), filteredCookies.get(), cookieURL, firstParty, sameSiteInfo);
+
+    END_BLOCK_OBJC_EXCEPTIONS;
+}
+
+static NSHTTPCookieAcceptPolicy httpCookieAcceptPolicy(CFHTTPCookieStorageRef cookieStorage)
+{
+    ASSERT(hasProcessPrivilege(ProcessPrivilege::CanAccessRawCookies));
+
+    if (!cookieStorage)
+        return [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookieAcceptPolicy];
+
+    return static_cast<NSHTTPCookieAcceptPolicy>(CFHTTPCookieStorageGetCookieAcceptPolicy(cookieStorage));
+}
+
+bool NetworkStorageSession::cookiesEnabled() const
+{
+    BEGIN_BLOCK_OBJC_EXCEPTIONS;
+
+    NSHTTPCookieAcceptPolicy cookieAcceptPolicy = httpCookieAcceptPolicy(cookieStorage().get());
+    return cookieAcceptPolicy == NSHTTPCookieAcceptPolicyAlways || cookieAcceptPolicy == NSHTTPCookieAcceptPolicyOnlyFromMainDocumentDomain || cookieAcceptPolicy == NSHTTPCookieAcceptPolicyExclusivelyFromMainDocumentDomain;
+
+    END_BLOCK_OBJC_EXCEPTIONS;
+    return false;
+}
+
+bool NetworkStorageSession::getRawCookies(const URL& firstParty, const SameSiteInfo& sameSiteInfo, const URL& url, std::optional<uint64_t> frameID, std::optional<uint64_t> pageID, Vector<Cookie>& rawCookies) const
+{
+    rawCookies.clear();
+    BEGIN_BLOCK_OBJC_EXCEPTIONS;
+
+    NSArray *cookies = cookiesForURL(*this, firstParty, sameSiteInfo, url, frameID, pageID);
+    NSUInteger count = [cookies count];
+    rawCookies.reserveCapacity(count);
+    for (NSUInteger i = 0; i < count; ++i) {
+        NSHTTPCookie *cookie = (NSHTTPCookie *)[cookies objectAtIndex:i];
+        rawCookies.uncheckedAppend({ cookie });
+    }
+
+    END_BLOCK_OBJC_EXCEPTIONS;
+    return true;
+}
+
+void NetworkStorageSession::deleteCookie(const URL& url, const String& cookieName) const
+{
+    ASSERT(hasProcessPrivilege(ProcessPrivilege::CanAccessRawCookies));
+
+    BEGIN_BLOCK_OBJC_EXCEPTIONS;
+
+    RetainPtr<CFHTTPCookieStorageRef> cookieStorage = this->cookieStorage();
+    NSArray *cookies = httpCookiesForURL(cookieStorage.get(), nil, std::nullopt, url);
+
+    NSString *cookieNameString = cookieName;
+
+    NSUInteger count = [cookies count];
+    for (NSUInteger i = 0; i < count; ++i) {
+        NSHTTPCookie *cookie = (NSHTTPCookie *)[cookies objectAtIndex:i];
+        if ([[cookie name] isEqualToString:cookieNameString])
+            deleteHTTPCookie(cookieStorage.get(), cookie);
+    }
+
+    END_BLOCK_OBJC_EXCEPTIONS;
+}
+
+void NetworkStorageSession::getHostnamesWithCookies(HashSet<String>& hostnames)
+{
+    BEGIN_BLOCK_OBJC_EXCEPTIONS;
+
+    NSArray *cookies = httpCookies(cookieStorage().get());
+    
+    for (NSHTTPCookie* cookie in cookies)
+        hostnames.add([cookie domain]);
+    
+    END_BLOCK_OBJC_EXCEPTIONS;
+}
+
+void NetworkStorageSession::deleteAllCookies()
+{
+    deleteAllHTTPCookies(cookieStorage().get());
+}
+
+void NetworkStorageSession::deleteCookiesForHostnames(const Vector<String>& hostnames)
+{
+    ASSERT(hasProcessPrivilege(ProcessPrivilege::CanAccessRawCookies));
+
+    BEGIN_BLOCK_OBJC_EXCEPTIONS;
+
+    RetainPtr<CFHTTPCookieStorageRef> cookieStorage = this->cookieStorage();
+    NSArray *cookies = httpCookies(cookieStorage.get());
+    if (!cookies)
+        return;
+
+    HashMap<String, Vector<RetainPtr<NSHTTPCookie>>> cookiesByDomain;
+    for (NSHTTPCookie* cookie in cookies) {
+        auto& cookies = cookiesByDomain.add(cookie.domain, Vector<RetainPtr<NSHTTPCookie>>()).iterator->value;
+        cookies.append(cookie);
+    }
+
+    for (const auto& hostname : hostnames) {
+        auto it = cookiesByDomain.find(hostname);
+        if (it == cookiesByDomain.end())
+            continue;
+
+        for (auto& cookie : it->value)
+            deleteHTTPCookie(cookieStorage.get(), cookie.get());
+    }
+
+    [nsCookieStorage() _saveCookies];
+
+    END_BLOCK_OBJC_EXCEPTIONS;
+}
+
+void NetworkStorageSession::deleteAllCookiesModifiedSince(WallTime timePoint)
+{
+    ASSERT(hasProcessPrivilege(ProcessPrivilege::CanAccessRawCookies));
+
+    if (![NSHTTPCookieStorage instancesRespondToSelector:@selector(removeCookiesSinceDate:)])
+        return;
+
+    NSTimeInterval timeInterval = timePoint.secondsSinceEpoch().seconds();
+    NSDate *date = [NSDate dateWithTimeIntervalSince1970:timeInterval];
+
+    auto *storage = nsCookieStorage();
+
+    [storage removeCookiesSinceDate:date];
+    [storage _saveCookies];
+}
+
 } // namespace WebCore
diff --git a/Source/WebCore/platform/network/curl/CookieJarCurl.cpp b/Source/WebCore/platform/network/curl/CookieJarCurl.cpp
deleted file mode 100644 (file)
index 5b4a245..0000000
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * Copyright (C) 2011 Apple Inc. All rights reserved.
- * Copyright (C) 2018 Sony Interactive Entertainment Inc.
- *
- *  This library is free software; you can redistribute it and/or
- *  modify it under the terms of the GNU Lesser General Public
- *  License as published by the Free Software Foundation; either
- *  version 2 of the License, or (at your option) any later version.
- *
- *  This library is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- *  Lesser General Public License for more details.
- *
- *  You should have received a copy of the GNU Lesser General Public
- *  License along with this library; if not, write to the Free Software
- *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- */
-
-#include "config.h"
-#include "CookieJarCurl.h"
-
-#if USE(CURL)
-#include "Cookie.h"
-#include "CookieRequestHeaderFieldProxy.h"
-#include "NetworkStorageSession.h"
-#include "URL.h"
-
-#include <wtf/text/WTFString.h>
-
-namespace WebCore {
-
-std::pair<String, bool> cookiesForDOM(const NetworkStorageSession& session, const URL& firstParty, const SameSiteInfo& sameSiteInfo, const URL& url, std::optional<uint64_t> frameID, std::optional<uint64_t> pageID, IncludeSecureCookies includeSecureCookies)
-{
-    return session.cookieStorage().cookiesForDOM(session, firstParty, sameSiteInfo, url, frameID, pageID, includeSecureCookies);
-}
-
-void setCookiesFromDOM(const NetworkStorageSession& session, const URL& firstParty, const SameSiteInfo& sameSiteInfo, const URL& url, std::optional<uint64_t> frameID, std::optional<uint64_t> pageID, const String& value)
-{
-    session.cookieStorage().setCookiesFromDOM(session, firstParty, sameSiteInfo, url, frameID, pageID, value);
-}
-
-std::pair<String, bool> cookieRequestHeaderFieldValue(const NetworkStorageSession& session, const URL& firstParty, const SameSiteInfo& sameSiteInfo, const URL& url, std::optional<uint64_t> frameID, std::optional<uint64_t> pageID, IncludeSecureCookies includeSecureCookies)
-{
-    return session.cookieStorage().cookieRequestHeaderFieldValue(session, firstParty, sameSiteInfo, url, frameID, pageID, includeSecureCookies);
-}
-
-std::pair<String, bool> cookieRequestHeaderFieldValue(const NetworkStorageSession& session, const CookieRequestHeaderFieldProxy& headerFieldProxy)
-{
-    return session.cookieStorage().cookieRequestHeaderFieldValue(session, headerFieldProxy.firstParty, headerFieldProxy.sameSiteInfo, headerFieldProxy.url, headerFieldProxy.frameID, headerFieldProxy.pageID, headerFieldProxy.includeSecureCookies);
-}
-
-bool cookiesEnabled(const NetworkStorageSession& session)
-{
-    return session.cookieStorage().cookiesEnabled(session);
-}
-
-bool getRawCookies(const NetworkStorageSession& session, const URL& firstParty, const SameSiteInfo& sameSiteInfo, const URL& url, std::optional<uint64_t> frameID, std::optional<uint64_t> pageID, Vector<Cookie>& rawCookies)
-{
-    return session.cookieStorage().getRawCookies(session, firstParty, sameSiteInfo, url, frameID, pageID, rawCookies);
-}
-
-void deleteCookie(const NetworkStorageSession& session, const URL& url, const String& cookie)
-{
-    session.cookieStorage().deleteCookie(session, url, cookie);
-}
-
-void getHostnamesWithCookies(const NetworkStorageSession& session, HashSet<String>& hostnames)
-{
-    session.cookieStorage().getHostnamesWithCookies(session, hostnames);
-}
-
-void deleteCookiesForHostnames(const NetworkStorageSession& session, const Vector<String>& cookieHostNames)
-{
-    session.cookieStorage().deleteCookiesForHostnames(session, cookieHostNames);
-}
-
-void deleteAllCookies(const NetworkStorageSession& session)
-{
-    session.cookieStorage().deleteAllCookies(session);
-}
-
-void deleteAllCookiesModifiedSince(const NetworkStorageSession& session, WallTime since)
-{
-    session.cookieStorage().deleteAllCookiesModifiedSince(session, since);
-}
-
-}
-
-#endif
index 2aa8dfd..e0b21cc 100644 (file)
 
 #pragma once
 
-#include "PlatformCookieJar.h"
+#include <wtf/Forward.h>
+#include <wtf/HashSet.h>
+#include <wtf/WallTime.h>
+#include <wtf/text/WTFString.h>
 
 namespace WebCore {
 
+class URL;
+class NetworkStorageSession;
+
+struct Cookie;
+struct CookieRequestHeaderFieldProxy;
+struct SameSiteInfo;
+
+enum class IncludeSecureCookies;
+
 class CookieJarCurl {
 public:
     virtual std::pair<String, bool> cookiesForDOM(const NetworkStorageSession&, const URL& firstParty, const SameSiteInfo&, const URL&, std::optional<uint64_t> frameID, std::optional<uint64_t> pageID, IncludeSecureCookies) const = 0;
index 061df19..86a41df 100644 (file)
 #include "Cookie.h"
 #include "CookieJarCurlDatabase.h"
 #include "CookieJarDB.h"
+#include "CookieRequestHeaderFieldProxy.h"
 #include "CurlContext.h"
 #include "FileSystem.h"
 #include "NetworkingContext.h"
 #include "ResourceHandle.h"
+#include "URL.h"
 
 #include <wtf/MainThread.h>
 #include <wtf/NeverDestroyed.h>
+#include <wtf/text/WTFString.h>
 
 namespace WebCore {
 
@@ -103,6 +106,21 @@ void NetworkStorageSession::switchToNewTestingSession()
     // FIXME: Implement for WebKit to use.
 }
 
+void NetworkStorageSession::setCookiesFromDOM(const URL& firstParty, const SameSiteInfo& sameSiteInfo, const URL& url, std::optional<uint64_t> frameID, std::optional<uint64_t> pageID, const String& value) const
+{
+    cookieStorage().setCookiesFromDOM(*this, firstParty, sameSiteInfo, url, frameID, pageID, value);
+}
+
+bool NetworkStorageSession::cookiesEnabled() const
+{
+    return cookieStorage().cookiesEnabled(*this);
+}
+
+std::pair<String, bool> NetworkStorageSession::cookiesForDOM(const URL& firstParty, const SameSiteInfo& sameSiteInfo, const URL& url, std::optional<uint64_t> frameID, std::optional<uint64_t> pageID, IncludeSecureCookies includeSecureCookies) const
+{
+    return cookieStorage().cookiesForDOM(*this, firstParty, sameSiteInfo, url, frameID, pageID, includeSecureCookies);
+}
+
 void NetworkStorageSession::setCookies(const Vector<Cookie>&, const URL&, const URL&)
 {
     // FIXME: Implement for WebKit to use.
@@ -118,23 +136,63 @@ void NetworkStorageSession::deleteCookie(const Cookie&)
     // FIXME: Implement for WebKit to use.
 }
 
+void NetworkStorageSession::deleteCookie(const URL& url, const String& cookie) const
+{
+    cookieStorage().deleteCookie(*this, url, cookie);
+}
+
+void NetworkStorageSession::deleteAllCookies()
+{
+    cookieStorage().deleteAllCookies(*this);
+}
+
+void NetworkStorageSession::deleteAllCookiesModifiedSince(WallTime since)
+{
+    cookieStorage().deleteAllCookiesModifiedSince(*this, since);
+}
+
+void NetworkStorageSession::deleteCookiesForHostnames(const Vector<String>& cookieHostNames)
+{
+    cookieStorage().deleteCookiesForHostnames(*this, cookieHostNames);
+}
+
 Vector<Cookie> NetworkStorageSession::getAllCookies()
 {
     // FIXME: Implement for WebKit to use.
     return { };
 }
 
+void NetworkStorageSession::getHostnamesWithCookies(HashSet<String>& hostnames)
+{
+    cookieStorage().getHostnamesWithCookies(*this, hostnames);
+}
+
 Vector<Cookie> NetworkStorageSession::getCookies(const URL&)
 {
     // FIXME: Implement for WebKit to use.
     return { };
 }
 
+bool NetworkStorageSession::getRawCookies(const URL& firstParty, const SameSiteInfo& sameSiteInfo, const URL& url, std::optional<uint64_t> frameID, std::optional<uint64_t> pageID, Vector<Cookie>& rawCookies) const
+{
+    return cookieStorage().getRawCookies(*this, firstParty, sameSiteInfo, url, frameID, pageID, rawCookies);
+}
+
 void NetworkStorageSession::flushCookieStore()
 {
     // FIXME: Implement for WebKit to use.
 }
 
+std::pair<String, bool> NetworkStorageSession::cookieRequestHeaderFieldValue(const URL& firstParty, const SameSiteInfo& sameSiteInfo, const URL& url, std::optional<uint64_t> frameID, std::optional<uint64_t> pageID, IncludeSecureCookies includeSecureCookies) const
+{
+    return cookieStorage().cookieRequestHeaderFieldValue(*this, firstParty, sameSiteInfo, url, frameID, pageID, includeSecureCookies);
+}
+
+std::pair<String, bool> NetworkStorageSession::cookieRequestHeaderFieldValue(const CookieRequestHeaderFieldProxy& headerFieldProxy) const
+{
+    return cookieStorage().cookieRequestHeaderFieldValue(*this, headerFieldProxy.firstParty, headerFieldProxy.sameSiteInfo, headerFieldProxy.url, headerFieldProxy.frameID, headerFieldProxy.pageID, headerFieldProxy.includeSecureCookies);
+}
+
 } // namespace WebCore
 
 #endif // USE(CURL)
diff --git a/Source/WebCore/platform/network/mac/CookieJarMac.mm b/Source/WebCore/platform/network/mac/CookieJarMac.mm
deleted file mode 100644 (file)
index c2640bd..0000000
+++ /dev/null
@@ -1,470 +0,0 @@
-/*
- * Copyright (C) 2003-2018 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#import "config.h"
-#import "PlatformCookieJar.h"
-
-#import "CookieRequestHeaderFieldProxy.h"
-#import "CookiesStrategy.h"
-#import "NetworkStorageSession.h"
-#import <pal/spi/cf/CFNetworkSPI.h>
-#import <wtf/BlockObjCExceptions.h>
-
-#import "Cookie.h"
-#import "CookieStorage.h"
-#import "SameSiteInfo.h"
-#import "URL.h"
-#import <wtf/Optional.h>
-#import <wtf/ProcessPrivilege.h>
-#import <wtf/text/StringBuilder.h>
-
-@interface NSURL ()
-- (CFURLRef)_cfurl;
-@end
-
-#if (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101400) || (PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 120000)
-@interface NSHTTPCookieStorage (Staging)
-- (void)_getCookiesForURL:(NSURL *)url mainDocumentURL:(NSURL *)mainDocumentURL partition:(NSString *)partition policyProperties:(NSDictionary*)props completionHandler:(void (^)(NSArray *))completionHandler;
-- (void)_setCookies:(NSArray *)cookies forURL:(NSURL *)URL mainDocumentURL:(NSURL *)mainDocumentURL policyProperties:(NSDictionary*) props;
-@end
-#endif
-
-namespace WebCore {
-
-static NSArray *httpCookies(CFHTTPCookieStorageRef cookieStorage)
-{
-    ASSERT(hasProcessPrivilege(ProcessPrivilege::CanAccessRawCookies));
-    if (!cookieStorage)
-        return [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookies];
-    
-    auto cookies = adoptCF(CFHTTPCookieStorageCopyCookies(cookieStorage));
-    return [NSHTTPCookie _cf2nsCookies:cookies.get()];
-}
-
-static void deleteHTTPCookie(CFHTTPCookieStorageRef cookieStorage, NSHTTPCookie *cookie)
-{
-    ASSERT(hasProcessPrivilege(ProcessPrivilege::CanAccessRawCookies));
-    if (!cookieStorage) {
-        [[NSHTTPCookieStorage sharedHTTPCookieStorage] deleteCookie:cookie];
-        return;
-    }
-    
-    CFHTTPCookieStorageDeleteCookie(cookieStorage, [cookie _GetInternalCFHTTPCookie]);
-}
-
-#if (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101400) || (PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 120000)
-static RetainPtr<NSDictionary> policyProperties(const SameSiteInfo& sameSiteInfo, NSURL *url)
-{
-    static NSURL *emptyURL = [[NSURL alloc] initWithString:@""];
-    NSDictionary *policyProperties = @{
-        @"_kCFHTTPCookiePolicyPropertySiteForCookies": sameSiteInfo.isSameSite ? url : emptyURL,
-        @"_kCFHTTPCookiePolicyPropertyIsTopLevelNavigation": [NSNumber numberWithBool:sameSiteInfo.isTopSite],
-    };
-    return policyProperties;
-}
-#endif
-
-static NSArray *cookiesForURL(NSHTTPCookieStorage *storage, NSURL *url, NSURL *mainDocumentURL, const std::optional<SameSiteInfo>& sameSiteInfo, NSString *partition = nullptr)
-{
-    // The _getCookiesForURL: method calls the completionHandler synchronously. We use std::optional<> to ensure this invariant.
-    std::optional<RetainPtr<NSArray *>> cookiesPtr;
-    auto completionHandler = [&cookiesPtr] (NSArray *cookies) { cookiesPtr = retainPtr(cookies); };
-#if (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101400) || (PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 120000)
-    if ([storage respondsToSelector:@selector(_getCookiesForURL:mainDocumentURL:partition:policyProperties:completionHandler:)])
-        [storage _getCookiesForURL:url mainDocumentURL:mainDocumentURL partition:partition policyProperties:sameSiteInfo ? policyProperties(sameSiteInfo.value(), url).get() : nullptr completionHandler:completionHandler];
-    else
-        [storage _getCookiesForURL:url mainDocumentURL:mainDocumentURL partition:partition completionHandler:completionHandler];
-#else
-    [storage _getCookiesForURL:url mainDocumentURL:mainDocumentURL partition:partition completionHandler:completionHandler];
-    UNUSED_PARAM(sameSiteInfo);
-#endif
-    ASSERT(!!cookiesPtr);
-    return cookiesPtr->autorelease();
-}
-
-static void setHTTPCookiesForURL(CFHTTPCookieStorageRef cookieStorage, NSArray *cookies, NSURL *url, NSURL *mainDocumentURL, const SameSiteInfo& sameSiteInfo)
-{
-    ASSERT(hasProcessPrivilege(ProcessPrivilege::CanAccessRawCookies));
-    if (!cookieStorage) {
-#if (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101400) || (PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 120000)
-        if ([NSHTTPCookieStorage instancesRespondToSelector:@selector(_setCookies:forURL:mainDocumentURL:policyProperties:)])
-            [[NSHTTPCookieStorage sharedHTTPCookieStorage] _setCookies:cookies forURL:url mainDocumentURL:mainDocumentURL policyProperties:policyProperties(sameSiteInfo, url).get()];
-        else
-#endif
-            [[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookies:cookies forURL:url mainDocumentURL:mainDocumentURL];
-        return;
-    }
-#if (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101400) || (PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 120000)
-    if ([NSHTTPCookieStorage instancesRespondToSelector:@selector(_setCookies:forURL:mainDocumentURL:policyProperties:)]) {
-        // FIXME: Stop creating a new NSHTTPCookieStorage object each time we want to query the cookie jar.
-        // NetworkStorageSession could instead keep a NSHTTPCookieStorage object for us.
-        RetainPtr<NSHTTPCookieStorage> nsCookieStorage = adoptNS([[NSHTTPCookieStorage alloc] _initWithCFHTTPCookieStorage:cookieStorage]);
-        [nsCookieStorage _setCookies:cookies forURL:url mainDocumentURL:mainDocumentURL policyProperties:policyProperties(sameSiteInfo, url).get()];
-    } else {
-#endif
-        auto cfCookies = adoptCF([NSHTTPCookie _ns2cfCookies:cookies]);
-        CFHTTPCookieStorageSetCookies(cookieStorage, cfCookies.get(), [url _cfurl], [mainDocumentURL _cfurl]);
-#if (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101400) || (PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 120000)
-    }
-#else
-    UNUSED_PARAM(sameSiteInfo);
-#endif
-}
-
-static NSArray *httpCookiesForURL(CFHTTPCookieStorageRef cookieStorage, NSURL *firstParty, const std::optional<SameSiteInfo>& sameSiteInfo, NSURL *url)
-{
-    ASSERT(hasProcessPrivilege(ProcessPrivilege::CanAccessRawCookies));
-    if (!cookieStorage)
-        cookieStorage = _CFHTTPCookieStorageGetDefault(kCFAllocatorDefault);
-
-    // FIXME: Stop creating a new NSHTTPCookieStorage object each time we want to query the cookie jar.
-    // NetworkStorageSession could instead keep a NSHTTPCookieStorage object for us.
-    RetainPtr<NSHTTPCookieStorage> nsCookieStorage = adoptNS([[NSHTTPCookieStorage alloc] _initWithCFHTTPCookieStorage:cookieStorage]);
-    return cookiesForURL(nsCookieStorage.get(), url, firstParty, sameSiteInfo);
-}
-
-static RetainPtr<NSArray> filterCookies(NSArray *unfilteredCookies)
-{
-    ASSERT(hasProcessPrivilege(ProcessPrivilege::CanAccessRawCookies));
-    NSUInteger count = [unfilteredCookies count];
-    RetainPtr<NSMutableArray> filteredCookies = adoptNS([[NSMutableArray alloc] initWithCapacity:count]);
-
-    for (NSUInteger i = 0; i < count; ++i) {
-        NSHTTPCookie *cookie = (NSHTTPCookie *)[unfilteredCookies objectAtIndex:i];
-
-        // <rdar://problem/5632883> On 10.5, NSHTTPCookieStorage would store an empty cookie,
-        // which would be sent as "Cookie: =". We have a workaround in setCookies() to prevent
-        // that, but we also need to avoid sending cookies that were previously stored, and
-        // there's no harm to doing this check because such a cookie is never valid.
-        if (![[cookie name] length])
-            continue;
-
-        if ([cookie isHTTPOnly])
-            continue;
-
-        [filteredCookies.get() addObject:cookie];
-    }
-
-    return filteredCookies;
-}
-
-#if HAVE(CFNETWORK_STORAGE_PARTITIONING)
-
-static NSArray *applyPartitionToCookies(NSString *partition, NSArray *cookies)
-{
-    ASSERT(hasProcessPrivilege(ProcessPrivilege::CanAccessRawCookies));
-
-    // FIXME 24747739: CFNetwork should expose this key as SPI
-    static NSString * const partitionKey = @"StoragePartition";
-
-    NSMutableArray *partitionedCookies = [NSMutableArray arrayWithCapacity:cookies.count];
-    for (NSHTTPCookie *cookie in cookies) {
-        RetainPtr<NSMutableDictionary> properties = adoptNS([cookie.properties mutableCopy]);
-        [properties setObject:partition forKey:partitionKey];
-        [partitionedCookies addObject:[NSHTTPCookie cookieWithProperties:properties.get()]];
-    }
-
-    return partitionedCookies;
-}
-
-static bool cookiesAreBlockedForURL(const NetworkStorageSession& session, const URL& firstParty, const URL& url)
-{
-    return session.shouldBlockCookies(firstParty, url);
-}
-
-static NSArray *cookiesInPartitionForURL(const NetworkStorageSession& session, const URL& firstParty, const SameSiteInfo& sameSiteInfo, const URL& url, std::optional<uint64_t> frameID, std::optional<uint64_t> pageID)
-{
-    ASSERT(hasProcessPrivilege(ProcessPrivilege::CanAccessRawCookies));
-    String partition = session.cookieStoragePartition(firstParty, url, frameID, pageID);
-    if (partition.isEmpty())
-        return nil;
-
-    // FIXME: Stop creating a new NSHTTPCookieStorage object each time we want to query the cookie jar.
-    // NetworkStorageSession could instead keep a NSHTTPCookieStorage object for us.
-    RetainPtr<NSHTTPCookieStorage> cookieStorage;
-    if (auto storage = session.cookieStorage())
-        cookieStorage = adoptNS([[NSHTTPCookieStorage alloc] _initWithCFHTTPCookieStorage:storage.get()]);
-    else
-        cookieStorage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
-    return cookiesForURL(cookieStorage.get(), url, firstParty, sameSiteInfo, partition);
-}
-
-#endif // HAVE(CFNETWORK_STORAGE_PARTITIONING)
-    
-static NSArray *cookiesForURL(const NetworkStorageSession& session, const URL& firstParty, const SameSiteInfo& sameSiteInfo, const URL& url, std::optional<uint64_t> frameID, std::optional<uint64_t> pageID)
-{
-#if HAVE(CFNETWORK_STORAGE_PARTITIONING)
-    if (cookiesAreBlockedForURL(session, firstParty, url))
-        return nil;
-    
-    if (NSArray *cookies = cookiesInPartitionForURL(session, firstParty, sameSiteInfo, url, frameID, pageID))
-        return cookies;
-#else
-    UNUSED_PARAM(frameID);
-    UNUSED_PARAM(pageID);
-#endif
-    return httpCookiesForURL(session.cookieStorage().get(), firstParty, sameSiteInfo, url);
-}
-
-enum IncludeHTTPOnlyOrNot { DoNotIncludeHTTPOnly, IncludeHTTPOnly };
-static std::pair<String, bool> cookiesForSession(const NetworkStorageSession& session, const URL& firstParty, const SameSiteInfo& sameSiteInfo, const URL& url, std::optional<uint64_t> frameID, std::optional<uint64_t> pageID, IncludeHTTPOnlyOrNot includeHTTPOnly, IncludeSecureCookies includeSecureCookies)
-{
-    ASSERT(hasProcessPrivilege(ProcessPrivilege::CanAccessRawCookies));
-
-    BEGIN_BLOCK_OBJC_EXCEPTIONS;
-
-    NSArray *cookies = cookiesForURL(session, firstParty, sameSiteInfo, url, frameID, pageID);
-    if (![cookies count])
-        return { String(), false }; // Return a null string, not an empty one that StringBuilder would create below.
-
-    StringBuilder cookiesBuilder;
-    bool didAccessSecureCookies = false;
-    for (NSHTTPCookie *cookie in cookies) {
-        if (![[cookie name] length])
-            continue;
-
-        if (!includeHTTPOnly && [cookie isHTTPOnly])
-            continue;
-
-        if ([cookie isSecure]) {
-            didAccessSecureCookies = true;
-            if (includeSecureCookies == IncludeSecureCookies::No)
-                continue;
-        }
-
-        if (!cookiesBuilder.isEmpty())
-            cookiesBuilder.appendLiteral("; ");
-
-        cookiesBuilder.append([cookie name]);
-        cookiesBuilder.append('=');
-        cookiesBuilder.append([cookie value]);
-    }
-    return { cookiesBuilder.toString(), didAccessSecureCookies };
-
-    END_BLOCK_OBJC_EXCEPTIONS;
-    return { String(), false };
-}
-
-static void deleteAllHTTPCookies(CFHTTPCookieStorageRef cookieStorage)
-{
-    ASSERT(hasProcessPrivilege(ProcessPrivilege::CanAccessRawCookies));
-
-    if (!cookieStorage) {
-        NSHTTPCookieStorage *cookieStorage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
-        NSArray *cookies = [cookieStorage cookies];
-        if (!cookies)
-            return;
-
-        for (NSHTTPCookie *cookie in cookies)
-            [cookieStorage deleteCookie:cookie];
-        return;
-    }
-
-    CFHTTPCookieStorageDeleteAllCookies(cookieStorage);
-}
-
-std::pair<String, bool> cookiesForDOM(const NetworkStorageSession& session, const URL& firstParty, const SameSiteInfo& sameSiteInfo, const URL& url, std::optional<uint64_t> frameID, std::optional<uint64_t> pageID, IncludeSecureCookies includeSecureCookies)
-{
-    return cookiesForSession(session, firstParty, sameSiteInfo, url, frameID, pageID, DoNotIncludeHTTPOnly, includeSecureCookies);
-}
-
-std::pair<String, bool> cookieRequestHeaderFieldValue(const NetworkStorageSession& session, const URL& firstParty, const SameSiteInfo& sameSiteInfo, const URL& url, std::optional<uint64_t> frameID, std::optional<uint64_t> pageID, IncludeSecureCookies includeSecureCookies)
-{
-    return cookiesForSession(session, firstParty, sameSiteInfo, url, frameID, pageID, IncludeHTTPOnly, includeSecureCookies);
-}
-
-std::pair<String, bool> cookieRequestHeaderFieldValue(const NetworkStorageSession& session, const CookieRequestHeaderFieldProxy& headerFieldProxy)
-{
-    return cookiesForSession(session, headerFieldProxy.firstParty, headerFieldProxy.sameSiteInfo, headerFieldProxy.url, headerFieldProxy.frameID, headerFieldProxy.pageID, IncludeHTTPOnly, headerFieldProxy.includeSecureCookies);
-}
-
-void setCookiesFromDOM(const NetworkStorageSession& session, const URL& firstParty, const SameSiteInfo& sameSiteInfo, const URL& url, std::optional<uint64_t> frameID, std::optional<uint64_t> pageID, const String& cookieStr)
-{
-    ASSERT(hasProcessPrivilege(ProcessPrivilege::CanAccessRawCookies));
-
-    BEGIN_BLOCK_OBJC_EXCEPTIONS;
-
-    // <rdar://problem/5632883> On 10.5, NSHTTPCookieStorage would store an empty cookie,
-    // which would be sent as "Cookie: =".
-    if (cookieStr.isEmpty())
-        return;
-
-    // <http://bugs.webkit.org/show_bug.cgi?id=6531>, <rdar://4409034>
-    // cookiesWithResponseHeaderFields doesn't parse cookies without a value
-    String cookieString = cookieStr.contains('=') ? cookieStr : cookieStr + "=";
-
-    NSURL *cookieURL = url;
-    NSDictionary *headerFields = [NSDictionary dictionaryWithObject:cookieString forKey:@"Set-Cookie"];
-
-#if PLATFORM(MAC)
-    NSArray *unfilteredCookies = [NSHTTPCookie _parsedCookiesWithResponseHeaderFields:headerFields forURL:cookieURL];
-#else
-    NSArray *unfilteredCookies = [NSHTTPCookie cookiesWithResponseHeaderFields:headerFields forURL:cookieURL];
-#endif
-
-    RetainPtr<NSArray> filteredCookies = filterCookies(unfilteredCookies);
-    ASSERT([filteredCookies.get() count] <= 1);
-
-#if HAVE(CFNETWORK_STORAGE_PARTITIONING)
-    if (session.shouldBlockCookies(firstParty, url))
-        return;
-
-    String partition = session.cookieStoragePartition(firstParty, url, frameID, pageID);
-    if (!partition.isEmpty())
-        filteredCookies = applyPartitionToCookies(partition, filteredCookies.get());
-#else
-    UNUSED_PARAM(frameID);
-    UNUSED_PARAM(pageID);
-#endif
-
-    setHTTPCookiesForURL(session.cookieStorage().get(), filteredCookies.get(), cookieURL, firstParty, sameSiteInfo);
-
-    END_BLOCK_OBJC_EXCEPTIONS;
-}
-
-static NSHTTPCookieAcceptPolicy httpCookieAcceptPolicy(CFHTTPCookieStorageRef cookieStorage)
-{
-    ASSERT(hasProcessPrivilege(ProcessPrivilege::CanAccessRawCookies));
-
-    if (!cookieStorage)
-        return [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookieAcceptPolicy];
-
-    return static_cast<NSHTTPCookieAcceptPolicy>(CFHTTPCookieStorageGetCookieAcceptPolicy(cookieStorage));
-}
-
-bool cookiesEnabled(const NetworkStorageSession& session)
-{
-    BEGIN_BLOCK_OBJC_EXCEPTIONS;
-
-    NSHTTPCookieAcceptPolicy cookieAcceptPolicy = httpCookieAcceptPolicy(session.cookieStorage().get());
-    return cookieAcceptPolicy == NSHTTPCookieAcceptPolicyAlways || cookieAcceptPolicy == NSHTTPCookieAcceptPolicyOnlyFromMainDocumentDomain || cookieAcceptPolicy == NSHTTPCookieAcceptPolicyExclusivelyFromMainDocumentDomain;
-
-    END_BLOCK_OBJC_EXCEPTIONS;
-    return false;
-}
-
-bool getRawCookies(const NetworkStorageSession& session, const URL& firstParty, const SameSiteInfo& sameSiteInfo, const URL& url, std::optional<uint64_t> frameID, std::optional<uint64_t> pageID, Vector<Cookie>& rawCookies)
-{
-    rawCookies.clear();
-    BEGIN_BLOCK_OBJC_EXCEPTIONS;
-
-    NSArray *cookies = cookiesForURL(session, firstParty, sameSiteInfo, url, frameID, pageID);
-    NSUInteger count = [cookies count];
-    rawCookies.reserveCapacity(count);
-    for (NSUInteger i = 0; i < count; ++i) {
-        NSHTTPCookie *cookie = (NSHTTPCookie *)[cookies objectAtIndex:i];
-        rawCookies.uncheckedAppend({ cookie });
-    }
-
-    END_BLOCK_OBJC_EXCEPTIONS;
-    return true;
-}
-
-void deleteCookie(const NetworkStorageSession& session, const URL& url, const String& cookieName)
-{
-    ASSERT(hasProcessPrivilege(ProcessPrivilege::CanAccessRawCookies));
-
-    BEGIN_BLOCK_OBJC_EXCEPTIONS;
-
-    RetainPtr<CFHTTPCookieStorageRef> cookieStorage = session.cookieStorage();
-    NSArray *cookies = httpCookiesForURL(cookieStorage.get(), nil, std::nullopt, url);
-
-    NSString *cookieNameString = cookieName;
-
-    NSUInteger count = [cookies count];
-    for (NSUInteger i = 0; i < count; ++i) {
-        NSHTTPCookie *cookie = (NSHTTPCookie *)[cookies objectAtIndex:i];
-        if ([[cookie name] isEqualToString:cookieNameString])
-            deleteHTTPCookie(cookieStorage.get(), cookie);
-    }
-
-    END_BLOCK_OBJC_EXCEPTIONS;
-}
-
-void getHostnamesWithCookies(const NetworkStorageSession& session, HashSet<String>& hostnames)
-{
-    BEGIN_BLOCK_OBJC_EXCEPTIONS;
-
-    NSArray *cookies = httpCookies(session.cookieStorage().get());
-    
-    for (NSHTTPCookie* cookie in cookies)
-        hostnames.add([cookie domain]);
-    
-    END_BLOCK_OBJC_EXCEPTIONS;
-}
-
-void deleteAllCookies(const NetworkStorageSession& session)
-{
-    deleteAllHTTPCookies(session.cookieStorage().get());
-}
-
-void deleteCookiesForHostnames(const NetworkStorageSession& session, const Vector<String>& hostnames)
-{
-    ASSERT(hasProcessPrivilege(ProcessPrivilege::CanAccessRawCookies));
-
-    BEGIN_BLOCK_OBJC_EXCEPTIONS;
-
-    RetainPtr<CFHTTPCookieStorageRef> cookieStorage = session.cookieStorage();
-    NSArray *cookies = httpCookies(cookieStorage.get());
-    if (!cookies)
-        return;
-
-    HashMap<String, Vector<RetainPtr<NSHTTPCookie>>> cookiesByDomain;
-    for (NSHTTPCookie* cookie in cookies) {
-        auto& cookies = cookiesByDomain.add(cookie.domain, Vector<RetainPtr<NSHTTPCookie>>()).iterator->value;
-        cookies.append(cookie);
-    }
-
-    for (const auto& hostname : hostnames) {
-        auto it = cookiesByDomain.find(hostname);
-        if (it == cookiesByDomain.end())
-            continue;
-
-        for (auto& cookie : it->value)
-            deleteHTTPCookie(cookieStorage.get(), cookie.get());
-    }
-
-    [session.nsCookieStorage() _saveCookies];
-
-    END_BLOCK_OBJC_EXCEPTIONS;
-}
-
-void deleteAllCookiesModifiedSince(const NetworkStorageSession& session, WallTime timePoint)
-{
-    ASSERT(hasProcessPrivilege(ProcessPrivilege::CanAccessRawCookies));
-
-    if (![NSHTTPCookieStorage instancesRespondToSelector:@selector(removeCookiesSinceDate:)])
-        return;
-
-    NSTimeInterval timeInterval = timePoint.secondsSinceEpoch().seconds();
-    NSDate *date = [NSDate dateWithTimeIntervalSince1970:timeInterval];
-
-    auto *storage = session.nsCookieStorage();
-
-    [storage removeCookiesSinceDate:date];
-    [storage _saveCookies];
-}
-
-}
index 8876310..b3e907f 100644 (file)
@@ -29,6 +29,7 @@
 #import "AuthenticationChallenge.h"
 #import "AuthenticationMac.h"
 #import "Logging.h"
+#import "NetworkingContext.h"
 #import "ResourceHandle.h"
 #import "ResourceHandleClient.h"
 #import "ResourceRequest.h"
diff --git a/Source/WebCore/platform/network/soup/CookieJarSoup.cpp b/Source/WebCore/platform/network/soup/CookieJarSoup.cpp
deleted file mode 100644 (file)
index 5ee8761..0000000
+++ /dev/null
@@ -1,260 +0,0 @@
-/*
- *  Copyright (C) 2008 Xan Lopez <xan@gnome.org>
- *  Copyright (C) 2009 Igalia S.L.
- *  Copyright (C) 2008 Apple Inc. All rights reserved.
- *
- *  This library is free software; you can redistribute it and/or
- *  modify it under the terms of the GNU Lesser General Public
- *  License as published by the Free Software Foundation; either
- *  version 2 of the License, or (at your option) any later version.
- *
- *  This library is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- *  Lesser General Public License for more details.
- *
- *  You should have received a copy of the GNU Lesser General Public
- *  License along with this library; if not, write to the Free Software
- *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- */
-
-#include "config.h"
-
-#if USE(SOUP)
-
-#include "Cookie.h"
-#include "CookieRequestHeaderFieldProxy.h"
-#include "CookiesStrategy.h"
-#include "GUniquePtrSoup.h"
-#include "NetworkStorageSession.h"
-#include "NetworkingContext.h"
-#include "PlatformCookieJar.h"
-#include "SoupNetworkSession.h"
-#include "URL.h"
-#include <wtf/DateMath.h>
-#include <wtf/glib/GRefPtr.h>
-#include <wtf/text/CString.h>
-
-namespace WebCore {
-
-static inline bool httpOnlyCookieExists(const GSList* cookies, const gchar* name, const gchar* path)
-{
-    for (const GSList* iter = cookies; iter; iter = g_slist_next(iter)) {
-        SoupCookie* cookie = static_cast<SoupCookie*>(iter->data);
-        if (!strcmp(soup_cookie_get_name(cookie), name)
-            && !g_strcmp0(soup_cookie_get_path(cookie), path)) {
-            if (soup_cookie_get_http_only(cookie))
-                return true;
-            break;
-        }
-    }
-    return false;
-}
-
-void setCookiesFromDOM(const NetworkStorageSession& session, const URL& firstParty, const SameSiteInfo&, const URL& url, std::optional<uint64_t> frameID, std::optional<uint64_t> pageID, const String& value)
-{
-    UNUSED_PARAM(frameID);
-    UNUSED_PARAM(pageID);
-    GUniquePtr<SoupURI> origin = url.createSoupURI();
-    if (!origin)
-        return;
-
-    GUniquePtr<SoupURI> firstPartyURI = firstParty.createSoupURI();
-    if (!firstPartyURI)
-        return;
-
-    // Get existing cookies for this origin.
-    SoupCookieJar* jar = session.cookieStorage();
-    GSList* existingCookies = soup_cookie_jar_get_cookie_list(jar, origin.get(), TRUE);
-
-    for (auto& cookieString : value.split('\n')) {
-        GUniquePtr<SoupCookie> cookie(soup_cookie_parse(cookieString.utf8().data(), origin.get()));
-        if (!cookie)
-            continue;
-
-        // Make sure the cookie is not httpOnly since such cookies should not be set from JavaScript.
-        if (soup_cookie_get_http_only(cookie.get()))
-            continue;
-
-        // Make sure we do not overwrite httpOnly cookies from JavaScript.
-        if (httpOnlyCookieExists(existingCookies, soup_cookie_get_name(cookie.get()), soup_cookie_get_path(cookie.get())))
-            continue;
-
-        soup_cookie_jar_add_cookie_with_first_party(jar, firstPartyURI.get(), cookie.release());
-    }
-
-    soup_cookies_free(existingCookies);
-}
-
-static std::pair<String, bool> cookiesForSession(const NetworkStorageSession& session, const URL& url, bool forHTTPHeader, IncludeSecureCookies includeSecureCookies)
-{
-    GUniquePtr<SoupURI> uri = url.createSoupURI();
-    if (!uri)
-        return { { }, false };
-
-    GSList* cookies = soup_cookie_jar_get_cookie_list(session.cookieStorage(), uri.get(), forHTTPHeader);
-    bool didAccessSecureCookies = false;
-
-    // libsoup should omit secure cookies itself if the protocol is not https.
-    if (url.protocolIs("https")) {
-        GSList* item = cookies;
-        while (item) {
-            auto cookie = static_cast<SoupCookie*>(item->data);
-            if (soup_cookie_get_secure(cookie)) {
-                didAccessSecureCookies = true;
-                if (includeSecureCookies == IncludeSecureCookies::No) {
-                    GSList* next = item->next;
-                    soup_cookie_free(static_cast<SoupCookie*>(item->data));
-                    cookies = g_slist_remove_link(cookies, item);
-                    item = next;
-                    continue;
-                }
-            }
-            item = item->next;
-        }
-    }
-
-    if (!cookies)
-        return { { }, false };
-
-    GUniquePtr<char> cookieHeader(soup_cookies_to_cookie_header(cookies));
-    soup_cookies_free(cookies);
-
-    return { String::fromUTF8(cookieHeader.get()), didAccessSecureCookies };
-}
-
-std::pair<String, bool> cookiesForDOM(const NetworkStorageSession& session, const URL& firstParty, const SameSiteInfo&, const URL& url, std::optional<uint64_t> frameID, std::optional<uint64_t> pageID, IncludeSecureCookies includeSecureCookies)
-{
-    UNUSED_PARAM(firstParty);
-    UNUSED_PARAM(frameID);
-    UNUSED_PARAM(pageID);
-    return cookiesForSession(session, url, false, includeSecureCookies);
-}
-
-std::pair<String, bool> cookieRequestHeaderFieldValue(const NetworkStorageSession& session, const URL& firstParty, const SameSiteInfo&, const URL& url, std::optional<uint64_t> frameID, std::optional<uint64_t> pageID, IncludeSecureCookies includeSecureCookies)
-{
-    UNUSED_PARAM(firstParty);
-    UNUSED_PARAM(frameID);
-    UNUSED_PARAM(pageID);
-    // Secure cookies will still only be included if url's protocol is https.
-    return cookiesForSession(session, url, true, includeSecureCookies);
-}
-
-std::pair<String, bool> cookieRequestHeaderFieldValue(const NetworkStorageSession& session, const CookieRequestHeaderFieldProxy& headerFieldProxy)
-{
-    return cookieRequestHeaderFieldValue(session, headerFieldProxy.firstParty, headerFieldProxy.sameSiteInfo, headerFieldProxy.url, headerFieldProxy.frameID, headerFieldProxy.pageID, headerFieldProxy.includeSecureCookies);
-}
-
-bool cookiesEnabled(const NetworkStorageSession& session)
-{
-    auto policy = soup_cookie_jar_get_accept_policy(session.cookieStorage());
-    return policy == SOUP_COOKIE_JAR_ACCEPT_ALWAYS || policy == SOUP_COOKIE_JAR_ACCEPT_NO_THIRD_PARTY;
-}
-
-bool getRawCookies(const NetworkStorageSession& session, const URL& firstParty, const SameSiteInfo&, const URL& url, std::optional<uint64_t> frameID, std::optional<uint64_t> pageID, Vector<Cookie>& rawCookies)
-{
-    UNUSED_PARAM(firstParty);
-    UNUSED_PARAM(frameID);
-    UNUSED_PARAM(pageID);
-    rawCookies.clear();
-    GUniquePtr<SoupURI> uri = url.createSoupURI();
-    if (!uri)
-        return false;
-
-    GUniquePtr<GSList> cookies(soup_cookie_jar_get_cookie_list(session.cookieStorage(), uri.get(), TRUE));
-    if (!cookies)
-        return false;
-
-    for (GSList* iter = cookies.get(); iter; iter = g_slist_next(iter)) {
-        SoupCookie* soupCookie = static_cast<SoupCookie*>(iter->data);
-        Cookie cookie;
-        cookie.name = String::fromUTF8(soupCookie->name);
-        cookie.value = String::fromUTF8(soupCookie->value);
-        cookie.domain = String::fromUTF8(soupCookie->domain);
-        cookie.path = String::fromUTF8(soupCookie->path);
-        cookie.created = 0;
-        cookie.expires = soupCookie->expires ? static_cast<double>(soup_date_to_time_t(soupCookie->expires)) * 1000 : 0;
-        cookie.httpOnly = soupCookie->http_only;
-        cookie.secure = soupCookie->secure;
-        cookie.session = !soupCookie->expires;
-        rawCookies.append(WTFMove(cookie));
-        soup_cookie_free(soupCookie);
-    }
-
-    return true;
-}
-
-void deleteCookie(const NetworkStorageSession& session, const URL& url, const String& name)
-{
-    GUniquePtr<SoupURI> uri = url.createSoupURI();
-    if (!uri)
-        return;
-
-    SoupCookieJar* jar = session.cookieStorage();
-    GUniquePtr<GSList> cookies(soup_cookie_jar_get_cookie_list(jar, uri.get(), TRUE));
-    if (!cookies)
-        return;
-
-    CString cookieName = name.utf8();
-    bool wasDeleted = false;
-    for (GSList* iter = cookies.get(); iter; iter = g_slist_next(iter)) {
-        SoupCookie* cookie = static_cast<SoupCookie*>(iter->data);
-        if (!wasDeleted && cookieName == cookie->name) {
-            soup_cookie_jar_delete_cookie(jar, cookie);
-            wasDeleted = true;
-        }
-        soup_cookie_free(cookie);
-    }
-}
-
-void getHostnamesWithCookies(const NetworkStorageSession& session, HashSet<String>& hostnames)
-{
-    GUniquePtr<GSList> cookies(soup_cookie_jar_all_cookies(session.cookieStorage()));
-    for (GSList* item = cookies.get(); item; item = g_slist_next(item)) {
-        SoupCookie* cookie = static_cast<SoupCookie*>(item->data);
-        if (cookie->domain)
-            hostnames.add(String::fromUTF8(cookie->domain));
-        soup_cookie_free(cookie);
-    }
-}
-
-void deleteCookiesForHostnames(const NetworkStorageSession& session, const Vector<String>& hostnames)
-{
-    SoupCookieJar* cookieJar = session.cookieStorage();
-
-    for (const auto& hostname : hostnames) {
-        CString hostNameString = hostname.utf8();
-
-        GUniquePtr<GSList> cookies(soup_cookie_jar_all_cookies(cookieJar));
-        for (GSList* item = cookies.get(); item; item = g_slist_next(item)) {
-            SoupCookie* cookie = static_cast<SoupCookie*>(item->data);
-            if (soup_cookie_domain_matches(cookie, hostNameString.data()))
-                soup_cookie_jar_delete_cookie(cookieJar, cookie);
-            soup_cookie_free(cookie);
-        }
-    }
-}
-
-void deleteAllCookies(const NetworkStorageSession& session)
-{
-    SoupCookieJar* cookieJar = session.cookieStorage();
-    GUniquePtr<GSList> cookies(soup_cookie_jar_all_cookies(cookieJar));
-    for (GSList* item = cookies.get(); item; item = g_slist_next(item)) {
-        SoupCookie* cookie = static_cast<SoupCookie*>(item->data);
-        soup_cookie_jar_delete_cookie(cookieJar, cookie);
-        soup_cookie_free(cookie);
-    }
-}
-
-void deleteAllCookiesModifiedSince(const NetworkStorageSession& session, WallTime timestamp)
-{
-    // FIXME: Add support for deleting cookies modified since the given timestamp. It should probably be added to libsoup.
-    if (timestamp == WallTime::fromRawSeconds(0))
-        deleteAllCookies(session);
-    else
-        g_warning("Deleting cookies modified since a given time span is not supported yet");
-}
-
-}
-
-#endif
index 5e3c245..b3d71a4 100644 (file)
@@ -32,6 +32,7 @@
 #if USE(SOUP)
 
 #include "Cookie.h"
+#include "CookieRequestHeaderFieldProxy.h"
 #include "GUniquePtrSoup.h"
 #include "ResourceHandle.h"
 #include "SoupNetworkSession.h"
@@ -291,6 +292,62 @@ void NetworkStorageSession::saveCredentialToPersistentStorage(const ProtectionSp
 #endif
 }
 
+bool NetworkStorageSession::cookiesEnabled() const
+{
+    auto policy = soup_cookie_jar_get_accept_policy(cookieStorage());
+    return policy == SOUP_COOKIE_JAR_ACCEPT_ALWAYS || policy == SOUP_COOKIE_JAR_ACCEPT_NO_THIRD_PARTY;
+}
+
+static inline bool httpOnlyCookieExists(const GSList* cookies, const gchar* name, const gchar* path)
+{
+    for (const GSList* iter = cookies; iter; iter = g_slist_next(iter)) {
+        SoupCookie* cookie = static_cast<SoupCookie*>(iter->data);
+        if (!strcmp(soup_cookie_get_name(cookie), name) 
+            && !g_strcmp0(soup_cookie_get_path(cookie), path)) {
+            if (soup_cookie_get_http_only(cookie))
+                return true;
+            break;
+        }
+    }
+    return false;
+}
+
+void NetworkStorageSession::setCookiesFromDOM(const URL& firstParty, const SameSiteInfo&, const URL& url, std::optional<uint64_t> frameID, std::optional<uint64_t> pageID, const String& value) const
+{
+    UNUSED_PARAM(frameID);
+    UNUSED_PARAM(pageID);
+    GUniquePtr<SoupURI> origin = url.createSoupURI();
+    if (!origin)
+        return;
+
+    GUniquePtr<SoupURI> firstPartyURI = firstParty.createSoupURI();
+    if (!firstPartyURI)
+        return;
+
+    // Get existing cookies for this origin.
+    SoupCookieJar* jar = cookieStorage();
+    GSList* existingCookies = soup_cookie_jar_get_cookie_list(jar, origin.get(), TRUE);
+
+    for (auto& cookieString : value.split('\n')) {
+        GUniquePtr<SoupCookie> cookie(soup_cookie_parse(cookieString.utf8().data(), origin.get()));
+
+        if (!cookie)
+            continue;
+
+        // Make sure the cookie is not httpOnly since such cookies should not be set from JavaScript.
+        if (soup_cookie_get_http_only(cookie.get()))
+            continue;
+
+        // Make sure we do not overwrite httpOnly cookies from JavaScript.
+        if (httpOnlyCookieExists(existingCookies, soup_cookie_get_name(cookie.get()), soup_cookie_get_path(cookie.get())))
+            continue;
+
+        soup_cookie_jar_add_cookie_with_first_party(jar, firstPartyURI.get(), cookie.release());
+    }
+
+    soup_cookies_free(existingCookies);
+}
+
 void NetworkStorageSession::setCookies(const Vector<Cookie>& cookies, const URL&, const URL&)
 {
     for (auto cookie : cookies)
@@ -308,6 +365,77 @@ void NetworkStorageSession::deleteCookie(const Cookie& cookie)
     soup_cookie_jar_delete_cookie(cookieStorage(), targetCookie.get());
 }
 
+void NetworkStorageSession::deleteCookie(const URL& url, const String& name) const
+{
+    GUniquePtr<SoupURI> uri = url.createSoupURI();
+    if (!uri)
+        return;
+
+    SoupCookieJar* jar = cookieStorage();
+    GUniquePtr<GSList> cookies(soup_cookie_jar_get_cookie_list(jar, uri.get(), TRUE));
+    if (!cookies)
+        return;
+
+    CString cookieName = name.utf8();
+    bool wasDeleted = false;
+    for (GSList* iter = cookies.get(); iter; iter = g_slist_next(iter)) {
+        SoupCookie* cookie = static_cast<SoupCookie*>(iter->data);
+        if (!wasDeleted && cookieName == cookie->name) {
+            soup_cookie_jar_delete_cookie(jar, cookie);
+            wasDeleted = true;
+        }
+        soup_cookie_free(cookie);
+    }
+}
+
+void NetworkStorageSession::deleteAllCookies()
+{
+    SoupCookieJar* cookieJar = cookieStorage();
+    GUniquePtr<GSList> cookies(soup_cookie_jar_all_cookies(cookieJar));
+    for (GSList* item = cookies.get(); item; item = g_slist_next(item)) {
+        SoupCookie* cookie = static_cast<SoupCookie*>(item->data);
+        soup_cookie_jar_delete_cookie(cookieJar, cookie);
+        soup_cookie_free(cookie);
+    }
+}
+
+void NetworkStorageSession::deleteAllCookiesModifiedSince(WallTime timestamp)
+{
+    // FIXME: Add support for deleting cookies modified since the given timestamp. It should probably be added to libsoup.
+    if (timestamp == WallTime::fromRawSeconds(0))
+        deleteAllCookies();
+    else
+        g_warning("Deleting cookies modified since a given time span is not supported yet");
+}
+
+void NetworkStorageSession::deleteCookiesForHostnames(const Vector<String>& hostnames)
+{
+    SoupCookieJar* cookieJar = cookieStorage();
+
+    for (const auto& hostname : hostnames) {
+        CString hostNameString = hostname.utf8();
+
+        GUniquePtr<GSList> cookies(soup_cookie_jar_all_cookies(cookieJar));
+        for (GSList* item = cookies.get(); item; item = g_slist_next(item)) {
+            SoupCookie* cookie = static_cast<SoupCookie*>(item->data);
+            if (soup_cookie_domain_matches(cookie, hostNameString.data()))
+                soup_cookie_jar_delete_cookie(cookieJar, cookie);
+            soup_cookie_free(cookie);
+        }
+    }
+}
+
+void NetworkStorageSession::getHostnamesWithCookies(HashSet<String>& hostnames)
+{
+    GUniquePtr<GSList> cookies(soup_cookie_jar_all_cookies(cookieStorage()));
+    for (GSList* item = cookies.get(); item; item = g_slist_next(item)) {
+        SoupCookie* cookie = static_cast<SoupCookie*>(item->data);
+        if (cookie->domain)
+            hostnames.add(String::fromUTF8(cookie->domain));
+        soup_cookie_free(cookie);
+    }
+}
+
 Vector<Cookie> NetworkStorageSession::getAllCookies()
 {
     // FIXME: Implement for WK2 to use.
@@ -330,6 +458,98 @@ Vector<Cookie> NetworkStorageSession::getCookies(const URL& url)
     return cookies;
 }
 
+bool NetworkStorageSession::getRawCookies(const URL& firstParty, const SameSiteInfo&, const URL& url, std::optional<uint64_t> frameID, std::optional<uint64_t> pageID, Vector<Cookie>& rawCookies) const
+{
+    UNUSED_PARAM(firstParty);
+    UNUSED_PARAM(frameID);
+    UNUSED_PARAM(pageID);
+    rawCookies.clear();
+    GUniquePtr<SoupURI> uri = url.createSoupURI();
+    if (!uri)
+        return false;
+
+    GUniquePtr<GSList> cookies(soup_cookie_jar_get_cookie_list(cookieStorage(), uri.get(), TRUE));
+    if (!cookies)
+        return false;
+
+    for (GSList* iter = cookies.get(); iter; iter = g_slist_next(iter)) {
+        SoupCookie* soupCookie = static_cast<SoupCookie*>(iter->data);
+        Cookie cookie;
+        cookie.name = String::fromUTF8(soupCookie->name);
+        cookie.value = String::fromUTF8(soupCookie->value);
+        cookie.domain = String::fromUTF8(soupCookie->domain);
+        cookie.path = String::fromUTF8(soupCookie->path);
+        cookie.created = 0;
+        cookie.expires = soupCookie->expires ? static_cast<double>(soup_date_to_time_t(soupCookie->expires)) * 1000 : 0;
+        cookie.httpOnly = soupCookie->http_only;
+        cookie.secure = soupCookie->secure;
+        cookie.session = !soupCookie->expires;
+        rawCookies.append(WTFMove(cookie));
+        soup_cookie_free(soupCookie);
+    }
+
+    return true;
+}
+
+static std::pair<String, bool> cookiesForSession(const NetworkStorageSession& session, const URL& url, bool forHTTPHeader, IncludeSecureCookies includeSecureCookies)
+{
+    GUniquePtr<SoupURI> uri = url.createSoupURI();
+    if (!uri)
+        return { { }, false };
+
+    GSList* cookies = soup_cookie_jar_get_cookie_list(session.cookieStorage(), uri.get(), forHTTPHeader);
+    bool didAccessSecureCookies = false;
+
+    // libsoup should omit secure cookies itself if the protocol is not https.
+    if (url.protocolIs("https")) {
+        GSList* item = cookies;
+        while (item) {
+            auto cookie = static_cast<SoupCookie*>(item->data);
+            if (soup_cookie_get_secure(cookie)) {
+                didAccessSecureCookies = true;
+                if (includeSecureCookies == IncludeSecureCookies::No) {
+                    GSList* next = item->next;
+                    soup_cookie_free(static_cast<SoupCookie*>(item->data));
+                    cookies = g_slist_remove_link(cookies, item);
+                    item = next;
+                    continue;
+                }
+            }
+            item = item->next;
+        }
+    }
+
+    if (!cookies)
+        return { { }, false };
+
+    GUniquePtr<char> cookieHeader(soup_cookies_to_cookie_header(cookies));
+    soup_cookies_free(cookies);
+
+    return { String::fromUTF8(cookieHeader.get()), didAccessSecureCookies };
+}
+
+std::pair<String, bool> NetworkStorageSession::cookiesForDOM(const URL& firstParty, const SameSiteInfo&, const URL& url, std::optional<uint64_t> frameID, std::optional<uint64_t> pageID, IncludeSecureCookies includeSecureCookies) const
+{
+    UNUSED_PARAM(firstParty);
+    UNUSED_PARAM(frameID);
+    UNUSED_PARAM(pageID);
+    return cookiesForSession(*this, url, false, includeSecureCookies);
+}
+
+std::pair<String, bool> NetworkStorageSession::cookieRequestHeaderFieldValue(const URL& firstParty, const SameSiteInfo&, const URL& url, std::optional<uint64_t> frameID, std::optional<uint64_t> pageID, IncludeSecureCookies includeSecureCookies) const
+{
+    UNUSED_PARAM(firstParty);
+    UNUSED_PARAM(frameID);
+    UNUSED_PARAM(pageID);
+    // Secure cookies will still only be included if url's protocol is https.
+    return cookiesForSession(*this, url, true, includeSecureCookies);
+}
+
+std::pair<String, bool> NetworkStorageSession::cookieRequestHeaderFieldValue(const CookieRequestHeaderFieldProxy& headerFieldProxy) const
+{
+    return cookieRequestHeaderFieldValue(headerFieldProxy.firstParty, headerFieldProxy.sameSiteInfo, headerFieldProxy.url, headerFieldProxy.frameID, headerFieldProxy.pageID, headerFieldProxy.includeSecureCookies);
+}
+
 void NetworkStorageSession::flushCookieStore()
 {
     // FIXME: Implement for WK2 to use.
index e09dec9..008ea4c 100644 (file)
@@ -1,3 +1,33 @@
+2018-07-30  Rob Buis  <rbuis@igalia.com>
+
+        https://bugs.webkit.org/show_bug.cgi?id=188137
+        Merge PlatformCookieJar functions into NetworkStorageSession
+
+        Adapt callsites to use NetworkStorageSession instead of CookieJar functions.
+
+        Reviewed by Alex Christensen.
+
+        * NetworkProcess/Cookies/WebCookieManager.cpp:
+        (WebKit::WebCookieManager::getHostnamesWithCookies):
+        (WebKit::WebCookieManager::deleteCookiesForHostname):
+        (WebKit::WebCookieManager::deleteAllCookies):
+        (WebKit::WebCookieManager::deleteAllCookiesModifiedSince):
+        * NetworkProcess/NetworkConnectionToWebProcess.cpp:
+        (WebKit::NetworkConnectionToWebProcess::cookiesForDOM):
+        (WebKit::NetworkConnectionToWebProcess::setCookiesFromDOM):
+        (WebKit::NetworkConnectionToWebProcess::cookiesEnabled):
+        (WebKit::NetworkConnectionToWebProcess::cookieRequestHeaderFieldValue):
+        (WebKit::NetworkConnectionToWebProcess::getRawCookies):
+        (WebKit::NetworkConnectionToWebProcess::deleteCookie):
+        * NetworkProcess/NetworkProcess.cpp:
+        (WebKit::NetworkProcess::fetchWebsiteData):
+        (WebKit::NetworkProcess::deleteWebsiteData):
+        (WebKit::NetworkProcess::deleteWebsiteDataForOrigins):
+        * NetworkProcess/NetworkResourceLoader.cpp:
+        (WebKit::logCookieInformationInternal):
+        * NetworkProcess/cache/NetworkCache.cpp:
+        * WebProcess/WebCoreSupport/WebPlatformStrategies.cpp:
+
 2018-07-30  Alex Christensen  <achristensen@webkit.org>
 
         Add RefCounted CompletionHandler wrapping abstraction for sending policy decisions back to WebProcess
index fe92bc1..0bb149c 100644 (file)
@@ -33,7 +33,6 @@
 #include <WebCore/Cookie.h>
 #include <WebCore/CookieStorage.h>
 #include <WebCore/NetworkStorageSession.h>
-#include <WebCore/PlatformCookieJar.h>
 #include <WebCore/URL.h>
 #include <wtf/MainThread.h>
 #include <wtf/text/StringHash.h>
@@ -60,7 +59,7 @@ void WebCookieManager::getHostnamesWithCookies(PAL::SessionID sessionID, Callbac
 {
     HashSet<String> hostnames;
     if (auto* storageSession = NetworkStorageSession::storageSession(sessionID))
-        WebCore::getHostnamesWithCookies(*storageSession, hostnames);
+        storageSession->getHostnamesWithCookies(hostnames);
 
     m_process.send(Messages::WebCookieManagerProxy::DidGetHostnamesWithCookies(copyToVector(hostnames), callbackID), 0);
 }
@@ -68,14 +67,14 @@ void WebCookieManager::getHostnamesWithCookies(PAL::SessionID sessionID, Callbac
 void WebCookieManager::deleteCookiesForHostname(PAL::SessionID sessionID, const String& hostname)
 {
     if (auto* storageSession = NetworkStorageSession::storageSession(sessionID))
-        WebCore::deleteCookiesForHostnames(*storageSession, { hostname });
+        storageSession->deleteCookiesForHostnames({ hostname });
 }
 
 
 void WebCookieManager::deleteAllCookies(PAL::SessionID sessionID)
 {
     if (auto* storageSession = NetworkStorageSession::storageSession(sessionID))
-        WebCore::deleteAllCookies(*storageSession);
+        storageSession->deleteAllCookies();
 }
 
 void WebCookieManager::deleteCookie(PAL::SessionID sessionID, const Cookie& cookie, CallbackID callbackID)
@@ -89,7 +88,7 @@ void WebCookieManager::deleteCookie(PAL::SessionID sessionID, const Cookie& cook
 void WebCookieManager::deleteAllCookiesModifiedSince(PAL::SessionID sessionID, WallTime time, CallbackID callbackID)
 {
     if (auto* storageSession = NetworkStorageSession::storageSession(sessionID))
-        WebCore::deleteAllCookiesModifiedSince(*storageSession, time);
+        storageSession->deleteAllCookiesModifiedSince(time);
 
     m_process.send(Messages::WebCookieManagerProxy::DidDeleteCookies(callbackID), 0);
 }
index a31f171..0838930 100644 (file)
@@ -52,7 +52,6 @@
 #include "WebsiteDataStore.h"
 #include "WebsiteDataStoreParameters.h"
 #include <WebCore/NetworkStorageSession.h>
-#include <WebCore/PlatformCookieJar.h>
 #include <WebCore/ResourceLoaderOptions.h>
 #include <WebCore/ResourceRequest.h>
 #include <WebCore/SameSiteInfo.h>
@@ -379,7 +378,7 @@ void NetworkConnectionToWebProcess::convertMainResourceLoadToDownload(PAL::Sessi
 void NetworkConnectionToWebProcess::cookiesForDOM(PAL::SessionID sessionID, const URL& firstParty, const SameSiteInfo& sameSiteInfo, const URL& url, std::optional<uint64_t> frameID, std::optional<uint64_t> pageID, IncludeSecureCookies includeSecureCookies, String& cookieString, bool& secureCookiesAccessed)
 {
     auto& networkStorageSession = storageSession(sessionID);
-    std::tie(cookieString, secureCookiesAccessed) = WebCore::cookiesForDOM(networkStorageSession, firstParty, sameSiteInfo, url, frameID, pageID, includeSecureCookies);
+    std::tie(cookieString, secureCookiesAccessed) = networkStorageSession.cookiesForDOM(firstParty, sameSiteInfo, url, frameID, pageID, includeSecureCookies);
 #if HAVE(CFNETWORK_STORAGE_PARTITIONING) && !RELEASE_LOG_DISABLED
     if (NetworkProcess::singleton().shouldLogCookieInformation())
         NetworkResourceLoader::logCookieInformation("NetworkConnectionToWebProcess::cookiesForDOM", reinterpret_cast<const void*>(this), networkStorageSession, firstParty, sameSiteInfo, url, emptyString(), frameID, pageID, std::nullopt);
@@ -389,7 +388,7 @@ void NetworkConnectionToWebProcess::cookiesForDOM(PAL::SessionID sessionID, cons
 void NetworkConnectionToWebProcess::setCookiesFromDOM(PAL::SessionID sessionID, const URL& firstParty, const SameSiteInfo& sameSiteInfo, const URL& url, std::optional<uint64_t> frameID, std::optional<uint64_t> pageID, const String& cookieString)
 {
     auto& networkStorageSession = storageSession(sessionID);
-    WebCore::setCookiesFromDOM(networkStorageSession, firstParty, sameSiteInfo, url, frameID, pageID, cookieString);
+    networkStorageSession.setCookiesFromDOM(firstParty, sameSiteInfo, url, frameID, pageID, cookieString);
 #if HAVE(CFNETWORK_STORAGE_PARTITIONING) && !RELEASE_LOG_DISABLED
     if (NetworkProcess::singleton().shouldLogCookieInformation())
         NetworkResourceLoader::logCookieInformation("NetworkConnectionToWebProcess::setCookiesFromDOM", reinterpret_cast<const void*>(this), networkStorageSession, firstParty, sameSiteInfo, url, emptyString(), frameID, pageID, std::nullopt);
@@ -398,22 +397,22 @@ void NetworkConnectionToWebProcess::setCookiesFromDOM(PAL::SessionID sessionID,
 
 void NetworkConnectionToWebProcess::cookiesEnabled(PAL::SessionID sessionID, bool& result)
 {
-    result = WebCore::cookiesEnabled(storageSession(sessionID));
+    result = storageSession(sessionID).cookiesEnabled();
 }
 
 void NetworkConnectionToWebProcess::cookieRequestHeaderFieldValue(PAL::SessionID sessionID, const URL& firstParty, const SameSiteInfo& sameSiteInfo, const URL& url, std::optional<uint64_t> frameID, std::optional<uint64_t> pageID, IncludeSecureCookies includeSecureCookies, String& cookieString, bool& secureCookiesAccessed)
 {
-    std::tie(cookieString, secureCookiesAccessed) = WebCore::cookieRequestHeaderFieldValue(storageSession(sessionID), firstParty, sameSiteInfo, url, frameID, pageID, includeSecureCookies);
+    std::tie(cookieString, secureCookiesAccessed) = storageSession(sessionID).cookieRequestHeaderFieldValue(firstParty, sameSiteInfo, url, frameID, pageID, includeSecureCookies);
 }
 
 void NetworkConnectionToWebProcess::getRawCookies(PAL::SessionID sessionID, const URL& firstParty, const SameSiteInfo& sameSiteInfo, const URL& url, std::optional<uint64_t> frameID, std::optional<uint64_t> pageID, Vector<Cookie>& result)
 {
-    WebCore::getRawCookies(storageSession(sessionID), firstParty, sameSiteInfo, url, frameID, pageID, result);
+    storageSession(sessionID).getRawCookies(firstParty, sameSiteInfo, url, frameID, pageID, result);
 }
 
 void NetworkConnectionToWebProcess::deleteCookie(PAL::SessionID sessionID, const URL& url, const String& cookieName)
 {
-    WebCore::deleteCookie(storageSession(sessionID), url, cookieName);
+    storageSession(sessionID).deleteCookie(url, cookieName);
 }
 
 void NetworkConnectionToWebProcess::registerFileBlobURL(const URL& url, const String& path, SandboxExtension::Handle&& extensionHandle, const String& contentType)
index 8bfefe3..5a124c8 100644 (file)
@@ -65,7 +65,6 @@
 #include <WebCore/MIMETypeRegistry.h>
 #include <WebCore/NetworkStateNotifier.h>
 #include <WebCore/NetworkStorageSession.h>
-#include <WebCore/PlatformCookieJar.h>
 #include <WebCore/ResourceRequest.h>
 #include <WebCore/RuntimeApplicationChecks.h>
 #include <WebCore/SchemeRegistry.h>
@@ -533,7 +532,7 @@ void NetworkProcess::fetchWebsiteData(PAL::SessionID sessionID, OptionSet<Websit
 
     if (websiteDataTypes.contains(WebsiteDataType::Cookies)) {
         if (auto* networkStorageSession = NetworkStorageSession::storageSession(sessionID))
-            getHostnamesWithCookies(*networkStorageSession, callbackAggregator->m_websiteData.hostNamesWithCookies);
+            networkStorageSession->getHostnamesWithCookies(callbackAggregator->m_websiteData.hostNamesWithCookies);
     }
 
     if (websiteDataTypes.contains(WebsiteDataType::Credentials)) {
@@ -565,7 +564,7 @@ void NetworkProcess::deleteWebsiteData(PAL::SessionID sessionID, OptionSet<Websi
 
     if (websiteDataTypes.contains(WebsiteDataType::Cookies)) {
         if (auto* networkStorageSession = NetworkStorageSession::storageSession(sessionID))
-            deleteAllCookiesModifiedSince(*networkStorageSession, modifiedSince);
+            networkStorageSession->deleteAllCookiesModifiedSince(modifiedSince);
     }
 
     if (websiteDataTypes.contains(WebsiteDataType::Credentials)) {
@@ -613,7 +612,7 @@ void NetworkProcess::deleteWebsiteDataForOrigins(PAL::SessionID sessionID, Optio
 {
     if (websiteDataTypes.contains(WebsiteDataType::Cookies)) {
         if (auto* networkStorageSession = NetworkStorageSession::storageSession(sessionID))
-            deleteCookiesForHostnames(*networkStorageSession, cookieHostNames);
+            networkStorageSession->deleteCookiesForHostnames(cookieHostNames);
     }
 
     auto clearTasksHandler = WTF::CallbackAggregator::create([this, callbackID] {
index 52ebf9a..caa7cd5 100644 (file)
@@ -59,7 +59,6 @@
 
 #if HAVE(CFNETWORK_STORAGE_PARTITIONING) && !RELEASE_LOG_DISABLED
 #include <WebCore/NetworkStorageSession.h>
-#include <WebCore/PlatformCookieJar.h>
 #endif
 
 #if USE(QUICK_LOOK)
@@ -1014,7 +1013,7 @@ static void logCookieInformationInternal(const String& label, const void* logged
     ASSERT(NetworkResourceLoader::shouldLogCookieInformation());
 
     Vector<WebCore::Cookie> cookies;
-    if (!WebCore::getRawCookies(networkStorageSession, partition, sameSiteInfo, url, frameID, pageID, cookies))
+    if (!networkStorageSession.getRawCookies(partition, sameSiteInfo, url, frameID, pageID, cookies))
         return;
 
     auto escapedURL = escapeForJSON(url.string());
index b72dc15..2ff0ca2 100644 (file)
@@ -35,7 +35,6 @@
 #include <WebCore/HTTPHeaderNames.h>
 #include <WebCore/LowPowerModeNotifier.h>
 #include <WebCore/NetworkStorageSession.h>
-#include <WebCore/PlatformCookieJar.h>
 #include <WebCore/ResourceRequest.h>
 #include <WebCore/ResourceResponse.h>
 #include <WebCore/SharedBuffer.h>
index 6913135..ae7388f 100644 (file)
@@ -54,7 +54,6 @@
 #include <WebCore/Page.h>
 #include <WebCore/PageGroup.h>
 #include <WebCore/PasteboardItemInfo.h>
-#include <WebCore/PlatformCookieJar.h>
 #include <WebCore/PlatformPasteboard.h>
 #include <WebCore/ProgressTracker.h>
 #include <WebCore/ResourceError.h>
index 04c985d..4a780de 100644 (file)
@@ -1,3 +1,22 @@
+2018-07-30  Rob Buis  <rbuis@igalia.com>
+
+        Merge PlatformCookieJar functions into NetworkStorageSession
+        https://bugs.webkit.org/show_bug.cgi?id=188137
+
+        Adapt callsites to use NetworkStorageSession instead of CookieJar functions.
+
+        Reviewed by Alex Christensen.
+
+        * WebCoreSupport/WebPlatformStrategies.mm:
+        (WebPlatformStrategies::cookiesForDOM):
+        (WebPlatformStrategies::setCookiesFromDOM):
+        (WebPlatformStrategies::cookiesEnabled):
+        (WebPlatformStrategies::cookieRequestHeaderFieldValue):
+        (WebPlatformStrategies::getRawCookies):
+        (WebPlatformStrategies::deleteCookie):
+        * WebView/WebPreferences.mm:
+        (+[WebPreferences _clearNetworkLoaderSession]):
+
 2018-07-28  Darin Adler  <darin@apple.com>
 
         [Cocoa] Update more WebCore Objective-C code to be ARC compatible
index 3450672..b53188e 100644 (file)
@@ -33,7 +33,6 @@
 #import <WebCore/Frame.h>
 #import <WebCore/NetworkStorageSession.h>
 #import <WebCore/PasteboardItemInfo.h>
-#import <WebCore/PlatformCookieJar.h>
 #import <WebCore/PlatformPasteboard.h>
 #import <WebCore/SharedBuffer.h>
 #import <WebCore/SubframeLoader.h>
@@ -75,38 +74,38 @@ BlobRegistry* WebPlatformStrategies::createBlobRegistry()
 
 std::pair<String, bool> WebPlatformStrategies::cookiesForDOM(const NetworkStorageSession& session, const URL& firstParty, const SameSiteInfo& sameSiteInfo, const URL& url, std::optional<uint64_t> frameID, std::optional<uint64_t> pageID, IncludeSecureCookies includeSecureCookies)
 {
-    return WebCore::cookiesForDOM(session, firstParty, sameSiteInfo, url, frameID, pageID, includeSecureCookies);
+    return session.cookiesForDOM(firstParty, sameSiteInfo, url, frameID, pageID, includeSecureCookies);
 }
 
 void WebPlatformStrategies::setCookiesFromDOM(const NetworkStorageSession& session, const URL& firstParty, const SameSiteInfo& sameSiteInfo, const URL& url, std::optional<uint64_t> frameID, std::optional<uint64_t> pageID, const String& cookieString)
 {
-    WebCore::setCookiesFromDOM(session, firstParty, sameSiteInfo, url, frameID, pageID, cookieString);
+    session.setCookiesFromDOM(firstParty, sameSiteInfo, url, frameID, pageID, cookieString);
 }
 
 bool WebPlatformStrategies::cookiesEnabled(const NetworkStorageSession& session)
 {
-    return WebCore::cookiesEnabled(session);
+    return session.cookiesEnabled();
 }
 
 std::pair<String, bool> WebPlatformStrategies::cookieRequestHeaderFieldValue(const NetworkStorageSession& session, const URL& firstParty, const SameSiteInfo& sameSiteInfo, const URL& url, std::optional<uint64_t> frameID, std::optional<uint64_t> pageID, IncludeSecureCookies includeSecureCookies)
 {
-    return WebCore::cookieRequestHeaderFieldValue(session, firstParty, sameSiteInfo, url, frameID, pageID, includeSecureCookies);
+    return session.cookieRequestHeaderFieldValue(firstParty, sameSiteInfo, url, frameID, pageID, includeSecureCookies);
 }
 
 std::pair<String, bool> WebPlatformStrategies::cookieRequestHeaderFieldValue(PAL::SessionID sessionID, const URL& firstParty, const SameSiteInfo& sameSiteInfo, const URL& url, std::optional<uint64_t> frameID, std::optional<uint64_t> pageID, IncludeSecureCookies includeSecureCookies)
 {
     auto& session = sessionID.isEphemeral() ? WebFrameNetworkingContext::ensurePrivateBrowsingSession() : NetworkStorageSession::defaultStorageSession();
-    return WebCore::cookieRequestHeaderFieldValue(session, firstParty, sameSiteInfo, url, frameID, pageID, includeSecureCookies);
+    return session.cookieRequestHeaderFieldValue(firstParty, sameSiteInfo, url, frameID, pageID, includeSecureCookies);
 }
 
 bool WebPlatformStrategies::getRawCookies(const NetworkStorageSession& session, const URL& firstParty, const SameSiteInfo& sameSiteInfo, const URL& url, std::optional<uint64_t> frameID, std::optional<uint64_t> pageID, Vector<Cookie>& rawCookies)
 {
-    return WebCore::getRawCookies(session, firstParty, sameSiteInfo, url, frameID, pageID, rawCookies);
+    return session.getRawCookies(firstParty, sameSiteInfo, url, frameID, pageID, rawCookies);
 }
 
 void WebPlatformStrategies::deleteCookie(const NetworkStorageSession& session, const URL& url, const String& cookieName)
 {
-    WebCore::deleteCookie(session, url, cookieName);
+    session.deleteCookie(url, cookieName);
 }
 
 void WebPlatformStrategies::getTypes(Vector<String>& types, const String& pasteboardName)
index c4d7422..7718d05 100644 (file)
@@ -42,7 +42,6 @@
 #import <WebCore/AudioSession.h>
 #import <WebCore/DeprecatedGlobalSettings.h>
 #import <WebCore/NetworkStorageSession.h>
-#import <WebCore/PlatformCookieJar.h>
 #import <WebCore/RuntimeApplicationChecks.h>
 #import <WebCore/Settings.h>
 #import <WebCore/TextEncodingRegistry.h>
@@ -1877,7 +1876,7 @@ static NSString *classIBCreatorID = nil;
 
 + (void)_clearNetworkLoaderSession
 {
-    WebCore::deleteAllCookies(NetworkStorageSession::defaultStorageSession());
+    NetworkStorageSession::defaultStorageSession().deleteAllCookies();
 }
 
 + (void)_setCurrentNetworkLoaderSessionCookieAcceptPolicy:(NSHTTPCookieAcceptPolicy)policy
index a73dfef..58c4a48 100644 (file)
@@ -1,3 +1,22 @@
+2018-07-30  Rob Buis  <rbuis@igalia.com>
+
+        https://bugs.webkit.org/show_bug.cgi?id=188137
+        Merge PlatformCookieJar functions into NetworkStorageSession
+
+        Adapt callsites to use NetworkStorageSession instead of CookieJar functions.
+
+        Reviewed by Alex Christensen.
+
+        * WebCoreSupport/WebPlatformStrategies.cpp:
+        (WebPlatformStrategies::cookiesForDOM):
+        (WebPlatformStrategies::setCookiesFromDOM):
+        (WebPlatformStrategies::cookiesEnabled):
+        (WebPlatformStrategies::cookieRequestHeaderFieldValue):
+        (WebPlatformStrategies::getRawCookies):
+        (WebPlatformStrategies::deleteCookie):
+        * WebPreferences.cpp:
+        (WebPreferences::clearNetworkLoaderSession):
+
 2018-07-26  Ross Kirsling  <ross.kirsling@sony.com>
 
         String(View) should have a splitAllowingEmptyEntries function instead of a flag parameter
index de26268..fab4218 100644 (file)
@@ -32,7 +32,6 @@
 #include <WebCore/NetworkStorageSession.h>
 #include <WebCore/Page.h>
 #include <WebCore/PageGroup.h>
-#include <WebCore/PlatformCookieJar.h>
 
 #if USE(CFURLCONNECTION)
 #include <WebKitSystemInterface/WebKitSystemInterface.h>
@@ -72,36 +71,36 @@ BlobRegistry* WebPlatformStrategies::createBlobRegistry()
 
 std::pair<String, bool> WebPlatformStrategies::cookiesForDOM(const NetworkStorageSession& session, const URL& firstParty, const SameSiteInfo& sameSiteInfo, const URL& url, std::optional<uint64_t> frameID, std::optional<uint64_t> pageID, IncludeSecureCookies includeSecureCookies)
 {
-    return WebCore::cookiesForDOM(session, firstParty, sameSiteInfo, url, frameID, pageID, includeSecureCookies);
+    return session.cookiesForDOM(firstParty, sameSiteInfo, url, frameID, pageID, includeSecureCookies);
 }
 
 void WebPlatformStrategies::setCookiesFromDOM(const NetworkStorageSession& session, const URL& firstParty, const SameSiteInfo& sameSiteInfo, const URL& url, std::optional<uint64_t> frameID, std::optional<uint64_t> pageID, const String& cookieString)
 {
-    WebCore::setCookiesFromDOM(session, firstParty, sameSiteInfo, url, frameID, pageID, cookieString);
+    session.setCookiesFromDOM(firstParty, sameSiteInfo, url, frameID, pageID, cookieString);
 }
 
 bool WebPlatformStrategies::cookiesEnabled(const NetworkStorageSession& session)
 {
-    return WebCore::cookiesEnabled(session);
+    return session.cookiesEnabled();
 }
 
 std::pair<String, bool> WebPlatformStrategies::cookieRequestHeaderFieldValue(const NetworkStorageSession& session, const URL& firstParty, const SameSiteInfo& sameSiteInfo, const URL& url, std::optional<uint64_t> frameID, std::optional<uint64_t> pageID, IncludeSecureCookies includeSecureCookies)
 {
-    return WebCore::cookieRequestHeaderFieldValue(session, firstParty, sameSiteInfo, url, frameID, pageID, includeSecureCookies);
+    return session.cookieRequestHeaderFieldValue(firstParty, sameSiteInfo, url, frameID, pageID, includeSecureCookies);
 }
 
 std::pair<String, bool> WebPlatformStrategies::cookieRequestHeaderFieldValue(PAL::SessionID sessionID, const URL& firstParty, const SameSiteInfo& sameSiteInfo, const URL& url, std::optional<uint64_t> frameID, std::optional<uint64_t> pageID, IncludeSecureCookies includeSecureCookies)
 {
     auto& session = sessionID.isEphemeral() ? WebFrameNetworkingContext::ensurePrivateBrowsingSession() : NetworkStorageSession::defaultStorageSession();
-    return WebCore::cookieRequestHeaderFieldValue(session, firstParty, sameSiteInfo, url, frameID, pageID, includeSecureCookies);
+    return session.cookieRequestHeaderFieldValue(firstParty, sameSiteInfo, url, frameID, pageID, includeSecureCookies);
 }
 
 bool WebPlatformStrategies::getRawCookies(const NetworkStorageSession& session, const URL& firstParty, const SameSiteInfo& sameSiteInfo, const URL& url, std::optional<uint64_t> frameID, std::optional<uint64_t> pageID, Vector<Cookie>& rawCookies)
 {
-    return WebCore::getRawCookies(session, firstParty, sameSiteInfo, url, frameID, pageID, rawCookies);
+    return session.getRawCookies(firstParty, sameSiteInfo, url, frameID, pageID, rawCookies);
 }
 
 void WebPlatformStrategies::deleteCookie(const NetworkStorageSession& session, const URL& url, const String& cookieName)
 {
-    WebCore::deleteCookie(session, url, cookieName);
+    session.deleteCookie(url, cookieName);
 }
index e100412..c08f2f7 100644 (file)
@@ -42,7 +42,6 @@
 #include <WebCore/FontCascade.h>
 #include <WebCore/LocalizedStrings.h>
 #include <WebCore/NetworkStorageSession.h>
-#include <WebCore/PlatformCookieJar.h>
 #include <limits>
 #include <shlobj.h>
 #include <wchar.h>
@@ -2120,7 +2119,7 @@ HRESULT WebPreferences::mediaPreloadingEnabled(_Out_ BOOL* enabled)
 
 HRESULT WebPreferences::clearNetworkLoaderSession()
 {
-    WebCore::deleteAllCookies(NetworkStorageSession::defaultStorageSession());
+    NetworkStorageSession::defaultStorageSession().deleteAllCookies();
     return S_OK;
 }