Changeset 170882 in webkit


Ignore:
Timestamp:
Jul 8, 2014 2:40:42 AM (10 years ago)
Author:
Carlos Garcia Campos
Message:

[GTK][Stable] Google Maps doesn't work with Version/X in the user agent
https://bugs.webkit.org/show_bug.cgi?id=134631

Reviewed by Sergio Villar Senin.

Source/WebCore:

Because of the JSC version used in stable branch, when the
Version/X string is present in the user agent, google maps uses
JavaScript API that we don't support. Move the google domain quirks
from WebKit1 to WebCore and add a quirk for google maps.

  • platform/gtk/UserAgentGtk.cpp:

(WebCore::googleDomains):
(WebCore::otherGoogleDomains):
(WebCore::isGoogleDomain): Returns whether the given host is a
known google domain
(WebCore::buildUserAgentString): Do not include the Version/X
string in the user agent if the ShouldNotIncludeSafariVersion
quirk is present.
(WebCore::standardUserAgentForURL): Add RequiresStandardUserAgent
quirk for any google doamin and ShouldNotIncludeSafariVersion for
Google Maps.

Source/WebKit/gtk:

Remove user agent quirks for google domains, since they are now
implemented in WebCore.

  • WebCoreSupport/FrameLoaderClientGtk.cpp:

(WebKit::FrameLoaderClient::userAgent): Pass the WebCore::URL
const reference to webkitWebSettingsUserAgentForURI().

  • webkit/webkitwebsettings.cpp:

(webkitWebSettingsUserAgentForURI): Use
WebCore::standardUserAgentForURL() when site specific quirks are enabled.

  • webkit/webkitwebsettingsprivate.h:

Tools:

Move user agent quirks tests from WebKit1 to WebCore.

  • TestWebKitAPI/Tests/WebCore/gtk/UserAgentQuirks.cpp:

(TestWebKitAPI::TEST):

  • TestWebKitAPI/Tests/WebKitGtk/testwebsettings.c:

(test_webkit_web_settings_user_agent):

