Title: [127889] trunk
Revision
127889
Author
mrobin...@webkit.org
Date
2012-09-07 10:52:07 -0700 (Fri, 07 Sep 2012)

Log Message

[GTK] Move user agent helpers to WebCore
https://bugs.webkit.org/show_bug.cgi?id=95745

Reviewed by Carlos Garcia Campos.

.:

Added an autoconf step for the new user agent shared code header in
WebCore. This is necessary so that we can use the user agent version
based on the information in the configure.ac file.

* configure.ac:

Source/WebCore:

Moved the user agent determination code from WebKit1 to WebCore so that it can
be shared with WebKit2. Also add a method for creating the user agent given
a non-default application name.

* GNUmakefile.list.am: Add new files to the list.
* platform/gtk/UserAgentGtk.cpp: Added.
* platform/gtk/UserAgentGtk.h.in: Added.

Source/WebKit/gtk:

Move the code for determining the user agent to WebCore and have WebKit1
use the new shared code.

* webkit/webkitwebsettings.cpp: Use the WebCore code to determine the user
agent in WebKit1.

Modified Paths

Added Paths

Diff

Modified: trunk/ChangeLog (127888 => 127889)


--- trunk/ChangeLog	2012-09-07 17:49:25 UTC (rev 127888)
+++ trunk/ChangeLog	2012-09-07 17:52:07 UTC (rev 127889)
@@ -1,3 +1,16 @@
+2012-09-07  Martin Robinson  <mrobin...@igalia.com>
+
+        [GTK] Move user agent helpers to WebCore
+        https://bugs.webkit.org/show_bug.cgi?id=95745
+
+        Reviewed by Carlos Garcia Campos.
+
+        Added an autoconf step for the new user agent shared code header in
+        WebCore. This is necessary so that we can use the user agent version
+        based on the information in the configure.ac file.
+
+        * configure.ac:
+
 2012-09-07  Allan Sandfeld Jensen  <allan.jen...@nokia.com>
 
         Simplify hitTestResultAtPoint and nodesFromRect APIs

Modified: trunk/Source/WebCore/ChangeLog (127888 => 127889)


--- trunk/Source/WebCore/ChangeLog	2012-09-07 17:49:25 UTC (rev 127888)
+++ trunk/Source/WebCore/ChangeLog	2012-09-07 17:52:07 UTC (rev 127889)
@@ -1,3 +1,18 @@
+2012-09-07  Martin Robinson  <mrobin...@igalia.com>
+
+        [GTK] Move user agent helpers to WebCore
+        https://bugs.webkit.org/show_bug.cgi?id=95745
+
+        Reviewed by Carlos Garcia Campos.
+
+        Moved the user agent determination code from WebKit1 to WebCore so that it can
+        be shared with WebKit2. Also add a method for creating the user agent given
+        a non-default application name.
+
+        * GNUmakefile.list.am: Add new files to the list.
+        * platform/gtk/UserAgentGtk.cpp: Added.
+        * platform/gtk/UserAgentGtk.h.in: Added.
+
 2012-09-07  Adam Barth  <aba...@webkit.org>
 
         Update bindings results after https://bugs.webkit.org/show_bug.cgi?id=96039

Modified: trunk/Source/WebCore/GNUmakefile.list.am (127888 => 127889)


--- trunk/Source/WebCore/GNUmakefile.list.am	2012-09-07 17:49:25 UTC (rev 127888)
+++ trunk/Source/WebCore/GNUmakefile.list.am	2012-09-07 17:52:07 UTC (rev 127889)
@@ -1145,6 +1145,7 @@
 	DerivedSources/WebCore/MathMLNames.h \
 	DerivedSources/WebCore/SVGElementFactory.cpp \
 	DerivedSources/WebCore/SVGNames.cpp \
+	DerivedSources/WebCore/UserAgentGtk.h \
 	DerivedSources/WebCore/UserAgentStyleSheetsData.cpp \
 	DerivedSources/WebCore/UserAgentStyleSheets.h \
 	DerivedSources/WebCore/WebKitFontFamilyNames.cpp \
