[SCM] WebKit Debian packaging branch, debian/experimental, updated. upstream/1.3.3-9427-gc2be6fc

kov at webkit.org kov at webkit.org
Wed Dec 22 13:17:58 UTC 2010


The following commit has been merged in the debian/experimental branch:
commit 2b9514d7aafc6c87e327949ddf51f29e7e47726b
Author: kov at webkit.org <kov at webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Fri Sep 10 17:14:44 2010 +0000

    2010-09-10  Gustavo Noronha Silva  <gns at gnome.org>
    
            Reviewed by Martin Robinson.
    
            [GTK] Google sites do not like WebKitGTK+
            https://bugs.webkit.org/show_bug.cgi?id=39617
    
            Special-case Google domains, and spoof User-Agent when talking to
            them, to stop being treated as a second-class citizen.
    
            * WebCoreSupport/FrameLoaderClientGtk.cpp:
            (WebKit::initializeDomainsList):
            (WebKit::isGoogleDomain):
            (WebKit::FrameLoaderClient::userAgent): If enable-site-specific-quirks
            is enabled, send the standard WebKit User-Agent string, disregarding the
            custom one set by the browser for Google domains.
            * webkit/webkitprivate.h:
            * webkit/webkitwebsettings.cpp:
            (webkitPlatform): Fix style, and simplify.
            (webkitOSVersion): Ditto.
            (webkitUserAgent): Add the Version/x.y string Safari has been
            using since Safari 2.2.
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@67211 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebKit/gtk/ChangeLog b/WebKit/gtk/ChangeLog
index ed084f8..ba69650 100644
--- a/WebKit/gtk/ChangeLog
+++ b/WebKit/gtk/ChangeLog
@@ -1,3 +1,26 @@
+2010-09-10  Gustavo Noronha Silva  <gns at gnome.org>
+
+        Reviewed by Martin Robinson.
+
+        [GTK] Google sites do not like WebKitGTK+
+        https://bugs.webkit.org/show_bug.cgi?id=39617
+
+        Special-case Google domains, and spoof User-Agent when talking to
+        them, to stop being treated as a second-class citizen.
+
+        * WebCoreSupport/FrameLoaderClientGtk.cpp:
+        (WebKit::initializeDomainsList):
+        (WebKit::isGoogleDomain):
+        (WebKit::FrameLoaderClient::userAgent): If enable-site-specific-quirks
+        is enabled, send the standard WebKit User-Agent string, disregarding the
+        custom one set by the browser for Google domains.
+        * webkit/webkitprivate.h:
+        * webkit/webkitwebsettings.cpp:
+        (webkitPlatform): Fix style, and simplify.
+        (webkitOSVersion): Ditto.
+        (webkitUserAgent): Add the Version/x.y string Safari has been
+        using since Safari 2.2.
+
 2010-09-10  Xan Lopez  <xlopez at igalia.com>
 
         Reviewed by Martin Robinson.
diff --git a/WebKit/gtk/WebCoreSupport/FrameLoaderClientGtk.cpp b/WebKit/gtk/WebCoreSupport/FrameLoaderClientGtk.cpp
index 4b0da3d..47ffa88 100644
--- a/WebKit/gtk/WebCoreSupport/FrameLoaderClientGtk.cpp
+++ b/WebKit/gtk/WebCoreSupport/FrameLoaderClientGtk.cpp
@@ -49,6 +49,7 @@
 #include "MIMETypeRegistry.h"
 #include "MouseEvent.h"
 #include "NotImplemented.h"
+#include "Page.h"
 #include "PlatformString.h"
 #include "PluginDatabase.h"
 #include "RenderPart.h"
@@ -93,9 +94,115 @@ FrameLoaderClient::~FrameLoaderClient()
         g_object_unref(m_policyDecision);
 }
 
