Changeset 169799 in webkit
- Timestamp:
- Jun 11, 2014, 12:38:35 AM (11 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r169797 r169799 1 2014-06-11 Carlos Garcia Campos <cgarcia@igalia.com> 2 3 [GTK] Use a different user agent string depending on the site 4 https://bugs.webkit.org/show_bug.cgi?id=132681 5 6 Reviewed by Anders Carlsson. 7 8 We have changed the user agent string several times to try to fix 9 broken websites that require specific things in the UA string to 10 properly work. But everytime we change the UA string to fix a 11 website we break others. We could use different UA string 12 depending on the website. UserAgentGtk code has also been cleaned 13 up, using NeverDestroyed instead of DEPRECATED_DEFINE_STATIC_LOCAL 14 and avoiding unneeded conversions to UTF-8. 15 16 * platform/gtk/UserAgentGtk.cpp: 17 (WebCore::UserAgentQuirks::UserAgentQuirks): New helper private 18 class to handle user agent quirks. 19 (WebCore::UserAgentQuirks::add): 20 (WebCore::UserAgentQuirks::contains): 21 (WebCore::UserAgentQuirks::isEmpty): 22 (WebCore::platformForUAString): Bring back this method that was 23 removed to always pretend to be Macintosh. 24 (WebCore::platformVersionForUAString): Return a different platform 25 version depending on the actual platform. 26 (WebCore::versionForUAString): Return the WebKit version. 27 (WebCore::buildUserAgentString): Helper function to build the user 28 agent taking into account the UserAgentQuirks received. 29 (WebCore::standardUserAgentStatic): Standard user agent string 30 when no quirks are present. 31 (WebCore::standardUserAgent): 32 (WebCore::standardUserAgentForURL): New method that returns the 33 user agent string for the given URL. 34 * platform/gtk/UserAgentGtk.h: 35 1 36 2014-06-11 Alex Christensen <achristensen@webkit.org> 2 37 -
trunk/Source/WebCore/platform/gtk/UserAgentGtk.cpp
r166405 r169799 1 1 /* 2 * Copyright (C) 2012 Igalia S.L.2 * Copyright (C) 2012, 2014 Igalia S.L. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 27 27 #include "UserAgentGtk.h" 28 28 29 #include <glib.h> 29 #include "URL.h" 30 #include <wtf/NeverDestroyed.h> 31 #include <wtf/text/StringBuilder.h> 30 32 31 33 #if OS(UNIX) … … 34 36 35 37 namespace WebCore { 38 39 class UserAgentQuirks { 40 public: 41 enum UserAgentQuirk { 42 NeedsSafariVersion6, 43 NeedsMacintoshPlatform, 44 45 NumUserAgentQuirks 46 }; 47 48 UserAgentQuirks() 49 : m_quirks(0) 50 { 51 COMPILE_ASSERT(sizeof(m_quirks) * 8 >= NumUserAgentQuirks, not_enough_room_for_quirks); 52 } 53 54 void add(UserAgentQuirk quirk) 55 { 56 ASSERT(quirk >= 0); 57 ASSERT_WITH_SECURITY_IMPLICATION(quirk < NumUserAgentQuirks); 58 59 m_quirks |= (1 << quirk); 60 } 61 62 bool contains(UserAgentQuirk quirk) const 63 { 64 return m_quirks & (1 << quirk); 65 } 66 67 bool isEmpty() const { return !m_quirks; } 68 69 private: 70 uint32_t m_quirks; 71 }; 36 72 37 73 static const char* cpuDescriptionForUAString() … … 48 84 } 49 85 50 static String platformVersionForUAString()86 static const char* platformForUAString() 51 87 { 52 DEPRECATED_DEFINE_STATIC_LOCAL(String, uaOSVersion, (String())); 53 if (!uaOSVersion.isEmpty()) 54 return uaOSVersion; 88 #if PLATFORM(X11) 89 return "X11"; 90 #elif OS(WINDOWS) 91 return ""; 92 #elif PLATFORM(MAC) 93 return "Macintosh"; 94 #elif defined(GDK_WINDOWING_DIRECTFB) 95 return "DirectFB"; 96 #else 97 return "Unknown"; 98 #endif 99 } 55 100 56 // We will always claim to be Safari in Mac OS X, since Safari in Linux triggers the iOS path on 57 // some websites. 58 uaOSVersion = String::format("%s Mac OS X", cpuDescriptionForUAString()); 101 static const String platformVersionForUAString() 102 { 103 #if OS(UNIX) 104 struct utsname name; 105 uname(&name); 106 static NeverDestroyed<const String> uaOSVersion(String::format("%s %s", name.sysname, name.machine)); 59 107 return uaOSVersion; 108 #else 109 // We will always claim to be Safari in Mac OS X, since Safari in Linux triggers the iOS path on some websites. 110 static NeverDestroyed<const String> uaOSVersion(String::format("%s Mac OS X", cpuDescriptionForUAString())); 111 return uaOSVersion; 112 #endif 113 } 114 115 static const String versionForUAString() 116 { 117 static NeverDestroyed<const String> uaVersion(String::format("%i.%i", USER_AGENT_GTK_MAJOR_VERSION, USER_AGENT_GTK_MINOR_VERSION)); 118 return uaVersion; 119 } 120 121 static String buildUserAgentString(const UserAgentQuirks& quirks) 122 { 123 StringBuilder uaString; 124 uaString.appendLiteral("Mozilla/5.0 "); 125 uaString.append('('); 126 127 if (quirks.contains(UserAgentQuirks::NeedsMacintoshPlatform)) 128 uaString.appendLiteral("Macintosh"); 129 else 130 uaString.append(platformForUAString()); 131 132 uaString.appendLiteral("; "); 133 134 if (quirks.contains(UserAgentQuirks::NeedsMacintoshPlatform)) { 135 uaString.append(cpuDescriptionForUAString()); 136 uaString.appendLiteral(" Mac OS X"); 137 } else 138 uaString.append(platformVersionForUAString()); 139 140 uaString.appendLiteral(") AppleWebKit/"); 141 uaString.append(versionForUAString()); 142 uaString.appendLiteral(" (KHTML, like Gecko) Safari/"); 143 uaString.append(versionForUAString()); 144 145 if (quirks.contains(UserAgentQuirks::NeedsSafariVersion6)) 146 uaString.appendLiteral(" Version/6.0"); 147 148 return uaString.toString(); 149 } 150 151 static const String standardUserAgentStatic() 152 { 153 static NeverDestroyed<const String> uaStatic(buildUserAgentString(UserAgentQuirks())); 154 return uaStatic; 60 155 } 61 156 … … 70 165 // wrong can cause sites to load the wrong JavaScript, CSS, or custom fonts. In some cases 71 166 // sites won't load resources at all. 72 DEPRECATED_DEFINE_STATIC_LOCAL(const CString, uaVersion, (String::format("%i.%i", USER_AGENT_GTK_MAJOR_VERSION, USER_AGENT_GTK_MINOR_VERSION).utf8()));73 DEPRECATED_DEFINE_STATIC_LOCAL(const String, staticUA, (String::format("Mozilla/5.0 (Macintosh; %s) AppleWebKit/%s (KHTML, like Gecko) Safari/%s Version/6.0",74 platformVersionForUAString().utf8().data(), uaVersion.data(), uaVersion.data())));75 76 167 if (applicationName.isEmpty()) 77 return sta ticUA;168 return standardUserAgentStatic(); 78 169 79 170 String finalApplicationVersion = applicationVersion; 80 171 if (finalApplicationVersion.isEmpty()) 81 finalApplicationVersion = uaVersion.data();172 finalApplicationVersion = versionForUAString(); 82 173 83 return String::format("%s %s/%s", staticUA.utf8().data(), applicationName.utf8().data(), finalApplicationVersion.utf8().data()); 174 return standardUserAgentStatic() + applicationName + '/' + finalApplicationVersion; 175 } 176 177 String standardUserAgentForURL(const URL& url) 178 { 179 ASSERT(!url.isNull()); 180 UserAgentQuirks quirks; 181 if (url.host().endsWith(".yahoo.com")) { 182 // www.yahoo.com redirects to the mobile version when Linux is present in the UA, 183 // use always Macintosh as platform. See https://bugs.webkit.org/show_bug.cgi?id=125444. 184 quirks.add(UserAgentQuirks::NeedsMacintoshPlatform); 185 } else if (url.host().endsWith(".globalforestwatch.org")) { 186 // www.globalforestwatch.org fails to redirect when Safari Version 6 is not present in the UA. 187 // See https://bugs.webkit.org/show_bug.cgi?id=129681. 188 quirks.add(UserAgentQuirks::NeedsSafariVersion6); 189 } 190 191 // The null string means we don't need a specific UA for the given URL. 192 return quirks.isEmpty() ? String() : buildUserAgentString(quirks); 84 193 } 85 194 -
trunk/Source/WebCore/platform/gtk/UserAgentGtk.h
r165676 r169799 1 1 /* 2 * Copyright (C) 2012 Igalia S.L.2 * Copyright (C) 2012, 2014 Igalia S.L. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 27 27 #define UserAgentGtk_h 28 28 29 #include <wtf/text/CString.h>30 29 #include <wtf/text/WTFString.h> 31 30 32 31 namespace WebCore { 32 class URL; 33 33 34 String standardUserAgent(const String& applicationName = "", const String& applicationVersion = ""); 34 String standardUserAgent(const String& applicationName = emptyString(), const String& applicationVersion = emptyString()); 35 String standardUserAgentForURL(const URL&); 35 36 36 37 } -
trunk/Source/WebKit2/ChangeLog
r169791 r169799 1 2014-06-11 Carlos Garcia Campos <cgarcia@igalia.com> 2 3 [GTK] Use a different user agent string depending on the site 4 https://bugs.webkit.org/show_bug.cgi?id=132681 5 6 Reviewed by Anders Carlsson. 7 8 * UIProcess/API/gtk/WebKitSettings.cpp: 9 (webkit_settings_class_init): Enable site specific quirks setting 10 by default. 11 * WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp: 12 (WebKit::WebFrameLoaderClient::userAgent): Pass the given URL to WebPage. 13 * WebProcess/WebPage/WebPage.cpp: 14 (WebKit::WebPage::userAgent): Try to get the user agent for the 15 URL received falling back to the current one otherwise. 16 * WebProcess/WebPage/WebPage.h: 17 (WebKit::WebPage::platformUserAgent): Added. 18 * WebProcess/WebPage/efl/WebPageEfl.cpp: 19 (WebKit::WebPage::platformUserAgent): Return null String. 20 * WebProcess/WebPage/gtk/WebPageGtk.cpp: 21 (WebKit::WebPage::platformUserAgent): Use WebCore::standardUserAgentForURL() when site specific quirks 22 setting is enabled. 23 * WebProcess/WebPage/ios/WebPageIOS.mm: 24 (WebKit::WebPage::platformUserAgent): Return null String. 25 * WebProcess/WebPage/mac/WebPageMac.mm: 26 (WebKit::WebPage::platformUserAgent): Return null String. 27 1 28 2014-06-10 Benjamin Poulain <benjamin@webkit.org> 2 29 -
trunk/Source/WebKit2/UIProcess/API/gtk/WebKitSettings.cpp
r168988 r169799 1057 1057 * special-case this and other cases to make some specific sites work. 1058 1058 */ 1059 g_object_class_install_property(gObjectClass, 1060 PROP_ENABLE_SITE_SPECIFIC_QUIRKS, 1061 g_param_spec_boolean("enable-site-specific-quirks", 1062 _("Enable Site Specific Quirks"), 1063 _("Enables the site-specific compatibility workarounds"), 1064 FALSE, 1065 readWriteConstructParamFlags)); 1059 g_object_class_install_property( 1060 gObjectClass, 1061 PROP_ENABLE_SITE_SPECIFIC_QUIRKS, 1062 g_param_spec_boolean( 1063 "enable-site-specific-quirks", 1064 _("Enable Site Specific Quirks"), 1065 _("Enables the site-specific compatibility workarounds"), 1066 TRUE, 1067 readWriteConstructParamFlags)); 1066 1068 1067 1069 /** -
trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp
r169603 r169799 1182 1182 } 1183 1183 1184 String WebFrameLoaderClient::userAgent(const URL& )1184 String WebFrameLoaderClient::userAgent(const URL& url) 1185 1185 { 1186 1186 WebPage* webPage = m_frame->page(); … … 1188 1188 return String(); 1189 1189 1190 return webPage->userAgent( );1190 return webPage->userAgent(url); 1191 1191 } 1192 1192 -
trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp
r169728 r169799 2285 2285 } 2286 2286 2287 String WebPage::userAgent(const URL& url) const 2288 { 2289 String userAgent = platformUserAgent(url); 2290 if (!userAgent.isEmpty()) 2291 return userAgent; 2292 2293 return m_userAgent; 2294 } 2295 2287 2296 void WebPage::suspendActiveDOMObjectsAndAnimations() 2288 2297 { -
trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h
r169696 r169799 129 129 class SubstituteData; 130 130 class TextCheckingRequest; 131 class URL; 131 132 class VisibleSelection; 132 133 struct KeypressCommand; … … 253 254 void didFinishLoad(WebFrame*); 254 255 void show(); 255 String userAgent() const { return m_userAgent; } 256 String userAgent(const WebCore::URL&) const; 257 String platformUserAgent(const WebCore::URL&) const; 256 258 WebCore::IntRect windowResizerRect() const; 257 259 WebCore::KeyboardUIMode keyboardUIMode(); -
trunk/Source/WebKit2/WebProcess/WebPage/efl/WebPageEfl.cpp
r162756 r169799 221 221 } 222 222 223 String WebPage::platformUserAgent(const URL&) const 224 { 225 return String(); 226 } 227 223 228 } // namespace WebKit -
trunk/Source/WebKit2/WebProcess/WebPage/gtk/WebPageGtk.cpp
r162754 r169799 43 43 #include <WebCore/PlatformKeyboardEvent.h> 44 44 #include <WebCore/Settings.h> 45 #include <WebCore/UserAgentGtk.h> 45 46 #include <wtf/gobject/GUniquePtr.h> 46 47 … … 169 170 #endif 170 171 172 String WebPage::platformUserAgent(const URL& url) const 173 { 174 if (url.isNull() || !m_page->settings().needsSiteSpecificQuirks()) 175 return String(); 176 177 return WebCore::standardUserAgentForURL(url); 178 } 179 171 180 } // namespace WebKit -
trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm
r169669 r169799 2407 2407 } 2408 2408 2409 String WebPage::platformUserAgent(const URL&) const 2410 { 2411 return String(); 2412 } 2413 2409 2414 } // namespace WebKit 2410 2415 -
trunk/Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm
r167974 r169799 762 762 { 763 763 NSMutableURLRequest* request = [[NSMutableURLRequest alloc] initWithURL:url]; 764 [request setValue:(NSString*)userAgent( ) forHTTPHeaderField:@"User-Agent"];764 [request setValue:(NSString*)userAgent(url) forHTTPHeaderField:@"User-Agent"]; 765 765 NSCachedURLResponse *cachedResponse; 766 766 if (CFURLStorageSessionRef storageSession = corePage()->mainFrame().loader().networkingContext()->storageSession().platformSession()) … … 776 776 { 777 777 RetainPtr<NSMutableURLRequest> request = adoptNS([[NSMutableURLRequest alloc] initWithURL:url]); 778 [request setValue:(NSString *)webPage->userAgent( ) forHTTPHeaderField:@"User-Agent"];778 [request setValue:(NSString *)webPage->userAgent(url) forHTTPHeaderField:@"User-Agent"]; 779 779 780 780 if (CFURLStorageSessionRef storageSession = webPage->corePage()->mainFrame().loader().networkingContext()->storageSession().platformSession()) … … 1044 1044 #endif 1045 1045 1046 String WebPage::platformUserAgent(const URL&) const 1047 { 1048 return String(); 1049 } 1050 1046 1051 } // namespace WebKit 1047 1052 -
trunk/Tools/ChangeLog
r169794 r169799 1 2014-06-11 Carlos Garcia Campos <cgarcia@igalia.com> 2 3 [GTK] Use a different user agent string depending on the site 4 https://bugs.webkit.org/show_bug.cgi?id=132681 5 6 Reviewed by Anders Carlsson. 7 8 Add a unit test to check user agent quirks. 9 10 * TestWebKitAPI/PlatformGTK.cmake: 11 * TestWebKitAPI/Tests/WebCore/gtk/UserAgentQuirks.cpp: Added. 12 (TestWebKitAPI::TEST): 13 * TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitSettings.cpp: 14 (testWebKitSettings): Site specific quirks setting is now enabled 15 by default. 16 1 17 2014-06-10 Gyuyoung Kim <gyuyoung.kim@samsung.com> 2 18 -
trunk/Tools/TestWebKitAPI/PlatformGTK.cmake
r168834 r169799 120 120 ${WEBCORE_DIR}/platform/gtk/GtkInputMethodFilter.cpp 121 121 ${TESTWEBKITAPI_DIR}/Tests/WebCore/gtk/InputMethodFilter.cpp 122 ${TESTWEBKITAPI_DIR}/Tests/WebCore/gtk/UserAgentQuirks.cpp 122 123 ) 123 124 -
trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitSettings.cpp
r161366 r169799 234 234 g_assert(webkit_settings_get_draw_compositing_indicators(settings)); 235 235 236 // By default, site specific quirks are disabled. 236 // By default, site specific quirks are enabled. 237 g_assert(webkit_settings_get_enable_site_specific_quirks(settings)); 238 webkit_settings_set_enable_site_specific_quirks(settings, FALSE); 237 239 g_assert(!webkit_settings_get_enable_site_specific_quirks(settings)); 238 webkit_settings_set_enable_site_specific_quirks(settings, TRUE);239 g_assert(webkit_settings_get_enable_site_specific_quirks(settings));240 240 241 241 // By default, page cache is enabled.
Note:
See TracChangeset
for help on using the changeset viewer.