[GTK] Use a different user agent string depending on the site
authorcarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 11 Jun 2014 07:38:35 +0000 (07:38 +0000)
committercarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 11 Jun 2014 07:38:35 +0000 (07:38 +0000)
commitce152dd10318da608d6b750fb3785ed234f56c8a
treef8365cc49a2a285c82e71089a853883d136ed629
parent4660aca28b45b3a45a0b79bbe8c4160205dfb503
[GTK] Use a different user agent string depending on the site
https://bugs.webkit.org/show_bug.cgi?id=132681

Reviewed by Anders Carlsson.

Source/WebCore:
We have changed the user agent string several times to try to fix
broken websites that require specific things in the UA string to
properly work. But everytime we change the UA string to fix a
website we break others. We could use different UA string
depending on the website. UserAgentGtk code has also been cleaned
up, using NeverDestroyed instead of DEPRECATED_DEFINE_STATIC_LOCAL
and avoiding unneeded conversions to UTF-8.

* platform/gtk/UserAgentGtk.cpp:
(WebCore::UserAgentQuirks::UserAgentQuirks): New helper private
class to handle user agent quirks.
(WebCore::UserAgentQuirks::add):
(WebCore::UserAgentQuirks::contains):
(WebCore::UserAgentQuirks::isEmpty):
(WebCore::platformForUAString): Bring back this method that was
removed to always pretend to be Macintosh.
(WebCore::platformVersionForUAString): Return a different platform
version depending on the actual platform.
(WebCore::versionForUAString): Return the WebKit version.
(WebCore::buildUserAgentString): Helper function to build the user
agent taking into account the UserAgentQuirks received.
(WebCore::standardUserAgentStatic): Standard user agent string
when no quirks are present.
(WebCore::standardUserAgent):
(WebCore::standardUserAgentForURL): New method that returns the
user agent string for the given URL.
* platform/gtk/UserAgentGtk.h:

Source/WebKit2:
* UIProcess/API/gtk/WebKitSettings.cpp:
(webkit_settings_class_init): Enable site specific quirks setting
by default.
* WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp:
(WebKit::WebFrameLoaderClient::userAgent): Pass the given URL to WebPage.
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::userAgent): Try to get the user agent for the
URL received falling back to the current one otherwise.
* WebProcess/WebPage/WebPage.h:
(WebKit::WebPage::platformUserAgent): Added.
* WebProcess/WebPage/efl/WebPageEfl.cpp:
(WebKit::WebPage::platformUserAgent): Return null String.
* WebProcess/WebPage/gtk/WebPageGtk.cpp:
(WebKit::WebPage::platformUserAgent): Use WebCore::standardUserAgentForURL() when site specific quirks
setting is enabled.
* WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::WebPage::platformUserAgent): Return null String.
* WebProcess/WebPage/mac/WebPageMac.mm:
(WebKit::WebPage::platformUserAgent): Return null String.

Tools:
Add a unit test to check user agent quirks.

* TestWebKitAPI/PlatformGTK.cmake:
* TestWebKitAPI/Tests/WebCore/gtk/UserAgentQuirks.cpp: Added.
(TestWebKitAPI::TEST):
* TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitSettings.cpp:
(testWebKitSettings): Site specific quirks setting is now enabled
by default.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@169799 268f45cc-cd09-0410-ab3c-d52691b4dbfc
16 files changed:
Source/WebCore/ChangeLog
Source/WebCore/platform/gtk/UserAgentGtk.cpp
Source/WebCore/platform/gtk/UserAgentGtk.h
Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/API/gtk/WebKitSettings.cpp
Source/WebKit2/WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp
Source/WebKit2/WebProcess/WebPage/WebPage.cpp
Source/WebKit2/WebProcess/WebPage/WebPage.h
Source/WebKit2/WebProcess/WebPage/efl/WebPageEfl.cpp
Source/WebKit2/WebProcess/WebPage/gtk/WebPageGtk.cpp
Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm
Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm
Tools/ChangeLog
Tools/TestWebKitAPI/PlatformGTK.cmake
Tools/TestWebKitAPI/Tests/WebCore/gtk/UserAgentQuirks.cpp [new file with mode: 0644]
Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitSettings.cpp