Ejemplo n.º 1
0
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();
}
Ejemplo n.º 2
0
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;
}
Ejemplo n.º 3
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();
}
Ejemplo n.º 4
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. 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.
    if (applicationName.isEmpty())
        return standardUserAgentStatic();

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

    return standardUserAgentStatic() + ' ' + applicationName + '/' + finalApplicationVersion;
}