Location:
releases/WebKitGTK/webkit-2.4
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • releases/WebKitGTK/webkit-2.4/Source/WebCore/ChangeLog

    r170800 r170882  
     12014-07-04  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        [GTK][Stable] Google Maps doesn't work with Version/X in the user agent
     4        https://bugs.webkit.org/show_bug.cgi?id=134631
     5
     6        Reviewed by Sergio Villar Senin.
     7
     8        Because of the JSC version used in stable branch, when the
     9        Version/X string is present in the user agent, google maps uses
     10        JavaScript API that we don't support. Move the google domain quirks
     11        from WebKit1 to WebCore and add a quirk for google maps.
     12
     13        * platform/gtk/UserAgentGtk.cpp:
     14        (WebCore::googleDomains):
     15        (WebCore::otherGoogleDomains):
     16        (WebCore::isGoogleDomain): Returns whether the given host is a
     17        known google domain
     18        (WebCore::buildUserAgentString): Do not include the Version/X
     19        string in the user agent if the ShouldNotIncludeSafariVersion
     20        quirk is present.
     21        (WebCore::standardUserAgentForURL): Add RequiresStandardUserAgent
     22        quirk for any google doamin and ShouldNotIncludeSafariVersion for
     23        Google Maps.
     24
    1252014-06-27  Philippe Normand  <pnormand@igalia.com>
    226
  • releases/WebKitGTK/webkit-2.4/Source/WebCore/platform/gtk/UserAgentGtk.cpp

    r170636 r170882  
    2828
    2929#include "URL.h"
     30#include <wtf/HashSet.h>
    3031#include <wtf/NeverDestroyed.h>
    3132#include <wtf/text/StringBuilder.h>
     33#include <wtf/text/StringHash.h>
    3234
    3335#if OS(UNIX)
     
    4143    enum UserAgentQuirk {
    4244        NeedsMacintoshPlatform,
     45        RequiresStandardUserAgent,
     46        ShouldNotClaimToBeSafari,
    4347
    4448        NumUserAgentQuirks
     
    6973    uint32_t m_quirks;
    7074};
     75
     76static const HashSet<String>& googleDomains()
     77{
     78    static NeverDestroyed<HashSet<String>> domains(std::initializer_list<String>({
     79        "biz",
     80        "com",
     81        "net",
     82        "org",
     83        "ae",
     84        "ag",
     85        "am",
     86        "at",
     87        "az",
     88        "be",
     89        "bi",
     90        "ca",
     91        "cc",
     92        "cd",
     93        "cg",
     94        "ch",
     95        "cl",
     96        "com.br",
     97        "com.do",
     98        "co.uk",
     99        "co.kr",
     100        "co.jp",
     101        "de",
     102        "dj",
     103        "dk",
     104        "ee",
     105        "es",
     106        "fi",
     107        "fm",
     108        "fr",
     109        "gg",
     110        "gl",
     111        "gm",
     112        "gs",
     113        "hn",
     114        "hu",
     115        "ie",
     116        "it",
     117        "je",
     118        "kz",
     119        "li",
     120        "lt",
     121        "lu",
     122        "lv",
     123        "ma",
     124        "ms",
     125        "mu",
     126        "mw",
     127        "nl",
     128        "no",
     129        "nu",
     130        "pl",
     131        "pn",
     132        "pt",
     133        "ru",
     134        "rw",
     135        "sh",
     136        "sk",
     137        "sm",
     138        "st",
     139        "td",
     140        "tk",
     141        "tp",
     142        "tv",
     143        "us",
     144        "uz",
     145        "ws"
     146    }));
     147    return domains;
     148}
     149
     150static const Vector<String>& otherGoogleDomains()
     151{
     152    static NeverDestroyed<Vector<String>> otherDomains(std::initializer_list<String>({
     153        "gmail.com",
     154        "youtube.com",
     155        "gstatic.com",
     156        "ytimg.com"
     157    }));
     158    return otherDomains;
     159}
     160
     161static bool isGoogleDomain(String host)
     162{
     163    // First check if this is one of the various google.com international domains.
     164    int position = host.find(".google.");
     165    if (position > 0 && googleDomains().contains(host.substring(position + sizeof(".google.") - 1)))
     166        return true;
     167
     168    // Then we check the possibility of it being one of the other, .com-only google domains.
     169    for (unsigned i = 0; i < otherGoogleDomains().size(); i++) {
     170        if (host.endsWith(otherGoogleDomains().at(i)))
     171            return true;
     172    }
     173
     174    return false;
     175}
    71176
    72177static const char* cpuDescriptionForUAString()
     
    139244    uaString.appendLiteral(") AppleWebKit/");
    140245    uaString.append(versionForUAString());
    141     // Version/X is mandatory *before* Safari/X to be a valid Safari UA. See
    142     // https://bugs.webkit.org/show_bug.cgi?id=133403 for details.
    143     uaString.appendLiteral(" (KHTML, like Gecko) Version/8.0 Safari/");
    144     uaString.append(versionForUAString());
     246
     247    uaString.appendLiteral(" (KHTML, like Gecko)");
     248    if (!quirks.contains(UserAgentQuirks::ShouldNotClaimToBeSafari)) {
     249        // Version/X is mandatory *before* Safari/X to be a valid Safari UA. See
     250        // https://bugs.webkit.org/show_bug.cgi?id=133403 for details.
     251        uaString.appendLiteral(" Version/8.0 Safari/");
     252        uaString.append(versionForUAString());
     253    }
    145254
    146255    return uaString.toString();
     
    181290        // use always Macintosh as platform. See https://bugs.webkit.org/show_bug.cgi?id=125444.
    182291        quirks.add(UserAgentQuirks::NeedsMacintoshPlatform);
     292    } else if (isGoogleDomain(url.host())) {
     293        // For Google domains, drop the browser's custom User Agent string, and use the
     294        // standard one, so they don't give us a broken experience.
     295        quirks.add(UserAgentQuirks::RequiresStandardUserAgent);
     296
     297        // Google Maps uses new JavaScript API not supported by us when Safari Version is present in the user agent.
     298        if (url.host().startsWith("maps.") || url.path().startsWith("/maps"))
     299            quirks.add(UserAgentQuirks::ShouldNotClaimToBeSafari);
    183300    }
    184301
  • releases/WebKitGTK/webkit-2.4/Source/WebKit/gtk/ChangeLog

    r169337 r170882  
     12014-07-04  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        [GTK][Stable] Google Maps doesn't work with Version/X in the user agent
     4        https://bugs.webkit.org/show_bug.cgi?id=134631
     5
     6        Reviewed by Sergio Villar Senin.
     7
     8        Remove user agent quirks for google domains, since they are now
     9        implemented in WebCore.
     10
     11        * WebCoreSupport/FrameLoaderClientGtk.cpp:
     12        (WebKit::FrameLoaderClient::userAgent): Pass the WebCore::URL
     13        const reference to webkitWebSettingsUserAgentForURI().
     14        * webkit/webkitwebsettings.cpp:
     15        (webkitWebSettingsUserAgentForURI): Use
     16        WebCore::standardUserAgentForURL() when site specific quirks are enabled.
     17        * webkit/webkitwebsettingsprivate.h:
     18
    1192014-05-26  Carlos Garcia Campos  <cgarcia@igalia.com>
    220
  • releases/WebKitGTK/webkit-2.4/Source/WebKit/gtk/WebCoreSupport/FrameLoaderClientGtk.cpp

    r163865 r170882  
    124124{
    125125    WebKitWebSettings* settings = webkit_web_view_get_settings(getViewFromFrame(m_frame));
    126     GUniquePtr<gchar> userAgentString(webkitWebSettingsUserAgentForURI(settings, url.string().utf8().data()));
     126    GUniquePtr<gchar> userAgentString(webkitWebSettingsUserAgentForURI(settings, url));
    127127    return String::fromUTF8(userAgentString.get());
    128128}
  • releases/WebKitGTK/webkit-2.4/Source/WebKit/gtk/webkit/webkitwebsettings.cpp

    r166484 r170882  
    15051505}
    15061506
    1507 static void initializeDomainsList(HashSet<String>& googleDomains)
    1508 {
    1509     // Google search domains.
    1510     googleDomains.add("biz");
    1511     googleDomains.add("com");
    1512     googleDomains.add("net");
    1513     googleDomains.add("org");
    1514     googleDomains.add("ae");
    1515     googleDomains.add("ag");
    1516     googleDomains.add("am");
    1517     googleDomains.add("at");
    1518     googleDomains.add("az");
    1519     googleDomains.add("be");
    1520     googleDomains.add("bi");
    1521     googleDomains.add("ca");
    1522     googleDomains.add("cc");
    1523     googleDomains.add("cd");
    1524     googleDomains.add("cg");
    1525     googleDomains.add("ch");
    1526     googleDomains.add("cl");
    1527     googleDomains.add("com.br");
    1528     googleDomains.add("com.do");
    1529     googleDomains.add("co.uk");
    1530     googleDomains.add("co.kr");
    1531     googleDomains.add("co.jp");
    1532     googleDomains.add("de");
    1533     googleDomains.add("dj");
    1534     googleDomains.add("dk");
    1535     googleDomains.add("ee");
    1536     googleDomains.add("es");
    1537     googleDomains.add("fi");
    1538     googleDomains.add("fm");
    1539     googleDomains.add("fr");
    1540     googleDomains.add("gg");
    1541     googleDomains.add("gl");
    1542     googleDomains.add("gm");
    1543     googleDomains.add("gs");
    1544     googleDomains.add("hn");
    1545     googleDomains.add("hu");
    1546     googleDomains.add("ie");
    1547     googleDomains.add("it");
    1548     googleDomains.add("je");
    1549     googleDomains.add("kz");
    1550     googleDomains.add("li");
    1551     googleDomains.add("lt");
    1552     googleDomains.add("lu");
    1553     googleDomains.add("lv");
    1554     googleDomains.add("ma");
    1555     googleDomains.add("ms");
    1556     googleDomains.add("mu");
    1557     googleDomains.add("mw");
    1558     googleDomains.add("nl");
    1559     googleDomains.add("no");
    1560     googleDomains.add("nu");
    1561     googleDomains.add("pl");
    1562     googleDomains.add("pn");
    1563     googleDomains.add("pt");
    1564     googleDomains.add("ru");
    1565     googleDomains.add("rw");
    1566     googleDomains.add("sh");
    1567     googleDomains.add("sk");
    1568     googleDomains.add("sm");
    1569     googleDomains.add("st");
    1570     googleDomains.add("td");
    1571     googleDomains.add("tk");
    1572     googleDomains.add("tp");
    1573     googleDomains.add("tv");
    1574     googleDomains.add("us");
    1575     googleDomains.add("uz");
    1576     googleDomains.add("ws");
    1577 }
    1578 
    1579 static void initializeOtherGoogleDomains(Vector<String>& otherGoogleDomains)
    1580 {
    1581     otherGoogleDomains.append("gmail.com");
    1582     otherGoogleDomains.append("youtube.com");
    1583     otherGoogleDomains.append("gstatic.com");
    1584     otherGoogleDomains.append("ytimg.com");
    1585 }
    1586 
    1587 static bool isGoogleDomain(String host)
    1588 {
    1589     DEFINE_STATIC_LOCAL(HashSet<String>, googleDomains, ());
    1590     DEFINE_STATIC_LOCAL(Vector<String>, otherGoogleDomains, ());
    1591 
    1592     if (googleDomains.isEmpty())
    1593         initializeDomainsList(googleDomains);
    1594 
    1595     if (otherGoogleDomains.isEmpty())
    1596         initializeOtherGoogleDomains(otherGoogleDomains);
    1597 
    1598     // First check if this is one of the various google.com international domains.
    1599     int position = host.find(".google.");
    1600     if (position > 0 && googleDomains.contains(host.substring(position + sizeof(".google.") - 1)))
    1601         return true;
    1602 
    1603     // Then we check the possibility of it being one of the other, .com-only google domains.
    1604     for (unsigned int i = 0; i < otherGoogleDomains.size(); i++) {
    1605         if (host.endsWith(otherGoogleDomains.at(i)))
    1606             return true;
    1607     }
    1608 
    1609     return false;
    1610 }
    1611 
    1612 static String userAgentForURL(const URL& url)
    1613 {
    1614     // For Google domains, drop the browser's custom User Agent string, and use the
    1615     // standard one, so they don't give us a broken experience.
    1616     if (isGoogleDomain(url.host()))
    1617         return standardUserAgent();
    1618 
    1619     return String();
    1620 }
    1621 
    16221507/*
    16231508 * Private usage only.
     
    16451530 * User-Agent that will be sent for the given URI.
    16461531 */
    1647 char* webkitWebSettingsUserAgentForURI(WebKitWebSettings* webSettings, const char* uri)
     1532char* webkitWebSettingsUserAgentForURI(WebKitWebSettings* webSettings, const WebCore::URL& url)
    16481533{
    1649     if (webSettings->priv->enableSiteSpecificQuirks) {
    1650         String userAgentString = userAgentForURL(WebCore::URL(WebCore::URL(), String::fromUTF8(uri)));
     1534    if (webSettings->priv->enableSiteSpecificQuirks && !url.isNull()) {
     1535        String userAgentString = WebCore::standardUserAgentForURL(url);
    16511536        if (!userAgentString.isEmpty())
    16521537            return g_strdup(userAgentString.utf8().data());
    16531538    }
    1654 
    16551539    return g_strdup(webkit_web_settings_get_user_agent(webSettings));
    16561540}
  • releases/WebKitGTK/webkit-2.4/Source/WebKit/gtk/webkit/webkitwebsettingsprivate.h

    r162644 r170882  
    2424#define webkitwebsettingsprivate_h
    2525
     26#include "URL.h"
    2627#include "webkitwebsettings.h"
    2728#include <wtf/text/CString.h>
     
    9394WEBKIT_API void webkit_web_settings_add_extra_plugin_directory(WebKitWebView*, const gchar* directory);
    9495
    95 WEBKIT_API char* webkitWebSettingsUserAgentForURI(WebKitWebSettings*, const gchar* uri);
     96WEBKIT_API char* webkitWebSettingsUserAgentForURI(WebKitWebSettings*, const WebCore::URL&);
    9697
    9798GSList* webkitWebViewGetEnchantDicts(WebKitWebView*);
  • releases/WebKitGTK/webkit-2.4/Tools/ChangeLog

    r170803 r170882  
     12014-07-04  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        [GTK][Stable] Google Maps doesn't work with Version/X in the user agent
     4        https://bugs.webkit.org/show_bug.cgi?id=134631
     5
     6        Reviewed by Sergio Villar Senin.
     7
     8        Move user agent quirks tests from WebKit1 to WebCore.
     9
     10        * TestWebKitAPI/Tests/WebCore/gtk/UserAgentQuirks.cpp:
     11        (TestWebKitAPI::TEST):
     12        * TestWebKitAPI/Tests/WebKitGtk/testwebsettings.c:
     13        (test_webkit_web_settings_user_agent):
     14
    1152014-02-05  Zan Dobersek  <zdobersek@igalia.com>
    216
  • releases/WebKitGTK/webkit-2.4/Tools/TestWebKitAPI/Tests/WebCore/gtk/UserAgentQuirks.cpp

    r170636 r170882  
    4444    EXPECT_TRUE(uaString.contains("Mac OS X"));
    4545    EXPECT_FALSE(uaString.contains("Linux"));
     46
     47    // For Google domains we always return the standard UA.
     48    uaString = standardUserAgent();
     49    EXPECT_FALSE(uaString.isNull());
     50    EXPECT_TRUE(uaString == standardUserAgentForURL(URL(ParsedURLString, "http://www.google.com/")));
     51    EXPECT_TRUE(uaString == standardUserAgentForURL(URL(ParsedURLString, "http://calendar.google.com/")));
     52    EXPECT_TRUE(uaString == standardUserAgentForURL(URL(ParsedURLString, "http://gmail.com/")));
     53    EXPECT_TRUE(uaString == standardUserAgentForURL(URL(ParsedURLString, "http://www.google.com.br/")));
     54    EXPECT_TRUE(uaString == standardUserAgentForURL(URL(ParsedURLString, "http://www.youtube.com/")));
     55    EXPECT_TRUE(uaString != standardUserAgentForURL(URL(ParsedURLString, "http://www.google.uk.not.com.br/")));
     56
     57    // For Google Maps we remove the Version/8.0 string.
     58    uaString = standardUserAgentForURL(URL(ParsedURLString, "http://maps.google.com/"));
     59    EXPECT_TRUE(uaString == standardUserAgentForURL(URL(ParsedURLString, "http://www.google.com/maps/")));
     60    EXPECT_FALSE(uaString.contains("Version/8.0 Safari/"));
    4661}
    4762
  • releases/WebKitGTK/webkit-2.4/Tools/TestWebKitAPI/Tests/WebKitGtk/testwebsettings.c

    r170009 r170882  
    2222#include <gtk/gtk.h>
    2323#include <webkit/webkit.h>
    24 
    25 /* Private API */
    26 char* webkitWebSettingsUserAgentForURI(WebKitWebSettings *settings, const char *uri);
    2724
    2825static void test_webkit_web_settings_copy(void)
     
    6259}
    6360
    64 static void test_non_quirky_user_agents(WebKitWebSettings *settings, const char *defaultUserAgent)
     61static void test_webkit_web_settings_user_agent(void)
    6562{
     63    WebKitWebSettings *settings;
     64    GtkWidget *webView;
     65    char *defaultUserAgent;
    6666    char *userAgent = 0;
     67    g_test_bug("17375");
     68
     69    webView = webkit_web_view_new();
     70    g_object_ref_sink(webView);
     71
     72    settings = webkit_web_view_get_settings(WEBKIT_WEB_VIEW(webView));
     73    defaultUserAgent = g_strdup(webkit_web_settings_get_user_agent(settings));
     74
     75    g_assert(g_strstr_len(defaultUserAgent, -1, "Version/8.0 Safari/"));
     76    g_assert(g_strstr_len(defaultUserAgent, -1, "Version/8.0") < g_strstr_len(defaultUserAgent, -1, "Safari/"));
    6777
    6878    // test a custom UA string
     
    8595    g_assert_cmpstr(userAgent, ==, defaultUserAgent);
    8696    g_free(userAgent);
    87 }
    88 
    89 static void test_webkit_web_settings_user_agent(void)
    90 {
    91     WebKitWebSettings *settings;
    92     GtkWidget *webView;
    93     char *defaultUserAgent;
    94     char *userAgent = 0;
    95     g_test_bug("17375");
    96 
    97     webView = webkit_web_view_new();
    98     g_object_ref_sink(webView);
    99 
    100     settings = webkit_web_view_get_settings(WEBKIT_WEB_VIEW(webView));
    101     defaultUserAgent = g_strdup(webkit_web_settings_get_user_agent(settings));
    102 
    103     g_assert(g_strstr_len(defaultUserAgent, -1, "Version/8.0 Safari/"));
    104     g_assert(g_strstr_len(defaultUserAgent, -1, "Version/8.0") < g_strstr_len(defaultUserAgent, -1, "Safari/"));
    105 
    106     test_non_quirky_user_agents(settings, defaultUserAgent);
    107 
    108     /* Test quirky google domains */
    109     g_object_set(settings, "user-agent", "testwebsettings/0.1", NULL);
    110 
    111     userAgent = webkitWebSettingsUserAgentForURI(settings, "http://www.google.com/");
    112     g_assert_cmpstr(userAgent, ==, "testwebsettings/0.1");
    113     g_free(userAgent);
    114 
    115     userAgent = webkitWebSettingsUserAgentForURI(settings, "http://gmail.com/");
    116     g_assert_cmpstr(userAgent, ==, "testwebsettings/0.1");
    117     g_free(userAgent);
    118 
    119     userAgent = webkitWebSettingsUserAgentForURI(settings, "http://www.google.com.br/");
    120     g_assert_cmpstr(userAgent, ==, "testwebsettings/0.1");
    121     g_free(userAgent);
    122 
    123     userAgent = webkitWebSettingsUserAgentForURI(settings, "http://calendar.google.com/");
    124     g_assert_cmpstr(userAgent, ==, "testwebsettings/0.1");
    125     g_free(userAgent);
    126 
    127     /* Now enable quirks handling */
    128     g_object_set(settings, "enable-site-specific-quirks", TRUE, NULL);
    129 
    130     test_non_quirky_user_agents(settings, defaultUserAgent);
    131 
    132     g_object_set(settings, "user-agent", "testwebsettings/0.1", NULL);
    133 
    134     userAgent = webkitWebSettingsUserAgentForURI(settings, "http://www.google.com/");
    135     g_assert_cmpstr(userAgent, ==, defaultUserAgent);
    136     g_free(userAgent);
    137 
    138     userAgent = webkitWebSettingsUserAgentForURI(settings, "http://gmail.com/");
    139     g_assert_cmpstr(userAgent, ==, defaultUserAgent);
    140     g_free(userAgent);
    141 
    142     userAgent = webkitWebSettingsUserAgentForURI(settings, "http://www.google.com.br/");
    143     g_assert_cmpstr(userAgent, ==, defaultUserAgent);
    144     g_free(userAgent);
    145 
    146     userAgent = webkitWebSettingsUserAgentForURI(settings, "http://www.google.uk.not.com.br/");
    147     g_assert_cmpstr(userAgent, ==, "testwebsettings/0.1");
    148     g_free(userAgent);
    14997
    15098    g_free(defaultUserAgent);
Note: See TracChangeset for help on using the changeset viewer.