Changeset 210785 in webkit


Ignore:
Timestamp:
Jan 16, 2017 3:24:23 AM (7 years ago)
Author:
Carlos Garcia Campos
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.

Location:
trunk/Source
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r210781 r210785  
     12017-01-16  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        [SOUP] Fix handling of accept language property
     4        https://bugs.webkit.org/show_bug.cgi?id=166969
     5
     6        Reviewed by Michael Catanzaro.
     7
     8        Add SoupNetworkSession::setInitialAcceptLanguages() static method and update setAcceptLanguages to receive the
     9        string already built from the languages vector. Now the SoupNetworkSession saves that value globally that
     10        is always used when creating new sessions.
     11
     12        * platform/network/soup/NetworkStorageSessionSoup.cpp:
     13        (WebCore::NetworkStorageSession::switchToNewTestingSession): Remove workaround.
     14        * platform/network/soup/SoupNetworkSession.cpp:
     15        (WebCore::SoupNetworkSession::SoupNetworkSession): If initial accept languages were set, apply them to the newly created context.
     16        (WebCore::SoupNetworkSession::setInitialAcceptLanguages): Just save the given value globally.
     17        (WebCore::SoupNetworkSession::setAcceptLanguages): It receives now the string, so just set it to the session.
     18        * platform/network/soup/SoupNetworkSession.h:
     19
    1202017-01-15  Michael Catanzaro  <mcatanzaro@igalia.com>
    221
  • trunk/Source/WebCore/platform/network/soup/NetworkStorageSessionSoup.cpp

    r210729 r210785  
    8585{
    8686    defaultSession() = std::make_unique<NetworkStorageSession>(SessionID::defaultSessionID(), std::make_unique<SoupNetworkSession>());
    87     // FIXME: Creating a testing session is losing soup session values set when initializing the network process.
    88     g_object_set(defaultSession()->soupNetworkSession().soupSession(), "accept-language", "en-us", nullptr);
    8987}
    9088
  • trunk/Source/WebCore/platform/network/soup/SoupNetworkSession.cpp

    r210729 r210785  
    4242#include <wtf/text/Base64.h>
    4343#include <wtf/text/CString.h>
    44 #include <wtf/text/StringBuilder.h>
    4544
    4645namespace WebCore {
    4746
    4847static bool gIgnoreTLSErrors;
     48static CString gInitialAcceptLanguages;
    4949
    5050#if !LOG_DISABLED
     
    139139        nullptr);
    140140
     141    if (!gInitialAcceptLanguages.isNull())
     142        setAcceptLanguages(gInitialAcceptLanguages);
     143
    141144#if SOUP_CHECK_VERSION(2, 53, 92)
    142145    if (soup_auth_negotiate_supported()) {
     
    248251}
    249252
    250 static CString buildAcceptLanguages(const Vector<String>& languages)
    251 {
    252     size_t languagesCount = languages.size();
    253 
    254     // Ignore "C" locale.
    255     size_t cLocalePosition = languages.find("c");
    256     if (cLocalePosition != notFound)
    257         languagesCount--;
    258 
    259     // Fallback to "en" if the list is empty.
    260     if (!languagesCount)
    261         return "en";
    262 
    263     // Calculate deltas for the quality values.
    264     int delta;
    265     if (languagesCount < 10)
    266         delta = 10;
    267     else if (languagesCount < 20)
    268         delta = 5;
    269     else
    270         delta = 1;
    271 
    272     // Set quality values for each language.
    273     StringBuilder builder;
    274     for (size_t i = 0; i < languages.size(); ++i) {
    275         if (i == cLocalePosition)
    276             continue;
    277 
    278         if (i)
    279             builder.appendLiteral(", ");
    280 
    281         builder.append(languages[i]);
    282 
    283         int quality = 100 - i * delta;
    284         if (quality > 0 && quality < 100) {
    285             char buffer[8];
    286             g_ascii_formatd(buffer, 8, "%.2f", quality / 100.0);
    287             builder.append(String::format(";q=%s", buffer));
    288         }
    289     }
    290 
    291     return builder.toString().utf8();
    292 }
    293 
    294 void SoupNetworkSession::setAcceptLanguages(const Vector<String>& languages)
    295 {
    296     g_object_set(m_soupSession.get(), "accept-language", buildAcceptLanguages(languages).data(), nullptr);
     253
     254void SoupNetworkSession::setInitialAcceptLanguages(const CString& languages)
     255{
     256    gInitialAcceptLanguages = languages;
     257}
     258
     259void SoupNetworkSession::setAcceptLanguages(const CString& languages)
     260{
     261    g_object_set(m_soupSession.get(), "accept-language", languages.data(), nullptr);
    297262}
    298263
  • trunk/Source/WebCore/platform/network/soup/SoupNetworkSession.h

    r210781 r210785  
    5959    void setupHTTPProxyFromEnvironment();
    6060
    61     void setAcceptLanguages(const Vector<String>&);
     61    static void setInitialAcceptLanguages(const CString&);
     62    void setAcceptLanguages(const CString&);
    6263
    6364    static void setShouldIgnoreTLSErrors(bool);
  • trunk/Source/WebKit2/ChangeLog

    r210765 r210785  
     12017-01-16  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        [SOUP] Fix handling of accept language property
     4        https://bugs.webkit.org/show_bug.cgi?id=166969
     5
     6        Reviewed by Michael Catanzaro.
     7
     8        * NetworkProcess/soup/NetworkProcessSoup.cpp:
     9        (WebKit::buildAcceptLanguages): Moved from WebCore.
     10        (WebKit::NetworkProcess::userPreferredLanguagesChanged): Build the accept language string from the vector and
     11        pass set it to SoupNetworkSession to be used for new sessions, and also to all other existing sessions.
     12
    1132017-01-14  Tim Horton  <timothy_horton@apple.com>
    214
  • trunk/Source/WebKit2/NetworkProcess/soup/NetworkProcessSoup.cpp

    r210729 r210785  
    4242#include <wtf/glib/GRefPtr.h>
    4343#include <wtf/glib/GUniquePtr.h>
     44#include <wtf/text/CString.h>
     45#include <wtf/text/StringBuilder.h>
    4446
    4547using namespace WebCore;
     
    4749namespace WebKit {
    4850
     51static CString buildAcceptLanguages(const Vector<String>& languages)
     52{
     53    size_t languagesCount = languages.size();
     54
     55    // Ignore "C" locale.
     56    size_t cLocalePosition = languages.find("c");
     57    if (cLocalePosition != notFound)
     58        languagesCount--;
     59
     60    // Fallback to "en" if the list is empty.
     61    if (!languagesCount)
     62        return "en";
     63
     64    // Calculate deltas for the quality values.
     65    int delta;
     66    if (languagesCount < 10)
     67        delta = 10;
     68    else if (languagesCount < 20)
     69        delta = 5;
     70    else
     71        delta = 1;
     72
     73    // Set quality values for each language.
     74    StringBuilder builder;
     75    for (size_t i = 0; i < languages.size(); ++i) {
     76        if (i == cLocalePosition)
     77            continue;
     78
     79        if (i)
     80            builder.appendLiteral(", ");
     81
     82        builder.append(languages[i]);
     83
     84        int quality = 100 - i * delta;
     85        if (quality > 0 && quality < 100) {
     86            char buffer[8];
     87            g_ascii_formatd(buffer, 8, "%.2f", quality / 100.0);
     88            builder.append(String::format(";q=%s", buffer));
     89        }
     90    }
     91
     92    return builder.toString().utf8();
     93}
     94
    4995void NetworkProcess::userPreferredLanguagesChanged(const Vector<String>& languages)
    5096{
    51     NetworkStorageSession::defaultStorageSession().soupNetworkSession().setAcceptLanguages(languages);
     97    auto acceptLanguages = buildAcceptLanguages(languages);
     98    SoupNetworkSession::setInitialAcceptLanguages(acceptLanguages);
     99    NetworkStorageSession::forEach([&acceptLanguages](const WebCore::NetworkStorageSession& session) {
     100        session.soupNetworkSession().setAcceptLanguages(acceptLanguages);
     101    });
    52102}
    53103
Note: See TracChangeset for help on using the changeset viewer.