| 1 | /* |
| 2 | * Copyright (C) 2011 Samsung Electronics. |
| 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 "config.h" |
| 27 | #include "WebCookieManager.h" |
| 28 | |
| 29 | #include "NetworkProcess.h" |
| 30 | #include "SoupCookiePersistentStorageType.h" |
| 31 | #include <WebCore/NetworkStorageSession.h> |
| 32 | #include <WebCore/SoupNetworkSession.h> |
| 33 | #include <libsoup/soup.h> |
| 34 | #include <wtf/glib/GRefPtr.h> |
| 35 | #include <wtf/text/CString.h> |
| 36 | |
| 37 | namespace WebKit { |
| 38 | using namespace WebCore; |
| 39 | |
| 40 | void WebCookieManager::platformSetHTTPCookieAcceptPolicy(HTTPCookieAcceptPolicy policy) |
| 41 | { |
| 42 | SoupCookieJarAcceptPolicy soupPolicy = SOUP_COOKIE_JAR_ACCEPT_NO_THIRD_PARTY; |
| 43 | switch (policy) { |
| 44 | case HTTPCookieAcceptPolicyAlways: |
| 45 | soupPolicy = SOUP_COOKIE_JAR_ACCEPT_ALWAYS; |
| 46 | break; |
| 47 | case HTTPCookieAcceptPolicyNever: |
| 48 | soupPolicy = SOUP_COOKIE_JAR_ACCEPT_NEVER; |
| 49 | break; |
| 50 | case HTTPCookieAcceptPolicyOnlyFromMainDocumentDomain: |
| 51 | soupPolicy = SOUP_COOKIE_JAR_ACCEPT_NO_THIRD_PARTY; |
| 52 | break; |
| 53 | } |
| 54 | |
| 55 | m_process.forEachNetworkStorageSession([soupPolicy] (const auto& session) { |
| 56 | soup_cookie_jar_set_accept_policy(session.cookieStorage(), soupPolicy); |
| 57 | }); |
| 58 | } |
| 59 | |
| 60 | HTTPCookieAcceptPolicy WebCookieManager::platformGetHTTPCookieAcceptPolicy() |
| 61 | { |
| 62 | switch (soup_cookie_jar_get_accept_policy(m_process.defaultStorageSession().cookieStorage())) { |
| 63 | case SOUP_COOKIE_JAR_ACCEPT_ALWAYS: |
| 64 | return HTTPCookieAcceptPolicyAlways; |
| 65 | case SOUP_COOKIE_JAR_ACCEPT_NEVER: |
| 66 | return HTTPCookieAcceptPolicyNever; |
| 67 | case SOUP_COOKIE_JAR_ACCEPT_NO_THIRD_PARTY: |
| 68 | return HTTPCookieAcceptPolicyOnlyFromMainDocumentDomain; |
| 69 | } |
| 70 | |
| 71 | ASSERT_NOT_REACHED(); |
| 72 | return HTTPCookieAcceptPolicyOnlyFromMainDocumentDomain; |
| 73 | } |
| 74 | |
| 75 | void WebCookieManager::setCookiePersistentStorage(PAL::SessionID sessionID, const String& storagePath, SoupCookiePersistentStorageType storageType) |
| 76 | { |
| 77 | GRefPtr<SoupCookieJar> jar; |
| 78 | switch (storageType) { |
| 79 | case SoupCookiePersistentStorageType::Text: |
| 80 | jar = adoptGRef(soup_cookie_jar_text_new(storagePath.utf8().data(), FALSE)); |
| 81 | break; |
| 82 | case SoupCookiePersistentStorageType::SQLite: |
| 83 | jar = adoptGRef(soup_cookie_jar_db_new(storagePath.utf8().data(), FALSE)); |
| 84 | break; |
| 85 | default: |
| 86 | ASSERT_NOT_REACHED(); |
| 87 | } |
| 88 | |
| 89 | if (auto* storageSession = m_process.storageSession(sessionID)) { |
| 90 | soup_cookie_jar_set_accept_policy(jar.get(), soup_cookie_jar_get_accept_policy(storageSession->cookieStorage())); |
| 91 | storageSession->setCookieStorage(jar.get()); |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | } // namespace WebKit |
| 96 | |