User agent string override for navigator.userAgent should be site specific quirks
authorrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 29 Jan 2019 07:15:00 +0000 (07:15 +0000)
committerrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 29 Jan 2019 07:15:00 +0000 (07:15 +0000)
https://bugs.webkit.org/show_bug.cgi?id=193950

Reviewed by Brent Fulgham.

Source/WebCore:

In order to make it possible to toggle the UA string override just for navigator.userAgent via Web Inspector,
we need to put this override behind the site specific quirks. Because WebInspector overrides Page's setting
without updating WKPreferences, there is no way for WKWebView client's to know whether the site specific quirks
had been disabled or not.

* loader/DocumentLoader.h:
(WebCore::DocumentLoader::setCustomJavaScriptUserAgentAsSiteSpecificQuirks):
(WebCore::DocumentLoader::customJavaScriptUserAgentAsSiteSpecificQuirks const):
(WebCore::DocumentLoader::setCustomJavaScriptUserAgent): Deleted.
(WebCore::DocumentLoader::customJavaScriptUserAgent const): Deleted.
* loader/FrameLoader.cpp:
(WebCore::FrameLoader::userAgentForJavaScript const):

Source/WebKit:

Renamed the various member variables, functions, properties and selectors.

* 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 setCustomJavaScriptUserAgentAsSiteSpecificQuirks:]): Renamed from setCustomJavaScriptUserAgent.
(-[_WKWebsitePolicies customJavaScriptUserAgentAsSiteSpecificQuirks]): Renamed from customJavaScriptUserAgent.

Tools:

Updated per the _WKWebsitePolicies rename.

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

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@240646 268f45cc-cd09-0410-ab3c-d52691b4dbfc

12 files changed:
Source/WebCore/ChangeLog
Source/WebCore/loader/DocumentLoader.h
Source/WebCore/loader/FrameLoader.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

index 542348c..1ad9c9f 100644 (file)
@@ -1,3 +1,23 @@
+2019-01-28  Ryosuke Niwa  <rniwa@webkit.org>
+
+        User agent string override for navigator.userAgent should be site specific quirks
+        https://bugs.webkit.org/show_bug.cgi?id=193950
+
+        Reviewed by Brent Fulgham.
+
+        In order to make it possible to toggle the UA string override just for navigator.userAgent via Web Inspector,
+        we need to put this override behind the site specific quirks. Because WebInspector overrides Page's setting
+        without updating WKPreferences, there is no way for WKWebView client's to know whether the site specific quirks
+        had been disabled or not.
+
+        * loader/DocumentLoader.h:
+        (WebCore::DocumentLoader::setCustomJavaScriptUserAgentAsSiteSpecificQuirks):
+        (WebCore::DocumentLoader::customJavaScriptUserAgentAsSiteSpecificQuirks const):
+        (WebCore::DocumentLoader::setCustomJavaScriptUserAgent): Deleted.
+        (WebCore::DocumentLoader::customJavaScriptUserAgent const): Deleted.
+        * loader/FrameLoader.cpp:
+        (WebCore::FrameLoader::userAgentForJavaScript const):
+
 2019-01-28  Devin Rousso  <drousso@apple.com>
 
         Web Inspector: provide a way to edit page WebRTC settings on a remote target
index f7c5457..ed3d21c 100644 (file)
@@ -271,8 +271,8 @@ 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 setCustomJavaScriptUserAgentAsSiteSpecificQuirks(const String& customUserAgent) { m_customJavaScriptUserAgentAsSiteSpecificQuirks = customUserAgent; }
+    const String& customJavaScriptUserAgentAsSiteSpecificQuirks() const { return m_customJavaScriptUserAgentAsSiteSpecificQuirks; }
 
     void setCustomNavigatorPlatform(const String& customNavigatorPlatform) { m_customNavigatorPlatform = customNavigatorPlatform; }
     const String& customNavigatorPlatform() const { return m_customNavigatorPlatform; }
@@ -546,7 +546,7 @@ private:
     HashMap<String, Vector<std::pair<String, uint32_t>>> m_pendingContentExtensionDisplayNoneSelectors;
 #endif
     String m_customUserAgent;
-    String m_customJavaScriptUserAgent;
+    String m_customJavaScriptUserAgentAsSiteSpecificQuirks;
     String m_customNavigatorPlatform;
     bool m_userContentExtensionsEnabled { true };
     bool m_deviceOrientationEventEnabled { true };
index fb8cbad..960f559 100644 (file)
@@ -2715,7 +2715,8 @@ String FrameLoader::userAgentForJavaScript(const URL& url) const
     String userAgent;
 
     if (auto* documentLoader = m_frame.mainFrame().loader().activeDocumentLoader()) {
-        userAgent = documentLoader->customJavaScriptUserAgent();
+        if (m_frame.settings().needsSiteSpecificQuirks())
+            userAgent = documentLoader->customJavaScriptUserAgentAsSiteSpecificQuirks();
         if (userAgent.isEmpty())
             userAgent = documentLoader->customUserAgent();
     }
