diff --git a/CHANGELOG.md b/CHANGELOG.md index 470a93c5..8e8da200 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,10 +16,10 @@ ### BREAKING CHANGES -- On Android, the `InAppWebView` widget uses hybrid composition by default (`useHybridComposition: true`) +- On Android, the `InAppWebView` widget uses hybrid composition by default (`useHybridComposition: true`) - All properties of `GeolocationPermissionShowPromptResponse` cannot be `null` - Removed `URLProtectionSpace.iosIsProxy` property -- `historyUrl` and `baseUrl` of `InAppWebViewInitialData` can be `null` +- `historyUrl` and `baseUrl` of `InAppWebViewInitialData` can be `null` ## 5.4.4+2 @@ -90,7 +90,7 @@ ## 5.4.1 -- Managed iOS native `detachFromEngine` flutter plugin event and updated `dispose` methods +- Managed iOS native `detachFromEngine` flutter plugin event and updated `dispose` methods - Updated Android native `HeadlessInAppWebViewManager.dispose` and `HeadlessInAppWebView.dispose` methods ## 5.4.0+3 @@ -345,7 +345,7 @@ - Renamed `toolbarTop` InAppBrowser cross-platform option to `hideToolbarTop` - Renamed `toolbarBottom` InAppBrowser ios-specific option to `hideToolbarBottom` - Removed `debuggingEnabled` WebView option; on Android you should use now the `AndroidInAppWebViewController.setWebContentsDebuggingEnabled(bool debuggingEnabled)` static method; on iOS, debugging is always enabled -- Removed `androidOnRequestFocus` event because it is never called +- Removed `androidOnRequestFocus` event because it is never called - Removed `initialHeaders` WebView attribute. Use `URLRequest.headers` attribute - Removed `headers` argument from `loadFile` WebView method - Removed `headers` argument from `openFile` InAppBrowser method @@ -361,11 +361,11 @@ - Changed return type of `getOriginalUrl` Android-specific WebView method to `Uri` - Changed return type of `getSafeBrowsingPrivacyPolicyUrl` Android-specific WebView method to `Uri` - Changed type of `url` argument of `onLoadStart`, `onLoadStop`, `onLoadError`, `onLoadHttpError`, `onLoadResourceCustomScheme`, `onUpdateVisitedHistory`, `onPrint`, `onPageCommitVisible`, `androidOnSafeBrowsingHit`, `androidOnRenderProcessUnresponsive`, `androidOnRenderProcessResponsive`, `androidOnFormResubmission`, `androidOnReceivedTouchIconUrl` WebView events to `Uri` -- Changed type of `baseUrl` and `androidHistoryUrl` arguments of `loadData` WebView method and `openData` InAppBrowser method +- Changed type of `baseUrl` and `androidHistoryUrl` arguments of `loadData` WebView method and `openData` InAppBrowser method - Changed `openUrl` InAppBrowser method to `openUrlRequest` - Changed type of `url` argument of `openWithSystemBrowser` InAppBrowser method to `Uri` -- Changed all InAppBrowser color options type from `String` to `Color` -- Changed all ChromeSafariBrowser color options type from `String` to `Color` +- Changed all InAppBrowser color options type from `String` to `Color` +- Changed all ChromeSafariBrowser color options type from `String` to `Color` - Updated attributes of `ShouldOverrideUrlLoadingRequest`, `ServerTrustChallenge` and `ClientCertChallenge` classes - Changed type of `url` attribute to `Uri` for `JsAlertRequest`, `JsAlertConfirm`, `JsPromptRequest` classes diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/webview/WebViewChannelDelegate.java b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/webview/WebViewChannelDelegate.java index 66687315..3667b54c 100644 --- a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/webview/WebViewChannelDelegate.java +++ b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/webview/WebViewChannelDelegate.java @@ -1182,7 +1182,7 @@ public class WebViewChannelDelegate extends ChannelDelegateImpl { @Nullable @Override public Integer decodeResult(@Nullable Object obj) { - return obj != null ? (Integer) ((Map) obj).get("action") : null; + return obj instanceof Integer ? (Integer) obj : null; } } @@ -1201,7 +1201,7 @@ public class WebViewChannelDelegate extends ChannelDelegateImpl { @Nullable @Override public Integer decodeResult(@Nullable Object obj) { - return obj != null ? (Integer) ((Map) obj).get("action") : null; + return obj instanceof Integer ? (Integer) obj : null; } } diff --git a/dev_packages/flutter_inappwebview_internal_annotations/lib/flutter_inappwebview_internal_annotations.dart b/dev_packages/flutter_inappwebview_internal_annotations/lib/flutter_inappwebview_internal_annotations.dart index a605dda0..841cf81c 100644 --- a/dev_packages/flutter_inappwebview_internal_annotations/lib/flutter_inappwebview_internal_annotations.dart +++ b/dev_packages/flutter_inappwebview_internal_annotations/lib/flutter_inappwebview_internal_annotations.dart @@ -3,6 +3,8 @@ library flutter_inappwebview_internal_annotations; export 'src/exchangeable_object.dart'; export 'src/exchangeable_object_constructor.dart'; export 'src/exchangeable_object_property.dart'; +export 'src/exchangeable_object_method.dart'; export 'src/exchangeable_enum.dart'; +export 'src/exchangeable_enum_custom_value.dart'; export 'src/supported_platforms.dart'; export 'src/enum_supported_platforms.dart'; \ No newline at end of file diff --git a/dev_packages/flutter_inappwebview_internal_annotations/lib/src/exchangeable_enum_custom_value.dart b/dev_packages/flutter_inappwebview_internal_annotations/lib/src/exchangeable_enum_custom_value.dart new file mode 100644 index 00000000..309efa39 --- /dev/null +++ b/dev_packages/flutter_inappwebview_internal_annotations/lib/src/exchangeable_enum_custom_value.dart @@ -0,0 +1,3 @@ +class ExchangeableEnumCustomValue { + const ExchangeableEnumCustomValue(); +} diff --git a/dev_packages/flutter_inappwebview_internal_annotations/lib/src/exchangeable_object_method.dart b/dev_packages/flutter_inappwebview_internal_annotations/lib/src/exchangeable_object_method.dart new file mode 100644 index 00000000..d922ca6b --- /dev/null +++ b/dev_packages/flutter_inappwebview_internal_annotations/lib/src/exchangeable_object_method.dart @@ -0,0 +1,9 @@ +class ExchangeableObjectMethod { + final bool ignore; + final bool toMapMergeWith; + + const ExchangeableObjectMethod({ + this.ignore = false, + this.toMapMergeWith = false + }); +} diff --git a/dev_packages/flutter_inappwebview_internal_annotations/pubspec.lock b/dev_packages/flutter_inappwebview_internal_annotations/pubspec.lock index d1a8e316..6f6fc33f 100644 --- a/dev_packages/flutter_inappwebview_internal_annotations/pubspec.lock +++ b/dev_packages/flutter_inappwebview_internal_annotations/pubspec.lock @@ -1,20 +1,27 @@ # Generated by pub # See https://dart.dev/tools/pub/glossary#lockfile packages: + _fe_analyzer_shared: + dependency: transitive + description: + name: _fe_analyzer_shared + url: "https://pub.dartlang.org" + source: hosted + version: "49.0.0" analyzer: dependency: transitive description: name: analyzer url: "https://pub.dartlang.org" source: hosted - version: "0.33.6+1" + version: "5.1.0" args: dependency: transitive description: name: args url: "https://pub.dartlang.org" source: hosted - version: "1.6.0" + version: "2.3.1" async: dependency: transitive description: @@ -28,21 +35,7 @@ packages: name: boolean_selector url: "https://pub.dartlang.org" source: hosted - version: "1.0.5" - charcode: - dependency: transitive - description: - name: charcode - url: "https://pub.dartlang.org" - source: hosted - version: "1.3.1" - clock: - dependency: transitive - description: - name: clock - url: "https://pub.dartlang.org" - source: hosted - version: "1.1.0" + version: "2.1.0" collection: dependency: transitive description: @@ -56,84 +49,63 @@ packages: name: convert url: "https://pub.dartlang.org" source: hosted - version: "2.1.1" + version: "3.0.2" + coverage: + dependency: transitive + description: + name: coverage + url: "https://pub.dartlang.org" + source: hosted + version: "1.6.1" crypto: dependency: transitive description: name: crypto url: "https://pub.dartlang.org" source: hosted - version: "2.1.5" - csslib: - dependency: transitive - description: - name: csslib - url: "https://pub.dartlang.org" - source: hosted - version: "0.17.1" + version: "3.0.2" file: dependency: transitive description: name: file url: "https://pub.dartlang.org" source: hosted - version: "5.2.1" - front_end: + version: "6.1.4" + frontend_server_client: dependency: transitive description: - name: front_end + name: frontend_server_client url: "https://pub.dartlang.org" source: hosted - version: "0.1.6+9" + version: "3.0.0" glob: dependency: transitive description: name: glob url: "https://pub.dartlang.org" source: hosted - version: "1.2.0" - html: - dependency: transitive - description: - name: html - url: "https://pub.dartlang.org" - source: hosted - version: "0.15.0" - http: - dependency: transitive - description: - name: http - url: "https://pub.dartlang.org" - source: hosted - version: "0.12.2" + version: "2.1.0" http_multi_server: dependency: transitive description: name: http_multi_server url: "https://pub.dartlang.org" source: hosted - version: "2.2.0" + version: "3.2.1" http_parser: dependency: transitive description: name: http_parser url: "https://pub.dartlang.org" source: hosted - version: "3.1.4" - intl: - dependency: transitive - description: - name: intl - url: "https://pub.dartlang.org" - source: hosted - version: "0.17.0" + version: "4.0.1" io: dependency: transitive description: name: io url: "https://pub.dartlang.org" source: hosted - version: "0.3.5" + version: "1.0.3" js: dependency: transitive description: @@ -141,34 +113,20 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.6.4" - json_rpc_2: - dependency: transitive - description: - name: json_rpc_2 - url: "https://pub.dartlang.org" - source: hosted - version: "2.2.2" - kernel: - dependency: transitive - description: - name: kernel - url: "https://pub.dartlang.org" - source: hosted - version: "0.3.6+9" logging: dependency: transitive description: name: logging url: "https://pub.dartlang.org" source: hosted - version: "0.11.4" + version: "1.0.2" matcher: dependency: transitive description: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.3+1" + version: "0.12.12" meta: dependency: transitive description: @@ -183,48 +141,20 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.0.0" - multi_server_socket: - dependency: transitive - description: - name: multi_server_socket - url: "https://pub.dartlang.org" - source: hosted - version: "1.0.2" - node_interop: - dependency: transitive - description: - name: node_interop - url: "https://pub.dartlang.org" - source: hosted - version: "1.2.1" - node_io: - dependency: transitive - description: - name: node_io - url: "https://pub.dartlang.org" - source: hosted - version: "1.2.0" node_preamble: dependency: transitive description: name: node_preamble url: "https://pub.dartlang.org" source: hosted - version: "1.4.13" + version: "2.0.1" package_config: dependency: transitive description: name: package_config url: "https://pub.dartlang.org" source: hosted - version: "1.9.3" - package_resolver: - dependency: transitive - description: - name: package_resolver - url: "https://pub.dartlang.org" - source: hosted - version: "1.0.10" + version: "2.1.0" path: dependency: transitive description: @@ -232,20 +162,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.8.1" - pedantic: - dependency: transitive - description: - name: pedantic - url: "https://pub.dartlang.org" - source: hosted - version: "1.11.1" - plugin: - dependency: transitive - description: - name: plugin - url: "https://pub.dartlang.org" - source: hosted - version: "0.2.0+3" pool: dependency: transitive description: @@ -259,42 +175,42 @@ packages: name: pub_semver url: "https://pub.dartlang.org" source: hosted - version: "1.4.4" + version: "2.1.1" shelf: dependency: transitive description: name: shelf url: "https://pub.dartlang.org" source: hosted - version: "0.7.9" + version: "1.4.0" shelf_packages_handler: dependency: transitive description: name: shelf_packages_handler url: "https://pub.dartlang.org" source: hosted - version: "1.0.4" + version: "3.0.1" shelf_static: dependency: transitive description: name: shelf_static url: "https://pub.dartlang.org" source: hosted - version: "0.2.9+2" + version: "1.1.1" shelf_web_socket: dependency: transitive description: name: shelf_web_socket url: "https://pub.dartlang.org" source: hosted - version: "0.2.4+1" + version: "1.0.2" source_map_stack_trace: dependency: transitive description: name: source_map_stack_trace url: "https://pub.dartlang.org" source: hosted - version: "1.1.5" + version: "2.1.0" source_maps: dependency: transitive description: @@ -322,7 +238,7 @@ packages: name: stream_channel url: "https://pub.dartlang.org" source: hosted - version: "1.7.0" + version: "2.1.1" string_scanner: dependency: transitive description: @@ -343,7 +259,21 @@ packages: name: test url: "https://pub.dartlang.org" source: hosted - version: "1.3.4" + version: "1.21.6" + test_api: + dependency: transitive + description: + name: test_api + url: "https://pub.dartlang.org" + source: hosted + version: "0.4.14" + test_core: + dependency: transitive + description: + name: test_core + url: "https://pub.dartlang.org" + source: hosted + version: "0.4.18" typed_data: dependency: transitive description: @@ -351,26 +281,33 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.3.0" - vm_service_client: + vm_service: dependency: transitive description: - name: vm_service_client + name: vm_service url: "https://pub.dartlang.org" source: hosted - version: "0.2.6+3" + version: "9.4.0" watcher: dependency: transitive description: name: watcher url: "https://pub.dartlang.org" source: hosted - version: "0.9.7+15" + version: "1.0.1" web_socket_channel: dependency: transitive description: name: web_socket_channel url: "https://pub.dartlang.org" source: hosted + version: "2.2.0" + webkit_inspection_protocol: + dependency: transitive + description: + name: webkit_inspection_protocol + url: "https://pub.dartlang.org" + source: hosted version: "1.2.0" yaml: dependency: transitive @@ -378,6 +315,6 @@ packages: name: yaml url: "https://pub.dartlang.org" source: hosted - version: "2.2.1" + version: "3.1.1" sdks: - dart: ">=2.16.0-100.0.dev <3.0.0" + dart: ">=2.18.0 <3.0.0" diff --git a/dev_packages/flutter_inappwebview_internal_annotations/pubspec.yaml b/dev_packages/flutter_inappwebview_internal_annotations/pubspec.yaml index 8ddd6cfc..1da06c6d 100755 --- a/dev_packages/flutter_inappwebview_internal_annotations/pubspec.yaml +++ b/dev_packages/flutter_inappwebview_internal_annotations/pubspec.yaml @@ -7,4 +7,4 @@ environment: sdk: ">=2.14.0 <3.0.0" dev_dependencies: - test: 1.3.4 \ No newline at end of file + test: ^1.21.6 \ No newline at end of file diff --git a/dev_packages/generators/lib/src/exchangeable_enum_generator.dart b/dev_packages/generators/lib/src/exchangeable_enum_generator.dart index 5fdc5af3..70724983 100644 --- a/dev_packages/generators/lib/src/exchangeable_enum_generator.dart +++ b/dev_packages/generators/lib/src/exchangeable_enum_generator.dart @@ -11,6 +11,8 @@ import 'util.dart'; final _coreCheckerEnumSupportedPlatforms = const TypeChecker.fromRuntime(EnumSupportedPlatforms); final _coreCheckerDeprecated = const TypeChecker.fromRuntime(Deprecated); +final _coreCheckerEnumCustomValue = + const TypeChecker.fromRuntime(ExchangeableEnumCustomValue); class ExchangeableEnumGenerator extends GeneratorForAnnotation { @@ -21,25 +23,25 @@ class ExchangeableEnumGenerator // Visits all the children of element in no particular order. element.visitChildren(visitor); - final className = visitor.constructor.returnType.element.name; + final className = visitor.constructor.returnType.element2.name; // remove "_" to generate the correct class name final extClassName = className.replaceFirst("_", ""); final classBuffer = StringBuffer(); final classDocs = - visitor.constructor.returnType.element.documentationComment; + visitor.constructor.returnType.element2.documentationComment; if (classDocs != null) { classBuffer.writeln(classDocs); } final classSupportedDocs = Util.getSupportedDocs( _coreCheckerEnumSupportedPlatforms, - visitor.constructor.returnType.element); + visitor.constructor.returnType.element2); if (classSupportedDocs != null) { classBuffer.writeln(classSupportedDocs); } - if (visitor.constructor.returnType.element.hasDeprecated) { + if (visitor.constructor.returnType.element2.hasDeprecated) { classBuffer.writeln( - "@Deprecated('${_coreCheckerDeprecated.firstAnnotationOfExact(visitor.constructor.returnType.element)?.getField("message")?.toStringValue()}')"); + "@Deprecated('${_coreCheckerDeprecated.firstAnnotationOfExact(visitor.constructor.returnType.element2)?.getField("message")?.toStringValue()}')"); } classBuffer.writeln('class $extClassName {'); @@ -66,6 +68,38 @@ class ExchangeableEnumGenerator if (fieldName == "_value" || fieldName == "_nativeValue") { continue; } + final isEnumCustomValue = _coreCheckerEnumCustomValue + .firstAnnotationOf(fieldElement) != null; + if (isEnumCustomValue) { + ParsedLibraryResult parsed = fieldElement.session + ?.getParsedLibraryByElement(fieldElement.library) + as ParsedLibraryResult; + final fieldBody = parsed + .getElementDeclaration(fieldElement) + ?.node + .toString() + .replaceAll(className, extClassName); + if (fieldBody != null) { + final docs = fieldElement.documentationComment; + if (docs != null) { + classBuffer.writeln(docs); + } + if (fieldElement.isStatic) { + classBuffer.write("static "); + } + if (fieldElement.isLate) { + classBuffer.write("late "); + } + if (fieldElement.isFinal) { + classBuffer.write("final "); + } + if (fieldElement.isConst) { + classBuffer.write("const "); + } + classBuffer.writeln("$fieldBody;"); + } + continue; + } final docs = fieldElement.documentationComment; if (docs != null) { classBuffer.writeln(docs); @@ -145,14 +179,17 @@ class ExchangeableEnumGenerator for (final entry in visitor.fields.entries) { final fieldName = entry.key; final fieldElement = entry.value; - if (!fieldElement.isPrivate && fieldElement.isStatic) { + final isEnumCustomValue = _coreCheckerEnumCustomValue + .firstAnnotationOf(fieldElement) != null; + if (!fieldElement.isPrivate && fieldElement.isStatic && !isEnumCustomValue) { classBuffer.writeln('$extClassName.$fieldName,'); } } classBuffer.writeln('].toSet();'); } - if (annotation.read("fromValueMethod").boolValue && !visitor.methods.containsKey("fromValue")) { + if (annotation.read("fromValueMethod").boolValue && (!visitor.methods.containsKey("fromValue") || + Util.methodHasIgnore(visitor.methods['fromNativeValue']!))) { final hasBitwiseOrOperator = annotation.read("bitwiseOrOperator").boolValue; classBuffer.writeln(""" @@ -171,7 +208,8 @@ class ExchangeableEnumGenerator """); } - if (annotation.read("fromNativeValueMethod").boolValue && !visitor.methods.containsKey("fromNativeValue")) { + if (annotation.read("fromNativeValueMethod").boolValue && (!visitor.methods.containsKey("fromNativeValue") || + Util.methodHasIgnore(visitor.methods['fromNativeValue']!))) { final hasBitwiseOrOperator = annotation.read("bitwiseOrOperator").boolValue; classBuffer.writeln(""" @@ -192,8 +230,13 @@ class ExchangeableEnumGenerator for (final entry in visitor.methods.entries) { final methodElement = entry.value; + if (Util.methodHasIgnore(methodElement)) { + continue; + } ParsedLibraryResult parsed = methodElement.session?.getParsedLibraryByElement(methodElement.library) as ParsedLibraryResult; - final methodBody = parsed.getElementDeclaration(methodElement)?.node; + final methodBody = parsed.getElementDeclaration(methodElement)?.node + .toString() + .replaceAll(className, extClassName); if (methodBody != null) { final docs = methodElement.documentationComment; if (docs != null) { @@ -208,21 +251,24 @@ class ExchangeableEnumGenerator } } - if (annotation.read("toValueMethod").boolValue && !visitor.methods.containsKey("toValue")) { + if (annotation.read("toValueMethod").boolValue && (!visitor.methods.containsKey("toValue") || + Util.methodHasIgnore(visitor.methods['toValue']!))) { classBuffer.writeln(""" ///Gets [${enumValue.type}] value. ${enumValue.type} toValue() => _value; """); } - if (annotation.read("toNativeValueMethod").boolValue && !visitor.methods.containsKey("toNativeValue")) { + if (annotation.read("toNativeValueMethod").boolValue && (!visitor.methods.containsKey("toNativeValue") || + Util.methodHasIgnore(visitor.methods['toNativeValue']!))) { classBuffer.writeln(""" ///Gets [${enumNativeValue.type}] native value. ${enumNativeValue.type} toNativeValue() => _nativeValue; """); } - if (annotation.read("hashCodeMethod").boolValue && !visitor.fields.containsKey("hashCode")) { + if (annotation.read("hashCodeMethod").boolValue && (!visitor.fields.containsKey("hashCode") || + Util.methodHasIgnore(visitor.methods['hashCode']!))) { classBuffer.writeln(""" @override int get hashCode => _value.hashCode; @@ -241,7 +287,8 @@ class ExchangeableEnumGenerator "$extClassName operator |($extClassName value) => $extClassName._internal(value.toValue() | _value, value.toNativeValue() | _nativeValue);"); } - if (annotation.read("toStringMethod").boolValue && !visitor.methods.containsKey("toString")) { + if (annotation.read("toStringMethod").boolValue && (!visitor.methods.containsKey("toString") || + Util.methodHasIgnore(visitor.methods['toString']!))) { classBuffer.writeln('@override'); classBuffer.writeln('String toString() {'); if (enumValue.type.isDartCoreString) { diff --git a/dev_packages/generators/lib/src/exchangeable_object_generator.dart b/dev_packages/generators/lib/src/exchangeable_object_generator.dart index aa567f4a..e6153a46 100644 --- a/dev_packages/generators/lib/src/exchangeable_object_generator.dart +++ b/dev_packages/generators/lib/src/exchangeable_object_generator.dart @@ -13,6 +13,8 @@ final _coreCheckerObjectConstructor = const TypeChecker.fromRuntime(ExchangeableObjectConstructor); final _coreCheckerObjectProperty = const TypeChecker.fromRuntime(ExchangeableObjectProperty); +final _coreCheckerObjectMethod = + const TypeChecker.fromRuntime(ExchangeableObjectMethod); final _coreCheckerEnum = const TypeChecker.fromRuntime(ExchangeableEnum); final _coreCheckerDeprecated = const TypeChecker.fromRuntime(Deprecated); final _coreCheckerSupportedPlatforms = @@ -27,32 +29,36 @@ class ExchangeableObjectGenerator // Visits all the children of element in no particular order. element.visitChildren(visitor); - final className = visitor.constructor.returnType.element.name; + final className = visitor.constructor.returnType.element2.name; final superClass = - visitor.constructor.returnType.superclass?.element.name != 'Object' + visitor.constructor.returnType.superclass?.element2.name != 'Object' ? visitor.constructor.returnType.superclass : null; - final superClassName = superClass?.element.name.replaceFirst("_", ""); + final interfaces = visitor.constructor.returnType.interfaces; + final superClassName = superClass?.element2.name.replaceFirst("_", ""); // remove "_" to generate the correct class name final extClassName = className.replaceFirst("_", ""); final classBuffer = StringBuffer(); final classDocs = - visitor.constructor.returnType.element.documentationComment; + visitor.constructor.returnType.element2.documentationComment; if (classDocs != null) { classBuffer.writeln(classDocs); } final classSupportedDocs = Util.getSupportedDocs( - _coreCheckerSupportedPlatforms, visitor.constructor.returnType.element); + _coreCheckerSupportedPlatforms, visitor.constructor.returnType.element2); if (classSupportedDocs != null) { classBuffer.writeln(classSupportedDocs); } - if (visitor.constructor.returnType.element.hasDeprecated) { + if (visitor.constructor.returnType.element2.hasDeprecated) { classBuffer.writeln( - "@Deprecated('${_coreCheckerDeprecated.firstAnnotationOfExact(visitor.constructor.returnType.element)?.getField("message")?.toStringValue()}')"); + "@Deprecated('${_coreCheckerDeprecated.firstAnnotationOfExact(visitor.constructor.returnType.element2)?.getField("message")?.toStringValue()}')"); } - classBuffer.write('class $extClassName'); + classBuffer.write('${(visitor.constructor.enclosingElement3 as ClassElement).isAbstract ? 'abstract ' : ''}class $extClassName'); + if (interfaces.isNotEmpty) { + classBuffer.writeln(' implements ${interfaces.map((i) => i.element2.name.replaceFirst("_", "")).join(', ')}'); + } if (superClass != null) { classBuffer.writeln(' extends ${superClassName}'); } @@ -98,6 +104,9 @@ class ExchangeableObjectGenerator if (fieldElement.isStatic) { classBuffer.write("static "); } + if (fieldElement.isLate) { + classBuffer.write("late "); + } if (fieldElement.isFinal) { classBuffer.write("final "); } @@ -155,7 +164,7 @@ class ExchangeableObjectGenerator if (constructorSupportedDocs == null) { constructorSupportedDocs = Util.getSupportedDocs( _coreCheckerSupportedPlatforms, - visitor.constructor.returnType.element); + visitor.constructor.returnType.element2); } if (constructorSupportedDocs != null) { classBuffer.writeln(constructorSupportedDocs); @@ -214,12 +223,17 @@ class ExchangeableObjectGenerator .trim(); final fieldElement = visitor.fields[fieldName]; if (fieldElement != null) { - final fieldTypeElement = fieldElement.type.element; - final deprecatedFieldTypeElement = deprecatedField.type.element; + final fieldTypeElement = fieldElement.type.element2; + final deprecatedFieldTypeElement = deprecatedField.type.element2; + + final isNullable = Util.typeIsNullable(fieldElement.type); + var hasDefaultValue = (fieldElement is ParameterElement) ? (fieldElement as ParameterElement).hasDefaultValue : false; + if (!isNullable && hasDefaultValue) { + continue; + } classBuffer.write('$fieldName = $fieldName ?? '); if (fieldTypeElement != null && deprecatedFieldTypeElement != null) { - final isNullable = Util.typeIsNullable(fieldElement.type); final deprecatedIsNullable = Util.typeIsNullable(deprecatedField.type); final hasFromMap = hasFromMapMethod(fieldTypeElement); @@ -257,8 +271,8 @@ class ExchangeableObjectGenerator classBuffer.writeln(';'); } - if (annotation.read("fromMapFactory").boolValue && - !visitor.methods.containsKey("fromMap")) { + if (annotation.read("fromMapFactory").boolValue && (!visitor.methods.containsKey("fromMap") || + Util.methodHasIgnore(visitor.methods['fromMap']!))) { classBuffer.writeln( '///Gets a possible [$extClassName] instance from a [Map] value.'); final nullable = annotation.read("nullableFromMapFactory").boolValue; @@ -272,7 +286,7 @@ class ExchangeableObjectGenerator classBuffer.writeln('final instance = $extClassName('); final fieldElements = []; if (superClass != null) { - fieldElements.addAll(superClass.element.fields); + fieldElements.addAll(superClass.element2.fields); } fieldElements.addAll(visitor.fields.values); final nonRequiredFields = []; @@ -301,7 +315,7 @@ class ExchangeableObjectGenerator ?.toFunctionValue(); if (customDeserializer != null) { final deserializerClassName = - customDeserializer.enclosingElement.name; + customDeserializer.enclosingElement3.name; if (deserializerClassName != null) { value = "$deserializerClassName.${customDeserializer.name}($value)"; @@ -334,6 +348,9 @@ class ExchangeableObjectGenerator for (final entry in visitor.methods.entries) { final methodElement = entry.value; + if (Util.methodHasIgnore(methodElement)) { + continue; + } ParsedLibraryResult parsed = methodElement.session ?.getParsedLibraryByElement(methodElement.library) as ParsedLibraryResult; @@ -353,14 +370,24 @@ class ExchangeableObjectGenerator } } - if (annotation.read("toMapMethod").boolValue && - !visitor.methods.containsKey("toMap")) { + if (annotation.read("toMapMethod").boolValue && (!visitor.methods.containsKey("toMap") || + Util.methodHasIgnore(visitor.methods['toMap']!))) { classBuffer.writeln('///Converts instance to a map.'); classBuffer.writeln('Map toMap() {'); classBuffer.writeln('return {'); + for (final entry in visitor.methods.entries) { + final methodElement = entry.value; + final toMapMergeWith = _coreCheckerObjectMethod + .firstAnnotationOf(methodElement) + ?.getField("toMapMergeWith") + ?.toBoolValue(); + if (toMapMergeWith == true) { + classBuffer.writeln('...${methodElement.name}(),'); + } + } final fieldElements = []; if (superClass != null) { - for (final fieldElement in superClass.element.fields) { + for (final fieldElement in superClass.element2.fields) { if (!fieldElement.isPrivate && !fieldElement.hasDeprecated && !fieldElement.isStatic && @@ -390,7 +417,7 @@ class ExchangeableObjectGenerator ?.getField("serializer") ?.toFunctionValue(); if (customSerializer != null) { - final serializerClassName = customSerializer.enclosingElement.name; + final serializerClassName = customSerializer.enclosingElement3.name; if (serializerClassName != null) { mapValue = "$serializerClassName.${customSerializer.name}($mapValue)"; @@ -408,22 +435,22 @@ class ExchangeableObjectGenerator classBuffer.writeln('}'); } - if (annotation.read("toJsonMethod").boolValue && - !visitor.methods.containsKey("toJson")) { + if (annotation.read("toJsonMethod").boolValue && (!visitor.methods.containsKey("toJson") || + Util.methodHasIgnore(visitor.methods['toJson']!))) { classBuffer.writeln('///Converts instance to a map.'); classBuffer.writeln('Map toJson() {'); classBuffer.writeln('return toMap();'); classBuffer.writeln('}'); } - if (annotation.read("toStringMethod").boolValue && - !visitor.methods.containsKey("toString")) { + if (annotation.read("toStringMethod").boolValue && (!visitor.methods.containsKey("toString") || + Util.methodHasIgnore(visitor.methods['toString']!))) { classBuffer.writeln('@override'); classBuffer.writeln('String toString() {'); classBuffer.write('return \'$extClassName{'); final fieldNames = []; if (superClass != null) { - for (final fieldElement in superClass.element.fields) { + for (final fieldElement in superClass.element2.fields) { final fieldName = fieldElement.name; if (!fieldElement.isPrivate && !fieldElement.hasDeprecated && @@ -453,7 +480,7 @@ class ExchangeableObjectGenerator } String getFromMapValue(String value, DartType elementType) { - final fieldTypeElement = elementType.element; + final fieldTypeElement = elementType.element2; final isNullable = Util.typeIsNullable(elementType); if (elementType.getDisplayString(withNullability: false) == "Uri") { if (!isNullable) { @@ -486,9 +513,9 @@ class ExchangeableObjectGenerator final genericTypeFieldName = 'e'; return value + (isNullable ? '?' : '') + - '.forEach(($genericTypeFieldName) => ' + + '.map(($genericTypeFieldName) => ' + getFromMapValue('$genericTypeFieldName', genericType) + - ')'; + ')${elementType.isDartCoreSet ? '.toSet()' : ''}'; } else { return value; } @@ -523,7 +550,7 @@ class ExchangeableObjectGenerator } String getToMapValue(String fieldName, DartType elementType) { - final fieldTypeElement = elementType.element; + final fieldTypeElement = elementType.element2; final isNullable = Util.typeIsNullable(elementType); if (elementType.getDisplayString(withNullability: false) == "Uri") { return fieldName + (isNullable ? '?' : '') + '.toString()'; diff --git a/dev_packages/generators/lib/src/util.dart b/dev_packages/generators/lib/src/util.dart index 7be8ff41..d30c33bb 100644 --- a/dev_packages/generators/lib/src/util.dart +++ b/dev_packages/generators/lib/src/util.dart @@ -3,6 +3,10 @@ import 'package:source_gen/source_gen.dart'; import 'package:analyzer/dart/element/type.dart'; import 'package:analyzer/dart/element/nullability_suffix.dart'; import 'package:analyzer/dart/constant/value.dart'; +import 'package:flutter_inappwebview_internal_annotations/flutter_inappwebview_internal_annotations.dart'; + +final _coreCheckerObjectMethod = + const TypeChecker.fromRuntime(ExchangeableObjectMethod); abstract class Util { static bool typeIsNullable(DartType type) { @@ -10,6 +14,14 @@ abstract class Util { type.toString() == 'dynamic'; } + static bool methodHasIgnore(MethodElement method) { + return _coreCheckerObjectMethod + .firstAnnotationOf(method) + ?.getField("ignore") + ?.toBoolValue() == + true; + } + static String? getSupportedDocs(TypeChecker checker, Element element) { final platformNoteList = []; final platformSupportedList = []; @@ -64,7 +76,7 @@ abstract class Util { } static bool canHaveGenerics(DartType type) { - final element = type.element; + final element = type.element2; if (element is ClassElement) { return element.typeParameters.isNotEmpty; } diff --git a/dev_packages/generators/pubspec.lock b/dev_packages/generators/pubspec.lock index b47fe7bb..00e926d6 100644 --- a/dev_packages/generators/pubspec.lock +++ b/dev_packages/generators/pubspec.lock @@ -7,14 +7,14 @@ packages: name: _fe_analyzer_shared url: "https://pub.dartlang.org" source: hosted - version: "39.0.0" + version: "49.0.0" analyzer: dependency: transitive description: name: analyzer url: "https://pub.dartlang.org" source: hosted - version: "4.0.0" + version: "5.1.0" args: dependency: transitive description: @@ -42,14 +42,14 @@ packages: name: build url: "https://pub.dartlang.org" source: hosted - version: "2.3.0" + version: "2.3.1" build_config: dependency: transitive description: name: build_config url: "https://pub.dartlang.org" source: hosted - version: "1.0.0" + version: "1.1.0" build_daemon: dependency: transitive description: @@ -63,21 +63,21 @@ packages: name: build_resolvers url: "https://pub.dartlang.org" source: hosted - version: "2.0.8" + version: "2.0.10" build_runner: dependency: "direct dev" description: name: build_runner url: "https://pub.dartlang.org" source: hosted - version: "2.1.10" + version: "2.2.1" build_runner_core: dependency: transitive description: name: build_runner_core url: "https://pub.dartlang.org" source: hosted - version: "7.2.3" + version: "7.2.4" build_test: dependency: "direct dev" description: @@ -98,21 +98,14 @@ packages: name: built_value url: "https://pub.dartlang.org" source: hosted - version: "8.3.0" + version: "8.4.1" characters: dependency: transitive description: name: characters url: "https://pub.dartlang.org" source: hosted - version: "1.2.0" - charcode: - dependency: transitive - description: - name: charcode - url: "https://pub.dartlang.org" - source: hosted - version: "1.3.1" + version: "1.2.1" checked_yaml: dependency: transitive description: @@ -126,28 +119,28 @@ packages: name: code_builder url: "https://pub.dartlang.org" source: hosted - version: "4.1.0" + version: "4.3.0" collection: dependency: transitive description: name: collection url: "https://pub.dartlang.org" source: hosted - version: "1.15.0" + version: "1.16.0" convert: dependency: transitive description: name: convert url: "https://pub.dartlang.org" source: hosted - version: "3.0.1" + version: "3.0.2" coverage: dependency: transitive description: name: coverage url: "https://pub.dartlang.org" source: hosted - version: "1.3.1" + version: "1.6.1" crypto: dependency: transitive description: @@ -161,21 +154,21 @@ packages: name: csslib url: "https://pub.dartlang.org" source: hosted - version: "0.17.1" + version: "0.17.2" dart_style: dependency: transitive description: name: dart_style url: "https://pub.dartlang.org" source: hosted - version: "2.2.3" + version: "2.2.4" file: dependency: transitive description: name: file url: "https://pub.dartlang.org" source: hosted - version: "6.1.2" + version: "6.1.4" fixnum: dependency: transitive description: @@ -201,14 +194,14 @@ packages: name: frontend_server_client url: "https://pub.dartlang.org" source: hosted - version: "2.1.2" + version: "2.1.3" glob: dependency: transitive description: name: glob url: "https://pub.dartlang.org" source: hosted - version: "2.0.2" + version: "2.1.0" graphs: dependency: transitive description: @@ -229,14 +222,14 @@ packages: name: http_multi_server url: "https://pub.dartlang.org" source: hosted - version: "3.2.0" + version: "3.2.1" http_parser: dependency: transitive description: name: http_parser url: "https://pub.dartlang.org" source: hosted - version: "4.0.0" + version: "4.0.1" io: dependency: transitive description: @@ -257,7 +250,7 @@ packages: name: json_annotation url: "https://pub.dartlang.org" source: hosted - version: "4.5.0" + version: "4.7.0" logging: dependency: transitive description: @@ -271,21 +264,21 @@ packages: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.11" + version: "0.12.12" material_color_utilities: dependency: transitive description: name: material_color_utilities url: "https://pub.dartlang.org" source: hosted - version: "0.1.3" + version: "0.1.5" meta: dependency: transitive description: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.7.0" + version: "1.8.0" mime: dependency: transitive description: @@ -306,21 +299,21 @@ packages: name: package_config url: "https://pub.dartlang.org" source: hosted - version: "2.0.2" + version: "2.1.0" path: dependency: transitive description: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.8.1" + version: "1.8.2" pool: dependency: transitive description: name: pool url: "https://pub.dartlang.org" source: hosted - version: "1.5.0" + version: "1.5.1" pub_semver: dependency: transitive description: @@ -334,35 +327,35 @@ packages: name: pubspec_parse url: "https://pub.dartlang.org" source: hosted - version: "1.2.0" + version: "1.2.1" shelf: dependency: transitive description: name: shelf url: "https://pub.dartlang.org" source: hosted - version: "1.3.0" + version: "1.4.0" shelf_packages_handler: dependency: transitive description: name: shelf_packages_handler url: "https://pub.dartlang.org" source: hosted - version: "3.0.0" + version: "3.0.1" shelf_static: dependency: transitive description: name: shelf_static url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "1.1.1" shelf_web_socket: dependency: transitive description: name: shelf_web_socket url: "https://pub.dartlang.org" source: hosted - version: "1.0.1" + version: "1.0.2" sky_engine: dependency: transitive description: flutter @@ -374,7 +367,7 @@ packages: name: source_gen url: "https://pub.dartlang.org" source: hosted - version: "1.2.2" + version: "1.2.5" source_map_stack_trace: dependency: transitive description: @@ -395,7 +388,7 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.9.0" + version: "1.9.1" stack_trace: dependency: transitive description: @@ -409,7 +402,7 @@ packages: name: stream_channel url: "https://pub.dartlang.org" source: hosted - version: "2.1.0" + version: "2.1.1" stream_transform: dependency: transitive description: @@ -430,28 +423,28 @@ packages: name: term_glyph url: "https://pub.dartlang.org" source: hosted - version: "1.2.0" + version: "1.2.1" test: dependency: "direct dev" description: name: test url: "https://pub.dartlang.org" source: hosted - version: "1.21.1" + version: "1.21.6" test_api: dependency: transitive description: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.4.9" + version: "0.4.14" test_core: dependency: transitive description: name: test_core url: "https://pub.dartlang.org" source: hosted - version: "0.4.13" + version: "0.4.18" timing: dependency: transitive description: @@ -465,21 +458,21 @@ packages: name: typed_data url: "https://pub.dartlang.org" source: hosted - version: "1.3.0" + version: "1.3.1" vector_math: dependency: transitive description: name: vector_math url: "https://pub.dartlang.org" source: hosted - version: "2.1.1" + version: "2.1.2" vm_service: dependency: transitive description: name: vm_service url: "https://pub.dartlang.org" source: hosted - version: "8.3.0" + version: "9.4.0" watcher: dependency: transitive description: @@ -500,7 +493,7 @@ packages: name: webkit_inspection_protocol url: "https://pub.dartlang.org" source: hosted - version: "1.0.1" + version: "1.2.0" yaml: dependency: transitive description: @@ -509,5 +502,5 @@ packages: source: hosted version: "3.1.1" sdks: - dart: ">=2.16.0 <3.0.0" + dart: ">=2.18.0 <3.0.0" flutter: ">=2.5.0" diff --git a/dev_packages/generators/pubspec.yaml b/dev_packages/generators/pubspec.yaml index ae78bc72..4f59c141 100755 --- a/dev_packages/generators/pubspec.yaml +++ b/dev_packages/generators/pubspec.yaml @@ -10,12 +10,12 @@ environment: dependencies: flutter: sdk: flutter - build: - source_gen: + build: ^2.3.1 + source_gen: ^1.2.5 flutter_inappwebview_internal_annotations: path: ../flutter_inappwebview_internal_annotations/ dev_dependencies: - build_runner: - build_test: + build_runner: ^2.2.1 + build_test: ^2.1.5 test: ^1.21.1 \ No newline at end of file diff --git a/dev_packages/test_gen/pubspec.lock b/dev_packages/test_gen/pubspec.lock index 7ae39e4f..3475a3e7 100644 --- a/dev_packages/test_gen/pubspec.lock +++ b/dev_packages/test_gen/pubspec.lock @@ -7,14 +7,14 @@ packages: name: _fe_analyzer_shared url: "https://pub.dartlang.org" source: hosted - version: "39.0.0" + version: "49.0.0" analyzer: dependency: transitive description: name: analyzer url: "https://pub.dartlang.org" source: hosted - version: "4.0.0" + version: "5.1.0" args: dependency: transitive description: @@ -35,14 +35,14 @@ packages: name: build url: "https://pub.dartlang.org" source: hosted - version: "2.3.0" + version: "2.3.1" build_config: dependency: transitive description: name: build_config url: "https://pub.dartlang.org" source: hosted - version: "1.0.0" + version: "1.1.0" build_daemon: dependency: transitive description: @@ -56,21 +56,21 @@ packages: name: build_resolvers url: "https://pub.dartlang.org" source: hosted - version: "2.0.8" + version: "2.0.10" build_runner: dependency: "direct dev" description: name: build_runner url: "https://pub.dartlang.org" source: hosted - version: "2.1.10" + version: "2.2.1" build_runner_core: dependency: transitive description: name: build_runner_core url: "https://pub.dartlang.org" source: hosted - version: "7.2.3" + version: "7.2.4" built_collection: dependency: transitive description: @@ -84,21 +84,14 @@ packages: name: built_value url: "https://pub.dartlang.org" source: hosted - version: "8.3.0" + version: "8.4.1" characters: dependency: transitive description: name: characters url: "https://pub.dartlang.org" source: hosted - version: "1.2.0" - charcode: - dependency: transitive - description: - name: charcode - url: "https://pub.dartlang.org" - source: hosted - version: "1.3.1" + version: "1.2.1" checked_yaml: dependency: transitive description: @@ -112,21 +105,21 @@ packages: name: code_builder url: "https://pub.dartlang.org" source: hosted - version: "4.1.0" + version: "4.3.0" collection: dependency: transitive description: name: collection url: "https://pub.dartlang.org" source: hosted - version: "1.15.0" + version: "1.16.0" convert: dependency: transitive description: name: convert url: "https://pub.dartlang.org" source: hosted - version: "3.0.1" + version: "3.0.2" crypto: dependency: transitive description: @@ -140,14 +133,14 @@ packages: name: dart_style url: "https://pub.dartlang.org" source: hosted - version: "2.2.3" + version: "2.2.4" file: dependency: transitive description: name: file url: "https://pub.dartlang.org" source: hosted - version: "6.1.2" + version: "6.1.4" fixnum: dependency: transitive description: @@ -173,7 +166,7 @@ packages: name: frontend_server_client url: "https://pub.dartlang.org" source: hosted - version: "2.1.2" + version: "2.1.3" generators: dependency: "direct dev" description: @@ -187,7 +180,7 @@ packages: name: glob url: "https://pub.dartlang.org" source: hosted - version: "2.0.2" + version: "2.1.0" graphs: dependency: transitive description: @@ -201,14 +194,14 @@ packages: name: http_multi_server url: "https://pub.dartlang.org" source: hosted - version: "3.2.0" + version: "3.2.1" http_parser: dependency: transitive description: name: http_parser url: "https://pub.dartlang.org" source: hosted - version: "4.0.0" + version: "4.0.1" io: dependency: transitive description: @@ -229,7 +222,7 @@ packages: name: json_annotation url: "https://pub.dartlang.org" source: hosted - version: "4.5.0" + version: "4.7.0" lints: dependency: "direct dev" description: @@ -250,21 +243,21 @@ packages: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.11" + version: "0.12.12" material_color_utilities: dependency: transitive description: name: material_color_utilities url: "https://pub.dartlang.org" source: hosted - version: "0.1.3" + version: "0.1.5" meta: dependency: transitive description: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.7.0" + version: "1.8.0" mime: dependency: transitive description: @@ -278,21 +271,21 @@ packages: name: package_config url: "https://pub.dartlang.org" source: hosted - version: "2.0.2" + version: "2.1.0" path: dependency: transitive description: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.8.1" + version: "1.8.2" pool: dependency: transitive description: name: pool url: "https://pub.dartlang.org" source: hosted - version: "1.5.0" + version: "1.5.1" pub_semver: dependency: transitive description: @@ -306,21 +299,21 @@ packages: name: pubspec_parse url: "https://pub.dartlang.org" source: hosted - version: "1.2.0" + version: "1.2.1" shelf: dependency: transitive description: name: shelf url: "https://pub.dartlang.org" source: hosted - version: "1.3.0" + version: "1.4.0" shelf_web_socket: dependency: transitive description: name: shelf_web_socket url: "https://pub.dartlang.org" source: hosted - version: "1.0.1" + version: "1.0.2" sky_engine: dependency: transitive description: flutter @@ -332,14 +325,14 @@ packages: name: source_gen url: "https://pub.dartlang.org" source: hosted - version: "1.2.2" + version: "1.2.5" source_span: dependency: transitive description: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.9.0" + version: "1.9.1" stack_trace: dependency: transitive description: @@ -353,7 +346,7 @@ packages: name: stream_channel url: "https://pub.dartlang.org" source: hosted - version: "2.1.0" + version: "2.1.1" stream_transform: dependency: transitive description: @@ -374,7 +367,7 @@ packages: name: term_glyph url: "https://pub.dartlang.org" source: hosted - version: "1.2.0" + version: "1.2.1" timing: dependency: transitive description: @@ -388,14 +381,14 @@ packages: name: typed_data url: "https://pub.dartlang.org" source: hosted - version: "1.3.0" + version: "1.3.1" vector_math: dependency: transitive description: name: vector_math url: "https://pub.dartlang.org" source: hosted - version: "2.1.1" + version: "2.1.2" watcher: dependency: transitive description: @@ -418,5 +411,5 @@ packages: source: hosted version: "3.1.1" sdks: - dart: ">=2.16.0 <3.0.0" + dart: ">=2.17.0 <3.0.0" flutter: ">=2.5.0" diff --git a/dev_packages/test_gen/pubspec.yaml b/dev_packages/test_gen/pubspec.yaml index 155717eb..3b11705e 100755 --- a/dev_packages/test_gen/pubspec.yaml +++ b/dev_packages/test_gen/pubspec.yaml @@ -14,7 +14,7 @@ dependencies: path: ../flutter_inappwebview_internal_annotations/ dev_dependencies: - build_runner: + build_runner: ^2.2.1 generators: path: ../generators/ lints: ^1.0.1 \ No newline at end of file diff --git a/example/test_assets/certificate.pfx b/example/test_assets/certificate.pfx index 3225678f..6e362107 100755 Binary files a/example/test_assets/certificate.pfx and b/example/test_assets/certificate.pfx differ diff --git a/ios/Classes/InAppWebView/WebViewChannelDelegate.swift b/ios/Classes/InAppWebView/WebViewChannelDelegate.swift index 761bc337..551e2b58 100644 --- a/ios/Classes/InAppWebView/WebViewChannelDelegate.swift +++ b/ios/Classes/InAppWebView/WebViewChannelDelegate.swift @@ -1007,7 +1007,7 @@ public class WebViewChannelDelegate : ChannelDelegate { override init() { super.init() self.decodeResult = { (obj: Any?) in - if let obj = obj as? [String: Any?], let action = obj["action"] as? Int { + if let action = obj as? Int { return action == 1 } return false diff --git a/lib/src/android/main.dart b/lib/src/android/main.dart index fce751da..5b7613df 100644 --- a/lib/src/android/main.dart +++ b/lib/src/android/main.dart @@ -1,3 +1,3 @@ export 'service_worker_controller.dart'; -export 'webview_feature.dart'; +export 'webview_feature.dart' show WebViewFeature, AndroidWebViewFeature; export 'proxy_controller.dart'; diff --git a/lib/src/android/webview_feature.dart b/lib/src/android/webview_feature.dart index 4c7f398a..ea8a2e46 100644 --- a/lib/src/android/webview_feature.dart +++ b/lib/src/android/webview_feature.dart @@ -1,255 +1,198 @@ import 'dart:async'; import 'package:flutter/services.dart'; +import 'package:flutter_inappwebview_internal_annotations/flutter_inappwebview_internal_annotations.dart'; import '../in_app_webview/in_app_webview_controller.dart'; import '../in_app_webview/in_app_webview_settings.dart'; import 'proxy_controller.dart'; import 'service_worker_controller.dart'; import '../web_message/main.dart'; +part 'webview_feature.g.dart'; + ///Class that represents an Android-specific utility class for checking which WebView Support Library features are supported on the device. -class WebViewFeature { +@ExchangeableEnum() +class WebViewFeature_ { + @ExchangeableEnumCustomValue() static const MethodChannel _channel = const MethodChannel( 'com.pichillilorenzo/flutter_inappwebview_webviewfeature'); + // ignore: unused_field final String _value; + const WebViewFeature_._internal(this._value); - const WebViewFeature._internal(this._value); - - static final Set values = [ - WebViewFeature.CREATE_WEB_MESSAGE_CHANNEL, - WebViewFeature.DISABLED_ACTION_MODE_MENU_ITEMS, - WebViewFeature.FORCE_DARK, - WebViewFeature.FORCE_DARK_STRATEGY, - WebViewFeature.GET_WEB_CHROME_CLIENT, - WebViewFeature.GET_WEB_VIEW_CLIENT, - WebViewFeature.GET_WEB_VIEW_RENDERER, - WebViewFeature.MULTI_PROCESS, - WebViewFeature.OFF_SCREEN_PRERASTER, - WebViewFeature.POST_WEB_MESSAGE, - WebViewFeature.PROXY_OVERRIDE, - WebViewFeature.RECEIVE_HTTP_ERROR, - WebViewFeature.RECEIVE_WEB_RESOURCE_ERROR, - WebViewFeature.SAFE_BROWSING_ALLOWLIST, - WebViewFeature.SAFE_BROWSING_ENABLE, - WebViewFeature.SAFE_BROWSING_HIT, - WebViewFeature.SAFE_BROWSING_PRIVACY_POLICY_URL, - WebViewFeature.SAFE_BROWSING_RESPONSE_BACK_TO_SAFETY, - WebViewFeature.SAFE_BROWSING_RESPONSE_PROCEED, - WebViewFeature.SAFE_BROWSING_RESPONSE_SHOW_INTERSTITIAL, - WebViewFeature.SERVICE_WORKER_BASIC_USAGE, - WebViewFeature.SERVICE_WORKER_BLOCK_NETWORK_LOADS, - WebViewFeature.SERVICE_WORKER_CACHE_MODE, - WebViewFeature.SERVICE_WORKER_CONTENT_ACCESS, - WebViewFeature.SERVICE_WORKER_FILE_ACCESS, - WebViewFeature.SERVICE_WORKER_SHOULD_INTERCEPT_REQUEST, - WebViewFeature.SHOULD_OVERRIDE_WITH_REDIRECTS, - WebViewFeature.START_SAFE_BROWSING, - WebViewFeature.TRACING_CONTROLLER_BASIC_USAGE, - WebViewFeature.VISUAL_STATE_CALLBACK, - WebViewFeature.WEB_MESSAGE_CALLBACK_ON_MESSAGE, - WebViewFeature.WEB_MESSAGE_LISTENER, - WebViewFeature.WEB_MESSAGE_PORT_CLOSE, - WebViewFeature.WEB_MESSAGE_PORT_POST_MESSAGE, - WebViewFeature.WEB_MESSAGE_PORT_SET_MESSAGE_CALLBACK, - WebViewFeature.WEB_RESOURCE_ERROR_GET_CODE, - WebViewFeature.WEB_RESOURCE_ERROR_GET_DESCRIPTION, - WebViewFeature.WEB_RESOURCE_REQUEST_IS_REDIRECT, - WebViewFeature.WEB_VIEW_RENDERER_CLIENT_BASIC_USAGE, - WebViewFeature.WEB_VIEW_RENDERER_TERMINATE, - ].toSet(); - - static WebViewFeature? fromValue(String? value) { - if (value != null) { - try { - return WebViewFeature.values - .firstWhere((element) => element.toValue() == value); - } catch (e) { - return null; - } - } - return null; - } - + @ExchangeableObjectMethod(ignore: true) String toValue() => _value; - @override - String toString() => _value; - ///This feature covers [InAppWebViewController.createWebMessageChannel]. static const CREATE_WEB_MESSAGE_CHANNEL = - const WebViewFeature._internal("CREATE_WEB_MESSAGE_CHANNEL"); + const WebViewFeature_._internal("CREATE_WEB_MESSAGE_CHANNEL"); ///This feature covers [InAppWebViewSettings.disabledActionModeMenuItems]. static const DISABLED_ACTION_MODE_MENU_ITEMS = - const WebViewFeature._internal("DISABLED_ACTION_MODE_MENU_ITEMS"); + const WebViewFeature_._internal("DISABLED_ACTION_MODE_MENU_ITEMS"); ///This feature covers [InAppWebViewSettings.forceDark]. - static const FORCE_DARK = const WebViewFeature._internal("FORCE_DARK"); + static const FORCE_DARK = const WebViewFeature_._internal("FORCE_DARK"); ///This feature covers [InAppWebViewSettings.forceDarkStrategy]. static const FORCE_DARK_STRATEGY = - const WebViewFeature._internal("FORCE_DARK_STRATEGY"); + const WebViewFeature_._internal("FORCE_DARK_STRATEGY"); /// static const GET_WEB_CHROME_CLIENT = - const WebViewFeature._internal("GET_WEB_CHROME_CLIENT"); + const WebViewFeature_._internal("GET_WEB_CHROME_CLIENT"); /// static const GET_WEB_VIEW_CLIENT = - const WebViewFeature._internal("GET_WEB_VIEW_CLIENT"); + const WebViewFeature_._internal("GET_WEB_VIEW_CLIENT"); /// static const GET_WEB_VIEW_RENDERER = - const WebViewFeature._internal("GET_WEB_VIEW_RENDERER"); + const WebViewFeature_._internal("GET_WEB_VIEW_RENDERER"); /// - static const MULTI_PROCESS = const WebViewFeature._internal("MULTI_PROCESS"); + static const MULTI_PROCESS = const WebViewFeature_._internal("MULTI_PROCESS"); ///This feature covers [InAppWebViewSettings.offscreenPreRaster]. static const OFF_SCREEN_PRERASTER = - const WebViewFeature._internal("OFF_SCREEN_PRERASTER"); + const WebViewFeature_._internal("OFF_SCREEN_PRERASTER"); ///This feature covers [InAppWebViewController.postWebMessage]. static const POST_WEB_MESSAGE = - const WebViewFeature._internal("POST_WEB_MESSAGE"); + const WebViewFeature_._internal("POST_WEB_MESSAGE"); ///This feature covers [ProxyController.setProxyOverride] and [ProxyController.clearProxyOverride]. static const PROXY_OVERRIDE = - const WebViewFeature._internal("PROXY_OVERRIDE"); + const WebViewFeature_._internal("PROXY_OVERRIDE"); /// static const RECEIVE_HTTP_ERROR = - const WebViewFeature._internal("RECEIVE_HTTP_ERROR"); + const WebViewFeature_._internal("RECEIVE_HTTP_ERROR"); /// static const RECEIVE_WEB_RESOURCE_ERROR = - const WebViewFeature._internal("RECEIVE_WEB_RESOURCE_ERROR"); + const WebViewFeature_._internal("RECEIVE_WEB_RESOURCE_ERROR"); ///This feature covers [InAppWebViewController.setSafeBrowsingAllowlist]. static const SAFE_BROWSING_ALLOWLIST = - const WebViewFeature._internal("SAFE_BROWSING_ALLOWLIST"); + const WebViewFeature_._internal("SAFE_BROWSING_ALLOWLIST"); ///This feature covers [InAppWebViewSettings.safeBrowsingEnabled]. static const SAFE_BROWSING_ENABLE = - const WebViewFeature._internal("SAFE_BROWSING_ENABLE"); + const WebViewFeature_._internal("SAFE_BROWSING_ENABLE"); /// static const SAFE_BROWSING_HIT = - const WebViewFeature._internal("SAFE_BROWSING_HIT"); + const WebViewFeature_._internal("SAFE_BROWSING_HIT"); ///This feature covers [InAppWebViewController.getSafeBrowsingPrivacyPolicyUrl]. static const SAFE_BROWSING_PRIVACY_POLICY_URL = - const WebViewFeature._internal("SAFE_BROWSING_PRIVACY_POLICY_URL"); + const WebViewFeature_._internal("SAFE_BROWSING_PRIVACY_POLICY_URL"); /// static const SAFE_BROWSING_RESPONSE_BACK_TO_SAFETY = - const WebViewFeature._internal("SAFE_BROWSING_RESPONSE_BACK_TO_SAFETY"); + const WebViewFeature_._internal("SAFE_BROWSING_RESPONSE_BACK_TO_SAFETY"); /// static const SAFE_BROWSING_RESPONSE_PROCEED = - const WebViewFeature._internal("SAFE_BROWSING_RESPONSE_PROCEED"); + const WebViewFeature_._internal("SAFE_BROWSING_RESPONSE_PROCEED"); /// static const SAFE_BROWSING_RESPONSE_SHOW_INTERSTITIAL = - const WebViewFeature._internal( + const WebViewFeature_._internal( "SAFE_BROWSING_RESPONSE_SHOW_INTERSTITIAL"); ///Use [SAFE_BROWSING_ALLOWLIST] instead. @Deprecated('Use SAFE_BROWSING_ALLOWLIST instead') static const SAFE_BROWSING_WHITELIST = - const WebViewFeature._internal("SAFE_BROWSING_WHITELIST"); + const WebViewFeature_._internal("SAFE_BROWSING_WHITELIST"); ///This feature covers [ServiceWorkerController]. static const SERVICE_WORKER_BASIC_USAGE = - const WebViewFeature._internal("SERVICE_WORKER_BASIC_USAGE"); + const WebViewFeature_._internal("SERVICE_WORKER_BASIC_USAGE"); ///This feature covers [ServiceWorkerController.setBlockNetworkLoads] and [ServiceWorkerController.getBlockNetworkLoads]. static const SERVICE_WORKER_BLOCK_NETWORK_LOADS = - const WebViewFeature._internal("SERVICE_WORKER_BLOCK_NETWORK_LOADS"); + const WebViewFeature_._internal("SERVICE_WORKER_BLOCK_NETWORK_LOADS"); ///This feature covers [ServiceWorkerController.setCacheMode] and [ServiceWorkerController.getCacheMode]. static const SERVICE_WORKER_CACHE_MODE = - const WebViewFeature._internal("SERVICE_WORKER_CACHE_MODE"); + const WebViewFeature_._internal("SERVICE_WORKER_CACHE_MODE"); ///This feature covers [ServiceWorkerController.setAllowContentAccess] and [ServiceWorkerController.getAllowContentAccess]. static const SERVICE_WORKER_CONTENT_ACCESS = - const WebViewFeature._internal("SERVICE_WORKER_CONTENT_ACCESS"); + const WebViewFeature_._internal("SERVICE_WORKER_CONTENT_ACCESS"); ///This feature covers [ServiceWorkerController.setAllowFileAccess] and [ServiceWorkerController.getAllowFileAccess]. static const SERVICE_WORKER_FILE_ACCESS = - const WebViewFeature._internal("SERVICE_WORKER_FILE_ACCESS"); + const WebViewFeature_._internal("SERVICE_WORKER_FILE_ACCESS"); ///This feature covers [ServiceWorkerClient.shouldInterceptRequest]. static const SERVICE_WORKER_SHOULD_INTERCEPT_REQUEST = - const WebViewFeature._internal("SERVICE_WORKER_SHOULD_INTERCEPT_REQUEST"); + const WebViewFeature_._internal("SERVICE_WORKER_SHOULD_INTERCEPT_REQUEST"); /// static const SHOULD_OVERRIDE_WITH_REDIRECTS = - const WebViewFeature._internal("SHOULD_OVERRIDE_WITH_REDIRECTS"); + const WebViewFeature_._internal("SHOULD_OVERRIDE_WITH_REDIRECTS"); ///This feature covers [InAppWebViewController.startSafeBrowsing]. static const START_SAFE_BROWSING = - const WebViewFeature._internal("START_SAFE_BROWSING"); + const WebViewFeature_._internal("START_SAFE_BROWSING"); /// static const TRACING_CONTROLLER_BASIC_USAGE = - const WebViewFeature._internal("TRACING_CONTROLLER_BASIC_USAGE"); + const WebViewFeature_._internal("TRACING_CONTROLLER_BASIC_USAGE"); /// static const VISUAL_STATE_CALLBACK = - const WebViewFeature._internal("VISUAL_STATE_CALLBACK"); + const WebViewFeature_._internal("VISUAL_STATE_CALLBACK"); /// static const WEB_MESSAGE_CALLBACK_ON_MESSAGE = - const WebViewFeature._internal("WEB_MESSAGE_CALLBACK_ON_MESSAGE"); + const WebViewFeature_._internal("WEB_MESSAGE_CALLBACK_ON_MESSAGE"); ///This feature covers [WebMessageListener]. static const WEB_MESSAGE_LISTENER = - const WebViewFeature._internal("WEB_MESSAGE_LISTENER"); + const WebViewFeature_._internal("WEB_MESSAGE_LISTENER"); /// static const WEB_MESSAGE_PORT_CLOSE = - const WebViewFeature._internal("WEB_MESSAGE_PORT_CLOSE"); + const WebViewFeature_._internal("WEB_MESSAGE_PORT_CLOSE"); /// static const WEB_MESSAGE_PORT_POST_MESSAGE = - const WebViewFeature._internal("WEB_MESSAGE_PORT_POST_MESSAGE"); + const WebViewFeature_._internal("WEB_MESSAGE_PORT_POST_MESSAGE"); /// static const WEB_MESSAGE_PORT_SET_MESSAGE_CALLBACK = - const WebViewFeature._internal("WEB_MESSAGE_PORT_SET_MESSAGE_CALLBACK"); + const WebViewFeature_._internal("WEB_MESSAGE_PORT_SET_MESSAGE_CALLBACK"); /// static const WEB_RESOURCE_ERROR_GET_CODE = - const WebViewFeature._internal("WEB_RESOURCE_ERROR_GET_CODE"); + const WebViewFeature_._internal("WEB_RESOURCE_ERROR_GET_CODE"); /// static const WEB_RESOURCE_ERROR_GET_DESCRIPTION = - const WebViewFeature._internal("WEB_RESOURCE_ERROR_GET_DESCRIPTION"); + const WebViewFeature_._internal("WEB_RESOURCE_ERROR_GET_DESCRIPTION"); /// static const WEB_RESOURCE_REQUEST_IS_REDIRECT = - const WebViewFeature._internal("WEB_RESOURCE_REQUEST_IS_REDIRECT"); + const WebViewFeature_._internal("WEB_RESOURCE_REQUEST_IS_REDIRECT"); /// static const WEB_VIEW_RENDERER_CLIENT_BASIC_USAGE = - const WebViewFeature._internal("WEB_VIEW_RENDERER_CLIENT_BASIC_USAGE"); + const WebViewFeature_._internal("WEB_VIEW_RENDERER_CLIENT_BASIC_USAGE"); /// static const WEB_VIEW_RENDERER_TERMINATE = - const WebViewFeature._internal("WEB_VIEW_RENDERER_TERMINATE"); - - bool operator ==(value) => value == _value; - - @override - int get hashCode => _value.hashCode; + const WebViewFeature_._internal("WEB_VIEW_RENDERER_TERMINATE"); ///Return whether a feature is supported at run-time. On devices running Android version `Build.VERSION_CODES.LOLLIPOP` and higher, ///this will check whether a feature is supported, depending on the combination of the desired feature, the Android version of device, ///and the WebView APK on the device. If running on a device with a lower API level, this will always return `false`. /// ///**Official Android API**: https://developer.android.com/reference/androidx/webkit/WebViewFeature#isFeatureSupported(java.lang.String) - static Future isFeatureSupported(WebViewFeature feature) async { + static Future isFeatureSupported(WebViewFeature_ feature) async { Map args = {}; args.putIfAbsent("feature", () => feature.toValue()); return await _channel.invokeMethod('isFeatureSupported', args); @@ -259,256 +202,196 @@ class WebViewFeature { ///Class that represents an Android-specific utility class for checking which WebView Support Library features are supported on the device. ///Use [WebViewFeature] instead. @Deprecated("Use WebViewFeature instead") -class AndroidWebViewFeature { +@ExchangeableEnum() +class AndroidWebViewFeature_ { + @ExchangeableEnumCustomValue() static const MethodChannel _channel = const MethodChannel( 'com.pichillilorenzo/flutter_inappwebview_webviewfeature'); + // ignore: unused_field final String _value; + const AndroidWebViewFeature_._internal(this._value); - const AndroidWebViewFeature._internal(this._value); - - static final Set values = [ - AndroidWebViewFeature.CREATE_WEB_MESSAGE_CHANNEL, - AndroidWebViewFeature.DISABLED_ACTION_MODE_MENU_ITEMS, - AndroidWebViewFeature.FORCE_DARK, - AndroidWebViewFeature.FORCE_DARK_STRATEGY, - AndroidWebViewFeature.GET_WEB_CHROME_CLIENT, - AndroidWebViewFeature.GET_WEB_VIEW_CLIENT, - AndroidWebViewFeature.GET_WEB_VIEW_RENDERER, - AndroidWebViewFeature.MULTI_PROCESS, - AndroidWebViewFeature.OFF_SCREEN_PRERASTER, - AndroidWebViewFeature.POST_WEB_MESSAGE, - AndroidWebViewFeature.PROXY_OVERRIDE, - AndroidWebViewFeature.RECEIVE_HTTP_ERROR, - AndroidWebViewFeature.RECEIVE_WEB_RESOURCE_ERROR, - AndroidWebViewFeature.SAFE_BROWSING_ALLOWLIST, - AndroidWebViewFeature.SAFE_BROWSING_ENABLE, - AndroidWebViewFeature.SAFE_BROWSING_HIT, - AndroidWebViewFeature.SAFE_BROWSING_PRIVACY_POLICY_URL, - AndroidWebViewFeature.SAFE_BROWSING_RESPONSE_BACK_TO_SAFETY, - AndroidWebViewFeature.SAFE_BROWSING_RESPONSE_PROCEED, - AndroidWebViewFeature.SAFE_BROWSING_RESPONSE_SHOW_INTERSTITIAL, - AndroidWebViewFeature.SERVICE_WORKER_BASIC_USAGE, - AndroidWebViewFeature.SERVICE_WORKER_BLOCK_NETWORK_LOADS, - AndroidWebViewFeature.SERVICE_WORKER_CACHE_MODE, - AndroidWebViewFeature.SERVICE_WORKER_CONTENT_ACCESS, - AndroidWebViewFeature.SERVICE_WORKER_FILE_ACCESS, - AndroidWebViewFeature.SERVICE_WORKER_SHOULD_INTERCEPT_REQUEST, - AndroidWebViewFeature.SHOULD_OVERRIDE_WITH_REDIRECTS, - AndroidWebViewFeature.START_SAFE_BROWSING, - AndroidWebViewFeature.TRACING_CONTROLLER_BASIC_USAGE, - AndroidWebViewFeature.VISUAL_STATE_CALLBACK, - AndroidWebViewFeature.WEB_MESSAGE_CALLBACK_ON_MESSAGE, - AndroidWebViewFeature.WEB_MESSAGE_LISTENER, - AndroidWebViewFeature.WEB_MESSAGE_PORT_CLOSE, - AndroidWebViewFeature.WEB_MESSAGE_PORT_POST_MESSAGE, - AndroidWebViewFeature.WEB_MESSAGE_PORT_SET_MESSAGE_CALLBACK, - AndroidWebViewFeature.WEB_RESOURCE_ERROR_GET_CODE, - AndroidWebViewFeature.WEB_RESOURCE_ERROR_GET_DESCRIPTION, - AndroidWebViewFeature.WEB_RESOURCE_REQUEST_IS_REDIRECT, - AndroidWebViewFeature.WEB_VIEW_RENDERER_CLIENT_BASIC_USAGE, - AndroidWebViewFeature.WEB_VIEW_RENDERER_TERMINATE, - ].toSet(); - - static AndroidWebViewFeature? fromValue(String? value) { - if (value != null) { - try { - return AndroidWebViewFeature.values - .firstWhere((element) => element.toValue() == value); - } catch (e) { - return null; - } - } - return null; - } - + @ExchangeableObjectMethod(ignore: true) String toValue() => _value; - @override - String toString() => _value; - /// static const CREATE_WEB_MESSAGE_CHANNEL = - const AndroidWebViewFeature._internal("CREATE_WEB_MESSAGE_CHANNEL"); + const AndroidWebViewFeature_._internal("CREATE_WEB_MESSAGE_CHANNEL"); /// static const DISABLED_ACTION_MODE_MENU_ITEMS = - const AndroidWebViewFeature._internal("DISABLED_ACTION_MODE_MENU_ITEMS"); + const AndroidWebViewFeature_._internal("DISABLED_ACTION_MODE_MENU_ITEMS"); /// - static const FORCE_DARK = const AndroidWebViewFeature._internal("FORCE_DARK"); + static const FORCE_DARK = const AndroidWebViewFeature_._internal("FORCE_DARK"); /// static const FORCE_DARK_STRATEGY = - const AndroidWebViewFeature._internal("FORCE_DARK_STRATEGY"); + const AndroidWebViewFeature_._internal("FORCE_DARK_STRATEGY"); /// static const GET_WEB_CHROME_CLIENT = - const AndroidWebViewFeature._internal("GET_WEB_CHROME_CLIENT"); + const AndroidWebViewFeature_._internal("GET_WEB_CHROME_CLIENT"); /// static const GET_WEB_VIEW_CLIENT = - const AndroidWebViewFeature._internal("GET_WEB_VIEW_CLIENT"); + const AndroidWebViewFeature_._internal("GET_WEB_VIEW_CLIENT"); /// static const GET_WEB_VIEW_RENDERER = - const AndroidWebViewFeature._internal("GET_WEB_VIEW_RENDERER"); + const AndroidWebViewFeature_._internal("GET_WEB_VIEW_RENDERER"); /// static const MULTI_PROCESS = - const AndroidWebViewFeature._internal("MULTI_PROCESS"); + const AndroidWebViewFeature_._internal("MULTI_PROCESS"); /// static const OFF_SCREEN_PRERASTER = - const AndroidWebViewFeature._internal("OFF_SCREEN_PRERASTER"); + const AndroidWebViewFeature_._internal("OFF_SCREEN_PRERASTER"); /// static const POST_WEB_MESSAGE = - const AndroidWebViewFeature._internal("POST_WEB_MESSAGE"); + const AndroidWebViewFeature_._internal("POST_WEB_MESSAGE"); /// static const PROXY_OVERRIDE = - const AndroidWebViewFeature._internal("PROXY_OVERRIDE"); + const AndroidWebViewFeature_._internal("PROXY_OVERRIDE"); /// static const RECEIVE_HTTP_ERROR = - const AndroidWebViewFeature._internal("RECEIVE_HTTP_ERROR"); + const AndroidWebViewFeature_._internal("RECEIVE_HTTP_ERROR"); /// static const RECEIVE_WEB_RESOURCE_ERROR = - const AndroidWebViewFeature._internal("RECEIVE_WEB_RESOURCE_ERROR"); + const AndroidWebViewFeature_._internal("RECEIVE_WEB_RESOURCE_ERROR"); /// static const SAFE_BROWSING_ALLOWLIST = - const AndroidWebViewFeature._internal("SAFE_BROWSING_ALLOWLIST"); + const AndroidWebViewFeature_._internal("SAFE_BROWSING_ALLOWLIST"); /// static const SAFE_BROWSING_ENABLE = - const AndroidWebViewFeature._internal("SAFE_BROWSING_ENABLE"); + const AndroidWebViewFeature_._internal("SAFE_BROWSING_ENABLE"); /// static const SAFE_BROWSING_HIT = - const AndroidWebViewFeature._internal("SAFE_BROWSING_HIT"); + const AndroidWebViewFeature_._internal("SAFE_BROWSING_HIT"); /// static const SAFE_BROWSING_PRIVACY_POLICY_URL = - const AndroidWebViewFeature._internal("SAFE_BROWSING_PRIVACY_POLICY_URL"); + const AndroidWebViewFeature_._internal("SAFE_BROWSING_PRIVACY_POLICY_URL"); /// static const SAFE_BROWSING_RESPONSE_BACK_TO_SAFETY = - const AndroidWebViewFeature._internal( + const AndroidWebViewFeature_._internal( "SAFE_BROWSING_RESPONSE_BACK_TO_SAFETY"); /// static const SAFE_BROWSING_RESPONSE_PROCEED = - const AndroidWebViewFeature._internal("SAFE_BROWSING_RESPONSE_PROCEED"); + const AndroidWebViewFeature_._internal("SAFE_BROWSING_RESPONSE_PROCEED"); /// static const SAFE_BROWSING_RESPONSE_SHOW_INTERSTITIAL = - const AndroidWebViewFeature._internal( + const AndroidWebViewFeature_._internal( "SAFE_BROWSING_RESPONSE_SHOW_INTERSTITIAL"); ///Use [SAFE_BROWSING_ALLOWLIST] instead. @Deprecated('Use SAFE_BROWSING_ALLOWLIST instead') static const SAFE_BROWSING_WHITELIST = - const AndroidWebViewFeature._internal("SAFE_BROWSING_WHITELIST"); + const AndroidWebViewFeature_._internal("SAFE_BROWSING_WHITELIST"); /// static const SERVICE_WORKER_BASIC_USAGE = - const AndroidWebViewFeature._internal("SERVICE_WORKER_BASIC_USAGE"); + const AndroidWebViewFeature_._internal("SERVICE_WORKER_BASIC_USAGE"); /// static const SERVICE_WORKER_BLOCK_NETWORK_LOADS = - const AndroidWebViewFeature._internal( + const AndroidWebViewFeature_._internal( "SERVICE_WORKER_BLOCK_NETWORK_LOADS"); /// static const SERVICE_WORKER_CACHE_MODE = - const AndroidWebViewFeature._internal("SERVICE_WORKER_CACHE_MODE"); + const AndroidWebViewFeature_._internal("SERVICE_WORKER_CACHE_MODE"); /// static const SERVICE_WORKER_CONTENT_ACCESS = - const AndroidWebViewFeature._internal("SERVICE_WORKER_CONTENT_ACCESS"); + const AndroidWebViewFeature_._internal("SERVICE_WORKER_CONTENT_ACCESS"); /// static const SERVICE_WORKER_FILE_ACCESS = - const AndroidWebViewFeature._internal("SERVICE_WORKER_FILE_ACCESS"); + const AndroidWebViewFeature_._internal("SERVICE_WORKER_FILE_ACCESS"); /// static const SERVICE_WORKER_SHOULD_INTERCEPT_REQUEST = - const AndroidWebViewFeature._internal( + const AndroidWebViewFeature_._internal( "SERVICE_WORKER_SHOULD_INTERCEPT_REQUEST"); /// static const SHOULD_OVERRIDE_WITH_REDIRECTS = - const AndroidWebViewFeature._internal("SHOULD_OVERRIDE_WITH_REDIRECTS"); + const AndroidWebViewFeature_._internal("SHOULD_OVERRIDE_WITH_REDIRECTS"); /// static const START_SAFE_BROWSING = - const AndroidWebViewFeature._internal("START_SAFE_BROWSING"); + const AndroidWebViewFeature_._internal("START_SAFE_BROWSING"); /// static const TRACING_CONTROLLER_BASIC_USAGE = - const AndroidWebViewFeature._internal("TRACING_CONTROLLER_BASIC_USAGE"); + const AndroidWebViewFeature_._internal("TRACING_CONTROLLER_BASIC_USAGE"); /// static const VISUAL_STATE_CALLBACK = - const AndroidWebViewFeature._internal("VISUAL_STATE_CALLBACK"); + const AndroidWebViewFeature_._internal("VISUAL_STATE_CALLBACK"); /// static const WEB_MESSAGE_CALLBACK_ON_MESSAGE = - const AndroidWebViewFeature._internal("WEB_MESSAGE_CALLBACK_ON_MESSAGE"); + const AndroidWebViewFeature_._internal("WEB_MESSAGE_CALLBACK_ON_MESSAGE"); /// static const WEB_MESSAGE_LISTENER = - const AndroidWebViewFeature._internal("WEB_MESSAGE_LISTENER"); + const AndroidWebViewFeature_._internal("WEB_MESSAGE_LISTENER"); /// static const WEB_MESSAGE_PORT_CLOSE = - const AndroidWebViewFeature._internal("WEB_MESSAGE_PORT_CLOSE"); + const AndroidWebViewFeature_._internal("WEB_MESSAGE_PORT_CLOSE"); /// static const WEB_MESSAGE_PORT_POST_MESSAGE = - const AndroidWebViewFeature._internal("WEB_MESSAGE_PORT_POST_MESSAGE"); + const AndroidWebViewFeature_._internal("WEB_MESSAGE_PORT_POST_MESSAGE"); /// static const WEB_MESSAGE_PORT_SET_MESSAGE_CALLBACK = - const AndroidWebViewFeature._internal( + const AndroidWebViewFeature_._internal( "WEB_MESSAGE_PORT_SET_MESSAGE_CALLBACK"); /// static const WEB_RESOURCE_ERROR_GET_CODE = - const AndroidWebViewFeature._internal("WEB_RESOURCE_ERROR_GET_CODE"); + const AndroidWebViewFeature_._internal("WEB_RESOURCE_ERROR_GET_CODE"); /// static const WEB_RESOURCE_ERROR_GET_DESCRIPTION = - const AndroidWebViewFeature._internal( + const AndroidWebViewFeature_._internal( "WEB_RESOURCE_ERROR_GET_DESCRIPTION"); /// static const WEB_RESOURCE_REQUEST_IS_REDIRECT = - const AndroidWebViewFeature._internal("WEB_RESOURCE_REQUEST_IS_REDIRECT"); + const AndroidWebViewFeature_._internal("WEB_RESOURCE_REQUEST_IS_REDIRECT"); /// static const WEB_VIEW_RENDERER_CLIENT_BASIC_USAGE = - const AndroidWebViewFeature._internal( + const AndroidWebViewFeature_._internal( "WEB_VIEW_RENDERER_CLIENT_BASIC_USAGE"); /// static const WEB_VIEW_RENDERER_TERMINATE = - const AndroidWebViewFeature._internal("WEB_VIEW_RENDERER_TERMINATE"); - - bool operator ==(value) => value == _value; - - @override - int get hashCode => _value.hashCode; + const AndroidWebViewFeature_._internal("WEB_VIEW_RENDERER_TERMINATE"); ///Return whether a feature is supported at run-time. On devices running Android version `Build.VERSION_CODES.LOLLIPOP` and higher, ///this will check whether a feature is supported, depending on the combination of the desired feature, the Android version of device, ///and the WebView APK on the device. If running on a device with a lower API level, this will always return `false`. /// ///**Official Android API**: https://developer.android.com/reference/androidx/webkit/WebViewFeature#isFeatureSupported(java.lang.String) - static Future isFeatureSupported(AndroidWebViewFeature feature) async { + static Future isFeatureSupported(AndroidWebViewFeature_ feature) async { Map args = {}; args.putIfAbsent("feature", () => feature.toValue()); return await _channel.invokeMethod('isFeatureSupported', args); diff --git a/lib/src/android/webview_feature.g.dart b/lib/src/android/webview_feature.g.dart new file mode 100644 index 00000000..6ef3baa9 --- /dev/null +++ b/lib/src/android/webview_feature.g.dart @@ -0,0 +1,580 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'webview_feature.dart'; + +// ************************************************************************** +// ExchangeableEnumGenerator +// ************************************************************************** + +///Class that represents an Android-specific utility class for checking which WebView Support Library features are supported on the device. +class WebViewFeature { + final String _value; + final String _nativeValue; + const WebViewFeature._internal(this._value, this._nativeValue); +// ignore: unused_element + factory WebViewFeature._internalMultiPlatform( + String value, Function nativeValue) => + WebViewFeature._internal(value, nativeValue()); + static const _channel = const MethodChannel( + 'com.pichillilorenzo/flutter_inappwebview_webviewfeature'); + + ///This feature covers [InAppWebViewController.createWebMessageChannel]. + static const CREATE_WEB_MESSAGE_CHANNEL = WebViewFeature._internal( + 'CREATE_WEB_MESSAGE_CHANNEL', 'CREATE_WEB_MESSAGE_CHANNEL'); + + ///This feature covers [InAppWebViewSettings.disabledActionModeMenuItems]. + static const DISABLED_ACTION_MODE_MENU_ITEMS = WebViewFeature._internal( + 'DISABLED_ACTION_MODE_MENU_ITEMS', 'DISABLED_ACTION_MODE_MENU_ITEMS'); + + ///This feature covers [InAppWebViewSettings.forceDark]. + static const FORCE_DARK = + WebViewFeature._internal('FORCE_DARK', 'FORCE_DARK'); + + ///This feature covers [InAppWebViewSettings.forceDarkStrategy]. + static const FORCE_DARK_STRATEGY = + WebViewFeature._internal('FORCE_DARK_STRATEGY', 'FORCE_DARK_STRATEGY'); + + /// + static const GET_WEB_CHROME_CLIENT = WebViewFeature._internal( + 'GET_WEB_CHROME_CLIENT', 'GET_WEB_CHROME_CLIENT'); + + /// + static const GET_WEB_VIEW_CLIENT = + WebViewFeature._internal('GET_WEB_VIEW_CLIENT', 'GET_WEB_VIEW_CLIENT'); + + /// + static const GET_WEB_VIEW_RENDERER = WebViewFeature._internal( + 'GET_WEB_VIEW_RENDERER', 'GET_WEB_VIEW_RENDERER'); + + /// + static const MULTI_PROCESS = + WebViewFeature._internal('MULTI_PROCESS', 'MULTI_PROCESS'); + + ///This feature covers [InAppWebViewSettings.offscreenPreRaster]. + static const OFF_SCREEN_PRERASTER = + WebViewFeature._internal('OFF_SCREEN_PRERASTER', 'OFF_SCREEN_PRERASTER'); + + ///This feature covers [InAppWebViewController.postWebMessage]. + static const POST_WEB_MESSAGE = + WebViewFeature._internal('POST_WEB_MESSAGE', 'POST_WEB_MESSAGE'); + + ///This feature covers [ProxyController.setProxyOverride] and [ProxyController.clearProxyOverride]. + static const PROXY_OVERRIDE = + WebViewFeature._internal('PROXY_OVERRIDE', 'PROXY_OVERRIDE'); + + /// + static const RECEIVE_HTTP_ERROR = + WebViewFeature._internal('RECEIVE_HTTP_ERROR', 'RECEIVE_HTTP_ERROR'); + + /// + static const RECEIVE_WEB_RESOURCE_ERROR = WebViewFeature._internal( + 'RECEIVE_WEB_RESOURCE_ERROR', 'RECEIVE_WEB_RESOURCE_ERROR'); + + ///This feature covers [InAppWebViewController.setSafeBrowsingAllowlist]. + static const SAFE_BROWSING_ALLOWLIST = WebViewFeature._internal( + 'SAFE_BROWSING_ALLOWLIST', 'SAFE_BROWSING_ALLOWLIST'); + + ///This feature covers [InAppWebViewSettings.safeBrowsingEnabled]. + static const SAFE_BROWSING_ENABLE = + WebViewFeature._internal('SAFE_BROWSING_ENABLE', 'SAFE_BROWSING_ENABLE'); + + /// + static const SAFE_BROWSING_HIT = + WebViewFeature._internal('SAFE_BROWSING_HIT', 'SAFE_BROWSING_HIT'); + + ///This feature covers [InAppWebViewController.getSafeBrowsingPrivacyPolicyUrl]. + static const SAFE_BROWSING_PRIVACY_POLICY_URL = WebViewFeature._internal( + 'SAFE_BROWSING_PRIVACY_POLICY_URL', 'SAFE_BROWSING_PRIVACY_POLICY_URL'); + + /// + static const SAFE_BROWSING_RESPONSE_BACK_TO_SAFETY = WebViewFeature._internal( + 'SAFE_BROWSING_RESPONSE_BACK_TO_SAFETY', + 'SAFE_BROWSING_RESPONSE_BACK_TO_SAFETY'); + + /// + static const SAFE_BROWSING_RESPONSE_PROCEED = WebViewFeature._internal( + 'SAFE_BROWSING_RESPONSE_PROCEED', 'SAFE_BROWSING_RESPONSE_PROCEED'); + + /// + static const SAFE_BROWSING_RESPONSE_SHOW_INTERSTITIAL = + WebViewFeature._internal('SAFE_BROWSING_RESPONSE_SHOW_INTERSTITIAL', + 'SAFE_BROWSING_RESPONSE_SHOW_INTERSTITIAL'); + + ///Use [SAFE_BROWSING_ALLOWLIST] instead. + static const SAFE_BROWSING_WHITELIST = WebViewFeature._internal( + 'SAFE_BROWSING_WHITELIST', 'SAFE_BROWSING_WHITELIST'); + + ///This feature covers [ServiceWorkerController]. + static const SERVICE_WORKER_BASIC_USAGE = WebViewFeature._internal( + 'SERVICE_WORKER_BASIC_USAGE', 'SERVICE_WORKER_BASIC_USAGE'); + + ///This feature covers [ServiceWorkerController.setBlockNetworkLoads] and [ServiceWorkerController.getBlockNetworkLoads]. + static const SERVICE_WORKER_BLOCK_NETWORK_LOADS = WebViewFeature._internal( + 'SERVICE_WORKER_BLOCK_NETWORK_LOADS', + 'SERVICE_WORKER_BLOCK_NETWORK_LOADS'); + + ///This feature covers [ServiceWorkerController.setCacheMode] and [ServiceWorkerController.getCacheMode]. + static const SERVICE_WORKER_CACHE_MODE = WebViewFeature._internal( + 'SERVICE_WORKER_CACHE_MODE', 'SERVICE_WORKER_CACHE_MODE'); + + ///This feature covers [ServiceWorkerController.setAllowContentAccess] and [ServiceWorkerController.getAllowContentAccess]. + static const SERVICE_WORKER_CONTENT_ACCESS = WebViewFeature._internal( + 'SERVICE_WORKER_CONTENT_ACCESS', 'SERVICE_WORKER_CONTENT_ACCESS'); + + ///This feature covers [ServiceWorkerController.setAllowFileAccess] and [ServiceWorkerController.getAllowFileAccess]. + static const SERVICE_WORKER_FILE_ACCESS = WebViewFeature._internal( + 'SERVICE_WORKER_FILE_ACCESS', 'SERVICE_WORKER_FILE_ACCESS'); + + ///This feature covers [ServiceWorkerClient.shouldInterceptRequest]. + static const SERVICE_WORKER_SHOULD_INTERCEPT_REQUEST = + WebViewFeature._internal('SERVICE_WORKER_SHOULD_INTERCEPT_REQUEST', + 'SERVICE_WORKER_SHOULD_INTERCEPT_REQUEST'); + + /// + static const SHOULD_OVERRIDE_WITH_REDIRECTS = WebViewFeature._internal( + 'SHOULD_OVERRIDE_WITH_REDIRECTS', 'SHOULD_OVERRIDE_WITH_REDIRECTS'); + + ///This feature covers [InAppWebViewController.startSafeBrowsing]. + static const START_SAFE_BROWSING = + WebViewFeature._internal('START_SAFE_BROWSING', 'START_SAFE_BROWSING'); + + /// + static const TRACING_CONTROLLER_BASIC_USAGE = WebViewFeature._internal( + 'TRACING_CONTROLLER_BASIC_USAGE', 'TRACING_CONTROLLER_BASIC_USAGE'); + + /// + static const VISUAL_STATE_CALLBACK = WebViewFeature._internal( + 'VISUAL_STATE_CALLBACK', 'VISUAL_STATE_CALLBACK'); + + /// + static const WEB_MESSAGE_CALLBACK_ON_MESSAGE = WebViewFeature._internal( + 'WEB_MESSAGE_CALLBACK_ON_MESSAGE', 'WEB_MESSAGE_CALLBACK_ON_MESSAGE'); + + ///This feature covers [WebMessageListener]. + static const WEB_MESSAGE_LISTENER = + WebViewFeature._internal('WEB_MESSAGE_LISTENER', 'WEB_MESSAGE_LISTENER'); + + /// + static const WEB_MESSAGE_PORT_CLOSE = WebViewFeature._internal( + 'WEB_MESSAGE_PORT_CLOSE', 'WEB_MESSAGE_PORT_CLOSE'); + + /// + static const WEB_MESSAGE_PORT_POST_MESSAGE = WebViewFeature._internal( + 'WEB_MESSAGE_PORT_POST_MESSAGE', 'WEB_MESSAGE_PORT_POST_MESSAGE'); + + /// + static const WEB_MESSAGE_PORT_SET_MESSAGE_CALLBACK = WebViewFeature._internal( + 'WEB_MESSAGE_PORT_SET_MESSAGE_CALLBACK', + 'WEB_MESSAGE_PORT_SET_MESSAGE_CALLBACK'); + + /// + static const WEB_RESOURCE_ERROR_GET_CODE = WebViewFeature._internal( + 'WEB_RESOURCE_ERROR_GET_CODE', 'WEB_RESOURCE_ERROR_GET_CODE'); + + /// + static const WEB_RESOURCE_ERROR_GET_DESCRIPTION = WebViewFeature._internal( + 'WEB_RESOURCE_ERROR_GET_DESCRIPTION', + 'WEB_RESOURCE_ERROR_GET_DESCRIPTION'); + + /// + static const WEB_RESOURCE_REQUEST_IS_REDIRECT = WebViewFeature._internal( + 'WEB_RESOURCE_REQUEST_IS_REDIRECT', 'WEB_RESOURCE_REQUEST_IS_REDIRECT'); + + /// + static const WEB_VIEW_RENDERER_CLIENT_BASIC_USAGE = WebViewFeature._internal( + 'WEB_VIEW_RENDERER_CLIENT_BASIC_USAGE', + 'WEB_VIEW_RENDERER_CLIENT_BASIC_USAGE'); + + /// + static const WEB_VIEW_RENDERER_TERMINATE = WebViewFeature._internal( + 'WEB_VIEW_RENDERER_TERMINATE', 'WEB_VIEW_RENDERER_TERMINATE'); + + ///Set of all values of [WebViewFeature]. + static final Set values = [ + WebViewFeature.CREATE_WEB_MESSAGE_CHANNEL, + WebViewFeature.DISABLED_ACTION_MODE_MENU_ITEMS, + WebViewFeature.FORCE_DARK, + WebViewFeature.FORCE_DARK_STRATEGY, + WebViewFeature.GET_WEB_CHROME_CLIENT, + WebViewFeature.GET_WEB_VIEW_CLIENT, + WebViewFeature.GET_WEB_VIEW_RENDERER, + WebViewFeature.MULTI_PROCESS, + WebViewFeature.OFF_SCREEN_PRERASTER, + WebViewFeature.POST_WEB_MESSAGE, + WebViewFeature.PROXY_OVERRIDE, + WebViewFeature.RECEIVE_HTTP_ERROR, + WebViewFeature.RECEIVE_WEB_RESOURCE_ERROR, + WebViewFeature.SAFE_BROWSING_ALLOWLIST, + WebViewFeature.SAFE_BROWSING_ENABLE, + WebViewFeature.SAFE_BROWSING_HIT, + WebViewFeature.SAFE_BROWSING_PRIVACY_POLICY_URL, + WebViewFeature.SAFE_BROWSING_RESPONSE_BACK_TO_SAFETY, + WebViewFeature.SAFE_BROWSING_RESPONSE_PROCEED, + WebViewFeature.SAFE_BROWSING_RESPONSE_SHOW_INTERSTITIAL, + WebViewFeature.SAFE_BROWSING_WHITELIST, + WebViewFeature.SERVICE_WORKER_BASIC_USAGE, + WebViewFeature.SERVICE_WORKER_BLOCK_NETWORK_LOADS, + WebViewFeature.SERVICE_WORKER_CACHE_MODE, + WebViewFeature.SERVICE_WORKER_CONTENT_ACCESS, + WebViewFeature.SERVICE_WORKER_FILE_ACCESS, + WebViewFeature.SERVICE_WORKER_SHOULD_INTERCEPT_REQUEST, + WebViewFeature.SHOULD_OVERRIDE_WITH_REDIRECTS, + WebViewFeature.START_SAFE_BROWSING, + WebViewFeature.TRACING_CONTROLLER_BASIC_USAGE, + WebViewFeature.VISUAL_STATE_CALLBACK, + WebViewFeature.WEB_MESSAGE_CALLBACK_ON_MESSAGE, + WebViewFeature.WEB_MESSAGE_LISTENER, + WebViewFeature.WEB_MESSAGE_PORT_CLOSE, + WebViewFeature.WEB_MESSAGE_PORT_POST_MESSAGE, + WebViewFeature.WEB_MESSAGE_PORT_SET_MESSAGE_CALLBACK, + WebViewFeature.WEB_RESOURCE_ERROR_GET_CODE, + WebViewFeature.WEB_RESOURCE_ERROR_GET_DESCRIPTION, + WebViewFeature.WEB_RESOURCE_REQUEST_IS_REDIRECT, + WebViewFeature.WEB_VIEW_RENDERER_CLIENT_BASIC_USAGE, + WebViewFeature.WEB_VIEW_RENDERER_TERMINATE, + ].toSet(); + + ///Gets a possible [WebViewFeature] instance from [String] value. + static WebViewFeature? fromValue(String? value) { + if (value != null) { + try { + return WebViewFeature.values + .firstWhere((element) => element.toValue() == value); + } catch (e) { + return null; + } + } + return null; + } + + ///Gets a possible [WebViewFeature] instance from a native value. + static WebViewFeature? fromNativeValue(String? value) { + if (value != null) { + try { + return WebViewFeature.values + .firstWhere((element) => element.toNativeValue() == value); + } catch (e) { + return null; + } + } + return null; + } + + ///Return whether a feature is supported at run-time. On devices running Android version `Build.VERSION_CODES.LOLLIPOP` and higher, + ///this will check whether a feature is supported, depending on the combination of the desired feature, the Android version of device, + ///and the WebView APK on the device. If running on a device with a lower API level, this will always return `false`. + /// + ///**Official Android API**: https://developer.android.com/reference/androidx/webkit/WebViewFeature#isFeatureSupported(java.lang.String) + static Future isFeatureSupported(WebViewFeature_ feature) async { + Map args = {}; + args.putIfAbsent("feature", () => feature.toValue()); + return await _channel.invokeMethod('isFeatureSupported', args); + } + + ///Gets [String] value. + String toValue() => _value; + + ///Gets [String] native value. + String toNativeValue() => _nativeValue; + + @override + int get hashCode => _value.hashCode; + + @override + bool operator ==(value) => value == _value; + + @override + String toString() { + return _value; + } +} + +///Class that represents an Android-specific utility class for checking which WebView Support Library features are supported on the device. +///Use [WebViewFeature] instead. +@Deprecated('Use WebViewFeature instead') +class AndroidWebViewFeature { + final String _value; + final String _nativeValue; + const AndroidWebViewFeature._internal(this._value, this._nativeValue); +// ignore: unused_element + factory AndroidWebViewFeature._internalMultiPlatform( + String value, Function nativeValue) => + AndroidWebViewFeature._internal(value, nativeValue()); + static const _channel = const MethodChannel( + 'com.pichillilorenzo/flutter_inappwebview_webviewfeature'); + + /// + static const CREATE_WEB_MESSAGE_CHANNEL = AndroidWebViewFeature._internal( + 'CREATE_WEB_MESSAGE_CHANNEL', 'CREATE_WEB_MESSAGE_CHANNEL'); + + /// + static const DISABLED_ACTION_MODE_MENU_ITEMS = + AndroidWebViewFeature._internal( + 'DISABLED_ACTION_MODE_MENU_ITEMS', 'DISABLED_ACTION_MODE_MENU_ITEMS'); + + /// + static const FORCE_DARK = + AndroidWebViewFeature._internal('FORCE_DARK', 'FORCE_DARK'); + + /// + static const FORCE_DARK_STRATEGY = AndroidWebViewFeature._internal( + 'FORCE_DARK_STRATEGY', 'FORCE_DARK_STRATEGY'); + + /// + static const GET_WEB_CHROME_CLIENT = AndroidWebViewFeature._internal( + 'GET_WEB_CHROME_CLIENT', 'GET_WEB_CHROME_CLIENT'); + + /// + static const GET_WEB_VIEW_CLIENT = AndroidWebViewFeature._internal( + 'GET_WEB_VIEW_CLIENT', 'GET_WEB_VIEW_CLIENT'); + + /// + static const GET_WEB_VIEW_RENDERER = AndroidWebViewFeature._internal( + 'GET_WEB_VIEW_RENDERER', 'GET_WEB_VIEW_RENDERER'); + + /// + static const MULTI_PROCESS = + AndroidWebViewFeature._internal('MULTI_PROCESS', 'MULTI_PROCESS'); + + /// + static const OFF_SCREEN_PRERASTER = AndroidWebViewFeature._internal( + 'OFF_SCREEN_PRERASTER', 'OFF_SCREEN_PRERASTER'); + + /// + static const POST_WEB_MESSAGE = + AndroidWebViewFeature._internal('POST_WEB_MESSAGE', 'POST_WEB_MESSAGE'); + + /// + static const PROXY_OVERRIDE = + AndroidWebViewFeature._internal('PROXY_OVERRIDE', 'PROXY_OVERRIDE'); + + /// + static const RECEIVE_HTTP_ERROR = AndroidWebViewFeature._internal( + 'RECEIVE_HTTP_ERROR', 'RECEIVE_HTTP_ERROR'); + + /// + static const RECEIVE_WEB_RESOURCE_ERROR = AndroidWebViewFeature._internal( + 'RECEIVE_WEB_RESOURCE_ERROR', 'RECEIVE_WEB_RESOURCE_ERROR'); + + /// + static const SAFE_BROWSING_ALLOWLIST = AndroidWebViewFeature._internal( + 'SAFE_BROWSING_ALLOWLIST', 'SAFE_BROWSING_ALLOWLIST'); + + /// + static const SAFE_BROWSING_ENABLE = AndroidWebViewFeature._internal( + 'SAFE_BROWSING_ENABLE', 'SAFE_BROWSING_ENABLE'); + + /// + static const SAFE_BROWSING_HIT = + AndroidWebViewFeature._internal('SAFE_BROWSING_HIT', 'SAFE_BROWSING_HIT'); + + /// + static const SAFE_BROWSING_PRIVACY_POLICY_URL = + AndroidWebViewFeature._internal('SAFE_BROWSING_PRIVACY_POLICY_URL', + 'SAFE_BROWSING_PRIVACY_POLICY_URL'); + + /// + static const SAFE_BROWSING_RESPONSE_BACK_TO_SAFETY = + AndroidWebViewFeature._internal('SAFE_BROWSING_RESPONSE_BACK_TO_SAFETY', + 'SAFE_BROWSING_RESPONSE_BACK_TO_SAFETY'); + + /// + static const SAFE_BROWSING_RESPONSE_PROCEED = AndroidWebViewFeature._internal( + 'SAFE_BROWSING_RESPONSE_PROCEED', 'SAFE_BROWSING_RESPONSE_PROCEED'); + + /// + static const SAFE_BROWSING_RESPONSE_SHOW_INTERSTITIAL = + AndroidWebViewFeature._internal( + 'SAFE_BROWSING_RESPONSE_SHOW_INTERSTITIAL', + 'SAFE_BROWSING_RESPONSE_SHOW_INTERSTITIAL'); + + ///Use [SAFE_BROWSING_ALLOWLIST] instead. + static const SAFE_BROWSING_WHITELIST = AndroidWebViewFeature._internal( + 'SAFE_BROWSING_WHITELIST', 'SAFE_BROWSING_WHITELIST'); + + /// + static const SERVICE_WORKER_BASIC_USAGE = AndroidWebViewFeature._internal( + 'SERVICE_WORKER_BASIC_USAGE', 'SERVICE_WORKER_BASIC_USAGE'); + + /// + static const SERVICE_WORKER_BLOCK_NETWORK_LOADS = + AndroidWebViewFeature._internal('SERVICE_WORKER_BLOCK_NETWORK_LOADS', + 'SERVICE_WORKER_BLOCK_NETWORK_LOADS'); + + /// + static const SERVICE_WORKER_CACHE_MODE = AndroidWebViewFeature._internal( + 'SERVICE_WORKER_CACHE_MODE', 'SERVICE_WORKER_CACHE_MODE'); + + /// + static const SERVICE_WORKER_CONTENT_ACCESS = AndroidWebViewFeature._internal( + 'SERVICE_WORKER_CONTENT_ACCESS', 'SERVICE_WORKER_CONTENT_ACCESS'); + + /// + static const SERVICE_WORKER_FILE_ACCESS = AndroidWebViewFeature._internal( + 'SERVICE_WORKER_FILE_ACCESS', 'SERVICE_WORKER_FILE_ACCESS'); + + /// + static const SERVICE_WORKER_SHOULD_INTERCEPT_REQUEST = + AndroidWebViewFeature._internal('SERVICE_WORKER_SHOULD_INTERCEPT_REQUEST', + 'SERVICE_WORKER_SHOULD_INTERCEPT_REQUEST'); + + /// + static const SHOULD_OVERRIDE_WITH_REDIRECTS = AndroidWebViewFeature._internal( + 'SHOULD_OVERRIDE_WITH_REDIRECTS', 'SHOULD_OVERRIDE_WITH_REDIRECTS'); + + /// + static const START_SAFE_BROWSING = AndroidWebViewFeature._internal( + 'START_SAFE_BROWSING', 'START_SAFE_BROWSING'); + + /// + static const TRACING_CONTROLLER_BASIC_USAGE = AndroidWebViewFeature._internal( + 'TRACING_CONTROLLER_BASIC_USAGE', 'TRACING_CONTROLLER_BASIC_USAGE'); + + /// + static const VISUAL_STATE_CALLBACK = AndroidWebViewFeature._internal( + 'VISUAL_STATE_CALLBACK', 'VISUAL_STATE_CALLBACK'); + + /// + static const WEB_MESSAGE_CALLBACK_ON_MESSAGE = + AndroidWebViewFeature._internal( + 'WEB_MESSAGE_CALLBACK_ON_MESSAGE', 'WEB_MESSAGE_CALLBACK_ON_MESSAGE'); + + /// + static const WEB_MESSAGE_LISTENER = AndroidWebViewFeature._internal( + 'WEB_MESSAGE_LISTENER', 'WEB_MESSAGE_LISTENER'); + + /// + static const WEB_MESSAGE_PORT_CLOSE = AndroidWebViewFeature._internal( + 'WEB_MESSAGE_PORT_CLOSE', 'WEB_MESSAGE_PORT_CLOSE'); + + /// + static const WEB_MESSAGE_PORT_POST_MESSAGE = AndroidWebViewFeature._internal( + 'WEB_MESSAGE_PORT_POST_MESSAGE', 'WEB_MESSAGE_PORT_POST_MESSAGE'); + + /// + static const WEB_MESSAGE_PORT_SET_MESSAGE_CALLBACK = + AndroidWebViewFeature._internal('WEB_MESSAGE_PORT_SET_MESSAGE_CALLBACK', + 'WEB_MESSAGE_PORT_SET_MESSAGE_CALLBACK'); + + /// + static const WEB_RESOURCE_ERROR_GET_CODE = AndroidWebViewFeature._internal( + 'WEB_RESOURCE_ERROR_GET_CODE', 'WEB_RESOURCE_ERROR_GET_CODE'); + + /// + static const WEB_RESOURCE_ERROR_GET_DESCRIPTION = + AndroidWebViewFeature._internal('WEB_RESOURCE_ERROR_GET_DESCRIPTION', + 'WEB_RESOURCE_ERROR_GET_DESCRIPTION'); + + /// + static const WEB_RESOURCE_REQUEST_IS_REDIRECT = + AndroidWebViewFeature._internal('WEB_RESOURCE_REQUEST_IS_REDIRECT', + 'WEB_RESOURCE_REQUEST_IS_REDIRECT'); + + /// + static const WEB_VIEW_RENDERER_CLIENT_BASIC_USAGE = + AndroidWebViewFeature._internal('WEB_VIEW_RENDERER_CLIENT_BASIC_USAGE', + 'WEB_VIEW_RENDERER_CLIENT_BASIC_USAGE'); + + /// + static const WEB_VIEW_RENDERER_TERMINATE = AndroidWebViewFeature._internal( + 'WEB_VIEW_RENDERER_TERMINATE', 'WEB_VIEW_RENDERER_TERMINATE'); + + ///Set of all values of [AndroidWebViewFeature]. + static final Set values = [ + AndroidWebViewFeature.CREATE_WEB_MESSAGE_CHANNEL, + AndroidWebViewFeature.DISABLED_ACTION_MODE_MENU_ITEMS, + AndroidWebViewFeature.FORCE_DARK, + AndroidWebViewFeature.FORCE_DARK_STRATEGY, + AndroidWebViewFeature.GET_WEB_CHROME_CLIENT, + AndroidWebViewFeature.GET_WEB_VIEW_CLIENT, + AndroidWebViewFeature.GET_WEB_VIEW_RENDERER, + AndroidWebViewFeature.MULTI_PROCESS, + AndroidWebViewFeature.OFF_SCREEN_PRERASTER, + AndroidWebViewFeature.POST_WEB_MESSAGE, + AndroidWebViewFeature.PROXY_OVERRIDE, + AndroidWebViewFeature.RECEIVE_HTTP_ERROR, + AndroidWebViewFeature.RECEIVE_WEB_RESOURCE_ERROR, + AndroidWebViewFeature.SAFE_BROWSING_ALLOWLIST, + AndroidWebViewFeature.SAFE_BROWSING_ENABLE, + AndroidWebViewFeature.SAFE_BROWSING_HIT, + AndroidWebViewFeature.SAFE_BROWSING_PRIVACY_POLICY_URL, + AndroidWebViewFeature.SAFE_BROWSING_RESPONSE_BACK_TO_SAFETY, + AndroidWebViewFeature.SAFE_BROWSING_RESPONSE_PROCEED, + AndroidWebViewFeature.SAFE_BROWSING_RESPONSE_SHOW_INTERSTITIAL, + AndroidWebViewFeature.SAFE_BROWSING_WHITELIST, + AndroidWebViewFeature.SERVICE_WORKER_BASIC_USAGE, + AndroidWebViewFeature.SERVICE_WORKER_BLOCK_NETWORK_LOADS, + AndroidWebViewFeature.SERVICE_WORKER_CACHE_MODE, + AndroidWebViewFeature.SERVICE_WORKER_CONTENT_ACCESS, + AndroidWebViewFeature.SERVICE_WORKER_FILE_ACCESS, + AndroidWebViewFeature.SERVICE_WORKER_SHOULD_INTERCEPT_REQUEST, + AndroidWebViewFeature.SHOULD_OVERRIDE_WITH_REDIRECTS, + AndroidWebViewFeature.START_SAFE_BROWSING, + AndroidWebViewFeature.TRACING_CONTROLLER_BASIC_USAGE, + AndroidWebViewFeature.VISUAL_STATE_CALLBACK, + AndroidWebViewFeature.WEB_MESSAGE_CALLBACK_ON_MESSAGE, + AndroidWebViewFeature.WEB_MESSAGE_LISTENER, + AndroidWebViewFeature.WEB_MESSAGE_PORT_CLOSE, + AndroidWebViewFeature.WEB_MESSAGE_PORT_POST_MESSAGE, + AndroidWebViewFeature.WEB_MESSAGE_PORT_SET_MESSAGE_CALLBACK, + AndroidWebViewFeature.WEB_RESOURCE_ERROR_GET_CODE, + AndroidWebViewFeature.WEB_RESOURCE_ERROR_GET_DESCRIPTION, + AndroidWebViewFeature.WEB_RESOURCE_REQUEST_IS_REDIRECT, + AndroidWebViewFeature.WEB_VIEW_RENDERER_CLIENT_BASIC_USAGE, + AndroidWebViewFeature.WEB_VIEW_RENDERER_TERMINATE, + ].toSet(); + + ///Gets a possible [AndroidWebViewFeature] instance from [String] value. + static AndroidWebViewFeature? fromValue(String? value) { + if (value != null) { + try { + return AndroidWebViewFeature.values + .firstWhere((element) => element.toValue() == value); + } catch (e) { + return null; + } + } + return null; + } + + ///Gets a possible [AndroidWebViewFeature] instance from a native value. + static AndroidWebViewFeature? fromNativeValue(String? value) { + if (value != null) { + try { + return AndroidWebViewFeature.values + .firstWhere((element) => element.toNativeValue() == value); + } catch (e) { + return null; + } + } + return null; + } + + ///Return whether a feature is supported at run-time. On devices running Android version `Build.VERSION_CODES.LOLLIPOP` and higher, + ///this will check whether a feature is supported, depending on the combination of the desired feature, the Android version of device, + ///and the WebView APK on the device. If running on a device with a lower API level, this will always return `false`. + /// + ///**Official Android API**: https://developer.android.com/reference/androidx/webkit/WebViewFeature#isFeatureSupported(java.lang.String) + static Future isFeatureSupported(AndroidWebViewFeature_ feature) async { + Map args = {}; + args.putIfAbsent("feature", () => feature.toValue()); + return await _channel.invokeMethod('isFeatureSupported', args); + } + + ///Gets [String] value. + String toValue() => _value; + + ///Gets [String] native value. + String toNativeValue() => _nativeValue; + + @override + int get hashCode => _value.hashCode; + + @override + bool operator ==(value) => value == _value; + + @override + String toString() { + return _value; + } +} diff --git a/lib/src/in_app_webview/apple/in_app_webview_options.dart b/lib/src/in_app_webview/apple/in_app_webview_options.dart index 4cc00046..2b98252b 100755 --- a/lib/src/in_app_webview/apple/in_app_webview_options.dart +++ b/lib/src/in_app_webview/apple/in_app_webview_options.dart @@ -196,8 +196,8 @@ class IOSInAppWebViewOptions ///- [IOSInAppWebViewOptions.enableViewportScale] /// ///Events affected: - ///- the `hitTestResult` argument of [WebView.onLongPressHitTestResult] will be empty - ///- the `hitTestResult` argument of [ContextMenu.onCreateContextMenu] will be empty + ///- the `hitTestResult` argument of [WebView.onLongPressHitTestResult] will be empty + ///- the `hitTestResult` argument of [ContextMenu.onCreateContextMenu] will be empty ///- [WebView.onLoadResource] ///- [WebView.shouldInterceptAjaxRequest] ///- [WebView.onAjaxReadyStateChange] @@ -214,7 +214,7 @@ class IOSInAppWebViewOptions ///Used in combination with [WebView.initialUrlRequest] or [WebView.initialData] (using the `file://` scheme), it represents the URL from which to read the web content. ///This URL must be a file-based URL (using the `file://` scheme). - ///Specify the same value as the [URLRequest.url] if you are using it with the [WebView.initialUrlRequest] parameter or + ///Specify the same value as the [URLRequest.url] if you are using it with the [WebView.initialUrlRequest] parameter or ///the [InAppWebViewInitialData.baseUrl] if you are using it with the [WebView.initialData] parameter to prevent WebView from reading any other content. ///Specify a directory to give WebView permission to read additional files in the specified directory. Uri? allowingReadAccessTo; diff --git a/lib/src/in_app_webview/in_app_webview_controller.dart b/lib/src/in_app_webview/in_app_webview_controller.dart index 41d6bb74..c48dd30f 100644 --- a/lib/src/in_app_webview/in_app_webview_controller.dart +++ b/lib/src/in_app_webview/in_app_webview_controller.dart @@ -445,19 +445,19 @@ class InAppWebViewController { if (_webview != null) { if (_webview!.onRenderProcessUnresponsive != null) return (await _webview!.onRenderProcessUnresponsive!(this, uri)) - ?.toMap(); + ?.toNativeValue(); else { // ignore: deprecated_member_use_from_same_package return (await _webview!.androidOnRenderProcessUnresponsive!( this, uri)) - ?.toMap(); + ?.toNativeValue(); } } else { return ((await _inAppBrowser!.onRenderProcessUnresponsive(uri)) ?? (await _inAppBrowser! // ignore: deprecated_member_use_from_same_package .androidOnRenderProcessUnresponsive(uri))) - ?.toMap(); + ?.toNativeValue(); } } break; @@ -473,19 +473,19 @@ class InAppWebViewController { if (_webview != null) { if (_webview!.onRenderProcessResponsive != null) return (await _webview!.onRenderProcessResponsive!(this, uri)) - ?.toMap(); + ?.toNativeValue(); else { // ignore: deprecated_member_use_from_same_package return (await _webview!.androidOnRenderProcessResponsive!( this, uri)) - ?.toMap(); + ?.toNativeValue(); } } else { return ((await _inAppBrowser!.onRenderProcessResponsive(uri)) ?? (await _inAppBrowser! // ignore: deprecated_member_use_from_same_package .androidOnRenderProcessResponsive(uri))) - ?.toMap(); + ?.toNativeValue(); } } break; @@ -957,19 +957,19 @@ class InAppWebViewController { if (_webview!.shouldAllowDeprecatedTLS != null) return (await _webview!.shouldAllowDeprecatedTLS!( this, challenge)) - ?.toMap(); + ?.toNativeValue(); else { // ignore: deprecated_member_use_from_same_package return (await _webview!.iosShouldAllowDeprecatedTLS!( this, challenge)) - ?.toMap(); + ?.toNativeValue(); } } else { return (await _inAppBrowser!.shouldAllowDeprecatedTLS(challenge)) - ?.toMap() ?? + ?.toNativeValue() ?? // ignore: deprecated_member_use_from_same_package (await _inAppBrowser!.iosShouldAllowDeprecatedTLS(challenge)) - ?.toMap(); + ?.toNativeValue(); } } break; @@ -2281,7 +2281,7 @@ class InAppWebViewController { ///Prints the current page. /// ///To obtain the [PrintJobController], use [settings] argument with [PrintJobSettings.handledByClient] to `true`. - ///Otherwise this method will return `null` and the [PrintJobController] will be handled and disposed automatically by the system. + ///Otherwise this method will return `null` and the [PrintJobController] will be handled and disposed automatically by the system. /// ///**NOTE**: available on Android 19+. /// @@ -2823,9 +2823,9 @@ class InAppWebViewController { ///[autoname] if `false`, takes [filePath] to be a file. ///If `true`, [filePath] is assumed to be a directory in which a filename will be chosen according to the URL of the current page. /// - ///**NOTE for iOS**: Available on iOS 14.0+. If [autoname] is `false`, the [filePath] must ends with the [WebArchiveFormat.WEBARCHIVE] file extension. + ///**NOTE for iOS**: Available on iOS 14.0+. If [autoname] is `false`, the [filePath] must ends with the [WebArchiveFormat.WEBARCHIVE] file extension. /// - ///**NOTE for Android**: if [autoname] is `false`, the [filePath] must ends with the [WebArchiveFormat.MHT] file extension. + ///**NOTE for Android**: if [autoname] is `false`, the [filePath] must ends with the [WebArchiveFormat.MHT] file extension. /// ///**Supported Platforms/Implementations**: ///- Android native WebView ([Official API - WebView.saveWebArchive](https://developer.android.com/reference/android/webkit/WebView#saveWebArchive(java.lang.String,%20boolean,%20android.webkit.ValueCallback%3Cjava.lang.String%3E))) @@ -2834,9 +2834,9 @@ class InAppWebViewController { {required String filePath, bool autoname = false}) async { if (!autoname) { if (defaultTargetPlatform == TargetPlatform.android) { - assert(filePath.endsWith("." + WebArchiveFormat.MHT.toValue())); + assert(filePath.endsWith("." + WebArchiveFormat.MHT.toNativeValue())); } else if (defaultTargetPlatform == TargetPlatform.iOS) { - assert(filePath.endsWith("." + WebArchiveFormat.WEBARCHIVE.toValue())); + assert(filePath.endsWith("." + WebArchiveFormat.WEBARCHIVE.toNativeValue())); } } diff --git a/lib/src/in_app_webview/in_app_webview_settings.dart b/lib/src/in_app_webview/in_app_webview_settings.dart index 29e5dcc0..f161820a 100755 --- a/lib/src/in_app_webview/in_app_webview_settings.dart +++ b/lib/src/in_app_webview/in_app_webview_settings.dart @@ -916,8 +916,8 @@ class InAppWebViewSettings { ///- [InAppWebViewSettings.enableViewportScale] /// ///Events affected: - ///- the `hitTestResult` argument of [WebView.onLongPressHitTestResult] will be empty - ///- the `hitTestResult` argument of [ContextMenu.onCreateContextMenu] will be empty + ///- the `hitTestResult` argument of [WebView.onLongPressHitTestResult] will be empty + ///- the `hitTestResult` argument of [ContextMenu.onCreateContextMenu] will be empty ///- [WebView.onLoadResource] ///- [WebView.shouldInterceptAjaxRequest] ///- [WebView.onAjaxReadyStateChange] @@ -937,7 +937,7 @@ class InAppWebViewSettings { ///Used in combination with [WebView.initialUrlRequest] or [WebView.initialData] (using the `file://` scheme), it represents the URL from which to read the web content. ///This URL must be a file-based URL (using the `file://` scheme). - ///Specify the same value as the [URLRequest.url] if you are using it with the [WebView.initialUrlRequest] parameter or + ///Specify the same value as the [URLRequest.url] if you are using it with the [WebView.initialUrlRequest] parameter or ///the [InAppWebViewInitialData.baseUrl] if you are using it with the [WebView.initialData] parameter to prevent WebView from reading any other content. ///Specify a directory to give WebView permission to read additional files in the specified directory. /// @@ -1108,7 +1108,7 @@ class InAppWebViewSettings { this.useHybridComposition = true, this.useShouldInterceptRequest = false, this.useOnRenderProcessGone = false, - this.overScrollMode = OverScrollMode.OVER_SCROLL_IF_CONTENT_SCROLLS, + this.overScrollMode = OverScrollMode.IF_CONTENT_SCROLLS, this.networkAvailable, this.scrollBarStyle = ScrollBarStyle.SCROLLBARS_INSIDE_OVERLAY, this.verticalScrollbarPosition = diff --git a/lib/src/print_job/print_job_settings.dart b/lib/src/print_job/print_job_settings.dart index d49b94c1..2d9503cf 100644 --- a/lib/src/print_job/print_job_settings.dart +++ b/lib/src/print_job/print_job_settings.dart @@ -6,7 +6,7 @@ import 'print_job_controller.dart'; ///Class that represents the settings of a [PrintJobController]. class PrintJobSettings { - ///Set this to `true` to handle the [PrintJobController]. + ///Set this to `true` to handle the [PrintJobController]. ///Otherwise, it will be handled and disposed automatically by the system. ///The default value is `false`. /// diff --git a/lib/src/types/content_world.dart b/lib/src/types/content_world.dart index 4607b0fc..3fe37a7e 100644 --- a/lib/src/types/content_world.dart +++ b/lib/src/types/content_world.dart @@ -4,7 +4,7 @@ final _contentWorldNameRegExp = RegExp(r'[\s]'); /// ///**NOTE for iOS**: available on iOS 14.0+. This class represents the native [WKContentWorld](https://developer.apple.com/documentation/webkit/wkcontentworld) class. /// -///**NOTE for Android**: it will create and append an `