Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[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.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@127889 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information...
commit b68ce80f656ad96bf3847024e19fadf73d088081 1 parent bbbd06c
@mrobinson mrobinson authored
View
13 ChangeLog
@@ -1,3 +1,16 @@
+2012-09-07 Martin Robinson <mrobinson@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.jensen@nokia.com>
Simplify hitTestResultAtPoint and nodesFromRect APIs
View
15 Source/WebCore/ChangeLog
@@ -1,3 +1,18 @@
+2012-09-07 Martin Robinson <mrobinson@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 <abarth@webkit.org>
Update bindings results after https://bugs.webkit.org/show_bug.cgi?id=96039
View
2  Source/WebCore/GNUmakefile.list.am
@@ -1145,6 +1145,7 @@ webcore_built_sources += \
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 @@ webcore_sources += \
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 \
View
106 Source/WebCore/platform/gtk/UserAgentGtk.cpp
@@ -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
+
View
42 Source/WebCore/platform/gtk/UserAgentGtk.h.in
@@ -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
+
View
13 Source/WebKit/gtk/ChangeLog
@@ -1,3 +1,16 @@
+2012-09-07 Martin Robinson <mrobinson@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 <sam@webkit.org>
Part 2 of removing PlatformString.h, remove PlatformString.h
View
76 Source/WebKit/gtk/webkit/webkitwebsettings.cpp
@@ -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 @@ enum {
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 @@ static void webkit_web_settings_set_property(GObject* object, guint prop_id, con
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 @@ static String userAgentForURL(const KURL& url)
// 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();
}
View
1  configure.ac
@@ -1287,6 +1287,7 @@ GNUmakefile
AC_CONFIG_FILES([
Source/WebKit/gtk/webkit/webkitversion.h
+DerivedSources/WebCore/UserAgentGtk.h:Source/WebCore/platform/gtk/UserAgentGtk.h.in
])
AC_CONFIG_FILES([
Please sign in to comment.
Something went wrong with that request. Please try again.