1 | /* |
2 | * Copyright (C) 2012, 2014, 2016 Igalia S.L. |
3 | * |
4 | * Redistribution and use in source and binary forms, with or without |
5 | * modification, are permitted provided that the following conditions |
6 | * are met: |
7 | * 1. Redistributions of source code must retain the above copyright |
8 | * notice, this list of conditions and the following disclaimer. |
9 | * 2. Redistributions in binary form must reproduce the above copyright |
10 | * notice, this list of conditions and the following disclaimer in the |
11 | * documentation and/or other materials provided with the distribution. |
12 | * |
13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
14 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
17 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
18 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
19 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
20 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
21 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
24 | */ |
25 | |
26 | #include "config.h" |
27 | #include "UserAgentQuirks.h" |
28 | |
29 | #include "PublicSuffix.h" |
30 | #include <wtf/URL.h> |
31 | |
32 | namespace WebCore { |
33 | |
34 | // When editing the quirks in this file, be sure to update |
35 | // Tools/TestWebKitAPI/Tests/WebCore/UserAgentQuirks.cpp. |
36 | |
37 | static bool isGoogle(const URL& url) |
38 | { |
39 | String baseDomain = topPrivatelyControlledDomain(url.host().toString()); |
40 | |
41 | // Our Google UA is *very* complicated to get right. Read |
42 | // https://webkit.org/b/142074 carefully before changing. Test that Earth |
43 | // view is available in Google Maps. Test Google Calendar. Test downloading |
44 | // the Hangouts browser plugin. Test logging out and logging in to a Google |
45 | // account. Change platformVersionForUAString() to return "FreeBSD amd64" |
46 | // and test everything again. |
47 | if (baseDomain.startsWith("google." )) |
48 | return true; |
49 | if (baseDomain == "gstatic.com" ) |
50 | return true; |
51 | if (baseDomain == "googleapis.com" ) |
52 | return true; |
53 | if (baseDomain == "googleusercontent.com" ) |
54 | return true; |
55 | |
56 | return false; |
57 | } |
58 | |
59 | // Be careful with this quirk: it's an invitation for sites to use JavaScript |
60 | // that works in Chrome that WebKit cannot handle. Prefer other quirks instead. |
61 | static bool urlRequiresChromeBrowser(const URL& url) |
62 | { |
63 | String baseDomain = topPrivatelyControlledDomain(url.host().toString()); |
64 | |
65 | // Needed for fonts on many sites to work with WebKit. |
66 | // https://bugs.webkit.org/show_bug.cgi?id=147296 |
67 | if (baseDomain == "typekit.net" || baseDomain == "typekit.com" ) |
68 | return true; |
69 | |
70 | return false; |
71 | } |
72 | |
73 | static bool urlRequiresMacintoshPlatform(const URL& url) |
74 | { |
75 | String domain = url.host().toString(); |
76 | String baseDomain = topPrivatelyControlledDomain(domain); |
77 | |
78 | // At least finance.yahoo.com displays a mobile version with WebKitGTK+'s standard user agent. |
79 | if (baseDomain == "yahoo.com" ) |
80 | return true; |
81 | |
82 | // taobao.com displays a mobile version with WebKitGTK+'s standard user agent. |
83 | if (baseDomain == "taobao.com" ) |
84 | return true; |
85 | |
86 | // web.whatsapp.com completely blocks users with WebKitGTK+'s standard user agent. |
87 | if (baseDomain == "whatsapp.com" ) |
88 | return true; |
89 | |
90 | // paypal.com completely blocks users with WebKitGTK+'s standard user agent. |
91 | if (baseDomain == "paypal.com" ) |
92 | return true; |
93 | |
94 | // chase.com displays a huge "please update your browser" warning with |
95 | // WebKitGTK+'s standard user agent. |
96 | if (baseDomain == "chase.com" ) |
97 | return true; |
98 | |
99 | // Microsoft Outlook Web App forces users with WebKitGTK+'s standard user |
100 | // agent to use the light version. Earlier versions even blocks users from |
101 | // accessing the calendar. |
102 | if (domain == "outlook.live.com" || domain == "mail.ntu.edu.tw" ) |
103 | return true; |
104 | |
105 | // Google Docs shows a scary unsupported browser warning with WebKitGTK+'s |
106 | // standard user agent. |
107 | if (domain == "docs.google.com" ) |
108 | return true; |
109 | |
110 | return false; |
111 | } |
112 | |
113 | static bool urlRequiresLinuxDesktopPlatform(const URL& url) |
114 | { |
115 | // docs.google.com requires the macOS platform quirk. |
116 | return isGoogle(url) && url.host() != "docs.google.com" ; |
117 | } |
118 | |
119 | UserAgentQuirks UserAgentQuirks::quirksForURL(const URL& url) |
120 | { |
121 | ASSERT(!url.isNull()); |
122 | |
123 | UserAgentQuirks quirks; |
124 | |
125 | if (urlRequiresChromeBrowser(url)) |
126 | quirks.add(UserAgentQuirks::NeedsChromeBrowser); |
127 | |
128 | if (urlRequiresMacintoshPlatform(url)) |
129 | quirks.add(UserAgentQuirks::NeedsMacintoshPlatform); |
130 | else if (urlRequiresLinuxDesktopPlatform(url)) |
131 | quirks.add(UserAgentQuirks::NeedsLinuxDesktopPlatform); |
132 | |
133 | return quirks; |
134 | } |
135 | |
136 | String UserAgentQuirks::stringForQuirk(UserAgentQuirk quirk) |
137 | { |
138 | switch (quirk) { |
139 | case NeedsChromeBrowser: |
140 | // Get versions from https://chromium.googlesource.com/chromium/src.git |
141 | return "Chrome/58.0.3029.81"_s ; |
142 | case NeedsMacintoshPlatform: |
143 | return "Macintosh; Intel Mac OS X 10_13_4"_s ; |
144 | case NeedsLinuxDesktopPlatform: |
145 | return "X11; Linux x86_64"_s ; |
146 | case NumUserAgentQuirks: |
147 | default: |
148 | ASSERT_NOT_REACHED(); |
149 | } |
150 | return ""_s ; |
151 | } |
152 | |
153 | } |
154 | |