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 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215
|
/*
* Copyright (C) 2012, 2014, 2016 Igalia S.L.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
#include "UserAgentQuirks.h"
#include "PublicSuffixStore.h"
#include <wtf/URL.h>
#include <wtf/glib/ChassisType.h>
namespace WebCore {
// When editing the quirks in this file, be sure to update
// Tools/TestWebKitAPI/Tests/WebCore/UserAgentQuirks.cpp.
//
// When testing changes, be sure to test with application branding enabled.
// Otherwise, we will not notice when urlRequiresUnbrandedUserAgent is needed.
// Be careful with this quirk: it's an invitation for sites to use JavaScript
// that works in Chrome that WebKit cannot handle. Prefer other quirks instead.
static bool urlRequiresChromeBrowser(const String& domain, const String& baseDomain)
{
// Needed for fonts on many sites to work with WebKit.
// https://bugs.webkit.org/show_bug.cgi?id=147296
if (baseDomain == "typekit.net"_s || baseDomain == "typekit.com"_s)
return true;
// This site completely blocks the login page with WebKitGTK's standard user
// agent and ask users to use Google Chrome or Microsoft Internet Explorer.
if (domain == "auth.mayohr.com"_s)
return true;
// Bank of America shows an unsupported browser warning with WebKitGTK's
// standard user agent.
if (baseDomain == "bankofamerica.com"_s)
return true;
// Google Docs shows an unsupported browser warning with WebKitGTK's
// standard user agent.
if (domain == "docs.google.com"_s)
return true;
// soundcloud.com serves broken MSE audio fragments with WebKitGTK's standard user agent.
if (baseDomain == "soundcloud.com"_s)
return true;
// https://webcompat.com/issues/123672
if (domain == "www.apple.com"_s)
return true;
return false;
}
// Prefer using the macOS platform quirk rather than the Firefox quirk. This
// quirk is good for websites that do macOS-specific things we don't want on
// other platforms, and when the risk of the website doing Firefox-specific
// things is relatively low.
static bool urlRequiresFirefoxBrowser(const String& domain)
{
// Red Hat Bugzilla displays a warning page when performing searches with WebKitGTK's standard
// user agent.
if (domain == "bugzilla.redhat.com"_s)
return true;
// www.bilibili.com uses "NativePlayer" which only supports 720P with
// WebKitGTK's standard user agent.
if (domain == "www.bilibili.com"_s)
return true;
#if ENABLE(THUNDER)
if (domain == "www.netflix.com"_s)
return true;
#endif
return false;
}
static bool urlRequiresMacintoshPlatform(const String& domain, const String& baseDomain)
{
// At least finance.yahoo.com displays a mobile version with WebKitGTK's standard user agent.
if (chassisType() != WTF::ChassisType::Mobile && baseDomain == "yahoo.com"_s)
return true;
// taobao.com displays a mobile version with WebKitGTK's standard user agent.
if (chassisType() != WTF::ChassisType::Mobile && baseDomain == "taobao.com"_s)
return true;
// web.whatsapp.com completely blocks users with WebKitGTK's standard user agent.
if (baseDomain == "whatsapp.com"_s)
return true;
// paypal.com completely blocks users with WebKitGTK's standard user agent.
if (baseDomain == "paypal.com"_s)
return true;
// chase.com displays a huge "please update your browser" warning with
// WebKitGTK's standard user agent.
if (baseDomain == "chase.com"_s)
return true;
// Microsoft Outlook Web App forces users with WebKitGTK's standard user
// agent to use the light version. Earlier versions even block users from
// accessing the calendar.
if (domain == "outlook.office.com"_s
|| domain == "outlook.office365.com"_s
|| domain == "mail.ntu.edu.tw"_s
|| domain == "exchange.tu-berlin.de"_s)
return true;
// https://www.sspa.juntadeandalucia.es/servicioandaluzdesalud/clicsalud/pages/portada.jsf
// Andalusian Health Service discriminates against WebKitGTK's standard user
// agent with an unsupported browser warning.
if (domain == "www.sspa.juntadeandalucia.es"_s)
return true;
// Atlassian Confluence discriminates against WebKitGTK's standard user agent
// by completely blocking access to the application. It runs on different
// subdomains for each Atlassian customer so the quirk must apply broadly.
if (baseDomain == "atlassian.net"_s)
return true;
// Rosetta Stone discriminates against WebKitGTK's standard mobile user agent
// by redirecting to an intent:// URL, which will of course fail to load.
if (domain == "totale.rosettastone.com"_s)
return true;
// DuckDuckGo discriminates against WebKitGTK's standard user agent by
// returning an HTTP 400 Bad Request error when loading every search result.
if (domain == "duckduckgo.com"_s)
return true;
return false;
}
static bool urlRequiresUnbrandedUserAgent(const String& domain)
{
// Google uses an ugly fallback login page if application branding is
// appended to WebKitGTK's standard user agent.
if (domain == "accounts.google.com"_s)
return true;
// Google Docs displays an unsupported browser warning if application
// branding is appended to WebKitGTK's standard user agent.
if (domain == "docs.google.com"_s)
return true;
// Google Drive displays an unsupported browser warning if application
// branding is appended to WebKitGTK's standard user agent.
if (domain == "drive.google.com"_s)
return true;
return false;
}
UserAgentQuirks UserAgentQuirks::quirksForURL(const URL& url)
{
ASSERT(!url.isNull());
String domain = url.host().toString();
UserAgentQuirks quirks;
String baseDomain = PublicSuffixStore::singleton().topPrivatelyControlledDomain(domain);
if (urlRequiresChromeBrowser(domain, baseDomain))
quirks.add(UserAgentQuirks::NeedsChromeBrowser);
else if (urlRequiresFirefoxBrowser(domain))
quirks.add(UserAgentQuirks::NeedsFirefoxBrowser);
if (urlRequiresMacintoshPlatform(domain, baseDomain))
quirks.add(UserAgentQuirks::NeedsMacintoshPlatform);
if (urlRequiresUnbrandedUserAgent(domain))
quirks.add(UserAgentQuirks::NeedsUnbrandedUserAgent);
return quirks;
}
String UserAgentQuirks::stringForQuirk(UserAgentQuirk quirk)
{
switch (quirk) {
case NeedsChromeBrowser:
return "Chrome/300.0.0.0"_s;
case NeedsFirefoxBrowser:
return "; rv:300.0) Gecko/20100101 Firefox/300.0"_s;
case NeedsMacintoshPlatform:
return "Macintosh; Intel Mac OS X 10_15"_s;
case NeedsUnbrandedUserAgent:
case NumUserAgentQuirks:
ASSERT_NOT_REACHED();
}
return ""_s;
}
}
|