Added InAppWebViewController.clearFormData Android-specific method, Added InAppWebViewController.clearAllCache static method, Added CookieManager.removeSessionCookies Android-specific method, Deprecated InAppWebViewController.clearCache and InAppWebViewSettings.clearCache, Deprecated InAppWebViewSettings.clearSessionCache, Updated CookieManager methods return value

This commit is contained in:
Lorenzo Pichilli 2023-12-12 00:40:25 +01:00
parent 36a299d8c9
commit b2a0a96898
37 changed files with 473 additions and 226 deletions

View File

@ -1,8 +1,14 @@
## 6.0.0-beta.32
- Updated minimum platform interface and implementation versions
- Updated `useShouldInterceptAjaxRequest` automatic infer logic
- Added `InAppWebViewSettings.interceptOnlyAsyncAjaxRequests` [#1905](https://github.com/pichillilorenzo/flutter_inappwebview/issues/1905)
- Added `InAppWebViewController.clearFormData` Android-specific method
- Added `InAppWebViewController.clearAllCache` static method
- Added `CookieManager.removeSessionCookies` Android-specific method
- Deprecated `InAppWebViewController.clearCache` and `InAppWebViewSettings.clearCache`. Use `InAppWebViewController.clearAllCache` static method instead
- Deprecated `InAppWebViewSettings.clearSessionCache`. Use `CookieManager.removeSessionCookies` method instead
- Updated `useShouldInterceptAjaxRequest` automatic infer logic
- Updated `CookieManager` methods return value
- Fixed "iOS crash at public func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage)" [#1912](https://github.com/pichillilorenzo/flutter_inappwebview/issues/1912)
- Fixed "iOS Fatal Crash" [#1894](https://github.com/pichillilorenzo/flutter_inappwebview/issues/1894)
- Fixed "getFavicons: _TypeError: type '_Map<String, dynamic>' is not a subtype of type 'Iterable<dynamic>'" [#1897](https://github.com/pichillilorenzo/flutter_inappwebview/issues/1897)

View File

@ -49,6 +49,12 @@ void setGetDelete() {
final url = WebUri(await pageLoaded.future);
if (defaultTargetPlatform == TargetPlatform.android) {
await cookieManager.setCookie(
url: url, name: "myCookie", value: "myValue");
expect(await cookieManager.removeSessionCookies(), isTrue);
}
await cookieManager.setCookie(url: url, name: "myCookie", value: "myValue");
List<Cookie> cookies = await cookieManager.getCookies(url: url);
expect(cookies, isNotEmpty);
@ -56,12 +62,20 @@ void setGetDelete() {
Cookie? cookie = await cookieManager.getCookie(url: url, name: "myCookie");
expect(cookie?.value.toString(), "myValue");
await cookieManager.deleteCookie(url: url, name: "myCookie");
expect(
await cookieManager.deleteCookie(url: url, name: "myCookie"), isTrue);
cookie = await cookieManager.getCookie(url: url, name: "myCookie");
expect(cookie, isNull);
expect(
await cookieManager.deleteCookies(
url: url, domain: ".${TEST_CROSS_PLATFORM_URL_1.host}");
url: url, domain: ".${TEST_CROSS_PLATFORM_URL_1.host}"),
isTrue);
cookies = await cookieManager.getCookies(url: url);
expect(cookies, isEmpty);
await cookieManager.setCookie(url: url, name: "myCookie", value: "myValue");
expect(await cookieManager.deleteAllCookies(), isTrue);
cookies = await cookieManager.getCookies(url: url);
expect(cookies, isEmpty);

View File

@ -9,29 +9,9 @@ void clearCache() {
TargetPlatform.macOS,
].contains(defaultTargetPlatform);
skippableTestWidgets('clearCache', (WidgetTester tester) async {
final Completer<InAppWebViewController> controllerCompleter =
Completer<InAppWebViewController>();
final Completer<void> pageLoaded = Completer<void>();
await tester.pumpWidget(
Directionality(
textDirection: TextDirection.ltr,
child: InAppWebView(
key: GlobalKey(),
initialUrlRequest: URLRequest(url: TEST_CROSS_PLATFORM_URL_1),
onWebViewCreated: (controller) {
controllerCompleter.complete(controller);
},
onLoadStop: (controller, url) {
pageLoaded.complete();
},
),
),
);
final InAppWebViewController controller = await controllerCompleter.future;
await pageLoaded.future;
await expectLater(controller.clearCache(), completes);
skippableTestWidgets('clearAllCache', (WidgetTester tester) async {
await expectLater(
InAppWebViewController.clearAllCache(includeDiskFiles: true),
completes);
}, skip: shouldSkip);
}

View File

@ -93,7 +93,7 @@ class CookieManager {
webViewController: webViewController?.platform);
///{@macro flutter_inappwebview_platform_interface.PlatformCookieManager.deleteCookie}
Future<void> deleteCookie(
Future<bool> deleteCookie(
{required WebUri url,
required String name,
String path = "/",
@ -110,7 +110,7 @@ class CookieManager {
webViewController: webViewController?.platform);
///{@macro flutter_inappwebview_platform_interface.PlatformCookieManager.deleteCookies}
Future<void> deleteCookies(
Future<bool> deleteCookies(
{required WebUri url,
String path = "/",
String? domain,
@ -125,10 +125,13 @@ class CookieManager {
webViewController: webViewController?.platform);
///{@macro flutter_inappwebview_platform_interface.PlatformCookieManager.deleteAllCookies}
Future<void> deleteAllCookies() => platform.deleteAllCookies();
Future<bool> deleteAllCookies() => platform.deleteAllCookies();
///{@macro flutter_inappwebview_platform_interface.PlatformCookieManager.getAllCookies}
Future<List<Cookie>> getAllCookies() => platform.getAllCookies();
///{@macro flutter_inappwebview_platform_interface.PlatformCookieManager.removeSessionCookies}
Future<bool> removeSessionCookies() => platform.removeSessionCookies();
}
///Class that contains only iOS-specific methods of [CookieManager].

View File

@ -206,6 +206,7 @@ class InAppWebViewController {
platform.getCopyBackForwardList();
///{@macro flutter_inappwebview_platform_interface.PlatformInAppWebViewController.clearCache}
@Deprecated("Use InAppWebViewController.clearAllCache instead")
Future<void> clearCache() => platform.clearCache();
///{@macro flutter_inappwebview_platform_interface.PlatformInAppWebViewController.findAllAsync}
@ -457,6 +458,9 @@ class InAppWebViewController {
///{@macro flutter_inappwebview_platform_interface.PlatformInAppWebViewController.isInFullscreen}
Future<bool> isInFullscreen() => platform.isInFullscreen();
///{@macro flutter_inappwebview_platform_interface.PlatformInAppWebViewController.clearFormData}
Future<void> clearFormData() => platform.clearFormData();
///{@macro flutter_inappwebview_platform_interface.PlatformInAppWebViewController.getCameraCaptureState}
Future<MediaCaptureState?> getCameraCaptureState() =>
platform.getCameraCaptureState();
@ -535,6 +539,11 @@ class InAppWebViewController {
static Future<void> disposeKeepAlive(InAppWebViewKeepAlive keepAlive) =>
PlatformInAppWebViewController.static().disposeKeepAlive(keepAlive);
///{@macro flutter_inappwebview_platform_interface.PlatformInAppWebViewController.clearAllCache}
static Future<void> clearAllCache({bool includeDiskFiles = true}) =>
PlatformInAppWebViewController.static()
.clearAllCache(includeDiskFiles: includeDiskFiles);
///{@macro flutter_inappwebview_platform_interface.PlatformInAppWebViewController.tRexRunnerHtml}
static Future<String> get tRexRunnerHtml =>
PlatformInAppWebViewController.static().tRexRunnerHtml;

View File

@ -1,7 +1,10 @@
## 1.0.8
- Implemented `InAppWebViewSettings.interceptOnlyAsyncAjaxRequests`
- Implemented `PlatformInAppWebViewController.clearFormData` method
- Implemented `PlatformCookieManager.removeSessionCookies` method
- Updated `useShouldInterceptAjaxRequest` automatic infer logic
- Updated `CookieManager` methods return value
## 1.0.7

View File

@ -100,6 +100,9 @@ public class MyCookieManager extends ChannelDelegateImpl {
case "deleteAllCookies":
deleteAllCookies(result);
break;
case "removeSessionCookies":
removeSessionCookies(result);
break;
default:
result.notImplemented();
}
@ -151,7 +154,10 @@ public class MyCookieManager extends ChannelDelegateImpl {
String sameSite,
final MethodChannel.Result result) {
cookieManager = getCookieManager();
if (cookieManager == null) return;
if (cookieManager == null) {
result.success(false);
return;
}
String cookieValue = name + "=" + value + "; Path=" + path;
@ -188,9 +194,9 @@ public class MyCookieManager extends ChannelDelegateImpl {
CookieSyncManager cookieSyncMngr = CookieSyncManager.createInstance(plugin.applicationContext);
cookieSyncMngr.startSync();
cookieManager.setCookie(url, cookieValue);
result.success(true);
cookieSyncMngr.stopSync();
cookieSyncMngr.sync();
result.success(true);
} else {
cookieManager.setCookie(url, cookieValue);
result.success(true);
@ -281,7 +287,10 @@ public class MyCookieManager extends ChannelDelegateImpl {
public void deleteCookie(String url, String name, String domain, String path, final MethodChannel.Result result) {
cookieManager = getCookieManager();
if (cookieManager == null) return;
if (cookieManager == null) {
result.success(false);
return;
}
String cookieValue = name + "=; Path=" + path + "; Max-Age=-1";
@ -294,7 +303,7 @@ public class MyCookieManager extends ChannelDelegateImpl {
cookieManager.setCookie(url, cookieValue, new ValueCallback<Boolean>() {
@Override
public void onReceiveValue(Boolean successful) {
result.success(true);
result.success(successful);
}
});
cookieManager.flush();
@ -303,9 +312,9 @@ public class MyCookieManager extends ChannelDelegateImpl {
CookieSyncManager cookieSyncMngr = CookieSyncManager.createInstance(plugin.applicationContext);
cookieSyncMngr.startSync();
cookieManager.setCookie(url, cookieValue);
result.success(true);
cookieSyncMngr.stopSync();
cookieSyncMngr.sync();
result.success(true);
} else {
cookieManager.setCookie(url, cookieValue);
result.success(true);
@ -314,7 +323,10 @@ public class MyCookieManager extends ChannelDelegateImpl {
public void deleteCookies(String url, String domain, String path, final MethodChannel.Result result) {
cookieManager = getCookieManager();
if (cookieManager == null) return;
if (cookieManager == null) {
result.success(false);
return;
}
CookieSyncManager cookieSyncMngr = null;
@ -355,13 +367,16 @@ public class MyCookieManager extends ChannelDelegateImpl {
public void deleteAllCookies(final MethodChannel.Result result) {
cookieManager = getCookieManager();
if (cookieManager == null) return;
if (cookieManager == null) {
result.success(false);
return;
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
cookieManager.removeAllCookies(new ValueCallback<Boolean>() {
@Override
public void onReceiveValue(Boolean successful) {
result.success(true);
result.success(successful);
}
});
cookieManager.flush();
@ -370,15 +385,44 @@ public class MyCookieManager extends ChannelDelegateImpl {
CookieSyncManager cookieSyncMngr = CookieSyncManager.createInstance(plugin.applicationContext);
cookieSyncMngr.startSync();
cookieManager.removeAllCookie();
result.success(true);
cookieSyncMngr.stopSync();
cookieSyncMngr.sync();
result.success(true);
} else {
cookieManager.removeAllCookie();
result.success(true);
}
}
public void removeSessionCookies(final MethodChannel.Result result) {
cookieManager = getCookieManager();
if (cookieManager == null) {
result.success(false);
return;
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
cookieManager.removeSessionCookies(new ValueCallback<Boolean>() {
@Override
public void onReceiveValue(Boolean successful) {
result.success(successful);
}
});
cookieManager.flush();
}
else if (plugin != null) {
CookieSyncManager cookieSyncMngr = CookieSyncManager.createInstance(plugin.applicationContext);
cookieSyncMngr.startSync();
cookieManager.removeSessionCookie();
cookieSyncMngr.stopSync();
cookieSyncMngr.sync();
result.success(true);
} else {
cookieManager.removeSessionCookie();
result.success(true);
}
}
public static String getCookieExpirationDate(Long timestamp) {
final SimpleDateFormat sdf = new SimpleDateFormat("EEE, dd MMM yyyy hh:mm:ss z", Locale.US);
sdf.setTimeZone(TimeZone.getTimeZone("GMT"));

View File

@ -96,6 +96,7 @@ public class InAppWebViewManager extends ChannelDelegateImpl {
result.success(false);
break;
case "getCurrentWebViewPackage":
{
Context context = null;
if (plugin != null) {
context = plugin.activity;
@ -105,6 +106,7 @@ public class InAppWebViewManager extends ChannelDelegateImpl {
}
PackageInfo packageInfo = context != null ? WebViewCompat.getCurrentWebViewPackage(context) : null;
result.success(packageInfo != null ? convertWebViewPackageToMap(packageInfo) : null);
}
break;
case "setWebContentsDebuggingEnabled":
{
@ -144,6 +146,22 @@ public class InAppWebViewManager extends ChannelDelegateImpl {
}
result.success(true);
break;
case "clearAllCache":
{
Context context = null;
if (plugin != null) {
context = plugin.activity;
if (context == null) {
context = plugin.applicationContext;
}
if (context != null) {
boolean includeDiskFiles = (boolean) call.argument("includeDiskFiles");
clearAllCache(context, includeDiskFiles);
}
}
}
result.success(true);
break;
default:
result.notImplemented();
}
@ -178,6 +196,12 @@ public class InAppWebViewManager extends ChannelDelegateImpl {
}
}
public void clearAllCache(@NonNull Context context, boolean includeDiskFiles) {
WebView tempWebView = new WebView(context);
tempWebView.clearCache(includeDiskFiles);
tempWebView.destroy();
}
@Override
public void dispose() {
super.dispose();

View File

@ -66,9 +66,9 @@ public class WebViewChannelDelegate extends ChannelDelegateImpl {
static final String LOG_TAG = "WebViewChannelDelegate";
@Nullable
private InAppWebViewInterface webView;
private InAppWebView webView;
public WebViewChannelDelegate(@NonNull InAppWebViewInterface webView, @NonNull MethodChannel channel) {
public WebViewChannelDelegate(@NonNull InAppWebView webView, @NonNull MethodChannel channel) {
super(channel);
this.webView = webView;
}
@ -670,6 +670,11 @@ public class WebViewChannelDelegate extends ChannelDelegateImpl {
result.success(false);
}
break;
case clearFormData:
if (webView != null) {
webView.clearFormData();
}
result.success(true);
}
}

View File

@ -30,6 +30,10 @@ public enum WebViewChannelDelegateMethods {
isHidden,
getCopyBackForwardList,
startSafeBrowsing,
/**
* @deprecated
*/
@Deprecated
clearCache,
clearSslPreferences,
/**
@ -77,5 +81,6 @@ public enum WebViewChannelDelegateMethods {
addWebMessageListener,
canScrollVertically,
canScrollHorizontally,
isInFullscreen
isInFullscreen,
clearFormData
}

View File

@ -672,6 +672,10 @@ final public class InAppWebView extends InputAwareWebView implements InAppWebVie
return isLoading;
}
/**
* @deprecated
*/
@Deprecated
private void clearCookies() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
CookieManager.getInstance().removeAllCookies(new ValueCallback<Boolean>() {
@ -685,6 +689,10 @@ final public class InAppWebView extends InputAwareWebView implements InAppWebVie
}
}
/**
* @deprecated
*/
@Deprecated
public void clearAllCache() {
clearCache(true);
clearCookies();

View File

@ -31,6 +31,10 @@ public class InAppWebViewSettings implements ISettings<InAppWebViewInterface> {
public Boolean useShouldOverrideUrlLoading = false;
public Boolean useOnLoadResource = false;
public Boolean useOnDownloadStart = false;
/**
* @deprecated
*/
@Deprecated
public Boolean clearCache = false;
public String userAgent = "";
public String applicationNameForUserAgent = "";
@ -57,6 +61,10 @@ public class InAppWebViewSettings implements ISettings<InAppWebViewInterface> {
public Boolean allowUniversalAccessFromFileURLs = false;
public Boolean allowBackgroundAudioPlaying = false;
public Integer textZoom = 100;
/**
* @deprecated
*/
@Deprecated
public Boolean clearSessionCache = false;
public Boolean builtInZoomControls = true;
public Boolean displayZoomControls = false;

View File

@ -160,7 +160,7 @@ class AndroidCookieManager extends PlatformCookieManager
}
@override
Future<void> deleteCookie(
Future<bool> deleteCookie(
{required WebUri url,
required String name,
String path = "/",
@ -176,11 +176,11 @@ class AndroidCookieManager extends PlatformCookieManager
args.putIfAbsent('name', () => name);
args.putIfAbsent('domain', () => domain);
args.putIfAbsent('path', () => path);
await channel?.invokeMethod('deleteCookie', args);
return await channel?.invokeMethod<bool>('deleteCookie', args) ?? false;
}
@override
Future<void> deleteCookies(
Future<bool> deleteCookies(
{required WebUri url,
String path = "/",
String? domain,
@ -193,13 +193,20 @@ class AndroidCookieManager extends PlatformCookieManager
args.putIfAbsent('url', () => url.toString());
args.putIfAbsent('domain', () => domain);
args.putIfAbsent('path', () => path);
await channel?.invokeMethod('deleteCookies', args);
return await channel?.invokeMethod<bool>('deleteCookies', args) ?? false;
}
@override
Future<void> deleteAllCookies() async {
Future<bool> deleteAllCookies() async {
Map<String, dynamic> args = <String, dynamic>{};
await channel?.invokeMethod('deleteAllCookies', args);
return await channel?.invokeMethod<bool>('deleteAllCookies', args) ?? false;
}
@override
Future<bool> removeSessionCookies() async {
Map<String, dynamic> args = <String, dynamic>{};
return await channel?.invokeMethod<bool>('removeSessionCookies', args) ??
false;
}
@override

View File

@ -2067,6 +2067,7 @@ class AndroidInAppWebViewController extends PlatformInAppWebViewController
}
@override
@Deprecated("Use InAppWebViewController.clearAllCache instead")
Future<void> clearCache() async {
Map<String, dynamic> args = <String, dynamic>{};
await channel?.invokeMethod('clearCache', args);
@ -2641,6 +2642,12 @@ class AndroidInAppWebViewController extends PlatformInAppWebViewController
return await channel?.invokeMethod<bool>('isInFullscreen', args) ?? false;
}
@override
Future<void> clearFormData() async {
Map<String, dynamic> args = <String, dynamic>{};
return await channel?.invokeMethod('clearFormData', args);
}
@override
Future<String> getDefaultUserAgent() async {
Map<String, dynamic> args = <String, dynamic>{};
@ -2724,6 +2731,13 @@ class AndroidInAppWebViewController extends PlatformInAppWebViewController
_keepAliveMap[keepAlive] = null;
}
@override
Future<void> clearAllCache({bool includeDiskFiles = true}) async {
Map<String, dynamic> args = <String, dynamic>{};
args.putIfAbsent('includeDiskFiles', () => includeDiskFiles);
await _staticChannel.invokeMethod('clearAllCache', args);
}
@override
Future<String> get tRexRunnerHtml async => await rootBundle.loadString(
'packages/flutter_inappwebview/assets/t_rex_runner/t-rex.html');

View File

@ -2,6 +2,7 @@
- Implemented `InAppWebViewSettings.interceptOnlyAsyncAjaxRequests`
- Updated `useShouldInterceptAjaxRequest` automatic infer logic
- Updated `CookieManager` methods return value
- Fixed "iOS crash at public func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage)" [#1912](https://github.com/pichillilorenzo/flutter_inappwebview/issues/1912)
## 1.0.8

View File

@ -1346,9 +1346,9 @@ public class InAppWebView: WKWebView, UIScrollViewDelegate, WKUIDelegate,
}
}
@available(*, deprecated, message: "Use InAppWebViewManager.clearAllCache instead.")
public func clearCache() {
if #available(iOS 9.0, *) {
//let websiteDataTypes = NSSet(array: [WKWebsiteDataTypeDiskCache, WKWebsiteDataTypeMemoryCache])
let date = NSDate(timeIntervalSince1970: 0)
WKWebsiteDataStore.default().removeData(ofTypes: WKWebsiteDataStore.allWebsiteDataTypes(), modifiedSince: date as Date, completionHandler:{ })
} else {

View File

@ -45,6 +45,11 @@ public class InAppWebViewManager: ChannelDelegate {
disposeKeepAlive(keepAliveId: keepAliveId)
result(true)
break
case "clearAllCache":
let includeDiskFiles = arguments!["includeDiskFiles"] as! Bool
clearAllCache(includeDiskFiles: includeDiskFiles, completionHandler: {
result(true)
})
default:
result(FlutterMethodNotImplemented)
break
@ -84,6 +89,24 @@ public class InAppWebViewManager: ChannelDelegate {
}
}
public func clearAllCache(includeDiskFiles: Bool, completionHandler: @escaping () -> Void) {
if #available(iOS 9.0, *) {
var websiteDataTypes = Set([WKWebsiteDataTypeMemoryCache])
if includeDiskFiles {
websiteDataTypes.insert(WKWebsiteDataTypeDiskCache)
if #available(iOS 11.3, *) {
websiteDataTypes.insert(WKWebsiteDataTypeFetchCache)
}
websiteDataTypes.insert(WKWebsiteDataTypeOfflineWebApplicationCache)
}
let date = NSDate(timeIntervalSince1970: 0)
WKWebsiteDataStore.default().removeData(ofTypes: websiteDataTypes, modifiedSince: date as Date, completionHandler: completionHandler)
} else {
URLCache.shared.removeAllCachedResponses()
completionHandler()
}
}
public override func dispose() {
super.dispose()
let keepAliveWebViewValues = keepAliveWebViews.values

View File

@ -14,6 +14,7 @@ public class InAppWebViewSettings: ISettings<InAppWebView> {
var useShouldOverrideUrlLoading = false
var useOnLoadResource = false
var useOnDownloadStart = false
@available(*, deprecated, message: "Use InAppWebViewManager.clearAllCache instead.")
var clearCache = false
var userAgent = ""
var applicationNameForUserAgent = ""

View File

@ -42,6 +42,7 @@ public enum WebViewChannelDelegateMethods: String {
case findNext = "findNext"
@available(*, deprecated, message: "Use FindInteractionController.clearMatches instead.")
case clearMatches = "clearMatches"
@available(*, deprecated, message: "Use InAppWebViewManager.clearAllCache instead.")
case clearCache = "clearCache"
case scrollTo = "scrollTo"
case scrollBy = "scrollBy"

View File

@ -305,7 +305,7 @@ class IOSCookieManager extends PlatformCookieManager with ChannelController {
}
@override
Future<void> deleteCookie(
Future<bool> deleteCookie(
{required WebUri url,
required String name,
String path = "/",
@ -327,7 +327,7 @@ class IOSCookieManager extends PlatformCookieManager with ChannelController {
domain: domain,
maxAge: -1,
webViewController: webViewController);
return;
return true;
}
Map<String, dynamic> args = <String, dynamic>{};
@ -335,11 +335,11 @@ class IOSCookieManager extends PlatformCookieManager with ChannelController {
args.putIfAbsent('name', () => name);
args.putIfAbsent('domain', () => domain);
args.putIfAbsent('path', () => path);
await channel?.invokeMethod('deleteCookie', args);
return await channel?.invokeMethod<bool>('deleteCookie', args) ?? false;
}
@override
Future<void> deleteCookies(
Future<bool> deleteCookies(
{required WebUri url,
String path = "/",
String? domain,
@ -363,20 +363,20 @@ class IOSCookieManager extends PlatformCookieManager with ChannelController {
maxAge: -1,
webViewController: webViewController);
}
return;
return true;
}
Map<String, dynamic> args = <String, dynamic>{};
args.putIfAbsent('url', () => url.toString());
args.putIfAbsent('domain', () => domain);
args.putIfAbsent('path', () => path);
await channel?.invokeMethod('deleteCookies', args);
return await channel?.invokeMethod<bool>('deleteCookies', args) ?? false;
}
@override
Future<void> deleteAllCookies() async {
Future<bool> deleteAllCookies() async {
Map<String, dynamic> args = <String, dynamic>{};
await channel?.invokeMethod('deleteAllCookies', args);
return await channel?.invokeMethod<bool>('deleteAllCookies', args) ?? false;
}
@override

View File

@ -2056,6 +2056,7 @@ class IOSInAppWebViewController extends PlatformInAppWebViewController
}
@override
@Deprecated("Use InAppWebViewController.clearAllCache instead")
Future<void> clearCache() async {
Map<String, dynamic> args = <String, dynamic>{};
await channel?.invokeMethod('clearCache', args);
@ -2704,6 +2705,13 @@ class IOSInAppWebViewController extends PlatformInAppWebViewController
_keepAliveMap[keepAlive] = null;
}
@override
Future<void> clearAllCache({bool includeDiskFiles = true}) async {
Map<String, dynamic> args = <String, dynamic>{};
args.putIfAbsent('includeDiskFiles', () => includeDiskFiles);
await _staticChannel.invokeMethod('clearAllCache', args);
}
@override
Future<String> get tRexRunnerHtml async => await rootBundle.loadString(
'packages/flutter_inappwebview/assets/t_rex_runner/t-rex.html');

View File

@ -2,6 +2,7 @@
- Implemented `InAppWebViewSettings.interceptOnlyAsyncAjaxRequests`
- Updated `useShouldInterceptAjaxRequest` automatic infer logic
- Updated `CookieManager` methods return value
- Fixed "iOS crash at public func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage)" [#1912](https://github.com/pichillilorenzo/flutter_inappwebview/issues/1912)
## 1.0.6

View File

@ -305,7 +305,7 @@ class MacOSCookieManager extends PlatformCookieManager with ChannelController {
}
@override
Future<void> deleteCookie(
Future<bool> deleteCookie(
{required WebUri url,
required String name,
String path = "/",
@ -327,7 +327,7 @@ class MacOSCookieManager extends PlatformCookieManager with ChannelController {
domain: domain,
maxAge: -1,
webViewController: webViewController);
return;
return true;
}
Map<String, dynamic> args = <String, dynamic>{};
@ -335,11 +335,11 @@ class MacOSCookieManager extends PlatformCookieManager with ChannelController {
args.putIfAbsent('name', () => name);
args.putIfAbsent('domain', () => domain);
args.putIfAbsent('path', () => path);
await channel?.invokeMethod('deleteCookie', args);
return await channel?.invokeMethod<bool>('deleteCookie', args) ?? false;
}
@override
Future<void> deleteCookies(
Future<bool> deleteCookies(
{required WebUri url,
String path = "/",
String? domain,
@ -363,20 +363,20 @@ class MacOSCookieManager extends PlatformCookieManager with ChannelController {
maxAge: -1,
webViewController: webViewController);
}
return;
return true;
}
Map<String, dynamic> args = <String, dynamic>{};
args.putIfAbsent('url', () => url.toString());
args.putIfAbsent('domain', () => domain);
args.putIfAbsent('path', () => path);
await channel?.invokeMethod('deleteCookies', args);
return await channel?.invokeMethod<bool>('deleteCookies', args) ?? false;
}
@override
Future<void> deleteAllCookies() async {
Future<bool> deleteAllCookies() async {
Map<String, dynamic> args = <String, dynamic>{};
await channel?.invokeMethod('deleteAllCookies', args);
return await channel?.invokeMethod<bool>('deleteAllCookies', args) ?? false;
}
@override

View File

@ -2057,6 +2057,7 @@ class MacOSInAppWebViewController extends PlatformInAppWebViewController
}
@override
@Deprecated("Use InAppWebViewController.clearAllCache instead")
Future<void> clearCache() async {
Map<String, dynamic> args = <String, dynamic>{};
await channel?.invokeMethod('clearCache', args);
@ -2640,6 +2641,13 @@ class MacOSInAppWebViewController extends PlatformInAppWebViewController
_keepAliveMap[keepAlive] = null;
}
@override
Future<void> clearAllCache({bool includeDiskFiles = true}) async {
Map<String, dynamic> args = <String, dynamic>{};
args.putIfAbsent('includeDiskFiles', () => includeDiskFiles);
await _staticChannel.invokeMethod('clearAllCache', args);
}
@override
Future<String> get tRexRunnerHtml async => await rootBundle.loadString(
'packages/flutter_inappwebview/assets/t_rex_runner/t-rex.html');

View File

@ -796,6 +796,7 @@ public class InAppWebView: WKWebView, WKUIDelegate,
}
}
@available(*, deprecated, message: "Use InAppWebViewManager.clearAllCache instead.")
public func clearCache() {
let date = NSDate(timeIntervalSince1970: 0)
WKWebsiteDataStore.default().removeData(ofTypes: WKWebsiteDataStore.allWebsiteDataTypes(), modifiedSince: date as Date, completionHandler:{ })

View File

@ -46,6 +46,11 @@ public class InAppWebViewManager: ChannelDelegate {
disposeKeepAlive(keepAliveId: keepAliveId)
result(true)
break
case "clearAllCache":
let includeDiskFiles = arguments!["includeDiskFiles"] as! Bool
clearAllCache(includeDiskFiles: includeDiskFiles, completionHandler: {
result(true)
})
default:
result(FlutterMethodNotImplemented)
break
@ -85,6 +90,19 @@ public class InAppWebViewManager: ChannelDelegate {
}
}
public func clearAllCache(includeDiskFiles: Bool, completionHandler: @escaping () -> Void) {
var websiteDataTypes = Set([WKWebsiteDataTypeMemoryCache])
if includeDiskFiles {
websiteDataTypes.insert(WKWebsiteDataTypeDiskCache)
if #available(macOS 10.13.4, *) {
websiteDataTypes.insert(WKWebsiteDataTypeFetchCache)
}
websiteDataTypes.insert(WKWebsiteDataTypeOfflineWebApplicationCache)
}
let date = NSDate(timeIntervalSince1970: 0)
WKWebsiteDataStore.default().removeData(ofTypes: websiteDataTypes, modifiedSince: date as Date, completionHandler: completionHandler)
}
public override func dispose() {
super.dispose()
let keepAliveWebViewValues = keepAliveWebViews.values

View File

@ -14,6 +14,7 @@ public class InAppWebViewSettings: ISettings<InAppWebView> {
var useShouldOverrideUrlLoading = false
var useOnLoadResource = false
var useOnDownloadStart = false
@available(*, deprecated, message: "Use InAppWebViewManager.clearAllCache instead.")
var clearCache = false
var userAgent = ""
var applicationNameForUserAgent = ""

View File

@ -42,6 +42,7 @@ public enum WebViewChannelDelegateMethods: String {
case findNext = "findNext"
@available(*, deprecated, message: "Use FindInteractionController.clearMatches instead.")
case clearMatches = "clearMatches"
@available(*, deprecated, message: "Use InAppWebViewManager.clearAllCache instead.")
case clearCache = "clearCache"
case scrollTo = "scrollTo"
case scrollBy = "scrollBy"

View File

@ -1,7 +1,10 @@
## 1.0.6
- Updated `InAppWebViewSettings.useShouldInterceptAjaxRequest` docs
- Added `InAppWebViewSettings.interceptOnlyAsyncAjaxRequests` [#1905](https://github.com/pichillilorenzo/flutter_inappwebview/issues/1905)
- Added `PlatformInAppWebViewController.clearFormData` method
- Added `PlatformCookieManager.removeSessionCookies` method
- Updated `InAppWebViewSettings.useShouldInterceptAjaxRequest` docs
- Updated `PlatformCookieManager` methods return value
## 1.0.5

View File

@ -41,7 +41,7 @@ abstract class PlatformChromeSafariBrowser extends PlatformInterface
///{@template flutter_inappwebview_platform_interface.PlatformChromeSafariBrowser.id}
///View ID used internally.
///@{endtemplate}
///{@endtemplate}
String get id {
throw UnimplementedError('id is not implemented on the current platform');
}

View File

@ -64,7 +64,7 @@ class PlatformInAppBrowserCreationParams {
///- Android native WebView
///- iOS
///- MacOS
///@{endtemplate}
///{@endtemplate}
abstract class PlatformInAppBrowser extends PlatformInterface
implements Disposable {
///Debug settings.
@ -75,43 +75,43 @@ abstract class PlatformInAppBrowser extends PlatformInterface
///{@template flutter_inappwebview_platform_interface.PlatformInAppBrowser.id}
///View ID used internally.
///@{endtemplate}
///{@endtemplate}
String get id {
throw UnimplementedError('id is not implemented on the current platform');
}
///{@template flutter_inappwebview_platform_interface.PlatformInAppBrowser.contextMenu}
///Context menu used by the browser. It should be set before opening the browser.
///@{endtemplate}
///{@endtemplate}
ContextMenu? get contextMenu => params.contextMenu;
///{@template flutter_inappwebview_platform_interface.PlatformInAppBrowser.pullToRefreshController}
///Represents the pull-to-refresh feature controller.
///@{endtemplate}
///{@endtemplate}
PlatformPullToRefreshController? get pullToRefreshController =>
params.pullToRefreshController;
///{@template flutter_inappwebview_platform_interface.PlatformInAppBrowser.findInteractionController}
///Represents the find interaction feature controller.
///@{endtemplate}
///{@endtemplate}
PlatformFindInteractionController? get findInteractionController =>
params.findInteractionController;
///{@template flutter_inappwebview_platform_interface.PlatformInAppBrowser.initialUserScripts}
///Initial list of user scripts to be loaded at start or end of a page loading.
///@{endtemplate}
///{@endtemplate}
UnmodifiableListView<UserScript>? get initialUserScripts =>
params.initialUserScripts;
///{@template flutter_inappwebview_platform_interface.PlatformInAppBrowser.windowId}
///The window id of a [CreateWindowAction.windowId].
///@{endtemplate}
///{@endtemplate}
int? get windowId => params.windowId;
///{@template flutter_inappwebview_platform_interface.PlatformInAppBrowser.webViewController}
///WebView Controller that can be used to access the [PlatformInAppWebViewController] API.
///When [onExit] is fired, this will be `null` and cannot be used anymore.
///@{endtemplate}
///{@endtemplate}
PlatformInAppWebViewController? get webViewController {
throw UnimplementedError(
'webViewController is not implemented on the current platform');

View File

@ -79,7 +79,8 @@ class InAppWebViewSettings_ {
platforms: [AndroidPlatform(), IOSPlatform(), MacOSPlatform()])
bool? useOnDownloadStart;
///Set to `true` to have all the browser's cache cleared before the new WebView is opened. The default value is `false`.
///Use [PlatformInAppWebViewController.clearAllCache] instead.
@Deprecated("Use InAppWebViewController.clearAllCache instead")
@SupportedPlatforms(
platforms: [AndroidPlatform(), IOSPlatform(), MacOSPlatform()])
bool? clearCache;
@ -398,7 +399,8 @@ because there isn't any way to make the website data store non-persistent for th
])
int? textZoom;
///Set to `true` to have the session cookie cache cleared before the new window is opened.
///Use [PlatformCookieManager.removeSessionCookies] instead.
@Deprecated("Use CookieManager.removeSessionCookies instead")
@SupportedPlatforms(platforms: [AndroidPlatform()])
bool? clearSessionCache;

View File

@ -176,6 +176,9 @@ abstract class PlatformCookieManager extends PlatformInterface {
///from the current context of the `WebView` managed by that controller when you need to target iOS below 11, MacOS below 10.13 and Web platform. JavaScript must be enabled in order to work.
///In this case the [url] parameter is ignored.
///
///The return value indicates whether the cookie was deleted successfully.
///Note that it will return always `true` for Web platform, iOS below 11.0 and MacOS below 10.13.
///
///**NOTE for iOS below 11.0 and MacOS below 10.13**: If [webViewController] is `null` or JavaScript is disabled for it, it will try to use a [PlatformHeadlessInAppWebView]
///to delete the cookie (session-only cookie and cookie with `isHttpOnly` enabled won't be deleted!).
///
@ -189,7 +192,7 @@ abstract class PlatformCookieManager extends PlatformInterface {
///- MacOS ([Official API - WKHTTPCookieStore.delete](https://developer.apple.com/documentation/webkit/wkhttpcookiestore/2882009-delete)
///- Web
///{@endtemplate}
Future<void> deleteCookie(
Future<bool> deleteCookie(
{required WebUri url,
required String name,
String path = "/",
@ -210,6 +213,9 @@ abstract class PlatformCookieManager extends PlatformInterface {
///from the current context of the `WebView` managed by that controller when you need to target iOS below 11, MacOS below 10.13 and Web platform. JavaScript must be enabled in order to work.
///In this case the [url] parameter is ignored.
///
///The return value indicates whether cookies were deleted successfully.
///Note that it will return always `true` for Web platform, iOS below 11.0 and MacOS below 10.13.
///
///**NOTE for iOS below 11.0 and MacOS below 10.13**: If [webViewController] is `null` or JavaScript is disabled for it, it will try to use a [PlatformHeadlessInAppWebView]
///to delete the cookies (session-only cookies and cookies with `isHttpOnly` enabled won't be deleted!).
///
@ -223,7 +229,7 @@ abstract class PlatformCookieManager extends PlatformInterface {
///- MacOS
///- Web
///{@endtemplate}
Future<void> deleteCookies(
Future<bool> deleteCookies(
{required WebUri url,
String path = "/",
String? domain,
@ -237,6 +243,9 @@ abstract class PlatformCookieManager extends PlatformInterface {
///{@template flutter_inappwebview_platform_interface.PlatformCookieManager.deleteAllCookies}
///Removes all cookies.
///
///The return value indicates whether any cookies were removed.
///Note that it will return always `true` for Web, iOS and MacOS platforms.
///
///**NOTE for iOS**: available from iOS 11.0+.
///
///**NOTE for MacOS**: available from iOS 10.13+.
@ -246,7 +255,7 @@ abstract class PlatformCookieManager extends PlatformInterface {
///- 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))
///{@endtemplate}
Future<void> deleteAllCookies() {
Future<bool> deleteAllCookies() {
throw UnimplementedError(
'deleteAllCookies is not implemented on the current platform');
}
@ -266,4 +275,17 @@ abstract class PlatformCookieManager extends PlatformInterface {
throw UnimplementedError(
'getAllCookies is not implemented on the current platform');
}
///{@template flutter_inappwebview_platform_interface.PlatformCookieManager.removeSessionCookies}
///Removes all session cookies, which are cookies without an expiration date.
///
///The return value indicates whether any cookies were removed.
///
///**Officially Supported Platforms/Implementations**:
///- Android native WebView ([Official API - CookieManager.removeSessionCookies](https://developer.android.com/reference/android/webkit/CookieManager#removeSessionCookies(android.webkit.ValueCallback%3Cjava.lang.Boolean%3E)))
///{@endtemplate}
Future<bool> removeSessionCookies() {
throw UnimplementedError(
'removeSessionCookies is not implemented on the current platform');
}
}

View File

@ -1,6 +1,7 @@
## 1.0.4
- Updated `flutter_inappwebview_platform_interface` version dependency to `1.0.6`
- Updated `CookieManager` methods return value
## 1.0.3

View File

@ -241,7 +241,7 @@ class WebPlatformCookieManager extends PlatformCookieManager
}
@override
Future<void> deleteCookie(
Future<bool> deleteCookie(
{required WebUri url,
required String name,
String path = "/",
@ -262,11 +262,11 @@ class WebPlatformCookieManager extends PlatformCookieManager
domain: domain,
maxAge: -1,
webViewController: webViewController);
return;
return true;
}
@override
Future<void> deleteCookies(
Future<bool> deleteCookies(
{required WebUri url,
String path = "/",
String? domain,
@ -289,7 +289,7 @@ class WebPlatformCookieManager extends PlatformCookieManager
maxAge: -1,
webViewController: webViewController);
}
return;
return true;
}
Future<String> _getCookieExpirationDate(int expiresDate) async {