iosWebViewFix/flutter_inappwebview/lib/src/cookie_manager.dart

161 lines
5.7 KiB
Dart
Raw Normal View History

import 'dart:async';
2023-11-17 22:28:11 +00:00
import 'package:flutter_inappwebview_platform_interface/flutter_inappwebview_platform_interface.dart';
import 'in_app_webview/in_app_webview_controller.dart';
2023-11-24 16:56:57 +00:00
///{@macro flutter_inappwebview_platform_interface.PlatformCookieManager}
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);
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-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;
///Gets the [CookieManager] shared instance.
static CookieManager instance() {
2023-11-17 22:28:11 +00:00
if (_instance == null) {
_instance = CookieManager();
}
return _instance!;
}
2023-11-24 16:56:57 +00:00
///{@macro flutter_inappwebview_platform_interface.PlatformCookieManager.setCookie}
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(
url: url,
name: name,
value: value,
path: path,
2023-11-17 22:28:11 +00:00
domain: domain,
expiresDate: expiresDate,
maxAge: maxAge,
isSecure: isSecure,
2023-11-17 22:28:11 +00:00
isHttpOnly: isHttpOnly,
sameSite: sameSite,
2023-11-17 22:28:11 +00:00
iosBelow11WebViewController: iosBelow11WebViewController?.platform,
webViewController: webViewController?.platform);
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);
2023-11-24 16:56:57 +00:00
///{@macro flutter_inappwebview_platform_interface.PlatformCookieManager.getCookie}
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);
2023-11-24 16:56:57 +00:00
///{@macro flutter_inappwebview_platform_interface.PlatformCookieManager.deleteCookie}
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(
url: url,
name: name,
path: path,
domain: domain,
2023-11-17 22:28:11 +00:00
iosBelow11WebViewController: iosBelow11WebViewController?.platform,
webViewController: webViewController?.platform);
2023-11-24 16:56:57 +00:00
///{@macro flutter_inappwebview_platform_interface.PlatformCookieManager.deleteCookies}
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);
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();
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();
}
///Class that contains only iOS-specific methods of [CookieManager].
2022-04-19 23:31:14 +00:00
///Use [CookieManager] instead.
@Deprecated("Use CookieManager instead")
class IOSCookieManager {
static IOSCookieManager? _instance;
///Gets the [IOSCookieManager] shared instance.
static IOSCookieManager instance() {
return (_instance != null) ? _instance! : _init();
}
IOSCookieManager._();
static IOSCookieManager _init() {
_instance = IOSCookieManager._();
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-02-22 22:54:09 +00:00
}