-String FrameLoaderClient::userAgent(const KURL&)
+static void initializeDomainsList(HashSet<String>& googleDomains)
+{
+    // Google search domains.
+    googleDomains.add("biz");
+    googleDomains.add("com");
+    googleDomains.add("net");
+    googleDomains.add("org");
+    googleDomains.add("ae");
+    googleDomains.add("ag");
+    googleDomains.add("am");
+    googleDomains.add("at");
+    googleDomains.add("az");
+    googleDomains.add("be");
+    googleDomains.add("bi");
+    googleDomains.add("ca");
+    googleDomains.add("cc");
+    googleDomains.add("cd");
+    googleDomains.add("cg");
+    googleDomains.add("ch");
+    googleDomains.add("cl");
+    googleDomains.add("com.br");
+    googleDomains.add("co.uk");
+    googleDomains.add("co.jp");
+    googleDomains.add("de");
+    googleDomains.add("dj");
+    googleDomains.add("dk");
+    googleDomains.add("es");
+    googleDomains.add("fi");
+    googleDomains.add("fm");
+    googleDomains.add("fr");
+    googleDomains.add("gg");
+    googleDomains.add("gl");
+    googleDomains.add("gm");
+    googleDomains.add("gs");
+    googleDomains.add("hn");
+    googleDomains.add("hu");
+    googleDomains.add("ie");
+    googleDomains.add("it");
+    googleDomains.add("je");
+    googleDomains.add("kz");
+    googleDomains.add("li");
+    googleDomains.add("lt");
+    googleDomains.add("lu");
+    googleDomains.add("lv");
+    googleDomains.add("ma");
+    googleDomains.add("ms");
+    googleDomains.add("mu");
+    googleDomains.add("mw");
+    googleDomains.add("nl");
+    googleDomains.add("no");
+    googleDomains.add("nu");
+    googleDomains.add("pl");
+    googleDomains.add("pn");
+    googleDomains.add("pt");
+    googleDomains.add("ru");
+    googleDomains.add("rw");
+    googleDomains.add("sh");
+    googleDomains.add("sk");
+    googleDomains.add("sm");
+    googleDomains.add("st");
+    googleDomains.add("td");
+    googleDomains.add("tk");
+    googleDomains.add("tp");
+    googleDomains.add("tv");
+    googleDomains.add("us");
+    googleDomains.add("uz");
+    googleDomains.add("ws");
+}
+
+static bool isGoogleDomain(String host)
+{
+    DEFINE_STATIC_LOCAL(HashSet<String>, googleDomains, ());
+    DEFINE_STATIC_LOCAL(Vector<String>, otherGoogleDomains, ());
+
+    if (googleDomains.isEmpty()) {
+        otherGoogleDomains.append("gmail.com");
+        otherGoogleDomains.append("youtube.com");
+        otherGoogleDomains.append("gstatic.com");
+        otherGoogleDomains.append("ytimg.com");
+
+        initializeDomainsList(googleDomains);
+    }
+
+    // First check if this is one of the various google.com international domains.
+    int position = host.find(".google.");
+    if (position > 0 && googleDomains.contains(host.substring(position + sizeof(".google."))))
+        return true;
+
+    // Then we check the possibility of it being one of the other, .com-only google domains.
+    for (unsigned int i = 0; i < otherGoogleDomains.size(); i++) {
+        if (host.endsWith(otherGoogleDomains.at(i)))
+            return true;
+    }
+
+    return false;
+}
+
+String FrameLoaderClient::userAgent(const KURL& url)
 {
     WebKitWebSettings* settings = webkit_web_view_get_settings(getViewFromFrame(m_frame));
+
+    gboolean useQuirks;
+    g_object_get(settings, "enable-site-specific-quirks", &useQuirks, NULL);
+
+    // For Google domains, drop the browser's custom User Agent string, and use the standard
+    // WebKit/Safari one, so they don't give us a broken experience.
+    if (useQuirks && isGoogleDomain(url.host()))
+        return webkitUserAgent();
+
     return String::fromUTF8(webkit_web_settings_get_user_agent(settings));
 }
 
diff --git a/WebKit/gtk/webkit/webkitprivate.h b/WebKit/gtk/webkit/webkitprivate.h
index bde5b55..0407fbf 100644
--- a/WebKit/gtk/webkit/webkitprivate.h
+++ b/WebKit/gtk/webkit/webkitprivate.h
@@ -59,6 +59,7 @@
 #include "FullscreenVideoController.h"
 #include "Node.h"
 #include "Page.h"
+#include "PlatformString.h"
 #include "ResourceHandle.h"
 #include "ResourceRequest.h"
 #include "ResourceResponse.h"
@@ -206,6 +207,9 @@ extern "C" {
         gboolean disposed;
     };
 
+    WTF::String
+    webkitUserAgent();
+
     void
     webkit_web_frame_core_frame_gone(WebKitWebFrame*);
 
