Changeset 248010 in webkit


Ignore:
Timestamp:
Jul 30, 2019 9:31:05 AM (5 years ago)
Author:
Carlos Garcia Campos
Message:

[SOUP] Move SoupNetworkSession ownership from NetworkStorageSession to NetworkSession
https://bugs.webkit.org/show_bug.cgi?id=200076

Reviewed by Michael Catanzaro.

Source/WebCore:

Remove the SoupNetworkSession from NetworkStorageSession.

  • platform/network/NetworkStorageSession.h:

(WebCore::NetworkStorageSession::cookieStorage const): Return the cookie jar.

  • platform/network/StorageSessionProvider.h:

(WebCore::StorageSessionProvider::soupSession const): Temporary add this virtual method that is required by
SocketStreamHandleImplSoup. It will be removed once we switch to libsoup WebSockets API soon.

  • platform/network/soup/DNSResolveQueueSoup.cpp:

(WebCore::globalDefaultSoupSessionAccessor): Rework the accessor to return the SoupSession directly since
that's what we really want.
(WebCore::DNSResolveQueueSoup::setGlobalDefaultSoupSessionAccessor):
(WebCore::DNSResolveQueueSoup::updateIsUsingProxy):
(WebCore::DNSResolveQueueSoup::platformResolve):
(WebCore::DNSResolveQueueSoup::resolve):

  • platform/network/soup/DNSResolveQueueSoup.h:
  • platform/network/soup/NetworkStorageSessionSoup.cpp:

(WebCore::NetworkStorageSession::NetworkStorageSession): Create and setup the default cookie jar.
(WebCore::NetworkStorageSession::~NetworkStorageSession): Only disconnect the cookie jar signals.
(WebCore::NetworkStorageSession::setCookieStorage): Update the cookie jar, now we know it's always a new one.

  • platform/network/soup/SocketStreamHandleImplSoup.cpp:

(WebCore::SocketStreamHandleImpl::create): Use the new virtual method from StorageSessionProvider to get the SoupSession.

  • platform/network/soup/SoupNetworkSession.cpp:

(WebCore::SoupNetworkSession::SoupNetworkSession): Remove the SoupCookieJar parameter.

  • platform/network/soup/SoupNetworkSession.h:

Source/WebKit:

NetworkStorageSession should only own the cookie jar, since it's the only thing it handles from the session.

  • NetworkProcess/Cookies/soup/WebCookieManagerSoup.cpp:

(WebKit::WebCookieManager::setCookiePersistentStorage): Use the network session instead of the storage session
to set the peristent cookie storage.

  • NetworkProcess/CustomProtocols/soup/LegacyCustomProtocolManagerSoup.cpp:

(WebKit::LegacyCustomProtocolManager::registerScheme): Iterate network sessions instead of storage sessions to
access the SoupNetworkSession.

  • NetworkProcess/NetworkConnectionToWebProcess.cpp:

(WebKit::NetworkConnectionToWebProcess::resourceLoadStatisticsUpdated): Use
NetworkProcess::forEachNetworkSession() to iterate network sessions.

  • NetworkProcess/NetworkProcess.cpp:

(WebKit::NetworkProcess::lowMemoryHandler): Ditto.
(WebKit::NetworkProcess::forEachNetworkSession): Added to iterate network sessions intead of exposing the map
that is always used to iterate the sessions.
(WebKit::NetworkProcess::switchToNewTestingSession): Use the new NetworkStorageSession constructor API.
(WebKit::NetworkProcess::ensureSession): Ditto.
(WebKit::NetworkProcess::destroySession): Allow to destroy the default session for soup based ports. This is
only called right before process exit to ensure we don't leak network resources like the cookies database.
(WebKit::NetworkProcess::setResourceLoadStatisticsEnabled): Use NetworkProcess::forEachNetworkSession() to
iterate network sessions.
(WebKit::NetworkProcess::fetchWebsiteData): Ditto.
(WebKit::NetworkProcess::deleteWebsiteDataForOrigins): Ditto.
(WebKit::NetworkProcess::deleteWebsiteDataForRegistrableDomains): Ditto.
(WebKit::NetworkProcess::registrableDomainsWithWebsiteData): Ditto.
(WebKit::NetworkProcess::setCacheModel): Ditto.
(WebKit::NetworkProcess::actualPrepareToSuspend): Ditto.
(WebKit::NetworkProcess::resume): Ditto.

  • NetworkProcess/NetworkProcess.h:
  • NetworkProcess/NetworkStorageSessionProvider.h:
  • NetworkProcess/cocoa/NetworkProcessCocoa.mm:

(WebKit::NetworkProcess::clearDiskCache): Ditto.

  • NetworkProcess/ios/NetworkProcessIOS.mm:

(WebKit::NetworkProcess::clearCacheForAllOrigins): Ditto.

  • NetworkProcess/soup/NetworkProcessMainSoup.cpp: Destroy the default session before process exists.
  • NetworkProcess/soup/NetworkProcessSoup.cpp:

(WebKit::NetworkProcess::userPreferredLanguagesChanged): Iterate network sessions instead of storage sessions to
access the SoupNetworkSession.
(WebKit::NetworkProcess::platformCreateDefaultStorageSession const): Use the new NetworkStorageSession constructor API.
(WebKit::NetworkProcess::clearDiskCache): Use NetworkProcess::forEachNetworkSession() to iterate network sessions.
(WebKit::NetworkProcess::setNetworkProxySettings): Iterate network sessions instead of storage sessions to
access the SoupNetworkSession.

  • NetworkProcess/soup/NetworkSessionSoup.cpp:

