From fa5449a50d41c4f59e1eb9d8cca283f19f50d889 Mon Sep 17 00:00:00 2001 From: Lorenzo Pichilli Date: Thu, 27 Oct 2022 11:02:49 +0200 Subject: [PATCH] Created WebUri class to replace Uri dart core type, fix #1402, fix #1328, fix #1350 --- CHANGELOG.md | 11 + .../types/WebResourceRequestExt.java | 13 +- .../in_app_webview/InAppWebViewClient.java | 14 +- .../src/exchangeable_object_generator.dart | 15 ++ .../chrome_safari_browser/custom_tabs.dart | 2 +- .../chrome_safari_browser/open_and_close.dart | 2 +- example/integration_test/constants.dart | 40 ++-- .../cookie_manager/set_get_delete.dart | 2 +- .../load_asset_file.dart | 4 +- .../in_app_webview/audio_playback_policy.dart | 4 +- .../in_app_webview/get_title.dart | 2 +- .../http_auth_credential_database.dart | 6 +- .../in_app_webview/inject_css.dart | 2 +- .../inject_javascript_file.dart | 5 +- .../in_app_webview/is_secure_context.dart | 2 +- .../in_app_webview/load_file_url.dart | 13 +- .../in_app_webview/on_received_error.dart | 2 +- .../in_app_webview/post_requests.dart | 11 +- .../in_app_webview/programmatic_scroll.dart | 5 +- .../programmatic_zoom_scale.dart | 6 +- .../in_app_webview/resize_webview.dart | 3 +- .../should_override_url_loading.dart | 8 +- .../in_app_webview/ssl_request.dart | 2 +- .../in_app_webview/video_playback_policy.dart | 10 +- .../in_app_webview/web_message.dart | 2 +- .../in_app_webview/webview_windows.dart | 2 +- example/integration_test/util.dart | 2 +- .../chrome_safari_browser_example.screen.dart | 2 +- .../lib/headless_in_app_webview.screen.dart | 4 +- .../lib/in_app_browser_example.screen.dart | 4 +- example/lib/in_app_webiew_example.screen.dart | 8 +- example/lib/main.dart | 15 +- ...authentication_session_example.screen.dart | 2 +- .../chrome_safari_browser.dart | 43 ++-- lib/src/cookie_manager.dart | 15 +- lib/src/in_app_browser/in_app_browser.dart | 28 +-- .../headless_in_app_webview.dart | 24 ++- lib/src/in_app_webview/in_app_webview.dart | 25 ++- .../in_app_webview_controller.dart | 80 ++++--- .../in_app_webview_settings.dart | 3 +- .../in_app_webview_settings.g.dart | 4 +- lib/src/in_app_webview/webview.dart | 25 ++- lib/src/main.dart | 1 + lib/src/print_job/print_job_settings.dart | 8 +- lib/src/types/ajax_request.dart | 5 +- lib/src/types/ajax_request.g.dart | 8 +- lib/src/types/download_start_request.dart | 3 +- lib/src/types/download_start_request.g.dart | 4 +- lib/src/types/favicon.dart | 3 +- lib/src/types/favicon.g.dart | 4 +- lib/src/types/fetch_request.dart | 3 +- lib/src/types/fetch_request.g.dart | 4 +- .../fetch_request_federated_credential.dart | 3 +- .../fetch_request_federated_credential.g.dart | 4 +- .../fetch_request_password_credential.dart | 3 +- .../fetch_request_password_credential.g.dart | 4 +- .../types/in_app_webview_initial_data.dart | 5 +- .../types/in_app_webview_initial_data.g.dart | 12 +- lib/src/types/js_alert_request.dart | 3 +- lib/src/types/js_alert_request.g.dart | 4 +- lib/src/types/js_before_unload_request.dart | 3 +- lib/src/types/js_before_unload_request.g.dart | 4 +- lib/src/types/js_confirm_request.dart | 3 +- lib/src/types/js_confirm_request.g.dart | 4 +- lib/src/types/js_prompt_request.dart | 3 +- lib/src/types/js_prompt_request.g.dart | 4 +- lib/src/types/loaded_resource.dart | 3 +- lib/src/types/loaded_resource.g.dart | 4 +- lib/src/types/on_post_message_callback.dart | 3 +- lib/src/types/permission_request.dart | 3 +- lib/src/types/permission_request.g.dart | 4 +- lib/src/types/print_job_attributes.dart | 3 +- lib/src/types/print_job_attributes.g.dart | 7 +- .../types/request_focus_node_href_result.dart | 3 +- .../request_focus_node_href_result.g.dart | 4 +- lib/src/types/request_image_ref_result.dart | 3 +- lib/src/types/request_image_ref_result.g.dart | 4 +- lib/src/types/ui_event_attribution.dart | 4 +- lib/src/types/ui_event_attribution.g.dart | 4 +- lib/src/types/url_request.dart | 5 +- lib/src/types/url_request.g.dart | 11 +- lib/src/types/url_response.dart | 4 +- lib/src/types/url_response.g.dart | 4 +- lib/src/types/web_history_item.dart | 5 +- lib/src/types/web_history_item.g.dart | 8 +- lib/src/types/web_resource_request.dart | 3 +- lib/src/types/web_resource_request.g.dart | 4 +- lib/src/web/in_app_web_view_web_element.dart | 3 +- .../web_authenticate_session.dart | 9 +- lib/src/web_message/web_message_listener.dart | 5 +- lib/src/web_uri.dart | 200 ++++++++++++++++++ pubspec.yaml | 2 +- 92 files changed, 579 insertions(+), 307 deletions(-) create mode 100644 lib/src/web_uri.dart diff --git a/CHANGELOG.md b/CHANGELOG.md index 9c586758..4e66b57f 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/types/WebResourceRequestExt.java b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/types/WebResourceRequestExt.java index f0a41d40..f866c78c 100644 --- a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/types/WebResourceRequestExt.java +++ b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/types/WebResourceRequestExt.java @@ -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 headers; private boolean isRedirect; private boolean hasGesture; private boolean isForMainFrame; private String method; - public WebResourceRequestExt(@NonNull Uri url, Map headers, boolean isRedirect, boolean hasGesture, boolean isForMainFrame, String method) { + public WebResourceRequestExt(@NonNull String url, Map 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 toMap() { Map 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; } diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/webview/in_app_webview/InAppWebViewClient.java b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/webview/in_app_webview/InAppWebViewClient.java index af415ed9..ead03e50 100755 --- a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/webview/in_app_webview/InAppWebViewClient.java +++ b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/webview/in_app_webview/InAppWebViewClient.java @@ -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); diff --git a/dev_packages/generators/lib/src/exchangeable_object_generator.dart b/dev_packages/generators/lib/src/exchangeable_object_generator.dart index 2a020fd8..a4a89207 100644 --- a/dev_packages/generators/lib/src/exchangeable_object_generator.dart +++ b/dev_packages/generators/lib/src/exchangeable_object_generator.dart @@ -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()'; diff --git a/example/integration_test/chrome_safari_browser/custom_tabs.dart b/example/integration_test/chrome_safari_browser/custom_tabs.dart index 4be2faac..de548e0d 100644 --- a/example/integration_test/chrome_safari_browser/custom_tabs.dart +++ b/example/integration_test/chrome_safari_browser/custom_tabs.dart @@ -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); diff --git a/example/integration_test/chrome_safari_browser/open_and_close.dart b/example/integration_test/chrome_safari_browser/open_and_close.dart index 13d2a6d8..a9979b17 100644 --- a/example/integration_test/chrome_safari_browser/open_and_close.dart +++ b/example/integration_test/chrome_safari_browser/open_and_close.dart @@ -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( diff --git a/example/integration_test/constants.dart b/example/integration_test/constants.dart index df709a96..8c13786b 100644 --- a/example/integration_test/constants.dart +++ b/example/integration_test/constants.dart @@ -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'); diff --git a/example/integration_test/cookie_manager/set_get_delete.dart b/example/integration_test/cookie_manager/set_get_delete.dart index badc3588..21256d55 100644 --- a/example/integration_test/cookie_manager/set_get_delete.dart +++ b/example/integration_test/cookie_manager/set_get_delete.dart @@ -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 cookies = await cookieManager.getCookies(url: url); diff --git a/example/integration_test/in_app_localhost_server/load_asset_file.dart b/example/integration_test/in_app_localhost_server/load_asset_file.dart index 6a7a7c9e..08faa9e3 100644 --- a/example/integration_test/in_app_localhost_server/load_asset_file.dart +++ b/example/integration_test/in_app_localhost_server/load_asset_file.dart @@ -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); }, diff --git a/example/integration_test/in_app_webview/audio_playback_policy.dart b/example/integration_test/in_app_webview/audio_playback_policy.dart index 6d4d2d5b..7b632b6b 100644 --- a/example/integration_test/in_app_webview/audio_playback_policy.dart +++ b/example/integration_test/in_app_webview/audio_playback_policy.dart @@ -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); diff --git a/example/integration_test/in_app_webview/get_title.dart b/example/integration_test/in_app_webview/get_title.dart index d96335cd..9c8beb8f 100644 --- a/example/integration_test/in_app_webview/get_title.dart +++ b/example/integration_test/in_app_webview/get_title.dart @@ -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'; diff --git a/example/integration_test/in_app_webview/http_auth_credential_database.dart b/example/integration_test/in_app_webview/http_auth_credential_database.dart index dfc8f0a2..0f41785a 100644 --- a/example/integration_test/in_app_webview/http_auth_credential_database.dart +++ b/example/integration_test/in_app_webview/http_auth_credential_database.dart @@ -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); }, diff --git a/example/integration_test/in_app_webview/inject_css.dart b/example/integration_test/in_app_webview/inject_css.dart index 0c5e6435..db19a0f6 100644 --- a/example/integration_test/in_app_webview/inject_css.dart +++ b/example/integration_test/in_app_webview/inject_css.dart @@ -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)); diff --git a/example/integration_test/in_app_webview/inject_javascript_file.dart b/example/integration_test/in_app_webview/inject_javascript_file.dart index 9360bc3d..42413483 100644 --- a/example/integration_test/in_app_webview/inject_javascript_file.dart +++ b/example/integration_test/in_app_webview/inject_javascript_file.dart @@ -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: () { diff --git a/example/integration_test/in_app_webview/is_secure_context.dart b/example/integration_test/in_app_webview/is_secure_context.dart index bd397ab9..938be690 100644 --- a/example/integration_test/in_app_webview/is_secure_context.dart +++ b/example/integration_test/in_app_webview/is_secure_context.dart @@ -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); } diff --git a/example/integration_test/in_app_webview/load_file_url.dart b/example/integration_test/in_app_webview/load_file_url.dart index 2f4ef400..a2f69f9c 100644 --- a/example/integration_test/in_app_webview/load_file_url.dart +++ b/example/integration_test/in_app_webview/load_file_url.dart @@ -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); diff --git a/example/integration_test/in_app_webview/on_received_error.dart b/example/integration_test/in_app_webview/on_received_error.dart index 285588b3..2e45e41b 100644 --- a/example/integration_test/in_app_webview/on_received_error.dart +++ b/example/integration_test/in_app_webview/on_received_error.dart @@ -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(); diff --git a/example/integration_test/in_app_webview/post_requests.dart b/example/integration_test/in_app_webview/post_requests.dart index 3703cfa6..ac391a59 100644 --- a/example/integration_test/in_app_webview/post_requests.dart +++ b/example/integration_test/in_app_webview/post_requests.dart @@ -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; diff --git a/example/integration_test/in_app_webview/programmatic_scroll.dart b/example/integration_test/in_app_webview/programmatic_scroll.dart index 016e0ee3..f65aff24 100644 --- a/example/integration_test/in_app_webview/programmatic_scroll.dart +++ b/example/integration_test/in_app_webview/programmatic_scroll.dart @@ -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 pageLoaded = Completer(); @@ -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); diff --git a/example/integration_test/in_app_webview/programmatic_zoom_scale.dart b/example/integration_test/in_app_webview/programmatic_zoom_scale.dart index 9a718760..7a0a942d 100644 --- a/example/integration_test/in_app_webview/programmatic_zoom_scale.dart +++ b/example/integration_test/in_app_webview/programmatic_zoom_scale.dart @@ -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); }, diff --git a/example/integration_test/in_app_webview/resize_webview.dart b/example/integration_test/in_app_webview/resize_webview.dart index 5b46ea17..e6bd5f94 100644 --- a/example/integration_test/in_app_webview/resize_webview.dart +++ b/example/integration_test/in_app_webview/resize_webview.dart @@ -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); diff --git a/example/integration_test/in_app_webview/should_override_url_loading.dart b/example/integration_test/in_app_webview/should_override_url_loading.dart index df1be6fd..9552e1d3 100644 --- a/example/integration_test/in_app_webview/should_override_url_loading.dart +++ b/example/integration_test/in_app_webview/should_override_url_loading.dart @@ -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); }, diff --git a/example/integration_test/in_app_webview/ssl_request.dart b/example/integration_test/in_app_webview/ssl_request.dart index 6265510f..14554a2d 100644 --- a/example/integration_test/in_app_webview/ssl_request.dart +++ b/example/integration_test/in_app_webview/ssl_request.dart @@ -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); }, diff --git a/example/integration_test/in_app_webview/video_playback_policy.dart b/example/integration_test/in_app_webview/video_playback_policy.dart index 2178a0ce..ea2ad136 100644 --- a/example/integration_test/in_app_webview/video_playback_policy.dart +++ b/example/integration_test/in_app_webview/video_playback_policy.dart @@ -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); diff --git a/example/integration_test/in_app_webview/web_message.dart b/example/integration_test/in_app_webview/web_message.dart index 669f4396..6c739265 100644 --- a/example/integration_test/in_app_webview/web_message.dart +++ b/example/integration_test/in_app_webview/web_message.dart @@ -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();"); }, diff --git a/example/integration_test/in_app_webview/webview_windows.dart b/example/integration_test/in_app_webview/webview_windows.dart index 6b619725..1208b39c 100644 --- a/example/integration_test/in_app_webview/webview_windows.dart +++ b/example/integration_test/in_app_webview/webview_windows.dart @@ -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); diff --git a/example/integration_test/util.dart b/example/integration_test/util.dart index 3ea3fb66..3ad44249 100644 --- a/example/integration_test/util.dart +++ b/example/integration_test/util.dart @@ -44,7 +44,7 @@ class MyInAppBrowser extends InAppBrowser { } @override - void onLoadStop(Uri? url) { + void onLoadStop(WebUri? url) { super.onLoadStop(url); if (!firstPageLoaded.isCompleted) { diff --git a/example/lib/chrome_safari_browser_example.screen.dart b/example/lib/chrome_safari_browser_example.screen.dart index 259629b6..99995909 100755 --- a/example/lib/chrome_safari_browser_example.screen.dart +++ b/example/lib/chrome_safari_browser_example.screen.dart @@ -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, diff --git a/example/lib/headless_in_app_webview.screen.dart b/example/lib/headless_in_app_webview.screen.dart index 6cd0d98f..1d260f38 100755 --- a/example/lib/headless_in_app_webview.screen.dart +++ b/example/lib/headless_in_app_webview.screen.dart @@ -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), diff --git a/example/lib/in_app_browser_example.screen.dart b/example/lib/in_app_browser_example.screen.dart index 76da9d8d..fee28a14 100755 --- a/example/lib/in_app_browser_example.screen.dart +++ b/example/lib/in_app_browser_example.screen.dart @@ -109,7 +109,7 @@ class _InAppBrowserExampleScreenState extends State { 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 { ElevatedButton( onPressed: () async { await InAppBrowser.openWithSystemBrowser( - url: Uri.parse("https://flutter.dev/")); + url: WebUri("https://flutter.dev/")); }, child: Text("Open System Browser")), ]))); diff --git a/example/lib/in_app_webiew_example.screen.dart b/example/lib/in_app_webiew_example.screen.dart index 30ab98c8..2c704c19 100755 --- a/example/lib/in_app_webiew_example.screen.dart +++ b/example/lib/in_app_webiew_example.screen.dart @@ -99,9 +99,9 @@ class _InAppWebViewExampleScreenState extends State { 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 { 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([]), initialSettings: settings, diff --git a/example/lib/main.dart b/example/lib/main.dart index 24450208..ab962709 100755 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -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 { 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 { '/InAppBrowser': (context) => InAppBrowserExampleScreen(), '/ChromeSafariBrowser': (context) => ChromeSafariBrowserExampleScreen(), '/HeadlessInAppWebView': (context) => HeadlessInAppWebViewExampleScreen(), - '/WebAuthenticationSession': (context) => WebAuthenticationSessionExampleScreen(), + '/WebAuthenticationSession': (context) => + WebAuthenticationSessionExampleScreen(), }); } } diff --git a/example/lib/web_authentication_session_example.screen.dart b/example/lib/web_authentication_session_example.screen.dart index 541e5cc1..761cf80d 100755 --- a/example/lib/web_authentication_session_example.screen.dart +++ b/example/lib/web_authentication_session_example.screen.dart @@ -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 { diff --git a/lib/src/chrome_safari_browser/chrome_safari_browser.dart b/lib/src/chrome_safari_browser/chrome_safari_browser.dart index 45c16aa4..2ee4a0d2 100755 --- a/lib/src/chrome_safari_browser/chrome_safari_browser.dart +++ b/lib/src/chrome_safari_browser/chrome_safari_browser.dart @@ -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 open( - {Uri? url, + {WebUri? url, Map? headers, - List? otherLikelyURLs, - Uri? referrer, + List? 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 launchUrl({ - required Uri url, + required WebUri url, Map? headers, - List? otherLikelyURLs, - Uri? referrer, + List? otherLikelyURLs, + WebUri? referrer, }) async { Map args = {}; 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 mayLaunchUrl({Uri? url, List? otherLikelyURLs}) async { + Future mayLaunchUrl( + {WebUri? url, List? otherLikelyURLs}) async { Map args = {}; 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 validateRelationship( - {required CustomTabsRelationType relation, required Uri origin}) async { + {required CustomTabsRelationType relation, + required WebUri origin}) async { Map args = {}; 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 prewarmConnections(List URLs) async { + static Future prewarmConnections(List URLs) async { Map args = {}; args.putIfAbsent('URLs', () => URLs.map((e) => e.toString()).toList()); Map? 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}); diff --git a/lib/src/cookie_manager.dart b/lib/src/cookie_manager.dart index 5d85d608..beab653b 100755 --- a/lib/src/cookie_manager.dart +++ b/lib/src/cookie_manager.dart @@ -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 setCookie( - {required Uri url, + {required WebUri url, required String name, required String value, String path = "/", @@ -127,7 +128,7 @@ class CookieManager { } Future _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> getCookies( - {required Uri url, + {required WebUri url, @Deprecated("Use webViewController instead") InAppWebViewController? iosBelow11WebViewController, InAppWebViewController? webViewController}) async { @@ -235,7 +236,7 @@ class CookieManager { } Future> _getCookiesWithJavaScript( - {required Uri url, InAppWebViewController? webViewController}) async { + {required WebUri url, InAppWebViewController? webViewController}) async { assert(url.toString().isNotEmpty); List cookies = []; @@ -310,7 +311,7 @@ class CookieManager { ///- MacOS ///- Web Future 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 deleteCookie( - {required Uri url, + {required WebUri url, required String name, String path = "/", String? domain, @@ -424,7 +425,7 @@ class CookieManager { ///- MacOS ///- Web Future deleteCookies( - {required Uri url, + {required WebUri url, String path = "/", String? domain, @Deprecated("Use webViewController instead") diff --git a/lib/src/in_app_browser/in_app_browser.dart b/lib/src/in_app_browser/in_app_browser.dart index 82fd6d3a..4081a04b 100755 --- a/lib/src/in_app_browser/in_app_browser.dart +++ b/lib/src/in_app_browser/in_app_browser.dart @@ -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 openWithSystemBrowser({required Uri url}) async { + static Future openWithSystemBrowser({required WebUri url}) async { assert(url.toString().isNotEmpty); Map args = {}; 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? 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? 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? onRenderProcessUnresponsive(Uri? url) { + Future? 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? onRenderProcessResponsive(Uri? url) { + Future? 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? onFormResubmission(Uri? url) { + Future? 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') diff --git a/lib/src/in_app_webview/headless_in_app_webview.dart b/lib/src/in_app_webview/headless_in_app_webview.dart index c0c9ca12..0943066f 100644 --- a/lib/src/in_app_webview/headless_in_app_webview.dart +++ b/lib/src/in_app_webview/headless_in_app_webview.dart @@ -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 Function(InAppWebViewController controller, Uri? url, + Future 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 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 Function( - InAppWebViewController controller, Uri? url)? onRenderProcessResponsive; + InAppWebViewController controller, WebUri? url)? + onRenderProcessResponsive; @override Future Function( - InAppWebViewController controller, Uri? url)? onRenderProcessUnresponsive; + InAppWebViewController controller, WebUri? url)? + onRenderProcessUnresponsive; @override Future Function(InAppWebViewController controller, - Uri url, SafeBrowsingThreat? threatType)? onSafeBrowsingHit; + WebUri url, SafeBrowsingThreat? threatType)? onSafeBrowsingHit; @override void Function(InAppWebViewController controller)? diff --git a/lib/src/in_app_webview/in_app_webview.dart b/lib/src/in_app_webview/in_app_webview.dart index a3e1a35f..ab3d88fe 100755 --- a/lib/src/in_app_webview/in_app_webview.dart +++ b/lib/src/in_app_webview/in_app_webview.dart @@ -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 Function(InAppWebViewController controller, Uri? url, + final Future 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 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 Function( - InAppWebViewController controller, Uri? url)? onRenderProcessResponsive; + InAppWebViewController controller, WebUri? url)? + onRenderProcessResponsive; @override final Future Function( - InAppWebViewController controller, Uri? url)? onRenderProcessUnresponsive; + InAppWebViewController controller, WebUri? url)? + onRenderProcessUnresponsive; @override final Future Function( InAppWebViewController controller, - Uri url, + WebUri url, SafeBrowsingThreat? threatType)? onSafeBrowsingHit; @override diff --git a/lib/src/in_app_webview/in_app_webview_controller.dart b/lib/src/in_app_webview/in_app_webview_controller.dart index 4bd7e244..71cd0727 100644 --- a/lib/src/in_app_webview/in_app_webview_controller.dart +++ b/lib/src/in_app_webview/in_app_webview_controller.dart @@ -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 getUrl() async { + Future getUrl() async { Map args = {}; 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 _createFavicons(Uri url, String? assetPathBase, String urlIcon, - String? rel, String? sizes, bool isManifest) { + List _createFavicons(WebUri url, String? assetPathBase, + String urlIcon, String? rel, String? sizes, bool isManifest) { List favicons = []; List 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 postUrl({required Uri url, required Uint8List postData}) async { + Future postUrl( + {required WebUri url, required Uint8List postData}) async { assert(url.toString().isNotEmpty); Map args = {}; 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 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 injectCSSFileFromUrl( - {required Uri urlFile, + {required WebUri urlFile, CSSLinkHtmlTagAttributes? cssLinkHtmlTagAttributes}) async { assert(urlFile.toString().isNotEmpty); Map args = {}; @@ -2453,10 +2449,10 @@ class InAppWebViewController { ///- iOS ///- MacOS ///- Web - Future getOriginalUrl() async { + Future getOriginalUrl() async { Map args = {}; 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 postWebMessage( - {required WebMessage message, Uri? targetOrigin}) async { + {required WebMessage message, WebUri? targetOrigin}) async { if (targetOrigin == null) { - targetOrigin = Uri(); + targetOrigin = WebUri(''); } Map args = {}; 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("

