[SOUP] Add SoupNetworkSession class to wrap a SoupSession
authorcarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 13 Jan 2014 18:25:43 +0000 (18:25 +0000)
committercarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 13 Jan 2014 18:25:43 +0000 (18:25 +0000)
https://bugs.webkit.org/show_bug.cgi?id=126813

Reviewed by Gustavo Noronha Silva.

Source/WebCore:

Add SoupNetworkSession class that wraps a SoupSession and move all
the code related to the SoupSession from ResourceHandle to
SoupNetworkSession, including the static methods to get the
default session and create testing and private sessions.

* GNUmakefile.list.am: Add new files to compilation.
* PlatformEfl.cmake: Ditto.
* PlatformGTK.cmake: Ditto.
* platform/network/NetworkStorageSession.h: Use SoupNetworkSession
instead of SoupSession.
* platform/network/ResourceHandle.h:
* platform/network/soup/CookieJarSoup.cpp:
(WebCore::cookieJarForSession): Use SoupNetworkSession to get the
SoupSession.
* platform/network/soup/DNSSoup.cpp:
(WebCore::DNSResolveQueue::platformResolve): Ditto.
* platform/network/soup/NetworkStorageSessionSoup.cpp:
(WebCore::NetworkStorageSession::NetworkStorageSession): Use
SoupNetworkSession instead of SoupSession.
(WebCore::NetworkStorageSession::~NetworkStorageSession):
(WebCore::NetworkStorageSession::defaultStorageSession): Create a
NetworkStorageSession with a NULL SoupNetworkSession which means
that the default SoupNetworkSession will be used.
(WebCore::NetworkStorageSession::createPrivateBrowsingSession):
Call SoupNetworkSession::createPrivateBrowsingSession() to create
the private session.
(WebCore::NetworkStorageSession::switchToNewTestingSession): Call
SoupNetworkSession::createTestingSession() to create the testing
session.
(WebCore::NetworkStorageSession::soupNetworkSession): Return the
SoupNetworkSession or the default one.
(WebCore::NetworkStorageSession::setSoupNetworkSession): Set a new
SoupNetworkSession.
* platform/network/soup/ResourceHandleSoup.cpp:
(WebCore::sessionFromContext): Use SoupNetworkSession to get the
SoupSession.
(WebCore::ResourceHandleInternal::soupSession): Simply call
sessionFromContext(), since ensureSessionIsInitialized() is no
longer needed, because the SoupSession are now initialized in the
SoupNetworkSession constructor.
(WebCore::ResourceHandle::didStartRequest): Function to notify the
ResourceHandle that current request has just started for web timing.
* platform/network/soup/SoupNetworkSession.cpp: Added.
(WebCore::soupLogPrinter): Logger callback.
(WebCore::SoupNetworkSession::defaultSession): Return a reference
to the default SoupNetworkSession.
(WebCore::SoupNetworkSession::createPrivateBrowsingSession):
Create a new private session.
(WebCore::SoupNetworkSession::createTestingSession): Create a new
testing session.
(WebCore::SoupNetworkSession::createForSoupSession): Create a new
SoupNetworkSession for the given SoupSession.
(WebCore::authenticateCallback): Callback emitted by the
SoupSession when the request needs authentication.
(WebCore::requestStartedCallback): Callback emitted by the
SoupSession when as request has just started.
(WebCore::SoupNetworkSession::SoupNetworkSession):
(WebCore::SoupNetworkSession::~SoupNetworkSession):
(WebCore::SoupNetworkSession::setupLogger): Helper private
function to setup the logger.
(WebCore::SoupNetworkSession::setCookieJar): Set a new CookieJar
in the session replacing the existing one.
(WebCore::SoupNetworkSession::cookieJar): Return the current
CookieJar of the session.
(WebCore::SoupNetworkSession::setCache): Set a disk cache.
(WebCore::SoupNetworkSession::cache): Return the current disk cache.
(WebCore::SoupNetworkSession::setSSLPolicy): Set the SSL policy.
(WebCore::SoupNetworkSession::sslPolicy): Get the current SSL policy.
(WebCore::SoupNetworkSession::setHTTPProxy): Set the HTTP proxy.
(WebCore::SoupNetworkSession::httpProxy): Get the current HTTP proxy.
(WebCore::SoupNetworkSession::setupHTTPProxyFromEnvironment): Set
the HTTP proxy using the environment variables.
(WebCore::buildAcceptLanguages): Helper function build the accept
language string in the format expected by soup (RFC 2616).
(WebCore::SoupNetworkSession::setAcceptLanguages): Set the accept
language for the given list of languages.
* platform/network/soup/SoupNetworkSession.h: Added.
(WebCore::SoupNetworkSession::soupSession): Return the SoupSession.

Source/WebKit/efl:

Use the new SoupNetworkSession API.

* ewk/ewk_cookies.cpp:
(ewk_cookies_file_set):
* ewk/ewk_main.cpp:
(_ewk_init_body):
* ewk/ewk_network.cpp:
(ewk_network_proxy_uri_set):
(ewk_network_proxy_uri_get):
(ewk_network_tls_certificate_check_get):
(ewk_network_tls_certificate_check_set):
(ewk_network_tls_ca_certificates_path_get):
(ewk_network_tls_ca_certificates_path_set):
(ewk_network_default_soup_session_get):
* ewk/ewk_view.cpp:
(ewk_view_soup_session_get):
(ewk_view_soup_session_set):

Source/WebKit/gtk:

* webkit/webkitglobals.cpp:
(webkit_get_default_session): Use the new SoupNetworkSession API
to get the default SoupSession

Source/WebKit2:

Use the new SoupNetworkSession API.

* NetworkProcess/soup/NetworkProcessSoup.cpp:
(WebKit::NetworkProcess::platformInitializeNetworkProcess):
(WebKit::NetworkProcess::platformSetCacheModel):
(WebKit::NetworkProcess::clearCacheForAllOrigins):
* NetworkProcess/unix/NetworkProcessMainUnix.cpp:
(WebKit::NetworkProcessMain):
* WebProcess/Cookies/soup/WebCookieManagerSoup.cpp:
(WebKit::WebCookieManager::setCookiePersistentStorage):
* WebProcess/efl/WebProcessMainEfl.cpp:
(WebKit::WebProcessMainEfl):
* WebProcess/gtk/WebProcessMainGtk.cpp:
(WebKit::WebProcessMainGtk):
* WebProcess/soup/WebProcessSoup.cpp:
(WebKit::WebProcess::platformSetCacheModel):
(WebKit::WebProcess::platformClearResourceCaches):
(WebKit::setSoupSessionAcceptLanguage):
(WebKit::WebProcess::platformInitializeWebProcess):
* WebProcess/soup/WebSoupRequestManager.cpp:
(WebKit::WebSoupRequestManager::registerURIScheme):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@161890 268f45cc-cd09-0410-ab3c-d52691b4dbfc

27 files changed:
Source/WebCore/ChangeLog
Source/WebCore/GNUmakefile.list.am
Source/WebCore/PlatformEfl.cmake
Source/WebCore/PlatformGTK.cmake
Source/WebCore/platform/network/NetworkStorageSession.h
Source/WebCore/platform/network/ResourceHandle.h
Source/WebCore/platform/network/soup/CookieJarSoup.cpp
Source/WebCore/platform/network/soup/DNSSoup.cpp
Source/WebCore/platform/network/soup/NetworkStorageSessionSoup.cpp
Source/WebCore/platform/network/soup/ResourceHandleSoup.cpp
Source/WebCore/platform/network/soup/SoupNetworkSession.cpp [new file with mode: 0644]
Source/WebCore/platform/network/soup/SoupNetworkSession.h [new file with mode: 0644]
Source/WebKit/efl/ChangeLog
Source/WebKit/efl/ewk/ewk_cookies.cpp
Source/WebKit/efl/ewk/ewk_main.cpp
Source/WebKit/efl/ewk/ewk_network.cpp
Source/WebKit/efl/ewk/ewk_view.cpp
Source/WebKit/gtk/ChangeLog
Source/WebKit/gtk/webkit/webkitglobals.cpp
Source/WebKit2/ChangeLog
Source/WebKit2/NetworkProcess/soup/NetworkProcessSoup.cpp
Source/WebKit2/NetworkProcess/unix/NetworkProcessMainUnix.cpp
Source/WebKit2/WebProcess/Cookies/soup/WebCookieManagerSoup.cpp
Source/WebKit2/WebProcess/efl/WebProcessMainEfl.cpp
Source/WebKit2/WebProcess/gtk/WebProcessMainGtk.cpp
Source/WebKit2/WebProcess/soup/WebProcessSoup.cpp
Source/WebKit2/WebProcess/soup/WebSoupRequestManager.cpp

