WebKit Bugzilla
Attachment 359993 Details for
Bug 193762
: Need a mechanism to override navigator.userAgent
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
WIP
wip193762.patch (text/plain), 9.82 KB, created by
Ryosuke Niwa
on 2019-01-23 21:40:23 PST
(
hide
)
Description:
WIP
Filename:
MIME Type:
Creator:
Ryosuke Niwa
Created:
2019-01-23 21:40:23 PST
Size:
9.82 KB
patch
obsolete
>commit b394e589104e0f046a92920ebeb18c73ed51577d >Author: Ryosuke Niwa <rniwa@webkit.org> >Date: Wed Jan 23 21:37:39 2019 -0800 > > WIP > >diff --git a/Source/WebCore/loader/DocumentLoader.h b/Source/WebCore/loader/DocumentLoader.h >index 804be9bd75e..f7c545751da 100644 >--- a/Source/WebCore/loader/DocumentLoader.h >+++ b/Source/WebCore/loader/DocumentLoader.h >@@ -270,7 +270,10 @@ public: > > void setCustomUserAgent(const String& customUserAgent) { m_customUserAgent = customUserAgent; } > const String& customUserAgent() const { return m_customUserAgent; } >- >+ >+ void setCustomJavaScriptUserAgent(const String& customJavaScriptUserAgent) { m_customJavaScriptUserAgent = customJavaScriptUserAgent; } >+ const String& customJavaScriptUserAgent() const { return m_customJavaScriptUserAgent; } >+ > void setCustomNavigatorPlatform(const String& customNavigatorPlatform) { m_customNavigatorPlatform = customNavigatorPlatform; } > const String& customNavigatorPlatform() const { return m_customNavigatorPlatform; } > >@@ -543,6 +546,7 @@ private: > HashMap<String, Vector<std::pair<String, uint32_t>>> m_pendingContentExtensionDisplayNoneSelectors; > #endif > String m_customUserAgent; >+ String m_customJavaScriptUserAgent; > String m_customNavigatorPlatform; > bool m_userContentExtensionsEnabled { true }; > bool m_deviceOrientationEventEnabled { true }; >diff --git a/Source/WebCore/loader/FrameLoader.cpp b/Source/WebCore/loader/FrameLoader.cpp >index ebf950ba6c2..43d7c648dd1 100644 >--- a/Source/WebCore/loader/FrameLoader.cpp >+++ b/Source/WebCore/loader/FrameLoader.cpp >@@ -2705,6 +2705,20 @@ String FrameLoader::userAgent(const URL& url) const > > return m_client.userAgent(url); > } >+ >+String FrameLoader::userAgentForJavaScript(const URL& url) const >+{ >+ if (auto* documentLoader = m_frame.mainFrame().loader().activeDocumentLoader()) { >+ auto& customJavaScriptUserAgent = documentLoader->customJavaScriptUserAgent(); >+ if (!customJavaScriptUserAgent.isEmpty()) >+ return customJavaScriptUserAgent; >+ auto& customUserAgent = documentLoader->customUserAgent(); >+ if (!customUserAgent.isEmpty()) >+ return customUserAgent; >+ } >+ >+ return m_client.userAgent(url); >+} > > String FrameLoader::navigatorPlatform() const > { >diff --git a/Source/WebCore/loader/FrameLoader.h b/Source/WebCore/loader/FrameLoader.h >index 0554aad82d7..89dcb98a775 100644 >--- a/Source/WebCore/loader/FrameLoader.h >+++ b/Source/WebCore/loader/FrameLoader.h >@@ -234,6 +234,7 @@ public: > > void dispatchOnloadEvents(); > String userAgent(const URL&) const; >+ String userAgentForJavaScript(const URL&) const; > String navigatorPlatform() const; > > void dispatchDidClearWindowObjectInWorld(DOMWrapperWorld&); >diff --git a/Source/WebCore/page/Navigator.cpp b/Source/WebCore/page/Navigator.cpp >index a1aaf8f3ac3..91e3f4d0d72 100644 >--- a/Source/WebCore/page/Navigator.cpp >+++ b/Source/WebCore/page/Navigator.cpp >@@ -92,7 +92,7 @@ const String& Navigator::userAgent() const > if (RuntimeEnabledFeatures::sharedFeatures().webAPIStatisticsEnabled()) > ResourceLoadObserver::shared().logNavigatorAPIAccessed(*frame->document(), ResourceLoadStatistics::NavigatorAPI::UserAgent); > if (m_userAgent.isNull()) >- m_userAgent = frame->loader().userAgent(frame->document()->url()); >+ m_userAgent = frame->loader().userAgentForJavaScript(frame->document()->url()); > return m_userAgent; > } > >diff --git a/Source/WebKit/Shared/WebsitePoliciesData.cpp b/Source/WebKit/Shared/WebsitePoliciesData.cpp >index fb8e240599d..1d1181b1a9a 100644 >--- a/Source/WebKit/Shared/WebsitePoliciesData.cpp >+++ b/Source/WebKit/Shared/WebsitePoliciesData.cpp >@@ -44,6 +44,7 @@ void WebsitePoliciesData::encode(IPC::Encoder& encoder) const > encoder << popUpPolicy; > encoder << websiteDataStoreParameters; > encoder << customUserAgent; >+ encoder << customJavaScriptUserAgent; > encoder << customNavigatorPlatform; > } > >@@ -89,6 +90,11 @@ Optional<WebsitePoliciesData> WebsitePoliciesData::decode(IPC::Decoder& decoder) > if (!customUserAgent) > return WTF::nullopt; > >+ Optional<String> customJavaScriptUserAgent; >+ decoder >> customJavaScriptUserAgent; >+ if (!customJavaScriptUserAgent) >+ return WTF::nullopt; >+ > Optional<String> customNavigatorPlatform; > decoder >> customNavigatorPlatform; > if (!customNavigatorPlatform) >@@ -103,6 +109,7 @@ Optional<WebsitePoliciesData> WebsitePoliciesData::decode(IPC::Decoder& decoder) > WTFMove(*popUpPolicy), > WTFMove(*websiteDataStoreParameters), > WTFMove(*customUserAgent), >+ WTFMove(*customJavaScriptUserAgent), > WTFMove(*customNavigatorPlatform), > } }; > } >@@ -111,6 +118,7 @@ void WebsitePoliciesData::applyToDocumentLoader(WebsitePoliciesData&& websitePol > { > documentLoader.setCustomHeaderFields(WTFMove(websitePolicies.customHeaderFields)); > documentLoader.setCustomUserAgent(websitePolicies.customUserAgent); >+ documentLoader.setCustomJavaScriptUserAgent(websitePolicies.customJavaScriptUserAgent); > documentLoader.setCustomNavigatorPlatform(websitePolicies.customNavigatorPlatform); > documentLoader.setDeviceOrientationEventEnabled(websitePolicies.deviceOrientationEventEnabled); > >diff --git a/Source/WebKit/Shared/WebsitePoliciesData.h b/Source/WebKit/Shared/WebsitePoliciesData.h >index fcaed27c403..506cda9fb8d 100644 >--- a/Source/WebKit/Shared/WebsitePoliciesData.h >+++ b/Source/WebKit/Shared/WebsitePoliciesData.h >@@ -54,8 +54,9 @@ struct WebsitePoliciesData { > WebsitePopUpPolicy popUpPolicy { WebsitePopUpPolicy::Default }; > Optional<WebsiteDataStoreParameters> websiteDataStoreParameters; > String customUserAgent; >+ String customJavaScriptUserAgent; > String customNavigatorPlatform; >- >+ > void encode(IPC::Encoder&) const; > static Optional<WebsitePoliciesData> decode(IPC::Decoder&); > }; >diff --git a/Source/WebKit/UIProcess/API/APIWebsitePolicies.cpp b/Source/WebKit/UIProcess/API/APIWebsitePolicies.cpp >index 8447696e3e2..52a1636b0bd 100644 >--- a/Source/WebKit/UIProcess/API/APIWebsitePolicies.cpp >+++ b/Source/WebKit/UIProcess/API/APIWebsitePolicies.cpp >@@ -56,7 +56,8 @@ WebKit::WebsitePoliciesData WebsitePolicies::data() > Optional<WebKit::WebsiteDataStoreParameters> parameters; > if (m_websiteDataStore) > parameters = m_websiteDataStore->websiteDataStore().parameters(); >- return { contentBlockersEnabled(), deviceOrientationEventEnabled(), allowedAutoplayQuirks(), autoplayPolicy(), customHeaderFields(), popUpPolicy(), WTFMove(parameters), m_customUserAgent, m_customNavigatorPlatform }; >+ return { contentBlockersEnabled(), deviceOrientationEventEnabled(), allowedAutoplayQuirks(), autoplayPolicy(), >+ customHeaderFields(), popUpPolicy(), WTFMove(parameters), m_customUserAgent, m_customJavaScriptUserAgent, m_customNavigatorPlatform }; > } > > } >diff --git a/Source/WebKit/UIProcess/API/APIWebsitePolicies.h b/Source/WebKit/UIProcess/API/APIWebsitePolicies.h >index 718c755f6f3..ee7fd25c478 100644 >--- a/Source/WebKit/UIProcess/API/APIWebsitePolicies.h >+++ b/Source/WebKit/UIProcess/API/APIWebsitePolicies.h >@@ -74,7 +74,10 @@ public: > > void setCustomUserAgent(const WTF::String& customUserAgent) { m_customUserAgent = customUserAgent; } > const WTF::String& customUserAgent() const { return m_customUserAgent; } >- >+ >+ void setCustomJavaScriptUserAgent(const WTF::String& customJavaScriptUserAgent) { m_customJavaScriptUserAgent = customJavaScriptUserAgent; } >+ const WTF::String& customJavaScriptUserAgent() const { return m_customJavaScriptUserAgent; } >+ > void setCustomNavigatorPlatform(const WTF::String& customNavigatorPlatform) { m_customNavigatorPlatform = customNavigatorPlatform; } > const WTF::String& customNavigatorPlatform() const { return m_customNavigatorPlatform; } > >@@ -89,6 +92,7 @@ private: > WebKit::WebsitePopUpPolicy m_popUpPolicy { WebKit::WebsitePopUpPolicy::Default }; > RefPtr<WebsiteDataStore> m_websiteDataStore; > WTF::String m_customUserAgent; >+ WTF::String m_customJavaScriptUserAgent; > WTF::String m_customNavigatorPlatform; > }; > >diff --git a/Source/WebKit/UIProcess/API/Cocoa/_WKWebsitePolicies.h b/Source/WebKit/UIProcess/API/Cocoa/_WKWebsitePolicies.h >index cb7c2d0a4b7..3f5688c7250 100644 >--- a/Source/WebKit/UIProcess/API/Cocoa/_WKWebsitePolicies.h >+++ b/Source/WebKit/UIProcess/API/Cocoa/_WKWebsitePolicies.h >@@ -59,6 +59,7 @@ WK_CLASS_AVAILABLE(macosx(10.12.3), ios(10.3)) > @property (nonatomic) _WKWebsitePopUpPolicy popUpPolicy WK_API_AVAILABLE(macosx(10.14), ios(12.0)); > @property (nonatomic, strong) WKWebsiteDataStore *websiteDataStore WK_API_AVAILABLE(macosx(10.13.4), ios(11.3)); > @property (nonatomic, copy) NSString *customUserAgent WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA)); >+@property (nonatomic, copy) NSString *customJavaScriptUserAgent WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA)); > @property (nonatomic, copy) NSString *customNavigatorPlatform WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA)); > @property (nonatomic) BOOL deviceOrientationEventEnabled WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA)); > >diff --git a/Source/WebKit/UIProcess/API/Cocoa/_WKWebsitePolicies.mm b/Source/WebKit/UIProcess/API/Cocoa/_WKWebsitePolicies.mm >index 3928e3949b6..fda88b09418 100644 >--- a/Source/WebKit/UIProcess/API/Cocoa/_WKWebsitePolicies.mm >+++ b/Source/WebKit/UIProcess/API/Cocoa/_WKWebsitePolicies.mm >@@ -209,6 +209,16 @@ - (NSString *)customUserAgent > return _websitePolicies->customUserAgent(); > } > >+- (void)setCustomJavaScriptUserAgent:(NSString *)customUserAgent >+{ >+ _websitePolicies->setCustomJavaScriptUserAgent(customUserAgent); >+} >+ >+- (NSString *)customJavaScriptUserAgent >+{ >+ return _websitePolicies->customJavaScriptUserAgent(); >+} >+ > - (void)setCustomNavigatorPlatform:(NSString *)customNavigatorPlatform > { > _websitePolicies->setCustomNavigatorPlatform(customNavigatorPlatform);
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 193762
:
359993
|
360088
|
360217
|
360223