[webview_flutter_wkwebview] Add support for custom URL scheme handlers#12236
Open
brlumen wants to merge 2 commits into
Open
[webview_flutter_wkwebview] Add support for custom URL scheme handlers#12236brlumen wants to merge 2 commits into
brlumen wants to merge 2 commits into
Conversation
Adds WebKitWebViewControllerCreationParams.urlSchemeHandlers, wrapping the native WKURLSchemeHandler API to load resources for custom URL schemes on iOS and macOS. Also adds constructors for the HTTPURLResponse, URLResponse, and NSError proxy APIs, needed to respond to scheme tasks from Dart.
Contributor
There was a problem hiding this comment.
Code Review
This pull request implements support for custom URL schemes in webview_flutter_wkwebview via the native WKURLSchemeHandler API, introducing WebKitUrlSchemeHandler and WebKitUrlSchemeTask along with their native Swift delegates and Pigeon bindings. The review feedback identifies a potential memory leak in _registerUrlSchemeHandler where tasks can remain in stoppedBeforeStart indefinitely, and recommends setting _stopped to true upon task completion to safeguard against post-completion calls.
… didFinish/didFail
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.
Adds support for loading resources with custom URL schemes on iOS and macOS by wrapping the native
WKURLSchemeHandlerAPI.New public API:
WebKitWebViewControllerCreationParams.urlSchemeHandlers— a map of URL scheme to handler. Handlers are registered at creation time becauseWKWebViewConfiguration.setURLSchemeHandleronly takes effect before theWKWebViewis created.WebKitUrlSchemeHandler—onStart/onStopcallbacks receiving aWebKitUrlSchemeTask.WebKitUrlSchemeTask— exposes the requesturl/httpMethodand the reply methodsdidReceiveResponse,didReceiveData,didFinish, anddidFail.Internal changes:
WKURLSchemeHandler(Dart-implemented, modeled afterWKScriptMessageHandler) andWKURLSchemeTask;WKWebViewConfiguration.setURLSchemeHandler; constructors for the existingHTTPURLResponse,URLResponse, andNSErrorProxyApis (needed to build responses from Dart).WKURLSchemeTaskmethod after the web view has stopped the task raisesNSException. Since the stop notification inherently races in-flight platform channel calls, the native side tracks stopped tasks (via an associated object) and turns late calls into no-ops; the equivalent race on the Dart side (stop arriving while the start handler is still reading the request) is also handled.Tests:
WKWebView, stopping an in-flight task when the page is replaced (with late replies being no-ops), delivering a large (3 MB) response body via main frame navigation to a custom scheme URL, and 24 concurrent requests on one page.Example use case: an email client that rewrites
cid:inline-image references to a custom scheme and serves the bytes from its local attachment cache.WKWebViewcannot intercepthttp(s):requests, so a custom scheme handler is the platform-sanctioned counterpart of Android'sshouldInterceptRequestfor serving locally cached subresources.Part of flutter/flutter#27896 (implements the iOS/macOS side).
Pre-Review Checklist
[shared_preferences]///).Footnotes
Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling. ↩ ↩2