Skip to content

MOBILE-269: WebView cache#35

Merged
enotniy merged 4 commits into
developfrom
feature/MOBILE-269
Jul 14, 2026
Merged

MOBILE-269: WebView cache#35
enotniy merged 4 commits into
developfrom
feature/MOBILE-269

Conversation

@enotniy

@enotniy enotniy commented Jul 14, 2026

Copy link
Copy Markdown
Collaborator

justSmK and others added 3 commits July 8, 2026 12:32
MOBILE-0000: Drain in-flight evaluate callbacks before destroying the WebView

Now that destroy actually executes, it raced the learned-hosts capture queued
right before close: the evaluate had run but its result callback comes back
from the renderer asynchronously, and an immediate destroy drops it (verified
live — hosts stopped persisting). The controller now counts pending evaluate
callbacks and destroys the moment the last one lands; a timeout only bounds a
renderer that never answers.

MOBILE-0000: Pin the httpsOrigin ASCII-plus-underscore charset with tests

MOBILE-0000: Fix the never-executing WebView destroy and pin prewarm navigation

AndroidWebViewController posted all work via View.post: after onClose detaches
the view, those posts land in the view's HandlerActionQueue and never drain —
destroy() included, so every closed webview in-app leaked a live WebView with
its page JS still running. Work now posts to a main-looper Handler with an
isDestroyed latch.

Also: the deprecated shouldOverrideUrlLoading overload now treats navigations
as main-frame so the lock holds on API < 24; the prewarm engine pins its
hidden WebView to SDK-issued documents; httpsOrigin accepts '_' and rejects
non-ASCII letters (punycode is the wire format).

MOBILE-0000: Cover fragment handling and authority charset in the planner

MOBILE-0000: Harden the prewarm planner and engine after the audit

- prewarm params are inserted before a '#' in the baseUrl: appended after
  it they land in the fragment, location.search stays empty and the web
  contract silently degrades to a plain page warm;
- httpsOrigin accepts only legal host[:port] characters — origins are
  interpolated into preconnect HTML attributes and a corrupt config value
  must never become markup;
- the engine destroys the WebView in its own runCatching so a failure in
  the cosmetic cleanup cannot leak the renderer.

MOBILE-0000: Let the prewarm engine evaluate JS on its hidden WebView

Gives the owning service a way to poll page state (network idle) without
exposing the WebView itself; null result when the instance is gone or
aborted.

MOBILE-0000: Drop the legacy prewarm stub bridge

The web page's official prewarm mode ships; the stub existed only to cover pages that
predate it. Against an old page the prewarm now degrades to a plain page warm (no
byendpoint) — shows are unaffected. Validated live on both platforms with stub-less
builds against the new page.

MOBILE-0000: Cover the prewarm baseUrl contract with planner tests

MOBILE-0000: Add official prewarm params to the content-page baseUrl

The web runtime is getting an official prewarm mode: with prewarm=1&endpointId&deviceUuid
on the document URL it boots tracker-only instead of relying on the legacy SdkBridge stub.
The stub stays attached as a fallback for the current prod page and now logs its calls —
the observable signal that a page took the legacy path.

MOBILE-0000: Terminal engine abort + preconnect without baseUrl host

abort() latches synchronously so a prewarm load posted from a background thread can't recreate the WebView after a real show takes over. Preconnect origins now come from contentUrl hosts only — baseUrl is just the cache partition, typically a synthetic host, and preconnecting it wasted a DNS lookup every launch.

MOBILE-0000: Production WebView cache + config-driven prewarm primitives

Persistent cache becomes unconditional (LOAD_DEFAULT). Add InAppWebViewPrewarmPlanner (commonMain, pure: origins/preconnect page/observed-hosts probe from config urls) and InAppWebViewPrewarmEngine (androidMain: hidden WebView loading preconnect + content page with a legacy receiveParam stub bridge, no reuse). MindboxWebViewLab shrinks to throwaway measurement switches + profiler.

MOBILE-0000: WebView cache + preconnect prototype (throwaway)

Add MindboxWebViewLab (LOAD_DEFAULT cache toggle, preconnect prewarm, throwaway show-time profiler) and wire it into AndroidWebViewController. Measurement scaffolding behind compile-time flags; remove before ship.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces infrastructure for warming and reusing WebView network state (DNS/TCP/TLS + HTTP cache) for in-app WebView content, including a planner for deriving what to prewarm from config and Android-side implementations to apply cache policy and run a hidden prewarm WebView.

Changes:

  • Added InAppWebViewPrewarmPlanner (+ common tests) to derive a prewarm plan, sanitize origins, and build preconnect HTML / contract URLs.
  • Added Android InAppWebViewPrewarmEngine and webViewCacheMode() (+ android unit test) to implement prewarm execution and unify cache-mode decisions.
  • Updated Android WebView controller to support cache-mode toggle, improve destroy sequencing around evaluateJavascript, and adjust legacy shouldOverrideUrlLoading behavior.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
mindbox-common/src/commonTest/kotlin/cloud/mindbox/mobile_sdk/inapp/webview/InAppWebViewPrewarmPlannerTest.kt Adds unit tests for origin normalization, plan building, preconnect HTML, and contract URL building.
mindbox-common/src/commonMain/kotlin/cloud/mindbox/mobile_sdk/inapp/webview/InAppWebViewPrewarmPlanner.kt Adds pure planning logic for WebView prewarm: selecting a layer, collecting origins, and generating preconnect HTML / scripts.
mindbox-common/src/androidUnitTest/kotlin/cloud/mindbox/mobile_sdk/inapp/webview/WebViewCachePolicyTest.kt Tests mapping from cache toggle to WebSettings.cacheMode.
mindbox-common/src/androidMain/kotlin/cloud/mindbox/mobile_sdk/inapp/webview/WebViewCachePolicy.kt Introduces shared cache-mode policy helper for Android WebViews.
mindbox-common/src/androidMain/kotlin/cloud/mindbox/mobile_sdk/inapp/webview/WebViewAndroid.kt Adds cache toggle + logging to controller creation, sets cache mode via policy, and improves destroy/evaluateJavascript sequencing.
mindbox-common/src/androidMain/kotlin/cloud/mindbox/mobile_sdk/inapp/webview/InAppWebViewPrewarmEngine.kt Adds Android prewarm engine that loads preconnect/content pages in a hidden WebView and can be released/aborted.
mindbox-common/build.gradle.kts Adds dependencies for androidUnitTest source set.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@justSmK

justSmK commented Jul 14, 2026

Copy link
Copy Markdown
Collaborator

Тесты не запускаются - mindbox-common/build.gradle.kts:57 ссылается на libs.junit, которого нет в каталоге kmp-репо (в каталоге android-sdk он есть — поэтому в композите локально собиралось). Фикс — 2 строки в gradle/libs.versions.toml

@enotniy
enotniy force-pushed the feature/MOBILE-269 branch 2 times, most recently from 05c417c to baa10ca Compare July 14, 2026 08:31
justSmK

This comment was marked as low quality.

@enotniy
enotniy force-pushed the feature/MOBILE-269 branch from baa10ca to e7d1b91 Compare July 14, 2026 10:26
@enotniy
enotniy force-pushed the feature/MOBILE-269 branch from e7d1b91 to 2179679 Compare July 14, 2026 10:46
@enotniy
enotniy merged commit 6cfaa31 into develop Jul 14, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants