From ac78c15e973ff681854b2f0c62564cd271fa8c0d Mon Sep 17 00:00:00 2001 From: Igor Kharakhordin Date: Wed, 11 Dec 2024 09:17:02 +0100 Subject: [PATCH 1/5] [webview_flutter_android] Add WebSettings methods setAllowFileAccess, setAllowContentAccess, setGeolocationEnabled, setCacheMode --- .../webview_flutter_android/CHANGELOG.md | 4 + .../webviewflutter/AndroidWebkitLibrary.g.kt | 128 ++++++++++++++++++ .../webviewflutter/WebSettingsProxyApi.java | 30 ++++ .../lib/src/android_webkit.g.dart | 116 ++++++++++++++++ .../lib/src/android_webview_controller.dart | 27 ++++ .../pigeons/android_webkit.dart | 35 +++++ .../webview_flutter_android/pubspec.yaml | 2 +- .../test/android_webview_controller_test.dart | 50 +++++++ ...android_webview_controller_test.mocks.dart | 70 ++++++++++ ...oid_webview_cookie_manager_test.mocks.dart | 40 ++++++ .../webview_android_widget_test.mocks.dart | 30 ++++ 11 files changed, 531 insertions(+), 1 deletion(-) diff --git a/packages/webview_flutter/webview_flutter_android/CHANGELOG.md b/packages/webview_flutter/webview_flutter_android/CHANGELOG.md index 16dcfd07e48..bb3f781b64c 100644 --- a/packages/webview_flutter/webview_flutter_android/CHANGELOG.md +++ b/packages/webview_flutter/webview_flutter_android/CHANGELOG.md @@ -1,3 +1,7 @@ +## 4.2.0 + +* Adds WebSettings methods: `AndroidWebViewController.setAllowFileAccess`, `AndroidWebViewController.setAllowContentAccess`, `AndroidWebViewController.setGeolocationEnabled` and `AndroidWebViewController.setCacheMode`. + ## 4.1.0 * Updates internal API wrapper to use `ProxyApi`s. diff --git a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/AndroidWebkitLibrary.g.kt b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/AndroidWebkitLibrary.g.kt index f2808272548..a1c1ca9864a 100644 --- a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/AndroidWebkitLibrary.g.kt +++ b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/AndroidWebkitLibrary.g.kt @@ -571,6 +571,7 @@ private class AndroidWebkitLibraryPigeonProxyApiBaseCodec( value is String || value is FileChooserMode || value is ConsoleMessageLevel || + value is CacheMode || value == null) { super.writeValue(stream, value) return @@ -726,6 +727,45 @@ enum class ConsoleMessageLevel(val raw: Int) { } } +/** + * Describes the way the cache is used. + * + * See https://developer.android.com/reference/android/webkit/WebSettings#setCacheMode(int). + */ +enum class CacheMode(val raw: Int) { + /** + * Normal cache usage mode. + * + * See https://developer.android.com/reference/android/webkit/WebSettings#LOAD_DEFAULT + */ + LOAD_DEFAULT(0), + /** + * Use cached resources when they are available, even if they have expired. Otherwise load + * resources from the network. + * + * See https://developer.android.com/reference/android/webkit/WebSettings#LOAD_CACHE_ELSE_NETWORK + */ + LOAD_CACHE_ELSE_NETWORK(1), + /** + * Don't use the cache, load from the network. + * + * See https://developer.android.com/reference/android/webkit/WebSettings#LOAD_CACHE_ELSE_NETWORK + */ + LOAD_NO_CACHE(2), + /** + * Don't use the network, load from the cache. + * + * See https://developer.android.com/reference/android/webkit/WebSettings#LOAD_CACHE_ONLY + */ + LOAD_CACHE_ONLY(3); + + companion object { + fun ofRaw(raw: Int): CacheMode? { + return values().firstOrNull { it.raw == raw } + } + } +} + private open class AndroidWebkitLibraryPigeonCodec : StandardMessageCodec() { override fun readValueOfType(type: Byte, buffer: ByteBuffer): Any? { return when (type) { @@ -735,6 +775,9 @@ private open class AndroidWebkitLibraryPigeonCodec : StandardMessageCodec() { 130.toByte() -> { return (readValue(buffer) as Long?)?.let { ConsoleMessageLevel.ofRaw(it.toInt()) } } + 131.toByte() -> { + return (readValue(buffer) as Long?)?.let { CacheMode.ofRaw(it.toInt()) } + } else -> super.readValueOfType(type, buffer) } } @@ -749,6 +792,10 @@ private open class AndroidWebkitLibraryPigeonCodec : StandardMessageCodec() { stream.write(130) writeValue(stream, value.raw) } + is CacheMode -> { + stream.write(131) + writeValue(stream, value.raw) + } else -> super.writeValue(stream, value) } } @@ -2104,6 +2151,15 @@ abstract class PigeonApiWebSettings( /** Enables or disables file access within WebView. */ abstract fun setAllowFileAccess(pigeon_instance: android.webkit.WebSettings, enabled: Boolean) + /** Enables or disables content URL access within WebView. */ + abstract fun setAllowContentAccess(pigeon_instance: android.webkit.WebSettings, enabled: Boolean) + + /** Sets whether Geolocation is enabled within WebView. */ + abstract fun setGeolocationEnabled(pigeon_instance: android.webkit.WebSettings, enabled: Boolean) + + /** Overrides the way the cache is used. */ + abstract fun setCacheMode(pigeon_instance: android.webkit.WebSettings, mode: CacheMode) + /** Sets the text zoom of the page in percent. */ abstract fun setTextZoom(pigeon_instance: android.webkit.WebSettings, textZoom: Long) @@ -2402,6 +2458,78 @@ abstract class PigeonApiWebSettings( channel.setMessageHandler(null) } } + run { + val channel = + BasicMessageChannel( + binaryMessenger, + "dev.flutter.pigeon.webview_flutter_android.WebSettings.setAllowContentAccess", + codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val pigeon_instanceArg = args[0] as android.webkit.WebSettings + val enabledArg = args[1] as Boolean + val wrapped: List = + try { + api.setAllowContentAccess(pigeon_instanceArg, enabledArg) + listOf(null) + } catch (exception: Throwable) { + wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = + BasicMessageChannel( + binaryMessenger, + "dev.flutter.pigeon.webview_flutter_android.WebSettings.setGeolocationEnabled", + codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val pigeon_instanceArg = args[0] as android.webkit.WebSettings + val enabledArg = args[1] as Boolean + val wrapped: List = + try { + api.setGeolocationEnabled(pigeon_instanceArg, enabledArg) + listOf(null) + } catch (exception: Throwable) { + wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = + BasicMessageChannel( + binaryMessenger, + "dev.flutter.pigeon.webview_flutter_android.WebSettings.setCacheMode", + codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val pigeon_instanceArg = args[0] as android.webkit.WebSettings + val modeArg = args[1] as CacheMode + val wrapped: List = + try { + api.setCacheMode(pigeon_instanceArg, modeArg) + listOf(null) + } catch (exception: Throwable) { + wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } run { val channel = BasicMessageChannel( diff --git a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/WebSettingsProxyApi.java b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/WebSettingsProxyApi.java index 82fa32b8150..bf167907b92 100644 --- a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/WebSettingsProxyApi.java +++ b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/WebSettingsProxyApi.java @@ -18,6 +18,21 @@ public WebSettingsProxyApi(@NonNull ProxyApiRegistrar pigeonRegistrar) { super(pigeonRegistrar); } + private static int mapCacheMode(CacheMode pigeonMode) { + switch (pigeonMode) { + case LOAD_DEFAULT: + return WebSettings.LOAD_DEFAULT; + case LOAD_CACHE_ELSE_NETWORK: + return WebSettings.LOAD_CACHE_ELSE_NETWORK; + case LOAD_NO_CACHE: + return WebSettings.LOAD_NO_CACHE; + case LOAD_CACHE_ONLY: + return WebSettings.LOAD_CACHE_ONLY; + } + + return WebSettings.LOAD_DEFAULT; + } + @Override public void setDomStorageEnabled(@NonNull WebSettings pigeon_instance, boolean flag) { pigeon_instance.setDomStorageEnabled(flag); @@ -81,6 +96,21 @@ public void setAllowFileAccess(@NonNull WebSettings pigeon_instance, boolean ena pigeon_instance.setAllowFileAccess(enabled); } + @Override + public void setAllowContentAccess(@NonNull WebSettings pigeon_instance, boolean enabled) { + pigeon_instance.setAllowContentAccess(enabled); + } + + @Override + public void setGeolocationEnabled(@NonNull WebSettings pigeon_instance, boolean enabled) { + pigeon_instance.setGeolocationEnabled(enabled); + } + + @Override + public void setCacheMode(@NonNull WebSettings pigeon_instance, @NonNull CacheMode mode) { + pigeon_instance.setCacheMode(mapCacheMode(mode)); + } + @Override public void setTextZoom(@NonNull WebSettings pigeon_instance, long textZoom) { pigeon_instance.setTextZoom((int) textZoom); diff --git a/packages/webview_flutter/webview_flutter_android/lib/src/android_webkit.g.dart b/packages/webview_flutter/webview_flutter_android/lib/src/android_webkit.g.dart index fc7174a27d0..e7dbd7a0982 100644 --- a/packages/webview_flutter/webview_flutter_android/lib/src/android_webkit.g.dart +++ b/packages/webview_flutter/webview_flutter_android/lib/src/android_webkit.g.dart @@ -503,6 +503,32 @@ enum ConsoleMessageLevel { unknown, } +/// Describes the way the cache is used. +/// +/// See https://developer.android.com/reference/android/webkit/WebSettings#setCacheMode(int). +enum CacheMode { + /// Normal cache usage mode. + /// + /// See https://developer.android.com/reference/android/webkit/WebSettings#LOAD_DEFAULT + loadDefault, + + /// Use cached resources when they are available, even if they have expired. + /// Otherwise load resources from the network. + /// + /// See https://developer.android.com/reference/android/webkit/WebSettings#LOAD_CACHE_ELSE_NETWORK + loadCacheElseNetwork, + + /// Don't use the cache, load from the network. + /// + /// See https://developer.android.com/reference/android/webkit/WebSettings#LOAD_CACHE_ELSE_NETWORK + loadNoCache, + + /// Don't use the network, load from the cache. + /// + /// See https://developer.android.com/reference/android/webkit/WebSettings#LOAD_CACHE_ONLY + loadCacheOnly, +} + class _PigeonCodec extends StandardMessageCodec { const _PigeonCodec(); @override @@ -516,6 +542,9 @@ class _PigeonCodec extends StandardMessageCodec { } else if (value is ConsoleMessageLevel) { buffer.putUint8(130); writeValue(buffer, value.index); + } else if (value is CacheMode) { + buffer.putUint8(131); + writeValue(buffer, value.index); } else { super.writeValue(buffer, value); } @@ -530,6 +559,9 @@ class _PigeonCodec extends StandardMessageCodec { case 130: final int? value = readValue(buffer) as int?; return value == null ? null : ConsoleMessageLevel.values[value]; + case 131: + final int? value = readValue(buffer) as int?; + return value == null ? null : CacheMode.values[value]; default: return super.readValueOfType(type, buffer); } @@ -2615,6 +2647,90 @@ class WebSettings extends PigeonInternalProxyApiBaseClass { } } + /// Enables or disables content URL access within WebView. + Future setAllowContentAccess(bool enabled) async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecWebSettings; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_android.WebSettings.setAllowContentAccess'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = await pigeonVar_channel + .send([this, enabled]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return; + } + } + + /// Sets whether Geolocation is enabled within WebView. + Future setGeolocationEnabled(bool enabled) async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecWebSettings; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_android.WebSettings.setGeolocationEnabled'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = await pigeonVar_channel + .send([this, enabled]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return; + } + } + + /// Overrides the way the cache is used. + Future setCacheMode(CacheMode mode) async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecWebSettings; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_android.WebSettings.setCacheMode'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = + await pigeonVar_channel.send([this, mode]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return; + } + } + /// Sets the text zoom of the page in percent. Future setTextZoom(int textZoom) async { final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = diff --git a/packages/webview_flutter/webview_flutter_android/lib/src/android_webview_controller.dart b/packages/webview_flutter/webview_flutter_android/lib/src/android_webview_controller.dart index c250a87d36a..f0aacc94217 100644 --- a/packages/webview_flutter/webview_flutter_android/lib/src/android_webview_controller.dart +++ b/packages/webview_flutter/webview_flutter_android/lib/src/android_webview_controller.dart @@ -17,6 +17,8 @@ import 'android_webkit_constants.dart'; import 'platform_views_service_proxy.dart'; import 'weak_reference_utils.dart'; +export 'android_webkit.g.dart' show CacheMode; + /// Object specifying creation parameters for creating a [AndroidWebViewController]. /// /// When adding additional fields make sure they can be null or have a default @@ -592,6 +594,31 @@ class AndroidWebViewController extends PlatformWebViewController { Future setTextZoom(int textZoom) => _webView.settings.setTextZoom(textZoom); + /// Enables or disables file access. + /// + /// The default is false. + Future setAllowFileAccess(bool enabled) => + _webView.settings.setAllowFileAccess(enabled); + + /// Enables or disables content URL access. + /// + /// The default is true. + Future setAllowContentAccess(bool enabled) => + _webView.settings.setAllowContentAccess(enabled); + + /// Sets whether Geolocation is enabled. + /// + /// The default is true. + Future setGeolocationEnabled(bool enabled) => + _webView.settings.setGeolocationEnabled(enabled); + + /// Allows the client to override the way the cache is used + /// by specifying one of [android_webview.CacheMode] values. + /// + /// The default is [android_webview.CacheMode.loadDefault]. + Future setCacheMode(android_webview.CacheMode mode) => + _webView.settings.setCacheMode(mode); + /// Sets the callback that is invoked when the client should show a file /// selector. Future setOnShowFileSelector( diff --git a/packages/webview_flutter/webview_flutter_android/pigeons/android_webkit.dart b/packages/webview_flutter/webview_flutter_android/pigeons/android_webkit.dart index 22435d5b97d..2f154c81f37 100644 --- a/packages/webview_flutter/webview_flutter_android/pigeons/android_webkit.dart +++ b/packages/webview_flutter/webview_flutter_android/pigeons/android_webkit.dart @@ -80,6 +80,32 @@ enum ConsoleMessageLevel { unknown, } +/// Describes the way the cache is used. +/// +/// See https://developer.android.com/reference/android/webkit/WebSettings#setCacheMode(int). +enum CacheMode { + /// Normal cache usage mode. + /// + /// See https://developer.android.com/reference/android/webkit/WebSettings#LOAD_DEFAULT + loadDefault, + + /// Use cached resources when they are available, even if they have expired. + /// Otherwise load resources from the network. + /// + /// See https://developer.android.com/reference/android/webkit/WebSettings#LOAD_CACHE_ELSE_NETWORK + loadCacheElseNetwork, + + /// Don't use the cache, load from the network. + /// + /// See https://developer.android.com/reference/android/webkit/WebSettings#LOAD_CACHE_ELSE_NETWORK + loadNoCache, + + /// Don't use the network, load from the cache. + /// + /// See https://developer.android.com/reference/android/webkit/WebSettings#LOAD_CACHE_ONLY + loadCacheOnly; +} + /// Encompasses parameters to the `WebViewClient.shouldInterceptRequest` method. /// /// See https://developer.android.com/reference/android/webkit/WebResourceRequest. @@ -354,6 +380,15 @@ abstract class WebSettings { /// Enables or disables file access within WebView. void setAllowFileAccess(bool enabled); + /// Enables or disables content URL access within WebView. + void setAllowContentAccess(bool enabled); + + /// Sets whether Geolocation is enabled within WebView. + void setGeolocationEnabled(bool enabled); + + /// Overrides the way the cache is used. + void setCacheMode(CacheMode mode); + /// Sets the text zoom of the page in percent. void setTextZoom(int textZoom); diff --git a/packages/webview_flutter/webview_flutter_android/pubspec.yaml b/packages/webview_flutter/webview_flutter_android/pubspec.yaml index 4ff9b6166a6..44f19b2af19 100644 --- a/packages/webview_flutter/webview_flutter_android/pubspec.yaml +++ b/packages/webview_flutter/webview_flutter_android/pubspec.yaml @@ -2,7 +2,7 @@ name: webview_flutter_android description: A Flutter plugin that provides a WebView widget on Android. repository: https://github.com/flutter/packages/tree/main/packages/webview_flutter/webview_flutter_android issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+webview%22 -version: 4.1.0 +version: 4.2.0 environment: sdk: ^3.5.0 diff --git a/packages/webview_flutter/webview_flutter_android/test/android_webview_controller_test.dart b/packages/webview_flutter/webview_flutter_android/test/android_webview_controller_test.dart index 6879c33253e..b1778441bbb 100644 --- a/packages/webview_flutter/webview_flutter_android/test/android_webview_controller_test.dart +++ b/packages/webview_flutter/webview_flutter_android/test/android_webview_controller_test.dart @@ -1510,6 +1510,56 @@ void main() { verify(mockSettings.setMediaPlaybackRequiresUserGesture(true)).called(1); }); + test('setAllowContentAccess', () async { + final MockWebView mockWebView = MockWebView(); + final MockWebSettings mockSettings = MockWebSettings(); + final AndroidWebViewController controller = createControllerWithMocks( + mockWebView: mockWebView, + mockSettings: mockSettings, + ); + + clearInteractions(mockWebView); + + await controller.setAllowContentAccess(false); + + verify(mockWebView.settings).called(1); + verify(mockSettings.setAllowContentAccess(false)).called(1); + }); + + test('setGeolocationEnabled', () async { + final MockWebView mockWebView = MockWebView(); + final MockWebSettings mockSettings = MockWebSettings(); + final AndroidWebViewController controller = createControllerWithMocks( + mockWebView: mockWebView, + mockSettings: mockSettings, + ); + + clearInteractions(mockWebView); + + await controller.setGeolocationEnabled(false); + + verify(mockWebView.settings).called(1); + verify(mockSettings.setGeolocationEnabled(false)).called(1); + }); + + test('setCacheMode', () async { + final MockWebView mockWebView = MockWebView(); + final MockWebSettings mockSettings = MockWebSettings(); + final AndroidWebViewController controller = createControllerWithMocks( + mockWebView: mockWebView, + mockSettings: mockSettings, + ); + + clearInteractions(mockWebView); + + const android_webview.CacheMode value = + android_webview.CacheMode.loadCacheElseNetwork; + await controller.setCacheMode(value); + + verify(mockWebView.settings).called(1); + verify(mockSettings.setCacheMode(value)).called(1); + }); + test('setTextZoom', () async { final MockWebView mockWebView = MockWebView(); final MockWebSettings mockSettings = MockWebSettings(); diff --git a/packages/webview_flutter/webview_flutter_android/test/android_webview_controller_test.mocks.dart b/packages/webview_flutter/webview_flutter_android/test/android_webview_controller_test.mocks.dart index d0254f2bd80..68817a47434 100644 --- a/packages/webview_flutter/webview_flutter_android/test/android_webview_controller_test.mocks.dart +++ b/packages/webview_flutter/webview_flutter_android/test/android_webview_controller_test.mocks.dart @@ -789,6 +789,46 @@ class MockAndroidWebViewController extends _i1.Mock returnValueForMissingStub: _i8.Future.value(), ) as _i8.Future); + @override + _i8.Future setAllowFileAccess(bool? enabled) => (super.noSuchMethod( + Invocation.method( + #setAllowFileAccess, + [enabled], + ), + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); + + @override + _i8.Future setAllowContentAccess(bool? enabled) => (super.noSuchMethod( + Invocation.method( + #setAllowContentAccess, + [enabled], + ), + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); + + @override + _i8.Future setGeolocationEnabled(bool? enabled) => (super.noSuchMethod( + Invocation.method( + #setGeolocationEnabled, + [enabled], + ), + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); + + @override + _i8.Future setCacheMode(_i2.CacheMode? mode) => (super.noSuchMethod( + Invocation.method( + #setCacheMode, + [mode], + ), + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); + @override _i8.Future setOnShowFileSelector( _i8.Future> Function(_i7.FileSelectorParams)? @@ -2638,6 +2678,36 @@ class MockWebSettings extends _i1.Mock implements _i2.WebSettings { returnValueForMissingStub: _i8.Future.value(), ) as _i8.Future); + @override + _i8.Future setAllowContentAccess(bool? enabled) => (super.noSuchMethod( + Invocation.method( + #setAllowContentAccess, + [enabled], + ), + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); + + @override + _i8.Future setGeolocationEnabled(bool? enabled) => (super.noSuchMethod( + Invocation.method( + #setGeolocationEnabled, + [enabled], + ), + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); + + @override + _i8.Future setCacheMode(_i2.CacheMode? mode) => (super.noSuchMethod( + Invocation.method( + #setCacheMode, + [mode], + ), + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); + @override _i8.Future setTextZoom(int? textZoom) => (super.noSuchMethod( Invocation.method( diff --git a/packages/webview_flutter/webview_flutter_android/test/android_webview_cookie_manager_test.mocks.dart b/packages/webview_flutter/webview_flutter_android/test/android_webview_cookie_manager_test.mocks.dart index 303f54d46f6..50895d862ec 100644 --- a/packages/webview_flutter/webview_flutter_android/test/android_webview_cookie_manager_test.mocks.dart +++ b/packages/webview_flutter/webview_flutter_android/test/android_webview_cookie_manager_test.mocks.dart @@ -494,6 +494,46 @@ class MockAndroidWebViewController extends _i1.Mock returnValueForMissingStub: _i5.Future.value(), ) as _i5.Future); + @override + _i5.Future setAllowFileAccess(bool? enabled) => (super.noSuchMethod( + Invocation.method( + #setAllowFileAccess, + [enabled], + ), + returnValue: _i5.Future.value(), + returnValueForMissingStub: _i5.Future.value(), + ) as _i5.Future); + + @override + _i5.Future setAllowContentAccess(bool? enabled) => (super.noSuchMethod( + Invocation.method( + #setAllowContentAccess, + [enabled], + ), + returnValue: _i5.Future.value(), + returnValueForMissingStub: _i5.Future.value(), + ) as _i5.Future); + + @override + _i5.Future setGeolocationEnabled(bool? enabled) => (super.noSuchMethod( + Invocation.method( + #setGeolocationEnabled, + [enabled], + ), + returnValue: _i5.Future.value(), + returnValueForMissingStub: _i5.Future.value(), + ) as _i5.Future); + + @override + _i5.Future setCacheMode(_i2.CacheMode? mode) => (super.noSuchMethod( + Invocation.method( + #setCacheMode, + [mode], + ), + returnValue: _i5.Future.value(), + returnValueForMissingStub: _i5.Future.value(), + ) as _i5.Future); + @override _i5.Future setOnShowFileSelector( _i5.Future> Function(_i6.FileSelectorParams)? diff --git a/packages/webview_flutter/webview_flutter_android/test/legacy/webview_android_widget_test.mocks.dart b/packages/webview_flutter/webview_flutter_android/test/legacy/webview_android_widget_test.mocks.dart index 44c8b8adb47..8d4fe7742b3 100644 --- a/packages/webview_flutter/webview_flutter_android/test/legacy/webview_android_widget_test.mocks.dart +++ b/packages/webview_flutter/webview_flutter_android/test/legacy/webview_android_widget_test.mocks.dart @@ -355,6 +355,36 @@ class MockWebSettings extends _i1.Mock implements _i2.WebSettings { returnValueForMissingStub: _i4.Future.value(), ) as _i4.Future); + @override + _i4.Future setAllowContentAccess(bool? enabled) => (super.noSuchMethod( + Invocation.method( + #setAllowContentAccess, + [enabled], + ), + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); + + @override + _i4.Future setGeolocationEnabled(bool? enabled) => (super.noSuchMethod( + Invocation.method( + #setGeolocationEnabled, + [enabled], + ), + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); + + @override + _i4.Future setCacheMode(_i2.CacheMode? mode) => (super.noSuchMethod( + Invocation.method( + #setCacheMode, + [mode], + ), + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); + @override _i4.Future setTextZoom(int? textZoom) => (super.noSuchMethod( Invocation.method( From 0488b59b339664874a18b097d6e2de6dc1d1113e Mon Sep 17 00:00:00 2001 From: Igor Kharakhordin Date: Sun, 15 Dec 2024 12:16:47 +0100 Subject: [PATCH 2/5] Merge adjustments --- .../webview_flutter/webview_flutter_android/CHANGELOG.md | 5 ++++- .../lib/src/android_webview_controller.dart | 6 ------ .../webview_flutter/webview_flutter_android/pubspec.yaml | 2 +- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/packages/webview_flutter/webview_flutter_android/CHANGELOG.md b/packages/webview_flutter/webview_flutter_android/CHANGELOG.md index 8751b8af41f..60a00c8d9de 100644 --- a/packages/webview_flutter/webview_flutter_android/CHANGELOG.md +++ b/packages/webview_flutter/webview_flutter_android/CHANGELOG.md @@ -1,6 +1,9 @@ +## 4.3.0 + +* Adds WebSettings methods: `AndroidWebViewController.setAllowContentAccess`, `AndroidWebViewController.setGeolocationEnabled` and `AndroidWebViewController.setCacheMode`. + ## 4.2.0 -* Adds WebSettings methods: `AndroidWebViewController.setAllowFileAccess`, `AndroidWebViewController.setAllowContentAccess`, `AndroidWebViewController.setGeolocationEnabled` and `AndroidWebViewController.setCacheMode`. * Adds support for configuring file access permissions. See `AndroidWebViewController.setAllowFileAccess`. ## 4.1.0 diff --git a/packages/webview_flutter/webview_flutter_android/lib/src/android_webview_controller.dart b/packages/webview_flutter/webview_flutter_android/lib/src/android_webview_controller.dart index 42681085282..f95e5623b33 100644 --- a/packages/webview_flutter/webview_flutter_android/lib/src/android_webview_controller.dart +++ b/packages/webview_flutter/webview_flutter_android/lib/src/android_webview_controller.dart @@ -601,12 +601,6 @@ class AndroidWebViewController extends PlatformWebViewController { Future setTextZoom(int textZoom) => _webView.settings.setTextZoom(textZoom); - /// Enables or disables file access. - /// - /// The default is false. - Future setAllowFileAccess(bool enabled) => - _webView.settings.setAllowFileAccess(enabled); - /// Enables or disables content URL access. /// /// The default is true. diff --git a/packages/webview_flutter/webview_flutter_android/pubspec.yaml b/packages/webview_flutter/webview_flutter_android/pubspec.yaml index 44f19b2af19..bd248b40f5d 100644 --- a/packages/webview_flutter/webview_flutter_android/pubspec.yaml +++ b/packages/webview_flutter/webview_flutter_android/pubspec.yaml @@ -2,7 +2,7 @@ name: webview_flutter_android description: A Flutter plugin that provides a WebView widget on Android. repository: https://github.com/flutter/packages/tree/main/packages/webview_flutter/webview_flutter_android issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+webview%22 -version: 4.2.0 +version: 4.3.0 environment: sdk: ^3.5.0 From 95673e362d31fe1f3b9c38be6f5f197fc829e6eb Mon Sep 17 00:00:00 2001 From: Igor Kharakhordin Date: Sun, 15 Dec 2024 12:19:21 +0100 Subject: [PATCH 3/5] Regenerate mocks --- ...android_webview_controller_test.mocks.dart | 20 +++++++++---------- ...oid_webview_cookie_manager_test.mocks.dart | 20 +++++++++---------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/packages/webview_flutter/webview_flutter_android/test/android_webview_controller_test.mocks.dart b/packages/webview_flutter/webview_flutter_android/test/android_webview_controller_test.mocks.dart index 68817a47434..c889eff1b90 100644 --- a/packages/webview_flutter/webview_flutter_android/test/android_webview_controller_test.mocks.dart +++ b/packages/webview_flutter/webview_flutter_android/test/android_webview_controller_test.mocks.dart @@ -455,6 +455,16 @@ class MockAndroidWebViewController extends _i1.Mock ), ) as _i3.PlatformWebViewControllerCreationParams); + @override + _i8.Future setAllowFileAccess(bool? allow) => (super.noSuchMethod( + Invocation.method( + #setAllowFileAccess, + [allow], + ), + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); + @override _i8.Future loadFile(String? absoluteFilePath) => (super.noSuchMethod( Invocation.method( @@ -789,16 +799,6 @@ class MockAndroidWebViewController extends _i1.Mock returnValueForMissingStub: _i8.Future.value(), ) as _i8.Future); - @override - _i8.Future setAllowFileAccess(bool? enabled) => (super.noSuchMethod( - Invocation.method( - #setAllowFileAccess, - [enabled], - ), - returnValue: _i8.Future.value(), - returnValueForMissingStub: _i8.Future.value(), - ) as _i8.Future); - @override _i8.Future setAllowContentAccess(bool? enabled) => (super.noSuchMethod( Invocation.method( diff --git a/packages/webview_flutter/webview_flutter_android/test/android_webview_cookie_manager_test.mocks.dart b/packages/webview_flutter/webview_flutter_android/test/android_webview_cookie_manager_test.mocks.dart index 50895d862ec..9340b399fc8 100644 --- a/packages/webview_flutter/webview_flutter_android/test/android_webview_cookie_manager_test.mocks.dart +++ b/packages/webview_flutter/webview_flutter_android/test/android_webview_cookie_manager_test.mocks.dart @@ -178,6 +178,16 @@ class MockAndroidWebViewController extends _i1.Mock ), ) as _i3.PlatformWebViewControllerCreationParams); + @override + _i5.Future setAllowFileAccess(bool? allow) => (super.noSuchMethod( + Invocation.method( + #setAllowFileAccess, + [allow], + ), + returnValue: _i5.Future.value(), + returnValueForMissingStub: _i5.Future.value(), + ) as _i5.Future); + @override _i5.Future loadFile(String? absoluteFilePath) => (super.noSuchMethod( Invocation.method( @@ -494,16 +504,6 @@ class MockAndroidWebViewController extends _i1.Mock returnValueForMissingStub: _i5.Future.value(), ) as _i5.Future); - @override - _i5.Future setAllowFileAccess(bool? enabled) => (super.noSuchMethod( - Invocation.method( - #setAllowFileAccess, - [enabled], - ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); - @override _i5.Future setAllowContentAccess(bool? enabled) => (super.noSuchMethod( Invocation.method( From 48f455e064eaf3dc89eb4f8a9e0090a7771d4799 Mon Sep 17 00:00:00 2001 From: Igor Kharakhordin Date: Wed, 8 Jan 2025 11:05:59 +0100 Subject: [PATCH 4/5] Remove setCacheMode method --- .../webview_flutter_android/CHANGELOG.md | 2 +- .../webviewflutter/AndroidWebkitLibrary.g.kt | 74 ------------------- .../webviewflutter/WebSettingsProxyApi.java | 20 ----- .../lib/src/android_webkit.g.dart | 60 --------------- .../lib/src/android_webview_controller.dart | 9 --- .../pigeons/android_webkit.dart | 29 -------- .../test/android_webview_controller_test.dart | 18 ----- ...android_webview_controller_test.mocks.dart | 20 ----- ...oid_webview_cookie_manager_test.mocks.dart | 10 --- .../webview_android_widget_test.mocks.dart | 10 --- 10 files changed, 1 insertion(+), 251 deletions(-) diff --git a/packages/webview_flutter/webview_flutter_android/CHANGELOG.md b/packages/webview_flutter/webview_flutter_android/CHANGELOG.md index 60a00c8d9de..36ef6047b5d 100644 --- a/packages/webview_flutter/webview_flutter_android/CHANGELOG.md +++ b/packages/webview_flutter/webview_flutter_android/CHANGELOG.md @@ -1,6 +1,6 @@ ## 4.3.0 -* Adds WebSettings methods: `AndroidWebViewController.setAllowContentAccess`, `AndroidWebViewController.setGeolocationEnabled` and `AndroidWebViewController.setCacheMode`. +* Adds WebSettings methods: `AndroidWebViewController.setAllowContentAccess` and `AndroidWebViewController.setGeolocationEnabled`. ## 4.2.0 diff --git a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/AndroidWebkitLibrary.g.kt b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/AndroidWebkitLibrary.g.kt index a1c1ca9864a..92cbf74aaa1 100644 --- a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/AndroidWebkitLibrary.g.kt +++ b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/AndroidWebkitLibrary.g.kt @@ -571,7 +571,6 @@ private class AndroidWebkitLibraryPigeonProxyApiBaseCodec( value is String || value is FileChooserMode || value is ConsoleMessageLevel || - value is CacheMode || value == null) { super.writeValue(stream, value) return @@ -727,45 +726,6 @@ enum class ConsoleMessageLevel(val raw: Int) { } } -/** - * Describes the way the cache is used. - * - * See https://developer.android.com/reference/android/webkit/WebSettings#setCacheMode(int). - */ -enum class CacheMode(val raw: Int) { - /** - * Normal cache usage mode. - * - * See https://developer.android.com/reference/android/webkit/WebSettings#LOAD_DEFAULT - */ - LOAD_DEFAULT(0), - /** - * Use cached resources when they are available, even if they have expired. Otherwise load - * resources from the network. - * - * See https://developer.android.com/reference/android/webkit/WebSettings#LOAD_CACHE_ELSE_NETWORK - */ - LOAD_CACHE_ELSE_NETWORK(1), - /** - * Don't use the cache, load from the network. - * - * See https://developer.android.com/reference/android/webkit/WebSettings#LOAD_CACHE_ELSE_NETWORK - */ - LOAD_NO_CACHE(2), - /** - * Don't use the network, load from the cache. - * - * See https://developer.android.com/reference/android/webkit/WebSettings#LOAD_CACHE_ONLY - */ - LOAD_CACHE_ONLY(3); - - companion object { - fun ofRaw(raw: Int): CacheMode? { - return values().firstOrNull { it.raw == raw } - } - } -} - private open class AndroidWebkitLibraryPigeonCodec : StandardMessageCodec() { override fun readValueOfType(type: Byte, buffer: ByteBuffer): Any? { return when (type) { @@ -775,9 +735,6 @@ private open class AndroidWebkitLibraryPigeonCodec : StandardMessageCodec() { 130.toByte() -> { return (readValue(buffer) as Long?)?.let { ConsoleMessageLevel.ofRaw(it.toInt()) } } - 131.toByte() -> { - return (readValue(buffer) as Long?)?.let { CacheMode.ofRaw(it.toInt()) } - } else -> super.readValueOfType(type, buffer) } } @@ -792,10 +749,6 @@ private open class AndroidWebkitLibraryPigeonCodec : StandardMessageCodec() { stream.write(130) writeValue(stream, value.raw) } - is CacheMode -> { - stream.write(131) - writeValue(stream, value.raw) - } else -> super.writeValue(stream, value) } } @@ -2157,9 +2110,6 @@ abstract class PigeonApiWebSettings( /** Sets whether Geolocation is enabled within WebView. */ abstract fun setGeolocationEnabled(pigeon_instance: android.webkit.WebSettings, enabled: Boolean) - /** Overrides the way the cache is used. */ - abstract fun setCacheMode(pigeon_instance: android.webkit.WebSettings, mode: CacheMode) - /** Sets the text zoom of the page in percent. */ abstract fun setTextZoom(pigeon_instance: android.webkit.WebSettings, textZoom: Long) @@ -2506,30 +2456,6 @@ abstract class PigeonApiWebSettings( channel.setMessageHandler(null) } } - run { - val channel = - BasicMessageChannel( - binaryMessenger, - "dev.flutter.pigeon.webview_flutter_android.WebSettings.setCacheMode", - codec) - if (api != null) { - channel.setMessageHandler { message, reply -> - val args = message as List - val pigeon_instanceArg = args[0] as android.webkit.WebSettings - val modeArg = args[1] as CacheMode - val wrapped: List = - try { - api.setCacheMode(pigeon_instanceArg, modeArg) - listOf(null) - } catch (exception: Throwable) { - wrapError(exception) - } - reply.reply(wrapped) - } - } else { - channel.setMessageHandler(null) - } - } run { val channel = BasicMessageChannel( diff --git a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/WebSettingsProxyApi.java b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/WebSettingsProxyApi.java index bf167907b92..43966249703 100644 --- a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/WebSettingsProxyApi.java +++ b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/WebSettingsProxyApi.java @@ -18,21 +18,6 @@ public WebSettingsProxyApi(@NonNull ProxyApiRegistrar pigeonRegistrar) { super(pigeonRegistrar); } - private static int mapCacheMode(CacheMode pigeonMode) { - switch (pigeonMode) { - case LOAD_DEFAULT: - return WebSettings.LOAD_DEFAULT; - case LOAD_CACHE_ELSE_NETWORK: - return WebSettings.LOAD_CACHE_ELSE_NETWORK; - case LOAD_NO_CACHE: - return WebSettings.LOAD_NO_CACHE; - case LOAD_CACHE_ONLY: - return WebSettings.LOAD_CACHE_ONLY; - } - - return WebSettings.LOAD_DEFAULT; - } - @Override public void setDomStorageEnabled(@NonNull WebSettings pigeon_instance, boolean flag) { pigeon_instance.setDomStorageEnabled(flag); @@ -106,11 +91,6 @@ public void setGeolocationEnabled(@NonNull WebSettings pigeon_instance, boolean pigeon_instance.setGeolocationEnabled(enabled); } - @Override - public void setCacheMode(@NonNull WebSettings pigeon_instance, @NonNull CacheMode mode) { - pigeon_instance.setCacheMode(mapCacheMode(mode)); - } - @Override public void setTextZoom(@NonNull WebSettings pigeon_instance, long textZoom) { pigeon_instance.setTextZoom((int) textZoom); diff --git a/packages/webview_flutter/webview_flutter_android/lib/src/android_webkit.g.dart b/packages/webview_flutter/webview_flutter_android/lib/src/android_webkit.g.dart index e7dbd7a0982..3ae3a187867 100644 --- a/packages/webview_flutter/webview_flutter_android/lib/src/android_webkit.g.dart +++ b/packages/webview_flutter/webview_flutter_android/lib/src/android_webkit.g.dart @@ -503,32 +503,6 @@ enum ConsoleMessageLevel { unknown, } -/// Describes the way the cache is used. -/// -/// See https://developer.android.com/reference/android/webkit/WebSettings#setCacheMode(int). -enum CacheMode { - /// Normal cache usage mode. - /// - /// See https://developer.android.com/reference/android/webkit/WebSettings#LOAD_DEFAULT - loadDefault, - - /// Use cached resources when they are available, even if they have expired. - /// Otherwise load resources from the network. - /// - /// See https://developer.android.com/reference/android/webkit/WebSettings#LOAD_CACHE_ELSE_NETWORK - loadCacheElseNetwork, - - /// Don't use the cache, load from the network. - /// - /// See https://developer.android.com/reference/android/webkit/WebSettings#LOAD_CACHE_ELSE_NETWORK - loadNoCache, - - /// Don't use the network, load from the cache. - /// - /// See https://developer.android.com/reference/android/webkit/WebSettings#LOAD_CACHE_ONLY - loadCacheOnly, -} - class _PigeonCodec extends StandardMessageCodec { const _PigeonCodec(); @override @@ -542,9 +516,6 @@ class _PigeonCodec extends StandardMessageCodec { } else if (value is ConsoleMessageLevel) { buffer.putUint8(130); writeValue(buffer, value.index); - } else if (value is CacheMode) { - buffer.putUint8(131); - writeValue(buffer, value.index); } else { super.writeValue(buffer, value); } @@ -559,9 +530,6 @@ class _PigeonCodec extends StandardMessageCodec { case 130: final int? value = readValue(buffer) as int?; return value == null ? null : ConsoleMessageLevel.values[value]; - case 131: - final int? value = readValue(buffer) as int?; - return value == null ? null : CacheMode.values[value]; default: return super.readValueOfType(type, buffer); } @@ -2703,34 +2671,6 @@ class WebSettings extends PigeonInternalProxyApiBaseClass { } } - /// Overrides the way the cache is used. - Future setCacheMode(CacheMode mode) async { - final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = - _pigeonVar_codecWebSettings; - final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; - const String pigeonVar_channelName = - 'dev.flutter.pigeon.webview_flutter_android.WebSettings.setCacheMode'; - final BasicMessageChannel pigeonVar_channel = - BasicMessageChannel( - pigeonVar_channelName, - pigeonChannelCodec, - binaryMessenger: pigeonVar_binaryMessenger, - ); - final List? pigeonVar_replyList = - await pigeonVar_channel.send([this, mode]) as List?; - if (pigeonVar_replyList == null) { - throw _createConnectionError(pigeonVar_channelName); - } else if (pigeonVar_replyList.length > 1) { - throw PlatformException( - code: pigeonVar_replyList[0]! as String, - message: pigeonVar_replyList[1] as String?, - details: pigeonVar_replyList[2], - ); - } else { - return; - } - } - /// Sets the text zoom of the page in percent. Future setTextZoom(int textZoom) async { final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = diff --git a/packages/webview_flutter/webview_flutter_android/lib/src/android_webview_controller.dart b/packages/webview_flutter/webview_flutter_android/lib/src/android_webview_controller.dart index f95e5623b33..7dc1c797376 100644 --- a/packages/webview_flutter/webview_flutter_android/lib/src/android_webview_controller.dart +++ b/packages/webview_flutter/webview_flutter_android/lib/src/android_webview_controller.dart @@ -17,8 +17,6 @@ import 'android_webkit_constants.dart'; import 'platform_views_service_proxy.dart'; import 'weak_reference_utils.dart'; -export 'android_webkit.g.dart' show CacheMode; - /// Object specifying creation parameters for creating a [AndroidWebViewController]. /// /// When adding additional fields make sure they can be null or have a default @@ -613,13 +611,6 @@ class AndroidWebViewController extends PlatformWebViewController { Future setGeolocationEnabled(bool enabled) => _webView.settings.setGeolocationEnabled(enabled); - /// Allows the client to override the way the cache is used - /// by specifying one of [android_webview.CacheMode] values. - /// - /// The default is [android_webview.CacheMode.loadDefault]. - Future setCacheMode(android_webview.CacheMode mode) => - _webView.settings.setCacheMode(mode); - /// Sets the callback that is invoked when the client should show a file /// selector. Future setOnShowFileSelector( diff --git a/packages/webview_flutter/webview_flutter_android/pigeons/android_webkit.dart b/packages/webview_flutter/webview_flutter_android/pigeons/android_webkit.dart index 2f154c81f37..8d3a4dbed5c 100644 --- a/packages/webview_flutter/webview_flutter_android/pigeons/android_webkit.dart +++ b/packages/webview_flutter/webview_flutter_android/pigeons/android_webkit.dart @@ -80,32 +80,6 @@ enum ConsoleMessageLevel { unknown, } -/// Describes the way the cache is used. -/// -/// See https://developer.android.com/reference/android/webkit/WebSettings#setCacheMode(int). -enum CacheMode { - /// Normal cache usage mode. - /// - /// See https://developer.android.com/reference/android/webkit/WebSettings#LOAD_DEFAULT - loadDefault, - - /// Use cached resources when they are available, even if they have expired. - /// Otherwise load resources from the network. - /// - /// See https://developer.android.com/reference/android/webkit/WebSettings#LOAD_CACHE_ELSE_NETWORK - loadCacheElseNetwork, - - /// Don't use the cache, load from the network. - /// - /// See https://developer.android.com/reference/android/webkit/WebSettings#LOAD_CACHE_ELSE_NETWORK - loadNoCache, - - /// Don't use the network, load from the cache. - /// - /// See https://developer.android.com/reference/android/webkit/WebSettings#LOAD_CACHE_ONLY - loadCacheOnly; -} - /// Encompasses parameters to the `WebViewClient.shouldInterceptRequest` method. /// /// See https://developer.android.com/reference/android/webkit/WebResourceRequest. @@ -386,9 +360,6 @@ abstract class WebSettings { /// Sets whether Geolocation is enabled within WebView. void setGeolocationEnabled(bool enabled); - /// Overrides the way the cache is used. - void setCacheMode(CacheMode mode); - /// Sets the text zoom of the page in percent. void setTextZoom(int textZoom); diff --git a/packages/webview_flutter/webview_flutter_android/test/android_webview_controller_test.dart b/packages/webview_flutter/webview_flutter_android/test/android_webview_controller_test.dart index aa4e09358aa..6762d1f0169 100644 --- a/packages/webview_flutter/webview_flutter_android/test/android_webview_controller_test.dart +++ b/packages/webview_flutter/webview_flutter_android/test/android_webview_controller_test.dart @@ -1558,24 +1558,6 @@ void main() { verify(mockSettings.setGeolocationEnabled(false)).called(1); }); - test('setCacheMode', () async { - final MockWebView mockWebView = MockWebView(); - final MockWebSettings mockSettings = MockWebSettings(); - final AndroidWebViewController controller = createControllerWithMocks( - mockWebView: mockWebView, - mockSettings: mockSettings, - ); - - clearInteractions(mockWebView); - - const android_webview.CacheMode value = - android_webview.CacheMode.loadCacheElseNetwork; - await controller.setCacheMode(value); - - verify(mockWebView.settings).called(1); - verify(mockSettings.setCacheMode(value)).called(1); - }); - test('setTextZoom', () async { final MockWebView mockWebView = MockWebView(); final MockWebSettings mockSettings = MockWebSettings(); diff --git a/packages/webview_flutter/webview_flutter_android/test/android_webview_controller_test.mocks.dart b/packages/webview_flutter/webview_flutter_android/test/android_webview_controller_test.mocks.dart index c889eff1b90..2e13f747bd6 100644 --- a/packages/webview_flutter/webview_flutter_android/test/android_webview_controller_test.mocks.dart +++ b/packages/webview_flutter/webview_flutter_android/test/android_webview_controller_test.mocks.dart @@ -819,16 +819,6 @@ class MockAndroidWebViewController extends _i1.Mock returnValueForMissingStub: _i8.Future.value(), ) as _i8.Future); - @override - _i8.Future setCacheMode(_i2.CacheMode? mode) => (super.noSuchMethod( - Invocation.method( - #setCacheMode, - [mode], - ), - returnValue: _i8.Future.value(), - returnValueForMissingStub: _i8.Future.value(), - ) as _i8.Future); - @override _i8.Future setOnShowFileSelector( _i8.Future> Function(_i7.FileSelectorParams)? @@ -2698,16 +2688,6 @@ class MockWebSettings extends _i1.Mock implements _i2.WebSettings { returnValueForMissingStub: _i8.Future.value(), ) as _i8.Future); - @override - _i8.Future setCacheMode(_i2.CacheMode? mode) => (super.noSuchMethod( - Invocation.method( - #setCacheMode, - [mode], - ), - returnValue: _i8.Future.value(), - returnValueForMissingStub: _i8.Future.value(), - ) as _i8.Future); - @override _i8.Future setTextZoom(int? textZoom) => (super.noSuchMethod( Invocation.method( diff --git a/packages/webview_flutter/webview_flutter_android/test/android_webview_cookie_manager_test.mocks.dart b/packages/webview_flutter/webview_flutter_android/test/android_webview_cookie_manager_test.mocks.dart index 9340b399fc8..9a80b3c10f1 100644 --- a/packages/webview_flutter/webview_flutter_android/test/android_webview_cookie_manager_test.mocks.dart +++ b/packages/webview_flutter/webview_flutter_android/test/android_webview_cookie_manager_test.mocks.dart @@ -524,16 +524,6 @@ class MockAndroidWebViewController extends _i1.Mock returnValueForMissingStub: _i5.Future.value(), ) as _i5.Future); - @override - _i5.Future setCacheMode(_i2.CacheMode? mode) => (super.noSuchMethod( - Invocation.method( - #setCacheMode, - [mode], - ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); - @override _i5.Future setOnShowFileSelector( _i5.Future> Function(_i6.FileSelectorParams)? diff --git a/packages/webview_flutter/webview_flutter_android/test/legacy/webview_android_widget_test.mocks.dart b/packages/webview_flutter/webview_flutter_android/test/legacy/webview_android_widget_test.mocks.dart index 8d4fe7742b3..ff695040404 100644 --- a/packages/webview_flutter/webview_flutter_android/test/legacy/webview_android_widget_test.mocks.dart +++ b/packages/webview_flutter/webview_flutter_android/test/legacy/webview_android_widget_test.mocks.dart @@ -375,16 +375,6 @@ class MockWebSettings extends _i1.Mock implements _i2.WebSettings { returnValueForMissingStub: _i4.Future.value(), ) as _i4.Future); - @override - _i4.Future setCacheMode(_i2.CacheMode? mode) => (super.noSuchMethod( - Invocation.method( - #setCacheMode, - [mode], - ), - returnValue: _i4.Future.value(), - returnValueForMissingStub: _i4.Future.value(), - ) as _i4.Future); - @override _i4.Future setTextZoom(int? textZoom) => (super.noSuchMethod( Invocation.method( From 85d1a8a6c321a1b748f06a9ec9c103d5356edc83 Mon Sep 17 00:00:00 2001 From: Igor Kharakhordin Date: Thu, 9 Jan 2025 09:25:48 +0100 Subject: [PATCH 5/5] Update CHANGELOG.md Co-authored-by: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> --- packages/webview_flutter/webview_flutter_android/CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/webview_flutter/webview_flutter_android/CHANGELOG.md b/packages/webview_flutter/webview_flutter_android/CHANGELOG.md index 36ef6047b5d..539c54c8a9f 100644 --- a/packages/webview_flutter/webview_flutter_android/CHANGELOG.md +++ b/packages/webview_flutter/webview_flutter_android/CHANGELOG.md @@ -1,6 +1,8 @@ ## 4.3.0 -* Adds WebSettings methods: `AndroidWebViewController.setAllowContentAccess` and `AndroidWebViewController.setGeolocationEnabled`. +* Adds support for disabling content URL access within WebView and disabling the Geolocation API. + See `AndroidWebViewController.setAllowContentAccess` and + `AndroidWebViewController.setGeolocationEnabled`. ## 4.2.0