@@ -4486,6 +4487,7 @@
 	Source/WebCore/platform/gtk/LoggingGtk.cpp \
 	Source/WebCore/platform/gtk/MIMETypeRegistryGtk.cpp \
 	Source/WebCore/platform/gtk/SharedBufferGtk.cpp \
+	Source/WebCore/platform/gtk/UserAgentGtk.cpp \
 	Source/WebCore/platform/gtk/TemporaryLinkStubs.cpp \
 	Source/WebCore/platform/HostWindow.h \
 	Source/WebCore/platform/KillRing.h \

Added: trunk/Source/WebCore/platform/gtk/UserAgentGtk.cpp (0 => 127889)


--- trunk/Source/WebCore/platform/gtk/UserAgentGtk.cpp	                        (rev 0)
+++ trunk/Source/WebCore/platform/gtk/UserAgentGtk.cpp	2012-09-07 17:52:07 UTC (rev 127889)
@@ -0,0 +1,106 @@
+/*
+ * Copyright (C) 2012 Igalia S.L.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "UserAgentGtk.h"
+
+#include <glib.h>
+
+#if OS(UNIX)
+#include <sys/utsname.h>
+#elif OS(WINDOWS)
+#include "SystemInfo.h"
+#endif
+
+namespace WebCore {
+
+static const char* platformForUAString()
+{
+#if PLATFORM(X11)
+    return "X11";
+#elif OS(WINDOWS)
+    return "";
+#elif PLATFORM(MAC)
+    return "Macintosh";
+#elif defined(GDK_WINDOWING_DIRECTFB)
+    return "DirectFB";
+#else
+    return "Unknown";
+#endif
+}
+
+static String platformVersionForUAString()
+{
+    DEFINE_STATIC_LOCAL(String, uaOSVersion, (String()));
+    if (!uaOSVersion.isEmpty())
+        return uaOSVersion;
+
+#if OS(WINDOWS)
+    uaOSVersion = windowsVersionForUAString();
+#elif OS(DARWIN)
+#if CPU(X86)
+    uaOSVersion = "Intel Mac OS X";
+#else
+    uaOSVersion = "PPC Mac OS X";
+#endif
+#elif OS(UNIX)
+    struct utsname name;
+    if (uname(&name) != -1)
+        uaOSVersion = String::format("%s %s", name.sysname, name.machine);
+    else
+        uaOSVersion = String("Unknown");
+#else
+    uaOSVersion = String("Unknown");
+#endif
+    return uaOSVersion;
+}
+
+String standardUserAgent(const String& applicationName, const String& applicationVersion)
+{
+    // Create a default user agent string with a liberal interpretation of 
+    // https://developer.mozilla.org/en-US/docs/User_Agent_Strings_Reference
+    //
+    // Forming a functional user agent is really difficult. We must mention Safari, because some
+    // sites check for that when detecting WebKit browsers. Additionally some sites assume that
+    // browsers that are "Safari" but not running on OS X are the Safari iOS browser, so we
+    // also claim to be  Chromium. Getting this wrong can cause sites to load the wrong _javascript_,
+    // CSS, or custom fonts. In some cases sites won't load resources at all.
+    DEFINE_STATIC_LOCAL(const CString, uaVersion, (String::format("%i.%i", WEBKIT_USER_AGENT_MAJOR_VERSION, WEBKIT_USER_AGENT_MINOR_VERSION).utf8()));
+    DEFINE_STATIC_LOCAL(const String, staticUA, (String::format("Mozilla/5.0 (%s; %s) AppleWebKit/%s (KHTML, like Gecko) "
+                                                                "Chromium/18.0.1025.168 Chrome/18.0.1025.168 Safari/%s",
+                                                                platformForUAString(), platformVersionForUAString().utf8().data(),
+                                                                uaVersion.data(), uaVersion.data())));
+    if (applicationName.isEmpty())
+        return staticUA;
+
+    String finalApplicationVersion = applicationVersion;
+    if (finalApplicationVersion.isEmpty())
+        finalApplicationVersion = uaVersion.data();
+
+    return String::format("%s %s/%s", staticUA.utf8().data(), applicationName.utf8().data(), finalApplicationVersion.utf8().data());
+}
+
+} // namespace WebCore
+
Property changes on: trunk/Source/WebCore/platform/gtk/UserAgentGtk.cpp
___________________________________________________________________

Added: svn:eol-style

Added: trunk/Source/WebCore/platform/gtk/UserAgentGtk.h.in (0 => 127889)


--- trunk/Source/WebCore/platform/gtk/UserAgentGtk.h.in	                        (rev 0)
+++ trunk/Source/WebCore/platform/gtk/UserAgentGtk.h.in	2012-09-07 17:52:07 UTC (rev 127889)
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2012 Igalia S.L.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef UserAgentGtk_h
+#define UserAgentGtk_h
+
+#include <wtf/text/CString.h>
+#include <wtf/text/WTFString.h>
+
+#define WEBKIT_USER_AGENT_MAJOR_VERSION (@WEBKIT_USER_AGENT_MAJOR_VERSION@)
+#define WEBKIT_USER_AGENT_MINOR_VERSION (@WEBKIT_USER_AGENT_MINOR_VERSION@)
+
+namespace WebCore {
+
+String standardUserAgent(const String& applicationName = "", const String& applicationVersion = "");
+
+}
+
+#endif // UserAgentGtk_h
+

Modified: trunk/Source/WebKit/gtk/ChangeLog (127888 => 127889)


--- trunk/Source/WebKit/gtk/ChangeLog	2012-09-07 17:49:25 UTC (rev 127888)
+++ trunk/Source/WebKit/gtk/ChangeLog	2012-09-07 17:52:07 UTC (rev 127889)
@@ -1,3 +1,16 @@
+2012-09-07  Martin Robinson  <mrobin...@igalia.com>
+
+        [GTK] Move user agent helpers to WebCore
+        https://bugs.webkit.org/show_bug.cgi?id=95745
+
+        Reviewed by Carlos Garcia Campos.
+
+        Move the code for determining the user agent to WebCore and have WebKit1
+        use the new shared code.
+
+        * webkit/webkitwebsettings.cpp: Use the WebCore code to determine the user
+        agent in WebKit1.
+
 2012-09-05  Sam Weinig  <s...@webkit.org>
 
         Part 2 of removing PlatformString.h, remove PlatformString.h

Modified: trunk/Source/WebKit/gtk/webkit/webkitwebsettings.cpp (127888 => 127889)


--- trunk/Source/WebKit/gtk/webkit/webkitwebsettings.cpp	2012-09-07 17:49:25 UTC (rev 127888)
+++ trunk/Source/WebKit/gtk/webkit/webkitwebsettings.cpp	2012-09-07 17:52:07 UTC (rev 127889)
@@ -30,6 +30,7 @@
 #include "FileSystem.h"
 #include "KURL.h"
 #include "PluginDatabase.h"
+#include "UserAgentGtk.h"
 #include "webkitenumtypes.h"
 #include "webkitglobalsprivate.h"
 #include "webkitversion.h"
@@ -39,12 +40,6 @@
 #include <wtf/text/StringConcatenate.h>
 #include <glib/gi18n-lib.h>
 
-#if OS(UNIX)
-#include <sys/utsname.h>
-#elif OS(WINDOWS)
-#include "SystemInfo.h"
-#endif
-
 /**
  * SECTION:webkitwebsettings
  * @short_description: Control the behaviour of a #WebKitWebView
@@ -126,71 +121,6 @@
     PROP_MEDIA_PLAYBACK_ALLOWS_INLINE
 };
 
-// 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 webkitPlatform()
-{
-#if PLATFORM(X11)
-    DEFINE_STATIC_LOCAL(const String, uaPlatform, (ASCIILiteral("X11; ")));
-#elif OS(WINDOWS)
-    DEFINE_STATIC_LOCAL(const String, uaPlatform, (String("")));
-#elif PLATFORM(MAC)
-    DEFINE_STATIC_LOCAL(const String, uaPlatform, (ASCIILiteral("Macintosh; ")));
-#elif defined(GDK_WINDOWING_DIRECTFB)
-    DEFINE_STATIC_LOCAL(const String, uaPlatform, (ASCIILiteral("DirectFB; ")));
-#else
-    DEFINE_STATIC_LOCAL(const String, uaPlatform, (ASCIILiteral("Unknown; ")));
-#endif
-
-    return uaPlatform;
-}
-
-static String webkitOSVersion()
-{
-   // FIXME: platform/version detection can be shared.
-#if OS(DARWIN)
-
-#if CPU(X86)
-    DEFINE_STATIC_LOCAL(const String, uaOSVersion, (ASCIILiteral("Intel Mac OS X")));
-#else
-    DEFINE_STATIC_LOCAL(const String, uaOSVersion, (ASCIILiteral("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)
-        uaOSVersion = makeString(name.sysname, ' ', name.machine);
-    else
-        uaOSVersion = ASCIILiteral("Unknown");
-#elif OS(WINDOWS)
-    DEFINE_STATIC_LOCAL(const String, uaOSVersion, (windowsVersionForUAString()));
-#else
-    DEFINE_STATIC_LOCAL(const String, uaOSVersion, (ASCIILiteral("Unknown")));
-#endif
-
-    return uaOSVersion;
-}
-
-static String chromeUserAgent()
-{
-    // 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
-    // We claim to be Chrome as well, which prevents sites that look for Safari and assume
-    // that since we are not OS X, that we are the mobile version of Safari.
-
-    DEFINE_STATIC_LOCAL(const String, uaVersion, (makeString(String::number(WEBKIT_USER_AGENT_MAJOR_VERSION), '.', String::number(WEBKIT_USER_AGENT_MINOR_VERSION), '+')));
-    DEFINE_STATIC_LOCAL(const String, staticUA, (makeString("Mozilla/5.0 (", webkitPlatform(), webkitOSVersion(), ") AppleWebKit/", uaVersion) +
-                                                 makeString(" (KHTML, like Gecko) Chromium/17.0.963.56 Chrome/17.0.963.56 Safari/", uaVersion)));
-
-    return staticUA;
-}
-
 static void webkit_web_settings_finalize(GObject* object);
 
 static void webkit_web_settings_set_property(GObject* object, guint prop_id, const GValue* value, GParamSpec* pspec);
@@ -1125,7 +1055,7 @@
         break;
     case PROP_USER_AGENT:
         if (!g_value_get_string(value) || !strlen(g_value_get_string(value)))
-            priv->userAgent = chromeUserAgent().utf8();
+            priv->userAgent = standardUserAgent().utf8();
         else
             priv->userAgent = g_value_get_string(value);
         break;
@@ -1559,7 +1489,7 @@
     // For Google domains, drop the browser's custom User Agent string, and use the
     // standard Chrome one, so they don't give us a broken experience.
     if (isGoogleDomain(url.host()))
-        return chromeUserAgent();
+        return standardUserAgent();
 
     return String();
 }

Modified: trunk/configure.ac (127888 => 127889)


--- trunk/configure.ac	2012-09-07 17:49:25 UTC (rev 127888)
+++ trunk/configure.ac	2012-09-07 17:52:07 UTC (rev 127889)
@@ -1287,6 +1287,7 @@
 
 AC_CONFIG_FILES([
 Source/WebKit/gtk/webkit/webkitversion.h
+DerivedSources/WebCore/UserAgentGtk.h:Source/WebCore/platform/gtk/UserAgentGtk.h.in
 ])
 
 AC_CONFIG_FILES([
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to