Title: [210785] trunk/Source
Revision
210785
Author
carlo...@webkit.org
Date
2017-01-16 03:24:23 -0800 (Mon, 16 Jan 2017)

Log Message

[SOUP] Fix handling of accept language property
https://bugs.webkit.org/show_bug.cgi?id=166969

Reviewed by Michael Catanzaro.

Source/WebCore:

Add SoupNetworkSession::setInitialAcceptLanguages() static method and update setAcceptLanguages to receive the
string already built from the languages vector. Now the SoupNetworkSession saves that value globally that
is always used when creating new sessions.

* platform/network/soup/NetworkStorageSessionSoup.cpp:
(WebCore::NetworkStorageSession::switchToNewTestingSession): Remove workaround.
* platform/network/soup/SoupNetworkSession.cpp:
(WebCore::SoupNetworkSession::SoupNetworkSession): If initial accept languages were set, apply them to the newly created context.
(WebCore::SoupNetworkSession::setInitialAcceptLanguages): Just save the given value globally.
(WebCore::SoupNetworkSession::setAcceptLanguages): It receives now the string, so just set it to the session.
* platform/network/soup/SoupNetworkSession.h:

Source/WebKit2:

* NetworkProcess/soup/NetworkProcessSoup.cpp:
(WebKit::buildAcceptLanguages): Moved from WebCore.
(WebKit::NetworkProcess::userPreferredLanguagesChanged): Build the accept language string from the vector and
pass set it to SoupNetworkSession to be used for new sessions, and also to all other existing sessions.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (210784 => 210785)


--- trunk/Source/WebCore/ChangeLog	2017-01-16 00:14:40 UTC (rev 210784)
+++ trunk/Source/WebCore/ChangeLog	2017-01-16 11:24:23 UTC (rev 210785)
@@ -1,3 +1,22 @@
+2017-01-16  Carlos Garcia Campos  <cgar...@igalia.com>
+
+        [SOUP] Fix handling of accept language property
+        https://bugs.webkit.org/show_bug.cgi?id=166969
+
+        Reviewed by Michael Catanzaro.
+
+        Add SoupNetworkSession::setInitialAcceptLanguages() static method and update setAcceptLanguages to receive the
+        string already built from the languages vector. Now the SoupNetworkSession saves that value globally that
+        is always used when creating new sessions.
+
+        * platform/network/soup/NetworkStorageSessionSoup.cpp:
+        (WebCore::NetworkStorageSession::switchToNewTestingSession): Remove workaround.
+        * platform/network/soup/SoupNetworkSession.cpp:
+        (WebCore::SoupNetworkSession::SoupNetworkSession): If initial accept languages were set, apply them to the newly created context.
+        (WebCore::SoupNetworkSession::setInitialAcceptLanguages): Just save the given value globally.
+        (WebCore::SoupNetworkSession::setAcceptLanguages): It receives now the string, so just set it to the session.
+        * platform/network/soup/SoupNetworkSession.h:
+
 2017-01-15  Michael Catanzaro  <mcatanz...@igalia.com>
 
         [SOUP] SoupNetworkSession constructor should be explicit

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


--- trunk/Source/WebCore/platform/network/soup/NetworkStorageSessionSoup.cpp	2017-01-16 00:14:40 UTC (rev 210784)
+++ trunk/Source/WebCore/platform/network/soup/NetworkStorageSessionSoup.cpp	2017-01-16 11:24:23 UTC (rev 210785)
@@ -84,8 +84,6 @@
 void NetworkStorageSession::switchToNewTestingSession()
 {
     defaultSession() = std::make_unique<NetworkStorageSession>(SessionID::defaultSessionID(), std::make_unique<SoupNetworkSession>());
-    // FIXME: Creating a testing session is losing soup session values set when initializing the network process.
-    g_object_set(defaultSession()->soupNetworkSession().soupSession(), "accept-language", "en-us", nullptr);
 }
 
 SoupNetworkSession& NetworkStorageSession::soupNetworkSession() const

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


--- trunk/Source/WebCore/platform/network/soup/SoupNetworkSession.cpp	2017-01-16 00:14:40 UTC (rev 210784)
+++ trunk/Source/WebCore/platform/network/soup/SoupNetworkSession.cpp	2017-01-16 11:24:23 UTC (rev 210785)
@@ -41,11 +41,11 @@
 #include <wtf/NeverDestroyed.h>
 #include <wtf/text/Base64.h>
 #include <wtf/text/CString.h>
-#include <wtf/text/StringBuilder.h>
 
 namespace WebCore {
 
 static bool gIgnoreTLSErrors;
+static CString gInitialAcceptLanguages;
 
 #if !LOG_DISABLED
 inline static void soupLogPrinter(SoupLogger*, SoupLoggerLogLevel, char direction, const char* data, gpointer)
@@ -138,6 +138,9 @@
         SOUP_SESSION_SSL_STRICT, FALSE,
         nullptr);
 
