Implement Same-Site cookies
[WebKit-https.git] / Source / WebKitLegacy / win / WebCoreSupport / WebPlatformStrategies.cpp
1 /*
2  * Copyright (C) 2010-2017 Apple Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23  * THE POSSIBILITY OF SUCH DAMAGE.
24  */
25
26 #include "WebPlatformStrategies.h"
27
28 #include "WebFrameNetworkingContext.h"
29 #include "WebResourceLoadScheduler.h"
30 #include <WebCore/BlobRegistryImpl.h>
31 #include <WebCore/FrameLoader.h>
32 #include <WebCore/NetworkStorageSession.h>
33 #include <WebCore/Page.h>
34 #include <WebCore/PageGroup.h>
35 #include <WebCore/PlatformCookieJar.h>
36
37 #if USE(CFURLCONNECTION)
38 #include <WebKitSystemInterface/WebKitSystemInterface.h>
39 #endif
40
41 using namespace WebCore;
42
43 void WebPlatformStrategies::initialize()
44 {
45     static NeverDestroyed<WebPlatformStrategies> platformStrategies;
46 }
47
48 WebPlatformStrategies::WebPlatformStrategies()
49 {
50     setPlatformStrategies(this);
51 }
52
53 CookiesStrategy* WebPlatformStrategies::createCookiesStrategy()
54 {
55     return this;
56 }
57
58 LoaderStrategy* WebPlatformStrategies::createLoaderStrategy()
59 {
60     return new WebResourceLoadScheduler;
61 }
62
63 PasteboardStrategy* WebPlatformStrategies::createPasteboardStrategy()
64 {
65     return nullptr;
66 }
67
68 BlobRegistry* WebPlatformStrategies::createBlobRegistry()
69 {
70     return new BlobRegistryImpl;
71 }
72
73 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)
74 {
75     return WebCore::cookiesForDOM(session, firstParty, sameSiteInfo, url, frameID, pageID, includeSecureCookies);
76 }
77
78 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)
79 {
80     WebCore::setCookiesFromDOM(session, firstParty, sameSiteInfo, url, frameID, pageID, cookieString);
81 }
82
83 bool WebPlatformStrategies::cookiesEnabled(const NetworkStorageSession& session)
84 {
85     return WebCore::cookiesEnabled(session);
86 }
87
88 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)
89 {
90     return WebCore::cookieRequestHeaderFieldValue(session, firstParty, sameSiteInfo, url, frameID, pageID, includeSecureCookies);
91 }
92
93 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)
94 {
95     auto& session = sessionID.isEphemeral() ? WebFrameNetworkingContext::ensurePrivateBrowsingSession() : NetworkStorageSession::defaultStorageSession();
96     return WebCore::cookieRequestHeaderFieldValue(session, firstParty, sameSiteInfo, url, frameID, pageID, includeSecureCookies);
97 }
98
99 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)
100 {
101     return WebCore::getRawCookies(session, firstParty, sameSiteInfo, url, frameID, pageID, rawCookies);
102 }
103
104 void WebPlatformStrategies::deleteCookie(const NetworkStorageSession& session, const URL& url, const String& cookieName)
105 {
106     WebCore::deleteCookie(session, url, cookieName);
107 }