index f396506..fb9bc98 100644 (file)
@@ -1,3 +1,89 @@
+2014-01-13  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        [SOUP] Add SoupNetworkSession class to wrap a SoupSession
+        https://bugs.webkit.org/show_bug.cgi?id=126813
+
+        Reviewed by Gustavo Noronha Silva.
+
+        Add SoupNetworkSession class that wraps a SoupSession and move all
+        the code related to the SoupSession from ResourceHandle to
+        SoupNetworkSession, including the static methods to get the
+        default session and create testing and private sessions.
+
+        * GNUmakefile.list.am: Add new files to compilation.
+        * PlatformEfl.cmake: Ditto.
+        * PlatformGTK.cmake: Ditto.
+        * platform/network/NetworkStorageSession.h: Use SoupNetworkSession
+        instead of SoupSession.
+        * platform/network/ResourceHandle.h:
+        * platform/network/soup/CookieJarSoup.cpp:
+        (WebCore::cookieJarForSession): Use SoupNetworkSession to get the
+        SoupSession.
+        * platform/network/soup/DNSSoup.cpp:
+        (WebCore::DNSResolveQueue::platformResolve): Ditto.
+        * platform/network/soup/NetworkStorageSessionSoup.cpp:
+        (WebCore::NetworkStorageSession::NetworkStorageSession): Use
+        SoupNetworkSession instead of SoupSession.
+        (WebCore::NetworkStorageSession::~NetworkStorageSession):
+        (WebCore::NetworkStorageSession::defaultStorageSession): Create a
+        NetworkStorageSession with a NULL SoupNetworkSession which means
+        that the default SoupNetworkSession will be used.
+        (WebCore::NetworkStorageSession::createPrivateBrowsingSession):
+        Call SoupNetworkSession::createPrivateBrowsingSession() to create
+        the private session.
+        (WebCore::NetworkStorageSession::switchToNewTestingSession): Call
+        SoupNetworkSession::createTestingSession() to create the testing
+        session.
+        (WebCore::NetworkStorageSession::soupNetworkSession): Return the
+        SoupNetworkSession or the default one.
+        (WebCore::NetworkStorageSession::setSoupNetworkSession): Set a new
+        SoupNetworkSession.
+        * platform/network/soup/ResourceHandleSoup.cpp:
+        (WebCore::sessionFromContext): Use SoupNetworkSession to get the
+        SoupSession.
+        (WebCore::ResourceHandleInternal::soupSession): Simply call
+        sessionFromContext(), since ensureSessionIsInitialized() is no
+        longer needed, because the SoupSession are now initialized in the
+        SoupNetworkSession constructor.
+        (WebCore::ResourceHandle::didStartRequest): Function to notify the
+        ResourceHandle that current request has just started for web timing.
+        * platform/network/soup/SoupNetworkSession.cpp: Added.
+        (WebCore::soupLogPrinter): Logger callback.
+        (WebCore::SoupNetworkSession::defaultSession): Return a reference
+        to the default SoupNetworkSession.
+        (WebCore::SoupNetworkSession::createPrivateBrowsingSession):
+        Create a new private session.
+        (WebCore::SoupNetworkSession::createTestingSession): Create a new
+        testing session.
+        (WebCore::SoupNetworkSession::createForSoupSession): Create a new
+        SoupNetworkSession for the given SoupSession.
+        (WebCore::authenticateCallback): Callback emitted by the
+        SoupSession when the request needs authentication.
+        (WebCore::requestStartedCallback): Callback emitted by the
+        SoupSession when as request has just started.
+        (WebCore::SoupNetworkSession::SoupNetworkSession):
+        (WebCore::SoupNetworkSession::~SoupNetworkSession):
+        (WebCore::SoupNetworkSession::setupLogger): Helper private
+        function to setup the logger.
+        (WebCore::SoupNetworkSession::setCookieJar): Set a new CookieJar
+        in the session replacing the existing one.
+        (WebCore::SoupNetworkSession::cookieJar): Return the current
+        CookieJar of the session.
+        (WebCore::SoupNetworkSession::setCache): Set a disk cache.
+        (WebCore::SoupNetworkSession::cache): Return the current disk cache.
+        (WebCore::SoupNetworkSession::setSSLPolicy): Set the SSL policy.
+        (WebCore::SoupNetworkSession::sslPolicy): Get the current SSL policy.
+        (WebCore::SoupNetworkSession::setHTTPProxy): Set the HTTP proxy.
+        (WebCore::SoupNetworkSession::httpProxy): Get the current HTTP proxy.
+        (WebCore::SoupNetworkSession::setupHTTPProxyFromEnvironment): Set
+        the HTTP proxy using the environment variables.
+        (WebCore::buildAcceptLanguages): Helper function build the accept
+        language string in the format expected by soup (RFC 2616).
+        (WebCore::SoupNetworkSession::setAcceptLanguages): Set the accept
+        language for the given list of languages.
+        * platform/network/soup/SoupNetworkSession.h: Added.
+        (WebCore::SoupNetworkSession::soupSession): Return the SoupSession.
+
 2014-01-13  Brent Fulgham  <bfulgham@apple.com>
 
         [WebGL] Error messages should use source code labels, not internal mangled symbols.
index b8e3b82..eb79b0c 100644 (file)
@@ -5472,7 +5472,6 @@ webcore_platform_sources += \
        Source/WebCore/platform/network/BlobRegistryImpl.h \
        Source/WebCore/platform/network/BlobResourceHandle.cpp \
        Source/WebCore/platform/network/BlobResourceHandle.h \
-       Source/WebCore/platform/network/soup/CertificateInfo.h \
        Source/WebCore/platform/network/BlobStorageData.h \
        Source/WebCore/platform/network/FormDataBuilder.cpp \
        Source/WebCore/platform/network/FormDataBuilder.h \
@@ -5494,6 +5493,7 @@ webcore_platform_sources += \
        Source/WebCore/platform/network/SynchronousLoaderClient.h \
        Source/WebCore/platform/network/soup/AuthenticationChallenge.h \
        Source/WebCore/platform/network/soup/AuthenticationChallengeSoup.cpp \
+       Source/WebCore/platform/network/soup/CertificateInfo.h \
        Source/WebCore/platform/network/soup/CertificateInfo.cpp \
        Source/WebCore/platform/network/soup/CookieJarSoup.cpp \
        Source/WebCore/platform/network/soup/CookieJarSoup.h \
@@ -5506,6 +5506,8 @@ webcore_platform_sources += \
        Source/WebCore/platform/network/soup/ResourceRequestSoup.cpp \
        Source/WebCore/platform/network/soup/ResourceResponse.h \
        Source/WebCore/platform/network/soup/ResourceResponseSoup.cpp \
+       Source/WebCore/platform/network/soup/SoupNetworkSession.h \
+       Source/WebCore/platform/network/soup/SoupNetworkSession.cpp \
        Source/WebCore/platform/network/soup/SynchronousLoaderClientSoup.cpp \
        Source/WebCore/platform/ScrollableArea.cpp \
        Source/WebCore/platform/ScrollableArea.h \