+    if (!gInitialAcceptLanguages.isNull())
+        setAcceptLanguages(gInitialAcceptLanguages);
+
 #if SOUP_CHECK_VERSION(2, 53, 92)
     if (soup_auth_negotiate_supported()) {
         g_object_set(m_soupSession.get(),
@@ -247,53 +250,15 @@
 #endif
 }
 
-static CString buildAcceptLanguages(const Vector<String>& languages)
+
+void SoupNetworkSession::setInitialAcceptLanguages(const CString& languages)
 {
-    size_t languagesCount = languages.size();
-
-    // Ignore "C" locale.
-    size_t cLocalePosition = languages.find("c");
-    if (cLocalePosition != notFound)
-        languagesCount--;
-
-    // Fallback to "en" if the list is empty.
-    if (!languagesCount)
-        return "en";
-
-    // Calculate deltas for the quality values.
-    int delta;
-    if (languagesCount < 10)
-        delta = 10;
-    else if (languagesCount < 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 == cLocalePosition)
-            continue;
-
-        if (i)
-            builder.appendLiteral(", ");
-
-        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();
+    gInitialAcceptLanguages = languages;
 }
 
-void SoupNetworkSession::setAcceptLanguages(const Vector<String>& languages)
+void SoupNetworkSession::setAcceptLanguages(const CString& languages)
 {
-    g_object_set(m_soupSession.get(), "accept-language", buildAcceptLanguages(languages).data(), nullptr);
+    g_object_set(m_soupSession.get(), "accept-language", languages.data(), nullptr);
 }
 
 void SoupNetworkSession::setShouldIgnoreTLSErrors(bool ignoreTLSErrors)

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


--- trunk/Source/WebCore/platform/network/soup/SoupNetworkSession.h	2017-01-16 00:14:40 UTC (rev 210784)
+++ trunk/Source/WebCore/platform/network/soup/SoupNetworkSession.h	2017-01-16 11:24:23 UTC (rev 210785)
@@ -58,7 +58,8 @@
 
     void setupHTTPProxyFromEnvironment();
 
-    void setAcceptLanguages(const Vector<String>&);
+    static void setInitialAcceptLanguages(const CString&);
+    void setAcceptLanguages(const CString&);
 
     static void setShouldIgnoreTLSErrors(bool);
     static void checkTLSErrors(SoupRequest*, SoupMessage*, std::function<void (const ResourceError&)>&&);

Modified: trunk/Source/WebKit2/ChangeLog (210784 => 210785)


--- trunk/Source/WebKit2/ChangeLog	2017-01-16 00:14:40 UTC (rev 210784)
+++ trunk/Source/WebKit2/ChangeLog	2017-01-16 11:24:23 UTC (rev 210785)
@@ -1,3 +1,15 @@
+2017-01-16  Carlos Garcia Campos  <cgar...@igalia.com>
+
+        [SOUP] Fix handling of accept language property
+        https://bugs.webkit.org/show_bug.cgi?id=166969
+
+        Reviewed by Michael Catanzaro.
+
+        * NetworkProcess/soup/NetworkProcessSoup.cpp:
+        (WebKit::buildAcceptLanguages): Moved from WebCore.
+        (WebKit::NetworkProcess::userPreferredLanguagesChanged): Build the accept language string from the vector and
+        pass set it to SoupNetworkSession to be used for new sessions, and also to all other existing sessions.
+
 2017-01-14  Tim Horton  <timothy_hor...@apple.com>
 
         Remove unused WKView initializer parameter

Modified: trunk/Source/WebKit2/NetworkProcess/soup/NetworkProcessSoup.cpp (210784 => 210785)


--- trunk/Source/WebKit2/NetworkProcess/soup/NetworkProcessSoup.cpp	2017-01-16 00:14:40 UTC (rev 210784)
+++ trunk/Source/WebKit2/NetworkProcess/soup/NetworkProcessSoup.cpp	2017-01-16 11:24:23 UTC (rev 210785)
@@ -41,14 +41,64 @@
 #include <wtf/RAMSize.h>
 #include <wtf/glib/GRefPtr.h>
 #include <wtf/glib/GUniquePtr.h>
+#include <wtf/text/CString.h>
+#include <wtf/text/StringBuilder.h>
 
 using namespace WebCore;
 
 namespace WebKit {
 
+static CString buildAcceptLanguages(const Vector<String>& languages)
+{
+    size_t languagesCount = languages.size();
+
+    // Ignore "C" locale.
+    size_t cLocalePosition = languages.find("c");
+    if (cLocalePosition != notFound)
+        languagesCount--;
+
+    // Fallback to "en" if the list is empty.
+    if (!languagesCount)
+        return "en";
+
+    // Calculate deltas for the quality values.
+    int delta;
+    if (languagesCount < 10)
+        delta = 10;
+    else if (languagesCount < 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 == cLocalePosition)
+            continue;
+
+        if (i)
+            builder.appendLiteral(", ");
+
+        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 NetworkProcess::userPreferredLanguagesChanged(const Vector<String>& languages)
 {
-    NetworkStorageSession::defaultStorageSession().soupNetworkSession().setAcceptLanguages(languages);
+    auto acceptLanguages = buildAcceptLanguages(languages);
+    SoupNetworkSession::setInitialAcceptLanguages(acceptLanguages);
+    NetworkStorageSession::forEach([&acceptLanguages](const WebCore::NetworkStorageSession& session) {
+        session.soupNetworkSession().setAcceptLanguages(acceptLanguages);
+    });
 }
 
 void NetworkProcess::platformInitializeNetworkProcess(const NetworkProcessCreationParameters& parameters)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to