[SOUP] Custom protocols don't work in private browsing mode
authorcarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 21 Jan 2017 07:40:19 +0000 (07:40 +0000)
committercarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 21 Jan 2017 07:40:19 +0000 (07:40 +0000)
https://bugs.webkit.org/show_bug.cgi?id=167236

Reviewed by Sergio Villar Senin.

Source/WebCore:

Add static method to set the global custom protocols request type and setup method to add the feature to the session.

* platform/network/soup/SoupNetworkSession.cpp:
(WebCore::SoupNetworkSession::SoupNetworkSession):
(WebCore::SoupNetworkSession::setCustomProtocolRequestType):
(WebCore::SoupNetworkSession::setupCustomProtocols):
* platform/network/soup/SoupNetworkSession.h:

Source/WebKit2:

We only register them in the default session.

* NetworkProcess/CustomProtocols/soup/CustomProtocolManagerSoup.cpp:
(WebKit::CustomProtocolManager::registerProtocolClass): Set the WEBKIT_TYPE_SOUP_REQUEST_GENERIC as type for
custom protocols, and setup custom protocols in all existing sessions.
(WebKit::CustomProtocolManager::registerScheme): Use g_type_class_peek instead of g_type_class_ref since we know
the class was already created in registerProtocolClass().

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

Source/WebCore/ChangeLog
Source/WebCore/platform/network/soup/SoupNetworkSession.cpp
Source/WebCore/platform/network/soup/SoupNetworkSession.h
Source/WebKit2/ChangeLog
Source/WebKit2/NetworkProcess/CustomProtocols/soup/CustomProtocolManagerSoup.cpp

index 6aa6bbf..93f467c 100644 (file)
@@ -1,3 +1,18 @@
+2017-01-20  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        [SOUP] Custom protocols don't work in private browsing mode
+        https://bugs.webkit.org/show_bug.cgi?id=167236
+
+        Reviewed by Sergio Villar Senin.
+
+        Add static method to set the global custom protocols request type and setup method to add the feature to the session.
+
+        * platform/network/soup/SoupNetworkSession.cpp:
+        (WebCore::SoupNetworkSession::SoupNetworkSession):
+        (WebCore::SoupNetworkSession::setCustomProtocolRequestType):
+        (WebCore::SoupNetworkSession::setupCustomProtocols):
+        * platform/network/soup/SoupNetworkSession.h:
+
 2017-01-20  Matt Rajca  <mrajca@apple.com>
 
         Record whether a media element was prevented from playing without user interaction
index 852b9b8..d4ff2a7 100644 (file)
@@ -48,6 +48,7 @@ namespace WebCore {
 static bool gIgnoreTLSErrors;
 static CString gInitialAcceptLanguages;
 static SoupNetworkProxySettings gProxySettings;
+static GType gCustomProtocolRequestType;
 
 #if !LOG_DISABLED
 inline static void soupLogPrinter(SoupLogger*, SoupLoggerLogLevel, char direction, const char* data, gpointer)
@@ -140,6 +141,8 @@ SoupNetworkSession::SoupNetworkSession(SoupCookieJar* cookieJar)
         SOUP_SESSION_SSL_STRICT, FALSE,
         nullptr);
 
+    setupCustomProtocols();
+
     if (!gInitialAcceptLanguages.isNull())
         setAcceptLanguages(gInitialAcceptLanguages);
 
@@ -289,6 +292,19 @@ void SoupNetworkSession::setAcceptLanguages(const CString& languages)
     g_object_set(m_soupSession.get(), "accept-language", languages.data(), nullptr);
 }
 