index fb4784c..4300795 100644 (file)
@@ -1,3 +1,25 @@
+2019-01-28  Ryosuke Niwa  <rniwa@webkit.org>
+
+        User agent string override for navigator.userAgent should be site specific quirks
+        https://bugs.webkit.org/show_bug.cgi?id=193950
+
+        Reviewed by Brent Fulgham.
+
+        Renamed the various member variables, functions, properties and selectors.
+
+        * 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 setCustomJavaScriptUserAgentAsSiteSpecificQuirks:]): Renamed from setCustomJavaScriptUserAgent.
+        (-[_WKWebsitePolicies customJavaScriptUserAgentAsSiteSpecificQuirks]): Renamed from customJavaScriptUserAgent.
+
 2019-01-28  Commit Queue  <commit-queue@webkit.org>
 
         Unreviewed, rolling out r240630.
index 1d1181b..6b3b02d 100644 (file)
@@ -44,7 +44,7 @@ void WebsitePoliciesData::encode(IPC::Encoder& encoder) const
     encoder << popUpPolicy;
     encoder << websiteDataStoreParameters;
     encoder << customUserAgent;
-    encoder << customJavaScriptUserAgent;
+    encoder << customJavaScriptUserAgentAsSiteSpecificQuirks;
     encoder << customNavigatorPlatform;
 }
 
@@ -90,9 +90,9 @@ Optional<WebsitePoliciesData> WebsitePoliciesData::decode(IPC::Decoder& decoder)
     if (!customUserAgent)
         return WTF::nullopt;
 
-    Optional<String> customJavaScriptUserAgent;
-    decoder >> customJavaScriptUserAgent;
-    if (!customJavaScriptUserAgent)
+    Optional<String> customJavaScriptUserAgentAsSiteSpecificQuirks;
+    decoder >> customJavaScriptUserAgentAsSiteSpecificQuirks;
+    if (!customJavaScriptUserAgentAsSiteSpecificQuirks)
         return WTF::nullopt;
 
     Optional<String> customNavigatorPlatform;
@@ -109,7 +109,7 @@ Optional<WebsitePoliciesData> WebsitePoliciesData::decode(IPC::Decoder& decoder)
         WTFMove(*popUpPolicy),
         WTFMove(*websiteDataStoreParameters),
         WTFMove(*customUserAgent),
-        WTFMove(*customJavaScriptUserAgent),
+        WTFMove(*customJavaScriptUserAgentAsSiteSpecificQuirks),
         WTFMove(*customNavigatorPlatform),
     } };
 }
@@ -118,7 +118,7 @@ void WebsitePoliciesData::applyToDocumentLoader(WebsitePoliciesData&& websitePol
 {
     documentLoader.setCustomHeaderFields(WTFMove(websitePolicies.customHeaderFields));
     documentLoader.setCustomUserAgent(websitePolicies.customUserAgent);
-    documentLoader.setCustomJavaScriptUserAgent(websitePolicies.customJavaScriptUserAgent);
+    documentLoader.setCustomJavaScriptUserAgentAsSiteSpecificQuirks(websitePolicies.customJavaScriptUserAgentAsSiteSpecificQuirks);
     documentLoader.setCustomNavigatorPlatform(websitePolicies.customNavigatorPlatform);
     documentLoader.setDeviceOrientationEventEnabled(websitePolicies.deviceOrientationEventEnabled);
     
index 506cda9..c2711a9 100644 (file)
@@ -54,7 +54,7 @@ struct WebsitePoliciesData {
     WebsitePopUpPolicy popUpPolicy { WebsitePopUpPolicy::Default };
     Optional<WebsiteDataStoreParameters> websiteDataStoreParameters;
     String customUserAgent;
-    String customJavaScriptUserAgent;
+    String customJavaScriptUserAgentAsSiteSpecificQuirks;
     String customNavigatorPlatform;
 
     void encode(IPC::Encoder&) const;
index 52a1636..c63ce06 100644 (file)
@@ -57,7 +57,7 @@ WebKit::WebsitePoliciesData WebsitePolicies::data()
     if (m_websiteDataStore)
         parameters = m_websiteDataStore->websiteDataStore().parameters();
     return { contentBlockersEnabled(), deviceOrientationEventEnabled(), allowedAutoplayQuirks(), autoplayPolicy(),
-        customHeaderFields(), popUpPolicy(), WTFMove(parameters), m_customUserAgent, m_customJavaScriptUserAgent, m_customNavigatorPlatform };
+        customHeaderFields(), popUpPolicy(), WTFMove(parameters), m_customUserAgent, m_customJavaScriptUserAgentAsSiteSpecificQuirks, m_customNavigatorPlatform };
 }
 
 }