Hello

")) ///); @@ -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 getSafeBrowsingPrivacyPolicyUrl() async { + static Future getSafeBrowsingPrivacyPolicyUrl() async { Map args = {}; String? url = await _staticChannel.invokeMethod( 'getSafeBrowsingPrivacyPolicyUrl', args); - return url != null ? Uri.tryParse(url) : null; + return url != null ? WebUri(url) : null; } ///Use [setSafeBrowsingAllowlist] instead. diff --git a/lib/src/in_app_webview/in_app_webview_settings.dart b/lib/src/in_app_webview/in_app_webview_settings.dart index dd00d45a..b6f665fd 100755 --- a/lib/src/in_app_webview/in_app_webview_settings.dart +++ b/lib/src/in_app_webview/in_app_webview_settings.dart @@ -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. diff --git a/lib/src/in_app_webview/in_app_webview_settings.g.dart b/lib/src/in_app_webview/in_app_webview_settings.g.dart index 5169263c..3945a36b 100644 --- a/lib/src/in_app_webview/in_app_webview_settings.g.dart +++ b/lib/src/in_app_webview/in_app_webview_settings.g.dart @@ -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']) diff --git a/lib/src/in_app_webview/webview.dart b/lib/src/in_app_webview/webview.dart index 4772e7bc..d03bdb13 100644 --- a/lib/src/in_app_webview/webview.dart +++ b/lib/src/in_app_webview/webview.dart @@ -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 Function(InAppWebViewController controller, Uri? url, + final Future 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 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 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 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 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. diff --git a/lib/src/main.dart b/lib/src/main.dart index c80f775d..05215eb6 100644 --- a/lib/src/main.dart +++ b/lib/src/main.dart @@ -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'; diff --git a/lib/src/print_job/print_job_settings.dart b/lib/src/print_job/print_job_settings.dart index ba1f6d7e..2d06d794 100644 --- a/lib/src/print_job/print_job_settings.dart +++ b/lib/src/print_job/print_job_settings.dart @@ -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"]), diff --git a/lib/src/types/ajax_request.dart b/lib/src/types/ajax_request.dart index 42d56f71..893b4072 100644 --- a/lib/src/types/ajax_request.dart +++ b/lib/src/types/ajax_request.dart @@ -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). diff --git a/lib/src/types/ajax_request.g.dart b/lib/src/types/ajax_request.g.dart index 8109d7d8..48c68294 100644 --- a/lib/src/types/ajax_request.g.dart +++ b/lib/src/types/ajax_request.g.dart @@ -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'], diff --git a/lib/src/types/download_start_request.dart b/lib/src/types/download_start_request.dart index a62fefb9..279e103c 100644 --- a/lib/src/types/download_start_request.dart +++ b/lib/src/types/download_start_request.dart @@ -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; diff --git a/lib/src/types/download_start_request.g.dart b/lib/src/types/download_start_request.g.dart index 2bc722ba..6e5ae15c 100644 --- a/lib/src/types/download_start_request.g.dart +++ b/lib/src/types/download_start_request.g.dart @@ -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'], diff --git a/lib/src/types/favicon.dart b/lib/src/types/favicon.dart index 4a0c87a2..3a7282f4 100644 --- a/lib/src/types/favicon.dart +++ b/lib/src/types/favicon.dart @@ -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; diff --git a/lib/src/types/favicon.g.dart b/lib/src/types/favicon.g.dart index 9730cdd2..7b1526ad 100644 --- a/lib/src/types/favicon.g.dart +++ b/lib/src/types/favicon.g.dart @@ -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'], diff --git a/lib/src/types/fetch_request.dart b/lib/src/types/fetch_request.dart index 6db506b0..ad3f949e 100644 --- a/lib/src/types/fetch_request.dart +++ b/lib/src/types/fetch_request.dart @@ -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; diff --git a/lib/src/types/fetch_request.g.dart b/lib/src/types/fetch_request.g.dart index 9cf02803..59205344 100644 --- a/lib/src/types/fetch_request.g.dart +++ b/lib/src/types/fetch_request.g.dart @@ -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(), body: map['body'], diff --git a/lib/src/types/fetch_request_federated_credential.dart b/lib/src/types/fetch_request_federated_credential.dart index 5b880730..6d8fd1c4 100644 --- a/lib/src/types/fetch_request_federated_credential.dart +++ b/lib/src/types/fetch_request_federated_credential.dart @@ -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}) diff --git a/lib/src/types/fetch_request_federated_credential.g.dart b/lib/src/types/fetch_request_federated_credential.g.dart index 071888c5..362b3cbd 100644 --- a/lib/src/types/fetch_request_federated_credential.g.dart +++ b/lib/src/types/fetch_request_federated_credential.g.dart @@ -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; diff --git a/lib/src/types/fetch_request_password_credential.dart b/lib/src/types/fetch_request_password_credential.dart index d4727705..4a3ccf31 100644 --- a/lib/src/types/fetch_request_password_credential.dart +++ b/lib/src/types/fetch_request_password_credential.dart @@ -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}) diff --git a/lib/src/types/fetch_request_password_credential.g.dart b/lib/src/types/fetch_request_password_credential.g.dart index b81fdf3a..6d5c2dbf 100644 --- a/lib/src/types/fetch_request_password_credential.g.dart +++ b/lib/src/types/fetch_request_password_credential.g.dart @@ -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; diff --git a/lib/src/types/in_app_webview_initial_data.dart b/lib/src/types/in_app_webview_initial_data.dart index b1a08ee6..152e2b9b 100644 --- a/lib/src/types/in_app_webview_initial_data.dart +++ b/lib/src/types/in_app_webview_initial_data.dart @@ -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, diff --git a/lib/src/types/in_app_webview_initial_data.g.dart b/lib/src/types/in_app_webview_initial_data.g.dart index b9382c4f..19ba282d 100644 --- a/lib/src/types/in_app_webview_initial_data.g.dart +++ b/lib/src/types/in_app_webview_initial_data.g.dart @@ -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']; diff --git a/lib/src/types/js_alert_request.dart b/lib/src/types/js_alert_request.dart index a0e7f490..c8739d7b 100644 --- a/lib/src/types/js_alert_request.dart +++ b/lib/src/types/js_alert_request.dart @@ -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; diff --git a/lib/src/types/js_alert_request.g.dart b/lib/src/types/js_alert_request.g.dart index cb38cf8b..f257c462 100644 --- a/lib/src/types/js_alert_request.g.dart +++ b/lib/src/types/js_alert_request.g.dart @@ -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'], diff --git a/lib/src/types/js_before_unload_request.dart b/lib/src/types/js_before_unload_request.dart index bd5d2c03..a91cb4b4 100644 --- a/lib/src/types/js_before_unload_request.dart +++ b/lib/src/types/js_before_unload_request.dart @@ -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; diff --git a/lib/src/types/js_before_unload_request.g.dart b/lib/src/types/js_before_unload_request.g.dart index ea8100ac..b6171b37 100644 --- a/lib/src/types/js_before_unload_request.g.dart +++ b/lib/src/types/js_before_unload_request.g.dart @@ -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; diff --git a/lib/src/types/js_confirm_request.dart b/lib/src/types/js_confirm_request.dart index f46f3b17..93409ac7 100644 --- a/lib/src/types/js_confirm_request.dart +++ b/lib/src/types/js_confirm_request.dart @@ -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; diff --git a/lib/src/types/js_confirm_request.g.dart b/lib/src/types/js_confirm_request.g.dart index 89ed0d50..0608b74b 100644 --- a/lib/src/types/js_confirm_request.g.dart +++ b/lib/src/types/js_confirm_request.g.dart @@ -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'], diff --git a/lib/src/types/js_prompt_request.dart b/lib/src/types/js_prompt_request.dart index a7230ed8..7b87fdb0 100644 --- a/lib/src/types/js_prompt_request.dart +++ b/lib/src/types/js_prompt_request.dart @@ -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; diff --git a/lib/src/types/js_prompt_request.g.dart b/lib/src/types/js_prompt_request.g.dart index 893a88cb..79cd9c46 100644 --- a/lib/src/types/js_prompt_request.g.dart +++ b/lib/src/types/js_prompt_request.g.dart @@ -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'], diff --git a/lib/src/types/loaded_resource.dart b/lib/src/types/loaded_resource.dart index a9feae15..b2de6727 100644 --- a/lib/src/types/loaded_resource.dart +++ b/lib/src/types/loaded_resource.dart @@ -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; diff --git a/lib/src/types/loaded_resource.g.dart b/lib/src/types/loaded_resource.g.dart index 9391d36d..9b68f7e7 100644 --- a/lib/src/types/loaded_resource.g.dart +++ b/lib/src/types/loaded_resource.g.dart @@ -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'], ); diff --git a/lib/src/types/on_post_message_callback.dart b/lib/src/types/on_post_message_callback.dart index 53e06516..f52512dd 100644 --- a/lib/src/types/on_post_message_callback.dart +++ b/lib/src/types/on_post_message_callback.dart @@ -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); diff --git a/lib/src/types/permission_request.dart b/lib/src/types/permission_request.dart index 99bb89cf..d47f93bc 100644 --- a/lib/src/types/permission_request.dart +++ b/lib/src/types/permission_request.dart @@ -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. /// diff --git a/lib/src/types/permission_request.g.dart b/lib/src/types/permission_request.g.dart index bf5bf761..f4fb053c 100644 --- a/lib/src/types/permission_request.g.dart +++ b/lib/src/types/permission_request.g.dart @@ -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()), ); instance.resources = List.from(map['resources'] diff --git a/lib/src/types/print_job_attributes.dart b/lib/src/types/print_job_attributes.dart index 18d5fd87..6ef0f81c 100644 --- a/lib/src/types/print_job_attributes.dart +++ b/lib/src/types/print_job_attributes.dart @@ -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()]) diff --git a/lib/src/types/print_job_attributes.g.dart b/lib/src/types/print_job_attributes.g.dart index cc76ed8b..cdd18f2b 100644 --- a/lib/src/types/print_job_attributes.g.dart +++ b/lib/src/types/print_job_attributes.g.dart @@ -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'], diff --git a/lib/src/types/request_focus_node_href_result.dart b/lib/src/types/request_focus_node_href_result.dart index 6a0acbdf..37805ff1 100644 --- a/lib/src/types/request_focus_node_href_result.dart +++ b/lib/src/types/request_focus_node_href_result.dart @@ -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; diff --git a/lib/src/types/request_focus_node_href_result.g.dart b/lib/src/types/request_focus_node_href_result.g.dart index 7434e0b8..2abc4916 100644 --- a/lib/src/types/request_focus_node_href_result.g.dart +++ b/lib/src/types/request_focus_node_href_result.g.dart @@ -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'], ); diff --git a/lib/src/types/request_image_ref_result.dart b/lib/src/types/request_image_ref_result.dart index 9c42aef1..de288b9c 100644 --- a/lib/src/types/request_image_ref_result.dart +++ b/lib/src/types/request_image_ref_result.dart @@ -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}); } diff --git a/lib/src/types/request_image_ref_result.g.dart b/lib/src/types/request_image_ref_result.g.dart index 57c217ef..99262626 100644 --- a/lib/src/types/request_image_ref_result.g.dart +++ b/lib/src/types/request_image_ref_result.g.dart @@ -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; } diff --git a/lib/src/types/ui_event_attribution.dart b/lib/src/types/ui_event_attribution.dart index 3ffb2d9b..f9e290ce 100644 --- a/lib/src/types/ui_event_attribution.dart +++ b/lib/src/types/ui_event_attribution.dart @@ -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; diff --git a/lib/src/types/ui_event_attribution.g.dart b/lib/src/types/ui_event_attribution.g.dart index 2dbbda79..baaa1b68 100644 --- a/lib/src/types/ui_event_attribution.g.dart +++ b/lib/src/types/ui_event_attribution.g.dart @@ -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'], ); diff --git a/lib/src/types/url_request.dart b/lib/src/types/url_request.dart index 9341d260..5a65ac67 100644 --- a/lib/src/types/url_request.dart +++ b/lib/src/types/url_request.dart @@ -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`. diff --git a/lib/src/types/url_request.g.dart b/lib/src/types/url_request.g.dart index 62a72b50..7af60d8c 100644 --- a/lib/src/types/url_request.g.dart +++ b/lib/src/types/url_request.g.dart @@ -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(), @@ -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']), diff --git a/lib/src/types/url_response.dart b/lib/src/types/url_response.dart index 5ecfad23..5896d0e9 100644 --- a/lib/src/types/url_response.dart +++ b/lib/src/types/url_response.dart @@ -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 response’s content. int expectedContentLength; diff --git a/lib/src/types/url_response.g.dart b/lib/src/types/url_response.g.dart index 5a6838c9..5d2bc672 100644 --- a/lib/src/types/url_response.g.dart +++ b/lib/src/types/url_response.g.dart @@ -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 response’s 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'], diff --git a/lib/src/types/web_history_item.dart b/lib/src/types/web_history_item.dart index d8f3227f..33994145 100644 --- a/lib/src/types/web_history_item.dart +++ b/lib/src/types/web_history_item.dart @@ -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; diff --git a/lib/src/types/web_history_item.g.dart b/lib/src/types/web_history_item.g.dart index a7f3c97d..b96dbc40 100644 --- a/lib/src/types/web_history_item.g.dart +++ b/lib/src/types/web_history_item.g.dart @@ -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'], ); diff --git a/lib/src/types/web_resource_request.dart b/lib/src/types/web_resource_request.dart index c66eaa7a..725ad7c1 100644 --- a/lib/src/types/web_resource_request.dart +++ b/lib/src/types/web_resource_request.dart @@ -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. /// diff --git a/lib/src/types/web_resource_request.g.dart b/lib/src/types/web_resource_request.g.dart index 53872702..ba6265f7 100644 --- a/lib/src/types/web_resource_request.g.dart +++ b/lib/src/types/web_resource_request.g.dart @@ -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(), method: map['method'], hasGesture: map['hasGesture'], diff --git a/lib/src/web/in_app_web_view_web_element.dart b/lib/src/web/in_app_web_view_web_element.dart index d3f5b979..46c51ad0 100644 --- a/lib/src/web/in_app_web_view_web_element.dart +++ b/lib/src/web/in_app_web_view_web_element.dart @@ -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 injectJavascriptFileFromUrl( diff --git a/lib/src/web_authentication_session/web_authenticate_session.dart b/lib/src/web_authentication_session/web_authenticate_session.dart index 6d17b69d..8f4558f0 100755 --- a/lib/src/web_authentication_session/web_authenticate_session.dart +++ b/lib/src/web_authentication_session/web_authenticate_session.dart @@ -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 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 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) { diff --git a/lib/src/web_message/web_message_listener.dart b/lib/src/web_message/web_message_listener.dart index 430370ca..c8916b57 100644 --- a/lib/src/web_message/web_message_listener.dart +++ b/lib/src/web_message/web_message_listener.dart @@ -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!); diff --git a/lib/src/web_uri.dart b/lib/src/web_uri.dart new file mode 100644 index 00000000..4abe5c8a --- /dev/null +++ b/lib/src/web_uri.dart @@ -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 get pathSegments => _uri.pathSegments; + + @override + int get port => _uri.port; + + @override + String get query => _uri.query; + + @override + Map get queryParameters => _uri.queryParameters; + + @override + Map> get queryParametersAll => _uri.queryParametersAll; + + @override + Uri removeFragment() { + return _uri.removeFragment(); + } + + @override + Uri replace( + {String? scheme, + String? userInfo, + String? host, + int? port, + String? path, + Iterable? pathSegments, + String? query, + Map? 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); +} diff --git a/pubspec.yaml b/pubspec.yaml index b8377c1d..7736d4dc 100755 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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