diff --git a/flutter_inappwebview/example/lib/main.dart b/flutter_inappwebview/example/lib/main.dart index 881061dd..ab93bf9d 100755 --- a/flutter_inappwebview/example/lib/main.dart +++ b/flutter_inappwebview/example/lib/main.dart @@ -24,6 +24,9 @@ Future main() async { // await Permission.storage.request(); if (!kIsWeb && defaultTargetPlatform == TargetPlatform.windows) { + final availableVersion = await WebViewEnvironment.getAvailableVersion(); + assert(availableVersion != null, 'Failed to find an installed WebView2 runtime or non-stable Microsoft Edge installation.'); + webViewEnvironment = await WebViewEnvironment.create(settings: WebViewEnvironmentSettings( userDataFolder: 'custom_path' diff --git a/flutter_inappwebview/lib/src/webview_environment/webview_environment.dart b/flutter_inappwebview/lib/src/webview_environment/webview_environment.dart index 4b89d135..b355df71 100644 --- a/flutter_inappwebview/lib/src/webview_environment/webview_environment.dart +++ b/flutter_inappwebview/lib/src/webview_environment/webview_environment.dart @@ -30,6 +30,14 @@ class WebViewEnvironment { return WebViewEnvironment.fromPlatform(platform: await PlatformWebViewEnvironment.static().create(settings: settings)); } + ///{@macro flutter_inappwebview_platform_interface.PlatformWebViewEnvironment.getAvailableVersion} + static Future getAvailableVersion( + {String? browserExecutableFolder}) => PlatformWebViewEnvironment.static().getAvailableVersion(browserExecutableFolder: browserExecutableFolder); + + ///{@macro flutter_inappwebview_platform_interface.PlatformWebViewEnvironment.getAvailableVersion} + static Future compareBrowserVersions( + {required String version1, required String version2}) => PlatformWebViewEnvironment.static().compareBrowserVersions(version1: version1, version2: version2); + ///{@macro flutter_inappwebview_platform_interface.PlatformWebViewEnvironment.dispose} Future dispose() => platform.dispose(); } \ No newline at end of file diff --git a/flutter_inappwebview_android/lib/src/inappwebview_platform.dart b/flutter_inappwebview_android/lib/src/inappwebview_platform.dart index 65e1b426..aa5c4207 100644 --- a/flutter_inappwebview_android/lib/src/inappwebview_platform.dart +++ b/flutter_inappwebview_android/lib/src/inappwebview_platform.dart @@ -155,7 +155,7 @@ class AndroidInAppWebViewPlatform extends InAppWebViewPlatform { /// Creates a new [AndroidWebStorage]. /// /// This function should only be called by the app-facing package. - /// Look at using [AndroidWebStorage] in `flutter_inappwebview` instead. + /// Look at using [WebStorage] in `flutter_inappwebview` instead. @override AndroidWebStorage createPlatformWebStorage( PlatformWebStorageCreationParams params, @@ -166,7 +166,7 @@ class AndroidInAppWebViewPlatform extends InAppWebViewPlatform { /// Creates a new [AndroidLocalStorage]. /// /// This function should only be called by the app-facing package. - /// Look at using [AndroidLocalStorage] in `flutter_inappwebview` instead. + /// Look at using [LocalStorage] in `flutter_inappwebview` instead. @override AndroidLocalStorage createPlatformLocalStorage( PlatformLocalStorageCreationParams params, @@ -177,7 +177,7 @@ class AndroidInAppWebViewPlatform extends InAppWebViewPlatform { /// Creates a new [AndroidSessionStorage]. /// /// This function should only be called by the app-facing package. - /// Look at using [PlatformSessionStorage] in `flutter_inappwebview` instead. + /// Look at using [SessionStorage] in `flutter_inappwebview` instead. @override AndroidSessionStorage createPlatformSessionStorage( PlatformSessionStorageCreationParams params, diff --git a/flutter_inappwebview_ios/lib/src/inappwebview_platform.dart b/flutter_inappwebview_ios/lib/src/inappwebview_platform.dart index 504f1f1a..fc27a56d 100644 --- a/flutter_inappwebview_ios/lib/src/inappwebview_platform.dart +++ b/flutter_inappwebview_ios/lib/src/inappwebview_platform.dart @@ -150,7 +150,7 @@ class IOSInAppWebViewPlatform extends InAppWebViewPlatform { /// Creates a new [IOSWebStorage]. /// /// This function should only be called by the app-facing package. - /// Look at using [IOSWebStorage] in `flutter_inappwebview` instead. + /// Look at using [WebStorage] in `flutter_inappwebview` instead. @override IOSWebStorage createPlatformWebStorage( PlatformWebStorageCreationParams params, @@ -161,7 +161,7 @@ class IOSInAppWebViewPlatform extends InAppWebViewPlatform { /// Creates a new [IOSLocalStorage]. /// /// This function should only be called by the app-facing package. - /// Look at using [IOSLocalStorage] in `flutter_inappwebview` instead. + /// Look at using [LocalStorage] in `flutter_inappwebview` instead. @override IOSLocalStorage createPlatformLocalStorage( PlatformLocalStorageCreationParams params, @@ -172,7 +172,7 @@ class IOSInAppWebViewPlatform extends InAppWebViewPlatform { /// Creates a new [IOSSessionStorage]. /// /// This function should only be called by the app-facing package. - /// Look at using [PlatformSessionStorage] in `flutter_inappwebview` instead. + /// Look at using [SessionStorage] in `flutter_inappwebview` instead. @override IOSSessionStorage createPlatformSessionStorage( PlatformSessionStorageCreationParams params, diff --git a/flutter_inappwebview_macos/lib/src/inappwebview_platform.dart b/flutter_inappwebview_macos/lib/src/inappwebview_platform.dart index 3e13e4f5..98f1e04a 100644 --- a/flutter_inappwebview_macos/lib/src/inappwebview_platform.dart +++ b/flutter_inappwebview_macos/lib/src/inappwebview_platform.dart @@ -138,7 +138,7 @@ class MacOSInAppWebViewPlatform extends InAppWebViewPlatform { /// Creates a new [MacOSWebStorage]. /// /// This function should only be called by the app-facing package. - /// Look at using [MacOSWebStorage] in `flutter_inappwebview` instead. + /// Look at using [WebStorage] in `flutter_inappwebview` instead. @override MacOSWebStorage createPlatformWebStorage( PlatformWebStorageCreationParams params, @@ -149,7 +149,7 @@ class MacOSInAppWebViewPlatform extends InAppWebViewPlatform { /// Creates a new [MacOSLocalStorage]. /// /// This function should only be called by the app-facing package. - /// Look at using [MacOSLocalStorage] in `flutter_inappwebview` instead. + /// Look at using [LocalStorage] in `flutter_inappwebview` instead. @override MacOSLocalStorage createPlatformLocalStorage( PlatformLocalStorageCreationParams params, @@ -160,7 +160,7 @@ class MacOSInAppWebViewPlatform extends InAppWebViewPlatform { /// Creates a new [MacOSSessionStorage]. /// /// This function should only be called by the app-facing package. - /// Look at using [PlatformSessionStorage] in `flutter_inappwebview` instead. + /// Look at using [SessionStorage] in `flutter_inappwebview` instead. @override MacOSSessionStorage createPlatformSessionStorage( PlatformSessionStorageCreationParams params, diff --git a/flutter_inappwebview_platform_interface/lib/src/platform_cookie_manager.dart b/flutter_inappwebview_platform_interface/lib/src/platform_cookie_manager.dart index 81bbb37a..700cc487 100755 --- a/flutter_inappwebview_platform_interface/lib/src/platform_cookie_manager.dart +++ b/flutter_inappwebview_platform_interface/lib/src/platform_cookie_manager.dart @@ -40,6 +40,7 @@ class PlatformCookieManagerCreationParams { ///- iOS ///- MacOS ///- Web +///- Windows ///{@endtemplate} abstract class PlatformCookieManager extends PlatformInterface { /// Creates a new [PlatformCookieManager] @@ -94,6 +95,7 @@ abstract class PlatformCookieManager extends PlatformInterface { ///- iOS ([Official API - WKHTTPCookieStore.setCookie](https://developer.apple.com/documentation/webkit/wkhttpcookiestore/2882007-setcookie)) ///- MacOS ([Official API - WKHTTPCookieStore.setCookie](https://developer.apple.com/documentation/webkit/wkhttpcookiestore/2882007-setcookie)) ///- Web + ///- Windows ///{@endtemplate} Future setCookie( {required WebUri url, @@ -133,6 +135,7 @@ abstract class PlatformCookieManager extends PlatformInterface { ///- iOS ([Official API - WKHTTPCookieStore.getAllCookies](https://developer.apple.com/documentation/webkit/wkhttpcookiestore/2882005-getallcookies)) ///- MacOS ([Official API - WKHTTPCookieStore.getAllCookies](https://developer.apple.com/documentation/webkit/wkhttpcookiestore/2882005-getallcookies)) ///- Web + ///- Windows ///{@endtemplate} Future> getCookies( {required WebUri url, @@ -163,6 +166,7 @@ abstract class PlatformCookieManager extends PlatformInterface { ///- iOS ///- MacOS ///- Web + ///- Windows ///{@endtemplate} Future getCookie( {required WebUri url, @@ -198,6 +202,7 @@ abstract class PlatformCookieManager extends PlatformInterface { ///- iOS ([Official API - WKHTTPCookieStore.delete](https://developer.apple.com/documentation/webkit/wkhttpcookiestore/2882009-delete) ///- MacOS ([Official API - WKHTTPCookieStore.delete](https://developer.apple.com/documentation/webkit/wkhttpcookiestore/2882009-delete) ///- Web + ///- Windows ///{@endtemplate} Future deleteCookie( {required WebUri url, @@ -235,6 +240,7 @@ abstract class PlatformCookieManager extends PlatformInterface { ///- iOS ///- MacOS ///- Web + ///- Windows ///{@endtemplate} Future deleteCookies( {required WebUri url, @@ -261,6 +267,7 @@ abstract class PlatformCookieManager extends PlatformInterface { ///- Android native WebView ([Official API - CookieManager.removeAllCookies](https://developer.android.com/reference/android/webkit/CookieManager#removeAllCookies(android.webkit.ValueCallback%3Cjava.lang.Boolean%3E))) ///- iOS ([Official API - WKWebsiteDataStore.removeData](https://developer.apple.com/documentation/webkit/wkwebsitedatastore/1532938-removedata)) ///- MacOS ([Official API - WKWebsiteDataStore.removeData](https://developer.apple.com/documentation/webkit/wkwebsitedatastore/1532938-removedata)) + ///- Windows ///{@endtemplate} Future deleteAllCookies() { throw UnimplementedError( diff --git a/flutter_inappwebview_platform_interface/lib/src/types/cookie.dart b/flutter_inappwebview_platform_interface/lib/src/types/cookie.dart index d0edfb4b..da4f3803 100644 --- a/flutter_inappwebview_platform_interface/lib/src/types/cookie.dart +++ b/flutter_inappwebview_platform_interface/lib/src/types/cookie.dart @@ -14,7 +14,8 @@ class Cookie_ { IOSPlatform(), MacOSPlatform(), AndroidPlatform(), - WebPlatform() + WebPlatform(), + WindowsPlatform() ]) String name; @@ -23,7 +24,8 @@ class Cookie_ { IOSPlatform(), MacOSPlatform(), AndroidPlatform(), - WebPlatform() + WebPlatform(), + WindowsPlatform() ]) dynamic value; @@ -33,12 +35,17 @@ class Cookie_ { MacOSPlatform(), AndroidPlatform( note: - "available on Android only if [WebViewFeature.GET_COOKIE_INFO] feature is supported.") + "available on Android only if [WebViewFeature.GET_COOKIE_INFO] feature is supported."), + WindowsPlatform() ]) int? expiresDate; ///Indicates if the cookie is a session only cookie. - @SupportedPlatforms(platforms: [IOSPlatform(), MacOSPlatform()]) + @SupportedPlatforms(platforms: [ + IOSPlatform(), + MacOSPlatform(), + WindowsPlatform() + ]) bool? isSessionOnly; ///The cookie domain. @@ -47,7 +54,8 @@ class Cookie_ { MacOSPlatform(), AndroidPlatform( note: - "available on Android only if [WebViewFeature.GET_COOKIE_INFO] feature is supported.") + "available on Android only if [WebViewFeature.GET_COOKIE_INFO] feature is supported."), + WindowsPlatform() ]) String? domain; @@ -57,7 +65,8 @@ class Cookie_ { MacOSPlatform(), AndroidPlatform( note: - "available on Android only if [WebViewFeature.GET_COOKIE_INFO] feature is supported.") + "available on Android only if [WebViewFeature.GET_COOKIE_INFO] feature is supported."), + WindowsPlatform() ]) HTTPCookieSameSitePolicy_? sameSite; @@ -67,7 +76,8 @@ class Cookie_ { MacOSPlatform(), AndroidPlatform( note: - "available on Android only if [WebViewFeature.GET_COOKIE_INFO] feature is supported.") + "available on Android only if [WebViewFeature.GET_COOKIE_INFO] feature is supported."), + WindowsPlatform() ]) bool? isSecure; @@ -77,7 +87,8 @@ class Cookie_ { MacOSPlatform(), AndroidPlatform( note: - "available on Android only if [WebViewFeature.GET_COOKIE_INFO] feature is supported.") + "available on Android only if [WebViewFeature.GET_COOKIE_INFO] feature is supported."), + WindowsPlatform() ]) bool? isHttpOnly; @@ -87,7 +98,8 @@ class Cookie_ { MacOSPlatform(), AndroidPlatform( note: - "available on Android only if [WebViewFeature.GET_COOKIE_INFO] feature is supported.") + "available on Android only if [WebViewFeature.GET_COOKIE_INFO] feature is supported."), + WindowsPlatform() ]) String? path; diff --git a/flutter_inappwebview_platform_interface/lib/src/types/cookie.g.dart b/flutter_inappwebview_platform_interface/lib/src/types/cookie.g.dart index 8b5e268d..ada5df95 100644 --- a/flutter_inappwebview_platform_interface/lib/src/types/cookie.g.dart +++ b/flutter_inappwebview_platform_interface/lib/src/types/cookie.g.dart @@ -16,6 +16,7 @@ class Cookie { ///- iOS ///- MacOS ///- Android native WebView + ///- Windows String? domain; ///The cookie expiration date in milliseconds. @@ -26,6 +27,7 @@ class Cookie { ///- iOS ///- MacOS ///- Android native WebView + ///- Windows int? expiresDate; ///Indicates if the cookie is a http only cookie. @@ -36,6 +38,7 @@ class Cookie { ///- iOS ///- MacOS ///- Android native WebView + ///- Windows bool? isHttpOnly; ///Indicates if the cookie is secure or not. @@ -46,6 +49,7 @@ class Cookie { ///- iOS ///- MacOS ///- Android native WebView + ///- Windows bool? isSecure; ///Indicates if the cookie is a session only cookie. @@ -53,6 +57,7 @@ class Cookie { ///**Officially Supported Platforms/Implementations**: ///- iOS ///- MacOS + ///- Windows bool? isSessionOnly; ///The cookie name. @@ -62,6 +67,7 @@ class Cookie { ///- MacOS ///- Android native WebView ///- Web but iframe requires same origin + ///- Windows String name; ///The cookie path. @@ -72,6 +78,7 @@ class Cookie { ///- iOS ///- MacOS ///- Android native WebView + ///- Windows String? path; ///The cookie same site policy. @@ -82,6 +89,7 @@ class Cookie { ///- iOS ///- MacOS ///- Android native WebView + ///- Windows HTTPCookieSameSitePolicy? sameSite; ///The cookie value. @@ -91,6 +99,7 @@ class Cookie { ///- MacOS ///- Android native WebView ///- Web but iframe requires same origin + ///- Windows dynamic value; Cookie( {this.domain, diff --git a/flutter_inappwebview_platform_interface/lib/src/web_storage/platform_web_storage.dart b/flutter_inappwebview_platform_interface/lib/src/web_storage/platform_web_storage.dart index 84ecd089..c47eb753 100644 --- a/flutter_inappwebview_platform_interface/lib/src/web_storage/platform_web_storage.dart +++ b/flutter_inappwebview_platform_interface/lib/src/web_storage/platform_web_storage.dart @@ -33,6 +33,7 @@ class PlatformWebStorageCreationParams { ///- iOS ///- MacOS ///- Web +///- Windows ///{@endtemplate} abstract class PlatformWebStorage extends PlatformInterface implements Disposable { diff --git a/flutter_inappwebview_platform_interface/lib/src/webview_environment/platform_webview_environment.dart b/flutter_inappwebview_platform_interface/lib/src/webview_environment/platform_webview_environment.dart index d5c156c9..0aea7510 100644 --- a/flutter_inappwebview_platform_interface/lib/src/webview_environment/platform_webview_environment.dart +++ b/flutter_inappwebview_platform_interface/lib/src/webview_environment/platform_webview_environment.dart @@ -20,6 +20,7 @@ class PlatformWebViewEnvironmentCreationParams { } ///Controls a WebView Environment used by WebView instances. +///Use [dispose] when not needed anymore to release references. /// ///**Officially Supported Platforms/Implementations**: ///- Windows @@ -102,6 +103,40 @@ abstract class PlatformWebViewEnvironment extends PlatformInterface 'create is not implemented on the current platform'); } + ///{@template flutter_inappwebview_platform_interface.PlatformWebViewEnvironment.getAvailableVersion} + ///Get the browser version info including channel name if it is not the WebView2 Runtime. + /// + ///Channel names are Beta, Dev, and Canary. + ///If an override exists for the browserExecutableFolder or the channel preference, the override is used. + ///If an override is not specified, then the parameter value passed to [getAvailableVersion] is used. + ///Returns `null` if it fails to find an installed WebView2 runtime or non-stable Microsoft Edge installation. + /// + ///**Officially Supported Platforms/Implementations**: + ///- Windows ([Official API - GetAvailableCoreWebView2BrowserVersionString](https://learn.microsoft.com/en-us/microsoft-edge/webview2/reference/win32/webview2-idl?view=webview2-1.0.2210.55#comparebrowserversions)) + ///{@endtemplate} + Future getAvailableVersion( + {String? browserExecutableFolder}) { + throw UnimplementedError( + 'getAvailableVersion is not implemented on the current platform'); + } + + ///{@template flutter_inappwebview_platform_interface.PlatformWebViewEnvironment.compareBrowserVersions} + ///This method is for anyone want to compare version correctly to determine which version is newer, older or same. + /// + ///Use it to determine whether to use webview2 or certain feature based upon version. + ///Sets the value of result to `-1`, `0` or `1` if version1 is less than, equal or greater than version2 respectively. + ///Returns `null` if it fails to parse any of the version strings. + ///Directly use the version info obtained from [getAvailableVersion] with input, channel information is ignored. + /// + ///**Officially Supported Platforms/Implementations**: + ///- Windows ([Official API - CompareBrowserVersions](https://learn.microsoft.com/en-us/microsoft-edge/webview2/reference/win32/webview2-idl?view=webview2-1.0.2210.55#comparebrowserversions)) + ///{@endtemplate} + Future compareBrowserVersions( + {required String version1, required String version2}) { + throw UnimplementedError( + 'compareBrowserVersions is not implemented on the current platform'); + } + ///{@template flutter_inappwebview_platform_interface.PlatformWebViewEnvironment.dispose} ///Disposes the WebView Environment reference. ///{@endtemplate} diff --git a/flutter_inappwebview_windows/lib/src/cookie_manager.dart b/flutter_inappwebview_windows/lib/src/cookie_manager.dart index 10882604..30474f7d 100644 --- a/flutter_inappwebview_windows/lib/src/cookie_manager.dart +++ b/flutter_inappwebview_windows/lib/src/cookie_manager.dart @@ -221,14 +221,6 @@ class WindowsCookieManager extends PlatformCookieManager return await channel?.invokeMethod('deleteAllCookies', args) ?? false; } - @override - Future removeSessionCookies() async { - Map args = {}; - args.putIfAbsent('webViewEnvironmentId', () => params.webViewEnvironment?.id); - return await channel?.invokeMethod('removeSessionCookies', args) ?? - false; - } - @override void dispose() { // empty diff --git a/flutter_inappwebview_windows/lib/src/find_interaction/find_interaction_controller.dart b/flutter_inappwebview_windows/lib/src/find_interaction/find_interaction_controller.dart index 9835059a..8868a3d6 100644 --- a/flutter_inappwebview_windows/lib/src/find_interaction/find_interaction_controller.dart +++ b/flutter_inappwebview_windows/lib/src/find_interaction/find_interaction_controller.dart @@ -8,18 +8,18 @@ import 'package:flutter_inappwebview_platform_interface/flutter_inappwebview_pla /// value to avoid breaking changes. See [PlatformFindInteractionControllerCreationParams] for /// more information. @immutable -class MacOSFindInteractionControllerCreationParams +class WindowsFindInteractionControllerCreationParams extends PlatformFindInteractionControllerCreationParams { - /// Creates a new [MacOSFindInteractionControllerCreationParams] instance. - const MacOSFindInteractionControllerCreationParams( + /// Creates a new [WindowsFindInteractionControllerCreationParams] instance. + const WindowsFindInteractionControllerCreationParams( {super.onFindResultReceived}); - /// Creates a [MacOSFindInteractionControllerCreationParams] instance based on [PlatformFindInteractionControllerCreationParams]. - factory MacOSFindInteractionControllerCreationParams.fromPlatformFindInteractionControllerCreationParams( + /// Creates a [WindowsFindInteractionControllerCreationParams] instance based on [PlatformFindInteractionControllerCreationParams]. + factory WindowsFindInteractionControllerCreationParams.fromPlatformFindInteractionControllerCreationParams( // Recommended placeholder to prevent being broken by platform interface. // ignore: avoid_unused_constructor_parameters PlatformFindInteractionControllerCreationParams params) { - return MacOSFindInteractionControllerCreationParams( + return WindowsFindInteractionControllerCreationParams( onFindResultReceived: params.onFindResultReceived); } } @@ -31,9 +31,9 @@ class WindowsFindInteractionController extends PlatformFindInteractionController WindowsFindInteractionController( PlatformFindInteractionControllerCreationParams params) : super.implementation( - params is MacOSFindInteractionControllerCreationParams + params is WindowsFindInteractionControllerCreationParams ? params - : MacOSFindInteractionControllerCreationParams + : WindowsFindInteractionControllerCreationParams .fromPlatformFindInteractionControllerCreationParams(params), ); diff --git a/flutter_inappwebview_windows/lib/src/http_auth_credentials_database.dart b/flutter_inappwebview_windows/lib/src/http_auth_credentials_database.dart index 28c9126f..90bc6e7e 100644 --- a/flutter_inappwebview_windows/lib/src/http_auth_credentials_database.dart +++ b/flutter_inappwebview_windows/lib/src/http_auth_credentials_database.dart @@ -3,38 +3,38 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/services.dart'; import 'package:flutter_inappwebview_platform_interface/flutter_inappwebview_platform_interface.dart'; -/// Object specifying creation parameters for creating a [MacOSHttpAuthCredentialDatabase]. +/// Object specifying creation parameters for creating a [WindowsHttpAuthCredentialDatabase]. /// /// When adding additional fields make sure they can be null or have a default /// value to avoid breaking changes. See [PlatformHttpAuthCredentialDatabaseCreationParams] for /// more information. @immutable -class MacOSHttpAuthCredentialDatabaseCreationParams +class WindowsHttpAuthCredentialDatabaseCreationParams extends PlatformHttpAuthCredentialDatabaseCreationParams { - /// Creates a new [MacOSHttpAuthCredentialDatabaseCreationParams] instance. - const MacOSHttpAuthCredentialDatabaseCreationParams( + /// Creates a new [WindowsHttpAuthCredentialDatabaseCreationParams] instance. + const WindowsHttpAuthCredentialDatabaseCreationParams( // This parameter prevents breaking changes later. // ignore: avoid_unused_constructor_parameters PlatformHttpAuthCredentialDatabaseCreationParams params, ) : super(); - /// Creates a [MacOSHttpAuthCredentialDatabaseCreationParams] instance based on [PlatformHttpAuthCredentialDatabaseCreationParams]. - factory MacOSHttpAuthCredentialDatabaseCreationParams.fromPlatformHttpAuthCredentialDatabaseCreationParams( + /// Creates a [WindowsHttpAuthCredentialDatabaseCreationParams] instance based on [PlatformHttpAuthCredentialDatabaseCreationParams]. + factory WindowsHttpAuthCredentialDatabaseCreationParams.fromPlatformHttpAuthCredentialDatabaseCreationParams( PlatformHttpAuthCredentialDatabaseCreationParams params) { - return MacOSHttpAuthCredentialDatabaseCreationParams(params); + return WindowsHttpAuthCredentialDatabaseCreationParams(params); } } ///{@macro flutter_inappwebview_platform_interface.PlatformHttpAuthCredentialDatabase} -class MacOSHttpAuthCredentialDatabase extends PlatformHttpAuthCredentialDatabase +class WindowsHttpAuthCredentialDatabase extends PlatformHttpAuthCredentialDatabase with ChannelController { - /// Creates a new [MacOSHttpAuthCredentialDatabase]. - MacOSHttpAuthCredentialDatabase( + /// Creates a new [WindowsHttpAuthCredentialDatabase]. + WindowsHttpAuthCredentialDatabase( PlatformHttpAuthCredentialDatabaseCreationParams params) : super.implementation( - params is MacOSHttpAuthCredentialDatabaseCreationParams + params is WindowsHttpAuthCredentialDatabaseCreationParams ? params - : MacOSHttpAuthCredentialDatabaseCreationParams + : WindowsHttpAuthCredentialDatabaseCreationParams .fromPlatformHttpAuthCredentialDatabaseCreationParams(params), ) { channel = const MethodChannel( @@ -43,16 +43,16 @@ class MacOSHttpAuthCredentialDatabase extends PlatformHttpAuthCredentialDatabase initMethodCallHandler(); } - static MacOSHttpAuthCredentialDatabase? _instance; + static WindowsHttpAuthCredentialDatabase? _instance; ///Gets the database shared instance. - static MacOSHttpAuthCredentialDatabase instance() { + static WindowsHttpAuthCredentialDatabase instance() { return (_instance != null) ? _instance! : _init(); } - static MacOSHttpAuthCredentialDatabase _init() { - _instance = MacOSHttpAuthCredentialDatabase( - MacOSHttpAuthCredentialDatabaseCreationParams( + static WindowsHttpAuthCredentialDatabase _init() { + _instance = WindowsHttpAuthCredentialDatabase( + WindowsHttpAuthCredentialDatabaseCreationParams( const PlatformHttpAuthCredentialDatabaseCreationParams())); return _instance!; } @@ -150,6 +150,6 @@ class MacOSHttpAuthCredentialDatabase extends PlatformHttpAuthCredentialDatabase } extension InternalHttpAuthCredentialDatabase - on MacOSHttpAuthCredentialDatabase { + on WindowsHttpAuthCredentialDatabase { get handleMethod => _handleMethod; } diff --git a/flutter_inappwebview_windows/lib/src/in_app_webview/in_app_webview_controller.dart b/flutter_inappwebview_windows/lib/src/in_app_webview/in_app_webview_controller.dart index b6373a8b..66e56d1e 100644 --- a/flutter_inappwebview_windows/lib/src/in_app_webview/in_app_webview_controller.dart +++ b/flutter_inappwebview_windows/lib/src/in_app_webview/in_app_webview_controller.dart @@ -75,7 +75,7 @@ class WindowsInAppWebViewController extends PlatformInAppWebViewController Set _webMessageListenerObjNames = Set(); Map _injectedScriptsFromURL = {}; Set _webMessageChannels = Set(); - Set _webMessageListeners = Set(); + Set _webMessageListeners = Set(); // static map that contains the properties to be saved and restored for keep alive feature static final Map @@ -89,7 +89,7 @@ class WindowsInAppWebViewController extends PlatformInAppWebViewController dynamic _controllerFromPlatform; @override - late MacOSWebStorage webStorage; + late WindowsWebStorage webStorage; WindowsInAppWebViewController( PlatformInAppWebViewControllerCreationParams params) @@ -161,9 +161,9 @@ class WindowsInAppWebViewController extends PlatformInAppWebViewController _controllerFromPlatform = params.webviewParams?.controllerFromPlatform?.call(this) ?? this; - webStorage = MacOSWebStorage(MacOSWebStorageCreationParams( - localStorage: MacOSLocalStorage.defaultStorage(controller: this), - sessionStorage: MacOSSessionStorage.defaultStorage(controller: this))); + webStorage = WindowsWebStorage(WindowsWebStorageCreationParams( + localStorage: WindowsLocalStorage.defaultStorage(controller: this), + sessionStorage: WindowsSessionStorage.defaultStorage(controller: this))); if (params.webviewParams is PlatformInAppWebViewWidgetCreationParams) { final keepAlive = @@ -189,7 +189,7 @@ class WindowsInAppWebViewController extends PlatformInAppWebViewController _webMessageChannels = props.webMessageChannels as Set; _webMessageListeners = - props.webMessageListeners as Set; + props.webMessageListeners as Set; } } } @@ -1311,9 +1311,9 @@ class WindowsInAppWebViewController extends PlatformInAppWebViewController String? url = call.arguments["url"]; String? printJobId = call.arguments["printJobId"]; WebUri? uri = url != null ? WebUri(url) : null; - MacOSPrintJobController? printJob = printJobId != null - ? MacOSPrintJobController( - MacOSPrintJobControllerCreationParams(id: printJobId)) + WindowsPrintJobController? printJob = printJobId != null + ? WindowsPrintJobController( + WindowsPrintJobControllerCreationParams(id: printJobId)) : null; if (webviewParams != null) { @@ -2139,14 +2139,14 @@ class WindowsInAppWebViewController extends PlatformInAppWebViewController } @override - Future printCurrentPage( + Future printCurrentPage( {PrintJobSettings? settings}) async { Map args = {}; args.putIfAbsent("settings", () => settings?.toMap()); String? jobId = await channel?.invokeMethod('printCurrentPage', args); if (jobId != null) { - return MacOSPrintJobController( + return WindowsPrintJobController( PlatformPrintJobControllerCreationParams(id: jobId)); } return null; @@ -2494,7 +2494,7 @@ class WindowsInAppWebViewController extends PlatformInAppWebViewController !_webMessageListenerObjNames .contains(webMessageListener.params.jsObjectName), "jsObjectName ${webMessageListener.params.jsObjectName} was already added."); - _webMessageListeners.add(webMessageListener as MacOSWebMessageListener); + _webMessageListeners.add(webMessageListener as WindowsWebMessageListener); _webMessageListenerObjNames.add(webMessageListener.params.jsObjectName); Map args = {}; diff --git a/flutter_inappwebview_windows/lib/src/inappwebview_platform.dart b/flutter_inappwebview_windows/lib/src/inappwebview_platform.dart index 93ffb9be..3dbf4ab7 100644 --- a/flutter_inappwebview_windows/lib/src/inappwebview_platform.dart +++ b/flutter_inappwebview_windows/lib/src/inappwebview_platform.dart @@ -6,6 +6,7 @@ import 'in_app_webview/in_app_webview.dart'; import 'in_app_webview/in_app_webview_controller.dart'; import 'in_app_webview/headless_in_app_webview.dart'; import 'webview_environment/webview_environment.dart'; +import 'web_storage/web_storage.dart'; /// Implementation of [InAppWebViewPlatform] using the WebKit API. class WindowsInAppWebViewPlatform extends InAppWebViewPlatform { @@ -107,4 +108,37 @@ class WindowsInAppWebViewPlatform extends InAppWebViewPlatform { WindowsWebViewEnvironment createPlatformWebViewEnvironmentStatic() { return WindowsWebViewEnvironment.static(); } + + /// Creates a new [WindowsWebStorage]. + /// + /// This function should only be called by the app-facing package. + /// Look at using [WebStorage] in `flutter_inappwebview` instead. + @override + WindowsWebStorage createPlatformWebStorage( + PlatformWebStorageCreationParams params, + ) { + return WindowsWebStorage(params); + } + + /// Creates a new [WindowsLocalStorage]. + /// + /// This function should only be called by the app-facing package. + /// Look at using [LocalStorage] in `flutter_inappwebview` instead. + @override + WindowsLocalStorage createPlatformLocalStorage( + PlatformLocalStorageCreationParams params, + ) { + return WindowsLocalStorage(params); + } + + /// Creates a new [WindowsSessionStorage]. + /// + /// This function should only be called by the app-facing package. + /// Look at using [SessionStorage] in `flutter_inappwebview` instead. + @override + WindowsSessionStorage createPlatformSessionStorage( + PlatformSessionStorageCreationParams params, + ) { + return WindowsSessionStorage(params); + } } diff --git a/flutter_inappwebview_windows/lib/src/print_job/print_job_controller.dart b/flutter_inappwebview_windows/lib/src/print_job/print_job_controller.dart index be3136d6..a1da365a 100644 --- a/flutter_inappwebview_windows/lib/src/print_job/print_job_controller.dart +++ b/flutter_inappwebview_windows/lib/src/print_job/print_job_controller.dart @@ -2,37 +2,37 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/services.dart'; import 'package:flutter_inappwebview_platform_interface/flutter_inappwebview_platform_interface.dart'; -/// Object specifying creation parameters for creating a [MacOSPrintJobController]. +/// Object specifying creation parameters for creating a [WindowsPrintJobController]. /// /// When adding additional fields make sure they can be null or have a default /// value to avoid breaking changes. See [PlatformPrintJobControllerCreationParams] for /// more information. @immutable -class MacOSPrintJobControllerCreationParams +class WindowsPrintJobControllerCreationParams extends PlatformPrintJobControllerCreationParams { - /// Creates a new [MacOSPrintJobControllerCreationParams] instance. - const MacOSPrintJobControllerCreationParams( + /// Creates a new [WindowsPrintJobControllerCreationParams] instance. + const WindowsPrintJobControllerCreationParams( {required super.id, super.onComplete}); - /// Creates a [MacOSPrintJobControllerCreationParams] instance based on [PlatformPrintJobControllerCreationParams]. - factory MacOSPrintJobControllerCreationParams.fromPlatformPrintJobControllerCreationParams( + /// Creates a [WindowsPrintJobControllerCreationParams] instance based on [PlatformPrintJobControllerCreationParams]. + factory WindowsPrintJobControllerCreationParams.fromPlatformPrintJobControllerCreationParams( // Recommended placeholder to prevent being broken by platform interface. // ignore: avoid_unused_constructor_parameters PlatformPrintJobControllerCreationParams params) { - return MacOSPrintJobControllerCreationParams( + return WindowsPrintJobControllerCreationParams( id: params.id, onComplete: params.onComplete); } } ///{@macro flutter_inappwebview_platform_interface.PlatformPrintJobController} -class MacOSPrintJobController extends PlatformPrintJobController +class WindowsPrintJobController extends PlatformPrintJobController with ChannelController { - /// Constructs a [MacOSPrintJobController]. - MacOSPrintJobController(PlatformPrintJobControllerCreationParams params) + /// Constructs a [WindowsPrintJobController]. + WindowsPrintJobController(PlatformPrintJobControllerCreationParams params) : super.implementation( - params is MacOSPrintJobControllerCreationParams + params is WindowsPrintJobControllerCreationParams ? params - : MacOSPrintJobControllerCreationParams + : WindowsPrintJobControllerCreationParams .fromPlatformPrintJobControllerCreationParams(params), ) { onComplete = params.onComplete; diff --git a/flutter_inappwebview_windows/lib/src/web_message/web_message_channel.dart b/flutter_inappwebview_windows/lib/src/web_message/web_message_channel.dart index 2077c759..2a47ab16 100644 --- a/flutter_inappwebview_windows/lib/src/web_message/web_message_channel.dart +++ b/flutter_inappwebview_windows/lib/src/web_message/web_message_channel.dart @@ -9,18 +9,18 @@ import 'web_message_port.dart'; /// value to avoid breaking changes. See [PlatformWebMessageChannelCreationParams] for /// more information. @immutable -class MacOSWebMessageChannelCreationParams +class WindowsWebMessageChannelCreationParams extends PlatformWebMessageChannelCreationParams { - /// Creates a new [MacOSWebMessageChannelCreationParams] instance. - const MacOSWebMessageChannelCreationParams( + /// Creates a new [WindowsWebMessageChannelCreationParams] instance. + const WindowsWebMessageChannelCreationParams( {required super.id, required super.port1, required super.port2}); - /// Creates a [MacOSWebMessageChannelCreationParams] instance based on [PlatformWebMessageChannelCreationParams]. - factory MacOSWebMessageChannelCreationParams.fromPlatformWebMessageChannelCreationParams( + /// Creates a [WindowsWebMessageChannelCreationParams] instance based on [PlatformWebMessageChannelCreationParams]. + factory WindowsWebMessageChannelCreationParams.fromPlatformWebMessageChannelCreationParams( // Recommended placeholder to prevent being broken by platform interface. // ignore: avoid_unused_constructor_parameters PlatformWebMessageChannelCreationParams params) { - return MacOSWebMessageChannelCreationParams( + return WindowsWebMessageChannelCreationParams( id: params.id, port1: params.port1, port2: params.port2); } @@ -36,9 +36,9 @@ class WindowsWebMessageChannel extends PlatformWebMessageChannel /// Constructs a [WindowsWebMessageChannel]. WindowsWebMessageChannel(PlatformWebMessageChannelCreationParams params) : super.implementation( - params is MacOSWebMessageChannelCreationParams + params is WindowsWebMessageChannelCreationParams ? params - : MacOSWebMessageChannelCreationParams + : WindowsWebMessageChannelCreationParams .fromPlatformWebMessageChannelCreationParams(params), ) { channel = MethodChannel( @@ -48,33 +48,33 @@ class WindowsWebMessageChannel extends PlatformWebMessageChannel } static final WindowsWebMessageChannel _staticValue = WindowsWebMessageChannel( - MacOSWebMessageChannelCreationParams( + WindowsWebMessageChannelCreationParams( id: '', port1: - MacOSWebMessagePort(MacOSWebMessagePortCreationParams(index: 0)), - port2: MacOSWebMessagePort( - MacOSWebMessagePortCreationParams(index: 1)))); + WindowsWebMessagePort(WindowsWebMessagePortCreationParams(index: 0)), + port2: WindowsWebMessagePort( + WindowsWebMessagePortCreationParams(index: 1)))); /// Provide static access. factory WindowsWebMessageChannel.static() { return _staticValue; } - MacOSWebMessagePort get _macosPort1 => port1 as MacOSWebMessagePort; + WindowsWebMessagePort get _macosPort1 => port1 as WindowsWebMessagePort; - MacOSWebMessagePort get _macosPort2 => port2 as MacOSWebMessagePort; + WindowsWebMessagePort get _macosPort2 => port2 as WindowsWebMessagePort; static WindowsWebMessageChannel? _fromMap(Map? map) { if (map == null) { return null; } var webMessageChannel = WindowsWebMessageChannel( - MacOSWebMessageChannelCreationParams( + WindowsWebMessageChannelCreationParams( id: map["id"], - port1: MacOSWebMessagePort( - MacOSWebMessagePortCreationParams(index: 0)), - port2: MacOSWebMessagePort( - MacOSWebMessagePortCreationParams(index: 1)))); + port1: WindowsWebMessagePort( + WindowsWebMessagePortCreationParams(index: 0)), + port2: WindowsWebMessagePort( + WindowsWebMessagePortCreationParams(index: 1)))); webMessageChannel._macosPort1.webMessageChannel = webMessageChannel; webMessageChannel._macosPort2.webMessageChannel = webMessageChannel; return webMessageChannel; diff --git a/flutter_inappwebview_windows/lib/src/web_message/web_message_listener.dart b/flutter_inappwebview_windows/lib/src/web_message/web_message_listener.dart index b2791eba..22a9cd76 100644 --- a/flutter_inappwebview_windows/lib/src/web_message/web_message_listener.dart +++ b/flutter_inappwebview_windows/lib/src/web_message/web_message_listener.dart @@ -2,26 +2,26 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/services.dart'; import 'package:flutter_inappwebview_platform_interface/flutter_inappwebview_platform_interface.dart'; -/// Object specifying creation parameters for creating a [MacOSWebMessageListener]. +/// Object specifying creation parameters for creating a [WindowsWebMessageListener]. /// /// When adding additional fields make sure they can be null or have a default /// value to avoid breaking changes. See [PlatformWebMessageListenerCreationParams] for /// more information. @immutable -class MacOSWebMessageListenerCreationParams +class WindowsWebMessageListenerCreationParams extends PlatformWebMessageListenerCreationParams { - /// Creates a new [MacOSWebMessageListenerCreationParams] instance. - const MacOSWebMessageListenerCreationParams( + /// Creates a new [WindowsWebMessageListenerCreationParams] instance. + const WindowsWebMessageListenerCreationParams( {required this.allowedOriginRules, required super.jsObjectName, super.onPostMessage}); - /// Creates a [MacOSWebMessageListenerCreationParams] instance based on [PlatformWebMessageListenerCreationParams]. - factory MacOSWebMessageListenerCreationParams.fromPlatformWebMessageListenerCreationParams( + /// Creates a [WindowsWebMessageListenerCreationParams] instance based on [PlatformWebMessageListenerCreationParams]. + factory WindowsWebMessageListenerCreationParams.fromPlatformWebMessageListenerCreationParams( // Recommended placeholder to prevent being broken by platform interface. // ignore: avoid_unused_constructor_parameters PlatformWebMessageListenerCreationParams params) { - return MacOSWebMessageListenerCreationParams( + return WindowsWebMessageListenerCreationParams( allowedOriginRules: params.allowedOriginRules ?? Set.from(["*"]), jsObjectName: params.jsObjectName, onPostMessage: params.onPostMessage); @@ -37,14 +37,14 @@ class MacOSWebMessageListenerCreationParams } ///{@macro flutter_inappwebview_platform_interface.PlatformWebMessageListener} -class MacOSWebMessageListener extends PlatformWebMessageListener +class WindowsWebMessageListener extends PlatformWebMessageListener with ChannelController { - /// Constructs a [MacOSWebMessageListener]. - MacOSWebMessageListener(PlatformWebMessageListenerCreationParams params) + /// Constructs a [WindowsWebMessageListener]. + WindowsWebMessageListener(PlatformWebMessageListenerCreationParams params) : super.implementation( - params is MacOSWebMessageListenerCreationParams + params is WindowsWebMessageListenerCreationParams ? params - : MacOSWebMessageListenerCreationParams + : WindowsWebMessageListenerCreationParams .fromPlatformWebMessageListenerCreationParams(params), ) { assert(!this._macosParams.allowedOriginRules.contains(""), @@ -60,8 +60,8 @@ class MacOSWebMessageListener extends PlatformWebMessageListener MacOSJavaScriptReplyProxy? _replyProxy; - MacOSWebMessageListenerCreationParams get _macosParams => - params as MacOSWebMessageListenerCreationParams; + WindowsWebMessageListenerCreationParams get _macosParams => + params as WindowsWebMessageListenerCreationParams; Future _handleMethod(MethodCall call) async { switch (call.method) { @@ -138,7 +138,7 @@ class MacOSJavaScriptReplyProxyCreationParams ///{@macro flutter_inappwebview_platform_interface.JavaScriptReplyProxy} class MacOSJavaScriptReplyProxy extends PlatformJavaScriptReplyProxy { - /// Constructs a [MacOSWebMessageListener]. + /// Constructs a [WindowsWebMessageListener]. MacOSJavaScriptReplyProxy(PlatformJavaScriptReplyProxyCreationParams params) : super.implementation( params is MacOSJavaScriptReplyProxyCreationParams @@ -147,8 +147,8 @@ class MacOSJavaScriptReplyProxy extends PlatformJavaScriptReplyProxy { .fromPlatformJavaScriptReplyProxyCreationParams(params), ); - MacOSWebMessageListener get _macosWebMessageListener => - params.webMessageListener as MacOSWebMessageListener; + WindowsWebMessageListener get _macosWebMessageListener => + params.webMessageListener as WindowsWebMessageListener; @override Future postMessage(WebMessage message) async { diff --git a/flutter_inappwebview_windows/lib/src/web_message/web_message_port.dart b/flutter_inappwebview_windows/lib/src/web_message/web_message_port.dart index be3ecece..f75c956e 100644 --- a/flutter_inappwebview_windows/lib/src/web_message/web_message_port.dart +++ b/flutter_inappwebview_windows/lib/src/web_message/web_message_port.dart @@ -3,23 +3,23 @@ import 'package:flutter_inappwebview_platform_interface/flutter_inappwebview_pla import 'web_message_channel.dart'; -/// Object specifying creation parameters for creating a [MacOSWebMessagePort]. +/// Object specifying creation parameters for creating a [WindowsWebMessagePort]. /// /// When adding additional fields make sure they can be null or have a default /// value to avoid breaking changes. See [PlatformWebMessagePortCreationParams] for /// more information. @immutable -class MacOSWebMessagePortCreationParams +class WindowsWebMessagePortCreationParams extends PlatformWebMessagePortCreationParams { - /// Creates a new [MacOSWebMessagePortCreationParams] instance. - const MacOSWebMessagePortCreationParams({required super.index}); + /// Creates a new [WindowsWebMessagePortCreationParams] instance. + const WindowsWebMessagePortCreationParams({required super.index}); - /// Creates a [MacOSWebMessagePortCreationParams] instance based on [PlatformWebMessagePortCreationParams]. - factory MacOSWebMessagePortCreationParams.fromPlatformWebMessagePortCreationParams( + /// Creates a [WindowsWebMessagePortCreationParams] instance based on [PlatformWebMessagePortCreationParams]. + factory WindowsWebMessagePortCreationParams.fromPlatformWebMessagePortCreationParams( // Recommended placeholder to prevent being broken by platform interface. // ignore: avoid_unused_constructor_parameters PlatformWebMessagePortCreationParams params) { - return MacOSWebMessagePortCreationParams(index: params.index); + return WindowsWebMessagePortCreationParams(index: params.index); } @override @@ -29,16 +29,16 @@ class MacOSWebMessagePortCreationParams } ///{@macro flutter_inappwebview_platform_interface.PlatformWebMessagePort} -class MacOSWebMessagePort extends PlatformWebMessagePort { +class WindowsWebMessagePort extends PlatformWebMessagePort { WebMessageCallback? _onMessage; late WindowsWebMessageChannel _webMessageChannel; - /// Constructs a [MacOSWebMessagePort]. - MacOSWebMessagePort(PlatformWebMessagePortCreationParams params) + /// Constructs a [WindowsWebMessagePort]. + WindowsWebMessagePort(PlatformWebMessagePortCreationParams params) : super.implementation( - params is MacOSWebMessagePortCreationParams + params is WindowsWebMessagePortCreationParams ? params - : MacOSWebMessagePortCreationParams + : WindowsWebMessagePortCreationParams .fromPlatformWebMessagePortCreationParams(params), ); @@ -85,7 +85,7 @@ class MacOSWebMessagePort extends PlatformWebMessagePort { } } -extension InternalWebMessagePort on MacOSWebMessagePort { +extension InternalWebMessagePort on WindowsWebMessagePort { WebMessageCallback? get onMessage => _onMessage; void set onMessage(WebMessageCallback? value) => _onMessage = value; diff --git a/flutter_inappwebview_windows/lib/src/web_storage/web_storage.dart b/flutter_inappwebview_windows/lib/src/web_storage/web_storage.dart index e884747b..7fe18b95 100644 --- a/flutter_inappwebview_windows/lib/src/web_storage/web_storage.dart +++ b/flutter_inappwebview_windows/lib/src/web_storage/web_storage.dart @@ -4,35 +4,35 @@ import 'package:flutter_inappwebview_platform_interface/flutter_inappwebview_pla import '../in_app_webview/in_app_webview_controller.dart'; -/// Object specifying creation parameters for creating a [MacOSWebStorage]. +/// Object specifying creation parameters for creating a [WindowsWebStorage]. /// /// When adding additional fields make sure they can be null or have a default /// value to avoid breaking changes. See [PlatformWebStorageCreationParams] for /// more information. -class MacOSWebStorageCreationParams extends PlatformWebStorageCreationParams { - /// Creates a new [MacOSWebStorageCreationParams] instance. - MacOSWebStorageCreationParams( +class WindowsWebStorageCreationParams extends PlatformWebStorageCreationParams { + /// Creates a new [WindowsWebStorageCreationParams] instance. + WindowsWebStorageCreationParams( {required super.localStorage, required super.sessionStorage}); - /// Creates a [MacOSWebStorageCreationParams] instance based on [PlatformWebStorageCreationParams]. - factory MacOSWebStorageCreationParams.fromPlatformWebStorageCreationParams( + /// Creates a [WindowsWebStorageCreationParams] instance based on [PlatformWebStorageCreationParams]. + factory WindowsWebStorageCreationParams.fromPlatformWebStorageCreationParams( // Recommended placeholder to prevent being broken by platform interface. // ignore: avoid_unused_constructor_parameters PlatformWebStorageCreationParams params) { - return MacOSWebStorageCreationParams( + return WindowsWebStorageCreationParams( localStorage: params.localStorage, sessionStorage: params.sessionStorage); } } ///{@macro flutter_inappwebview_platform_interface.PlatformWebStorage} -class MacOSWebStorage extends PlatformWebStorage { - /// Constructs a [MacOSWebStorage]. - MacOSWebStorage(PlatformWebStorageCreationParams params) +class WindowsWebStorage extends PlatformWebStorage { + /// Constructs a [WindowsWebStorage]. + WindowsWebStorage(PlatformWebStorageCreationParams params) : super.implementation( - params is MacOSWebStorageCreationParams + params is WindowsWebStorageCreationParams ? params - : MacOSWebStorageCreationParams + : WindowsWebStorageCreationParams .fromPlatformWebStorageCreationParams(params), ); @@ -49,28 +49,28 @@ class MacOSWebStorage extends PlatformWebStorage { } } -/// Object specifying creation parameters for creating a [MacOSStorage]. +/// Object specifying creation parameters for creating a [WindowsStorage]. /// /// When adding additional fields make sure they can be null or have a default /// value to avoid breaking changes. See [PlatformStorageCreationParams] for /// more information. -class MacOSStorageCreationParams extends PlatformStorageCreationParams { - /// Creates a new [MacOSStorageCreationParams] instance. - MacOSStorageCreationParams( +class WindowsStorageCreationParams extends PlatformStorageCreationParams { + /// Creates a new [WindowsStorageCreationParams] instance. + WindowsStorageCreationParams( {required super.controller, required super.webStorageType}); - /// Creates a [MacOSStorageCreationParams] instance based on [PlatformStorageCreationParams]. - factory MacOSStorageCreationParams.fromPlatformStorageCreationParams( + /// Creates a [WindowsStorageCreationParams] instance based on [PlatformStorageCreationParams]. + factory WindowsStorageCreationParams.fromPlatformStorageCreationParams( // Recommended placeholder to prevent being broken by platform interface. // ignore: avoid_unused_constructor_parameters PlatformStorageCreationParams params) { - return MacOSStorageCreationParams( + return WindowsStorageCreationParams( controller: params.controller, webStorageType: params.webStorageType); } } ///{@macro flutter_inappwebview_platform_interface.PlatformStorage} -abstract class MacOSStorage implements PlatformStorage { +abstract class WindowsStorage implements PlatformStorage { @override WindowsInAppWebViewController? controller; @@ -168,40 +168,40 @@ abstract class MacOSStorage implements PlatformStorage { } } -/// Object specifying creation parameters for creating a [MacOSLocalStorage]. +/// Object specifying creation parameters for creating a [WindowsLocalStorage]. /// /// When adding additional fields make sure they can be null or have a default /// value to avoid breaking changes. See [PlatformLocalStorageCreationParams] for /// more information. -class MacOSLocalStorageCreationParams +class WindowsLocalStorageCreationParams extends PlatformLocalStorageCreationParams { - /// Creates a new [MacOSLocalStorageCreationParams] instance. - MacOSLocalStorageCreationParams(super.params); + /// Creates a new [WindowsLocalStorageCreationParams] instance. + WindowsLocalStorageCreationParams(super.params); - /// Creates a [MacOSLocalStorageCreationParams] instance based on [PlatformLocalStorageCreationParams]. - factory MacOSLocalStorageCreationParams.fromPlatformLocalStorageCreationParams( + /// Creates a [WindowsLocalStorageCreationParams] instance based on [PlatformLocalStorageCreationParams]. + factory WindowsLocalStorageCreationParams.fromPlatformLocalStorageCreationParams( // Recommended placeholder to prevent being broken by platform interface. // ignore: avoid_unused_constructor_parameters PlatformLocalStorageCreationParams params) { - return MacOSLocalStorageCreationParams(params); + return WindowsLocalStorageCreationParams(params); } } ///{@macro flutter_inappwebview_platform_interface.PlatformLocalStorage} -class MacOSLocalStorage extends PlatformLocalStorage with MacOSStorage { - /// Constructs a [MacOSLocalStorage]. - MacOSLocalStorage(PlatformLocalStorageCreationParams params) +class WindowsLocalStorage extends PlatformLocalStorage with WindowsStorage { + /// Constructs a [WindowsLocalStorage]. + WindowsLocalStorage(PlatformLocalStorageCreationParams params) : super.implementation( - params is MacOSLocalStorageCreationParams + params is WindowsLocalStorageCreationParams ? params - : MacOSLocalStorageCreationParams + : WindowsLocalStorageCreationParams .fromPlatformLocalStorageCreationParams(params), ); /// Default storage - factory MacOSLocalStorage.defaultStorage( + factory WindowsLocalStorage.defaultStorage( {required PlatformInAppWebViewController? controller}) { - return MacOSLocalStorage(MacOSLocalStorageCreationParams( + return WindowsLocalStorage(WindowsLocalStorageCreationParams( PlatformLocalStorageCreationParams(PlatformStorageCreationParams( controller: controller, webStorageType: WebStorageType.LOCAL_STORAGE)))); @@ -212,40 +212,40 @@ class MacOSLocalStorage extends PlatformLocalStorage with MacOSStorage { params.controller as WindowsInAppWebViewController?; } -/// Object specifying creation parameters for creating a [MacOSSessionStorage]. +/// Object specifying creation parameters for creating a [WindowsSessionStorage]. /// /// When adding additional fields make sure they can be null or have a default /// value to avoid breaking changes. See [PlatformSessionStorageCreationParams] for /// more information. -class MacOSSessionStorageCreationParams +class WindowsSessionStorageCreationParams extends PlatformSessionStorageCreationParams { - /// Creates a new [MacOSSessionStorageCreationParams] instance. - MacOSSessionStorageCreationParams(super.params); + /// Creates a new [WindowsSessionStorageCreationParams] instance. + WindowsSessionStorageCreationParams(super.params); - /// Creates a [MacOSSessionStorageCreationParams] instance based on [PlatformSessionStorageCreationParams]. - factory MacOSSessionStorageCreationParams.fromPlatformSessionStorageCreationParams( + /// Creates a [WindowsSessionStorageCreationParams] instance based on [PlatformSessionStorageCreationParams]. + factory WindowsSessionStorageCreationParams.fromPlatformSessionStorageCreationParams( // Recommended placeholder to prevent being broken by platform interface. // ignore: avoid_unused_constructor_parameters PlatformSessionStorageCreationParams params) { - return MacOSSessionStorageCreationParams(params); + return WindowsSessionStorageCreationParams(params); } } ///{@macro flutter_inappwebview_platform_interface.PlatformSessionStorage} -class MacOSSessionStorage extends PlatformSessionStorage with MacOSStorage { - /// Constructs a [MacOSSessionStorage]. - MacOSSessionStorage(PlatformSessionStorageCreationParams params) +class WindowsSessionStorage extends PlatformSessionStorage with WindowsStorage { + /// Constructs a [WindowsSessionStorage]. + WindowsSessionStorage(PlatformSessionStorageCreationParams params) : super.implementation( - params is MacOSSessionStorageCreationParams + params is WindowsSessionStorageCreationParams ? params - : MacOSSessionStorageCreationParams + : WindowsSessionStorageCreationParams .fromPlatformSessionStorageCreationParams(params), ); /// Default storage - factory MacOSSessionStorage.defaultStorage( + factory WindowsSessionStorage.defaultStorage( {required PlatformInAppWebViewController? controller}) { - return MacOSSessionStorage(MacOSSessionStorageCreationParams( + return WindowsSessionStorage(WindowsSessionStorageCreationParams( PlatformSessionStorageCreationParams(PlatformStorageCreationParams( controller: controller, webStorageType: WebStorageType.SESSION_STORAGE)))); diff --git a/flutter_inappwebview_windows/lib/src/web_storage/web_storage_manager.dart b/flutter_inappwebview_windows/lib/src/web_storage/web_storage_manager.dart index b281f0d7..cd9c24e6 100644 --- a/flutter_inappwebview_windows/lib/src/web_storage/web_storage_manager.dart +++ b/flutter_inappwebview_windows/lib/src/web_storage/web_storage_manager.dart @@ -4,37 +4,37 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/services.dart'; import 'package:flutter_inappwebview_platform_interface/flutter_inappwebview_platform_interface.dart'; -/// Object specifying creation parameters for creating a [MacOSWebStorageManager]. +/// Object specifying creation parameters for creating a [WindowsWebStorageManager]. /// /// When adding additional fields make sure they can be null or have a default /// value to avoid breaking changes. See [PlatformWebStorageManagerCreationParams] for /// more information. @immutable -class MacOSWebStorageManagerCreationParams +class WindowsWebStorageManagerCreationParams extends PlatformWebStorageManagerCreationParams { - /// Creates a new [MacOSWebStorageManagerCreationParams] instance. - const MacOSWebStorageManagerCreationParams( + /// Creates a new [WindowsWebStorageManagerCreationParams] instance. + const WindowsWebStorageManagerCreationParams( // This parameter prevents breaking changes later. // ignore: avoid_unused_constructor_parameters PlatformWebStorageManagerCreationParams params, ) : super(); - /// Creates a [MacOSWebStorageManagerCreationParams] instance based on [PlatformWebStorageManagerCreationParams]. - factory MacOSWebStorageManagerCreationParams.fromPlatformWebStorageManagerCreationParams( + /// Creates a [WindowsWebStorageManagerCreationParams] instance based on [PlatformWebStorageManagerCreationParams]. + factory WindowsWebStorageManagerCreationParams.fromPlatformWebStorageManagerCreationParams( PlatformWebStorageManagerCreationParams params) { - return MacOSWebStorageManagerCreationParams(params); + return WindowsWebStorageManagerCreationParams(params); } } ///{@macro flutter_inappwebview_platform_interface.PlatformWebStorageManager} -class MacOSWebStorageManager extends PlatformWebStorageManager +class WindowsWebStorageManager extends PlatformWebStorageManager with ChannelController { - /// Creates a new [MacOSWebStorageManager]. - MacOSWebStorageManager(PlatformWebStorageManagerCreationParams params) + /// Creates a new [WindowsWebStorageManager]. + WindowsWebStorageManager(PlatformWebStorageManagerCreationParams params) : super.implementation( - params is MacOSWebStorageManagerCreationParams + params is WindowsWebStorageManagerCreationParams ? params - : MacOSWebStorageManagerCreationParams + : WindowsWebStorageManagerCreationParams .fromPlatformWebStorageManagerCreationParams(params), ) { channel = const MethodChannel( @@ -43,15 +43,15 @@ class MacOSWebStorageManager extends PlatformWebStorageManager initMethodCallHandler(); } - static MacOSWebStorageManager? _instance; + static WindowsWebStorageManager? _instance; ///Gets the WebStorage manager shared instance. - static MacOSWebStorageManager instance() { + static WindowsWebStorageManager instance() { return (_instance != null) ? _instance! : _init(); } - static MacOSWebStorageManager _init() { - _instance = MacOSWebStorageManager(MacOSWebStorageManagerCreationParams( + static WindowsWebStorageManager _init() { + _instance = WindowsWebStorageManager(WindowsWebStorageManagerCreationParams( const PlatformWebStorageManagerCreationParams())); return _instance!; } @@ -129,6 +129,6 @@ class MacOSWebStorageManager extends PlatformWebStorageManager } } -extension InternalWebStorageManager on MacOSWebStorageManager { +extension InternalWebStorageManager on WindowsWebStorageManager { get handleMethod => _handleMethod; } diff --git a/flutter_inappwebview_windows/lib/src/webview_environment/webview_environment.dart b/flutter_inappwebview_windows/lib/src/webview_environment/webview_environment.dart index b15a8963..c2020b5c 100644 --- a/flutter_inappwebview_windows/lib/src/webview_environment/webview_environment.dart +++ b/flutter_inappwebview_windows/lib/src/webview_environment/webview_environment.dart @@ -89,6 +89,25 @@ class WindowsWebViewEnvironment extends PlatformWebViewEnvironment return env; } + @override + Future getAvailableVersion( + {String? browserExecutableFolder}) async { + Map args = {}; + args.putIfAbsent('browserExecutableFolder', () => browserExecutableFolder); + return await _staticChannel.invokeMethod( + 'getAvailableVersion', args); + } + + @override + Future compareBrowserVersions( + {required String version1, required String version2}) async { + Map args = {}; + args.putIfAbsent('version1', () => version1); + args.putIfAbsent('version2', () => version2); + return await _staticChannel.invokeMethod( + 'compareBrowserVersions', args); + } + @override Future dispose() async { Map args = {}; diff --git a/flutter_inappwebview_windows/windows/CMakeLists.txt b/flutter_inappwebview_windows/windows/CMakeLists.txt index aaac0851..9b6da7af 100644 --- a/flutter_inappwebview_windows/windows/CMakeLists.txt +++ b/flutter_inappwebview_windows/windows/CMakeLists.txt @@ -74,6 +74,7 @@ list(APPEND PLUGIN_SOURCES "types/size_2d.h" "types/rect.cpp" "types/rect.h" + "types/callbacks_complete.h" "types/screenshot_configuration.cpp" "types/screenshot_configuration.h" "custom_platform_view/custom_platform_view.cc" diff --git a/flutter_inappwebview_windows/windows/cookie_manager.cpp b/flutter_inappwebview_windows/windows/cookie_manager.cpp index 9ab62069..2fa0eb5d 100644 --- a/flutter_inappwebview_windows/windows/cookie_manager.cpp +++ b/flutter_inappwebview_windows/windows/cookie_manager.cpp @@ -5,6 +5,7 @@ #include #include "cookie_manager.h" +#include "types/callbacks_complete.h" #include "utils/flutter.h" #include "utils/log.h" @@ -41,6 +42,46 @@ namespace flutter_inappwebview_plugin result_->Success(created); }); } + else if (string_equals(methodName, "getCookie")) { + auto url = get_fl_map_value(arguments, "url"); + auto name = get_fl_map_value(arguments, "name"); + getCookie(webViewEnvironment, url, name, [result_](const flutter::EncodableValue& cookie) + { + result_->Success(cookie); + }); + } + else if (string_equals(methodName, "getCookies")) { + auto url = get_fl_map_value(arguments, "url"); + getCookies(webViewEnvironment, url, [result_](const flutter::EncodableList& cookies) + { + result_->Success(cookies); + }); + } + else if (string_equals(methodName, "deleteCookie")) { + auto url = get_fl_map_value(arguments, "url"); + auto name = get_fl_map_value(arguments, "name"); + auto path = get_fl_map_value(arguments, "path"); + auto domain = get_optional_fl_map_value(arguments, "domain"); + deleteCookie(webViewEnvironment, url, name, path, domain, [result_](const bool& deleted) + { + result_->Success(deleted); + }); + } + else if (string_equals(methodName, "deleteCookies")) { + auto url = get_fl_map_value(arguments, "url"); + auto path = get_fl_map_value(arguments, "path"); + auto domain = get_optional_fl_map_value(arguments, "domain"); + deleteCookies(webViewEnvironment, url, path, domain, [result_](const bool& deleted) + { + result_->Success(deleted); + }); + } + else if (string_equals(methodName, "deleteAllCookies")) { + deleteAllCookies(webViewEnvironment, [result_](const bool& deleted) + { + result_->Success(deleted); + }); + } else { result_->NotImplemented(); } @@ -57,7 +98,7 @@ namespace flutter_inappwebview_plugin } } - void CookieManager::setCookie(WebViewEnvironment* webViewEnvironment, const flutter::EncodableMap& map, std::function completionHandler) const + void CookieManager::setCookie(WebViewEnvironment* webViewEnvironment, const flutter::EncodableMap& map, std::function completionHandler) const { if (!plugin || !plugin->webViewEnvironmentManager) { if (completionHandler) { @@ -118,6 +159,188 @@ namespace flutter_inappwebview_plugin } } + void CookieManager::getCookie(WebViewEnvironment* webViewEnvironment, const std::string& url, const std::string& name, std::function completionHandler) const + { + if (!plugin || !plugin->webViewEnvironmentManager) { + if (completionHandler) { + completionHandler(make_fl_value()); + } + return; + } + + nlohmann::json parameters = { + {"urls", std::vector{url}} + }; + + auto hr = webViewEnvironment->getWebView()->CallDevToolsProtocolMethod(L"Network.getCookies", utf8_to_wide(parameters.dump()).c_str(), Callback( + [completionHandler, name](HRESULT errorCode, LPCWSTR returnObjectAsJson) + { + if (succeededOrLog(errorCode)) { + nlohmann::json json = nlohmann::json::parse(wide_to_utf8(returnObjectAsJson)); + auto jsonCookies = json["cookies"].get>(); + for (auto& jsonCookie : jsonCookies) { + auto cookieName = jsonCookie["name"].get(); + if (string_equals(name, cookieName)) { + completionHandler(flutter::EncodableMap{ + {"name", cookieName}, + {"value", jsonCookie["value"].get()}, + {"domain", jsonCookie["domain"].get()}, + {"path", jsonCookie["path"].get()}, + {"expiresDate", jsonCookie["expires"].get()}, + {"isHttpOnly", jsonCookie["httpOnly"].get()}, + {"isSecure", jsonCookie["secure"].get()}, + {"isSessionOnly", jsonCookie["session"].get()}, + {"sameSite", jsonCookie.contains("sameSite") ? jsonCookie["sameSite"].get() : make_fl_value()} + }); + return S_OK; + } + } + } + if (completionHandler) { + completionHandler(make_fl_value()); + } + return S_OK; + } + ).Get()); + + if (failedAndLog(hr) && completionHandler) { + completionHandler(make_fl_value()); + } + } + + void CookieManager::getCookies(WebViewEnvironment* webViewEnvironment, const std::string& url, std::function completionHandler) const + { + if (!plugin || !plugin->webViewEnvironmentManager) { + if (completionHandler) { + completionHandler({}); + } + return; + } + + nlohmann::json parameters = { + {"urls", std::vector{url}} + }; + + auto hr = webViewEnvironment->getWebView()->CallDevToolsProtocolMethod(L"Network.getCookies", utf8_to_wide(parameters.dump()).c_str(), Callback( + [completionHandler](HRESULT errorCode, LPCWSTR returnObjectAsJson) + { + std::vector cookies = {}; + if (succeededOrLog(errorCode)) { + nlohmann::json json = nlohmann::json::parse(wide_to_utf8(returnObjectAsJson)); + auto jsonCookies = json["cookies"].get>(); + for (auto& jsonCookie : jsonCookies) { + cookies.push_back(flutter::EncodableMap{ + {"name", jsonCookie["name"].get()}, + {"value", jsonCookie["value"].get()}, + {"domain", jsonCookie["domain"].get()}, + {"path", jsonCookie["path"].get()}, + {"expiresDate", jsonCookie["expires"].get()}, + {"isHttpOnly", jsonCookie["httpOnly"].get()}, + {"isSecure", jsonCookie["secure"].get()}, + {"isSessionOnly", jsonCookie["session"].get()}, + {"sameSite", jsonCookie.contains("sameSite") ? jsonCookie["sameSite"].get() : make_fl_value()} + }); + } + } + if (completionHandler) { + completionHandler(cookies); + } + return S_OK; + } + ).Get()); + + if (failedAndLog(hr) && completionHandler) { + completionHandler({}); + } + } + + void CookieManager::deleteCookie(WebViewEnvironment* webViewEnvironment, const std::string& url, const std::string& name, const std::string& path, const std::optional& domain, std::function completionHandler) const + { + if (!plugin || !plugin->webViewEnvironmentManager) { + if (completionHandler) { + completionHandler(false); + } + return; + } + + nlohmann::json parameters = { + {"url", url}, + {"name", name}, + {"path", path} + }; + if (domain.has_value()) { + parameters["domain"] = domain.value(); + } + + auto hr = webViewEnvironment->getWebView()->CallDevToolsProtocolMethod(L"Network.deleteCookies", utf8_to_wide(parameters.dump()).c_str(), Callback( + [completionHandler](HRESULT errorCode, LPCWSTR returnObjectAsJson) + { + if (completionHandler) { + completionHandler(succeededOrLog(errorCode)); + } + return S_OK; + } + ).Get()); + + if (failedAndLog(hr) && completionHandler) { + completionHandler(false); + } + } + + void CookieManager::deleteCookies(WebViewEnvironment* webViewEnvironment, const std::string& url, const std::string& path, const std::optional& domain, std::function completionHandler) const + { + if (!plugin || !plugin->webViewEnvironmentManager) { + if (completionHandler) { + completionHandler(false); + } + return; + } + + getCookies(webViewEnvironment, url, [this, webViewEnvironment, url, path, domain, completionHandler](const flutter::EncodableList& cookies) + { + auto callbacksComplete = std::make_shared>( + [completionHandler](const std::vector& values) + { + if (completionHandler) { + completionHandler(true); + } + }); + + for (auto& cookie : cookies) { + auto cookieMap = std::get(cookie); + auto name = get_fl_map_value(cookieMap, "name"); + deleteCookie(webViewEnvironment, url, name, path, domain, [callbacksComplete](const bool& deleted) + { + callbacksComplete->addValue(deleted); + }); + } + }); + } + + void CookieManager::deleteAllCookies(WebViewEnvironment* webViewEnvironment, std::function completionHandler) const + { + if (!plugin || !plugin->webViewEnvironmentManager) { + if (completionHandler) { + completionHandler(false); + } + return; + } + + auto hr = webViewEnvironment->getWebView()->CallDevToolsProtocolMethod(L"Network.clearBrowserCookies", L"{}", Callback( + [completionHandler](HRESULT errorCode, LPCWSTR returnObjectAsJson) + { + if (completionHandler) { + completionHandler(succeededOrLog(errorCode)); + } + return S_OK; + } + ).Get()); + + if (failedAndLog(hr) && completionHandler) { + completionHandler(false); + } + } + CookieManager::~CookieManager() { debugLog("dealloc CookieManager"); diff --git a/flutter_inappwebview_windows/windows/cookie_manager.h b/flutter_inappwebview_windows/windows/cookie_manager.h index b6f596d7..313fd8a2 100644 --- a/flutter_inappwebview_windows/windows/cookie_manager.h +++ b/flutter_inappwebview_windows/windows/cookie_manager.h @@ -4,6 +4,7 @@ #include #include #include +#include #include "flutter_inappwebview_windows_plugin.h" #include "types/channel_delegate.h" @@ -25,7 +26,12 @@ namespace flutter_inappwebview_plugin const flutter::MethodCall& method_call, std::unique_ptr> result); - void setCookie(WebViewEnvironment* webViewEnvironment, const flutter::EncodableMap& map, std::function completionHandler) const; + void setCookie(WebViewEnvironment* webViewEnvironment, const flutter::EncodableMap& map, std::function completionHandler) const; + void getCookie(WebViewEnvironment* webViewEnvironment, const std::string& url, const std::string& name, std::function completionHandler) const; + void getCookies(WebViewEnvironment* webViewEnvironment, const std::string& url, std::function completionHandler) const; + void deleteCookie(WebViewEnvironment* webViewEnvironment, const std::string& url, const std::string& name, const std::string& path, const std::optional& domain, std::function completionHandler) const; + void deleteCookies(WebViewEnvironment* webViewEnvironment, const std::string& url, const std::string& path, const std::optional& domain, std::function completionHandler) const; + void deleteAllCookies(WebViewEnvironment* webViewEnvironment, std::function completionHandler) const; }; } diff --git a/flutter_inappwebview_windows/windows/types/callbacks_complete.h b/flutter_inappwebview_windows/windows/types/callbacks_complete.h new file mode 100644 index 00000000..c2ba5704 --- /dev/null +++ b/flutter_inappwebview_windows/windows/types/callbacks_complete.h @@ -0,0 +1,39 @@ +#ifndef FLUTTER_INAPPWEBVIEW_PLUGIN_CALLBACKS_COMPLETE_H_ +#define FLUTTER_INAPPWEBVIEW_PLUGIN_CALLBACKS_COMPLETE_H_ + +#include +#include +#include + +namespace flutter_inappwebview_plugin +{ + template + class CallbacksComplete + { + public: + std::function&)> onComplete; + + CallbacksComplete(const std::function&)> onComplete) + : onComplete(onComplete) + {} + + ~CallbacksComplete() + { + if (onComplete) { + onComplete(values_); + } + } + + void addValue(const T& value) + { + const std::lock_guard lock(mutex_); + values_.push_back(value); + } + + private: + std::vector values_; + std::mutex mutex_; + }; +} + +#endif //FLUTTER_INAPPWEBVIEW_PLUGIN_CALLBACKS_COMPLETE_H_ \ No newline at end of file diff --git a/flutter_inappwebview_windows/windows/webview_environment/webview_environment_manager.cpp b/flutter_inappwebview_windows/windows/webview_environment/webview_environment_manager.cpp index 81e07fd8..bae69c1a 100644 --- a/flutter_inappwebview_windows/windows/webview_environment/webview_environment_manager.cpp +++ b/flutter_inappwebview_windows/windows/webview_environment/webview_environment_manager.cpp @@ -39,6 +39,15 @@ namespace flutter_inappwebview_plugin auto settings = settingsMap.has_value() ? std::make_unique(settingsMap.value()) : nullptr; createWebViewEnvironment(id, std::move(settings), std::move(result)); } + else if (string_equals(methodName, "getAvailableVersion")) { + auto browserExecutableFolder = get_optional_fl_map_value(*arguments, "browserExecutableFolder"); + result->Success(make_fl_value(getAvailableVersion(browserExecutableFolder))); + } + else if (string_equals(methodName, "compareBrowserVersions")) { + auto version1 = get_fl_map_value(*arguments, "version1"); + auto version2 = get_fl_map_value(*arguments, "version2"); + result->Success(make_fl_value(compareBrowserVersions(version1, version2))); + } else { result->NotImplemented(); } @@ -89,6 +98,24 @@ namespace flutter_inappwebview_plugin }); } + std::optional WebViewEnvironmentManager::getAvailableVersion(std::optional browserExecutableFolder) + { + wil::unique_cotaskmem_string versionInfo; + if (succeededOrLog(GetAvailableCoreWebView2BrowserVersionString(browserExecutableFolder.has_value() ? utf8_to_wide(browserExecutableFolder.value()).c_str() : nullptr, &versionInfo))) { + return wide_to_utf8(versionInfo.get()); + } + return std::nullopt; + } + + std::optional WebViewEnvironmentManager::compareBrowserVersions(std::string version1, std::string version2) + { + int result = 0; + if (succeededOrLog(CompareBrowserVersions(utf8_to_wide(version1).c_str(), utf8_to_wide(version2).c_str(), &result))) { + return result; + } + return std::nullopt; + } + WebViewEnvironmentManager::~WebViewEnvironmentManager() { debugLog("dealloc WebViewEnvironmentManager"); diff --git a/flutter_inappwebview_windows/windows/webview_environment/webview_environment_manager.h b/flutter_inappwebview_windows/windows/webview_environment/webview_environment_manager.h index a8bc82fa..6bfcafcb 100644 --- a/flutter_inappwebview_windows/windows/webview_environment/webview_environment_manager.h +++ b/flutter_inappwebview_windows/windows/webview_environment/webview_environment_manager.h @@ -34,6 +34,9 @@ namespace flutter_inappwebview_plugin { return hwnd_; } + + static std::optional getAvailableVersion(std::optional browserExecutableFolder); + static std::optional compareBrowserVersions(std::string version1, std::string version2); private: std::unique_ptr defaultEnvironment_; WNDCLASS windowClass_ = {};