2 * Copyright (C) 2017 Sony Interactive Entertainment Inc.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
27 #include "NetworkStorageSession.h"
32 #include "CookieJarCurl.h"
33 #include "CookieJarDB.h"
34 #include "CookieRequestHeaderFieldProxy.h"
35 #include "CurlContext.h"
36 #include "NetworkingContext.h"
37 #include "ResourceHandle.h"
38 #include <wtf/FileSystem.h>
39 #include <wtf/MainThread.h>
40 #include <wtf/NeverDestroyed.h>
42 #include <wtf/text/WTFString.h>
46 static String defaultCookieJarPath()
48 static const char* defaultFileName = "cookie.jar.db";
49 char* cookieJarPath = getenv("CURL_COOKIE_JAR_PATH");
54 return FileSystem::pathByAppendingComponent(FileSystem::localUserSpecificStorageDirectory(), defaultFileName);
56 // FIXME: https://bugs.webkit.org/show_bug.cgi?id=192417
57 return defaultFileName;
61 NetworkStorageSession::NetworkStorageSession(PAL::SessionID sessionID)
62 : m_sessionID(sessionID)
63 , m_cookieStorage(makeUniqueRef<CookieJarCurl>())
64 , m_cookieDatabase(makeUniqueRef<CookieJarDB>(defaultCookieJarPath()))
68 NetworkStorageSession::~NetworkStorageSession()
72 void NetworkStorageSession::setCookieDatabase(UniqueRef<CookieJarDB>&& cookieDatabase)
74 m_cookieDatabase = WTFMove(cookieDatabase);
77 CookieJarDB& NetworkStorageSession::cookieDatabase() const
79 m_cookieDatabase->open();
80 return m_cookieDatabase;
83 void NetworkStorageSession::setCookiesFromDOM(const URL& firstParty, const SameSiteInfo& sameSiteInfo, const URL& url, Optional<uint64_t> frameID, Optional<uint64_t> pageID, const String& value) const
85 cookieStorage().setCookiesFromDOM(*this, firstParty, sameSiteInfo, url, frameID, pageID, value);
88 bool NetworkStorageSession::cookiesEnabled() const
90 return cookieStorage().cookiesEnabled(*this);
93 std::pair<String, bool> NetworkStorageSession::cookiesForDOM(const URL& firstParty, const SameSiteInfo& sameSiteInfo, const URL& url, Optional<uint64_t> frameID, Optional<uint64_t> pageID, IncludeSecureCookies includeSecureCookies) const
95 return cookieStorage().cookiesForDOM(*this, firstParty, sameSiteInfo, url, frameID, pageID, includeSecureCookies);
98 void NetworkStorageSession::setCookies(const Vector<Cookie>&, const URL&, const URL&)
100 // FIXME: Implement for WebKit to use.
103 void NetworkStorageSession::setCookie(const Cookie&)
105 // FIXME: Implement for WebKit to use.
108 void NetworkStorageSession::deleteCookie(const Cookie&)
110 // FIXME: Implement for WebKit to use.
113 void NetworkStorageSession::deleteCookie(const URL& url, const String& cookie) const
115 cookieStorage().deleteCookie(*this, url, cookie);
118 void NetworkStorageSession::deleteAllCookies()
120 cookieStorage().deleteAllCookies(*this);
123 void NetworkStorageSession::deleteAllCookiesModifiedSince(WallTime since)
125 cookieStorage().deleteAllCookiesModifiedSince(*this, since);
128 void NetworkStorageSession::deleteCookiesForHostnames(const Vector<String>& cookieHostNames)
130 cookieStorage().deleteCookiesForHostnames(*this, cookieHostNames);
133 Vector<Cookie> NetworkStorageSession::getAllCookies()
135 // FIXME: Implement for WebKit to use.
139 void NetworkStorageSession::getHostnamesWithCookies(HashSet<String>& hostnames)
141 cookieStorage().getHostnamesWithCookies(*this, hostnames);
144 Vector<Cookie> NetworkStorageSession::getCookies(const URL&)
146 // FIXME: Implement for WebKit to use.
150 bool NetworkStorageSession::getRawCookies(const URL& firstParty, const SameSiteInfo& sameSiteInfo, const URL& url, Optional<uint64_t> frameID, Optional<uint64_t> pageID, Vector<Cookie>& rawCookies) const
152 return cookieStorage().getRawCookies(*this, firstParty, sameSiteInfo, url, frameID, pageID, rawCookies);
155 void NetworkStorageSession::flushCookieStore()
157 // FIXME: Implement for WebKit to use.
160 std::pair<String, bool> NetworkStorageSession::cookieRequestHeaderFieldValue(const URL& firstParty, const SameSiteInfo& sameSiteInfo, const URL& url, Optional<uint64_t> frameID, Optional<uint64_t> pageID, IncludeSecureCookies includeSecureCookies) const
162 return cookieStorage().cookieRequestHeaderFieldValue(*this, firstParty, sameSiteInfo, url, frameID, pageID, includeSecureCookies);
165 std::pair<String, bool> NetworkStorageSession::cookieRequestHeaderFieldValue(const CookieRequestHeaderFieldProxy& headerFieldProxy) const
167 return cookieStorage().cookieRequestHeaderFieldValue(*this, headerFieldProxy.firstParty, headerFieldProxy.sameSiteInfo, headerFieldProxy.url, headerFieldProxy.frameID, headerFieldProxy.pageID, headerFieldProxy.includeSecureCookies);
170 void NetworkStorageSession::setProxySettings(CurlProxySettings&& proxySettings)
172 CurlContext::singleton().setProxySettings(WTFMove(proxySettings));
175 } // namespace WebCore