2019-11-02 03:16:47 +00:00
|
|
|
import 'dart:async';
|
|
|
|
|
2023-11-17 22:28:11 +00:00
|
|
|
import 'package:flutter_inappwebview_platform_interface/flutter_inappwebview_platform_interface.dart';
|
2019-10-26 02:42:50 +00:00
|
|
|
|
2021-02-22 11:16:23 +00:00
|
|
|
import 'in_app_webview/in_app_webview_controller.dart';
|
2019-11-25 00:42:27 +00:00
|
|
|
|
2023-11-24 16:56:57 +00:00
|
|
|
///{@macro flutter_inappwebview_platform_interface.PlatformCookieManager}
|
2019-10-26 02:42:50 +00:00
|
|
|
class CookieManager {
|
2023-11-24 16:56:57 +00:00
|
|
|
///{@macro flutter_inappwebview_platform_interface.PlatformCookieManager}
|
2023-11-17 22:28:11 +00:00
|
|
|
CookieManager()
|
|
|
|
: this.fromPlatformCreationParams(
|
|
|
|
const PlatformCookieManagerCreationParams(),
|
|
|
|
);
|
|
|
|
|
|
|
|
/// Constructs a [CookieManager] from creation params for a specific
|
|
|
|
/// platform.
|
|
|
|
CookieManager.fromPlatformCreationParams(
|
|
|
|
PlatformCookieManagerCreationParams params,
|
|
|
|
) : this.fromPlatform(PlatformCookieManager(params));
|
|
|
|
|
|
|
|
/// Constructs a [CookieManager] from a specific platform
|
|
|
|
/// implementation.
|
|
|
|
CookieManager.fromPlatform(this.platform);
|
2019-10-26 02:42:50 +00:00
|
|
|
|
2023-11-24 16:56:57 +00:00
|
|
|
/// Implementation of [PlatformCookieManager] for the current platform.
|
2023-11-17 22:28:11 +00:00
|
|
|
final PlatformCookieManager platform;
|
2022-10-19 00:42:23 +00:00
|
|
|
|
2022-04-19 23:31:14 +00:00
|
|
|
///Use [CookieManager] instead.
|
|
|
|
@Deprecated("Use CookieManager instead")
|
2023-11-17 22:28:11 +00:00
|
|
|
IOSCookieManager ios = IOSCookieManager.instance();
|
|
|
|
|
|
|
|
static CookieManager? _instance;
|
2021-01-31 21:08:20 +00:00
|
|
|
|
|
|
|
///Gets the [CookieManager] shared instance.
|
2019-10-31 02:20:07 +00:00
|
|
|
static CookieManager instance() {
|
2023-11-17 22:28:11 +00:00
|
|
|
if (_instance == null) {
|
|
|
|
_instance = CookieManager();
|
|
|
|
}
|
2021-01-28 16:10:15 +00:00
|
|
|
return _instance!;
|
2019-10-31 02:20:07 +00:00
|
|
|
}
|
|
|
|
|
2023-11-24 16:56:57 +00:00
|
|
|
///{@macro flutter_inappwebview_platform_interface.PlatformCookieManager.setCookie}
|
2023-11-10 13:13:06 +00:00
|
|
|
Future<bool> setCookie(
|
2023-11-17 22:28:11 +00:00
|
|
|
{required WebUri url,
|
|
|
|
required String name,
|
|
|
|
required String value,
|
|
|
|
String path = "/",
|
|
|
|
String? domain,
|
|
|
|
int? expiresDate,
|
|
|
|
int? maxAge,
|
|
|
|
bool? isSecure,
|
|
|
|
bool? isHttpOnly,
|
|
|
|
HTTPCookieSameSitePolicy? sameSite,
|
|
|
|
@Deprecated("Use webViewController instead")
|
|
|
|
InAppWebViewController? iosBelow11WebViewController,
|
|
|
|
InAppWebViewController? webViewController}) =>
|
|
|
|
platform.setCookie(
|
2022-10-18 16:12:33 +00:00
|
|
|
url: url,
|
|
|
|
name: name,
|
|
|
|
value: value,
|
|
|
|
path: path,
|
2023-11-17 22:28:11 +00:00
|
|
|
domain: domain,
|
2022-10-18 16:12:33 +00:00
|
|
|
expiresDate: expiresDate,
|
|
|
|
maxAge: maxAge,
|
|
|
|
isSecure: isSecure,
|
2023-11-17 22:28:11 +00:00
|
|
|
isHttpOnly: isHttpOnly,
|
2022-10-18 16:12:33 +00:00
|
|
|
sameSite: sameSite,
|
2023-11-17 22:28:11 +00:00
|
|
|
iosBelow11WebViewController: iosBelow11WebViewController?.platform,
|
|
|
|
webViewController: webViewController?.platform);
|
2021-02-01 14:55:27 +00:00
|
|
|
|
2023-11-24 16:56:57 +00:00
|
|
|
///{@macro flutter_inappwebview_platform_interface.PlatformCookieManager.getCookies}
|
2021-02-22 22:54:09 +00:00
|
|
|
Future<List<Cookie>> getCookies(
|
2023-11-17 22:28:11 +00:00
|
|
|
{required WebUri url,
|
|
|
|
@Deprecated("Use webViewController instead")
|
|
|
|
InAppWebViewController? iosBelow11WebViewController,
|
|
|
|
InAppWebViewController? webViewController}) =>
|
|
|
|
platform.getCookies(
|
|
|
|
url: url,
|
|
|
|
iosBelow11WebViewController: iosBelow11WebViewController?.platform,
|
|
|
|
webViewController: webViewController?.platform);
|
2021-02-01 14:55:27 +00:00
|
|
|
|
2023-11-24 16:56:57 +00:00
|
|
|
///{@macro flutter_inappwebview_platform_interface.PlatformCookieManager.getCookie}
|
2021-01-28 16:10:15 +00:00
|
|
|
Future<Cookie?> getCookie(
|
2023-11-17 22:28:11 +00:00
|
|
|
{required WebUri url,
|
|
|
|
required String name,
|
|
|
|
@Deprecated("Use webViewController instead")
|
|
|
|
InAppWebViewController? iosBelow11WebViewController,
|
|
|
|
InAppWebViewController? webViewController}) =>
|
|
|
|
platform.getCookie(
|
|
|
|
url: url,
|
|
|
|
name: name,
|
|
|
|
iosBelow11WebViewController: iosBelow11WebViewController?.platform,
|
|
|
|
webViewController: webViewController?.platform);
|
2019-10-26 02:42:50 +00:00
|
|
|
|
2023-11-24 16:56:57 +00:00
|
|
|
///{@macro flutter_inappwebview_platform_interface.PlatformCookieManager.deleteCookie}
|
2019-12-01 11:55:06 +00:00
|
|
|
Future<void> deleteCookie(
|
2023-11-17 22:28:11 +00:00
|
|
|
{required WebUri url,
|
|
|
|
required String name,
|
|
|
|
String path = "/",
|
|
|
|
String? domain,
|
|
|
|
@Deprecated("Use webViewController instead")
|
|
|
|
InAppWebViewController? iosBelow11WebViewController,
|
|
|
|
InAppWebViewController? webViewController}) =>
|
|
|
|
platform.deleteCookie(
|
2022-10-18 16:12:33 +00:00
|
|
|
url: url,
|
|
|
|
name: name,
|
|
|
|
path: path,
|
|
|
|
domain: domain,
|
2023-11-17 22:28:11 +00:00
|
|
|
iosBelow11WebViewController: iosBelow11WebViewController?.platform,
|
|
|
|
webViewController: webViewController?.platform);
|
2019-10-26 02:42:50 +00:00
|
|
|
|
2023-11-24 16:56:57 +00:00
|
|
|
///{@macro flutter_inappwebview_platform_interface.PlatformCookieManager.deleteCookies}
|
2019-12-01 11:55:06 +00:00
|
|
|
Future<void> deleteCookies(
|
2023-11-17 22:28:11 +00:00
|
|
|
{required WebUri url,
|
|
|
|
String path = "/",
|
|
|
|
String? domain,
|
|
|
|
@Deprecated("Use webViewController instead")
|
|
|
|
InAppWebViewController? iosBelow11WebViewController,
|
|
|
|
InAppWebViewController? webViewController}) =>
|
|
|
|
platform.deleteCookies(
|
|
|
|
url: url,
|
|
|
|
path: path,
|
|
|
|
domain: domain,
|
|
|
|
iosBelow11WebViewController: iosBelow11WebViewController?.platform,
|
|
|
|
webViewController: webViewController?.platform);
|
2019-10-26 02:42:50 +00:00
|
|
|
|
2023-11-24 16:56:57 +00:00
|
|
|
///{@macro flutter_inappwebview_platform_interface.PlatformCookieManager.deleteAllCookies}
|
2023-11-17 22:28:11 +00:00
|
|
|
Future<void> deleteAllCookies() => platform.deleteAllCookies();
|
2019-10-26 02:42:50 +00:00
|
|
|
|
2023-11-24 16:56:57 +00:00
|
|
|
///{@macro flutter_inappwebview_platform_interface.PlatformCookieManager.getAllCookies}
|
2023-11-17 22:28:11 +00:00
|
|
|
Future<List<Cookie>> getAllCookies() => platform.getAllCookies();
|
2019-12-01 11:55:06 +00:00
|
|
|
}
|
2021-01-31 21:08:20 +00:00
|
|
|
|
|
|
|
///Class that contains only iOS-specific methods of [CookieManager].
|
2022-04-19 23:31:14 +00:00
|
|
|
///Use [CookieManager] instead.
|
|
|
|
@Deprecated("Use CookieManager instead")
|
2021-01-31 21:08:20 +00:00
|
|
|
class IOSCookieManager {
|
|
|
|
static IOSCookieManager? _instance;
|
|
|
|
|
|
|
|
///Gets the [IOSCookieManager] shared instance.
|
|
|
|
static IOSCookieManager instance() {
|
|
|
|
return (_instance != null) ? _instance! : _init();
|
|
|
|
}
|
|
|
|
|
2022-10-19 00:42:23 +00:00
|
|
|
IOSCookieManager._();
|
|
|
|
|
2021-01-31 21:08:20 +00:00
|
|
|
static IOSCookieManager _init() {
|
2022-10-19 00:42:23 +00:00
|
|
|
_instance = IOSCookieManager._();
|
2021-01-31 21:08:20 +00:00
|
|
|
return _instance!;
|
|
|
|
}
|
|
|
|
|
|
|
|
///Fetches all stored cookies.
|
|
|
|
///
|
|
|
|
///**NOTE**: available on iOS 11.0+.
|
|
|
|
///
|
|
|
|
///**Official iOS API**: https://developer.apple.com/documentation/webkit/wkhttpcookiestore/2882005-getallcookies
|
|
|
|
Future<List<Cookie>> getAllCookies() async {
|
2023-11-17 22:28:11 +00:00
|
|
|
return CookieManager.instance().getAllCookies();
|
2021-01-31 21:08:20 +00:00
|
|
|
}
|
2021-02-22 22:54:09 +00:00
|
|
|
}
|