1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
|
/*
Copyright (C) 2008, 2009, 2012 Nokia Corporation and/or its subsidiary(-ies)
Copyright (C) 2007 Staikos Computing Services Inc.
Copyright (C) 2007 Apple Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "config.h"
#include "UserAgentQt.h"
#include <QGuiApplication>
#include <wtf/text/CString.h>
#include <wtf/text/WTFString.h>
#if OS(WINDOWS)
#include <SystemInfo.h>
#endif // OS(WINDOWS)
namespace WebCore {
/*!
This function is called when a user agent for HTTP requests is needed.
This implementation returns the following value:
"Mozilla/5.0 (%Platform%%Security%%Subplatform%) AppleWebKit/%WebKitVersion% (KHTML, like Gecko) %AppVersion Safari/%WebKitVersion%"
In this string the following values are replaced the first time the function is called:
\list
\li %Platform% expands to the windowing system followed by "; " if it is not Windows (e.g. "X11; ").
\li %Security% expands to "N; " if SSL is disabled.
\li %Subplatform% expands to the operating system version (e.g. "Windows NT 6.1" or "Intel Mac OS X 10.5").
\li %WebKitVersion% is the version of WebKit the application was compiled against.
\endlist
The following value is replaced each time the funciton is called
\list
\li %AppVersion% expands to QCoreApplication::applicationName()/QCoreApplication::applicationVersion() if they're set; otherwise defaulting to Qt and the current Qt version.
\endlist
*/
String UserAgentQt::standardUserAgent(const String &applicationNameForUserAgent, unsigned int webkitMajorVersion, unsigned int webkitMinorVersion)
{
static QString ua;
if (ua.isNull()) {
ua = QLatin1String("Mozilla/5.0 (%1%2%3) AppleWebKit/%4 (KHTML, like Gecko) %99 Safari/%5");
// Platform.
ua = ua.arg(QLatin1String(
#if OS(MAC_OS_X)
"Macintosh; "
#elif OS(WINDOWS)
""
#else
(QGuiApplication::platformName() == QLatin1String("xcb")) ? "X11; " : "Unknown; "
#endif
));
// Security strength.
QString securityStrength;
#if defined(QT_NO_SSL)
securityStrength = QLatin1String("N; ");
#endif
ua = ua.arg(securityStrength);
// Operating system.
ua = ua.arg(QLatin1String(
#if OS(AIX)
"AIX"
#elif OS(WINDOWS)
windowsVersionForUAString().latin1().data()
#elif OS(MAC_OS_X)
#if CPU(X86) || CPU(X86_64)
"Intel Mac OS X"
#else
"PPC Mac OS X"
#endif
#elif OS(FREEBSD)
"FreeBSD"
#elif OS(HURD)
"GNU Hurd"
#elif OS(LINUX)
#if CPU(X86_64)
"Linux x86_64"
#elif CPU(X86)
"Linux i686"
#else
"Linux"
#endif
#elif OS(NETBSD)
"NetBSD"
#elif OS(OPENBSD)
"OpenBSD"
#elif OS(QNX)
"QNX"
#elif OS(SOLARIS)
"Sun Solaris"
#elif OS(UNIX) // FIXME Looks like all unix variants above are the only cases where OS_UNIX is set.
"UNIX BSD/SYSV system"
#else
"Unknown"
#endif
));
// WebKit version.
QString version = QString::number(webkitMajorVersion) + QLatin1Char('.') + QString::number(webkitMinorVersion);
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);
}
}
|