In a WKWebView app on macOS, if a page reads window.screenX/window.screenY, they get back nonsensical data. This is because UIClient::windowFrame() returns an empty rect, which we then send through coordinate-flipping code. windowFrame() needs to work for the Objective-C API.
We may have done this on purpose for privacy reasons.
diff --git a/Source/WebKit2/UIProcess/Cocoa/UIDelegate.h b/Source/WebKit2/UIProcess/Cocoa/UIDelegate.h index d9381d3d19b4f4533b02a0e04400da81f61dcb84..61fe613cbbddc7142ccb73e3aa360a4f280041fe 100644 --- a/Source/WebKit2/UIProcess/Cocoa/UIDelegate.h +++ b/Source/WebKit2/UIProcess/Cocoa/UIDelegate.h @@ -88,6 +88,7 @@ private: void runJavaScriptPrompt(WebKit::WebPageProxy*, const WTF::String&, const WTF::String&, WebKit::WebFrameProxy*, const WebCore::SecurityOriginData&, Function<void (const WTF::String&)>&& completionHandler) override; void exceededDatabaseQuota(WebPageProxy*, WebFrameProxy*, API::SecurityOrigin*, const WTF::String& databaseName, const WTF::String& displayName, unsigned long long currentQuota, unsigned long long currentOriginUsage, unsigned long long currentUsage, unsigned long long expectedUsage, Function<void (unsigned long long)>&& completionHandler) override; void reachedApplicationCacheOriginQuota(WebPageProxy*, const WebCore::SecurityOrigin&, uint64_t currentQuota, uint64_t totalBytesNeeded, Function<void (unsigned long long)>&& completionHandler) override; + WebCore::FloatRect windowFrame(WebKit::WebPageProxy*) override; #if PLATFORM(MAC) bool runOpenPanel(WebPageProxy*, WebFrameProxy*, const WebCore::SecurityOriginData&, API::OpenPanelParameters*, WebOpenPanelResultListenerProxy*) override; #endif diff --git a/Source/WebKit2/UIProcess/Cocoa/UIDelegate.mm b/Source/WebKit2/UIProcess/Cocoa/UIDelegate.mm index 4f21e823301c3c6adcd39d6ce0b077ce7c4ca5b1..3a8e3c4ce5ac1a07d386898c1ef734b9d2cd6cb6 100644 --- a/Source/WebKit2/UIProcess/Cocoa/UIDelegate.mm +++ b/Source/WebKit2/UIProcess/Cocoa/UIDelegate.mm @@ -529,6 +529,15 @@ void UIDelegate::UIClient::reachedApplicationCacheOriginQuota(WebPageProxy*, con }).get()]; } +WebCore::FloatRect UIDelegate::UIClient::windowFrame(WebKit::WebPageProxy*) +{ + WKWebView *webView = m_uiDelegate.m_webView; + if (!webView.window) + return { }; + + return webView.window.frame; +} + void UIDelegate::UIClient::printFrame(WebKit::WebPageProxy*, WebKit::WebFrameProxy* webFrameProxy) { ASSERT_ARG(webFrameProxy, webFrameProxy);
<rdar://problem/33945134>
I am coming from https://bugs.webkit.org/show_bug.cgi?id=234256 that I filed yesterday. As I mentioned there (and in my StackOverflow at https://stackoverflow.com/q/70339906) I can calculate these values on any touch event (MouseEvent.screenY - MouseEvent.clientY, or so). So, it doesn't make much sense to me that it's not returned for "privacy reasons" only until the user touches anywhere on the page (even for scrolling), just once.