Title: [210729] trunk/Source
Revision
210729
Author
carlo...@webkit.org
Date
2017-01-13 00:24:54 -0800 (Fri, 13 Jan 2017)

Log Message

[SOUP] Simplify cookie storage handling
https://bugs.webkit.org/show_bug.cgi?id=166967

Reviewed by Sergio Villar Senin.

Source/WebCore:

We currently have a global cookie storage, and several create() methods in SoupNetworkSession to create sessions
with different cookie jars. This could be simplified by moving the cookie storage handling to
NetworkStorageSession and removing all create() methods from SoupNetworkSession. This patch also removes the
default SoupNetworkSession in favor of using the default NetworkStorageSession.

* platform/network/NetworkStorageSession.h: Add a default cookie storage to be used when the
NetworkStorageSession doesn't have a platform soup session.
* platform/network/soup/CookieJarSoup.cpp: Remove the global cookie storage handling.
(WebCore::setCookiesFromDOM): Use NetworkStorageSession::cookieStorage() instead.
(WebCore::cookiesForSession): Ditto.
(WebCore::cookiesEnabled): Check the policy instead like all other ports do, since now we will always have a
default shared cookie jar.
(WebCore::getRawCookies): Use NetworkStorageSession::cookieStorage() instead.
(WebCore::deleteCookie): Ditto.
(WebCore::addCookie): Ditto.
(WebCore::getHostnamesWithCookies): Ditto.
(WebCore::deleteCookiesForHostnames): Ditto.
(WebCore::deleteAllCookies): Ditto.
* platform/network/soup/CookieJarSoup.h: Removed.
* platform/network/soup/CookieStorageSoup.cpp:
(WebCore::soupCookiesChanged): Use the cookie storage from the NetworkStorageSession::defaultStorageSession().
(WebCore::startObservingCookieChanges): Ditto.
(WebCore::stopObservingCookieChanges): Ditto.
* platform/network/soup/DNSSoup.cpp:
(WebCore::DNSResolveQueue::updateIsUsingProxy): Get the SoupSession from the NetworkStorageSession::defaultStorageSession().
(WebCore::DNSResolveQueue::platformResolve): Ditto.
* platform/network/soup/NetworkStorageSessionSoup.cpp:
(WebCore::NetworkStorageSession::NetworkStorageSession):
(WebCore::NetworkStorageSession::ensurePrivateBrowsingSession): Create a new SoupNetworkSession without
providing a cookie storage to ensure it creates its own private one.
(WebCore::NetworkStorageSession::switchToNewTestingSession): Ditto.
(WebCore::NetworkStorageSession::soupNetworkSession): Create the SoupNetworkSession on demand passing the global
shared cookie storage.
(WebCore::NetworkStorageSession::cookieStorage): Return the cookie storage from the SoupNetworkSession if we
have one, otherwise create the global shared one and return it.
* platform/network/soup/ResourceHandleSoup.cpp:
(WebCore::sessionFromContext): Get the SoupSession from the NetworkStorageSession::defaultStorageSession().
* platform/network/soup/SoupNetworkSession.cpp:
(WebCore::SoupNetworkSession::SoupNetworkSession): Remove all create methods and the unused constructor that
receives a SoupSession. Allow to pass a nullptr SoupCookieJar and create one in such case.
* platform/network/soup/SoupNetworkSession.h:

Source/WebKit2:

Get the SoupSession from NetworkStorageSession::defaultStorageSession().

* NetworkProcess/CustomProtocols/soup/CustomProtocolManagerSoup.cpp:
(WebKit::CustomProtocolManager::registerScheme): Get the SoupSession from NetworkStorageSession::defaultStorageSession().
* NetworkProcess/efl/NetworkProcessMainEfl.cpp: Ditto.
* NetworkProcess/soup/NetworkProcessSoup.cpp:
(WebKit::NetworkProcess::userPreferredLanguagesChanged): Ditto.
(WebKit::NetworkProcess::platformInitializeNetworkProcess): SoupNetworkSession::clearOldSoupCache is static.
* WebProcess/Cookies/soup/WebCookieManagerSoup.cpp:
(WebKit::WebCookieManager::platformGetHTTPCookieAcceptPolicy): Use the cookie storage from NetworkStorageSession::defaultStorageSession().
(WebKit::WebCookieManager::setCookiePersistentStorage): Ditto.
* WebProcess/WebCoreSupport/soup/WebFrameNetworkingContext.cpp:
(WebKit::WebFrameNetworkingContext::setCookieAcceptPolicyForAllContexts): Ditto.
* WebProcess/efl/WebProcessMainEfl.cpp:

Modified Paths

Removed Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (210728 => 210729)


--- trunk/Source/WebCore/ChangeLog	2017-01-13 08:17:13 UTC (rev 210728)
+++ trunk/Source/WebCore/ChangeLog	2017-01-13 08:24:54 UTC (rev 210729)
@@ -1,3 +1,52 @@
+2017-01-13  Carlos Garcia Campos  <cgar...@igalia.com>
+
+        [SOUP] Simplify cookie storage handling
+        https://bugs.webkit.org/show_bug.cgi?id=166967
+
+        Reviewed by Sergio Villar Senin.
+
+        We currently have a global cookie storage, and several create() methods in SoupNetworkSession to create sessions
+        with different cookie jars. This could be simplified by moving the cookie storage handling to
+        NetworkStorageSession and removing all create() methods from SoupNetworkSession. This patch also removes the
+        default SoupNetworkSession in favor of using the default NetworkStorageSession.
+
+        * platform/network/NetworkStorageSession.h: Add a default cookie storage to be used when the
+        NetworkStorageSession doesn't have a platform soup session.
+        * platform/network/soup/CookieJarSoup.cpp: Remove the global cookie storage handling.
+        (WebCore::setCookiesFromDOM): Use NetworkStorageSession::cookieStorage() instead.
+        (WebCore::cookiesForSession): Ditto.
+        (WebCore::cookiesEnabled): Check the policy instead like all other ports do, since now we will always have a
+        default shared cookie jar.
+        (WebCore::getRawCookies): Use NetworkStorageSession::cookieStorage() instead.
+        (WebCore::deleteCookie): Ditto.
+        (WebCore::addCookie): Ditto.
+        (WebCore::getHostnamesWithCookies): Ditto.
+        (WebCore::deleteCookiesForHostnames): Ditto.
+        (WebCore::deleteAllCookies): Ditto.
+        * platform/network/soup/CookieJarSoup.h: Removed.
+        * platform/network/soup/CookieStorageSoup.cpp:
+        (WebCore::soupCookiesChanged): Use the cookie storage from the NetworkStorageSession::defaultStorageSession().
+        (WebCore::startObservingCookieChanges): Ditto.
+        (WebCore::stopObservingCookieChanges): Ditto.
+        * platform/network/soup/DNSSoup.cpp:
+        (WebCore::DNSResolveQueue::updateIsUsingProxy): Get the SoupSession from the NetworkStorageSession::defaultStorageSession().
+        (WebCore::DNSResolveQueue::platformResolve): Ditto.
+        * platform/network/soup/NetworkStorageSessionSoup.cpp:
+        (WebCore::NetworkStorageSession::NetworkStorageSession):
+        (WebCore::NetworkStorageSession::ensurePrivateBrowsingSession): Create a new SoupNetworkSession without
+        providing a cookie storage to ensure it creates its own private one.
+        (WebCore::NetworkStorageSession::switchToNewTestingSession): Ditto.
+        (WebCore::NetworkStorageSession::soupNetworkSession): Create the SoupNetworkSession on demand passing the global
+        shared cookie storage.
+        (WebCore::NetworkStorageSession::cookieStorage): Return the cookie storage from the SoupNetworkSession if we
+        have one, otherwise create the global shared one and return it.
+        * platform/network/soup/ResourceHandleSoup.cpp:
+        (WebCore::sessionFromContext): Get the SoupSession from the NetworkStorageSession::defaultStorageSession().
+        * platform/network/soup/SoupNetworkSession.cpp:
+        (WebCore::SoupNetworkSession::SoupNetworkSession): Remove all create methods and the unused constructor that
+        receives a SoupSession. Allow to pass a nullptr SoupCookieJar and create one in such case.
+        * platform/network/soup/SoupNetworkSession.h:
+
 2017-01-12  Tim Horton  <timothy_hor...@apple.com>
 
         Keyboard accessory bar can appear on top of full-screen video

Modified: trunk/Source/WebCore/platform/network/NetworkStorageSession.h (210728 => 210729)


--- trunk/Source/WebCore/platform/network/NetworkStorageSession.h	2017-01-13 08:17:13 UTC (rev 210728)
+++ trunk/Source/WebCore/platform/network/NetworkStorageSession.h	2017-01-13 08:24:54 UTC (rev 210729)
@@ -37,6 +37,7 @@
 #if USE(SOUP)
 #include <wtf/Function.h>
 #include <wtf/glib/GRefPtr.h>
