windows: completed CookieManager implementation, added WebViewEnvironment getAvailableVersion and compareBrowserVersions methods
This commit is contained in:
parent
7da9cb2643
commit
ade2edfb7d
|
@ -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'
|
||||
|
|
|
@ -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<String?> getAvailableVersion(
|
||||
{String? browserExecutableFolder}) => PlatformWebViewEnvironment.static().getAvailableVersion(browserExecutableFolder: browserExecutableFolder);
|
||||
|
||||
///{@macro flutter_inappwebview_platform_interface.PlatformWebViewEnvironment.getAvailableVersion}
|
||||
static Future<int?> compareBrowserVersions(
|
||||
{required String version1, required String version2}) => PlatformWebViewEnvironment.static().compareBrowserVersions(version1: version1, version2: version2);
|
||||
|
||||
///{@macro flutter_inappwebview_platform_interface.PlatformWebViewEnvironment.dispose}
|
||||
Future<void> dispose() => platform.dispose();
|
||||
}
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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<bool> 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<List<Cookie>> getCookies(
|
||||
{required WebUri url,
|
||||
|
@ -163,6 +166,7 @@ abstract class PlatformCookieManager extends PlatformInterface {
|
|||
///- iOS
|
||||
///- MacOS
|
||||
///- Web
|
||||
///- Windows
|
||||
///{@endtemplate}
|
||||
Future<Cookie?> 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<bool> deleteCookie(
|
||||
{required WebUri url,
|
||||
|
@ -235,6 +240,7 @@ abstract class PlatformCookieManager extends PlatformInterface {
|
|||
///- iOS
|
||||
///- MacOS
|
||||
///- Web
|
||||
///- Windows
|
||||
///{@endtemplate}
|
||||
Future<bool> 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<bool> deleteAllCookies() {
|
||||
throw UnimplementedError(
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -33,6 +33,7 @@ class PlatformWebStorageCreationParams {
|
|||
///- iOS
|
||||
///- MacOS
|
||||
///- Web
|
||||
///- Windows
|
||||
///{@endtemplate}
|
||||
abstract class PlatformWebStorage extends PlatformInterface
|
||||
implements Disposable {
|
||||
|
|
|
@ -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<String?> 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<int?> 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}
|
||||
|
|
|
@ -221,14 +221,6 @@ class WindowsCookieManager extends PlatformCookieManager
|
|||
return await channel?.invokeMethod<bool>('deleteAllCookies', args) ?? false;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<bool> removeSessionCookies() async {
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
args.putIfAbsent('webViewEnvironmentId', () => params.webViewEnvironment?.id);
|
||||
return await channel?.invokeMethod<bool>('removeSessionCookies', args) ??
|
||||
false;
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
// empty
|
||||
|
|
|
@ -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),
|
||||
);
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -75,7 +75,7 @@ class WindowsInAppWebViewController extends PlatformInAppWebViewController
|
|||
Set<String> _webMessageListenerObjNames = Set();
|
||||
Map<String, ScriptHtmlTagAttributes> _injectedScriptsFromURL = {};
|
||||
Set<WindowsWebMessageChannel> _webMessageChannels = Set();
|
||||
Set<MacOSWebMessageListener> _webMessageListeners = Set();
|
||||
Set<WindowsWebMessageListener> _webMessageListeners = Set();
|
||||
|
||||
// static map that contains the properties to be saved and restored for keep alive feature
|
||||
static final Map<InAppWebViewKeepAlive, InAppWebViewControllerKeepAliveProps?>
|
||||
|
@ -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<WindowsWebMessageChannel>;
|
||||
_webMessageListeners =
|
||||
props.webMessageListeners as Set<MacOSWebMessageListener>;
|
||||
props.webMessageListeners as Set<WindowsWebMessageListener>;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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<MacOSPrintJobController?> printCurrentPage(
|
||||
Future<WindowsPrintJobController?> printCurrentPage(
|
||||
{PrintJobSettings? settings}) async {
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
args.putIfAbsent("settings", () => settings?.toMap());
|
||||
String? jobId =
|
||||
await channel?.invokeMethod<String?>('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<String, dynamic> args = <String, dynamic>{};
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<String, dynamic>? 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;
|
||||
|
|
|
@ -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<dynamic> _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<void> postMessage(WebMessage message) async {
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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))));
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -89,6 +89,25 @@ class WindowsWebViewEnvironment extends PlatformWebViewEnvironment
|
|||
return env;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<String?> getAvailableVersion(
|
||||
{String? browserExecutableFolder}) async {
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
args.putIfAbsent('browserExecutableFolder', () => browserExecutableFolder);
|
||||
return await _staticChannel.invokeMethod<String>(
|
||||
'getAvailableVersion', args);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<int?> compareBrowserVersions(
|
||||
{required String version1, required String version2}) async {
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
args.putIfAbsent('version1', () => version1);
|
||||
args.putIfAbsent('version2', () => version2);
|
||||
return await _staticChannel.invokeMethod<int>(
|
||||
'compareBrowserVersions', args);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> dispose() async {
|
||||
Map<String, dynamic> args = <String, dynamic>{};
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include <wrl/event.h>
|
||||
|
||||
#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<std::string>(arguments, "url");
|
||||
auto name = get_fl_map_value<std::string>(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<std::string>(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<std::string>(arguments, "url");
|
||||
auto name = get_fl_map_value<std::string>(arguments, "name");
|
||||
auto path = get_fl_map_value<std::string>(arguments, "path");
|
||||
auto domain = get_optional_fl_map_value<std::string>(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<std::string>(arguments, "url");
|
||||
auto path = get_fl_map_value<std::string>(arguments, "path");
|
||||
auto domain = get_optional_fl_map_value<std::string>(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<void(bool)> completionHandler) const
|
||||
void CookieManager::setCookie(WebViewEnvironment* webViewEnvironment, const flutter::EncodableMap& map, std::function<void(const bool&)> 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<void(const flutter::EncodableValue&)> completionHandler) const
|
||||
{
|
||||
if (!plugin || !plugin->webViewEnvironmentManager) {
|
||||
if (completionHandler) {
|
||||
completionHandler(make_fl_value());
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
nlohmann::json parameters = {
|
||||
{"urls", std::vector<std::string>{url}}
|
||||
};
|
||||
|
||||
auto hr = webViewEnvironment->getWebView()->CallDevToolsProtocolMethod(L"Network.getCookies", utf8_to_wide(parameters.dump()).c_str(), Callback<ICoreWebView2CallDevToolsProtocolMethodCompletedHandler>(
|
||||
[completionHandler, name](HRESULT errorCode, LPCWSTR returnObjectAsJson)
|
||||
{
|
||||
if (succeededOrLog(errorCode)) {
|
||||
nlohmann::json json = nlohmann::json::parse(wide_to_utf8(returnObjectAsJson));
|
||||
auto jsonCookies = json["cookies"].get<std::vector<nlohmann::json>>();
|
||||
for (auto& jsonCookie : jsonCookies) {
|
||||
auto cookieName = jsonCookie["name"].get<std::string>();
|
||||
if (string_equals(name, cookieName)) {
|
||||
completionHandler(flutter::EncodableMap{
|
||||
{"name", cookieName},
|
||||
{"value", jsonCookie["value"].get<std::string>()},
|
||||
{"domain", jsonCookie["domain"].get<std::string>()},
|
||||
{"path", jsonCookie["path"].get<std::string>()},
|
||||
{"expiresDate", jsonCookie["expires"].get<int64_t>()},
|
||||
{"isHttpOnly", jsonCookie["httpOnly"].get<bool>()},
|
||||
{"isSecure", jsonCookie["secure"].get<bool>()},
|
||||
{"isSessionOnly", jsonCookie["session"].get<bool>()},
|
||||
{"sameSite", jsonCookie.contains("sameSite") ? jsonCookie["sameSite"].get<std::string>() : 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<void(const flutter::EncodableList&)> completionHandler) const
|
||||
{
|
||||
if (!plugin || !plugin->webViewEnvironmentManager) {
|
||||
if (completionHandler) {
|
||||
completionHandler({});
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
nlohmann::json parameters = {
|
||||
{"urls", std::vector<std::string>{url}}
|
||||
};
|
||||
|
||||
auto hr = webViewEnvironment->getWebView()->CallDevToolsProtocolMethod(L"Network.getCookies", utf8_to_wide(parameters.dump()).c_str(), Callback<ICoreWebView2CallDevToolsProtocolMethodCompletedHandler>(
|
||||
[completionHandler](HRESULT errorCode, LPCWSTR returnObjectAsJson)
|
||||
{
|
||||
std::vector<flutter::EncodableValue> cookies = {};
|
||||
if (succeededOrLog(errorCode)) {
|
||||
nlohmann::json json = nlohmann::json::parse(wide_to_utf8(returnObjectAsJson));
|
||||
auto jsonCookies = json["cookies"].get<std::vector<nlohmann::json>>();
|
||||
for (auto& jsonCookie : jsonCookies) {
|
||||
cookies.push_back(flutter::EncodableMap{
|
||||
{"name", jsonCookie["name"].get<std::string>()},
|
||||
{"value", jsonCookie["value"].get<std::string>()},
|
||||
{"domain", jsonCookie["domain"].get<std::string>()},
|
||||
{"path", jsonCookie["path"].get<std::string>()},
|
||||
{"expiresDate", jsonCookie["expires"].get<int64_t>()},
|
||||
{"isHttpOnly", jsonCookie["httpOnly"].get<bool>()},
|
||||
{"isSecure", jsonCookie["secure"].get<bool>()},
|
||||
{"isSessionOnly", jsonCookie["session"].get<bool>()},
|
||||
{"sameSite", jsonCookie.contains("sameSite") ? jsonCookie["sameSite"].get<std::string>() : 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<std::string>& domain, std::function<void(const bool&)> 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<ICoreWebView2CallDevToolsProtocolMethodCompletedHandler>(
|
||||
[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<std::string>& domain, std::function<void(const bool&)> 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<CallbacksComplete<bool>>(
|
||||
[completionHandler](const std::vector<bool>& values)
|
||||
{
|
||||
if (completionHandler) {
|
||||
completionHandler(true);
|
||||
}
|
||||
});
|
||||
|
||||
for (auto& cookie : cookies) {
|
||||
auto cookieMap = std::get<flutter::EncodableMap>(cookie);
|
||||
auto name = get_fl_map_value<std::string>(cookieMap, "name");
|
||||
deleteCookie(webViewEnvironment, url, name, path, domain, [callbacksComplete](const bool& deleted)
|
||||
{
|
||||
callbacksComplete->addValue(deleted);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void CookieManager::deleteAllCookies(WebViewEnvironment* webViewEnvironment, std::function<void(const bool&)> completionHandler) const
|
||||
{
|
||||
if (!plugin || !plugin->webViewEnvironmentManager) {
|
||||
if (completionHandler) {
|
||||
completionHandler(false);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
auto hr = webViewEnvironment->getWebView()->CallDevToolsProtocolMethod(L"Network.clearBrowserCookies", L"{}", Callback<ICoreWebView2CallDevToolsProtocolMethodCompletedHandler>(
|
||||
[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");
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include <flutter/method_channel.h>
|
||||
#include <flutter/standard_message_codec.h>
|
||||
#include <functional>
|
||||
#include <optional>
|
||||
|
||||
#include "flutter_inappwebview_windows_plugin.h"
|
||||
#include "types/channel_delegate.h"
|
||||
|
@ -25,7 +26,12 @@ namespace flutter_inappwebview_plugin
|
|||
const flutter::MethodCall<flutter::EncodableValue>& method_call,
|
||||
std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result);
|
||||
|
||||
void setCookie(WebViewEnvironment* webViewEnvironment, const flutter::EncodableMap& map, std::function<void(bool)> completionHandler) const;
|
||||
void setCookie(WebViewEnvironment* webViewEnvironment, const flutter::EncodableMap& map, std::function<void(const bool&)> completionHandler) const;
|
||||
void getCookie(WebViewEnvironment* webViewEnvironment, const std::string& url, const std::string& name, std::function<void(const flutter::EncodableValue&)> completionHandler) const;
|
||||
void getCookies(WebViewEnvironment* webViewEnvironment, const std::string& url, std::function<void(const flutter::EncodableList&)> completionHandler) const;
|
||||
void deleteCookie(WebViewEnvironment* webViewEnvironment, const std::string& url, const std::string& name, const std::string& path, const std::optional<std::string>& domain, std::function<void(const bool&)> completionHandler) const;
|
||||
void deleteCookies(WebViewEnvironment* webViewEnvironment, const std::string& url, const std::string& path, const std::optional<std::string>& domain, std::function<void(const bool&)> completionHandler) const;
|
||||
void deleteAllCookies(WebViewEnvironment* webViewEnvironment, std::function<void(const bool&)> completionHandler) const;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
#ifndef FLUTTER_INAPPWEBVIEW_PLUGIN_CALLBACKS_COMPLETE_H_
|
||||
#define FLUTTER_INAPPWEBVIEW_PLUGIN_CALLBACKS_COMPLETE_H_
|
||||
|
||||
#include <functional>
|
||||
#include <mutex>
|
||||
#include <vector>
|
||||
|
||||
namespace flutter_inappwebview_plugin
|
||||
{
|
||||
template<typename T>
|
||||
class CallbacksComplete
|
||||
{
|
||||
public:
|
||||
std::function<void(const std::vector<T>&)> onComplete;
|
||||
|
||||
CallbacksComplete(const std::function<void(const std::vector<T>&)> onComplete)
|
||||
: onComplete(onComplete)
|
||||
{}
|
||||
|
||||
~CallbacksComplete()
|
||||
{
|
||||
if (onComplete) {
|
||||
onComplete(values_);
|
||||
}
|
||||
}
|
||||
|
||||
void addValue(const T& value)
|
||||
{
|
||||
const std::lock_guard<std::mutex> lock(mutex_);
|
||||
values_.push_back(value);
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<T> values_;
|
||||
std::mutex mutex_;
|
||||
};
|
||||
}
|
||||
|
||||
#endif //FLUTTER_INAPPWEBVIEW_PLUGIN_CALLBACKS_COMPLETE_H_
|
|
@ -39,6 +39,15 @@ namespace flutter_inappwebview_plugin
|
|||
auto settings = settingsMap.has_value() ? std::make_unique<WebViewEnvironmentSettings>(settingsMap.value()) : nullptr;
|
||||
createWebViewEnvironment(id, std::move(settings), std::move(result));
|
||||
}
|
||||
else if (string_equals(methodName, "getAvailableVersion")) {
|
||||
auto browserExecutableFolder = get_optional_fl_map_value<std::string>(*arguments, "browserExecutableFolder");
|
||||
result->Success(make_fl_value(getAvailableVersion(browserExecutableFolder)));
|
||||
}
|
||||
else if (string_equals(methodName, "compareBrowserVersions")) {
|
||||
auto version1 = get_fl_map_value<std::string>(*arguments, "version1");
|
||||
auto version2 = get_fl_map_value<std::string>(*arguments, "version2");
|
||||
result->Success(make_fl_value(compareBrowserVersions(version1, version2)));
|
||||
}
|
||||
else {
|
||||
result->NotImplemented();
|
||||
}
|
||||
|
@ -89,6 +98,24 @@ namespace flutter_inappwebview_plugin
|
|||
});
|
||||
}
|
||||
|
||||
std::optional<std::string> WebViewEnvironmentManager::getAvailableVersion(std::optional<std::string> 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<int> 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");
|
||||
|
|
|
@ -34,6 +34,9 @@ namespace flutter_inappwebview_plugin
|
|||
{
|
||||
return hwnd_;
|
||||
}
|
||||
|
||||
static std::optional<std::string> getAvailableVersion(std::optional<std::string> browserExecutableFolder);
|
||||
static std::optional<int> compareBrowserVersions(std::string version1, std::string version2);
|
||||
private:
|
||||
std::unique_ptr<WebViewEnvironment> defaultEnvironment_;
|
||||
WNDCLASS windowClass_ = {};
|
||||
|
|
Loading…
Reference in New Issue