Need a mechanism to override navigator.userAgent
authorrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 26 Jan 2019 06:50:58 +0000 (06:50 +0000)
committerrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 26 Jan 2019 06:50:58 +0000 (06:50 +0000)
commit82ecc4ca8f2a60c82cb7a132f5fcb53e4e98dfe4
tree6632d6c8453436a8d6d2fc680d9d112b531f391a
parent3ab7d2c53b473cc204a5fddc3174e758b6dfd818
Need a mechanism to override navigator.userAgent
https://bugs.webkit.org/show_bug.cgi?id=193762
<rdar://problem/47504939>

Reviewed by Brent Fulgham.

Source/WebCore:

Added the ability to specify user agent string just for navigator.userAgent via DocumentLoader.

* loader/DocumentLoader.h:
(WebCore::DocumentLoader::setCustomJavaScriptUserAgent):
(WebCore::DocumentLoader::customJavaScriptUserAgent const):
* loader/FrameLoader.cpp:
(WebCore::FrameLoader::userAgentForJavaScript const):
* loader/FrameLoader.h:
* page/Navigator.cpp:
(WebCore::Navigator::userAgent const):

Source/WebKit:

This patch adds a new _WKWebsitePolicies SPI to specify the user agent string returned by
navigator.userAgent without affecting the user agent string used to send network requests.

Tests: WebKit.WebsitePoliciesCustomJavaScriptUserAgent
       WebKit.WebsitePoliciesCustomUserAgents

* Shared/WebsitePoliciesData.cpp:
(WebKit::WebsitePoliciesData::encode const):
(WebKit::WebsitePoliciesData::decode):
(WebKit::WebsitePoliciesData::applyToDocumentLoader):
* Shared/WebsitePoliciesData.h:
* UIProcess/API/APIWebsitePolicies.cpp:
(API::WebsitePolicies::data):
* UIProcess/API/APIWebsitePolicies.h:
* UIProcess/API/Cocoa/_WKWebsitePolicies.h:
* UIProcess/API/Cocoa/_WKWebsitePolicies.mm:
(-[_WKWebsitePolicies setCustomJavaScriptUserAgent:]):
(-[_WKWebsitePolicies customJavaScriptUserAgent]):

Tools:

Added test cases for _WKWebsitePolicies.customJavaScriptUserAgent.

* TestWebKitAPI/Tests/WebKitCocoa/WebsitePolicies.mm:
(-[CustomJavaScriptUserAgentDelegate _webView:decidePolicyForNavigationAction:userInfo:decisionHandler:]):
(-[CustomJavaScriptUserAgentDelegate webView:didFinishNavigation:]):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@240541 268f45cc-cd09-0410-ab3c-d52691b4dbfc
14 files changed:
Source/WebCore/ChangeLog
Source/WebCore/loader/DocumentLoader.h
Source/WebCore/loader/FrameLoader.cpp
Source/WebCore/loader/FrameLoader.h
Source/WebCore/page/Navigator.cpp
Source/WebKit/ChangeLog
Source/WebKit/Shared/WebsitePoliciesData.cpp
Source/WebKit/Shared/WebsitePoliciesData.h
Source/WebKit/UIProcess/API/APIWebsitePolicies.cpp
Source/WebKit/UIProcess/API/APIWebsitePolicies.h
Source/WebKit/UIProcess/API/Cocoa/_WKWebsitePolicies.h
Source/WebKit/UIProcess/API/Cocoa/_WKWebsitePolicies.mm
Tools/ChangeLog
Tools/TestWebKitAPI/Tests/WebKitCocoa/WebsitePolicies.mm