Created WebUri class to replace Uri dart core type, fix #1402, fix #1328, fix #1350

This commit is contained in:
Lorenzo Pichilli 2022-10-27 11:02:49 +02:00
parent 52fb4b3263
commit fa5449a50d
92 changed files with 579 additions and 307 deletions

View File

@ -1,3 +1,14 @@
## 6.0.0-beta.10
- Created `WebUri` class to replace `Uri` dart core type. Related to:
- "Uri.tryParse will make the host to be lowercase" [#1402](https://github.com/pichillilorenzo/flutter_inappwebview/issues/1402)
- "An error occurs when using a specific intent" [#1328](https://github.com/pichillilorenzo/flutter_inappwebview/issues/1328)
- "Android shouldOverrideUrlLoading not working" [#1350](https://github.com/pichillilorenzo/flutter_inappwebview/issues/1350)
### BREAKING CHANGES
- Replaced the usage of `Uri` type with the new `WebUri` type
## 6.0.0-beta.9
- Added `headers`, `otherLikelyURLs`, `referrer` arguments on `ChromeSafariBrowser.open` method for Android

View File

@ -1,6 +1,5 @@
package com.pichillilorenzo.flutter_inappwebview.types;
import android.net.Uri;
import android.os.Build;
import android.webkit.WebResourceRequest;
@ -14,14 +13,14 @@ import java.util.Map;
public class WebResourceRequestExt {
@NonNull
private Uri url;
private String url;
private Map<String, String> headers;
private boolean isRedirect;
private boolean hasGesture;
private boolean isForMainFrame;
private String method;
public WebResourceRequestExt(@NonNull Uri url, Map<String, String> headers, boolean isRedirect, boolean hasGesture, boolean isForMainFrame, String method) {
public WebResourceRequestExt(@NonNull String url, Map<String, String> headers, boolean isRedirect, boolean hasGesture, boolean isForMainFrame, String method) {
this.url = url;
this.headers = headers;
this.isRedirect = isRedirect;
@ -38,7 +37,7 @@ public class WebResourceRequestExt {
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
isRedirect = request.isRedirect();
}
return new WebResourceRequestExt(request.getUrl(),
return new WebResourceRequestExt(request.getUrl().toString(),
request.getRequestHeaders(),
isRedirect,
request.hasGesture(),
@ -49,7 +48,7 @@ public class WebResourceRequestExt {
public Map<String, Object> toMap() {
Map<String, Object> webResourceRequestMap = new HashMap<>();
webResourceRequestMap.put("url", url.toString());
webResourceRequestMap.put("url", url);
webResourceRequestMap.put("headers", headers);
webResourceRequestMap.put("isRedirect", isRedirect);
webResourceRequestMap.put("hasGesture", hasGesture);
@ -59,11 +58,11 @@ public class WebResourceRequestExt {
}
@NonNull
public Uri getUrl() {
public String getUrl() {
return url;
}
public void setUrl(@NonNull Uri url) {
public void setUrl(@NonNull String url) {
this.url = url;
}

View File

@ -307,7 +307,7 @@ public class InAppWebViewClient extends WebViewClient {
}
WebResourceRequestExt request = new WebResourceRequestExt(
Uri.parse(failingUrl),
failingUrl,
null,
false,
false,
@ -627,7 +627,8 @@ public class InAppWebViewClient extends WebViewClient {
if (webView.webViewAssetLoaderExt != null && webView.webViewAssetLoaderExt.loader != null) {
try {
WebResourceResponse webResourceResponse = webView.webViewAssetLoaderExt.loader.shouldInterceptRequest(request.getUrl());
final Uri uri = Uri.parse(request.getUrl());
WebResourceResponse webResourceResponse = webView.webViewAssetLoaderExt.loader.shouldInterceptRequest(uri);
if (webResourceResponse != null) {
return webResourceResponse;
}
@ -667,8 +668,11 @@ public class InAppWebViewClient extends WebViewClient {
return null;
}
final String url = request.getUrl().toString();
String scheme = request.getUrl().getScheme();
final String url = request.getUrl();
String scheme = url.split(":")[0].toLowerCase();
try {
scheme = Uri.parse(request.getUrl()).getScheme();
} catch (Exception ignored) {}
if (webView.customSettings.resourceCustomSchemes != null && webView.customSettings.resourceCustomSchemes.contains(scheme)) {
CustomSchemeResponse customSchemeResponse = null;
@ -710,7 +714,7 @@ public class InAppWebViewClient extends WebViewClient {
@Override
public WebResourceResponse shouldInterceptRequest(WebView view, final String url) {
WebResourceRequestExt requestExt = new WebResourceRequestExt(
Uri.parse(url), null, false,
url, null, false,
false, true, "GET"
);
return shouldInterceptRequest(view, requestExt);

View File

@ -257,6 +257,13 @@ class ExchangeableObjectGenerator
} else if (hasFromValue && deprecatedHasToValue) {
classBuffer.write(fieldTypeElement.name!.replaceFirst("_", "") +
'.fromValue($deprecatedFieldName${deprecatedIsNullable ? '?' : ''}.toValue())${!isNullable ? '!' : ''}');
} else if (deprecatedField.type.getDisplayString(withNullability: false) == "Uri" &&
fieldElement.type.getDisplayString(withNullability: false) == "WebUri") {
if (deprecatedIsNullable) {
classBuffer.write("($deprecatedFieldName != null ? WebUri.uri($deprecatedFieldName!) : ${isNullable ? "null" : "WebUri('')"})");
} else {
classBuffer.write("WebUri.uri($deprecatedFieldName)");
}
} else {
classBuffer.write(deprecatedFieldName);
}
@ -496,6 +503,12 @@ class ExchangeableObjectGenerator
} else {
return "$value != null ? Uri.tryParse($value) : null";
}
} else if (elementType.getDisplayString(withNullability: false) == "WebUri") {
if (!isNullable) {
return "WebUri($value)";
} else {
return "$value != null ? WebUri($value) : null";
}
} else if (elementType.getDisplayString(withNullability: false) ==
"Color") {
if (!isNullable) {
@ -573,6 +586,8 @@ class ExchangeableObjectGenerator
final isNullable = Util.typeIsNullable(elementType);
if (elementType.getDisplayString(withNullability: false) == "Uri") {
return fieldName + (isNullable ? '?' : '') + '.toString()';
} else if (elementType.getDisplayString(withNullability: false) == "WebUri") {
return fieldName + (isNullable ? '?' : '') + '.toString()';
} else if (elementType.getDisplayString(withNullability: false) ==
"Color") {
return fieldName + (isNullable ? '?' : '') + '.toHex()';

View File

@ -20,7 +20,7 @@ void customTabs() {
await chromeSafariBrowser.open(
url: TEST_URL_1,
referrer: Uri.parse("android-app://custom-referrer"),
referrer: WebUri("android-app://custom-referrer"),
settings: ChromeSafariBrowserSettings(isSingleInstance: true));
await expectLater(chromeSafariBrowser.opened.future, completes);
expect(chromeSafariBrowser.isOpened(), true);

View File

@ -39,7 +39,7 @@ void openAndClose() {
presentationStyle: ModalPresentationStyle.OVER_FULL_SCREEN,
eventAttribution: UIEventAttribution(
sourceIdentifier: 4,
destinationURL: Uri.parse("https://shop.example/test.html"),
destinationURL: WebUri("https://shop.example/test.html"),
sourceDescription: "Banner ad for Test.",
purchaser: "Shop Example, Inc."),
activityButton: ActivityButton(

View File

@ -1,28 +1,30 @@
final TEST_URL_ABOUT_BLANK = Uri.parse('about:blank');
final TEST_CROSS_PLATFORM_URL_1 = Uri.parse('https://flutter.dev/');
final TEST_CROSS_PLATFORM_URL_2 = Uri.parse('https://www.bing.com/');
final TEST_URL_1 = Uri.parse('https://github.com/flutter');
final TEST_URL_2 = Uri.parse('https://www.google.com/');
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
final TEST_URL_ABOUT_BLANK = WebUri('about:blank');
final TEST_CROSS_PLATFORM_URL_1 = WebUri('https://flutter.dev/');
final TEST_CROSS_PLATFORM_URL_2 = WebUri('https://www.bing.com/');
final TEST_URL_1 = WebUri('https://github.com/flutter');
final TEST_URL_2 = WebUri('https://www.google.com/');
final TEST_URL_3 =
Uri.parse('https://github.com/pichillilorenzo/flutter_inappwebview');
final TEST_URL_4 = Uri.parse('https://www.youtube.com/');
final TEST_URL_EXAMPLE = Uri.parse('https://www.example.com/');
final TEST_URL_HTTP_EXAMPLE = Uri.parse('http://www.example.com/');
final TEST_URL_404 = Uri.parse('https://google.com/404');
WebUri('https://github.com/pichillilorenzo/flutter_inappwebview');
final TEST_URL_4 = WebUri('https://www.youtube.com/');
final TEST_URL_EXAMPLE = WebUri('https://www.example.com/');
final TEST_URL_HTTP_EXAMPLE = WebUri('http://www.example.com/');
final TEST_URL_404 = WebUri('https://google.com/404');
final TEST_WEB_PLATFORM_BASE_URL =
Uri.parse(Uri.base.toString().replaceFirst("/#/", "/"));
WebUri(Uri.base.toString().replaceFirst("/#/", "/"));
final TEST_WEB_PLATFORM_URL_1 =
Uri.parse(TEST_WEB_PLATFORM_BASE_URL.toString() + 'page.html');
WebUri(TEST_WEB_PLATFORM_BASE_URL.toString() + 'page.html');
final TEST_WEB_PLATFORM_URL_2 =
Uri.parse(TEST_WEB_PLATFORM_BASE_URL.toString() + 'page-2.html');
WebUri(TEST_WEB_PLATFORM_BASE_URL.toString() + 'page-2.html');
final TEST_WEB_PLATFORM_URL_3 =
Uri.parse(TEST_WEB_PLATFORM_BASE_URL.toString() + 'heavy-page.html');
final TEST_NOT_A_WEBSITE_URL = Uri.parse('https://www.notawebsite..com/');
WebUri(TEST_WEB_PLATFORM_BASE_URL.toString() + 'heavy-page.html');
final TEST_NOT_A_WEBSITE_URL = WebUri('https://www.notawebsite..com/');
final TEST_CHROME_SAFE_BROWSING_MALWARE =
Uri.parse('chrome://safe-browsing/match?type=malware');
final TEST_PERMISSION_SITE = Uri.parse('https://permission.site/');
final TEST_SERVICE_WORKER_URL = Uri.parse(
WebUri('chrome://safe-browsing/match?type=malware');
final TEST_PERMISSION_SITE = WebUri('https://permission.site/');
final TEST_SERVICE_WORKER_URL = WebUri(
'https://mdn.github.io/dom-examples/service-worker/simple-service-worker/');
final TEST_WEBVIEW_ASSET_LOADER_DOMAIN = 'my.custom.domain.com';
final TEST_WEBVIEW_ASSET_LOADER_URL = Uri.parse(
final TEST_WEBVIEW_ASSET_LOADER_URL = WebUri(
'https://$TEST_WEBVIEW_ASSET_LOADER_DOMAIN/assets/flutter_assets/assets/website/index.html');

View File

@ -55,7 +55,7 @@ void setGetDelete() {
);
}
final url = Uri.parse(await pageLoaded.future);
final url = WebUri(await pageLoaded.future);
await cookieManager.setCookie(url: url, name: "myCookie", value: "myValue");
List<Cookie> cookies = await cookieManager.getCookies(url: url);

View File

@ -22,7 +22,7 @@ void loadAssetFile(InAppLocalhostServer localhostServer) {
var headlessWebView = new HeadlessInAppWebView(
initialUrlRequest: URLRequest(
url: Uri.parse('http://localhost:8080/test_assets/index.html')),
url: WebUri('http://localhost:8080/test_assets/index.html')),
onWebViewCreated: (controller) {
controllerCompleter.complete(controller);
},
@ -37,7 +37,7 @@ void loadAssetFile(InAppLocalhostServer localhostServer) {
child: InAppWebView(
key: GlobalKey(),
initialUrlRequest: URLRequest(
url: Uri.parse('http://localhost:8080/test_assets/index.html')),
url: WebUri('http://localhost:8080/test_assets/index.html')),
onWebViewCreated: (controller) {
controllerCompleter.complete(controller);
},

View File

@ -60,7 +60,7 @@ void audioPlaybackPolicy() {
child: InAppWebView(
key: GlobalKey(),
initialUrlRequest: URLRequest(
url: Uri.parse(
url: WebUri(
'data:text/html;charset=utf-8;base64,$audioTestBase64')),
onWebViewCreated: (controller) {
controllerCompleter.complete(controller);
@ -96,7 +96,7 @@ void audioPlaybackPolicy() {
child: InAppWebView(
key: GlobalKey(),
initialUrlRequest: URLRequest(
url: Uri.parse(
url: WebUri(
'data:text/html;charset=utf-8;base64,$audioTestBase64')),
onWebViewCreated: (controller) {
controllerCompleter.complete(controller);

View File

@ -29,7 +29,7 @@ void getTitle() {
base64Encode(const Utf8Encoder().convert(getTitleTest));
var url = !kIsWeb
? Uri.parse('data:text/html;charset=utf-8;base64,$getTitleTestBase64')
? WebUri('data:text/html;charset=utf-8;base64,$getTitleTestBase64')
: TEST_WEB_PLATFORM_URL_1;
var expectedValue = !kIsWeb ? 'Some title' : 'page';

View File

@ -39,8 +39,7 @@ void httpAuthCredentialDatabase() {
child: InAppWebView(
key: GlobalKey(),
initialUrlRequest: URLRequest(
url:
Uri.parse("http://${environment["NODE_SERVER_IP"]}:8081/")),
url: WebUri("http://${environment["NODE_SERVER_IP"]}:8081/")),
onWebViewCreated: (controller) {
controllerCompleter.complete(controller);
},
@ -95,8 +94,7 @@ void httpAuthCredentialDatabase() {
child: InAppWebView(
key: GlobalKey(),
initialUrlRequest: URLRequest(
url:
Uri.parse("http://${environment["NODE_SERVER_IP"]}:8081/")),
url: WebUri("http://${environment["NODE_SERVER_IP"]}:8081/")),
onWebViewCreated: (controller) {
controllerCompleter.complete(controller);
},

View File

@ -84,7 +84,7 @@ void injectCSS() {
await pageLoaded.future;
await controller.injectCSSFileFromUrl(
urlFile: Uri.parse(
urlFile: WebUri(
'https://getbootstrap.com/docs/4.3/dist/css/bootstrap.min.css'),
cssLinkHtmlTagAttributes: CSSLinkHtmlTagAttributes(id: 'bootstrap'));
await Future.delayed(Duration(seconds: 2));

View File

@ -47,8 +47,7 @@ void injectJavascriptFile() {
await pageLoaded.future;
await controller.injectJavascriptFileFromUrl(
urlFile:
Uri.parse('https://www.notawebsite..com/jquery-3.3.1.min.js'),
urlFile: WebUri('https://www.notawebsite..com/jquery-3.3.1.min.js'),
scriptHtmlTagAttributes: ScriptHtmlTagAttributes(
id: 'jquery-error',
onError: () {
@ -65,7 +64,7 @@ void injectJavascriptFile() {
true);
await controller.injectJavascriptFileFromUrl(
urlFile: Uri.parse('https://code.jquery.com/jquery-3.3.1.min.js'),
urlFile: WebUri('https://code.jquery.com/jquery-3.3.1.min.js'),
scriptHtmlTagAttributes: ScriptHtmlTagAttributes(
id: 'jquery',
onLoad: () {

View File

@ -46,7 +46,7 @@ void isSecureContext() {
if (!kIsWeb) {
await controller.loadUrl(
urlRequest: URLRequest(url: Uri.parse('http://example.com/')));
urlRequest: URLRequest(url: WebUri('http://example.com/')));
await pageLoads.stream.first;
expect(await controller.isSecureContext(), false);
}

View File

@ -63,7 +63,7 @@ void loadFileUrl() {
child: InAppWebView(
key: GlobalKey(),
initialUrlRequest:
URLRequest(url: Uri.parse('file://${fileHtml.path}')),
URLRequest(url: WebUri('file://${fileHtml.path}')),
onConsoleMessage: (controller, consoleMessage) {
consoleMessageShouldNotComplete.complete(consoleMessage);
},
@ -82,10 +82,9 @@ void loadFileUrl() {
child: InAppWebView(
key: GlobalKey(),
initialUrlRequest:
URLRequest(url: Uri.parse('file://${fileHtml.path}')),
URLRequest(url: WebUri('file://${fileHtml.path}')),
initialSettings: InAppWebViewSettings(
allowingReadAccessTo:
Uri.parse('file://${appSupportDir.path}/')),
allowingReadAccessTo: WebUri('file://${appSupportDir.path}/')),
onConsoleMessage: (controller, consoleMessage) {
consoleMessageCompleter.complete(consoleMessage);
},
@ -110,7 +109,7 @@ void loadFileUrl() {
onWebViewCreated: (controller) {
controller.loadUrl(
urlRequest:
URLRequest(url: Uri.parse('file://${fileHtml.path}')));
URLRequest(url: WebUri('file://${fileHtml.path}')));
},
onConsoleMessage: (controller, consoleMessage) {
consoleMessageShouldNotComplete.complete(consoleMessage);
@ -132,9 +131,9 @@ void loadFileUrl() {
onWebViewCreated: (controller) {
controller.loadUrl(
urlRequest:
URLRequest(url: Uri.parse('file://${fileHtml.path}')),
URLRequest(url: WebUri('file://${fileHtml.path}')),
allowingReadAccessTo:
Uri.parse('file://${appSupportDir.path}/'));
WebUri('file://${appSupportDir.path}/'));
},
onConsoleMessage: (controller, consoleMessage) {
consoleMessageCompleter.complete(consoleMessage);

View File

@ -53,7 +53,7 @@ void onReceivedError() {
child: InAppWebView(
key: GlobalKey(),
initialUrlRequest: URLRequest(
url: Uri.parse(
url: WebUri(
'data:text/html;charset=utf-8;base64,PCFET0NUWVBFIGh0bWw+')),
onReceivedError: (controller, request, error) {
onReceivedErrorCompleter.complete();

View File

@ -30,7 +30,7 @@ void postRequests() {
child: InAppWebView(
key: GlobalKey(),
initialUrlRequest: URLRequest(
url: Uri.parse(
url: WebUri(
"http://${environment["NODE_SERVER_IP"]}:8082/test-post"),
method: 'POST',
body: Uint8List.fromList(utf8.encode("name=FooBar")),
@ -68,7 +68,7 @@ void postRequests() {
textDirection: TextDirection.ltr,
child: InAppWebView(
key: GlobalKey(),
initialUrlRequest: URLRequest(url: Uri.parse('about:blank')),
initialUrlRequest: URLRequest(url: WebUri('about:blank')),
onWebViewCreated: (controller) {
controllerCompleter.complete(controller);
},
@ -87,7 +87,7 @@ void postRequests() {
var postData = Uint8List.fromList(utf8.encode("name=FooBar"));
await controller.loadUrl(
urlRequest: URLRequest(
url: Uri.parse(
url: WebUri(
"http://${environment["NODE_SERVER_IP"]}:8082/test-post"),
method: 'POST',
body: postData,
@ -114,7 +114,7 @@ void postRequests() {
textDirection: TextDirection.ltr,
child: InAppWebView(
key: GlobalKey(),
initialUrlRequest: URLRequest(url: Uri.parse('about:blank')),
initialUrlRequest: URLRequest(url: WebUri('about:blank')),
onWebViewCreated: (controller) {
controllerCompleter.complete(controller);
},
@ -132,8 +132,7 @@ void postRequests() {
var postData = Uint8List.fromList(utf8.encode("name=FooBar"));
await controller.postUrl(
url: Uri.parse(
"http://${environment["NODE_SERVER_IP"]}:8082/test-post"),
url: WebUri("http://${environment["NODE_SERVER_IP"]}:8082/test-post"),
postData: postData);
await postPageLoaded.future;

View File

@ -52,8 +52,7 @@ void programmaticScroll() {
base64Encode(const Utf8Encoder().convert(scrollTestPage));
var url = !kIsWeb
? Uri.parse(
'data:text/html;charset=utf-8;base64,$scrollTestPageBase64')
? WebUri('data:text/html;charset=utf-8;base64,$scrollTestPageBase64')
: TEST_WEB_PLATFORM_URL_1;
final Completer<void> pageLoaded = Completer<void>();
@ -143,7 +142,7 @@ void programmaticScroll() {
textDirection: TextDirection.ltr,
child: InAppWebView(
initialUrlRequest: URLRequest(
url: Uri.parse(
url: WebUri(
'data:text/html;charset=utf-8;base64,$scrollTestPageBase64')),
onWebViewCreated: (controller) {
controllerCompleter.complete(controller);

View File

@ -103,8 +103,7 @@ void programmaticZoomScale() {
textDirection: TextDirection.ltr,
child: InAppWebView(
key: GlobalKey(),
initialUrlRequest:
URLRequest(url: Uri.parse('https://flutter.dev')),
initialUrlRequest: URLRequest(url: WebUri('https://flutter.dev')),
onWebViewCreated: (controller) {
controllerCompleter.complete(controller);
},
@ -133,8 +132,7 @@ void programmaticZoomScale() {
textDirection: TextDirection.ltr,
child: InAppWebView(
key: GlobalKey(),
initialUrlRequest:
URLRequest(url: Uri.parse('https://flutter.dev')),
initialUrlRequest: URLRequest(url: WebUri('https://flutter.dev')),
onWebViewCreated: (controller) {
controllerCompleter.complete(controller);
},

View File

@ -44,8 +44,7 @@ void resizeWebView() {
final InAppWebView webView = InAppWebView(
key: key,
initialUrlRequest: URLRequest(
url: Uri.parse(
'data:text/html;charset=utf-8;base64,$resizeTestBase64')),
url: WebUri('data:text/html;charset=utf-8;base64,$resizeTestBase64')),
onWebViewCreated: (controller) {
controllerCompleter.complete(controller);

View File

@ -33,7 +33,7 @@ void shouldOverrideUrlLoading() {
textDirection: TextDirection.ltr,
child: InAppWebView(
key: GlobalKey(),
initialUrlRequest: URLRequest(url: Uri.parse(pageEncoded)),
initialUrlRequest: URLRequest(url: WebUri(pageEncoded)),
onWebViewCreated: (controller) {
controllerCompleter.complete(controller);
},
@ -86,7 +86,7 @@ void shouldOverrideUrlLoading() {
textDirection: TextDirection.ltr,
child: InAppWebView(
key: GlobalKey(),
initialUrlRequest: URLRequest(url: Uri.parse(pageEncoded)),
initialUrlRequest: URLRequest(url: WebUri(pageEncoded)),
onWebViewCreated: (controller) {
controllerCompleter.complete(controller);
},
@ -145,7 +145,7 @@ void shouldOverrideUrlLoading() {
textDirection: TextDirection.ltr,
child: InAppWebView(
key: GlobalKey(),
initialUrlRequest: URLRequest(url: Uri.parse(pageEncoded)),
initialUrlRequest: URLRequest(url: WebUri(pageEncoded)),
onWebViewCreated: (controller) {
controllerCompleter.complete(controller);
},
@ -197,7 +197,7 @@ void shouldOverrideUrlLoading() {
textDirection: TextDirection.ltr,
child: InAppWebView(
key: GlobalKey(),
initialUrlRequest: URLRequest(url: Uri.parse(pageEncoded)),
initialUrlRequest: URLRequest(url: WebUri(pageEncoded)),
onWebViewCreated: (controller) {
controllerCompleter.complete(controller);
},

View File

@ -26,7 +26,7 @@ void sslRequest() {
child: InAppWebView(
key: GlobalKey(),
initialUrlRequest: URLRequest(
url: Uri.parse("https://${environment["NODE_SERVER_IP"]}:4433/")),
url: WebUri("https://${environment["NODE_SERVER_IP"]}:4433/")),
onWebViewCreated: (controller) {
controllerCompleter.complete(controller);
},

View File

@ -68,7 +68,7 @@ void videoPlaybackPolicy() {
child: InAppWebView(
key: GlobalKey(),
initialUrlRequest: URLRequest(
url: Uri.parse(
url: WebUri(
'data:text/html;charset=utf-8;base64,$videoTestBase64')),
onWebViewCreated: (controller) {
controllerCompleter.complete(controller);
@ -99,7 +99,7 @@ void videoPlaybackPolicy() {
child: InAppWebView(
key: GlobalKey(),
initialUrlRequest: URLRequest(
url: Uri.parse(
url: WebUri(
'data:text/html;charset=utf-8;base64,$videoTestBase64')),
onWebViewCreated: (controller) {
controllerCompleter.complete(controller);
@ -141,7 +141,7 @@ void videoPlaybackPolicy() {
child: InAppWebView(
key: GlobalKey(),
initialUrlRequest: URLRequest(
url: Uri.parse(
url: WebUri(
'data:text/html;charset=utf-8;base64,$videoTestBase64')),
onWebViewCreated: (controller) {
controllerCompleter.complete(controller);
@ -185,7 +185,7 @@ void videoPlaybackPolicy() {
child: InAppWebView(
key: GlobalKey(),
initialUrlRequest: URLRequest(
url: Uri.parse(
url: WebUri(
'data:text/html;charset=utf-8;base64,$videoTestBase64')),
onWebViewCreated: (controller) {
controllerCompleter.complete(controller);
@ -230,7 +230,7 @@ void videoPlaybackPolicy() {
child: InAppWebView(
key: GlobalKey(),
initialUrlRequest: URLRequest(
url: Uri.parse(
url: WebUri(
'data:text/html;charset=utf-8;base64,$videoTestBase64')),
onWebViewCreated: (controller) {
controllerCompleter.complete(controller);

View File

@ -72,7 +72,7 @@ void webMessage() {
});
await controller.postWebMessage(
message: WebMessage(data: "capturePort", ports: [port2]),
targetOrigin: Uri.parse("*"));
targetOrigin: WebUri("*"));
await controller.evaluateJavascript(
source: "document.getElementById('button').click();");
},

View File

@ -278,7 +278,7 @@ void webViewWindows() {
child: InAppWebView(
key: GlobalKey(),
initialUrlRequest: URLRequest(
url: Uri.parse(
url: WebUri(
'data:text/html;charset=utf-8;base64,$openWindowTestBase64')),
onWebViewCreated: (controller) {
controllerCompleter.complete(controller);

View File

@ -44,7 +44,7 @@ class MyInAppBrowser extends InAppBrowser {
}
@override
void onLoadStop(Uri? url) {
void onLoadStop(WebUri? url) {
super.onLoadStop(url);
if (!firstPageLoaded.isCompleted) {

View File

@ -78,7 +78,7 @@ class _ChromeSafariBrowserExampleScreenState
child: ElevatedButton(
onPressed: () async {
await widget.browser.open(
url: Uri.parse("https://flutter.dev/"),
url: WebUri("https://flutter.dev/"),
settings: ChromeSafariBrowserSettings(
shareState: CustomTabsShareState.SHARE_STATE_OFF,
isSingleInstance: false,

View File

@ -20,8 +20,8 @@ class _HeadlessInAppWebViewExampleScreenState
super.initState();
var url = !kIsWeb
? Uri.parse("https://flutter.dev")
: Uri.parse("http://localhost:${Uri.base.port}/page.html");
? WebUri("https://flutter.dev")
: WebUri("http://localhost:${Uri.base.port}/page.html");
headlessWebView = new HeadlessInAppWebView(
initialUrlRequest: URLRequest(url: url),

View File

@ -109,7 +109,7 @@ class _InAppBrowserExampleScreenState extends State<InAppBrowserExampleScreen> {
onPressed: () async {
await widget.browser.openUrlRequest(
urlRequest:
URLRequest(url: Uri.parse("https://flutter.dev")),
URLRequest(url: WebUri("https://flutter.dev")),
settings: InAppBrowserClassSettings(
browserSettings: InAppBrowserSettings(
toolbarTopBackgroundColor: Colors.blue,
@ -126,7 +126,7 @@ class _InAppBrowserExampleScreenState extends State<InAppBrowserExampleScreen> {
ElevatedButton(
onPressed: () async {
await InAppBrowser.openWithSystemBrowser(
url: Uri.parse("https://flutter.dev/"));
url: WebUri("https://flutter.dev/"));
},
child: Text("Open System Browser")),
])));

View File

@ -99,9 +99,9 @@ class _InAppWebViewExampleScreenState extends State<InAppWebViewExampleScreen> {
controller: urlController,
keyboardType: TextInputType.text,
onSubmitted: (value) {
var url = Uri.parse(value);
var url = WebUri(value);
if (url.scheme.isEmpty) {
url = Uri.parse((!kIsWeb
url = WebUri((!kIsWeb
? "https://www.google.com/search?q="
: "https://www.bing.com/search?q=") +
value);
@ -115,9 +115,9 @@ class _InAppWebViewExampleScreenState extends State<InAppWebViewExampleScreen> {
InAppWebView(
key: webViewKey,
initialUrlRequest:
URLRequest(url: Uri.parse('https://flutter.dev')),
URLRequest(url: WebUri('https://flutter.dev')),
// initialUrlRequest:
// URLRequest(url: Uri.parse(Uri.base.toString().replaceFirst("/#/", "/") + 'page.html')),
// URLRequest(url: WebUri(Uri.base.toString().replaceFirst("/#/", "/") + 'page.html')),
// initialFile: "assets/index.html",
initialUserScripts: UnmodifiableListView<UserScript>([]),
initialSettings: settings,

View File

@ -10,10 +10,12 @@ import 'package:flutter_inappwebview_example/in_app_webiew_example.screen.dart';
import 'package:flutter_inappwebview_example/in_app_browser_example.screen.dart';
import 'package:flutter_inappwebview_example/web_authentication_session_example.screen.dart';
import 'package:pointer_interceptor/pointer_interceptor.dart';
// import 'package:path_provider/path_provider.dart';
// import 'package:permission_handler/permission_handler.dart';
InAppLocalhostServer localhostServer = new InAppLocalhostServer(documentRoot: 'assets');
InAppLocalhostServer localhostServer =
new InAppLocalhostServer(documentRoot: 'assets');
Future main() async {
WidgetsFlutterBinding.ensureInitialized();
@ -148,14 +150,16 @@ class _MyAppState extends State<MyApp> {
return MaterialApp(initialRoute: '/', routes: {
'/': (context) => InAppWebViewExampleScreen(),
});
}
}f
if (defaultTargetPlatform == TargetPlatform.macOS) {
return MaterialApp(initialRoute: '/', routes: {
// '/': (context) => InAppWebViewExampleScreen(),
// '/InAppBrowser': (context) => InAppBrowserExampleScreen(),
'/': (context) => InAppBrowserExampleScreen(),
'/HeadlessInAppWebView': (context) => HeadlessInAppWebViewExampleScreen(),
'/WebAuthenticationSession': (context) => WebAuthenticationSessionExampleScreen(),
'/HeadlessInAppWebView': (context) =>
HeadlessInAppWebViewExampleScreen(),
'/WebAuthenticationSession': (context) =>
WebAuthenticationSessionExampleScreen(),
});
}
return MaterialApp(initialRoute: '/', routes: {
@ -163,7 +167,8 @@ class _MyAppState extends State<MyApp> {
'/InAppBrowser': (context) => InAppBrowserExampleScreen(),
'/ChromeSafariBrowser': (context) => ChromeSafariBrowserExampleScreen(),
'/HeadlessInAppWebView': (context) => HeadlessInAppWebViewExampleScreen(),
'/WebAuthenticationSession': (context) => WebAuthenticationSessionExampleScreen(),
'/WebAuthenticationSession': (context) =>
WebAuthenticationSessionExampleScreen(),
});
}
}

View File

@ -52,7 +52,7 @@ class _WebAuthenticationSessionExampleScreenState
.contains(defaultTargetPlatform) &&
await WebAuthenticationSession.isAvailable()) {
session = await WebAuthenticationSession.create(
url: Uri.parse(
url: WebUri(
"http://localhost:8080/web-auth.html"),
callbackURLScheme: "test",
onComplete: (url, error) async {

View File

@ -12,6 +12,7 @@ import '../types/ui_image.dart';
import '../util.dart';
import '../debug_logging_settings.dart';
import '../web_uri.dart';
import 'chrome_safari_browser_settings.dart';
class ChromeSafariBrowserAlreadyOpenedException implements Exception {
@ -103,7 +104,7 @@ class ChromeSafariBrowser {
break;
case "onInitialLoadDidRedirect":
final String? url = call.arguments["url"];
final Uri? uri = url != null ? Uri.tryParse(url) : null;
final WebUri? uri = url != null ? WebUri(url) : null;
onInitialLoadDidRedirect(uri);
break;
case "onNavigationEvent":
@ -115,7 +116,7 @@ class ChromeSafariBrowser {
final relation =
CustomTabsRelationType.fromNativeValue(call.arguments["relation"]);
final requestedOrigin = call.arguments["requestedOrigin"] != null
? Uri.tryParse(call.arguments["requestedOrigin"])
? WebUri(call.arguments["requestedOrigin"])
: null;
final bool result = call.arguments["result"];
onRelationshipValidationResult(relation, requestedOrigin, result);
@ -136,22 +137,22 @@ class ChromeSafariBrowser {
this._actionButton?.action!(url, title);
}
if (this._actionButton?.onClick != null) {
this._actionButton?.onClick!(Uri.tryParse(url), title);
this._actionButton?.onClick!(WebUri(url), title);
}
} else if (this._menuItems[id] != null) {
if (this._menuItems[id]?.action != null) {
this._menuItems[id]?.action!(url, title);
}
if (this._menuItems[id]?.onClick != null) {
this._menuItems[id]?.onClick!(Uri.tryParse(url), title);
this._menuItems[id]?.onClick!(WebUri(url), title);
}
}
break;
case "onSecondaryItemActionPerform":
final clickableIDs = this._secondaryToolbar?.clickableIDs;
if (clickableIDs != null) {
Uri? url = call.arguments["url"] != null
? Uri.tryParse(call.arguments["url"])
WebUri? url = call.arguments["url"] != null
? WebUri(call.arguments["url"])
: null;
String name = call.arguments["name"];
for (final clickable in clickableIDs) {
@ -199,10 +200,10 @@ class ChromeSafariBrowser {
///- Android
///- iOS
Future<void> open(
{Uri? url,
{WebUri? url,
Map<String, String>? headers,
List<Uri>? otherLikelyURLs,
Uri? referrer,
List<WebUri>? otherLikelyURLs,
WebUri? referrer,
@Deprecated('Use settings instead')
// ignore: deprecated_member_use_from_same_package
ChromeSafariBrowserClassOptions? options,
@ -257,10 +258,10 @@ class ChromeSafariBrowser {
///**Supported Platforms/Implementations**:
///- Android
Future<void> launchUrl({
required Uri url,
required WebUri url,
Map<String, String>? headers,
List<Uri>? otherLikelyURLs,
Uri? referrer,
List<WebUri>? otherLikelyURLs,
WebUri? referrer,
}) async {
Map<String, dynamic> args = <String, dynamic>{};
args.putIfAbsent('url', () => url.toString());
@ -283,7 +284,8 @@ class ChromeSafariBrowser {
///
///**Supported Platforms/Implementations**:
///- Android ([Official API - CustomTabsSession.mayLaunchUrl](https://developer.android.com/reference/androidx/browser/customtabs/CustomTabsSession#mayLaunchUrl(android.net.Uri,android.os.Bundle,java.util.List%3Candroid.os.Bundle%3E)))
Future<bool> mayLaunchUrl({Uri? url, List<Uri>? otherLikelyURLs}) async {
Future<bool> mayLaunchUrl(
{WebUri? url, List<WebUri>? otherLikelyURLs}) async {
Map<String, dynamic> args = <String, dynamic>{};
args.putIfAbsent('url', () => url?.toString());
args.putIfAbsent('otherLikelyURLs',
@ -308,7 +310,8 @@ class ChromeSafariBrowser {
///**Supported Platforms/Implementations**:
///- Android ([Official API - CustomTabsSession.validateRelationship](https://developer.android.com/reference/androidx/browser/customtabs/CustomTabsSession#validateRelationship(int,android.net.Uri,android.os.Bundle)))
Future<bool> validateRelationship(
{required CustomTabsRelationType relation, required Uri origin}) async {
{required CustomTabsRelationType relation,
required WebUri origin}) async {
Map<String, dynamic> args = <String, dynamic>{};
args.putIfAbsent('relation', () => relation.toNativeValue());
args.putIfAbsent('origin', () => origin.toString());
@ -453,7 +456,7 @@ class ChromeSafariBrowser {
///
///**Supported Platforms/Implementations**:
///- iOS ([Official API - SFSafariViewController.prewarmConnections](https://developer.apple.com/documentation/safariservices/sfsafariviewcontroller/3752133-prewarmconnections))
static Future<PrewarmingToken?> prewarmConnections(List<Uri> URLs) async {
static Future<PrewarmingToken?> prewarmConnections(List<WebUri> URLs) async {
Map<String, dynamic> args = <String, dynamic>{};
args.putIfAbsent('URLs', () => URLs.map((e) => e.toString()).toList());
Map<String, dynamic>? result =
@ -501,7 +504,7 @@ class ChromeSafariBrowser {
///
///**Supported Platforms/Implementations**:
///- iOS ([Official API - SFSafariViewControllerDelegate.safariViewController](https://developer.apple.com/documentation/safariservices/sfsafariviewcontrollerdelegate/2923545-safariviewcontroller))
void onInitialLoadDidRedirect(Uri? url) {}
void onInitialLoadDidRedirect(WebUri? url) {}
///Event fired when a navigation event happens.
///
@ -520,7 +523,7 @@ class ChromeSafariBrowser {
///**Supported Platforms/Implementations**:
///- Android ([Official API - CustomTabsCallback.onRelationshipValidationResult](https://developer.android.com/reference/androidx/browser/customtabs/CustomTabsCallback#onRelationshipValidationResult(int,android.net.Uri,boolean,android.os.Bundle)))
void onRelationshipValidationResult(
CustomTabsRelationType? relation, Uri? requestedOrigin, bool result) {}
CustomTabsRelationType? relation, WebUri? requestedOrigin, bool result) {}
///Event fired when the user opens the current page in the default browser by tapping the toolbar button.
///
@ -587,7 +590,7 @@ class ChromeSafariBrowserActionButton {
void Function(String url, String title)? action;
///Callback function to be invoked when the action button is clicked
void Function(Uri? url, String title)? onClick;
void Function(WebUri? url, String title)? onClick;
ChromeSafariBrowserActionButton(
{required this.id,
@ -638,7 +641,7 @@ class ChromeSafariBrowserMenuItem {
void Function(String url, String title)? action;
///Callback function to be invoked when the menu item is clicked
void Function(Uri? url, String title)? onClick;
void Function(WebUri? url, String title)? onClick;
ChromeSafariBrowserMenuItem(
{required this.id,
@ -712,7 +715,7 @@ class ChromeSafariBrowserSecondaryToolbarClickableID {
AndroidResource id;
///Callback function to be invoked when the item is clicked
void Function(Uri? url)? onClick;
void Function(WebUri? url)? onClick;
ChromeSafariBrowserSecondaryToolbarClickableID(
{required this.id, this.onClick});

View File

@ -8,6 +8,7 @@ import 'in_app_webview/headless_in_app_webview.dart';
import 'platform_util.dart';
import 'types/main.dart';
import 'web_uri.dart';
///Class that implements a singleton object (shared instance) which manages the cookies used by WebView instances.
///On Android, it is implemented using [CookieManager](https://developer.android.com/reference/android/webkit/CookieManager).
@ -76,7 +77,7 @@ class CookieManager {
///- MacOS ([Official API - WKHTTPCookieStore.setCookie](https://developer.apple.com/documentation/webkit/wkhttpcookiestore/2882007-setcookie))
///- Web
Future<void> setCookie(
{required Uri url,
{required WebUri url,
required String name,
required String value,
String path = "/",
@ -127,7 +128,7 @@ class CookieManager {
}
Future<void> _setCookieWithJavaScript(
{required Uri url,
{required WebUri url,
required String name,
required String value,
String path = "/",
@ -197,7 +198,7 @@ class CookieManager {
///- MacOS ([Official API - WKHTTPCookieStore.getAllCookies](https://developer.apple.com/documentation/webkit/wkhttpcookiestore/2882005-getallcookies))
///- Web
Future<List<Cookie>> getCookies(
{required Uri url,
{required WebUri url,
@Deprecated("Use webViewController instead")
InAppWebViewController? iosBelow11WebViewController,
InAppWebViewController? webViewController}) async {
@ -235,7 +236,7 @@ class CookieManager {
}
Future<List<Cookie>> _getCookiesWithJavaScript(
{required Uri url, InAppWebViewController? webViewController}) async {
{required WebUri url, InAppWebViewController? webViewController}) async {
assert(url.toString().isNotEmpty);
List<Cookie> cookies = [];
@ -310,7 +311,7 @@ class CookieManager {
///- MacOS
///- Web
Future<Cookie?> getCookie(
{required Uri url,
{required WebUri url,
required String name,
@Deprecated("Use webViewController instead")
InAppWebViewController? iosBelow11WebViewController,
@ -371,7 +372,7 @@ class CookieManager {
///- MacOS ([Official API - WKHTTPCookieStore.delete](https://developer.apple.com/documentation/webkit/wkhttpcookiestore/2882009-delete)
///- Web
Future<void> deleteCookie(
{required Uri url,
{required WebUri url,
required String name,
String path = "/",
String? domain,
@ -424,7 +425,7 @@ class CookieManager {
///- MacOS
///- Web
Future<void> deleteCookies(
{required Uri url,
{required WebUri url,
String path = "/",
String? domain,
@Deprecated("Use webViewController instead")

View File

@ -14,6 +14,7 @@ import '../in_app_webview/in_app_webview_settings.dart';
import '../util.dart';
import '../print_job/main.dart';
import '../web_uri.dart';
import 'in_app_browser_settings.dart';
import '../debug_logging_settings.dart';
@ -271,9 +272,9 @@ class InAppBrowser {
{required String data,
String mimeType = "text/html",
String encoding = "utf8",
Uri? baseUrl,
WebUri? baseUrl,
@Deprecated("Use historyUrl instead") Uri? androidHistoryUrl,
Uri? historyUrl,
WebUri? historyUrl,
// ignore: deprecated_member_use_from_same_package
@Deprecated('Use settings instead') InAppBrowserClassOptions? options,
InAppBrowserClassSettings? settings}) async {
@ -313,7 +314,7 @@ class InAppBrowser {
///- Android native WebView
///- iOS
///- MacOS
static Future<void> openWithSystemBrowser({required Uri url}) async {
static Future<void> openWithSystemBrowser({required WebUri url}) async {
assert(url.toString().isNotEmpty);
Map<String, dynamic> args = <String, dynamic>{};
args.putIfAbsent('url', () => url.toString());
@ -462,7 +463,7 @@ class InAppBrowser {
///- Android native WebView ([Official API - WebViewClient.onPageStarted](https://developer.android.com/reference/android/webkit/WebViewClient#onPageStarted(android.webkit.WebView,%20java.lang.String,%20android.graphics.Bitmap)))
///- iOS ([Official API - WKNavigationDelegate.webView](https://developer.apple.com/documentation/webkit/wknavigationdelegate/1455621-webview))
///- MacOS ([Official API - WKNavigationDelegate.webView](https://developer.apple.com/documentation/webkit/wknavigationdelegate/1455621-webview))
void onLoadStart(Uri? url) {}
void onLoadStart(WebUri? url) {}
///Event fired when the [InAppBrowser] finishes loading an [url].
///
@ -470,7 +471,7 @@ class InAppBrowser {
///- Android native WebView ([Official API - WebViewClient.onPageFinished](https://developer.android.com/reference/android/webkit/WebViewClient#onPageFinished(android.webkit.WebView,%20java.lang.String)))
///- iOS ([Official API - WKNavigationDelegate.webView](https://developer.apple.com/documentation/webkit/wknavigationdelegate/1455629-webview))
///- MacOS ([Official API - WKNavigationDelegate.webView](https://developer.apple.com/documentation/webkit/wknavigationdelegate/1455629-webview))
void onLoadStop(Uri? url) {}
void onLoadStop(WebUri? url) {}
///Use [onReceivedError] instead.
@Deprecated("Use onReceivedError instead")
@ -839,7 +840,7 @@ class InAppBrowser {
///- Android native WebView ([Official API - WebViewClient.doUpdateVisitedHistory](https://developer.android.com/reference/android/webkit/WebViewClient#doUpdateVisitedHistory(android.webkit.WebView,%20java.lang.String,%20boolean)))
///- iOS
///- MacOS
void onUpdateVisitedHistory(Uri? url, bool? isReload) {}
void onUpdateVisitedHistory(WebUri? url, bool? isReload) {}
///Use [onPrintRequest] instead
@Deprecated("Use onPrintRequest instead")
@ -858,7 +859,7 @@ class InAppBrowser {
///- iOS
///- MacOS
Future<bool?>? onPrintRequest(
Uri? url, PrintJobController? printJobController) {
WebUri? url, PrintJobController? printJobController) {
return null;
}
@ -898,7 +899,7 @@ class InAppBrowser {
///- Android native WebView ([Official API - WebViewClient.onPageCommitVisible](https://developer.android.com/reference/android/webkit/WebViewClient#onPageCommitVisible(android.webkit.WebView,%20java.lang.String)))
///- iOS ([Official API - WKNavigationDelegate.webView](https://developer.apple.com/documentation/webkit/wknavigationdelegate/1455635-webview))
///- MacOS ([Official API - WKNavigationDelegate.webView](https://developer.apple.com/documentation/webkit/wknavigationdelegate/1455635-webview))
void onPageCommitVisible(Uri? url) {}
void onPageCommitVisible(WebUri? url) {}
///Event fired when a change in the document title occurred.
///
@ -955,7 +956,7 @@ class InAppBrowser {
///**Supported Platforms/Implementations**:
///- Android native WebView ([Official API - WebViewClient.onSafeBrowsingHit](https://developer.android.com/reference/android/webkit/WebViewClient#onSafeBrowsingHit(android.webkit.WebView,%20android.webkit.WebResourceRequest,%20int,%20android.webkit.SafeBrowsingResponse)))
Future<SafeBrowsingResponse?>? onSafeBrowsingHit(
Uri url, SafeBrowsingThreat? threatType) {
WebUri url, SafeBrowsingThreat? threatType) {
return null;
}
@ -1072,7 +1073,8 @@ class InAppBrowser {
///
///**Supported Platforms/Implementations**:
///- Android native WebView ([Official API - WebViewRenderProcessClient.onRenderProcessUnresponsive](https://developer.android.com/reference/android/webkit/WebViewRenderProcessClient#onRenderProcessUnresponsive(android.webkit.WebView,%20android.webkit.WebViewRenderProcess)))
Future<WebViewRenderProcessAction?>? onRenderProcessUnresponsive(Uri? url) {
Future<WebViewRenderProcessAction?>? onRenderProcessUnresponsive(
WebUri? url) {
return null;
}
@ -1095,7 +1097,7 @@ class InAppBrowser {
///
///**Supported Platforms/Implementations**:
///- Android native WebView ([Official API - WebViewRenderProcessClient.onRenderProcessResponsive](https://developer.android.com/reference/android/webkit/WebViewRenderProcessClient#onRenderProcessResponsive(android.webkit.WebView,%20android.webkit.WebViewRenderProcess)))
Future<WebViewRenderProcessAction?>? onRenderProcessResponsive(Uri? url) {
Future<WebViewRenderProcessAction?>? onRenderProcessResponsive(WebUri? url) {
return null;
}
@ -1125,7 +1127,7 @@ class InAppBrowser {
///
///**Supported Platforms/Implementations**:
///- Android native WebView ([Official API - WebViewClient.onFormResubmission](https://developer.android.com/reference/android/webkit/WebViewClient#onFormResubmission(android.webkit.WebView,%20android.os.Message,%20android.os.Message)))
Future<FormResubmissionAction?>? onFormResubmission(Uri? url) {
Future<FormResubmissionAction?>? onFormResubmission(WebUri? url) {
return null;
}
@ -1157,7 +1159,7 @@ class InAppBrowser {
///
///**Supported Platforms/Implementations**:
///- Android native WebView ([Official API - WebChromeClient.onReceivedTouchIconUrl](https://developer.android.com/reference/android/webkit/WebChromeClient#onReceivedTouchIconUrl(android.webkit.WebView,%20java.lang.String,%20boolean)))
void onReceivedTouchIconUrl(Uri url, bool precomposed) {}
void onReceivedTouchIconUrl(WebUri url, bool precomposed) {}
///Use [onJsBeforeUnload] instead.
@Deprecated('Use onJsBeforeUnload instead')

View File

@ -9,6 +9,7 @@ import '../context_menu.dart';
import '../find_interaction/find_interaction_controller.dart';
import '../types/main.dart';
import '../print_job/main.dart';
import '../web_uri.dart';
import 'webview.dart';
import 'in_app_webview_controller.dart';
import 'in_app_webview_settings.dart';
@ -364,7 +365,7 @@ class HeadlessInAppWebView implements WebView, Disposable {
Uri url, SafeBrowsingThreat? threatType)? androidOnSafeBrowsingHit;
@override
void Function(InAppWebViewController controller, Uri? url)?
void Function(InAppWebViewController controller, WebUri? url)?
onPageCommitVisible;
@override
@ -490,10 +491,10 @@ class HeadlessInAppWebView implements WebView, Disposable {
onLoadResourceWithCustomScheme;
@override
void Function(InAppWebViewController controller, Uri? url)? onLoadStart;
void Function(InAppWebViewController controller, WebUri? url)? onLoadStart;
@override
void Function(InAppWebViewController controller, Uri? url)? onLoadStop;
void Function(InAppWebViewController controller, WebUri? url)? onLoadStop;
@override
void Function(InAppWebViewController controller,
@ -505,7 +506,7 @@ class HeadlessInAppWebView implements WebView, Disposable {
void Function(InAppWebViewController controller, Uri? url)? onPrint;
@override
Future<bool?> Function(InAppWebViewController controller, Uri? url,
Future<bool?> Function(InAppWebViewController controller, WebUri? url,
PrintJobController? printJobController)? onPrintRequest;
@override
@ -529,7 +530,7 @@ class HeadlessInAppWebView implements WebView, Disposable {
onScrollChanged;
@override
void Function(InAppWebViewController controller, Uri? url, bool? isReload)?
void Function(InAppWebViewController controller, WebUri? url, bool? isReload)?
onUpdateVisitedHistory;
@override
@ -636,7 +637,7 @@ class HeadlessInAppWebView implements WebView, Disposable {
@override
Future<FormResubmissionAction?> Function(
InAppWebViewController controller, Uri? url)? onFormResubmission;
InAppWebViewController controller, WebUri? url)? onFormResubmission;
@override
void Function(InAppWebViewController controller)?
@ -668,7 +669,8 @@ class HeadlessInAppWebView implements WebView, Disposable {
onReceivedLoginRequest;
@override
void Function(InAppWebViewController controller, Uri url, bool precomposed)?
void Function(
InAppWebViewController controller, WebUri url, bool precomposed)?
onReceivedTouchIconUrl;
@override
@ -678,15 +680,17 @@ class HeadlessInAppWebView implements WebView, Disposable {
@override
Future<WebViewRenderProcessAction?> Function(
InAppWebViewController controller, Uri? url)? onRenderProcessResponsive;
InAppWebViewController controller, WebUri? url)?
onRenderProcessResponsive;
@override
Future<WebViewRenderProcessAction?> Function(
InAppWebViewController controller, Uri? url)? onRenderProcessUnresponsive;
InAppWebViewController controller, WebUri? url)?
onRenderProcessUnresponsive;
@override
Future<SafeBrowsingResponse?> Function(InAppWebViewController controller,
Uri url, SafeBrowsingThreat? threatType)? onSafeBrowsingHit;
WebUri url, SafeBrowsingThreat? threatType)? onSafeBrowsingHit;
@override
void Function(InAppWebViewController controller)?

View File

@ -18,6 +18,7 @@ import '../context_menu.dart';
import '../types/main.dart';
import '../print_job/main.dart';
import '../web_uri.dart';
import 'webview.dart';
import 'in_app_webview_controller.dart';
import 'in_app_webview_settings.dart';
@ -231,7 +232,7 @@ class InAppWebView extends StatefulWidget implements WebView {
final ContextMenu? contextMenu;
@override
final void Function(InAppWebViewController controller, Uri? url)?
final void Function(InAppWebViewController controller, WebUri? url)?
onPageCommitVisible;
@override
@ -375,10 +376,12 @@ class InAppWebView extends StatefulWidget implements WebView {
onLoadResourceWithCustomScheme;
@override
final void Function(InAppWebViewController controller, Uri? url)? onLoadStart;
final void Function(InAppWebViewController controller, WebUri? url)?
onLoadStart;
@override
final void Function(InAppWebViewController controller, Uri? url)? onLoadStop;
final void Function(InAppWebViewController controller, WebUri? url)?
onLoadStop;
@override
final void Function(InAppWebViewController controller,
@ -390,7 +393,7 @@ class InAppWebView extends StatefulWidget implements WebView {
final void Function(InAppWebViewController controller, Uri? url)? onPrint;
@override
final Future<bool?> Function(InAppWebViewController controller, Uri? url,
final Future<bool?> Function(InAppWebViewController controller, WebUri? url,
PrintJobController? printJobController)? onPrintRequest;
@override
@ -416,7 +419,7 @@ class InAppWebView extends StatefulWidget implements WebView {
@override
final void Function(
InAppWebViewController controller, Uri? url, bool? isReload)?
InAppWebViewController controller, WebUri? url, bool? isReload)?
onUpdateVisitedHistory;
@override
@ -513,7 +516,7 @@ class InAppWebView extends StatefulWidget implements WebView {
@override
final Future<FormResubmissionAction?> Function(
InAppWebViewController controller, Uri? url)? onFormResubmission;
InAppWebViewController controller, WebUri? url)? onFormResubmission;
@override
final void Function(InAppWebViewController controller)?
@ -549,7 +552,7 @@ class InAppWebView extends StatefulWidget implements WebView {
@override
final void Function(
InAppWebViewController controller, Uri url, bool precomposed)?
InAppWebViewController controller, WebUri url, bool precomposed)?
onReceivedTouchIconUrl;
@override
@ -559,16 +562,18 @@ class InAppWebView extends StatefulWidget implements WebView {
@override
final Future<WebViewRenderProcessAction?> Function(
InAppWebViewController controller, Uri? url)? onRenderProcessResponsive;
InAppWebViewController controller, WebUri? url)?
onRenderProcessResponsive;
@override
final Future<WebViewRenderProcessAction?> Function(
InAppWebViewController controller, Uri? url)? onRenderProcessUnresponsive;
InAppWebViewController controller, WebUri? url)?
onRenderProcessUnresponsive;
@override
final Future<SafeBrowsingResponse?> Function(
InAppWebViewController controller,
Uri url,
WebUri url,
SafeBrowsingThreat? threatType)? onSafeBrowsingHit;
@override

View File

@ -9,6 +9,7 @@ import 'dart:ui';
import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import '../web_uri.dart';
import 'android/in_app_webview_controller.dart';
import 'apple/in_app_webview_controller.dart';
@ -134,7 +135,7 @@ class InAppWebViewController {
if ((_webview != null && _webview!.onLoadStart != null) ||
_inAppBrowser != null) {
String? url = call.arguments["url"];
Uri? uri = url != null ? Uri.tryParse(url) : null;
WebUri? uri = url != null ? WebUri(url) : null;
if (_webview != null && _webview!.onLoadStart != null)
_webview!.onLoadStart!(this, uri);
else
@ -145,7 +146,7 @@ class InAppWebViewController {
if ((_webview != null && _webview!.onLoadStop != null) ||
_inAppBrowser != null) {
String? url = call.arguments["url"];
Uri? uri = url != null ? Uri.tryParse(url) : null;
WebUri? uri = url != null ? WebUri(url) : null;
if (_webview != null && _webview!.onLoadStop != null)
_webview!.onLoadStop!(this, uri);
else
@ -435,7 +436,7 @@ class InAppWebViewController {
_webview!.androidOnRenderProcessUnresponsive != null)) ||
_inAppBrowser != null) {
String? url = call.arguments["url"];
Uri? uri = url != null ? Uri.tryParse(url) : null;
WebUri? uri = url != null ? WebUri(url) : null;
if (_webview != null) {
if (_webview!.onRenderProcessUnresponsive != null)
@ -463,7 +464,7 @@ class InAppWebViewController {
_webview!.androidOnRenderProcessResponsive != null)) ||
_inAppBrowser != null) {
String? url = call.arguments["url"];
Uri? uri = url != null ? Uri.tryParse(url) : null;
WebUri? uri = url != null ? WebUri(url) : null;
if (_webview != null) {
if (_webview!.onRenderProcessResponsive != null)
@ -516,7 +517,7 @@ class InAppWebViewController {
_webview!.androidOnFormResubmission != null)) ||
_inAppBrowser != null) {
String? url = call.arguments["url"];
Uri? uri = url != null ? Uri.tryParse(url) : null;
WebUri? uri = url != null ? WebUri(url) : null;
if (_webview != null) {
if (_webview!.onFormResubmission != null)
@ -589,7 +590,7 @@ class InAppWebViewController {
_inAppBrowser != null) {
String url = call.arguments["url"];
bool precomposed = call.arguments["precomposed"];
Uri uri = Uri.tryParse(url) ?? Uri();
WebUri uri = WebUri(url);
if (_webview != null) {
if (_webview!.onReceivedTouchIconUrl != null)
@ -689,7 +690,7 @@ class InAppWebViewController {
String url = call.arguments["url"];
SafeBrowsingThreat? threatType =
SafeBrowsingThreat.fromNativeValue(call.arguments["threatType"]);
Uri uri = Uri.tryParse(url) ?? Uri();
WebUri uri = WebUri(url);
if (_webview != null) {
if (_webview!.onSafeBrowsingHit != null)
@ -867,7 +868,7 @@ class InAppWebViewController {
_inAppBrowser != null) {
String? url = call.arguments["url"];
bool? isReload = call.arguments["isReload"];
Uri? uri = url != null ? Uri.tryParse(url) : null;
WebUri? uri = url != null ? WebUri(url) : null;
if (_webview != null && _webview!.onUpdateVisitedHistory != null)
_webview!.onUpdateVisitedHistory!(this, uri, isReload);
else
@ -895,7 +896,7 @@ class InAppWebViewController {
if ((_webview != null && _webview!.onPageCommitVisible != null) ||
_inAppBrowser != null) {
String? url = call.arguments["url"];
Uri? uri = url != null ? Uri.tryParse(url) : null;
WebUri? uri = url != null ? WebUri(url) : null;
if (_webview != null && _webview!.onPageCommitVisible != null)
_webview!.onPageCommitVisible!(this, uri);
else
@ -1120,7 +1121,7 @@ class InAppWebViewController {
_inAppBrowser != null) {
String? url = call.arguments["url"];
String? printJobId = call.arguments["printJobId"];
Uri? uri = url != null ? Uri.tryParse(url) : null;
WebUri? uri = url != null ? WebUri(url) : null;
PrintJobController? printJob =
printJobId != null ? PrintJobController(id: printJobId) : null;
@ -1330,10 +1331,10 @@ class InAppWebViewController {
///- iOS ([Official API - WKWebView.url](https://developer.apple.com/documentation/webkit/wkwebview/1415005-url))
///- MacOS ([Official API - WKWebView.url](https://developer.apple.com/documentation/webkit/wkwebview/1415005-url))
///- Web
Future<Uri?> getUrl() async {
Future<WebUri?> getUrl() async {
Map<String, dynamic> args = <String, dynamic>{};
String? url = await _channel.invokeMethod('getUrl', args);
return url != null ? Uri.tryParse(url) : null;
return url != null ? WebUri(url) : null;
}
///Gets the title for the current page.
@ -1493,7 +1494,7 @@ class InAppWebViewController {
HttpClient client = HttpClient();
var faviconUrl =
webviewUrl.scheme + "://" + webviewUrl.host + "/favicon.ico";
var faviconUri = Uri.parse(faviconUrl);
var faviconUri = WebUri(faviconUrl);
var headRequest = await client.headUrl(faviconUri);
var headResponse = await headRequest.close();
if (headResponse.statusCode == 200) {
@ -1546,8 +1547,8 @@ class InAppWebViewController {
return url.startsWith("http://") || url.startsWith("https://");
}
List<Favicon> _createFavicons(Uri url, String? assetPathBase, String urlIcon,
String? rel, String? sizes, bool isManifest) {
List<Favicon> _createFavicons(WebUri url, String? assetPathBase,
String urlIcon, String? rel, String? sizes, bool isManifest) {
List<Favicon> favicons = [];
List<String> urlSplitted = urlIcon.split("/");
@ -1574,17 +1575,11 @@ class InAppWebViewController {
int width = int.parse(size.split("x")[0]);
int height = int.parse(size.split("x")[1]);
favicons.add(Favicon(
url: Uri.tryParse(urlIcon) ?? Uri(),
rel: rel,
width: width,
height: height));
url: WebUri(urlIcon), rel: rel, width: width, height: height));
}
} else {
favicons.add(Favicon(
url: Uri.tryParse(urlIcon) ?? Uri(),
rel: rel,
width: null,
height: null));
favicons.add(
Favicon(url: WebUri(urlIcon), rel: rel, width: null, height: null));
}
return favicons;
@ -1613,7 +1608,7 @@ class InAppWebViewController {
{required URLRequest urlRequest,
@Deprecated('Use allowingReadAccessTo instead')
Uri? iosAllowingReadAccessTo,
Uri? allowingReadAccessTo}) async {
WebUri? allowingReadAccessTo}) async {
assert(urlRequest.url != null && urlRequest.url.toString().isNotEmpty);
assert(
allowingReadAccessTo == null || allowingReadAccessTo.isScheme("file"));
@ -1635,7 +1630,7 @@ class InAppWebViewController {
///Example:
///```dart
///var postData = Uint8List.fromList(utf8.encode("firstname=Foo&surname=Bar"));
///controller.postUrl(url: Uri.parse("https://www.example.com/"), postData: postData);
///controller.postUrl(url: WebUri("https://www.example.com/"), postData: postData);
///```
///
///**NOTE for Web**: it will try to create an XMLHttpRequest and load the result inside the iframe.
@ -1645,7 +1640,8 @@ class InAppWebViewController {
///- iOS
///- MacOS
///- Web
Future<void> postUrl({required Uri url, required Uint8List postData}) async {
Future<void> postUrl(
{required WebUri url, required Uint8List postData}) async {
assert(url.toString().isNotEmpty);
Map<String, dynamic> args = <String, dynamic>{};
args.putIfAbsent('url', () => url.toString());
@ -1676,13 +1672,13 @@ class InAppWebViewController {
{required String data,
String mimeType = "text/html",
String encoding = "utf8",
Uri? baseUrl,
WebUri? baseUrl,
@Deprecated('Use historyUrl instead')
Uri? androidHistoryUrl,
Uri? historyUrl,
WebUri? historyUrl,
@Deprecated('Use allowingReadAccessTo instead')
Uri? iosAllowingReadAccessTo,
Uri? allowingReadAccessTo}) async {
WebUri? allowingReadAccessTo}) async {
assert(
allowingReadAccessTo == null || allowingReadAccessTo.isScheme("file"));
assert(iosAllowingReadAccessTo == null ||
@ -1938,7 +1934,7 @@ class InAppWebViewController {
///- MacOS
///- Web
Future<void> injectJavascriptFileFromUrl(
{required Uri urlFile,
{required WebUri urlFile,
ScriptHtmlTagAttributes? scriptHtmlTagAttributes}) async {
assert(urlFile.toString().isNotEmpty);
var id = scriptHtmlTagAttributes?.id;
@ -2009,7 +2005,7 @@ class InAppWebViewController {
///- MacOS
///- Web
Future<void> injectCSSFileFromUrl(
{required Uri urlFile,
{required WebUri urlFile,
CSSLinkHtmlTagAttributes? cssLinkHtmlTagAttributes}) async {
assert(urlFile.toString().isNotEmpty);
Map<String, dynamic> args = <String, dynamic>{};
@ -2453,10 +2449,10 @@ class InAppWebViewController {
///- iOS
///- MacOS
///- Web
Future<Uri?> getOriginalUrl() async {
Future<WebUri?> getOriginalUrl() async {
Map<String, dynamic> args = <String, dynamic>{};
String? url = await _channel.invokeMethod('getOriginalUrl', args);
return url != null ? Uri.tryParse(url) : null;
return url != null ? WebUri(url) : null;
}
///Gets the current zoom scale of the WebView.
@ -2553,7 +2549,7 @@ class InAppWebViewController {
await _channel.invokeMethod('requestFocusNodeHref', args);
return result != null
? RequestFocusNodeHrefResult(
url: result['url'] != null ? Uri.tryParse(result['url']) : null,
url: result['url'] != null ? WebUri(result['url']) : null,
title: result['title'],
src: result['src'],
)
@ -2573,7 +2569,7 @@ class InAppWebViewController {
await _channel.invokeMethod('requestImageRef', args);
return result != null
? RequestImageRefResult(
url: result['url'] != null ? Uri.tryParse(result['url']) : null,
url: result['url'] != null ? WebUri(result['url']) : null,
)
: null;
}
@ -3018,9 +3014,9 @@ class InAppWebViewController {
///- iOS
///- MacOS
Future<void> postWebMessage(
{required WebMessage message, Uri? targetOrigin}) async {
{required WebMessage message, WebUri? targetOrigin}) async {
if (targetOrigin == null) {
targetOrigin = Uri();
targetOrigin = WebUri('');
}
Map<String, dynamic> args = <String, dynamic>{};
args.putIfAbsent('message', () => message.toMap());
@ -3177,7 +3173,7 @@ class InAppWebViewController {
/// },
/// ));
/// }
/// await controller.loadUrl(urlRequest: URLRequest(url: Uri.parse("https://www.example.com")));
/// await controller.loadUrl(urlRequest: URLRequest(url: WebUri("https://www.example.com")));
/// },
/// ),
///```
@ -3541,7 +3537,7 @@ class InAppWebViewController {
///Example:
///```dart
///controller.loadSimulateloadSimulatedRequestdRequest(urlRequest: URLRequest(
/// url: Uri.parse("https://flutter.dev"),
/// url: WebUri("https://flutter.dev"),
/// ),
/// data: Uint8List.fromList(utf8.encode("<h1>Hello</h1>"))
///);
@ -3606,11 +3602,11 @@ class InAppWebViewController {
///
///**Supported Platforms/Implementations**:
///- Android native WebView ([Official API - WebViewCompat.getSafeBrowsingPrivacyPolicyUrl](https://developer.android.com/reference/androidx/webkit/WebViewCompat#getSafeBrowsingPrivacyPolicyUrl()))
static Future<Uri?> getSafeBrowsingPrivacyPolicyUrl() async {
static Future<WebUri?> getSafeBrowsingPrivacyPolicyUrl() async {
Map<String, dynamic> args = <String, dynamic>{};
String? url = await _staticChannel.invokeMethod(
'getSafeBrowsingPrivacyPolicyUrl', args);
return url != null ? Uri.tryParse(url) : null;
return url != null ? WebUri(url) : null;
}
///Use [setSafeBrowsingAllowlist] instead.

View File

@ -21,6 +21,7 @@ import '../types/scrollview_content_inset_adjustment_behavior.dart';
import '../types/scrollview_deceleration_rate.dart';
import '../types/selection_granularity.dart';
import '../types/vertical_scrollbar_position.dart';
import '../web_uri.dart';
import 'android/in_app_webview_options.dart';
import 'apple/in_app_webview_options.dart';
import '../content_blocker.dart';
@ -1123,7 +1124,7 @@ class InAppWebViewSettings_ {
///**Supported Platforms/Implementations**:
///- iOS
///- MacOS
Uri? allowingReadAccessTo;
WebUri? allowingReadAccessTo;
///Set to `true` to disable the context menu (copy, select, etc.) that is shown when the user emits a long press event on a HTML link.
///This is implemented using also JavaScript, so it must be enabled or it won't work.

View File

@ -1080,7 +1080,7 @@ class InAppWebViewSettings {
///**Supported Platforms/Implementations**:
///- iOS
///- MacOS
Uri? allowingReadAccessTo;
WebUri? allowingReadAccessTo;
///Set to `true` to disable the context menu (copy, select, etc.) that is shown when the user emits a long press event on a HTML link.
///This is implemented using also JavaScript, so it must be enabled or it won't work.
@ -1430,7 +1430,7 @@ class InAppWebViewSettings {
map['requestedWithHeaderMode']),
mediaType: map['mediaType'],
allowingReadAccessTo: map['allowingReadAccessTo'] != null
? Uri.tryParse(map['allowingReadAccessTo'])
? WebUri(map['allowingReadAccessTo'])
: null,
underPageBackgroundColor: map['underPageBackgroundColor'] != null
? UtilColor.fromStringRepresentation(map['underPageBackgroundColor'])

View File

@ -7,6 +7,7 @@ import '../pull_to_refresh/pull_to_refresh_controller.dart';
import '../context_menu.dart';
import '../types/main.dart';
import '../web_uri.dart';
import 'in_app_webview_controller.dart';
import 'in_app_webview_settings.dart';
import 'headless_in_app_webview.dart';
@ -52,7 +53,8 @@ abstract class WebView {
///- iOS ([Official API - WKNavigationDelegate.webView](https://developer.apple.com/documentation/webkit/wknavigationdelegate/1455621-webview))
///- MacOS ([Official API - WKNavigationDelegate.webView](https://developer.apple.com/documentation/webkit/wknavigationdelegate/1455621-webview))
///- Web
final void Function(InAppWebViewController controller, Uri? url)? onLoadStart;
final void Function(InAppWebViewController controller, WebUri? url)?
onLoadStart;
///Event fired when the [WebView] finishes loading an [url].
///
@ -64,7 +66,8 @@ abstract class WebView {
///- iOS ([Official API - WKNavigationDelegate.webView](https://developer.apple.com/documentation/webkit/wknavigationdelegate/1455629-webview))
///- MacOS ([Official API - WKNavigationDelegate.webView](https://developer.apple.com/documentation/webkit/wknavigationdelegate/1455629-webview))
///- Web ([Official API - Window.onload](https://developer.mozilla.org/en-US/docs/Web/API/Window/load_event))
final void Function(InAppWebViewController controller, Uri? url)? onLoadStop;
final void Function(InAppWebViewController controller, WebUri? url)?
onLoadStop;
///Use [onReceivedError] instead.
@Deprecated("Use onReceivedError instead")
@ -459,7 +462,7 @@ abstract class WebView {
///- MacOS
///- Web
final void Function(
InAppWebViewController controller, Uri? url, bool? isReload)?
InAppWebViewController controller, WebUri? url, bool? isReload)?
onUpdateVisitedHistory;
///Use [onPrintRequest] instead
@ -482,7 +485,7 @@ abstract class WebView {
///- iOS
///- MacOS
///- Web
final Future<bool?> Function(InAppWebViewController controller, Uri? url,
final Future<bool?> Function(InAppWebViewController controller, WebUri? url,
PrintJobController? printJobController)? onPrintRequest;
///Event fired when an HTML element of the webview has been clicked and held.
@ -528,7 +531,7 @@ abstract class WebView {
///- Android native WebView ([Official API - WebViewClient.onPageCommitVisible](https://developer.android.com/reference/android/webkit/WebViewClient#onPageCommitVisible(android.webkit.WebView,%20java.lang.String)))
///- iOS ([Official API - WKNavigationDelegate.webView](https://developer.apple.com/documentation/webkit/wknavigationdelegate/1455635-webview))
///- MacOS ([Official API - WKNavigationDelegate.webView](https://developer.apple.com/documentation/webkit/wknavigationdelegate/1455635-webview))
final void Function(InAppWebViewController controller, Uri? url)?
final void Function(InAppWebViewController controller, WebUri? url)?
onPageCommitVisible;
///Event fired when a change in the document title occurred.
@ -597,7 +600,7 @@ abstract class WebView {
///- Android native WebView ([Official API - WebViewClient.onSafeBrowsingHit](https://developer.android.com/reference/android/webkit/WebViewClient#onSafeBrowsingHit(android.webkit.WebView,%20android.webkit.WebResourceRequest,%20int,%20android.webkit.SafeBrowsingResponse)))
final Future<SafeBrowsingResponse?> Function(
InAppWebViewController controller,
Uri url,
WebUri url,
SafeBrowsingThreat? threatType)? onSafeBrowsingHit;
///Use [onPermissionRequest] instead.
@ -709,7 +712,8 @@ abstract class WebView {
///**Supported Platforms/Implementations**:
///- Android native WebView ([Official API - WebViewRenderProcessClient.onRenderProcessUnresponsive](https://developer.android.com/reference/android/webkit/WebViewRenderProcessClient#onRenderProcessUnresponsive(android.webkit.WebView,%20android.webkit.WebViewRenderProcess)))
final Future<WebViewRenderProcessAction?> Function(
InAppWebViewController controller, Uri? url)? onRenderProcessUnresponsive;
InAppWebViewController controller, WebUri? url)?
onRenderProcessUnresponsive;
///Use [onRenderProcessResponsive] instead.
@Deprecated("Use onRenderProcessResponsive instead")
@ -730,7 +734,8 @@ abstract class WebView {
///**Supported Platforms/Implementations**:
///- Android native WebView ([Official API - WebViewRenderProcessClient.onRenderProcessResponsive](https://developer.android.com/reference/android/webkit/WebViewRenderProcessClient#onRenderProcessResponsive(android.webkit.WebView,%20android.webkit.WebViewRenderProcess)))
final Future<WebViewRenderProcessAction?> Function(
InAppWebViewController controller, Uri? url)? onRenderProcessResponsive;
InAppWebViewController controller, WebUri? url)?
onRenderProcessResponsive;
///Use [onRenderProcessGone] instead.
@Deprecated("Use onRenderProcessGone instead")
@ -762,7 +767,7 @@ abstract class WebView {
///**Supported Platforms/Implementations**:
///- Android native WebView ([Official API - WebViewClient.onFormResubmission](https://developer.android.com/reference/android/webkit/WebViewClient#onFormResubmission(android.webkit.WebView,%20android.os.Message,%20android.os.Message)))
final Future<FormResubmissionAction?> Function(
InAppWebViewController controller, Uri? url)? onFormResubmission;
InAppWebViewController controller, WebUri? url)? onFormResubmission;
///Use [onZoomScaleChanged] instead.
@Deprecated('Use onZoomScaleChanged instead')
@ -799,7 +804,7 @@ abstract class WebView {
///**Supported Platforms/Implementations**:
///- Android native WebView ([Official API - WebChromeClient.onReceivedTouchIconUrl](https://developer.android.com/reference/android/webkit/WebChromeClient#onReceivedTouchIconUrl(android.webkit.WebView,%20java.lang.String,%20boolean)))
final void Function(
InAppWebViewController controller, Uri url, bool precomposed)?
InAppWebViewController controller, WebUri url, bool precomposed)?
onReceivedTouchIconUrl;
///Use [onJsBeforeUnload] instead.

View File

@ -18,3 +18,4 @@ export 'web_authentication_session/main.dart';
export 'print_job/main.dart';
export 'debug_logging_settings.dart';
export 'find_interaction/main.dart';
export 'web_uri.dart';

View File

@ -2,6 +2,7 @@ import 'package:flutter/cupertino.dart';
import '../types/main.dart';
import '../util.dart';
import '../web_uri.dart';
import 'print_job_controller.dart';
///Class that represents the settings of a [PrintJobController].
@ -244,7 +245,7 @@ class PrintJobSettings {
///
///**Supported Platforms/Implementations**:
///- MacOS
Uri? jobSavingURL;
WebUri? jobSavingURL;
///The name of the currently selected paper size.
///
@ -440,9 +441,8 @@ class PrintJobSettings {
showsProgressPanel: map["showsProgressPanel"],
jobDisposition:
PrintJobDisposition.fromNativeValue(map["jobDisposition"]),
jobSavingURL: map["jobSavingURL"] != null
? Uri.tryParse(map["jobSavingURL"])
: null,
jobSavingURL:
map["jobSavingURL"] != null ? WebUri(map["jobSavingURL"]) : null,
paperName: map["paperName"],
horizontalPagination:
PrintJobPaginationMode.fromNativeValue(map["horizontalPagination"]),

View File

@ -1,5 +1,6 @@
import 'package:flutter_inappwebview_internal_annotations/flutter_inappwebview_internal_annotations.dart';
import '../web_uri.dart';
import 'ajax_request_headers.dart';
import 'ajax_request_ready_state.dart';
import 'ajax_request_event.dart';
@ -17,7 +18,7 @@ class AjaxRequest_ {
String? method;
///The URL of the `XMLHttpRequest` request.
Uri? url;
WebUri? url;
///An optional Boolean parameter, defaulting to true, indicating whether or not the request is performed asynchronously.
bool? isAsync;
@ -46,7 +47,7 @@ class AjaxRequest_ {
///The serialized URL of the response or the empty string if the URL is null.
///If the URL is returned, any URL fragment present in the URL will be stripped away.
///The value of responseURL will be the final URL obtained after any redirects.
Uri? responseURL;
WebUri? responseURL;
///It is an enumerated string value specifying the type of data contained in the response.
///It also lets the author change the [response type](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/responseType).

View File

@ -15,7 +15,7 @@ class AjaxRequest {
String? method;
///The URL of the `XMLHttpRequest` request.
Uri? url;
WebUri? url;
///An optional Boolean parameter, defaulting to true, indicating whether or not the request is performed asynchronously.
bool? isAsync;
@ -44,7 +44,7 @@ class AjaxRequest {
///The serialized URL of the response or the empty string if the URL is null.
///If the URL is returned, any URL fragment present in the URL will be stripped away.
///The value of responseURL will be the final URL obtained after any redirects.
Uri? responseURL;
WebUri? responseURL;
///It is an enumerated string value specifying the type of data contained in the response.
///It also lets the author change the [response type](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/responseType).
@ -103,7 +103,7 @@ class AjaxRequest {
final instance = AjaxRequest(
data: map['data'],
method: map['method'],
url: map['url'] != null ? Uri.tryParse(map['url']) : null,
url: map['url'] != null ? WebUri(map['url']) : null,
isAsync: map['isAsync'],
user: map['user'],
password: map['password'],
@ -113,7 +113,7 @@ class AjaxRequest {
readyState: AjaxRequestReadyState.fromNativeValue(map['readyState']),
status: map['status'],
responseURL:
map['responseURL'] != null ? Uri.tryParse(map['responseURL']) : null,
map['responseURL'] != null ? WebUri(map['responseURL']) : null,
responseType: map['responseType'],
response: map['response'],
responseText: map['responseText'],

View File

@ -1,6 +1,7 @@
import 'package:flutter_inappwebview_internal_annotations/flutter_inappwebview_internal_annotations.dart';
import '../in_app_webview/webview.dart';
import '../web_uri.dart';
part 'download_start_request.g.dart';
@ -8,7 +9,7 @@ part 'download_start_request.g.dart';
@ExchangeableObject()
class DownloadStartRequest_ {
///The full url to the content that should be downloaded.
Uri url;
WebUri url;
///the user agent to be used for the download.
String? userAgent;

View File

@ -9,7 +9,7 @@ part of 'download_start_request.dart';
///Class representing a download request of the WebView used by the event [WebView.onDownloadStartRequest].
class DownloadStartRequest {
///The full url to the content that should be downloaded.
Uri url;
WebUri url;
///the user agent to be used for the download.
String? userAgent;
@ -43,7 +43,7 @@ class DownloadStartRequest {
return null;
}
final instance = DownloadStartRequest(
url: (Uri.tryParse(map['url']) ?? Uri()),
url: WebUri(map['url']),
userAgent: map['userAgent'],
contentDisposition: map['contentDisposition'],
mimeType: map['mimeType'],

View File

@ -1,6 +1,7 @@
import 'package:flutter_inappwebview_internal_annotations/flutter_inappwebview_internal_annotations.dart';
import '../in_app_webview/in_app_webview_controller.dart';
import '../web_uri.dart';
part 'favicon.g.dart';
@ -8,7 +9,7 @@ part 'favicon.g.dart';
@ExchangeableObject()
class Favicon_ {
///The url of the favicon image.
Uri url;
WebUri url;
///The relationship between the current web page and the favicon image.
String? rel;

View File

@ -9,7 +9,7 @@ part of 'favicon.dart';
///Class that represents a favicon of a website. It is used by [InAppWebViewController.getFavicons] method.
class Favicon {
///The url of the favicon image.
Uri url;
WebUri url;
///The relationship between the current web page and the favicon image.
String? rel;
@ -27,7 +27,7 @@ class Favicon {
return null;
}
final instance = Favicon(
url: (Uri.tryParse(map['url']) ?? Uri()),
url: WebUri(map['url']),
rel: map['rel'],
width: map['width'],
height: map['height'],

View File

@ -1,5 +1,6 @@
import 'package:flutter_inappwebview_internal_annotations/flutter_inappwebview_internal_annotations.dart';
import '../web_uri.dart';
import 'fetch_request_action.dart';
import 'fetch_request_credential.dart';
import 'fetch_request_credential_default.dart';
@ -28,7 +29,7 @@ FetchRequestCredential? _fetchRequestCredentialDeserializer(dynamic value) {
@ExchangeableObject()
class FetchRequest_ {
///The URL of the request.
Uri? url;
WebUri? url;
///The HTTP request method used of the request.
String? method;

View File

@ -9,7 +9,7 @@ part of 'fetch_request.dart';
///Class that represents a HTTP request created with JavaScript using the [Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch).
class FetchRequest {
///The URL of the request.
Uri? url;
WebUri? url;
///The HTTP request method used of the request.
String? method;
@ -67,7 +67,7 @@ class FetchRequest {
return null;
}
final instance = FetchRequest(
url: map['url'] != null ? Uri.tryParse(map['url']) : null,
url: map['url'] != null ? WebUri(map['url']) : null,
method: map['method'],
headers: map['headers']?.cast<String, dynamic>(),
body: map['body'],

View File

@ -1,5 +1,6 @@
import 'package:flutter_inappwebview_internal_annotations/flutter_inappwebview_internal_annotations.dart';
import '../web_uri.dart';
import 'fetch_request_credential.dart';
part 'fetch_request_federated_credential.g.dart';
@ -20,7 +21,7 @@ class FetchRequestFederatedCredential_ extends FetchRequestCredential_ {
String? provider;
///URL pointing to an image for an icon. This image is intended for display in a credential chooser. The URL must be accessible without authentication.
Uri? iconURL;
WebUri? iconURL;
FetchRequestFederatedCredential_(
{type, this.id, this.name, this.protocol, this.provider, this.iconURL})

View File

@ -21,7 +21,7 @@ class FetchRequestFederatedCredential extends FetchRequestCredential {
String? provider;
///URL pointing to an image for an icon. This image is intended for display in a credential chooser. The URL must be accessible without authentication.
Uri? iconURL;
WebUri? iconURL;
FetchRequestFederatedCredential(
{this.id,
this.name,
@ -41,7 +41,7 @@ class FetchRequestFederatedCredential extends FetchRequestCredential {
name: map['name'],
protocol: map['protocol'],
provider: map['provider'],
iconURL: map['iconURL'] != null ? Uri.tryParse(map['iconURL']) : null,
iconURL: map['iconURL'] != null ? WebUri(map['iconURL']) : null,
);
instance.type = map['type'];
return instance;

View File

@ -1,5 +1,6 @@
import 'package:flutter_inappwebview_internal_annotations/flutter_inappwebview_internal_annotations.dart';
import '../web_uri.dart';
import 'fetch_request_credential.dart';
part 'fetch_request_password_credential.g.dart';
@ -17,7 +18,7 @@ class FetchRequestPasswordCredential_ extends FetchRequestCredential_ {
String? password;
///URL pointing to an image for an icon. This image is intended for display in a credential chooser. The URL must be accessible without authentication.
Uri? iconURL;
WebUri? iconURL;
FetchRequestPasswordCredential_(
{type, this.id, this.name, this.password, this.iconURL})

View File

@ -18,7 +18,7 @@ class FetchRequestPasswordCredential extends FetchRequestCredential {
String? password;
///URL pointing to an image for an icon. This image is intended for display in a credential chooser. The URL must be accessible without authentication.
Uri? iconURL;
WebUri? iconURL;
FetchRequestPasswordCredential(
{this.id, this.name, this.password, this.iconURL, String? type})
: super(type: type);
@ -32,7 +32,7 @@ class FetchRequestPasswordCredential extends FetchRequestCredential {
id: map['id'],
name: map['name'],
password: map['password'],
iconURL: map['iconURL'] != null ? Uri.tryParse(map['iconURL']) : null,
iconURL: map['iconURL'] != null ? WebUri(map['iconURL']) : null,
);
instance.type = map['type'];
return instance;

View File

@ -1,6 +1,7 @@
import 'package:flutter_inappwebview_internal_annotations/flutter_inappwebview_internal_annotations.dart';
import '../in_app_webview/webview.dart';
import '../web_uri.dart';
part 'in_app_webview_initial_data.g.dart';
@ -17,7 +18,7 @@ class InAppWebViewInitialData_ {
String encoding;
///The URL to use as the page's base URL. If `null` defaults to `about:blank`.
Uri? baseUrl;
WebUri? baseUrl;
///Use [historyUrl] instead.
@Deprecated('Use historyUrl instead')
@ -25,7 +26,7 @@ class InAppWebViewInitialData_ {
///The URL to use as the history entry. If `null` defaults to `about:blank`. If non-null, this must be a valid URL.
@SupportedPlatforms(platforms: [AndroidPlatform()])
Uri? historyUrl;
WebUri? historyUrl;
InAppWebViewInitialData_(
{required this.data,

View File

@ -18,7 +18,7 @@ class InAppWebViewInitialData {
String encoding;
///The URL to use as the page's base URL. If `null` defaults to `about:blank`.
Uri? baseUrl;
WebUri? baseUrl;
///Use [historyUrl] instead.
@Deprecated('Use historyUrl instead')
@ -28,7 +28,7 @@ class InAppWebViewInitialData {
///
///**Supported Platforms/Implementations**:
///- Android native WebView
Uri? historyUrl;
WebUri? historyUrl;
InAppWebViewInitialData(
{required this.data,
this.mimeType = "text/html",
@ -36,7 +36,8 @@ class InAppWebViewInitialData {
this.baseUrl,
@Deprecated('Use historyUrl instead') this.androidHistoryUrl,
this.historyUrl}) {
historyUrl = historyUrl ?? androidHistoryUrl;
historyUrl = historyUrl ??
(androidHistoryUrl != null ? WebUri.uri(androidHistoryUrl!) : null);
}
///Gets a possible [InAppWebViewInitialData] instance from a [Map] value.
@ -46,11 +47,10 @@ class InAppWebViewInitialData {
}
final instance = InAppWebViewInitialData(
data: map['data'],
baseUrl: map['baseUrl'] != null ? Uri.tryParse(map['baseUrl']) : null,
baseUrl: map['baseUrl'] != null ? WebUri(map['baseUrl']) : null,
androidHistoryUrl:
map['historyUrl'] != null ? Uri.tryParse(map['historyUrl']) : null,
historyUrl:
map['historyUrl'] != null ? Uri.tryParse(map['historyUrl']) : null,
historyUrl: map['historyUrl'] != null ? WebUri(map['historyUrl']) : null,
);
instance.mimeType = map['mimeType'];
instance.encoding = map['encoding'];

View File

@ -1,6 +1,7 @@
import 'package:flutter_inappwebview_internal_annotations/flutter_inappwebview_internal_annotations.dart';
import '../in_app_webview/webview.dart';
import '../web_uri.dart';
part 'js_alert_request.g.dart';
@ -8,7 +9,7 @@ part 'js_alert_request.g.dart';
@ExchangeableObject()
class JsAlertRequest_ {
///The url of the page requesting the dialog.
Uri? url;
WebUri? url;
///Message to be displayed in the window.
String? message;

View File

@ -9,7 +9,7 @@ part of 'js_alert_request.dart';
///Class that represents the request of the [WebView.onJsAlert] event.
class JsAlertRequest {
///The url of the page requesting the dialog.
Uri? url;
WebUri? url;
///Message to be displayed in the window.
String? message;
@ -37,7 +37,7 @@ class JsAlertRequest {
return null;
}
final instance = JsAlertRequest(
url: map['url'] != null ? Uri.tryParse(map['url']) : null,
url: map['url'] != null ? WebUri(map['url']) : null,
message: map['message'],
iosIsMainFrame: map['isMainFrame'],
isMainFrame: map['isMainFrame'],

View File

@ -1,6 +1,7 @@
import 'package:flutter_inappwebview_internal_annotations/flutter_inappwebview_internal_annotations.dart';
import '../in_app_webview/webview.dart';
import '../web_uri.dart';
part 'js_before_unload_request.g.dart';
@ -8,7 +9,7 @@ part 'js_before_unload_request.g.dart';
@ExchangeableObject()
class JsBeforeUnloadRequest_ {
///The url of the page requesting the dialog.
Uri? url;
WebUri? url;
///Message to be displayed in the window.
String? message;

View File

@ -9,7 +9,7 @@ part of 'js_before_unload_request.dart';
///Class that represents the request of the [WebView.onJsBeforeUnload] event.
class JsBeforeUnloadRequest {
///The url of the page requesting the dialog.
Uri? url;
WebUri? url;
///Message to be displayed in the window.
String? message;
@ -21,7 +21,7 @@ class JsBeforeUnloadRequest {
return null;
}
final instance = JsBeforeUnloadRequest(
url: map['url'] != null ? Uri.tryParse(map['url']) : null,
url: map['url'] != null ? WebUri(map['url']) : null,
message: map['message'],
);
return instance;

View File

@ -1,6 +1,7 @@
import 'package:flutter_inappwebview_internal_annotations/flutter_inappwebview_internal_annotations.dart';
import '../in_app_webview/webview.dart';
import '../web_uri.dart';
part 'js_confirm_request.g.dart';
@ -8,7 +9,7 @@ part 'js_confirm_request.g.dart';
@ExchangeableObject()
class JsConfirmRequest_ {
///The url of the page requesting the dialog.
Uri? url;
WebUri? url;
///Message to be displayed in the window.
String? message;

View File

@ -9,7 +9,7 @@ part of 'js_confirm_request.dart';
///Class that represents the request of the [WebView.onJsConfirm] event.
class JsConfirmRequest {
///The url of the page requesting the dialog.
Uri? url;
WebUri? url;
///Message to be displayed in the window.
String? message;
@ -37,7 +37,7 @@ class JsConfirmRequest {
return null;
}
final instance = JsConfirmRequest(
url: map['url'] != null ? Uri.tryParse(map['url']) : null,
url: map['url'] != null ? WebUri(map['url']) : null,
message: map['message'],
iosIsMainFrame: map['isMainFrame'],
isMainFrame: map['isMainFrame'],

View File

@ -1,6 +1,7 @@
import 'package:flutter_inappwebview_internal_annotations/flutter_inappwebview_internal_annotations.dart';
import '../in_app_webview/webview.dart';
import '../web_uri.dart';
part 'js_prompt_request.g.dart';
@ -8,7 +9,7 @@ part 'js_prompt_request.g.dart';
@ExchangeableObject()
class JsPromptRequest_ {
///The url of the page requesting the dialog.
Uri? url;
WebUri? url;
///Message to be displayed in the window.
String? message;

View File

@ -9,7 +9,7 @@ part of 'js_prompt_request.dart';
///Class that represents the request of the [WebView.onJsPrompt] event.
class JsPromptRequest {
///The url of the page requesting the dialog.
Uri? url;
WebUri? url;
///Message to be displayed in the window.
String? message;
@ -41,7 +41,7 @@ class JsPromptRequest {
return null;
}
final instance = JsPromptRequest(
url: map['url'] != null ? Uri.tryParse(map['url']) : null,
url: map['url'] != null ? WebUri(map['url']) : null,
message: map['message'],
defaultValue: map['defaultValue'],
iosIsMainFrame: map['isMainFrame'],

View File

@ -1,6 +1,7 @@
import 'package:flutter_inappwebview_internal_annotations/flutter_inappwebview_internal_annotations.dart';
import '../in_app_webview/webview.dart';
import '../web_uri.dart';
part 'loaded_resource.g.dart';
@ -12,7 +13,7 @@ class LoadedResource_ {
String? initiatorType;
///Resource URL.
Uri? url;
WebUri? url;
///Returns the [DOMHighResTimeStamp](https://developer.mozilla.org/en-US/docs/Web/API/DOMHighResTimeStamp) for the time a resource fetch started.
double? startTime;

View File

@ -13,7 +13,7 @@ class LoadedResource {
String? initiatorType;
///Resource URL.
Uri? url;
WebUri? url;
///Returns the [DOMHighResTimeStamp](https://developer.mozilla.org/en-US/docs/Web/API/DOMHighResTimeStamp) for the time a resource fetch started.
double? startTime;
@ -29,7 +29,7 @@ class LoadedResource {
}
final instance = LoadedResource(
initiatorType: map['initiatorType'],
url: map['url'] != null ? Uri.tryParse(map['url']) : null,
url: map['url'] != null ? WebUri(map['url']) : null,
startTime: map['startTime'],
duration: map['duration'],
);

View File

@ -1,5 +1,6 @@
import '../web_message/main.dart';
import '../web_uri.dart';
///The listener for handling [WebMessageListener] events sent by a `postMessage()` on the injected JavaScript object.
typedef void OnPostMessageCallback(String? message, Uri? sourceOrigin,
typedef void OnPostMessageCallback(String? message, WebUri? sourceOrigin,
bool isMainFrame, JavaScriptReplyProxy replyProxy);

View File

@ -1,6 +1,7 @@
import 'package:flutter_inappwebview_internal_annotations/flutter_inappwebview_internal_annotations.dart';
import '../in_app_webview/webview.dart';
import '../web_uri.dart';
import 'permission_resource_type.dart';
import 'permission_response.dart';
import 'frame_info.dart';
@ -11,7 +12,7 @@ part 'permission_request.g.dart';
@ExchangeableObject()
class PermissionRequest_ {
///The origin of web content which attempt to access the restricted resources.
Uri origin;
WebUri origin;
///List of resources the web content wants to access.
///

View File

@ -9,7 +9,7 @@ part of 'permission_request.dart';
///Class that represents the response used by the [WebView.onPermissionRequest] event.
class PermissionRequest {
///The origin of web content which attempt to access the restricted resources.
Uri origin;
WebUri origin;
///List of resources the web content wants to access.
///
@ -28,7 +28,7 @@ class PermissionRequest {
return null;
}
final instance = PermissionRequest(
origin: (Uri.tryParse(map['origin']) ?? Uri()),
origin: WebUri(map['origin']),
frame: FrameInfo.fromMap(map['frame']?.cast<String, dynamic>()),
);
instance.resources = List<PermissionResourceType>.from(map['resources']

View File

@ -3,6 +3,7 @@ import 'package:flutter_inappwebview_internal_annotations/flutter_inappwebview_i
import '../util.dart';
import '../print_job/main.dart';
import '../web_uri.dart';
import 'in_app_webview_rect.dart';
import 'print_job_color_mode.dart';
import 'print_job_duplex_mode.dart';
@ -130,7 +131,7 @@ class PrintJobAttributes_ {
///An URL containing the location to which the job file will be saved when the [jobDisposition] is [PrintJobDisposition.SAVE].
@SupportedPlatforms(platforms: [MacOSPlatform()])
Uri? jobSavingURL;
WebUri? jobSavingURL;
///If `true`, produce detailed reports when an error occurs.
@SupportedPlatforms(platforms: [MacOSPlatform()])

View File

@ -165,7 +165,7 @@ class PrintJobAttributes {
///
///**Supported Platforms/Implementations**:
///- MacOS
Uri? jobSavingURL;
WebUri? jobSavingURL;
///If `true`, produce detailed reports when an error occurs.
///
@ -273,9 +273,8 @@ class PrintJobAttributes {
isVerticallyCentered: map['isVerticallyCentered'],
isSelectionOnly: map['isSelectionOnly'],
scalingFactor: map['scalingFactor'],
jobSavingURL: map['jobSavingURL'] != null
? Uri.tryParse(map['jobSavingURL'])
: null,
jobSavingURL:
map['jobSavingURL'] != null ? WebUri(map['jobSavingURL']) : null,
detailedErrorReporting: map['detailedErrorReporting'],
faxNumber: map['faxNumber'],
headerAndFooter: map['headerAndFooter'],

View File

@ -1,6 +1,7 @@
import 'package:flutter_inappwebview_internal_annotations/flutter_inappwebview_internal_annotations.dart';
import '../in_app_webview/in_app_webview_controller.dart';
import '../web_uri.dart';
part 'request_focus_node_href_result.g.dart';
@ -8,7 +9,7 @@ part 'request_focus_node_href_result.g.dart';
@ExchangeableObject()
class RequestFocusNodeHrefResult_ {
///The anchor's href attribute.
Uri? url;
WebUri? url;
///The anchor's text.
String? title;

View File

@ -9,7 +9,7 @@ part of 'request_focus_node_href_result.dart';
///Class that represents the result used by the [InAppWebViewController.requestFocusNodeHref] method.
class RequestFocusNodeHrefResult {
///The anchor's href attribute.
Uri? url;
WebUri? url;
///The anchor's text.
String? title;
@ -24,7 +24,7 @@ class RequestFocusNodeHrefResult {
return null;
}
final instance = RequestFocusNodeHrefResult(
url: map['url'] != null ? Uri.tryParse(map['url']) : null,
url: map['url'] != null ? WebUri(map['url']) : null,
title: map['title'],
src: map['src'],
);

View File

@ -1,6 +1,7 @@
import 'package:flutter_inappwebview_internal_annotations/flutter_inappwebview_internal_annotations.dart';
import '../in_app_webview/in_app_webview_controller.dart';
import '../web_uri.dart';
part 'request_image_ref_result.g.dart';
@ -8,7 +9,7 @@ part 'request_image_ref_result.g.dart';
@ExchangeableObject()
class RequestImageRefResult_ {
///The image's url.
Uri? url;
WebUri? url;
RequestImageRefResult_({this.url});
}

View File

@ -9,7 +9,7 @@ part of 'request_image_ref_result.dart';
///Class that represents the result used by the [InAppWebViewController.requestImageRef] method.
class RequestImageRefResult {
///The image's url.
Uri? url;
WebUri? url;
RequestImageRefResult({this.url});
///Gets a possible [RequestImageRefResult] instance from a [Map] value.
@ -18,7 +18,7 @@ class RequestImageRefResult {
return null;
}
final instance = RequestImageRefResult(
url: map['url'] != null ? Uri.tryParse(map['url']) : null,
url: map['url'] != null ? WebUri(map['url']) : null,
);
return instance;
}

View File

@ -1,5 +1,7 @@
import 'package:flutter_inappwebview_internal_annotations/flutter_inappwebview_internal_annotations.dart';
import '../web_uri.dart';
part 'ui_event_attribution.g.dart';
///Class that represents an object that contains event attribution information for Private Click Measurement.
@ -18,7 +20,7 @@ class UIEventAttribution_ {
int sourceIdentifier;
///The destination URL of the attribution.
Uri destinationURL;
WebUri destinationURL;
///A description of the source of the attribution.
String sourceDescription;

View File

@ -21,7 +21,7 @@ class UIEventAttribution {
int sourceIdentifier;
///The destination URL of the attribution.
Uri destinationURL;
WebUri destinationURL;
///A description of the source of the attribution.
String sourceDescription;
@ -41,7 +41,7 @@ class UIEventAttribution {
}
final instance = UIEventAttribution(
sourceIdentifier: map['sourceIdentifier'],
destinationURL: (Uri.tryParse(map['destinationURL']) ?? Uri()),
destinationURL: WebUri(map['destinationURL']),
sourceDescription: map['sourceDescription'],
purchaser: map['purchaser'],
);

View File

@ -1,6 +1,7 @@
import 'dart:typed_data';
import 'package:flutter_inappwebview_internal_annotations/flutter_inappwebview_internal_annotations.dart';
import '../web_uri.dart';
import 'url_request_cache_policy.dart';
import 'url_request_network_service_type.dart';
import 'url_request_attribution.dart';
@ -11,7 +12,7 @@ part 'url_request.g.dart';
@ExchangeableObject()
class URLRequest_ {
///The URL of the request. Setting this to `null` will load `about:blank`.
Uri? url;
WebUri? url;
///The HTTP request method.
///
@ -142,7 +143,7 @@ class URLRequest_ {
apiUrl:
"https://developer.apple.com/documentation/foundation/urlrequest/2011552-maindocumenturl")
])
Uri? mainDocumentURL;
WebUri? mainDocumentURL;
///`true` if server endpoint is known to support HTTP/3. Enables QUIC racing
///without HTTP/3 service discovery. Defaults to `false`.

View File

@ -9,7 +9,7 @@ part of 'url_request.dart';
///A URL load request that is independent of protocol or URL scheme.
class URLRequest {
///The URL of the request. Setting this to `null` will load `about:blank`.
Uri? url;
WebUri? url;
///The HTTP request method.
///
@ -111,7 +111,7 @@ class URLRequest {
///
///**Supported Platforms/Implementations**:
///- iOS ([Official API - URLRequest.mainDocumentURL](https://developer.apple.com/documentation/foundation/urlrequest/2011552-maindocumenturl))
Uri? mainDocumentURL;
WebUri? mainDocumentURL;
///`true` if server endpoint is known to support HTTP/3. Enables QUIC racing
///without HTTP/3 service discovery. Defaults to `false`.
@ -177,7 +177,8 @@ class URLRequest {
URLRequestNetworkServiceType.fromNativeValue(
iosNetworkServiceType?.toNativeValue());
timeoutInterval = timeoutInterval ?? iosTimeoutInterval;
mainDocumentURL = mainDocumentURL ?? iosMainDocumentURL;
mainDocumentURL = mainDocumentURL ??
(iosMainDocumentURL != null ? WebUri.uri(iosMainDocumentURL!) : null);
}
///Gets a possible [URLRequest] instance from a [Map] value.
@ -186,7 +187,7 @@ class URLRequest {
return null;
}
final instance = URLRequest(
url: map['url'] != null ? Uri.tryParse(map['url']) : null,
url: map['url'] != null ? WebUri(map['url']) : null,
method: map['method'],
body: map['body'],
headers: map['headers']?.cast<String, String>(),
@ -213,7 +214,7 @@ class URLRequest {
? Uri.tryParse(map['mainDocumentURL'])
: null,
mainDocumentURL: map['mainDocumentURL'] != null
? Uri.tryParse(map['mainDocumentURL'])
? WebUri(map['mainDocumentURL'])
: null,
assumesHTTP3Capable: map['assumesHTTP3Capable'],
attribution: URLRequestAttribution.fromNativeValue(map['attribution']),

View File

@ -1,12 +1,14 @@
import 'package:flutter_inappwebview_internal_annotations/flutter_inappwebview_internal_annotations.dart';
import '../web_uri.dart';
part 'url_response.g.dart';
///The metadata associated with the response to a URL load request, independent of protocol and URL scheme.
@ExchangeableObject()
class URLResponse_ {
///The URL for the response.
Uri? url;
WebUri? url;
///The expected length of the responses content.
int expectedContentLength;

View File

@ -9,7 +9,7 @@ part of 'url_response.dart';
///The metadata associated with the response to a URL load request, independent of protocol and URL scheme.
class URLResponse {
///The URL for the response.
Uri? url;
WebUri? url;
///The expected length of the responses content.
int expectedContentLength;
@ -43,7 +43,7 @@ class URLResponse {
return null;
}
final instance = URLResponse(
url: map['url'] != null ? Uri.tryParse(map['url']) : null,
url: map['url'] != null ? WebUri(map['url']) : null,
expectedContentLength: map['expectedContentLength'],
mimeType: map['mimeType'],
suggestedFilename: map['suggestedFilename'],

View File

@ -2,6 +2,7 @@ import 'package:flutter_inappwebview_internal_annotations/flutter_inappwebview_i
import '../in_app_webview/webview.dart';
import '../web_uri.dart';
import 'web_history.dart';
part 'web_history_item.g.dart';
@ -11,13 +12,13 @@ part 'web_history_item.g.dart';
@ExchangeableObject()
class WebHistoryItem_ {
///Original url of this history item.
Uri? originalUrl;
WebUri? originalUrl;
///Document title of this history item.
String? title;
///Url of this history item.
Uri? url;
WebUri? url;
///0-based position index in the back-forward [WebHistory.list].
int? index;

View File

@ -10,13 +10,13 @@ part of 'web_history_item.dart';
///Each [WebHistoryItem] is a snapshot of the requested history item.
class WebHistoryItem {
///Original url of this history item.
Uri? originalUrl;
WebUri? originalUrl;
///Document title of this history item.
String? title;
///Url of this history item.
Uri? url;
WebUri? url;
///0-based position index in the back-forward [WebHistory.list].
int? index;
@ -33,9 +33,9 @@ class WebHistoryItem {
}
final instance = WebHistoryItem(
originalUrl:
map['originalUrl'] != null ? Uri.tryParse(map['originalUrl']) : null,
map['originalUrl'] != null ? WebUri(map['originalUrl']) : null,
title: map['title'],
url: map['url'] != null ? Uri.tryParse(map['url']) : null,
url: map['url'] != null ? WebUri(map['url']) : null,
index: map['index'],
offset: map['offset'],
);

View File

@ -1,6 +1,7 @@
import 'package:flutter_inappwebview_internal_annotations/flutter_inappwebview_internal_annotations.dart';
import '../in_app_webview/webview.dart';
import '../web_uri.dart';
part 'web_resource_request.g.dart';
@ -8,7 +9,7 @@ part 'web_resource_request.g.dart';
@ExchangeableObject()
class WebResourceRequest_ {
///The URL for which the resource request was made.
Uri url;
WebUri url;
///The headers associated with the request.
///

View File

@ -9,7 +9,7 @@ part of 'web_resource_request.dart';
///Class representing a resource request of the [WebView].
class WebResourceRequest {
///The URL for which the resource request was made.
Uri url;
WebUri url;
///The headers associated with the request.
///
@ -52,7 +52,7 @@ class WebResourceRequest {
return null;
}
final instance = WebResourceRequest(
url: (Uri.tryParse(map['url']) ?? Uri()),
url: WebUri(map['url']),
headers: map['headers']?.cast<String, String>(),
method: map['method'],
hasGesture: map['hasGesture'],

View File

@ -2,6 +2,7 @@ import 'dart:async';
import 'dart:typed_data';
import 'dart:ui';
import 'package:flutter/services.dart';
import 'package:flutter_inappwebview/src/web_uri.dart';
import 'dart:html';
import 'dart:js' as js;
@ -344,7 +345,7 @@ class InAppWebViewWebElement implements Disposable {
{required String url, required Uint8List postData}) async {
await loadUrl(
urlRequest:
URLRequest(url: Uri.tryParse(url), method: "POST", body: postData));
URLRequest(url: WebUri(url), method: "POST", body: postData));
}
Future<void> injectJavascriptFileFromUrl(

View File

@ -7,11 +7,12 @@ import '../debug_logging_settings.dart';
import '../types/main.dart';
import '../types/disposable.dart';
import '../web_uri.dart';
import 'web_authenticate_session_settings.dart';
///A completion handler for the [WebAuthenticationSession].
typedef WebAuthenticationSessionCompletionHandler = Future<void> Function(
Uri? url, WebAuthenticationSessionError? error)?;
WebUri? url, WebAuthenticationSessionError? error)?;
///A session that an app uses to authenticate a user through a web service.
///
@ -44,7 +45,7 @@ class WebAuthenticationSession implements Disposable {
late final String id;
///A URL with the `http` or `https` scheme pointing to the authentication webpage.
final Uri url;
final WebUri url;
///The custom URL scheme that the app expects in the callback URL.
final String? callbackURLScheme;
@ -67,7 +68,7 @@ class WebAuthenticationSession implements Disposable {
///
///[onComplete] represents a completion handler the session calls when it completes successfully, or when the user cancels the session.
static Future<WebAuthenticationSession> create(
{required Uri url,
{required WebUri url,
String? callbackURLScheme,
WebAuthenticationSessionCompletionHandler onComplete,
WebAuthenticationSessionSettings? initialSettings}) async {
@ -129,7 +130,7 @@ class WebAuthenticationSession implements Disposable {
switch (call.method) {
case "onComplete":
String? url = call.arguments["url"];
Uri? uri = url != null ? Uri.tryParse(url) : null;
WebUri? uri = url != null ? WebUri(url) : null;
var error = WebAuthenticationSessionError.fromNativeValue(
call.arguments["errorCode"]);
if (onComplete != null) {

View File

@ -1,6 +1,7 @@
import 'package:flutter/services.dart';
import '../in_app_webview/in_app_webview_controller.dart';
import '../types/main.dart';
import '../web_uri.dart';
///This listener receives messages sent on the JavaScript object which was injected by [InAppWebViewController.addWebMessageListener].
///
@ -59,8 +60,8 @@ class WebMessageListener {
}
if (onPostMessage != null) {
String? message = call.arguments["message"];
Uri? sourceOrigin = call.arguments["sourceOrigin"] != null
? Uri.tryParse(call.arguments["sourceOrigin"])
WebUri? sourceOrigin = call.arguments["sourceOrigin"] != null
? WebUri(call.arguments["sourceOrigin"])
: null;
bool isMainFrame = call.arguments["isMainFrame"];
onPostMessage!(message, sourceOrigin, isMainFrame, _replyProxy!);

200
lib/src/web_uri.dart Normal file
View File

@ -0,0 +1,200 @@
///Class that implements the [Uri] interface to maintain also the raw string value used by [Uri.parse].
///
///This class is used because some strings coming from the native platform side
///are not parsed correctly or could lose letter case information,
///so [rawValue] can be used as a fallback value.
///
///Examples:
///```dart
/// // InAppWebView example
/// InAppWebView(
/// initialUrlRequest:
/// URLRequest(url: WebUri('https://flutter.dev'))
/// )
///
/// // example of letter case difference
/// final uri = WebUri('scheme://customHostValue', forceToStringRawValue: false);
/// print(uri.rawValue); // scheme://customHostValue
/// print(uri.isValidUri); // true
/// print(uri.uriValue.toString()); // scheme://customhostvalue
/// print(uri.toString()); // scheme://customhostvalue
///
/// uri.forceToStringRawValue = true;
/// print(uri.toString()); // scheme://customHostValue
///
/// // example of a not valid URI
/// // Uncaught Error: FormatException: Invalid port (at character 14)
/// final invalidUri = WebUri('intent://not:valid_uri');
/// print(invalidUri.rawValue); // intent://not:valid_uri
/// print(invalidUri.isValidUri); // false
/// print(invalidUri.uriValue.toString()); // ''
/// print(invalidUri.toString()); // intent://not:valid_uri
///```
class WebUri implements Uri {
Uri _uri = Uri();
String _rawValue = '';
bool _isValidUri = false;
///Whether to force the usage of [rawValue] when calling [toString] or not.
///Because [toString] is used to send URI strings to the native platform side,
///this flag is useful when you want to send [rawValue] instead of [uriValue]`.toString()`.
///
///The default value is `false`.
bool forceToStringRawValue = false;
///Initialize a [WebUri] using a raw string value.
///In this case, [uriValue]`.toString()` and [rawValue] could not have the same value.
WebUri(String source, {this.forceToStringRawValue = false}) {
_rawValue = source;
try {
_uri = Uri.parse(this._rawValue);
_isValidUri = true;
} catch (e, stacktrace) {
print(e);
print(stacktrace);
}
}
///Initialize a [WebUri] using an [Uri] instance.
///In this case, [uriValue]`.toString()` and [rawValue] will have the same value.
WebUri.uri(Uri uri) {
_uri = uri;
_rawValue = uri.toString();
_isValidUri = true;
}
///Raw string value used by [Uri.parse].
String get rawValue => _rawValue;
///Uri parsed value. If [isValidUri] is `false`, the value will be `Uri()`.
Uri get uriValue => _uri;
///`true` if [rawValue] has been parsed correctly, otherwise `false`.
bool get isValidUri => _isValidUri;
@override
String get authority => _uri.authority;
@override
UriData? get data => _uri.data;
@override
String get fragment => _uri.fragment;
@override
bool get hasAbsolutePath => _uri.hasAbsolutePath;
@override
bool get hasAuthority => _uri.hasAuthority;
@override
bool get hasEmptyPath => _uri.hasEmptyPath;
@override
bool get hasFragment => _uri.hasFragment;
@override
bool get hasPort => _uri.hasPort;
@override
bool get hasQuery => _uri.hasQuery;
@override
bool get hasScheme => _uri.hasScheme;
@override
String get host => _uri.host;
@override
bool get isAbsolute => _uri.isAbsolute;
@override
bool isScheme(String scheme) {
return _uri.isScheme(scheme);
}
@override
Uri normalizePath() {
return _uri.normalizePath();
}
@override
String get origin => _uri.origin;
@override
String get path => _uri.path;
@override
List<String> get pathSegments => _uri.pathSegments;
@override
int get port => _uri.port;
@override
String get query => _uri.query;
@override
Map<String, String> get queryParameters => _uri.queryParameters;
@override
Map<String, List<String>> get queryParametersAll => _uri.queryParametersAll;
@override
Uri removeFragment() {
return _uri.removeFragment();
}
@override
Uri replace(
{String? scheme,
String? userInfo,
String? host,
int? port,
String? path,
Iterable<String>? pathSegments,
String? query,
Map<String, dynamic>? queryParameters,
String? fragment}) {
return _uri.replace(
scheme: scheme,
userInfo: userInfo,
host: host,
port: port,
path: path,
pathSegments: pathSegments,
query: query,
queryParameters: queryParameters,
fragment: fragment);
}
@override
Uri resolve(String reference) {
return _uri.resolve(reference);
}
@override
Uri resolveUri(Uri reference) {
return _uri.resolveUri(reference);
}
@override
String get scheme => _uri.scheme;
@override
String toFilePath({bool? windows}) {
return _uri.toFilePath(windows: windows);
}
@override
String get userInfo => _uri.userInfo;
///If [forceToStringRawValue] is `true` or [isValidUri] is `false`, it returns [rawValue],
///otherwise the value of [uriValue]`.toString()`.
@override
String toString() {
return forceToStringRawValue || !_isValidUri ? _rawValue : _uri.toString();
}
@override
dynamic noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
}

View File

@ -1,6 +1,6 @@
name: flutter_inappwebview
description: A Flutter plugin that allows you to add an inline webview, to use an headless webview, and to open an in-app browser window.
version: 6.0.0-beta.9
version: 6.0.0-beta.10
homepage: https://inappwebview.dev/
repository: https://github.com/pichillilorenzo/flutter_inappwebview
issue_tracker: https://github.com/pichillilorenzo/flutter_inappwebview/issues