static String buildUserAgentString(const UserAgentQuirks& quirks)
{
    StringBuilder uaString;
    uaString.appendLiteral("Mozilla/5.0 ");
    uaString.append('(');

    if (quirks.contains(UserAgentQuirks::NeedsMacintoshPlatform))
        uaString.appendLiteral("Macintosh");
    else
        uaString.append(platformForUAString());

    uaString.appendLiteral("; ");

    if (quirks.contains(UserAgentQuirks::NeedsMacintoshPlatform)) {
        uaString.append(cpuDescriptionForUAString());
        uaString.appendLiteral(" Mac OS X");
    } else
        uaString.append(platformVersionForUAString());

    uaString.appendLiteral(") AppleWebKit/");
    uaString.append(versionForUAString());
    // Version/X is mandatory *before* Safari/X to be a valid Safari UA. See
    // https://bugs.webkit.org/show_bug.cgi?id=133403 for details.
    uaString.appendLiteral(" (KHTML, like Gecko) Version/8.0 Safari/");
    uaString.append(versionForUAString());

    return uaString.toString();
}
Beispiel #2
0
static String buildUserAgentString(const UserAgentQuirks& quirks)
{
    StringBuilder uaString;
    uaString.appendLiteral("Mozilla/5.0 ");
    uaString.append('(');

    if (quirks.contains(UserAgentQuirks::NeedsMacintoshPlatform))
        uaString.append(UserAgentQuirks::stringForQuirk(UserAgentQuirks::NeedsMacintoshPlatform));
    else if (quirks.contains(UserAgentQuirks::NeedsLinuxDesktopPlatform))
        uaString.append(UserAgentQuirks::stringForQuirk(UserAgentQuirks::NeedsLinuxDesktopPlatform));
    else {
        uaString.append(platformForUAString());
        uaString.appendLiteral("; ");
        uaString.append(platformVersionForUAString());
    }

    if (quirks.contains(UserAgentQuirks::NeedsFirefoxBrowser)) {
        uaString.appendLiteral("; ");
        uaString.append(UserAgentQuirks::firefoxRevisionString());
        uaString.appendLiteral(") ");
    } else {
        uaString.appendLiteral(") AppleWebKit/");
        uaString.append(versionForUAString());
        uaString.appendLiteral(" (KHTML, like Gecko) ");
    }

    // Note that Chrome UAs advertise *both* Chrome and Safari.
    if (quirks.contains(UserAgentQuirks::NeedsChromeBrowser)) {
        uaString.append(UserAgentQuirks::stringForQuirk(UserAgentQuirks::NeedsChromeBrowser));
        uaString.appendLiteral(" ");
    } else if (quirks.contains(UserAgentQuirks::NeedsFirefoxBrowser)) {
        uaString.append(UserAgentQuirks::stringForQuirk(UserAgentQuirks::NeedsFirefoxBrowser));
        uaString.appendLiteral(" ");
    }

    if (!quirks.contains(UserAgentQuirks::NeedsFirefoxBrowser)) {
        // Version/X is mandatory *before* Safari/X to be a valid Safari UA. See
        // https://bugs.webkit.org/show_bug.cgi?id=133403 for details.
        uaString.appendLiteral("Version/10.0 Safari/");
        uaString.append(versionForUAString());
    }

    return uaString.toString();
}
Beispiel #3
0
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", USER_AGENT_GTK_MAJOR_VERSION, USER_AGENT_GTK_MINOR_VERSION).utf8()));
    DEFINE_STATIC_LOCAL(const String, staticUA, (String::format("Mozilla/5.0 (%s; %s) AppleWebKit/%s (KHTML, like Gecko) "
                        "Chromium/25.0.1349.2 Chrome/25.0.1349.2 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());
}
String standardUserAgent(const String& applicationName, const String& applicationVersion)
{
    const String& version = ASCIILiteral(versionForUAString());
    static NeverDestroyed<String> standardUserAgentString = makeString("Mozilla/5.0 (", platformForUAString(), "; ", platformVersionForUAString(),
        ") AppleWebKit/", version, " (KHTML, like Gecko) Version/8.0 Safari/601.2.7");

    if (applicationName.isEmpty())
        return standardUserAgentString;

    String finalApplicationVersion = applicationVersion;
    if (finalApplicationVersion.isEmpty())
        finalApplicationVersion = ASCIILiteral(versionForUAString());

    return standardUserAgentString + ' ' + applicationName + '/' + finalApplicationVersion;
}