Esempio 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();
}
Esempio n. 2
0
UserAgentQuirks UserAgentQuirks::quirksForURL(const URL& url)
{
    ASSERT(!url.isNull());
    UserAgentQuirks quirks;
    if (urlRequiresChromeBrowser(url))
        quirks.add(UserAgentQuirks::NeedsChromeBrowser);
    if (urlRequiresMacintoshPlatform(url))
        quirks.add(UserAgentQuirks::NeedsMacintoshPlatform);
    return quirks;
}
Esempio n. 3
0
String standardUserAgentForURL(const URL& url)
{
    ASSERT(!url.isNull());
    UserAgentQuirks quirks;
    if (url.host().endsWith(".yahoo.com")) {
        // www.yahoo.com redirects to the mobile version when Linux is present in the UA,
        // use always Macintosh as platform. See https://bugs.webkit.org/show_bug.cgi?id=125444.
        quirks.add(UserAgentQuirks::NeedsMacintoshPlatform);
    }

    // The null string means we don't need a specific UA for the given URL.
    return quirks.isEmpty() ? String() : buildUserAgentString(quirks);
}
Esempio n. 4
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();
}