Skip to content

Instantly share code, notes, and snippets.

@lauromoura
Created April 3, 2012 20:01
Show Gist options
  • Save lauromoura/2295156 to your computer and use it in GitHub Desktop.
Save lauromoura/2295156 to your computer and use it in GitHub Desktop.
User agent patch
diff --git a/Source/WebKit2/UIProcess/qt/WebPageProxyQt.cpp b/Source/WebKit2/UIProcess/qt/WebPageProxyQt.cpp
index ac9fde418b0c42f9f4dec87a330b1a9e1a4e5f14..8667a2f401025ce140d62694332ac9850018057f 100644
--- a/Source/WebKit2/UIProcess/qt/WebPageProxyQt.cpp
+++ b/Source/WebKit2/UIProcess/qt/WebPageProxyQt.cpp
@@ -32,8 +32,14 @@
#include "qquicknetworkreply_p.h"
#include "WebPageMessages.h"
#include "WebProcessProxy.h"
+#include <QtCore/QCoreApplication>
#include <WebCore/Editor.h>
#include <WebCore/NotImplemented.h>
+#if defined Q_OS_WIN32
+#include <WebCore/SystemInfo.h>
+#endif // Q_OS_WIN32
+#include <WebKitVersion.h>
+
using namespace WebCore;
@@ -41,8 +47,138 @@ namespace WebKit {
String WebPageProxy::standardUserAgent(const String& applicationNameForUserAgent)
{
- // FIXME: This should not be hard coded.
- return "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6) AppleWebKit/531.4 (KHTML, like Gecko) Version/4.0.3 Safari/531.4";
+ static QString ua;
+
+ if (ua.isNull()) {
+ // Static fields.
+ // %1 Platform.
+ // %2 Security strength.
+ // %3 Operating system.
+ // %4 WebKit version
+ // %5 WebKit version (front end)
+ // Runtime-defined fields
+ // %99 Application name/version
+ ua = QLatin1String("Mozilla/5.0 (%1%2%3) AppleWebKit/%4 (KHTML, like Gecko) %99 Safari/%5");
+
+ // Platform.
+ ua = ua.arg(QLatin1String(
+#ifdef Q_WS_MAC
+ "Macintosh; "
+#elif defined Q_WS_QWS
+ "QtEmbedded; "
+#elif defined Q_WS_WIN
+ // Nothing.
+#elif defined Q_WS_X11
+ "X11; "
+#else
+ "Unknown; "
+#endif
+ ));
+
+ // Security strength.
+ QString securityStrength;
+#if defined(QT_NO_OPENSSL)
+ securityStrength = QLatin1String("N; ");
+#endif
+ ua = ua.arg(securityStrength);
+
+ // Operating system.
+ ua = ua.arg(QLatin1String(
+#ifdef Q_OS_AIX
+ "AIX"
+#elif defined Q_OS_WIN32
+ windowsVersionForUAString()
+#elif defined Q_OS_DARWIN
+#ifdef __i386__ || __x86_64__
+ "Intel Mac OS X"
+#else
+ "PPC Mac OS X"
+#endif
+
+#elif defined Q_OS_BSDI
+ "BSD"
+#elif defined Q_OS_BSD4
+ "BSD Four"
+#elif defined Q_OS_CYGWIN
+ "Cygwin"
+#elif defined Q_OS_DGUX
+ "DG/UX"
+#elif defined Q_OS_DYNIX
+ "DYNIX/ptx"
+#elif defined Q_OS_FREEBSD
+ "FreeBSD"
+#elif defined Q_OS_HPUX
+ "HP-UX"
+#elif defined Q_OS_HURD
+ "GNU Hurd"
+#elif defined Q_OS_IRIX
+ "SGI Irix"
+#elif defined Q_OS_LINUX
+
+#if defined(__x86_64__)
+ "Linux x86_64"
+#elif defined(__i386__)
+ "Linux i686"
+#else
+ "Linux"
+#endif
+
+#elif defined Q_OS_LYNX
+ "LynxOS"
+#elif defined Q_OS_NETBSD
+ "NetBSD"
+#elif defined Q_OS_OS2
+ "OS/2"
+#elif defined Q_OS_OPENBSD
+ "OpenBSD"
+#elif defined Q_OS_OS2EMX
+ "OS/2"
+#elif defined Q_OS_OSF
+ "HP Tru64 UNIX"
+#elif defined Q_OS_QNX6
+ "QNX RTP Six"
+#elif defined Q_OS_QNX
+ "QNX"
+#elif defined Q_OS_RELIANT
+ "Reliant UNIX"
+#elif defined Q_OS_SCO
+ "SCO OpenServer"
+#elif defined Q_OS_SOLARIS
+ "Sun Solaris"
+#elif defined Q_OS_ULTRIX
+ "DEC Ultrix"
+#elif defined Q_OS_UNIX
+ "UNIX BSD/SYSV system"
+#elif defined Q_OS_UNIXWARE
+ "UnixWare Seven, Open UNIX Eight"
+#else
+ "Unknown"
+#endif
+ ));
+
+ // WebKit version.
+ // FIXME: macros from WebKit1.
+ QString version = QString(QLatin1String("%1.%2+")).arg(QString::number(WEBKIT_MAJOR_VERSION),
+ QString::number(WEBKIT_MINOR_VERSION));
+ ua = ua.arg(version, version);
+ }
+
+ QString appName;
+ if (applicationNameForUserAgent.isEmpty())
+ appName = QCoreApplication::applicationName();
+ else
+ appName = applicationNameForUserAgent;
+
+ if (!appName.isEmpty()) {
+ QString appVer = QCoreApplication::applicationVersion();
+ if (!appVer.isEmpty())
+ appName.append(QLatin1Char('/') + appVer);
+ } else {
+ // Qt version.
+ appName = QLatin1String("Qt/") + QLatin1String(qVersion());
+ }
+
+ return ua.arg(appName);
}
void WebPageProxy::saveRecentSearches(const String&, const Vector<String>&)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment