RFR: 8275138: WebView: UserAgent string is empty for first request
Ambarish Rapte
arapte at openjdk.java.net
Wed Oct 20 09:54:09 UTC 2021
On Thu, 14 Oct 2021 12:32:24 GMT, Kevin Rushforth <kcr at openjdk.org> wrote:
> 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.
looks good to me too.
-------------
Marked as reviewed by arapte (Reviewer).
PR: https://git.openjdk.java.net/jfx/pull/643
More information about the openjfx-dev
mailing list