RFR: 8275138: WebView: UserAgent string is empty for first request

Kevin Rushforth kcr at openjdk.java.net
Thu Oct 14 12:38:08 UTC 2021


The failure was caused by a change that was done in connection with the WebKit 610.2 update, [JDK-8259635](https://bugs.openjdk.java.net/browse/JDK-8259635). The `FrameLoaderClient::userAgent` function was changed in WebKit itself to be a const method in WebKit 610.2. We override that method in `FrameLoaderClientJava` to return the user agent string, which is done by reading the user agent from an instance of the `Page` class.  `FrameLoaderClientJava` has a `m_page` field that is lazily initialized whenever it is needed. This lazy initialization can no longer be done from the `userAgent` method, since it is `const`, as can be seen from this change that was done as part of WebKit 610.2:


--- a/modules/javafx.web/src/main/native/Source/WebKitLegacy/java/WebCoreSupport/FrameLoaderClientJava.cpp
+++ b/modules/javafx.web/src/main/native/Source/WebKitLegacy/java/WebCoreSupport/FrameLoaderClientJava.cpp
-String FrameLoaderClientJava::userAgent(const URL&)
+String FrameLoaderClientJava::userAgent(const URL&) const
 {
-    return page()->settings().userAgent();
+    if (!m_page)
+        return emptyString();
+    return m_page->settings().userAgent();
 }


Formerly, if the `m_page` field was uninitialized, FrameLoaderClient::userAgent would have initialized it by the call to the `page()` function, but since it is now `const` we can't do that. This means that the user agent string will be empty until some other method is called that initializes the `m_page` field.

The fix is to initialize that field when the `WebPage` is created. We can't do it in the constructor, since the needed reference to the `Page` class isn't yet available, so I added an `init` method that is called from `WebPage::twkInit`.

I added a new unit test that fails without the fix and passes with the fix.

-------------

Commit messages:
 - 8275138: WebView: UserAgent string is empty for first request

Changes: https://git.openjdk.java.net/jfx/pull/643/files
 Webrev: https://webrevs.openjdk.java.net/?repo=jfx&pr=643&range=00
  Issue: https://bugs.openjdk.java.net/browse/JDK-8275138
  Stats: 51 lines in 4 files changed: 33 ins; 0 del; 18 mod
  Patch: https://git.openjdk.java.net/jfx/pull/643.diff
  Fetch: git fetch https://git.openjdk.java.net/jfx pull/643/head:pull/643

PR: https://git.openjdk.java.net/jfx/pull/643


More information about the openjfx-dev mailing list