index ee7fd25..347f37d 100644 (file)
@@ -75,8 +75,8 @@ 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 setCustomJavaScriptUserAgentAsSiteSpecificQuirks(const WTF::String& customUserAgent) { m_customJavaScriptUserAgentAsSiteSpecificQuirks = customUserAgent; }
+    const WTF::String& customJavaScriptUserAgentAsSiteSpecificQuirks() const { return m_customJavaScriptUserAgentAsSiteSpecificQuirks; }
 
     void setCustomNavigatorPlatform(const WTF::String& customNavigatorPlatform) { m_customNavigatorPlatform = customNavigatorPlatform; }
     const WTF::String& customNavigatorPlatform() const { return m_customNavigatorPlatform; }
@@ -92,7 +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_customJavaScriptUserAgentAsSiteSpecificQuirks;
     WTF::String m_customNavigatorPlatform;
 };
 
index 3f5688c..f43cfd3 100644 (file)
@@ -59,7 +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 *customJavaScriptUserAgentAsSiteSpecificQuirks 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));
 
index fda88b0..dde107a 100644 (file)
     return _websitePolicies->customUserAgent();
 }
 
-- (void)setCustomJavaScriptUserAgent:(NSString *)customUserAgent
+- (void)setCustomJavaScriptUserAgentAsSiteSpecificQuirks:(NSString *)customUserAgent
 {
-    _websitePolicies->setCustomJavaScriptUserAgent(customUserAgent);
+    _websitePolicies->setCustomJavaScriptUserAgentAsSiteSpecificQuirks(customUserAgent);
 }
 
-- (NSString *)customJavaScriptUserAgent
+- (NSString *)customJavaScriptUserAgentAsSiteSpecificQuirks
 {
-    return _websitePolicies->customJavaScriptUserAgent();
+    return _websitePolicies->customJavaScriptUserAgentAsSiteSpecificQuirks();
 }
 
 - (void)setCustomNavigatorPlatform:(NSString *)customNavigatorPlatform
index 8cf0c9c..1e829b5 100644 (file)
@@ -1,3 +1,15 @@
+2019-01-28  Ryosuke Niwa  <rniwa@webkit.org>
+
+        User agent string override for navigator.userAgent should be site specific quirks
+        https://bugs.webkit.org/show_bug.cgi?id=193950
+
+        Reviewed by Brent Fulgham.
+
+        Updated per the _WKWebsitePolicies rename.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/WebsitePolicies.mm:
+        (-[CustomJavaScriptUserAgentDelegate _webView:decidePolicyForNavigationAction:userInfo:decisionHandler:]):
+
 2019-01-28  Ross Kirsling  <ross.kirsling@sony.com>
 
         Remove unnecessary `using namespace WTF`s (or at least restrict their scope).
index 5e4c7c5..db166c2 100644 (file)
@@ -29,6 +29,7 @@
 #import "TestWKWebView.h"
 #import <WebKit/WKNavigationDelegatePrivate.h>
 #import <WebKit/WKPagePrivate.h>
+#import <WebKit/WKPreferencesPrivate.h>
 #import <WebKit/WKPreferencesRefPrivate.h>
 #import <WebKit/WKUIDelegatePrivate.h>
 #import <WebKit/WKURLSchemeTaskPrivate.h>
@@ -1114,7 +1115,7 @@ TEST(WebKit, WebsitePoliciesCustomUserAgent)
 {
     _WKWebsitePolicies *websitePolicies = [[[_WKWebsitePolicies alloc] init] autorelease];
     if (navigationAction.targetFrame.mainFrame) {
-        [websitePolicies setCustomJavaScriptUserAgent:@"Foo Custom JavaScript UserAgent"];
+        [websitePolicies setCustomJavaScriptUserAgentAsSiteSpecificQuirks:@"Foo Custom JavaScript UserAgent"];
         if (_setCustomUserAgent)
             [websitePolicies setCustomUserAgent:@"Foo Custom Request UserAgent"];
     }
@@ -1142,6 +1143,7 @@ TEST(WebKit, WebsitePoliciesCustomJavaScriptUserAgent)
         EXPECT_TRUE([userAgentString hasSuffix:@"(KHTML, like Gecko)"]);
     }];
     [configuration setURLSchemeHandler:schemeHandler.get() forURLScheme:@"test"];
+    [configuration preferences]._needsSiteSpecificQuirks = YES;
 
     auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
 
@@ -1173,6 +1175,7 @@ TEST(WebKit, WebsitePoliciesCustomUserAgents)
         EXPECT_STREQ("Foo Custom Request UserAgent", [[task.request valueForHTTPHeaderField:@"User-Agent"] UTF8String]);
     }];
     [configuration setURLSchemeHandler:schemeHandler.get() forURLScheme:@"test"];
+    [configuration preferences]._needsSiteSpecificQuirks = YES;
 
     auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);