Beispiel #1
0
String WebPageProxy::standardUserAgent(const String& applicationNameForUserAgent)
{
    DEFINE_STATIC_LOCAL(String, osVersion, (windowsVersionForUAString()));
    DEFINE_STATIC_LOCAL(String, webKitVersion, (userVisibleWebKitVersionString()));

    return makeString("Mozilla/5.0 (", osVersion, ") AppleWebKit/", webKitVersion, " (KHTML, like Gecko)", applicationNameForUserAgent.isEmpty() ? "" : " ", applicationNameForUserAgent);
}
static String agentOS()
{
#if OS(DARWIN)
#if CPU(X86)
    return "Intel Mac OS X";
#else
    return "PPC Mac OS X";
#endif
#elif OS(UNIX)
    struct utsname name;
    if (uname(&name) != -1)
        return makeString(name.sysname, ' ', name.machine);
    
    return "Unknown";
#elif OS(WINDOWS)
    return windowsVersionForUAString();
#else
    notImplemented();
    return "Unknown";
#endif
}
/*!
    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)
            ""
#elif HAVE(QT5)
            (QGuiApplication::platformName() == QLatin1String("xcb")) ? "X11; " : "Unknown; "
#elif OS(UNIX)
            "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(
#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);
}