Repository navigation
feat(webview2): Add host bridge and virtual host mapping - #25594
Draft
morning4coffe-dev wants to merge 5 commits into
Draft
morning4coffe-dev wants to merge 5 commits into
morning4coffe-dev wants to merge 5 commits into
Conversation
Shared script and capability base that give native views without WebView2 (WebKit, Android, WebKitGTK) chrome.webview messaging, document-created scripts and DOMContentLoaded. No platform uses it yet.
Views that cannot intercept https can opt in with ISupportsCustomSchemeVirtualHosts; CoreWebView2 then translates uno-app:// URLs to https:// at its boundary. Without the capability nothing changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of #25395. Stacked on #25593 and #25592 (base branch
dev/doti/webview2-stackismasterplus those two PRs; this PR will be retargeted tomasteronce they merge, so only its own five commits are in the diff).Shared, platform-neutral pieces for web views that have no native
chrome.webviewand, on WebKit, cannot intercepthttps: macOS, iOS, Linux X11 and Android. No platform uses it yet; the follow-up PRs (one per platform) wire each native view to it. Nothing changes on any platform until then.What this adds (internal)
WebViewMessageBridge: builds the JavaScript that gives a pagewindow.chrome.webview(postMessage,addEventListener/removeEventListener, a hidden host entry point forPostWebMessageAsString/Json). It does nothing ifchrome.webviewalready exists, and reports DOMContentLoaded once, from the top frame, through a reserved message. The outbound channel is a parameter.ScriptBridgeWebViewCapabilities: implementsISupportsDocumentCreatedScripts,ISupportsPostWebMessageandISupportsDOMContentLoaded(from feat(webview2): Add document scripts and messaging #25592) on top of two platform primitives (evaluate a script; apply the document-start script set), with three injection modes (DocumentStart,BeforeParse,Late).WebViewVirtualHostMap+ISupportsCustomSchemeVirtualHosts: translateshttps://<virtual host>/...to a custom scheme (uno-appfor now, one constant) and back, for hosts that cannot intercepthttps.CoreWebView2applies it only when the native view opts in, at the points where URLs cross the boundary:Source,Navigate,NavigationStarting,NavigationCompleted,NewWindowRequested,WebMessageReceived.Source, theWebResourceRequestedrequest URI and its filters. Without the capability behavior is unchanged. By default the non-routable0.0.0.0/8range (what Blazor's WebView uses) counts as virtual.WebResourceResponseSnapshot: copies any response (managed or native) into status, reason, headers and body bytes.Verification
DYLD_LIBRARY_PATH=~/.nuget/packages/uno.icu-macos/<version>/runtimes/osx/native), independent of this change.WebViewMessageBridge.node.js, 8 checks pass). The repo has no JavaScript engine in the unit-test host, so it is a committed one-off and not part of the test run.SamplesApphead builds (Win32, macOS and X11 runtimes included).Open questions for review
uno-appis one constant,WebViewVirtualHostMap.NativeScheme).0.0.0.0/8rule apply only to Blazor, rather than to every app using such URLs on an opted-in platform?Origin/Refererrequest headers keep the nativeuno-app://form.CoreWebView2; frame filtering is left to each platform.