+typedef struct _SoupCookieJar SoupCookieJar;
 #endif
 
 namespace WebCore {
@@ -67,10 +68,11 @@
     WEBCORE_EXPORT RetainPtr<CFHTTPCookieStorageRef> cookieStorage() const;
     WEBCORE_EXPORT static void setCookieStoragePartitioningEnabled(bool);
 #elif USE(SOUP)
-    NetworkStorageSession(SessionID, std::unique_ptr<SoupNetworkSession>);
+    NetworkStorageSession(SessionID, std::unique_ptr<SoupNetworkSession>&&);
     ~NetworkStorageSession();
 
     SoupNetworkSession& soupNetworkSession() const;
+    SoupCookieJar* cookieStorage() const;
     void getCredentialFromPersistentStorage(const ProtectionSpace&, Function<void (Credential&&)> completionHandler);
     void saveCredentialToPersistentStorage(const ProtectionSpace&, const Credential&);
 #else
@@ -87,7 +89,8 @@
 #if PLATFORM(COCOA) || USE(CFURLCONNECTION)
     RetainPtr<CFURLStorageSessionRef> m_platformSession;
 #elif USE(SOUP)
-    std::unique_ptr<SoupNetworkSession> m_session;
+    mutable std::unique_ptr<SoupNetworkSession> m_session;
+    mutable GRefPtr<SoupCookieJar> m_cookieStorage;
 #if USE(LIBSECRET)
     Function<void (Credential&&)> m_persisentStorageCompletionHandler;
     GRefPtr<GCancellable> m_persisentStorageCancellable;

Modified: trunk/Source/WebCore/platform/network/soup/CookieJarSoup.cpp (210728 => 210729)


--- trunk/Source/WebCore/platform/network/soup/CookieJarSoup.cpp	2017-01-13 08:17:13 UTC (rev 210728)
+++ trunk/Source/WebCore/platform/network/soup/CookieJarSoup.cpp	2017-01-13 08:24:54 UTC (rev 210729)
@@ -22,8 +22,6 @@
 
 #if USE(SOUP)
 
-#include "CookieJarSoup.h"
-
 #include "Cookie.h"
 #include "GUniquePtrSoup.h"
 #include "NetworkStorageSession.h"
@@ -37,42 +35,6 @@
 
 namespace WebCore {
 
-static SoupCookieJar* cookieJarForSession(const NetworkStorageSession& session)
-{
-    return session.soupNetworkSession().cookieJar();
-}
-
-static GRefPtr<SoupCookieJar>& defaultCookieJar()
-{
-    DEPRECATED_DEFINE_STATIC_LOCAL(GRefPtr<SoupCookieJar>, cookieJar, ());
-    return cookieJar;
-}
-
-SoupCookieJar* soupCookieJar()
-{
-    if (GRefPtr<SoupCookieJar>& jar = defaultCookieJar())
-        return jar.get();
-
-    SoupCookieJar* jar = soup_cookie_jar_new();
-    soup_cookie_jar_set_accept_policy(jar, SOUP_COOKIE_JAR_ACCEPT_NO_THIRD_PARTY);
-    setSoupCookieJar(jar);
-    return jar;
-}
-
-SoupCookieJar* createPrivateBrowsingCookieJar()
-{
-    SoupCookieJar* jar = soup_cookie_jar_new();
-
-    soup_cookie_jar_set_accept_policy(jar, SOUP_COOKIE_JAR_ACCEPT_NO_THIRD_PARTY);
-
-    return jar;
-}
-
-void setSoupCookieJar(SoupCookieJar* jar)
-{
-    defaultCookieJar() = jar;
-}
-
 static inline bool httpOnlyCookieExists(const GSList* cookies, const gchar* name, const gchar* path)
 {
     for (const GSList* iter = cookies; iter; iter = g_slist_next(iter)) {
@@ -89,9 +51,7 @@
 
 void setCookiesFromDOM(const NetworkStorageSession& session, const URL& firstParty, const URL& url, const String& value)
 {
-    SoupCookieJar* jar = cookieJarForSession(session);
-    if (!jar)
-        return;
+    SoupCookieJar* jar = session.cookieStorage();
 
     GUniquePtr<SoupURI> origin = url.createSoupURI();
     GUniquePtr<SoupURI> firstPartyURI = firstParty.createSoupURI();
@@ -123,12 +83,8 @@
 
 static String cookiesForSession(const NetworkStorageSession& session, const URL& url, bool forHTTPHeader)
 {
-    SoupCookieJar* jar = cookieJarForSession(session);
-    if (!jar)
-        return String();
-
     GUniquePtr<SoupURI> uri = url.createSoupURI();
-    GUniquePtr<char> cookies(soup_cookie_jar_get_cookies(jar, uri.get(), forHTTPHeader));
+    GUniquePtr<char> cookies(soup_cookie_jar_get_cookies(session.cookieStorage(), uri.get(), forHTTPHeader));
     return String::fromUTF8(cookies.get());
 }
 
@@ -144,18 +100,15 @@
 
 bool cookiesEnabled(const NetworkStorageSession& session, const URL& /*firstParty*/, const URL& /*url*/)
 {
-    return !!cookieJarForSession(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 URL& url, Vector<Cookie>& rawCookies)
 {
     rawCookies.clear();
-    SoupCookieJar* jar = cookieJarForSession(session);
-    if (!jar)
-        return false;
-
     GUniquePtr<SoupURI> uri = url.createSoupURI();
-    GUniquePtr<GSList> cookies(soup_cookie_jar_get_cookie_list(jar, uri.get(), TRUE));
+    GUniquePtr<GSList> cookies(soup_cookie_jar_get_cookie_list(session.cookieStorage(), uri.get(), TRUE));
     if (!cookies)
         return false;
 
@@ -172,9 +125,7 @@
 
 void deleteCookie(const NetworkStorageSession& session, const URL& url, const String& name)
 {
-    SoupCookieJar* jar = cookieJarForSession(session);
-    if (!jar)
-        return;
+    SoupCookieJar* jar = session.cookieStorage();
 
     GUniquePtr<SoupURI> uri = url.createSoupURI();
     GUniquePtr<GSList> cookies(soup_cookie_jar_get_cookie_list(jar, uri.get(), TRUE));
@@ -217,13 +168,12 @@
 
 void addCookie(const NetworkStorageSession& session, const URL&, const Cookie& cookie)
 {
-    soup_cookie_jar_add_cookie(cookieJarForSession(session), toSoupCookie(cookie));
+    soup_cookie_jar_add_cookie(session.cookieStorage(), toSoupCookie(cookie));
 }
 
 void getHostnamesWithCookies(const NetworkStorageSession& session, HashSet<String>& hostnames)
 {
-    SoupCookieJar* cookieJar = cookieJarForSession(session);
-    GUniquePtr<GSList> cookies(soup_cookie_jar_all_cookies(cookieJar));
+    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)
@@ -234,9 +184,11 @@
 
 void deleteCookiesForHostnames(const NetworkStorageSession& session, const Vector<String>& hostnames)
 {
+    SoupCookieJar* cookieJar = session.cookieStorage();
+
     for (const auto& hostname : hostnames) {
         CString hostNameString = hostname.utf8();
-        SoupCookieJar* cookieJar = cookieJarForSession(session);
+
         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);
@@ -249,7 +201,7 @@
 
 void deleteAllCookies(const NetworkStorageSession& session)
 {
-    SoupCookieJar* cookieJar = cookieJarForSession(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);

Deleted: trunk/Source/WebCore/platform/network/soup/CookieJarSoup.h (210728 => 210729)


--- trunk/Source/WebCore/platform/network/soup/CookieJarSoup.h	2017-01-13 08:17:13 UTC (rev 210728)
+++ trunk/Source/WebCore/platform/network/soup/CookieJarSoup.h	2017-01-13 08:24:54 UTC (rev 210729)
@@ -1,41 +0,0 @@
-/*
- * Copyright (C) 2008 Xan Lopez <x...@gnome.org>
- * Copyright (C) 2008 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.
- */
-
-#ifndef CookieJarSoup_h
-#define CookieJarSoup_h
-
-#include <libsoup/soup.h>
-
-namespace WebCore {
-
-SoupCookieJar* soupCookieJar();
-void setSoupCookieJar(SoupCookieJar*);
-
-SoupCookieJar* createPrivateBrowsingCookieJar();
-
-}
-
-#endif

Modified: trunk/Source/WebCore/platform/network/soup/CookieStorageSoup.cpp (210728 => 210729)


--- trunk/Source/WebCore/platform/network/soup/CookieStorageSoup.cpp	2017-01-13 08:17:13 UTC (rev 210728)
+++ trunk/Source/WebCore/platform/network/soup/CookieStorageSoup.cpp	2017-01-13 08:24:54 UTC (rev 210729)
@@ -21,18 +21,16 @@
 
 #if USE(SOUP)
 
-#include "CookieJarSoup.h"
-#include "NotImplemented.h"
+#include "NetworkStorageSession.h"
+#include <libsoup/soup.h>
 
-#include <stdio.h>
-
 namespace WebCore {
 
 static CookieChangeCallbackPtr cookieChangeCallback;
 
-static void soupCookiesChanged(SoupCookieJar* jar, SoupCookie*, SoupCookie*, gpointer)
+static void soupCookiesChanged(SoupCookieJar* jar)
 {
-    if (jar != soupCookieJar())
+    if (jar != NetworkStorageSession::defaultStorageSession().cookieStorage())
         return;
     cookieChangeCallback();
 }
@@ -42,13 +40,13 @@
     ASSERT(!cookieChangeCallback);
     cookieChangeCallback = callback;
 
-    g_signal_connect(soupCookieJar(), "changed", G_CALLBACK(soupCookiesChanged), 0);
+    g_signal_connect(NetworkStorageSession::defaultStorageSession().cookieStorage(), "changed", G_CALLBACK(soupCookiesChanged), 0);
 }
 
 void stopObservingCookieChanges()
 {
-    g_signal_handlers_disconnect_by_func(soupCookieJar(), reinterpret_cast<void*>(soupCookiesChanged), 0);
-    cookieChangeCallback = 0;
+    g_signal_handlers_disconnect_by_func(NetworkStorageSession::defaultStorageSession().cookieStorage(), reinterpret_cast<void*>(soupCookiesChanged), nullptr);
+    cookieChangeCallback = nullptr;
 }
 
 }

Modified: trunk/Source/WebCore/platform/network/soup/DNSSoup.cpp (210728 => 210729)


--- trunk/Source/WebCore/platform/network/soup/DNSSoup.cpp	2017-01-13 08:17:13 UTC (rev 210728)
+++ trunk/Source/WebCore/platform/network/soup/DNSSoup.cpp	2017-01-13 08:24:54 UTC (rev 210729)
@@ -30,6 +30,7 @@
 
 #if USE(SOUP)
 
+#include "NetworkStorageSession.h"
 #include "SoupNetworkSession.h"
 #include <libsoup/soup.h>
 #include <wtf/MainThread.h>
@@ -78,7 +79,7 @@
 void DNSResolveQueue::updateIsUsingProxy()
 {
     GRefPtr<GProxyResolver> resolver;
-    g_object_get(SoupNetworkSession::defaultSession().soupSession(), "proxy-resolver", &resolver.outPtr(), nullptr);
+    g_object_get(NetworkStorageSession::defaultStorageSession().soupNetworkSession().soupSession(), "proxy-resolver", &resolver.outPtr(), nullptr);
     ASSERT(resolver);
 
     g_proxy_resolver_lookup_async(resolver.get(), "http://example.com/", nullptr, proxyResolvedForHttpUriCallback, &m_isUsingProxy);
@@ -94,7 +95,7 @@
 {
     ASSERT(isMainThread());
 
-    soup_session_prefetch_dns(SoupNetworkSession::defaultSession().soupSession(), hostname.utf8().data(), nullptr, resolvedCallback, nullptr);
+    soup_session_prefetch_dns(NetworkStorageSession::defaultStorageSession().soupNetworkSession().soupSession(), hostname.utf8().data(), nullptr, resolvedCallback, nullptr);
 }
 
 void prefetchDNS(const String& hostname)

Modified: trunk/Source/WebCore/platform/network/soup/NetworkStorageSessionSoup.cpp (210728 => 210729)


--- trunk/Source/WebCore/platform/network/soup/NetworkStorageSessionSoup.cpp	2017-01-13 08:17:13 UTC (rev 210728)
+++ trunk/Source/WebCore/platform/network/soup/NetworkStorageSessionSoup.cpp	2017-01-13 08:24:54 UTC (rev 210729)
@@ -47,7 +47,7 @@
 
 namespace WebCore {
 
-NetworkStorageSession::NetworkStorageSession(SessionID sessionID, std::unique_ptr<SoupNetworkSession> session)
+NetworkStorageSession::NetworkStorageSession(SessionID sessionID, std::unique_ptr<SoupNetworkSession>&& session)
     : m_sessionID(sessionID)
     , m_session(WTFMove(session))
 {
@@ -76,22 +76,40 @@
 
 void NetworkStorageSession::ensurePrivateBrowsingSession(SessionID sessionID, const String&)
 {
-    auto session = std::make_unique<NetworkStorageSession>(sessionID, SoupNetworkSession::createPrivateBrowsingSession());
     ASSERT(sessionID != SessionID::defaultSessionID());
     ASSERT(!globalSessionMap().contains(sessionID));
-    globalSessionMap().add(sessionID, WTFMove(session));
+    globalSessionMap().add(sessionID, std::make_unique<NetworkStorageSession>(sessionID, std::make_unique<SoupNetworkSession>()));
 }
 
 void NetworkStorageSession::switchToNewTestingSession()
 {
-    defaultSession() = std::make_unique<NetworkStorageSession>(SessionID::defaultSessionID(), SoupNetworkSession::createTestingSession());
+    defaultSession() = std::make_unique<NetworkStorageSession>(SessionID::defaultSessionID(), std::make_unique<SoupNetworkSession>());
+    // FIXME: Creating a testing session is losing soup session values set when initializing the network process.
+    g_object_set(defaultSession()->soupNetworkSession().soupSession(), "accept-language", "en-us", nullptr);
 }
 
 SoupNetworkSession& NetworkStorageSession::soupNetworkSession() const
 {
-    return m_session ? *m_session : SoupNetworkSession::defaultSession();
+    if (!m_session)
+        m_session = std::make_unique<SoupNetworkSession>(cookieStorage());
+    return *m_session;
 }
 
+SoupCookieJar* NetworkStorageSession::cookieStorage() const
+{
+    if (m_session) {
+        m_cookieStorage = nullptr;
+        ASSERT(m_session->cookieJar());
+        return m_session->cookieJar();
+    }
+
+    if (!m_cookieStorage) {
+        m_cookieStorage = adoptGRef(soup_cookie_jar_new());
+        soup_cookie_jar_set_accept_policy(m_cookieStorage.get(), SOUP_COOKIE_JAR_ACCEPT_NO_THIRD_PARTY);
+    }
+    return m_cookieStorage.get();
+}
+
 #if USE(LIBSECRET)
 static const char* schemeFromProtectionSpaceServerType(ProtectionSpaceServerType serverType)
 {

Modified: trunk/Source/WebCore/platform/network/soup/ResourceHandleSoup.cpp (210728 => 210729)


--- trunk/Source/WebCore/platform/network/soup/ResourceHandleSoup.cpp	2017-01-13 08:17:13 UTC (rev 210728)
+++ trunk/Source/WebCore/platform/network/soup/ResourceHandleSoup.cpp	2017-01-13 08:24:54 UTC (rev 210729)
@@ -31,7 +31,6 @@
 
 #if USE(SOUP)
 
-#include "CookieJarSoup.h"
 #include "CredentialStorage.h"
 #include "FileSystem.h"
 #include "GUniquePtrSoup.h"
@@ -81,7 +80,7 @@
 static SoupSession* sessionFromContext(NetworkingContext* context)
 {
     if (!context || !context->isValid())
-        return SoupNetworkSession::defaultSession().soupSession();
+        return NetworkStorageSession::defaultStorageSession().soupNetworkSession().soupSession();
     return context->storageSession().soupNetworkSession().soupSession();
 }
 

Modified: trunk/Source/WebCore/platform/network/soup/SoupNetworkSession.cpp (210728 => 210729)


--- trunk/Source/WebCore/platform/network/soup/SoupNetworkSession.cpp	2017-01-13 08:17:13 UTC (rev 210728)
+++ trunk/Source/WebCore/platform/network/soup/SoupNetworkSession.cpp	2017-01-13 08:24:54 UTC (rev 210729)
@@ -30,7 +30,6 @@
 #include "SoupNetworkSession.h"
 
 #include "AuthenticationChallenge.h"
-#include "CookieJarSoup.h"
 #include "CryptoDigest.h"
 #include "FileSystem.h"
 #include "GUniquePtrSoup.h"
@@ -93,31 +92,6 @@
     return certificates;
 }
 
-SoupNetworkSession& SoupNetworkSession::defaultSession()
-{
-    static NeverDestroyed<SoupNetworkSession> networkSession(soupCookieJar());
-    return networkSession;
-}
-
-std::unique_ptr<SoupNetworkSession> SoupNetworkSession::createPrivateBrowsingSession()
-{
-    return std::unique_ptr<SoupNetworkSession>(new SoupNetworkSession(soupCookieJar()));
-}
-
-std::unique_ptr<SoupNetworkSession> SoupNetworkSession::createTestingSession()
-{
-    auto cookieJar = adoptGRef(createPrivateBrowsingCookieJar());
-    auto newSoupSession = std::unique_ptr<SoupNetworkSession>(new SoupNetworkSession(cookieJar.get()));
-    // FIXME: Creating a testing session is losing soup session values set when initializing the network process.
-    g_object_set(newSoupSession->soupSession(), "accept-language", "en-us", nullptr);
-    return newSoupSession;
-}
-
-std::unique_ptr<SoupNetworkSession> SoupNetworkSession::createForSoupSession(SoupSession* soupSession)
-{
-    return std::unique_ptr<SoupNetworkSession>(new SoupNetworkSession(soupSession));
-}
-
 static void authenticateCallback(SoupSession*, SoupMessage* soupMessage, SoupAuth* soupAuth, gboolean retrying)
 {
     RefPtr<ResourceHandle> handle = static_cast<ResourceHandle*>(g_object_get_data(G_OBJECT(soupMessage), "handle"));
@@ -146,6 +120,12 @@
     static const int maxConnections = 17;
     static const int maxConnectionsPerHost = 6;
 
+    GRefPtr<SoupCookieJar> jar = cookieJar;
+    if (!jar) {
+        jar = adoptGRef(soup_cookie_jar_new());
+        soup_cookie_jar_set_accept_policy(jar.get(), SOUP_COOKIE_JAR_ACCEPT_NO_THIRD_PARTY);
+    }
+
     g_object_set(m_soupSession.get(),
         SOUP_SESSION_MAX_CONNS, maxConnections,
         SOUP_SESSION_MAX_CONNS_PER_HOST, maxConnectionsPerHost,
@@ -152,7 +132,7 @@
         SOUP_SESSION_ADD_FEATURE_BY_TYPE, SOUP_TYPE_CONTENT_DECODER,
         SOUP_SESSION_ADD_FEATURE_BY_TYPE, SOUP_TYPE_CONTENT_SNIFFER,
         SOUP_SESSION_ADD_FEATURE_BY_TYPE, SOUP_TYPE_PROXY_RESOLVER_DEFAULT,
-        SOUP_SESSION_ADD_FEATURE, cookieJar,
+        SOUP_SESSION_ADD_FEATURE, jar.get(),
         SOUP_SESSION_USE_THREAD_CONTEXT, TRUE,
         SOUP_SESSION_SSL_USE_SYSTEM_CA_FILE, TRUE,
         SOUP_SESSION_SSL_STRICT, FALSE,
@@ -174,12 +154,6 @@
 #endif
 }
 
-SoupNetworkSession::SoupNetworkSession(SoupSession* soupSession)
-    : m_soupSession(soupSession)
-{
-    setupLogger();
-}
-
 SoupNetworkSession::~SoupNetworkSession()
 {
 }

Modified: trunk/Source/WebCore/platform/network/soup/SoupNetworkSession.h (210728 => 210729)


--- trunk/Source/WebCore/platform/network/soup/SoupNetworkSession.h	2017-01-13 08:17:13 UTC (rev 210728)
+++ trunk/Source/WebCore/platform/network/soup/SoupNetworkSession.h	2017-01-13 08:24:54 UTC (rev 210729)
@@ -46,13 +46,9 @@
 class SoupNetworkSession {
     WTF_MAKE_NONCOPYABLE(SoupNetworkSession); WTF_MAKE_FAST_ALLOCATED;
 public:
+    SoupNetworkSession(SoupCookieJar* = nullptr);
     ~SoupNetworkSession();
 
-    static SoupNetworkSession& defaultSession();
-    static std::unique_ptr<SoupNetworkSession> createPrivateBrowsingSession();
-    static std::unique_ptr<SoupNetworkSession> createTestingSession();
-    static std::unique_ptr<SoupNetworkSession> createForSoupSession(SoupSession*);
-
     SoupSession* soupSession() const { return m_soupSession.get(); }
 
     void setCookieJar(SoupCookieJar*);
@@ -69,11 +65,6 @@
     static void allowSpecificHTTPSCertificateForHost(const CertificateInfo&, const String& host);
 
 private:
-    friend class NeverDestroyed<SoupNetworkSession>;
-
-    SoupNetworkSession(SoupCookieJar*);
-    SoupNetworkSession(SoupSession*);
-
     void setHTTPProxy(const char* httpProxy, const char* httpProxyExceptions);
 
     void setupLogger();

Modified: trunk/Source/WebKit2/ChangeLog (210728 => 210729)


--- trunk/Source/WebKit2/ChangeLog	2017-01-13 08:17:13 UTC (rev 210728)
+++ trunk/Source/WebKit2/ChangeLog	2017-01-13 08:24:54 UTC (rev 210729)
@@ -1,3 +1,25 @@
+2017-01-13  Carlos Garcia Campos  <cgar...@igalia.com>
+
+        [SOUP] Simplify cookie storage handling
+        https://bugs.webkit.org/show_bug.cgi?id=166967
+
+        Reviewed by Sergio Villar Senin.
+
+        Get the SoupSession from NetworkStorageSession::defaultStorageSession().
+
+        * NetworkProcess/CustomProtocols/soup/CustomProtocolManagerSoup.cpp:
+        (WebKit::CustomProtocolManager::registerScheme): Get the SoupSession from NetworkStorageSession::defaultStorageSession().
+        * NetworkProcess/efl/NetworkProcessMainEfl.cpp: Ditto.
+        * NetworkProcess/soup/NetworkProcessSoup.cpp:
+        (WebKit::NetworkProcess::userPreferredLanguagesChanged): Ditto.
+        (WebKit::NetworkProcess::platformInitializeNetworkProcess): SoupNetworkSession::clearOldSoupCache is static.
+        * WebProcess/Cookies/soup/WebCookieManagerSoup.cpp:
+        (WebKit::WebCookieManager::platformGetHTTPCookieAcceptPolicy): Use the cookie storage from NetworkStorageSession::defaultStorageSession().
+        (WebKit::WebCookieManager::setCookiePersistentStorage): Ditto.
+        * WebProcess/WebCoreSupport/soup/WebFrameNetworkingContext.cpp:
+        (WebKit::WebFrameNetworkingContext::setCookieAcceptPolicyForAllContexts): Ditto.
+        * WebProcess/efl/WebProcessMainEfl.cpp:
+
 2017-01-12  Carlos Garcia Campos  <cgar...@igalia.com>
 
         [SOUP] Do not use the legacy session ID in WebFrameNetworkingContext::storageSession()

Modified: trunk/Source/WebKit2/NetworkProcess/CustomProtocols/soup/CustomProtocolManagerSoup.cpp (210728 => 210729)


--- trunk/Source/WebKit2/NetworkProcess/CustomProtocols/soup/CustomProtocolManagerSoup.cpp	2017-01-13 08:17:13 UTC (rev 210728)
+++ trunk/Source/WebKit2/NetworkProcess/CustomProtocols/soup/CustomProtocolManagerSoup.cpp	2017-01-13 08:24:54 UTC (rev 210729)
@@ -24,6 +24,7 @@
 #include "DataReference.h"
 #include "NetworkProcess.h"
 #include "WebKitSoupRequestInputStream.h"
+#include <WebCore/NetworkStorageSession.h>
 #include <WebCore/NotImplemented.h>
 #include <WebCore/ResourceError.h>
 #include <WebCore/ResourceRequest.h>
@@ -90,7 +91,7 @@
 
     auto* genericRequestClass = static_cast<SoupRequestClass*>(g_type_class_ref(WEBKIT_TYPE_SOUP_REQUEST_GENERIC));
     genericRequestClass->schemes = const_cast<const char**>(reinterpret_cast<char**>(m_registeredSchemes->pdata));
-    soup_session_add_feature_by_type(SoupNetworkSession::defaultSession().soupSession(), WEBKIT_TYPE_SOUP_REQUEST_GENERIC);
+    soup_session_add_feature_by_type(NetworkStorageSession::defaultStorageSession().soupNetworkSession().soupSession(), WEBKIT_TYPE_SOUP_REQUEST_GENERIC);
 }
 
 void CustomProtocolManager::unregisterScheme(const String&)

Modified: trunk/Source/WebKit2/NetworkProcess/efl/NetworkProcessMainEfl.cpp (210728 => 210729)


--- trunk/Source/WebKit2/NetworkProcess/efl/NetworkProcessMainEfl.cpp	2017-01-13 08:17:13 UTC (rev 210728)
+++ trunk/Source/WebKit2/NetworkProcess/efl/NetworkProcessMainEfl.cpp	2017-01-13 08:24:54 UTC (rev 210729)
@@ -30,6 +30,7 @@
 #include "ChildProcessMain.h"
 #include "NetworkProcess.h"
 #include <Ecore.h>
+#include <WebCore/NetworkStorageSession.h>
 #include <WebCore/SoupNetworkSession.h>
 #include <libsoup/soup.h>
 
@@ -47,7 +48,7 @@
         if (!ecore_main_loop_glib_integrate())
             return false;
 
-        SoupNetworkSession::defaultSession().setupHTTPProxyFromEnvironment();
+        NetworkStorageSession::defaultStorageSession().soupNetworkSession().setupHTTPProxyFromEnvironment();
         return true;
     }
 

Modified: trunk/Source/WebKit2/NetworkProcess/soup/NetworkProcessSoup.cpp (210728 => 210729)


--- trunk/Source/WebKit2/NetworkProcess/soup/NetworkProcessSoup.cpp	2017-01-13 08:17:13 UTC (rev 210728)
+++ trunk/Source/WebKit2/NetworkProcess/soup/NetworkProcessSoup.cpp	2017-01-13 08:24:54 UTC (rev 210729)
@@ -33,6 +33,7 @@
 #include "WebCookieManager.h"
 #include <WebCore/CertificateInfo.h>
 #include <WebCore/FileSystem.h>
+#include <WebCore/NetworkStorageSession.h>
 #include <WebCore/NotImplemented.h>
 #include <WebCore/ResourceHandle.h>
 #include <WebCore/SoupNetworkSession.h>
@@ -47,7 +48,7 @@
 
 void NetworkProcess::userPreferredLanguagesChanged(const Vector<String>& languages)
 {
-    SoupNetworkSession::defaultSession().setAcceptLanguages(languages);
+    NetworkStorageSession::defaultStorageSession().soupNetworkSession().setAcceptLanguages(languages);
 }
 
 void NetworkProcess::platformInitializeNetworkProcess(const NetworkProcessCreationParameters& parameters)
@@ -55,7 +56,7 @@
     ASSERT(!parameters.diskCacheDirectory.isEmpty());
     m_diskCacheDirectory = parameters.diskCacheDirectory;
 
-    SoupNetworkSession::defaultSession().clearOldSoupCache(WebCore::directoryName(m_diskCacheDirectory));
+    SoupNetworkSession::clearOldSoupCache(WebCore::directoryName(m_diskCacheDirectory));
 
     NetworkCache::Cache::Parameters cacheParameters {
         parameters.shouldEnableNetworkCacheEfficacyLogging

Modified: trunk/Source/WebKit2/WebProcess/Cookies/soup/WebCookieManagerSoup.cpp (210728 => 210729)


--- trunk/Source/WebKit2/WebProcess/Cookies/soup/WebCookieManagerSoup.cpp	2017-01-13 08:17:13 UTC (rev 210728)
+++ trunk/Source/WebKit2/WebProcess/Cookies/soup/WebCookieManagerSoup.cpp	2017-01-13 08:24:54 UTC (rev 210729)
@@ -29,7 +29,7 @@
 #include "ChildProcess.h"
 #include "WebFrameNetworkingContext.h"
 #include "WebKitSoupCookieJarSqlite.h"
-#include <WebCore/CookieJarSoup.h>
+#include <WebCore/NetworkStorageSession.h>
 #include <WebCore/SoupNetworkSession.h>
 #include <libsoup/soup.h>
 #include <wtf/glib/GRefPtr.h>
@@ -46,26 +46,17 @@
 
 HTTPCookieAcceptPolicy WebCookieManager::platformGetHTTPCookieAcceptPolicy()
 {
-    SoupCookieJar* cookieJar = WebCore::soupCookieJar();
-    SoupCookieJarAcceptPolicy soupPolicy;
-
-    HTTPCookieAcceptPolicy policy;
-
-    soupPolicy = soup_cookie_jar_get_accept_policy(cookieJar);
-    switch (soupPolicy) {
+    switch (soup_cookie_jar_get_accept_policy(NetworkStorageSession::defaultStorageSession().cookieStorage())) {
     case SOUP_COOKIE_JAR_ACCEPT_ALWAYS:
-        policy = HTTPCookieAcceptPolicyAlways;
-        break;
+        return HTTPCookieAcceptPolicyAlways;
     case SOUP_COOKIE_JAR_ACCEPT_NEVER:
-        policy = HTTPCookieAcceptPolicyNever;
-        break;
+        return HTTPCookieAcceptPolicyNever;
     case SOUP_COOKIE_JAR_ACCEPT_NO_THIRD_PARTY:
-        policy = HTTPCookieAcceptPolicyOnlyFromMainDocumentDomain;
-        break;
-    default:
-        policy = HTTPCookieAcceptPolicyAlways;
+        return HTTPCookieAcceptPolicyOnlyFromMainDocumentDomain;
     }
-    return policy;
+
+    ASSERT_NOT_REACHED();
+    return HTTPCookieAcceptPolicyOnlyFromMainDocumentDomain;
 }
 
 void WebCookieManager::setCookiePersistentStorage(const String& storagePath, uint32_t storageType)
@@ -82,9 +73,9 @@
         ASSERT_NOT_REACHED();
     }
 
-    soup_cookie_jar_set_accept_policy(jar.get(), soup_cookie_jar_get_accept_policy(WebCore::soupCookieJar()));
-    SoupNetworkSession::defaultSession().setCookieJar(jar.get());
-    WebCore::setSoupCookieJar(jar.get());
+    auto& storageSession = NetworkStorageSession::defaultStorageSession();
+    soup_cookie_jar_set_accept_policy(jar.get(), soup_cookie_jar_get_accept_policy(storageSession.cookieStorage()));
+    storageSession.soupNetworkSession().setCookieJar(jar.get());
 }
 
 } // namespace WebKit

Modified: trunk/Source/WebKit2/WebProcess/WebCoreSupport/soup/WebFrameNetworkingContext.cpp (210728 => 210729)


--- trunk/Source/WebKit2/WebProcess/WebCoreSupport/soup/WebFrameNetworkingContext.cpp	2017-01-13 08:17:13 UTC (rev 210728)
+++ trunk/Source/WebKit2/WebProcess/WebCoreSupport/soup/WebFrameNetworkingContext.cpp	2017-01-13 08:24:54 UTC (rev 210729)
@@ -31,7 +31,6 @@
 #include "SessionTracker.h"
 #include "WebFrame.h"
 #include "WebPage.h"
-#include <WebCore/CookieJarSoup.h>
 #include <WebCore/NetworkStorageSession.h>
 #include <WebCore/SessionID.h>
 #include <WebCore/Settings.h>
@@ -68,11 +67,10 @@
         break;
     }
 
-    SoupCookieJar* cookieJar = WebCore::soupCookieJar();
-    soup_cookie_jar_set_accept_policy(cookieJar, soupPolicy);
+    soup_cookie_jar_set_accept_policy(NetworkStorageSession::defaultStorageSession().cookieStorage(), soupPolicy);
 
     NetworkStorageSession::forEach([&] (const NetworkStorageSession& session) {
-        soup_cookie_jar_set_accept_policy(session.soupNetworkSession().cookieJar(), soupPolicy);
+        soup_cookie_jar_set_accept_policy(session.cookieStorage(), soupPolicy);
     });
 }
 

Modified: trunk/Source/WebKit2/WebProcess/efl/WebProcessMainEfl.cpp (210728 => 210729)


--- trunk/Source/WebKit2/WebProcess/efl/WebProcessMainEfl.cpp	2017-01-13 08:17:13 UTC (rev 210728)
+++ trunk/Source/WebKit2/WebProcess/efl/WebProcessMainEfl.cpp	2017-01-13 08:24:54 UTC (rev 210729)
@@ -32,6 +32,7 @@
 #include <Ecore_Evas.h>
 #include <Edje.h>
 #include <Efreet.h>
+#include <WebCore/NetworkStorageSession.h>
 #include <WebCore/SoupNetworkSession.h>
 #include <libsoup/soup.h>
 
@@ -98,7 +99,7 @@
         if (!ecore_main_loop_glib_integrate())
             return false;
 
-        SoupNetworkSession::defaultSession().setupHTTPProxyFromEnvironment();
+        NetworkStorageSession::defaultStorageSession().soupNetworkSession().setupHTTPProxyFromEnvironment();
         return true;
     }
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to