Diff
Modified: trunk/Source/WebCore/ChangeLog (239383 => 239384)
--- trunk/Source/WebCore/ChangeLog 2018-12-19 19:58:21 UTC (rev 239383)
+++ trunk/Source/WebCore/ChangeLog 2018-12-19 20:21:31 UTC (rev 239384)
@@ -1,3 +1,28 @@
+2018-12-19 Megan Gardner <[email protected]>
+
+ Allow clients to set the navigator platform
+ https://bugs.webkit.org/show_bug.cgi?id=192735
+
+ Reviewed by Tim Horton.
+
+ Expanded TestWebKitAPI/Tests/WebKitCocoa/WebsitePolicies.mm.
+
+ Lots of piping to allow the setting of a custom navigator platform.
+
+ * loader/DocumentLoader.h:
+ (WebCore::DocumentLoader::setCustomNavigatorPlatform):
+ (WebCore::DocumentLoader::customNavigatorPlatform const):
+ * loader/FrameLoader.cpp:
+ (WebCore::FrameLoader::navigatorPlatform const):
+ * loader/FrameLoader.h:
+ * page/Navigator.cpp:
+ (WebCore::Navigator::platform const):
+ * page/Navigator.h:
+ * page/NavigatorBase.cpp:
+ (WebCore::NavigatorBase::platform const):
+ (WebCore::NavigatorBase::platform): Deleted.
+ * page/NavigatorBase.h:
+
2018-12-19 Ryan Haddad <[email protected]>
Unreviewed, rolling out r239347.
Modified: trunk/Source/WebCore/loader/DocumentLoader.h (239383 => 239384)
--- trunk/Source/WebCore/loader/DocumentLoader.h 2018-12-19 19:58:21 UTC (rev 239383)
+++ trunk/Source/WebCore/loader/DocumentLoader.h 2018-12-19 20:21:31 UTC (rev 239384)
@@ -266,6 +266,9 @@
void setCustomUserAgent(const String& customUserAgent) { m_customUserAgent = customUserAgent; }
const String& customUserAgent() const { return m_customUserAgent; }
+
+ void setCustomNavigatorPlatform(const String& customNavigatorPlatform) { m_customNavigatorPlatform = customNavigatorPlatform; }
+ const String& customNavigatorPlatform() const { return m_customNavigatorPlatform; }
OptionSet<AutoplayQuirk> allowedAutoplayQuirks() const { return m_allowedAutoplayQuirks; }
void setAllowedAutoplayQuirks(OptionSet<AutoplayQuirk> allowedQuirks) { m_allowedAutoplayQuirks = allowedQuirks; }
@@ -536,6 +539,7 @@
HashMap<String, Vector<std::pair<String, uint32_t>>> m_pendingContentExtensionDisplayNoneSelectors;
#endif
String m_customUserAgent;
+ String m_customNavigatorPlatform;
bool m_userContentExtensionsEnabled { true };
AutoplayPolicy m_autoplayPolicy { AutoplayPolicy::Default };
OptionSet<AutoplayQuirk> m_allowedAutoplayQuirks;
Modified: trunk/Source/WebCore/loader/FrameLoader.cpp (239383 => 239384)
--- trunk/Source/WebCore/loader/FrameLoader.cpp 2018-12-19 19:58:21 UTC (rev 239383)
+++ trunk/Source/WebCore/loader/FrameLoader.cpp 2018-12-19 20:21:31 UTC (rev 239384)
@@ -2677,6 +2677,16 @@
return m_client.userAgent(url);
}
+
+String FrameLoader::navigatorPlatform() const
+{
+ if (auto* documentLoader = m_frame.mainFrame().loader().activeDocumentLoader()) {
+ auto& customNavigatorPlatform = documentLoader->customNavigatorPlatform();
+ if (!customNavigatorPlatform.isEmpty())
+ return customNavigatorPlatform;
+ }
+ return String();
+}
void FrameLoader::dispatchOnloadEvents()
{
Modified: trunk/Source/WebCore/loader/FrameLoader.h (239383 => 239384)
--- trunk/Source/WebCore/loader/FrameLoader.h 2018-12-19 19:58:21 UTC (rev 239383)
+++ trunk/Source/WebCore/loader/FrameLoader.h 2018-12-19 20:21:31 UTC (rev 239384)
@@ -234,6 +234,7 @@
void dispatchOnloadEvents();
String userAgent(const URL&) const;
+ String navigatorPlatform() const;
void dispatchDidClearWindowObjectInWorld(DOMWrapperWorld&);
void dispatchDidClearWindowObjectsInAllWorlds();
Modified: trunk/Source/WebCore/page/Navigator.cpp (239383 => 239384)
--- trunk/Source/WebCore/page/Navigator.cpp 2018-12-19 19:58:21 UTC (rev 239383)
+++ trunk/Source/WebCore/page/Navigator.cpp 2018-12-19 20:21:31 UTC (rev 239384)
@@ -95,7 +95,21 @@
m_userAgent = frame->loader().userAgent(frame->document()->url());
return m_userAgent;
}
+
+const String& Navigator::platform() const
+{
+ auto* frame = this->frame();
+ if (!frame || !frame->page())
+ return m_platform;
+ if (m_platform.isNull())
+ m_platform = frame->loader().navigatorPlatform();
+
+ if (m_platform.isNull())
+ m_platform = NavigatorBase::platform();
+ return m_platform;
+}
+
void Navigator::userAgentChanged()
{
m_userAgent = String();
Modified: trunk/Source/WebCore/page/Navigator.h (239383 => 239384)
--- trunk/Source/WebCore/page/Navigator.h 2018-12-19 19:58:21 UTC (rev 239383)
+++ trunk/Source/WebCore/page/Navigator.h 2018-12-19 20:21:31 UTC (rev 239384)
@@ -42,6 +42,7 @@
bool cookieEnabled() const;
bool javaEnabled() const;
const String& userAgent() const final;
+ const String& platform() const final;
void userAgentChanged();
bool onLine() const final;
void share(ScriptExecutionContext&, ShareData, Ref<DeferredPromise>&&);
@@ -58,6 +59,7 @@
mutable RefPtr<DOMPluginArray> m_plugins;
mutable RefPtr<DOMMimeTypeArray> m_mimeTypes;
mutable String m_userAgent;
+ mutable String m_platform;
};
}
Modified: trunk/Source/WebCore/page/NavigatorBase.cpp (239383 => 239384)
--- trunk/Source/WebCore/page/NavigatorBase.cpp 2018-12-19 19:58:21 UTC (rev 239383)
+++ trunk/Source/WebCore/page/NavigatorBase.cpp 2018-12-19 20:21:31 UTC (rev 239384)
@@ -100,16 +100,17 @@
return agent.substring(agent.find('/') + 1);
}
-String NavigatorBase::platform()
+const String& NavigatorBase::platform() const
{
+ static NeverDestroyed<String> defaultPlatform = WEBCORE_NAVIGATOR_PLATFORM;
#if OS(LINUX)
if (!String(WEBCORE_NAVIGATOR_PLATFORM).isEmpty())
- return WEBCORE_NAVIGATOR_PLATFORM;
+ return defaultPlatform;
struct utsname osname;
static NeverDestroyed<String> platformName(uname(&osname) >= 0 ? String(osname.sysname) + " "_str + String(osname.machine) : emptyString());
return platformName;
#else
- return WEBCORE_NAVIGATOR_PLATFORM;
+ return defaultPlatform;
#endif
}
Modified: trunk/Source/WebCore/page/NavigatorBase.h (239383 => 239384)
--- trunk/Source/WebCore/page/NavigatorBase.h 2018-12-19 19:58:21 UTC (rev 239383)
+++ trunk/Source/WebCore/page/NavigatorBase.h 2018-12-19 20:21:31 UTC (rev 239384)
@@ -43,7 +43,7 @@
static String appName();
String appVersion() const;
virtual const String& userAgent() const = 0;
- static String platform();
+ virtual const String& platform() const;
static String appCodeName();
static String product();
Modified: trunk/Source/WebKit/ChangeLog (239383 => 239384)
--- trunk/Source/WebKit/ChangeLog 2018-12-19 19:58:21 UTC (rev 239383)
+++ trunk/Source/WebKit/ChangeLog 2018-12-19 20:21:31 UTC (rev 239384)
@@ -1,3 +1,30 @@
+2018-12-19 Megan Gardner <[email protected]>
+
+ Allow clients to set the navigator platform
+ https://bugs.webkit.org/show_bug.cgi?id=192735
+
+ Reviewed by Tim Horton.
+
+ Add private API to allow clients to override the default navigator
+ platform. Some websites check for the platform, which
+ interfears with our request desktop site feature. This should
+ help more sites function as expected.
+
+ * 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 setCustomNavigatorPlatform:]):
+ (-[_WKWebsitePolicies customNavigatorPlatform]):
+ * UIProcess/Cocoa/NavigationState.mm:
+ (WebKit::NavigationState::NavigationClient::decidePolicyForNavigationAction):
+
2018-12-19 Truitt Savell <[email protected]>
Unreviewed, rolling out r239358.
Modified: trunk/Source/WebKit/Shared/WebsitePoliciesData.cpp (239383 => 239384)
--- trunk/Source/WebKit/Shared/WebsitePoliciesData.cpp 2018-12-19 19:58:21 UTC (rev 239383)
+++ trunk/Source/WebKit/Shared/WebsitePoliciesData.cpp 2018-12-19 20:21:31 UTC (rev 239384)
@@ -43,6 +43,7 @@
encoder << popUpPolicy;
encoder << websiteDataStoreParameters;
encoder << customUserAgent;
+ encoder << customNavigatorPlatform;
}
std::optional<WebsitePoliciesData> WebsitePoliciesData::decode(IPC::Decoder& decoder)
@@ -81,6 +82,11 @@
decoder >> customUserAgent;
if (!customUserAgent)
return std::nullopt;
+
+ std::optional<String> customNavigatorPlatform;
+ decoder >> customNavigatorPlatform;
+ if (!customNavigatorPlatform)
+ return std::nullopt;
return { {
WTFMove(*contentBlockersEnabled),
@@ -90,6 +96,7 @@
WTFMove(*popUpPolicy),
WTFMove(*websiteDataStoreParameters),
WTFMove(*customUserAgent),
+ WTFMove(*customNavigatorPlatform),
} };
}
@@ -97,6 +104,7 @@
{
documentLoader.setCustomHeaderFields(WTFMove(websitePolicies.customHeaderFields));
documentLoader.setCustomUserAgent(websitePolicies.customUserAgent);
+ documentLoader.setCustomNavigatorPlatform(websitePolicies.customNavigatorPlatform);
// Only setUserContentExtensionsEnabled if it hasn't already been disabled by reloading without content blockers.
if (documentLoader.userContentExtensionsEnabled())
Modified: trunk/Source/WebKit/Shared/WebsitePoliciesData.h (239383 => 239384)
--- trunk/Source/WebKit/Shared/WebsitePoliciesData.h 2018-12-19 19:58:21 UTC (rev 239383)
+++ trunk/Source/WebKit/Shared/WebsitePoliciesData.h 2018-12-19 20:21:31 UTC (rev 239384)
@@ -53,6 +53,7 @@
WebsitePopUpPolicy popUpPolicy { WebsitePopUpPolicy::Default };
std::optional<WebsiteDataStoreParameters> websiteDataStoreParameters;
String customUserAgent;
+ String customNavigatorPlatform;
void encode(IPC::Encoder&) const;
static std::optional<WebsitePoliciesData> decode(IPC::Decoder&);
Modified: trunk/Source/WebKit/UIProcess/API/APIWebsitePolicies.cpp (239383 => 239384)
--- trunk/Source/WebKit/UIProcess/API/APIWebsitePolicies.cpp 2018-12-19 19:58:21 UTC (rev 239383)
+++ trunk/Source/WebKit/UIProcess/API/APIWebsitePolicies.cpp 2018-12-19 20:21:31 UTC (rev 239384)
@@ -56,7 +56,7 @@
std::optional<WebKit::WebsiteDataStoreParameters> parameters;
if (m_websiteDataStore)
parameters = m_websiteDataStore->websiteDataStore().parameters();
- return { contentBlockersEnabled(), allowedAutoplayQuirks(), autoplayPolicy(), customHeaderFields(), popUpPolicy(), WTFMove(parameters), m_customUserAgent };
+ return { contentBlockersEnabled(), allowedAutoplayQuirks(), autoplayPolicy(), customHeaderFields(), popUpPolicy(), WTFMove(parameters), m_customUserAgent, m_customNavigatorPlatform };
}
}
Modified: trunk/Source/WebKit/UIProcess/API/APIWebsitePolicies.h (239383 => 239384)
--- trunk/Source/WebKit/UIProcess/API/APIWebsitePolicies.h 2018-12-19 19:58:21 UTC (rev 239383)
+++ trunk/Source/WebKit/UIProcess/API/APIWebsitePolicies.h 2018-12-19 20:21:31 UTC (rev 239384)
@@ -71,6 +71,9 @@
void setCustomUserAgent(const WTF::String& customUserAgent) { m_customUserAgent = customUserAgent; }
const WTF::String& customUserAgent() const { return m_customUserAgent; }
+
+ void setCustomNavigatorPlatform(const WTF::String& customNavigatorPlatform) { m_customNavigatorPlatform = customNavigatorPlatform; }
+ const WTF::String& customNavigatorPlatform() const { return m_customNavigatorPlatform; }
private:
WebsitePolicies(bool contentBlockersEnabled, OptionSet<WebKit::WebsiteAutoplayQuirk>, WebKit::WebsiteAutoplayPolicy, Vector<WebCore::HTTPHeaderField>&&, WebKit::WebsitePopUpPolicy, RefPtr<WebsiteDataStore>&&);
@@ -82,6 +85,7 @@
WebKit::WebsitePopUpPolicy m_popUpPolicy { WebKit::WebsitePopUpPolicy::Default };
RefPtr<WebsiteDataStore> m_websiteDataStore;
WTF::String m_customUserAgent;
+ WTF::String m_customNavigatorPlatform;
};
} // namespace API
Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/_WKWebsitePolicies.h (239383 => 239384)
--- trunk/Source/WebKit/UIProcess/API/Cocoa/_WKWebsitePolicies.h 2018-12-19 19:58:21 UTC (rev 239383)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/_WKWebsitePolicies.h 2018-12-19 20:21:31 UTC (rev 239384)
@@ -58,6 +58,7 @@
@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 *customNavigatorPlatform WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
@end
Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/_WKWebsitePolicies.mm (239383 => 239384)
--- trunk/Source/WebKit/UIProcess/API/Cocoa/_WKWebsitePolicies.mm 2018-12-19 19:58:21 UTC (rev 239383)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/_WKWebsitePolicies.mm 2018-12-19 20:21:31 UTC (rev 239384)
@@ -193,6 +193,16 @@
return _websitePolicies->customUserAgent();
}
+- (void)setCustomNavigatorPlatform:(NSString *)customNavigatorPlatform
+{
+ _websitePolicies->setCustomNavigatorPlatform(customNavigatorPlatform);
+}
+
+- (NSString *)customNavigatorPlatform
+{
+ return _websitePolicies->customNavigatorPlatform();
+}
+
- (NSString *)description
{
return [NSString stringWithFormat:@"<%@: %p; contentBlockersEnabled = %d>", NSStringFromClass(self.class), self, self.contentBlockersEnabled];
Modified: trunk/Source/WebKit/UIProcess/Cocoa/NavigationState.mm (239383 => 239384)
--- trunk/Source/WebKit/UIProcess/Cocoa/NavigationState.mm 2018-12-19 19:58:21 UTC (rev 239383)
+++ trunk/Source/WebKit/UIProcess/Cocoa/NavigationState.mm 2018-12-19 20:21:31 UTC (rev 239384)
@@ -549,6 +549,8 @@
}
if (!apiWebsitePolicies->customUserAgent().isNull() && subframeNavigation)
[NSException raise:NSInvalidArgumentException format:@"_WKWebsitePolicies.customUserAgent must be nil for subframe navigations."];
+ if (!apiWebsitePolicies->customNavigatorPlatform().isNull() && subframeNavigation)
+ [NSException raise:NSInvalidArgumentException format:@"_WKWebsitePolicies.customNavigatorPlatform must be nil for subframe navigations."];
}
switch (actionPolicy) {
Modified: trunk/Source/WebKitLegacy/mac/ChangeLog (239383 => 239384)
--- trunk/Source/WebKitLegacy/mac/ChangeLog 2018-12-19 19:58:21 UTC (rev 239383)
+++ trunk/Source/WebKitLegacy/mac/ChangeLog 2018-12-19 20:21:31 UTC (rev 239384)
@@ -1,3 +1,16 @@
+2018-12-19 Megan Gardner <[email protected]>
+
+ Allow clients to set the navigator platform
+ https://bugs.webkit.org/show_bug.cgi?id=192735
+
+ Reviewed by Tim Horton.
+
+ Add stubs to fill out the added functionality in FrameLoaderClient.
+
+ * WebCoreSupport/WebFrameLoaderClient.h:
+ * WebCoreSupport/WebFrameLoaderClient.mm:
+ (WebFrameLoaderClient::navigatorPlatform):
+
2018-12-17 Ryosuke Niwa <[email protected]>
offsetLeft and offsetParent should adjust across shadow boundaries
Modified: trunk/Tools/ChangeLog (239383 => 239384)
--- trunk/Tools/ChangeLog 2018-12-19 19:58:21 UTC (rev 239383)
+++ trunk/Tools/ChangeLog 2018-12-19 20:21:31 UTC (rev 239384)
@@ -1,3 +1,16 @@
+2018-12-19 Megan Gardner <[email protected]>
+
+ Allow clients to set the navigator platform
+ https://bugs.webkit.org/show_bug.cgi?id=192735
+
+ Reviewed by Tim Horton.
+
+ Add a test for setting a custom navigator platform.
+
+ * TestWebKitAPI/Tests/WebKitCocoa/WebsitePolicies.mm:
+ (-[CustomNavigatorPlatformDelegate _webView:decidePolicyForNavigationAction:userInfo:decisionHandler:]):
+ (-[CustomNavigatorPlatformDelegate webView:didFinishNavigation:]):
+
2018-12-19 Truitt Savell <[email protected]>
Unreviewed, rolling out r239358.
Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WebsitePolicies.mm (239383 => 239384)
--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WebsitePolicies.mm 2018-12-19 19:58:21 UTC (rev 239383)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WebsitePolicies.mm 2018-12-19 20:21:31 UTC (rev 239384)
@@ -983,6 +983,47 @@
loadCount = 0;
}
+@interface CustomNavigatorPlatformDelegate : NSObject <WKNavigationDelegate> {
+}
+@end
+
+@implementation CustomNavigatorPlatformDelegate
+
+- (void)_webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction userInfo:(id <NSSecureCoding>)userInfo decisionHandler:(void (^)(WKNavigationActionPolicy, _WKWebsitePolicies *))decisionHandler
+{
+ _WKWebsitePolicies *websitePolicies = [[[_WKWebsitePolicies alloc] init] autorelease];
+ if (navigationAction.targetFrame.mainFrame)
+ [websitePolicies setCustomNavigatorPlatform:@"Test Custom Platform"];
+
+ decisionHandler(WKNavigationActionPolicyAllow, websitePolicies);
+}
+
+- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation
+{
+ finishedNavigation = true;
+}
+
+@end
+
+TEST(WebKit, WebsitePoliciesCustomNavigatorPlatform)
+{
+ auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+
+ auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
+
+ auto delegate = adoptNS([[CustomNavigatorPlatformDelegate alloc] init]);
+ [webView setNavigationDelegate:delegate.get()];
+
+ NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"data:text/html,hello"]];
+ [webView loadRequest:request];
+
+ TestWebKitAPI::Util::run(&finishedNavigation);
+ finishedNavigation = false;
+
+ EXPECT_STREQ("Test Custom Platform", [[webView stringByEvaluatingJavaScript:@"navigator.platform"] UTF8String]);
+}
+
+
@interface PopUpPoliciesDelegate : NSObject <WKNavigationDelegate, WKUIDelegatePrivate>
@property (nonatomic, copy) _WKWebsitePopUpPolicy(^popUpPolicyForURL)(NSURL *);
@end