diff --git a/WebKit/gtk/webkit/webkitwebsettings.cpp b/WebKit/gtk/webkit/webkitwebsettings.cpp
index 71a338c..767fce1 100644
--- a/WebKit/gtk/webkit/webkitwebsettings.cpp
+++ b/WebKit/gtk/webkit/webkitwebsettings.cpp
@@ -163,56 +163,62 @@ enum {
 // Create a default user agent string
 // This is a liberal interpretation of http://www.mozilla.org/build/revised-user-agent-strings.html
 // See also http://developer.apple.com/internet/safari/faq.html#anchor2
-static String webkit_get_user_agent()
+static String webkitPlatform()
 {
-    gchar* platform;
-    gchar* osVersion;
-
 #if PLATFORM(X11)
-    platform = g_strdup("X11");
+    DEFINE_STATIC_LOCAL(const String, uaPlatform, (String("X11")));
 #elif OS(WINDOWS)
-    platform = g_strdup("Windows");
+    DEFINE_STATIC_LOCAL(const String, uaPlatform, (String("Windows")));
 #elif PLATFORM(MAC)
-    platform = g_strdup("Macintosh");
+    DEFINE_STATIC_LOCAL(const String, uaPlatform, (String("Macintosh")));
 #elif defined(GDK_WINDOWING_DIRECTFB)
-    platform = g_strdup("DirectFB");
+    DEFINE_STATIC_LOCAL(const String, uaPlatform, (String("DirectFB")));
 #else
-    platform = g_strdup("Unknown");
+    DEFINE_STATIC_LOCAL(const String, uaPlatform, (String("Unknown")));
 #endif
 
+    return uaPlatform;
+}
+
+static String webkitOSVersion()
+{
    // FIXME: platform/version detection can be shared.
 #if OS(DARWIN)
 
 #if CPU(X86)
-    osVersion = g_strdup("Intel Mac OS X");
+    DEFINE_STATIC_LOCAL(const String, uaOSVersion, (String("Intel Mac OS X")));
 #else
-    osVersion = g_strdup("PPC Mac OS X");
+    DEFINE_STATIC_LOCAL(const String, uaOSVersion, (String("PPC Mac OS X")));
 #endif
 
 #elif OS(UNIX)
+    DEFINE_STATIC_LOCAL(String, uaOSVersion, (String()));
+
+    if (!uaOSVersion.isEmpty())
+        return uaOSVersion;
+
     struct utsname name;
     if (uname(&name) != -1)
-        osVersion = g_strdup_printf("%s %s", name.sysname, name.machine);
+        uaOSVersion = String::format("%s %s", name.sysname, name.machine);
     else
-        osVersion = g_strdup("Unknown");
-
+        uaOSVersion = String("Unknown");
 #elif OS(WINDOWS)
-    // FIXME: Compute the Windows version
-    osVersion = g_strdup("Windows");
-
+    DEFINE_STATIC_LOCAL(const String, uaOSVersion, (String("Windows")));
 #else
-    osVersion = g_strdup("Unknown");
+    DEFINE_STATIC_LOCAL(const String, uaOSVersion, (String("Unknown")));
 #endif
 
+    return uaOSVersion;
+}
+
+String webkitUserAgent()
+{
     // We mention Safari since many broken sites check for it (OmniWeb does this too)
     // We re-use the WebKit version, though it doesn't seem to matter much in practice
 
     DEFINE_STATIC_LOCAL(const String, uaVersion, (String::format("%d.%d+", WEBKIT_USER_AGENT_MAJOR_VERSION, WEBKIT_USER_AGENT_MINOR_VERSION)));
-    DEFINE_STATIC_LOCAL(const String, staticUA, (String::format("Mozilla/5.0 (%s; U; %s; %s) AppleWebKit/%s (KHTML, like Gecko) Safari/%s",
-                                                                platform, osVersion, defaultLanguage().utf8().data(), uaVersion.utf8().data(), uaVersion.utf8().data())));
-
-    g_free(osVersion);
-    g_free(platform);
+    DEFINE_STATIC_LOCAL(const String, staticUA, (String::format("Mozilla/5.0 (%s; U; %s; %s) AppleWebKit/%s (KHTML, like Gecko) Version/5.0 Safari/%s",
+                                                                webkitPlatform().utf8().data(), webkitOSVersion().utf8().data(), defaultLanguage().utf8().data(), uaVersion.utf8().data(), uaVersion.utf8().data())));
 
     return staticUA;
 }
@@ -607,7 +613,7 @@ static void webkit_web_settings_class_init(WebKitWebSettingsClass* klass)
                                     g_param_spec_string("user-agent",
                                                         _("User Agent"),
                                                         _("The User-Agent string used by WebKitGtk"),
-                                                        webkit_get_user_agent().utf8().data(),
+                                                        webkitUserAgent().utf8().data(),
                                                         flags));
 
     /**
@@ -1034,7 +1040,7 @@ static void webkit_web_settings_set_property(GObject* object, guint prop_id, con
     case PROP_USER_AGENT:
         g_free(priv->user_agent);
         if (!g_value_get_string(value) || !strlen(g_value_get_string(value)))
-            priv->user_agent = g_strdup(webkit_get_user_agent().utf8().data());
+            priv->user_agent = g_strdup(webkitUserAgent().utf8().data());
         else
             priv->user_agent = g_strdup(g_value_get_string(value));
         break;

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list