(WebKit::NetworkSessionSoup::NetworkSessionSoup): Create the SoupNetworkSession and setup cookies.
(WebKit::NetworkSessionSoup::soupSession const): Return the SoupSession of SoupNetworkSession.
(WebKit::NetworkSessionSoup::setCookiePersistentStorage): Setup a new cookie jar.

  • NetworkProcess/soup/NetworkSessionSoup.h:
Location:
trunk/Source
Files:
21 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r248009 r248010  
     12019-07-24  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        [SOUP] Move SoupNetworkSession ownership from NetworkStorageSession to NetworkSession
     4        https://bugs.webkit.org/show_bug.cgi?id=200076
     5
     6        Reviewed by Michael Catanzaro.
     7
     8        Remove the SoupNetworkSession from NetworkStorageSession.
     9
     10        * platform/network/NetworkStorageSession.h:
     11        (WebCore::NetworkStorageSession::cookieStorage const): Return the cookie jar.
     12        * platform/network/StorageSessionProvider.h:
     13        (WebCore::StorageSessionProvider::soupSession const): Temporary add this virtual method that is required by
     14        SocketStreamHandleImplSoup. It will be removed once we switch to libsoup WebSockets API soon.
     15        * platform/network/soup/DNSResolveQueueSoup.cpp:
     16        (WebCore::globalDefaultSoupSessionAccessor): Rework the accessor to return the SoupSession directly since
     17        that's what we really want.
     18        (WebCore::DNSResolveQueueSoup::setGlobalDefaultSoupSessionAccessor):
     19        (WebCore::DNSResolveQueueSoup::updateIsUsingProxy):
     20        (WebCore::DNSResolveQueueSoup::platformResolve):
     21        (WebCore::DNSResolveQueueSoup::resolve):
     22        * platform/network/soup/DNSResolveQueueSoup.h:
     23        * platform/network/soup/NetworkStorageSessionSoup.cpp:
     24        (WebCore::NetworkStorageSession::NetworkStorageSession): Create and setup the default cookie jar.
     25        (WebCore::NetworkStorageSession::~NetworkStorageSession): Only disconnect the cookie jar signals.
     26        (WebCore::NetworkStorageSession::setCookieStorage): Update the cookie jar, now we know it's always a new one.
     27        * platform/network/soup/SocketStreamHandleImplSoup.cpp:
     28        (WebCore::SocketStreamHandleImpl::create): Use the new virtual method from StorageSessionProvider to get the SoupSession.
     29        * platform/network/soup/SoupNetworkSession.cpp:
     30        (WebCore::SoupNetworkSession::SoupNetworkSession): Remove the SoupCookieJar parameter.
     31        * platform/network/soup/SoupNetworkSession.h:
     32
    1332019-07-30  Michael Catanzaro  <mcatanzaro@igalia.com>
    234
  • trunk/Source/WebCore/platform/network/NetworkStorageSession.h

    r245796 r248010  
    6666class NetworkingContext;
    6767class ResourceRequest;
    68 class SoupNetworkSession;
    6968
    7069struct Cookie;
     
    9897    WEBCORE_EXPORT static void setStorageAccessAPIEnabled(bool);
    9998#elif USE(SOUP)
    100     WEBCORE_EXPORT NetworkStorageSession(PAL::SessionID, std::unique_ptr<SoupNetworkSession>&&);
     99    WEBCORE_EXPORT explicit NetworkStorageSession(PAL::SessionID);
    101100    ~NetworkStorageSession();
    102101
    103     SoupNetworkSession& soupNetworkSession() const;
    104     void clearSoupNetworkSession();
    105     SoupCookieJar* cookieStorage() const;
    106     void setCookieStorage(SoupCookieJar*);
     102    SoupCookieJar* cookieStorage() const { return m_cookieStorage.get(); }
     103    void setCookieStorage(GRefPtr<SoupCookieJar>&&);
    107104    void setCookieObserverHandler(Function<void ()>&&);
    108105    void getCredentialFromPersistentStorage(const ProtectionSpace&, GCancellable*, Function<void (Credential&&)>&& completionHandler);
     
    172169    static void cookiesDidChange(NetworkStorageSession*);
    173170
    174     mutable std::unique_ptr<SoupNetworkSession> m_session;
     171    GRefPtr<SoupCookieJar> m_cookieStorage;
    175172    Function<void ()> m_cookieObserverHandler;
    176173#elif USE(CURL)
  • trunk/Source/WebCore/platform/network/StorageSessionProvider.h

    r240117 r248010  
    2828#include <wtf/ThreadSafeRefCounted.h>
    2929
     30#if USE(SOUP)
     31typedef struct _SoupSession SoupSession;
     32#endif
     33
    3034namespace PAL {
    3135class SessionID;
     
    4044    virtual NetworkStorageSession* storageSession() const = 0;
    4145
     46#if USE(SOUP)
     47    // FIXME: This is only required by SocketStreamHandleImplSoup, remove it when we switch to libsoup WebSockets API.
     48    virtual SoupSession* soupSession() const { return nullptr; }
     49#endif
     50
    4251    virtual ~StorageSessionProvider() { }
    4352};
  • trunk/Source/WebCore/platform/network/soup/DNSResolveQueueSoup.cpp

    r243163 r248010  
    3030#if USE(SOUP)
    3131
    32 #include "NetworkStorageSession.h"
    33 #include "SoupNetworkSession.h"
    3432#include <libsoup/soup.h>
    3533#include <wtf/CompletionHandler.h>
     
    7977}
    8078
    81 Function<NetworkStorageSession&()>& globalDefaultNetworkStorageSessionAccessor()
    82 {
    83     static NeverDestroyed<Function<NetworkStorageSession&()>> accessor;
     79Function<SoupSession*()>& globalDefaultSoupSessionAccessor()
     80{
     81    static NeverDestroyed<Function<SoupSession*()>> accessor;
    8482    return accessor.get();
    8583}
    8684
    87 void DNSResolveQueueSoup::setGlobalDefaultNetworkStorageSessionAccessor(Function<NetworkStorageSession&()>&& accessor)
    88 {
    89     globalDefaultNetworkStorageSessionAccessor() = WTFMove(accessor);
     85void DNSResolveQueueSoup::setGlobalDefaultSoupSessionAccessor(Function<SoupSession*()>&& accessor)
     86{
     87    globalDefaultSoupSessionAccessor() = WTFMove(accessor);
    9088}
    9189
     
    9391{
    9492    GRefPtr<GProxyResolver> resolver;
    95     g_object_get(globalDefaultNetworkStorageSessionAccessor()().soupNetworkSession().soupSession(), "proxy-resolver", &resolver.outPtr(), nullptr);
     93    g_object_get(globalDefaultSoupSessionAccessor()(), "proxy-resolver", &resolver.outPtr(), nullptr);
    9694    ASSERT(resolver);
    9795
     
    176174    ASSERT(isMainThread());
    177175
    178     soup_session_prefetch_dns(globalDefaultNetworkStorageSessionAccessor()().soupNetworkSession().soupSession(), hostname.utf8().data(), nullptr, resolvedCallback, nullptr);
     176    soup_session_prefetch_dns(globalDefaultSoupSessionAccessor()(), hostname.utf8().data(), nullptr, resolvedCallback, nullptr);
    179177}
    180178
     
    185183    auto address = adoptGRef(soup_address_new(hostname.utf8().data(), 0));
    186184    auto cancellable = adoptGRef(g_cancellable_new());
    187     soup_address_resolve_async(address.get(), soup_session_get_async_context(WebCore::globalDefaultNetworkStorageSessionAccessor()().soupNetworkSession().soupSession()), cancellable.get(), resolvedWithObserverCallback, this);
     185    soup_address_resolve_async(address.get(), soup_session_get_async_context(globalDefaultSoupSessionAccessor()()), cancellable.get(), resolvedWithObserverCallback, this);
    188186
    189187    g_object_set_data(G_OBJECT(address.get()), "identifier", GUINT_TO_POINTER(identifier));
  • trunk/Source/WebCore/platform/network/soup/DNSResolveQueueSoup.h

    r240292 r248010  
    3131#include <wtf/glib/GRefPtr.h>
    3232
     33typedef struct _SoupSession SoupSession;
     34
    3335namespace WebCore {
    3436
     
    4042
    4143    DNSResolveQueueSoup() = default;
    42     static void setGlobalDefaultNetworkStorageSessionAccessor(Function<NetworkStorageSession&()>&&);
     44    static void setGlobalDefaultSoupSessionAccessor(Function<SoupSession*()>&&);
    4345    void resolve(const String& hostname, uint64_t identifier, DNSCompletionHandler&&) final;
    4446    void stopResolve(uint64_t identifier) final;
  • trunk/Source/WebCore/platform/network/soup/NetworkStorageSessionSoup.cpp

    r246790 r248010  
    5454namespace WebCore {
    5555
    56 NetworkStorageSession::NetworkStorageSession(PAL::SessionID sessionID, std::unique_ptr<SoupNetworkSession>&& session)
     56NetworkStorageSession::NetworkStorageSession(PAL::SessionID sessionID)
    5757    : m_sessionID(sessionID)
    58     , m_session(WTFMove(session))
    59 {
    60     ASSERT(m_session->cookieJar());
    61     g_signal_connect_swapped(m_session->cookieJar(), "changed", G_CALLBACK(cookiesDidChange), this);
     58    , m_cookieStorage(adoptGRef(soup_cookie_jar_new()))
     59{
     60    soup_cookie_jar_set_accept_policy(m_cookieStorage.get(), SOUP_COOKIE_JAR_ACCEPT_NO_THIRD_PARTY);
     61    g_signal_connect_swapped(m_cookieStorage.get(), "changed", G_CALLBACK(cookiesDidChange), this);
    6262}
    6363
    6464NetworkStorageSession::~NetworkStorageSession()
    6565{
    66     clearSoupNetworkSession();
    67 }
    68 
    69 SoupNetworkSession& NetworkStorageSession::soupNetworkSession() const
    70 {
    71     ASSERT(m_session);
    72     return *m_session.get();
    73 };
    74 
    75 void NetworkStorageSession::clearSoupNetworkSession()
    76 {
    77     if (m_session) {
    78         ASSERT(m_session->cookieJar());
    79         g_signal_handlers_disconnect_matched(m_session->cookieJar(), G_SIGNAL_MATCH_DATA, 0, 0, nullptr, nullptr, this);
    80     }
    81 
    82     m_session = nullptr;
    83     m_cookieObserverHandler = nullptr;
     66    g_signal_handlers_disconnect_matched(m_cookieStorage.get(), G_SIGNAL_MATCH_DATA, 0, 0, nullptr, nullptr, this);
    8467}
    8568
     
    9073}
    9174
    92 SoupCookieJar* NetworkStorageSession::cookieStorage() const
    93 {
    94     ASSERT(m_session);
    95     ASSERT(m_session->cookieJar());
    96     return m_session->cookieJar();
    97 }
    98 
    99 void NetworkStorageSession::setCookieStorage(SoupCookieJar* jar)
    100 {
    101     ASSERT(jar);
    102     ASSERT(m_session);
    103     ASSERT(m_session->cookieJar());
    104 
    105     if (m_session->cookieJar() == jar)
    106         return;
    107 
    108     g_signal_handlers_disconnect_matched(m_session->cookieJar(), G_SIGNAL_MATCH_DATA, 0, 0, nullptr, nullptr, this);
    109     m_session->setCookieJar(jar);
    110     g_signal_connect_swapped(m_session->cookieJar(), "changed", G_CALLBACK(cookiesDidChange), this);
     75void NetworkStorageSession::setCookieStorage(GRefPtr<SoupCookieJar>&& jar)
     76{
     77    g_signal_handlers_disconnect_matched(m_cookieStorage.get(), G_SIGNAL_MATCH_DATA, 0, 0, nullptr, nullptr, this);
     78    m_cookieStorage = WTFMove(jar);
     79    g_signal_connect_swapped(m_cookieStorage.get(), "changed", G_CALLBACK(cookiesDidChange), this);
    11180}
    11281
  • trunk/Source/WebCore/platform/network/soup/SocketStreamHandleImplSoup.cpp

    r240340 r248010  
    3737#include "DeprecatedGlobalSettings.h"
    3838#include "Logging.h"
    39 #include "NetworkStorageSession.h"
    4039#include "ResourceError.h"
    4140#include "SocketStreamError.h"
    4241#include "SocketStreamHandleClient.h"
    43 #include "SoupNetworkSession.h"
    4442#include "StorageSessionProvider.h"
    4543#include "URLSoup.h"
     
    8886
    8987#if SOUP_CHECK_VERSION(2, 61, 90)
    90     auto* networkStorageSession = storageSessionProvider ? storageSessionProvider->storageSession() : nullptr;
    91     if (!networkStorageSession)
     88    auto* soupSession = storageSessionProvider ? storageSessionProvider->soupSession() : nullptr;
     89    if (!soupSession)
    9290        return socket;
    9391
    9492    auto uri = urlToSoupURI(url);
    9593    Ref<SocketStreamHandle> protectedSocketStreamHandle = socket.copyRef();
    96     soup_session_connect_async(networkStorageSession->soupNetworkSession().soupSession(), uri.get(), socket->m_cancellable.get(),
     94    soup_session_connect_async(soupSession, uri.get(), socket->m_cancellable.get(),
    9795        url.protocolIs("wss") ? reinterpret_cast<SoupSessionConnectProgressCallback>(connectProgressCallback) : nullptr,
    9896        reinterpret_cast<GAsyncReadyCallback>(connectedCallback), &protectedSocketStreamHandle.leakRef());
  • trunk/Source/WebCore/platform/network/soup/SoupNetworkSession.cpp

    r246677 r248010  
    107107}
    108108
    109 SoupNetworkSession::SoupNetworkSession(PAL::SessionID sessionID, SoupCookieJar* cookieJar)
     109SoupNetworkSession::SoupNetworkSession(PAL::SessionID sessionID)
    110110    : m_soupSession(adoptGRef(soup_session_new()))
    111111{
     
    117117    static const int maxConnectionsPerHost = 6;
    118118
    119     GRefPtr<SoupCookieJar> jar = cookieJar;
    120     if (!jar) {
    121         jar = adoptGRef(soup_cookie_jar_new());
    122         soup_cookie_jar_set_accept_policy(jar.get(), SOUP_COOKIE_JAR_ACCEPT_NO_THIRD_PARTY);
    123     }
    124 
    125119    g_object_set(m_soupSession.get(),
    126120        SOUP_SESSION_MAX_CONNS, maxConnections,
     
    129123        SOUP_SESSION_IDLE_TIMEOUT, 0,
    130124        SOUP_SESSION_ADD_FEATURE_BY_TYPE, SOUP_TYPE_CONTENT_SNIFFER,
    131         SOUP_SESSION_ADD_FEATURE, jar.get(),
    132125        nullptr);
    133126
  • trunk/Source/WebCore/platform/network/soup/SoupNetworkSession.h

    r239427 r248010  
    5050    WTF_MAKE_NONCOPYABLE(SoupNetworkSession); WTF_MAKE_FAST_ALLOCATED;
    5151public:
    52     explicit SoupNetworkSession(PAL::SessionID = PAL::SessionID::defaultSessionID(), SoupCookieJar* = nullptr);
     52    explicit SoupNetworkSession(PAL::SessionID);
    5353    ~SoupNetworkSession();
    5454
  • trunk/Source/WebKit/ChangeLog

    r248006 r248010  
     12019-07-24  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        [SOUP] Move SoupNetworkSession ownership from NetworkStorageSession to NetworkSession
     4        https://bugs.webkit.org/show_bug.cgi?id=200076
     5
     6        Reviewed by Michael Catanzaro.
     7
     8        NetworkStorageSession should only own the cookie jar, since it's the only thing it handles from the session.
     9
     10        * NetworkProcess/Cookies/soup/WebCookieManagerSoup.cpp:
     11        (WebKit::WebCookieManager::setCookiePersistentStorage): Use the network session instead of the storage session
     12        to set the peristent cookie storage.
     13        * NetworkProcess/CustomProtocols/soup/LegacyCustomProtocolManagerSoup.cpp:
     14        (WebKit::LegacyCustomProtocolManager::registerScheme): Iterate network sessions instead of storage sessions to
     15        access the SoupNetworkSession.
     16        * NetworkProcess/NetworkConnectionToWebProcess.cpp:
     17        (WebKit::NetworkConnectionToWebProcess::resourceLoadStatisticsUpdated): Use
     18        NetworkProcess::forEachNetworkSession() to iterate network sessions.
     19        * NetworkProcess/NetworkProcess.cpp:
     20        (WebKit::NetworkProcess::lowMemoryHandler): Ditto.
     21        (WebKit::NetworkProcess::forEachNetworkSession): Added to iterate network sessions intead of exposing the map
     22        that is always used to iterate the sessions.
     23        (WebKit::NetworkProcess::switchToNewTestingSession): Use the new NetworkStorageSession constructor API.
     24        (WebKit::NetworkProcess::ensureSession): Ditto.
     25        (WebKit::NetworkProcess::destroySession): Allow to destroy the default session for soup based ports. This is
     26        only called right before process exit to ensure we don't leak network resources like the cookies database.
     27        (WebKit::NetworkProcess::setResourceLoadStatisticsEnabled): Use NetworkProcess::forEachNetworkSession() to
     28        iterate network sessions.
     29        (WebKit::NetworkProcess::fetchWebsiteData): Ditto.
     30        (WebKit::NetworkProcess::deleteWebsiteDataForOrigins): Ditto.
     31        (WebKit::NetworkProcess::deleteWebsiteDataForRegistrableDomains): Ditto.
     32        (WebKit::NetworkProcess::registrableDomainsWithWebsiteData): Ditto.
     33        (WebKit::NetworkProcess::setCacheModel): Ditto.
     34        (WebKit::NetworkProcess::actualPrepareToSuspend): Ditto.
     35        (WebKit::NetworkProcess::resume): Ditto.
     36        * NetworkProcess/NetworkProcess.h:
     37        * NetworkProcess/NetworkStorageSessionProvider.h:
     38        * NetworkProcess/cocoa/NetworkProcessCocoa.mm:
     39        (WebKit::NetworkProcess::clearDiskCache): Ditto.
     40        * NetworkProcess/ios/NetworkProcessIOS.mm:
     41        (WebKit::NetworkProcess::clearCacheForAllOrigins): Ditto.
     42        * NetworkProcess/soup/NetworkProcessMainSoup.cpp: Destroy the default session before process exists.
     43        * NetworkProcess/soup/NetworkProcessSoup.cpp:
     44        (WebKit::NetworkProcess::userPreferredLanguagesChanged): Iterate network sessions instead of storage sessions to
     45        access the SoupNetworkSession.
     46        (WebKit::NetworkProcess::platformCreateDefaultStorageSession const): Use the new NetworkStorageSession constructor API.
     47        (WebKit::NetworkProcess::clearDiskCache): Use NetworkProcess::forEachNetworkSession() to iterate network sessions.
     48        (WebKit::NetworkProcess::setNetworkProxySettings): Iterate network sessions instead of storage sessions to
     49        access the SoupNetworkSession.
     50        * NetworkProcess/soup/NetworkSessionSoup.cpp:
     51        (WebKit::NetworkSessionSoup::NetworkSessionSoup): Create the SoupNetworkSession and setup cookies.
     52        (WebKit::NetworkSessionSoup::soupSession const): Return the SoupSession of SoupNetworkSession.
     53        (WebKit::NetworkSessionSoup::setCookiePersistentStorage): Setup a new cookie jar.
     54        * NetworkProcess/soup/NetworkSessionSoup.h:
     55
    1562019-07-30  Truitt Savell  <tsavell@apple.com>
    257
  • trunk/Source/WebKit/NetworkProcess/Cookies/soup/WebCookieManagerSoup.cpp

    r247188 r248010  
    2828
    2929#include "NetworkProcess.h"
     30#include "NetworkSessionSoup.h"
    3031#include "SoupCookiePersistentStorageType.h"
    3132#include <WebCore/NetworkStorageSession.h>
    3233#include <WebCore/SoupNetworkSession.h>
    3334#include <libsoup/soup.h>
    34 #include <wtf/glib/GRefPtr.h>
    35 #include <wtf/text/CString.h>
    3635
    3736namespace WebKit {
     
    7877void WebCookieManager::setCookiePersistentStorage(PAL::SessionID sessionID, const String& storagePath, SoupCookiePersistentStorageType storageType)
    7978{
    80     GRefPtr<SoupCookieJar> jar;
    81     switch (storageType) {
    82     case SoupCookiePersistentStorageType::Text:
    83         jar = adoptGRef(soup_cookie_jar_text_new(storagePath.utf8().data(), FALSE));
    84         break;
    85     case SoupCookiePersistentStorageType::SQLite:
    86         jar = adoptGRef(soup_cookie_jar_db_new(storagePath.utf8().data(), FALSE));
    87         break;
    88     default:
    89         ASSERT_NOT_REACHED();
    90     }
    91 
    92     if (auto* storageSession = m_process.storageSession(sessionID)) {
    93         soup_cookie_jar_set_accept_policy(jar.get(), soup_cookie_jar_get_accept_policy(storageSession->cookieStorage()));
    94         storageSession->setCookieStorage(jar.get());
    95     }
     79    if (auto* networkSession = m_process.networkSession(sessionID))
     80        static_cast<NetworkSessionSoup&>(*networkSession).setCookiePersistentStorage(storagePath, storageType);
    9681}
    9782
  • trunk/Source/WebKit/NetworkProcess/CustomProtocols/soup/LegacyCustomProtocolManagerSoup.cpp

    r240366 r248010  
    2424#include "LegacyCustomProtocolManagerMessages.h"
    2525#include "NetworkProcess.h"
     26#include "NetworkSessionSoup.h"
    2627#include "WebKitSoupRequestInputStream.h"
    27 #include <WebCore/NetworkStorageSession.h>
    2828#include <WebCore/NotImplemented.h>
    2929#include <WebCore/ResourceError.h>
     
    103103    ASSERT(genericRequestClass);
    104104    genericRequestClass->schemes = const_cast<const char**>(reinterpret_cast<char**>(m_registeredSchemes->pdata));
    105     lastCreatedNetworkProcess()->forEachNetworkStorageSession([](const auto& session) {
    106         session.soupNetworkSession().setupCustomProtocols();
     105    lastCreatedNetworkProcess()->forEachNetworkSession([](const auto& session) {
     106        static_cast<const NetworkSessionSoup&>(session).soupNetworkSession().setupCustomProtocols();
    107107    });
    108108}
  • trunk/Source/WebKit/NetworkProcess/NetworkProcess.cpp

    r247908 r248010  
    101101
    102102#if USE(SOUP)
     103#include "NetworkSessionSoup.h"
    103104#include <WebCore/DNSResolveQueueSoup.h>
    104105#include <WebCore/SoupNetworkSession.h>
     
    152153
    153154#if USE(SOUP)
    154     DNSResolveQueueSoup::setGlobalDefaultNetworkStorageSessionAccessor([this]() -> NetworkStorageSession& {
    155         return defaultStorageSession();
     155    DNSResolveQueueSoup::setGlobalDefaultSoupSessionAccessor([this]() -> SoupSession* {
     156        return static_cast<NetworkSessionSoup&>(*networkSession(PAL::SessionID::defaultSessionID())).soupSession();
    156157    });
    157158#endif
     
    275276    WTF::releaseFastMallocFreeMemory();
    276277
    277     for (auto& networkSession : m_networkSessions.values())
    278         networkSession->clearPrefetchCache();
     278    forEachNetworkSession([](auto& networkSession) {
     279        networkSession.clearPrefetchCache();
     280    });
    279281}
    280282
     
    487489}
    488490
     491void NetworkProcess::forEachNetworkSession(const Function<void(NetworkSession&)>& functor)
     492{
     493    for (auto& session : m_networkSessions.values())
     494        functor(*session);
     495}
     496
    489497void NetworkProcess::switchToNewTestingSession()
    490498{
     
    503511
    504512    m_defaultNetworkStorageSession = std::make_unique<WebCore::NetworkStorageSession>(PAL::SessionID::defaultSessionID(), WTFMove(session), WTFMove(cookieStorage));
    505 #elif USE(SOUP)
    506     m_defaultNetworkStorageSession = std::make_unique<WebCore::NetworkStorageSession>(PAL::SessionID::defaultSessionID(), std::make_unique<WebCore::SoupNetworkSession>());
    507 #elif USE(CURL)
     513#elif USE(CURL) || USE(SOUP)
    508514    m_defaultNetworkStorageSession = std::make_unique<WebCore::NetworkStorageSession>(PAL::SessionID::defaultSessionID());
    509515#endif
     
    537543
    538544    addResult.iterator->value = std::make_unique<NetworkStorageSession>(sessionID, WTFMove(storageSession), WTFMove(cookieStorage));
    539 #elif USE(SOUP)
    540     addResult.iterator->value = std::make_unique<NetworkStorageSession>(sessionID, std::make_unique<SoupNetworkSession>(sessionID));
    541 #elif USE(CURL)
     545#elif USE(CURL) || USE(SOUP)
    542546    addResult.iterator->value = std::make_unique<NetworkStorageSession>(sessionID);
    543547#endif
     
    595599        return;
    596600
     601#if !USE(SOUP)
     602    // Soup based ports destroy the default session right before the process exits to avoid leaking
     603    // network resources like the cookies database.
    597604    ASSERT(sessionID != PAL::SessionID::defaultSessionID());
     605#endif
    598606
    599607    if (auto session = m_networkSessions.take(sessionID))
     
    11471155void NetworkProcess::setResourceLoadStatisticsEnabled(bool enabled)
    11481156{
    1149     for (auto& networkSession : m_networkSessions.values())
    1150         networkSession->setResourceLoadStatisticsEnabled(enabled);
     1157    forEachNetworkSession([enabled](auto& networkSession) {
     1158        networkSession.setResourceLoadStatisticsEnabled(enabled);
     1159    });
    11511160}
    11521161
     
    13601369#endif
    13611370    if (websiteDataTypes.contains(WebsiteDataType::DiskCache)) {
    1362         for (auto& session : networkSessions().values()) {
    1363             fetchDiskCacheEntries(session->cache(), sessionID, fetchOptions, [callbackAggregator = callbackAggregator.copyRef()](auto entries) mutable {
     1371        forEachNetworkSession([sessionID, fetchOptions, &callbackAggregator](auto& session) {
     1372            fetchDiskCacheEntries(session.cache(), sessionID, fetchOptions, [callbackAggregator = callbackAggregator.copyRef()](auto entries) mutable {
    13641373                callbackAggregator->m_websiteData.entries.appendVector(entries);
    13651374            });
    1366         }
     1375        });
    13671376    }
    13681377}
     
    15201529
    15211530    if (websiteDataTypes.contains(WebsiteDataType::DiskCache) && !sessionID.isEphemeral()) {
    1522         for (auto& session : networkSessions().values())
    1523             clearDiskCacheEntries(session->cache(), originDatas, [clearTasksHandler = clearTasksHandler.copyRef()] { });
     1531        forEachNetworkSession([originDatas, &clearTasksHandler](auto& session) {
     1532            clearDiskCacheEntries(session.cache(), originDatas, [clearTasksHandler = clearTasksHandler.copyRef()] { });
     1533        });
    15241534    }
    15251535
     
    17551765
    17561766    if (websiteDataTypes.contains(WebsiteDataType::DiskCache)) {
    1757         for (auto& session : networkSessions().values()) {
    1758             fetchDiskCacheEntries(session->cache(), sessionID, fetchOptions, [domainsToDeleteAllButCookiesFor, callbackAggregator = callbackAggregator.copyRef(), session = makeWeakPtr(session.get())](auto entries) mutable {
     1767        forEachNetworkSession([sessionID, fetchOptions, &domainsToDeleteAllButCookiesFor, &callbackAggregator](auto& session) {
     1768            fetchDiskCacheEntries(session.cache(), sessionID, fetchOptions, [domainsToDeleteAllButCookiesFor, callbackAggregator = callbackAggregator.copyRef(), session = makeWeakPtr(&session)](auto entries) mutable {
    17591769                if (!session)
    17601770                    return;
     
    17691779                clearDiskCacheEntries(session->cache(), entriesToDelete, [callbackAggregator = callbackAggregator.copyRef()] { });
    17701780            });
    1771         }
     1781        });
    17721782    }
    17731783
     
    18911901   
    18921902    if (websiteDataTypes.contains(WebsiteDataType::DiskCache)) {
    1893         for (auto& session : networkSessions().values()) {
    1894             fetchDiskCacheEntries(session->cache(), sessionID, fetchOptions, [callbackAggregator = callbackAggregator.copyRef()](auto entries) mutable {
     1903        forEachNetworkSession([sessionID, fetchOptions, &callbackAggregator](auto& session) {
     1904            fetchDiskCacheEntries(session.cache(), sessionID, fetchOptions, [callbackAggregator = callbackAggregator.copyRef()](auto entries) mutable {
    18951905                callbackAggregator->m_websiteData.entries.appendVector(entries);
    18961906            });
    1897         }
     1907        });
    18981908    }
    18991909}
     
    19871997        calculateURLCacheSizes(cacheModel, diskFreeSize, urlCacheMemoryCapacity, urlCacheDiskCapacity);
    19881998    }
    1989    
    1990     for (auto& session : networkSessions().values()) {
    1991         if (auto* cache = session->cache())
     1999
     2000    forEachNetworkSession([urlCacheDiskCapacity](auto& session) {
     2001        if (auto* cache = session.cache())
    19922002            cache->setCapacity(urlCacheDiskCapacity);
    1993     }
     2003    });
    19942004}
    19952005
     
    20852095#endif
    20862096
    2087     for (auto& session : m_networkSessions)
    2088         session.value->storageManager().suspend([callbackAggregator] { });
     2097    forEachNetworkSession([&callbackAggregator](auto& session) {
     2098        session.storageManager().suspend([callbackAggregator] { });
     2099    });
    20892100}
    20902101
     
    21562167#endif
    21572168
    2158     for (auto& session : m_networkSessions)
    2159         session.value->storageManager().resume();
     2169    forEachNetworkSession([](auto& session) {
     2170        session.storageManager().resume();
     2171    });
    21602172}
    21612173
  • trunk/Source/WebKit/NetworkProcess/NetworkProcess.h

    r247831 r248010  
    167167    void destroySession(const PAL::SessionID&);
    168168
    169     // Needed for test infrastructure
    170     HashMap<PAL::SessionID, std::unique_ptr<NetworkSession>>& networkSessions() { return m_networkSessions; }
     169    void forEachNetworkSession(const Function<void(NetworkSession&)>&);
    171170
    172171    void forEachNetworkStorageSession(const Function<void(WebCore::NetworkStorageSession&)>&);
  • trunk/Source/WebKit/NetworkProcess/NetworkStorageSessionProvider.h

    r240292 r248010  
    3232#include <wtf/WeakPtr.h>
    3333
     34#if USE(SOUP)
     35#include "NetworkSessionSoup.h"
     36#endif
     37
    3438namespace WebKit {
    3539
     
    5054    }
    5155
     56#if USE(SOUP)
     57    SoupSession* soupSession() const final
     58    {
     59        if (!m_networkProcess)
     60            return nullptr;
     61
     62        if (auto* session = m_networkProcess->networkSession(m_sessionID))
     63            return static_cast<NetworkSessionSoup&>(*session).soupSession();
     64
     65        return nullptr;
     66    }
     67#endif
     68
    5269    WeakPtr<NetworkProcess> m_networkProcess;
    5370    PAL::SessionID m_sessionID;
  • trunk/Source/WebKit/NetworkProcess/cocoa/NetworkProcessCocoa.mm

    r247567 r248010  
    200200    dispatch_group_async(group, dispatch_get_main_queue(), makeBlockPtr([this, protectedThis = makeRef(*this), modifiedSince, completionHandler = WTFMove(completionHandler)] () mutable {
    201201        auto aggregator = CallbackAggregator::create(WTFMove(completionHandler));
    202         for (auto& session : networkSessions().values()) {
    203             if (auto* cache = session->cache())
     202        forEachNetworkSession([modifiedSince, &aggregator](NetworkSession& session) {
     203            if (auto* cache = session.cache())
    204204                cache->clear(modifiedSince, [aggregator = aggregator.copyRef()] () { });
    205         }
     205        });
    206206    }).get());
    207207}
  • trunk/Source/WebKit/NetworkProcess/ios/NetworkProcessIOS.mm

    r247567 r248010  
    7979    if (resourceCachesToClear == InMemoryResourceCachesOnly)
    8080        return;
    81     for (auto& session : networkSessions().values()) {
    82         if (auto* cache = session->cache())
     81    forEachNetworkSession([](NetworkSession& session) {
     82        if (auto* cache = session.cache())
    8383            cache->clear();
    84     }
     84    });
    8585}
    8686
  • trunk/Source/WebKit/NetworkProcess/soup/NetworkProcessMainSoup.cpp

    r240683 r248010  
    4242        // Needed to destroy the SoupSession and SoupCookieJar, e.g. to avoid
    4343        // leaking SQLite temporary journaling files.
    44         globalNetworkProcess->defaultStorageSession().clearSoupNetworkSession();
     44        globalNetworkProcess->destroySession(PAL::SessionID::defaultSessionID());
    4545    }
    4646};
  • trunk/Source/WebKit/NetworkProcess/soup/NetworkProcessSoup.cpp

    r247567 r248010  
    3030#include "NetworkCache.h"
    3131#include "NetworkProcessCreationParameters.h"
    32 #include "NetworkSession.h"
     32#include "NetworkSessionSoup.h"
    3333#include "ResourceCachesToClear.h"
    3434#include "WebCookieManager.h"
     
    100100    auto acceptLanguages = buildAcceptLanguages(languages);
    101101    SoupNetworkSession::setInitialAcceptLanguages(acceptLanguages);
    102     forEachNetworkStorageSession([&acceptLanguages](const auto& session) {
    103         session.soupNetworkSession().setAcceptLanguages(acceptLanguages);
     102    forEachNetworkSession([&acceptLanguages](const auto& session) {
     103        static_cast<const NetworkSessionSoup&>(session).soupNetworkSession().setAcceptLanguages(acceptLanguages);
    104104    });
    105105}
     
    134134std::unique_ptr<WebCore::NetworkStorageSession> NetworkProcess::platformCreateDefaultStorageSession() const
    135135{
    136     return std::make_unique<WebCore::NetworkStorageSession>(PAL::SessionID::defaultSessionID(), std::make_unique<SoupNetworkSession>(PAL::SessionID::defaultSessionID()));
     136    return std::make_unique<WebCore::NetworkStorageSession>(PAL::SessionID::defaultSessionID());
    137137}
    138138
     
    158158{
    159159    auto aggregator = CallbackAggregator::create(WTFMove(completionHandler));
    160     for (auto& session : networkSessions().values()) {
    161         if (auto* cache = session->cache())
     160    forEachNetworkSession([modifiedSince, &aggregator](NetworkSession& session) {
     161        if (auto* cache = session.cache())
    162162            cache->clear(modifiedSince, [aggregator = aggregator.copyRef()] () { });
    163     }
     163    });
    164164}
    165165
     
    172172{
    173173    SoupNetworkSession::setProxySettings(settings);
    174     forEachNetworkStorageSession([](const auto& session) {
    175         session.soupNetworkSession().setupProxy();
     174    forEachNetworkSession([](const auto& session) {
     175        static_cast<const NetworkSessionSoup&>(session).soupNetworkSession().setupProxy();
    176176    });
    177177}
  • trunk/Source/WebKit/NetworkProcess/soup/NetworkSessionSoup.cpp

    r247567 r248010  
    4242NetworkSessionSoup::NetworkSessionSoup(NetworkProcess& networkProcess, NetworkSessionCreationParameters&& parameters)
    4343    : NetworkSession(networkProcess, parameters)
     44    , m_networkSession(std::make_unique<SoupNetworkSession>(m_sessionID))
    4445{
    45     networkStorageSession()->setCookieObserverHandler([this] {
     46    auto* storageSession = networkStorageSession();
     47    ASSERT(storageSession);
     48
     49    if (!parameters.cookiePersistentStoragePath.isEmpty())
     50        setCookiePersistentStorage(parameters.cookiePersistentStoragePath, parameters.cookiePersistentStorageType);
     51    else
     52        m_networkSession->setCookieJar(storageSession->cookieStorage());
     53
     54    storageSession->setCookieObserverHandler([this] {
    4655        this->networkProcess().supplement<WebCookieManager>()->notifyCookiesDidChange(m_sessionID);
    4756    });
    48 
    49     if (!parameters.cookiePersistentStoragePath.isEmpty())
    50         this->networkProcess().supplement<WebCookieManager>()->setCookiePersistentStorage(m_sessionID, parameters.cookiePersistentStoragePath, parameters.cookiePersistentStorageType);
    5157}
    5258
     
    5965SoupSession* NetworkSessionSoup::soupSession() const
    6066{
    61     return networkStorageSession()->soupNetworkSession().soupSession();
     67    return m_networkSession->soupSession();
     68}
     69
     70void NetworkSessionSoup::setCookiePersistentStorage(const String& storagePath, SoupCookiePersistentStorageType storageType)
     71{
     72    auto* storageSession = networkStorageSession();
     73    if (!storageSession)
     74        return;
     75
     76    GRefPtr<SoupCookieJar> jar;
     77    switch (storageType) {
     78    case SoupCookiePersistentStorageType::Text:
     79        jar = adoptGRef(soup_cookie_jar_text_new(storagePath.utf8().data(), FALSE));
     80        break;
     81    case SoupCookiePersistentStorageType::SQLite:
     82        jar = adoptGRef(soup_cookie_jar_db_new(storagePath.utf8().data(), FALSE));
     83        break;
     84    default:
     85        ASSERT_NOT_REACHED();
     86    }
     87
     88    soup_cookie_jar_set_accept_policy(jar.get(), soup_cookie_jar_get_accept_policy(storageSession->cookieStorage()));
     89    storageSession->setCookieStorage(WTFMove(jar));
     90
     91    m_networkSession->setCookieJar(storageSession->cookieStorage());
    6292}
    6393
  • trunk/Source/WebKit/NetworkProcess/soup/NetworkSessionSoup.h

    r247831 r248010  
    2727
    2828#include "NetworkSession.h"
     29#include "SoupCookiePersistentStorageType.h"
    2930
    3031typedef struct _SoupSession SoupSession;
     32
     33namespace WebCore {
     34class SoupNetworkSession;
     35}
    3136
    3237namespace WebKit {
     
    4550    ~NetworkSessionSoup();
    4651
     52    WebCore::SoupNetworkSession& soupNetworkSession() const { return *m_networkSession; }
    4753    SoupSession* soupSession() const;
     54
     55    void setCookiePersistentStorage(const String& storagePath, SoupCookiePersistentStorageType);
    4856
    4957private:
    5058    std::unique_ptr<WebSocketTask> createWebSocketTask(NetworkSocketChannel&, const WebCore::ResourceRequest&, const String& protocol) final;
    5159    void clearCredentials() final;
     60
     61    std::unique_ptr<WebCore::SoupNetworkSession> m_networkSession;
    5262};
    5363
Note: See TracChangeset for help on using the changeset viewer.