index 50e72d0..7105ec4 100644 (file)
@@ -166,6 +166,7 @@ list(APPEND WebCore_SOURCES
     platform/network/soup/ResourceRequestSoup.cpp
     platform/network/soup/ResourceResponseSoup.cpp
     platform/network/soup/SocketStreamHandleSoup.cpp
+    platform/network/soup/SoupNetworkSession.cpp
     platform/network/soup/SoupURIUtils.cpp
     platform/network/soup/SynchronousLoaderClientSoup.cpp
 
index f723e54..01f0104 100644 (file)
@@ -124,6 +124,7 @@ list(APPEND WebCore_SOURCES
     platform/network/soup/ResourceRequestSoup.cpp
     platform/network/soup/ResourceResponseSoup.cpp
     platform/network/soup/SocketStreamHandleSoup.cpp
+    platform/network/soup/SoupNetworkSession.cpp
     platform/network/soup/SoupURIUtils.cpp
     platform/network/soup/SynchronousLoaderClientSoup.cpp
 
index 56a0a59..bb6fb7f 100644 (file)
 #if PLATFORM(MAC) || USE(CFNETWORK)
 typedef const struct __CFURLStorageSession* CFURLStorageSessionRef;
 typedef struct OpaqueCFHTTPCookieStorage*  CFHTTPCookieStorageRef;
-#elif USE(SOUP)
-#include <wtf/gobject/GRefPtr.h>
-typedef struct _SoupCookieJar SoupCookieJar;
-typedef struct _SoupSession SoupSession;
 #endif
 
 namespace WebCore {
 
 class NetworkingContext;
+class SoupNetworkSession;
 
 class NetworkStorageSession {
     WTF_MAKE_NONCOPYABLE(NetworkStorageSession); WTF_MAKE_FAST_ALLOCATED;
@@ -60,9 +57,10 @@ public:
     CFURLStorageSessionRef platformSession() { return m_platformSession.get(); }
     RetainPtr<CFHTTPCookieStorageRef> cookieStorage() const;
 #elif USE(SOUP)
-    NetworkStorageSession(SoupSession*);
-    void setSoupSession(SoupSession* session) { m_session = session; }
-    SoupSession* soupSession() const { return m_session.get(); }
+    NetworkStorageSession(std::unique_ptr<SoupNetworkSession>);
+    ~NetworkStorageSession();
+    SoupNetworkSession& soupNetworkSession() const;
+    void setSoupNetworkSession(std::unique_ptr<SoupNetworkSession>);
 #else
     NetworkStorageSession(NetworkingContext*);
     ~NetworkStorageSession();
@@ -74,7 +72,7 @@ private:
     NetworkStorageSession();
     RetainPtr<CFURLStorageSessionRef> m_platformSession;
 #elif USE(SOUP)
-    GRefPtr<SoupSession> m_session;
+    std::unique_ptr<SoupNetworkSession> m_session;
 #else
     RefPtr<NetworkingContext> m_context;
 #endif
index 7d53b90..41e2f5c 100644 (file)
@@ -180,9 +180,7 @@ public:
     bool cancelledOrClientless();
     void ensureReadBuffer();
     size_t currentStreamPosition() const;
-    static SoupSession* defaultSession();
-    static SoupSession* createTestingSession();
-    static SoupSession* createPrivateBrowsingSession();
+    void didStartRequest();
     static uint64_t getSoupRequestInitiatingPageID(SoupRequest*);
     static void setHostAllowsAnyHTTPSCertificate(const String&);
     static void setClientCertificate(const String& host, GTlsCertificate*);
index dd5dbd5..15fd7c5 100644 (file)
@@ -26,7 +26,7 @@
 #include "URL.h"
 #include "NetworkingContext.h"
 #include "PlatformCookieJar.h"
-#include "ResourceHandle.h"
+#include "SoupNetworkSession.h"
 #include <wtf/gobject/GRefPtr.h>
 #include <wtf/text/CString.h>
 
@@ -34,8 +34,7 @@ namespace WebCore {
 
 static SoupCookieJar* cookieJarForSession(const NetworkStorageSession& session)
 {
-    ASSERT(session.soupSession());
-    return SOUP_COOKIE_JAR(soup_session_get_feature(session.soupSession(), SOUP_TYPE_COOKIE_JAR));
+    return session.soupNetworkSession().cookieJar();
 }
 
 static GRefPtr<SoupCookieJar>& defaultCookieJar()
index baba204..2eab9a3 100644 (file)
@@ -29,7 +29,7 @@
 #include "DNSResolveQueue.h"
 
 #include "GOwnPtrSoup.h"
-#include "ResourceHandle.h"
+#include "SoupNetworkSession.h"
 #include <libsoup/soup.h>
 #include <wtf/MainThread.h>
 #include <wtf/text/CString.h>
@@ -53,7 +53,7 @@ void DNSResolveQueue::platformResolve(const String& hostname)
 {
     ASSERT(isMainThread());
 
-    soup_session_prefetch_dns(ResourceHandle::defaultSession(), hostname.utf8().data(), 0, resolvedCallback, 0);
+    soup_session_prefetch_dns(SoupNetworkSession::defaultSession().soupSession(), hostname.utf8().data(), nullptr, resolvedCallback, nullptr);
 }
 
 void prefetchDNS(const String& hostname)
index 74d108a..67f1950 100644 (file)
 #include "NetworkStorageSession.h"
 
 #include "ResourceHandle.h"
+#include "SoupNetworkSession.h"
 #include <wtf/MainThread.h>
 #include <wtf/NeverDestroyed.h>
 
 namespace WebCore {
 
-NetworkStorageSession::NetworkStorageSession(SoupSession* session)
-    : m_session(adoptGRef(session))
+NetworkStorageSession::NetworkStorageSession(std::unique_ptr<SoupNetworkSession> session)
+    : m_session(std::move(session))
     , m_isPrivate(false)
 {
 }
 
+NetworkStorageSession::~NetworkStorageSession()
+{
+}
+
 static std::unique_ptr<NetworkStorageSession>& defaultSession()
 {
     ASSERT(isMainThread());
@@ -49,20 +54,30 @@ static std::unique_ptr<NetworkStorageSession>& defaultSession()
 NetworkStorageSession& NetworkStorageSession::defaultStorageSession()
 {
     if (!defaultSession())
-        defaultSession() = std::make_unique<NetworkStorageSession>(ResourceHandle::defaultSession());
+        defaultSession() = std::make_unique<NetworkStorageSession>(nullptr);
     return *defaultSession();
 }
 
 std::unique_ptr<NetworkStorageSession> NetworkStorageSession::createPrivateBrowsingSession(const String&)
 {
-    auto session = std::make_unique<NetworkStorageSession>(ResourceHandle::createPrivateBrowsingSession());
+    auto session = std::make_unique<NetworkStorageSession>(SoupNetworkSession::createPrivateBrowsingSession());
     session->m_isPrivate = true;
     return session;
 }
 
 void NetworkStorageSession::switchToNewTestingSession()
 {
-    defaultSession() = std::make_unique<NetworkStorageSession>(ResourceHandle::createTestingSession());
+    defaultSession() = std::make_unique<NetworkStorageSession>(SoupNetworkSession::createTestingSession());
+}
+
+SoupNetworkSession& NetworkStorageSession::soupNetworkSession() const
+{
+    return m_session ? *m_session : SoupNetworkSession::defaultSession();
+}
+
+void NetworkStorageSession::setSoupNetworkSession(std::unique_ptr<SoupNetworkSession> session)
+{
+    m_session = std::move(session);
 }
 
 }
index 07a53a2..4c70749 100644 (file)
@@ -35,7 +35,6 @@
 #include "GOwnPtrSoup.h"
 #include "HTTPParsers.h"
 #include "LocalizedStrings.h"
-#include "Logging.h"
 #include "MIMETypeRegistry.h"
 #include "NetworkingContext.h"
 #include "NotImplemented.h"
@@ -44,6 +43,7 @@
 #include "ResourceHandleInternal.h"
 #include "ResourceResponse.h"
 #include "SharedBuffer.h"
+#include "SoupNetworkSession.h"
 #include "SoupURIUtils.h"
 #include "TextEncoding.h"
 #include <errno.h>
 
 namespace WebCore {
 
-inline static void soupLogPrinter(SoupLogger*, SoupLoggerLogLevel, char direction, const char* data, gpointer)
-{
-#if LOG_DISABLED
-    UNUSED_PARAM(direction);
-    UNUSED_PARAM(data);
-#endif
-    LOG(Network, "%c %s", direction, data);
-}
-
 static bool loadingSynchronousRequest = false;
 static const size_t gDefaultReadBufferSize = 8192;
 
@@ -260,8 +251,8 @@ ResourceHandleInternal::~ResourceHandleInternal()
 static SoupSession* sessionFromContext(NetworkingContext* context)
 {
     if (!context || !context->isValid())
-        return ResourceHandle::defaultSession();
-    return context->storageSession().soupSession();
+        return SoupNetworkSession::defaultSession().soupSession();
+    return context->storageSession().soupNetworkSession().soupSession();
 }
 
 ResourceHandle::~ResourceHandle()
@@ -269,36 +260,9 @@ ResourceHandle::~ResourceHandle()
     cleanupSoupRequestOperation(this, true);
 }
 
-static void ensureSessionIsInitialized(SoupSession* session)
-{
-    if (g_object_get_data(G_OBJECT(session), "webkit-init"))
-        return;
-
-    if (session == ResourceHandle::defaultSession()) {
-        SoupCookieJar* jar = SOUP_COOKIE_JAR(soup_session_get_feature(session, SOUP_TYPE_COOKIE_JAR));
-        if (!jar)
-            soup_session_add_feature(session, SOUP_SESSION_FEATURE(soupCookieJar()));
-        else
-            setSoupCookieJar(jar);
-    }
-
-#if !LOG_DISABLED
-    if (!soup_session_get_feature(session, SOUP_TYPE_LOGGER) && LogNetwork.state == WTFLogChannelOn) {
-        SoupLogger* logger = soup_logger_new(static_cast<SoupLoggerLogLevel>(SOUP_LOGGER_LOG_BODY), -1);
-        soup_session_add_feature(session, SOUP_SESSION_FEATURE(logger));
-        soup_logger_set_printer(logger, soupLogPrinter, 0, 0);
-        g_object_unref(logger);
-    }
-#endif // !LOG_DISABLED
-
-    g_object_set_data(G_OBJECT(session), "webkit-init", reinterpret_cast<void*>(0xdeadbeef));
-}
-
 SoupSession* ResourceHandleInternal::soupSession()
 {
-    SoupSession* session = sessionFromContext(m_context.get());
-    ensureSessionIsInitialized(session);
-    return session;
+    return sessionFromContext(m_context.get());
 }
 
 bool ResourceHandle::cancelledOrClientless()
@@ -879,13 +843,9 @@ static void wroteBodyCallback(SoupMessage*, gpointer data)
     d->m_response.resourceLoadTiming()->sendEnd = milisecondsSinceRequest(d->m_response.resourceLoadTiming()->requestTime);
 }
 
-static void requestStartedCallback(SoupSession*, SoupMessage* soupMessage, SoupSocket*, gpointer)
+void ResourceHandle::didStartRequest()
 {
-    RefPtr<ResourceHandle> handle = static_cast<ResourceHandle*>(g_object_get_data(G_OBJECT(soupMessage), "handle"));
-    if (!handle)
-        return;
-
-    ResourceHandleInternal* d = handle->getInternal();
+    ResourceHandleInternal* d = getInternal();
     if (!d->m_response.resourceLoadTiming())
         return;
 
@@ -1431,62 +1391,6 @@ static gboolean requestTimeoutCallback(gpointer data)
     return FALSE;
 }
 
-static void authenticateCallback(SoupSession* session, SoupMessage* soupMessage, SoupAuth* soupAuth, gboolean retrying)
-{
-    RefPtr<ResourceHandle> handle = static_cast<ResourceHandle*>(g_object_get_data(G_OBJECT(soupMessage), "handle"));
-    if (!handle)
-        return;
-    handle->didReceiveAuthenticationChallenge(AuthenticationChallenge(session, soupMessage, soupAuth, retrying, handle.get()));
-}
-
-static SoupSession* createSoupSession()
-{
-    // Values taken from http://www.browserscope.org/  following
-    // the rule "Do What Every Other Modern Browser Is Doing". They seem
-    // to significantly improve page loading time compared to soup's
-    // default values.
-    static const int maxConnections = 35;
-    static const int maxConnectionsPerHost = 6;
-
-    SoupSession* session = soup_session_async_new();
-    g_object_set(session,
-        SOUP_SESSION_MAX_CONNS, maxConnections,
-        SOUP_SESSION_MAX_CONNS_PER_HOST, maxConnectionsPerHost,
-        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_USE_THREAD_CONTEXT, TRUE,
-        NULL);
-    g_signal_connect(session, "authenticate", G_CALLBACK(authenticateCallback), 0);
-
-#if ENABLE(WEB_TIMING)
-    g_signal_connect(session, "request-started", G_CALLBACK(requestStartedCallback), 0);
-#endif
-
-    return session;
-}
-
-SoupSession* ResourceHandle::defaultSession()
-{
-    static SoupSession* session = createSoupSession();
-    return session;
-}
-
-SoupSession* ResourceHandle::createTestingSession()
-{
-    SoupSession* session = createSoupSession();
-    // The testing session operates with the default cookie jar.
-    soup_session_add_feature(session, SOUP_SESSION_FEATURE(soupCookieJar()));
-    return session;
-}
-
-SoupSession* ResourceHandle::createPrivateBrowsingSession()
-{
-    SoupSession* session = createSoupSession();
-    soup_session_add_feature(session, SOUP_SESSION_FEATURE(createPrivateBrowsingCookieJar()));
-    return session;
-}
-
 uint64_t ResourceHandle::getSoupRequestInitiatingPageID(SoupRequest* request)
 {
     uint64_t* initiatingPageIDPtr = static_cast<uint64_t*>(g_object_get_data(G_OBJECT(request), gSoupRequestInitiatingPageIDKey));
diff --git a/Source/WebCore/platform/network/soup/SoupNetworkSession.cpp b/Source/WebCore/platform/network/soup/SoupNetworkSession.cpp
new file mode 100644 (file)
index 0000000..9448394
--- /dev/null
@@ -0,0 +1,276 @@
+/*
+ * Copyright (C) 2014 Igalia S.L.
+ *
+ * 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 COMPUTER, 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 COMPUTER, 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.
+ */
+
+#include "config.h"
+#include "SoupNetworkSession.h"
+
+#include "AuthenticationChallenge.h"
+#include "CookieJarSoup.h"
+#include "GOwnPtrSoup.h"
+#include "Logging.h"
+#include "ResourceHandle.h"
+#include <libsoup/soup.h>
+#include <wtf/text/CString.h>
+#include <wtf/text/StringBuilder.h>
+
+#if PLATFORM(EFL)
+#include "ProxyResolverSoup.h"
+#endif
+
+namespace WebCore {
+
+#if !LOG_DISABLED
+inline static void soupLogPrinter(SoupLogger*, SoupLoggerLogLevel, char direction, const char* data, gpointer)
+{
+    LOG(Network, "%c %s", direction, data);
+}
+#endif
+
+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()
+{
+    GRefPtr<SoupCookieJar> cookieJar = adoptGRef(createPrivateBrowsingCookieJar());
+    return std::unique_ptr<SoupNetworkSession>(new SoupNetworkSession(cookieJar.get()));
+}
+
+std::unique_ptr<SoupNetworkSession> SoupNetworkSession::createForSoupSession(SoupSession* soupSession)
+{
+    return std::unique_ptr<SoupNetworkSession>(new SoupNetworkSession(soupSession));
+}
+
+static void authenticateCallback(SoupSession* session, SoupMessage* soupMessage, SoupAuth* soupAuth, gboolean retrying)
+{
+    RefPtr<ResourceHandle> handle = static_cast<ResourceHandle*>(g_object_get_data(G_OBJECT(soupMessage), "handle"));
+    if (!handle)
+        return;
+    handle->didReceiveAuthenticationChallenge(AuthenticationChallenge(session, soupMessage, soupAuth, retrying, handle.get()));
+}
+
+static void requestStartedCallback(SoupSession*, SoupMessage* soupMessage, SoupSocket*, gpointer)
+{
+    RefPtr<ResourceHandle> handle = static_cast<ResourceHandle*>(g_object_get_data(G_OBJECT(soupMessage), "handle"));
+    if (!handle)
+        return;
+    handle->didStartRequest();
+}
+
+SoupNetworkSession::SoupNetworkSession(SoupCookieJar* cookieJar)
+    : m_soupSession(adoptGRef(soup_session_async_new()))
+{
+    // Values taken from http://www.browserscope.org/ following
+    // the rule "Do What Every Other Modern Browser Is Doing". They seem
+    // to significantly improve page loading time compared to soup's
+    // default values.
+    static const int maxConnections = 35;
+    static const int maxConnectionsPerHost = 6;
+
+    g_object_set(m_soupSession.get(),
+        SOUP_SESSION_MAX_CONNS, maxConnections,
+        SOUP_SESSION_MAX_CONNS_PER_HOST, maxConnectionsPerHost,
+        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_USE_THREAD_CONTEXT, TRUE,
+        nullptr);
+
+    setupLogger();
+
+    g_signal_connect(m_soupSession.get(), "authenticate", G_CALLBACK(authenticateCallback), nullptr);
+#if ENABLE(WEB_TIMING)
+    g_signal_connect(m_soupSession.get(), "request-started", G_CALLBACK(requestStartedCallback), nullptr);
+#endif
+}
+
+SoupNetworkSession::SoupNetworkSession(SoupSession* soupSession)
+    : m_soupSession(soupSession)
+{
+    setupLogger();
+}
+
+SoupNetworkSession::~SoupNetworkSession()
+{
+}
+
+void SoupNetworkSession::setupLogger()
+{
+#if !LOG_DISABLED
+    if (LogNetwork.state != WTFLogChannelOn || soup_session_get_feature(m_soupSession.get(), SOUP_TYPE_LOGGER))
+        return;
+
+    GRefPtr<SoupLogger> logger = adoptGRef(soup_logger_new(SOUP_LOGGER_LOG_BODY, -1));
+    soup_session_add_feature(m_soupSession.get(), SOUP_SESSION_FEATURE(logger.get()));
+    soup_logger_set_printer(logger.get(), soupLogPrinter, nullptr, nullptr);
+#endif
+}
+
+void SoupNetworkSession::setCookieJar(SoupCookieJar* jar)
+{
+    if (SoupCookieJar* currentJar = cookieJar())
+        soup_session_remove_feature(m_soupSession.get(), SOUP_SESSION_FEATURE(currentJar));
+    soup_session_add_feature(m_soupSession.get(), SOUP_SESSION_FEATURE(jar));
+}
+
+SoupCookieJar* SoupNetworkSession::cookieJar() const
+{
+    return SOUP_COOKIE_JAR(soup_session_get_feature(m_soupSession.get(), SOUP_TYPE_COOKIE_JAR));
+}
+
+void SoupNetworkSession::setCache(SoupCache* cache)
+{
+    ASSERT(!soup_session_get_feature(m_soupSession.get(), SOUP_TYPE_CACHE));
+    soup_session_add_feature(m_soupSession.get(), SOUP_SESSION_FEATURE(cache));
+}
+
+SoupCache* SoupNetworkSession::cache() const
+{
+    SoupSessionFeature* soupCache = soup_session_get_feature(m_soupSession.get(), SOUP_TYPE_CACHE);
+    return soupCache ? SOUP_CACHE(soupCache) : nullptr;
+}
+
+void SoupNetworkSession::setSSLPolicy(SSLPolicy flags)
+{
+    g_object_set(m_soupSession.get(),
+        SOUP_SESSION_SSL_USE_SYSTEM_CA_FILE, flags & SSLUseSystemCAFile ? TRUE : FALSE,
+        SOUP_SESSION_SSL_STRICT, flags & SSLStrict ? TRUE : FALSE,
+        nullptr);
+}
+
+SoupNetworkSession::SSLPolicy SoupNetworkSession::sslPolicy() const
+{
+    gboolean useSystemCAFile, strict;
+    g_object_get(m_soupSession.get(),
+        SOUP_SESSION_SSL_USE_SYSTEM_CA_FILE, &useSystemCAFile,
+        SOUP_SESSION_SSL_STRICT, &strict,
+        nullptr);
+
+    SSLPolicy flags = 0;
+    if (useSystemCAFile)
+        flags |= SSLUseSystemCAFile;
+    if (strict)
+        flags |= SSLStrict;
+    return flags;
+}
+
+void SoupNetworkSession::setHTTPProxy(const char* httpProxy, const char* httpProxyExceptions)
+{
+#if PLATFORM(EFL)
+    // Only for EFL because GTK port uses the default resolver, which uses GIO's proxy resolver.
+    if (!httpProxy) {
+        soup_session_remove_feature_by_type(m_soupSession.get(), SOUP_TYPE_PROXY_URI_RESOLVER);
+        return;
+    }
+
+    GRefPtr<SoupProxyURIResolver> resolver = adoptGRef(soupProxyResolverWkNew(httpProxy, httpProxyExceptions));
+    soup_session_add_feature(m_soupSession.get(), SOUP_SESSION_FEATURE(resolver.get()));
+#else
+    UNUSED_PARAM(httpProxy);
+    UNUSED_PARAM(httpProxyExceptions);
+#endif
+}
+
+char* SoupNetworkSession::httpProxy() const
+{
+#if PLATFORM(EFL)
+    SoupSessionFeature* soupResolver = soup_session_get_feature(m_soupSession.get(), SOUP_TYPE_PROXY_URI_RESOLVER);
+    if (!soupResolver)
+        return nullptr;
+
+    GOwnPtr<SoupURI> uri;
+    g_object_get(soupResolver, SOUP_PROXY_RESOLVER_WK_PROXY_URI, &uri.outPtr(), nullptr);
+
+    return uri ? soup_uri_to_string(uri.get(), FALSE) : nullptr;
+#else
+    return nullptr;
+#endif
+}
+
+void SoupNetworkSession::setupHTTPProxyFromEnvironment()
+{
+#if PLATFORM(EFL)
+    const char* httpProxy = getenv("http_proxy");
+    if (!httpProxy)
+        return;
+
+    setHTTPProxy(httpProxy, getenv("no_proxy"));
+#endif
+}
+
+static CString buildAcceptLanguages(Vector<String> languages)
+{
+    // Ignore "C" locale.
+    size_t position = languages.find("c");
+    if (position != notFound)
+        languages.remove(position);
+
+    // Fallback to "en" if the list is empty.
+    if (languages.isEmpty())
+        return "en";
+
+    // Calculate deltas for the quality values.
+    int delta;
+    if (languages.size() < 10)
+        delta = 10;
+    else if (languages.size() < 20)
+        delta = 5;
+    else
+        delta = 1;
+
+    // Set quality values for each language.
+    StringBuilder builder;
+    for (size_t i = 0; i < languages.size(); ++i) {
+        if (i)
+            builder.append(", ");
+
+        builder.append(languages[i]);
+
+        int quality = 100 - i * delta;
+        if (quality > 0 && quality < 100) {
+            char buffer[8];
+            g_ascii_formatd(buffer, 8, "%.2f", quality / 100.0);
+            builder.append(String::format(";q=%s", buffer));
+        }
+    }
+
+    return builder.toString().utf8();
+}
+
+void SoupNetworkSession::setAcceptLanguages(Vector<String> languages)
+{
+    g_object_set(m_soupSession.get(), "accept-language", buildAcceptLanguages(languages).data(), nullptr);
+}
+
+} // namespace WebCore
+
diff --git a/Source/WebCore/platform/network/soup/SoupNetworkSession.h b/Source/WebCore/platform/network/soup/SoupNetworkSession.h
new file mode 100644 (file)
index 0000000..179d22e
--- /dev/null
@@ -0,0 +1,86 @@
+/*
+ * Copyright (C) 2014 Igalia S.L.
+ *
+ * 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 COMPUTER, 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 COMPUTER, 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 SoupNetworkSession_h
+#define SoupNetworkSession_h
+
+#include <wtf/NeverDestroyed.h>
+#include <wtf/Noncopyable.h>
+#include <wtf/Vector.h>
+#include <wtf/gobject/GRefPtr.h>
+#include <wtf/text/WTFString.h>
+
+typedef struct _SoupCache SoupCache;
+typedef struct _SoupCookieJar SoupCookieJar;
+typedef struct _SoupSession SoupSession;
+
+namespace WebCore {
+
+class SoupNetworkSession {
+    WTF_MAKE_NONCOPYABLE(SoupNetworkSession); WTF_MAKE_FAST_ALLOCATED;
+    friend class NeverDestroyed<SoupNetworkSession>;
+public:
+    ~SoupNetworkSession();
+
+    static SoupNetworkSession& defaultSession();
+    static std::unique_ptr<SoupNetworkSession> createPrivateBrowsingSession();
+    static std::unique_ptr<SoupNetworkSession> createTestingSession();
+    static std::unique_ptr<SoupNetworkSession> createForSoupSession(SoupSession*);
+
+    enum SSLPolicyFlags {
+        SSLStrict = 1 << 0,
+        SSLUseSystemCAFile = 1 << 1
+    };
+    typedef unsigned SSLPolicy;
+
+    SoupSession* soupSession() const { return m_soupSession.get(); }
+
+    void setCookieJar(SoupCookieJar*);
+    SoupCookieJar* cookieJar() const;
+
+    void setCache(SoupCache*);
+    SoupCache* cache() const;
+
+    void setSSLPolicy(SSLPolicy);
+    SSLPolicy sslPolicy() const;
+
+    void setHTTPProxy(const char* httpProxy, const char* httpProxyExceptions);
+    char* httpProxy() const;
+    void setupHTTPProxyFromEnvironment();
+
+    void setAcceptLanguages(Vector<String>);
+
+private:
+    SoupNetworkSession(SoupCookieJar*);
+    SoupNetworkSession(SoupSession*);
+
+    void setupLogger();
+
+    GRefPtr<SoupSession> m_soupSession;
+};
+
+} // namespace WebCore
+
+#endif
index 150a300..919a89f 100644 (file)
@@ -1,3 +1,28 @@
+2014-01-13  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        [SOUP] Add SoupNetworkSession class to wrap a SoupSession
+        https://bugs.webkit.org/show_bug.cgi?id=126813
+
+        Reviewed by Gustavo Noronha Silva.
+
+        Use the new SoupNetworkSession API.
+
+        * ewk/ewk_cookies.cpp:
+        (ewk_cookies_file_set):
+        * ewk/ewk_main.cpp:
+        (_ewk_init_body):
+        * ewk/ewk_network.cpp:
+        (ewk_network_proxy_uri_set):
+        (ewk_network_proxy_uri_get):
+        (ewk_network_tls_certificate_check_get):
+        (ewk_network_tls_certificate_check_set):
+        (ewk_network_tls_ca_certificates_path_get):
+        (ewk_network_tls_ca_certificates_path_set):
+        (ewk_network_default_soup_session_get):
+        * ewk/ewk_view.cpp:
+        (ewk_view_soup_session_get):
+        (ewk_view_soup_session_set):
+
 2014-01-12  Jinwoo Song  <jinwoo7.song@samsung.com>
 
         Fix build warnings by unused parameter
index bbee8e4..633ae81 100644 (file)
@@ -22,7 +22,7 @@
 #include "ewk_cookies.h"
 
 #include "CookieJarSoup.h"
-#include "ResourceHandle.h"
+#include "SoupNetworkSession.h"
 #include <Eina.h>
 #include <eina_safety_checks.h>
 #include <glib.h>
@@ -42,13 +42,9 @@ Eina_Bool ewk_cookies_file_set(const char* filename)
 
     soup_cookie_jar_set_accept_policy(cookieJar, SOUP_COOKIE_JAR_ACCEPT_NO_THIRD_PARTY);
 
-    SoupSession* session = WebCore::ResourceHandle::defaultSession();
-    SoupSessionFeature* oldjar = soup_session_get_feature(session, SOUP_TYPE_COOKIE_JAR);
-    if (oldjar)
-        soup_session_remove_feature(session, oldjar);
-
+    WebCore::SoupNetworkSession::defaultSession().setCookieJar(cookieJar);
     WebCore::setSoupCookieJar(cookieJar);
-    soup_session_add_feature(session, SOUP_SESSION_FEATURE(cookieJar));
+    g_object_unref(cookieJar);
 
     return true;
 }
index d716777..72ffcd6 100644 (file)
@@ -29,6 +29,7 @@
 #include "ResourceHandle.h"
 #include "ScriptController.h"
 #include "Settings.h"
+#include "SoupNetworkSession.h"
 #include "StorageTracker.h"
 #include "StorageTrackerClientEfl.h"
 #include "ewk_auth_soup_private.h"
@@ -204,9 +205,8 @@ Eina_Bool _ewk_init_body(void)
 
     WebCore::StorageTracker::initializeTracker(localStorageDirectory.utf8().data(), trackerClient());
 
-    SoupSession* session = WebCore::ResourceHandle::defaultSession();
     SoupSessionFeature* auth_dialog = static_cast<SoupSessionFeature*>(g_object_new(EWK_TYPE_SOUP_AUTH_DIALOG, 0));
-    soup_session_add_feature(session, auth_dialog);
+    soup_session_add_feature(WebCore::SoupNetworkSession::defaultSession().soupSession(), auth_dialog);
 
     WebCore::ResourceHandle::setIgnoreSSLErrors(true);
 
index 52d20aa..8f4c049 100644 (file)
@@ -23,6 +23,7 @@
 #include "NetworkStateNotifier.h"
 #include "ProxyResolverSoup.h"
 #include "ResourceHandle.h"
+#include "SoupNetworkSession.h"
 #include "ewk_private.h"
 #include <Eina.h>
 #include <libsoup/soup.h>
 
 void ewk_network_proxy_uri_set(const char* proxy)
 {
-    SoupSession* session = WebCore::ResourceHandle::defaultSession();
-
-    if (!proxy) {
+    if (!proxy)
         ERR("no proxy uri. remove proxy feature in soup.");
-        soup_session_remove_feature_by_type(session, SOUP_TYPE_PROXY_URI_RESOLVER);
-        return;
-    }
-
-    SoupProxyURIResolver* resolverEfl = soupProxyResolverWkNew(proxy, 0);
-    soup_session_add_feature(session, SOUP_SESSION_FEATURE(resolverEfl));
-    g_object_unref(resolverEfl);
+    WebCore::SoupNetworkSession::defaultSession().setHTTPProxy(proxy, 0);
 }
 
 const char* ewk_network_proxy_uri_get(void)
 {
-    SoupURI* uri;
-    SoupSession* session = WebCore::ResourceHandle::defaultSession();
-    SoupProxyURIResolver* resolver = SOUP_PROXY_URI_RESOLVER(soup_session_get_feature(session, SOUP_TYPE_PROXY_URI_RESOLVER));
-    if (!resolver)
-        return 0;
-
-    g_object_get(resolver, SOUP_PROXY_RESOLVER_WK_PROXY_URI, &uri, NULL);
-
+    char* uri = WebCore::SoupNetworkSession::defaultSession().httpProxy();
     if (!uri) {
         ERR("no proxy uri");
         return 0;
     }
 
-    WTF::String proxy = soup_uri_to_string(uri, false);
-    return eina_stringshare_add(proxy.utf8().data());
+    return eina_stringshare_add(uri);
 }
 
 Eina_Bool ewk_network_tls_certificate_check_get()
 {
-    bool checkCertificates = false;
-
-    SoupSession* defaultSession = WebCore::ResourceHandle::defaultSession();
-    g_object_get(defaultSession, "ssl-strict", &checkCertificates, NULL);
-
-    return checkCertificates;
+    unsigned policy = WebCore::SoupNetworkSession::defaultSession().sslPolicy();
+    return policy & WebCore::SoupNetworkSession::SSLStrict;
 }
 
 void ewk_network_tls_certificate_check_set(Eina_Bool checkCertificates)
 {
-    SoupSession* defaultSession = WebCore::ResourceHandle::defaultSession();
-    g_object_set(defaultSession, "ssl-strict", checkCertificates, NULL);
+    unsigned policy = WebCore::SoupNetworkSession::defaultSession().sslPolicy();
+    WebCore::SoupNetworkSession::defaultSession().setSSLPolicy(policy | WebCore::SoupNetworkSession::SSLStrict);
 }
 
 const char* ewk_network_tls_ca_certificates_path_get()
 {
     const char* bundlePath = 0;
 
-    SoupSession* defaultSession = WebCore::ResourceHandle::defaultSession();
+    SoupSession* defaultSession = WebCore::SoupNetworkSession::defaultSession().soupSession();
     g_object_get(defaultSession, "ssl-ca-file", &bundlePath, NULL);
 
     return bundlePath;
@@ -90,11 +71,11 @@ const char* ewk_network_tls_ca_certificates_path_get()
 
 void ewk_network_tls_ca_certificates_path_set(const char* bundlePath)
 {
-    SoupSession* defaultSession = WebCore::ResourceHandle::defaultSession();
+    SoupSession* defaultSession = WebCore::SoupNetworkSession::defaultSession().soupSession();
     g_object_set(defaultSession, "ssl-ca-file", bundlePath, NULL);
 }
 
 SoupSession* ewk_network_default_soup_session_get()
 {
-    return WebCore::ResourceHandle::defaultSession();
+    return WebCore::SoupNetworkSession::defaultSession().soupSession();
 }
index 47f19ab..4703ffc 100644 (file)
@@ -65,6 +65,7 @@
 #include "RuntimeEnabledFeatures.h"
 #include "ScriptController.h"
 #include "Settings.h"
+#include "SoupNetworkSession.h"
 #include "TiledBackingStore.h"
 #include "c_instance.h"
 #include "ewk_contextmenu_private.h"
@@ -4546,7 +4547,7 @@ SoupSession* ewk_view_soup_session_get(const Evas_Object* ewkView)
 {
     EWK_VIEW_SD_GET_OR_RETURN(ewkView, smartData, 0);
     EWK_VIEW_PRIV_GET_OR_RETURN(smartData, priv, 0);
-    return priv->storageSession->soupSession();
+    return priv->storageSession->soupNetworkSession().soupSession();
 }
 
 void ewk_view_soup_session_set(Evas_Object* ewkView, SoupSession* session)
@@ -4558,7 +4559,7 @@ void ewk_view_soup_session_set(Evas_Object* ewkView, SoupSession* session)
             "a SoupSessionSync was provided.");
         return;
     }
-    priv->storageSession->setSoupSession(session);
+    priv->storageSession->setSoupNetworkSession(WebCore::SoupNetworkSession::createForSoupSession(session));
 }
 
 Eina_Bool ewk_view_setting_enable_xss_auditor_get(const Evas_Object* ewkView)
index 736a3d3..21258db 100644 (file)
@@ -1,5 +1,16 @@
 2014-01-13  Carlos Garcia Campos  <cgarcia@igalia.com>
 
+        [SOUP] Add SoupNetworkSession class to wrap a SoupSession
+        https://bugs.webkit.org/show_bug.cgi?id=126813
+
+        Reviewed by Gustavo Noronha Silva.
+
+        * webkit/webkitglobals.cpp:
+        (webkit_get_default_session): Use the new SoupNetworkSession API
+        to get the default SoupSession
+
+2014-01-13  Carlos Garcia Campos  <cgarcia@igalia.com>
+
         Unreviewed. Update NEWS and Versions.m4 for 2.3.4 release.
 
         * NEWS: Added release notes for 2.3.4.
index 2cb5be5..f61c8e2 100644 (file)
@@ -39,6 +39,7 @@
 #include "ResourceHandleInternal.h"
 #include "ResourceResponse.h"
 #include "SchemeRegistry.h"
+#include "SoupNetworkSession.h"
 #include "TextEncodingRegistry.h"
 #include "webkitapplicationcache.h"
 #include "webkitfavicondatabase.h"
@@ -83,7 +84,7 @@ using namespace WebCore;
 SoupSession* webkit_get_default_session ()
 {
     webkitInit();
-    return ResourceHandle::defaultSession();
+    return SoupNetworkSession::defaultSession().soupSession();
 }
 
 /**
index 804bc96..a021e7b 100644 (file)
@@ -1,3 +1,32 @@
+2014-01-13  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        [SOUP] Add SoupNetworkSession class to wrap a SoupSession
+        https://bugs.webkit.org/show_bug.cgi?id=126813
+
+        Reviewed by Gustavo Noronha Silva.
+
+        Use the new SoupNetworkSession API.
+
+        * NetworkProcess/soup/NetworkProcessSoup.cpp:
+        (WebKit::NetworkProcess::platformInitializeNetworkProcess):
+        (WebKit::NetworkProcess::platformSetCacheModel):
+        (WebKit::NetworkProcess::clearCacheForAllOrigins):
+        * NetworkProcess/unix/NetworkProcessMainUnix.cpp:
+        (WebKit::NetworkProcessMain):
+        * WebProcess/Cookies/soup/WebCookieManagerSoup.cpp:
+        (WebKit::WebCookieManager::setCookiePersistentStorage):
+        * WebProcess/efl/WebProcessMainEfl.cpp:
+        (WebKit::WebProcessMainEfl):
+        * WebProcess/gtk/WebProcessMainGtk.cpp:
+        (WebKit::WebProcessMainGtk):
+        * WebProcess/soup/WebProcessSoup.cpp:
+        (WebKit::WebProcess::platformSetCacheModel):
+        (WebKit::WebProcess::platformClearResourceCaches):
+        (WebKit::setSoupSessionAcceptLanguage):
+        (WebKit::WebProcess::platformInitializeWebProcess):
+        * WebProcess/soup/WebSoupRequestManager.cpp:
+        (WebKit::WebSoupRequestManager::registerURIScheme):
+
 2014-01-13  Zalan Bujtas  <zalan@apple.com>
 
         Enable SUBPIXEL_LAYOUT on Mac
index 6d7cf97..58dd5c6 100644 (file)
@@ -35,6 +35,7 @@
 #include <WebCore/FileSystem.h>
 #include <WebCore/NotImplemented.h>
 #include <WebCore/ResourceHandle.h>
+#include <WebCore/SoupNetworkSession.h>
 #include <libsoup/soup.h>
 #include <wtf/gobject/GOwnPtr.h>
 #include <wtf/gobject/GRefPtr.h>
@@ -78,7 +79,7 @@ void NetworkProcess::platformInitializeNetworkProcess(const NetworkProcessCreati
 {
     ASSERT(!parameters.diskCacheDirectory.isEmpty());
     GRefPtr<SoupCache> soupCache = adoptGRef(soup_cache_new(parameters.diskCacheDirectory.utf8().data(), SOUP_CACHE_SINGLE_USER));
-    soup_session_add_feature(WebCore::ResourceHandle::defaultSession(), SOUP_SESSION_FEATURE(soupCache.get()));
+    SoupNetworkSession::defaultSession().setCache(soupCache.get());
     soup_cache_load(soupCache.get());
 
     if (!parameters.cookiePersistentStoragePath.isEmpty()) {
@@ -101,8 +102,7 @@ void NetworkProcess::platformSetCacheModel(CacheModel cacheModel)
     unsigned long urlCacheMemoryCapacity = 0;
     unsigned long urlCacheDiskCapacity = 0;
 
-    SoupSession* session = ResourceHandle::defaultSession();
-    SoupCache* cache = SOUP_CACHE(soup_session_get_feature(session, SOUP_TYPE_CACHE));
+    SoupCache* cache = SoupNetworkSession::defaultSession().cache();
     uint64_t diskFreeSize = getCacheDiskFreeSize(cache) / 1024 / 1024;
 
     uint64_t memSize = getMemorySize();
@@ -129,8 +129,7 @@ void NetworkProcess::clearCacheForAllOrigins(uint32_t cachesToClear)
     if (cachesToClear == InMemoryResourceCachesOnly)
         return;
 
-    SoupSession* session = ResourceHandle::defaultSession();
-    soup_cache_clear(SOUP_CACHE(soup_session_get_feature(session, SOUP_TYPE_CACHE)));
+    soup_cache_clear(SoupNetworkSession::defaultSession().cache());
 }
 
 void NetworkProcess::platformTerminate()
index 0f525ae..03a8bcf 100644 (file)
@@ -31,7 +31,7 @@
 
 #include "WKBase.h"
 #include "WebKit2Initialize.h"
-#include <WebCore/ResourceHandle.h>
+#include <WebCore/SoupNetworkSession.h>
 #include <WebKit2/NetworkProcess.h>
 #include <error.h>
 #include <runtime/InitializeThreading.h>
@@ -41,7 +41,6 @@
 #include <wtf/gobject/GRefPtr.h>
 
 #if PLATFORM(EFL)
-#include "ProxyResolverSoup.h"
 #include <Ecore.h>
 #endif
 
@@ -68,18 +67,7 @@ WK_EXPORT int NetworkProcessMain(int argc, char* argv[])
 
     InitializeWebKit2();
 
-#if USE(SOUP)
-    SoupSession* session = ResourceHandle::defaultSession();
-#if PLATFORM(EFL)
-    // Only for EFL because GTK port uses the default resolver, which uses GIO's proxy resolver.
-    const char* httpProxy = getenv("http_proxy");
-    if (httpProxy) {
-        const char* noProxy = getenv("no_proxy");
-        GRefPtr<SoupProxyURIResolver> resolver = adoptGRef(soupProxyResolverWkNew(httpProxy, noProxy));
-        soup_session_add_feature(session, SOUP_SESSION_FEATURE(resolver.get()));
-    }
-#endif
-#endif
+    SoupNetworkSession::defaultSession().setupHTTPProxyFromEnvironment();
 
     int socket = atoi(argv[1]);
 
@@ -92,16 +80,15 @@ WK_EXPORT int NetworkProcessMain(int argc, char* argv[])
     // Despite using system CAs to validate certificates we're
     // accepting invalid certificates by default. New API will be
     // added later to let client accept/discard invalid certificates.
-    g_object_set(session, SOUP_SESSION_SSL_USE_SYSTEM_CA_FILE, TRUE,
-        SOUP_SESSION_SSL_STRICT, FALSE, NULL);
+    SoupNetworkSession::defaultSession().setSSLPolicy(SoupNetworkSession::SSLUseSystemCAFile);
 #endif
 
     RunLoop::run();
 
 #if USE(SOUP)
-    if (SoupSessionFeature* soupCache = soup_session_get_feature(session, SOUP_TYPE_CACHE)) {
-        soup_cache_flush(SOUP_CACHE(soupCache));
-        soup_cache_dump(SOUP_CACHE(soupCache));
+    if (SoupCache* soupCache = SoupNetworkSession::defaultSession().cache()) {
+        soup_cache_flush(soupCache);
+        soup_cache_dump(soupCache);
     }
 #endif
 
index 17de312..7054f43 100644 (file)
@@ -29,7 +29,7 @@
 #include "ChildProcess.h"
 #include "WebKitSoupCookieJarSqlite.h"
 #include <WebCore/CookieJarSoup.h>
-#include <WebCore/ResourceHandle.h>
+#include <WebCore/SoupNetworkSession.h>
 #include <libsoup/soup.h>
 #include <wtf/gobject/GRefPtr.h>
 #include <wtf/text/CString.h>
@@ -96,12 +96,8 @@ void WebCookieManager::setCookiePersistentStorage(const String& storagePath, uin
         ASSERT_NOT_REACHED();
     }
 
-    SoupCookieJar* currentJar = WebCore::soupCookieJar();
-    soup_cookie_jar_set_accept_policy(jar.get(), soup_cookie_jar_get_accept_policy(currentJar));
-    SoupSession* session = ResourceHandle::defaultSession();
-    soup_session_remove_feature(session, SOUP_SESSION_FEATURE(currentJar));
-    soup_session_add_feature(session, SOUP_SESSION_FEATURE(jar.get()));
-
+    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());
 }
 
index 4d249db..fdd5670 100644 (file)
@@ -35,7 +35,7 @@
 #include <Efreet.h>
 #include <WebCore/AuthenticationChallenge.h>
 #include <WebCore/NetworkingContext.h>
-#include <WebCore/ResourceHandle.h>
+#include <WebCore/SoupNetworkSession.h>
 #include <WebKit2/WebProcess.h>
 #include <libsoup/soup.h>
 #include <runtime/Operations.h>
@@ -114,14 +114,7 @@ WK_EXPORT int WebProcessMainEfl(int argc, char* argv[])
 
     InitializeWebKit2();
 
-    SoupSession* session = WebCore::ResourceHandle::defaultSession();
-    const char* httpProxy = getenv("http_proxy");
-    if (httpProxy) {
-        const char* noProxy = getenv("no_proxy");
-        SoupProxyURIResolver* resolverEfl = soupProxyResolverWkNew(httpProxy, noProxy);
-        soup_session_add_feature(session, SOUP_SESSION_FEATURE(resolverEfl));
-        g_object_unref(resolverEfl);
-    }
+    SoupNetworkSession::defaultSession().setupHTTPProxyFromEnvironment();
 
     int socket = atoi(argv[1]);
 
@@ -132,9 +125,9 @@ WK_EXPORT int WebProcessMainEfl(int argc, char* argv[])
 
     RunLoop::run();
 
-    if (SoupSessionFeature* soupCache = soup_session_get_feature(session, SOUP_TYPE_CACHE)) {
-        soup_cache_flush(SOUP_CACHE(soupCache));
-        soup_cache_dump(SOUP_CACHE(soupCache));
+    if (SoupCache* soupCache = SoupNetworkSession::defaultSession().cache()) {
+        soup_cache_flush(soupCache);
+        soup_cache_dump(soupCache);
     }
 
     edje_shutdown();
index b481ee3..e15f602 100644 (file)
@@ -31,7 +31,7 @@
 #include "WebKit2Initialize.h"
 #include <WebCore/AuthenticationChallenge.h>
 #include <WebCore/NetworkingContext.h>
-#include <WebCore/ResourceHandle.h>
+#include <WebCore/SoupNetworkSession.h>
 #include <WebKit2/WebProcess.h>
 #include <gtk/gtk.h>
 #include <libintl.h>
@@ -71,15 +71,13 @@ WK_EXPORT int WebProcessMainGtk(int argc, char* argv[])
     // Despite using system CAs to validate certificates we're
     // accepting invalid certificates by default. New API will be
     // added later to let client accept/discard invalid certificates.
-    SoupSession* session = WebCore::ResourceHandle::defaultSession();
-    g_object_set(session, SOUP_SESSION_SSL_USE_SYSTEM_CA_FILE, TRUE,
-                 SOUP_SESSION_SSL_STRICT, FALSE, NULL);
+    SoupNetworkSession::defaultSession().setSSLPolicy(SoupNetworkSession::SSLUseSystemCAFile);
 
     RunLoop::run();
 
-    if (SoupSessionFeature* soupCache = soup_session_get_feature(session, SOUP_TYPE_CACHE)) {
-        soup_cache_flush(SOUP_CACHE(soupCache));
-        soup_cache_dump(SOUP_CACHE(soupCache));
+    if (SoupCache* soupCache = SoupNetworkSession::defaultSession().cache()) {
+        soup_cache_flush(soupCache);
+        soup_cache_dump(soupCache);
     }
 
     return 0;
index 733078d..809abf6 100644 (file)
 #include <WebCore/MemoryCache.h>
 #include <WebCore/PageCache.h>
 #include <WebCore/ResourceHandle.h>
+#include <WebCore/SoupNetworkSession.h>
 #include <libsoup/soup.h>
 #include <wtf/gobject/GOwnPtr.h>
 #include <wtf/gobject/GRefPtr.h>
-#include <wtf/text/CString.h>
-#include <wtf/text/StringBuilder.h>
 
 namespace WebKit {
 
@@ -94,7 +93,7 @@ void WebProcess::platformSetCacheModel(CacheModel cacheModel)
     SoupCache* cache = nullptr;
 
     if (!usesNetworkProcess()) {
-        cache = SOUP_CACHE(soup_session_get_feature(WebCore::ResourceHandle::defaultSession(), SOUP_TYPE_CACHE));
+        cache = WebCore::SoupNetworkSession::defaultSession().cache();
         diskFreeSize = getCacheDiskFreeSize(cache) / 1024 / 1024;
     }
 
@@ -122,52 +121,12 @@ void WebProcess::platformClearResourceCaches(ResourceCachesToClear cachesToClear
     if (usesNetworkProcess())
         return;
 
-    soup_cache_clear(SOUP_CACHE(soup_session_get_feature(WebCore::ResourceHandle::defaultSession(), SOUP_TYPE_CACHE)));
-}
-
-// This function is based on Epiphany code in ephy-embed-prefs.c.
-static CString buildAcceptLanguages(Vector<String> languages)
-{
-    // Ignore "C" locale.
-    size_t position = languages.find("c");
-    if (position != notFound)
-        languages.remove(position);
-
-    // Fallback to "en" if the list is empty.
-    if (languages.isEmpty())
-        return "en";
-
-    // Calculate deltas for the quality values.
-    int delta;
-    if (languages.size() < 10)
-        delta = 10;
-    else if (languages.size() < 20)
-        delta = 5;
-    else
-        delta = 1;
-
-    // Set quality values for each language.
-    StringBuilder builder;
-    for (size_t i = 0; i < languages.size(); ++i) {
-        if (i)
-            builder.append(", ");
-
-        builder.append(languages[i]);
-
-        int quality = 100 - i * delta;
-        if (quality > 0 && quality < 100) {
-            char buffer[8];
-            g_ascii_formatd(buffer, 8, "%.2f", quality / 100.0);
-            builder.append(String::format(";q=%s", buffer));
-        }
-    }
-
-    return builder.toString().utf8();
+    soup_cache_clear(WebCore::SoupNetworkSession::defaultSession().cache());
 }
 
 static void setSoupSessionAcceptLanguage(Vector<String> languages)
 {
-    g_object_set(WebCore::ResourceHandle::defaultSession(), "accept-language", buildAcceptLanguages(languages).data(), NULL);
+    WebCore::SoupNetworkSession::defaultSession().setAcceptLanguages(languages);
 }
 
 static void languageChanged(void*)
@@ -191,7 +150,7 @@ void WebProcess::platformInitializeWebProcess(const WebProcessCreationParameters
 
     ASSERT(!parameters.diskCacheDirectory.isEmpty());
     GRefPtr<SoupCache> soupCache = adoptGRef(soup_cache_new(parameters.diskCacheDirectory.utf8().data(), SOUP_CACHE_SINGLE_USER));
-    soup_session_add_feature(WebCore::ResourceHandle::defaultSession(), SOUP_SESSION_FEATURE(soupCache.get()));
+    WebCore::SoupNetworkSession::defaultSession().setCache(soupCache.get());
     soup_cache_load(soupCache.get());
 
     if (!parameters.cookiePersistentStoragePath.isEmpty()) {
index bd0cf62..70fcad5 100644 (file)
@@ -30,6 +30,7 @@
 #include "WebSoupRequestManagerProxyMessages.h"
 #include <WebCore/ResourceHandle.h>
 #include <WebCore/ResourceRequest.h>
+#include <WebCore/SoupNetworkSession.h>
 #include <wtf/gobject/GOwnPtr.h>
 #include <wtf/text/CString.h>
 
@@ -98,7 +99,7 @@ void WebSoupRequestManager::registerURIScheme(const String& scheme)
     g_ptr_array_add(m_schemes.get(), g_strdup(scheme.utf8().data()));
     g_ptr_array_add(m_schemes.get(), 0);
 
-    SoupSession* session = WebCore::ResourceHandle::defaultSession();
+    SoupSession* session = WebCore::SoupNetworkSession::defaultSession().soupSession();
     SoupRequestClass* genericRequestClass = static_cast<SoupRequestClass*>(g_type_class_ref(WEBKIT_TYPE_SOUP_REQUEST_GENERIC));
     genericRequestClass->schemes = const_cast<const char**>(reinterpret_cast<char**>(m_schemes->pdata));
     soup_session_add_feature_by_type(session, WEBKIT_TYPE_SOUP_REQUEST_GENERIC);