+void SoupNetworkSession::setCustomProtocolRequestType(GType requestType)
+{
+    ASSERT(g_type_is_a(requestType, SOUP_TYPE_REQUEST));
+    gCustomProtocolRequestType = requestType;
+}
+
+void SoupNetworkSession::setupCustomProtocols()
+{
+    if (!g_type_is_a(gCustomProtocolRequestType, SOUP_TYPE_REQUEST))
+        return;
+    soup_session_add_feature_by_type(m_soupSession.get(), gCustomProtocolRequestType);
+}
+
 void SoupNetworkSession::setShouldIgnoreTLSErrors(bool ignoreTLSErrors)
 {
     gIgnoreTLSErrors = ignoreTLSErrors;
index 9f2e8ce..4668f69 100644 (file)
@@ -32,6 +32,7 @@
 #include <wtf/glib/GRefPtr.h>
 #include <wtf/text/WTFString.h>
 
+typedef size_t GType;
 typedef struct _SoupCache SoupCache;
 typedef struct _SoupCookieJar SoupCookieJar;
 typedef struct _SoupMessage SoupMessage;
@@ -70,6 +71,9 @@ public:
     static void checkTLSErrors(SoupRequest*, SoupMessage*, std::function<void (const ResourceError&)>&&);
     static void allowSpecificHTTPSCertificateForHost(const CertificateInfo&, const String& host);
 
+    static void setCustomProtocolRequestType(GType);
+    void setupCustomProtocols();
+
 private:
     void setupLogger();
 
index c71c3f1..189f3e9 100644 (file)
@@ -1,3 +1,18 @@
+2017-01-20  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        [SOUP] Custom protocols don't work in private browsing mode
+        https://bugs.webkit.org/show_bug.cgi?id=167236
+
+        Reviewed by Sergio Villar Senin.
+
+        We only register them in the default session.
+
+        * NetworkProcess/CustomProtocols/soup/CustomProtocolManagerSoup.cpp:
+        (WebKit::CustomProtocolManager::registerProtocolClass): Set the WEBKIT_TYPE_SOUP_REQUEST_GENERIC as type for
+        custom protocols, and setup custom protocols in all existing sessions.
+        (WebKit::CustomProtocolManager::registerScheme): Use g_type_class_peek instead of g_type_class_ref since we know
+        the class was already created in registerProtocolClass().
+
 2017-01-20  Brady Eidson  <beidson@apple.com>
 
         Require a button press on a gamepad for them to be exposed to the DOM.
index 13a028a..14ad130 100644 (file)
@@ -77,6 +77,11 @@ private:
 void CustomProtocolManager::registerProtocolClass()
 {
     static_cast<WebKitSoupRequestGenericClass*>(g_type_class_ref(WEBKIT_TYPE_SOUP_REQUEST_GENERIC))->client = &CustomProtocolRequestClient::singleton();
+    SoupNetworkSession::setCustomProtocolRequestType(WEBKIT_TYPE_SOUP_REQUEST_GENERIC);
+    NetworkStorageSession::forEach([](const WebCore::NetworkStorageSession& session) {
+        if (auto* soupSession = session.soupNetworkSession())
+            soupSession->setupCustomProtocols();
+    });
 }
 
 void CustomProtocolManager::registerScheme(const String& scheme)
@@ -89,9 +94,9 @@ void CustomProtocolManager::registerScheme(const String& scheme)
     g_ptr_array_add(m_registeredSchemes.get(), g_strdup(scheme.utf8().data()));
     g_ptr_array_add(m_registeredSchemes.get(), nullptr);
 
-    auto* genericRequestClass = static_cast<SoupRequestClass*>(g_type_class_ref(WEBKIT_TYPE_SOUP_REQUEST_GENERIC));
+    auto* genericRequestClass = static_cast<SoupRequestClass*>(g_type_class_peek(WEBKIT_TYPE_SOUP_REQUEST_GENERIC));
+    ASSERT(genericRequestClass);
     genericRequestClass->schemes = const_cast<const char**>(reinterpret_cast<char**>(m_registeredSchemes->pdata));
-    soup_session_add_feature_by_type(NetworkStorageSession::defaultStorageSession().getOrCreateSoupNetworkSession().soupSession(), WEBKIT_TYPE_SOUP_REQUEST_GENERIC);
 }
 
 void CustomProtocolManager::unregisterScheme(const String&)