Changeset 207406 in webkit
- Timestamp:
- Oct 17, 2016 4:30:17 AM (8 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 1 deleted
- 11 edited
- 1 copied
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r207403 r207406 1 2016-10-17 Michael Catanzaro <mcatanzaro@igalia.com> 2 3 Move user agent quirks to cross-platform location 4 https://bugs.webkit.org/show_bug.cgi?id=163508 5 6 Reviewed by Carlos Garcia Campos. 7 8 Tested by Tools/TestWebKitAPI/Tests/WebCore/UserAgentQuirks.cpp. 9 10 * PlatformGTK.cmake: 11 * platform/UserAgent.h: Renamed from Source/WebCore/platform/gtk/UserAgentGtk.h. 12 * platform/UserAgentQuirks.cpp: Added. Moved from UserAgentGtk.cpp. 13 (WebCore::urlRequiresChromeBrowser): Sneakily tighten up Google domain detection, it should 14 only apply to sites if the base domain matches google.*, not any base domain that starts 15 with google. 16 (WebCore::urlRequiresMacintoshPlatform): 17 (WebCore::UserAgentQuirks::quirksForURL): 18 (WebCore::UserAgentQuirks::stringForQuirk): 19 * platform/UserAgentQuirks.h: Moved from UserAgentGtk.cpp. prepare-ChangeLog thinks it was 20 renamed from Source/WebCore/platform/efl/UserAgentEfl.h, but prepare-ChangeLog is dumb. 21 (WebCore::UserAgentQuirks::UserAgentQuirks): 22 (WebCore::UserAgentQuirks::add): 23 (WebCore::UserAgentQuirks::contains): 24 (WebCore::UserAgentQuirks::isEmpty): 25 * platform/efl/UserAgentEfl.cpp: 26 (WebCore::standardUserAgentForURL): 27 * platform/gtk/UserAgentGtk.cpp: 28 (WebCore::buildUserAgentString): 29 (WebCore::standardUserAgentForURL): 30 (): Deleted. 31 (WebCore::UserAgentQuirks::UserAgentQuirks): Deleted. 32 (WebCore::UserAgentQuirks::add): Deleted. 33 (WebCore::UserAgentQuirks::contains): Deleted. 34 (WebCore::UserAgentQuirks::isEmpty): Deleted. 35 (WebCore::urlRequiresChromeBrowser): Deleted. 36 (WebCore::urlRequiresMacintoshPlatform): Deleted. 37 1 38 2016-10-17 Alberto Garcia <berto@igalia.com> 2 39 -
trunk/Source/WebCore/PlatformGTK.cmake
r206883 r207406 85 85 86 86 platform/KillRingNone.cpp 87 platform/UserAgentQuirks.cpp 87 88 88 89 platform/audio/glib/AudioBusGLib.cpp -
trunk/Source/WebCore/platform/UserAgent.h
r207405 r207406 1 1 /* 2 * Copyright (C) 2012, 2014 Igalia S.L. 2 * Copyright (C) 2012, 2014, 2016 Igalia S.L. 3 * Copyright (C) 2014 Apple Inc. 3 4 * 4 5 * Redistribution and use in source and binary forms, with or without … … 24 25 */ 25 26 26 #ifndef UserAgentGtk_h 27 #define UserAgentGtk_h 27 #pragma once 28 29 #if PLATFORM(COCOA) 30 // FIXME: Remove Source/WebCore/page/cocoa/UserAgent.h 31 #include_next "UserAgent.h" 32 #else 28 33 29 34 #include <wtf/text/WTFString.h> … … 37 42 } 38 43 39 #endif // UserAgentGtk_h 40 44 #endif -
trunk/Source/WebCore/platform/UserAgentQuirks.h
r207405 r207406 1 1 /* 2 * Copyright (C) 201 5 Naver Corp. All rights reserved.2 * Copyright (C) 2012, 2014, 2016 Igalia S.L. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 24 24 */ 25 25 26 #ifndef UserAgentEfl_h 27 #define UserAgentEfl_h 26 #pragma once 28 27 28 #include <wtf/Assertions.h> 29 29 #include <wtf/text/WTFString.h> 30 30 31 31 namespace WebCore { 32 32 33 String standardUserAgent(const String& applicationName = emptyString(), const String& applicationVersion = emptyString()); 33 class URL; 34 35 class UserAgentQuirks { 36 public: 37 enum UserAgentQuirk { 38 NeedsChromeBrowser, 39 NeedsMacintoshPlatform, 40 41 NumUserAgentQuirks 42 }; 43 44 UserAgentQuirks() 45 : m_quirks(0) 46 { 47 COMPILE_ASSERT(sizeof(m_quirks) * 8 >= NumUserAgentQuirks, not_enough_room_for_quirks); 48 } 49 50 void add(UserAgentQuirk quirk) 51 { 52 ASSERT(quirk >= 0); 53 ASSERT_WITH_SECURITY_IMPLICATION(quirk < NumUserAgentQuirks); 54 55 m_quirks |= (1 << quirk); 56 } 57 58 bool contains(UserAgentQuirk quirk) const 59 { 60 return m_quirks & (1 << quirk); 61 } 62 63 bool isEmpty() const { return !m_quirks; } 64 65 static UserAgentQuirks quirksForURL(const URL&); 66 67 static String stringForQuirk(UserAgentQuirk); 68 69 private: 70 uint32_t m_quirks; 71 }; 34 72 35 73 } 36 37 #endif // UserAgentEfl_h38 -
trunk/Source/WebCore/platform/efl/UserAgentEfl.cpp
r202813 r207406 25 25 26 26 #include "config.h" 27 #include "UserAgent Efl.h"27 #include "UserAgent.h" 28 28 29 29 #include <wtf/NeverDestroyed.h> … … 76 76 } 77 77 78 String standardUserAgentForURL(const URL&) 79 { 80 // Disable user agent quirks for now. 81 return String(); 82 } 83 78 84 } // namespace WebCore 79 85 -
trunk/Source/WebCore/platform/gtk/UserAgentGtk.cpp
r207376 r207406 25 25 26 26 #include "config.h" 27 #include "UserAgent Gtk.h"27 #include "UserAgent.h" 28 28 29 #include "PublicSuffix.h"30 29 #include "URL.h" 30 #include "UserAgentQuirks.h" 31 31 #include <wtf/NeverDestroyed.h> 32 32 #include <wtf/text/StringBuilder.h> … … 43 43 44 44 namespace WebCore { 45 46 class UserAgentQuirks {47 public:48 enum UserAgentQuirk {49 NeedsChromeBrowser,50 NeedsMacintoshPlatform,51 52 NumUserAgentQuirks53 };54 55 UserAgentQuirks()56 : m_quirks(0)57 {58 COMPILE_ASSERT(sizeof(m_quirks) * 8 >= NumUserAgentQuirks, not_enough_room_for_quirks);59 }60 61 void add(UserAgentQuirk quirk)62 {63 ASSERT(quirk >= 0);64 ASSERT_WITH_SECURITY_IMPLICATION(quirk < NumUserAgentQuirks);65 66 m_quirks |= (1 << quirk);67 }68 69 bool contains(UserAgentQuirk quirk) const70 {71 return m_quirks & (1 << quirk);72 }73 74 bool isEmpty() const { return !m_quirks; }75 76 private:77 uint32_t m_quirks;78 };79 45 80 46 static const char* platformForUAString() … … 116 82 117 83 if (quirks.contains(UserAgentQuirks::NeedsMacintoshPlatform)) 118 uaString.append Literal("Macintosh");119 else 84 uaString.append(UserAgentQuirks::stringForQuirk(UserAgentQuirks::NeedsMacintoshPlatform)); 85 else { 120 86 uaString.append(platformForUAString()); 121 122 uaString.appendLiteral("; "); 123 124 if (quirks.contains(UserAgentQuirks::NeedsMacintoshPlatform)) 125 uaString.appendLiteral("Intel Mac OS X 10_12"); 126 else 87 uaString.appendLiteral("; "); 127 88 uaString.append(platformVersionForUAString()); 89 } 128 90 129 91 uaString.appendLiteral(") AppleWebKit/"); … … 132 94 133 95 // Note that Chrome UAs advertise *both* Chrome and Safari. 134 // We set a meaningful value only for the first two digits here. 135 if (quirks.contains(UserAgentQuirks::NeedsChromeBrowser)) 136 uaString.append("Chrome/54.0.2704.106 "); 96 if (quirks.contains(UserAgentQuirks::NeedsChromeBrowser)) { 97 uaString.append(UserAgentQuirks::stringForQuirk(UserAgentQuirks::NeedsChromeBrowser)); 98 uaString.appendLiteral(" "); 99 } 137 100 138 101 // Version/X is mandatory *before* Safari/X to be a valid Safari UA. See … … 170 133 } 171 134 172 // Be careful with this quirk: it's an invitation for sites to use JavaScript we can't handle.173 static bool urlRequiresChromeBrowser(const URL& url)174 {175 String baseDomain = topPrivatelyControlledDomain(url.host());176 177 // Needed for fonts on many sites, https://bugs.webkit.org/show_bug.cgi?id=147296178 if (baseDomain == "typekit.net" || baseDomain == "typekit.com")179 return true;180 181 // Shut off Chrome ads. Avoid missing features on maps.google.com.182 if (baseDomain.startsWith("google"))183 return true;184 185 // Needed for YouTube 360 (requires ENABLE_MEDIA_SOURCE).186 if (baseDomain == "youtube.com")187 return true;188 189 // Slack completely blocks users with our standard user agent.190 if (baseDomain == "slack.com")191 return true;192 193 return false;194 }195 196 static bool urlRequiresMacintoshPlatform(const URL& url)197 {198 String baseDomain = topPrivatelyControlledDomain(url.host());199 200 // At least finance.yahoo.com displays a mobile version with our standard user agent.201 if (baseDomain == "yahoo.com")202 return true;203 204 // taobao.com displays a mobile version with our standard user agent.205 if (baseDomain == "taobao.com")206 return true;207 208 // web.whatsapp.com completely blocks users with our standard user agent.209 if (baseDomain == "whatsapp.com")210 return true;211 212 return false;213 }214 215 135 String standardUserAgentForURL(const URL& url) 216 136 { 217 ASSERT(!url.isNull()); 218 UserAgentQuirks quirks; 219 if (urlRequiresChromeBrowser(url)) 220 quirks.add(UserAgentQuirks::NeedsChromeBrowser); 221 if (urlRequiresMacintoshPlatform(url)) 222 quirks.add(UserAgentQuirks::NeedsMacintoshPlatform); 223 137 auto quirks = UserAgentQuirks::quirksForURL(url); 224 138 // The null string means we don't need a specific UA for the given URL. 225 139 return quirks.isEmpty() ? String() : buildUserAgentString(quirks); -
trunk/Source/WebKit2/ChangeLog
r207405 r207406 1 2016-10-17 Michael Catanzaro <mcatanzaro@igalia.com> 2 3 Move user agent quirks to cross-platform location 4 https://bugs.webkit.org/show_bug.cgi?id=163508 5 6 Reviewed by Carlos Garcia Campos. 7 8 #include <WebCore/UserAgent.h> instead of <WebCore/UserAgentGtk.h>. 9 10 * UIProcess/API/gtk/WebKitSettings.cpp: 11 * UIProcess/efl/WebPageProxyEfl.cpp: 12 * UIProcess/gtk/WebPageProxyGtk.cpp: 13 * WebProcess/WebPage/gtk/WebPageGtk.cpp: 14 1 15 2016-10-17 Carlos Garcia Campos <cgarcia@igalia.com> 2 16 -
trunk/Source/WebKit2/UIProcess/API/gtk/WebKitSettings.cpp
r200497 r207406 37 37 #include "WebPageProxy.h" 38 38 #include "WebPreferences.h" 39 #include <WebCore/UserAgent Gtk.h>39 #include <WebCore/UserAgent.h> 40 40 #include <glib/gi18n-lib.h> 41 41 #include <wtf/text/CString.h> -
trunk/Source/WebKit2/UIProcess/efl/WebPageProxyEfl.cpp
r205009 r207406 30 30 #include "NativeWebKeyboardEvent.h" 31 31 #include "NotImplemented.h" 32 #include "UserAgent Efl.h"32 #include "UserAgent.h" 33 33 #include "WebPageMessages.h" 34 34 #include "WebProcessProxy.h" -
trunk/Source/WebKit2/UIProcess/gtk/WebPageProxyGtk.cpp
r205909 r207406 35 35 #include "WebProcessProxy.h" 36 36 #include "WebsiteDataStore.h" 37 #include <WebCore/UserAgent Gtk.h>37 #include <WebCore/UserAgent.h> 38 38 #include <gtk/gtkx.h> 39 39 #include <wtf/NeverDestroyed.h> -
trunk/Source/WebKit2/WebProcess/WebPage/gtk/WebPageGtk.cpp
r205909 r207406 47 47 #include <WebCore/PlatformKeyboardEvent.h> 48 48 #include <WebCore/Settings.h> 49 #include <WebCore/UserAgent Gtk.h>49 #include <WebCore/UserAgent.h> 50 50 #include <wtf/glib/GUniquePtr.h> 51 51 -
trunk/Tools/ChangeLog
r207405 r207406 1 2016-10-17 Michael Catanzaro <mcatanzaro@igalia.com> 2 3 Move user agent quirks to cross-platform location 4 https://bugs.webkit.org/show_bug.cgi?id=163508 5 6 Reviewed by Carlos Garcia Campos. 7 8 Move the test to a cross-platform location and improve it to better check the full list of 9 sites we have defined quirks for. 10 11 * TestWebKitAPI/PlatformGTK.cmake: 12 * TestWebKitAPI/Tests/WebCore/UserAgentQuirks.cpp: Renamed from Tools/TestWebKitAPI/Tests/WebCore/gtk/UserAgentQuirks.cpp. 13 (TestWebKitAPI::assertUserAgentForURLHasChromeBrowserQuirk): 14 (TestWebKitAPI::assertUserAgentForURLHasMacPlatformQuirk): 15 (TestWebKitAPI::TEST): 16 1 17 2016-10-17 Carlos Garcia Campos <cgarcia@igalia.com> 2 18 -
trunk/Tools/TestWebKitAPI/PlatformGTK.cmake
r207325 r207406 126 126 set_target_properties(TestWebKit2 PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${TESTWEBKITAPI_RUNTIME_OUTPUT_DIRECTORY}/WebKit2) 127 127 128 set(TestWebCoreGtk_SOURCES129 ${TESTWEBKITAPI_DIR}/Tests/WebCore/gtk/UserAgentQuirks.cpp130 )131 132 128 add_executable(TestWebCore 133 129 ${test_main_SOURCES} 134 ${TestWebCoreGtk_SOURCES}135 130 ${TESTWEBKITAPI_DIR}/TestsController.cpp 131 ${TESTWEBKITAPI_DIR}/Tests/WebCore/FileSystem.cpp 136 132 ${TESTWEBKITAPI_DIR}/Tests/WebCore/HTMLParserIdioms.cpp 137 133 ${TESTWEBKITAPI_DIR}/Tests/WebCore/LayoutUnit.cpp 134 ${TESTWEBKITAPI_DIR}/Tests/WebCore/PublicSuffix.cpp 135 ${TESTWEBKITAPI_DIR}/Tests/WebCore/SharedBuffer.cpp 138 136 ${TESTWEBKITAPI_DIR}/Tests/WebCore/URL.cpp 139 137 ${TESTWEBKITAPI_DIR}/Tests/WebCore/URLParser.cpp 140 ${TESTWEBKITAPI_DIR}/Tests/WebCore/SharedBuffer.cpp 141 ${TESTWEBKITAPI_DIR}/Tests/WebCore/FileSystem.cpp 142 ${TESTWEBKITAPI_DIR}/Tests/WebCore/PublicSuffix.cpp 138 ${TESTWEBKITAPI_DIR}/Tests/WebCore/UserAgentQuirks.cpp 143 139 ) 144 140 -
trunk/Tools/TestWebKitAPI/Tests/WebCore/UserAgentQuirks.cpp
r207405 r207406 27 27 28 28 #include <WebCore/URL.h> 29 #include <WebCore/UserAgent Gtk.h>29 #include <WebCore/UserAgent.h> 30 30 31 31 using namespace WebCore; … … 33 33 namespace TestWebKitAPI { 34 34 35 TEST(WebCore, UserAgentQuirksTest) 35 static void assertUserAgentForURLHasChromeBrowserQuirk(const char* url) 36 { 37 String uaString = standardUserAgentForURL(URL(ParsedURLString, url)); 38 39 #if !OS(MAC_OS_X) 40 EXPECT_FALSE(uaString.contains("Macintosh")); 41 EXPECT_FALSE(uaString.contains("Mac OS X")); 42 #endif 43 #if OS(LINUX) 44 EXPECT_TRUE(uaString.contains("Linux")); 45 #endif 46 #if OS(WINDOWS) 47 EXPECT_TRUE(uaString.contains("Windows")); 48 #endif 49 50 EXPECT_TRUE(uaString.contains("Chrome")); 51 EXPECT_TRUE(uaString.contains("Safari")); 52 EXPECT_FALSE(uaString.contains("Chromium")); 53 } 54 55 static void assertUserAgentForURLHasMacPlatformQuirk(const char* url) 56 { 57 String uaString = standardUserAgentForURL(URL(ParsedURLString, url)); 58 59 EXPECT_TRUE(uaString.contains("Macintosh")); 60 EXPECT_TRUE(uaString.contains("Mac OS X")); 61 EXPECT_FALSE(uaString.contains("Linux")); 62 EXPECT_FALSE(uaString.contains("Windows")); 63 EXPECT_FALSE(uaString.contains("Chrome")); 64 } 65 66 TEST(UserAgentTest, Quirks) 36 67 { 37 68 // A site with not quirks should return a null String. … … 39 70 EXPECT_TRUE(uaString.isNull()); 40 71 41 // web.whatsapp.com requires MAC OS platform in the UA. 42 uaString = standardUserAgentForURL(URL(ParsedURLString, "http://web.whatsapp.com/")); 43 EXPECT_TRUE(uaString.contains("Macintosh")); 44 EXPECT_TRUE(uaString.contains("Mac OS X")); 45 EXPECT_FALSE(uaString.contains("Linux")); 72 // Google quirk should not affect sites with similar domains. 73 uaString = standardUserAgentForURL(URL(ParsedURLString, "http://www.googleblog.com/")); 46 74 EXPECT_FALSE(uaString.contains("Chrome")); 47 75 48 // google domains require Chrome in the UA 49 uaString = standardUserAgentForURL(URL(ParsedURLString, "http://www.google.es/")); 50 EXPECT_FALSE(uaString.contains("Macintosh")); 51 EXPECT_FALSE(uaString.contains("Mac OS X")); 52 EXPECT_TRUE(uaString.contains("Linux")); 53 EXPECT_TRUE(uaString.contains("Chrome")); 76 assertUserAgentForURLHasChromeBrowserQuirk("http://typekit.com/"); 77 assertUserAgentForURLHasChromeBrowserQuirk("http://typekit.net/"); 78 assertUserAgentForURLHasChromeBrowserQuirk("http://www.google.com/"); 79 assertUserAgentForURLHasChromeBrowserQuirk("http://www.google.es/"); 80 assertUserAgentForURLHasChromeBrowserQuirk("http://calendar.google.com/"); 81 assertUserAgentForURLHasChromeBrowserQuirk("http://maps.google.com/"); 82 assertUserAgentForURLHasChromeBrowserQuirk("http://plus.google.com/"); 83 assertUserAgentForURLHasChromeBrowserQuirk("http://www.youtube.com/"); 84 assertUserAgentForURLHasChromeBrowserQuirk("http://www.slack.com/"); 54 85 55 uaString = standardUserAgentForURL(URL(ParsedURLString, "http://maps.google.com/")); 56 EXPECT_FALSE(uaString.contains("Macintosh")); 57 EXPECT_FALSE(uaString.contains("Mac OS X")); 58 EXPECT_TRUE(uaString.contains("Linux")); 59 EXPECT_TRUE(uaString.contains("Chrome")); 60 61 // Slack requires Chrome in the UA 62 uaString = standardUserAgentForURL(URL(ParsedURLString, "http://www.slack.com/")); 63 EXPECT_FALSE(uaString.contains("Macintosh")); 64 EXPECT_FALSE(uaString.contains("Mac OS X")); 65 EXPECT_TRUE(uaString.contains("Linux")); 66 EXPECT_TRUE(uaString.contains("Chrome")); 86 assertUserAgentForURLHasMacPlatformQuirk("http://www.yahoo.com/"); 87 assertUserAgentForURLHasMacPlatformQuirk("http://finance.yahoo.com/"); 88 assertUserAgentForURLHasMacPlatformQuirk("http://intl.taobao.com/"); 89 assertUserAgentForURLHasMacPlatformQuirk("http://www.whatsapp.com/"); 90 assertUserAgentForURLHasMacPlatformQuirk("http://web.whatsapp.com/"); 67 91 } 68 92
Note: See TracChangeset
for help on using the changeset viewer.