diff --git a/packages/webview_flutter/webview_flutter_android/CHANGELOG.md b/packages/webview_flutter/webview_flutter_android/CHANGELOG.md index 5c0b002dba01..16dcfd07e48c 100644 --- a/packages/webview_flutter/webview_flutter_android/CHANGELOG.md +++ b/packages/webview_flutter/webview_flutter_android/CHANGELOG.md @@ -1,3 +1,7 @@ +## 4.1.0 + +* Updates internal API wrapper to use `ProxyApi`s. + ## 4.0.3 * Bumps androidx.annotation:annotation from 1.8.2 to 1.9.1. diff --git a/packages/webview_flutter/webview_flutter_android/CONTRIBUTING.md b/packages/webview_flutter/webview_flutter_android/CONTRIBUTING.md new file mode 100644 index 000000000000..0ecb255b33a1 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_android/CONTRIBUTING.md @@ -0,0 +1,74 @@ +# Contributing to `webview_flutter_android` + +Please start by taking a look at the general guide to contributing to the `flutter/packages` repo: +https://github.com/flutter/packages/blob/main/CONTRIBUTING.md + +## Package Structure + +This plugin serves as a platform implementation plugin as outlined in [federated plugins](https://docs.flutter.dev/packages-and-plugins/developing-packages#federated-plugins). +The sections below will provide an overview of how this plugin implements this portion with Android. + +For making changes to this package, please take a look at [changing federated plugins](https://github.com/flutter/flutter/blob/master/docs/ecosystem/contributing/README.md#changing-federated-plugins). + +### Quick Overview + +This plugin implements the platform interface provided by `webview_flutter_platform_interface` using +the native WebKit APIs for Android. + +#### SDK Wrappers + +To access native APIS, this plugins uses Dart wrappers of the native library. The native library is +wrapped using using the `ProxyApi` feature from the `pigeon` package. + +The wrappers for the native library can be updated and modified by changing `pigeons/android_webkit.dart`. + +The generated files are located: +* `lib/src/android_webkit.g.dart` +* `android/src/main/java/io/flutter/plugins/webviewflutter/AndroidWebkitLibrary.g.kt` + +To update the wrapper, follow the steps below: + +##### 1. Ensure the project has been built at least once + +Run `flutter build apk --debug` in `example/`. + +##### 2. Make changes to the respective pigeon file that matches the native SDK + +* Android Dependency: https://developer.android.com/reference/android/webkit/package-summary +* Pigeon file to update: `pigeons/android_webkit.dart` + +##### 3. Run the code generator from the terminal + +Run: `dart run pigeon --input pigeons/android_webkit.dart` + +##### 4. Update the generated APIs in native code + +Running the `flutter build` command from step 1 again should provide build errors and indicate what +needs to be done. Alternatively, it can be easier to update native code with the platform's specific +IDE: + +Open `example/android/` in a separate Android Studio project. + +##### 5. Write API tests + +Assuming a non-static method or constructor was added to the native wrapper, a native test will need +to be added. + +Tests location: `android/src/test/java/io/flutter/plugins/webviewflutter/` + +## Important Notes + +### Calling `WebView.destroy()` after Dart Instance is Garbage Collected + +To avoid a potentially breaking change, the code in `android/src/main/java/io/flutter/plugins/webviewflutter/AndroidWebkitLibrary.g.kt` +needs to be updated after the pigeon generator is run. Please add + +```kotlin +val instance: Any? = getInstance(identifier) +if (instance is WebViewProxyApi.WebViewPlatformView) { + instance.destroy() +} +``` + +to `AndroidWebkitLibraryPigeonInstanceManager.remove`. The current implementation of the native +code doesn't currently support handling when the Dart instance is garbage collected. diff --git a/packages/webview_flutter/webview_flutter_android/README.md b/packages/webview_flutter/webview_flutter_android/README.md index 3a5710765bf7..214b50c079ba 100644 --- a/packages/webview_flutter/webview_flutter_android/README.md +++ b/packages/webview_flutter/webview_flutter_android/README.md @@ -73,5 +73,9 @@ androidController.setCustomWidgetCallbacks( ); ``` +## Contributing + +For information on contributing to this plugin, see [`CONTRIBUTING.md`](CONTRIBUTING.md). + [1]: https://pub.dev/packages/webview_flutter [2]: https://flutter.dev/to/endorsed-federated-plugin diff --git a/packages/webview_flutter/webview_flutter_android/android/build.gradle b/packages/webview_flutter/webview_flutter_android/android/build.gradle index 7e453e969046..12c459eaf8b8 100644 --- a/packages/webview_flutter/webview_flutter_android/android/build.gradle +++ b/packages/webview_flutter/webview_flutter_android/android/build.gradle @@ -2,6 +2,7 @@ group 'io.flutter.plugins.webviewflutter' version '1.0-SNAPSHOT' buildscript { + ext.kotlin_version = '1.9.10' repositories { google() mavenCentral() @@ -9,6 +10,7 @@ buildscript { dependencies { classpath 'com.android.tools.build:gradle:8.0.0' + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } @@ -20,11 +22,21 @@ rootProject.allprojects { } apply plugin: 'com.android.library' +apply plugin: 'kotlin-android' android { namespace 'io.flutter.plugins.webviewflutter' compileSdk 34 + compileOptions { + sourceCompatibility JavaVersion.VERSION_11 + targetCompatibility JavaVersion.VERSION_11 + } + + kotlinOptions { + jvmTarget = '11' + } + defaultConfig { minSdkVersion 21 testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" @@ -44,11 +56,6 @@ android { testImplementation 'androidx.test:core:1.3.0' } - compileOptions { - sourceCompatibility JavaVersion.VERSION_11 - targetCompatibility JavaVersion.VERSION_11 - } - testOptions { unitTests.includeAndroidResources = true unitTests.returnDefaultValues = true diff --git a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/AndroidWebkitLibrary.g.kt b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/AndroidWebkitLibrary.g.kt new file mode 100644 index 000000000000..f28082725487 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/AndroidWebkitLibrary.g.kt @@ -0,0 +1,4743 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. +// Autogenerated from Pigeon (v22.5.0), do not edit directly. +// See also: https://pub.dev/packages/pigeon +@file:Suppress("UNCHECKED_CAST", "ArrayInDataClass", "SyntheticAccessor") + +package io.flutter.plugins.webviewflutter + +import android.util.Log +import io.flutter.plugin.common.BasicMessageChannel +import io.flutter.plugin.common.BinaryMessenger +import io.flutter.plugin.common.MessageCodec +import io.flutter.plugin.common.StandardMessageCodec +import java.io.ByteArrayOutputStream +import java.nio.ByteBuffer + +private fun wrapResult(result: Any?): List { + return listOf(result) +} + +private fun wrapError(exception: Throwable): List { + return if (exception is AndroidWebKitError) { + listOf(exception.code, exception.message, exception.details) + } else { + listOf( + exception.javaClass.simpleName, + exception.toString(), + "Cause: " + exception.cause + ", Stacktrace: " + Log.getStackTraceString(exception)) + } +} + +private fun createConnectionError(channelName: String): AndroidWebKitError { + return AndroidWebKitError( + "channel-error", "Unable to establish connection on channel: '$channelName'.", "") +} + +/** + * Error class for passing custom error details to Flutter via a thrown PlatformException. + * + * @property code The error code. + * @property message The error message. + * @property details The error details. Must be a datatype supported by the api codec. + */ +class AndroidWebKitError( + val code: String, + override val message: String? = null, + val details: Any? = null +) : Throwable() +/** + * Maintains instances used to communicate with the corresponding objects in Dart. + * + * Objects stored in this container are represented by an object in Dart that is also stored in an + * InstanceManager with the same identifier. + * + * When an instance is added with an identifier, either can be used to retrieve the other. + * + * Added instances are added as a weak reference and a strong reference. When the strong reference + * is removed with [remove] and the weak reference is deallocated, the + * `finalizationListener.onFinalize` is called with the instance's identifier. However, if the + * strong reference is removed and then the identifier is retrieved with the intention to pass the + * identifier to Dart (e.g. calling [getIdentifierForStrongReference]), the strong reference to the + * instance is recreated. The strong reference will then need to be removed manually again. + */ +@Suppress("UNCHECKED_CAST", "MemberVisibilityCanBePrivate") +class AndroidWebkitLibraryPigeonInstanceManager( + private val finalizationListener: PigeonFinalizationListener +) { + /** Interface for listening when a weak reference of an instance is removed from the manager. */ + interface PigeonFinalizationListener { + fun onFinalize(identifier: Long) + } + + private val identifiers = java.util.WeakHashMap() + private val weakInstances = HashMap>() + private val strongInstances = HashMap() + private val referenceQueue = java.lang.ref.ReferenceQueue() + private val weakReferencesToIdentifiers = HashMap, Long>() + private val handler = android.os.Handler(android.os.Looper.getMainLooper()) + private var nextIdentifier: Long = minHostCreatedIdentifier + private var hasFinalizationListenerStopped = false + + /** + * Modifies the time interval used to define how often this instance removes garbage collected + * weak references to native Android objects that this instance was managing. + */ + var clearFinalizedWeakReferencesInterval: Long = 3000 + set(value) { + handler.removeCallbacks { this.releaseAllFinalizedInstances() } + field = value + releaseAllFinalizedInstances() + } + + init { + handler.postDelayed({ releaseAllFinalizedInstances() }, clearFinalizedWeakReferencesInterval) + } + + companion object { + // Identifiers are locked to a specific range to avoid collisions with objects + // created simultaneously from Dart. + // Host uses identifiers >= 2^16 and Dart is expected to use values n where, + // 0 <= n < 2^16. + private const val minHostCreatedIdentifier: Long = 65536 + private const val tag = "PigeonInstanceManager" + + /** + * Instantiate a new manager with a listener for garbage collected weak references. + * + * When the manager is no longer needed, [stopFinalizationListener] must be called. + */ + fun create( + finalizationListener: PigeonFinalizationListener + ): AndroidWebkitLibraryPigeonInstanceManager { + return AndroidWebkitLibraryPigeonInstanceManager(finalizationListener) + } + } + + /** + * Removes `identifier` and return its associated strongly referenced instance, if present, from + * the manager. + */ + fun remove(identifier: Long): T? { + logWarningIfFinalizationListenerHasStopped() + val instance: Any? = getInstance(identifier) + if (instance is WebViewProxyApi.WebViewPlatformView) { + instance.destroy() + } + return strongInstances.remove(identifier) as T? + } + + /** + * Retrieves the identifier paired with an instance, if present, otherwise `null`. + * + * If the manager contains a strong reference to `instance`, it will return the identifier + * associated with `instance`. If the manager contains only a weak reference to `instance`, a new + * strong reference to `instance` will be added and will need to be removed again with [remove]. + * + * If this method returns a nonnull identifier, this method also expects the Dart + * `AndroidWebkitLibraryPigeonInstanceManager` to have, or recreate, a weak reference to the Dart + * instance the identifier is associated with. + */ + fun getIdentifierForStrongReference(instance: Any?): Long? { + logWarningIfFinalizationListenerHasStopped() + val identifier = identifiers[instance] + if (identifier != null) { + strongInstances[identifier] = instance!! + } + return identifier + } + + /** + * Adds a new instance that was instantiated from Dart. + * + * The same instance can be added multiple times, but each identifier must be unique. This allows + * two objects that are equivalent (e.g. the `equals` method returns true and their hashcodes are + * equal) to both be added. + * + * [identifier] must be >= 0 and unique. + */ + fun addDartCreatedInstance(instance: Any, identifier: Long) { + logWarningIfFinalizationListenerHasStopped() + addInstance(instance, identifier) + } + + /** + * Adds a new unique instance that was instantiated from the host platform. + * + * [identifier] must be >= 0 and unique. + */ + fun addHostCreatedInstance(instance: Any): Long { + logWarningIfFinalizationListenerHasStopped() + require(!containsInstance(instance)) { + "Instance of ${instance.javaClass} has already been added." + } + val identifier = nextIdentifier++ + addInstance(instance, identifier) + return identifier + } + + /** Retrieves the instance associated with identifier, if present, otherwise `null`. */ + fun getInstance(identifier: Long): T? { + logWarningIfFinalizationListenerHasStopped() + val instance = weakInstances[identifier] as java.lang.ref.WeakReference? + return instance?.get() + } + + /** Returns whether this manager contains the given `instance`. */ + fun containsInstance(instance: Any?): Boolean { + logWarningIfFinalizationListenerHasStopped() + return identifiers.containsKey(instance) + } + + /** + * Stops the periodic run of the [PigeonFinalizationListener] for instances that have been garbage + * collected. + * + * The InstanceManager can continue to be used, but the [PigeonFinalizationListener] will no + * longer be called and methods will log a warning. + */ + fun stopFinalizationListener() { + handler.removeCallbacks { this.releaseAllFinalizedInstances() } + hasFinalizationListenerStopped = true + } + + /** + * Removes all of the instances from this manager. + * + * The manager will be empty after this call returns. + */ + fun clear() { + identifiers.clear() + weakInstances.clear() + strongInstances.clear() + weakReferencesToIdentifiers.clear() + } + + /** + * Whether the [PigeonFinalizationListener] is still being called for instances that are garbage + * collected. + * + * See [stopFinalizationListener]. + */ + fun hasFinalizationListenerStopped(): Boolean { + return hasFinalizationListenerStopped + } + + private fun releaseAllFinalizedInstances() { + if (hasFinalizationListenerStopped()) { + return + } + var reference: java.lang.ref.WeakReference? + while ((referenceQueue.poll() as java.lang.ref.WeakReference?).also { reference = it } != + null) { + val identifier = weakReferencesToIdentifiers.remove(reference) + if (identifier != null) { + weakInstances.remove(identifier) + strongInstances.remove(identifier) + finalizationListener.onFinalize(identifier) + } + } + handler.postDelayed({ releaseAllFinalizedInstances() }, clearFinalizedWeakReferencesInterval) + } + + private fun addInstance(instance: Any, identifier: Long) { + require(identifier >= 0) { "Identifier must be >= 0: $identifier" } + require(!weakInstances.containsKey(identifier)) { + "Identifier has already been added: $identifier" + } + val weakReference = java.lang.ref.WeakReference(instance, referenceQueue) + identifiers[instance] = identifier + weakInstances[identifier] = weakReference + weakReferencesToIdentifiers[weakReference] = identifier + strongInstances[identifier] = instance + } + + private fun logWarningIfFinalizationListenerHasStopped() { + if (hasFinalizationListenerStopped()) { + Log.w( + tag, + "The manager was used after calls to the PigeonFinalizationListener has been stopped.") + } + } +} + +/** Generated API for managing the Dart and native `InstanceManager`s. */ +private class AndroidWebkitLibraryPigeonInstanceManagerApi(val binaryMessenger: BinaryMessenger) { + companion object { + /** The codec used by AndroidWebkitLibraryPigeonInstanceManagerApi. */ + val codec: MessageCodec by lazy { AndroidWebkitLibraryPigeonCodec() } + + /** + * Sets up an instance of `AndroidWebkitLibraryPigeonInstanceManagerApi` to handle messages from + * the `binaryMessenger`. + */ + fun setUpMessageHandlers( + binaryMessenger: BinaryMessenger, + instanceManager: AndroidWebkitLibraryPigeonInstanceManager? + ) { + run { + val channel = + BasicMessageChannel( + binaryMessenger, + "dev.flutter.pigeon.webview_flutter_android.PigeonInternalInstanceManager.removeStrongReference", + codec) + if (instanceManager != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val identifierArg = args[0] as Long + val wrapped: List = + try { + instanceManager.remove(identifierArg) + listOf(null) + } catch (exception: Throwable) { + wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = + BasicMessageChannel( + binaryMessenger, + "dev.flutter.pigeon.webview_flutter_android.PigeonInternalInstanceManager.clear", + codec) + if (instanceManager != null) { + channel.setMessageHandler { _, reply -> + val wrapped: List = + try { + instanceManager.clear() + listOf(null) + } catch (exception: Throwable) { + wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + } + } + + fun removeStrongReference(identifierArg: Long, callback: (Result) -> Unit) { + val channelName = + "dev.flutter.pigeon.webview_flutter_android.PigeonInternalInstanceManager.removeStrongReference" + val channel = BasicMessageChannel(binaryMessenger, channelName, codec) + channel.send(listOf(identifierArg)) { + if (it is List<*>) { + if (it.size > 1) { + callback( + Result.failure( + AndroidWebKitError(it[0] as String, it[1] as String, it[2] as String?))) + } else { + callback(Result.success(Unit)) + } + } else { + callback(Result.failure(createConnectionError(channelName))) + } + } + } +} +/** + * Provides implementations for each ProxyApi implementation and provides access to resources needed + * by any implementation. + */ +abstract class AndroidWebkitLibraryPigeonProxyApiRegistrar(val binaryMessenger: BinaryMessenger) { + /** Whether APIs should ignore calling to Dart. */ + public var ignoreCallsToDart = false + val instanceManager: AndroidWebkitLibraryPigeonInstanceManager + private var _codec: MessageCodec? = null + val codec: MessageCodec + get() { + if (_codec == null) { + _codec = AndroidWebkitLibraryPigeonProxyApiBaseCodec(this) + } + return _codec!! + } + + init { + val api = AndroidWebkitLibraryPigeonInstanceManagerApi(binaryMessenger) + instanceManager = + AndroidWebkitLibraryPigeonInstanceManager.create( + object : AndroidWebkitLibraryPigeonInstanceManager.PigeonFinalizationListener { + override fun onFinalize(identifier: Long) { + api.removeStrongReference(identifier) { + if (it.isFailure) { + Log.e( + "PigeonProxyApiRegistrar", + "Failed to remove Dart strong reference with identifier: $identifier") + } + } + } + }) + } + /** + * An implementation of [PigeonApiWebResourceRequest] used to add a new Dart instance of + * `WebResourceRequest` to the Dart `InstanceManager`. + */ + abstract fun getPigeonApiWebResourceRequest(): PigeonApiWebResourceRequest + + /** + * An implementation of [PigeonApiWebResourceResponse] used to add a new Dart instance of + * `WebResourceResponse` to the Dart `InstanceManager`. + */ + abstract fun getPigeonApiWebResourceResponse(): PigeonApiWebResourceResponse + + /** + * An implementation of [PigeonApiWebResourceError] used to add a new Dart instance of + * `WebResourceError` to the Dart `InstanceManager`. + */ + abstract fun getPigeonApiWebResourceError(): PigeonApiWebResourceError + + /** + * An implementation of [PigeonApiWebResourceErrorCompat] used to add a new Dart instance of + * `WebResourceErrorCompat` to the Dart `InstanceManager`. + */ + abstract fun getPigeonApiWebResourceErrorCompat(): PigeonApiWebResourceErrorCompat + + /** + * An implementation of [PigeonApiWebViewPoint] used to add a new Dart instance of `WebViewPoint` + * to the Dart `InstanceManager`. + */ + abstract fun getPigeonApiWebViewPoint(): PigeonApiWebViewPoint + + /** + * An implementation of [PigeonApiConsoleMessage] used to add a new Dart instance of + * `ConsoleMessage` to the Dart `InstanceManager`. + */ + abstract fun getPigeonApiConsoleMessage(): PigeonApiConsoleMessage + + /** + * An implementation of [PigeonApiCookieManager] used to add a new Dart instance of + * `CookieManager` to the Dart `InstanceManager`. + */ + abstract fun getPigeonApiCookieManager(): PigeonApiCookieManager + + /** + * An implementation of [PigeonApiWebView] used to add a new Dart instance of `WebView` to the + * Dart `InstanceManager`. + */ + abstract fun getPigeonApiWebView(): PigeonApiWebView + + /** + * An implementation of [PigeonApiWebSettings] used to add a new Dart instance of `WebSettings` to + * the Dart `InstanceManager`. + */ + abstract fun getPigeonApiWebSettings(): PigeonApiWebSettings + + /** + * An implementation of [PigeonApiJavaScriptChannel] used to add a new Dart instance of + * `JavaScriptChannel` to the Dart `InstanceManager`. + */ + abstract fun getPigeonApiJavaScriptChannel(): PigeonApiJavaScriptChannel + + /** + * An implementation of [PigeonApiWebViewClient] used to add a new Dart instance of + * `WebViewClient` to the Dart `InstanceManager`. + */ + abstract fun getPigeonApiWebViewClient(): PigeonApiWebViewClient + + /** + * An implementation of [PigeonApiDownloadListener] used to add a new Dart instance of + * `DownloadListener` to the Dart `InstanceManager`. + */ + abstract fun getPigeonApiDownloadListener(): PigeonApiDownloadListener + + /** + * An implementation of [PigeonApiWebChromeClient] used to add a new Dart instance of + * `WebChromeClient` to the Dart `InstanceManager`. + */ + abstract fun getPigeonApiWebChromeClient(): PigeonApiWebChromeClient + + /** + * An implementation of [PigeonApiFlutterAssetManager] used to add a new Dart instance of + * `FlutterAssetManager` to the Dart `InstanceManager`. + */ + abstract fun getPigeonApiFlutterAssetManager(): PigeonApiFlutterAssetManager + + /** + * An implementation of [PigeonApiWebStorage] used to add a new Dart instance of `WebStorage` to + * the Dart `InstanceManager`. + */ + abstract fun getPigeonApiWebStorage(): PigeonApiWebStorage + + /** + * An implementation of [PigeonApiFileChooserParams] used to add a new Dart instance of + * `FileChooserParams` to the Dart `InstanceManager`. + */ + abstract fun getPigeonApiFileChooserParams(): PigeonApiFileChooserParams + + /** + * An implementation of [PigeonApiPermissionRequest] used to add a new Dart instance of + * `PermissionRequest` to the Dart `InstanceManager`. + */ + abstract fun getPigeonApiPermissionRequest(): PigeonApiPermissionRequest + + /** + * An implementation of [PigeonApiCustomViewCallback] used to add a new Dart instance of + * `CustomViewCallback` to the Dart `InstanceManager`. + */ + abstract fun getPigeonApiCustomViewCallback(): PigeonApiCustomViewCallback + + /** + * An implementation of [PigeonApiView] used to add a new Dart instance of `View` to the Dart + * `InstanceManager`. + */ + abstract fun getPigeonApiView(): PigeonApiView + + /** + * An implementation of [PigeonApiGeolocationPermissionsCallback] used to add a new Dart instance + * of `GeolocationPermissionsCallback` to the Dart `InstanceManager`. + */ + abstract fun getPigeonApiGeolocationPermissionsCallback(): PigeonApiGeolocationPermissionsCallback + + /** + * An implementation of [PigeonApiHttpAuthHandler] used to add a new Dart instance of + * `HttpAuthHandler` to the Dart `InstanceManager`. + */ + abstract fun getPigeonApiHttpAuthHandler(): PigeonApiHttpAuthHandler + + fun setUp() { + AndroidWebkitLibraryPigeonInstanceManagerApi.setUpMessageHandlers( + binaryMessenger, instanceManager) + PigeonApiCookieManager.setUpMessageHandlers(binaryMessenger, getPigeonApiCookieManager()) + PigeonApiWebView.setUpMessageHandlers(binaryMessenger, getPigeonApiWebView()) + PigeonApiWebSettings.setUpMessageHandlers(binaryMessenger, getPigeonApiWebSettings()) + PigeonApiJavaScriptChannel.setUpMessageHandlers( + binaryMessenger, getPigeonApiJavaScriptChannel()) + PigeonApiWebViewClient.setUpMessageHandlers(binaryMessenger, getPigeonApiWebViewClient()) + PigeonApiDownloadListener.setUpMessageHandlers(binaryMessenger, getPigeonApiDownloadListener()) + PigeonApiWebChromeClient.setUpMessageHandlers(binaryMessenger, getPigeonApiWebChromeClient()) + PigeonApiFlutterAssetManager.setUpMessageHandlers( + binaryMessenger, getPigeonApiFlutterAssetManager()) + PigeonApiWebStorage.setUpMessageHandlers(binaryMessenger, getPigeonApiWebStorage()) + PigeonApiPermissionRequest.setUpMessageHandlers( + binaryMessenger, getPigeonApiPermissionRequest()) + PigeonApiCustomViewCallback.setUpMessageHandlers( + binaryMessenger, getPigeonApiCustomViewCallback()) + PigeonApiView.setUpMessageHandlers(binaryMessenger, getPigeonApiView()) + PigeonApiGeolocationPermissionsCallback.setUpMessageHandlers( + binaryMessenger, getPigeonApiGeolocationPermissionsCallback()) + PigeonApiHttpAuthHandler.setUpMessageHandlers(binaryMessenger, getPigeonApiHttpAuthHandler()) + } + + fun tearDown() { + AndroidWebkitLibraryPigeonInstanceManagerApi.setUpMessageHandlers(binaryMessenger, null) + PigeonApiCookieManager.setUpMessageHandlers(binaryMessenger, null) + PigeonApiWebView.setUpMessageHandlers(binaryMessenger, null) + PigeonApiWebSettings.setUpMessageHandlers(binaryMessenger, null) + PigeonApiJavaScriptChannel.setUpMessageHandlers(binaryMessenger, null) + PigeonApiWebViewClient.setUpMessageHandlers(binaryMessenger, null) + PigeonApiDownloadListener.setUpMessageHandlers(binaryMessenger, null) + PigeonApiWebChromeClient.setUpMessageHandlers(binaryMessenger, null) + PigeonApiFlutterAssetManager.setUpMessageHandlers(binaryMessenger, null) + PigeonApiWebStorage.setUpMessageHandlers(binaryMessenger, null) + PigeonApiPermissionRequest.setUpMessageHandlers(binaryMessenger, null) + PigeonApiCustomViewCallback.setUpMessageHandlers(binaryMessenger, null) + PigeonApiView.setUpMessageHandlers(binaryMessenger, null) + PigeonApiGeolocationPermissionsCallback.setUpMessageHandlers(binaryMessenger, null) + PigeonApiHttpAuthHandler.setUpMessageHandlers(binaryMessenger, null) + } +} + +private class AndroidWebkitLibraryPigeonProxyApiBaseCodec( + val registrar: AndroidWebkitLibraryPigeonProxyApiRegistrar +) : AndroidWebkitLibraryPigeonCodec() { + override fun readValueOfType(type: Byte, buffer: ByteBuffer): Any? { + return when (type) { + 128.toByte() -> { + return registrar.instanceManager.getInstance(readValue(buffer) as Long) + } + else -> super.readValueOfType(type, buffer) + } + } + + override fun writeValue(stream: ByteArrayOutputStream, value: Any?) { + if (value is Boolean || + value is ByteArray || + value is Double || + value is DoubleArray || + value is FloatArray || + value is Int || + value is IntArray || + value is List<*> || + value is Long || + value is LongArray || + value is Map<*, *> || + value is String || + value is FileChooserMode || + value is ConsoleMessageLevel || + value == null) { + super.writeValue(stream, value) + return + } + + if (value is android.webkit.WebResourceRequest) { + registrar.getPigeonApiWebResourceRequest().pigeon_newInstance(value) {} + } else if (value is android.webkit.WebResourceResponse) { + registrar.getPigeonApiWebResourceResponse().pigeon_newInstance(value) {} + } else if (android.os.Build.VERSION.SDK_INT >= 23 && value is android.webkit.WebResourceError) { + registrar.getPigeonApiWebResourceError().pigeon_newInstance(value) {} + } else if (value is androidx.webkit.WebResourceErrorCompat) { + registrar.getPigeonApiWebResourceErrorCompat().pigeon_newInstance(value) {} + } else if (value is WebViewPoint) { + registrar.getPigeonApiWebViewPoint().pigeon_newInstance(value) {} + } else if (value is android.webkit.ConsoleMessage) { + registrar.getPigeonApiConsoleMessage().pigeon_newInstance(value) {} + } else if (value is android.webkit.CookieManager) { + registrar.getPigeonApiCookieManager().pigeon_newInstance(value) {} + } else if (value is android.webkit.WebView) { + registrar.getPigeonApiWebView().pigeon_newInstance(value) {} + } else if (value is android.webkit.WebSettings) { + registrar.getPigeonApiWebSettings().pigeon_newInstance(value) {} + } else if (value is JavaScriptChannel) { + registrar.getPigeonApiJavaScriptChannel().pigeon_newInstance(value) {} + } else if (value is android.webkit.WebViewClient) { + registrar.getPigeonApiWebViewClient().pigeon_newInstance(value) {} + } else if (value is android.webkit.DownloadListener) { + registrar.getPigeonApiDownloadListener().pigeon_newInstance(value) {} + } else if (value + is io.flutter.plugins.webviewflutter.WebChromeClientProxyApi.WebChromeClientImpl) { + registrar.getPigeonApiWebChromeClient().pigeon_newInstance(value) {} + } else if (value is io.flutter.plugins.webviewflutter.FlutterAssetManager) { + registrar.getPigeonApiFlutterAssetManager().pigeon_newInstance(value) {} + } else if (value is android.webkit.WebStorage) { + registrar.getPigeonApiWebStorage().pigeon_newInstance(value) {} + } else if (value is android.webkit.WebChromeClient.FileChooserParams) { + registrar.getPigeonApiFileChooserParams().pigeon_newInstance(value) {} + } else if (value is android.webkit.PermissionRequest) { + registrar.getPigeonApiPermissionRequest().pigeon_newInstance(value) {} + } else if (value is android.webkit.WebChromeClient.CustomViewCallback) { + registrar.getPigeonApiCustomViewCallback().pigeon_newInstance(value) {} + } else if (value is android.view.View) { + registrar.getPigeonApiView().pigeon_newInstance(value) {} + } else if (value is android.webkit.GeolocationPermissions.Callback) { + registrar.getPigeonApiGeolocationPermissionsCallback().pigeon_newInstance(value) {} + } else if (value is android.webkit.HttpAuthHandler) { + registrar.getPigeonApiHttpAuthHandler().pigeon_newInstance(value) {} + } + + when { + registrar.instanceManager.containsInstance(value) -> { + stream.write(128) + writeValue(stream, registrar.instanceManager.getIdentifierForStrongReference(value)) + } + else -> + throw IllegalArgumentException( + "Unsupported value: '$value' of type '${value.javaClass.name}'") + } + } +} + +/** + * Mode of how to select files for a file chooser. + * + * See https://developer.android.com/reference/android/webkit/WebChromeClient.FileChooserParams. + */ +enum class FileChooserMode(val raw: Int) { + /** + * Open single file and requires that the file exists before allowing the user to pick it. + * + * See + * https://developer.android.com/reference/android/webkit/WebChromeClient.FileChooserParams#MODE_OPEN. + */ + OPEN(0), + /** + * Similar to [open] but allows multiple files to be selected. + * + * See + * https://developer.android.com/reference/android/webkit/WebChromeClient.FileChooserParams#MODE_OPEN_MULTIPLE. + */ + OPEN_MULTIPLE(1), + /** + * Allows picking a nonexistent file and saving it. + * + * See + * https://developer.android.com/reference/android/webkit/WebChromeClient.FileChooserParams#MODE_SAVE. + */ + SAVE(2), + /** + * Indicates a `FileChooserMode` with an unknown mode. + * + * This does not represent an actual value provided by the platform and only indicates a value was + * provided that isn't currently supported. + */ + UNKNOWN(3); + + companion object { + fun ofRaw(raw: Int): FileChooserMode? { + return values().firstOrNull { it.raw == raw } + } + } +} + +/** + * Indicates the type of message logged to the console. + * + * See https://developer.android.com/reference/android/webkit/ConsoleMessage.MessageLevel. + */ +enum class ConsoleMessageLevel(val raw: Int) { + /** + * Indicates a message is logged for debugging. + * + * See https://developer.android.com/reference/android/webkit/ConsoleMessage.MessageLevel#DEBUG. + */ + DEBUG(0), + /** + * Indicates a message is provided as an error. + * + * See https://developer.android.com/reference/android/webkit/ConsoleMessage.MessageLevel#ERROR. + */ + ERROR(1), + /** + * Indicates a message is provided as a basic log message. + * + * See https://developer.android.com/reference/android/webkit/ConsoleMessage.MessageLevel#LOG. + */ + LOG(2), + /** + * Indicates a message is provided as a tip. + * + * See https://developer.android.com/reference/android/webkit/ConsoleMessage.MessageLevel#TIP. + */ + TIP(3), + /** + * Indicates a message is provided as a warning. + * + * See https://developer.android.com/reference/android/webkit/ConsoleMessage.MessageLevel#WARNING. + */ + WARNING(4), + /** + * Indicates a message with an unknown level. + * + * This does not represent an actual value provided by the platform and only indicates a value was + * provided that isn't currently supported. + */ + UNKNOWN(5); + + companion object { + fun ofRaw(raw: Int): ConsoleMessageLevel? { + return values().firstOrNull { it.raw == raw } + } + } +} + +private open class AndroidWebkitLibraryPigeonCodec : StandardMessageCodec() { + override fun readValueOfType(type: Byte, buffer: ByteBuffer): Any? { + return when (type) { + 129.toByte() -> { + return (readValue(buffer) as Long?)?.let { FileChooserMode.ofRaw(it.toInt()) } + } + 130.toByte() -> { + return (readValue(buffer) as Long?)?.let { ConsoleMessageLevel.ofRaw(it.toInt()) } + } + else -> super.readValueOfType(type, buffer) + } + } + + override fun writeValue(stream: ByteArrayOutputStream, value: Any?) { + when (value) { + is FileChooserMode -> { + stream.write(129) + writeValue(stream, value.raw) + } + is ConsoleMessageLevel -> { + stream.write(130) + writeValue(stream, value.raw) + } + else -> super.writeValue(stream, value) + } + } +} + +/** + * Encompasses parameters to the `WebViewClient.shouldInterceptRequest` method. + * + * See https://developer.android.com/reference/android/webkit/WebResourceRequest. + */ +@Suppress("UNCHECKED_CAST") +abstract class PigeonApiWebResourceRequest( + open val pigeonRegistrar: AndroidWebkitLibraryPigeonProxyApiRegistrar +) { + /** The URL for which the resource request was made. */ + abstract fun url(pigeon_instance: android.webkit.WebResourceRequest): String + + /** Whether the request was made in order to fetch the main frame's document. */ + abstract fun isForMainFrame(pigeon_instance: android.webkit.WebResourceRequest): Boolean + + /** Whether the request was a result of a server-side redirect. */ + abstract fun isRedirect(pigeon_instance: android.webkit.WebResourceRequest): Boolean? + + /** Whether a gesture (such as a click) was associated with the request. */ + abstract fun hasGesture(pigeon_instance: android.webkit.WebResourceRequest): Boolean + + /** The method associated with the request, for example "GET". */ + abstract fun method(pigeon_instance: android.webkit.WebResourceRequest): String + + /** The headers associated with the request. */ + abstract fun requestHeaders( + pigeon_instance: android.webkit.WebResourceRequest + ): Map? + + @Suppress("LocalVariableName", "FunctionName") + /** Creates a Dart instance of WebResourceRequest and attaches it to [pigeon_instanceArg]. */ + fun pigeon_newInstance( + pigeon_instanceArg: android.webkit.WebResourceRequest, + callback: (Result) -> Unit + ) { + if (pigeonRegistrar.ignoreCallsToDart) { + callback( + Result.failure( + AndroidWebKitError("ignore-calls-error", "Calls to Dart are being ignored.", ""))) + return + } + if (pigeonRegistrar.instanceManager.containsInstance(pigeon_instanceArg)) { + Result.success(Unit) + return + } + val pigeon_identifierArg = + pigeonRegistrar.instanceManager.addHostCreatedInstance(pigeon_instanceArg) + val urlArg = url(pigeon_instanceArg) + val isForMainFrameArg = isForMainFrame(pigeon_instanceArg) + val isRedirectArg = isRedirect(pigeon_instanceArg) + val hasGestureArg = hasGesture(pigeon_instanceArg) + val methodArg = method(pigeon_instanceArg) + val requestHeadersArg = requestHeaders(pigeon_instanceArg) + val binaryMessenger = pigeonRegistrar.binaryMessenger + val codec = pigeonRegistrar.codec + val channelName = + "dev.flutter.pigeon.webview_flutter_android.WebResourceRequest.pigeon_newInstance" + val channel = BasicMessageChannel(binaryMessenger, channelName, codec) + channel.send( + listOf( + pigeon_identifierArg, + urlArg, + isForMainFrameArg, + isRedirectArg, + hasGestureArg, + methodArg, + requestHeadersArg)) { + if (it is List<*>) { + if (it.size > 1) { + callback( + Result.failure( + AndroidWebKitError(it[0] as String, it[1] as String, it[2] as String?))) + } else { + callback(Result.success(Unit)) + } + } else { + callback(Result.failure(createConnectionError(channelName))) + } + } + } +} +/** + * Encapsulates a resource response. + * + * See https://developer.android.com/reference/android/webkit/WebResourceResponse. + */ +@Suppress("UNCHECKED_CAST") +abstract class PigeonApiWebResourceResponse( + open val pigeonRegistrar: AndroidWebkitLibraryPigeonProxyApiRegistrar +) { + /** The resource response's status code. */ + abstract fun statusCode(pigeon_instance: android.webkit.WebResourceResponse): Long + + @Suppress("LocalVariableName", "FunctionName") + /** Creates a Dart instance of WebResourceResponse and attaches it to [pigeon_instanceArg]. */ + fun pigeon_newInstance( + pigeon_instanceArg: android.webkit.WebResourceResponse, + callback: (Result) -> Unit + ) { + if (pigeonRegistrar.ignoreCallsToDart) { + callback( + Result.failure( + AndroidWebKitError("ignore-calls-error", "Calls to Dart are being ignored.", ""))) + return + } + if (pigeonRegistrar.instanceManager.containsInstance(pigeon_instanceArg)) { + Result.success(Unit) + return + } + val pigeon_identifierArg = + pigeonRegistrar.instanceManager.addHostCreatedInstance(pigeon_instanceArg) + val statusCodeArg = statusCode(pigeon_instanceArg) + val binaryMessenger = pigeonRegistrar.binaryMessenger + val codec = pigeonRegistrar.codec + val channelName = + "dev.flutter.pigeon.webview_flutter_android.WebResourceResponse.pigeon_newInstance" + val channel = BasicMessageChannel(binaryMessenger, channelName, codec) + channel.send(listOf(pigeon_identifierArg, statusCodeArg)) { + if (it is List<*>) { + if (it.size > 1) { + callback( + Result.failure( + AndroidWebKitError(it[0] as String, it[1] as String, it[2] as String?))) + } else { + callback(Result.success(Unit)) + } + } else { + callback(Result.failure(createConnectionError(channelName))) + } + } + } +} +/** + * Encapsulates information about errors that occurred during loading of web resources. + * + * See https://developer.android.com/reference/android/webkit/WebResourceError. + */ +@Suppress("UNCHECKED_CAST") +abstract class PigeonApiWebResourceError( + open val pigeonRegistrar: AndroidWebkitLibraryPigeonProxyApiRegistrar +) { + /** The error code of the error. */ + @androidx.annotation.RequiresApi(api = 23) + abstract fun errorCode(pigeon_instance: android.webkit.WebResourceError): Long + + /** The string describing the error. */ + @androidx.annotation.RequiresApi(api = 23) + abstract fun description(pigeon_instance: android.webkit.WebResourceError): String + + @Suppress("LocalVariableName", "FunctionName") + /** Creates a Dart instance of WebResourceError and attaches it to [pigeon_instanceArg]. */ + @androidx.annotation.RequiresApi(api = 23) + fun pigeon_newInstance( + pigeon_instanceArg: android.webkit.WebResourceError, + callback: (Result) -> Unit + ) { + if (pigeonRegistrar.ignoreCallsToDart) { + callback( + Result.failure( + AndroidWebKitError("ignore-calls-error", "Calls to Dart are being ignored.", ""))) + return + } + if (pigeonRegistrar.instanceManager.containsInstance(pigeon_instanceArg)) { + Result.success(Unit) + return + } + val pigeon_identifierArg = + pigeonRegistrar.instanceManager.addHostCreatedInstance(pigeon_instanceArg) + val errorCodeArg = errorCode(pigeon_instanceArg) + val descriptionArg = description(pigeon_instanceArg) + val binaryMessenger = pigeonRegistrar.binaryMessenger + val codec = pigeonRegistrar.codec + val channelName = + "dev.flutter.pigeon.webview_flutter_android.WebResourceError.pigeon_newInstance" + val channel = BasicMessageChannel(binaryMessenger, channelName, codec) + channel.send(listOf(pigeon_identifierArg, errorCodeArg, descriptionArg)) { + if (it is List<*>) { + if (it.size > 1) { + callback( + Result.failure( + AndroidWebKitError(it[0] as String, it[1] as String, it[2] as String?))) + } else { + callback(Result.success(Unit)) + } + } else { + callback(Result.failure(createConnectionError(channelName))) + } + } + } +} +/** + * Encapsulates information about errors that occurred during loading of web resources. + * + * See https://developer.android.com/reference/androidx/webkit/WebResourceErrorCompat. + */ +@Suppress("UNCHECKED_CAST") +abstract class PigeonApiWebResourceErrorCompat( + open val pigeonRegistrar: AndroidWebkitLibraryPigeonProxyApiRegistrar +) { + /** The error code of the error. */ + abstract fun errorCode(pigeon_instance: androidx.webkit.WebResourceErrorCompat): Long + + /** The string describing the error. */ + abstract fun description(pigeon_instance: androidx.webkit.WebResourceErrorCompat): String + + @Suppress("LocalVariableName", "FunctionName") + /** Creates a Dart instance of WebResourceErrorCompat and attaches it to [pigeon_instanceArg]. */ + fun pigeon_newInstance( + pigeon_instanceArg: androidx.webkit.WebResourceErrorCompat, + callback: (Result) -> Unit + ) { + if (pigeonRegistrar.ignoreCallsToDart) { + callback( + Result.failure( + AndroidWebKitError("ignore-calls-error", "Calls to Dart are being ignored.", ""))) + return + } + if (pigeonRegistrar.instanceManager.containsInstance(pigeon_instanceArg)) { + Result.success(Unit) + return + } + val pigeon_identifierArg = + pigeonRegistrar.instanceManager.addHostCreatedInstance(pigeon_instanceArg) + val errorCodeArg = errorCode(pigeon_instanceArg) + val descriptionArg = description(pigeon_instanceArg) + val binaryMessenger = pigeonRegistrar.binaryMessenger + val codec = pigeonRegistrar.codec + val channelName = + "dev.flutter.pigeon.webview_flutter_android.WebResourceErrorCompat.pigeon_newInstance" + val channel = BasicMessageChannel(binaryMessenger, channelName, codec) + channel.send(listOf(pigeon_identifierArg, errorCodeArg, descriptionArg)) { + if (it is List<*>) { + if (it.size > 1) { + callback( + Result.failure( + AndroidWebKitError(it[0] as String, it[1] as String, it[2] as String?))) + } else { + callback(Result.success(Unit)) + } + } else { + callback(Result.failure(createConnectionError(channelName))) + } + } + } +} +/** + * Represents a position on a web page. + * + * This is a custom class created for convenience of the wrapper. + */ +@Suppress("UNCHECKED_CAST") +abstract class PigeonApiWebViewPoint( + open val pigeonRegistrar: AndroidWebkitLibraryPigeonProxyApiRegistrar +) { + abstract fun x(pigeon_instance: WebViewPoint): Long + + abstract fun y(pigeon_instance: WebViewPoint): Long + + @Suppress("LocalVariableName", "FunctionName") + /** Creates a Dart instance of WebViewPoint and attaches it to [pigeon_instanceArg]. */ + fun pigeon_newInstance(pigeon_instanceArg: WebViewPoint, callback: (Result) -> Unit) { + if (pigeonRegistrar.ignoreCallsToDart) { + callback( + Result.failure( + AndroidWebKitError("ignore-calls-error", "Calls to Dart are being ignored.", ""))) + return + } + if (pigeonRegistrar.instanceManager.containsInstance(pigeon_instanceArg)) { + Result.success(Unit) + return + } + val pigeon_identifierArg = + pigeonRegistrar.instanceManager.addHostCreatedInstance(pigeon_instanceArg) + val xArg = x(pigeon_instanceArg) + val yArg = y(pigeon_instanceArg) + val binaryMessenger = pigeonRegistrar.binaryMessenger + val codec = pigeonRegistrar.codec + val channelName = "dev.flutter.pigeon.webview_flutter_android.WebViewPoint.pigeon_newInstance" + val channel = BasicMessageChannel(binaryMessenger, channelName, codec) + channel.send(listOf(pigeon_identifierArg, xArg, yArg)) { + if (it is List<*>) { + if (it.size > 1) { + callback( + Result.failure( + AndroidWebKitError(it[0] as String, it[1] as String, it[2] as String?))) + } else { + callback(Result.success(Unit)) + } + } else { + callback(Result.failure(createConnectionError(channelName))) + } + } + } +} +/** + * Represents a JavaScript console message from WebCore. + * + * See https://developer.android.com/reference/android/webkit/ConsoleMessage + */ +@Suppress("UNCHECKED_CAST") +abstract class PigeonApiConsoleMessage( + open val pigeonRegistrar: AndroidWebkitLibraryPigeonProxyApiRegistrar +) { + abstract fun lineNumber(pigeon_instance: android.webkit.ConsoleMessage): Long + + abstract fun message(pigeon_instance: android.webkit.ConsoleMessage): String + + abstract fun level(pigeon_instance: android.webkit.ConsoleMessage): ConsoleMessageLevel + + abstract fun sourceId(pigeon_instance: android.webkit.ConsoleMessage): String + + @Suppress("LocalVariableName", "FunctionName") + /** Creates a Dart instance of ConsoleMessage and attaches it to [pigeon_instanceArg]. */ + fun pigeon_newInstance( + pigeon_instanceArg: android.webkit.ConsoleMessage, + callback: (Result) -> Unit + ) { + if (pigeonRegistrar.ignoreCallsToDart) { + callback( + Result.failure( + AndroidWebKitError("ignore-calls-error", "Calls to Dart are being ignored.", ""))) + return + } + if (pigeonRegistrar.instanceManager.containsInstance(pigeon_instanceArg)) { + Result.success(Unit) + return + } + val pigeon_identifierArg = + pigeonRegistrar.instanceManager.addHostCreatedInstance(pigeon_instanceArg) + val lineNumberArg = lineNumber(pigeon_instanceArg) + val messageArg = message(pigeon_instanceArg) + val levelArg = level(pigeon_instanceArg) + val sourceIdArg = sourceId(pigeon_instanceArg) + val binaryMessenger = pigeonRegistrar.binaryMessenger + val codec = pigeonRegistrar.codec + val channelName = "dev.flutter.pigeon.webview_flutter_android.ConsoleMessage.pigeon_newInstance" + val channel = BasicMessageChannel(binaryMessenger, channelName, codec) + channel.send(listOf(pigeon_identifierArg, lineNumberArg, messageArg, levelArg, sourceIdArg)) { + if (it is List<*>) { + if (it.size > 1) { + callback( + Result.failure( + AndroidWebKitError(it[0] as String, it[1] as String, it[2] as String?))) + } else { + callback(Result.success(Unit)) + } + } else { + callback(Result.failure(createConnectionError(channelName))) + } + } + } +} +/** + * Manages the cookies used by an application's `WebView` instances. + * + * See https://developer.android.com/reference/android/webkit/CookieManager. + */ +@Suppress("UNCHECKED_CAST") +abstract class PigeonApiCookieManager( + open val pigeonRegistrar: AndroidWebkitLibraryPigeonProxyApiRegistrar +) { + abstract fun instance(): android.webkit.CookieManager + + /** Sets a single cookie (key-value pair) for the given URL. */ + abstract fun setCookie(pigeon_instance: android.webkit.CookieManager, url: String, value: String) + + /** Removes all cookies. */ + abstract fun removeAllCookies( + pigeon_instance: android.webkit.CookieManager, + callback: (Result) -> Unit + ) + + /** Sets whether the `WebView` should allow third party cookies to be set. */ + abstract fun setAcceptThirdPartyCookies( + pigeon_instance: android.webkit.CookieManager, + webView: android.webkit.WebView, + accept: Boolean + ) + + companion object { + @Suppress("LocalVariableName") + fun setUpMessageHandlers(binaryMessenger: BinaryMessenger, api: PigeonApiCookieManager?) { + val codec = api?.pigeonRegistrar?.codec ?: AndroidWebkitLibraryPigeonCodec() + run { + val channel = + BasicMessageChannel( + binaryMessenger, + "dev.flutter.pigeon.webview_flutter_android.CookieManager.instance", + codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val pigeon_identifierArg = args[0] as Long + val wrapped: List = + try { + api.pigeonRegistrar.instanceManager.addDartCreatedInstance( + api.instance(), pigeon_identifierArg) + listOf(null) + } catch (exception: Throwable) { + wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = + BasicMessageChannel( + binaryMessenger, + "dev.flutter.pigeon.webview_flutter_android.CookieManager.setCookie", + codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val pigeon_instanceArg = args[0] as android.webkit.CookieManager + val urlArg = args[1] as String + val valueArg = args[2] as String + val wrapped: List = + try { + api.setCookie(pigeon_instanceArg, urlArg, valueArg) + listOf(null) + } catch (exception: Throwable) { + wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = + BasicMessageChannel( + binaryMessenger, + "dev.flutter.pigeon.webview_flutter_android.CookieManager.removeAllCookies", + codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val pigeon_instanceArg = args[0] as android.webkit.CookieManager + api.removeAllCookies(pigeon_instanceArg) { result: Result -> + val error = result.exceptionOrNull() + if (error != null) { + reply.reply(wrapError(error)) + } else { + val data = result.getOrNull() + reply.reply(wrapResult(data)) + } + } + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = + BasicMessageChannel( + binaryMessenger, + "dev.flutter.pigeon.webview_flutter_android.CookieManager.setAcceptThirdPartyCookies", + codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val pigeon_instanceArg = args[0] as android.webkit.CookieManager + val webViewArg = args[1] as android.webkit.WebView + val acceptArg = args[2] as Boolean + val wrapped: List = + try { + api.setAcceptThirdPartyCookies(pigeon_instanceArg, webViewArg, acceptArg) + listOf(null) + } catch (exception: Throwable) { + wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + } + } + + @Suppress("LocalVariableName", "FunctionName") + /** Creates a Dart instance of CookieManager and attaches it to [pigeon_instanceArg]. */ + fun pigeon_newInstance( + pigeon_instanceArg: android.webkit.CookieManager, + callback: (Result) -> Unit + ) { + if (pigeonRegistrar.ignoreCallsToDart) { + callback( + Result.failure( + AndroidWebKitError("ignore-calls-error", "Calls to Dart are being ignored.", ""))) + return + } + if (pigeonRegistrar.instanceManager.containsInstance(pigeon_instanceArg)) { + Result.success(Unit) + return + } + val pigeon_identifierArg = + pigeonRegistrar.instanceManager.addHostCreatedInstance(pigeon_instanceArg) + val binaryMessenger = pigeonRegistrar.binaryMessenger + val codec = pigeonRegistrar.codec + val channelName = "dev.flutter.pigeon.webview_flutter_android.CookieManager.pigeon_newInstance" + val channel = BasicMessageChannel(binaryMessenger, channelName, codec) + channel.send(listOf(pigeon_identifierArg)) { + if (it is List<*>) { + if (it.size > 1) { + callback( + Result.failure( + AndroidWebKitError(it[0] as String, it[1] as String, it[2] as String?))) + } else { + callback(Result.success(Unit)) + } + } else { + callback(Result.failure(createConnectionError(channelName))) + } + } + } +} +/** + * A View that displays web pages. + * + * See https://developer.android.com/reference/android/webkit/WebView. + */ +@Suppress("UNCHECKED_CAST") +abstract class PigeonApiWebView( + open val pigeonRegistrar: AndroidWebkitLibraryPigeonProxyApiRegistrar +) { + abstract fun pigeon_defaultConstructor(): android.webkit.WebView + + /** The WebSettings object used to control the settings for this WebView. */ + abstract fun settings(pigeon_instance: android.webkit.WebView): android.webkit.WebSettings + + /** Loads the given data into this WebView using a 'data' scheme URL. */ + abstract fun loadData( + pigeon_instance: android.webkit.WebView, + data: String, + mimeType: String?, + encoding: String? + ) + + /** Loads the given data into this WebView, using baseUrl as the base URL for the content. */ + abstract fun loadDataWithBaseUrl( + pigeon_instance: android.webkit.WebView, + baseUrl: String?, + data: String, + mimeType: String?, + encoding: String?, + historyUrl: String? + ) + + /** Loads the given URL. */ + abstract fun loadUrl( + pigeon_instance: android.webkit.WebView, + url: String, + headers: Map + ) + + /** Loads the URL with postData using "POST" method into this WebView. */ + abstract fun postUrl(pigeon_instance: android.webkit.WebView, url: String, data: ByteArray) + + /** Gets the URL for the current page. */ + abstract fun getUrl(pigeon_instance: android.webkit.WebView): String? + + /** Gets whether this WebView has a back history item. */ + abstract fun canGoBack(pigeon_instance: android.webkit.WebView): Boolean + + /** Gets whether this WebView has a forward history item. */ + abstract fun canGoForward(pigeon_instance: android.webkit.WebView): Boolean + + /** Goes back in the history of this WebView. */ + abstract fun goBack(pigeon_instance: android.webkit.WebView) + + /** Goes forward in the history of this WebView. */ + abstract fun goForward(pigeon_instance: android.webkit.WebView) + + /** Reloads the current URL. */ + abstract fun reload(pigeon_instance: android.webkit.WebView) + + /** Clears the resource cache. */ + abstract fun clearCache(pigeon_instance: android.webkit.WebView, includeDiskFiles: Boolean) + + /** Asynchronously evaluates JavaScript in the context of the currently displayed page. */ + abstract fun evaluateJavascript( + pigeon_instance: android.webkit.WebView, + javascriptString: String, + callback: (Result) -> Unit + ) + + /** Gets the title for the current page. */ + abstract fun getTitle(pigeon_instance: android.webkit.WebView): String? + + /** + * Enables debugging of web contents (HTML / CSS / JavaScript) loaded into any WebViews of this + * application. + */ + abstract fun setWebContentsDebuggingEnabled(enabled: Boolean) + + /** Sets the WebViewClient that will receive various notifications and requests. */ + abstract fun setWebViewClient( + pigeon_instance: android.webkit.WebView, + client: android.webkit.WebViewClient? + ) + + /** Injects the supplied Java object into this WebView. */ + abstract fun addJavaScriptChannel( + pigeon_instance: android.webkit.WebView, + channel: JavaScriptChannel + ) + + /** Removes a previously injected Java object from this WebView. */ + abstract fun removeJavaScriptChannel(pigeon_instance: android.webkit.WebView, name: String) + + /** + * Registers the interface to be used when content can not be handled by the rendering engine, and + * should be downloaded instead. + */ + abstract fun setDownloadListener( + pigeon_instance: android.webkit.WebView, + listener: android.webkit.DownloadListener? + ) + + /** Sets the chrome handler. */ + abstract fun setWebChromeClient( + pigeon_instance: android.webkit.WebView, + client: io.flutter.plugins.webviewflutter.WebChromeClientProxyApi.WebChromeClientImpl? + ) + + /** Sets the background color for this view. */ + abstract fun setBackgroundColor(pigeon_instance: android.webkit.WebView, color: Long) + + /** Destroys the internal state of this WebView. */ + abstract fun destroy(pigeon_instance: android.webkit.WebView) + + companion object { + @Suppress("LocalVariableName") + fun setUpMessageHandlers(binaryMessenger: BinaryMessenger, api: PigeonApiWebView?) { + val codec = api?.pigeonRegistrar?.codec ?: AndroidWebkitLibraryPigeonCodec() + run { + val channel = + BasicMessageChannel( + binaryMessenger, + "dev.flutter.pigeon.webview_flutter_android.WebView.pigeon_defaultConstructor", + codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val pigeon_identifierArg = args[0] as Long + val wrapped: List = + try { + api.pigeonRegistrar.instanceManager.addDartCreatedInstance( + api.pigeon_defaultConstructor(), pigeon_identifierArg) + listOf(null) + } catch (exception: Throwable) { + wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = + BasicMessageChannel( + binaryMessenger, + "dev.flutter.pigeon.webview_flutter_android.WebView.settings", + codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val pigeon_instanceArg = args[0] as android.webkit.WebView + val pigeon_identifierArg = args[1] as Long + val wrapped: List = + try { + api.pigeonRegistrar.instanceManager.addDartCreatedInstance( + api.settings(pigeon_instanceArg), pigeon_identifierArg) + listOf(null) + } catch (exception: Throwable) { + wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = + BasicMessageChannel( + binaryMessenger, + "dev.flutter.pigeon.webview_flutter_android.WebView.loadData", + codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val pigeon_instanceArg = args[0] as android.webkit.WebView + val dataArg = args[1] as String + val mimeTypeArg = args[2] as String? + val encodingArg = args[3] as String? + val wrapped: List = + try { + api.loadData(pigeon_instanceArg, dataArg, mimeTypeArg, encodingArg) + listOf(null) + } catch (exception: Throwable) { + wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = + BasicMessageChannel( + binaryMessenger, + "dev.flutter.pigeon.webview_flutter_android.WebView.loadDataWithBaseUrl", + codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val pigeon_instanceArg = args[0] as android.webkit.WebView + val baseUrlArg = args[1] as String? + val dataArg = args[2] as String + val mimeTypeArg = args[3] as String? + val encodingArg = args[4] as String? + val historyUrlArg = args[5] as String? + val wrapped: List = + try { + api.loadDataWithBaseUrl( + pigeon_instanceArg, + baseUrlArg, + dataArg, + mimeTypeArg, + encodingArg, + historyUrlArg) + listOf(null) + } catch (exception: Throwable) { + wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = + BasicMessageChannel( + binaryMessenger, + "dev.flutter.pigeon.webview_flutter_android.WebView.loadUrl", + codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val pigeon_instanceArg = args[0] as android.webkit.WebView + val urlArg = args[1] as String + val headersArg = args[2] as Map + val wrapped: List = + try { + api.loadUrl(pigeon_instanceArg, urlArg, headersArg) + listOf(null) + } catch (exception: Throwable) { + wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = + BasicMessageChannel( + binaryMessenger, + "dev.flutter.pigeon.webview_flutter_android.WebView.postUrl", + codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val pigeon_instanceArg = args[0] as android.webkit.WebView + val urlArg = args[1] as String + val dataArg = args[2] as ByteArray + val wrapped: List = + try { + api.postUrl(pigeon_instanceArg, urlArg, dataArg) + listOf(null) + } catch (exception: Throwable) { + wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = + BasicMessageChannel( + binaryMessenger, "dev.flutter.pigeon.webview_flutter_android.WebView.getUrl", codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val pigeon_instanceArg = args[0] as android.webkit.WebView + val wrapped: List = + try { + listOf(api.getUrl(pigeon_instanceArg)) + } catch (exception: Throwable) { + wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = + BasicMessageChannel( + binaryMessenger, + "dev.flutter.pigeon.webview_flutter_android.WebView.canGoBack", + codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val pigeon_instanceArg = args[0] as android.webkit.WebView + val wrapped: List = + try { + listOf(api.canGoBack(pigeon_instanceArg)) + } catch (exception: Throwable) { + wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = + BasicMessageChannel( + binaryMessenger, + "dev.flutter.pigeon.webview_flutter_android.WebView.canGoForward", + codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val pigeon_instanceArg = args[0] as android.webkit.WebView + val wrapped: List = + try { + listOf(api.canGoForward(pigeon_instanceArg)) + } catch (exception: Throwable) { + wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = + BasicMessageChannel( + binaryMessenger, "dev.flutter.pigeon.webview_flutter_android.WebView.goBack", codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val pigeon_instanceArg = args[0] as android.webkit.WebView + val wrapped: List = + try { + api.goBack(pigeon_instanceArg) + listOf(null) + } catch (exception: Throwable) { + wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = + BasicMessageChannel( + binaryMessenger, + "dev.flutter.pigeon.webview_flutter_android.WebView.goForward", + codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val pigeon_instanceArg = args[0] as android.webkit.WebView + val wrapped: List = + try { + api.goForward(pigeon_instanceArg) + listOf(null) + } catch (exception: Throwable) { + wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = + BasicMessageChannel( + binaryMessenger, "dev.flutter.pigeon.webview_flutter_android.WebView.reload", codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val pigeon_instanceArg = args[0] as android.webkit.WebView + val wrapped: List = + try { + api.reload(pigeon_instanceArg) + listOf(null) + } catch (exception: Throwable) { + wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = + BasicMessageChannel( + binaryMessenger, + "dev.flutter.pigeon.webview_flutter_android.WebView.clearCache", + codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val pigeon_instanceArg = args[0] as android.webkit.WebView + val includeDiskFilesArg = args[1] as Boolean + val wrapped: List = + try { + api.clearCache(pigeon_instanceArg, includeDiskFilesArg) + listOf(null) + } catch (exception: Throwable) { + wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = + BasicMessageChannel( + binaryMessenger, + "dev.flutter.pigeon.webview_flutter_android.WebView.evaluateJavascript", + codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val pigeon_instanceArg = args[0] as android.webkit.WebView + val javascriptStringArg = args[1] as String + api.evaluateJavascript(pigeon_instanceArg, javascriptStringArg) { + result: Result -> + val error = result.exceptionOrNull() + if (error != null) { + reply.reply(wrapError(error)) + } else { + val data = result.getOrNull() + reply.reply(wrapResult(data)) + } + } + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = + BasicMessageChannel( + binaryMessenger, + "dev.flutter.pigeon.webview_flutter_android.WebView.getTitle", + codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val pigeon_instanceArg = args[0] as android.webkit.WebView + val wrapped: List = + try { + listOf(api.getTitle(pigeon_instanceArg)) + } catch (exception: Throwable) { + wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = + BasicMessageChannel( + binaryMessenger, + "dev.flutter.pigeon.webview_flutter_android.WebView.setWebContentsDebuggingEnabled", + codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val enabledArg = args[0] as Boolean + val wrapped: List = + try { + api.setWebContentsDebuggingEnabled(enabledArg) + listOf(null) + } catch (exception: Throwable) { + wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = + BasicMessageChannel( + binaryMessenger, + "dev.flutter.pigeon.webview_flutter_android.WebView.setWebViewClient", + codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val pigeon_instanceArg = args[0] as android.webkit.WebView + val clientArg = args[1] as android.webkit.WebViewClient? + val wrapped: List = + try { + api.setWebViewClient(pigeon_instanceArg, clientArg) + listOf(null) + } catch (exception: Throwable) { + wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = + BasicMessageChannel( + binaryMessenger, + "dev.flutter.pigeon.webview_flutter_android.WebView.addJavaScriptChannel", + codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val pigeon_instanceArg = args[0] as android.webkit.WebView + val channelArg = args[1] as JavaScriptChannel + val wrapped: List = + try { + api.addJavaScriptChannel(pigeon_instanceArg, channelArg) + listOf(null) + } catch (exception: Throwable) { + wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = + BasicMessageChannel( + binaryMessenger, + "dev.flutter.pigeon.webview_flutter_android.WebView.removeJavaScriptChannel", + codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val pigeon_instanceArg = args[0] as android.webkit.WebView + val nameArg = args[1] as String + val wrapped: List = + try { + api.removeJavaScriptChannel(pigeon_instanceArg, nameArg) + listOf(null) + } catch (exception: Throwable) { + wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = + BasicMessageChannel( + binaryMessenger, + "dev.flutter.pigeon.webview_flutter_android.WebView.setDownloadListener", + codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val pigeon_instanceArg = args[0] as android.webkit.WebView + val listenerArg = args[1] as android.webkit.DownloadListener? + val wrapped: List = + try { + api.setDownloadListener(pigeon_instanceArg, listenerArg) + listOf(null) + } catch (exception: Throwable) { + wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = + BasicMessageChannel( + binaryMessenger, + "dev.flutter.pigeon.webview_flutter_android.WebView.setWebChromeClient", + codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val pigeon_instanceArg = args[0] as android.webkit.WebView + val clientArg = + args[1] + as + io.flutter.plugins.webviewflutter.WebChromeClientProxyApi.WebChromeClientImpl? + val wrapped: List = + try { + api.setWebChromeClient(pigeon_instanceArg, clientArg) + listOf(null) + } catch (exception: Throwable) { + wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = + BasicMessageChannel( + binaryMessenger, + "dev.flutter.pigeon.webview_flutter_android.WebView.setBackgroundColor", + codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val pigeon_instanceArg = args[0] as android.webkit.WebView + val colorArg = args[1] as Long + val wrapped: List = + try { + api.setBackgroundColor(pigeon_instanceArg, colorArg) + listOf(null) + } catch (exception: Throwable) { + wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = + BasicMessageChannel( + binaryMessenger, + "dev.flutter.pigeon.webview_flutter_android.WebView.destroy", + codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val pigeon_instanceArg = args[0] as android.webkit.WebView + val wrapped: List = + try { + api.destroy(pigeon_instanceArg) + listOf(null) + } catch (exception: Throwable) { + wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + } + } + + @Suppress("LocalVariableName", "FunctionName") + /** Creates a Dart instance of WebView and attaches it to [pigeon_instanceArg]. */ + fun pigeon_newInstance( + pigeon_instanceArg: android.webkit.WebView, + callback: (Result) -> Unit + ) { + if (pigeonRegistrar.ignoreCallsToDart) { + callback( + Result.failure( + AndroidWebKitError("ignore-calls-error", "Calls to Dart are being ignored.", ""))) + return + } + if (pigeonRegistrar.instanceManager.containsInstance(pigeon_instanceArg)) { + Result.success(Unit) + return + } + val pigeon_identifierArg = + pigeonRegistrar.instanceManager.addHostCreatedInstance(pigeon_instanceArg) + val binaryMessenger = pigeonRegistrar.binaryMessenger + val codec = pigeonRegistrar.codec + val channelName = "dev.flutter.pigeon.webview_flutter_android.WebView.pigeon_newInstance" + val channel = BasicMessageChannel(binaryMessenger, channelName, codec) + channel.send(listOf(pigeon_identifierArg)) { + if (it is List<*>) { + if (it.size > 1) { + callback( + Result.failure( + AndroidWebKitError(it[0] as String, it[1] as String, it[2] as String?))) + } else { + callback(Result.success(Unit)) + } + } else { + callback(Result.failure(createConnectionError(channelName))) + } + } + } + + /** + * This is called in response to an internal scroll in this view (i.e., the view scrolled its own + * contents). + */ + fun onScrollChanged( + pigeon_instanceArg: android.webkit.WebView, + leftArg: Long, + topArg: Long, + oldLeftArg: Long, + oldTopArg: Long, + callback: (Result) -> Unit + ) { + if (pigeonRegistrar.ignoreCallsToDart) { + callback( + Result.failure( + AndroidWebKitError("ignore-calls-error", "Calls to Dart are being ignored.", ""))) + return + } + val binaryMessenger = pigeonRegistrar.binaryMessenger + val codec = pigeonRegistrar.codec + val channelName = "dev.flutter.pigeon.webview_flutter_android.WebView.onScrollChanged" + val channel = BasicMessageChannel(binaryMessenger, channelName, codec) + channel.send(listOf(pigeon_instanceArg, leftArg, topArg, oldLeftArg, oldTopArg)) { + if (it is List<*>) { + if (it.size > 1) { + callback( + Result.failure( + AndroidWebKitError(it[0] as String, it[1] as String, it[2] as String?))) + } else { + callback(Result.success(Unit)) + } + } else { + callback(Result.failure(createConnectionError(channelName))) + } + } + } + + @Suppress("FunctionName") + /** An implementation of [PigeonApiView] used to access callback methods */ + fun pigeon_getPigeonApiView(): PigeonApiView { + return pigeonRegistrar.getPigeonApiView() + } +} +/** + * Manages settings state for a `WebView`. + * + * See https://developer.android.com/reference/android/webkit/WebSettings. + */ +@Suppress("UNCHECKED_CAST") +abstract class PigeonApiWebSettings( + open val pigeonRegistrar: AndroidWebkitLibraryPigeonProxyApiRegistrar +) { + /** Sets whether the DOM storage API is enabled. */ + abstract fun setDomStorageEnabled(pigeon_instance: android.webkit.WebSettings, flag: Boolean) + + /** Tells JavaScript to open windows automatically. */ + abstract fun setJavaScriptCanOpenWindowsAutomatically( + pigeon_instance: android.webkit.WebSettings, + flag: Boolean + ) + + /** Sets whether the WebView whether supports multiple windows. */ + abstract fun setSupportMultipleWindows( + pigeon_instance: android.webkit.WebSettings, + support: Boolean + ) + + /** Tells the WebView to enable JavaScript execution. */ + abstract fun setJavaScriptEnabled(pigeon_instance: android.webkit.WebSettings, flag: Boolean) + + /** Sets the WebView's user-agent string. */ + abstract fun setUserAgentString( + pigeon_instance: android.webkit.WebSettings, + userAgentString: String? + ) + + /** Sets whether the WebView requires a user gesture to play media. */ + abstract fun setMediaPlaybackRequiresUserGesture( + pigeon_instance: android.webkit.WebSettings, + require: Boolean + ) + + /** + * Sets whether the WebView should support zooming using its on-screen zoom controls and gestures. + */ + abstract fun setSupportZoom(pigeon_instance: android.webkit.WebSettings, support: Boolean) + + /** + * Sets whether the WebView loads pages in overview mode, that is, zooms out the content to fit on + * screen by width. + */ + abstract fun setLoadWithOverviewMode( + pigeon_instance: android.webkit.WebSettings, + overview: Boolean + ) + + /** + * Sets whether the WebView should enable support for the "viewport" HTML meta tag or should use a + * wide viewport. + */ + abstract fun setUseWideViewPort(pigeon_instance: android.webkit.WebSettings, use: Boolean) + + /** + * Sets whether the WebView should display on-screen zoom controls when using the built-in zoom + * mechanisms. + */ + abstract fun setDisplayZoomControls(pigeon_instance: android.webkit.WebSettings, enabled: Boolean) + + /** + * Sets whether the WebView should display on-screen zoom controls when using the built-in zoom + * mechanisms. + */ + abstract fun setBuiltInZoomControls(pigeon_instance: android.webkit.WebSettings, enabled: Boolean) + + /** Enables or disables file access within WebView. */ + abstract fun setAllowFileAccess(pigeon_instance: android.webkit.WebSettings, enabled: Boolean) + + /** Sets the text zoom of the page in percent. */ + abstract fun setTextZoom(pigeon_instance: android.webkit.WebSettings, textZoom: Long) + + /** Gets the WebView's user-agent string. */ + abstract fun getUserAgentString(pigeon_instance: android.webkit.WebSettings): String + + companion object { + @Suppress("LocalVariableName") + fun setUpMessageHandlers(binaryMessenger: BinaryMessenger, api: PigeonApiWebSettings?) { + val codec = api?.pigeonRegistrar?.codec ?: AndroidWebkitLibraryPigeonCodec() + run { + val channel = + BasicMessageChannel( + binaryMessenger, + "dev.flutter.pigeon.webview_flutter_android.WebSettings.setDomStorageEnabled", + codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val pigeon_instanceArg = args[0] as android.webkit.WebSettings + val flagArg = args[1] as Boolean + val wrapped: List = + try { + api.setDomStorageEnabled(pigeon_instanceArg, flagArg) + listOf(null) + } catch (exception: Throwable) { + wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = + BasicMessageChannel( + binaryMessenger, + "dev.flutter.pigeon.webview_flutter_android.WebSettings.setJavaScriptCanOpenWindowsAutomatically", + codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val pigeon_instanceArg = args[0] as android.webkit.WebSettings + val flagArg = args[1] as Boolean + val wrapped: List = + try { + api.setJavaScriptCanOpenWindowsAutomatically(pigeon_instanceArg, flagArg) + listOf(null) + } catch (exception: Throwable) { + wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = + BasicMessageChannel( + binaryMessenger, + "dev.flutter.pigeon.webview_flutter_android.WebSettings.setSupportMultipleWindows", + codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val pigeon_instanceArg = args[0] as android.webkit.WebSettings + val supportArg = args[1] as Boolean + val wrapped: List = + try { + api.setSupportMultipleWindows(pigeon_instanceArg, supportArg) + listOf(null) + } catch (exception: Throwable) { + wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = + BasicMessageChannel( + binaryMessenger, + "dev.flutter.pigeon.webview_flutter_android.WebSettings.setJavaScriptEnabled", + codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val pigeon_instanceArg = args[0] as android.webkit.WebSettings + val flagArg = args[1] as Boolean + val wrapped: List = + try { + api.setJavaScriptEnabled(pigeon_instanceArg, flagArg) + listOf(null) + } catch (exception: Throwable) { + wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = + BasicMessageChannel( + binaryMessenger, + "dev.flutter.pigeon.webview_flutter_android.WebSettings.setUserAgentString", + codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val pigeon_instanceArg = args[0] as android.webkit.WebSettings + val userAgentStringArg = args[1] as String? + val wrapped: List = + try { + api.setUserAgentString(pigeon_instanceArg, userAgentStringArg) + listOf(null) + } catch (exception: Throwable) { + wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = + BasicMessageChannel( + binaryMessenger, + "dev.flutter.pigeon.webview_flutter_android.WebSettings.setMediaPlaybackRequiresUserGesture", + codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val pigeon_instanceArg = args[0] as android.webkit.WebSettings + val requireArg = args[1] as Boolean + val wrapped: List = + try { + api.setMediaPlaybackRequiresUserGesture(pigeon_instanceArg, requireArg) + listOf(null) + } catch (exception: Throwable) { + wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = + BasicMessageChannel( + binaryMessenger, + "dev.flutter.pigeon.webview_flutter_android.WebSettings.setSupportZoom", + codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val pigeon_instanceArg = args[0] as android.webkit.WebSettings + val supportArg = args[1] as Boolean + val wrapped: List = + try { + api.setSupportZoom(pigeon_instanceArg, supportArg) + listOf(null) + } catch (exception: Throwable) { + wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = + BasicMessageChannel( + binaryMessenger, + "dev.flutter.pigeon.webview_flutter_android.WebSettings.setLoadWithOverviewMode", + codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val pigeon_instanceArg = args[0] as android.webkit.WebSettings + val overviewArg = args[1] as Boolean + val wrapped: List = + try { + api.setLoadWithOverviewMode(pigeon_instanceArg, overviewArg) + listOf(null) + } catch (exception: Throwable) { + wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = + BasicMessageChannel( + binaryMessenger, + "dev.flutter.pigeon.webview_flutter_android.WebSettings.setUseWideViewPort", + codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val pigeon_instanceArg = args[0] as android.webkit.WebSettings + val useArg = args[1] as Boolean + val wrapped: List = + try { + api.setUseWideViewPort(pigeon_instanceArg, useArg) + listOf(null) + } catch (exception: Throwable) { + wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = + BasicMessageChannel( + binaryMessenger, + "dev.flutter.pigeon.webview_flutter_android.WebSettings.setDisplayZoomControls", + codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val pigeon_instanceArg = args[0] as android.webkit.WebSettings + val enabledArg = args[1] as Boolean + val wrapped: List = + try { + api.setDisplayZoomControls(pigeon_instanceArg, enabledArg) + listOf(null) + } catch (exception: Throwable) { + wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = + BasicMessageChannel( + binaryMessenger, + "dev.flutter.pigeon.webview_flutter_android.WebSettings.setBuiltInZoomControls", + codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val pigeon_instanceArg = args[0] as android.webkit.WebSettings + val enabledArg = args[1] as Boolean + val wrapped: List = + try { + api.setBuiltInZoomControls(pigeon_instanceArg, enabledArg) + listOf(null) + } catch (exception: Throwable) { + wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = + BasicMessageChannel( + binaryMessenger, + "dev.flutter.pigeon.webview_flutter_android.WebSettings.setAllowFileAccess", + codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val pigeon_instanceArg = args[0] as android.webkit.WebSettings + val enabledArg = args[1] as Boolean + val wrapped: List = + try { + api.setAllowFileAccess(pigeon_instanceArg, enabledArg) + listOf(null) + } catch (exception: Throwable) { + wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = + BasicMessageChannel( + binaryMessenger, + "dev.flutter.pigeon.webview_flutter_android.WebSettings.setTextZoom", + codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val pigeon_instanceArg = args[0] as android.webkit.WebSettings + val textZoomArg = args[1] as Long + val wrapped: List = + try { + api.setTextZoom(pigeon_instanceArg, textZoomArg) + listOf(null) + } catch (exception: Throwable) { + wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = + BasicMessageChannel( + binaryMessenger, + "dev.flutter.pigeon.webview_flutter_android.WebSettings.getUserAgentString", + codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val pigeon_instanceArg = args[0] as android.webkit.WebSettings + val wrapped: List = + try { + listOf(api.getUserAgentString(pigeon_instanceArg)) + } catch (exception: Throwable) { + wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + } + } + + @Suppress("LocalVariableName", "FunctionName") + /** Creates a Dart instance of WebSettings and attaches it to [pigeon_instanceArg]. */ + fun pigeon_newInstance( + pigeon_instanceArg: android.webkit.WebSettings, + callback: (Result) -> Unit + ) { + if (pigeonRegistrar.ignoreCallsToDart) { + callback( + Result.failure( + AndroidWebKitError("ignore-calls-error", "Calls to Dart are being ignored.", ""))) + return + } + if (pigeonRegistrar.instanceManager.containsInstance(pigeon_instanceArg)) { + Result.success(Unit) + return + } + val pigeon_identifierArg = + pigeonRegistrar.instanceManager.addHostCreatedInstance(pigeon_instanceArg) + val binaryMessenger = pigeonRegistrar.binaryMessenger + val codec = pigeonRegistrar.codec + val channelName = "dev.flutter.pigeon.webview_flutter_android.WebSettings.pigeon_newInstance" + val channel = BasicMessageChannel(binaryMessenger, channelName, codec) + channel.send(listOf(pigeon_identifierArg)) { + if (it is List<*>) { + if (it.size > 1) { + callback( + Result.failure( + AndroidWebKitError(it[0] as String, it[1] as String, it[2] as String?))) + } else { + callback(Result.success(Unit)) + } + } else { + callback(Result.failure(createConnectionError(channelName))) + } + } + } +} +/** + * A JavaScript interface for exposing Javascript callbacks to Dart. + * + * This is a custom class for the wrapper that is annotated with + * [JavascriptInterface](https://developer.android.com/reference/android/webkit/JavascriptInterface). + */ +@Suppress("UNCHECKED_CAST") +abstract class PigeonApiJavaScriptChannel( + open val pigeonRegistrar: AndroidWebkitLibraryPigeonProxyApiRegistrar +) { + abstract fun pigeon_defaultConstructor(channelName: String): JavaScriptChannel + + companion object { + @Suppress("LocalVariableName") + fun setUpMessageHandlers(binaryMessenger: BinaryMessenger, api: PigeonApiJavaScriptChannel?) { + val codec = api?.pigeonRegistrar?.codec ?: AndroidWebkitLibraryPigeonCodec() + run { + val channel = + BasicMessageChannel( + binaryMessenger, + "dev.flutter.pigeon.webview_flutter_android.JavaScriptChannel.pigeon_defaultConstructor", + codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val pigeon_identifierArg = args[0] as Long + val channelNameArg = args[1] as String + val wrapped: List = + try { + api.pigeonRegistrar.instanceManager.addDartCreatedInstance( + api.pigeon_defaultConstructor(channelNameArg), pigeon_identifierArg) + listOf(null) + } catch (exception: Throwable) { + wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + } + } + + @Suppress("LocalVariableName", "FunctionName") + /** Creates a Dart instance of JavaScriptChannel and attaches it to [pigeon_instanceArg]. */ + fun pigeon_newInstance(pigeon_instanceArg: JavaScriptChannel, callback: (Result) -> Unit) { + if (pigeonRegistrar.ignoreCallsToDart) { + callback( + Result.failure( + AndroidWebKitError("ignore-calls-error", "Calls to Dart are being ignored.", ""))) + return + } + if (pigeonRegistrar.instanceManager.containsInstance(pigeon_instanceArg)) { + Result.success(Unit) + return + } + throw IllegalStateException( + "Attempting to create a new Dart instance of JavaScriptChannel, but the class has a nonnull callback method.") + } + + /** Handles callbacks messages from JavaScript. */ + fun postMessage( + pigeon_instanceArg: JavaScriptChannel, + messageArg: String, + callback: (Result) -> Unit + ) { + if (pigeonRegistrar.ignoreCallsToDart) { + callback( + Result.failure( + AndroidWebKitError("ignore-calls-error", "Calls to Dart are being ignored.", ""))) + return + } + val binaryMessenger = pigeonRegistrar.binaryMessenger + val codec = pigeonRegistrar.codec + val channelName = "dev.flutter.pigeon.webview_flutter_android.JavaScriptChannel.postMessage" + val channel = BasicMessageChannel(binaryMessenger, channelName, codec) + channel.send(listOf(pigeon_instanceArg, messageArg)) { + if (it is List<*>) { + if (it.size > 1) { + callback( + Result.failure( + AndroidWebKitError(it[0] as String, it[1] as String, it[2] as String?))) + } else { + callback(Result.success(Unit)) + } + } else { + callback(Result.failure(createConnectionError(channelName))) + } + } + } +} +/** + * Receives various notifications and requests from a `WebView`. + * + * See https://developer.android.com/reference/android/webkit/WebViewClient. + */ +@Suppress("UNCHECKED_CAST") +abstract class PigeonApiWebViewClient( + open val pigeonRegistrar: AndroidWebkitLibraryPigeonProxyApiRegistrar +) { + abstract fun pigeon_defaultConstructor(): android.webkit.WebViewClient + + /** + * Sets the required synchronous return value for the Java method, + * `WebViewClient.shouldOverrideUrlLoading(...)`. + * + * The Java method, `WebViewClient.shouldOverrideUrlLoading(...)`, requires a boolean to be + * returned and this method sets the returned value for all calls to the Java method. + * + * Setting this to true causes the current [WebView] to abort loading any URL received by + * [requestLoading] or [urlLoading], while setting this to false causes the [WebView] to continue + * loading a URL as usual. + * + * Defaults to false. + */ + abstract fun setSynchronousReturnValueForShouldOverrideUrlLoading( + pigeon_instance: android.webkit.WebViewClient, + value: Boolean + ) + + companion object { + @Suppress("LocalVariableName") + fun setUpMessageHandlers(binaryMessenger: BinaryMessenger, api: PigeonApiWebViewClient?) { + val codec = api?.pigeonRegistrar?.codec ?: AndroidWebkitLibraryPigeonCodec() + run { + val channel = + BasicMessageChannel( + binaryMessenger, + "dev.flutter.pigeon.webview_flutter_android.WebViewClient.pigeon_defaultConstructor", + codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val pigeon_identifierArg = args[0] as Long + val wrapped: List = + try { + api.pigeonRegistrar.instanceManager.addDartCreatedInstance( + api.pigeon_defaultConstructor(), pigeon_identifierArg) + listOf(null) + } catch (exception: Throwable) { + wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = + BasicMessageChannel( + binaryMessenger, + "dev.flutter.pigeon.webview_flutter_android.WebViewClient.setSynchronousReturnValueForShouldOverrideUrlLoading", + codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val pigeon_instanceArg = args[0] as android.webkit.WebViewClient + val valueArg = args[1] as Boolean + val wrapped: List = + try { + api.setSynchronousReturnValueForShouldOverrideUrlLoading( + pigeon_instanceArg, valueArg) + listOf(null) + } catch (exception: Throwable) { + wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + } + } + + @Suppress("LocalVariableName", "FunctionName") + /** Creates a Dart instance of WebViewClient and attaches it to [pigeon_instanceArg]. */ + fun pigeon_newInstance( + pigeon_instanceArg: android.webkit.WebViewClient, + callback: (Result) -> Unit + ) { + if (pigeonRegistrar.ignoreCallsToDart) { + callback( + Result.failure( + AndroidWebKitError("ignore-calls-error", "Calls to Dart are being ignored.", ""))) + return + } + if (pigeonRegistrar.instanceManager.containsInstance(pigeon_instanceArg)) { + Result.success(Unit) + return + } + val pigeon_identifierArg = + pigeonRegistrar.instanceManager.addHostCreatedInstance(pigeon_instanceArg) + val binaryMessenger = pigeonRegistrar.binaryMessenger + val codec = pigeonRegistrar.codec + val channelName = "dev.flutter.pigeon.webview_flutter_android.WebViewClient.pigeon_newInstance" + val channel = BasicMessageChannel(binaryMessenger, channelName, codec) + channel.send(listOf(pigeon_identifierArg)) { + if (it is List<*>) { + if (it.size > 1) { + callback( + Result.failure( + AndroidWebKitError(it[0] as String, it[1] as String, it[2] as String?))) + } else { + callback(Result.success(Unit)) + } + } else { + callback(Result.failure(createConnectionError(channelName))) + } + } + } + + /** Notify the host application that a page has started loading. */ + fun onPageStarted( + pigeon_instanceArg: android.webkit.WebViewClient, + webViewArg: android.webkit.WebView, + urlArg: String, + callback: (Result) -> Unit + ) { + if (pigeonRegistrar.ignoreCallsToDart) { + callback( + Result.failure( + AndroidWebKitError("ignore-calls-error", "Calls to Dart are being ignored.", ""))) + return + } + val binaryMessenger = pigeonRegistrar.binaryMessenger + val codec = pigeonRegistrar.codec + val channelName = "dev.flutter.pigeon.webview_flutter_android.WebViewClient.onPageStarted" + val channel = BasicMessageChannel(binaryMessenger, channelName, codec) + channel.send(listOf(pigeon_instanceArg, webViewArg, urlArg)) { + if (it is List<*>) { + if (it.size > 1) { + callback( + Result.failure( + AndroidWebKitError(it[0] as String, it[1] as String, it[2] as String?))) + } else { + callback(Result.success(Unit)) + } + } else { + callback(Result.failure(createConnectionError(channelName))) + } + } + } + + /** Notify the host application that a page has finished loading. */ + fun onPageFinished( + pigeon_instanceArg: android.webkit.WebViewClient, + webViewArg: android.webkit.WebView, + urlArg: String, + callback: (Result) -> Unit + ) { + if (pigeonRegistrar.ignoreCallsToDart) { + callback( + Result.failure( + AndroidWebKitError("ignore-calls-error", "Calls to Dart are being ignored.", ""))) + return + } + val binaryMessenger = pigeonRegistrar.binaryMessenger + val codec = pigeonRegistrar.codec + val channelName = "dev.flutter.pigeon.webview_flutter_android.WebViewClient.onPageFinished" + val channel = BasicMessageChannel(binaryMessenger, channelName, codec) + channel.send(listOf(pigeon_instanceArg, webViewArg, urlArg)) { + if (it is List<*>) { + if (it.size > 1) { + callback( + Result.failure( + AndroidWebKitError(it[0] as String, it[1] as String, it[2] as String?))) + } else { + callback(Result.success(Unit)) + } + } else { + callback(Result.failure(createConnectionError(channelName))) + } + } + } + + /** + * Notify the host application that an HTTP error has been received from the server while loading + * a resource. + */ + fun onReceivedHttpError( + pigeon_instanceArg: android.webkit.WebViewClient, + webViewArg: android.webkit.WebView, + requestArg: android.webkit.WebResourceRequest, + responseArg: android.webkit.WebResourceResponse, + callback: (Result) -> Unit + ) { + if (pigeonRegistrar.ignoreCallsToDart) { + callback( + Result.failure( + AndroidWebKitError("ignore-calls-error", "Calls to Dart are being ignored.", ""))) + return + } + val binaryMessenger = pigeonRegistrar.binaryMessenger + val codec = pigeonRegistrar.codec + val channelName = "dev.flutter.pigeon.webview_flutter_android.WebViewClient.onReceivedHttpError" + val channel = BasicMessageChannel(binaryMessenger, channelName, codec) + channel.send(listOf(pigeon_instanceArg, webViewArg, requestArg, responseArg)) { + if (it is List<*>) { + if (it.size > 1) { + callback( + Result.failure( + AndroidWebKitError(it[0] as String, it[1] as String, it[2] as String?))) + } else { + callback(Result.success(Unit)) + } + } else { + callback(Result.failure(createConnectionError(channelName))) + } + } + } + + /** Report web resource loading error to the host application. */ + @androidx.annotation.RequiresApi(api = 23) + fun onReceivedRequestError( + pigeon_instanceArg: android.webkit.WebViewClient, + webViewArg: android.webkit.WebView, + requestArg: android.webkit.WebResourceRequest, + errorArg: android.webkit.WebResourceError, + callback: (Result) -> Unit + ) { + if (pigeonRegistrar.ignoreCallsToDart) { + callback( + Result.failure( + AndroidWebKitError("ignore-calls-error", "Calls to Dart are being ignored.", ""))) + return + } + val binaryMessenger = pigeonRegistrar.binaryMessenger + val codec = pigeonRegistrar.codec + val channelName = + "dev.flutter.pigeon.webview_flutter_android.WebViewClient.onReceivedRequestError" + val channel = BasicMessageChannel(binaryMessenger, channelName, codec) + channel.send(listOf(pigeon_instanceArg, webViewArg, requestArg, errorArg)) { + if (it is List<*>) { + if (it.size > 1) { + callback( + Result.failure( + AndroidWebKitError(it[0] as String, it[1] as String, it[2] as String?))) + } else { + callback(Result.success(Unit)) + } + } else { + callback(Result.failure(createConnectionError(channelName))) + } + } + } + + /** Report web resource loading error to the host application. */ + fun onReceivedRequestErrorCompat( + pigeon_instanceArg: android.webkit.WebViewClient, + webViewArg: android.webkit.WebView, + requestArg: android.webkit.WebResourceRequest, + errorArg: androidx.webkit.WebResourceErrorCompat, + callback: (Result) -> Unit + ) { + if (pigeonRegistrar.ignoreCallsToDart) { + callback( + Result.failure( + AndroidWebKitError("ignore-calls-error", "Calls to Dart are being ignored.", ""))) + return + } + val binaryMessenger = pigeonRegistrar.binaryMessenger + val codec = pigeonRegistrar.codec + val channelName = + "dev.flutter.pigeon.webview_flutter_android.WebViewClient.onReceivedRequestErrorCompat" + val channel = BasicMessageChannel(binaryMessenger, channelName, codec) + channel.send(listOf(pigeon_instanceArg, webViewArg, requestArg, errorArg)) { + if (it is List<*>) { + if (it.size > 1) { + callback( + Result.failure( + AndroidWebKitError(it[0] as String, it[1] as String, it[2] as String?))) + } else { + callback(Result.success(Unit)) + } + } else { + callback(Result.failure(createConnectionError(channelName))) + } + } + } + + /** Report an error to the host application. */ + fun onReceivedError( + pigeon_instanceArg: android.webkit.WebViewClient, + webViewArg: android.webkit.WebView, + errorCodeArg: Long, + descriptionArg: String, + failingUrlArg: String, + callback: (Result) -> Unit + ) { + if (pigeonRegistrar.ignoreCallsToDart) { + callback( + Result.failure( + AndroidWebKitError("ignore-calls-error", "Calls to Dart are being ignored.", ""))) + return + } + val binaryMessenger = pigeonRegistrar.binaryMessenger + val codec = pigeonRegistrar.codec + val channelName = "dev.flutter.pigeon.webview_flutter_android.WebViewClient.onReceivedError" + val channel = BasicMessageChannel(binaryMessenger, channelName, codec) + channel.send( + listOf(pigeon_instanceArg, webViewArg, errorCodeArg, descriptionArg, failingUrlArg)) { + if (it is List<*>) { + if (it.size > 1) { + callback( + Result.failure( + AndroidWebKitError(it[0] as String, it[1] as String, it[2] as String?))) + } else { + callback(Result.success(Unit)) + } + } else { + callback(Result.failure(createConnectionError(channelName))) + } + } + } + + /** + * Give the host application a chance to take control when a URL is about to be loaded in the + * current WebView. + */ + fun requestLoading( + pigeon_instanceArg: android.webkit.WebViewClient, + webViewArg: android.webkit.WebView, + requestArg: android.webkit.WebResourceRequest, + callback: (Result) -> Unit + ) { + if (pigeonRegistrar.ignoreCallsToDart) { + callback( + Result.failure( + AndroidWebKitError("ignore-calls-error", "Calls to Dart are being ignored.", ""))) + return + } + val binaryMessenger = pigeonRegistrar.binaryMessenger + val codec = pigeonRegistrar.codec + val channelName = "dev.flutter.pigeon.webview_flutter_android.WebViewClient.requestLoading" + val channel = BasicMessageChannel(binaryMessenger, channelName, codec) + channel.send(listOf(pigeon_instanceArg, webViewArg, requestArg)) { + if (it is List<*>) { + if (it.size > 1) { + callback( + Result.failure( + AndroidWebKitError(it[0] as String, it[1] as String, it[2] as String?))) + } else { + callback(Result.success(Unit)) + } + } else { + callback(Result.failure(createConnectionError(channelName))) + } + } + } + + /** + * Give the host application a chance to take control when a URL is about to be loaded in the + * current WebView. + */ + fun urlLoading( + pigeon_instanceArg: android.webkit.WebViewClient, + webViewArg: android.webkit.WebView, + urlArg: String, + callback: (Result) -> Unit + ) { + if (pigeonRegistrar.ignoreCallsToDart) { + callback( + Result.failure( + AndroidWebKitError("ignore-calls-error", "Calls to Dart are being ignored.", ""))) + return + } + val binaryMessenger = pigeonRegistrar.binaryMessenger + val codec = pigeonRegistrar.codec + val channelName = "dev.flutter.pigeon.webview_flutter_android.WebViewClient.urlLoading" + val channel = BasicMessageChannel(binaryMessenger, channelName, codec) + channel.send(listOf(pigeon_instanceArg, webViewArg, urlArg)) { + if (it is List<*>) { + if (it.size > 1) { + callback( + Result.failure( + AndroidWebKitError(it[0] as String, it[1] as String, it[2] as String?))) + } else { + callback(Result.success(Unit)) + } + } else { + callback(Result.failure(createConnectionError(channelName))) + } + } + } + + /** Notify the host application to update its visited links database. */ + fun doUpdateVisitedHistory( + pigeon_instanceArg: android.webkit.WebViewClient, + webViewArg: android.webkit.WebView, + urlArg: String, + isReloadArg: Boolean, + callback: (Result) -> Unit + ) { + if (pigeonRegistrar.ignoreCallsToDart) { + callback( + Result.failure( + AndroidWebKitError("ignore-calls-error", "Calls to Dart are being ignored.", ""))) + return + } + val binaryMessenger = pigeonRegistrar.binaryMessenger + val codec = pigeonRegistrar.codec + val channelName = + "dev.flutter.pigeon.webview_flutter_android.WebViewClient.doUpdateVisitedHistory" + val channel = BasicMessageChannel(binaryMessenger, channelName, codec) + channel.send(listOf(pigeon_instanceArg, webViewArg, urlArg, isReloadArg)) { + if (it is List<*>) { + if (it.size > 1) { + callback( + Result.failure( + AndroidWebKitError(it[0] as String, it[1] as String, it[2] as String?))) + } else { + callback(Result.success(Unit)) + } + } else { + callback(Result.failure(createConnectionError(channelName))) + } + } + } + + /** Notifies the host application that the WebView received an HTTP authentication request. */ + fun onReceivedHttpAuthRequest( + pigeon_instanceArg: android.webkit.WebViewClient, + webViewArg: android.webkit.WebView, + handlerArg: android.webkit.HttpAuthHandler, + hostArg: String, + realmArg: String, + callback: (Result) -> Unit + ) { + if (pigeonRegistrar.ignoreCallsToDart) { + callback( + Result.failure( + AndroidWebKitError("ignore-calls-error", "Calls to Dart are being ignored.", ""))) + return + } + val binaryMessenger = pigeonRegistrar.binaryMessenger + val codec = pigeonRegistrar.codec + val channelName = + "dev.flutter.pigeon.webview_flutter_android.WebViewClient.onReceivedHttpAuthRequest" + val channel = BasicMessageChannel(binaryMessenger, channelName, codec) + channel.send(listOf(pigeon_instanceArg, webViewArg, handlerArg, hostArg, realmArg)) { + if (it is List<*>) { + if (it.size > 1) { + callback( + Result.failure( + AndroidWebKitError(it[0] as String, it[1] as String, it[2] as String?))) + } else { + callback(Result.success(Unit)) + } + } else { + callback(Result.failure(createConnectionError(channelName))) + } + } + } +} +/** + * Handles notifications that a file should be downloaded. + * + * See https://developer.android.com/reference/android/webkit/DownloadListener. + */ +@Suppress("UNCHECKED_CAST") +abstract class PigeonApiDownloadListener( + open val pigeonRegistrar: AndroidWebkitLibraryPigeonProxyApiRegistrar +) { + abstract fun pigeon_defaultConstructor(): android.webkit.DownloadListener + + companion object { + @Suppress("LocalVariableName") + fun setUpMessageHandlers(binaryMessenger: BinaryMessenger, api: PigeonApiDownloadListener?) { + val codec = api?.pigeonRegistrar?.codec ?: AndroidWebkitLibraryPigeonCodec() + run { + val channel = + BasicMessageChannel( + binaryMessenger, + "dev.flutter.pigeon.webview_flutter_android.DownloadListener.pigeon_defaultConstructor", + codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val pigeon_identifierArg = args[0] as Long + val wrapped: List = + try { + api.pigeonRegistrar.instanceManager.addDartCreatedInstance( + api.pigeon_defaultConstructor(), pigeon_identifierArg) + listOf(null) + } catch (exception: Throwable) { + wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + } + } + + @Suppress("LocalVariableName", "FunctionName") + /** Creates a Dart instance of DownloadListener and attaches it to [pigeon_instanceArg]. */ + fun pigeon_newInstance( + pigeon_instanceArg: android.webkit.DownloadListener, + callback: (Result) -> Unit + ) { + if (pigeonRegistrar.ignoreCallsToDart) { + callback( + Result.failure( + AndroidWebKitError("ignore-calls-error", "Calls to Dart are being ignored.", ""))) + return + } + if (pigeonRegistrar.instanceManager.containsInstance(pigeon_instanceArg)) { + Result.success(Unit) + return + } + throw IllegalStateException( + "Attempting to create a new Dart instance of DownloadListener, but the class has a nonnull callback method.") + } + + /** Notify the host application that a file should be downloaded. */ + fun onDownloadStart( + pigeon_instanceArg: android.webkit.DownloadListener, + urlArg: String, + userAgentArg: String, + contentDispositionArg: String, + mimetypeArg: String, + contentLengthArg: Long, + callback: (Result) -> Unit + ) { + if (pigeonRegistrar.ignoreCallsToDart) { + callback( + Result.failure( + AndroidWebKitError("ignore-calls-error", "Calls to Dart are being ignored.", ""))) + return + } + val binaryMessenger = pigeonRegistrar.binaryMessenger + val codec = pigeonRegistrar.codec + val channelName = "dev.flutter.pigeon.webview_flutter_android.DownloadListener.onDownloadStart" + val channel = BasicMessageChannel(binaryMessenger, channelName, codec) + channel.send( + listOf( + pigeon_instanceArg, + urlArg, + userAgentArg, + contentDispositionArg, + mimetypeArg, + contentLengthArg)) { + if (it is List<*>) { + if (it.size > 1) { + callback( + Result.failure( + AndroidWebKitError(it[0] as String, it[1] as String, it[2] as String?))) + } else { + callback(Result.success(Unit)) + } + } else { + callback(Result.failure(createConnectionError(channelName))) + } + } + } +} +/** + * Handles notification of JavaScript dialogs, favicons, titles, and the progress. + * + * See https://developer.android.com/reference/android/webkit/WebChromeClient. + */ +@Suppress("UNCHECKED_CAST") +abstract class PigeonApiWebChromeClient( + open val pigeonRegistrar: AndroidWebkitLibraryPigeonProxyApiRegistrar +) { + abstract fun pigeon_defaultConstructor(): + io.flutter.plugins.webviewflutter.WebChromeClientProxyApi.WebChromeClientImpl + + /** + * Sets the required synchronous return value for the Java method, + * `WebChromeClient.onShowFileChooser(...)`. + * + * The Java method, `WebChromeClient.onShowFileChooser(...)`, requires a boolean to be returned + * and this method sets the returned value for all calls to the Java method. + * + * Setting this to true indicates that all file chooser requests should be handled by + * `onShowFileChooser` and the returned list of Strings will be returned to the WebView. + * Otherwise, the client will use the default handling and the returned value in + * `onShowFileChooser` will be ignored. + * + * Requires `onShowFileChooser` to be nonnull. + * + * Defaults to false. + */ + abstract fun setSynchronousReturnValueForOnShowFileChooser( + pigeon_instance: + io.flutter.plugins.webviewflutter.WebChromeClientProxyApi.WebChromeClientImpl, + value: Boolean + ) + + /** + * Sets the required synchronous return value for the Java method, + * `WebChromeClient.onConsoleMessage(...)`. + * + * The Java method, `WebChromeClient.onConsoleMessage(...)`, requires a boolean to be returned and + * this method sets the returned value for all calls to the Java method. + * + * Setting this to true indicates that the client is handling all console messages. + * + * Requires `onConsoleMessage` to be nonnull. + * + * Defaults to false. + */ + abstract fun setSynchronousReturnValueForOnConsoleMessage( + pigeon_instance: + io.flutter.plugins.webviewflutter.WebChromeClientProxyApi.WebChromeClientImpl, + value: Boolean + ) + + /** + * Sets the required synchronous return value for the Java method, + * `WebChromeClient.onJsAlert(...)`. + * + * The Java method, `WebChromeClient.onJsAlert(...)`, requires a boolean to be returned and this + * method sets the returned value for all calls to the Java method. + * + * Setting this to true indicates that the client is handling all console messages. + * + * Requires `onJsAlert` to be nonnull. + * + * Defaults to false. + */ + abstract fun setSynchronousReturnValueForOnJsAlert( + pigeon_instance: + io.flutter.plugins.webviewflutter.WebChromeClientProxyApi.WebChromeClientImpl, + value: Boolean + ) + + /** + * Sets the required synchronous return value for the Java method, + * `WebChromeClient.onJsConfirm(...)`. + * + * The Java method, `WebChromeClient.onJsConfirm(...)`, requires a boolean to be returned and this + * method sets the returned value for all calls to the Java method. + * + * Setting this to true indicates that the client is handling all console messages. + * + * Requires `onJsConfirm` to be nonnull. + * + * Defaults to false. + */ + abstract fun setSynchronousReturnValueForOnJsConfirm( + pigeon_instance: + io.flutter.plugins.webviewflutter.WebChromeClientProxyApi.WebChromeClientImpl, + value: Boolean + ) + + /** + * Sets the required synchronous return value for the Java method, + * `WebChromeClient.onJsPrompt(...)`. + * + * The Java method, `WebChromeClient.onJsPrompt(...)`, requires a boolean to be returned and this + * method sets the returned value for all calls to the Java method. + * + * Setting this to true indicates that the client is handling all console messages. + * + * Requires `onJsPrompt` to be nonnull. + * + * Defaults to false. + */ + abstract fun setSynchronousReturnValueForOnJsPrompt( + pigeon_instance: + io.flutter.plugins.webviewflutter.WebChromeClientProxyApi.WebChromeClientImpl, + value: Boolean + ) + + companion object { + @Suppress("LocalVariableName") + fun setUpMessageHandlers(binaryMessenger: BinaryMessenger, api: PigeonApiWebChromeClient?) { + val codec = api?.pigeonRegistrar?.codec ?: AndroidWebkitLibraryPigeonCodec() + run { + val channel = + BasicMessageChannel( + binaryMessenger, + "dev.flutter.pigeon.webview_flutter_android.WebChromeClient.pigeon_defaultConstructor", + codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val pigeon_identifierArg = args[0] as Long + val wrapped: List = + try { + api.pigeonRegistrar.instanceManager.addDartCreatedInstance( + api.pigeon_defaultConstructor(), pigeon_identifierArg) + listOf(null) + } catch (exception: Throwable) { + wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = + BasicMessageChannel( + binaryMessenger, + "dev.flutter.pigeon.webview_flutter_android.WebChromeClient.setSynchronousReturnValueForOnShowFileChooser", + codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val pigeon_instanceArg = + args[0] + as io.flutter.plugins.webviewflutter.WebChromeClientProxyApi.WebChromeClientImpl + val valueArg = args[1] as Boolean + val wrapped: List = + try { + api.setSynchronousReturnValueForOnShowFileChooser(pigeon_instanceArg, valueArg) + listOf(null) + } catch (exception: Throwable) { + wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = + BasicMessageChannel( + binaryMessenger, + "dev.flutter.pigeon.webview_flutter_android.WebChromeClient.setSynchronousReturnValueForOnConsoleMessage", + codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val pigeon_instanceArg = + args[0] + as io.flutter.plugins.webviewflutter.WebChromeClientProxyApi.WebChromeClientImpl + val valueArg = args[1] as Boolean + val wrapped: List = + try { + api.setSynchronousReturnValueForOnConsoleMessage(pigeon_instanceArg, valueArg) + listOf(null) + } catch (exception: Throwable) { + wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = + BasicMessageChannel( + binaryMessenger, + "dev.flutter.pigeon.webview_flutter_android.WebChromeClient.setSynchronousReturnValueForOnJsAlert", + codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val pigeon_instanceArg = + args[0] + as io.flutter.plugins.webviewflutter.WebChromeClientProxyApi.WebChromeClientImpl + val valueArg = args[1] as Boolean + val wrapped: List = + try { + api.setSynchronousReturnValueForOnJsAlert(pigeon_instanceArg, valueArg) + listOf(null) + } catch (exception: Throwable) { + wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = + BasicMessageChannel( + binaryMessenger, + "dev.flutter.pigeon.webview_flutter_android.WebChromeClient.setSynchronousReturnValueForOnJsConfirm", + codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val pigeon_instanceArg = + args[0] + as io.flutter.plugins.webviewflutter.WebChromeClientProxyApi.WebChromeClientImpl + val valueArg = args[1] as Boolean + val wrapped: List = + try { + api.setSynchronousReturnValueForOnJsConfirm(pigeon_instanceArg, valueArg) + listOf(null) + } catch (exception: Throwable) { + wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = + BasicMessageChannel( + binaryMessenger, + "dev.flutter.pigeon.webview_flutter_android.WebChromeClient.setSynchronousReturnValueForOnJsPrompt", + codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val pigeon_instanceArg = + args[0] + as io.flutter.plugins.webviewflutter.WebChromeClientProxyApi.WebChromeClientImpl + val valueArg = args[1] as Boolean + val wrapped: List = + try { + api.setSynchronousReturnValueForOnJsPrompt(pigeon_instanceArg, valueArg) + listOf(null) + } catch (exception: Throwable) { + wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + } + } + + @Suppress("LocalVariableName", "FunctionName") + /** Creates a Dart instance of WebChromeClient and attaches it to [pigeon_instanceArg]. */ + fun pigeon_newInstance( + pigeon_instanceArg: + io.flutter.plugins.webviewflutter.WebChromeClientProxyApi.WebChromeClientImpl, + callback: (Result) -> Unit + ) { + if (pigeonRegistrar.ignoreCallsToDart) { + callback( + Result.failure( + AndroidWebKitError("ignore-calls-error", "Calls to Dart are being ignored.", ""))) + return + } + if (pigeonRegistrar.instanceManager.containsInstance(pigeon_instanceArg)) { + Result.success(Unit) + return + } + val pigeon_identifierArg = + pigeonRegistrar.instanceManager.addHostCreatedInstance(pigeon_instanceArg) + val binaryMessenger = pigeonRegistrar.binaryMessenger + val codec = pigeonRegistrar.codec + val channelName = + "dev.flutter.pigeon.webview_flutter_android.WebChromeClient.pigeon_newInstance" + val channel = BasicMessageChannel(binaryMessenger, channelName, codec) + channel.send(listOf(pigeon_identifierArg)) { + if (it is List<*>) { + if (it.size > 1) { + callback( + Result.failure( + AndroidWebKitError(it[0] as String, it[1] as String, it[2] as String?))) + } else { + callback(Result.success(Unit)) + } + } else { + callback(Result.failure(createConnectionError(channelName))) + } + } + } + + /** Tell the host application the current progress of loading a page. */ + fun onProgressChanged( + pigeon_instanceArg: + io.flutter.plugins.webviewflutter.WebChromeClientProxyApi.WebChromeClientImpl, + webViewArg: android.webkit.WebView, + progressArg: Long, + callback: (Result) -> Unit + ) { + if (pigeonRegistrar.ignoreCallsToDart) { + callback( + Result.failure( + AndroidWebKitError("ignore-calls-error", "Calls to Dart are being ignored.", ""))) + return + } + val binaryMessenger = pigeonRegistrar.binaryMessenger + val codec = pigeonRegistrar.codec + val channelName = "dev.flutter.pigeon.webview_flutter_android.WebChromeClient.onProgressChanged" + val channel = BasicMessageChannel(binaryMessenger, channelName, codec) + channel.send(listOf(pigeon_instanceArg, webViewArg, progressArg)) { + if (it is List<*>) { + if (it.size > 1) { + callback( + Result.failure( + AndroidWebKitError(it[0] as String, it[1] as String, it[2] as String?))) + } else { + callback(Result.success(Unit)) + } + } else { + callback(Result.failure(createConnectionError(channelName))) + } + } + } + + /** Tell the client to show a file chooser. */ + fun onShowFileChooser( + pigeon_instanceArg: + io.flutter.plugins.webviewflutter.WebChromeClientProxyApi.WebChromeClientImpl, + webViewArg: android.webkit.WebView, + paramsArg: android.webkit.WebChromeClient.FileChooserParams, + callback: (Result>) -> Unit + ) { + if (pigeonRegistrar.ignoreCallsToDart) { + callback( + Result.failure( + AndroidWebKitError("ignore-calls-error", "Calls to Dart are being ignored.", ""))) + return + } + val binaryMessenger = pigeonRegistrar.binaryMessenger + val codec = pigeonRegistrar.codec + val channelName = "dev.flutter.pigeon.webview_flutter_android.WebChromeClient.onShowFileChooser" + val channel = BasicMessageChannel(binaryMessenger, channelName, codec) + channel.send(listOf(pigeon_instanceArg, webViewArg, paramsArg)) { + if (it is List<*>) { + if (it.size > 1) { + callback( + Result.failure( + AndroidWebKitError(it[0] as String, it[1] as String, it[2] as String?))) + } else if (it[0] == null) { + callback( + Result.failure( + AndroidWebKitError( + "null-error", + "Flutter api returned null value for non-null return value.", + ""))) + } else { + val output = it[0] as List + callback(Result.success(output)) + } + } else { + callback(Result.failure(createConnectionError(channelName))) + } + } + } + + /** + * Notify the host application that web content is requesting permission to access the specified + * resources and the permission currently isn't granted or denied. + */ + fun onPermissionRequest( + pigeon_instanceArg: + io.flutter.plugins.webviewflutter.WebChromeClientProxyApi.WebChromeClientImpl, + requestArg: android.webkit.PermissionRequest, + callback: (Result) -> Unit + ) { + if (pigeonRegistrar.ignoreCallsToDart) { + callback( + Result.failure( + AndroidWebKitError("ignore-calls-error", "Calls to Dart are being ignored.", ""))) + return + } + val binaryMessenger = pigeonRegistrar.binaryMessenger + val codec = pigeonRegistrar.codec + val channelName = + "dev.flutter.pigeon.webview_flutter_android.WebChromeClient.onPermissionRequest" + val channel = BasicMessageChannel(binaryMessenger, channelName, codec) + channel.send(listOf(pigeon_instanceArg, requestArg)) { + if (it is List<*>) { + if (it.size > 1) { + callback( + Result.failure( + AndroidWebKitError(it[0] as String, it[1] as String, it[2] as String?))) + } else { + callback(Result.success(Unit)) + } + } else { + callback(Result.failure(createConnectionError(channelName))) + } + } + } + + /** Callback to Dart function `WebChromeClient.onShowCustomView`. */ + fun onShowCustomView( + pigeon_instanceArg: + io.flutter.plugins.webviewflutter.WebChromeClientProxyApi.WebChromeClientImpl, + viewArg: android.view.View, + callbackArg: android.webkit.WebChromeClient.CustomViewCallback, + callback: (Result) -> Unit + ) { + if (pigeonRegistrar.ignoreCallsToDart) { + callback( + Result.failure( + AndroidWebKitError("ignore-calls-error", "Calls to Dart are being ignored.", ""))) + return + } + val binaryMessenger = pigeonRegistrar.binaryMessenger + val codec = pigeonRegistrar.codec + val channelName = "dev.flutter.pigeon.webview_flutter_android.WebChromeClient.onShowCustomView" + val channel = BasicMessageChannel(binaryMessenger, channelName, codec) + channel.send(listOf(pigeon_instanceArg, viewArg, callbackArg)) { + if (it is List<*>) { + if (it.size > 1) { + callback( + Result.failure( + AndroidWebKitError(it[0] as String, it[1] as String, it[2] as String?))) + } else { + callback(Result.success(Unit)) + } + } else { + callback(Result.failure(createConnectionError(channelName))) + } + } + } + + /** Notify the host application that the current page has entered full screen mode. */ + fun onHideCustomView( + pigeon_instanceArg: + io.flutter.plugins.webviewflutter.WebChromeClientProxyApi.WebChromeClientImpl, + callback: (Result) -> Unit + ) { + if (pigeonRegistrar.ignoreCallsToDart) { + callback( + Result.failure( + AndroidWebKitError("ignore-calls-error", "Calls to Dart are being ignored.", ""))) + return + } + val binaryMessenger = pigeonRegistrar.binaryMessenger + val codec = pigeonRegistrar.codec + val channelName = "dev.flutter.pigeon.webview_flutter_android.WebChromeClient.onHideCustomView" + val channel = BasicMessageChannel(binaryMessenger, channelName, codec) + channel.send(listOf(pigeon_instanceArg)) { + if (it is List<*>) { + if (it.size > 1) { + callback( + Result.failure( + AndroidWebKitError(it[0] as String, it[1] as String, it[2] as String?))) + } else { + callback(Result.success(Unit)) + } + } else { + callback(Result.failure(createConnectionError(channelName))) + } + } + } + + /** + * Notify the host application that web content from the specified origin is attempting to use the + * Geolocation API, but no permission state is currently set for that origin. + */ + fun onGeolocationPermissionsShowPrompt( + pigeon_instanceArg: + io.flutter.plugins.webviewflutter.WebChromeClientProxyApi.WebChromeClientImpl, + originArg: String, + callbackArg: android.webkit.GeolocationPermissions.Callback, + callback: (Result) -> Unit + ) { + if (pigeonRegistrar.ignoreCallsToDart) { + callback( + Result.failure( + AndroidWebKitError("ignore-calls-error", "Calls to Dart are being ignored.", ""))) + return + } + val binaryMessenger = pigeonRegistrar.binaryMessenger + val codec = pigeonRegistrar.codec + val channelName = + "dev.flutter.pigeon.webview_flutter_android.WebChromeClient.onGeolocationPermissionsShowPrompt" + val channel = BasicMessageChannel(binaryMessenger, channelName, codec) + channel.send(listOf(pigeon_instanceArg, originArg, callbackArg)) { + if (it is List<*>) { + if (it.size > 1) { + callback( + Result.failure( + AndroidWebKitError(it[0] as String, it[1] as String, it[2] as String?))) + } else { + callback(Result.success(Unit)) + } + } else { + callback(Result.failure(createConnectionError(channelName))) + } + } + } + + /** + * Notify the host application that a request for Geolocation permissions, made with a previous + * call to `onGeolocationPermissionsShowPrompt` has been canceled. + */ + fun onGeolocationPermissionsHidePrompt( + pigeon_instanceArg: + io.flutter.plugins.webviewflutter.WebChromeClientProxyApi.WebChromeClientImpl, + callback: (Result) -> Unit + ) { + if (pigeonRegistrar.ignoreCallsToDart) { + callback( + Result.failure( + AndroidWebKitError("ignore-calls-error", "Calls to Dart are being ignored.", ""))) + return + } + val binaryMessenger = pigeonRegistrar.binaryMessenger + val codec = pigeonRegistrar.codec + val channelName = + "dev.flutter.pigeon.webview_flutter_android.WebChromeClient.onGeolocationPermissionsHidePrompt" + val channel = BasicMessageChannel(binaryMessenger, channelName, codec) + channel.send(listOf(pigeon_instanceArg)) { + if (it is List<*>) { + if (it.size > 1) { + callback( + Result.failure( + AndroidWebKitError(it[0] as String, it[1] as String, it[2] as String?))) + } else { + callback(Result.success(Unit)) + } + } else { + callback(Result.failure(createConnectionError(channelName))) + } + } + } + + /** Report a JavaScript console message to the host application. */ + fun onConsoleMessage( + pigeon_instanceArg: + io.flutter.plugins.webviewflutter.WebChromeClientProxyApi.WebChromeClientImpl, + messageArg: android.webkit.ConsoleMessage, + callback: (Result) -> Unit + ) { + if (pigeonRegistrar.ignoreCallsToDart) { + callback( + Result.failure( + AndroidWebKitError("ignore-calls-error", "Calls to Dart are being ignored.", ""))) + return + } + val binaryMessenger = pigeonRegistrar.binaryMessenger + val codec = pigeonRegistrar.codec + val channelName = "dev.flutter.pigeon.webview_flutter_android.WebChromeClient.onConsoleMessage" + val channel = BasicMessageChannel(binaryMessenger, channelName, codec) + channel.send(listOf(pigeon_instanceArg, messageArg)) { + if (it is List<*>) { + if (it.size > 1) { + callback( + Result.failure( + AndroidWebKitError(it[0] as String, it[1] as String, it[2] as String?))) + } else { + callback(Result.success(Unit)) + } + } else { + callback(Result.failure(createConnectionError(channelName))) + } + } + } + + /** + * Notify the host application that the web page wants to display a JavaScript `alert()` dialog. + */ + fun onJsAlert( + pigeon_instanceArg: + io.flutter.plugins.webviewflutter.WebChromeClientProxyApi.WebChromeClientImpl, + webViewArg: android.webkit.WebView, + urlArg: String, + messageArg: String, + callback: (Result) -> Unit + ) { + if (pigeonRegistrar.ignoreCallsToDart) { + callback( + Result.failure( + AndroidWebKitError("ignore-calls-error", "Calls to Dart are being ignored.", ""))) + return + } + val binaryMessenger = pigeonRegistrar.binaryMessenger + val codec = pigeonRegistrar.codec + val channelName = "dev.flutter.pigeon.webview_flutter_android.WebChromeClient.onJsAlert" + val channel = BasicMessageChannel(binaryMessenger, channelName, codec) + channel.send(listOf(pigeon_instanceArg, webViewArg, urlArg, messageArg)) { + if (it is List<*>) { + if (it.size > 1) { + callback( + Result.failure( + AndroidWebKitError(it[0] as String, it[1] as String, it[2] as String?))) + } else { + callback(Result.success(Unit)) + } + } else { + callback(Result.failure(createConnectionError(channelName))) + } + } + } + + /** + * Notify the host application that the web page wants to display a JavaScript `confirm()` dialog. + */ + fun onJsConfirm( + pigeon_instanceArg: + io.flutter.plugins.webviewflutter.WebChromeClientProxyApi.WebChromeClientImpl, + webViewArg: android.webkit.WebView, + urlArg: String, + messageArg: String, + callback: (Result) -> Unit + ) { + if (pigeonRegistrar.ignoreCallsToDart) { + callback( + Result.failure( + AndroidWebKitError("ignore-calls-error", "Calls to Dart are being ignored.", ""))) + return + } + val binaryMessenger = pigeonRegistrar.binaryMessenger + val codec = pigeonRegistrar.codec + val channelName = "dev.flutter.pigeon.webview_flutter_android.WebChromeClient.onJsConfirm" + val channel = BasicMessageChannel(binaryMessenger, channelName, codec) + channel.send(listOf(pigeon_instanceArg, webViewArg, urlArg, messageArg)) { + if (it is List<*>) { + if (it.size > 1) { + callback( + Result.failure( + AndroidWebKitError(it[0] as String, it[1] as String, it[2] as String?))) + } else if (it[0] == null) { + callback( + Result.failure( + AndroidWebKitError( + "null-error", + "Flutter api returned null value for non-null return value.", + ""))) + } else { + val output = it[0] as Boolean + callback(Result.success(output)) + } + } else { + callback(Result.failure(createConnectionError(channelName))) + } + } + } + + /** + * Notify the host application that the web page wants to display a JavaScript `prompt()` dialog. + */ + fun onJsPrompt( + pigeon_instanceArg: + io.flutter.plugins.webviewflutter.WebChromeClientProxyApi.WebChromeClientImpl, + webViewArg: android.webkit.WebView, + urlArg: String, + messageArg: String, + defaultValueArg: String, + callback: (Result) -> Unit + ) { + if (pigeonRegistrar.ignoreCallsToDart) { + callback( + Result.failure( + AndroidWebKitError("ignore-calls-error", "Calls to Dart are being ignored.", ""))) + return + } + val binaryMessenger = pigeonRegistrar.binaryMessenger + val codec = pigeonRegistrar.codec + val channelName = "dev.flutter.pigeon.webview_flutter_android.WebChromeClient.onJsPrompt" + val channel = BasicMessageChannel(binaryMessenger, channelName, codec) + channel.send(listOf(pigeon_instanceArg, webViewArg, urlArg, messageArg, defaultValueArg)) { + if (it is List<*>) { + if (it.size > 1) { + callback( + Result.failure( + AndroidWebKitError(it[0] as String, it[1] as String, it[2] as String?))) + } else { + val output = it[0] as String? + callback(Result.success(output)) + } + } else { + callback(Result.failure(createConnectionError(channelName))) + } + } + } +} +/** + * Provides access to the assets registered as part of the App bundle. + * + * Convenience class for accessing Flutter asset resources. + */ +@Suppress("UNCHECKED_CAST") +abstract class PigeonApiFlutterAssetManager( + open val pigeonRegistrar: AndroidWebkitLibraryPigeonProxyApiRegistrar +) { + /** The global instance of the `FlutterAssetManager`. */ + abstract fun instance(): io.flutter.plugins.webviewflutter.FlutterAssetManager + + /** + * Returns a String array of all the assets at the given path. + * + * Throws an IOException in case I/O operations were interrupted. + */ + abstract fun list( + pigeon_instance: io.flutter.plugins.webviewflutter.FlutterAssetManager, + path: String + ): List + + /** + * Gets the relative file path to the Flutter asset with the given name, including the file's + * extension, e.g., "myImage.jpg". + * + * The returned file path is relative to the Android app's standard asset's directory. Therefore, + * the returned path is appropriate to pass to Android's AssetManager, but the path is not + * appropriate to load as an absolute path. + */ + abstract fun getAssetFilePathByName( + pigeon_instance: io.flutter.plugins.webviewflutter.FlutterAssetManager, + name: String + ): String + + companion object { + @Suppress("LocalVariableName") + fun setUpMessageHandlers(binaryMessenger: BinaryMessenger, api: PigeonApiFlutterAssetManager?) { + val codec = api?.pigeonRegistrar?.codec ?: AndroidWebkitLibraryPigeonCodec() + run { + val channel = + BasicMessageChannel( + binaryMessenger, + "dev.flutter.pigeon.webview_flutter_android.FlutterAssetManager.instance", + codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val pigeon_identifierArg = args[0] as Long + val wrapped: List = + try { + api.pigeonRegistrar.instanceManager.addDartCreatedInstance( + api.instance(), pigeon_identifierArg) + listOf(null) + } catch (exception: Throwable) { + wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = + BasicMessageChannel( + binaryMessenger, + "dev.flutter.pigeon.webview_flutter_android.FlutterAssetManager.list", + codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val pigeon_instanceArg = + args[0] as io.flutter.plugins.webviewflutter.FlutterAssetManager + val pathArg = args[1] as String + val wrapped: List = + try { + listOf(api.list(pigeon_instanceArg, pathArg)) + } catch (exception: Throwable) { + wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = + BasicMessageChannel( + binaryMessenger, + "dev.flutter.pigeon.webview_flutter_android.FlutterAssetManager.getAssetFilePathByName", + codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val pigeon_instanceArg = + args[0] as io.flutter.plugins.webviewflutter.FlutterAssetManager + val nameArg = args[1] as String + val wrapped: List = + try { + listOf(api.getAssetFilePathByName(pigeon_instanceArg, nameArg)) + } catch (exception: Throwable) { + wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + } + } + + @Suppress("LocalVariableName", "FunctionName") + /** Creates a Dart instance of FlutterAssetManager and attaches it to [pigeon_instanceArg]. */ + fun pigeon_newInstance( + pigeon_instanceArg: io.flutter.plugins.webviewflutter.FlutterAssetManager, + callback: (Result) -> Unit + ) { + if (pigeonRegistrar.ignoreCallsToDart) { + callback( + Result.failure( + AndroidWebKitError("ignore-calls-error", "Calls to Dart are being ignored.", ""))) + return + } + if (pigeonRegistrar.instanceManager.containsInstance(pigeon_instanceArg)) { + Result.success(Unit) + return + } + val pigeon_identifierArg = + pigeonRegistrar.instanceManager.addHostCreatedInstance(pigeon_instanceArg) + val binaryMessenger = pigeonRegistrar.binaryMessenger + val codec = pigeonRegistrar.codec + val channelName = + "dev.flutter.pigeon.webview_flutter_android.FlutterAssetManager.pigeon_newInstance" + val channel = BasicMessageChannel(binaryMessenger, channelName, codec) + channel.send(listOf(pigeon_identifierArg)) { + if (it is List<*>) { + if (it.size > 1) { + callback( + Result.failure( + AndroidWebKitError(it[0] as String, it[1] as String, it[2] as String?))) + } else { + callback(Result.success(Unit)) + } + } else { + callback(Result.failure(createConnectionError(channelName))) + } + } + } +} +/** + * This class is used to manage the JavaScript storage APIs provided by the WebView. + * + * See https://developer.android.com/reference/android/webkit/WebStorage. + */ +@Suppress("UNCHECKED_CAST") +abstract class PigeonApiWebStorage( + open val pigeonRegistrar: AndroidWebkitLibraryPigeonProxyApiRegistrar +) { + abstract fun instance(): android.webkit.WebStorage + + /** Clears all storage currently being used by the JavaScript storage APIs. */ + abstract fun deleteAllData(pigeon_instance: android.webkit.WebStorage) + + companion object { + @Suppress("LocalVariableName") + fun setUpMessageHandlers(binaryMessenger: BinaryMessenger, api: PigeonApiWebStorage?) { + val codec = api?.pigeonRegistrar?.codec ?: AndroidWebkitLibraryPigeonCodec() + run { + val channel = + BasicMessageChannel( + binaryMessenger, + "dev.flutter.pigeon.webview_flutter_android.WebStorage.instance", + codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val pigeon_identifierArg = args[0] as Long + val wrapped: List = + try { + api.pigeonRegistrar.instanceManager.addDartCreatedInstance( + api.instance(), pigeon_identifierArg) + listOf(null) + } catch (exception: Throwable) { + wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = + BasicMessageChannel( + binaryMessenger, + "dev.flutter.pigeon.webview_flutter_android.WebStorage.deleteAllData", + codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val pigeon_instanceArg = args[0] as android.webkit.WebStorage + val wrapped: List = + try { + api.deleteAllData(pigeon_instanceArg) + listOf(null) + } catch (exception: Throwable) { + wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + } + } + + @Suppress("LocalVariableName", "FunctionName") + /** Creates a Dart instance of WebStorage and attaches it to [pigeon_instanceArg]. */ + fun pigeon_newInstance( + pigeon_instanceArg: android.webkit.WebStorage, + callback: (Result) -> Unit + ) { + if (pigeonRegistrar.ignoreCallsToDart) { + callback( + Result.failure( + AndroidWebKitError("ignore-calls-error", "Calls to Dart are being ignored.", ""))) + return + } + if (pigeonRegistrar.instanceManager.containsInstance(pigeon_instanceArg)) { + Result.success(Unit) + return + } + val pigeon_identifierArg = + pigeonRegistrar.instanceManager.addHostCreatedInstance(pigeon_instanceArg) + val binaryMessenger = pigeonRegistrar.binaryMessenger + val codec = pigeonRegistrar.codec + val channelName = "dev.flutter.pigeon.webview_flutter_android.WebStorage.pigeon_newInstance" + val channel = BasicMessageChannel(binaryMessenger, channelName, codec) + channel.send(listOf(pigeon_identifierArg)) { + if (it is List<*>) { + if (it.size > 1) { + callback( + Result.failure( + AndroidWebKitError(it[0] as String, it[1] as String, it[2] as String?))) + } else { + callback(Result.success(Unit)) + } + } else { + callback(Result.failure(createConnectionError(channelName))) + } + } + } +} +/** + * Parameters used in the `WebChromeClient.onShowFileChooser` method. + * + * See https://developer.android.com/reference/android/webkit/WebChromeClient.FileChooserParams. + */ +@Suppress("UNCHECKED_CAST") +abstract class PigeonApiFileChooserParams( + open val pigeonRegistrar: AndroidWebkitLibraryPigeonProxyApiRegistrar +) { + /** Preference for a live media captured value (e.g. Camera, Microphone). */ + abstract fun isCaptureEnabled( + pigeon_instance: android.webkit.WebChromeClient.FileChooserParams + ): Boolean + + /** An array of acceptable MIME types. */ + abstract fun acceptTypes( + pigeon_instance: android.webkit.WebChromeClient.FileChooserParams + ): List + + /** File chooser mode. */ + abstract fun mode( + pigeon_instance: android.webkit.WebChromeClient.FileChooserParams + ): FileChooserMode + + /** File name of a default selection if specified, or null. */ + abstract fun filenameHint( + pigeon_instance: android.webkit.WebChromeClient.FileChooserParams + ): String? + + @Suppress("LocalVariableName", "FunctionName") + /** Creates a Dart instance of FileChooserParams and attaches it to [pigeon_instanceArg]. */ + fun pigeon_newInstance( + pigeon_instanceArg: android.webkit.WebChromeClient.FileChooserParams, + callback: (Result) -> Unit + ) { + if (pigeonRegistrar.ignoreCallsToDart) { + callback( + Result.failure( + AndroidWebKitError("ignore-calls-error", "Calls to Dart are being ignored.", ""))) + return + } + if (pigeonRegistrar.instanceManager.containsInstance(pigeon_instanceArg)) { + Result.success(Unit) + return + } + val pigeon_identifierArg = + pigeonRegistrar.instanceManager.addHostCreatedInstance(pigeon_instanceArg) + val isCaptureEnabledArg = isCaptureEnabled(pigeon_instanceArg) + val acceptTypesArg = acceptTypes(pigeon_instanceArg) + val modeArg = mode(pigeon_instanceArg) + val filenameHintArg = filenameHint(pigeon_instanceArg) + val binaryMessenger = pigeonRegistrar.binaryMessenger + val codec = pigeonRegistrar.codec + val channelName = + "dev.flutter.pigeon.webview_flutter_android.FileChooserParams.pigeon_newInstance" + val channel = BasicMessageChannel(binaryMessenger, channelName, codec) + channel.send( + listOf( + pigeon_identifierArg, isCaptureEnabledArg, acceptTypesArg, modeArg, filenameHintArg)) { + if (it is List<*>) { + if (it.size > 1) { + callback( + Result.failure( + AndroidWebKitError(it[0] as String, it[1] as String, it[2] as String?))) + } else { + callback(Result.success(Unit)) + } + } else { + callback(Result.failure(createConnectionError(channelName))) + } + } + } +} +/** + * This class defines a permission request and is used when web content requests access to protected + * resources. + * + * See https://developer.android.com/reference/android/webkit/PermissionRequest. + */ +@Suppress("UNCHECKED_CAST") +abstract class PigeonApiPermissionRequest( + open val pigeonRegistrar: AndroidWebkitLibraryPigeonProxyApiRegistrar +) { + abstract fun resources(pigeon_instance: android.webkit.PermissionRequest): List + + /** Call this method to grant origin the permission to access the given resources. */ + abstract fun grant(pigeon_instance: android.webkit.PermissionRequest, resources: List) + + /** Call this method to deny the request. */ + abstract fun deny(pigeon_instance: android.webkit.PermissionRequest) + + companion object { + @Suppress("LocalVariableName") + fun setUpMessageHandlers(binaryMessenger: BinaryMessenger, api: PigeonApiPermissionRequest?) { + val codec = api?.pigeonRegistrar?.codec ?: AndroidWebkitLibraryPigeonCodec() + run { + val channel = + BasicMessageChannel( + binaryMessenger, + "dev.flutter.pigeon.webview_flutter_android.PermissionRequest.grant", + codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val pigeon_instanceArg = args[0] as android.webkit.PermissionRequest + val resourcesArg = args[1] as List + val wrapped: List = + try { + api.grant(pigeon_instanceArg, resourcesArg) + listOf(null) + } catch (exception: Throwable) { + wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = + BasicMessageChannel( + binaryMessenger, + "dev.flutter.pigeon.webview_flutter_android.PermissionRequest.deny", + codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val pigeon_instanceArg = args[0] as android.webkit.PermissionRequest + val wrapped: List = + try { + api.deny(pigeon_instanceArg) + listOf(null) + } catch (exception: Throwable) { + wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + } + } + + @Suppress("LocalVariableName", "FunctionName") + /** Creates a Dart instance of PermissionRequest and attaches it to [pigeon_instanceArg]. */ + fun pigeon_newInstance( + pigeon_instanceArg: android.webkit.PermissionRequest, + callback: (Result) -> Unit + ) { + if (pigeonRegistrar.ignoreCallsToDart) { + callback( + Result.failure( + AndroidWebKitError("ignore-calls-error", "Calls to Dart are being ignored.", ""))) + return + } + if (pigeonRegistrar.instanceManager.containsInstance(pigeon_instanceArg)) { + Result.success(Unit) + return + } + val pigeon_identifierArg = + pigeonRegistrar.instanceManager.addHostCreatedInstance(pigeon_instanceArg) + val resourcesArg = resources(pigeon_instanceArg) + val binaryMessenger = pigeonRegistrar.binaryMessenger + val codec = pigeonRegistrar.codec + val channelName = + "dev.flutter.pigeon.webview_flutter_android.PermissionRequest.pigeon_newInstance" + val channel = BasicMessageChannel(binaryMessenger, channelName, codec) + channel.send(listOf(pigeon_identifierArg, resourcesArg)) { + if (it is List<*>) { + if (it.size > 1) { + callback( + Result.failure( + AndroidWebKitError(it[0] as String, it[1] as String, it[2] as String?))) + } else { + callback(Result.success(Unit)) + } + } else { + callback(Result.failure(createConnectionError(channelName))) + } + } + } +} +/** + * A callback interface used by the host application to notify the current page that its custom view + * has been dismissed. + * + * See https://developer.android.com/reference/android/webkit/WebChromeClient.CustomViewCallback. + */ +@Suppress("UNCHECKED_CAST") +abstract class PigeonApiCustomViewCallback( + open val pigeonRegistrar: AndroidWebkitLibraryPigeonProxyApiRegistrar +) { + /** Invoked when the host application dismisses the custom view. */ + abstract fun onCustomViewHidden( + pigeon_instance: android.webkit.WebChromeClient.CustomViewCallback + ) + + companion object { + @Suppress("LocalVariableName") + fun setUpMessageHandlers(binaryMessenger: BinaryMessenger, api: PigeonApiCustomViewCallback?) { + val codec = api?.pigeonRegistrar?.codec ?: AndroidWebkitLibraryPigeonCodec() + run { + val channel = + BasicMessageChannel( + binaryMessenger, + "dev.flutter.pigeon.webview_flutter_android.CustomViewCallback.onCustomViewHidden", + codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val pigeon_instanceArg = args[0] as android.webkit.WebChromeClient.CustomViewCallback + val wrapped: List = + try { + api.onCustomViewHidden(pigeon_instanceArg) + listOf(null) + } catch (exception: Throwable) { + wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + } + } + + @Suppress("LocalVariableName", "FunctionName") + /** Creates a Dart instance of CustomViewCallback and attaches it to [pigeon_instanceArg]. */ + fun pigeon_newInstance( + pigeon_instanceArg: android.webkit.WebChromeClient.CustomViewCallback, + callback: (Result) -> Unit + ) { + if (pigeonRegistrar.ignoreCallsToDart) { + callback( + Result.failure( + AndroidWebKitError("ignore-calls-error", "Calls to Dart are being ignored.", ""))) + return + } + if (pigeonRegistrar.instanceManager.containsInstance(pigeon_instanceArg)) { + Result.success(Unit) + return + } + val pigeon_identifierArg = + pigeonRegistrar.instanceManager.addHostCreatedInstance(pigeon_instanceArg) + val binaryMessenger = pigeonRegistrar.binaryMessenger + val codec = pigeonRegistrar.codec + val channelName = + "dev.flutter.pigeon.webview_flutter_android.CustomViewCallback.pigeon_newInstance" + val channel = BasicMessageChannel(binaryMessenger, channelName, codec) + channel.send(listOf(pigeon_identifierArg)) { + if (it is List<*>) { + if (it.size > 1) { + callback( + Result.failure( + AndroidWebKitError(it[0] as String, it[1] as String, it[2] as String?))) + } else { + callback(Result.success(Unit)) + } + } else { + callback(Result.failure(createConnectionError(channelName))) + } + } + } +} +/** + * This class represents the basic building block for user interface components. + * + * See https://developer.android.com/reference/android/view/View. + */ +@Suppress("UNCHECKED_CAST") +abstract class PigeonApiView( + open val pigeonRegistrar: AndroidWebkitLibraryPigeonProxyApiRegistrar +) { + /** Set the scrolled position of your view. */ + abstract fun scrollTo(pigeon_instance: android.view.View, x: Long, y: Long) + + /** Move the scrolled position of your view. */ + abstract fun scrollBy(pigeon_instance: android.view.View, x: Long, y: Long) + + /** Return the scrolled position of this view. */ + abstract fun getScrollPosition(pigeon_instance: android.view.View): WebViewPoint + + companion object { + @Suppress("LocalVariableName") + fun setUpMessageHandlers(binaryMessenger: BinaryMessenger, api: PigeonApiView?) { + val codec = api?.pigeonRegistrar?.codec ?: AndroidWebkitLibraryPigeonCodec() + run { + val channel = + BasicMessageChannel( + binaryMessenger, "dev.flutter.pigeon.webview_flutter_android.View.scrollTo", codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val pigeon_instanceArg = args[0] as android.view.View + val xArg = args[1] as Long + val yArg = args[2] as Long + val wrapped: List = + try { + api.scrollTo(pigeon_instanceArg, xArg, yArg) + listOf(null) + } catch (exception: Throwable) { + wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = + BasicMessageChannel( + binaryMessenger, "dev.flutter.pigeon.webview_flutter_android.View.scrollBy", codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val pigeon_instanceArg = args[0] as android.view.View + val xArg = args[1] as Long + val yArg = args[2] as Long + val wrapped: List = + try { + api.scrollBy(pigeon_instanceArg, xArg, yArg) + listOf(null) + } catch (exception: Throwable) { + wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = + BasicMessageChannel( + binaryMessenger, + "dev.flutter.pigeon.webview_flutter_android.View.getScrollPosition", + codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val pigeon_instanceArg = args[0] as android.view.View + val wrapped: List = + try { + listOf(api.getScrollPosition(pigeon_instanceArg)) + } catch (exception: Throwable) { + wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + } + } + + @Suppress("LocalVariableName", "FunctionName") + /** Creates a Dart instance of View and attaches it to [pigeon_instanceArg]. */ + fun pigeon_newInstance(pigeon_instanceArg: android.view.View, callback: (Result) -> Unit) { + if (pigeonRegistrar.ignoreCallsToDart) { + callback( + Result.failure( + AndroidWebKitError("ignore-calls-error", "Calls to Dart are being ignored.", ""))) + return + } + if (pigeonRegistrar.instanceManager.containsInstance(pigeon_instanceArg)) { + Result.success(Unit) + return + } + val pigeon_identifierArg = + pigeonRegistrar.instanceManager.addHostCreatedInstance(pigeon_instanceArg) + val binaryMessenger = pigeonRegistrar.binaryMessenger + val codec = pigeonRegistrar.codec + val channelName = "dev.flutter.pigeon.webview_flutter_android.View.pigeon_newInstance" + val channel = BasicMessageChannel(binaryMessenger, channelName, codec) + channel.send(listOf(pigeon_identifierArg)) { + if (it is List<*>) { + if (it.size > 1) { + callback( + Result.failure( + AndroidWebKitError(it[0] as String, it[1] as String, it[2] as String?))) + } else { + callback(Result.success(Unit)) + } + } else { + callback(Result.failure(createConnectionError(channelName))) + } + } + } +} +/** + * A callback interface used by the host application to set the Geolocation permission state for an + * origin. + * + * See https://developer.android.com/reference/android/webkit/GeolocationPermissions.Callback. + */ +@Suppress("UNCHECKED_CAST") +abstract class PigeonApiGeolocationPermissionsCallback( + open val pigeonRegistrar: AndroidWebkitLibraryPigeonProxyApiRegistrar +) { + /** Sets the Geolocation permission state for the supplied origin. */ + abstract fun invoke( + pigeon_instance: android.webkit.GeolocationPermissions.Callback, + origin: String, + allow: Boolean, + retain: Boolean + ) + + companion object { + @Suppress("LocalVariableName") + fun setUpMessageHandlers( + binaryMessenger: BinaryMessenger, + api: PigeonApiGeolocationPermissionsCallback? + ) { + val codec = api?.pigeonRegistrar?.codec ?: AndroidWebkitLibraryPigeonCodec() + run { + val channel = + BasicMessageChannel( + binaryMessenger, + "dev.flutter.pigeon.webview_flutter_android.GeolocationPermissionsCallback.invoke", + codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val pigeon_instanceArg = args[0] as android.webkit.GeolocationPermissions.Callback + val originArg = args[1] as String + val allowArg = args[2] as Boolean + val retainArg = args[3] as Boolean + val wrapped: List = + try { + api.invoke(pigeon_instanceArg, originArg, allowArg, retainArg) + listOf(null) + } catch (exception: Throwable) { + wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + } + } + + @Suppress("LocalVariableName", "FunctionName") + /** + * Creates a Dart instance of GeolocationPermissionsCallback and attaches it to + * [pigeon_instanceArg]. + */ + fun pigeon_newInstance( + pigeon_instanceArg: android.webkit.GeolocationPermissions.Callback, + callback: (Result) -> Unit + ) { + if (pigeonRegistrar.ignoreCallsToDart) { + callback( + Result.failure( + AndroidWebKitError("ignore-calls-error", "Calls to Dart are being ignored.", ""))) + return + } + if (pigeonRegistrar.instanceManager.containsInstance(pigeon_instanceArg)) { + Result.success(Unit) + return + } + val pigeon_identifierArg = + pigeonRegistrar.instanceManager.addHostCreatedInstance(pigeon_instanceArg) + val binaryMessenger = pigeonRegistrar.binaryMessenger + val codec = pigeonRegistrar.codec + val channelName = + "dev.flutter.pigeon.webview_flutter_android.GeolocationPermissionsCallback.pigeon_newInstance" + val channel = BasicMessageChannel(binaryMessenger, channelName, codec) + channel.send(listOf(pigeon_identifierArg)) { + if (it is List<*>) { + if (it.size > 1) { + callback( + Result.failure( + AndroidWebKitError(it[0] as String, it[1] as String, it[2] as String?))) + } else { + callback(Result.success(Unit)) + } + } else { + callback(Result.failure(createConnectionError(channelName))) + } + } + } +} +/** + * Represents a request for HTTP authentication. + * + * See https://developer.android.com/reference/android/webkit/HttpAuthHandler. + */ +@Suppress("UNCHECKED_CAST") +abstract class PigeonApiHttpAuthHandler( + open val pigeonRegistrar: AndroidWebkitLibraryPigeonProxyApiRegistrar +) { + /** + * Gets whether the credentials stored for the current host (i.e. the host for which + * `WebViewClient.onReceivedHttpAuthRequest` was called) are suitable for use. + */ + abstract fun useHttpAuthUsernamePassword(pigeon_instance: android.webkit.HttpAuthHandler): Boolean + + /** Instructs the WebView to cancel the authentication request.. */ + abstract fun cancel(pigeon_instance: android.webkit.HttpAuthHandler) + + /** Instructs the WebView to proceed with the authentication with the given credentials. */ + abstract fun proceed( + pigeon_instance: android.webkit.HttpAuthHandler, + username: String, + password: String + ) + + companion object { + @Suppress("LocalVariableName") + fun setUpMessageHandlers(binaryMessenger: BinaryMessenger, api: PigeonApiHttpAuthHandler?) { + val codec = api?.pigeonRegistrar?.codec ?: AndroidWebkitLibraryPigeonCodec() + run { + val channel = + BasicMessageChannel( + binaryMessenger, + "dev.flutter.pigeon.webview_flutter_android.HttpAuthHandler.useHttpAuthUsernamePassword", + codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val pigeon_instanceArg = args[0] as android.webkit.HttpAuthHandler + val wrapped: List = + try { + listOf(api.useHttpAuthUsernamePassword(pigeon_instanceArg)) + } catch (exception: Throwable) { + wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = + BasicMessageChannel( + binaryMessenger, + "dev.flutter.pigeon.webview_flutter_android.HttpAuthHandler.cancel", + codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val pigeon_instanceArg = args[0] as android.webkit.HttpAuthHandler + val wrapped: List = + try { + api.cancel(pigeon_instanceArg) + listOf(null) + } catch (exception: Throwable) { + wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + run { + val channel = + BasicMessageChannel( + binaryMessenger, + "dev.flutter.pigeon.webview_flutter_android.HttpAuthHandler.proceed", + codec) + if (api != null) { + channel.setMessageHandler { message, reply -> + val args = message as List + val pigeon_instanceArg = args[0] as android.webkit.HttpAuthHandler + val usernameArg = args[1] as String + val passwordArg = args[2] as String + val wrapped: List = + try { + api.proceed(pigeon_instanceArg, usernameArg, passwordArg) + listOf(null) + } catch (exception: Throwable) { + wrapError(exception) + } + reply.reply(wrapped) + } + } else { + channel.setMessageHandler(null) + } + } + } + } + + @Suppress("LocalVariableName", "FunctionName") + /** Creates a Dart instance of HttpAuthHandler and attaches it to [pigeon_instanceArg]. */ + fun pigeon_newInstance( + pigeon_instanceArg: android.webkit.HttpAuthHandler, + callback: (Result) -> Unit + ) { + if (pigeonRegistrar.ignoreCallsToDart) { + callback( + Result.failure( + AndroidWebKitError("ignore-calls-error", "Calls to Dart are being ignored.", ""))) + return + } + if (pigeonRegistrar.instanceManager.containsInstance(pigeon_instanceArg)) { + Result.success(Unit) + return + } + val pigeon_identifierArg = + pigeonRegistrar.instanceManager.addHostCreatedInstance(pigeon_instanceArg) + val binaryMessenger = pigeonRegistrar.binaryMessenger + val codec = pigeonRegistrar.codec + val channelName = + "dev.flutter.pigeon.webview_flutter_android.HttpAuthHandler.pigeon_newInstance" + val channel = BasicMessageChannel(binaryMessenger, channelName, codec) + channel.send(listOf(pigeon_identifierArg)) { + if (it is List<*>) { + if (it.size > 1) { + callback( + Result.failure( + AndroidWebKitError(it[0] as String, it[1] as String, it[2] as String?))) + } else { + callback(Result.success(Unit)) + } + } else { + callback(Result.failure(createConnectionError(channelName))) + } + } + } +} diff --git a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/ConsoleMessageProxyApi.java b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/ConsoleMessageProxyApi.java new file mode 100644 index 000000000000..4b566356a559 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/ConsoleMessageProxyApi.java @@ -0,0 +1,50 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +package io.flutter.plugins.webviewflutter; + +import android.webkit.ConsoleMessage; +import androidx.annotation.NonNull; + +public class ConsoleMessageProxyApi extends PigeonApiConsoleMessage { + public ConsoleMessageProxyApi(@NonNull ProxyApiRegistrar pigeonRegistrar) { + super(pigeonRegistrar); + } + + @Override + public long lineNumber(@NonNull ConsoleMessage pigeon_instance) { + return pigeon_instance.lineNumber(); + } + + @NonNull + @Override + public String message(@NonNull ConsoleMessage pigeon_instance) { + return pigeon_instance.message(); + } + + @NonNull + @Override + public ConsoleMessageLevel level(@NonNull ConsoleMessage pigeon_instance) { + switch (pigeon_instance.messageLevel()) { + case TIP: + return ConsoleMessageLevel.TIP; + case LOG: + return ConsoleMessageLevel.LOG; + case WARNING: + return ConsoleMessageLevel.WARNING; + case ERROR: + return ConsoleMessageLevel.ERROR; + case DEBUG: + return ConsoleMessageLevel.DEBUG; + default: + return ConsoleMessageLevel.UNKNOWN; + } + } + + @NonNull + @Override + public String sourceId(@NonNull ConsoleMessage pigeon_instance) { + return pigeon_instance.sourceId(); + } +} diff --git a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/CookieManagerHostApiImpl.java b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/CookieManagerHostApiImpl.java deleted file mode 100644 index 51ecfcb97596..000000000000 --- a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/CookieManagerHostApiImpl.java +++ /dev/null @@ -1,133 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -package io.flutter.plugins.webviewflutter; - -import android.os.Build; -import android.webkit.CookieManager; -import androidx.annotation.ChecksSdkIntAtLeast; -import androidx.annotation.NonNull; -import androidx.annotation.VisibleForTesting; -import io.flutter.plugin.common.BinaryMessenger; -import io.flutter.plugins.webviewflutter.GeneratedAndroidWebView.CookieManagerHostApi; -import java.util.Objects; - -/** - * Host API implementation for `CookieManager`. - * - *

This class may handle instantiating and adding native object instances that are attached to a - * Dart instance or handle method calls on the associated native class or an instance of the class. - */ -public class CookieManagerHostApiImpl implements CookieManagerHostApi { - // To ease adding additional methods, this value is added prematurely. - @SuppressWarnings({"unused", "FieldCanBeLocal"}) - private final BinaryMessenger binaryMessenger; - - private final InstanceManager instanceManager; - private final CookieManagerProxy proxy; - private final @NonNull AndroidSdkChecker sdkChecker; - - // Interface for an injectable SDK version checker. - @VisibleForTesting - interface AndroidSdkChecker { - @ChecksSdkIntAtLeast(parameter = 0) - boolean sdkIsAtLeast(int version); - } - - /** Proxy for constructors and static method of `CookieManager`. */ - @VisibleForTesting - static class CookieManagerProxy { - /** Handles the Dart static method `MyClass.myStaticMethod`. */ - @NonNull - public CookieManager getInstance() { - return CookieManager.getInstance(); - } - } - - /** - * Constructs a {@link CookieManagerHostApiImpl}. - * - * @param binaryMessenger used to communicate with Dart over asynchronous messages - * @param instanceManager maintains instances stored to communicate with attached Dart objects - */ - public CookieManagerHostApiImpl( - @NonNull BinaryMessenger binaryMessenger, @NonNull InstanceManager instanceManager) { - this(binaryMessenger, instanceManager, new CookieManagerProxy()); - } - - @VisibleForTesting - CookieManagerHostApiImpl( - @NonNull BinaryMessenger binaryMessenger, - @NonNull InstanceManager instanceManager, - @NonNull CookieManagerProxy proxy) { - this( - binaryMessenger, instanceManager, proxy, (int version) -> Build.VERSION.SDK_INT >= version); - } - - @VisibleForTesting - CookieManagerHostApiImpl( - @NonNull BinaryMessenger binaryMessenger, - @NonNull InstanceManager instanceManager, - @NonNull CookieManagerProxy proxy, - @NonNull AndroidSdkChecker sdkChecker) { - this.binaryMessenger = binaryMessenger; - this.instanceManager = instanceManager; - this.proxy = proxy; - this.sdkChecker = sdkChecker; - } - - @Override - public void attachInstance(@NonNull Long instanceIdentifier) { - instanceManager.addDartCreatedInstance(proxy.getInstance(), instanceIdentifier); - } - - @Override - public void setCookie(@NonNull Long identifier, @NonNull String url, @NonNull String value) { - getCookieManagerInstance(identifier).setCookie(url, value); - } - - @Override - public void removeAllCookies( - @NonNull Long identifier, @NonNull GeneratedAndroidWebView.Result result) { - if (sdkChecker.sdkIsAtLeast(Build.VERSION_CODES.LOLLIPOP)) { - getCookieManagerInstance(identifier).removeAllCookies(result::success); - } else { - result.success(removeCookiesPreL(getCookieManagerInstance(identifier))); - } - } - - @Override - public void setAcceptThirdPartyCookies( - @NonNull Long identifier, @NonNull Long webViewIdentifier, @NonNull Boolean accept) { - if (sdkChecker.sdkIsAtLeast(Build.VERSION_CODES.LOLLIPOP)) { - getCookieManagerInstance(identifier) - .setAcceptThirdPartyCookies( - Objects.requireNonNull(instanceManager.getInstance(webViewIdentifier)), accept); - } else { - throw new UnsupportedOperationException( - "`setAcceptThirdPartyCookies` is unsupported on versions below `Build.VERSION_CODES.LOLLIPOP`."); - } - } - - /** - * Removes all cookies from the given cookie manager, using the deprecated (pre-Lollipop) - * implementation. - * - * @param cookieManager The cookie manager to clear all cookies from. - * @return Whether any cookies were removed. - */ - @SuppressWarnings("deprecation") - private boolean removeCookiesPreL(CookieManager cookieManager) { - final boolean hasCookies = cookieManager.hasCookies(); - if (hasCookies) { - cookieManager.removeAllCookie(); - } - return hasCookies; - } - - @NonNull - private CookieManager getCookieManagerInstance(@NonNull Long identifier) { - return Objects.requireNonNull(instanceManager.getInstance(identifier)); - } -} diff --git a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/CookieManagerProxyApi.java b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/CookieManagerProxyApi.java new file mode 100644 index 000000000000..35bc3dee1f6d --- /dev/null +++ b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/CookieManagerProxyApi.java @@ -0,0 +1,55 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +package io.flutter.plugins.webviewflutter; + +import android.webkit.CookieManager; +import android.webkit.WebView; +import androidx.annotation.NonNull; +import kotlin.Result; +import kotlin.Unit; +import kotlin.jvm.functions.Function1; + +/** + * Host API implementation for `CookieManager`. + * + *

This class may handle instantiating and adding native object instances that are attached to a + * Dart instance or handle method calls on the associated native class or an instance of the class. + */ +public class CookieManagerProxyApi extends PigeonApiCookieManager { + public CookieManagerProxyApi(@NonNull ProxyApiRegistrar pigeonRegistrar) { + super(pigeonRegistrar); + } + + @NonNull + @Override + public ProxyApiRegistrar getPigeonRegistrar() { + return (ProxyApiRegistrar) super.getPigeonRegistrar(); + } + + @NonNull + @Override + public CookieManager instance() { + return CookieManager.getInstance(); + } + + @Override + public void setCookie( + @NonNull CookieManager pigeon_instance, @NonNull String url, @NonNull String value) { + pigeon_instance.setCookie(url, value); + } + + @Override + public void removeAllCookies( + @NonNull CookieManager pigeon_instance, + @NonNull Function1, Unit> callback) { + pigeon_instance.removeAllCookies(aBoolean -> ResultCompat.success(aBoolean, callback)); + } + + @Override + public void setAcceptThirdPartyCookies( + @NonNull CookieManager pigeon_instance, @NonNull WebView webView, boolean accept) { + pigeon_instance.setAcceptThirdPartyCookies(webView, accept); + } +} diff --git a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/CustomViewCallbackFlutterApiImpl.java b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/CustomViewCallbackFlutterApiImpl.java deleted file mode 100644 index ffe70f694164..000000000000 --- a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/CustomViewCallbackFlutterApiImpl.java +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -package io.flutter.plugins.webviewflutter; - -import android.webkit.WebChromeClient.CustomViewCallback; -import androidx.annotation.NonNull; -import androidx.annotation.VisibleForTesting; -import io.flutter.plugin.common.BinaryMessenger; -import io.flutter.plugins.webviewflutter.GeneratedAndroidWebView.CustomViewCallbackFlutterApi; - -/** - * Flutter API implementation for `CustomViewCallback`. - * - *

This class may handle adding native instances that are attached to a Dart instance or passing - * arguments of callbacks methods to a Dart instance. - */ -public class CustomViewCallbackFlutterApiImpl { - // To ease adding additional methods, this value is added prematurely. - @SuppressWarnings({"unused", "FieldCanBeLocal"}) - private final BinaryMessenger binaryMessenger; - - private final InstanceManager instanceManager; - private CustomViewCallbackFlutterApi api; - - /** - * Constructs a {@link CustomViewCallbackFlutterApiImpl}. - * - * @param binaryMessenger used to communicate with Dart over asynchronous messages - * @param instanceManager maintains instances stored to communicate with attached Dart objects - */ - public CustomViewCallbackFlutterApiImpl( - @NonNull BinaryMessenger binaryMessenger, @NonNull InstanceManager instanceManager) { - this.binaryMessenger = binaryMessenger; - this.instanceManager = instanceManager; - api = new CustomViewCallbackFlutterApi(binaryMessenger); - } - - /** - * Stores the `CustomViewCallback` instance and notifies Dart to create and store a new - * `CustomViewCallback` instance that is attached to this one. If `instance` has already been - * added, this method does nothing. - */ - public void create( - @NonNull CustomViewCallback instance, - @NonNull CustomViewCallbackFlutterApi.Reply callback) { - if (!instanceManager.containsInstance(instance)) { - api.create(instanceManager.addHostCreatedInstance(instance), callback); - } - } - - /** - * Sets the Flutter API used to send messages to Dart. - * - *

This is only visible for testing. - */ - @VisibleForTesting - void setApi(@NonNull CustomViewCallbackFlutterApi api) { - this.api = api; - } -} diff --git a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/CustomViewCallbackHostApiImpl.java b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/CustomViewCallbackHostApiImpl.java deleted file mode 100644 index 44b8c454cc65..000000000000 --- a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/CustomViewCallbackHostApiImpl.java +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -package io.flutter.plugins.webviewflutter; - -import android.webkit.WebChromeClient.CustomViewCallback; -import androidx.annotation.NonNull; -import io.flutter.plugin.common.BinaryMessenger; -import io.flutter.plugins.webviewflutter.GeneratedAndroidWebView.CustomViewCallbackHostApi; -import java.util.Objects; - -/** - * Host API implementation for `CustomViewCallback`. - * - *

This class may handle instantiating and adding native object instances that are attached to a - * Dart instance or handle method calls on the associated native class or an instance of the class. - */ -public class CustomViewCallbackHostApiImpl implements CustomViewCallbackHostApi { - // To ease adding additional methods, this value is added prematurely. - @SuppressWarnings({"unused", "FieldCanBeLocal"}) - private final BinaryMessenger binaryMessenger; - - private final InstanceManager instanceManager; - - /** - * Constructs a {@link CustomViewCallbackHostApiImpl}. - * - * @param binaryMessenger used to communicate with Dart over asynchronous messages - * @param instanceManager maintains instances stored to communicate with attached Dart objects - */ - public CustomViewCallbackHostApiImpl( - @NonNull BinaryMessenger binaryMessenger, @NonNull InstanceManager instanceManager) { - this.binaryMessenger = binaryMessenger; - this.instanceManager = instanceManager; - } - - @Override - public void onCustomViewHidden(@NonNull Long identifier) { - getCustomViewCallbackInstance(identifier).onCustomViewHidden(); - } - - private CustomViewCallback getCustomViewCallbackInstance(@NonNull Long identifier) { - return Objects.requireNonNull(instanceManager.getInstance(identifier)); - } -} diff --git a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/CustomViewCallbackProxyApi.java b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/CustomViewCallbackProxyApi.java new file mode 100644 index 000000000000..df438f0485dc --- /dev/null +++ b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/CustomViewCallbackProxyApi.java @@ -0,0 +1,26 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +package io.flutter.plugins.webviewflutter; + +import android.webkit.WebChromeClient.CustomViewCallback; +import androidx.annotation.NonNull; + +/** + * Host API implementation for `CustomViewCallback`. + * + *

This class may handle instantiating and adding native object instances that are attached to a + * Dart instance or handle method calls on the associated native class or an instance of the class. + */ +public class CustomViewCallbackProxyApi extends PigeonApiCustomViewCallback { + /** Constructs a {@link CustomViewCallbackProxyApi}. */ + public CustomViewCallbackProxyApi(@NonNull ProxyApiRegistrar pigeonRegistrar) { + super(pigeonRegistrar); + } + + @Override + public void onCustomViewHidden(@NonNull CustomViewCallback pigeon_instance) { + pigeon_instance.onCustomViewHidden(); + } +} diff --git a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/DownloadListenerFlutterApiImpl.java b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/DownloadListenerFlutterApiImpl.java deleted file mode 100644 index f1ddb3a4817e..000000000000 --- a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/DownloadListenerFlutterApiImpl.java +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -package io.flutter.plugins.webviewflutter; - -import android.webkit.DownloadListener; -import androidx.annotation.NonNull; -import io.flutter.plugin.common.BinaryMessenger; -import io.flutter.plugins.webviewflutter.GeneratedAndroidWebView.DownloadListenerFlutterApi; - -/** - * Flutter Api implementation for {@link DownloadListener}. - * - *

Passes arguments of callbacks methods from a {@link DownloadListener} to Dart. - */ -public class DownloadListenerFlutterApiImpl extends DownloadListenerFlutterApi { - private final InstanceManager instanceManager; - - /** - * Creates a Flutter api that sends messages to Dart. - * - * @param binaryMessenger handles sending messages to Dart - * @param instanceManager maintains instances stored to communicate with Dart objects - */ - public DownloadListenerFlutterApiImpl( - @NonNull BinaryMessenger binaryMessenger, @NonNull InstanceManager instanceManager) { - super(binaryMessenger); - this.instanceManager = instanceManager; - } - - /** Passes arguments from {@link DownloadListener#onDownloadStart} to Dart. */ - public void onDownloadStart( - @NonNull DownloadListener downloadListener, - @NonNull String url, - @NonNull String userAgent, - @NonNull String contentDisposition, - @NonNull String mimetype, - long contentLength, - @NonNull Reply callback) { - onDownloadStart( - getIdentifierForListener(downloadListener), - url, - userAgent, - contentDisposition, - mimetype, - contentLength, - callback); - } - - private long getIdentifierForListener(DownloadListener listener) { - final Long identifier = instanceManager.getIdentifierForStrongReference(listener); - if (identifier == null) { - throw new IllegalStateException("Could not find identifier for DownloadListener."); - } - return identifier; - } -} diff --git a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/DownloadListenerHostApiImpl.java b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/DownloadListenerHostApiImpl.java deleted file mode 100644 index 09fffe0b8c13..000000000000 --- a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/DownloadListenerHostApiImpl.java +++ /dev/null @@ -1,85 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -package io.flutter.plugins.webviewflutter; - -import android.webkit.DownloadListener; -import androidx.annotation.NonNull; -import io.flutter.plugins.webviewflutter.GeneratedAndroidWebView.DownloadListenerHostApi; - -/** - * Host api implementation for {@link DownloadListener}. - * - *

Handles creating {@link DownloadListener}s that intercommunicate with a paired Dart object. - */ -public class DownloadListenerHostApiImpl implements DownloadListenerHostApi { - private final InstanceManager instanceManager; - private final DownloadListenerCreator downloadListenerCreator; - private final DownloadListenerFlutterApiImpl flutterApi; - - /** - * Implementation of {@link DownloadListener} that passes arguments of callback methods to Dart. - */ - public static class DownloadListenerImpl implements DownloadListener { - private final DownloadListenerFlutterApiImpl flutterApi; - - /** - * Creates a {@link DownloadListenerImpl} that passes arguments of callbacks methods to Dart. - * - * @param flutterApi handles sending messages to Dart - */ - public DownloadListenerImpl(@NonNull DownloadListenerFlutterApiImpl flutterApi) { - this.flutterApi = flutterApi; - } - - @Override - public void onDownloadStart( - @NonNull String url, - @NonNull String userAgent, - @NonNull String contentDisposition, - @NonNull String mimetype, - long contentLength) { - flutterApi.onDownloadStart( - this, url, userAgent, contentDisposition, mimetype, contentLength, reply -> {}); - } - } - - /** Handles creating {@link DownloadListenerImpl}s for a {@link DownloadListenerHostApiImpl}. */ - public static class DownloadListenerCreator { - /** - * Creates a {@link DownloadListenerImpl}. - * - * @param flutterApi handles sending messages to Dart - * @return the created {@link DownloadListenerImpl} - */ - @NonNull - public DownloadListenerImpl createDownloadListener( - @NonNull DownloadListenerFlutterApiImpl flutterApi) { - return new DownloadListenerImpl(flutterApi); - } - } - - /** - * Creates a host API that handles creating {@link DownloadListener}s. - * - * @param instanceManager maintains instances stored to communicate with Dart objects - * @param downloadListenerCreator handles creating {@link DownloadListenerImpl}s - * @param flutterApi handles sending messages to Dart - */ - public DownloadListenerHostApiImpl( - @NonNull InstanceManager instanceManager, - @NonNull DownloadListenerCreator downloadListenerCreator, - @NonNull DownloadListenerFlutterApiImpl flutterApi) { - this.instanceManager = instanceManager; - this.downloadListenerCreator = downloadListenerCreator; - this.flutterApi = flutterApi; - } - - @Override - public void create(@NonNull Long instanceId) { - final DownloadListener downloadListener = - downloadListenerCreator.createDownloadListener(flutterApi); - instanceManager.addDartCreatedInstance(downloadListener, instanceId); - } -} diff --git a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/DownloadListenerProxyApi.java b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/DownloadListenerProxyApi.java new file mode 100644 index 000000000000..87e616410c29 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/DownloadListenerProxyApi.java @@ -0,0 +1,66 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +package io.flutter.plugins.webviewflutter; + +import android.webkit.DownloadListener; +import androidx.annotation.NonNull; + +/** + * Host api implementation for {@link DownloadListener}. + * + *

Handles creating {@link DownloadListener}s that intercommunicate with a paired Dart object. + */ +public class DownloadListenerProxyApi extends PigeonApiDownloadListener { + /** + * Implementation of {@link DownloadListener} that passes arguments of callback methods to Dart. + */ + public static class DownloadListenerImpl implements DownloadListener { + private final DownloadListenerProxyApi api; + + /** + * Creates a {@link DownloadListenerImpl} that passes arguments of callbacks methods to Dart. + */ + public DownloadListenerImpl(@NonNull DownloadListenerProxyApi api) { + this.api = api; + } + + @Override + public void onDownloadStart( + @NonNull String url, + @NonNull String userAgent, + @NonNull String contentDisposition, + @NonNull String mimetype, + long contentLength) { + api.getPigeonRegistrar() + .runOnMainThread( + () -> + api.onDownloadStart( + this, + url, + userAgent, + contentDisposition, + mimetype, + contentLength, + reply -> null)); + } + } + + /** Creates a host API that handles creating {@link DownloadListener}s. */ + public DownloadListenerProxyApi(@NonNull ProxyApiRegistrar pigeonRegistrar) { + super(pigeonRegistrar); + } + + @NonNull + @Override + public DownloadListener pigeon_defaultConstructor() { + return new DownloadListenerImpl(this); + } + + @NonNull + @Override + public ProxyApiRegistrar getPigeonRegistrar() { + return (ProxyApiRegistrar) super.getPigeonRegistrar(); + } +} diff --git a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/FileChooserParamsFlutterApiImpl.java b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/FileChooserParamsFlutterApiImpl.java deleted file mode 100644 index d0f5b9c4d64a..000000000000 --- a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/FileChooserParamsFlutterApiImpl.java +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -package io.flutter.plugins.webviewflutter; - -import android.webkit.WebChromeClient; -import androidx.annotation.NonNull; -import io.flutter.plugin.common.BinaryMessenger; -import java.util.Arrays; - -/** - * Flutter Api implementation for {@link android.webkit.WebChromeClient.FileChooserParams}. - * - *

Passes arguments of callbacks methods from a {@link - * android.webkit.WebChromeClient.FileChooserParams} to Dart. - */ -public class FileChooserParamsFlutterApiImpl - extends GeneratedAndroidWebView.FileChooserParamsFlutterApi { - private final InstanceManager instanceManager; - - /** - * Creates a Flutter api that sends messages to Dart. - * - * @param binaryMessenger handles sending messages to Dart - * @param instanceManager maintains instances stored to communicate with Dart objects - */ - public FileChooserParamsFlutterApiImpl( - @NonNull BinaryMessenger binaryMessenger, @NonNull InstanceManager instanceManager) { - super(binaryMessenger); - this.instanceManager = instanceManager; - } - - private static GeneratedAndroidWebView.FileChooserMode toFileChooserEnumData(int mode) { - - switch (mode) { - case WebChromeClient.FileChooserParams.MODE_OPEN: - return GeneratedAndroidWebView.FileChooserMode.OPEN; - - case WebChromeClient.FileChooserParams.MODE_OPEN_MULTIPLE: - return GeneratedAndroidWebView.FileChooserMode.OPEN_MULTIPLE; - - case WebChromeClient.FileChooserParams.MODE_SAVE: - return GeneratedAndroidWebView.FileChooserMode.SAVE; - - default: - throw new IllegalArgumentException(String.format("Unsupported FileChooserMode: %d", mode)); - } - } - - /** - * Stores the FileChooserParams instance and notifies Dart to create a new FileChooserParams - * instance that is attached to this one. - */ - public void create( - @NonNull WebChromeClient.FileChooserParams instance, @NonNull Reply callback) { - if (!instanceManager.containsInstance(instance)) { - create( - instanceManager.addHostCreatedInstance(instance), - instance.isCaptureEnabled(), - Arrays.asList(instance.getAcceptTypes()), - toFileChooserEnumData(instance.getMode()), - instance.getFilenameHint(), - callback); - } - } -} diff --git a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/FileChooserParamsProxyApi.java b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/FileChooserParamsProxyApi.java new file mode 100644 index 000000000000..44cb3fe9a7ca --- /dev/null +++ b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/FileChooserParamsProxyApi.java @@ -0,0 +1,56 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +package io.flutter.plugins.webviewflutter; + +import android.webkit.WebChromeClient; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import java.util.Arrays; +import java.util.List; + +/** + * Flutter Api implementation for {@link android.webkit.WebChromeClient.FileChooserParams}. + * + *

Passes arguments of callbacks methods from a {@link + * android.webkit.WebChromeClient.FileChooserParams} to Dart. + */ +public class FileChooserParamsProxyApi extends PigeonApiFileChooserParams { + /** Creates a Flutter api that sends messages to Dart. */ + public FileChooserParamsProxyApi(@NonNull ProxyApiRegistrar pigeonRegistrar) { + super(pigeonRegistrar); + } + + @Override + public boolean isCaptureEnabled(@NonNull WebChromeClient.FileChooserParams pigeon_instance) { + return pigeon_instance.isCaptureEnabled(); + } + + @NonNull + @Override + public List acceptTypes(@NonNull WebChromeClient.FileChooserParams pigeon_instance) { + return Arrays.asList(pigeon_instance.getAcceptTypes()); + } + + @NonNull + @Override + public FileChooserMode mode(@NonNull WebChromeClient.FileChooserParams pigeon_instance) { + switch (pigeon_instance.getMode()) { + case WebChromeClient.FileChooserParams.MODE_OPEN: + return FileChooserMode.OPEN; + case WebChromeClient.FileChooserParams.MODE_OPEN_MULTIPLE: + return FileChooserMode.OPEN_MULTIPLE; + case WebChromeClient.FileChooserParams.MODE_SAVE: + return FileChooserMode.SAVE; + default: + return FileChooserMode.UNKNOWN; + } + } + + @Nullable + @Override + public String filenameHint(@NonNull WebChromeClient.FileChooserParams pigeon_instance) { + return pigeon_instance.getFilenameHint(); + } +} diff --git a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/FlutterAssetManager.java b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/FlutterAssetManager.java index d59943414b79..b0c20b4c2d89 100644 --- a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/FlutterAssetManager.java +++ b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/FlutterAssetManager.java @@ -6,13 +6,13 @@ import android.content.res.AssetManager; import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import io.flutter.embedding.engine.plugins.FlutterPlugin; import java.io.IOException; /** Provides access to the assets registered as part of the App bundle. */ -@SuppressWarnings({"deprecation", "DeprecatedIsStillUsed"}) -abstract class FlutterAssetManager { - final AssetManager assetManager; +public abstract class FlutterAssetManager { + @NonNull final AssetManager assetManager; /** * Constructs a new instance of the {@link FlutterAssetManager}. @@ -20,7 +20,7 @@ abstract class FlutterAssetManager { * @param assetManager Instance of Android's {@link AssetManager} used to access assets within the * App bundle. */ - public FlutterAssetManager(AssetManager assetManager) { + public FlutterAssetManager(@NonNull AssetManager assetManager) { this.assetManager = assetManager; } @@ -32,7 +32,8 @@ public FlutterAssetManager(AssetManager assetManager) { * Therefore, the returned path is appropriate to pass to Android's AssetManager, but the path is * not appropriate to load as an absolute path. */ - abstract String getAssetFilePathByName(String name); + @Nullable + abstract String getAssetFilePathByName(@NonNull String name); /** * Returns a String array of all the assets at the given path. @@ -43,6 +44,7 @@ public FlutterAssetManager(AssetManager assetManager) { * This value may be null. * @throws IOException Throws an IOException in case I/O operations were interrupted. */ + @NonNull public String[] list(@NonNull String path) throws IOException { return assetManager.list(path); } @@ -64,13 +66,13 @@ static class PluginBindingFlutterAssetManager extends FlutterAssetManager { * paths to assets registered by Flutter. */ PluginBindingFlutterAssetManager( - AssetManager assetManager, FlutterPlugin.FlutterAssets flutterAssets) { + @NonNull AssetManager assetManager, @NonNull FlutterPlugin.FlutterAssets flutterAssets) { super(assetManager); this.flutterAssets = flutterAssets; } @Override - public String getAssetFilePathByName(String name) { + public String getAssetFilePathByName(@NonNull String name) { return flutterAssets.getAssetFilePathByName(name); } } diff --git a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/FlutterAssetManagerHostApiImpl.java b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/FlutterAssetManagerHostApiImpl.java deleted file mode 100644 index ba6d1e5fd574..000000000000 --- a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/FlutterAssetManagerHostApiImpl.java +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -package io.flutter.plugins.webviewflutter; - -import android.webkit.WebView; -import androidx.annotation.NonNull; -import io.flutter.plugins.webviewflutter.GeneratedAndroidWebView.FlutterAssetManagerHostApi; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -/** - * Host api implementation for {@link WebView}. - * - *

Handles creating {@link WebView}s that intercommunicate with a paired Dart object. - */ -public class FlutterAssetManagerHostApiImpl implements FlutterAssetManagerHostApi { - final FlutterAssetManager flutterAssetManager; - - /** Constructs a new instance of {@link FlutterAssetManagerHostApiImpl}. */ - public FlutterAssetManagerHostApiImpl(@NonNull FlutterAssetManager flutterAssetManager) { - this.flutterAssetManager = flutterAssetManager; - } - - @NonNull - @Override - public List list(@NonNull String path) { - try { - String[] paths = flutterAssetManager.list(path); - - if (paths == null) { - return new ArrayList<>(); - } - - return Arrays.asList(paths); - } catch (IOException ex) { - throw new RuntimeException(ex.getMessage()); - } - } - - @NonNull - @Override - public String getAssetFilePathByName(@NonNull String name) { - return flutterAssetManager.getAssetFilePathByName(name); - } -} diff --git a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/FlutterAssetManagerProxyApi.java b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/FlutterAssetManagerProxyApi.java new file mode 100644 index 000000000000..5905d87d4bcf --- /dev/null +++ b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/FlutterAssetManagerProxyApi.java @@ -0,0 +1,59 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +package io.flutter.plugins.webviewflutter; + +import android.webkit.WebView; +import androidx.annotation.NonNull; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +/** + * Host api implementation for {@link WebView}. + * + *

Handles creating {@link WebView}s that intercommunicate with a paired Dart object. + */ +public class FlutterAssetManagerProxyApi extends PigeonApiFlutterAssetManager { + /** Constructs a new instance of {@link FlutterAssetManagerProxyApi}. */ + public FlutterAssetManagerProxyApi(@NonNull ProxyApiRegistrar pigeonRegistrar) { + super(pigeonRegistrar); + } + + @NonNull + @Override + public FlutterAssetManager instance() { + return getPigeonRegistrar().getFlutterAssetManager(); + } + + @NonNull + @Override + public List list(@NonNull FlutterAssetManager pigeon_instance, @NonNull String path) { + try { + String[] paths = pigeon_instance.list(path); + + if (paths == null) { + return new ArrayList<>(); + } + + return Arrays.asList(paths); + } catch (IOException ex) { + throw new RuntimeException(ex.getMessage()); + } + } + + @NonNull + @Override + public String getAssetFilePathByName( + @NonNull FlutterAssetManager pigeon_instance, @NonNull String name) { + return pigeon_instance.getAssetFilePathByName(name); + } + + @NonNull + @Override + public ProxyApiRegistrar getPigeonRegistrar() { + return (ProxyApiRegistrar) super.getPigeonRegistrar(); + } +} diff --git a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/FlutterViewFactory.java b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/FlutterViewFactory.java index f77bf8d95bdd..813013b8e6c5 100644 --- a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/FlutterViewFactory.java +++ b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/FlutterViewFactory.java @@ -13,9 +13,9 @@ import io.flutter.plugin.platform.PlatformViewFactory; class FlutterViewFactory extends PlatformViewFactory { - private final InstanceManager instanceManager; + private final AndroidWebkitLibraryPigeonInstanceManager instanceManager; - FlutterViewFactory(InstanceManager instanceManager) { + FlutterViewFactory(AndroidWebkitLibraryPigeonInstanceManager instanceManager) { super(StandardMessageCodec.INSTANCE); this.instanceManager = instanceManager; } diff --git a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/GeneratedAndroidWebView.java b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/GeneratedAndroidWebView.java deleted file mode 100644 index cfdadec40144..000000000000 --- a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/GeneratedAndroidWebView.java +++ /dev/null @@ -1,3826 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -// Autogenerated from Pigeon (v11.0.1), do not edit directly. -// See also: https://pub.dev/packages/pigeon - -package io.flutter.plugins.webviewflutter; - -import android.util.Log; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import io.flutter.plugin.common.BasicMessageChannel; -import io.flutter.plugin.common.BinaryMessenger; -import io.flutter.plugin.common.MessageCodec; -import io.flutter.plugin.common.StandardMessageCodec; -import java.io.ByteArrayOutputStream; -import java.nio.ByteBuffer; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.Map; - -/** Generated class from Pigeon. */ -@SuppressWarnings({"unused", "unchecked", "CodeBlock2Expr", "RedundantSuppression", "serial"}) -public class GeneratedAndroidWebView { - - /** Error class for passing custom error details to Flutter via a thrown PlatformException. */ - public static class FlutterError extends RuntimeException { - - /** The error code. */ - public final String code; - - /** The error details. Must be a datatype supported by the api codec. */ - public final Object details; - - public FlutterError(@NonNull String code, @Nullable String message, @Nullable Object details) { - super(message); - this.code = code; - this.details = details; - } - } - - @NonNull - protected static ArrayList wrapError(@NonNull Throwable exception) { - ArrayList errorList = new ArrayList(3); - if (exception instanceof FlutterError) { - FlutterError error = (FlutterError) exception; - errorList.add(error.code); - errorList.add(error.getMessage()); - errorList.add(error.details); - } else { - errorList.add(exception.toString()); - errorList.add(exception.getClass().getSimpleName()); - errorList.add( - "Cause: " + exception.getCause() + ", Stacktrace: " + Log.getStackTraceString(exception)); - } - return errorList; - } - - /** - * Mode of how to select files for a file chooser. - * - *

See - * https://developer.android.com/reference/android/webkit/WebChromeClient.FileChooserParams. - */ - public enum FileChooserMode { - /** - * Open single file and requires that the file exists before allowing the user to pick it. - * - *

See - * https://developer.android.com/reference/android/webkit/WebChromeClient.FileChooserParams#MODE_OPEN. - */ - OPEN(0), - /** - * Similar to [open] but allows multiple files to be selected. - * - *

See - * https://developer.android.com/reference/android/webkit/WebChromeClient.FileChooserParams#MODE_OPEN_MULTIPLE. - */ - OPEN_MULTIPLE(1), - /** - * Allows picking a nonexistent file and saving it. - * - *

See - * https://developer.android.com/reference/android/webkit/WebChromeClient.FileChooserParams#MODE_SAVE. - */ - SAVE(2); - - final int index; - - private FileChooserMode(final int index) { - this.index = index; - } - } - - /** - * Indicates the type of message logged to the console. - * - *

See https://developer.android.com/reference/android/webkit/ConsoleMessage.MessageLevel. - */ - public enum ConsoleMessageLevel { - /** - * Indicates a message is logged for debugging. - * - *

See - * https://developer.android.com/reference/android/webkit/ConsoleMessage.MessageLevel#DEBUG. - */ - DEBUG(0), - /** - * Indicates a message is provided as an error. - * - *

See - * https://developer.android.com/reference/android/webkit/ConsoleMessage.MessageLevel#ERROR. - */ - ERROR(1), - /** - * Indicates a message is provided as a basic log message. - * - *

See - * https://developer.android.com/reference/android/webkit/ConsoleMessage.MessageLevel#LOG. - */ - LOG(2), - /** - * Indicates a message is provided as a tip. - * - *

See - * https://developer.android.com/reference/android/webkit/ConsoleMessage.MessageLevel#TIP. - */ - TIP(3), - /** - * Indicates a message is provided as a warning. - * - *

See - * https://developer.android.com/reference/android/webkit/ConsoleMessage.MessageLevel#WARNING. - */ - WARNING(4), - /** - * Indicates a message with an unknown level. - * - *

This does not represent an actual value provided by the platform and only indicates a - * value was provided that isn't currently supported. - */ - UNKNOWN(5); - - final int index; - - private ConsoleMessageLevel(final int index) { - this.index = index; - } - } - - /** Generated class from Pigeon that represents data sent in messages. */ - public static final class WebResourceRequestData { - private @NonNull String url; - - public @NonNull String getUrl() { - return url; - } - - public void setUrl(@NonNull String setterArg) { - if (setterArg == null) { - throw new IllegalStateException("Nonnull field \"url\" is null."); - } - this.url = setterArg; - } - - private @NonNull Boolean isForMainFrame; - - public @NonNull Boolean getIsForMainFrame() { - return isForMainFrame; - } - - public void setIsForMainFrame(@NonNull Boolean setterArg) { - if (setterArg == null) { - throw new IllegalStateException("Nonnull field \"isForMainFrame\" is null."); - } - this.isForMainFrame = setterArg; - } - - private @Nullable Boolean isRedirect; - - public @Nullable Boolean getIsRedirect() { - return isRedirect; - } - - public void setIsRedirect(@Nullable Boolean setterArg) { - this.isRedirect = setterArg; - } - - private @NonNull Boolean hasGesture; - - public @NonNull Boolean getHasGesture() { - return hasGesture; - } - - public void setHasGesture(@NonNull Boolean setterArg) { - if (setterArg == null) { - throw new IllegalStateException("Nonnull field \"hasGesture\" is null."); - } - this.hasGesture = setterArg; - } - - private @NonNull String method; - - public @NonNull String getMethod() { - return method; - } - - public void setMethod(@NonNull String setterArg) { - if (setterArg == null) { - throw new IllegalStateException("Nonnull field \"method\" is null."); - } - this.method = setterArg; - } - - private @NonNull Map requestHeaders; - - public @NonNull Map getRequestHeaders() { - return requestHeaders; - } - - public void setRequestHeaders(@NonNull Map setterArg) { - if (setterArg == null) { - throw new IllegalStateException("Nonnull field \"requestHeaders\" is null."); - } - this.requestHeaders = setterArg; - } - - /** Constructor is non-public to enforce null safety; use Builder. */ - WebResourceRequestData() {} - - public static final class Builder { - - private @Nullable String url; - - public @NonNull Builder setUrl(@NonNull String setterArg) { - this.url = setterArg; - return this; - } - - private @Nullable Boolean isForMainFrame; - - public @NonNull Builder setIsForMainFrame(@NonNull Boolean setterArg) { - this.isForMainFrame = setterArg; - return this; - } - - private @Nullable Boolean isRedirect; - - public @NonNull Builder setIsRedirect(@Nullable Boolean setterArg) { - this.isRedirect = setterArg; - return this; - } - - private @Nullable Boolean hasGesture; - - public @NonNull Builder setHasGesture(@NonNull Boolean setterArg) { - this.hasGesture = setterArg; - return this; - } - - private @Nullable String method; - - public @NonNull Builder setMethod(@NonNull String setterArg) { - this.method = setterArg; - return this; - } - - private @Nullable Map requestHeaders; - - public @NonNull Builder setRequestHeaders(@NonNull Map setterArg) { - this.requestHeaders = setterArg; - return this; - } - - public @NonNull WebResourceRequestData build() { - WebResourceRequestData pigeonReturn = new WebResourceRequestData(); - pigeonReturn.setUrl(url); - pigeonReturn.setIsForMainFrame(isForMainFrame); - pigeonReturn.setIsRedirect(isRedirect); - pigeonReturn.setHasGesture(hasGesture); - pigeonReturn.setMethod(method); - pigeonReturn.setRequestHeaders(requestHeaders); - return pigeonReturn; - } - } - - @NonNull - ArrayList toList() { - ArrayList toListResult = new ArrayList(6); - toListResult.add(url); - toListResult.add(isForMainFrame); - toListResult.add(isRedirect); - toListResult.add(hasGesture); - toListResult.add(method); - toListResult.add(requestHeaders); - return toListResult; - } - - static @NonNull WebResourceRequestData fromList(@NonNull ArrayList list) { - WebResourceRequestData pigeonResult = new WebResourceRequestData(); - Object url = list.get(0); - pigeonResult.setUrl((String) url); - Object isForMainFrame = list.get(1); - pigeonResult.setIsForMainFrame((Boolean) isForMainFrame); - Object isRedirect = list.get(2); - pigeonResult.setIsRedirect((Boolean) isRedirect); - Object hasGesture = list.get(3); - pigeonResult.setHasGesture((Boolean) hasGesture); - Object method = list.get(4); - pigeonResult.setMethod((String) method); - Object requestHeaders = list.get(5); - pigeonResult.setRequestHeaders((Map) requestHeaders); - return pigeonResult; - } - } - - /** Generated class from Pigeon that represents data sent in messages. */ - public static final class WebResourceResponseData { - private @NonNull Long statusCode; - - public @NonNull Long getStatusCode() { - return statusCode; - } - - public void setStatusCode(@NonNull Long setterArg) { - if (setterArg == null) { - throw new IllegalStateException("Nonnull field \"statusCode\" is null."); - } - this.statusCode = setterArg; - } - - /** Constructor is non-public to enforce null safety; use Builder. */ - WebResourceResponseData() {} - - public static final class Builder { - - private @Nullable Long statusCode; - - public @NonNull Builder setStatusCode(@NonNull Long setterArg) { - this.statusCode = setterArg; - return this; - } - - public @NonNull WebResourceResponseData build() { - WebResourceResponseData pigeonReturn = new WebResourceResponseData(); - pigeonReturn.setStatusCode(statusCode); - return pigeonReturn; - } - } - - @NonNull - ArrayList toList() { - ArrayList toListResult = new ArrayList(1); - toListResult.add(statusCode); - return toListResult; - } - - static @NonNull WebResourceResponseData fromList(@NonNull ArrayList list) { - WebResourceResponseData pigeonResult = new WebResourceResponseData(); - Object statusCode = list.get(0); - pigeonResult.setStatusCode( - (statusCode == null) - ? null - : ((statusCode instanceof Integer) ? (Integer) statusCode : (Long) statusCode)); - return pigeonResult; - } - } - - /** Generated class from Pigeon that represents data sent in messages. */ - public static final class WebResourceErrorData { - private @NonNull Long errorCode; - - public @NonNull Long getErrorCode() { - return errorCode; - } - - public void setErrorCode(@NonNull Long setterArg) { - if (setterArg == null) { - throw new IllegalStateException("Nonnull field \"errorCode\" is null."); - } - this.errorCode = setterArg; - } - - private @NonNull String description; - - public @NonNull String getDescription() { - return description; - } - - public void setDescription(@NonNull String setterArg) { - if (setterArg == null) { - throw new IllegalStateException("Nonnull field \"description\" is null."); - } - this.description = setterArg; - } - - /** Constructor is non-public to enforce null safety; use Builder. */ - WebResourceErrorData() {} - - public static final class Builder { - - private @Nullable Long errorCode; - - public @NonNull Builder setErrorCode(@NonNull Long setterArg) { - this.errorCode = setterArg; - return this; - } - - private @Nullable String description; - - public @NonNull Builder setDescription(@NonNull String setterArg) { - this.description = setterArg; - return this; - } - - public @NonNull WebResourceErrorData build() { - WebResourceErrorData pigeonReturn = new WebResourceErrorData(); - pigeonReturn.setErrorCode(errorCode); - pigeonReturn.setDescription(description); - return pigeonReturn; - } - } - - @NonNull - ArrayList toList() { - ArrayList toListResult = new ArrayList(2); - toListResult.add(errorCode); - toListResult.add(description); - return toListResult; - } - - static @NonNull WebResourceErrorData fromList(@NonNull ArrayList list) { - WebResourceErrorData pigeonResult = new WebResourceErrorData(); - Object errorCode = list.get(0); - pigeonResult.setErrorCode( - (errorCode == null) - ? null - : ((errorCode instanceof Integer) ? (Integer) errorCode : (Long) errorCode)); - Object description = list.get(1); - pigeonResult.setDescription((String) description); - return pigeonResult; - } - } - - /** Generated class from Pigeon that represents data sent in messages. */ - public static final class WebViewPoint { - private @NonNull Long x; - - public @NonNull Long getX() { - return x; - } - - public void setX(@NonNull Long setterArg) { - if (setterArg == null) { - throw new IllegalStateException("Nonnull field \"x\" is null."); - } - this.x = setterArg; - } - - private @NonNull Long y; - - public @NonNull Long getY() { - return y; - } - - public void setY(@NonNull Long setterArg) { - if (setterArg == null) { - throw new IllegalStateException("Nonnull field \"y\" is null."); - } - this.y = setterArg; - } - - /** Constructor is non-public to enforce null safety; use Builder. */ - WebViewPoint() {} - - public static final class Builder { - - private @Nullable Long x; - - public @NonNull Builder setX(@NonNull Long setterArg) { - this.x = setterArg; - return this; - } - - private @Nullable Long y; - - public @NonNull Builder setY(@NonNull Long setterArg) { - this.y = setterArg; - return this; - } - - public @NonNull WebViewPoint build() { - WebViewPoint pigeonReturn = new WebViewPoint(); - pigeonReturn.setX(x); - pigeonReturn.setY(y); - return pigeonReturn; - } - } - - @NonNull - ArrayList toList() { - ArrayList toListResult = new ArrayList(2); - toListResult.add(x); - toListResult.add(y); - return toListResult; - } - - static @NonNull WebViewPoint fromList(@NonNull ArrayList list) { - WebViewPoint pigeonResult = new WebViewPoint(); - Object x = list.get(0); - pigeonResult.setX((x == null) ? null : ((x instanceof Integer) ? (Integer) x : (Long) x)); - Object y = list.get(1); - pigeonResult.setY((y == null) ? null : ((y instanceof Integer) ? (Integer) y : (Long) y)); - return pigeonResult; - } - } - - /** - * Represents a JavaScript console message from WebCore. - * - *

See https://developer.android.com/reference/android/webkit/ConsoleMessage - * - *

Generated class from Pigeon that represents data sent in messages. - */ - public static final class ConsoleMessage { - private @NonNull Long lineNumber; - - public @NonNull Long getLineNumber() { - return lineNumber; - } - - public void setLineNumber(@NonNull Long setterArg) { - if (setterArg == null) { - throw new IllegalStateException("Nonnull field \"lineNumber\" is null."); - } - this.lineNumber = setterArg; - } - - private @NonNull String message; - - public @NonNull String getMessage() { - return message; - } - - public void setMessage(@NonNull String setterArg) { - if (setterArg == null) { - throw new IllegalStateException("Nonnull field \"message\" is null."); - } - this.message = setterArg; - } - - private @NonNull ConsoleMessageLevel level; - - public @NonNull ConsoleMessageLevel getLevel() { - return level; - } - - public void setLevel(@NonNull ConsoleMessageLevel setterArg) { - if (setterArg == null) { - throw new IllegalStateException("Nonnull field \"level\" is null."); - } - this.level = setterArg; - } - - private @NonNull String sourceId; - - public @NonNull String getSourceId() { - return sourceId; - } - - public void setSourceId(@NonNull String setterArg) { - if (setterArg == null) { - throw new IllegalStateException("Nonnull field \"sourceId\" is null."); - } - this.sourceId = setterArg; - } - - /** Constructor is non-public to enforce null safety; use Builder. */ - ConsoleMessage() {} - - public static final class Builder { - - private @Nullable Long lineNumber; - - public @NonNull Builder setLineNumber(@NonNull Long setterArg) { - this.lineNumber = setterArg; - return this; - } - - private @Nullable String message; - - public @NonNull Builder setMessage(@NonNull String setterArg) { - this.message = setterArg; - return this; - } - - private @Nullable ConsoleMessageLevel level; - - public @NonNull Builder setLevel(@NonNull ConsoleMessageLevel setterArg) { - this.level = setterArg; - return this; - } - - private @Nullable String sourceId; - - public @NonNull Builder setSourceId(@NonNull String setterArg) { - this.sourceId = setterArg; - return this; - } - - public @NonNull ConsoleMessage build() { - ConsoleMessage pigeonReturn = new ConsoleMessage(); - pigeonReturn.setLineNumber(lineNumber); - pigeonReturn.setMessage(message); - pigeonReturn.setLevel(level); - pigeonReturn.setSourceId(sourceId); - return pigeonReturn; - } - } - - @NonNull - ArrayList toList() { - ArrayList toListResult = new ArrayList(4); - toListResult.add(lineNumber); - toListResult.add(message); - toListResult.add(level == null ? null : level.index); - toListResult.add(sourceId); - return toListResult; - } - - static @NonNull ConsoleMessage fromList(@NonNull ArrayList list) { - ConsoleMessage pigeonResult = new ConsoleMessage(); - Object lineNumber = list.get(0); - pigeonResult.setLineNumber( - (lineNumber == null) - ? null - : ((lineNumber instanceof Integer) ? (Integer) lineNumber : (Long) lineNumber)); - Object message = list.get(1); - pigeonResult.setMessage((String) message); - Object level = list.get(2); - pigeonResult.setLevel(ConsoleMessageLevel.values()[(int) level]); - Object sourceId = list.get(3); - pigeonResult.setSourceId((String) sourceId); - return pigeonResult; - } - } - - public interface Result { - @SuppressWarnings("UnknownNullness") - void success(T result); - - void error(@NonNull Throwable error); - } - /** - * Host API for managing the native `InstanceManager`. - * - *

Generated interface from Pigeon that represents a handler of messages from Flutter. - */ - public interface InstanceManagerHostApi { - /** - * Clear the native `InstanceManager`. - * - *

This is typically only used after a hot restart. - */ - void clear(); - - /** The codec used by InstanceManagerHostApi. */ - static @NonNull MessageCodec getCodec() { - return new StandardMessageCodec(); - } - /** - * Sets up an instance of `InstanceManagerHostApi` to handle messages through the - * `binaryMessenger`. - */ - static void setup( - @NonNull BinaryMessenger binaryMessenger, @Nullable InstanceManagerHostApi api) { - { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.webview_flutter_android.InstanceManagerHostApi.clear", - getCodec()); - if (api != null) { - channel.setMessageHandler( - (message, reply) -> { - ArrayList wrapped = new ArrayList(); - try { - api.clear(); - wrapped.add(0, null); - } catch (Throwable exception) { - ArrayList wrappedError = wrapError(exception); - wrapped = wrappedError; - } - reply.reply(wrapped); - }); - } else { - channel.setMessageHandler(null); - } - } - } - } - /** - * Handles methods calls to the native Java Object class. - * - *

Also handles calls to remove the reference to an instance with `dispose`. - * - *

See https://docs.oracle.com/javase/7/docs/api/java/lang/Object.html. - * - *

Generated interface from Pigeon that represents a handler of messages from Flutter. - */ - public interface JavaObjectHostApi { - - void dispose(@NonNull Long identifier); - - /** The codec used by JavaObjectHostApi. */ - static @NonNull MessageCodec getCodec() { - return new StandardMessageCodec(); - } - /** - * Sets up an instance of `JavaObjectHostApi` to handle messages through the `binaryMessenger`. - */ - static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable JavaObjectHostApi api) { - { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.webview_flutter_android.JavaObjectHostApi.dispose", - getCodec()); - if (api != null) { - channel.setMessageHandler( - (message, reply) -> { - ArrayList wrapped = new ArrayList(); - ArrayList args = (ArrayList) message; - Number identifierArg = (Number) args.get(0); - try { - api.dispose((identifierArg == null) ? null : identifierArg.longValue()); - wrapped.add(0, null); - } catch (Throwable exception) { - ArrayList wrappedError = wrapError(exception); - wrapped = wrappedError; - } - reply.reply(wrapped); - }); - } else { - channel.setMessageHandler(null); - } - } - } - } - /** - * Handles callbacks methods for the native Java Object class. - * - *

See https://docs.oracle.com/javase/7/docs/api/java/lang/Object.html. - * - *

Generated class from Pigeon that represents Flutter messages that can be called from Java. - */ - public static class JavaObjectFlutterApi { - private final @NonNull BinaryMessenger binaryMessenger; - - public JavaObjectFlutterApi(@NonNull BinaryMessenger argBinaryMessenger) { - this.binaryMessenger = argBinaryMessenger; - } - - /** Public interface for sending reply. */ - @SuppressWarnings("UnknownNullness") - public interface Reply { - void reply(T reply); - } - /** The codec used by JavaObjectFlutterApi. */ - static @NonNull MessageCodec getCodec() { - return new StandardMessageCodec(); - } - - public void dispose(@NonNull Long identifierArg, @NonNull Reply callback) { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.webview_flutter_android.JavaObjectFlutterApi.dispose", - getCodec()); - channel.send( - new ArrayList(Collections.singletonList(identifierArg)), - channelReply -> callback.reply(null)); - } - } - /** - * Host API for `CookieManager`. - * - *

This class may handle instantiating and adding native object instances that are attached to - * a Dart instance or handle method calls on the associated native class or an instance of the - * class. - * - *

Generated interface from Pigeon that represents a handler of messages from Flutter. - */ - public interface CookieManagerHostApi { - /** Handles attaching `CookieManager.instance` to a native instance. */ - void attachInstance(@NonNull Long instanceIdentifier); - /** Handles Dart method `CookieManager.setCookie`. */ - void setCookie(@NonNull Long identifier, @NonNull String url, @NonNull String value); - /** Handles Dart method `CookieManager.removeAllCookies`. */ - void removeAllCookies(@NonNull Long identifier, @NonNull Result result); - /** Handles Dart method `CookieManager.setAcceptThirdPartyCookies`. */ - void setAcceptThirdPartyCookies( - @NonNull Long identifier, @NonNull Long webViewIdentifier, @NonNull Boolean accept); - - /** The codec used by CookieManagerHostApi. */ - static @NonNull MessageCodec getCodec() { - return new StandardMessageCodec(); - } - /** - * Sets up an instance of `CookieManagerHostApi` to handle messages through the - * `binaryMessenger`. - */ - static void setup( - @NonNull BinaryMessenger binaryMessenger, @Nullable CookieManagerHostApi api) { - { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.webview_flutter_android.CookieManagerHostApi.attachInstance", - getCodec()); - if (api != null) { - channel.setMessageHandler( - (message, reply) -> { - ArrayList wrapped = new ArrayList(); - ArrayList args = (ArrayList) message; - Number instanceIdentifierArg = (Number) args.get(0); - try { - api.attachInstance( - (instanceIdentifierArg == null) ? null : instanceIdentifierArg.longValue()); - wrapped.add(0, null); - } catch (Throwable exception) { - ArrayList wrappedError = wrapError(exception); - wrapped = wrappedError; - } - reply.reply(wrapped); - }); - } else { - channel.setMessageHandler(null); - } - } - { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.webview_flutter_android.CookieManagerHostApi.setCookie", - getCodec()); - if (api != null) { - channel.setMessageHandler( - (message, reply) -> { - ArrayList wrapped = new ArrayList(); - ArrayList args = (ArrayList) message; - Number identifierArg = (Number) args.get(0); - String urlArg = (String) args.get(1); - String valueArg = (String) args.get(2); - try { - api.setCookie( - (identifierArg == null) ? null : identifierArg.longValue(), urlArg, valueArg); - wrapped.add(0, null); - } catch (Throwable exception) { - ArrayList wrappedError = wrapError(exception); - wrapped = wrappedError; - } - reply.reply(wrapped); - }); - } else { - channel.setMessageHandler(null); - } - } - { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.webview_flutter_android.CookieManagerHostApi.removeAllCookies", - getCodec()); - if (api != null) { - channel.setMessageHandler( - (message, reply) -> { - ArrayList wrapped = new ArrayList(); - ArrayList args = (ArrayList) message; - Number identifierArg = (Number) args.get(0); - Result resultCallback = - new Result() { - public void success(Boolean result) { - wrapped.add(0, result); - reply.reply(wrapped); - } - - public void error(Throwable error) { - ArrayList wrappedError = wrapError(error); - reply.reply(wrappedError); - } - }; - - api.removeAllCookies( - (identifierArg == null) ? null : identifierArg.longValue(), resultCallback); - }); - } else { - channel.setMessageHandler(null); - } - } - { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.webview_flutter_android.CookieManagerHostApi.setAcceptThirdPartyCookies", - getCodec()); - if (api != null) { - channel.setMessageHandler( - (message, reply) -> { - ArrayList wrapped = new ArrayList(); - ArrayList args = (ArrayList) message; - Number identifierArg = (Number) args.get(0); - Number webViewIdentifierArg = (Number) args.get(1); - Boolean acceptArg = (Boolean) args.get(2); - try { - api.setAcceptThirdPartyCookies( - (identifierArg == null) ? null : identifierArg.longValue(), - (webViewIdentifierArg == null) ? null : webViewIdentifierArg.longValue(), - acceptArg); - wrapped.add(0, null); - } catch (Throwable exception) { - ArrayList wrappedError = wrapError(exception); - wrapped = wrappedError; - } - reply.reply(wrapped); - }); - } else { - channel.setMessageHandler(null); - } - } - } - } - - private static class WebViewHostApiCodec extends StandardMessageCodec { - public static final WebViewHostApiCodec INSTANCE = new WebViewHostApiCodec(); - - private WebViewHostApiCodec() {} - - @Override - protected Object readValueOfType(byte type, @NonNull ByteBuffer buffer) { - switch (type) { - case (byte) 128: - return WebViewPoint.fromList((ArrayList) readValue(buffer)); - default: - return super.readValueOfType(type, buffer); - } - } - - @Override - protected void writeValue(@NonNull ByteArrayOutputStream stream, Object value) { - if (value instanceof WebViewPoint) { - stream.write(128); - writeValue(stream, ((WebViewPoint) value).toList()); - } else { - super.writeValue(stream, value); - } - } - } - - /** Generated interface from Pigeon that represents a handler of messages from Flutter. */ - public interface WebViewHostApi { - - void create(@NonNull Long instanceId); - - void loadData( - @NonNull Long instanceId, - @NonNull String data, - @Nullable String mimeType, - @Nullable String encoding); - - void loadDataWithBaseUrl( - @NonNull Long instanceId, - @Nullable String baseUrl, - @NonNull String data, - @Nullable String mimeType, - @Nullable String encoding, - @Nullable String historyUrl); - - void loadUrl( - @NonNull Long instanceId, @NonNull String url, @NonNull Map headers); - - void postUrl(@NonNull Long instanceId, @NonNull String url, @NonNull byte[] data); - - @Nullable - String getUrl(@NonNull Long instanceId); - - @NonNull - Boolean canGoBack(@NonNull Long instanceId); - - @NonNull - Boolean canGoForward(@NonNull Long instanceId); - - void goBack(@NonNull Long instanceId); - - void goForward(@NonNull Long instanceId); - - void reload(@NonNull Long instanceId); - - void clearCache(@NonNull Long instanceId, @NonNull Boolean includeDiskFiles); - - void evaluateJavascript( - @NonNull Long instanceId, @NonNull String javascriptString, @NonNull Result result); - - @Nullable - String getTitle(@NonNull Long instanceId); - - void scrollTo(@NonNull Long instanceId, @NonNull Long x, @NonNull Long y); - - void scrollBy(@NonNull Long instanceId, @NonNull Long x, @NonNull Long y); - - @NonNull - Long getScrollX(@NonNull Long instanceId); - - @NonNull - Long getScrollY(@NonNull Long instanceId); - - @NonNull - WebViewPoint getScrollPosition(@NonNull Long instanceId); - - void setWebContentsDebuggingEnabled(@NonNull Boolean enabled); - - void setWebViewClient(@NonNull Long instanceId, @NonNull Long webViewClientInstanceId); - - void addJavaScriptChannel(@NonNull Long instanceId, @NonNull Long javaScriptChannelInstanceId); - - void removeJavaScriptChannel( - @NonNull Long instanceId, @NonNull Long javaScriptChannelInstanceId); - - void setDownloadListener(@NonNull Long instanceId, @Nullable Long listenerInstanceId); - - void setWebChromeClient(@NonNull Long instanceId, @Nullable Long clientInstanceId); - - void setBackgroundColor(@NonNull Long instanceId, @NonNull Long color); - - /** The codec used by WebViewHostApi. */ - static @NonNull MessageCodec getCodec() { - return WebViewHostApiCodec.INSTANCE; - } - /** Sets up an instance of `WebViewHostApi` to handle messages through the `binaryMessenger`. */ - static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable WebViewHostApi api) { - { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.create", - getCodec()); - if (api != null) { - channel.setMessageHandler( - (message, reply) -> { - ArrayList wrapped = new ArrayList(); - ArrayList args = (ArrayList) message; - Number instanceIdArg = (Number) args.get(0); - try { - api.create((instanceIdArg == null) ? null : instanceIdArg.longValue()); - wrapped.add(0, null); - } catch (Throwable exception) { - ArrayList wrappedError = wrapError(exception); - wrapped = wrappedError; - } - reply.reply(wrapped); - }); - } else { - channel.setMessageHandler(null); - } - } - { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.loadData", - getCodec()); - if (api != null) { - channel.setMessageHandler( - (message, reply) -> { - ArrayList wrapped = new ArrayList(); - ArrayList args = (ArrayList) message; - Number instanceIdArg = (Number) args.get(0); - String dataArg = (String) args.get(1); - String mimeTypeArg = (String) args.get(2); - String encodingArg = (String) args.get(3); - try { - api.loadData( - (instanceIdArg == null) ? null : instanceIdArg.longValue(), - dataArg, - mimeTypeArg, - encodingArg); - wrapped.add(0, null); - } catch (Throwable exception) { - ArrayList wrappedError = wrapError(exception); - wrapped = wrappedError; - } - reply.reply(wrapped); - }); - } else { - channel.setMessageHandler(null); - } - } - { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.loadDataWithBaseUrl", - getCodec()); - if (api != null) { - channel.setMessageHandler( - (message, reply) -> { - ArrayList wrapped = new ArrayList(); - ArrayList args = (ArrayList) message; - Number instanceIdArg = (Number) args.get(0); - String baseUrlArg = (String) args.get(1); - String dataArg = (String) args.get(2); - String mimeTypeArg = (String) args.get(3); - String encodingArg = (String) args.get(4); - String historyUrlArg = (String) args.get(5); - try { - api.loadDataWithBaseUrl( - (instanceIdArg == null) ? null : instanceIdArg.longValue(), - baseUrlArg, - dataArg, - mimeTypeArg, - encodingArg, - historyUrlArg); - wrapped.add(0, null); - } catch (Throwable exception) { - ArrayList wrappedError = wrapError(exception); - wrapped = wrappedError; - } - reply.reply(wrapped); - }); - } else { - channel.setMessageHandler(null); - } - } - { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.loadUrl", - getCodec()); - if (api != null) { - channel.setMessageHandler( - (message, reply) -> { - ArrayList wrapped = new ArrayList(); - ArrayList args = (ArrayList) message; - Number instanceIdArg = (Number) args.get(0); - String urlArg = (String) args.get(1); - Map headersArg = (Map) args.get(2); - try { - api.loadUrl( - (instanceIdArg == null) ? null : instanceIdArg.longValue(), - urlArg, - headersArg); - wrapped.add(0, null); - } catch (Throwable exception) { - ArrayList wrappedError = wrapError(exception); - wrapped = wrappedError; - } - reply.reply(wrapped); - }); - } else { - channel.setMessageHandler(null); - } - } - { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.postUrl", - getCodec()); - if (api != null) { - channel.setMessageHandler( - (message, reply) -> { - ArrayList wrapped = new ArrayList(); - ArrayList args = (ArrayList) message; - Number instanceIdArg = (Number) args.get(0); - String urlArg = (String) args.get(1); - byte[] dataArg = (byte[]) args.get(2); - try { - api.postUrl( - (instanceIdArg == null) ? null : instanceIdArg.longValue(), urlArg, dataArg); - wrapped.add(0, null); - } catch (Throwable exception) { - ArrayList wrappedError = wrapError(exception); - wrapped = wrappedError; - } - reply.reply(wrapped); - }); - } else { - channel.setMessageHandler(null); - } - } - { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.getUrl", - getCodec()); - if (api != null) { - channel.setMessageHandler( - (message, reply) -> { - ArrayList wrapped = new ArrayList(); - ArrayList args = (ArrayList) message; - Number instanceIdArg = (Number) args.get(0); - try { - String output = - api.getUrl((instanceIdArg == null) ? null : instanceIdArg.longValue()); - wrapped.add(0, output); - } catch (Throwable exception) { - ArrayList wrappedError = wrapError(exception); - wrapped = wrappedError; - } - reply.reply(wrapped); - }); - } else { - channel.setMessageHandler(null); - } - } - { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.canGoBack", - getCodec()); - if (api != null) { - channel.setMessageHandler( - (message, reply) -> { - ArrayList wrapped = new ArrayList(); - ArrayList args = (ArrayList) message; - Number instanceIdArg = (Number) args.get(0); - try { - Boolean output = - api.canGoBack((instanceIdArg == null) ? null : instanceIdArg.longValue()); - wrapped.add(0, output); - } catch (Throwable exception) { - ArrayList wrappedError = wrapError(exception); - wrapped = wrappedError; - } - reply.reply(wrapped); - }); - } else { - channel.setMessageHandler(null); - } - } - { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.canGoForward", - getCodec()); - if (api != null) { - channel.setMessageHandler( - (message, reply) -> { - ArrayList wrapped = new ArrayList(); - ArrayList args = (ArrayList) message; - Number instanceIdArg = (Number) args.get(0); - try { - Boolean output = - api.canGoForward((instanceIdArg == null) ? null : instanceIdArg.longValue()); - wrapped.add(0, output); - } catch (Throwable exception) { - ArrayList wrappedError = wrapError(exception); - wrapped = wrappedError; - } - reply.reply(wrapped); - }); - } else { - channel.setMessageHandler(null); - } - } - { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.goBack", - getCodec()); - if (api != null) { - channel.setMessageHandler( - (message, reply) -> { - ArrayList wrapped = new ArrayList(); - ArrayList args = (ArrayList) message; - Number instanceIdArg = (Number) args.get(0); - try { - api.goBack((instanceIdArg == null) ? null : instanceIdArg.longValue()); - wrapped.add(0, null); - } catch (Throwable exception) { - ArrayList wrappedError = wrapError(exception); - wrapped = wrappedError; - } - reply.reply(wrapped); - }); - } else { - channel.setMessageHandler(null); - } - } - { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.goForward", - getCodec()); - if (api != null) { - channel.setMessageHandler( - (message, reply) -> { - ArrayList wrapped = new ArrayList(); - ArrayList args = (ArrayList) message; - Number instanceIdArg = (Number) args.get(0); - try { - api.goForward((instanceIdArg == null) ? null : instanceIdArg.longValue()); - wrapped.add(0, null); - } catch (Throwable exception) { - ArrayList wrappedError = wrapError(exception); - wrapped = wrappedError; - } - reply.reply(wrapped); - }); - } else { - channel.setMessageHandler(null); - } - } - { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.reload", - getCodec()); - if (api != null) { - channel.setMessageHandler( - (message, reply) -> { - ArrayList wrapped = new ArrayList(); - ArrayList args = (ArrayList) message; - Number instanceIdArg = (Number) args.get(0); - try { - api.reload((instanceIdArg == null) ? null : instanceIdArg.longValue()); - wrapped.add(0, null); - } catch (Throwable exception) { - ArrayList wrappedError = wrapError(exception); - wrapped = wrappedError; - } - reply.reply(wrapped); - }); - } else { - channel.setMessageHandler(null); - } - } - { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.clearCache", - getCodec()); - if (api != null) { - channel.setMessageHandler( - (message, reply) -> { - ArrayList wrapped = new ArrayList(); - ArrayList args = (ArrayList) message; - Number instanceIdArg = (Number) args.get(0); - Boolean includeDiskFilesArg = (Boolean) args.get(1); - try { - api.clearCache( - (instanceIdArg == null) ? null : instanceIdArg.longValue(), - includeDiskFilesArg); - wrapped.add(0, null); - } catch (Throwable exception) { - ArrayList wrappedError = wrapError(exception); - wrapped = wrappedError; - } - reply.reply(wrapped); - }); - } else { - channel.setMessageHandler(null); - } - } - { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.evaluateJavascript", - getCodec()); - if (api != null) { - channel.setMessageHandler( - (message, reply) -> { - ArrayList wrapped = new ArrayList(); - ArrayList args = (ArrayList) message; - Number instanceIdArg = (Number) args.get(0); - String javascriptStringArg = (String) args.get(1); - Result resultCallback = - new Result() { - public void success(String result) { - wrapped.add(0, result); - reply.reply(wrapped); - } - - public void error(Throwable error) { - ArrayList wrappedError = wrapError(error); - reply.reply(wrappedError); - } - }; - - api.evaluateJavascript( - (instanceIdArg == null) ? null : instanceIdArg.longValue(), - javascriptStringArg, - resultCallback); - }); - } else { - channel.setMessageHandler(null); - } - } - { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.getTitle", - getCodec()); - if (api != null) { - channel.setMessageHandler( - (message, reply) -> { - ArrayList wrapped = new ArrayList(); - ArrayList args = (ArrayList) message; - Number instanceIdArg = (Number) args.get(0); - try { - String output = - api.getTitle((instanceIdArg == null) ? null : instanceIdArg.longValue()); - wrapped.add(0, output); - } catch (Throwable exception) { - ArrayList wrappedError = wrapError(exception); - wrapped = wrappedError; - } - reply.reply(wrapped); - }); - } else { - channel.setMessageHandler(null); - } - } - { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.scrollTo", - getCodec()); - if (api != null) { - channel.setMessageHandler( - (message, reply) -> { - ArrayList wrapped = new ArrayList(); - ArrayList args = (ArrayList) message; - Number instanceIdArg = (Number) args.get(0); - Number xArg = (Number) args.get(1); - Number yArg = (Number) args.get(2); - try { - api.scrollTo( - (instanceIdArg == null) ? null : instanceIdArg.longValue(), - (xArg == null) ? null : xArg.longValue(), - (yArg == null) ? null : yArg.longValue()); - wrapped.add(0, null); - } catch (Throwable exception) { - ArrayList wrappedError = wrapError(exception); - wrapped = wrappedError; - } - reply.reply(wrapped); - }); - } else { - channel.setMessageHandler(null); - } - } - { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.scrollBy", - getCodec()); - if (api != null) { - channel.setMessageHandler( - (message, reply) -> { - ArrayList wrapped = new ArrayList(); - ArrayList args = (ArrayList) message; - Number instanceIdArg = (Number) args.get(0); - Number xArg = (Number) args.get(1); - Number yArg = (Number) args.get(2); - try { - api.scrollBy( - (instanceIdArg == null) ? null : instanceIdArg.longValue(), - (xArg == null) ? null : xArg.longValue(), - (yArg == null) ? null : yArg.longValue()); - wrapped.add(0, null); - } catch (Throwable exception) { - ArrayList wrappedError = wrapError(exception); - wrapped = wrappedError; - } - reply.reply(wrapped); - }); - } else { - channel.setMessageHandler(null); - } - } - { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.getScrollX", - getCodec()); - if (api != null) { - channel.setMessageHandler( - (message, reply) -> { - ArrayList wrapped = new ArrayList(); - ArrayList args = (ArrayList) message; - Number instanceIdArg = (Number) args.get(0); - try { - Long output = - api.getScrollX((instanceIdArg == null) ? null : instanceIdArg.longValue()); - wrapped.add(0, output); - } catch (Throwable exception) { - ArrayList wrappedError = wrapError(exception); - wrapped = wrappedError; - } - reply.reply(wrapped); - }); - } else { - channel.setMessageHandler(null); - } - } - { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.getScrollY", - getCodec()); - if (api != null) { - channel.setMessageHandler( - (message, reply) -> { - ArrayList wrapped = new ArrayList(); - ArrayList args = (ArrayList) message; - Number instanceIdArg = (Number) args.get(0); - try { - Long output = - api.getScrollY((instanceIdArg == null) ? null : instanceIdArg.longValue()); - wrapped.add(0, output); - } catch (Throwable exception) { - ArrayList wrappedError = wrapError(exception); - wrapped = wrappedError; - } - reply.reply(wrapped); - }); - } else { - channel.setMessageHandler(null); - } - } - { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.getScrollPosition", - getCodec()); - if (api != null) { - channel.setMessageHandler( - (message, reply) -> { - ArrayList wrapped = new ArrayList(); - ArrayList args = (ArrayList) message; - Number instanceIdArg = (Number) args.get(0); - try { - WebViewPoint output = - api.getScrollPosition( - (instanceIdArg == null) ? null : instanceIdArg.longValue()); - wrapped.add(0, output); - } catch (Throwable exception) { - ArrayList wrappedError = wrapError(exception); - wrapped = wrappedError; - } - reply.reply(wrapped); - }); - } else { - channel.setMessageHandler(null); - } - } - { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.setWebContentsDebuggingEnabled", - getCodec()); - if (api != null) { - channel.setMessageHandler( - (message, reply) -> { - ArrayList wrapped = new ArrayList(); - ArrayList args = (ArrayList) message; - Boolean enabledArg = (Boolean) args.get(0); - try { - api.setWebContentsDebuggingEnabled(enabledArg); - wrapped.add(0, null); - } catch (Throwable exception) { - ArrayList wrappedError = wrapError(exception); - wrapped = wrappedError; - } - reply.reply(wrapped); - }); - } else { - channel.setMessageHandler(null); - } - } - { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.setWebViewClient", - getCodec()); - if (api != null) { - channel.setMessageHandler( - (message, reply) -> { - ArrayList wrapped = new ArrayList(); - ArrayList args = (ArrayList) message; - Number instanceIdArg = (Number) args.get(0); - Number webViewClientInstanceIdArg = (Number) args.get(1); - try { - api.setWebViewClient( - (instanceIdArg == null) ? null : instanceIdArg.longValue(), - (webViewClientInstanceIdArg == null) - ? null - : webViewClientInstanceIdArg.longValue()); - wrapped.add(0, null); - } catch (Throwable exception) { - ArrayList wrappedError = wrapError(exception); - wrapped = wrappedError; - } - reply.reply(wrapped); - }); - } else { - channel.setMessageHandler(null); - } - } - { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.addJavaScriptChannel", - getCodec()); - if (api != null) { - channel.setMessageHandler( - (message, reply) -> { - ArrayList wrapped = new ArrayList(); - ArrayList args = (ArrayList) message; - Number instanceIdArg = (Number) args.get(0); - Number javaScriptChannelInstanceIdArg = (Number) args.get(1); - try { - api.addJavaScriptChannel( - (instanceIdArg == null) ? null : instanceIdArg.longValue(), - (javaScriptChannelInstanceIdArg == null) - ? null - : javaScriptChannelInstanceIdArg.longValue()); - wrapped.add(0, null); - } catch (Throwable exception) { - ArrayList wrappedError = wrapError(exception); - wrapped = wrappedError; - } - reply.reply(wrapped); - }); - } else { - channel.setMessageHandler(null); - } - } - { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.removeJavaScriptChannel", - getCodec()); - if (api != null) { - channel.setMessageHandler( - (message, reply) -> { - ArrayList wrapped = new ArrayList(); - ArrayList args = (ArrayList) message; - Number instanceIdArg = (Number) args.get(0); - Number javaScriptChannelInstanceIdArg = (Number) args.get(1); - try { - api.removeJavaScriptChannel( - (instanceIdArg == null) ? null : instanceIdArg.longValue(), - (javaScriptChannelInstanceIdArg == null) - ? null - : javaScriptChannelInstanceIdArg.longValue()); - wrapped.add(0, null); - } catch (Throwable exception) { - ArrayList wrappedError = wrapError(exception); - wrapped = wrappedError; - } - reply.reply(wrapped); - }); - } else { - channel.setMessageHandler(null); - } - } - { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.setDownloadListener", - getCodec()); - if (api != null) { - channel.setMessageHandler( - (message, reply) -> { - ArrayList wrapped = new ArrayList(); - ArrayList args = (ArrayList) message; - Number instanceIdArg = (Number) args.get(0); - Number listenerInstanceIdArg = (Number) args.get(1); - try { - api.setDownloadListener( - (instanceIdArg == null) ? null : instanceIdArg.longValue(), - (listenerInstanceIdArg == null) ? null : listenerInstanceIdArg.longValue()); - wrapped.add(0, null); - } catch (Throwable exception) { - ArrayList wrappedError = wrapError(exception); - wrapped = wrappedError; - } - reply.reply(wrapped); - }); - } else { - channel.setMessageHandler(null); - } - } - { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.setWebChromeClient", - getCodec()); - if (api != null) { - channel.setMessageHandler( - (message, reply) -> { - ArrayList wrapped = new ArrayList(); - ArrayList args = (ArrayList) message; - Number instanceIdArg = (Number) args.get(0); - Number clientInstanceIdArg = (Number) args.get(1); - try { - api.setWebChromeClient( - (instanceIdArg == null) ? null : instanceIdArg.longValue(), - (clientInstanceIdArg == null) ? null : clientInstanceIdArg.longValue()); - wrapped.add(0, null); - } catch (Throwable exception) { - ArrayList wrappedError = wrapError(exception); - wrapped = wrappedError; - } - reply.reply(wrapped); - }); - } else { - channel.setMessageHandler(null); - } - } - { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.setBackgroundColor", - getCodec()); - if (api != null) { - channel.setMessageHandler( - (message, reply) -> { - ArrayList wrapped = new ArrayList(); - ArrayList args = (ArrayList) message; - Number instanceIdArg = (Number) args.get(0); - Number colorArg = (Number) args.get(1); - try { - api.setBackgroundColor( - (instanceIdArg == null) ? null : instanceIdArg.longValue(), - (colorArg == null) ? null : colorArg.longValue()); - wrapped.add(0, null); - } catch (Throwable exception) { - ArrayList wrappedError = wrapError(exception); - wrapped = wrappedError; - } - reply.reply(wrapped); - }); - } else { - channel.setMessageHandler(null); - } - } - } - } - /** - * Flutter API for `WebView`. - * - *

This class may handle instantiating and adding Dart instances that are attached to a native - * instance or receiving callback methods from an overridden native class. - * - *

See https://developer.android.com/reference/android/webkit/WebView. - * - *

Generated class from Pigeon that represents Flutter messages that can be called from Java. - */ - public static class WebViewFlutterApi { - private final @NonNull BinaryMessenger binaryMessenger; - - public WebViewFlutterApi(@NonNull BinaryMessenger argBinaryMessenger) { - this.binaryMessenger = argBinaryMessenger; - } - - /** Public interface for sending reply. */ - @SuppressWarnings("UnknownNullness") - public interface Reply { - void reply(T reply); - } - /** The codec used by WebViewFlutterApi. */ - static @NonNull MessageCodec getCodec() { - return new StandardMessageCodec(); - } - /** Create a new Dart instance and add it to the `InstanceManager`. */ - public void create(@NonNull Long identifierArg, @NonNull Reply callback) { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.webview_flutter_android.WebViewFlutterApi.create", - getCodec()); - channel.send( - new ArrayList(Collections.singletonList(identifierArg)), - channelReply -> callback.reply(null)); - } - - public void onScrollChanged( - @NonNull Long webViewInstanceIdArg, - @NonNull Long leftArg, - @NonNull Long topArg, - @NonNull Long oldLeftArg, - @NonNull Long oldTopArg, - @NonNull Reply callback) { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.webview_flutter_android.WebViewFlutterApi.onScrollChanged", - getCodec()); - channel.send( - new ArrayList( - Arrays.asList(webViewInstanceIdArg, leftArg, topArg, oldLeftArg, oldTopArg)), - channelReply -> callback.reply(null)); - } - } - /** Generated interface from Pigeon that represents a handler of messages from Flutter. */ - public interface WebSettingsHostApi { - - void create(@NonNull Long instanceId, @NonNull Long webViewInstanceId); - - void setDomStorageEnabled(@NonNull Long instanceId, @NonNull Boolean flag); - - void setJavaScriptCanOpenWindowsAutomatically(@NonNull Long instanceId, @NonNull Boolean flag); - - void setSupportMultipleWindows(@NonNull Long instanceId, @NonNull Boolean support); - - void setJavaScriptEnabled(@NonNull Long instanceId, @NonNull Boolean flag); - - void setUserAgentString(@NonNull Long instanceId, @Nullable String userAgentString); - - void setMediaPlaybackRequiresUserGesture(@NonNull Long instanceId, @NonNull Boolean require); - - void setSupportZoom(@NonNull Long instanceId, @NonNull Boolean support); - - void setLoadWithOverviewMode(@NonNull Long instanceId, @NonNull Boolean overview); - - void setUseWideViewPort(@NonNull Long instanceId, @NonNull Boolean use); - - void setDisplayZoomControls(@NonNull Long instanceId, @NonNull Boolean enabled); - - void setBuiltInZoomControls(@NonNull Long instanceId, @NonNull Boolean enabled); - - void setAllowFileAccess(@NonNull Long instanceId, @NonNull Boolean enabled); - - void setTextZoom(@NonNull Long instanceId, @NonNull Long textZoom); - - @NonNull - String getUserAgentString(@NonNull Long instanceId); - - /** The codec used by WebSettingsHostApi. */ - static @NonNull MessageCodec getCodec() { - return new StandardMessageCodec(); - } - /** - * Sets up an instance of `WebSettingsHostApi` to handle messages through the `binaryMessenger`. - */ - static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable WebSettingsHostApi api) { - { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.webview_flutter_android.WebSettingsHostApi.create", - getCodec()); - if (api != null) { - channel.setMessageHandler( - (message, reply) -> { - ArrayList wrapped = new ArrayList(); - ArrayList args = (ArrayList) message; - Number instanceIdArg = (Number) args.get(0); - Number webViewInstanceIdArg = (Number) args.get(1); - try { - api.create( - (instanceIdArg == null) ? null : instanceIdArg.longValue(), - (webViewInstanceIdArg == null) ? null : webViewInstanceIdArg.longValue()); - wrapped.add(0, null); - } catch (Throwable exception) { - ArrayList wrappedError = wrapError(exception); - wrapped = wrappedError; - } - reply.reply(wrapped); - }); - } else { - channel.setMessageHandler(null); - } - } - { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.webview_flutter_android.WebSettingsHostApi.setDomStorageEnabled", - getCodec()); - if (api != null) { - channel.setMessageHandler( - (message, reply) -> { - ArrayList wrapped = new ArrayList(); - ArrayList args = (ArrayList) message; - Number instanceIdArg = (Number) args.get(0); - Boolean flagArg = (Boolean) args.get(1); - try { - api.setDomStorageEnabled( - (instanceIdArg == null) ? null : instanceIdArg.longValue(), flagArg); - wrapped.add(0, null); - } catch (Throwable exception) { - ArrayList wrappedError = wrapError(exception); - wrapped = wrappedError; - } - reply.reply(wrapped); - }); - } else { - channel.setMessageHandler(null); - } - } - { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.webview_flutter_android.WebSettingsHostApi.setJavaScriptCanOpenWindowsAutomatically", - getCodec()); - if (api != null) { - channel.setMessageHandler( - (message, reply) -> { - ArrayList wrapped = new ArrayList(); - ArrayList args = (ArrayList) message; - Number instanceIdArg = (Number) args.get(0); - Boolean flagArg = (Boolean) args.get(1); - try { - api.setJavaScriptCanOpenWindowsAutomatically( - (instanceIdArg == null) ? null : instanceIdArg.longValue(), flagArg); - wrapped.add(0, null); - } catch (Throwable exception) { - ArrayList wrappedError = wrapError(exception); - wrapped = wrappedError; - } - reply.reply(wrapped); - }); - } else { - channel.setMessageHandler(null); - } - } - { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.webview_flutter_android.WebSettingsHostApi.setSupportMultipleWindows", - getCodec()); - if (api != null) { - channel.setMessageHandler( - (message, reply) -> { - ArrayList wrapped = new ArrayList(); - ArrayList args = (ArrayList) message; - Number instanceIdArg = (Number) args.get(0); - Boolean supportArg = (Boolean) args.get(1); - try { - api.setSupportMultipleWindows( - (instanceIdArg == null) ? null : instanceIdArg.longValue(), supportArg); - wrapped.add(0, null); - } catch (Throwable exception) { - ArrayList wrappedError = wrapError(exception); - wrapped = wrappedError; - } - reply.reply(wrapped); - }); - } else { - channel.setMessageHandler(null); - } - } - { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.webview_flutter_android.WebSettingsHostApi.setJavaScriptEnabled", - getCodec()); - if (api != null) { - channel.setMessageHandler( - (message, reply) -> { - ArrayList wrapped = new ArrayList(); - ArrayList args = (ArrayList) message; - Number instanceIdArg = (Number) args.get(0); - Boolean flagArg = (Boolean) args.get(1); - try { - api.setJavaScriptEnabled( - (instanceIdArg == null) ? null : instanceIdArg.longValue(), flagArg); - wrapped.add(0, null); - } catch (Throwable exception) { - ArrayList wrappedError = wrapError(exception); - wrapped = wrappedError; - } - reply.reply(wrapped); - }); - } else { - channel.setMessageHandler(null); - } - } - { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.webview_flutter_android.WebSettingsHostApi.setUserAgentString", - getCodec()); - if (api != null) { - channel.setMessageHandler( - (message, reply) -> { - ArrayList wrapped = new ArrayList(); - ArrayList args = (ArrayList) message; - Number instanceIdArg = (Number) args.get(0); - String userAgentStringArg = (String) args.get(1); - try { - api.setUserAgentString( - (instanceIdArg == null) ? null : instanceIdArg.longValue(), - userAgentStringArg); - wrapped.add(0, null); - } catch (Throwable exception) { - ArrayList wrappedError = wrapError(exception); - wrapped = wrappedError; - } - reply.reply(wrapped); - }); - } else { - channel.setMessageHandler(null); - } - } - { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.webview_flutter_android.WebSettingsHostApi.setMediaPlaybackRequiresUserGesture", - getCodec()); - if (api != null) { - channel.setMessageHandler( - (message, reply) -> { - ArrayList wrapped = new ArrayList(); - ArrayList args = (ArrayList) message; - Number instanceIdArg = (Number) args.get(0); - Boolean requireArg = (Boolean) args.get(1); - try { - api.setMediaPlaybackRequiresUserGesture( - (instanceIdArg == null) ? null : instanceIdArg.longValue(), requireArg); - wrapped.add(0, null); - } catch (Throwable exception) { - ArrayList wrappedError = wrapError(exception); - wrapped = wrappedError; - } - reply.reply(wrapped); - }); - } else { - channel.setMessageHandler(null); - } - } - { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.webview_flutter_android.WebSettingsHostApi.setSupportZoom", - getCodec()); - if (api != null) { - channel.setMessageHandler( - (message, reply) -> { - ArrayList wrapped = new ArrayList(); - ArrayList args = (ArrayList) message; - Number instanceIdArg = (Number) args.get(0); - Boolean supportArg = (Boolean) args.get(1); - try { - api.setSupportZoom( - (instanceIdArg == null) ? null : instanceIdArg.longValue(), supportArg); - wrapped.add(0, null); - } catch (Throwable exception) { - ArrayList wrappedError = wrapError(exception); - wrapped = wrappedError; - } - reply.reply(wrapped); - }); - } else { - channel.setMessageHandler(null); - } - } - { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.webview_flutter_android.WebSettingsHostApi.setLoadWithOverviewMode", - getCodec()); - if (api != null) { - channel.setMessageHandler( - (message, reply) -> { - ArrayList wrapped = new ArrayList(); - ArrayList args = (ArrayList) message; - Number instanceIdArg = (Number) args.get(0); - Boolean overviewArg = (Boolean) args.get(1); - try { - api.setLoadWithOverviewMode( - (instanceIdArg == null) ? null : instanceIdArg.longValue(), overviewArg); - wrapped.add(0, null); - } catch (Throwable exception) { - ArrayList wrappedError = wrapError(exception); - wrapped = wrappedError; - } - reply.reply(wrapped); - }); - } else { - channel.setMessageHandler(null); - } - } - { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.webview_flutter_android.WebSettingsHostApi.setUseWideViewPort", - getCodec()); - if (api != null) { - channel.setMessageHandler( - (message, reply) -> { - ArrayList wrapped = new ArrayList(); - ArrayList args = (ArrayList) message; - Number instanceIdArg = (Number) args.get(0); - Boolean useArg = (Boolean) args.get(1); - try { - api.setUseWideViewPort( - (instanceIdArg == null) ? null : instanceIdArg.longValue(), useArg); - wrapped.add(0, null); - } catch (Throwable exception) { - ArrayList wrappedError = wrapError(exception); - wrapped = wrappedError; - } - reply.reply(wrapped); - }); - } else { - channel.setMessageHandler(null); - } - } - { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.webview_flutter_android.WebSettingsHostApi.setDisplayZoomControls", - getCodec()); - if (api != null) { - channel.setMessageHandler( - (message, reply) -> { - ArrayList wrapped = new ArrayList(); - ArrayList args = (ArrayList) message; - Number instanceIdArg = (Number) args.get(0); - Boolean enabledArg = (Boolean) args.get(1); - try { - api.setDisplayZoomControls( - (instanceIdArg == null) ? null : instanceIdArg.longValue(), enabledArg); - wrapped.add(0, null); - } catch (Throwable exception) { - ArrayList wrappedError = wrapError(exception); - wrapped = wrappedError; - } - reply.reply(wrapped); - }); - } else { - channel.setMessageHandler(null); - } - } - { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.webview_flutter_android.WebSettingsHostApi.setBuiltInZoomControls", - getCodec()); - if (api != null) { - channel.setMessageHandler( - (message, reply) -> { - ArrayList wrapped = new ArrayList(); - ArrayList args = (ArrayList) message; - Number instanceIdArg = (Number) args.get(0); - Boolean enabledArg = (Boolean) args.get(1); - try { - api.setBuiltInZoomControls( - (instanceIdArg == null) ? null : instanceIdArg.longValue(), enabledArg); - wrapped.add(0, null); - } catch (Throwable exception) { - ArrayList wrappedError = wrapError(exception); - wrapped = wrappedError; - } - reply.reply(wrapped); - }); - } else { - channel.setMessageHandler(null); - } - } - { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.webview_flutter_android.WebSettingsHostApi.setAllowFileAccess", - getCodec()); - if (api != null) { - channel.setMessageHandler( - (message, reply) -> { - ArrayList wrapped = new ArrayList(); - ArrayList args = (ArrayList) message; - Number instanceIdArg = (Number) args.get(0); - Boolean enabledArg = (Boolean) args.get(1); - try { - api.setAllowFileAccess( - (instanceIdArg == null) ? null : instanceIdArg.longValue(), enabledArg); - wrapped.add(0, null); - } catch (Throwable exception) { - ArrayList wrappedError = wrapError(exception); - wrapped = wrappedError; - } - reply.reply(wrapped); - }); - } else { - channel.setMessageHandler(null); - } - } - { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.webview_flutter_android.WebSettingsHostApi.setTextZoom", - getCodec()); - if (api != null) { - channel.setMessageHandler( - (message, reply) -> { - ArrayList wrapped = new ArrayList(); - ArrayList args = (ArrayList) message; - Number instanceIdArg = (Number) args.get(0); - Number textZoomArg = (Number) args.get(1); - try { - api.setTextZoom( - (instanceIdArg == null) ? null : instanceIdArg.longValue(), - (textZoomArg == null) ? null : textZoomArg.longValue()); - wrapped.add(0, null); - } catch (Throwable exception) { - ArrayList wrappedError = wrapError(exception); - wrapped = wrappedError; - } - reply.reply(wrapped); - }); - } else { - channel.setMessageHandler(null); - } - } - { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.webview_flutter_android.WebSettingsHostApi.getUserAgentString", - getCodec()); - if (api != null) { - channel.setMessageHandler( - (message, reply) -> { - ArrayList wrapped = new ArrayList(); - ArrayList args = (ArrayList) message; - Number instanceIdArg = (Number) args.get(0); - try { - String output = - api.getUserAgentString( - (instanceIdArg == null) ? null : instanceIdArg.longValue()); - wrapped.add(0, output); - } catch (Throwable exception) { - ArrayList wrappedError = wrapError(exception); - wrapped = wrappedError; - } - reply.reply(wrapped); - }); - } else { - channel.setMessageHandler(null); - } - } - } - } - /** Generated interface from Pigeon that represents a handler of messages from Flutter. */ - public interface JavaScriptChannelHostApi { - - void create(@NonNull Long instanceId, @NonNull String channelName); - - /** The codec used by JavaScriptChannelHostApi. */ - static @NonNull MessageCodec getCodec() { - return new StandardMessageCodec(); - } - /** - * Sets up an instance of `JavaScriptChannelHostApi` to handle messages through the - * `binaryMessenger`. - */ - static void setup( - @NonNull BinaryMessenger binaryMessenger, @Nullable JavaScriptChannelHostApi api) { - { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.webview_flutter_android.JavaScriptChannelHostApi.create", - getCodec()); - if (api != null) { - channel.setMessageHandler( - (message, reply) -> { - ArrayList wrapped = new ArrayList(); - ArrayList args = (ArrayList) message; - Number instanceIdArg = (Number) args.get(0); - String channelNameArg = (String) args.get(1); - try { - api.create( - (instanceIdArg == null) ? null : instanceIdArg.longValue(), channelNameArg); - wrapped.add(0, null); - } catch (Throwable exception) { - ArrayList wrappedError = wrapError(exception); - wrapped = wrappedError; - } - reply.reply(wrapped); - }); - } else { - channel.setMessageHandler(null); - } - } - } - } - /** Generated class from Pigeon that represents Flutter messages that can be called from Java. */ - public static class JavaScriptChannelFlutterApi { - private final @NonNull BinaryMessenger binaryMessenger; - - public JavaScriptChannelFlutterApi(@NonNull BinaryMessenger argBinaryMessenger) { - this.binaryMessenger = argBinaryMessenger; - } - - /** Public interface for sending reply. */ - @SuppressWarnings("UnknownNullness") - public interface Reply { - void reply(T reply); - } - /** The codec used by JavaScriptChannelFlutterApi. */ - static @NonNull MessageCodec getCodec() { - return new StandardMessageCodec(); - } - - public void postMessage( - @NonNull Long instanceIdArg, @NonNull String messageArg, @NonNull Reply callback) { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.webview_flutter_android.JavaScriptChannelFlutterApi.postMessage", - getCodec()); - channel.send( - new ArrayList(Arrays.asList(instanceIdArg, messageArg)), - channelReply -> callback.reply(null)); - } - } - /** Generated interface from Pigeon that represents a handler of messages from Flutter. */ - public interface WebViewClientHostApi { - - void create(@NonNull Long instanceId); - - void setSynchronousReturnValueForShouldOverrideUrlLoading( - @NonNull Long instanceId, @NonNull Boolean value); - - /** The codec used by WebViewClientHostApi. */ - static @NonNull MessageCodec getCodec() { - return new StandardMessageCodec(); - } - /** - * Sets up an instance of `WebViewClientHostApi` to handle messages through the - * `binaryMessenger`. - */ - static void setup( - @NonNull BinaryMessenger binaryMessenger, @Nullable WebViewClientHostApi api) { - { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.webview_flutter_android.WebViewClientHostApi.create", - getCodec()); - if (api != null) { - channel.setMessageHandler( - (message, reply) -> { - ArrayList wrapped = new ArrayList(); - ArrayList args = (ArrayList) message; - Number instanceIdArg = (Number) args.get(0); - try { - api.create((instanceIdArg == null) ? null : instanceIdArg.longValue()); - wrapped.add(0, null); - } catch (Throwable exception) { - ArrayList wrappedError = wrapError(exception); - wrapped = wrappedError; - } - reply.reply(wrapped); - }); - } else { - channel.setMessageHandler(null); - } - } - { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.webview_flutter_android.WebViewClientHostApi.setSynchronousReturnValueForShouldOverrideUrlLoading", - getCodec()); - if (api != null) { - channel.setMessageHandler( - (message, reply) -> { - ArrayList wrapped = new ArrayList(); - ArrayList args = (ArrayList) message; - Number instanceIdArg = (Number) args.get(0); - Boolean valueArg = (Boolean) args.get(1); - try { - api.setSynchronousReturnValueForShouldOverrideUrlLoading( - (instanceIdArg == null) ? null : instanceIdArg.longValue(), valueArg); - wrapped.add(0, null); - } catch (Throwable exception) { - ArrayList wrappedError = wrapError(exception); - wrapped = wrappedError; - } - reply.reply(wrapped); - }); - } else { - channel.setMessageHandler(null); - } - } - } - } - - private static class WebViewClientFlutterApiCodec extends StandardMessageCodec { - public static final WebViewClientFlutterApiCodec INSTANCE = new WebViewClientFlutterApiCodec(); - - private WebViewClientFlutterApiCodec() {} - - @Override - protected Object readValueOfType(byte type, @NonNull ByteBuffer buffer) { - switch (type) { - case (byte) 128: - return WebResourceErrorData.fromList((ArrayList) readValue(buffer)); - case (byte) 129: - return WebResourceRequestData.fromList((ArrayList) readValue(buffer)); - case (byte) 130: - return WebResourceResponseData.fromList((ArrayList) readValue(buffer)); - default: - return super.readValueOfType(type, buffer); - } - } - - @Override - protected void writeValue(@NonNull ByteArrayOutputStream stream, Object value) { - if (value instanceof WebResourceErrorData) { - stream.write(128); - writeValue(stream, ((WebResourceErrorData) value).toList()); - } else if (value instanceof WebResourceRequestData) { - stream.write(129); - writeValue(stream, ((WebResourceRequestData) value).toList()); - } else if (value instanceof WebResourceResponseData) { - stream.write(130); - writeValue(stream, ((WebResourceResponseData) value).toList()); - } else { - super.writeValue(stream, value); - } - } - } - - /** Generated class from Pigeon that represents Flutter messages that can be called from Java. */ - public static class WebViewClientFlutterApi { - private final @NonNull BinaryMessenger binaryMessenger; - - public WebViewClientFlutterApi(@NonNull BinaryMessenger argBinaryMessenger) { - this.binaryMessenger = argBinaryMessenger; - } - - /** Public interface for sending reply. */ - @SuppressWarnings("UnknownNullness") - public interface Reply { - void reply(T reply); - } - /** The codec used by WebViewClientFlutterApi. */ - static @NonNull MessageCodec getCodec() { - return WebViewClientFlutterApiCodec.INSTANCE; - } - - public void onPageStarted( - @NonNull Long instanceIdArg, - @NonNull Long webViewInstanceIdArg, - @NonNull String urlArg, - @NonNull Reply callback) { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.webview_flutter_android.WebViewClientFlutterApi.onPageStarted", - getCodec()); - channel.send( - new ArrayList(Arrays.asList(instanceIdArg, webViewInstanceIdArg, urlArg)), - channelReply -> callback.reply(null)); - } - - public void onPageFinished( - @NonNull Long instanceIdArg, - @NonNull Long webViewInstanceIdArg, - @NonNull String urlArg, - @NonNull Reply callback) { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.webview_flutter_android.WebViewClientFlutterApi.onPageFinished", - getCodec()); - channel.send( - new ArrayList(Arrays.asList(instanceIdArg, webViewInstanceIdArg, urlArg)), - channelReply -> callback.reply(null)); - } - - public void onReceivedHttpError( - @NonNull Long instanceIdArg, - @NonNull Long webViewInstanceIdArg, - @NonNull WebResourceRequestData requestArg, - @NonNull WebResourceResponseData responseArg, - @NonNull Reply callback) { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.webview_flutter_android.WebViewClientFlutterApi.onReceivedHttpError", - getCodec()); - channel.send( - new ArrayList( - Arrays.asList(instanceIdArg, webViewInstanceIdArg, requestArg, responseArg)), - channelReply -> callback.reply(null)); - } - - public void onReceivedRequestError( - @NonNull Long instanceIdArg, - @NonNull Long webViewInstanceIdArg, - @NonNull WebResourceRequestData requestArg, - @NonNull WebResourceErrorData errorArg, - @NonNull Reply callback) { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.webview_flutter_android.WebViewClientFlutterApi.onReceivedRequestError", - getCodec()); - channel.send( - new ArrayList( - Arrays.asList(instanceIdArg, webViewInstanceIdArg, requestArg, errorArg)), - channelReply -> callback.reply(null)); - } - - public void onReceivedError( - @NonNull Long instanceIdArg, - @NonNull Long webViewInstanceIdArg, - @NonNull Long errorCodeArg, - @NonNull String descriptionArg, - @NonNull String failingUrlArg, - @NonNull Reply callback) { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.webview_flutter_android.WebViewClientFlutterApi.onReceivedError", - getCodec()); - channel.send( - new ArrayList( - Arrays.asList( - instanceIdArg, - webViewInstanceIdArg, - errorCodeArg, - descriptionArg, - failingUrlArg)), - channelReply -> callback.reply(null)); - } - - public void requestLoading( - @NonNull Long instanceIdArg, - @NonNull Long webViewInstanceIdArg, - @NonNull WebResourceRequestData requestArg, - @NonNull Reply callback) { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.webview_flutter_android.WebViewClientFlutterApi.requestLoading", - getCodec()); - channel.send( - new ArrayList(Arrays.asList(instanceIdArg, webViewInstanceIdArg, requestArg)), - channelReply -> callback.reply(null)); - } - - public void urlLoading( - @NonNull Long instanceIdArg, - @NonNull Long webViewInstanceIdArg, - @NonNull String urlArg, - @NonNull Reply callback) { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.webview_flutter_android.WebViewClientFlutterApi.urlLoading", - getCodec()); - channel.send( - new ArrayList(Arrays.asList(instanceIdArg, webViewInstanceIdArg, urlArg)), - channelReply -> callback.reply(null)); - } - - public void doUpdateVisitedHistory( - @NonNull Long instanceIdArg, - @NonNull Long webViewInstanceIdArg, - @NonNull String urlArg, - @NonNull Boolean isReloadArg, - @NonNull Reply callback) { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.webview_flutter_android.WebViewClientFlutterApi.doUpdateVisitedHistory", - getCodec()); - channel.send( - new ArrayList( - Arrays.asList(instanceIdArg, webViewInstanceIdArg, urlArg, isReloadArg)), - channelReply -> callback.reply(null)); - } - - public void onReceivedHttpAuthRequest( - @NonNull Long instanceIdArg, - @NonNull Long webViewInstanceIdArg, - @NonNull Long httpAuthHandlerInstanceIdArg, - @NonNull String hostArg, - @NonNull String realmArg, - @NonNull Reply callback) { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.webview_flutter_android.WebViewClientFlutterApi.onReceivedHttpAuthRequest", - getCodec()); - channel.send( - new ArrayList( - Arrays.asList( - instanceIdArg, - webViewInstanceIdArg, - httpAuthHandlerInstanceIdArg, - hostArg, - realmArg)), - channelReply -> callback.reply(null)); - } - } - /** Generated interface from Pigeon that represents a handler of messages from Flutter. */ - public interface DownloadListenerHostApi { - - void create(@NonNull Long instanceId); - - /** The codec used by DownloadListenerHostApi. */ - static @NonNull MessageCodec getCodec() { - return new StandardMessageCodec(); - } - /** - * Sets up an instance of `DownloadListenerHostApi` to handle messages through the - * `binaryMessenger`. - */ - static void setup( - @NonNull BinaryMessenger binaryMessenger, @Nullable DownloadListenerHostApi api) { - { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.webview_flutter_android.DownloadListenerHostApi.create", - getCodec()); - if (api != null) { - channel.setMessageHandler( - (message, reply) -> { - ArrayList wrapped = new ArrayList(); - ArrayList args = (ArrayList) message; - Number instanceIdArg = (Number) args.get(0); - try { - api.create((instanceIdArg == null) ? null : instanceIdArg.longValue()); - wrapped.add(0, null); - } catch (Throwable exception) { - ArrayList wrappedError = wrapError(exception); - wrapped = wrappedError; - } - reply.reply(wrapped); - }); - } else { - channel.setMessageHandler(null); - } - } - } - } - /** Generated class from Pigeon that represents Flutter messages that can be called from Java. */ - public static class DownloadListenerFlutterApi { - private final @NonNull BinaryMessenger binaryMessenger; - - public DownloadListenerFlutterApi(@NonNull BinaryMessenger argBinaryMessenger) { - this.binaryMessenger = argBinaryMessenger; - } - - /** Public interface for sending reply. */ - @SuppressWarnings("UnknownNullness") - public interface Reply { - void reply(T reply); - } - /** The codec used by DownloadListenerFlutterApi. */ - static @NonNull MessageCodec getCodec() { - return new StandardMessageCodec(); - } - - public void onDownloadStart( - @NonNull Long instanceIdArg, - @NonNull String urlArg, - @NonNull String userAgentArg, - @NonNull String contentDispositionArg, - @NonNull String mimetypeArg, - @NonNull Long contentLengthArg, - @NonNull Reply callback) { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.webview_flutter_android.DownloadListenerFlutterApi.onDownloadStart", - getCodec()); - channel.send( - new ArrayList( - Arrays.asList( - instanceIdArg, - urlArg, - userAgentArg, - contentDispositionArg, - mimetypeArg, - contentLengthArg)), - channelReply -> callback.reply(null)); - } - } - /** Generated interface from Pigeon that represents a handler of messages from Flutter. */ - public interface WebChromeClientHostApi { - - void create(@NonNull Long instanceId); - - void setSynchronousReturnValueForOnShowFileChooser( - @NonNull Long instanceId, @NonNull Boolean value); - - void setSynchronousReturnValueForOnConsoleMessage( - @NonNull Long instanceId, @NonNull Boolean value); - - void setSynchronousReturnValueForOnJsAlert(@NonNull Long instanceId, @NonNull Boolean value); - - void setSynchronousReturnValueForOnJsConfirm(@NonNull Long instanceId, @NonNull Boolean value); - - void setSynchronousReturnValueForOnJsPrompt(@NonNull Long instanceId, @NonNull Boolean value); - - /** The codec used by WebChromeClientHostApi. */ - static @NonNull MessageCodec getCodec() { - return new StandardMessageCodec(); - } - /** - * Sets up an instance of `WebChromeClientHostApi` to handle messages through the - * `binaryMessenger`. - */ - static void setup( - @NonNull BinaryMessenger binaryMessenger, @Nullable WebChromeClientHostApi api) { - { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.webview_flutter_android.WebChromeClientHostApi.create", - getCodec()); - if (api != null) { - channel.setMessageHandler( - (message, reply) -> { - ArrayList wrapped = new ArrayList(); - ArrayList args = (ArrayList) message; - Number instanceIdArg = (Number) args.get(0); - try { - api.create((instanceIdArg == null) ? null : instanceIdArg.longValue()); - wrapped.add(0, null); - } catch (Throwable exception) { - ArrayList wrappedError = wrapError(exception); - wrapped = wrappedError; - } - reply.reply(wrapped); - }); - } else { - channel.setMessageHandler(null); - } - } - { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.webview_flutter_android.WebChromeClientHostApi.setSynchronousReturnValueForOnShowFileChooser", - getCodec()); - if (api != null) { - channel.setMessageHandler( - (message, reply) -> { - ArrayList wrapped = new ArrayList(); - ArrayList args = (ArrayList) message; - Number instanceIdArg = (Number) args.get(0); - Boolean valueArg = (Boolean) args.get(1); - try { - api.setSynchronousReturnValueForOnShowFileChooser( - (instanceIdArg == null) ? null : instanceIdArg.longValue(), valueArg); - wrapped.add(0, null); - } catch (Throwable exception) { - ArrayList wrappedError = wrapError(exception); - wrapped = wrappedError; - } - reply.reply(wrapped); - }); - } else { - channel.setMessageHandler(null); - } - } - { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.webview_flutter_android.WebChromeClientHostApi.setSynchronousReturnValueForOnConsoleMessage", - getCodec()); - if (api != null) { - channel.setMessageHandler( - (message, reply) -> { - ArrayList wrapped = new ArrayList(); - ArrayList args = (ArrayList) message; - Number instanceIdArg = (Number) args.get(0); - Boolean valueArg = (Boolean) args.get(1); - try { - api.setSynchronousReturnValueForOnConsoleMessage( - (instanceIdArg == null) ? null : instanceIdArg.longValue(), valueArg); - wrapped.add(0, null); - } catch (Throwable exception) { - ArrayList wrappedError = wrapError(exception); - wrapped = wrappedError; - } - reply.reply(wrapped); - }); - } else { - channel.setMessageHandler(null); - } - } - { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.webview_flutter_android.WebChromeClientHostApi.setSynchronousReturnValueForOnJsAlert", - getCodec()); - if (api != null) { - channel.setMessageHandler( - (message, reply) -> { - ArrayList wrapped = new ArrayList(); - ArrayList args = (ArrayList) message; - Number instanceIdArg = (Number) args.get(0); - Boolean valueArg = (Boolean) args.get(1); - try { - api.setSynchronousReturnValueForOnJsAlert( - (instanceIdArg == null) ? null : instanceIdArg.longValue(), valueArg); - wrapped.add(0, null); - } catch (Throwable exception) { - ArrayList wrappedError = wrapError(exception); - wrapped = wrappedError; - } - reply.reply(wrapped); - }); - } else { - channel.setMessageHandler(null); - } - } - { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.webview_flutter_android.WebChromeClientHostApi.setSynchronousReturnValueForOnJsConfirm", - getCodec()); - if (api != null) { - channel.setMessageHandler( - (message, reply) -> { - ArrayList wrapped = new ArrayList(); - ArrayList args = (ArrayList) message; - Number instanceIdArg = (Number) args.get(0); - Boolean valueArg = (Boolean) args.get(1); - try { - api.setSynchronousReturnValueForOnJsConfirm( - (instanceIdArg == null) ? null : instanceIdArg.longValue(), valueArg); - wrapped.add(0, null); - } catch (Throwable exception) { - ArrayList wrappedError = wrapError(exception); - wrapped = wrappedError; - } - reply.reply(wrapped); - }); - } else { - channel.setMessageHandler(null); - } - } - { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.webview_flutter_android.WebChromeClientHostApi.setSynchronousReturnValueForOnJsPrompt", - getCodec()); - if (api != null) { - channel.setMessageHandler( - (message, reply) -> { - ArrayList wrapped = new ArrayList(); - ArrayList args = (ArrayList) message; - Number instanceIdArg = (Number) args.get(0); - Boolean valueArg = (Boolean) args.get(1); - try { - api.setSynchronousReturnValueForOnJsPrompt( - (instanceIdArg == null) ? null : instanceIdArg.longValue(), valueArg); - wrapped.add(0, null); - } catch (Throwable exception) { - ArrayList wrappedError = wrapError(exception); - wrapped = wrappedError; - } - reply.reply(wrapped); - }); - } else { - channel.setMessageHandler(null); - } - } - } - } - /** Generated interface from Pigeon that represents a handler of messages from Flutter. */ - public interface FlutterAssetManagerHostApi { - - @NonNull - List list(@NonNull String path); - - @NonNull - String getAssetFilePathByName(@NonNull String name); - - /** The codec used by FlutterAssetManagerHostApi. */ - static @NonNull MessageCodec getCodec() { - return new StandardMessageCodec(); - } - /** - * Sets up an instance of `FlutterAssetManagerHostApi` to handle messages through the - * `binaryMessenger`. - */ - static void setup( - @NonNull BinaryMessenger binaryMessenger, @Nullable FlutterAssetManagerHostApi api) { - { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.webview_flutter_android.FlutterAssetManagerHostApi.list", - getCodec()); - if (api != null) { - channel.setMessageHandler( - (message, reply) -> { - ArrayList wrapped = new ArrayList(); - ArrayList args = (ArrayList) message; - String pathArg = (String) args.get(0); - try { - List output = api.list(pathArg); - wrapped.add(0, output); - } catch (Throwable exception) { - ArrayList wrappedError = wrapError(exception); - wrapped = wrappedError; - } - reply.reply(wrapped); - }); - } else { - channel.setMessageHandler(null); - } - } - { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.webview_flutter_android.FlutterAssetManagerHostApi.getAssetFilePathByName", - getCodec()); - if (api != null) { - channel.setMessageHandler( - (message, reply) -> { - ArrayList wrapped = new ArrayList(); - ArrayList args = (ArrayList) message; - String nameArg = (String) args.get(0); - try { - String output = api.getAssetFilePathByName(nameArg); - wrapped.add(0, output); - } catch (Throwable exception) { - ArrayList wrappedError = wrapError(exception); - wrapped = wrappedError; - } - reply.reply(wrapped); - }); - } else { - channel.setMessageHandler(null); - } - } - } - } - - private static class WebChromeClientFlutterApiCodec extends StandardMessageCodec { - public static final WebChromeClientFlutterApiCodec INSTANCE = - new WebChromeClientFlutterApiCodec(); - - private WebChromeClientFlutterApiCodec() {} - - @Override - protected Object readValueOfType(byte type, @NonNull ByteBuffer buffer) { - switch (type) { - case (byte) 128: - return ConsoleMessage.fromList((ArrayList) readValue(buffer)); - default: - return super.readValueOfType(type, buffer); - } - } - - @Override - protected void writeValue(@NonNull ByteArrayOutputStream stream, Object value) { - if (value instanceof ConsoleMessage) { - stream.write(128); - writeValue(stream, ((ConsoleMessage) value).toList()); - } else { - super.writeValue(stream, value); - } - } - } - - /** Generated class from Pigeon that represents Flutter messages that can be called from Java. */ - public static class WebChromeClientFlutterApi { - private final @NonNull BinaryMessenger binaryMessenger; - - public WebChromeClientFlutterApi(@NonNull BinaryMessenger argBinaryMessenger) { - this.binaryMessenger = argBinaryMessenger; - } - - /** Public interface for sending reply. */ - @SuppressWarnings("UnknownNullness") - public interface Reply { - void reply(T reply); - } - /** The codec used by WebChromeClientFlutterApi. */ - static @NonNull MessageCodec getCodec() { - return WebChromeClientFlutterApiCodec.INSTANCE; - } - - public void onProgressChanged( - @NonNull Long instanceIdArg, - @NonNull Long webViewInstanceIdArg, - @NonNull Long progressArg, - @NonNull Reply callback) { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.webview_flutter_android.WebChromeClientFlutterApi.onProgressChanged", - getCodec()); - channel.send( - new ArrayList(Arrays.asList(instanceIdArg, webViewInstanceIdArg, progressArg)), - channelReply -> callback.reply(null)); - } - - public void onShowFileChooser( - @NonNull Long instanceIdArg, - @NonNull Long webViewInstanceIdArg, - @NonNull Long paramsInstanceIdArg, - @NonNull Reply> callback) { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.webview_flutter_android.WebChromeClientFlutterApi.onShowFileChooser", - getCodec()); - channel.send( - new ArrayList( - Arrays.asList(instanceIdArg, webViewInstanceIdArg, paramsInstanceIdArg)), - channelReply -> { - @SuppressWarnings("ConstantConditions") - List output = (List) channelReply; - callback.reply(output); - }); - } - /** Callback to Dart function `WebChromeClient.onPermissionRequest`. */ - public void onPermissionRequest( - @NonNull Long instanceIdArg, - @NonNull Long requestInstanceIdArg, - @NonNull Reply callback) { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.webview_flutter_android.WebChromeClientFlutterApi.onPermissionRequest", - getCodec()); - channel.send( - new ArrayList(Arrays.asList(instanceIdArg, requestInstanceIdArg)), - channelReply -> callback.reply(null)); - } - /** Callback to Dart function `WebChromeClient.onShowCustomView`. */ - public void onShowCustomView( - @NonNull Long instanceIdArg, - @NonNull Long viewIdentifierArg, - @NonNull Long callbackIdentifierArg, - @NonNull Reply callback) { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.webview_flutter_android.WebChromeClientFlutterApi.onShowCustomView", - getCodec()); - channel.send( - new ArrayList( - Arrays.asList(instanceIdArg, viewIdentifierArg, callbackIdentifierArg)), - channelReply -> callback.reply(null)); - } - /** Callback to Dart function `WebChromeClient.onHideCustomView`. */ - public void onHideCustomView(@NonNull Long instanceIdArg, @NonNull Reply callback) { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.webview_flutter_android.WebChromeClientFlutterApi.onHideCustomView", - getCodec()); - channel.send( - new ArrayList(Collections.singletonList(instanceIdArg)), - channelReply -> callback.reply(null)); - } - /** Callback to Dart function `WebChromeClient.onGeolocationPermissionsShowPrompt`. */ - public void onGeolocationPermissionsShowPrompt( - @NonNull Long instanceIdArg, - @NonNull Long paramsInstanceIdArg, - @NonNull String originArg, - @NonNull Reply callback) { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.webview_flutter_android.WebChromeClientFlutterApi.onGeolocationPermissionsShowPrompt", - getCodec()); - channel.send( - new ArrayList(Arrays.asList(instanceIdArg, paramsInstanceIdArg, originArg)), - channelReply -> callback.reply(null)); - } - /** Callback to Dart function `WebChromeClient.onGeolocationPermissionsHidePrompt`. */ - public void onGeolocationPermissionsHidePrompt( - @NonNull Long identifierArg, @NonNull Reply callback) { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.webview_flutter_android.WebChromeClientFlutterApi.onGeolocationPermissionsHidePrompt", - getCodec()); - channel.send( - new ArrayList(Collections.singletonList(identifierArg)), - channelReply -> callback.reply(null)); - } - /** Callback to Dart function `WebChromeClient.onConsoleMessage`. */ - public void onConsoleMessage( - @NonNull Long instanceIdArg, - @NonNull ConsoleMessage messageArg, - @NonNull Reply callback) { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.webview_flutter_android.WebChromeClientFlutterApi.onConsoleMessage", - getCodec()); - channel.send( - new ArrayList(Arrays.asList(instanceIdArg, messageArg)), - channelReply -> callback.reply(null)); - } - - public void onJsAlert( - @NonNull Long instanceIdArg, - @NonNull String urlArg, - @NonNull String messageArg, - @NonNull Reply callback) { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.webview_flutter_android.WebChromeClientFlutterApi.onJsAlert", - getCodec()); - channel.send( - new ArrayList(Arrays.asList(instanceIdArg, urlArg, messageArg)), - channelReply -> callback.reply(null)); - } - - public void onJsConfirm( - @NonNull Long instanceIdArg, - @NonNull String urlArg, - @NonNull String messageArg, - @NonNull Reply callback) { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.webview_flutter_android.WebChromeClientFlutterApi.onJsConfirm", - getCodec()); - channel.send( - new ArrayList(Arrays.asList(instanceIdArg, urlArg, messageArg)), - channelReply -> { - @SuppressWarnings("ConstantConditions") - Boolean output = (Boolean) channelReply; - callback.reply(output); - }); - } - - public void onJsPrompt( - @NonNull Long instanceIdArg, - @NonNull String urlArg, - @NonNull String messageArg, - @NonNull String defaultValueArg, - @NonNull Reply callback) { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.webview_flutter_android.WebChromeClientFlutterApi.onJsPrompt", - getCodec()); - channel.send( - new ArrayList(Arrays.asList(instanceIdArg, urlArg, messageArg, defaultValueArg)), - channelReply -> { - @SuppressWarnings("ConstantConditions") - String output = (String) channelReply; - callback.reply(output); - }); - } - } - /** Generated interface from Pigeon that represents a handler of messages from Flutter. */ - public interface WebStorageHostApi { - - void create(@NonNull Long instanceId); - - void deleteAllData(@NonNull Long instanceId); - - /** The codec used by WebStorageHostApi. */ - static @NonNull MessageCodec getCodec() { - return new StandardMessageCodec(); - } - /** - * Sets up an instance of `WebStorageHostApi` to handle messages through the `binaryMessenger`. - */ - static void setup(@NonNull BinaryMessenger binaryMessenger, @Nullable WebStorageHostApi api) { - { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.webview_flutter_android.WebStorageHostApi.create", - getCodec()); - if (api != null) { - channel.setMessageHandler( - (message, reply) -> { - ArrayList wrapped = new ArrayList(); - ArrayList args = (ArrayList) message; - Number instanceIdArg = (Number) args.get(0); - try { - api.create((instanceIdArg == null) ? null : instanceIdArg.longValue()); - wrapped.add(0, null); - } catch (Throwable exception) { - ArrayList wrappedError = wrapError(exception); - wrapped = wrappedError; - } - reply.reply(wrapped); - }); - } else { - channel.setMessageHandler(null); - } - } - { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.webview_flutter_android.WebStorageHostApi.deleteAllData", - getCodec()); - if (api != null) { - channel.setMessageHandler( - (message, reply) -> { - ArrayList wrapped = new ArrayList(); - ArrayList args = (ArrayList) message; - Number instanceIdArg = (Number) args.get(0); - try { - api.deleteAllData((instanceIdArg == null) ? null : instanceIdArg.longValue()); - wrapped.add(0, null); - } catch (Throwable exception) { - ArrayList wrappedError = wrapError(exception); - wrapped = wrappedError; - } - reply.reply(wrapped); - }); - } else { - channel.setMessageHandler(null); - } - } - } - } - /** - * Handles callbacks methods for the native Java FileChooserParams class. - * - *

See - * https://developer.android.com/reference/android/webkit/WebChromeClient.FileChooserParams. - * - *

Generated class from Pigeon that represents Flutter messages that can be called from Java. - */ - public static class FileChooserParamsFlutterApi { - private final @NonNull BinaryMessenger binaryMessenger; - - public FileChooserParamsFlutterApi(@NonNull BinaryMessenger argBinaryMessenger) { - this.binaryMessenger = argBinaryMessenger; - } - - /** Public interface for sending reply. */ - @SuppressWarnings("UnknownNullness") - public interface Reply { - void reply(T reply); - } - /** The codec used by FileChooserParamsFlutterApi. */ - static @NonNull MessageCodec getCodec() { - return new StandardMessageCodec(); - } - - public void create( - @NonNull Long instanceIdArg, - @NonNull Boolean isCaptureEnabledArg, - @NonNull List acceptTypesArg, - @NonNull FileChooserMode modeArg, - @Nullable String filenameHintArg, - @NonNull Reply callback) { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.webview_flutter_android.FileChooserParamsFlutterApi.create", - getCodec()); - channel.send( - new ArrayList( - Arrays.asList( - instanceIdArg, - isCaptureEnabledArg, - acceptTypesArg, - modeArg.index, - filenameHintArg)), - channelReply -> callback.reply(null)); - } - } - /** - * Host API for `PermissionRequest`. - * - *

This class may handle instantiating and adding native object instances that are attached to - * a Dart instance or handle method calls on the associated native class or an instance of the - * class. - * - *

See https://developer.android.com/reference/android/webkit/PermissionRequest. - * - *

Generated interface from Pigeon that represents a handler of messages from Flutter. - */ - public interface PermissionRequestHostApi { - /** Handles Dart method `PermissionRequest.grant`. */ - void grant(@NonNull Long instanceId, @NonNull List resources); - /** Handles Dart method `PermissionRequest.deny`. */ - void deny(@NonNull Long instanceId); - - /** The codec used by PermissionRequestHostApi. */ - static @NonNull MessageCodec getCodec() { - return new StandardMessageCodec(); - } - /** - * Sets up an instance of `PermissionRequestHostApi` to handle messages through the - * `binaryMessenger`. - */ - static void setup( - @NonNull BinaryMessenger binaryMessenger, @Nullable PermissionRequestHostApi api) { - { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.webview_flutter_android.PermissionRequestHostApi.grant", - getCodec()); - if (api != null) { - channel.setMessageHandler( - (message, reply) -> { - ArrayList wrapped = new ArrayList(); - ArrayList args = (ArrayList) message; - Number instanceIdArg = (Number) args.get(0); - List resourcesArg = (List) args.get(1); - try { - api.grant( - (instanceIdArg == null) ? null : instanceIdArg.longValue(), resourcesArg); - wrapped.add(0, null); - } catch (Throwable exception) { - ArrayList wrappedError = wrapError(exception); - wrapped = wrappedError; - } - reply.reply(wrapped); - }); - } else { - channel.setMessageHandler(null); - } - } - { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.webview_flutter_android.PermissionRequestHostApi.deny", - getCodec()); - if (api != null) { - channel.setMessageHandler( - (message, reply) -> { - ArrayList wrapped = new ArrayList(); - ArrayList args = (ArrayList) message; - Number instanceIdArg = (Number) args.get(0); - try { - api.deny((instanceIdArg == null) ? null : instanceIdArg.longValue()); - wrapped.add(0, null); - } catch (Throwable exception) { - ArrayList wrappedError = wrapError(exception); - wrapped = wrappedError; - } - reply.reply(wrapped); - }); - } else { - channel.setMessageHandler(null); - } - } - } - } - /** - * Flutter API for `PermissionRequest`. - * - *

This class may handle instantiating and adding Dart instances that are attached to a native - * instance or receiving callback methods from an overridden native class. - * - *

See https://developer.android.com/reference/android/webkit/PermissionRequest. - * - *

Generated class from Pigeon that represents Flutter messages that can be called from Java. - */ - public static class PermissionRequestFlutterApi { - private final @NonNull BinaryMessenger binaryMessenger; - - public PermissionRequestFlutterApi(@NonNull BinaryMessenger argBinaryMessenger) { - this.binaryMessenger = argBinaryMessenger; - } - - /** Public interface for sending reply. */ - @SuppressWarnings("UnknownNullness") - public interface Reply { - void reply(T reply); - } - /** The codec used by PermissionRequestFlutterApi. */ - static @NonNull MessageCodec getCodec() { - return new StandardMessageCodec(); - } - /** Create a new Dart instance and add it to the `InstanceManager`. */ - public void create( - @NonNull Long instanceIdArg, - @NonNull List resourcesArg, - @NonNull Reply callback) { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.webview_flutter_android.PermissionRequestFlutterApi.create", - getCodec()); - channel.send( - new ArrayList(Arrays.asList(instanceIdArg, resourcesArg)), - channelReply -> callback.reply(null)); - } - } - /** - * Host API for `CustomViewCallback`. - * - *

This class may handle instantiating and adding native object instances that are attached to - * a Dart instance or handle method calls on the associated native class or an instance of the - * class. - * - *

See - * https://developer.android.com/reference/android/webkit/WebChromeClient.CustomViewCallback. - * - *

Generated interface from Pigeon that represents a handler of messages from Flutter. - */ - public interface CustomViewCallbackHostApi { - /** Handles Dart method `CustomViewCallback.onCustomViewHidden`. */ - void onCustomViewHidden(@NonNull Long identifier); - - /** The codec used by CustomViewCallbackHostApi. */ - static @NonNull MessageCodec getCodec() { - return new StandardMessageCodec(); - } - /** - * Sets up an instance of `CustomViewCallbackHostApi` to handle messages through the - * `binaryMessenger`. - */ - static void setup( - @NonNull BinaryMessenger binaryMessenger, @Nullable CustomViewCallbackHostApi api) { - { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.webview_flutter_android.CustomViewCallbackHostApi.onCustomViewHidden", - getCodec()); - if (api != null) { - channel.setMessageHandler( - (message, reply) -> { - ArrayList wrapped = new ArrayList(); - ArrayList args = (ArrayList) message; - Number identifierArg = (Number) args.get(0); - try { - api.onCustomViewHidden( - (identifierArg == null) ? null : identifierArg.longValue()); - wrapped.add(0, null); - } catch (Throwable exception) { - ArrayList wrappedError = wrapError(exception); - wrapped = wrappedError; - } - reply.reply(wrapped); - }); - } else { - channel.setMessageHandler(null); - } - } - } - } - /** - * Flutter API for `CustomViewCallback`. - * - *

This class may handle instantiating and adding Dart instances that are attached to a native - * instance or receiving callback methods from an overridden native class. - * - *

See - * https://developer.android.com/reference/android/webkit/WebChromeClient.CustomViewCallback. - * - *

Generated class from Pigeon that represents Flutter messages that can be called from Java. - */ - public static class CustomViewCallbackFlutterApi { - private final @NonNull BinaryMessenger binaryMessenger; - - public CustomViewCallbackFlutterApi(@NonNull BinaryMessenger argBinaryMessenger) { - this.binaryMessenger = argBinaryMessenger; - } - - /** Public interface for sending reply. */ - @SuppressWarnings("UnknownNullness") - public interface Reply { - void reply(T reply); - } - /** The codec used by CustomViewCallbackFlutterApi. */ - static @NonNull MessageCodec getCodec() { - return new StandardMessageCodec(); - } - /** Create a new Dart instance and add it to the `InstanceManager`. */ - public void create(@NonNull Long identifierArg, @NonNull Reply callback) { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.webview_flutter_android.CustomViewCallbackFlutterApi.create", - getCodec()); - channel.send( - new ArrayList(Collections.singletonList(identifierArg)), - channelReply -> callback.reply(null)); - } - } - /** - * Flutter API for `View`. - * - *

This class may handle instantiating and adding Dart instances that are attached to a native - * instance or receiving callback methods from an overridden native class. - * - *

See https://developer.android.com/reference/android/view/View. - * - *

Generated class from Pigeon that represents Flutter messages that can be called from Java. - */ - public static class ViewFlutterApi { - private final @NonNull BinaryMessenger binaryMessenger; - - public ViewFlutterApi(@NonNull BinaryMessenger argBinaryMessenger) { - this.binaryMessenger = argBinaryMessenger; - } - - /** Public interface for sending reply. */ - @SuppressWarnings("UnknownNullness") - public interface Reply { - void reply(T reply); - } - /** The codec used by ViewFlutterApi. */ - static @NonNull MessageCodec getCodec() { - return new StandardMessageCodec(); - } - /** Create a new Dart instance and add it to the `InstanceManager`. */ - public void create(@NonNull Long identifierArg, @NonNull Reply callback) { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.webview_flutter_android.ViewFlutterApi.create", - getCodec()); - channel.send( - new ArrayList(Collections.singletonList(identifierArg)), - channelReply -> callback.reply(null)); - } - } - /** - * Host API for `GeolocationPermissionsCallback`. - * - *

This class may handle instantiating and adding native object instances that are attached to - * a Dart instance or handle method calls on the associated native class or an instance of the - * class. - * - *

See https://developer.android.com/reference/android/webkit/GeolocationPermissions.Callback. - * - *

Generated interface from Pigeon that represents a handler of messages from Flutter. - */ - public interface GeolocationPermissionsCallbackHostApi { - /** Handles Dart method `GeolocationPermissionsCallback.invoke`. */ - void invoke( - @NonNull Long instanceId, - @NonNull String origin, - @NonNull Boolean allow, - @NonNull Boolean retain); - - /** The codec used by GeolocationPermissionsCallbackHostApi. */ - static @NonNull MessageCodec getCodec() { - return new StandardMessageCodec(); - } - /** - * Sets up an instance of `GeolocationPermissionsCallbackHostApi` to handle messages through the - * `binaryMessenger`. - */ - static void setup( - @NonNull BinaryMessenger binaryMessenger, - @Nullable GeolocationPermissionsCallbackHostApi api) { - { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.webview_flutter_android.GeolocationPermissionsCallbackHostApi.invoke", - getCodec()); - if (api != null) { - channel.setMessageHandler( - (message, reply) -> { - ArrayList wrapped = new ArrayList(); - ArrayList args = (ArrayList) message; - Number instanceIdArg = (Number) args.get(0); - String originArg = (String) args.get(1); - Boolean allowArg = (Boolean) args.get(2); - Boolean retainArg = (Boolean) args.get(3); - try { - api.invoke( - (instanceIdArg == null) ? null : instanceIdArg.longValue(), - originArg, - allowArg, - retainArg); - wrapped.add(0, null); - } catch (Throwable exception) { - ArrayList wrappedError = wrapError(exception); - wrapped = wrappedError; - } - reply.reply(wrapped); - }); - } else { - channel.setMessageHandler(null); - } - } - } - } - /** - * Flutter API for `GeolocationPermissionsCallback`. - * - *

This class may handle instantiating and adding Dart instances that are attached to a native - * instance or receiving callback methods from an overridden native class. - * - *

See https://developer.android.com/reference/android/webkit/GeolocationPermissions.Callback. - * - *

Generated class from Pigeon that represents Flutter messages that can be called from Java. - */ - public static class GeolocationPermissionsCallbackFlutterApi { - private final @NonNull BinaryMessenger binaryMessenger; - - public GeolocationPermissionsCallbackFlutterApi(@NonNull BinaryMessenger argBinaryMessenger) { - this.binaryMessenger = argBinaryMessenger; - } - - /** Public interface for sending reply. */ - @SuppressWarnings("UnknownNullness") - public interface Reply { - void reply(T reply); - } - /** The codec used by GeolocationPermissionsCallbackFlutterApi. */ - static @NonNull MessageCodec getCodec() { - return new StandardMessageCodec(); - } - /** Create a new Dart instance and add it to the `InstanceManager`. */ - public void create(@NonNull Long instanceIdArg, @NonNull Reply callback) { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.webview_flutter_android.GeolocationPermissionsCallbackFlutterApi.create", - getCodec()); - channel.send( - new ArrayList(Collections.singletonList(instanceIdArg)), - channelReply -> callback.reply(null)); - } - } - /** - * Host API for `HttpAuthHandler`. - * - *

This class may handle instantiating and adding native object instances that are attached to - * a Dart instance or handle method calls on the associated native class or an instance of the - * class. - * - *

See https://developer.android.com/reference/android/webkit/HttpAuthHandler. - * - *

Generated interface from Pigeon that represents a handler of messages from Flutter. - */ - public interface HttpAuthHandlerHostApi { - /** Handles Dart method `HttpAuthHandler.useHttpAuthUsernamePassword`. */ - @NonNull - Boolean useHttpAuthUsernamePassword(@NonNull Long instanceId); - /** Handles Dart method `HttpAuthHandler.cancel`. */ - void cancel(@NonNull Long instanceId); - /** Handles Dart method `HttpAuthHandler.proceed`. */ - void proceed(@NonNull Long instanceId, @NonNull String username, @NonNull String password); - - /** The codec used by HttpAuthHandlerHostApi. */ - static @NonNull MessageCodec getCodec() { - return new StandardMessageCodec(); - } - /** - * Sets up an instance of `HttpAuthHandlerHostApi` to handle messages through the - * `binaryMessenger`. - */ - static void setup( - @NonNull BinaryMessenger binaryMessenger, @Nullable HttpAuthHandlerHostApi api) { - { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.webview_flutter_android.HttpAuthHandlerHostApi.useHttpAuthUsernamePassword", - getCodec()); - if (api != null) { - channel.setMessageHandler( - (message, reply) -> { - ArrayList wrapped = new ArrayList(); - ArrayList args = (ArrayList) message; - Number instanceIdArg = (Number) args.get(0); - try { - Boolean output = - api.useHttpAuthUsernamePassword( - (instanceIdArg == null) ? null : instanceIdArg.longValue()); - wrapped.add(0, output); - } catch (Throwable exception) { - ArrayList wrappedError = wrapError(exception); - wrapped = wrappedError; - } - reply.reply(wrapped); - }); - } else { - channel.setMessageHandler(null); - } - } - { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.webview_flutter_android.HttpAuthHandlerHostApi.cancel", - getCodec()); - if (api != null) { - channel.setMessageHandler( - (message, reply) -> { - ArrayList wrapped = new ArrayList(); - ArrayList args = (ArrayList) message; - Number instanceIdArg = (Number) args.get(0); - try { - api.cancel((instanceIdArg == null) ? null : instanceIdArg.longValue()); - wrapped.add(0, null); - } catch (Throwable exception) { - ArrayList wrappedError = wrapError(exception); - wrapped = wrappedError; - } - reply.reply(wrapped); - }); - } else { - channel.setMessageHandler(null); - } - } - { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.webview_flutter_android.HttpAuthHandlerHostApi.proceed", - getCodec()); - if (api != null) { - channel.setMessageHandler( - (message, reply) -> { - ArrayList wrapped = new ArrayList(); - ArrayList args = (ArrayList) message; - Number instanceIdArg = (Number) args.get(0); - String usernameArg = (String) args.get(1); - String passwordArg = (String) args.get(2); - try { - api.proceed( - (instanceIdArg == null) ? null : instanceIdArg.longValue(), - usernameArg, - passwordArg); - wrapped.add(0, null); - } catch (Throwable exception) { - ArrayList wrappedError = wrapError(exception); - wrapped = wrappedError; - } - reply.reply(wrapped); - }); - } else { - channel.setMessageHandler(null); - } - } - } - } - /** - * Flutter API for `HttpAuthHandler`. - * - *

This class may handle instantiating and adding Dart instances that are attached to a native - * instance or receiving callback methods from an overridden native class. - * - *

See https://developer.android.com/reference/android/webkit/HttpAuthHandler. - * - *

Generated class from Pigeon that represents Flutter messages that can be called from Java. - */ - public static class HttpAuthHandlerFlutterApi { - private final @NonNull BinaryMessenger binaryMessenger; - - public HttpAuthHandlerFlutterApi(@NonNull BinaryMessenger argBinaryMessenger) { - this.binaryMessenger = argBinaryMessenger; - } - - /** Public interface for sending reply. */ - @SuppressWarnings("UnknownNullness") - public interface Reply { - void reply(T reply); - } - /** The codec used by HttpAuthHandlerFlutterApi. */ - static @NonNull MessageCodec getCodec() { - return new StandardMessageCodec(); - } - /** Create a new Dart instance and add it to the `InstanceManager`. */ - public void create(@NonNull Long instanceIdArg, @NonNull Reply callback) { - BasicMessageChannel channel = - new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.webview_flutter_android.HttpAuthHandlerFlutterApi.create", - getCodec()); - channel.send( - new ArrayList(Collections.singletonList(instanceIdArg)), - channelReply -> callback.reply(null)); - } - } -} diff --git a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/GeolocationPermissionsCallbackFlutterApiImpl.java b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/GeolocationPermissionsCallbackFlutterApiImpl.java deleted file mode 100644 index 32c66c0d9f31..000000000000 --- a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/GeolocationPermissionsCallbackFlutterApiImpl.java +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -package io.flutter.plugins.webviewflutter; - -import android.webkit.GeolocationPermissions; -import androidx.annotation.NonNull; -import androidx.annotation.VisibleForTesting; -import io.flutter.plugin.common.BinaryMessenger; -import io.flutter.plugins.webviewflutter.GeneratedAndroidWebView.GeolocationPermissionsCallbackFlutterApi; - -/** - * Flutter API implementation for `GeolocationPermissionsCallback`. - * - *

This class may handle adding native instances that are attached to a Dart instance or passing - * arguments of callbacks methods to a Dart instance. - */ -public class GeolocationPermissionsCallbackFlutterApiImpl { - // To ease adding additional methods, this value is added prematurely. - @SuppressWarnings({"unused", "FieldCanBeLocal"}) - private final BinaryMessenger binaryMessenger; - - private final InstanceManager instanceManager; - private GeolocationPermissionsCallbackFlutterApi api; - - /** - * Constructs a {@link GeolocationPermissionsCallbackFlutterApiImpl}. - * - * @param binaryMessenger used to communicate with Dart over asynchronous messages - * @param instanceManager maintains instances stored to communicate with attached Dart objects - */ - public GeolocationPermissionsCallbackFlutterApiImpl( - @NonNull BinaryMessenger binaryMessenger, @NonNull InstanceManager instanceManager) { - this.binaryMessenger = binaryMessenger; - this.instanceManager = instanceManager; - api = new GeolocationPermissionsCallbackFlutterApi(binaryMessenger); - } - - /** - * Stores the `GeolocationPermissionsCallback` instance and notifies Dart to create and store a - * new `GeolocationPermissionsCallback` instance that is attached to this one. If `instance` has - * already been added, this method does nothing. - */ - public void create( - @NonNull GeolocationPermissions.Callback instance, - @NonNull GeolocationPermissionsCallbackFlutterApi.Reply callback) { - if (!instanceManager.containsInstance(instance)) { - api.create(instanceManager.addHostCreatedInstance(instance), callback); - } - } - - /** - * Sets the Flutter API used to send messages to Dart. - * - *

This is only visible for testing. - */ - @VisibleForTesting - void setApi(@NonNull GeolocationPermissionsCallbackFlutterApi api) { - this.api = api; - } -} diff --git a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/GeolocationPermissionsCallbackHostApiImpl.java b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/GeolocationPermissionsCallbackHostApiImpl.java deleted file mode 100644 index 58981b6e3703..000000000000 --- a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/GeolocationPermissionsCallbackHostApiImpl.java +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -package io.flutter.plugins.webviewflutter; - -import android.webkit.GeolocationPermissions; -import androidx.annotation.NonNull; -import io.flutter.plugin.common.BinaryMessenger; -import io.flutter.plugins.webviewflutter.GeneratedAndroidWebView.GeolocationPermissionsCallbackHostApi; -import java.util.Objects; - -/** - * Host API implementation for `GeolocationPermissionsCallback`. - * - *

This class may handle instantiating and adding native object instances that are attached to a - * Dart instance or handle method calls on the associated native class or an instance of the class. - */ -public class GeolocationPermissionsCallbackHostApiImpl - implements GeolocationPermissionsCallbackHostApi { - // To ease adding additional methods, this value is added prematurely. - @SuppressWarnings({"unused", "FieldCanBeLocal"}) - private final BinaryMessenger binaryMessenger; - - private final InstanceManager instanceManager; - - /** - * Constructs a {@link GeolocationPermissionsCallbackHostApiImpl}. - * - * @param binaryMessenger used to communicate with Dart over asynchronous messages - * @param instanceManager maintains instances stored to communicate with attached Dart objects - */ - public GeolocationPermissionsCallbackHostApiImpl( - @NonNull BinaryMessenger binaryMessenger, @NonNull InstanceManager instanceManager) { - this.binaryMessenger = binaryMessenger; - this.instanceManager = instanceManager; - } - - @Override - public void invoke( - @NonNull Long instanceId, - @NonNull String origin, - @NonNull Boolean allow, - @NonNull Boolean retain) { - getGeolocationPermissionsCallbackInstance(instanceId).invoke(origin, allow, retain); - } - - private GeolocationPermissions.Callback getGeolocationPermissionsCallbackInstance( - @NonNull Long identifier) { - return Objects.requireNonNull(instanceManager.getInstance(identifier)); - } -} diff --git a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/GeolocationPermissionsCallbackProxyApi.java b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/GeolocationPermissionsCallbackProxyApi.java new file mode 100644 index 000000000000..c19fd39df571 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/GeolocationPermissionsCallbackProxyApi.java @@ -0,0 +1,31 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +package io.flutter.plugins.webviewflutter; + +import android.webkit.GeolocationPermissions; +import androidx.annotation.NonNull; + +/** + * Host API implementation for `GeolocationPermissionsCallback`. + * + *

This class may handle instantiating and adding native object instances that are attached to a + * Dart instance or handle method calls on the associated native class or an instance of the class. + */ +public class GeolocationPermissionsCallbackProxyApi + extends PigeonApiGeolocationPermissionsCallback { + /** Constructs a {@link GeolocationPermissionsCallbackProxyApi}. */ + public GeolocationPermissionsCallbackProxyApi(@NonNull ProxyApiRegistrar pigeonRegistrar) { + super(pigeonRegistrar); + } + + @Override + public void invoke( + @NonNull GeolocationPermissions.Callback pigeon_instance, + @NonNull String origin, + boolean allow, + boolean retain) { + pigeon_instance.invoke(origin, allow, retain); + } +} diff --git a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/HttpAuthHandlerFlutterApiImpl.java b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/HttpAuthHandlerFlutterApiImpl.java deleted file mode 100644 index 1d5a170ff3b2..000000000000 --- a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/HttpAuthHandlerFlutterApiImpl.java +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -package io.flutter.plugins.webviewflutter; - -import android.webkit.HttpAuthHandler; -import androidx.annotation.NonNull; -import io.flutter.plugin.common.BinaryMessenger; -import io.flutter.plugins.webviewflutter.GeneratedAndroidWebView.HttpAuthHandlerFlutterApi; - -/** - * Flutter API implementation for {@link HttpAuthHandler}. - * - *

This class may handle adding native instances that are attached to a Dart instance or passing - * arguments of callbacks methods to a Dart instance. - */ -public class HttpAuthHandlerFlutterApiImpl { - // To ease adding additional methods, this value is added prematurely. - @SuppressWarnings({"unused", "FieldCanBeLocal"}) - private final BinaryMessenger binaryMessenger; - - private final InstanceManager instanceManager; - - private final HttpAuthHandlerFlutterApi api; - - /** - * Constructs a {@link HttpAuthHandlerFlutterApiImpl}. - * - * @param binaryMessenger used to communicate with Dart over asynchronous messages - * @param instanceManager maintains instances stored to communicate with attached Dart objects - */ - public HttpAuthHandlerFlutterApiImpl( - @NonNull BinaryMessenger binaryMessenger, @NonNull InstanceManager instanceManager) { - this.binaryMessenger = binaryMessenger; - this.instanceManager = instanceManager; - api = new HttpAuthHandlerFlutterApi(binaryMessenger); - } - - /** - * Stores the `HttpAuthHandler` instance and notifies Dart to create and store a new - * `HttpAuthHandler` instance that is attached to this one. If `instance` has already been added, - * this method does nothing. - */ - public void create( - @NonNull HttpAuthHandler instance, @NonNull HttpAuthHandlerFlutterApi.Reply callback) { - if (!instanceManager.containsInstance(instance)) { - api.create(instanceManager.addHostCreatedInstance(instance), callback); - } - } -} diff --git a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/HttpAuthHandlerHostApiImpl.java b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/HttpAuthHandlerHostApiImpl.java deleted file mode 100644 index 591571d2a6cc..000000000000 --- a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/HttpAuthHandlerHostApiImpl.java +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -package io.flutter.plugins.webviewflutter; - -import android.webkit.HttpAuthHandler; -import androidx.annotation.NonNull; -import io.flutter.plugin.common.BinaryMessenger; -import io.flutter.plugins.webviewflutter.GeneratedAndroidWebView.HttpAuthHandlerHostApi; -import java.util.Objects; - -/** - * Host api implementation for {@link HttpAuthHandler}. - * - *

Handles creating {@link HttpAuthHandler}s that intercommunicate with a paired Dart object. - */ -public class HttpAuthHandlerHostApiImpl implements HttpAuthHandlerHostApi { - // To ease adding additional methods, this value is added prematurely. - @SuppressWarnings({"unused", "FieldCanBeLocal"}) - private final BinaryMessenger binaryMessenger; - - private final InstanceManager instanceManager; - - /** - * Constructs a {@link HttpAuthHandlerHostApiImpl}. - * - * @param binaryMessenger used to communicate with Dart over asynchronous messages - * @param instanceManager maintains instances stored to communicate with attached Dart objects - */ - public HttpAuthHandlerHostApiImpl( - @NonNull BinaryMessenger binaryMessenger, @NonNull InstanceManager instanceManager) { - this.binaryMessenger = binaryMessenger; - this.instanceManager = instanceManager; - } - - @NonNull - @Override - public Boolean useHttpAuthUsernamePassword(@NonNull Long instanceId) { - return getHttpAuthHandlerInstance(instanceId).useHttpAuthUsernamePassword(); - } - - @Override - public void cancel(@NonNull Long instanceId) { - getHttpAuthHandlerInstance(instanceId).cancel(); - } - - @Override - public void proceed( - @NonNull Long instanceId, @NonNull String username, @NonNull String password) { - getHttpAuthHandlerInstance(instanceId).proceed(username, password); - } - - private HttpAuthHandler getHttpAuthHandlerInstance(@NonNull Long instanceId) { - return Objects.requireNonNull(instanceManager.getInstance(instanceId)); - } -} diff --git a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/HttpAuthHandlerProxyApi.java b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/HttpAuthHandlerProxyApi.java new file mode 100644 index 000000000000..7a9e7b0b1236 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/HttpAuthHandlerProxyApi.java @@ -0,0 +1,38 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +package io.flutter.plugins.webviewflutter; + +import android.webkit.HttpAuthHandler; +import androidx.annotation.NonNull; + +/** + * Host api implementation for {@link HttpAuthHandler}. + * + *

Handles creating {@link HttpAuthHandler}s that intercommunicate with a paired Dart object. + */ +public class HttpAuthHandlerProxyApi extends PigeonApiHttpAuthHandler { + /** Constructs a {@link HttpAuthHandlerProxyApi}. */ + public HttpAuthHandlerProxyApi(@NonNull ProxyApiRegistrar pigeonRegistrar) { + super(pigeonRegistrar); + } + + @Override + public boolean useHttpAuthUsernamePassword(@NonNull HttpAuthHandler pigeon_instance) { + return pigeon_instance.useHttpAuthUsernamePassword(); + } + + @Override + public void cancel(@NonNull HttpAuthHandler pigeon_instance) { + pigeon_instance.cancel(); + } + + @Override + public void proceed( + @NonNull HttpAuthHandler pigeon_instance, + @NonNull String username, + @NonNull String password) { + pigeon_instance.proceed(username, password); + } +} diff --git a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/InstanceManager.java b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/InstanceManager.java deleted file mode 100644 index 44b47ef5fd6a..000000000000 --- a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/InstanceManager.java +++ /dev/null @@ -1,258 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -package io.flutter.plugins.webviewflutter; - -import android.os.Handler; -import android.os.Looper; -import android.util.Log; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import java.lang.ref.ReferenceQueue; -import java.lang.ref.WeakReference; -import java.util.HashMap; -import java.util.WeakHashMap; - -/** - * Maintains instances used to communicate with the corresponding objects in Dart. - * - *

Objects stored in this container are represented by an object in Dart that is also stored in - * an InstanceManager with the same identifier. - * - *

When an instance is added with an identifier, either can be used to retrieve the other. - * - *

Added instances are added as a weak reference and a strong reference. When the strong - * reference is removed with `{@link #remove(long)}` and the weak reference is deallocated, the - * `finalizationListener` is made with the instance's identifier. However, if the strong reference - * is removed and then the identifier is retrieved with the intention to pass the identifier to Dart - * (e.g. calling {@link #getIdentifierForStrongReference(Object)}), the strong reference to the - * instance is recreated. The strong reference will then need to be removed manually again. - */ -@SuppressWarnings("unchecked") -public class InstanceManager { - // Identifiers are locked to a specific range to avoid collisions with objects - // created simultaneously from Dart. - // Host uses identifiers >= 2^16 and Dart is expected to use values n where, - // 0 <= n < 2^16. - private static final long MIN_HOST_CREATED_IDENTIFIER = 65536; - private static final long CLEAR_FINALIZED_WEAK_REFERENCES_INTERVAL = 3000; - private static final String TAG = "InstanceManager"; - - /** Interface for listening when a weak reference of an instance is removed from the manager. */ - public interface FinalizationListener { - void onFinalize(long identifier); - } - - private final WeakHashMap identifiers = new WeakHashMap<>(); - private final HashMap> weakInstances = new HashMap<>(); - private final HashMap strongInstances = new HashMap<>(); - - private final ReferenceQueue referenceQueue = new ReferenceQueue<>(); - private final HashMap, Long> weakReferencesToIdentifiers = new HashMap<>(); - - private final Handler handler = new Handler(Looper.getMainLooper()); - - private final FinalizationListener finalizationListener; - - private long nextIdentifier = MIN_HOST_CREATED_IDENTIFIER; - private boolean hasFinalizationListenerStopped = false; - - /** - * Instantiate a new manager. - * - *

When the manager is no longer needed, {@link #stopFinalizationListener()} must be called. - * - * @param finalizationListener the listener for garbage collected weak references. - * @return a new `InstanceManager`. - */ - @NonNull - public static InstanceManager create(@NonNull FinalizationListener finalizationListener) { - return new InstanceManager(finalizationListener); - } - - private InstanceManager(FinalizationListener finalizationListener) { - this.finalizationListener = finalizationListener; - handler.postDelayed( - this::releaseAllFinalizedInstances, CLEAR_FINALIZED_WEAK_REFERENCES_INTERVAL); - } - - /** - * Removes `identifier` and its associated strongly referenced instance, if present, from the - * manager. - * - * @param identifier the identifier paired to an instance. - * @param the expected return type. - * @return the removed instance if the manager contains the given identifier, otherwise `null` if - * the manager doesn't contain the value. - */ - @Nullable - public T remove(long identifier) { - logWarningIfFinalizationListenerHasStopped(); - return (T) strongInstances.remove(identifier); - } - - /** - * Retrieves the identifier paired with an instance. - * - *

If the manager contains a strong reference to `instance`, it will return the identifier - * associated with `instance`. If the manager contains only a weak reference to `instance`, a new - * strong reference to `instance` will be added and will need to be removed again with {@link - * #remove(long)}. - * - *

If this method returns a nonnull identifier, this method also expects the Dart - * `InstanceManager` to have, or recreate, a weak reference to the Dart instance the identifier is - * associated with. - * - * @param instance an instance that may be stored in the manager. - * @return the identifier associated with `instance` if the manager contains the value, otherwise - * `null` if the manager doesn't contain the value. - */ - @Nullable - public Long getIdentifierForStrongReference(@Nullable Object instance) { - logWarningIfFinalizationListenerHasStopped(); - - final Long identifier = identifiers.get(instance); - if (identifier != null) { - strongInstances.put(identifier, instance); - } - return identifier; - } - - /** - * Adds a new instance that was instantiated from Dart. - * - *

The same instance can be added multiple times, but each identifier must be unique. This - * allows two objects that are equivalent (e.g. the `equals` method returns true and their - * hashcodes are equal) to both be added. - * - * @param instance the instance to be stored. - * @param identifier the identifier to be paired with instance. This value must be >= 0 and - * unique. - */ - public void addDartCreatedInstance(@NonNull Object instance, long identifier) { - logWarningIfFinalizationListenerHasStopped(); - addInstance(instance, identifier); - } - - /** - * Adds a new instance that was instantiated from the host platform. - * - * @param instance the instance to be stored. This must be unique to all other added instances. - * @return the unique identifier (>= 0) stored with instance. - */ - public long addHostCreatedInstance(@NonNull Object instance) { - logWarningIfFinalizationListenerHasStopped(); - - if (containsInstance(instance)) { - throw new IllegalArgumentException( - "Instance of " + instance.getClass() + " has already been added."); - } - final long identifier = nextIdentifier++; - addInstance(instance, identifier); - return identifier; - } - - /** - * Retrieves the instance associated with identifier. - * - * @param identifier the identifier associated with an instance. - * @param the expected return type. - * @return the instance associated with `identifier` if the manager contains the value, otherwise - * `null` if the manager doesn't contain the value. - */ - @Nullable - public T getInstance(long identifier) { - logWarningIfFinalizationListenerHasStopped(); - - final WeakReference instance = (WeakReference) weakInstances.get(identifier); - if (instance != null) { - return instance.get(); - } - return null; - } - - /** - * Returns whether this manager contains the given `instance`. - * - * @param instance the instance whose presence in this manager is to be tested. - * @return whether this manager contains the given `instance`. - */ - public boolean containsInstance(@Nullable Object instance) { - logWarningIfFinalizationListenerHasStopped(); - return identifiers.containsKey(instance); - } - - /** - * Stop the periodic run of the {@link FinalizationListener} for instances that have been garbage - * collected. - * - *

The InstanceManager can continue to be used, but the {@link FinalizationListener} will no - * longer be called and methods will log a warning. - */ - public void stopFinalizationListener() { - handler.removeCallbacks(this::releaseAllFinalizedInstances); - hasFinalizationListenerStopped = true; - } - - /** - * Removes all of the instances from this manager. - * - *

The manager will be empty after this call returns. - */ - public void clear() { - identifiers.clear(); - weakInstances.clear(); - strongInstances.clear(); - weakReferencesToIdentifiers.clear(); - } - - /** - * Whether the {@link FinalizationListener} is still being called for instances that are garbage - * collected. - * - *

See {@link #stopFinalizationListener()}. - */ - public boolean hasFinalizationListenerStopped() { - return hasFinalizationListenerStopped; - } - - private void releaseAllFinalizedInstances() { - if (hasFinalizationListenerStopped()) { - return; - } - - WeakReference reference; - while ((reference = (WeakReference) referenceQueue.poll()) != null) { - final Long identifier = weakReferencesToIdentifiers.remove(reference); - if (identifier != null) { - weakInstances.remove(identifier); - strongInstances.remove(identifier); - finalizationListener.onFinalize(identifier); - } - } - handler.postDelayed( - this::releaseAllFinalizedInstances, CLEAR_FINALIZED_WEAK_REFERENCES_INTERVAL); - } - - private void addInstance(Object instance, long identifier) { - if (identifier < 0) { - throw new IllegalArgumentException(String.format("Identifier must be >= 0: %d", identifier)); - } - if (weakInstances.containsKey(identifier)) { - throw new IllegalArgumentException( - String.format("Identifier has already been added: %d", identifier)); - } - final WeakReference weakReference = new WeakReference<>(instance, referenceQueue); - identifiers.put(instance, identifier); - weakInstances.put(identifier, weakReference); - weakReferencesToIdentifiers.put(weakReference, identifier); - strongInstances.put(identifier, instance); - } - - private void logWarningIfFinalizationListenerHasStopped() { - if (hasFinalizationListenerStopped()) { - Log.w(TAG, "The manager was used after calls to the FinalizationListener have been stopped."); - } - } -} diff --git a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/JavaObjectHostApiImpl.java b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/JavaObjectHostApiImpl.java deleted file mode 100644 index a10cd77852d0..000000000000 --- a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/JavaObjectHostApiImpl.java +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -package io.flutter.plugins.webviewflutter; - -import androidx.annotation.NonNull; - -/** - * A pigeon Host API implementation that handles creating {@link Object}s and invoking its static - * and instance methods. - * - *

{@link Object} instances created by {@link JavaObjectHostApiImpl} are used to intercommunicate - * with a paired Dart object. - */ -public class JavaObjectHostApiImpl implements GeneratedAndroidWebView.JavaObjectHostApi { - private final InstanceManager instanceManager; - - /** - * Constructs a {@link JavaObjectHostApiImpl}. - * - * @param instanceManager maintains instances stored to communicate with Dart objects - */ - public JavaObjectHostApiImpl(@NonNull InstanceManager instanceManager) { - this.instanceManager = instanceManager; - } - - @Override - public void dispose(@NonNull Long identifier) { - final Object instance = instanceManager.getInstance(identifier); - if (instance instanceof WebViewHostApiImpl.WebViewPlatformView) { - ((WebViewHostApiImpl.WebViewPlatformView) instance).destroy(); - } - instanceManager.remove(identifier); - } -} diff --git a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/JavaScriptChannel.java b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/JavaScriptChannel.java index 09dbfc9ab5dd..954a80584448 100644 --- a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/JavaScriptChannel.java +++ b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/JavaScriptChannel.java @@ -4,8 +4,6 @@ package io.flutter.plugins.webviewflutter; -import android.os.Handler; -import android.os.Looper; import android.webkit.JavascriptInterface; import androidx.annotation.NonNull; @@ -17,37 +15,23 @@ * code. */ public class JavaScriptChannel { - private final Handler platformThreadHandler; final String javaScriptChannelName; - private final JavaScriptChannelFlutterApiImpl flutterApi; + private final JavaScriptChannelProxyApi api; - /** - * Creates a {@link JavaScriptChannel} that passes arguments of callback methods to Dart. - * - * @param flutterApi the Flutter Api to which JS messages are sent - * @param channelName JavaScript channel the message was sent through - * @param platformThreadHandler handles making callbacks on the desired thread - */ - public JavaScriptChannel( - @NonNull JavaScriptChannelFlutterApiImpl flutterApi, - @NonNull String channelName, - @NonNull Handler platformThreadHandler) { - this.flutterApi = flutterApi; + /** Creates a {@link JavaScriptChannel} that passes arguments of callback methods to Dart. */ + public JavaScriptChannel(@NonNull String channelName, @NonNull JavaScriptChannelProxyApi api) { this.javaScriptChannelName = channelName; - this.platformThreadHandler = platformThreadHandler; + this.api = api; } // Suppressing unused warning as this is invoked from JavaScript. @SuppressWarnings("unused") @JavascriptInterface public void postMessage(@NonNull final String message) { - final Runnable postMessageRunnable = - () -> flutterApi.postMessage(JavaScriptChannel.this, message, reply -> {}); - - if (platformThreadHandler.getLooper() == Looper.myLooper()) { - postMessageRunnable.run(); - } else { - platformThreadHandler.post(postMessageRunnable); - } + api.getPigeonRegistrar() + .runOnMainThread( + () -> { + api.postMessage(JavaScriptChannel.this, message, reply -> null); + }); } } diff --git a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/JavaScriptChannelFlutterApiImpl.java b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/JavaScriptChannelFlutterApiImpl.java deleted file mode 100644 index cd78f19a9349..000000000000 --- a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/JavaScriptChannelFlutterApiImpl.java +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -package io.flutter.plugins.webviewflutter; - -import androidx.annotation.NonNull; -import io.flutter.plugin.common.BinaryMessenger; -import io.flutter.plugins.webviewflutter.GeneratedAndroidWebView.JavaScriptChannelFlutterApi; - -/** - * Flutter Api implementation for {@link JavaScriptChannel}. - * - *

Passes arguments of callbacks methods from a {@link JavaScriptChannel} to Dart. - */ -public class JavaScriptChannelFlutterApiImpl extends JavaScriptChannelFlutterApi { - private final InstanceManager instanceManager; - - /** - * Creates a Flutter api that sends messages to Dart. - * - * @param binaryMessenger Handles sending messages to Dart. - * @param instanceManager Maintains instances stored to communicate with Dart objects. - */ - public JavaScriptChannelFlutterApiImpl( - @NonNull BinaryMessenger binaryMessenger, @NonNull InstanceManager instanceManager) { - super(binaryMessenger); - this.instanceManager = instanceManager; - } - - /** Passes arguments from {@link JavaScriptChannel#postMessage} to Dart. */ - public void postMessage( - @NonNull JavaScriptChannel javaScriptChannel, - @NonNull String messageArg, - @NonNull Reply callback) { - super.postMessage(getIdentifierForJavaScriptChannel(javaScriptChannel), messageArg, callback); - } - - private long getIdentifierForJavaScriptChannel(JavaScriptChannel javaScriptChannel) { - final Long identifier = instanceManager.getIdentifierForStrongReference(javaScriptChannel); - if (identifier == null) { - throw new IllegalStateException("Could not find identifier for JavaScriptChannel."); - } - return identifier; - } -} diff --git a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/JavaScriptChannelHostApiImpl.java b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/JavaScriptChannelHostApiImpl.java deleted file mode 100644 index d4509338c787..000000000000 --- a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/JavaScriptChannelHostApiImpl.java +++ /dev/null @@ -1,77 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -package io.flutter.plugins.webviewflutter; - -import android.os.Handler; -import androidx.annotation.NonNull; -import io.flutter.plugins.webviewflutter.GeneratedAndroidWebView.JavaScriptChannelHostApi; - -/** - * Host api implementation for {@link JavaScriptChannel}. - * - *

Handles creating {@link JavaScriptChannel}s that intercommunicate with a paired Dart object. - */ -public class JavaScriptChannelHostApiImpl implements JavaScriptChannelHostApi { - private final InstanceManager instanceManager; - private final JavaScriptChannelCreator javaScriptChannelCreator; - private final JavaScriptChannelFlutterApiImpl flutterApi; - - private Handler platformThreadHandler; - - /** Handles creating {@link JavaScriptChannel}s for a {@link JavaScriptChannelHostApiImpl}. */ - public static class JavaScriptChannelCreator { - /** - * Creates a {@link JavaScriptChannel}. - * - * @param flutterApi handles sending messages to Dart - * @param channelName JavaScript channel the message should be sent through - * @param platformThreadHandler handles making callbacks on the desired thread - * @return the created {@link JavaScriptChannel} - */ - @NonNull - public JavaScriptChannel createJavaScriptChannel( - @NonNull JavaScriptChannelFlutterApiImpl flutterApi, - @NonNull String channelName, - @NonNull Handler platformThreadHandler) { - return new JavaScriptChannel(flutterApi, channelName, platformThreadHandler); - } - } - - /** - * Creates a host API that handles creating {@link JavaScriptChannel}s. - * - * @param instanceManager maintains instances stored to communicate with Dart objects - * @param javaScriptChannelCreator handles creating {@link JavaScriptChannel}s - * @param flutterApi handles sending messages to Dart - * @param platformThreadHandler handles making callbacks on the desired thread - */ - public JavaScriptChannelHostApiImpl( - @NonNull InstanceManager instanceManager, - @NonNull JavaScriptChannelCreator javaScriptChannelCreator, - @NonNull JavaScriptChannelFlutterApiImpl flutterApi, - @NonNull Handler platformThreadHandler) { - this.instanceManager = instanceManager; - this.javaScriptChannelCreator = javaScriptChannelCreator; - this.flutterApi = flutterApi; - this.platformThreadHandler = platformThreadHandler; - } - - /** - * Sets the platformThreadHandler to make callbacks - * - * @param platformThreadHandler the new thread handler - */ - public void setPlatformThreadHandler(@NonNull Handler platformThreadHandler) { - this.platformThreadHandler = platformThreadHandler; - } - - @Override - public void create(@NonNull Long instanceId, @NonNull String channelName) { - final JavaScriptChannel javaScriptChannel = - javaScriptChannelCreator.createJavaScriptChannel( - flutterApi, channelName, platformThreadHandler); - instanceManager.addDartCreatedInstance(javaScriptChannel, instanceId); - } -} diff --git a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/JavaScriptChannelProxyApi.java b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/JavaScriptChannelProxyApi.java new file mode 100644 index 000000000000..91486310a2cf --- /dev/null +++ b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/JavaScriptChannelProxyApi.java @@ -0,0 +1,32 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +package io.flutter.plugins.webviewflutter; + +import androidx.annotation.NonNull; + +/** + * Host api implementation for {@link JavaScriptChannel}. + * + *

Handles creating {@link JavaScriptChannel}s that intercommunicate with a paired Dart object. + */ +public class JavaScriptChannelProxyApi extends PigeonApiJavaScriptChannel { + + /** Creates a host API that handles creating {@link JavaScriptChannel}s. */ + public JavaScriptChannelProxyApi(@NonNull ProxyApiRegistrar pigeonRegistrar) { + super(pigeonRegistrar); + } + + @NonNull + @Override + public JavaScriptChannel pigeon_defaultConstructor(@NonNull String channelName) { + return new JavaScriptChannel(channelName, this); + } + + @NonNull + @Override + public ProxyApiRegistrar getPigeonRegistrar() { + return (ProxyApiRegistrar) super.getPigeonRegistrar(); + } +} diff --git a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/PermissionRequestFlutterApiImpl.java b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/PermissionRequestFlutterApiImpl.java deleted file mode 100644 index e959a9965fd0..000000000000 --- a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/PermissionRequestFlutterApiImpl.java +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -package io.flutter.plugins.webviewflutter; - -import android.webkit.PermissionRequest; -import androidx.annotation.NonNull; -import androidx.annotation.VisibleForTesting; -import io.flutter.plugin.common.BinaryMessenger; -import io.flutter.plugins.webviewflutter.GeneratedAndroidWebView.PermissionRequestFlutterApi; -import java.util.Arrays; - -/** - * Flutter API implementation for `PermissionRequest`. - * - *

This class may handle adding native instances that are attached to a Dart instance or passing - * arguments of callbacks methods to a Dart instance. - */ -public class PermissionRequestFlutterApiImpl { - // To ease adding additional methods, this value is added prematurely. - @SuppressWarnings({"unused", "FieldCanBeLocal"}) - private final BinaryMessenger binaryMessenger; - - private final InstanceManager instanceManager; - private PermissionRequestFlutterApi api; - - /** - * Constructs a {@link PermissionRequestFlutterApiImpl}. - * - * @param binaryMessenger used to communicate with Dart over asynchronous messages - * @param instanceManager maintains instances stored to communicate with attached Dart objects - */ - public PermissionRequestFlutterApiImpl( - @NonNull BinaryMessenger binaryMessenger, @NonNull InstanceManager instanceManager) { - this.binaryMessenger = binaryMessenger; - this.instanceManager = instanceManager; - api = new PermissionRequestFlutterApi(binaryMessenger); - } - - /** - * Stores the `PermissionRequest` instance and notifies Dart to create and store a new - * `PermissionRequest` instance that is attached to this one. If `instance` has already been - * added, this method does nothing. - */ - public void create( - @NonNull PermissionRequest instance, - @NonNull String[] resources, - @NonNull PermissionRequestFlutterApi.Reply callback) { - if (!instanceManager.containsInstance(instance)) { - api.create( - instanceManager.addHostCreatedInstance(instance), Arrays.asList(resources), callback); - } - } - - /** - * Sets the Flutter API used to send messages to Dart. - * - *

This is only visible for testing. - */ - @VisibleForTesting - void setApi(@NonNull PermissionRequestFlutterApi api) { - this.api = api; - } -} diff --git a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/PermissionRequestHostApiImpl.java b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/PermissionRequestHostApiImpl.java deleted file mode 100644 index 2a7e6ccb58a0..000000000000 --- a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/PermissionRequestHostApiImpl.java +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -package io.flutter.plugins.webviewflutter; - -import android.webkit.PermissionRequest; -import androidx.annotation.NonNull; -import io.flutter.plugin.common.BinaryMessenger; -import io.flutter.plugins.webviewflutter.GeneratedAndroidWebView.PermissionRequestHostApi; -import java.util.List; -import java.util.Objects; - -/** - * Host API implementation for `PermissionRequest`. - * - *

This class may handle instantiating and adding native object instances that are attached to a - * Dart instance or handle method calls on the associated native class or an instance of the class. - */ -public class PermissionRequestHostApiImpl implements PermissionRequestHostApi { - // To ease adding additional methods, this value is added prematurely. - @SuppressWarnings({"unused", "FieldCanBeLocal"}) - private final BinaryMessenger binaryMessenger; - - private final InstanceManager instanceManager; - - /** - * Constructs a {@link PermissionRequestHostApiImpl}. - * - * @param binaryMessenger used to communicate with Dart over asynchronous messages - * @param instanceManager maintains instances stored to communicate with attached Dart objects - */ - public PermissionRequestHostApiImpl( - @NonNull BinaryMessenger binaryMessenger, @NonNull InstanceManager instanceManager) { - this.binaryMessenger = binaryMessenger; - this.instanceManager = instanceManager; - } - - @Override - public void grant(@NonNull Long instanceId, @NonNull List resources) { - getPermissionRequestInstance(instanceId).grant(resources.toArray(new String[0])); - } - - @Override - public void deny(@NonNull Long instanceId) { - getPermissionRequestInstance(instanceId).deny(); - } - - private PermissionRequest getPermissionRequestInstance(@NonNull Long identifier) { - return Objects.requireNonNull(instanceManager.getInstance(identifier)); - } -} diff --git a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/PermissionRequestProxyApi.java b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/PermissionRequestProxyApi.java new file mode 100644 index 000000000000..235d75f3fa5d --- /dev/null +++ b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/PermissionRequestProxyApi.java @@ -0,0 +1,39 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +package io.flutter.plugins.webviewflutter; + +import android.webkit.PermissionRequest; +import androidx.annotation.NonNull; +import java.util.Arrays; +import java.util.List; + +/** + * Host API implementation for `PermissionRequest`. + * + *

This class may handle instantiating and adding native object instances that are attached to a + * Dart instance or handle method calls on the associated native class or an instance of the class. + */ +public class PermissionRequestProxyApi extends PigeonApiPermissionRequest { + /** Constructs a {@link PermissionRequestProxyApi}. */ + public PermissionRequestProxyApi(@NonNull ProxyApiRegistrar pigeonRegistrar) { + super(pigeonRegistrar); + } + + @NonNull + @Override + public List resources(@NonNull PermissionRequest pigeon_instance) { + return Arrays.asList(pigeon_instance.getResources()); + } + + @Override + public void grant(@NonNull PermissionRequest pigeon_instance, @NonNull List resources) { + pigeon_instance.grant(resources.toArray(new String[0])); + } + + @Override + public void deny(@NonNull PermissionRequest pigeon_instance) { + pigeon_instance.deny(); + } +} diff --git a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/ProxyApiRegistrar.java b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/ProxyApiRegistrar.java new file mode 100644 index 000000000000..bc86c51dd28c --- /dev/null +++ b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/ProxyApiRegistrar.java @@ -0,0 +1,199 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +package io.flutter.plugins.webviewflutter; + +import android.app.Activity; +import android.content.Context; +import android.os.Build; +import android.os.Handler; +import android.os.Looper; +import android.util.Log; +import androidx.annotation.ChecksSdkIntAtLeast; +import androidx.annotation.NonNull; +import androidx.annotation.RequiresApi; +import io.flutter.plugin.common.BinaryMessenger; + +public class ProxyApiRegistrar extends AndroidWebkitLibraryPigeonProxyApiRegistrar { + @NonNull private Context context; + + @NonNull private final FlutterAssetManager flutterAssetManager; + + public ProxyApiRegistrar( + @NonNull BinaryMessenger binaryMessenger, + @NonNull Context context, + @NonNull FlutterAssetManager flutterAssetManager) { + super(binaryMessenger); + this.context = context; + this.flutterAssetManager = flutterAssetManager; + } + + // Interface for an injectable SDK version checker. + @ChecksSdkIntAtLeast(parameter = 0) + boolean sdkIsAtLeast(int version) { + return Build.VERSION.SDK_INT >= version; + } + + // Added to be overridden for tests. The test implementation calls `callback` immediately, instead + // of waiting for the main thread to run it. + void runOnMainThread(Runnable runnable) { + if (context instanceof Activity) { + ((Activity) context).runOnUiThread(runnable); + } else { + new Handler(Looper.getMainLooper()).post(runnable); + } + } + + // For logging exception received from Host -> Dart message calls. + void logError(String tag, Throwable exception) { + Log.e( + tag, + exception.getClass().getSimpleName() + + ", Message: " + + exception.getMessage() + + ", Stacktrace: " + + Log.getStackTraceString(exception)); + } + + @NonNull + @Override + public PigeonApiWebResourceRequest getPigeonApiWebResourceRequest() { + return new WebResourceRequestProxyApi(this); + } + + @RequiresApi(api = Build.VERSION_CODES.M) + @NonNull + @Override + public PigeonApiWebResourceError getPigeonApiWebResourceError() { + return new WebResourceErrorProxyApi(this); + } + + @NonNull + @Override + public PigeonApiWebResourceErrorCompat getPigeonApiWebResourceErrorCompat() { + return new WebResourceErrorCompatProxyApi(this); + } + + @NonNull + @Override + public PigeonApiWebViewPoint getPigeonApiWebViewPoint() { + return new WebViewPointProxyApi(this); + } + + @NonNull + @Override + public PigeonApiConsoleMessage getPigeonApiConsoleMessage() { + return new ConsoleMessageProxyApi(this); + } + + @NonNull + @Override + public PigeonApiCookieManager getPigeonApiCookieManager() { + return new CookieManagerProxyApi(this); + } + + @NonNull + @Override + public PigeonApiWebResourceResponse getPigeonApiWebResourceResponse() { + return new WebResourceResponseProxyApi(this); + } + + @NonNull + @Override + public PigeonApiWebView getPigeonApiWebView() { + return new WebViewProxyApi(this); + } + + @NonNull + @Override + public PigeonApiWebSettings getPigeonApiWebSettings() { + return new WebSettingsProxyApi(this); + } + + @NonNull + @Override + public PigeonApiJavaScriptChannel getPigeonApiJavaScriptChannel() { + return new JavaScriptChannelProxyApi(this); + } + + @NonNull + @Override + public PigeonApiWebViewClient getPigeonApiWebViewClient() { + return new WebViewClientProxyApi(this); + } + + @NonNull + @Override + public PigeonApiDownloadListener getPigeonApiDownloadListener() { + return new DownloadListenerProxyApi(this); + } + + @NonNull + @Override + public PigeonApiWebChromeClient getPigeonApiWebChromeClient() { + return new WebChromeClientProxyApi(this); + } + + @NonNull + @Override + public PigeonApiFlutterAssetManager getPigeonApiFlutterAssetManager() { + return new FlutterAssetManagerProxyApi(this); + } + + @NonNull + @Override + public PigeonApiWebStorage getPigeonApiWebStorage() { + return new WebStorageProxyApi(this); + } + + @NonNull + @Override + public PigeonApiFileChooserParams getPigeonApiFileChooserParams() { + return new FileChooserParamsProxyApi(this); + } + + @NonNull + @Override + public PigeonApiPermissionRequest getPigeonApiPermissionRequest() { + return new PermissionRequestProxyApi(this); + } + + @NonNull + @Override + public PigeonApiCustomViewCallback getPigeonApiCustomViewCallback() { + return new CustomViewCallbackProxyApi(this); + } + + @NonNull + @Override + public PigeonApiView getPigeonApiView() { + return new ViewProxyApi(this); + } + + @NonNull + @Override + public PigeonApiGeolocationPermissionsCallback getPigeonApiGeolocationPermissionsCallback() { + return new GeolocationPermissionsCallbackProxyApi(this); + } + + @NonNull + @Override + public PigeonApiHttpAuthHandler getPigeonApiHttpAuthHandler() { + return new HttpAuthHandlerProxyApi(this); + } + + @NonNull + public Context getContext() { + return context; + } + + public void setContext(@NonNull Context context) { + this.context = context; + } + + @NonNull + public FlutterAssetManager getFlutterAssetManager() { + return flutterAssetManager; + } +} diff --git a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/ResultCompat.kt b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/ResultCompat.kt new file mode 100644 index 000000000000..20ddf770f8b0 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/ResultCompat.kt @@ -0,0 +1,41 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +package io.flutter.plugins.webviewflutter + +/** + * ResultCompat. + * + * It is intended to solve the problem of being unable to obtain [kotlin.Result] in Java. + * + * [kotlin.Result] has a weird quirk when it is passed to Java where it seems to wrap itself. + */ +@Suppress("UNCHECKED_CAST") +class ResultCompat(val result: Result) { + private val value: T? = result.getOrNull() + private val exception = result.exceptionOrNull() + val isSuccess = result.isSuccess + val isFailure = result.isFailure + + companion object { + @JvmStatic + fun success(value: T, callback: Any) { + val castedCallback: (Result) -> Unit = callback as (Result) -> Unit + castedCallback(Result.success(value)) + } + + @JvmStatic + fun asCompatCallback(result: (ResultCompat) -> Unit): (Result) -> Unit { + return { result(ResultCompat(it)) } + } + } + + fun getOrNull(): T? { + return value + } + + fun exceptionOrNull(): Throwable? { + return exception + } +} diff --git a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/ViewFlutterApiImpl.java b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/ViewFlutterApiImpl.java deleted file mode 100644 index 653bfa9faf3d..000000000000 --- a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/ViewFlutterApiImpl.java +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -package io.flutter.plugins.webviewflutter; - -import android.view.View; -import androidx.annotation.NonNull; -import androidx.annotation.VisibleForTesting; -import io.flutter.plugin.common.BinaryMessenger; -import io.flutter.plugins.webviewflutter.GeneratedAndroidWebView.ViewFlutterApi; - -/** - * Flutter API implementation for `View`. - * - *

This class may handle adding native instances that are attached to a Dart instance or passing - * arguments of callbacks methods to a Dart instance. - */ -public class ViewFlutterApiImpl { - // To ease adding additional methods, this value is added prematurely. - @SuppressWarnings({"unused", "FieldCanBeLocal"}) - private final BinaryMessenger binaryMessenger; - - private final InstanceManager instanceManager; - private ViewFlutterApi api; - - /** - * Constructs a {@link ViewFlutterApiImpl}. - * - * @param binaryMessenger used to communicate with Dart over asynchronous messages - * @param instanceManager maintains instances stored to communicate with attached Dart objects - */ - public ViewFlutterApiImpl( - @NonNull BinaryMessenger binaryMessenger, @NonNull InstanceManager instanceManager) { - this.binaryMessenger = binaryMessenger; - this.instanceManager = instanceManager; - api = new ViewFlutterApi(binaryMessenger); - } - - /** - * Stores the `View` instance and notifies Dart to create and store a new `View` instance that is - * attached to this one. If `instance` has already been added, this method does nothing. - */ - public void create(@NonNull View instance, @NonNull ViewFlutterApi.Reply callback) { - if (!instanceManager.containsInstance(instance)) { - api.create(instanceManager.addHostCreatedInstance(instance), callback); - } - } - - /** - * Sets the Flutter API used to send messages to Dart. - * - *

This is only visible for testing. - */ - @VisibleForTesting - void setApi(@NonNull ViewFlutterApi api) { - this.api = api; - } -} diff --git a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/ViewProxyApi.java b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/ViewProxyApi.java new file mode 100644 index 000000000000..e5efbd15f814 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/ViewProxyApi.java @@ -0,0 +1,37 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +package io.flutter.plugins.webviewflutter; + +import android.view.View; +import androidx.annotation.NonNull; + +/** + * Flutter API implementation for `View`. + * + *

This class may handle adding native instances that are attached to a Dart instance or passing + * arguments of callbacks methods to a Dart instance. + */ +public class ViewProxyApi extends PigeonApiView { + /** Constructs a {@link ViewProxyApi}. */ + public ViewProxyApi(@NonNull ProxyApiRegistrar pigeonRegistrar) { + super(pigeonRegistrar); + } + + @Override + public void scrollTo(@NonNull View pigeon_instance, long x, long y) { + pigeon_instance.scrollTo((int) x, (int) y); + } + + @Override + public void scrollBy(@NonNull View pigeon_instance, long x, long y) { + pigeon_instance.scrollBy((int) x, (int) y); + } + + @NonNull + @Override + public WebViewPoint getScrollPosition(@NonNull View pigeon_instance) { + return new WebViewPoint(pigeon_instance.getScrollX(), pigeon_instance.getScrollY()); + } +} diff --git a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/WebChromeClientFlutterApiImpl.java b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/WebChromeClientFlutterApiImpl.java deleted file mode 100644 index 45a1c98adae1..000000000000 --- a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/WebChromeClientFlutterApiImpl.java +++ /dev/null @@ -1,243 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -package io.flutter.plugins.webviewflutter; - -import android.view.View; -import android.webkit.ConsoleMessage; -import android.webkit.GeolocationPermissions; -import android.webkit.PermissionRequest; -import android.webkit.WebChromeClient; -import android.webkit.WebView; -import androidx.annotation.NonNull; -import io.flutter.plugin.common.BinaryMessenger; -import io.flutter.plugins.webviewflutter.GeneratedAndroidWebView.WebChromeClientFlutterApi; -import java.util.List; -import java.util.Objects; - -/** - * Flutter Api implementation for {@link WebChromeClient}. - * - *

Passes arguments of callbacks methods from a {@link WebChromeClient} to Dart. - */ -public class WebChromeClientFlutterApiImpl extends WebChromeClientFlutterApi { - private final BinaryMessenger binaryMessenger; - private final InstanceManager instanceManager; - private final WebViewFlutterApiImpl webViewFlutterApi; - - private static GeneratedAndroidWebView.ConsoleMessageLevel toConsoleMessageLevel( - ConsoleMessage.MessageLevel level) { - switch (level) { - case TIP: - return GeneratedAndroidWebView.ConsoleMessageLevel.TIP; - case LOG: - return GeneratedAndroidWebView.ConsoleMessageLevel.LOG; - case WARNING: - return GeneratedAndroidWebView.ConsoleMessageLevel.WARNING; - case ERROR: - return GeneratedAndroidWebView.ConsoleMessageLevel.ERROR; - case DEBUG: - return GeneratedAndroidWebView.ConsoleMessageLevel.DEBUG; - } - - return GeneratedAndroidWebView.ConsoleMessageLevel.UNKNOWN; - } - - /** - * Creates a Flutter api that sends messages to Dart. - * - * @param binaryMessenger handles sending messages to Dart - * @param instanceManager maintains instances stored to communicate with Dart objects - */ - public WebChromeClientFlutterApiImpl( - @NonNull BinaryMessenger binaryMessenger, @NonNull InstanceManager instanceManager) { - super(binaryMessenger); - this.binaryMessenger = binaryMessenger; - this.instanceManager = instanceManager; - webViewFlutterApi = new WebViewFlutterApiImpl(binaryMessenger, instanceManager); - } - - /** Passes arguments from {@link WebChromeClient#onProgressChanged} to Dart. */ - public void onProgressChanged( - @NonNull WebChromeClient webChromeClient, - @NonNull WebView webView, - @NonNull Long progress, - @NonNull Reply callback) { - webViewFlutterApi.create(webView, reply -> {}); - - final Long webViewIdentifier = - Objects.requireNonNull(instanceManager.getIdentifierForStrongReference(webView)); - super.onProgressChanged( - getIdentifierForClient(webChromeClient), webViewIdentifier, progress, callback); - } - - /** Passes arguments from {@link WebChromeClient#onShowFileChooser} to Dart. */ - public void onShowFileChooser( - @NonNull WebChromeClient webChromeClient, - @NonNull WebView webView, - @NonNull WebChromeClient.FileChooserParams fileChooserParams, - @NonNull Reply> callback) { - webViewFlutterApi.create(webView, reply -> {}); - - new FileChooserParamsFlutterApiImpl(binaryMessenger, instanceManager) - .create(fileChooserParams, reply -> {}); - - onShowFileChooser( - Objects.requireNonNull(instanceManager.getIdentifierForStrongReference(webChromeClient)), - Objects.requireNonNull(instanceManager.getIdentifierForStrongReference(webView)), - Objects.requireNonNull(instanceManager.getIdentifierForStrongReference(fileChooserParams)), - callback); - } - - /** Passes arguments from {@link WebChromeClient#onGeolocationPermissionsShowPrompt} to Dart. */ - public void onGeolocationPermissionsShowPrompt( - @NonNull WebChromeClient webChromeClient, - @NonNull String origin, - @NonNull GeolocationPermissions.Callback callback, - @NonNull WebChromeClientFlutterApi.Reply replyCallback) { - new GeolocationPermissionsCallbackFlutterApiImpl(binaryMessenger, instanceManager) - .create(callback, reply -> {}); - onGeolocationPermissionsShowPrompt( - Objects.requireNonNull(instanceManager.getIdentifierForStrongReference(webChromeClient)), - Objects.requireNonNull(instanceManager.getIdentifierForStrongReference(callback)), - origin, - replyCallback); - } - - /** - * Sends a message to Dart to call `WebChromeClient.onGeolocationPermissionsHidePrompt` on the - * Dart object representing `instance`. - */ - public void onGeolocationPermissionsHidePrompt( - @NonNull WebChromeClient instance, @NonNull WebChromeClientFlutterApi.Reply callback) { - super.onGeolocationPermissionsHidePrompt( - Objects.requireNonNull(instanceManager.getIdentifierForStrongReference(instance)), - callback); - } - - /** - * Sends a message to Dart to call `WebChromeClient.onPermissionRequest` on the Dart object - * representing `instance`. - */ - public void onPermissionRequest( - @NonNull WebChromeClient instance, - @NonNull PermissionRequest request, - @NonNull WebChromeClientFlutterApi.Reply callback) { - new PermissionRequestFlutterApiImpl(binaryMessenger, instanceManager) - .create(request, request.getResources(), reply -> {}); - - super.onPermissionRequest( - Objects.requireNonNull(instanceManager.getIdentifierForStrongReference(instance)), - Objects.requireNonNull(instanceManager.getIdentifierForStrongReference(request)), - callback); - } - - /** - * Sends a message to Dart to call `WebChromeClient.onShowCustomView` on the Dart object - * representing `instance`. - */ - public void onShowCustomView( - @NonNull WebChromeClient instance, - @NonNull View view, - @NonNull WebChromeClient.CustomViewCallback customViewCallback, - @NonNull WebChromeClientFlutterApi.Reply callback) { - new ViewFlutterApiImpl(binaryMessenger, instanceManager).create(view, reply -> {}); - new CustomViewCallbackFlutterApiImpl(binaryMessenger, instanceManager) - .create(customViewCallback, reply -> {}); - - onShowCustomView( - Objects.requireNonNull(instanceManager.getIdentifierForStrongReference(instance)), - Objects.requireNonNull(instanceManager.getIdentifierForStrongReference(view)), - Objects.requireNonNull(instanceManager.getIdentifierForStrongReference(customViewCallback)), - callback); - } - - /** - * Sends a message to Dart to call `WebChromeClient.onHideCustomView` on the Dart object - * representing `instance`. - */ - public void onHideCustomView( - @NonNull WebChromeClient instance, @NonNull WebChromeClientFlutterApi.Reply callback) { - super.onHideCustomView( - Objects.requireNonNull(instanceManager.getIdentifierForStrongReference(instance)), - callback); - } - - /** - * Sends a message to Dart to call `WebChromeClient.onConsoleMessage` on the Dart object - * representing `instance`. - */ - public void onConsoleMessage( - @NonNull WebChromeClient instance, - @NonNull ConsoleMessage message, - @NonNull Reply callback) { - super.onConsoleMessage( - Objects.requireNonNull(instanceManager.getIdentifierForStrongReference(instance)), - new GeneratedAndroidWebView.ConsoleMessage.Builder() - .setLineNumber((long) message.lineNumber()) - .setMessage(message.message()) - .setLevel(toConsoleMessageLevel(message.messageLevel())) - .setSourceId(message.sourceId()) - .build(), - callback); - } - - /** - * Sends a message to Dart to call `WebChromeClient.onJsAlert` on the Dart object representing - * `instance`. - */ - public void onJsAlert( - @NonNull WebChromeClient instance, - @NonNull String url, - @NonNull String message, - @NonNull WebChromeClientFlutterApi.Reply callback) { - super.onJsAlert( - Objects.requireNonNull(instanceManager.getIdentifierForStrongReference(instance)), - url, - message, - callback); - } - - /** - * Sends a message to Dart to call `WebChromeClient.onJsConfirm` on the Dart object representing - * `instance`. - */ - public void onJsConfirm( - @NonNull WebChromeClient instance, - @NonNull String url, - @NonNull String message, - @NonNull WebChromeClientFlutterApi.Reply callback) { - super.onJsConfirm( - Objects.requireNonNull(instanceManager.getIdentifierForStrongReference(instance)), - url, - message, - callback); - } - - /** - * Sends a message to Dart to call `WebChromeClient.onJsPrompt` on the Dart object representing - * `instance`. - */ - public void onJsPrompt( - @NonNull WebChromeClient instance, - @NonNull String url, - @NonNull String message, - @NonNull String defaultValue, - @NonNull WebChromeClientFlutterApi.Reply callback) { - super.onJsPrompt( - Objects.requireNonNull(instanceManager.getIdentifierForStrongReference(instance)), - url, - message, - defaultValue, - callback); - } - - private long getIdentifierForClient(WebChromeClient webChromeClient) { - final Long identifier = instanceManager.getIdentifierForStrongReference(webChromeClient); - if (identifier == null) { - throw new IllegalStateException("Could not find identifier for WebChromeClient."); - } - return identifier; - } -} diff --git a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/WebChromeClientHostApiImpl.java b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/WebChromeClientProxyApi.java similarity index 61% rename from packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/WebChromeClientHostApiImpl.java rename to packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/WebChromeClientProxyApi.java index 2edb012c5350..8a0d86f7b45b 100644 --- a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/WebChromeClientHostApiImpl.java +++ b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/WebChromeClientProxyApi.java @@ -4,7 +4,6 @@ package io.flutter.plugins.webviewflutter; -import android.content.Context; import android.net.Uri; import android.os.Build; import android.os.Message; @@ -23,7 +22,7 @@ import androidx.annotation.Nullable; import androidx.annotation.RequiresApi; import androidx.annotation.VisibleForTesting; -import io.flutter.plugins.webviewflutter.GeneratedAndroidWebView.WebChromeClientHostApi; +import java.util.List; import java.util.Objects; /** @@ -31,17 +30,14 @@ * *

Handles creating {@link WebChromeClient}s that intercommunicate with a paired Dart object. */ -public class WebChromeClientHostApiImpl implements WebChromeClientHostApi { - private final InstanceManager instanceManager; - private final WebChromeClientCreator webChromeClientCreator; - private final WebChromeClientFlutterApiImpl flutterApi; - private Context context; - +public class WebChromeClientProxyApi extends PigeonApiWebChromeClient { /** * Implementation of {@link WebChromeClient} that passes arguments of callback methods to Dart. */ public static class WebChromeClientImpl extends SecureWebChromeClient { - private final WebChromeClientFlutterApiImpl flutterApi; + private static final String TAG = "WebChromeClientImpl"; + + private final WebChromeClientProxyApi api; private boolean returnValueForOnShowFileChooser = false; private boolean returnValueForOnConsoleMessage = false; @@ -49,38 +45,34 @@ public static class WebChromeClientImpl extends SecureWebChromeClient { private boolean returnValueForOnJsConfirm = false; private boolean returnValueForOnJsPrompt = false; - /** - * Creates a {@link WebChromeClient} that passes arguments of callbacks methods to Dart. - * - * @param flutterApi handles sending messages to Dart - */ - public WebChromeClientImpl(@NonNull WebChromeClientFlutterApiImpl flutterApi) { - this.flutterApi = flutterApi; + /** Creates a {@link WebChromeClient} that passes arguments of callbacks methods to Dart. */ + public WebChromeClientImpl(@NonNull WebChromeClientProxyApi api) { + this.api = api; } @Override public void onProgressChanged(@NonNull WebView view, int progress) { - flutterApi.onProgressChanged(this, view, (long) progress, reply -> {}); + api.onProgressChanged(this, view, (long) progress, reply -> null); } @Override public void onShowCustomView(View view, WebChromeClient.CustomViewCallback callback) { - flutterApi.onShowCustomView(this, view, callback, reply -> {}); + api.onShowCustomView(this, view, callback, reply -> null); } @Override public void onHideCustomView() { - flutterApi.onHideCustomView(this, reply -> {}); + api.onHideCustomView(this, reply -> null); } public void onGeolocationPermissionsShowPrompt( @NonNull String origin, @NonNull GeolocationPermissions.Callback callback) { - flutterApi.onGeolocationPermissionsShowPrompt(this, origin, callback, reply -> {}); + api.onGeolocationPermissionsShowPrompt(this, origin, callback, reply -> null); } @Override public void onGeolocationPermissionsHidePrompt() { - flutterApi.onGeolocationPermissionsHidePrompt(this, reply -> {}); + api.onGeolocationPermissionsHidePrompt(this, reply -> null); } @SuppressWarnings("LambdaLast") @@ -90,32 +82,43 @@ public boolean onShowFileChooser( @NonNull ValueCallback filePathCallback, @NonNull FileChooserParams fileChooserParams) { final boolean currentReturnValueForOnShowFileChooser = returnValueForOnShowFileChooser; - flutterApi.onShowFileChooser( + api.onShowFileChooser( this, webView, fileChooserParams, - reply -> { - // The returned list of file paths can only be passed to `filePathCallback` if the - // `onShowFileChooser` method returned true. - if (currentReturnValueForOnShowFileChooser) { - final Uri[] filePaths = new Uri[reply.size()]; - for (int i = 0; i < reply.size(); i++) { - filePaths[i] = Uri.parse(reply.get(i)); - } - filePathCallback.onReceiveValue(filePaths); - } - }); + ResultCompat.asCompatCallback( + reply -> { + if (reply.isFailure()) { + api.getPigeonRegistrar() + .logError(TAG, Objects.requireNonNull(reply.exceptionOrNull())); + return null; + } + + final List value = Objects.requireNonNull(reply.getOrNull()); + + // The returned list of file paths can only be passed to `filePathCallback` if the + // `onShowFileChooser` method returned true. + if (currentReturnValueForOnShowFileChooser) { + final Uri[] filePaths = new Uri[value.size()]; + for (int i = 0; i < value.size(); i++) { + filePaths[i] = Uri.parse(value.get(i)); + } + filePathCallback.onReceiveValue(filePaths); + } + + return null; + })); return currentReturnValueForOnShowFileChooser; } @Override public void onPermissionRequest(@NonNull PermissionRequest request) { - flutterApi.onPermissionRequest(this, request, reply -> {}); + api.onPermissionRequest(this, request, reply -> null); } @Override public boolean onConsoleMessage(ConsoleMessage consoleMessage) { - flutterApi.onConsoleMessage(this, consoleMessage, reply -> {}); + api.onConsoleMessage(this, consoleMessage, reply -> null); return returnValueForOnConsoleMessage; } @@ -144,13 +147,22 @@ public void setReturnValueForOnJsPrompt(boolean value) { @Override public boolean onJsAlert(WebView view, String url, String message, JsResult result) { if (returnValueForOnJsAlert) { - flutterApi.onJsAlert( + api.onJsAlert( this, + view, url, message, - reply -> { - result.confirm(); - }); + ResultCompat.asCompatCallback( + reply -> { + if (reply.isFailure()) { + api.getPigeonRegistrar() + .logError(TAG, Objects.requireNonNull(reply.exceptionOrNull())); + return null; + } + + result.confirm(); + return null; + })); return true; } else { return false; @@ -160,17 +172,27 @@ public boolean onJsAlert(WebView view, String url, String message, JsResult resu @Override public boolean onJsConfirm(WebView view, String url, String message, JsResult result) { if (returnValueForOnJsConfirm) { - flutterApi.onJsConfirm( + api.onJsConfirm( this, + view, url, message, - reply -> { - if (reply) { - result.confirm(); - } else { - result.cancel(); - } - }); + ResultCompat.asCompatCallback( + reply -> { + if (reply.isFailure()) { + api.getPigeonRegistrar() + .logError(TAG, Objects.requireNonNull(reply.exceptionOrNull())); + return null; + } + + if (Boolean.TRUE.equals(reply.getOrNull())) { + result.confirm(); + } else { + result.cancel(); + } + + return null; + })); return true; } else { return false; @@ -181,19 +203,30 @@ public boolean onJsConfirm(WebView view, String url, String message, JsResult re public boolean onJsPrompt( WebView view, String url, String message, String defaultValue, JsPromptResult result) { if (returnValueForOnJsPrompt) { - flutterApi.onJsPrompt( + api.onJsPrompt( this, + view, url, message, defaultValue, - reply -> { - @Nullable String inputMessage = reply; - if (inputMessage != null) { - result.confirm(inputMessage); - } else { - result.cancel(); - } - }); + ResultCompat.asCompatCallback( + reply -> { + if (reply.isFailure()) { + api.getPigeonRegistrar() + .logError(TAG, Objects.requireNonNull(reply.exceptionOrNull())); + return null; + } + + @Nullable final String inputMessage = reply.getOrNull(); + + if (inputMessage != null) { + result.confirm(inputMessage); + } else { + result.cancel(); + } + + return null; + })); return true; } else { return false; @@ -289,81 +322,50 @@ public void setWebViewClient(@NonNull WebViewClient webViewClient) { } } - /** Handles creating {@link WebChromeClient}s for a {@link WebChromeClientHostApiImpl}. */ - public static class WebChromeClientCreator { - /** - * Creates a {@link WebChromeClientHostApiImpl.WebChromeClientImpl}. - * - * @param flutterApi handles sending messages to Dart - * @return the created {@link WebChromeClientHostApiImpl.WebChromeClientImpl} - */ - @NonNull - public WebChromeClientImpl createWebChromeClient( - @NonNull WebChromeClientFlutterApiImpl flutterApi) { - return new WebChromeClientImpl(flutterApi); - } - } - - /** - * Creates a host API that handles creating {@link WebChromeClient}s. - * - * @param instanceManager maintains instances stored to communicate with Dart objects - * @param webChromeClientCreator handles creating {@link WebChromeClient}s - * @param flutterApi handles sending messages to Dart - */ - public WebChromeClientHostApiImpl( - @NonNull InstanceManager instanceManager, - @NonNull WebChromeClientCreator webChromeClientCreator, - @NonNull WebChromeClientFlutterApiImpl flutterApi) { - this.instanceManager = instanceManager; - this.webChromeClientCreator = webChromeClientCreator; - this.flutterApi = flutterApi; + /** Creates a host API that handles creating {@link WebChromeClient}s. */ + public WebChromeClientProxyApi(@NonNull ProxyApiRegistrar pigeonRegistrar) { + super(pigeonRegistrar); } + @NonNull @Override - public void create(@NonNull Long instanceId) { - final WebChromeClient webChromeClient = - webChromeClientCreator.createWebChromeClient(flutterApi); - instanceManager.addDartCreatedInstance(webChromeClient, instanceId); + public WebChromeClientImpl pigeon_defaultConstructor() { + return new WebChromeClientImpl(this); } @Override public void setSynchronousReturnValueForOnShowFileChooser( - @NonNull Long instanceId, @NonNull Boolean value) { - final WebChromeClientImpl webChromeClient = - Objects.requireNonNull(instanceManager.getInstance(instanceId)); - webChromeClient.setReturnValueForOnShowFileChooser(value); + @NonNull WebChromeClientImpl pigeon_instance, boolean value) { + pigeon_instance.setReturnValueForOnShowFileChooser(value); } @Override public void setSynchronousReturnValueForOnConsoleMessage( - @NonNull Long instanceId, @NonNull Boolean value) { - final WebChromeClientImpl webChromeClient = - Objects.requireNonNull(instanceManager.getInstance(instanceId)); - webChromeClient.setReturnValueForOnConsoleMessage(value); + @NonNull WebChromeClientImpl pigeon_instance, boolean value) { + pigeon_instance.setReturnValueForOnConsoleMessage(value); } @Override public void setSynchronousReturnValueForOnJsAlert( - @NonNull Long instanceId, @NonNull Boolean value) { - final WebChromeClientImpl webChromeClient = - Objects.requireNonNull(instanceManager.getInstance(instanceId)); - webChromeClient.setReturnValueForOnJsAlert(value); + @NonNull WebChromeClientImpl pigeon_instance, boolean value) { + pigeon_instance.setReturnValueForOnJsAlert(value); } @Override public void setSynchronousReturnValueForOnJsConfirm( - @NonNull Long instanceId, @NonNull Boolean value) { - final WebChromeClientImpl webChromeClient = - Objects.requireNonNull(instanceManager.getInstance(instanceId)); - webChromeClient.setReturnValueForOnJsConfirm(value); + @NonNull WebChromeClientImpl pigeon_instance, boolean value) { + pigeon_instance.setReturnValueForOnJsConfirm(value); } @Override public void setSynchronousReturnValueForOnJsPrompt( - @NonNull Long instanceId, @NonNull Boolean value) { - final WebChromeClientImpl webChromeClient = - Objects.requireNonNull(instanceManager.getInstance(instanceId)); - webChromeClient.setReturnValueForOnJsPrompt(value); + @NonNull WebChromeClientImpl pigeon_instance, boolean value) { + pigeon_instance.setReturnValueForOnJsPrompt(value); + } + + @NonNull + @Override + public ProxyApiRegistrar getPigeonRegistrar() { + return (ProxyApiRegistrar) super.getPigeonRegistrar(); } } diff --git a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/WebResourceErrorCompatProxyApi.java b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/WebResourceErrorCompatProxyApi.java new file mode 100644 index 000000000000..3e3d8c85fdd8 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/WebResourceErrorCompatProxyApi.java @@ -0,0 +1,28 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +package io.flutter.plugins.webviewflutter; + +import android.annotation.SuppressLint; +import androidx.annotation.NonNull; +import androidx.webkit.WebResourceErrorCompat; + +public class WebResourceErrorCompatProxyApi extends PigeonApiWebResourceErrorCompat { + public WebResourceErrorCompatProxyApi(@NonNull ProxyApiRegistrar pigeonRegistrar) { + super(pigeonRegistrar); + } + + @SuppressLint("RequiresFeature") + @Override + public long errorCode(@NonNull WebResourceErrorCompat pigeon_instance) { + return pigeon_instance.getErrorCode(); + } + + @SuppressLint("RequiresFeature") + @NonNull + @Override + public String description(@NonNull WebResourceErrorCompat pigeon_instance) { + return pigeon_instance.getDescription().toString(); + } +} diff --git a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/WebResourceErrorProxyApi.java b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/WebResourceErrorProxyApi.java new file mode 100644 index 000000000000..88baba36e161 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/WebResourceErrorProxyApi.java @@ -0,0 +1,28 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +package io.flutter.plugins.webviewflutter; + +import android.os.Build; +import android.webkit.WebResourceError; +import androidx.annotation.NonNull; +import androidx.annotation.RequiresApi; + +@RequiresApi(api = Build.VERSION_CODES.M) +public class WebResourceErrorProxyApi extends PigeonApiWebResourceError { + public WebResourceErrorProxyApi(@NonNull ProxyApiRegistrar pigeonRegistrar) { + super(pigeonRegistrar); + } + + @Override + public long errorCode(@NonNull WebResourceError pigeon_instance) { + return pigeon_instance.getErrorCode(); + } + + @NonNull + @Override + public String description(@NonNull WebResourceError pigeon_instance) { + return pigeon_instance.getDescription().toString(); + } +} diff --git a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/WebResourceRequestProxyApi.java b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/WebResourceRequestProxyApi.java new file mode 100644 index 000000000000..872cf27d2d18 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/WebResourceRequestProxyApi.java @@ -0,0 +1,68 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +package io.flutter.plugins.webviewflutter; + +import android.os.Build; +import android.webkit.WebResourceRequest; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import java.util.Collections; +import java.util.Map; + +public class WebResourceRequestProxyApi extends PigeonApiWebResourceRequest { + public WebResourceRequestProxyApi(@NonNull ProxyApiRegistrar pigeonRegistrar) { + super(pigeonRegistrar); + } + + @NonNull + @Override + public String url(@NonNull WebResourceRequest pigeon_instance) { + return pigeon_instance.getUrl().toString(); + } + + @NonNull + @Override + public boolean isForMainFrame(@NonNull WebResourceRequest pigeon_instance) { + return pigeon_instance.isForMainFrame(); + } + + @Nullable + @Override + public Boolean isRedirect(@NonNull WebResourceRequest pigeon_instance) { + if (getPigeonRegistrar().sdkIsAtLeast(Build.VERSION_CODES.N)) { + return pigeon_instance.isRedirect(); + } + + return null; + } + + @NonNull + @Override + public boolean hasGesture(@NonNull WebResourceRequest pigeon_instance) { + return pigeon_instance.hasGesture(); + } + + @NonNull + @Override + public String method(@NonNull WebResourceRequest pigeon_instance) { + return pigeon_instance.getMethod(); + } + + @Nullable + @Override + public Map requestHeaders(@NonNull WebResourceRequest pigeon_instance) { + if (pigeon_instance.getRequestHeaders() == null) { + return Collections.emptyMap(); + } else { + return pigeon_instance.getRequestHeaders(); + } + } + + @NonNull + @Override + public ProxyApiRegistrar getPigeonRegistrar() { + return (ProxyApiRegistrar) super.getPigeonRegistrar(); + } +} diff --git a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/WebResourceResponseProxyApi.java b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/WebResourceResponseProxyApi.java new file mode 100644 index 000000000000..b627af9241f5 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/WebResourceResponseProxyApi.java @@ -0,0 +1,19 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +package io.flutter.plugins.webviewflutter; + +import android.webkit.WebResourceResponse; +import androidx.annotation.NonNull; + +public class WebResourceResponseProxyApi extends PigeonApiWebResourceResponse { + public WebResourceResponseProxyApi(@NonNull ProxyApiRegistrar pigeonRegistrar) { + super(pigeonRegistrar); + } + + @Override + public long statusCode(@NonNull WebResourceResponse pigeon_instance) { + return pigeon_instance.getStatusCode(); + } +} diff --git a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/WebSettingsHostApiImpl.java b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/WebSettingsHostApiImpl.java deleted file mode 100644 index 8eac2ed6a0c5..000000000000 --- a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/WebSettingsHostApiImpl.java +++ /dev/null @@ -1,142 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -package io.flutter.plugins.webviewflutter; - -import android.webkit.WebSettings; -import android.webkit.WebView; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import io.flutter.plugins.webviewflutter.GeneratedAndroidWebView.WebSettingsHostApi; -import java.util.Objects; - -/** - * Host api implementation for {@link WebSettings}. - * - *

Handles creating {@link WebSettings}s that intercommunicate with a paired Dart object. - */ -public class WebSettingsHostApiImpl implements WebSettingsHostApi { - private final InstanceManager instanceManager; - private final WebSettingsCreator webSettingsCreator; - - /** Handles creating {@link WebSettings} for a {@link WebSettingsHostApiImpl}. */ - public static class WebSettingsCreator { - /** - * Creates a {@link WebSettings}. - * - * @param webView the {@link WebView} which the settings affect - * @return the created {@link WebSettings} - */ - @NonNull - public WebSettings createWebSettings(@NonNull WebView webView) { - return webView.getSettings(); - } - } - - /** - * Creates a host API that handles creating {@link WebSettings} and invoke its methods. - * - * @param instanceManager maintains instances stored to communicate with Dart objects - * @param webSettingsCreator handles creating {@link WebSettings}s - */ - public WebSettingsHostApiImpl( - @NonNull InstanceManager instanceManager, @NonNull WebSettingsCreator webSettingsCreator) { - this.instanceManager = instanceManager; - this.webSettingsCreator = webSettingsCreator; - } - - @Override - public void create(@NonNull Long instanceId, @NonNull Long webViewInstanceId) { - final WebView webView = Objects.requireNonNull(instanceManager.getInstance(webViewInstanceId)); - instanceManager.addDartCreatedInstance( - webSettingsCreator.createWebSettings(webView), instanceId); - } - - @Override - public void setDomStorageEnabled(@NonNull Long instanceId, @NonNull Boolean flag) { - final WebSettings webSettings = Objects.requireNonNull(instanceManager.getInstance(instanceId)); - webSettings.setDomStorageEnabled(flag); - } - - @Override - public void setJavaScriptCanOpenWindowsAutomatically( - @NonNull Long instanceId, @NonNull Boolean flag) { - final WebSettings webSettings = Objects.requireNonNull(instanceManager.getInstance(instanceId)); - webSettings.setJavaScriptCanOpenWindowsAutomatically(flag); - } - - @Override - public void setSupportMultipleWindows(@NonNull Long instanceId, @NonNull Boolean support) { - final WebSettings webSettings = Objects.requireNonNull(instanceManager.getInstance(instanceId)); - webSettings.setSupportMultipleWindows(support); - } - - @Override - public void setJavaScriptEnabled(@NonNull Long instanceId, @NonNull Boolean flag) { - final WebSettings webSettings = Objects.requireNonNull(instanceManager.getInstance(instanceId)); - webSettings.setJavaScriptEnabled(flag); - } - - @Override - public void setUserAgentString(@NonNull Long instanceId, @Nullable String userAgentString) { - final WebSettings webSettings = Objects.requireNonNull(instanceManager.getInstance(instanceId)); - webSettings.setUserAgentString(userAgentString); - } - - @Override - public void setMediaPlaybackRequiresUserGesture( - @NonNull Long instanceId, @NonNull Boolean require) { - final WebSettings webSettings = Objects.requireNonNull(instanceManager.getInstance(instanceId)); - webSettings.setMediaPlaybackRequiresUserGesture(require); - } - - @Override - public void setSupportZoom(@NonNull Long instanceId, @NonNull Boolean support) { - final WebSettings webSettings = Objects.requireNonNull(instanceManager.getInstance(instanceId)); - webSettings.setSupportZoom(support); - } - - @Override - public void setLoadWithOverviewMode(@NonNull Long instanceId, @NonNull Boolean overview) { - final WebSettings webSettings = Objects.requireNonNull(instanceManager.getInstance(instanceId)); - webSettings.setLoadWithOverviewMode(overview); - } - - @Override - public void setUseWideViewPort(@NonNull Long instanceId, @NonNull Boolean use) { - final WebSettings webSettings = Objects.requireNonNull(instanceManager.getInstance(instanceId)); - webSettings.setUseWideViewPort(use); - } - - @Override - public void setDisplayZoomControls(@NonNull Long instanceId, @NonNull Boolean enabled) { - final WebSettings webSettings = Objects.requireNonNull(instanceManager.getInstance(instanceId)); - webSettings.setDisplayZoomControls(enabled); - } - - @Override - public void setBuiltInZoomControls(@NonNull Long instanceId, @NonNull Boolean enabled) { - final WebSettings webSettings = Objects.requireNonNull(instanceManager.getInstance(instanceId)); - webSettings.setBuiltInZoomControls(enabled); - } - - @Override - public void setAllowFileAccess(@NonNull Long instanceId, @NonNull Boolean enabled) { - final WebSettings webSettings = Objects.requireNonNull(instanceManager.getInstance(instanceId)); - webSettings.setAllowFileAccess(enabled); - } - - @Override - public void setTextZoom(@NonNull Long instanceId, @NonNull Long textZoom) { - final WebSettings webSettings = Objects.requireNonNull(instanceManager.getInstance(instanceId)); - webSettings.setTextZoom(textZoom.intValue()); - } - - @NonNull - @Override - public String getUserAgentString(@NonNull Long instanceId) { - final WebSettings webSettings = Objects.requireNonNull(instanceManager.getInstance(instanceId)); - return webSettings.getUserAgentString(); - } -} diff --git a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/WebSettingsProxyApi.java b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/WebSettingsProxyApi.java new file mode 100644 index 000000000000..82fa32b8150e --- /dev/null +++ b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/WebSettingsProxyApi.java @@ -0,0 +1,94 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +package io.flutter.plugins.webviewflutter; + +import android.webkit.WebSettings; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + +/** + * Host api implementation for {@link WebSettings}. + * + *

Handles creating {@link WebSettings}s that intercommunicate with a paired Dart object. + */ +public class WebSettingsProxyApi extends PigeonApiWebSettings { + public WebSettingsProxyApi(@NonNull ProxyApiRegistrar pigeonRegistrar) { + super(pigeonRegistrar); + } + + @Override + public void setDomStorageEnabled(@NonNull WebSettings pigeon_instance, boolean flag) { + pigeon_instance.setDomStorageEnabled(flag); + } + + @Override + public void setJavaScriptCanOpenWindowsAutomatically( + @NonNull WebSettings pigeon_instance, boolean flag) { + pigeon_instance.setJavaScriptCanOpenWindowsAutomatically(flag); + } + + @Override + public void setSupportMultipleWindows(@NonNull WebSettings pigeon_instance, boolean support) { + pigeon_instance.setSupportMultipleWindows(support); + } + + @Override + public void setJavaScriptEnabled(@NonNull WebSettings pigeon_instance, boolean flag) { + pigeon_instance.setJavaScriptEnabled(flag); + } + + @Override + public void setUserAgentString( + @NonNull WebSettings pigeon_instance, @Nullable String userAgentString) { + pigeon_instance.setUserAgentString(userAgentString); + } + + @Override + public void setMediaPlaybackRequiresUserGesture( + @NonNull WebSettings pigeon_instance, boolean require) { + pigeon_instance.setMediaPlaybackRequiresUserGesture(require); + } + + @Override + public void setSupportZoom(@NonNull WebSettings pigeon_instance, boolean support) { + pigeon_instance.setSupportZoom(support); + } + + @Override + public void setLoadWithOverviewMode(@NonNull WebSettings pigeon_instance, boolean overview) { + pigeon_instance.setLoadWithOverviewMode(overview); + } + + @Override + public void setUseWideViewPort(@NonNull WebSettings pigeon_instance, boolean use) { + pigeon_instance.setUseWideViewPort(use); + } + + @Override + public void setDisplayZoomControls(@NonNull WebSettings pigeon_instance, boolean enabled) { + pigeon_instance.setDisplayZoomControls(enabled); + } + + @Override + public void setBuiltInZoomControls(@NonNull WebSettings pigeon_instance, boolean enabled) { + pigeon_instance.setBuiltInZoomControls(enabled); + } + + @Override + public void setAllowFileAccess(@NonNull WebSettings pigeon_instance, boolean enabled) { + pigeon_instance.setAllowFileAccess(enabled); + } + + @Override + public void setTextZoom(@NonNull WebSettings pigeon_instance, long textZoom) { + pigeon_instance.setTextZoom((int) textZoom); + } + + @NonNull + @Override + public String getUserAgentString(@NonNull WebSettings pigeon_instance) { + return pigeon_instance.getUserAgentString(); + } +} diff --git a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/WebStorageHostApiImpl.java b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/WebStorageHostApiImpl.java deleted file mode 100644 index 036a395eaa5b..000000000000 --- a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/WebStorageHostApiImpl.java +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -package io.flutter.plugins.webviewflutter; - -import android.webkit.WebStorage; -import androidx.annotation.NonNull; -import io.flutter.plugins.webviewflutter.GeneratedAndroidWebView.WebStorageHostApi; -import java.util.Objects; - -/** - * Host api implementation for {@link WebStorage}. - * - *

Handles creating {@link WebStorage}s that intercommunicate with a paired Dart object. - */ -public class WebStorageHostApiImpl implements WebStorageHostApi { - private final InstanceManager instanceManager; - private final WebStorageCreator webStorageCreator; - - /** Handles creating {@link WebStorage} for a {@link WebStorageHostApiImpl}. */ - public static class WebStorageCreator { - /** - * Creates a {@link WebStorage}. - * - * @return the created {@link WebStorage}. Defaults to {@link WebStorage#getInstance} - */ - @NonNull - public WebStorage createWebStorage() { - return WebStorage.getInstance(); - } - } - - /** - * Creates a host API that handles creating {@link WebStorage} and invoke its methods. - * - * @param instanceManager maintains instances stored to communicate with Dart objects - * @param webStorageCreator handles creating {@link WebStorage}s - */ - public WebStorageHostApiImpl( - @NonNull InstanceManager instanceManager, @NonNull WebStorageCreator webStorageCreator) { - this.instanceManager = instanceManager; - this.webStorageCreator = webStorageCreator; - } - - @Override - public void create(@NonNull Long instanceId) { - instanceManager.addDartCreatedInstance(webStorageCreator.createWebStorage(), instanceId); - } - - @Override - public void deleteAllData(@NonNull Long instanceId) { - final WebStorage webStorage = Objects.requireNonNull(instanceManager.getInstance(instanceId)); - webStorage.deleteAllData(); - } -} diff --git a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/WebStorageProxyApi.java b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/WebStorageProxyApi.java new file mode 100644 index 000000000000..4c338acc20d0 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/WebStorageProxyApi.java @@ -0,0 +1,31 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +package io.flutter.plugins.webviewflutter; + +import android.webkit.WebStorage; +import androidx.annotation.NonNull; + +/** + * Host api implementation for {@link WebStorage}. + * + *

Handles creating {@link WebStorage}s that intercommunicate with a paired Dart object. + */ +public class WebStorageProxyApi extends PigeonApiWebStorage { + /** Creates a host API that handles creating {@link WebStorage} and invoke its methods. */ + public WebStorageProxyApi(@NonNull ProxyApiRegistrar pigeonRegistrar) { + super(pigeonRegistrar); + } + + @NonNull + @Override + public WebStorage instance() { + return WebStorage.getInstance(); + } + + @Override + public void deleteAllData(@NonNull WebStorage pigeon_instance) { + pigeon_instance.deleteAllData(); + } +} diff --git a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/WebViewClientFlutterApiImpl.java b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/WebViewClientFlutterApiImpl.java deleted file mode 100644 index b94238bcb4b5..000000000000 --- a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/WebViewClientFlutterApiImpl.java +++ /dev/null @@ -1,286 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -package io.flutter.plugins.webviewflutter; - -import android.annotation.SuppressLint; -import android.os.Build; -import android.webkit.HttpAuthHandler; -import android.webkit.WebResourceError; -import android.webkit.WebResourceRequest; -import android.webkit.WebResourceResponse; -import android.webkit.WebView; -import android.webkit.WebViewClient; -import androidx.annotation.NonNull; -import androidx.annotation.RequiresApi; -import androidx.webkit.WebResourceErrorCompat; -import io.flutter.plugin.common.BinaryMessenger; -import io.flutter.plugins.webviewflutter.GeneratedAndroidWebView.WebViewClientFlutterApi; -import java.util.HashMap; -import java.util.Objects; - -/** - * Flutter Api implementation for {@link WebViewClient}. - * - *

Passes arguments of callbacks methods from a {@link WebViewClient} to Dart. - */ -public class WebViewClientFlutterApiImpl extends WebViewClientFlutterApi { - // To ease adding additional methods, this value is added prematurely. - @SuppressWarnings({"unused", "FieldCanBeLocal"}) - private final BinaryMessenger binaryMessenger; - - private final InstanceManager instanceManager; - private final WebViewFlutterApiImpl webViewFlutterApi; - - @RequiresApi(api = Build.VERSION_CODES.M) - static GeneratedAndroidWebView.WebResourceErrorData createWebResourceErrorData( - WebResourceError error) { - return new GeneratedAndroidWebView.WebResourceErrorData.Builder() - .setErrorCode((long) error.getErrorCode()) - .setDescription(error.getDescription().toString()) - .build(); - } - - @SuppressLint("RequiresFeature") - static GeneratedAndroidWebView.WebResourceErrorData createWebResourceErrorData( - WebResourceErrorCompat error) { - return new GeneratedAndroidWebView.WebResourceErrorData.Builder() - .setErrorCode((long) error.getErrorCode()) - .setDescription(error.getDescription().toString()) - .build(); - } - - static GeneratedAndroidWebView.WebResourceRequestData createWebResourceRequestData( - WebResourceRequest request) { - final GeneratedAndroidWebView.WebResourceRequestData.Builder requestData = - new GeneratedAndroidWebView.WebResourceRequestData.Builder() - .setUrl(request.getUrl().toString()) - .setIsForMainFrame(request.isForMainFrame()) - .setHasGesture(request.hasGesture()) - .setMethod(request.getMethod()) - .setRequestHeaders( - request.getRequestHeaders() != null - ? request.getRequestHeaders() - : new HashMap<>()); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { - requestData.setIsRedirect(request.isRedirect()); - } - - return requestData.build(); - } - - static GeneratedAndroidWebView.WebResourceResponseData createWebResourceResponseData( - WebResourceResponse response) { - final GeneratedAndroidWebView.WebResourceResponseData.Builder responseData = - new GeneratedAndroidWebView.WebResourceResponseData.Builder() - .setStatusCode((long) response.getStatusCode()); - - return responseData.build(); - } - - /** - * Creates a Flutter api that sends messages to Dart. - * - * @param binaryMessenger handles sending messages to Dart - * @param instanceManager maintains instances stored to communicate with Dart objects - */ - public WebViewClientFlutterApiImpl( - @NonNull BinaryMessenger binaryMessenger, @NonNull InstanceManager instanceManager) { - super(binaryMessenger); - this.binaryMessenger = binaryMessenger; - this.instanceManager = instanceManager; - webViewFlutterApi = new WebViewFlutterApiImpl(binaryMessenger, instanceManager); - } - - /** Passes arguments from {@link WebViewClient#onPageStarted} to Dart. */ - public void onPageStarted( - @NonNull WebViewClient webViewClient, - @NonNull WebView webView, - @NonNull String urlArg, - @NonNull Reply callback) { - webViewFlutterApi.create(webView, reply -> {}); - - final Long webViewIdentifier = - Objects.requireNonNull(instanceManager.getIdentifierForStrongReference(webView)); - onPageStarted(getIdentifierForClient(webViewClient), webViewIdentifier, urlArg, callback); - } - - /** Passes arguments from {@link WebViewClient#onPageFinished} to Dart. */ - public void onPageFinished( - @NonNull WebViewClient webViewClient, - @NonNull WebView webView, - @NonNull String urlArg, - @NonNull Reply callback) { - webViewFlutterApi.create(webView, reply -> {}); - - final Long webViewIdentifier = - Objects.requireNonNull(instanceManager.getIdentifierForStrongReference(webView)); - onPageFinished(getIdentifierForClient(webViewClient), webViewIdentifier, urlArg, callback); - } - - /** Passes arguments from {@link WebViewClient#onReceivedHttpError} to Dart. */ - public void onReceivedHttpError( - @NonNull WebViewClient webViewClient, - @NonNull WebView webView, - @NonNull WebResourceRequest request, - @NonNull WebResourceResponse response, - @NonNull Reply callback) { - webViewFlutterApi.create(webView, reply -> {}); - - final Long webViewIdentifier = instanceManager.getIdentifierForStrongReference(webView); - onReceivedHttpError( - getIdentifierForClient(webViewClient), - webViewIdentifier, - createWebResourceRequestData(request), - createWebResourceResponseData(response), - callback); - } - - /** - * Passes arguments from {@link WebViewClient#onReceivedError(WebView, WebResourceRequest, - * WebResourceError)} to Dart. - */ - @RequiresApi(api = Build.VERSION_CODES.M) - public void onReceivedRequestError( - @NonNull WebViewClient webViewClient, - @NonNull WebView webView, - @NonNull WebResourceRequest request, - @NonNull WebResourceError error, - @NonNull Reply callback) { - webViewFlutterApi.create(webView, reply -> {}); - - final Long webViewIdentifier = - Objects.requireNonNull(instanceManager.getIdentifierForStrongReference(webView)); - onReceivedRequestError( - getIdentifierForClient(webViewClient), - webViewIdentifier, - createWebResourceRequestData(request), - createWebResourceErrorData(error), - callback); - } - - /** - * Passes arguments from {@link androidx.webkit.WebViewClientCompat#onReceivedError(WebView, - * WebResourceRequest, WebResourceError)} to Dart. - */ - public void onReceivedRequestError( - @NonNull WebViewClient webViewClient, - @NonNull WebView webView, - @NonNull WebResourceRequest request, - @NonNull WebResourceErrorCompat error, - @NonNull Reply callback) { - webViewFlutterApi.create(webView, reply -> {}); - - final Long webViewIdentifier = - Objects.requireNonNull(instanceManager.getIdentifierForStrongReference(webView)); - onReceivedRequestError( - getIdentifierForClient(webViewClient), - webViewIdentifier, - createWebResourceRequestData(request), - createWebResourceErrorData(error), - callback); - } - - /** - * Passes arguments from {@link WebViewClient#onReceivedError(WebView, int, String, String)} to - * Dart. - */ - public void onReceivedError( - @NonNull WebViewClient webViewClient, - @NonNull WebView webView, - @NonNull Long errorCodeArg, - @NonNull String descriptionArg, - @NonNull String failingUrlArg, - @NonNull Reply callback) { - webViewFlutterApi.create(webView, reply -> {}); - - final Long webViewIdentifier = - Objects.requireNonNull(instanceManager.getIdentifierForStrongReference(webView)); - onReceivedError( - getIdentifierForClient(webViewClient), - webViewIdentifier, - errorCodeArg, - descriptionArg, - failingUrlArg, - callback); - } - - /** - * Passes arguments from {@link WebViewClient#shouldOverrideUrlLoading(WebView, - * WebResourceRequest)} to Dart. - */ - public void requestLoading( - @NonNull WebViewClient webViewClient, - @NonNull WebView webView, - @NonNull WebResourceRequest request, - @NonNull Reply callback) { - webViewFlutterApi.create(webView, reply -> {}); - - final Long webViewIdentifier = - Objects.requireNonNull(instanceManager.getIdentifierForStrongReference(webView)); - requestLoading( - getIdentifierForClient(webViewClient), - webViewIdentifier, - createWebResourceRequestData(request), - callback); - } - - /** - * Passes arguments from {@link WebViewClient#shouldOverrideUrlLoading(WebView, String)} to Dart. - */ - public void urlLoading( - @NonNull WebViewClient webViewClient, - @NonNull WebView webView, - @NonNull String urlArg, - @NonNull Reply callback) { - webViewFlutterApi.create(webView, reply -> {}); - - final Long webViewIdentifier = - Objects.requireNonNull(instanceManager.getIdentifierForStrongReference(webView)); - urlLoading(getIdentifierForClient(webViewClient), webViewIdentifier, urlArg, callback); - } - - /** Passes arguments from {@link WebViewClient#doUpdateVisitedHistory} to Dart. */ - public void doUpdateVisitedHistory( - @NonNull WebViewClient webViewClient, - @NonNull WebView webView, - @NonNull String url, - boolean isReload, - @NonNull Reply callback) { - webViewFlutterApi.create(webView, reply -> {}); - - final Long webViewIdentifier = - Objects.requireNonNull(instanceManager.getIdentifierForStrongReference(webView)); - doUpdateVisitedHistory( - getIdentifierForClient(webViewClient), webViewIdentifier, url, isReload, callback); - } - - /** Passes arguments from {@link WebViewClient#onReceivedHttpAuthRequest} to Dart. */ - public void onReceivedHttpAuthRequest( - @NonNull WebViewClient webViewClient, - @NonNull WebView webview, - @NonNull HttpAuthHandler httpAuthHandler, - @NonNull String host, - @NonNull String realm, - @NonNull Reply callback) { - new HttpAuthHandlerFlutterApiImpl(binaryMessenger, instanceManager) - .create(httpAuthHandler, reply -> {}); - - onReceivedHttpAuthRequest( - Objects.requireNonNull(instanceManager.getIdentifierForStrongReference(webViewClient)), - Objects.requireNonNull(instanceManager.getIdentifierForStrongReference(webview)), - Objects.requireNonNull(instanceManager.getIdentifierForStrongReference(httpAuthHandler)), - host, - realm, - callback); - } - - private long getIdentifierForClient(WebViewClient webViewClient) { - final Long identifier = instanceManager.getIdentifierForStrongReference(webViewClient); - if (identifier == null) { - throw new IllegalStateException("Could not find identifier for WebViewClient."); - } - return identifier; - } -} diff --git a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/WebViewClientHostApiImpl.java b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/WebViewClientProxyApi.java similarity index 58% rename from packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/WebViewClientHostApiImpl.java rename to packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/WebViewClientProxyApi.java index a71b5efbcc4f..ca456528a919 100644 --- a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/WebViewClientHostApiImpl.java +++ b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/WebViewClientProxyApi.java @@ -17,41 +17,38 @@ import androidx.annotation.RequiresApi; import androidx.webkit.WebResourceErrorCompat; import androidx.webkit.WebViewClientCompat; -import java.util.Objects; /** * Host api implementation for {@link WebViewClient}. * *

Handles creating {@link WebViewClient}s that intercommunicate with a paired Dart object. */ -public class WebViewClientHostApiImpl implements GeneratedAndroidWebView.WebViewClientHostApi { - private final InstanceManager instanceManager; - private final WebViewClientCreator webViewClientCreator; - private final WebViewClientFlutterApiImpl flutterApi; - +public class WebViewClientProxyApi extends PigeonApiWebViewClient { /** Implementation of {@link WebViewClient} that passes arguments of callback methods to Dart. */ @RequiresApi(Build.VERSION_CODES.N) public static class WebViewClientImpl extends WebViewClient { - private final WebViewClientFlutterApiImpl flutterApi; + private final WebViewClientProxyApi api; private boolean returnValueForShouldOverrideUrlLoading = false; /** * Creates a {@link WebViewClient} that passes arguments of callbacks methods to Dart. * - * @param flutterApi handles sending messages to Dart. + * @param api handles sending messages to Dart. */ - public WebViewClientImpl(@NonNull WebViewClientFlutterApiImpl flutterApi) { - this.flutterApi = flutterApi; + public WebViewClientImpl(@NonNull WebViewClientProxyApi api) { + this.api = api; } @Override public void onPageStarted(@NonNull WebView view, @NonNull String url, @NonNull Bitmap favicon) { - flutterApi.onPageStarted(this, view, url, reply -> {}); + api.getPigeonRegistrar() + .runOnMainThread(() -> api.onPageStarted(this, view, url, reply -> null)); } @Override public void onPageFinished(@NonNull WebView view, @NonNull String url) { - flutterApi.onPageFinished(this, view, url, reply -> {}); + api.getPigeonRegistrar() + .runOnMainThread(() -> api.onPageFinished(this, view, url, reply -> null)); } @Override @@ -59,7 +56,9 @@ public void onReceivedHttpError( @NonNull WebView view, @NonNull WebResourceRequest request, @NonNull WebResourceResponse response) { - flutterApi.onReceivedHttpError(this, view, request, response, reply -> {}); + api.getPigeonRegistrar() + .runOnMainThread( + () -> api.onReceivedHttpError(this, view, request, response, reply -> null)); } @Override @@ -67,7 +66,9 @@ public void onReceivedError( @NonNull WebView view, @NonNull WebResourceRequest request, @NonNull WebResourceError error) { - flutterApi.onReceivedRequestError(this, view, request, error, reply -> {}); + api.getPigeonRegistrar() + .runOnMainThread( + () -> api.onReceivedRequestError(this, view, request, error, reply -> null)); } // Legacy codepath for < 23; newer versions use the variant above. @@ -78,14 +79,18 @@ public void onReceivedError( int errorCode, @NonNull String description, @NonNull String failingUrl) { - flutterApi.onReceivedError( - this, view, (long) errorCode, description, failingUrl, reply -> {}); + api.getPigeonRegistrar() + .runOnMainThread( + () -> + api.onReceivedError( + this, view, (long) errorCode, description, failingUrl, reply -> null)); } @Override public boolean shouldOverrideUrlLoading( @NonNull WebView view, @NonNull WebResourceRequest request) { - flutterApi.requestLoading(this, view, request, reply -> {}); + api.getPigeonRegistrar() + .runOnMainThread(() -> api.requestLoading(this, view, request, reply -> null)); // The client is only allowed to stop navigations that target the main frame because // overridden URLs are passed to `loadUrl` and `loadUrl` cannot load a subframe. @@ -96,14 +101,17 @@ public boolean shouldOverrideUrlLoading( @SuppressWarnings("deprecation") @Override public boolean shouldOverrideUrlLoading(@NonNull WebView view, @NonNull String url) { - flutterApi.urlLoading(this, view, url, reply -> {}); + api.getPigeonRegistrar() + .runOnMainThread(() -> api.urlLoading(this, view, url, reply -> null)); return returnValueForShouldOverrideUrlLoading; } @Override public void doUpdateVisitedHistory( @NonNull WebView view, @NonNull String url, boolean isReload) { - flutterApi.doUpdateVisitedHistory(this, view, url, isReload, reply -> {}); + api.getPigeonRegistrar() + .runOnMainThread( + () -> api.doUpdateVisitedHistory(this, view, url, isReload, reply -> null)); } @Override @@ -112,7 +120,9 @@ public void onReceivedHttpAuthRequest( @NonNull HttpAuthHandler handler, @NonNull String host, @NonNull String realm) { - flutterApi.onReceivedHttpAuthRequest(this, view, handler, host, realm, reply -> {}); + api.getPigeonRegistrar() + .runOnMainThread( + () -> api.onReceivedHttpAuthRequest(this, view, handler, host, realm, reply -> null)); } @Override @@ -133,21 +143,23 @@ public void setReturnValueForShouldOverrideUrlLoading(boolean value) { * Dart. */ public static class WebViewClientCompatImpl extends WebViewClientCompat { - private final WebViewClientFlutterApiImpl flutterApi; + private final WebViewClientProxyApi api; private boolean returnValueForShouldOverrideUrlLoading = false; - public WebViewClientCompatImpl(@NonNull WebViewClientFlutterApiImpl flutterApi) { - this.flutterApi = flutterApi; + public WebViewClientCompatImpl(@NonNull WebViewClientProxyApi api) { + this.api = api; } @Override public void onPageStarted(@NonNull WebView view, @NonNull String url, @NonNull Bitmap favicon) { - flutterApi.onPageStarted(this, view, url, reply -> {}); + api.getPigeonRegistrar() + .runOnMainThread(() -> api.onPageStarted(this, view, url, reply -> null)); } @Override public void onPageFinished(@NonNull WebView view, @NonNull String url) { - flutterApi.onPageFinished(this, view, url, reply -> {}); + api.getPigeonRegistrar() + .runOnMainThread(() -> api.onPageFinished(this, view, url, reply -> null)); } @Override @@ -155,7 +167,9 @@ public void onReceivedHttpError( @NonNull WebView view, @NonNull WebResourceRequest request, @NonNull WebResourceResponse response) { - flutterApi.onReceivedHttpError(this, view, request, response, reply -> {}); + api.getPigeonRegistrar() + .runOnMainThread( + () -> api.onReceivedHttpError(this, view, request, response, reply -> null)); } @Override @@ -163,7 +177,9 @@ public void onReceivedError( @NonNull WebView view, @NonNull WebResourceRequest request, @NonNull WebResourceErrorCompat error) { - flutterApi.onReceivedRequestError(this, view, request, error, reply -> {}); + api.getPigeonRegistrar() + .runOnMainThread( + () -> api.onReceivedRequestErrorCompat(this, view, request, error, reply -> null)); } // Legacy codepath for versions that don't support the variant above. @@ -174,32 +190,38 @@ public void onReceivedError( int errorCode, @NonNull String description, @NonNull String failingUrl) { - flutterApi.onReceivedError( - this, view, (long) errorCode, description, failingUrl, reply -> {}); + api.getPigeonRegistrar() + .runOnMainThread( + () -> + api.onReceivedError( + this, view, (long) errorCode, description, failingUrl, reply -> null)); } @Override public boolean shouldOverrideUrlLoading( @NonNull WebView view, @NonNull WebResourceRequest request) { - flutterApi.requestLoading(this, view, request, reply -> {}); + api.getPigeonRegistrar() + .runOnMainThread(() -> api.requestLoading(this, view, request, reply -> null)); // The client is only allowed to stop navigations that target the main frame because // overridden URLs are passed to `loadUrl` and `loadUrl` cannot load a subframe. return request.isForMainFrame() && returnValueForShouldOverrideUrlLoading; } - // Legacy codepath for < Lollipop; newer versions use the variant above. @SuppressWarnings("deprecation") @Override public boolean shouldOverrideUrlLoading(@NonNull WebView view, @NonNull String url) { - flutterApi.urlLoading(this, view, url, reply -> {}); + api.getPigeonRegistrar() + .runOnMainThread(() -> api.urlLoading(this, view, url, reply -> null)); return returnValueForShouldOverrideUrlLoading; } @Override public void doUpdateVisitedHistory( @NonNull WebView view, @NonNull String url, boolean isReload) { - flutterApi.doUpdateVisitedHistory(this, view, url, isReload, reply -> {}); + api.getPigeonRegistrar() + .runOnMainThread( + () -> api.doUpdateVisitedHistory(this, view, url, isReload, reply -> null)); } // Handles an HTTP authentication request. @@ -209,7 +231,9 @@ public void doUpdateVisitedHistory( @Override public void onReceivedHttpAuthRequest( @NonNull WebView view, HttpAuthHandler handler, String host, String realm) { - flutterApi.onReceivedHttpAuthRequest(this, view, handler, host, realm, reply -> {}); + api.getPigeonRegistrar() + .runOnMainThread( + () -> api.onReceivedHttpAuthRequest(this, view, handler, host, realm, reply -> null)); } @Override @@ -225,67 +249,46 @@ public void setReturnValueForShouldOverrideUrlLoading(boolean value) { } } - /** Handles creating {@link WebViewClient}s for a {@link WebViewClientHostApiImpl}. */ - public static class WebViewClientCreator { - /** - * Creates a {@link WebViewClient}. - * - * @param flutterApi handles sending messages to Dart - * @return the created {@link WebViewClient} - */ - @NonNull - public WebViewClient createWebViewClient(@NonNull WebViewClientFlutterApiImpl flutterApi) { - // WebViewClientCompat is used to get - // shouldOverrideUrlLoading(WebView view, WebResourceRequest request) - // invoked by the webview on older Android devices, without it pages that use iframes will - // be broken when a navigationDelegate is set on Android version earlier than N. - // - // However, this if statement attempts to avoid using WebViewClientCompat on versions >= N due - // to bug https://bugs.chromium.org/p/chromium/issues/detail?id=925887. Also, see - // https://github.com/flutter/flutter/issues/29446. - if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { - return new WebViewClientImpl(flutterApi); - } else { - return new WebViewClientCompatImpl(flutterApi); - } - } - } - - /** - * Creates a host API that handles creating {@link WebViewClient}s. - * - * @param instanceManager maintains instances stored to communicate with Dart objects - * @param webViewClientCreator handles creating {@link WebViewClient}s - * @param flutterApi handles sending messages to Dart - */ - public WebViewClientHostApiImpl( - @NonNull InstanceManager instanceManager, - @NonNull WebViewClientCreator webViewClientCreator, - @NonNull WebViewClientFlutterApiImpl flutterApi) { - this.instanceManager = instanceManager; - this.webViewClientCreator = webViewClientCreator; - this.flutterApi = flutterApi; + /** Creates a host API that handles creating {@link WebViewClient}s. */ + public WebViewClientProxyApi(@NonNull ProxyApiRegistrar pigeonRegistrar) { + super(pigeonRegistrar); } + @NonNull @Override - public void create(@NonNull Long instanceId) { - final WebViewClient webViewClient = webViewClientCreator.createWebViewClient(flutterApi); - instanceManager.addDartCreatedInstance(webViewClient, instanceId); + public WebViewClient pigeon_defaultConstructor() { + // WebViewClientCompat is used to get + // shouldOverrideUrlLoading(WebView view, WebResourceRequest request) + // invoked by the webview on older Android devices, without it pages that use iframes will + // be broken when a navigationDelegate is set on Android version earlier than N. + // + // However, this if statement attempts to avoid using WebViewClientCompat on versions >= N due + // to bug https://bugs.chromium.org/p/chromium/issues/detail?id=925887. Also, see + // https://github.com/flutter/flutter/issues/29446. + if (getPigeonRegistrar().sdkIsAtLeast(Build.VERSION_CODES.N)) { + return new WebViewClientImpl(this); + } else { + return new WebViewClientCompatImpl(this); + } } @Override public void setSynchronousReturnValueForShouldOverrideUrlLoading( - @NonNull Long instanceId, @NonNull Boolean value) { - final WebViewClient webViewClient = - Objects.requireNonNull(instanceManager.getInstance(instanceId)); - if (webViewClient instanceof WebViewClientCompatImpl) { - ((WebViewClientCompatImpl) webViewClient).setReturnValueForShouldOverrideUrlLoading(value); - } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N - && webViewClient instanceof WebViewClientImpl) { - ((WebViewClientImpl) webViewClient).setReturnValueForShouldOverrideUrlLoading(value); + @NonNull WebViewClient pigeon_instance, boolean value) { + if (pigeon_instance instanceof WebViewClientCompatImpl) { + ((WebViewClientCompatImpl) pigeon_instance).setReturnValueForShouldOverrideUrlLoading(value); + } else if (getPigeonRegistrar().sdkIsAtLeast(Build.VERSION_CODES.N) + && pigeon_instance instanceof WebViewClientImpl) { + ((WebViewClientImpl) pigeon_instance).setReturnValueForShouldOverrideUrlLoading(value); } else { throw new IllegalStateException( "This WebViewClient doesn't support setting the returnValueForShouldOverrideUrlLoading."); } } + + @NonNull + @Override + public ProxyApiRegistrar getPigeonRegistrar() { + return (ProxyApiRegistrar) super.getPigeonRegistrar(); + } } diff --git a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/WebViewFlutterApiImpl.java b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/WebViewFlutterApiImpl.java deleted file mode 100644 index c368cfbe5047..000000000000 --- a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/WebViewFlutterApiImpl.java +++ /dev/null @@ -1,76 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -package io.flutter.plugins.webviewflutter; - -import android.webkit.WebView; -import androidx.annotation.NonNull; -import androidx.annotation.VisibleForTesting; -import io.flutter.plugin.common.BinaryMessenger; -import io.flutter.plugins.webviewflutter.GeneratedAndroidWebView.WebViewFlutterApi; -import java.util.Objects; - -/** - * Flutter API implementation for `WebView`. - * - *

This class may handle adding native instances that are attached to a Dart instance or passing - * arguments of callbacks methods to a Dart instance. - */ -public class WebViewFlutterApiImpl { - // To ease adding additional methods, this value is added prematurely. - @SuppressWarnings({"unused", "FieldCanBeLocal"}) - private final BinaryMessenger binaryMessenger; - - private final InstanceManager instanceManager; - private WebViewFlutterApi api; - - /** - * Constructs a {@link WebViewFlutterApiImpl}. - * - * @param binaryMessenger used to communicate with Dart over asynchronous messages - * @param instanceManager maintains instances stored to communicate with attached Dart objects - */ - public WebViewFlutterApiImpl( - @NonNull BinaryMessenger binaryMessenger, @NonNull InstanceManager instanceManager) { - this.binaryMessenger = binaryMessenger; - this.instanceManager = instanceManager; - api = new WebViewFlutterApi(binaryMessenger); - } - - /** - * Stores the `WebView` instance and notifies Dart to create and store a new `WebView` instance - * that is attached to this one. If `instance` has already been added, this method does nothing. - */ - public void create(@NonNull WebView instance, @NonNull WebViewFlutterApi.Reply callback) { - if (!instanceManager.containsInstance(instance)) { - api.create(instanceManager.addHostCreatedInstance(instance), callback); - } - } - - /** - * Sets the Flutter API used to send messages to Dart. - * - *

This is only visible for testing. - */ - @VisibleForTesting - void setApi(@NonNull WebViewFlutterApi api) { - this.api = api; - } - - public void onScrollChanged( - @NonNull WebView instance, - @NonNull Long left, - @NonNull Long top, - @NonNull Long oldLeft, - @NonNull Long oldTop, - @NonNull WebViewFlutterApi.Reply callback) { - api.onScrollChanged( - Objects.requireNonNull(instanceManager.getIdentifierForStrongReference(instance)), - left, - top, - oldLeft, - oldTop, - callback); - } -} diff --git a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/WebViewFlutterPlugin.java b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/WebViewFlutterPlugin.java index 80c574badf81..db7a670e86dc 100644 --- a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/WebViewFlutterPlugin.java +++ b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/WebViewFlutterPlugin.java @@ -4,30 +4,11 @@ package io.flutter.plugins.webviewflutter; -import android.content.Context; -import android.os.Handler; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import io.flutter.embedding.engine.plugins.FlutterPlugin; import io.flutter.embedding.engine.plugins.activity.ActivityAware; import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding; -import io.flutter.plugin.common.BinaryMessenger; -import io.flutter.plugin.platform.PlatformViewRegistry; -import io.flutter.plugins.webviewflutter.GeneratedAndroidWebView.CookieManagerHostApi; -import io.flutter.plugins.webviewflutter.GeneratedAndroidWebView.CustomViewCallbackHostApi; -import io.flutter.plugins.webviewflutter.GeneratedAndroidWebView.DownloadListenerHostApi; -import io.flutter.plugins.webviewflutter.GeneratedAndroidWebView.FlutterAssetManagerHostApi; -import io.flutter.plugins.webviewflutter.GeneratedAndroidWebView.GeolocationPermissionsCallbackHostApi; -import io.flutter.plugins.webviewflutter.GeneratedAndroidWebView.HttpAuthHandlerHostApi; -import io.flutter.plugins.webviewflutter.GeneratedAndroidWebView.InstanceManagerHostApi; -import io.flutter.plugins.webviewflutter.GeneratedAndroidWebView.JavaObjectHostApi; -import io.flutter.plugins.webviewflutter.GeneratedAndroidWebView.JavaScriptChannelHostApi; -import io.flutter.plugins.webviewflutter.GeneratedAndroidWebView.PermissionRequestHostApi; -import io.flutter.plugins.webviewflutter.GeneratedAndroidWebView.WebChromeClientHostApi; -import io.flutter.plugins.webviewflutter.GeneratedAndroidWebView.WebSettingsHostApi; -import io.flutter.plugins.webviewflutter.GeneratedAndroidWebView.WebStorageHostApi; -import io.flutter.plugins.webviewflutter.GeneratedAndroidWebView.WebViewClientHostApi; -import io.flutter.plugins.webviewflutter.GeneratedAndroidWebView.WebViewHostApi; /** * Java platform implementation of the webview_flutter plugin. @@ -35,11 +16,8 @@ *

Register this in an add to app scenario to gracefully handle activity and context changes. */ public class WebViewFlutterPlugin implements FlutterPlugin, ActivityAware { - @Nullable private InstanceManager instanceManager; - private FlutterPluginBinding pluginBinding; - private WebViewHostApiImpl webViewHostApi; - private JavaScriptChannelHostApiImpl javaScriptChannelHostApi; + private ProxyApiRegistrar proxyApiRegistrar; /** * Add an instance of this to {@link io.flutter.embedding.engine.plugins.PluginRegistry} to @@ -50,123 +28,61 @@ public class WebViewFlutterPlugin implements FlutterPlugin, ActivityAware { */ public WebViewFlutterPlugin() {} - private void setUp( - BinaryMessenger binaryMessenger, - PlatformViewRegistry viewRegistry, - Context context, - FlutterAssetManager flutterAssetManager) { - instanceManager = - InstanceManager.create( - identifier -> - new GeneratedAndroidWebView.JavaObjectFlutterApi(binaryMessenger) - .dispose(identifier, reply -> {})); - - InstanceManagerHostApi.setup(binaryMessenger, () -> instanceManager.clear()); - - viewRegistry.registerViewFactory( - "plugins.flutter.io/webview", new FlutterViewFactory(instanceManager)); - - webViewHostApi = - new WebViewHostApiImpl( - instanceManager, binaryMessenger, new WebViewHostApiImpl.WebViewProxy(), context); - javaScriptChannelHostApi = - new JavaScriptChannelHostApiImpl( - instanceManager, - new JavaScriptChannelHostApiImpl.JavaScriptChannelCreator(), - new JavaScriptChannelFlutterApiImpl(binaryMessenger, instanceManager), - new Handler(context.getMainLooper())); - - JavaObjectHostApi.setup(binaryMessenger, new JavaObjectHostApiImpl(instanceManager)); - WebViewHostApi.setup(binaryMessenger, webViewHostApi); - JavaScriptChannelHostApi.setup(binaryMessenger, javaScriptChannelHostApi); - WebViewClientHostApi.setup( - binaryMessenger, - new WebViewClientHostApiImpl( - instanceManager, - new WebViewClientHostApiImpl.WebViewClientCreator(), - new WebViewClientFlutterApiImpl(binaryMessenger, instanceManager))); - WebChromeClientHostApi.setup( - binaryMessenger, - new WebChromeClientHostApiImpl( - instanceManager, - new WebChromeClientHostApiImpl.WebChromeClientCreator(), - new WebChromeClientFlutterApiImpl(binaryMessenger, instanceManager))); - DownloadListenerHostApi.setup( - binaryMessenger, - new DownloadListenerHostApiImpl( - instanceManager, - new DownloadListenerHostApiImpl.DownloadListenerCreator(), - new DownloadListenerFlutterApiImpl(binaryMessenger, instanceManager))); - WebSettingsHostApi.setup( - binaryMessenger, - new WebSettingsHostApiImpl( - instanceManager, new WebSettingsHostApiImpl.WebSettingsCreator())); - FlutterAssetManagerHostApi.setup( - binaryMessenger, new FlutterAssetManagerHostApiImpl(flutterAssetManager)); - CookieManagerHostApi.setup( - binaryMessenger, new CookieManagerHostApiImpl(binaryMessenger, instanceManager)); - WebStorageHostApi.setup( - binaryMessenger, - new WebStorageHostApiImpl(instanceManager, new WebStorageHostApiImpl.WebStorageCreator())); - PermissionRequestHostApi.setup( - binaryMessenger, new PermissionRequestHostApiImpl(binaryMessenger, instanceManager)); - GeolocationPermissionsCallbackHostApi.setup( - binaryMessenger, - new GeolocationPermissionsCallbackHostApiImpl(binaryMessenger, instanceManager)); - CustomViewCallbackHostApi.setup( - binaryMessenger, new CustomViewCallbackHostApiImpl(binaryMessenger, instanceManager)); - HttpAuthHandlerHostApi.setup( - binaryMessenger, new HttpAuthHandlerHostApiImpl(binaryMessenger, instanceManager)); - } - @Override public void onAttachedToEngine(@NonNull FlutterPluginBinding binding) { pluginBinding = binding; - setUp( - binding.getBinaryMessenger(), - binding.getPlatformViewRegistry(), - binding.getApplicationContext(), - new FlutterAssetManager.PluginBindingFlutterAssetManager( - binding.getApplicationContext().getAssets(), binding.getFlutterAssets())); + + proxyApiRegistrar = + new ProxyApiRegistrar( + binding.getBinaryMessenger(), + binding.getApplicationContext(), + new FlutterAssetManager.PluginBindingFlutterAssetManager( + binding.getApplicationContext().getAssets(), binding.getFlutterAssets())); + + binding + .getPlatformViewRegistry() + .registerViewFactory( + "plugins.flutter.io/webview", + new FlutterViewFactory(proxyApiRegistrar.getInstanceManager())); + + proxyApiRegistrar.setUp(); } @Override public void onDetachedFromEngine(@NonNull FlutterPluginBinding binding) { - if (instanceManager != null) { - instanceManager.stopFinalizationListener(); - instanceManager = null; + if (proxyApiRegistrar != null) { + proxyApiRegistrar.tearDown(); + proxyApiRegistrar.getInstanceManager().stopFinalizationListener(); + proxyApiRegistrar = null; } } @Override public void onAttachedToActivity(@NonNull ActivityPluginBinding activityPluginBinding) { - updateContext(activityPluginBinding.getActivity()); + if (proxyApiRegistrar != null) { + proxyApiRegistrar.setContext(activityPluginBinding.getActivity()); + } } @Override public void onDetachedFromActivityForConfigChanges() { - updateContext(pluginBinding.getApplicationContext()); + proxyApiRegistrar.setContext(pluginBinding.getApplicationContext()); } @Override public void onReattachedToActivityForConfigChanges( @NonNull ActivityPluginBinding activityPluginBinding) { - updateContext(activityPluginBinding.getActivity()); + proxyApiRegistrar.setContext(activityPluginBinding.getActivity()); } @Override public void onDetachedFromActivity() { - updateContext(pluginBinding.getApplicationContext()); - } - - private void updateContext(Context context) { - webViewHostApi.setContext(context); - javaScriptChannelHostApi.setPlatformThreadHandler(new Handler(context.getMainLooper())); + proxyApiRegistrar.setContext(pluginBinding.getApplicationContext()); } /** Maintains instances used to communicate with the corresponding objects in Dart. */ @Nullable - public InstanceManager getInstanceManager() { - return instanceManager; + public AndroidWebkitLibraryPigeonInstanceManager getInstanceManager() { + return proxyApiRegistrar.getInstanceManager(); } } diff --git a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/WebViewHostApiImpl.java b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/WebViewHostApiImpl.java deleted file mode 100644 index 3e22234ff716..000000000000 --- a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/WebViewHostApiImpl.java +++ /dev/null @@ -1,430 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -package io.flutter.plugins.webviewflutter; - -import android.annotation.SuppressLint; -import android.content.Context; -import android.hardware.display.DisplayManager; -import android.os.Build; -import android.view.View; -import android.view.ViewParent; -import android.webkit.WebChromeClient; -import android.webkit.WebView; -import android.webkit.WebViewClient; -import androidx.annotation.ChecksSdkIntAtLeast; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.annotation.VisibleForTesting; -import io.flutter.embedding.android.FlutterView; -import io.flutter.plugin.common.BinaryMessenger; -import io.flutter.plugin.platform.PlatformView; -import io.flutter.plugins.webviewflutter.GeneratedAndroidWebView.WebViewHostApi; -import java.util.Map; -import java.util.Objects; - -/** - * Host api implementation for {@link WebView}. - * - *

Handles creating {@link WebView}s that intercommunicate with a paired Dart object. - */ -public class WebViewHostApiImpl implements WebViewHostApi { - private final InstanceManager instanceManager; - private final WebViewProxy webViewProxy; - private final BinaryMessenger binaryMessenger; - - private Context context; - - /** Handles creating and calling static methods for {@link WebView}s. */ - public static class WebViewProxy { - /** - * Creates a {@link WebViewPlatformView}. - * - * @param context an Activity Context to access application assets - * @param binaryMessenger used to communicate with Dart over asynchronous messages - * @param instanceManager mangages instances used to communicate with the corresponding objects - * in Dart - * @return the created {@link WebViewPlatformView} - */ - @NonNull - public WebViewPlatformView createWebView( - @NonNull Context context, - @NonNull BinaryMessenger binaryMessenger, - @NonNull InstanceManager instanceManager) { - return new WebViewPlatformView(context, binaryMessenger, instanceManager); - } - - /** - * Forwards call to {@link WebView#setWebContentsDebuggingEnabled}. - * - * @param enabled whether debugging should be enabled - */ - public void setWebContentsDebuggingEnabled(boolean enabled) { - WebView.setWebContentsDebuggingEnabled(enabled); - } - } - - /** Implementation of {@link WebView} that can be used as a Flutter {@link PlatformView}s. */ - @SuppressLint("ViewConstructor") - public static class WebViewPlatformView extends WebView implements PlatformView { - // To ease adding callback methods, this value is added prematurely. - @SuppressWarnings("unused") - private WebViewFlutterApiImpl api; - - private WebViewClient currentWebViewClient; - private WebChromeClientHostApiImpl.SecureWebChromeClient currentWebChromeClient; - - private final @NonNull AndroidSdkChecker sdkChecker; - - // Interface for an injectable SDK version checker. - @VisibleForTesting - interface AndroidSdkChecker { - @ChecksSdkIntAtLeast(parameter = 0) - boolean sdkIsAtLeast(int version); - } - - /** - * Creates a {@link WebViewPlatformView}. - * - * @param context an Activity Context to access application assets. This value cannot be null. - */ - public WebViewPlatformView( - @NonNull Context context, - @NonNull BinaryMessenger binaryMessenger, - @NonNull InstanceManager instanceManager) { - this( - context, - binaryMessenger, - instanceManager, - (int version) -> Build.VERSION.SDK_INT >= version); - } - - @VisibleForTesting - WebViewPlatformView( - @NonNull Context context, - @NonNull BinaryMessenger binaryMessenger, - @NonNull InstanceManager instanceManager, - @NonNull AndroidSdkChecker sdkChecker) { - super(context); - currentWebViewClient = new WebViewClient(); - currentWebChromeClient = new WebChromeClientHostApiImpl.SecureWebChromeClient(); - api = new WebViewFlutterApiImpl(binaryMessenger, instanceManager); - this.sdkChecker = sdkChecker; - - setWebViewClient(currentWebViewClient); - setWebChromeClient(currentWebChromeClient); - } - - @Nullable - @Override - public View getView() { - return this; - } - - @Override - public void dispose() {} - - // TODO(bparrishMines): This should be removed once https://github.com/flutter/engine/pull/40771 makes it to stable. - // Temporary fix for https://github.com/flutter/flutter/issues/92165. The FlutterView is setting - // setImportantForAutofill(IMPORTANT_FOR_AUTOFILL_YES_EXCLUDE_DESCENDANTS) which prevents this - // view from automatically being traversed for autofill. - @Override - protected void onAttachedToWindow() { - super.onAttachedToWindow(); - if (sdkChecker.sdkIsAtLeast(Build.VERSION_CODES.O)) { - final FlutterView flutterView = tryFindFlutterView(); - if (flutterView != null) { - flutterView.setImportantForAutofill(IMPORTANT_FOR_AUTOFILL_YES); - } - } - } - - // Attempt to traverse the parents of this view until a FlutterView is found. - private FlutterView tryFindFlutterView() { - ViewParent currentView = this; - - while (currentView.getParent() != null) { - currentView = currentView.getParent(); - if (currentView instanceof FlutterView) { - return (FlutterView) currentView; - } - } - - return null; - } - - @Override - public void setWebViewClient(@NonNull WebViewClient webViewClient) { - super.setWebViewClient(webViewClient); - currentWebViewClient = webViewClient; - currentWebChromeClient.setWebViewClient(webViewClient); - } - - @Override - public void setWebChromeClient(@Nullable WebChromeClient client) { - super.setWebChromeClient(client); - if (!(client instanceof WebChromeClientHostApiImpl.SecureWebChromeClient)) { - throw new AssertionError("Client must be a SecureWebChromeClient."); - } - currentWebChromeClient = (WebChromeClientHostApiImpl.SecureWebChromeClient) client; - currentWebChromeClient.setWebViewClient(currentWebViewClient); - } - - // When running unit tests, the parent `WebView` class is replaced by a stub that returns null - // for every method. This is overridden so that this returns the current WebChromeClient during - // unit tests. This should only remain overridden as long as `setWebChromeClient` is overridden. - @Nullable - @Override - public WebChromeClient getWebChromeClient() { - return currentWebChromeClient; - } - - @Override - protected void onScrollChanged(int left, int top, int oldLeft, int oldTop) { - super.onScrollChanged(left, top, oldLeft, oldTop); - api.onScrollChanged( - this, (long) left, (long) top, (long) oldLeft, (long) oldTop, reply -> {}); - } - - /** - * Flutter API used to send messages back to Dart. - * - *

This is only visible for testing. - */ - @SuppressWarnings("unused") - @VisibleForTesting - void setApi(WebViewFlutterApiImpl api) { - this.api = api; - } - } - - /** - * Creates a host API that handles creating {@link WebView}s and invoking its methods. - * - * @param instanceManager maintains instances stored to communicate with Dart objects - * @param binaryMessenger used to communicate with Dart over asynchronous messages - * @param webViewProxy handles creating {@link WebView}s and calling its static methods - * @param context an Activity Context to access application assets. This value cannot be null. - */ - public WebViewHostApiImpl( - @NonNull InstanceManager instanceManager, - @NonNull BinaryMessenger binaryMessenger, - @NonNull WebViewProxy webViewProxy, - @Nullable Context context) { - this.instanceManager = instanceManager; - this.binaryMessenger = binaryMessenger; - this.webViewProxy = webViewProxy; - this.context = context; - } - - /** - * Sets the context to construct {@link WebView}s. - * - * @param context the new context. - */ - public void setContext(@Nullable Context context) { - this.context = context; - } - - @Override - public void create(@NonNull Long instanceId) { - DisplayListenerProxy displayListenerProxy = new DisplayListenerProxy(); - DisplayManager displayManager = - (DisplayManager) context.getSystemService(Context.DISPLAY_SERVICE); - displayListenerProxy.onPreWebViewInitialization(displayManager); - - final WebView webView = webViewProxy.createWebView(context, binaryMessenger, instanceManager); - - displayListenerProxy.onPostWebViewInitialization(displayManager); - instanceManager.addDartCreatedInstance(webView, instanceId); - } - - @Override - public void loadData( - @NonNull Long instanceId, - @NonNull String data, - @Nullable String mimeType, - @Nullable String encoding) { - final WebView webView = Objects.requireNonNull(instanceManager.getInstance(instanceId)); - webView.loadData(data, mimeType, encoding); - } - - @Override - public void loadDataWithBaseUrl( - @NonNull Long instanceId, - @Nullable String baseUrl, - @NonNull String data, - @Nullable String mimeType, - @Nullable String encoding, - @Nullable String historyUrl) { - final WebView webView = Objects.requireNonNull(instanceManager.getInstance(instanceId)); - webView.loadDataWithBaseURL(baseUrl, data, mimeType, encoding, historyUrl); - } - - @Override - public void loadUrl( - @NonNull Long instanceId, @NonNull String url, @NonNull Map headers) { - final WebView webView = Objects.requireNonNull(instanceManager.getInstance(instanceId)); - webView.loadUrl(url, headers); - } - - @Override - public void postUrl(@NonNull Long instanceId, @NonNull String url, @NonNull byte[] data) { - final WebView webView = Objects.requireNonNull(instanceManager.getInstance(instanceId)); - webView.postUrl(url, data); - } - - @Nullable - @Override - public String getUrl(@NonNull Long instanceId) { - final WebView webView = Objects.requireNonNull(instanceManager.getInstance(instanceId)); - return webView.getUrl(); - } - - @NonNull - @Override - public Boolean canGoBack(@NonNull Long instanceId) { - final WebView webView = Objects.requireNonNull(instanceManager.getInstance(instanceId)); - return webView.canGoBack(); - } - - @NonNull - @Override - public Boolean canGoForward(@NonNull Long instanceId) { - final WebView webView = Objects.requireNonNull(instanceManager.getInstance(instanceId)); - return webView.canGoForward(); - } - - @Override - public void goBack(@NonNull Long instanceId) { - final WebView webView = Objects.requireNonNull(instanceManager.getInstance(instanceId)); - webView.goBack(); - } - - @Override - public void goForward(@NonNull Long instanceId) { - final WebView webView = Objects.requireNonNull(instanceManager.getInstance(instanceId)); - webView.goForward(); - } - - @Override - public void reload(@NonNull Long instanceId) { - final WebView webView = Objects.requireNonNull(instanceManager.getInstance(instanceId)); - webView.reload(); - } - - @Override - public void clearCache(@NonNull Long instanceId, @NonNull Boolean includeDiskFiles) { - final WebView webView = Objects.requireNonNull(instanceManager.getInstance(instanceId)); - webView.clearCache(includeDiskFiles); - } - - @Override - public void evaluateJavascript( - @NonNull Long instanceId, - @NonNull String javascriptString, - @NonNull GeneratedAndroidWebView.Result result) { - final WebView webView = Objects.requireNonNull(instanceManager.getInstance(instanceId)); - webView.evaluateJavascript(javascriptString, result::success); - } - - @Nullable - @Override - public String getTitle(@NonNull Long instanceId) { - final WebView webView = Objects.requireNonNull(instanceManager.getInstance(instanceId)); - return webView.getTitle(); - } - - @Override - public void scrollTo(@NonNull Long instanceId, @NonNull Long x, @NonNull Long y) { - final WebView webView = Objects.requireNonNull(instanceManager.getInstance(instanceId)); - webView.scrollTo(x.intValue(), y.intValue()); - } - - @Override - public void scrollBy(@NonNull Long instanceId, @NonNull Long x, @NonNull Long y) { - final WebView webView = Objects.requireNonNull(instanceManager.getInstance(instanceId)); - webView.scrollBy(x.intValue(), y.intValue()); - } - - @NonNull - @Override - public Long getScrollX(@NonNull Long instanceId) { - final WebView webView = Objects.requireNonNull(instanceManager.getInstance(instanceId)); - return (long) webView.getScrollX(); - } - - @NonNull - @Override - public Long getScrollY(@NonNull Long instanceId) { - final WebView webView = Objects.requireNonNull(instanceManager.getInstance(instanceId)); - return (long) webView.getScrollY(); - } - - @NonNull - @Override - public GeneratedAndroidWebView.WebViewPoint getScrollPosition(@NonNull Long instanceId) { - final WebView webView = Objects.requireNonNull(instanceManager.getInstance(instanceId)); - return new GeneratedAndroidWebView.WebViewPoint.Builder() - .setX((long) webView.getScrollX()) - .setY((long) webView.getScrollY()) - .build(); - } - - @Override - public void setWebContentsDebuggingEnabled(@NonNull Boolean enabled) { - webViewProxy.setWebContentsDebuggingEnabled(enabled); - } - - @Override - public void setWebViewClient(@NonNull Long instanceId, @NonNull Long webViewClientInstanceId) { - final WebView webView = Objects.requireNonNull(instanceManager.getInstance(instanceId)); - webView.setWebViewClient(instanceManager.getInstance(webViewClientInstanceId)); - } - - @SuppressLint("JavascriptInterface") - @Override - public void addJavaScriptChannel( - @NonNull Long instanceId, @NonNull Long javaScriptChannelInstanceId) { - final WebView webView = Objects.requireNonNull(instanceManager.getInstance(instanceId)); - final JavaScriptChannel javaScriptChannel = - Objects.requireNonNull(instanceManager.getInstance(javaScriptChannelInstanceId)); - webView.addJavascriptInterface(javaScriptChannel, javaScriptChannel.javaScriptChannelName); - } - - @Override - public void removeJavaScriptChannel( - @NonNull Long instanceId, @NonNull Long javaScriptChannelInstanceId) { - final WebView webView = Objects.requireNonNull(instanceManager.getInstance(instanceId)); - final JavaScriptChannel javaScriptChannel = - Objects.requireNonNull((instanceManager.getInstance(javaScriptChannelInstanceId))); - webView.removeJavascriptInterface(javaScriptChannel.javaScriptChannelName); - } - - @Override - public void setDownloadListener(@NonNull Long instanceId, @Nullable Long listenerInstanceId) { - final WebView webView = Objects.requireNonNull(instanceManager.getInstance(instanceId)); - webView.setDownloadListener( - instanceManager.getInstance(Objects.requireNonNull(listenerInstanceId))); - } - - @Override - public void setWebChromeClient(@NonNull Long instanceId, @Nullable Long clientInstanceId) { - final WebView webView = Objects.requireNonNull(instanceManager.getInstance(instanceId)); - webView.setWebChromeClient( - instanceManager.getInstance(Objects.requireNonNull(clientInstanceId))); - } - - @Override - public void setBackgroundColor(@NonNull Long instanceId, @NonNull Long color) { - final WebView webView = Objects.requireNonNull(instanceManager.getInstance(instanceId)); - webView.setBackgroundColor(color.intValue()); - } - - /** Maintains instances used to communicate with the corresponding WebView Dart object. */ - @NonNull - public InstanceManager getInstanceManager() { - return instanceManager; - } -} diff --git a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/WebViewPoint.java b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/WebViewPoint.java new file mode 100644 index 000000000000..67fd64fef502 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/WebViewPoint.java @@ -0,0 +1,28 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +package io.flutter.plugins.webviewflutter; + +/** + * Represents a position on a web page. + * + *

This is a custom class created for convenience of the wrapper. + */ +public class WebViewPoint { + private final long x; + private final long y; + + public WebViewPoint(long x, long y) { + this.x = x; + this.y = y; + } + + public long getX() { + return x; + } + + public long getY() { + return y; + } +} diff --git a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/WebViewPointProxyApi.java b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/WebViewPointProxyApi.java new file mode 100644 index 000000000000..715570122211 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/WebViewPointProxyApi.java @@ -0,0 +1,23 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +package io.flutter.plugins.webviewflutter; + +import androidx.annotation.NonNull; + +public class WebViewPointProxyApi extends PigeonApiWebViewPoint { + public WebViewPointProxyApi(@NonNull ProxyApiRegistrar pigeonRegistrar) { + super(pigeonRegistrar); + } + + @Override + public long x(@NonNull WebViewPoint pigeon_instance) { + return pigeon_instance.getX(); + } + + @Override + public long y(@NonNull WebViewPoint pigeon_instance) { + return pigeon_instance.getY(); + } +} diff --git a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/WebViewProxyApi.java b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/WebViewProxyApi.java new file mode 100644 index 000000000000..7f9769055265 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/WebViewProxyApi.java @@ -0,0 +1,284 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +package io.flutter.plugins.webviewflutter; + +import android.annotation.SuppressLint; +import android.content.Context; +import android.hardware.display.DisplayManager; +import android.os.Build; +import android.view.View; +import android.view.ViewParent; +import android.webkit.DownloadListener; +import android.webkit.WebChromeClient; +import android.webkit.WebSettings; +import android.webkit.WebView; +import android.webkit.WebViewClient; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import io.flutter.embedding.android.FlutterView; +import io.flutter.plugin.platform.PlatformView; +import java.util.Map; +import kotlin.Result; +import kotlin.Unit; +import kotlin.jvm.functions.Function1; + +/** + * Host api implementation for {@link WebView}. + * + *

Handles creating {@link WebView}s that intercommunicate with a paired Dart object. + */ +public class WebViewProxyApi extends PigeonApiWebView { + /** Implementation of {@link WebView} that can be used as a Flutter {@link PlatformView}s. */ + @SuppressLint("ViewConstructor") + public static class WebViewPlatformView extends WebView implements PlatformView { + private final WebViewProxyApi api; + + private WebViewClient currentWebViewClient; + + private WebChromeClientProxyApi.SecureWebChromeClient currentWebChromeClient; + + WebViewPlatformView(@NonNull WebViewProxyApi api) { + super(api.getPigeonRegistrar().getContext()); + this.api = api; + currentWebViewClient = new WebViewClient(); + currentWebChromeClient = new WebChromeClientProxyApi.SecureWebChromeClient(); + + setWebViewClient(currentWebViewClient); + setWebChromeClient(currentWebChromeClient); + } + + @Nullable + @Override + public View getView() { + return this; + } + + @Override + public void dispose() {} + + // TODO(bparrishMines): This should be removed once https://github.com/flutter/engine/pull/40771 makes it to stable. + // Temporary fix for https://github.com/flutter/flutter/issues/92165. The FlutterView is setting + // setImportantForAutofill(IMPORTANT_FOR_AUTOFILL_YES_EXCLUDE_DESCENDANTS) which prevents this + // view from automatically being traversed for autofill. + @Override + protected void onAttachedToWindow() { + super.onAttachedToWindow(); + if (api.getPigeonRegistrar().sdkIsAtLeast(Build.VERSION_CODES.O)) { + final FlutterView flutterView = tryFindFlutterView(); + if (flutterView != null) { + flutterView.setImportantForAutofill(IMPORTANT_FOR_AUTOFILL_YES); + } + } + } + + // Attempt to traverse the parents of this view until a FlutterView is found. + private FlutterView tryFindFlutterView() { + ViewParent currentView = this; + + while (currentView.getParent() != null) { + currentView = currentView.getParent(); + if (currentView instanceof FlutterView) { + return (FlutterView) currentView; + } + } + + return null; + } + + @Override + public void setWebViewClient(@NonNull WebViewClient webViewClient) { + super.setWebViewClient(webViewClient); + currentWebViewClient = webViewClient; + currentWebChromeClient.setWebViewClient(webViewClient); + } + + @Override + public void setWebChromeClient(@Nullable WebChromeClient client) { + super.setWebChromeClient(client); + if (!(client instanceof WebChromeClientProxyApi.SecureWebChromeClient)) { + throw new AssertionError("Client must be a SecureWebChromeClient."); + } + currentWebChromeClient = (WebChromeClientProxyApi.SecureWebChromeClient) client; + currentWebChromeClient.setWebViewClient(currentWebViewClient); + } + + // When running unit tests, the parent `WebView` class is replaced by a stub that returns null + // for every method. This is overridden so that this returns the current WebChromeClient during + // unit tests. This should only remain overridden as long as `setWebChromeClient` is overridden. + @Nullable + @Override + public WebChromeClient getWebChromeClient() { + return currentWebChromeClient; + } + + @Override + protected void onScrollChanged(int left, int top, int oldLeft, int oldTop) { + super.onScrollChanged(left, top, oldLeft, oldTop); + api.getPigeonRegistrar() + .runOnMainThread( + () -> + api.onScrollChanged( + this, (long) left, (long) top, (long) oldLeft, (long) oldTop, reply -> null)); + } + } + + public WebViewProxyApi(@NonNull ProxyApiRegistrar pigeonRegistrar) { + super(pigeonRegistrar); + } + + @NonNull + @Override + public WebView pigeon_defaultConstructor() { + DisplayListenerProxy displayListenerProxy = new DisplayListenerProxy(); + DisplayManager displayManager = + (DisplayManager) + getPigeonRegistrar().getContext().getSystemService(Context.DISPLAY_SERVICE); + displayListenerProxy.onPreWebViewInitialization(displayManager); + + final WebView webView = new WebViewPlatformView(this); + displayListenerProxy.onPostWebViewInitialization(displayManager); + + return webView; + } + + @NonNull + @Override + public WebSettings settings(@NonNull WebView pigeon_instance) { + return pigeon_instance.getSettings(); + } + + @Override + public void loadData( + @NonNull WebView pigeon_instance, + @NonNull String data, + @Nullable String mimeType, + @Nullable String encoding) { + pigeon_instance.loadData(data, mimeType, encoding); + } + + @Override + public void loadDataWithBaseUrl( + @NonNull WebView pigeon_instance, + @Nullable String baseUrl, + @NonNull String data, + @Nullable String mimeType, + @Nullable String encoding, + @Nullable String historyUrl) { + pigeon_instance.loadDataWithBaseURL(baseUrl, data, mimeType, encoding, historyUrl); + } + + @Override + public void loadUrl( + @NonNull WebView pigeon_instance, @NonNull String url, @NonNull Map headers) { + pigeon_instance.loadUrl(url, headers); + } + + @Override + public void postUrl(@NonNull WebView pigeon_instance, @NonNull String url, @NonNull byte[] data) { + pigeon_instance.postUrl(url, data); + } + + @Nullable + @Override + public String getUrl(@NonNull WebView pigeon_instance) { + return pigeon_instance.getUrl(); + } + + @Override + public boolean canGoBack(@NonNull WebView pigeon_instance) { + return pigeon_instance.canGoBack(); + } + + @Override + public boolean canGoForward(@NonNull WebView pigeon_instance) { + return pigeon_instance.canGoForward(); + } + + @Override + public void goBack(@NonNull WebView pigeon_instance) { + pigeon_instance.goBack(); + } + + @Override + public void goForward(@NonNull WebView pigeon_instance) { + pigeon_instance.goForward(); + } + + @Override + public void reload(@NonNull WebView pigeon_instance) { + pigeon_instance.reload(); + } + + @Override + public void clearCache(@NonNull WebView pigeon_instance, boolean includeDiskFiles) { + pigeon_instance.clearCache(includeDiskFiles); + } + + @Override + public void evaluateJavascript( + @NonNull WebView pigeon_instance, + @NonNull String javascriptString, + @NonNull Function1, Unit> callback) { + pigeon_instance.evaluateJavascript( + javascriptString, result -> ResultCompat.success(result, callback)); + } + + @Nullable + @Override + public String getTitle(@NonNull WebView pigeon_instance) { + return pigeon_instance.getTitle(); + } + + @Override + public void setWebContentsDebuggingEnabled(boolean enabled) { + WebView.setWebContentsDebuggingEnabled(enabled); + } + + @Override + public void setWebViewClient(@NonNull WebView pigeon_instance, @Nullable WebViewClient client) { + pigeon_instance.setWebViewClient(client); + } + + @SuppressLint("JavascriptInterface") + @Override + public void addJavaScriptChannel( + @NonNull WebView pigeon_instance, @NonNull JavaScriptChannel channel) { + pigeon_instance.addJavascriptInterface(channel, channel.javaScriptChannelName); + } + + @Override + public void removeJavaScriptChannel(@NonNull WebView pigeon_instance, @NonNull String channel) { + pigeon_instance.removeJavascriptInterface(channel); + } + + @Override + public void setDownloadListener( + @NonNull WebView pigeon_instance, @Nullable DownloadListener listener) { + pigeon_instance.setDownloadListener(listener); + } + + @Override + public void setWebChromeClient( + @NonNull WebView pigeon_instance, + @Nullable WebChromeClientProxyApi.WebChromeClientImpl client) { + pigeon_instance.setWebChromeClient(client); + } + + @Override + public void setBackgroundColor(@NonNull WebView pigeon_instance, long color) { + pigeon_instance.setBackgroundColor((int) color); + } + + @NonNull + @Override + public ProxyApiRegistrar getPigeonRegistrar() { + return (ProxyApiRegistrar) super.getPigeonRegistrar(); + } + + @Override + public void destroy(@NonNull WebView pigeon_instance) { + pigeon_instance.destroy(); + } +} diff --git a/packages/webview_flutter/webview_flutter_android/android/src/test/java/android/net/Uri.java b/packages/webview_flutter/webview_flutter_android/android/src/test/java/android/net/Uri.java new file mode 100644 index 000000000000..e5648c325527 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_android/android/src/test/java/android/net/Uri.java @@ -0,0 +1,27 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +package android.net; + +import androidx.annotation.NonNull; + +// Creates an implementation of Uri that can be used with unittests and the JVM. Typically +// android.net.Uri does nothing when not used with an Android environment. +public class Uri { + private final String url; + + public static Uri parse(String url) { + return new Uri(url); + } + + private Uri(String url) { + this.url = url; + } + + @NonNull + @Override + public String toString() { + return url; + } +} diff --git a/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/ConsoleMessageTest.java b/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/ConsoleMessageTest.java new file mode 100644 index 000000000000..ab169b9c316d --- /dev/null +++ b/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/ConsoleMessageTest.java @@ -0,0 +1,58 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +package io.flutter.plugins.webviewflutter; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import android.webkit.ConsoleMessage; +import org.junit.Test; + +public class ConsoleMessageTest { + @Test + public void lineNumber() { + final PigeonApiConsoleMessage api = new TestProxyApiRegistrar().getPigeonApiConsoleMessage(); + + final ConsoleMessage instance = mock(ConsoleMessage.class); + final Long value = 0L; + when(instance.lineNumber()).thenReturn(value.intValue()); + + assertEquals(value, (Long) api.lineNumber(instance)); + } + + @Test + public void message() { + final PigeonApiConsoleMessage api = new TestProxyApiRegistrar().getPigeonApiConsoleMessage(); + + final ConsoleMessage instance = mock(ConsoleMessage.class); + final String value = "myString"; + when(instance.message()).thenReturn(value); + + assertEquals(value, api.message(instance)); + } + + @Test + public void level() { + final PigeonApiConsoleMessage api = new TestProxyApiRegistrar().getPigeonApiConsoleMessage(); + + final ConsoleMessage instance = mock(ConsoleMessage.class); + final ConsoleMessageLevel value = io.flutter.plugins.webviewflutter.ConsoleMessageLevel.DEBUG; + when(instance.messageLevel()).thenReturn(ConsoleMessage.MessageLevel.DEBUG); + + assertEquals(value, api.level(instance)); + } + + @Test + public void sourceId() { + final PigeonApiConsoleMessage api = new TestProxyApiRegistrar().getPigeonApiConsoleMessage(); + + final ConsoleMessage instance = mock(ConsoleMessage.class); + final String value = "myString"; + when(instance.sourceId()).thenReturn(value); + + assertEquals(value, api.sourceId(instance)); + } +} diff --git a/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/CookieManagerTest.java b/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/CookieManagerTest.java index b2b52d843fa6..15f43bceafff 100644 --- a/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/CookieManagerTest.java +++ b/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/CookieManagerTest.java @@ -7,99 +7,45 @@ import static org.junit.Assert.assertEquals; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; -import android.os.Build; import android.webkit.CookieManager; import android.webkit.ValueCallback; import android.webkit.WebView; -import androidx.annotation.NonNull; -import io.flutter.plugin.common.BinaryMessenger; -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; import org.junit.Test; import org.mockito.ArgumentCaptor; -import org.mockito.Mock; -import org.mockito.junit.MockitoJUnit; -import org.mockito.junit.MockitoRule; public class CookieManagerTest { - @Rule public MockitoRule mockitoRule = MockitoJUnit.rule(); - @Mock public CookieManager mockCookieManager; - @Mock public BinaryMessenger mockBinaryMessenger; - @Mock public CookieManagerHostApiImpl.CookieManagerProxy mockProxy; - InstanceManager instanceManager; - - @Before - public void setUp() { - instanceManager = InstanceManager.create(identifier -> {}); - } - - @After - public void tearDown() { - instanceManager.stopFinalizationListener(); - } - - @Test - public void getInstance() { - final CookieManager mockCookieManager = mock(CookieManager.class); - final long instanceIdentifier = 1; - - when(mockProxy.getInstance()).thenReturn(mockCookieManager); - - final CookieManagerHostApiImpl hostApi = - new CookieManagerHostApiImpl(mockBinaryMessenger, instanceManager, mockProxy); - hostApi.attachInstance(instanceIdentifier); - - assertEquals(instanceManager.getInstance(instanceIdentifier), mockCookieManager); - } - @Test public void setCookie() { - final String url = "testString"; - final String value = "testString2"; - - final long instanceIdentifier = 0; - instanceManager.addDartCreatedInstance(mockCookieManager, instanceIdentifier); + final PigeonApiCookieManager api = new TestProxyApiRegistrar().getPigeonApiCookieManager(); - final CookieManagerHostApiImpl hostApi = - new CookieManagerHostApiImpl(mockBinaryMessenger, instanceManager); + final CookieManager instance = mock(CookieManager.class); + final String url = "myString"; + final String value = "myString2"; + api.setCookie(instance, url, value); - hostApi.setCookie(instanceIdentifier, url, value); - - verify(mockCookieManager).setCookie(url, value); + verify(instance).setCookie(url, value); } - @SuppressWarnings({"rawtypes", "unchecked"}) @Test - public void clearCookies() { - final long instanceIdentifier = 0; - instanceManager.addDartCreatedInstance(mockCookieManager, instanceIdentifier); + public void removeAllCookies() { + final PigeonApiCookieManager api = new TestProxyApiRegistrar().getPigeonApiCookieManager(); - final CookieManagerHostApiImpl hostApi = - new CookieManagerHostApiImpl( - mockBinaryMessenger, - instanceManager, - new CookieManagerHostApiImpl.CookieManagerProxy(), - (int version) -> version <= Build.VERSION_CODES.LOLLIPOP); + final CookieManager instance = mock(CookieManager.class); final Boolean[] successResult = new Boolean[1]; - hostApi.removeAllCookies( - instanceIdentifier, - new GeneratedAndroidWebView.Result() { - @Override - public void success(Boolean result) { - successResult[0] = result; - } - - @Override - public void error(@NonNull Throwable error) {} - }); - - final ArgumentCaptor valueCallbackArgumentCaptor = + api.removeAllCookies( + instance, + ResultCompat.asCompatCallback( + reply -> { + successResult[0] = reply.getOrNull(); + return null; + })); + + @SuppressWarnings("unchecked") + final ArgumentCaptor> valueCallbackArgumentCaptor = ArgumentCaptor.forClass(ValueCallback.class); - verify(mockCookieManager).removeAllCookies(valueCallbackArgumentCaptor.capture()); + verify(instance).removeAllCookies(valueCallbackArgumentCaptor.capture()); final Boolean returnValue = true; valueCallbackArgumentCaptor.getValue().onReceiveValue(returnValue); @@ -109,24 +55,13 @@ public void error(@NonNull Throwable error) {} @Test public void setAcceptThirdPartyCookies() { - final WebView mockWebView = mock(WebView.class); - final long webViewIdentifier = 4; - instanceManager.addDartCreatedInstance(mockWebView, webViewIdentifier); + final PigeonApiCookieManager api = new TestProxyApiRegistrar().getPigeonApiCookieManager(); + final CookieManager instance = mock(CookieManager.class); + final android.webkit.WebView webView = mock(WebView.class); final boolean accept = true; + api.setAcceptThirdPartyCookies(instance, webView, accept); - final long instanceIdentifier = 0; - instanceManager.addDartCreatedInstance(mockCookieManager, instanceIdentifier); - - final CookieManagerHostApiImpl hostApi = - new CookieManagerHostApiImpl( - mockBinaryMessenger, - instanceManager, - new CookieManagerHostApiImpl.CookieManagerProxy(), - (int version) -> version <= Build.VERSION_CODES.LOLLIPOP); - - hostApi.setAcceptThirdPartyCookies(instanceIdentifier, webViewIdentifier, accept); - - verify(mockCookieManager).setAcceptThirdPartyCookies(mockWebView, accept); + verify(instance).setAcceptThirdPartyCookies(webView, accept); } } diff --git a/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/CustomViewCallbackTest.java b/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/CustomViewCallbackTest.java index 3a633999532d..8e37e1b9bf3e 100644 --- a/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/CustomViewCallbackTest.java +++ b/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/CustomViewCallbackTest.java @@ -4,68 +4,21 @@ package io.flutter.plugins.webviewflutter; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import android.webkit.WebChromeClient.CustomViewCallback; -import io.flutter.plugin.common.BinaryMessenger; -import io.flutter.plugins.webviewflutter.GeneratedAndroidWebView.CustomViewCallbackFlutterApi; -import java.util.Objects; -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; import org.junit.Test; -import org.mockito.Mock; -import org.mockito.junit.MockitoJUnit; -import org.mockito.junit.MockitoRule; public class CustomViewCallbackTest { - - @Rule public MockitoRule mockitoRule = MockitoJUnit.rule(); - - @Mock public CustomViewCallback mockCustomViewCallback; - - @Mock public BinaryMessenger mockBinaryMessenger; - - @Mock public CustomViewCallbackFlutterApi mockFlutterApi; - - InstanceManager instanceManager; - - @Before - public void setUp() { - instanceManager = InstanceManager.create(identifier -> {}); - } - - @After - public void tearDown() { - instanceManager.stopFinalizationListener(); - } - @Test public void onCustomViewHidden() { - final long instanceIdentifier = 0; - instanceManager.addDartCreatedInstance(mockCustomViewCallback, instanceIdentifier); - - final CustomViewCallbackHostApiImpl hostApi = - new CustomViewCallbackHostApiImpl(mockBinaryMessenger, instanceManager); - - hostApi.onCustomViewHidden(instanceIdentifier); - - verify(mockCustomViewCallback).onCustomViewHidden(); - } - - @Test - public void flutterApiCreate() { - final CustomViewCallbackFlutterApiImpl flutterApi = - new CustomViewCallbackFlutterApiImpl(mockBinaryMessenger, instanceManager); - flutterApi.setApi(mockFlutterApi); + final PigeonApiCustomViewCallback api = + new TestProxyApiRegistrar().getPigeonApiCustomViewCallback(); - flutterApi.create(mockCustomViewCallback, reply -> {}); + final CustomViewCallback instance = mock(CustomViewCallback.class); + api.onCustomViewHidden(instance); - final long instanceIdentifier = - Objects.requireNonNull( - instanceManager.getIdentifierForStrongReference(mockCustomViewCallback)); - verify(mockFlutterApi).create(eq(instanceIdentifier), any()); + verify(instance).onCustomViewHidden(); } } diff --git a/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/DownloadListenerTest.java b/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/DownloadListenerTest.java index ae0029648eba..2055d6fe488b 100644 --- a/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/DownloadListenerTest.java +++ b/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/DownloadListenerTest.java @@ -4,65 +4,47 @@ package io.flutter.plugins.webviewflutter; +import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; -import io.flutter.plugins.webviewflutter.DownloadListenerHostApiImpl.DownloadListenerCreator; -import io.flutter.plugins.webviewflutter.DownloadListenerHostApiImpl.DownloadListenerImpl; -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; +import io.flutter.plugins.webviewflutter.DownloadListenerProxyApi.DownloadListenerImpl; import org.junit.Test; -import org.mockito.Mock; -import org.mockito.junit.MockitoJUnit; -import org.mockito.junit.MockitoRule; public class DownloadListenerTest { - @Rule public MockitoRule mockitoRule = MockitoJUnit.rule(); - - @Mock public DownloadListenerFlutterApiImpl mockFlutterApi; - - InstanceManager instanceManager; - DownloadListenerHostApiImpl hostApiImpl; - DownloadListenerImpl downloadListener; - - @Before - public void setUp() { - instanceManager = InstanceManager.create(identifier -> {}); - - final DownloadListenerCreator downloadListenerCreator = - new DownloadListenerCreator() { - @Override - public DownloadListenerImpl createDownloadListener( - DownloadListenerFlutterApiImpl flutterApi) { - downloadListener = super.createDownloadListener(flutterApi); - return downloadListener; - } - }; - - hostApiImpl = - new DownloadListenerHostApiImpl(instanceManager, downloadListenerCreator, mockFlutterApi); - hostApiImpl.create(0L); - } + @Test + public void pigeon_defaultConstructor() { + final PigeonApiDownloadListener api = + new TestProxyApiRegistrar().getPigeonApiDownloadListener(); - @After - public void tearDown() { - instanceManager.stopFinalizationListener(); + assertTrue( + api.pigeon_defaultConstructor() instanceof DownloadListenerProxyApi.DownloadListenerImpl); } @Test - public void postMessage() { - downloadListener.onDownloadStart( - "https://www.google.com", "userAgent", "contentDisposition", "mimetype", 54); - verify(mockFlutterApi) + public void onDownloadStart() { + final DownloadListenerProxyApi mockApi = mock(DownloadListenerProxyApi.class); + when(mockApi.getPigeonRegistrar()).thenReturn(new TestProxyApiRegistrar()); + + final DownloadListenerImpl instance = new DownloadListenerImpl(mockApi); + final String url = "myString"; + final String userAgent = "myString1"; + final String contentDisposition = "myString2"; + final String mimetype = "myString3"; + final Long contentLength = 0L; + instance.onDownloadStart(url, userAgent, contentDisposition, mimetype, contentLength); + + verify(mockApi) .onDownloadStart( - eq(downloadListener), - eq("https://www.google.com"), - eq("userAgent"), - eq("contentDisposition"), - eq("mimetype"), - eq(54L), + eq(instance), + eq(url), + eq(userAgent), + eq(contentDisposition), + eq(mimetype), + eq(contentLength), any()); } } diff --git a/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/FileChooserParamsTest.java b/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/FileChooserParamsTest.java index 412b48671e8d..1b9fdf40540d 100644 --- a/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/FileChooserParamsTest.java +++ b/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/FileChooserParamsTest.java @@ -5,69 +5,60 @@ package io.flutter.plugins.webviewflutter; import static org.junit.Assert.assertEquals; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import android.webkit.WebChromeClient.FileChooserParams; -import io.flutter.plugin.common.BinaryMessenger; -import java.util.Arrays; -import java.util.Objects; -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; +import java.util.Collections; +import java.util.List; import org.junit.Test; -import org.mockito.ArgumentCaptor; -import org.mockito.Mock; -import org.mockito.junit.MockitoJUnit; -import org.mockito.junit.MockitoRule; public class FileChooserParamsTest { - @Rule public MockitoRule mockitoRule = MockitoJUnit.rule(); + @Test + public void isCaptureEnabled() { + final PigeonApiFileChooserParams api = + new TestProxyApiRegistrar().getPigeonApiFileChooserParams(); - @Mock public FileChooserParams mockFileChooserParams; + final FileChooserParams instance = mock(FileChooserParams.class); + final Boolean value = true; + when(instance.isCaptureEnabled()).thenReturn(value); - @Mock public BinaryMessenger mockBinaryMessenger; + assertEquals(value, api.isCaptureEnabled(instance)); + } - InstanceManager instanceManager; + @Test + public void acceptTypes() { + final PigeonApiFileChooserParams api = + new TestProxyApiRegistrar().getPigeonApiFileChooserParams(); - @Before - public void setUp() { - instanceManager = InstanceManager.create(identifier -> {}); - } + final FileChooserParams instance = mock(FileChooserParams.class); + final List value = Collections.singletonList("myString"); + when(instance.getAcceptTypes()).thenReturn(value.toArray(new String[0])); - @After - public void tearDown() { - instanceManager.stopFinalizationListener(); + assertEquals(value, api.acceptTypes(instance)); } @Test - public void flutterApiCreate() { - final FileChooserParamsFlutterApiImpl spyFlutterApi = - spy(new FileChooserParamsFlutterApiImpl(mockBinaryMessenger, instanceManager)); + public void mode() { + final PigeonApiFileChooserParams api = + new TestProxyApiRegistrar().getPigeonApiFileChooserParams(); - when(mockFileChooserParams.isCaptureEnabled()).thenReturn(true); - when(mockFileChooserParams.getAcceptTypes()).thenReturn(new String[] {"my", "list"}); - when(mockFileChooserParams.getMode()).thenReturn(FileChooserParams.MODE_OPEN_MULTIPLE); - when(mockFileChooserParams.getFilenameHint()).thenReturn("filenameHint"); - spyFlutterApi.create(mockFileChooserParams, reply -> {}); + final FileChooserParams instance = mock(FileChooserParams.class); + final FileChooserMode value = io.flutter.plugins.webviewflutter.FileChooserMode.OPEN; + when(instance.getMode()).thenReturn(FileChooserParams.MODE_OPEN); + + assertEquals(value, api.mode(instance)); + } + + @Test + public void filenameHint() { + final PigeonApiFileChooserParams api = + new TestProxyApiRegistrar().getPigeonApiFileChooserParams(); - final long identifier = - Objects.requireNonNull( - instanceManager.getIdentifierForStrongReference(mockFileChooserParams)); - final ArgumentCaptor modeCaptor = - ArgumentCaptor.forClass(GeneratedAndroidWebView.FileChooserMode.class); + final FileChooserParams instance = mock(FileChooserParams.class); + final String value = "myString"; + when(instance.getFilenameHint()).thenReturn(value); - verify(spyFlutterApi) - .create( - eq(identifier), - eq(true), - eq(Arrays.asList("my", "list")), - modeCaptor.capture(), - eq("filenameHint"), - any()); - assertEquals(modeCaptor.getValue(), GeneratedAndroidWebView.FileChooserMode.OPEN_MULTIPLE); + assertEquals(value, api.filenameHint(instance)); } } diff --git a/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/FlutterAssetManagerHostApiImplTest.java b/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/FlutterAssetManagerHostApiImplTest.java deleted file mode 100644 index f530365a9334..000000000000 --- a/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/FlutterAssetManagerHostApiImplTest.java +++ /dev/null @@ -1,76 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -package io.flutter.plugins.webviewflutter; - -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import java.io.IOException; -import java.util.List; -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mock; - -public class FlutterAssetManagerHostApiImplTest { - @Mock FlutterAssetManager mockFlutterAssetManager; - - FlutterAssetManagerHostApiImpl testFlutterAssetManagerHostApiImpl; - - @Before - public void setUp() { - mockFlutterAssetManager = mock(FlutterAssetManager.class); - - testFlutterAssetManagerHostApiImpl = - new FlutterAssetManagerHostApiImpl(mockFlutterAssetManager); - } - - @Test - public void list() { - try { - when(mockFlutterAssetManager.list("test/path")) - .thenReturn(new String[] {"index.html", "styles.css"}); - List actualFilePaths = testFlutterAssetManagerHostApiImpl.list("test/path"); - verify(mockFlutterAssetManager).list("test/path"); - assertArrayEquals(new String[] {"index.html", "styles.css"}, actualFilePaths.toArray()); - } catch (IOException ex) { - fail(); - } - } - - @Test - public void list_returns_empty_list_when_no_results() { - try { - when(mockFlutterAssetManager.list("test/path")).thenReturn(null); - List actualFilePaths = testFlutterAssetManagerHostApiImpl.list("test/path"); - verify(mockFlutterAssetManager).list("test/path"); - assertArrayEquals(new String[] {}, actualFilePaths.toArray()); - } catch (IOException ex) { - fail(); - } - } - - @Test(expected = RuntimeException.class) - public void list_should_convert_io_exception_to_runtime_exception() { - try { - when(mockFlutterAssetManager.list("test/path")).thenThrow(new IOException()); - testFlutterAssetManagerHostApiImpl.list("test/path"); - } catch (IOException ex) { - fail(); - } - } - - @Test - public void getAssetFilePathByName() { - when(mockFlutterAssetManager.getAssetFilePathByName("index.html")) - .thenReturn("flutter_assets/index.html"); - String filePath = testFlutterAssetManagerHostApiImpl.getAssetFilePathByName("index.html"); - verify(mockFlutterAssetManager).getAssetFilePathByName("index.html"); - assertEquals("flutter_assets/index.html", filePath); - } -} diff --git a/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/FlutterAssetManagerTest.java b/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/FlutterAssetManagerTest.java new file mode 100644 index 000000000000..e51545db777b --- /dev/null +++ b/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/FlutterAssetManagerTest.java @@ -0,0 +1,71 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +package io.flutter.plugins.webviewflutter; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import java.io.IOException; +import java.util.Collections; +import java.util.List; +import org.junit.Test; + +public class FlutterAssetManagerTest { + @Test + public void list() throws IOException { + final PigeonApiFlutterAssetManager api = + new TestProxyApiRegistrar().getPigeonApiFlutterAssetManager(); + + final FlutterAssetManager instance = mock(FlutterAssetManager.class); + final String path = "myString"; + final List value = Collections.singletonList("myString"); + when(instance.list(path)).thenReturn(value.toArray(new String[0])); + + assertEquals(value, api.list(instance, path)); + } + + @Test + public void list_returns_empty_list_when_no_results() throws IOException { + final PigeonApiFlutterAssetManager api = + new TestProxyApiRegistrar().getPigeonApiFlutterAssetManager(); + + final FlutterAssetManager instance = mock(FlutterAssetManager.class); + final String path = "myString"; + when(instance.list(path)).thenReturn(null); + + assertEquals(Collections.emptyList(), api.list(instance, path)); + } + + @Test(expected = RuntimeException.class) + public void list_should_convert_io_exception_to_runtime_exception() { + final PigeonApiFlutterAssetManager api = + new TestProxyApiRegistrar().getPigeonApiFlutterAssetManager(); + + final FlutterAssetManager instance = mock(FlutterAssetManager.class); + final String path = "test/path"; + + try { + when(instance.list(path)).thenThrow(new IOException()); + api.list(instance, "test/path"); + } catch (IOException e) { + fail(); + } + } + + @Test + public void getAssetFilePathByName() { + final PigeonApiFlutterAssetManager api = + new TestProxyApiRegistrar().getPigeonApiFlutterAssetManager(); + + final FlutterAssetManager instance = mock(FlutterAssetManager.class); + final String name = "myString"; + final String value = "myString1"; + when(instance.getAssetFilePathByName(name)).thenReturn(value); + + assertEquals(value, api.getAssetFilePathByName(instance, name)); + } +} diff --git a/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/GeolocationPermissionsCallbackTest.java b/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/GeolocationPermissionsCallbackTest.java index 14f8e15bf864..de254e31d549 100644 --- a/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/GeolocationPermissionsCallbackTest.java +++ b/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/GeolocationPermissionsCallbackTest.java @@ -4,71 +4,24 @@ package io.flutter.plugins.webviewflutter; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import android.webkit.GeolocationPermissions; -import io.flutter.plugin.common.BinaryMessenger; -import io.flutter.plugins.webviewflutter.GeneratedAndroidWebView.GeolocationPermissionsCallbackFlutterApi; -import java.util.Objects; -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; import org.junit.Test; -import org.mockito.Mock; -import org.mockito.junit.MockitoJUnit; -import org.mockito.junit.MockitoRule; public class GeolocationPermissionsCallbackTest { - @Rule public MockitoRule mockitoRule = MockitoJUnit.rule(); - - @Mock public GeolocationPermissions.Callback mockGeolocationPermissionsCallback; - - @Mock public BinaryMessenger mockBinaryMessenger; - - @Mock public GeolocationPermissionsCallbackFlutterApi mockFlutterApi; - - InstanceManager instanceManager; - - @Before - public void setUp() { - instanceManager = InstanceManager.create(identifier -> {}); - } - - @After - public void tearDown() { - instanceManager.stopFinalizationListener(); - } - @Test public void invoke() { - final String origin = "testString"; - final boolean allow = true; - final boolean retain = true; - - final long instanceIdentifier = 0; - instanceManager.addDartCreatedInstance(mockGeolocationPermissionsCallback, instanceIdentifier); - - final GeolocationPermissionsCallbackHostApiImpl hostApi = - new GeolocationPermissionsCallbackHostApiImpl(mockBinaryMessenger, instanceManager); + final PigeonApiGeolocationPermissionsCallback api = + new TestProxyApiRegistrar().getPigeonApiGeolocationPermissionsCallback(); - hostApi.invoke(instanceIdentifier, origin, allow, retain); - - verify(mockGeolocationPermissionsCallback).invoke(origin, allow, retain); - } - - @Test - public void flutterApiCreate() { - final GeolocationPermissionsCallbackFlutterApiImpl flutterApi = - new GeolocationPermissionsCallbackFlutterApiImpl(mockBinaryMessenger, instanceManager); - flutterApi.setApi(mockFlutterApi); - - flutterApi.create(mockGeolocationPermissionsCallback, reply -> {}); + final GeolocationPermissions.Callback instance = mock(GeolocationPermissions.Callback.class); + final String origin = "myString"; + final boolean allow = true; + final boolean retain = false; + api.invoke(instance, origin, allow, retain); - final long instanceIdentifier = - Objects.requireNonNull( - instanceManager.getIdentifierForStrongReference(mockGeolocationPermissionsCallback)); - verify(mockFlutterApi).create(eq(instanceIdentifier), any()); + verify(instance).invoke(origin, allow, retain); } } diff --git a/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/HttpAuthHandlerTest.java b/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/HttpAuthHandlerTest.java index a66f41bd292a..9fbc95669c62 100644 --- a/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/HttpAuthHandlerTest.java +++ b/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/HttpAuthHandlerTest.java @@ -4,73 +4,45 @@ package io.flutter.plugins.webviewflutter; -import static org.mockito.ArgumentMatchers.eq; +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; import android.webkit.HttpAuthHandler; -import io.flutter.plugin.common.BinaryMessenger; -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; import org.junit.Test; -import org.mockito.Mock; -import org.mockito.junit.MockitoJUnit; -import org.mockito.junit.MockitoRule; public class HttpAuthHandlerTest { - @Rule public MockitoRule mockitoRule = MockitoJUnit.rule(); - - @Mock HttpAuthHandler mockAuthHandler; - - @Mock BinaryMessenger mockBinaryMessenger; - - InstanceManager instanceManager; - - @Before - public void setUp() { - instanceManager = InstanceManager.create(identifier -> {}); - } - - @After - public void tearDown() { - instanceManager.stopFinalizationListener(); - } - @Test public void proceed() { - final HttpAuthHandlerHostApiImpl hostApi = - new HttpAuthHandlerHostApiImpl(mockBinaryMessenger, instanceManager); - final long instanceIdentifier = 65L; - final String username = "username"; - final String password = "password"; - instanceManager.addDartCreatedInstance(mockAuthHandler, instanceIdentifier); + final PigeonApiHttpAuthHandler api = new TestProxyApiRegistrar().getPigeonApiHttpAuthHandler(); - hostApi.proceed(instanceIdentifier, username, password); + final HttpAuthHandler instance = mock(HttpAuthHandler.class); + final String username = "myString"; + final String password = "myString1"; + api.proceed(instance, username, password); - verify(mockAuthHandler).proceed(eq(username), eq(password)); + verify(instance).proceed(username, password); } @Test public void cancel() { - final HttpAuthHandlerHostApiImpl hostApi = - new HttpAuthHandlerHostApiImpl(mockBinaryMessenger, instanceManager); - final long instanceIdentifier = 65L; - instanceManager.addDartCreatedInstance(mockAuthHandler, instanceIdentifier); + final PigeonApiHttpAuthHandler api = new TestProxyApiRegistrar().getPigeonApiHttpAuthHandler(); - hostApi.cancel(instanceIdentifier); + final HttpAuthHandler instance = mock(HttpAuthHandler.class); + api.cancel(instance); - verify(mockAuthHandler).cancel(); + verify(instance).cancel(); } @Test public void useHttpAuthUsernamePassword() { - final HttpAuthHandlerHostApiImpl hostApi = - new HttpAuthHandlerHostApiImpl(mockBinaryMessenger, instanceManager); - final long instanceIdentifier = 65L; - instanceManager.addDartCreatedInstance(mockAuthHandler, instanceIdentifier); + final PigeonApiHttpAuthHandler api = new TestProxyApiRegistrar().getPigeonApiHttpAuthHandler(); - hostApi.useHttpAuthUsernamePassword(instanceIdentifier); + final HttpAuthHandler instance = mock(HttpAuthHandler.class); + final Boolean value = true; + when(instance.useHttpAuthUsernamePassword()).thenReturn(value); - verify(mockAuthHandler).useHttpAuthUsernamePassword(); + assertEquals(value, api.useHttpAuthUsernamePassword(instance)); } } diff --git a/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/InstanceManagerTest.java b/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/InstanceManagerTest.java deleted file mode 100644 index 2f2ea7769ddd..000000000000 --- a/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/InstanceManagerTest.java +++ /dev/null @@ -1,140 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -package io.flutter.plugins.webviewflutter; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; - -import org.junit.Test; - -public class InstanceManagerTest { - @Test - public void addDartCreatedInstance() { - final InstanceManager instanceManager = InstanceManager.create(identifier -> {}); - - final Object object = new Object(); - instanceManager.addDartCreatedInstance(object, 0); - - assertEquals(object, instanceManager.getInstance(0)); - assertEquals((Long) 0L, instanceManager.getIdentifierForStrongReference(object)); - assertTrue(instanceManager.containsInstance(object)); - - instanceManager.stopFinalizationListener(); - } - - @Test - public void addHostCreatedInstance() { - final InstanceManager instanceManager = InstanceManager.create(identifier -> {}); - - final Object object = new Object(); - long identifier = instanceManager.addHostCreatedInstance(object); - - assertNotNull(instanceManager.getInstance(identifier)); - assertEquals(object, instanceManager.getInstance(identifier)); - assertTrue(instanceManager.containsInstance(object)); - - instanceManager.stopFinalizationListener(); - } - - @Test - public void remove() { - final InstanceManager instanceManager = InstanceManager.create(identifier -> {}); - - Object object = new Object(); - instanceManager.addDartCreatedInstance(object, 0); - - assertEquals(object, instanceManager.remove(0)); - - // To allow for object to be garbage collected. - //noinspection UnusedAssignment - object = null; - - Runtime.getRuntime().gc(); - - assertNull(instanceManager.getInstance(0)); - - instanceManager.stopFinalizationListener(); - } - - @Test - public void clear() { - final InstanceManager instanceManager = InstanceManager.create(identifier -> {}); - - final Object instance = new Object(); - - instanceManager.addDartCreatedInstance(instance, 0); - assertTrue(instanceManager.containsInstance(instance)); - - instanceManager.clear(); - assertFalse(instanceManager.containsInstance(instance)); - - instanceManager.stopFinalizationListener(); - } - - @Test - public void canAddSameObjectWithAddDartCreatedInstance() { - final InstanceManager instanceManager = InstanceManager.create(identifier -> {}); - - final Object instance = new Object(); - - instanceManager.addDartCreatedInstance(instance, 0); - instanceManager.addDartCreatedInstance(instance, 1); - - assertTrue(instanceManager.containsInstance(instance)); - - assertEquals(instanceManager.getInstance(0), instance); - assertEquals(instanceManager.getInstance(1), instance); - - instanceManager.stopFinalizationListener(); - } - - @Test(expected = IllegalArgumentException.class) - public void cannotAddSameObjectsWithAddHostCreatedInstance() { - final InstanceManager instanceManager = InstanceManager.create(identifier -> {}); - - final Object instance = new Object(); - - instanceManager.addHostCreatedInstance(instance); - instanceManager.addHostCreatedInstance(instance); - - instanceManager.stopFinalizationListener(); - } - - @Test(expected = IllegalArgumentException.class) - public void cannotUseIdentifierLessThanZero() { - final InstanceManager instanceManager = InstanceManager.create(identifier -> {}); - - instanceManager.addDartCreatedInstance(new Object(), -1); - - instanceManager.stopFinalizationListener(); - } - - @Test(expected = IllegalArgumentException.class) - public void identifiersMustBeUnique() { - final InstanceManager instanceManager = InstanceManager.create(identifier -> {}); - - instanceManager.addDartCreatedInstance(new Object(), 0); - instanceManager.addDartCreatedInstance(new Object(), 0); - - instanceManager.stopFinalizationListener(); - } - - @Test - public void managerIsUsableWhileListenerHasStopped() { - final InstanceManager instanceManager = InstanceManager.create(identifier -> {}); - instanceManager.stopFinalizationListener(); - - final Object instance = new Object(); - final long identifier = 0; - - instanceManager.addDartCreatedInstance(instance, identifier); - assertEquals(instanceManager.getInstance(identifier), instance); - assertEquals(instanceManager.getIdentifierForStrongReference(instance), (Long) identifier); - assertTrue(instanceManager.containsInstance(instance)); - } -} diff --git a/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/JavaObjectHostApiTest.java b/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/JavaObjectHostApiTest.java deleted file mode 100644 index 88c759d10829..000000000000 --- a/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/JavaObjectHostApiTest.java +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -package io.flutter.plugins.webviewflutter; - -import static org.junit.Assert.assertNull; - -import org.junit.Test; - -public class JavaObjectHostApiTest { - @Test - public void dispose() { - final InstanceManager instanceManager = InstanceManager.create(identifier -> {}); - - final JavaObjectHostApiImpl hostApi = new JavaObjectHostApiImpl(instanceManager); - - Object object = new Object(); - instanceManager.addDartCreatedInstance(object, 0); - - // To free object for garbage collection. - //noinspection UnusedAssignment - object = null; - - hostApi.dispose(0L); - Runtime.getRuntime().gc(); - - assertNull(instanceManager.getInstance(0)); - - instanceManager.stopFinalizationListener(); - } -} diff --git a/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/JavaScriptChannelTest.java b/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/JavaScriptChannelTest.java index 0c9647a8cb9c..b0d201fe8a08 100644 --- a/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/JavaScriptChannelTest.java +++ b/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/JavaScriptChannelTest.java @@ -6,63 +6,22 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; -import android.os.Handler; -import android.os.Looper; -import io.flutter.plugins.webviewflutter.JavaScriptChannelHostApiImpl.JavaScriptChannelCreator; -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; import org.junit.Test; -import org.mockito.Mock; -import org.mockito.junit.MockitoJUnit; -import org.mockito.junit.MockitoRule; public class JavaScriptChannelTest { - @Rule public MockitoRule mockitoRule = MockitoJUnit.rule(); - - @Mock public JavaScriptChannelFlutterApiImpl mockFlutterApi; - - InstanceManager instanceManager; - JavaScriptChannelHostApiImpl hostApiImpl; - JavaScriptChannel javaScriptChannel; - - @Before - public void setUp() { - instanceManager = InstanceManager.create(identifier -> {}); - - final JavaScriptChannelCreator javaScriptChannelCreator = - new JavaScriptChannelCreator() { - @Override - public JavaScriptChannel createJavaScriptChannel( - JavaScriptChannelFlutterApiImpl javaScriptChannelFlutterApi, - String channelName, - Handler platformThreadHandler) { - javaScriptChannel = - super.createJavaScriptChannel( - javaScriptChannelFlutterApi, channelName, platformThreadHandler); - return javaScriptChannel; - } - }; - - hostApiImpl = - new JavaScriptChannelHostApiImpl( - instanceManager, - javaScriptChannelCreator, - mockFlutterApi, - new Handler(Looper.myLooper())); - hostApiImpl.create(0L, "aChannelName"); - } - - @After - public void tearDown() { - instanceManager.stopFinalizationListener(); - } - @Test public void postMessage() { - javaScriptChannel.postMessage("A message post."); - verify(mockFlutterApi).postMessage(eq(javaScriptChannel), eq("A message post."), any()); + final JavaScriptChannelProxyApi mockApi = mock(JavaScriptChannelProxyApi.class); + when(mockApi.getPigeonRegistrar()).thenReturn(new TestProxyApiRegistrar()); + + final JavaScriptChannel instance = new JavaScriptChannel("channel", mockApi); + final String message = "myString"; + instance.postMessage(message); + + verify(mockApi).postMessage(eq(instance), eq(message), any()); } } diff --git a/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/PermissionRequestTest.java b/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/PermissionRequestTest.java index 8e7756936c80..9bd406106f05 100644 --- a/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/PermissionRequestTest.java +++ b/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/PermissionRequestTest.java @@ -5,47 +5,17 @@ package io.flutter.plugins.webviewflutter; import static org.junit.Assert.assertEquals; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; import android.webkit.PermissionRequest; -import io.flutter.plugin.common.BinaryMessenger; import java.util.Collections; import java.util.List; -import java.util.Objects; -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; import org.junit.Test; -import org.mockito.Mock; -import org.mockito.junit.MockitoJUnit; -import org.mockito.junit.MockitoRule; public class PermissionRequestTest { - @Rule public MockitoRule mockitoRule = MockitoJUnit.rule(); - - @Mock public PermissionRequest mockPermissionRequest; - - @Mock public BinaryMessenger mockBinaryMessenger; - - @Mock - public io.flutter.plugins.webviewflutter.GeneratedAndroidWebView.PermissionRequestFlutterApi - mockFlutterApi; - - InstanceManager instanceManager; - - @Before - public void setUp() { - instanceManager = InstanceManager.create(identifier -> {}); - } - - @After - public void tearDown() { - instanceManager.stopFinalizationListener(); - } - - // These values MUST equal the constants for the Dart PermissionRequest class. + // These values MUST equal the constants for the Dart PermissionRequestConstants class. @Test public void enums() { assertEquals(PermissionRequest.RESOURCE_AUDIO_CAPTURE, "android.webkit.resource.AUDIO_CAPTURE"); @@ -58,47 +28,37 @@ public void enums() { @Test public void grant() { + final PigeonApiPermissionRequest api = + new TestProxyApiRegistrar().getPigeonApiPermissionRequest(); + + final PermissionRequest instance = mock(PermissionRequest.class); final List resources = Collections.singletonList(PermissionRequest.RESOURCE_AUDIO_CAPTURE); + api.grant(instance, resources); - final long instanceIdentifier = 0; - instanceManager.addDartCreatedInstance(mockPermissionRequest, instanceIdentifier); - - final PermissionRequestHostApiImpl hostApi = - new PermissionRequestHostApiImpl(mockBinaryMessenger, instanceManager); - - hostApi.grant(instanceIdentifier, resources); - - verify(mockPermissionRequest).grant(new String[] {PermissionRequest.RESOURCE_AUDIO_CAPTURE}); + verify(instance).grant(new String[] {PermissionRequest.RESOURCE_AUDIO_CAPTURE}); } @Test public void deny() { - final long instanceIdentifier = 0; - instanceManager.addDartCreatedInstance(mockPermissionRequest, instanceIdentifier); + final PigeonApiPermissionRequest api = + new TestProxyApiRegistrar().getPigeonApiPermissionRequest(); - final PermissionRequestHostApiImpl hostApi = - new PermissionRequestHostApiImpl(mockBinaryMessenger, instanceManager); + final PermissionRequest instance = mock(PermissionRequest.class); + api.deny(instance); - hostApi.deny(instanceIdentifier); - - verify(mockPermissionRequest).deny(); + verify(instance).deny(); } @Test - public void flutterApiCreate() { - final PermissionRequestFlutterApiImpl flutterApi = - new PermissionRequestFlutterApiImpl(mockBinaryMessenger, instanceManager); - flutterApi.setApi(mockFlutterApi); - - final List resources = - Collections.singletonList(PermissionRequest.RESOURCE_AUDIO_CAPTURE); + public void resources() { + final PigeonApiPermissionRequest api = + new TestProxyApiRegistrar().getPigeonApiPermissionRequest(); - flutterApi.create(mockPermissionRequest, resources.toArray(new String[0]), reply -> {}); + final PermissionRequest instance = mock(PermissionRequest.class); + final List value = Collections.singletonList(PermissionRequest.RESOURCE_AUDIO_CAPTURE); + when(instance.getResources()).thenReturn(value.toArray(new String[0])); - final long instanceIdentifier = - Objects.requireNonNull( - instanceManager.getIdentifierForStrongReference(mockPermissionRequest)); - verify(mockFlutterApi).create(eq(instanceIdentifier), eq(resources), any()); + assertEquals(value, api.resources(instance)); } } diff --git a/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/TestProxyApiRegistrar.java b/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/TestProxyApiRegistrar.java new file mode 100644 index 000000000000..b77be19ea19d --- /dev/null +++ b/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/TestProxyApiRegistrar.java @@ -0,0 +1,30 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +package io.flutter.plugins.webviewflutter; + +import static org.mockito.Mockito.mock; + +import android.content.Context; +import io.flutter.plugin.common.BinaryMessenger; + +/** + * Test implementation of `ProxyApiRegistrar` that provides mocks, instantly runs callbacks instead + * of posting them, and makes all SDK checks pass by default. + */ +public class TestProxyApiRegistrar extends ProxyApiRegistrar { + public TestProxyApiRegistrar() { + super(mock(BinaryMessenger.class), mock(Context.class), mock(FlutterAssetManager.class)); + } + + @Override + void runOnMainThread(Runnable runnable) { + runnable.run(); + } + + @Override + boolean sdkIsAtLeast(int version) { + return true; + } +} diff --git a/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/ViewTest.java b/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/ViewTest.java index 3019900d6618..2ae41983d44e 100644 --- a/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/ViewTest.java +++ b/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/ViewTest.java @@ -4,54 +4,49 @@ package io.flutter.plugins.webviewflutter; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.eq; +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; import android.view.View; -import io.flutter.plugin.common.BinaryMessenger; -import io.flutter.plugins.webviewflutter.GeneratedAndroidWebView.ViewFlutterApi; -import java.util.Objects; -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; import org.junit.Test; -import org.mockito.Mock; -import org.mockito.junit.MockitoJUnit; -import org.mockito.junit.MockitoRule; public class ViewTest { + @Test + public void scrollTo() { + final PigeonApiView api = new TestProxyApiRegistrar().getPigeonApiView(); - @Rule public MockitoRule mockitoRule = MockitoJUnit.rule(); - - @Mock public View mockView; - - @Mock public BinaryMessenger mockBinaryMessenger; + final View instance = mock(View.class); + final long x = 0L; + final long y = 1L; + api.scrollTo(instance, x, y); - @Mock public ViewFlutterApi mockFlutterApi; + verify(instance).scrollTo((int) x, (int) y); + } - InstanceManager instanceManager; + @Test + public void scrollBy() { + final PigeonApiView api = new TestProxyApiRegistrar().getPigeonApiView(); - @Before - public void setUp() { - instanceManager = InstanceManager.create(identifier -> {}); - } + final View instance = mock(View.class); + final long x = 0L; + final long y = 1L; + api.scrollBy(instance, x, y); - @After - public void tearDown() { - instanceManager.stopFinalizationListener(); + verify(instance).scrollBy((int) x, (int) y); } @Test - public void flutterApiCreate() { - final ViewFlutterApiImpl flutterApi = - new ViewFlutterApiImpl(mockBinaryMessenger, instanceManager); - flutterApi.setApi(mockFlutterApi); + public void getScrollPosition() { + final PigeonApiView api = new TestProxyApiRegistrar().getPigeonApiView(); - flutterApi.create(mockView, reply -> {}); + final View instance = mock(View.class); + final WebViewPoint value = new WebViewPoint(0L, 1L); + when(instance.getScrollX()).thenReturn((int) value.getX()); + when(instance.getScrollY()).thenReturn((int) value.getY()); - final long instanceIdentifier = - Objects.requireNonNull(instanceManager.getIdentifierForStrongReference(mockView)); - verify(mockFlutterApi).create(eq(instanceIdentifier), any()); + assertEquals(value.getX(), api.getScrollPosition(instance).getX()); + assertEquals(value.getY(), api.getScrollPosition(instance).getY()); } } diff --git a/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/WebChromeClientTest.java b/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/WebChromeClientTest.java index ef49dded9b56..168743d1130c 100644 --- a/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/WebChromeClientTest.java +++ b/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/WebChromeClientTest.java @@ -18,66 +18,30 @@ import android.view.View; import android.webkit.ConsoleMessage; import android.webkit.GeolocationPermissions; +import android.webkit.JsPromptResult; +import android.webkit.JsResult; import android.webkit.PermissionRequest; import android.webkit.WebChromeClient; import android.webkit.WebResourceRequest; import android.webkit.WebView; import android.webkit.WebView.WebViewTransport; import android.webkit.WebViewClient; -import androidx.annotation.NonNull; -import io.flutter.plugins.webviewflutter.WebChromeClientHostApiImpl.WebChromeClientCreator; -import io.flutter.plugins.webviewflutter.WebChromeClientHostApiImpl.WebChromeClientImpl; -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; +import io.flutter.plugins.webviewflutter.WebChromeClientProxyApi.WebChromeClientImpl; import org.junit.Test; import org.mockito.ArgumentCaptor; -import org.mockito.Mock; -import org.mockito.junit.MockitoJUnit; -import org.mockito.junit.MockitoRule; public class WebChromeClientTest { - @Rule public MockitoRule mockitoRule = MockitoJUnit.rule(); - - @Mock public WebChromeClientFlutterApiImpl mockFlutterApi; - - @Mock public WebView mockWebView; - - @Mock public WebViewClient mockWebViewClient; - - InstanceManager instanceManager; - WebChromeClientHostApiImpl hostApiImpl; - WebChromeClientImpl webChromeClient; - - @Before - public void setUp() { - instanceManager = InstanceManager.create(identifier -> {}); - - final WebChromeClientCreator webChromeClientCreator = - new WebChromeClientCreator() { - @Override - @NonNull - public WebChromeClientImpl createWebChromeClient( - @NonNull WebChromeClientFlutterApiImpl flutterApi) { - webChromeClient = super.createWebChromeClient(flutterApi); - return webChromeClient; - } - }; - - hostApiImpl = - new WebChromeClientHostApiImpl(instanceManager, webChromeClientCreator, mockFlutterApi); - hostApiImpl.create(2L); - } - - @After - public void tearDown() { - instanceManager.stopFinalizationListener(); - } - @Test public void onProgressChanged() { - webChromeClient.onProgressChanged(mockWebView, 23); - verify(mockFlutterApi).onProgressChanged(eq(webChromeClient), eq(mockWebView), eq(23L), any()); + final WebChromeClientProxyApi mockApi = mock(WebChromeClientProxyApi.class); + when(mockApi.getPigeonRegistrar()).thenReturn(new TestProxyApiRegistrar()); + + final WebChromeClientImpl instance = new WebChromeClientImpl(mockApi); + final android.webkit.WebView webView = mock(WebView.class); + final Long progress = 0L; + instance.onProgressChanged(webView, progress.intValue()); + + verify(mockApi).onProgressChanged(eq(instance), eq(webView), eq(progress), any()); } @Test @@ -88,8 +52,13 @@ public void onCreateWindow() { final Message message = new Message(); message.obj = mock(WebViewTransport.class); - webChromeClient.setWebViewClient(mockWebViewClient); - assertTrue(webChromeClient.onCreateWindow(mockWebView, message, mockOnCreateWindowWebView)); + final WebChromeClientProxyApi mockApi = mock(WebChromeClientProxyApi.class); + final WebChromeClientImpl instance = new WebChromeClientImpl(mockApi); + + final WebViewClient mockWebViewClient = mock(WebViewClient.class); + final WebView mockWebView = mock(WebView.class); + instance.setWebViewClient(mockWebViewClient); + assertTrue(instance.onCreateWindow(mockWebView, message, mockOnCreateWindowWebView)); /// Capture the WebViewClient used with onCreateWindow WebView. final ArgumentCaptor webViewClientCaptor = @@ -122,58 +91,127 @@ public void onCreateWindow() { @Test public void onPermissionRequest() { - final PermissionRequest mockRequest = mock(PermissionRequest.class); - instanceManager.addDartCreatedInstance(mockRequest, 10); - webChromeClient.onPermissionRequest(mockRequest); - verify(mockFlutterApi).onPermissionRequest(eq(webChromeClient), eq(mockRequest), any()); + final WebChromeClientProxyApi mockApi = mock(WebChromeClientProxyApi.class); + when(mockApi.getPigeonRegistrar()).thenReturn(new TestProxyApiRegistrar()); + + final WebChromeClientImpl instance = new WebChromeClientImpl(mockApi); + final android.webkit.PermissionRequest request = mock(PermissionRequest.class); + instance.onPermissionRequest(request); + + verify(mockApi).onPermissionRequest(eq(instance), eq(request), any()); } @Test public void onShowCustomView() { - final View mockView = mock(View.class); - instanceManager.addDartCreatedInstance(mockView, 10); + final WebChromeClientProxyApi mockApi = mock(WebChromeClientProxyApi.class); + when(mockApi.getPigeonRegistrar()).thenReturn(new TestProxyApiRegistrar()); - final WebChromeClient.CustomViewCallback mockCustomViewCallback = + final WebChromeClientImpl instance = new WebChromeClientImpl(mockApi); + final android.view.View view = mock(View.class); + final android.webkit.WebChromeClient.CustomViewCallback callback = mock(WebChromeClient.CustomViewCallback.class); - instanceManager.addDartCreatedInstance(mockView, 12); + instance.onShowCustomView(view, callback); - webChromeClient.onShowCustomView(mockView, mockCustomViewCallback); - verify(mockFlutterApi) - .onShowCustomView(eq(webChromeClient), eq(mockView), eq(mockCustomViewCallback), any()); + verify(mockApi).onShowCustomView(eq(instance), eq(view), eq(callback), any()); } @Test public void onHideCustomView() { - webChromeClient.onHideCustomView(); - verify(mockFlutterApi).onHideCustomView(eq(webChromeClient), any()); + final WebChromeClientProxyApi mockApi = mock(WebChromeClientProxyApi.class); + when(mockApi.getPigeonRegistrar()).thenReturn(new TestProxyApiRegistrar()); + + final WebChromeClientImpl instance = new WebChromeClientImpl(mockApi); + instance.onHideCustomView(); + + verify(mockApi).onHideCustomView(eq(instance), any()); } + @Test public void onGeolocationPermissionsShowPrompt() { - final GeolocationPermissions.Callback mockCallback = + final WebChromeClientProxyApi mockApi = mock(WebChromeClientProxyApi.class); + when(mockApi.getPigeonRegistrar()).thenReturn(new TestProxyApiRegistrar()); + + final WebChromeClientImpl instance = new WebChromeClientImpl(mockApi); + final String origin = "myString"; + final android.webkit.GeolocationPermissions.Callback callback = mock(GeolocationPermissions.Callback.class); - webChromeClient.onGeolocationPermissionsShowPrompt("https://flutter.dev", mockCallback); + instance.onGeolocationPermissionsShowPrompt(origin, callback); - verify(mockFlutterApi) - .onGeolocationPermissionsShowPrompt( - eq(webChromeClient), eq("https://flutter.dev"), eq(mockCallback), any()); + verify(mockApi) + .onGeolocationPermissionsShowPrompt(eq(instance), eq(origin), eq(callback), any()); } @Test public void onGeolocationPermissionsHidePrompt() { - webChromeClient.onGeolocationPermissionsHidePrompt(); - verify(mockFlutterApi).onGeolocationPermissionsHidePrompt(eq(webChromeClient), any()); + final WebChromeClientProxyApi mockApi = mock(WebChromeClientProxyApi.class); + when(mockApi.getPigeonRegistrar()).thenReturn(new TestProxyApiRegistrar()); + + final WebChromeClientImpl instance = new WebChromeClientImpl(mockApi); + instance.onGeolocationPermissionsHidePrompt(); + + verify(mockApi).onGeolocationPermissionsHidePrompt(eq(instance), any()); } @Test public void onConsoleMessage() { - webChromeClient.onConsoleMessage( - new ConsoleMessage("message", "sourceId", 23, ConsoleMessage.MessageLevel.ERROR)); - verify(mockFlutterApi).onConsoleMessage(eq(webChromeClient), any(), any()); + final WebChromeClientProxyApi mockApi = mock(WebChromeClientProxyApi.class); + when(mockApi.getPigeonRegistrar()).thenReturn(new TestProxyApiRegistrar()); + + final WebChromeClientImpl instance = new WebChromeClientImpl(mockApi); + instance.setReturnValueForOnConsoleMessage(true); + final android.webkit.ConsoleMessage message = mock(ConsoleMessage.class); + instance.onConsoleMessage(message); + + verify(mockApi).onConsoleMessage(eq(instance), eq(message), any()); + } + + @Test + public void onJsAlert() { + final WebChromeClientProxyApi mockApi = mock(WebChromeClientProxyApi.class); + when(mockApi.getPigeonRegistrar()).thenReturn(new TestProxyApiRegistrar()); + + final WebChromeClientImpl instance = new WebChromeClientImpl(mockApi); + instance.setReturnValueForOnJsAlert(true); + final android.webkit.WebView webView = mock(WebView.class); + final String url = "myString"; + final String message = "myString"; + final JsResult mockJsResult = mock(JsResult.class); + instance.onJsAlert(webView, url, message, mockJsResult); + + verify(mockApi).onJsAlert(eq(instance), eq(webView), eq(url), eq(message), any()); + } + + @Test + public void onJsConfirm() { + final WebChromeClientProxyApi mockApi = mock(WebChromeClientProxyApi.class); + when(mockApi.getPigeonRegistrar()).thenReturn(new TestProxyApiRegistrar()); + + final WebChromeClientImpl instance = new WebChromeClientImpl(mockApi); + instance.setReturnValueForOnJsConfirm(true); + final android.webkit.WebView webView = mock(WebView.class); + final String url = "myString"; + final String message = "myString"; + final JsResult mockJsResult = mock(JsResult.class); + instance.onJsConfirm(webView, url, message, mockJsResult); + + verify(mockApi).onJsConfirm(eq(instance), eq(webView), eq(url), eq(message), any()); } @Test - public void setReturnValueForOnConsoleMessage() { - webChromeClient.setReturnValueForOnConsoleMessage(true); - assertTrue(webChromeClient.onConsoleMessage(null)); + public void onJsPrompt() { + final WebChromeClientProxyApi mockApi = mock(WebChromeClientProxyApi.class); + when(mockApi.getPigeonRegistrar()).thenReturn(new TestProxyApiRegistrar()); + + final WebChromeClientImpl instance = new WebChromeClientImpl(mockApi); + instance.setReturnValueForOnJsPrompt(true); + final android.webkit.WebView webView = mock(WebView.class); + final String url = "myString"; + final String message = "myString"; + final String defaultValue = "myString"; + final JsPromptResult mockJsPromptResult = mock(JsPromptResult.class); + instance.onJsPrompt(webView, url, message, defaultValue, mockJsPromptResult); + + verify(mockApi) + .onJsPrompt(eq(instance), eq(webView), eq(url), eq(message), eq(defaultValue), any()); } } diff --git a/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/WebResourceErrorCompatTest.java b/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/WebResourceErrorCompatTest.java new file mode 100644 index 000000000000..b4cf88e4a843 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/WebResourceErrorCompatTest.java @@ -0,0 +1,38 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +package io.flutter.plugins.webviewflutter; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import androidx.webkit.WebResourceErrorCompat; +import org.junit.Test; + +public class WebResourceErrorCompatTest { + @Test + public void errorCode() { + final PigeonApiWebResourceErrorCompat api = + new TestProxyApiRegistrar().getPigeonApiWebResourceErrorCompat(); + + final WebResourceErrorCompat instance = mock(WebResourceErrorCompat.class); + final Long value = 0L; + when(instance.getErrorCode()).thenReturn(value.intValue()); + + assertEquals(value, (Long) api.errorCode(instance)); + } + + @Test + public void description() { + final PigeonApiWebResourceErrorCompat api = + new TestProxyApiRegistrar().getPigeonApiWebResourceErrorCompat(); + + final WebResourceErrorCompat instance = mock(WebResourceErrorCompat.class); + final String value = "myString"; + when(instance.getDescription()).thenReturn(value); + + assertEquals(value, api.description(instance)); + } +} diff --git a/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/WebResourceErrorTest.java b/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/WebResourceErrorTest.java new file mode 100644 index 000000000000..c0b7e2d2c290 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/WebResourceErrorTest.java @@ -0,0 +1,38 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +package io.flutter.plugins.webviewflutter; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import android.webkit.WebResourceError; +import org.junit.Test; + +public class WebResourceErrorTest { + @Test + public void errorCode() { + final PigeonApiWebResourceError api = + new TestProxyApiRegistrar().getPigeonApiWebResourceError(); + + final WebResourceError instance = mock(WebResourceError.class); + final Long value = 0L; + when(instance.getErrorCode()).thenReturn(value.intValue()); + + assertEquals(value, (Long) api.errorCode(instance)); + } + + @Test + public void description() { + final PigeonApiWebResourceError api = + new TestProxyApiRegistrar().getPigeonApiWebResourceError(); + + final WebResourceError instance = mock(WebResourceError.class); + final String value = "myString"; + when(instance.getDescription()).thenReturn(value); + + assertEquals(value, api.description(instance)); + } +} diff --git a/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/WebResourceRequestTest.java b/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/WebResourceRequestTest.java new file mode 100644 index 000000000000..d769293fdf71 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/WebResourceRequestTest.java @@ -0,0 +1,107 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +package io.flutter.plugins.webviewflutter; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import android.net.Uri; +import android.webkit.WebResourceRequest; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import org.junit.Test; + +public class WebResourceRequestTest { + @Test + public void url() { + final PigeonApiWebResourceRequest api = + new TestProxyApiRegistrar().getPigeonApiWebResourceRequest(); + + final WebResourceRequest instance = mock(WebResourceRequest.class); + final String value = "myString"; + when(instance.getUrl()).thenReturn(Uri.parse(value)); + + assertEquals(value, api.url(instance)); + } + + @Test + public void isForMainFrame() { + final PigeonApiWebResourceRequest api = + new TestProxyApiRegistrar().getPigeonApiWebResourceRequest(); + + final WebResourceRequest instance = mock(WebResourceRequest.class); + final Boolean value = true; + when(instance.isForMainFrame()).thenReturn(value); + + assertEquals(value, api.isForMainFrame(instance)); + } + + @Test + public void isRedirect() { + final PigeonApiWebResourceRequest api = + new TestProxyApiRegistrar().getPigeonApiWebResourceRequest(); + + final WebResourceRequest instance = mock(WebResourceRequest.class); + final Boolean value = true; + when(instance.isRedirect()).thenReturn(value); + + assertEquals(value, api.isRedirect(instance)); + } + + @Test + public void hasGesture() { + final PigeonApiWebResourceRequest api = + new TestProxyApiRegistrar().getPigeonApiWebResourceRequest(); + + final WebResourceRequest instance = mock(WebResourceRequest.class); + final Boolean value = true; + when(instance.hasGesture()).thenReturn(value); + + assertEquals(value, api.hasGesture(instance)); + } + + @Test + public void method() { + final PigeonApiWebResourceRequest api = + new TestProxyApiRegistrar().getPigeonApiWebResourceRequest(); + + final WebResourceRequest instance = mock(WebResourceRequest.class); + final String value = "myString"; + when(instance.getMethod()).thenReturn(value); + + assertEquals(value, api.method(instance)); + } + + @Test + public void requestHeaders() { + final PigeonApiWebResourceRequest api = + new TestProxyApiRegistrar().getPigeonApiWebResourceRequest(); + + final WebResourceRequest instance = mock(WebResourceRequest.class); + final Map value = + new HashMap() { + { + put("myString", "myString1"); + } + }; + when(instance.getRequestHeaders()).thenReturn(value); + + assertEquals(value, api.requestHeaders(instance)); + } + + @Test + public void requestHeadersHandlesNull() { + final PigeonApiWebResourceRequest api = + new TestProxyApiRegistrar().getPigeonApiWebResourceRequest(); + + final WebResourceRequest instance = mock(WebResourceRequest.class); + final Map value = Collections.emptyMap(); + when(instance.getRequestHeaders()).thenReturn(value); + + assertEquals(value, api.requestHeaders(instance)); + } +} diff --git a/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/WebResourceResponseTest.java b/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/WebResourceResponseTest.java new file mode 100644 index 000000000000..cc869d62e35a --- /dev/null +++ b/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/WebResourceResponseTest.java @@ -0,0 +1,26 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +package io.flutter.plugins.webviewflutter; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import android.webkit.WebResourceResponse; +import org.junit.Test; + +public class WebResourceResponseTest { + @Test + public void statusCode() { + final PigeonApiWebResourceResponse api = + new TestProxyApiRegistrar().getPigeonApiWebResourceResponse(); + + final WebResourceResponse instance = mock(WebResourceResponse.class); + final Long value = 0L; + when(instance.getStatusCode()).thenReturn(value.intValue()); + + assertEquals(value, (Long) api.statusCode(instance)); + } +} diff --git a/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/WebSettingsTest.java b/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/WebSettingsTest.java index 47d98ecce4f0..52ac10716158 100644 --- a/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/WebSettingsTest.java +++ b/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/WebSettingsTest.java @@ -5,124 +5,165 @@ package io.flutter.plugins.webviewflutter; import static org.junit.Assert.assertEquals; -import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import android.webkit.WebSettings; -import android.webkit.WebView; -import io.flutter.plugins.webviewflutter.WebSettingsHostApiImpl.WebSettingsCreator; -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; import org.junit.Test; -import org.mockito.Mock; -import org.mockito.junit.MockitoJUnit; -import org.mockito.junit.MockitoRule; public class WebSettingsTest { - @Rule public MockitoRule mockitoRule = MockitoJUnit.rule(); - - @Mock public WebSettings mockWebSettings; - - @Mock WebSettingsCreator mockWebSettingsCreator; - - InstanceManager testInstanceManager; - WebSettingsHostApiImpl testHostApiImpl; - - @Before - public void setUp() { - testInstanceManager = InstanceManager.create(identifier -> {}); - - when(mockWebSettingsCreator.createWebSettings(any())).thenReturn(mockWebSettings); - testHostApiImpl = new WebSettingsHostApiImpl(testInstanceManager, mockWebSettingsCreator); - - testInstanceManager.addDartCreatedInstance(mock(WebView.class), 1); - testHostApiImpl.create(0L, 1L); - } - - @After - public void tearDown() { - testInstanceManager.stopFinalizationListener(); - } - @Test public void setDomStorageEnabled() { - testHostApiImpl.setDomStorageEnabled(0L, true); - verify(mockWebSettings).setDomStorageEnabled(true); + final PigeonApiWebSettings api = new TestProxyApiRegistrar().getPigeonApiWebSettings(); + + final WebSettings instance = mock(WebSettings.class); + final boolean flag = true; + api.setDomStorageEnabled(instance, flag); + + verify(instance).setDomStorageEnabled(flag); } @Test public void setJavaScriptCanOpenWindowsAutomatically() { - testHostApiImpl.setJavaScriptCanOpenWindowsAutomatically(0L, false); - verify(mockWebSettings).setJavaScriptCanOpenWindowsAutomatically(false); + final PigeonApiWebSettings api = new TestProxyApiRegistrar().getPigeonApiWebSettings(); + + final WebSettings instance = mock(WebSettings.class); + final boolean flag = true; + api.setJavaScriptCanOpenWindowsAutomatically(instance, flag); + + verify(instance).setJavaScriptCanOpenWindowsAutomatically(flag); } @Test public void setSupportMultipleWindows() { - testHostApiImpl.setSupportMultipleWindows(0L, true); - verify(mockWebSettings).setSupportMultipleWindows(true); + final PigeonApiWebSettings api = new TestProxyApiRegistrar().getPigeonApiWebSettings(); + + final WebSettings instance = mock(WebSettings.class); + final boolean support = true; + api.setSupportMultipleWindows(instance, support); + + verify(instance).setSupportMultipleWindows(support); } @Test public void setJavaScriptEnabled() { - testHostApiImpl.setJavaScriptEnabled(0L, false); - verify(mockWebSettings).setJavaScriptEnabled(false); + final PigeonApiWebSettings api = new TestProxyApiRegistrar().getPigeonApiWebSettings(); + + final WebSettings instance = mock(WebSettings.class); + final boolean flag = true; + api.setJavaScriptEnabled(instance, flag); + + verify(instance).setJavaScriptEnabled(flag); } @Test public void setUserAgentString() { - testHostApiImpl.setUserAgentString(0L, "hello"); - verify(mockWebSettings).setUserAgentString("hello"); + final PigeonApiWebSettings api = new TestProxyApiRegistrar().getPigeonApiWebSettings(); + + final WebSettings instance = mock(WebSettings.class); + final String userAgentString = "myString"; + api.setUserAgentString(instance, userAgentString); + + verify(instance).setUserAgentString(userAgentString); } @Test public void setMediaPlaybackRequiresUserGesture() { - testHostApiImpl.setMediaPlaybackRequiresUserGesture(0L, false); - verify(mockWebSettings).setMediaPlaybackRequiresUserGesture(false); + final PigeonApiWebSettings api = new TestProxyApiRegistrar().getPigeonApiWebSettings(); + + final WebSettings instance = mock(WebSettings.class); + final boolean require = true; + api.setMediaPlaybackRequiresUserGesture(instance, require); + + verify(instance).setMediaPlaybackRequiresUserGesture(require); } @Test public void setSupportZoom() { - testHostApiImpl.setSupportZoom(0L, true); - verify(mockWebSettings).setSupportZoom(true); + final PigeonApiWebSettings api = new TestProxyApiRegistrar().getPigeonApiWebSettings(); + + final WebSettings instance = mock(WebSettings.class); + final boolean support = true; + api.setSupportZoom(instance, support); + + verify(instance).setSupportZoom(support); } @Test public void setLoadWithOverviewMode() { - testHostApiImpl.setLoadWithOverviewMode(0L, false); - verify(mockWebSettings).setLoadWithOverviewMode(false); + final PigeonApiWebSettings api = new TestProxyApiRegistrar().getPigeonApiWebSettings(); + + final WebSettings instance = mock(WebSettings.class); + final boolean overview = true; + api.setLoadWithOverviewMode(instance, overview); + + verify(instance).setLoadWithOverviewMode(overview); } @Test public void setUseWideViewPort() { - testHostApiImpl.setUseWideViewPort(0L, true); - verify(mockWebSettings).setUseWideViewPort(true); + final PigeonApiWebSettings api = new TestProxyApiRegistrar().getPigeonApiWebSettings(); + + final WebSettings instance = mock(WebSettings.class); + final boolean use = true; + api.setUseWideViewPort(instance, use); + + verify(instance).setUseWideViewPort(use); } @Test public void setDisplayZoomControls() { - testHostApiImpl.setDisplayZoomControls(0L, false); - verify(mockWebSettings).setDisplayZoomControls(false); + final PigeonApiWebSettings api = new TestProxyApiRegistrar().getPigeonApiWebSettings(); + + final WebSettings instance = mock(WebSettings.class); + final boolean enabled = true; + api.setDisplayZoomControls(instance, enabled); + + verify(instance).setDisplayZoomControls(enabled); } @Test public void setBuiltInZoomControls() { - testHostApiImpl.setBuiltInZoomControls(0L, true); - verify(mockWebSettings).setBuiltInZoomControls(true); + final PigeonApiWebSettings api = new TestProxyApiRegistrar().getPigeonApiWebSettings(); + + final WebSettings instance = mock(WebSettings.class); + final boolean enabled = true; + api.setBuiltInZoomControls(instance, enabled); + + verify(instance).setBuiltInZoomControls(enabled); + } + + @Test + public void setAllowFileAccess() { + final PigeonApiWebSettings api = new TestProxyApiRegistrar().getPigeonApiWebSettings(); + + final WebSettings instance = mock(WebSettings.class); + final boolean enabled = true; + api.setAllowFileAccess(instance, enabled); + + verify(instance).setAllowFileAccess(enabled); } @Test public void setTextZoom() { - testHostApiImpl.setTextZoom(0L, 100L); - verify(mockWebSettings).setTextZoom(100); + final PigeonApiWebSettings api = new TestProxyApiRegistrar().getPigeonApiWebSettings(); + + final WebSettings instance = mock(WebSettings.class); + final long textZoom = 0L; + api.setTextZoom(instance, textZoom); + + verify(instance).setTextZoom((int) textZoom); } @Test public void getUserAgentString() { - final String userAgent = "str"; - when(mockWebSettings.getUserAgentString()).thenReturn(userAgent); - assertEquals(testHostApiImpl.getUserAgentString(0L), userAgent); + final PigeonApiWebSettings api = new TestProxyApiRegistrar().getPigeonApiWebSettings(); + + final WebSettings instance = mock(WebSettings.class); + final String value = "myString"; + when(instance.getUserAgentString()).thenReturn(value); + + assertEquals(value, api.getUserAgentString(instance)); } } diff --git a/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/WebStorageHostApiImplTest.java b/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/WebStorageHostApiImplTest.java deleted file mode 100644 index 5756ce7a1747..000000000000 --- a/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/WebStorageHostApiImplTest.java +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -package io.flutter.plugins.webviewflutter; - -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import android.webkit.WebStorage; -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.mockito.Mock; -import org.mockito.junit.MockitoJUnit; -import org.mockito.junit.MockitoRule; - -public class WebStorageHostApiImplTest { - @Rule public MockitoRule mockitoRule = MockitoJUnit.rule(); - - @Mock public WebStorage mockWebStorage; - - @Mock WebStorageHostApiImpl.WebStorageCreator mockWebStorageCreator; - - InstanceManager testInstanceManager; - WebStorageHostApiImpl testHostApiImpl; - - @Before - public void setUp() { - testInstanceManager = InstanceManager.create(identifier -> {}); - - when(mockWebStorageCreator.createWebStorage()).thenReturn(mockWebStorage); - testHostApiImpl = new WebStorageHostApiImpl(testInstanceManager, mockWebStorageCreator); - testHostApiImpl.create(0L); - } - - @After - public void tearDown() { - testInstanceManager.stopFinalizationListener(); - } - - @Test - public void deleteAllData() { - testHostApiImpl.deleteAllData(0L); - verify(mockWebStorage).deleteAllData(); - } -} diff --git a/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/WebStorageTest.java b/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/WebStorageTest.java new file mode 100644 index 000000000000..64eb848a1928 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/WebStorageTest.java @@ -0,0 +1,23 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +package io.flutter.plugins.webviewflutter; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; + +import android.webkit.WebStorage; +import org.junit.Test; + +public class WebStorageTest { + @Test + public void deleteAllData() { + final PigeonApiWebStorage api = new TestProxyApiRegistrar().getPigeonApiWebStorage(); + + final WebStorage instance = mock(WebStorage.class); + api.deleteAllData(instance); + + verify(instance).deleteAllData(); + } +} diff --git a/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/WebViewClientCompatImplTest.java b/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/WebViewClientCompatImplTest.java deleted file mode 100644 index fa165238f662..000000000000 --- a/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/WebViewClientCompatImplTest.java +++ /dev/null @@ -1,213 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -package io.flutter.plugins.webviewflutter; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import android.net.Uri; -import android.webkit.WebResourceRequest; -import android.webkit.WebResourceResponse; -import android.webkit.WebView; -import android.webkit.WebViewClient; -import androidx.annotation.NonNull; -import io.flutter.plugins.webviewflutter.WebViewClientHostApiImpl.WebViewClientCompatImpl; -import io.flutter.plugins.webviewflutter.WebViewClientHostApiImpl.WebViewClientCreator; -import java.util.HashMap; -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.mockito.Mock; -import org.mockito.junit.MockitoJUnit; -import org.mockito.junit.MockitoRule; - -public class WebViewClientCompatImplTest { - @Rule public MockitoRule mockitoRule = MockitoJUnit.rule(); - - @Mock public WebViewClientFlutterApiImpl mockFlutterApi; - - @Mock public WebView mockWebView; - - InstanceManager instanceManager; - WebViewClientHostApiImpl hostApiImpl; - WebViewClientCompatImpl webViewClient; - - @Before - public void setUp() { - instanceManager = InstanceManager.create(identifier -> {}); - - final WebViewClientCreator webViewClientCreator = - new WebViewClientCreator() { - @Override - @NonNull - public WebViewClient createWebViewClient( - @NonNull WebViewClientFlutterApiImpl flutterApi) { - webViewClient = new WebViewClientCompatImpl(flutterApi); - return webViewClient; - } - }; - - hostApiImpl = - new WebViewClientHostApiImpl(instanceManager, webViewClientCreator, mockFlutterApi); - hostApiImpl.create(1L); - } - - @After - public void tearDown() { - instanceManager.stopFinalizationListener(); - } - - @Test - public void onPageStarted() { - webViewClient.onPageStarted(mockWebView, "https://www.google.com", null); - verify(mockFlutterApi) - .onPageStarted(eq(webViewClient), eq(mockWebView), eq("https://www.google.com"), any()); - } - - @Test - public void onReceivedError() { - webViewClient.onReceivedError(mockWebView, 32, "description", "https://www.google.com"); - verify(mockFlutterApi) - .onReceivedError( - eq(webViewClient), - eq(mockWebView), - eq(32L), - eq("description"), - eq("https://www.google.com"), - any()); - } - - @Test - public void urlLoading() { - webViewClient.shouldOverrideUrlLoading(mockWebView, "https://www.google.com"); - verify(mockFlutterApi) - .urlLoading(eq(webViewClient), eq(mockWebView), eq("https://www.google.com"), any()); - } - - @Test - public void urlLoadingForMainFrame() { - webViewClient.setReturnValueForShouldOverrideUrlLoading(false); - - final WebResourceRequest mockRequest = mock(WebResourceRequest.class); - when(mockRequest.isForMainFrame()).thenReturn(true); - - assertFalse(webViewClient.shouldOverrideUrlLoading(mockWebView, mockRequest)); - verify(mockFlutterApi) - .requestLoading(eq(webViewClient), eq(mockWebView), eq(mockRequest), any()); - } - - @Test - public void urlLoadingForMainFrameWithOverride() { - webViewClient.setReturnValueForShouldOverrideUrlLoading(true); - - final WebResourceRequest mockRequest = mock(WebResourceRequest.class); - when(mockRequest.isForMainFrame()).thenReturn(true); - - assertTrue(webViewClient.shouldOverrideUrlLoading(mockWebView, mockRequest)); - verify(mockFlutterApi) - .requestLoading(eq(webViewClient), eq(mockWebView), eq(mockRequest), any()); - } - - @Test - public void urlLoadingNotForMainFrame() { - webViewClient.setReturnValueForShouldOverrideUrlLoading(false); - - final WebResourceRequest mockRequest = mock(WebResourceRequest.class); - when(mockRequest.isForMainFrame()).thenReturn(false); - - assertFalse(webViewClient.shouldOverrideUrlLoading(mockWebView, mockRequest)); - verify(mockFlutterApi) - .requestLoading(eq(webViewClient), eq(mockWebView), eq(mockRequest), any()); - } - - @Test - public void urlLoadingNotForMainFrameWithOverride() { - webViewClient.setReturnValueForShouldOverrideUrlLoading(true); - - final WebResourceRequest mockRequest = mock(WebResourceRequest.class); - when(mockRequest.isForMainFrame()).thenReturn(false); - - assertFalse(webViewClient.shouldOverrideUrlLoading(mockWebView, mockRequest)); - verify(mockFlutterApi) - .requestLoading(eq(webViewClient), eq(mockWebView), eq(mockRequest), any()); - } - - @Test - public void convertWebResourceRequestWithNullHeaders() { - final Uri mockUri = mock(Uri.class); - when(mockUri.toString()).thenReturn(""); - - final WebResourceRequest mockRequest = mock(WebResourceRequest.class); - when(mockRequest.getMethod()).thenReturn("method"); - when(mockRequest.getUrl()).thenReturn(mockUri); - when(mockRequest.isForMainFrame()).thenReturn(true); - when(mockRequest.getRequestHeaders()).thenReturn(null); - - final GeneratedAndroidWebView.WebResourceRequestData data = - WebViewClientFlutterApiImpl.createWebResourceRequestData(mockRequest); - assertEquals(data.getRequestHeaders(), new HashMap()); - } - - @Test - public void setReturnValueForShouldOverrideUrlLoading() { - WebViewClientHostApiImpl.WebViewClientCompatImpl mockWebViewClient = mock(); - final WebViewClientHostApiImpl webViewClientHostApi = - new WebViewClientHostApiImpl( - instanceManager, - new WebViewClientCreator() { - @NonNull - @Override - public WebViewClient createWebViewClient( - @NonNull WebViewClientFlutterApiImpl flutterApi) { - return mockWebViewClient; - } - }, - mockFlutterApi); - - instanceManager.addDartCreatedInstance(mockWebViewClient, 2); - webViewClientHostApi.setSynchronousReturnValueForShouldOverrideUrlLoading(2L, false); - - verify(mockWebViewClient).setReturnValueForShouldOverrideUrlLoading(false); - } - - @Test - public void doUpdateVisitedHistory() { - webViewClient.doUpdateVisitedHistory(mockWebView, "https://www.google.com", true); - verify(mockFlutterApi) - .doUpdateVisitedHistory( - eq(webViewClient), eq(mockWebView), eq("https://www.google.com"), eq(true), any()); - } - - @Test - public void onReceivedHttpError() { - final Uri mockUri = mock(Uri.class); - when(mockUri.toString()).thenReturn(""); - - final WebResourceRequest mockRequest = mock(WebResourceRequest.class); - when(mockRequest.getMethod()).thenReturn("method"); - when(mockRequest.getUrl()).thenReturn(mockUri); - when(mockRequest.isForMainFrame()).thenReturn(true); - when(mockRequest.getRequestHeaders()).thenReturn(null); - - final WebResourceResponse mockResponse = mock(WebResourceResponse.class); - when(mockResponse.getStatusCode()).thenReturn(404); - - webViewClient.onReceivedHttpError(mockWebView, mockRequest, mockResponse); - verify(mockFlutterApi) - .onReceivedHttpError( - eq(webViewClient), - eq(mockWebView), - any(WebResourceRequest.class), - any(WebResourceResponse.class), - any()); - } -} diff --git a/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/WebViewClientCompatTest.java b/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/WebViewClientCompatTest.java new file mode 100644 index 000000000000..6c9bf1c7effa --- /dev/null +++ b/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/WebViewClientCompatTest.java @@ -0,0 +1,161 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +package io.flutter.plugins.webviewflutter; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import android.webkit.HttpAuthHandler; +import android.webkit.WebResourceRequest; +import android.webkit.WebView; +import org.junit.Test; + +public class WebViewClientCompatTest { + @Test + public void onPageStarted() { + final WebViewClientProxyApi mockApi = mock(WebViewClientProxyApi.class); + when(mockApi.getPigeonRegistrar()).thenReturn(new TestProxyApiRegistrar()); + + final WebViewClientProxyApi.WebViewClientCompatImpl instance = + new WebViewClientProxyApi.WebViewClientCompatImpl(mockApi); + final WebView webView = mock(WebView.class); + final String url = "myString"; + instance.onPageStarted(webView, url, null); + + verify(mockApi).onPageStarted(eq(instance), eq(webView), eq(url), any()); + } + + @Test + public void onReceivedError() { + final WebViewClientProxyApi mockApi = mock(WebViewClientProxyApi.class); + when(mockApi.getPigeonRegistrar()).thenReturn(new TestProxyApiRegistrar()); + + final WebViewClientProxyApi.WebViewClientCompatImpl instance = + new WebViewClientProxyApi.WebViewClientCompatImpl(mockApi); + final android.webkit.WebView webView = mock(WebView.class); + final Long errorCode = 0L; + final String description = "myString"; + final String failingUrl = "myString1"; + instance.onReceivedError(webView, errorCode.intValue(), description, failingUrl); + + verify(mockApi) + .onReceivedError( + eq(instance), eq(webView), eq(errorCode), eq(description), eq(failingUrl), any()); + } + + @Test + public void urlLoading() { + final WebViewClientProxyApi mockApi = mock(WebViewClientProxyApi.class); + when(mockApi.getPigeonRegistrar()).thenReturn(new TestProxyApiRegistrar()); + + final WebViewClientProxyApi.WebViewClientCompatImpl instance = + new WebViewClientProxyApi.WebViewClientCompatImpl(mockApi); + final android.webkit.WebView webView = mock(WebView.class); + final String url = "myString"; + instance.shouldOverrideUrlLoading(webView, url); + + verify(mockApi).urlLoading(eq(instance), eq(webView), eq(url), any()); + } + + @Test + public void urlLoadingForMainFrame() { + final WebViewClientProxyApi mockApi = mock(WebViewClientProxyApi.class); + when(mockApi.getPigeonRegistrar()).thenReturn(new TestProxyApiRegistrar()); + + final WebViewClientProxyApi.WebViewClientCompatImpl instance = + new WebViewClientProxyApi.WebViewClientCompatImpl(mockApi); + instance.setReturnValueForShouldOverrideUrlLoading(false); + final android.webkit.WebView webView = mock(WebView.class); + final String url = "myString"; + instance.shouldOverrideUrlLoading(webView, url); + + verify(mockApi).urlLoading(eq(instance), eq(webView), eq(url), any()); + } + + @Test + public void urlLoadingForMainFrameWithOverride() { + final WebViewClientProxyApi mockApi = mock(WebViewClientProxyApi.class); + when(mockApi.getPigeonRegistrar()).thenReturn(new TestProxyApiRegistrar()); + + final WebViewClientProxyApi.WebViewClientCompatImpl instance = + new WebViewClientProxyApi.WebViewClientCompatImpl(mockApi); + instance.setReturnValueForShouldOverrideUrlLoading(true); + final android.webkit.WebView webView = mock(WebView.class); + final String url = "myString"; + + assertTrue(instance.shouldOverrideUrlLoading(webView, url)); + verify(mockApi).urlLoading(eq(instance), eq(webView), eq(url), any()); + } + + @Test + public void urlLoadingNotForMainFrame() { + final WebViewClientProxyApi mockApi = mock(WebViewClientProxyApi.class); + when(mockApi.getPigeonRegistrar()).thenReturn(new TestProxyApiRegistrar()); + + final WebViewClientProxyApi.WebViewClientCompatImpl instance = + new WebViewClientProxyApi.WebViewClientCompatImpl(mockApi); + final android.webkit.WebView webView = mock(WebView.class); + final android.webkit.WebResourceRequest request = mock(WebResourceRequest.class); + when(request.isForMainFrame()).thenReturn(false); + instance.shouldOverrideUrlLoading(webView, request); + + verify(mockApi).requestLoading(eq(instance), eq(webView), eq(request), any()); + } + + @Test + public void urlLoadingNotForMainFrameWithOverride() { + final WebViewClientProxyApi mockApi = mock(WebViewClientProxyApi.class); + when(mockApi.getPigeonRegistrar()).thenReturn(new TestProxyApiRegistrar()); + + final WebViewClientProxyApi.WebViewClientCompatImpl instance = + new WebViewClientProxyApi.WebViewClientCompatImpl(mockApi); + instance.setReturnValueForShouldOverrideUrlLoading(true); + + final android.webkit.WebView webView = mock(WebView.class); + final android.webkit.WebResourceRequest request = mock(WebResourceRequest.class); + when(request.isForMainFrame()).thenReturn(false); + + assertFalse(instance.shouldOverrideUrlLoading(webView, request)); + verify(mockApi).requestLoading(eq(instance), eq(webView), eq(request), any()); + } + + @Test + public void doUpdateVisitedHistory() { + final WebViewClientProxyApi mockApi = mock(WebViewClientProxyApi.class); + when(mockApi.getPigeonRegistrar()).thenReturn(new TestProxyApiRegistrar()); + + final WebViewClientProxyApi.WebViewClientCompatImpl instance = + new WebViewClientProxyApi.WebViewClientCompatImpl(mockApi); + final android.webkit.WebView webView = mock(WebView.class); + final String url = "myString"; + final Boolean isReload = true; + instance.doUpdateVisitedHistory(webView, url, isReload); + + verify(mockApi).doUpdateVisitedHistory(eq(instance), eq(webView), eq(url), eq(isReload), any()); + } + + @Test + public void onReceivedHttpError() { + final WebViewClientProxyApi mockApi = mock(WebViewClientProxyApi.class); + when(mockApi.getPigeonRegistrar()).thenReturn(new TestProxyApiRegistrar()); + + final WebViewClientProxyApi.WebViewClientCompatImpl instance = + new WebViewClientProxyApi.WebViewClientCompatImpl(mockApi); + final android.webkit.WebView webView = mock(WebView.class); + final HttpAuthHandler handler = mock(HttpAuthHandler.class); + final String host = "myString"; + final String realm = "myString1"; + instance.onReceivedHttpAuthRequest(webView, handler, host, realm); + + verify(mockApi) + .onReceivedHttpAuthRequest( + eq(instance), eq(webView), eq(handler), eq(host), eq(realm), any()); + } +} diff --git a/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/WebViewClientImplTest.java b/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/WebViewClientImplTest.java deleted file mode 100644 index cddd089ab4b8..000000000000 --- a/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/WebViewClientImplTest.java +++ /dev/null @@ -1,190 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -package io.flutter.plugins.webviewflutter; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import android.net.Uri; -import android.webkit.WebResourceRequest; -import android.webkit.WebResourceResponse; -import android.webkit.WebView; -import android.webkit.WebViewClient; -import androidx.annotation.NonNull; -import io.flutter.plugins.webviewflutter.WebViewClientHostApiImpl.WebViewClientCreator; -import java.util.HashMap; -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.mockito.Mock; -import org.mockito.junit.MockitoJUnit; -import org.mockito.junit.MockitoRule; - -public class WebViewClientImplTest { - @Rule public MockitoRule mockitoRule = MockitoJUnit.rule(); - - @Mock public WebViewClientFlutterApiImpl mockFlutterApi; - - @Mock public WebView mockWebView; - - InstanceManager instanceManager; - WebViewClientHostApiImpl hostApiImpl; - WebViewClientHostApiImpl.WebViewClientImpl webViewClient; - - @Before - public void setUp() { - instanceManager = InstanceManager.create(identifier -> {}); - - final WebViewClientCreator webViewClientCreator = - new WebViewClientCreator() { - @Override - @NonNull - public WebViewClient createWebViewClient( - @NonNull WebViewClientFlutterApiImpl flutterApi) { - webViewClient = new WebViewClientHostApiImpl.WebViewClientImpl(flutterApi); - return webViewClient; - } - }; - - hostApiImpl = - new WebViewClientHostApiImpl(instanceManager, webViewClientCreator, mockFlutterApi); - hostApiImpl.create(1L); - } - - @After - public void tearDown() { - instanceManager.stopFinalizationListener(); - } - - @Test - public void onPageStarted() { - webViewClient.onPageStarted(mockWebView, "https://www.google.com", null); - verify(mockFlutterApi) - .onPageStarted(eq(webViewClient), eq(mockWebView), eq("https://www.google.com"), any()); - } - - @Test - public void onReceivedError() { - webViewClient.onReceivedError(mockWebView, 32, "description", "https://www.google.com"); - verify(mockFlutterApi) - .onReceivedError( - eq(webViewClient), - eq(mockWebView), - eq(32L), - eq("description"), - eq("https://www.google.com"), - any()); - } - - @Test - public void urlLoading() { - webViewClient.shouldOverrideUrlLoading(mockWebView, "https://www.google.com"); - verify(mockFlutterApi) - .urlLoading(eq(webViewClient), eq(mockWebView), eq("https://www.google.com"), any()); - } - - @Test - public void urlLoadingForMainFrame() { - webViewClient.setReturnValueForShouldOverrideUrlLoading(false); - - final WebResourceRequest mockRequest = mock(WebResourceRequest.class); - when(mockRequest.isForMainFrame()).thenReturn(true); - - assertFalse(webViewClient.shouldOverrideUrlLoading(mockWebView, mockRequest)); - verify(mockFlutterApi) - .requestLoading(eq(webViewClient), eq(mockWebView), eq(mockRequest), any()); - } - - @Test - public void urlLoadingForMainFrameWithOverride() { - webViewClient.setReturnValueForShouldOverrideUrlLoading(true); - - final WebResourceRequest mockRequest = mock(WebResourceRequest.class); - when(mockRequest.isForMainFrame()).thenReturn(true); - - assertTrue(webViewClient.shouldOverrideUrlLoading(mockWebView, mockRequest)); - verify(mockFlutterApi) - .requestLoading(eq(webViewClient), eq(mockWebView), eq(mockRequest), any()); - } - - @Test - public void urlLoadingNotForMainFrame() { - webViewClient.setReturnValueForShouldOverrideUrlLoading(false); - - final WebResourceRequest mockRequest = mock(WebResourceRequest.class); - when(mockRequest.isForMainFrame()).thenReturn(false); - - assertFalse(webViewClient.shouldOverrideUrlLoading(mockWebView, mockRequest)); - verify(mockFlutterApi) - .requestLoading(eq(webViewClient), eq(mockWebView), eq(mockRequest), any()); - } - - @Test - public void urlLoadingNotForMainFrameWithOverride() { - webViewClient.setReturnValueForShouldOverrideUrlLoading(true); - - final WebResourceRequest mockRequest = mock(WebResourceRequest.class); - when(mockRequest.isForMainFrame()).thenReturn(false); - - assertFalse(webViewClient.shouldOverrideUrlLoading(mockWebView, mockRequest)); - verify(mockFlutterApi) - .requestLoading(eq(webViewClient), eq(mockWebView), eq(mockRequest), any()); - } - - @Test - public void convertWebResourceRequestWithNullHeaders() { - final Uri mockUri = mock(Uri.class); - when(mockUri.toString()).thenReturn(""); - - final WebResourceRequest mockRequest = mock(WebResourceRequest.class); - when(mockRequest.getMethod()).thenReturn("method"); - when(mockRequest.getUrl()).thenReturn(mockUri); - when(mockRequest.isForMainFrame()).thenReturn(true); - when(mockRequest.getRequestHeaders()).thenReturn(null); - - final GeneratedAndroidWebView.WebResourceRequestData data = - WebViewClientFlutterApiImpl.createWebResourceRequestData(mockRequest); - assertEquals(data.getRequestHeaders(), new HashMap()); - } - - @Test - public void doUpdateVisitedHistory() { - webViewClient.doUpdateVisitedHistory(mockWebView, "https://www.google.com", true); - verify(mockFlutterApi) - .doUpdateVisitedHistory( - eq(webViewClient), eq(mockWebView), eq("https://www.google.com"), eq(true), any()); - } - - @Test - public void onReceivedHttpError() { - final Uri mockUri = mock(Uri.class); - when(mockUri.toString()).thenReturn(""); - - final WebResourceRequest mockRequest = mock(WebResourceRequest.class); - when(mockRequest.getMethod()).thenReturn("method"); - when(mockRequest.getUrl()).thenReturn(mockUri); - when(mockRequest.isForMainFrame()).thenReturn(true); - when(mockRequest.getRequestHeaders()).thenReturn(null); - - final WebResourceResponse mockResponse = mock(WebResourceResponse.class); - when(mockResponse.getStatusCode()).thenReturn(404); - - webViewClient.onReceivedHttpError(mockWebView, mockRequest, mockResponse); - verify(mockFlutterApi) - .onReceivedHttpError( - eq(webViewClient), - eq(mockWebView), - any(WebResourceRequest.class), - any(WebResourceResponse.class), - any()); - } -} diff --git a/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/WebViewClientTest.java b/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/WebViewClientTest.java new file mode 100644 index 000000000000..015bf46705de --- /dev/null +++ b/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/WebViewClientTest.java @@ -0,0 +1,151 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +package io.flutter.plugins.webviewflutter; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import android.webkit.HttpAuthHandler; +import android.webkit.WebResourceRequest; +import android.webkit.WebView; +import io.flutter.plugins.webviewflutter.WebViewClientProxyApi.WebViewClientImpl; +import org.junit.Test; + +public class WebViewClientTest { + @Test + public void onPageStarted() { + final WebViewClientProxyApi mockApi = mock(WebViewClientProxyApi.class); + when(mockApi.getPigeonRegistrar()).thenReturn(new TestProxyApiRegistrar()); + + final WebViewClientImpl instance = new WebViewClientProxyApi.WebViewClientImpl(mockApi); + final WebView webView = mock(WebView.class); + final String url = "myString"; + instance.onPageStarted(webView, url, null); + + verify(mockApi).onPageStarted(eq(instance), eq(webView), eq(url), any()); + } + + @Test + public void onReceivedError() { + final WebViewClientProxyApi mockApi = mock(WebViewClientProxyApi.class); + when(mockApi.getPigeonRegistrar()).thenReturn(new TestProxyApiRegistrar()); + + final WebViewClientImpl instance = new WebViewClientImpl(mockApi); + final android.webkit.WebView webView = mock(WebView.class); + final Long errorCode = 0L; + final String description = "myString"; + final String failingUrl = "myString1"; + instance.onReceivedError(webView, errorCode.intValue(), description, failingUrl); + + verify(mockApi) + .onReceivedError( + eq(instance), eq(webView), eq(errorCode), eq(description), eq(failingUrl), any()); + } + + @Test + public void urlLoading() { + final WebViewClientProxyApi mockApi = mock(WebViewClientProxyApi.class); + when(mockApi.getPigeonRegistrar()).thenReturn(new TestProxyApiRegistrar()); + + final WebViewClientImpl instance = new WebViewClientImpl(mockApi); + final android.webkit.WebView webView = mock(WebView.class); + final String url = "myString"; + instance.shouldOverrideUrlLoading(webView, url); + + verify(mockApi).urlLoading(eq(instance), eq(webView), eq(url), any()); + } + + @Test + public void urlLoadingForMainFrame() { + final WebViewClientProxyApi mockApi = mock(WebViewClientProxyApi.class); + when(mockApi.getPigeonRegistrar()).thenReturn(new TestProxyApiRegistrar()); + + final WebViewClientImpl instance = new WebViewClientImpl(mockApi); + instance.setReturnValueForShouldOverrideUrlLoading(false); + final android.webkit.WebView webView = mock(WebView.class); + final String url = "myString"; + instance.shouldOverrideUrlLoading(webView, url); + + verify(mockApi).urlLoading(eq(instance), eq(webView), eq(url), any()); + } + + @Test + public void urlLoadingForMainFrameWithOverride() { + final WebViewClientProxyApi mockApi = mock(WebViewClientProxyApi.class); + when(mockApi.getPigeonRegistrar()).thenReturn(new TestProxyApiRegistrar()); + + final WebViewClientImpl instance = new WebViewClientImpl(mockApi); + instance.setReturnValueForShouldOverrideUrlLoading(true); + final android.webkit.WebView webView = mock(WebView.class); + final String url = "myString"; + + assertTrue(instance.shouldOverrideUrlLoading(webView, url)); + verify(mockApi).urlLoading(eq(instance), eq(webView), eq(url), any()); + } + + @Test + public void urlLoadingNotForMainFrame() { + final WebViewClientProxyApi mockApi = mock(WebViewClientProxyApi.class); + when(mockApi.getPigeonRegistrar()).thenReturn(new TestProxyApiRegistrar()); + + final WebViewClientImpl instance = new WebViewClientImpl(mockApi); + final android.webkit.WebView webView = mock(WebView.class); + final android.webkit.WebResourceRequest request = mock(WebResourceRequest.class); + when(request.isForMainFrame()).thenReturn(false); + instance.shouldOverrideUrlLoading(webView, request); + + verify(mockApi).requestLoading(eq(instance), eq(webView), eq(request), any()); + } + + @Test + public void urlLoadingNotForMainFrameWithOverride() { + final WebViewClientProxyApi mockApi = mock(WebViewClientProxyApi.class); + when(mockApi.getPigeonRegistrar()).thenReturn(new TestProxyApiRegistrar()); + + final WebViewClientImpl instance = new WebViewClientImpl(mockApi); + final android.webkit.WebView webView = mock(WebView.class); + final android.webkit.WebResourceRequest request = mock(WebResourceRequest.class); + when(request.isForMainFrame()).thenReturn(false); + + assertFalse(instance.shouldOverrideUrlLoading(webView, request)); + verify(mockApi).requestLoading(eq(instance), eq(webView), eq(request), any()); + } + + @Test + public void doUpdateVisitedHistory() { + final WebViewClientProxyApi mockApi = mock(WebViewClientProxyApi.class); + when(mockApi.getPigeonRegistrar()).thenReturn(new TestProxyApiRegistrar()); + + final WebViewClientImpl instance = new WebViewClientImpl(mockApi); + final android.webkit.WebView webView = mock(WebView.class); + final String url = "myString"; + final Boolean isReload = true; + instance.doUpdateVisitedHistory(webView, url, isReload); + + verify(mockApi).doUpdateVisitedHistory(eq(instance), eq(webView), eq(url), eq(isReload), any()); + } + + @Test + public void onReceivedHttpError() { + final WebViewClientProxyApi mockApi = mock(WebViewClientProxyApi.class); + when(mockApi.getPigeonRegistrar()).thenReturn(new TestProxyApiRegistrar()); + + final WebViewClientImpl instance = new WebViewClientImpl(mockApi); + final android.webkit.WebView webView = mock(WebView.class); + final HttpAuthHandler handler = mock(HttpAuthHandler.class); + final String host = "myString"; + final String realm = "myString1"; + instance.onReceivedHttpAuthRequest(webView, handler, host, realm); + + verify(mockApi) + .onReceivedHttpAuthRequest( + eq(instance), eq(webView), eq(handler), eq(host), eq(realm), any()); + } +} diff --git a/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/WebViewFlutterAndroidExternalApiTest.java b/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/WebViewFlutterAndroidExternalApiTest.java index 0877dcaf2b06..e27c28d0939c 100644 --- a/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/WebViewFlutterAndroidExternalApiTest.java +++ b/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/WebViewFlutterAndroidExternalApiTest.java @@ -43,7 +43,8 @@ public void getWebView() { webViewFlutterPlugin.onAttachedToEngine(mockPluginBinding); - final InstanceManager instanceManager = webViewFlutterPlugin.getInstanceManager(); + final AndroidWebkitLibraryPigeonInstanceManager instanceManager = + webViewFlutterPlugin.getInstanceManager(); assertNotNull(instanceManager); final WebView mockWebView = mock(WebView.class); diff --git a/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/WebViewPointTest.java b/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/WebViewPointTest.java new file mode 100644 index 000000000000..75c91c33b3c4 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/WebViewPointTest.java @@ -0,0 +1,35 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +package io.flutter.plugins.webviewflutter; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import org.junit.Test; + +public class WebViewPointTest { + @Test + public void x() { + final PigeonApiWebViewPoint api = new TestProxyApiRegistrar().getPigeonApiWebViewPoint(); + + final WebViewPoint instance = mock(WebViewPoint.class); + final Long value = 0L; + when(instance.getX()).thenReturn(value); + + assertEquals(value, (Long) api.x(instance)); + } + + @Test + public void y() { + final PigeonApiWebViewPoint api = new TestProxyApiRegistrar().getPigeonApiWebViewPoint(); + + final WebViewPoint instance = mock(WebViewPoint.class); + final Long value = 0L; + when(instance.getY()).thenReturn(value); + + assertEquals(value, (Long) api.y(instance)); + } +} diff --git a/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/WebViewTest.java b/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/WebViewTest.java index 126485be01f4..2aaf62d5cbdf 100644 --- a/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/WebViewTest.java +++ b/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/WebViewTest.java @@ -14,343 +14,335 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import android.content.Context; -import android.os.Build; import android.view.View; import android.webkit.DownloadListener; import android.webkit.ValueCallback; -import android.webkit.WebChromeClient; +import android.webkit.WebView; import android.webkit.WebViewClient; -import androidx.annotation.NonNull; import io.flutter.embedding.android.FlutterView; -import io.flutter.plugin.common.BinaryMessenger; -import io.flutter.plugins.webviewflutter.GeneratedAndroidWebView.WebViewFlutterApi; -import io.flutter.plugins.webviewflutter.WebViewHostApiImpl.WebViewPlatformView; import java.util.HashMap; -import java.util.Objects; -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; +import java.util.Map; import org.junit.Test; import org.mockito.ArgumentCaptor; -import org.mockito.Mock; -import org.mockito.junit.MockitoJUnit; -import org.mockito.junit.MockitoRule; public class WebViewTest { - @Rule public MockitoRule mockitoRule = MockitoJUnit.rule(); - - @Mock public WebViewPlatformView mockWebView; - - @Mock WebViewHostApiImpl.WebViewProxy mockWebViewProxy; - - @Mock Context mockContext; - - @Mock BinaryMessenger mockBinaryMessenger; - - InstanceManager testInstanceManager; - WebViewHostApiImpl testHostApiImpl; - - @Before - public void setUp() { - testInstanceManager = InstanceManager.create(identifier -> {}); - - when(mockWebViewProxy.createWebView(mockContext, mockBinaryMessenger, testInstanceManager)) - .thenReturn(mockWebView); - testHostApiImpl = - new WebViewHostApiImpl( - testInstanceManager, mockBinaryMessenger, mockWebViewProxy, mockContext); - testHostApiImpl.create(0L); - } + @Test + public void pigeon_defaultConstructor() { + final PigeonApiWebView api = new TestProxyApiRegistrar().getPigeonApiWebView(); - @After - public void tearDown() { - testInstanceManager.stopFinalizationListener(); + assertTrue(api.pigeon_defaultConstructor() instanceof WebViewProxyApi.WebViewPlatformView); } @Test public void loadData() { - testHostApiImpl.loadData( - 0L, "VGhpcyBkYXRhIGlzIGJhc2U2NCBlbmNvZGVkLg==", "text/plain", "base64"); - verify(mockWebView) - .loadData("VGhpcyBkYXRhIGlzIGJhc2U2NCBlbmNvZGVkLg==", "text/plain", "base64"); + final PigeonApiWebView api = new TestProxyApiRegistrar().getPigeonApiWebView(); + + final WebView instance = mock(WebView.class); + final String data = "VGhpcyBkYXRhIGlzIGJhc2U2NCBlbmNvZGVkLg=="; + final String mimeType = "text/plain"; + final String encoding = "base64"; + api.loadData(instance, data, mimeType, encoding); + + verify(instance).loadData(data, mimeType, encoding); } @Test public void loadDataWithNullValues() { - testHostApiImpl.loadData(0L, "VGhpcyBkYXRhIGlzIGJhc2U2NCBlbmNvZGVkLg==", null, null); - verify(mockWebView).loadData("VGhpcyBkYXRhIGlzIGJhc2U2NCBlbmNvZGVkLg==", null, null); + final PigeonApiWebView api = new TestProxyApiRegistrar().getPigeonApiWebView(); + + final WebView instance = mock(WebView.class); + final String data = "VGhpcyBkYXRhIGlzIGJhc2U2NCBlbmNvZGVkLg=="; + final String mimeType = null; + final String encoding = null; + api.loadData(instance, data, mimeType, encoding); + + verify(instance).loadData(data, mimeType, encoding); } @Test public void loadDataWithBaseUrl() { - testHostApiImpl.loadDataWithBaseUrl( - 0L, - "https://flutter.dev", - "VGhpcyBkYXRhIGlzIGJhc2U2NCBlbmNvZGVkLg==", - "text/plain", - "base64", - "about:blank"); - verify(mockWebView) - .loadDataWithBaseURL( - "https://flutter.dev", - "VGhpcyBkYXRhIGlzIGJhc2U2NCBlbmNvZGVkLg==", - "text/plain", - "base64", - "about:blank"); + final PigeonApiWebView api = new TestProxyApiRegistrar().getPigeonApiWebView(); + + final WebView instance = mock(WebView.class); + final String baseUrl = "myString"; + final String data = "myString1"; + final String mimeType = "myString2"; + final String encoding = "myString3"; + final String historyUrl = "myString4"; + api.loadDataWithBaseUrl(instance, baseUrl, data, mimeType, encoding, historyUrl); + + verify(instance).loadDataWithBaseURL(baseUrl, data, mimeType, encoding, historyUrl); } @Test public void loadDataWithBaseUrlAndNullValues() { - testHostApiImpl.loadDataWithBaseUrl( - 0L, null, "VGhpcyBkYXRhIGlzIGJhc2U2NCBlbmNvZGVkLg==", null, null, null); - verify(mockWebView) - .loadDataWithBaseURL(null, "VGhpcyBkYXRhIGlzIGJhc2U2NCBlbmNvZGVkLg==", null, null, null); + final PigeonApiWebView api = new TestProxyApiRegistrar().getPigeonApiWebView(); + + final WebView instance = mock(WebView.class); + final String baseUrl = null; + final String data = "myString1"; + final String mimeType = null; + final String encoding = null; + final String historyUrl = null; + api.loadDataWithBaseUrl(instance, baseUrl, data, mimeType, encoding, historyUrl); + + verify(instance).loadDataWithBaseURL(baseUrl, data, mimeType, encoding, historyUrl); } @Test public void loadUrl() { - testHostApiImpl.loadUrl(0L, "https://www.google.com", new HashMap<>()); - verify(mockWebView).loadUrl("https://www.google.com", new HashMap<>()); + final PigeonApiWebView api = new TestProxyApiRegistrar().getPigeonApiWebView(); + + final WebView instance = mock(WebView.class); + final String url = "myString"; + final Map headers = + new HashMap() { + { + put("myString", "myString"); + } + }; + api.loadUrl(instance, url, headers); + + verify(instance).loadUrl(url, headers); } @Test public void postUrl() { - testHostApiImpl.postUrl(0L, "https://www.google.com", new byte[] {0x01, 0x02}); - verify(mockWebView).postUrl("https://www.google.com", new byte[] {0x01, 0x02}); + final PigeonApiWebView api = new TestProxyApiRegistrar().getPigeonApiWebView(); + + final WebView instance = mock(WebView.class); + final String url = "myString"; + final byte[] data = {(byte) 0xA1}; + api.postUrl(instance, url, data); + + verify(instance).postUrl(url, data); } @Test public void getUrl() { - when(mockWebView.getUrl()).thenReturn("https://www.google.com"); - assertEquals(testHostApiImpl.getUrl(0L), "https://www.google.com"); + final PigeonApiWebView api = new TestProxyApiRegistrar().getPigeonApiWebView(); + + final WebView instance = mock(WebView.class); + final String value = "myString"; + when(instance.getUrl()).thenReturn(value); + + assertEquals(value, api.getUrl(instance)); } @Test public void canGoBack() { - when(mockWebView.canGoBack()).thenReturn(true); - assertEquals(testHostApiImpl.canGoBack(0L), true); + final PigeonApiWebView api = new TestProxyApiRegistrar().getPigeonApiWebView(); + + final WebView instance = mock(WebView.class); + final Boolean value = true; + when(instance.canGoBack()).thenReturn(value); + + assertEquals(value, api.canGoBack(instance)); } @Test public void canGoForward() { - when(mockWebView.canGoForward()).thenReturn(false); - assertEquals(testHostApiImpl.canGoForward(0L), false); + final PigeonApiWebView api = new TestProxyApiRegistrar().getPigeonApiWebView(); + + final WebView instance = mock(WebView.class); + final Boolean value = true; + when(instance.canGoForward()).thenReturn(value); + + assertEquals(value, api.canGoForward(instance)); } @Test public void goBack() { - testHostApiImpl.goBack(0L); - verify(mockWebView).goBack(); + final PigeonApiWebView api = new TestProxyApiRegistrar().getPigeonApiWebView(); + + final WebView instance = mock(WebView.class); + api.goBack(instance); + + verify(instance).goBack(); } @Test public void goForward() { - testHostApiImpl.goForward(0L); - verify(mockWebView).goForward(); + final PigeonApiWebView api = new TestProxyApiRegistrar().getPigeonApiWebView(); + + final WebView instance = mock(WebView.class); + api.goForward(instance); + + verify(instance).goForward(); } @Test public void reload() { - testHostApiImpl.reload(0L); - verify(mockWebView).reload(); + final PigeonApiWebView api = new TestProxyApiRegistrar().getPigeonApiWebView(); + + final WebView instance = mock(WebView.class); + api.reload(instance); + + verify(instance).reload(); } @Test public void clearCache() { - testHostApiImpl.clearCache(0L, false); - verify(mockWebView).clearCache(false); + final PigeonApiWebView api = new TestProxyApiRegistrar().getPigeonApiWebView(); + + final WebView instance = mock(WebView.class); + final boolean includeDiskFiles = true; + api.clearCache(instance, includeDiskFiles); + + verify(instance).clearCache(includeDiskFiles); } @Test public void evaluateJavaScript() { - final String[] successValue = new String[1]; - testHostApiImpl.evaluateJavascript( - 0L, - "2 + 2", - new GeneratedAndroidWebView.Result() { - @Override - public void success(String result) { - successValue[0] = result; - } - - @Override - public void error(@NonNull Throwable error) {} - }); + final PigeonApiWebView api = new TestProxyApiRegistrar().getPigeonApiWebView(); + + final WebView instance = mock(WebView.class); + final String script = "2 + 2"; + final String[] resultValue = new String[1]; + api.evaluateJavascript( + instance, + script, + ResultCompat.asCompatCallback( + reply -> { + resultValue[0] = reply.getOrNull(); + return null; + })); @SuppressWarnings("unchecked") final ArgumentCaptor> callbackCaptor = ArgumentCaptor.forClass(ValueCallback.class); - verify(mockWebView).evaluateJavascript(eq("2 + 2"), callbackCaptor.capture()); + verify(instance).evaluateJavascript(eq(script), callbackCaptor.capture()); - callbackCaptor.getValue().onReceiveValue("da result"); - assertEquals(successValue[0], "da result"); + final String result = "resultValue"; + callbackCaptor.getValue().onReceiveValue(result); + assertEquals(resultValue[0], result); } @Test public void getTitle() { - when(mockWebView.getTitle()).thenReturn("My title"); - assertEquals(testHostApiImpl.getTitle(0L), "My title"); - } + final PigeonApiWebView api = new TestProxyApiRegistrar().getPigeonApiWebView(); - @Test - public void scrollTo() { - testHostApiImpl.scrollTo(0L, 12L, 13L); - verify(mockWebView).scrollTo(12, 13); - } - - @Test - public void scrollBy() { - testHostApiImpl.scrollBy(0L, 15L, 23L); - verify(mockWebView).scrollBy(15, 23); - } - - @Test - public void getScrollX() { - when(mockWebView.getScrollX()).thenReturn(55); - assertEquals((long) testHostApiImpl.getScrollX(0L), 55); - } - - @Test - public void getScrollY() { - when(mockWebView.getScrollY()).thenReturn(23); - assertEquals((long) testHostApiImpl.getScrollY(0L), 23); - } + final WebView instance = mock(WebView.class); + final String value = "myString"; + when(instance.getTitle()).thenReturn(value); - @Test - public void getScrollPosition() { - when(mockWebView.getScrollX()).thenReturn(1); - when(mockWebView.getScrollY()).thenReturn(2); - final GeneratedAndroidWebView.WebViewPoint position = testHostApiImpl.getScrollPosition(0L); - assertEquals((long) position.getX(), 1L); - assertEquals((long) position.getY(), 2L); + assertEquals(value, api.getTitle(instance)); } @Test public void setWebViewClient() { - final WebViewClient mockWebViewClient = mock(WebViewClient.class); - testInstanceManager.addDartCreatedInstance(mockWebViewClient, 1L); + final PigeonApiWebView api = new TestProxyApiRegistrar().getPigeonApiWebView(); + + final WebView instance = mock(WebView.class); + final android.webkit.WebViewClient client = mock(WebViewClient.class); + api.setWebViewClient(instance, client); - testHostApiImpl.setWebViewClient(0L, 1L); - verify(mockWebView).setWebViewClient(mockWebViewClient); + verify(instance).setWebViewClient(client); } @Test public void addJavaScriptChannel() { - final JavaScriptChannel javaScriptChannel = - new JavaScriptChannel(mock(JavaScriptChannelFlutterApiImpl.class), "aName", null); - testInstanceManager.addDartCreatedInstance(javaScriptChannel, 1L); + final PigeonApiWebView api = new TestProxyApiRegistrar().getPigeonApiWebView(); + + final WebView instance = mock(WebView.class); + final JavaScriptChannel channel = mock(JavaScriptChannel.class); + api.addJavaScriptChannel(instance, channel); - testHostApiImpl.addJavaScriptChannel(0L, 1L); - verify(mockWebView).addJavascriptInterface(javaScriptChannel, "aName"); + verify(instance).addJavascriptInterface(channel, channel.javaScriptChannelName); } @Test public void removeJavaScriptChannel() { - final JavaScriptChannel javaScriptChannel = - new JavaScriptChannel(mock(JavaScriptChannelFlutterApiImpl.class), "aName", null); - testInstanceManager.addDartCreatedInstance(javaScriptChannel, 1L); + final PigeonApiWebView api = new TestProxyApiRegistrar().getPigeonApiWebView(); - testHostApiImpl.removeJavaScriptChannel(0L, 1L); - verify(mockWebView).removeJavascriptInterface("aName"); + final WebView instance = mock(WebView.class); + final String name = "myString"; + api.removeJavaScriptChannel(instance, name); + + verify(instance).removeJavascriptInterface(name); } @Test public void setDownloadListener() { - final DownloadListener mockDownloadListener = mock(DownloadListener.class); - testInstanceManager.addDartCreatedInstance(mockDownloadListener, 1L); + final PigeonApiWebView api = new TestProxyApiRegistrar().getPigeonApiWebView(); + + final WebView instance = mock(WebView.class); + final android.webkit.DownloadListener listener = mock(DownloadListener.class); + api.setDownloadListener(instance, listener); - testHostApiImpl.setDownloadListener(0L, 1L); - verify(mockWebView).setDownloadListener(mockDownloadListener); + verify(instance).setDownloadListener(listener); } @Test public void setWebChromeClient() { - final WebChromeClient mockWebChromeClient = mock(WebChromeClient.class); - testInstanceManager.addDartCreatedInstance(mockWebChromeClient, 1L); + final PigeonApiWebView api = new TestProxyApiRegistrar().getPigeonApiWebView(); - testHostApiImpl.setWebChromeClient(0L, 1L); - verify(mockWebView).setWebChromeClient(mockWebChromeClient); - } + final WebView instance = mock(WebView.class); + final io.flutter.plugins.webviewflutter.WebChromeClientProxyApi.WebChromeClientImpl client = + mock(WebChromeClientProxyApi.WebChromeClientImpl.class); + api.setWebChromeClient(instance, client); - @Test - public void defaultWebChromeClientIsSecureWebChromeClient() { - final WebViewPlatformView webView = new WebViewPlatformView(mockContext, null, null); - assertTrue( - webView.getWebChromeClient() instanceof WebChromeClientHostApiImpl.SecureWebChromeClient); - assertFalse( - webView.getWebChromeClient() instanceof WebChromeClientHostApiImpl.WebChromeClientImpl); + verify(instance).setWebChromeClient(client); } @Test - public void defaultWebChromeClientDoesNotAttemptToCommunicateWithDart() { - final WebViewPlatformView webView = new WebViewPlatformView(mockContext, null, null); - // This shouldn't throw an Exception. - Objects.requireNonNull(webView.getWebChromeClient()).onProgressChanged(webView, 0); - } + public void setBackgroundColor() { + final PigeonApiWebView api = new TestProxyApiRegistrar().getPigeonApiWebView(); - @Test - public void disposeDoesNotCallDestroy() { - final boolean[] destroyCalled = {false}; - final WebViewPlatformView webView = - new WebViewPlatformView(mockContext, null, null) { - @Override - public void destroy() { - destroyCalled[0] = true; - } - }; - webView.dispose(); + final WebView instance = mock(WebView.class); + final long color = 0L; + api.setBackgroundColor(instance, color); - assertFalse(destroyCalled[0]); + verify(instance).setBackgroundColor((int) color); } @Test - public void destroyWebViewWhenDisposedFromJavaObjectHostApi() { - final boolean[] destroyCalled = {false}; - final WebViewPlatformView webView = - new WebViewPlatformView(mockContext, null, null) { - @Override - public void destroy() { - destroyCalled[0] = true; - } - }; - - testInstanceManager.addDartCreatedInstance(webView, 1); - final JavaObjectHostApiImpl javaObjectHostApi = new JavaObjectHostApiImpl(testInstanceManager); - javaObjectHostApi.dispose(1L); + public void defaultWebChromeClientIsSecureWebChromeClient() { + final WebViewProxyApi mockApi = mock(WebViewProxyApi.class); + when(mockApi.getPigeonRegistrar()).thenReturn(new TestProxyApiRegistrar()); + final WebViewProxyApi.WebViewPlatformView webView = + new WebViewProxyApi.WebViewPlatformView(mockApi); - assertTrue(destroyCalled[0]); + assertTrue( + webView.getWebChromeClient() instanceof WebChromeClientProxyApi.SecureWebChromeClient); + assertFalse( + webView.getWebChromeClient() instanceof WebChromeClientProxyApi.WebChromeClientImpl); } + // This test verifies that WebView.destroy() is called when the Dart instance is garbage collected. + // This requires adding + // + // ``` + // val instance: Any? = getInstance(identifier) + // if (instance is WebViewProxyApi.WebViewPlatformView) { + // instance.destroy() + // } + // ``` + // + // to `AndroidWebkitLibraryPigeonInstanceManager.remove` in the generated code. This is done as a + // temporary workaround to prevent the transition to the new pigeon ProxyApi generator from being + // a breaking change. Maintainers should consider whether continuing to call `destroy` on + // `WebView` is valuable. @Test - public void flutterApiCreate() { - final InstanceManager instanceManager = InstanceManager.create(identifier -> {}); + public void destroyWebViewWhenRemovedFromInstanceManager() { + final WebViewProxyApi.WebViewPlatformView mockWebView = + mock(WebViewProxyApi.WebViewPlatformView.class); - final WebViewFlutterApiImpl flutterApiImpl = - new WebViewFlutterApiImpl(mockBinaryMessenger, instanceManager); + final TestProxyApiRegistrar registrar = new TestProxyApiRegistrar(); + registrar.getInstanceManager().addDartCreatedInstance(mockWebView, 0); - final WebViewFlutterApi mockFlutterApi = mock(WebViewFlutterApi.class); - flutterApiImpl.setApi(mockFlutterApi); - - flutterApiImpl.create(mockWebView, reply -> {}); - - final long instanceIdentifier = - Objects.requireNonNull(instanceManager.getIdentifierForStrongReference(mockWebView)); - verify(mockFlutterApi).create(eq(instanceIdentifier), any()); - - instanceManager.stopFinalizationListener(); + registrar.getInstanceManager().remove(0); + verify(mockWebView).destroy(); } @Test public void setImportantForAutofillForParentFlutterView() { - final WebViewPlatformView webView = - new WebViewPlatformView( - mockContext, - mockBinaryMessenger, - testInstanceManager, - (int version) -> version <= Build.VERSION_CODES.O); - - final WebViewPlatformView webViewSpy = spy(webView); + final WebViewProxyApi mockApi = mock(WebViewProxyApi.class); + when(mockApi.getPigeonRegistrar()).thenReturn(new TestProxyApiRegistrar()); + final WebViewProxyApi.WebViewPlatformView webView = + new WebViewProxyApi.WebViewPlatformView(mockApi); + + final WebViewProxyApi.WebViewPlatformView webViewSpy = spy(webView); final FlutterView mockFlutterView = mock(FlutterView.class); when(webViewSpy.getParent()).thenReturn(mockFlutterView); @@ -361,22 +353,19 @@ public void setImportantForAutofillForParentFlutterView() { @Test public void onScrollChanged() { - final InstanceManager instanceManager = InstanceManager.create(identifier -> {}); - - final WebViewFlutterApiImpl flutterApiImpl = - new WebViewFlutterApiImpl(mockBinaryMessenger, instanceManager); - - final WebViewFlutterApi mockFlutterApi = mock(WebViewFlutterApi.class); - flutterApiImpl.setApi(mockFlutterApi); - flutterApiImpl.create(mockWebView, reply -> {}); - - flutterApiImpl.onScrollChanged(mockWebView, 0L, 1L, 2L, 3L, reply -> {}); - - final long instanceIdentifier = - Objects.requireNonNull(instanceManager.getIdentifierForStrongReference(mockWebView)); - verify(mockFlutterApi) - .onScrollChanged(eq(instanceIdentifier), eq(0L), eq(1L), eq(2L), eq(3L), any()); - - instanceManager.stopFinalizationListener(); + final WebViewProxyApi mockApi = mock(WebViewProxyApi.class); + when(mockApi.getPigeonRegistrar()).thenReturn(new TestProxyApiRegistrar()); + + final WebViewProxyApi.WebViewPlatformView instance = + new WebViewProxyApi.WebViewPlatformView(mockApi); + final Long left = 0L; + final Long top = 0L; + final Long oldLeft = 0L; + final Long oldTop = 0L; + instance.onScrollChanged( + left.intValue(), top.intValue(), oldLeft.intValue(), oldTop.intValue()); + + verify(mockApi) + .onScrollChanged(eq(instance), eq(left), eq(top), eq(oldLeft), eq(oldTop), any()); } } diff --git a/packages/webview_flutter/webview_flutter_android/example/android/app/src/androidTest/java/io/flutter/plugins/webviewflutterexample/InstanceManagerTest.java b/packages/webview_flutter/webview_flutter_android/example/android/app/src/androidTest/java/io/flutter/plugins/webviewflutterexample/InstanceManagerTest.java deleted file mode 100644 index 54cff982d4b3..000000000000 --- a/packages/webview_flutter/webview_flutter_android/example/android/app/src/androidTest/java/io/flutter/plugins/webviewflutterexample/InstanceManagerTest.java +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -package io.flutter.plugins.webviewflutterexample; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; - -import androidx.test.ext.junit.runners.AndroidJUnit4; -import io.flutter.plugins.webviewflutter.InstanceManager; -import org.junit.Test; -import org.junit.runner.RunWith; - -@RunWith(AndroidJUnit4.class) -public class InstanceManagerTest { - @Test - public void managerDoesNotTriggerFinalizationListenerWhenStopped() throws InterruptedException { - final boolean[] callbackTriggered = {false}; - final InstanceManager instanceManager = - InstanceManager.create(identifier -> callbackTriggered[0] = true); - instanceManager.stopFinalizationListener(); - - Object object = new Object(); - instanceManager.addDartCreatedInstance(object, 0); - - assertEquals(object, instanceManager.remove(0)); - - // To allow for object to be garbage collected. - //noinspection UnusedAssignment - object = null; - - Runtime.getRuntime().gc(); - - // Wait for the interval after finalized callbacks are made for garbage collected objects. - // See InstanceManager.CLEAR_FINALIZED_WEAK_REFERENCES_INTERVAL. - Thread.sleep(30000); - - assertNull(instanceManager.getInstance(0)); - assertFalse(callbackTriggered[0]); - } -} diff --git a/packages/webview_flutter/webview_flutter_android/example/android/settings.gradle b/packages/webview_flutter/webview_flutter_android/example/android/settings.gradle index bb344fb79fff..885c93847df2 100644 --- a/packages/webview_flutter/webview_flutter_android/example/android/settings.gradle +++ b/packages/webview_flutter/webview_flutter_android/example/android/settings.gradle @@ -20,7 +20,7 @@ pluginManagement { plugins { id "dev.flutter.flutter-plugin-loader" version "1.0.0" id "com.android.application" version "8.5.1" apply false - id "org.jetbrains.kotlin.android" version "1.7.10" apply false + id "org.jetbrains.kotlin.android" version "1.9.10" apply false id "com.google.cloud.artifactregistry.gradle-plugin" version "2.2.1" } diff --git a/packages/webview_flutter/webview_flutter_android/example/integration_test/webview_flutter_test.dart b/packages/webview_flutter/webview_flutter_android/example/integration_test/webview_flutter_test.dart index d5ed471afd36..3c7b1f8a7d91 100644 --- a/packages/webview_flutter/webview_flutter_android/example/integration_test/webview_flutter_test.dart +++ b/packages/webview_flutter/webview_flutter_android/example/integration_test/webview_flutter_test.dart @@ -14,10 +14,9 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:integration_test/integration_test.dart'; -import 'package:webview_flutter_android/src/android_webview.dart' as android; -import 'package:webview_flutter_android/src/android_webview.g.dart'; -import 'package:webview_flutter_android/src/android_webview_api_impls.dart'; -import 'package:webview_flutter_android/src/instance_manager.dart'; +import 'package:webview_flutter_android/src/android_proxy.dart'; +import 'package:webview_flutter_android/src/android_webkit.g.dart' + as android_webkit; import 'package:webview_flutter_android/src/weak_reference_utils.dart'; import 'package:webview_flutter_android/webview_flutter_android.dart'; import 'package:webview_flutter_platform_interface/webview_flutter_platform_interface.dart'; @@ -88,7 +87,8 @@ Future main() async { 'withWeakRefenceTo allows encapsulating class to be garbage collected', (WidgetTester tester) async { final Completer gcCompleter = Completer(); - final InstanceManager instanceManager = InstanceManager( + final android_webkit.PigeonInstanceManager instanceManager = + android_webkit.PigeonInstanceManager( onWeakReferenceRemoved: gcCompleter.complete, ); @@ -111,38 +111,32 @@ Future main() async { (WidgetTester tester) async { final Completer webViewGCCompleter = Completer(); - late final InstanceManager instanceManager; - instanceManager = - InstanceManager(onWeakReferenceRemoved: (int identifier) { - final Copyable instance = - instanceManager.getInstanceWithWeakReference(identifier)!; - if (instance is android.WebView && !webViewGCCompleter.isCompleted) { + const int webViewToken = -1; + final Finalizer finalizer = Finalizer((int token) { + if (token == webViewToken) { webViewGCCompleter.complete(); } }); - // Since the InstanceManager of the apis are being changed, the native - // InstanceManager needs to be cleared otherwise an exception will be - // thrown that an identifier is being reused. - await InstanceManagerHostApi().clear(); - - android.WebView.api = WebViewHostApiImpl( - instanceManager: instanceManager, - ); - android.WebSettings.api = - WebSettingsHostApiImpl(instanceManager: instanceManager); - android.WebChromeClient.api = WebChromeClientHostApiImpl( - instanceManager: instanceManager, - ); - await tester.pumpWidget( Builder( builder: (BuildContext context) { return PlatformWebViewWidget( AndroidWebViewWidgetCreationParams( - instanceManager: instanceManager, controller: PlatformWebViewController( - const PlatformWebViewControllerCreationParams(), + AndroidWebViewControllerCreationParams( + androidWebViewProxy: AndroidWebViewProxy(newWebView: ({ + void Function(android_webkit.WebView, int, int, int, int)? + onScrollChanged, + }) { + final android_webkit.WebView webView = + android_webkit.WebView( + onScrollChanged: onScrollChanged, + ); + finalizer.attach(webView, webViewToken); + return webView; + }), + ), ), ), ).build(context); @@ -156,7 +150,6 @@ Future main() async { builder: (BuildContext context) { return PlatformWebViewWidget( AndroidWebViewWidgetCreationParams( - instanceManager: instanceManager, controller: PlatformWebViewController( const PlatformWebViewControllerCreationParams(), ), @@ -175,10 +168,6 @@ Future main() async { await tester.pumpAndSettle(); await expectLater(webViewGCCompleter.future, completes); - - android.WebView.api = WebViewHostApiImpl(); - android.WebSettings.api = WebSettingsHostApiImpl(); - android.WebChromeClient.api = WebChromeClientHostApiImpl(); }, timeout: const Timeout(Duration(seconds: 10)), ); @@ -1692,13 +1681,15 @@ class ResizableWebViewState extends State { } } -class CopyableObjectWithCallback with Copyable { +class CopyableObjectWithCallback + extends android_webkit.PigeonInternalProxyApiBaseClass { CopyableObjectWithCallback(this.callback); final VoidCallback callback; @override - CopyableObjectWithCallback copy() { + // ignore: non_constant_identifier_names + CopyableObjectWithCallback pigeon_copy() { return CopyableObjectWithCallback(callback); } } diff --git a/packages/webview_flutter/webview_flutter_android/example/integration_test/webview_flutter_test_legacy.dart b/packages/webview_flutter/webview_flutter_android/example/integration_test/webview_flutter_test_legacy.dart index 51f71d7801b8..1bd1895b8b55 100644 --- a/packages/webview_flutter/webview_flutter_android/example/integration_test/webview_flutter_test_legacy.dart +++ b/packages/webview_flutter/webview_flutter_android/example/integration_test/webview_flutter_test_legacy.dart @@ -15,9 +15,7 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:integration_test/integration_test.dart'; -import 'package:webview_flutter_android/src/android_webview.dart' as android; -import 'package:webview_flutter_android/src/android_webview_api_impls.dart'; -import 'package:webview_flutter_android/src/instance_manager.dart'; +import 'package:webview_flutter_android/src/android_webkit.g.dart' as android; import 'package:webview_flutter_android/src/weak_reference_utils.dart'; import 'package:webview_flutter_android/src/webview_flutter_android_legacy.dart'; import 'package:webview_flutter_android_example/legacy/navigation_decision.dart'; @@ -107,7 +105,8 @@ Future main() async { 'withWeakRefenceTo allows encapsulating class to be garbage collected', (WidgetTester tester) async { final Completer gcCompleter = Completer(); - final InstanceManager instanceManager = InstanceManager( + final android.PigeonInstanceManager instanceManager = + android.PigeonInstanceManager( onWeakReferenceRemoved: gcCompleter.complete, ); @@ -132,32 +131,16 @@ Future main() async { (WidgetTester tester) async { final Completer webViewGCCompleter = Completer(); - late final InstanceManager instanceManager; - instanceManager = - InstanceManager(onWeakReferenceRemoved: (int identifier) { - final Copyable instance = + late final android.PigeonInstanceManager instanceManager; + instanceManager = android.PigeonInstanceManager( + onWeakReferenceRemoved: (int identifier) { + final android.PigeonInternalProxyApiBaseClass instance = instanceManager.getInstanceWithWeakReference(identifier)!; if (instance is android.WebView && !webViewGCCompleter.isCompleted) { webViewGCCompleter.complete(); } }); - android.WebView.api = WebViewHostApiImpl( - instanceManager: instanceManager, - ); - android.WebSettings.api = WebSettingsHostApiImpl( - instanceManager: instanceManager, - ); - android.WebChromeClient.api = WebChromeClientHostApiImpl( - instanceManager: instanceManager, - ); - android.WebViewClient.api = WebViewClientHostApiImpl( - instanceManager: instanceManager, - ); - android.DownloadListener.api = DownloadListenerHostApiImpl( - instanceManager: instanceManager, - ); - // Continually recreate web views until one is disposed through garbage // collection. while (!webViewGCCompleter.isCompleted) { @@ -185,15 +168,6 @@ Future main() async { await tester.pumpWidget(Container()); await tester.pumpAndSettle(); } - - android.WebView.api = WebViewHostApiImpl(); - android.WebSettings.api = WebSettingsHostApiImpl(); - android.WebChromeClient.api = WebChromeClientHostApiImpl(); - android.WebViewClient.api = WebViewClientHostApiImpl(); - android.DownloadListener.api = DownloadListenerHostApiImpl(); - - // Create a new `WebStorage` with the default InstanceManager. - android.WebStorage.instance = android.WebStorage(); }, skip: true, ); @@ -1613,13 +1587,15 @@ class ResizableWebViewState extends State { } } -class CopyableObjectWithCallback with Copyable { +class CopyableObjectWithCallback + extends android.PigeonInternalProxyApiBaseClass { CopyableObjectWithCallback(this.callback); final VoidCallback callback; @override - CopyableObjectWithCallback copy() { + // ignore: non_constant_identifier_names + CopyableObjectWithCallback pigeon_copy() { return CopyableObjectWithCallback(callback); } } diff --git a/packages/webview_flutter/webview_flutter_android/lib/src/android_proxy.dart b/packages/webview_flutter/webview_flutter_android/lib/src/android_proxy.dart index 78089d714b38..ccb9dc77f508 100644 --- a/packages/webview_flutter/webview_flutter_android/lib/src/android_proxy.dart +++ b/packages/webview_flutter/webview_flutter_android/lib/src/android_proxy.dart @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import 'android_webview.dart' as android_webview; +import 'android_webkit.g.dart'; /// Handles constructing objects and calling static methods for the Android /// WebView native library. @@ -14,119 +14,124 @@ import 'android_webview.dart' as android_webview; /// By default each function calls the default constructor of the WebView class /// it intends to return. class AndroidWebViewProxy { - /// Constructs a [AndroidWebViewProxy]. + /// Constructs an [AndroidWebViewProxy]. const AndroidWebViewProxy({ - this.createAndroidWebView = android_webview.WebView.new, - this.createAndroidWebChromeClient = android_webview.WebChromeClient.new, - this.createAndroidWebViewClient = android_webview.WebViewClient.new, - this.createFlutterAssetManager = android_webview.FlutterAssetManager.new, - this.createJavaScriptChannel = android_webview.JavaScriptChannel.new, - this.createDownloadListener = android_webview.DownloadListener.new, + this.newWebView = WebView.new, + this.newJavaScriptChannel = JavaScriptChannel.new, + this.newWebViewClient = WebViewClient.new, + this.newDownloadListener = DownloadListener.new, + this.newWebChromeClient = WebChromeClient.new, + this.setWebContentsDebuggingEnabledWebView = + WebView.setWebContentsDebuggingEnabled, + this.instanceCookieManager = _instanceCookieManager, + this.instanceFlutterAssetManager = _instanceFlutterAssetManager, + this.instanceWebStorage = _instanceWebStorage, }); - /// Constructs a [android_webview.WebView]. - final android_webview.WebView Function({ - void Function(int left, int top, int oldLeft, int oldTop)? onScrollChanged, - }) createAndroidWebView; - - /// Constructs a [android_webview.WebChromeClient]. - final android_webview.WebChromeClient Function({ - void Function(android_webview.WebView webView, int progress)? - onProgressChanged, - Future> Function( - android_webview.WebView webView, - android_webview.FileChooserParams params, - )? onShowFileChooser, - void Function( - android_webview.WebChromeClient instance, - android_webview.PermissionRequest request, - )? onPermissionRequest, - Future Function(String origin, - android_webview.GeolocationPermissionsCallback callback)? - onGeolocationPermissionsShowPrompt, - void Function(android_webview.WebChromeClient instance)? - onGeolocationPermissionsHidePrompt, - void Function(android_webview.WebChromeClient instance, - android_webview.ConsoleMessage message)? - onConsoleMessage, + /// Constructs [WebView]. + final WebView Function({ void Function( - android_webview.WebChromeClient instance, - android_webview.View view, - android_webview.CustomViewCallback callback)? - onShowCustomView, - void Function(android_webview.WebChromeClient instance)? onHideCustomView, - Future Function(String url, String message)? onJsAlert, - Future Function(String url, String message)? onJsConfirm, - Future Function(String url, String message, String defaultValue)? - onJsPrompt, - }) createAndroidWebChromeClient; + WebView, + int left, + int top, + int oldLeft, + int oldTop, + )? onScrollChanged, + }) newWebView; - /// Constructs a [android_webview.WebViewClient]. - final android_webview.WebViewClient Function({ - void Function(android_webview.WebView webView, String url)? onPageStarted, - void Function(android_webview.WebView webView, String url)? onPageFinished, + /// Constructs [JavaScriptChannel]. + final JavaScriptChannel Function({ + required String channelName, + required void Function(JavaScriptChannel, String) postMessage, + }) newJavaScriptChannel; + + /// Constructs [WebViewClient]. + final WebViewClient Function({ + void Function(WebViewClient, WebView, String)? onPageStarted, + void Function(WebViewClient, WebView, String)? onPageFinished, void Function( - android_webview.WebView webView, - android_webview.WebResourceRequest request, - android_webview.WebResourceResponse response, + WebViewClient, + WebView, + WebResourceRequest, + WebResourceResponse, )? onReceivedHttpError, void Function( - android_webview.WebView webView, - android_webview.WebResourceRequest request, - android_webview.WebResourceError error, + WebViewClient, + WebView, + WebResourceRequest, + WebResourceError, )? onReceivedRequestError, - @Deprecated('Only called on Android version < 23.') - void Function( - android_webview.WebView webView, - int errorCode, - String description, - String failingUrl, - )? onReceivedError, void Function( - android_webview.WebView webView, - android_webview.WebResourceRequest request, - )? requestLoading, - void Function(android_webview.WebView webView, String url)? urlLoading, - void Function(android_webview.WebView webView, String url, bool isReload)? - doUpdateVisitedHistory, + WebViewClient, + WebView, + WebResourceRequest, + WebResourceErrorCompat, + )? onReceivedRequestErrorCompat, + void Function(WebViewClient, WebView, int, String, String)? onReceivedError, + void Function(WebViewClient, WebView, WebResourceRequest)? requestLoading, + void Function(WebViewClient, WebView, String)? urlLoading, + void Function(WebViewClient, WebView, String, bool)? doUpdateVisitedHistory, + void Function(WebViewClient, WebView, HttpAuthHandler, String, String)? + onReceivedHttpAuthRequest, + }) newWebViewClient; + + /// Constructs [DownloadListener]. + final DownloadListener Function({ + required void Function( + DownloadListener, String, String, String, String, int) + onDownloadStart, + }) newDownloadListener; + + /// Constructs [WebChromeClient]. + final WebChromeClient Function({ + void Function(WebChromeClient, WebView, int)? onProgressChanged, + Future> Function( + WebChromeClient, + WebView, + FileChooserParams, + )? onShowFileChooser, + void Function(WebChromeClient, PermissionRequest)? onPermissionRequest, + void Function(WebChromeClient, View, CustomViewCallback)? onShowCustomView, + void Function(WebChromeClient)? onHideCustomView, void Function( - android_webview.WebView webView, - android_webview.HttpAuthHandler handler, - String host, - String realm, - )? onReceivedHttpAuthRequest, - }) createAndroidWebViewClient; + WebChromeClient, + String, + GeolocationPermissionsCallback, + )? onGeolocationPermissionsShowPrompt, + void Function(WebChromeClient)? onGeolocationPermissionsHidePrompt, + void Function(WebChromeClient, ConsoleMessage)? onConsoleMessage, + Future Function(WebChromeClient, WebView, String, String)? onJsAlert, + Future Function( + WebChromeClient, + WebView, + String, + String, + )? onJsConfirm, + Future Function( + WebChromeClient, + WebView, + String, + String, + String, + )? onJsPrompt, + }) newWebChromeClient; - /// Constructs a [android_webview.FlutterAssetManager]. - final android_webview.FlutterAssetManager Function() - createFlutterAssetManager; + /// Calls to [WebView.setWebContentsDebuggingEnabled]. + final Future Function(bool) setWebContentsDebuggingEnabledWebView; - /// Constructs a [android_webview.JavaScriptChannel]. - final android_webview.JavaScriptChannel Function( - String channelName, { - required void Function(String) postMessage, - }) createJavaScriptChannel; + /// Calls to [CookieManager.instance]. + final CookieManager Function() instanceCookieManager; - /// Constructs a [android_webview.DownloadListener]. - final android_webview.DownloadListener Function({ - required void Function( - String url, - String userAgent, - String contentDisposition, - String mimetype, - int contentLength, - ) onDownloadStart, - }) createDownloadListener; + /// Calls to [FlutterAssetManager.instance]. + final FlutterAssetManager Function() instanceFlutterAssetManager; + + /// Calls to [WebStorage.instance]. + final WebStorage Function() instanceWebStorage; + + static CookieManager _instanceCookieManager() => CookieManager.instance; + + static FlutterAssetManager _instanceFlutterAssetManager() => + FlutterAssetManager.instance; - /// Enables debugging of web contents (HTML / CSS / JavaScript) loaded into any WebViews of this application. - /// - /// This flag can be enabled in order to facilitate debugging of web layouts - /// and JavaScript code running inside WebViews. Please refer to - /// [android_webview.WebView] documentation for the debugging guide. The - /// default is false. - /// - /// See [android_webview.WebView].setWebContentsDebuggingEnabled. - Future setWebContentsDebuggingEnabled(bool enabled) { - return android_webview.WebView.setWebContentsDebuggingEnabled(enabled); - } + static WebStorage _instanceWebStorage() => WebStorage.instance; } diff --git a/packages/webview_flutter/webview_flutter_android/lib/src/android_webkit.g.dart b/packages/webview_flutter/webview_flutter_android/lib/src/android_webkit.g.dart new file mode 100644 index 000000000000..fc7174a27d08 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_android/lib/src/android_webkit.g.dart @@ -0,0 +1,6151 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. +// Autogenerated from Pigeon (v22.5.0), do not edit directly. +// See also: https://pub.dev/packages/pigeon +// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import, no_leading_underscores_for_local_identifiers + +import 'dart:async'; +import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List; + +import 'package:flutter/foundation.dart' + show ReadBuffer, WriteBuffer, immutable, protected; +import 'package:flutter/services.dart'; +import 'package:flutter/widgets.dart' show WidgetsFlutterBinding; + +PlatformException _createConnectionError(String channelName) { + return PlatformException( + code: 'channel-error', + message: 'Unable to establish connection on channel: "$channelName".', + ); +} + +List wrapResponse( + {Object? result, PlatformException? error, bool empty = false}) { + if (empty) { + return []; + } + if (error == null) { + return [result]; + } + return [error.code, error.message, error.details]; +} + +/// An immutable object that serves as the base class for all ProxyApis and +/// can provide functional copies of itself. +/// +/// All implementers are expected to be [immutable] as defined by the annotation +/// and override [pigeon_copy] returning an instance of itself. +@immutable +abstract class PigeonInternalProxyApiBaseClass { + /// Construct a [PigeonInternalProxyApiBaseClass]. + PigeonInternalProxyApiBaseClass({ + this.pigeon_binaryMessenger, + PigeonInstanceManager? pigeon_instanceManager, + }) : pigeon_instanceManager = + pigeon_instanceManager ?? PigeonInstanceManager.instance; + + /// Sends and receives binary data across the Flutter platform barrier. + /// + /// If it is null, the default BinaryMessenger will be used, which routes to + /// the host platform. + @protected + final BinaryMessenger? pigeon_binaryMessenger; + + /// Maintains instances stored to communicate with native language objects. + @protected + final PigeonInstanceManager pigeon_instanceManager; + + /// Instantiates and returns a functionally identical object to oneself. + /// + /// Outside of tests, this method should only ever be called by + /// [PigeonInstanceManager]. + /// + /// Subclasses should always override their parent's implementation of this + /// method. + @protected + PigeonInternalProxyApiBaseClass pigeon_copy(); +} + +/// Maintains instances used to communicate with the native objects they +/// represent. +/// +/// Added instances are stored as weak references and their copies are stored +/// as strong references to maintain access to their variables and callback +/// methods. Both are stored with the same identifier. +/// +/// When a weak referenced instance becomes inaccessible, +/// [onWeakReferenceRemoved] is called with its associated identifier. +/// +/// If an instance is retrieved and has the possibility to be used, +/// (e.g. calling [getInstanceWithWeakReference]) a copy of the strong reference +/// is added as a weak reference with the same identifier. This prevents a +/// scenario where the weak referenced instance was released and then later +/// returned by the host platform. +class PigeonInstanceManager { + /// Constructs a [PigeonInstanceManager]. + PigeonInstanceManager({required void Function(int) onWeakReferenceRemoved}) { + this.onWeakReferenceRemoved = (int identifier) { + _weakInstances.remove(identifier); + onWeakReferenceRemoved(identifier); + }; + _finalizer = Finalizer(this.onWeakReferenceRemoved); + } + + // Identifiers are locked to a specific range to avoid collisions with objects + // created simultaneously by the host platform. + // Host uses identifiers >= 2^16 and Dart is expected to use values n where, + // 0 <= n < 2^16. + static const int _maxDartCreatedIdentifier = 65536; + + /// The default [PigeonInstanceManager] used by ProxyApis. + /// + /// On creation, this manager makes a call to clear the native + /// InstanceManager. This is to prevent identifier conflicts after a host + /// restart. + static final PigeonInstanceManager instance = _initInstance(); + + // Expando is used because it doesn't prevent its keys from becoming + // inaccessible. This allows the manager to efficiently retrieve an identifier + // of an instance without holding a strong reference to that instance. + // + // It also doesn't use `==` to search for identifiers, which would lead to an + // infinite loop when comparing an object to its copy. (i.e. which was caused + // by calling instanceManager.getIdentifier() inside of `==` while this was a + // HashMap). + final Expando _identifiers = Expando(); + final Map> + _weakInstances = >{}; + final Map _strongInstances = + {}; + late final Finalizer _finalizer; + int _nextIdentifier = 0; + + /// Called when a weak referenced instance is removed by [removeWeakReference] + /// or becomes inaccessible. + late final void Function(int) onWeakReferenceRemoved; + + static PigeonInstanceManager _initInstance() { + WidgetsFlutterBinding.ensureInitialized(); + final _PigeonInternalInstanceManagerApi api = + _PigeonInternalInstanceManagerApi(); + // Clears the native `PigeonInstanceManager` on the initial use of the Dart one. + api.clear(); + final PigeonInstanceManager instanceManager = PigeonInstanceManager( + onWeakReferenceRemoved: (int identifier) { + api.removeStrongReference(identifier); + }, + ); + _PigeonInternalInstanceManagerApi.setUpMessageHandlers( + instanceManager: instanceManager); + WebResourceRequest.pigeon_setUpMessageHandlers( + pigeon_instanceManager: instanceManager); + WebResourceResponse.pigeon_setUpMessageHandlers( + pigeon_instanceManager: instanceManager); + WebResourceError.pigeon_setUpMessageHandlers( + pigeon_instanceManager: instanceManager); + WebResourceErrorCompat.pigeon_setUpMessageHandlers( + pigeon_instanceManager: instanceManager); + WebViewPoint.pigeon_setUpMessageHandlers( + pigeon_instanceManager: instanceManager); + ConsoleMessage.pigeon_setUpMessageHandlers( + pigeon_instanceManager: instanceManager); + CookieManager.pigeon_setUpMessageHandlers( + pigeon_instanceManager: instanceManager); + WebView.pigeon_setUpMessageHandlers( + pigeon_instanceManager: instanceManager); + WebSettings.pigeon_setUpMessageHandlers( + pigeon_instanceManager: instanceManager); + JavaScriptChannel.pigeon_setUpMessageHandlers( + pigeon_instanceManager: instanceManager); + WebViewClient.pigeon_setUpMessageHandlers( + pigeon_instanceManager: instanceManager); + DownloadListener.pigeon_setUpMessageHandlers( + pigeon_instanceManager: instanceManager); + WebChromeClient.pigeon_setUpMessageHandlers( + pigeon_instanceManager: instanceManager); + FlutterAssetManager.pigeon_setUpMessageHandlers( + pigeon_instanceManager: instanceManager); + WebStorage.pigeon_setUpMessageHandlers( + pigeon_instanceManager: instanceManager); + FileChooserParams.pigeon_setUpMessageHandlers( + pigeon_instanceManager: instanceManager); + PermissionRequest.pigeon_setUpMessageHandlers( + pigeon_instanceManager: instanceManager); + CustomViewCallback.pigeon_setUpMessageHandlers( + pigeon_instanceManager: instanceManager); + View.pigeon_setUpMessageHandlers(pigeon_instanceManager: instanceManager); + GeolocationPermissionsCallback.pigeon_setUpMessageHandlers( + pigeon_instanceManager: instanceManager); + HttpAuthHandler.pigeon_setUpMessageHandlers( + pigeon_instanceManager: instanceManager); + return instanceManager; + } + + /// Adds a new instance that was instantiated by Dart. + /// + /// In other words, Dart wants to add a new instance that will represent + /// an object that will be instantiated on the host platform. + /// + /// Throws assertion error if the instance has already been added. + /// + /// Returns the randomly generated id of the [instance] added. + int addDartCreatedInstance(PigeonInternalProxyApiBaseClass instance) { + final int identifier = _nextUniqueIdentifier(); + _addInstanceWithIdentifier(instance, identifier); + return identifier; + } + + /// Removes the instance, if present, and call [onWeakReferenceRemoved] with + /// its identifier. + /// + /// Returns the identifier associated with the removed instance. Otherwise, + /// `null` if the instance was not found in this manager. + /// + /// This does not remove the strong referenced instance associated with + /// [instance]. This can be done with [remove]. + int? removeWeakReference(PigeonInternalProxyApiBaseClass instance) { + final int? identifier = getIdentifier(instance); + if (identifier == null) { + return null; + } + + _identifiers[instance] = null; + _finalizer.detach(instance); + onWeakReferenceRemoved(identifier); + + return identifier; + } + + /// Removes [identifier] and its associated strongly referenced instance, if + /// present, from the manager. + /// + /// Returns the strong referenced instance associated with [identifier] before + /// it was removed. Returns `null` if [identifier] was not associated with + /// any strong reference. + /// + /// This does not remove the weak referenced instance associated with + /// [identifier]. This can be done with [removeWeakReference]. + T? remove(int identifier) { + return _strongInstances.remove(identifier) as T?; + } + + /// Retrieves the instance associated with identifier. + /// + /// The value returned is chosen from the following order: + /// + /// 1. A weakly referenced instance associated with identifier. + /// 2. If the only instance associated with identifier is a strongly + /// referenced instance, a copy of the instance is added as a weak reference + /// with the same identifier. Returning the newly created copy. + /// 3. If no instance is associated with identifier, returns null. + /// + /// This method also expects the host `InstanceManager` to have a strong + /// reference to the instance the identifier is associated with. + T? getInstanceWithWeakReference( + int identifier) { + final PigeonInternalProxyApiBaseClass? weakInstance = + _weakInstances[identifier]?.target; + + if (weakInstance == null) { + final PigeonInternalProxyApiBaseClass? strongInstance = + _strongInstances[identifier]; + if (strongInstance != null) { + final PigeonInternalProxyApiBaseClass copy = + strongInstance.pigeon_copy(); + _identifiers[copy] = identifier; + _weakInstances[identifier] = + WeakReference(copy); + _finalizer.attach(copy, identifier, detach: copy); + return copy as T; + } + return strongInstance as T?; + } + + return weakInstance as T; + } + + /// Retrieves the identifier associated with instance. + int? getIdentifier(PigeonInternalProxyApiBaseClass instance) { + return _identifiers[instance]; + } + + /// Adds a new instance that was instantiated by the host platform. + /// + /// In other words, the host platform wants to add a new instance that + /// represents an object on the host platform. Stored with [identifier]. + /// + /// Throws assertion error if the instance or its identifier has already been + /// added. + /// + /// Returns unique identifier of the [instance] added. + void addHostCreatedInstance( + PigeonInternalProxyApiBaseClass instance, int identifier) { + _addInstanceWithIdentifier(instance, identifier); + } + + void _addInstanceWithIdentifier( + PigeonInternalProxyApiBaseClass instance, int identifier) { + assert(!containsIdentifier(identifier)); + assert(getIdentifier(instance) == null); + assert(identifier >= 0); + + _identifiers[instance] = identifier; + _weakInstances[identifier] = + WeakReference(instance); + _finalizer.attach(instance, identifier, detach: instance); + + final PigeonInternalProxyApiBaseClass copy = instance.pigeon_copy(); + _identifiers[copy] = identifier; + _strongInstances[identifier] = copy; + } + + /// Whether this manager contains the given [identifier]. + bool containsIdentifier(int identifier) { + return _weakInstances.containsKey(identifier) || + _strongInstances.containsKey(identifier); + } + + int _nextUniqueIdentifier() { + late int identifier; + do { + identifier = _nextIdentifier; + _nextIdentifier = (_nextIdentifier + 1) % _maxDartCreatedIdentifier; + } while (containsIdentifier(identifier)); + return identifier; + } +} + +/// Generated API for managing the Dart and native `PigeonInstanceManager`s. +class _PigeonInternalInstanceManagerApi { + /// Constructor for [_PigeonInternalInstanceManagerApi]. + _PigeonInternalInstanceManagerApi({BinaryMessenger? binaryMessenger}) + : pigeonVar_binaryMessenger = binaryMessenger; + + final BinaryMessenger? pigeonVar_binaryMessenger; + + static const MessageCodec pigeonChannelCodec = _PigeonCodec(); + + static void setUpMessageHandlers({ + bool pigeon_clearHandlers = false, + BinaryMessenger? binaryMessenger, + PigeonInstanceManager? instanceManager, + }) { + { + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.webview_flutter_android.PigeonInternalInstanceManager.removeStrongReference', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (pigeon_clearHandlers) { + pigeonVar_channel.setMessageHandler(null); + } else { + pigeonVar_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.PigeonInternalInstanceManager.removeStrongReference was null.'); + final List args = (message as List?)!; + final int? arg_identifier = (args[0] as int?); + assert(arg_identifier != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.PigeonInternalInstanceManager.removeStrongReference was null, expected non-null int.'); + try { + (instanceManager ?? PigeonInstanceManager.instance) + .remove(arg_identifier!); + return wrapResponse(empty: true); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } + } + + Future removeStrongReference(int identifier) async { + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_android.PigeonInternalInstanceManager.removeStrongReference'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = + await pigeonVar_channel.send([identifier]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return; + } + } + + /// Clear the native `PigeonInstanceManager`. + /// + /// This is typically called after a hot restart. + Future clear() async { + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_android.PigeonInternalInstanceManager.clear'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = + await pigeonVar_channel.send(null) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return; + } + } +} + +class _PigeonInternalProxyApiBaseCodec extends _PigeonCodec { + const _PigeonInternalProxyApiBaseCodec(this.instanceManager); + final PigeonInstanceManager instanceManager; + @override + void writeValue(WriteBuffer buffer, Object? value) { + if (value is PigeonInternalProxyApiBaseClass) { + buffer.putUint8(128); + writeValue(buffer, instanceManager.getIdentifier(value)); + } else { + super.writeValue(buffer, value); + } + } + + @override + Object? readValueOfType(int type, ReadBuffer buffer) { + switch (type) { + case 128: + return instanceManager + .getInstanceWithWeakReference(readValue(buffer)! as int); + default: + return super.readValueOfType(type, buffer); + } + } +} + +/// Mode of how to select files for a file chooser. +/// +/// See https://developer.android.com/reference/android/webkit/WebChromeClient.FileChooserParams. +enum FileChooserMode { + /// Open single file and requires that the file exists before allowing the + /// user to pick it. + /// + /// See https://developer.android.com/reference/android/webkit/WebChromeClient.FileChooserParams#MODE_OPEN. + open, + + /// Similar to [open] but allows multiple files to be selected. + /// + /// See https://developer.android.com/reference/android/webkit/WebChromeClient.FileChooserParams#MODE_OPEN_MULTIPLE. + openMultiple, + + /// Allows picking a nonexistent file and saving it. + /// + /// See https://developer.android.com/reference/android/webkit/WebChromeClient.FileChooserParams#MODE_SAVE. + save, + + /// Indicates a `FileChooserMode` with an unknown mode. + /// + /// This does not represent an actual value provided by the platform and only + /// indicates a value was provided that isn't currently supported. + unknown, +} + +/// Indicates the type of message logged to the console. +/// +/// See https://developer.android.com/reference/android/webkit/ConsoleMessage.MessageLevel. +enum ConsoleMessageLevel { + /// Indicates a message is logged for debugging. + /// + /// See https://developer.android.com/reference/android/webkit/ConsoleMessage.MessageLevel#DEBUG. + debug, + + /// Indicates a message is provided as an error. + /// + /// See https://developer.android.com/reference/android/webkit/ConsoleMessage.MessageLevel#ERROR. + error, + + /// Indicates a message is provided as a basic log message. + /// + /// See https://developer.android.com/reference/android/webkit/ConsoleMessage.MessageLevel#LOG. + log, + + /// Indicates a message is provided as a tip. + /// + /// See https://developer.android.com/reference/android/webkit/ConsoleMessage.MessageLevel#TIP. + tip, + + /// Indicates a message is provided as a warning. + /// + /// See https://developer.android.com/reference/android/webkit/ConsoleMessage.MessageLevel#WARNING. + warning, + + /// Indicates a message with an unknown level. + /// + /// This does not represent an actual value provided by the platform and only + /// indicates a value was provided that isn't currently supported. + unknown, +} + +class _PigeonCodec extends StandardMessageCodec { + const _PigeonCodec(); + @override + void writeValue(WriteBuffer buffer, Object? value) { + if (value is int) { + buffer.putUint8(4); + buffer.putInt64(value); + } else if (value is FileChooserMode) { + buffer.putUint8(129); + writeValue(buffer, value.index); + } else if (value is ConsoleMessageLevel) { + buffer.putUint8(130); + writeValue(buffer, value.index); + } else { + super.writeValue(buffer, value); + } + } + + @override + Object? readValueOfType(int type, ReadBuffer buffer) { + switch (type) { + case 129: + final int? value = readValue(buffer) as int?; + return value == null ? null : FileChooserMode.values[value]; + case 130: + final int? value = readValue(buffer) as int?; + return value == null ? null : ConsoleMessageLevel.values[value]; + default: + return super.readValueOfType(type, buffer); + } + } +} + +/// Encompasses parameters to the `WebViewClient.shouldInterceptRequest` method. +/// +/// See https://developer.android.com/reference/android/webkit/WebResourceRequest. +class WebResourceRequest extends PigeonInternalProxyApiBaseClass { + /// Constructs [WebResourceRequest] without creating the associated native object. + /// + /// This should only be used by subclasses created by this library or to + /// create copies for an [PigeonInstanceManager]. + @protected + WebResourceRequest.pigeon_detached({ + super.pigeon_binaryMessenger, + super.pigeon_instanceManager, + required this.url, + required this.isForMainFrame, + this.isRedirect, + required this.hasGesture, + required this.method, + this.requestHeaders, + }); + + /// The URL for which the resource request was made. + final String url; + + /// Whether the request was made in order to fetch the main frame's document. + final bool isForMainFrame; + + /// Whether the request was a result of a server-side redirect. + final bool? isRedirect; + + /// Whether a gesture (such as a click) was associated with the request. + final bool hasGesture; + + /// The method associated with the request, for example "GET". + final String method; + + /// The headers associated with the request. + final Map? requestHeaders; + + static void pigeon_setUpMessageHandlers({ + bool pigeon_clearHandlers = false, + BinaryMessenger? pigeon_binaryMessenger, + PigeonInstanceManager? pigeon_instanceManager, + WebResourceRequest Function( + String url, + bool isForMainFrame, + bool? isRedirect, + bool hasGesture, + String method, + Map? requestHeaders, + )? pigeon_newInstance, + }) { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _PigeonInternalProxyApiBaseCodec( + pigeon_instanceManager ?? PigeonInstanceManager.instance); + final BinaryMessenger? binaryMessenger = pigeon_binaryMessenger; + { + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.webview_flutter_android.WebResourceRequest.pigeon_newInstance', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (pigeon_clearHandlers) { + pigeonVar_channel.setMessageHandler(null); + } else { + pigeonVar_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebResourceRequest.pigeon_newInstance was null.'); + final List args = (message as List?)!; + final int? arg_pigeon_instanceIdentifier = (args[0] as int?); + assert(arg_pigeon_instanceIdentifier != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebResourceRequest.pigeon_newInstance was null, expected non-null int.'); + final String? arg_url = (args[1] as String?); + assert(arg_url != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebResourceRequest.pigeon_newInstance was null, expected non-null String.'); + final bool? arg_isForMainFrame = (args[2] as bool?); + assert(arg_isForMainFrame != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebResourceRequest.pigeon_newInstance was null, expected non-null bool.'); + final bool? arg_isRedirect = (args[3] as bool?); + final bool? arg_hasGesture = (args[4] as bool?); + assert(arg_hasGesture != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebResourceRequest.pigeon_newInstance was null, expected non-null bool.'); + final String? arg_method = (args[5] as String?); + assert(arg_method != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebResourceRequest.pigeon_newInstance was null, expected non-null String.'); + final Map? arg_requestHeaders = + (args[6] as Map?)?.cast(); + try { + (pigeon_instanceManager ?? PigeonInstanceManager.instance) + .addHostCreatedInstance( + pigeon_newInstance?.call( + arg_url!, + arg_isForMainFrame!, + arg_isRedirect, + arg_hasGesture!, + arg_method!, + arg_requestHeaders) ?? + WebResourceRequest.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + url: arg_url!, + isForMainFrame: arg_isForMainFrame!, + isRedirect: arg_isRedirect, + hasGesture: arg_hasGesture!, + method: arg_method!, + requestHeaders: arg_requestHeaders, + ), + arg_pigeon_instanceIdentifier!, + ); + return wrapResponse(empty: true); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } + } + + @override + WebResourceRequest pigeon_copy() { + return WebResourceRequest.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + url: url, + isForMainFrame: isForMainFrame, + isRedirect: isRedirect, + hasGesture: hasGesture, + method: method, + requestHeaders: requestHeaders, + ); + } +} + +/// Encapsulates a resource response. +/// +/// See https://developer.android.com/reference/android/webkit/WebResourceResponse. +class WebResourceResponse extends PigeonInternalProxyApiBaseClass { + /// Constructs [WebResourceResponse] without creating the associated native object. + /// + /// This should only be used by subclasses created by this library or to + /// create copies for an [PigeonInstanceManager]. + @protected + WebResourceResponse.pigeon_detached({ + super.pigeon_binaryMessenger, + super.pigeon_instanceManager, + required this.statusCode, + }); + + /// The resource response's status code. + final int statusCode; + + static void pigeon_setUpMessageHandlers({ + bool pigeon_clearHandlers = false, + BinaryMessenger? pigeon_binaryMessenger, + PigeonInstanceManager? pigeon_instanceManager, + WebResourceResponse Function(int statusCode)? pigeon_newInstance, + }) { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _PigeonInternalProxyApiBaseCodec( + pigeon_instanceManager ?? PigeonInstanceManager.instance); + final BinaryMessenger? binaryMessenger = pigeon_binaryMessenger; + { + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.webview_flutter_android.WebResourceResponse.pigeon_newInstance', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (pigeon_clearHandlers) { + pigeonVar_channel.setMessageHandler(null); + } else { + pigeonVar_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebResourceResponse.pigeon_newInstance was null.'); + final List args = (message as List?)!; + final int? arg_pigeon_instanceIdentifier = (args[0] as int?); + assert(arg_pigeon_instanceIdentifier != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebResourceResponse.pigeon_newInstance was null, expected non-null int.'); + final int? arg_statusCode = (args[1] as int?); + assert(arg_statusCode != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebResourceResponse.pigeon_newInstance was null, expected non-null int.'); + try { + (pigeon_instanceManager ?? PigeonInstanceManager.instance) + .addHostCreatedInstance( + pigeon_newInstance?.call(arg_statusCode!) ?? + WebResourceResponse.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + statusCode: arg_statusCode!, + ), + arg_pigeon_instanceIdentifier!, + ); + return wrapResponse(empty: true); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } + } + + @override + WebResourceResponse pigeon_copy() { + return WebResourceResponse.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + statusCode: statusCode, + ); + } +} + +/// Encapsulates information about errors that occurred during loading of web +/// resources. +/// +/// See https://developer.android.com/reference/android/webkit/WebResourceError. +class WebResourceError extends PigeonInternalProxyApiBaseClass { + /// Constructs [WebResourceError] without creating the associated native object. + /// + /// This should only be used by subclasses created by this library or to + /// create copies for an [PigeonInstanceManager]. + @protected + WebResourceError.pigeon_detached({ + super.pigeon_binaryMessenger, + super.pigeon_instanceManager, + required this.errorCode, + required this.description, + }); + + /// The error code of the error. + final int errorCode; + + /// The string describing the error. + final String description; + + static void pigeon_setUpMessageHandlers({ + bool pigeon_clearHandlers = false, + BinaryMessenger? pigeon_binaryMessenger, + PigeonInstanceManager? pigeon_instanceManager, + WebResourceError Function( + int errorCode, + String description, + )? pigeon_newInstance, + }) { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _PigeonInternalProxyApiBaseCodec( + pigeon_instanceManager ?? PigeonInstanceManager.instance); + final BinaryMessenger? binaryMessenger = pigeon_binaryMessenger; + { + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.webview_flutter_android.WebResourceError.pigeon_newInstance', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (pigeon_clearHandlers) { + pigeonVar_channel.setMessageHandler(null); + } else { + pigeonVar_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebResourceError.pigeon_newInstance was null.'); + final List args = (message as List?)!; + final int? arg_pigeon_instanceIdentifier = (args[0] as int?); + assert(arg_pigeon_instanceIdentifier != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebResourceError.pigeon_newInstance was null, expected non-null int.'); + final int? arg_errorCode = (args[1] as int?); + assert(arg_errorCode != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebResourceError.pigeon_newInstance was null, expected non-null int.'); + final String? arg_description = (args[2] as String?); + assert(arg_description != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebResourceError.pigeon_newInstance was null, expected non-null String.'); + try { + (pigeon_instanceManager ?? PigeonInstanceManager.instance) + .addHostCreatedInstance( + pigeon_newInstance?.call(arg_errorCode!, arg_description!) ?? + WebResourceError.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + errorCode: arg_errorCode!, + description: arg_description!, + ), + arg_pigeon_instanceIdentifier!, + ); + return wrapResponse(empty: true); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } + } + + @override + WebResourceError pigeon_copy() { + return WebResourceError.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + errorCode: errorCode, + description: description, + ); + } +} + +/// Encapsulates information about errors that occurred during loading of web +/// resources. +/// +/// See https://developer.android.com/reference/androidx/webkit/WebResourceErrorCompat. +class WebResourceErrorCompat extends PigeonInternalProxyApiBaseClass { + /// Constructs [WebResourceErrorCompat] without creating the associated native object. + /// + /// This should only be used by subclasses created by this library or to + /// create copies for an [PigeonInstanceManager]. + @protected + WebResourceErrorCompat.pigeon_detached({ + super.pigeon_binaryMessenger, + super.pigeon_instanceManager, + required this.errorCode, + required this.description, + }); + + /// The error code of the error. + final int errorCode; + + /// The string describing the error. + final String description; + + static void pigeon_setUpMessageHandlers({ + bool pigeon_clearHandlers = false, + BinaryMessenger? pigeon_binaryMessenger, + PigeonInstanceManager? pigeon_instanceManager, + WebResourceErrorCompat Function( + int errorCode, + String description, + )? pigeon_newInstance, + }) { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _PigeonInternalProxyApiBaseCodec( + pigeon_instanceManager ?? PigeonInstanceManager.instance); + final BinaryMessenger? binaryMessenger = pigeon_binaryMessenger; + { + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.webview_flutter_android.WebResourceErrorCompat.pigeon_newInstance', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (pigeon_clearHandlers) { + pigeonVar_channel.setMessageHandler(null); + } else { + pigeonVar_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebResourceErrorCompat.pigeon_newInstance was null.'); + final List args = (message as List?)!; + final int? arg_pigeon_instanceIdentifier = (args[0] as int?); + assert(arg_pigeon_instanceIdentifier != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebResourceErrorCompat.pigeon_newInstance was null, expected non-null int.'); + final int? arg_errorCode = (args[1] as int?); + assert(arg_errorCode != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebResourceErrorCompat.pigeon_newInstance was null, expected non-null int.'); + final String? arg_description = (args[2] as String?); + assert(arg_description != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebResourceErrorCompat.pigeon_newInstance was null, expected non-null String.'); + try { + (pigeon_instanceManager ?? PigeonInstanceManager.instance) + .addHostCreatedInstance( + pigeon_newInstance?.call(arg_errorCode!, arg_description!) ?? + WebResourceErrorCompat.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + errorCode: arg_errorCode!, + description: arg_description!, + ), + arg_pigeon_instanceIdentifier!, + ); + return wrapResponse(empty: true); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } + } + + @override + WebResourceErrorCompat pigeon_copy() { + return WebResourceErrorCompat.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + errorCode: errorCode, + description: description, + ); + } +} + +/// Represents a position on a web page. +/// +/// This is a custom class created for convenience of the wrapper. +class WebViewPoint extends PigeonInternalProxyApiBaseClass { + /// Constructs [WebViewPoint] without creating the associated native object. + /// + /// This should only be used by subclasses created by this library or to + /// create copies for an [PigeonInstanceManager]. + @protected + WebViewPoint.pigeon_detached({ + super.pigeon_binaryMessenger, + super.pigeon_instanceManager, + required this.x, + required this.y, + }); + + final int x; + + final int y; + + static void pigeon_setUpMessageHandlers({ + bool pigeon_clearHandlers = false, + BinaryMessenger? pigeon_binaryMessenger, + PigeonInstanceManager? pigeon_instanceManager, + WebViewPoint Function( + int x, + int y, + )? pigeon_newInstance, + }) { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _PigeonInternalProxyApiBaseCodec( + pigeon_instanceManager ?? PigeonInstanceManager.instance); + final BinaryMessenger? binaryMessenger = pigeon_binaryMessenger; + { + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.webview_flutter_android.WebViewPoint.pigeon_newInstance', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (pigeon_clearHandlers) { + pigeonVar_channel.setMessageHandler(null); + } else { + pigeonVar_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewPoint.pigeon_newInstance was null.'); + final List args = (message as List?)!; + final int? arg_pigeon_instanceIdentifier = (args[0] as int?); + assert(arg_pigeon_instanceIdentifier != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewPoint.pigeon_newInstance was null, expected non-null int.'); + final int? arg_x = (args[1] as int?); + assert(arg_x != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewPoint.pigeon_newInstance was null, expected non-null int.'); + final int? arg_y = (args[2] as int?); + assert(arg_y != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewPoint.pigeon_newInstance was null, expected non-null int.'); + try { + (pigeon_instanceManager ?? PigeonInstanceManager.instance) + .addHostCreatedInstance( + pigeon_newInstance?.call(arg_x!, arg_y!) ?? + WebViewPoint.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + x: arg_x!, + y: arg_y!, + ), + arg_pigeon_instanceIdentifier!, + ); + return wrapResponse(empty: true); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } + } + + @override + WebViewPoint pigeon_copy() { + return WebViewPoint.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + x: x, + y: y, + ); + } +} + +/// Represents a JavaScript console message from WebCore. +/// +/// See https://developer.android.com/reference/android/webkit/ConsoleMessage +class ConsoleMessage extends PigeonInternalProxyApiBaseClass { + /// Constructs [ConsoleMessage] without creating the associated native object. + /// + /// This should only be used by subclasses created by this library or to + /// create copies for an [PigeonInstanceManager]. + @protected + ConsoleMessage.pigeon_detached({ + super.pigeon_binaryMessenger, + super.pigeon_instanceManager, + required this.lineNumber, + required this.message, + required this.level, + required this.sourceId, + }); + + final int lineNumber; + + final String message; + + final ConsoleMessageLevel level; + + final String sourceId; + + static void pigeon_setUpMessageHandlers({ + bool pigeon_clearHandlers = false, + BinaryMessenger? pigeon_binaryMessenger, + PigeonInstanceManager? pigeon_instanceManager, + ConsoleMessage Function( + int lineNumber, + String message, + ConsoleMessageLevel level, + String sourceId, + )? pigeon_newInstance, + }) { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _PigeonInternalProxyApiBaseCodec( + pigeon_instanceManager ?? PigeonInstanceManager.instance); + final BinaryMessenger? binaryMessenger = pigeon_binaryMessenger; + { + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.webview_flutter_android.ConsoleMessage.pigeon_newInstance', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (pigeon_clearHandlers) { + pigeonVar_channel.setMessageHandler(null); + } else { + pigeonVar_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.ConsoleMessage.pigeon_newInstance was null.'); + final List args = (message as List?)!; + final int? arg_pigeon_instanceIdentifier = (args[0] as int?); + assert(arg_pigeon_instanceIdentifier != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.ConsoleMessage.pigeon_newInstance was null, expected non-null int.'); + final int? arg_lineNumber = (args[1] as int?); + assert(arg_lineNumber != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.ConsoleMessage.pigeon_newInstance was null, expected non-null int.'); + final String? arg_message = (args[2] as String?); + assert(arg_message != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.ConsoleMessage.pigeon_newInstance was null, expected non-null String.'); + final ConsoleMessageLevel? arg_level = + (args[3] as ConsoleMessageLevel?); + assert(arg_level != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.ConsoleMessage.pigeon_newInstance was null, expected non-null ConsoleMessageLevel.'); + final String? arg_sourceId = (args[4] as String?); + assert(arg_sourceId != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.ConsoleMessage.pigeon_newInstance was null, expected non-null String.'); + try { + (pigeon_instanceManager ?? PigeonInstanceManager.instance) + .addHostCreatedInstance( + pigeon_newInstance?.call(arg_lineNumber!, arg_message!, + arg_level!, arg_sourceId!) ?? + ConsoleMessage.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + lineNumber: arg_lineNumber!, + message: arg_message!, + level: arg_level!, + sourceId: arg_sourceId!, + ), + arg_pigeon_instanceIdentifier!, + ); + return wrapResponse(empty: true); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } + } + + @override + ConsoleMessage pigeon_copy() { + return ConsoleMessage.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + lineNumber: lineNumber, + message: message, + level: level, + sourceId: sourceId, + ); + } +} + +/// Manages the cookies used by an application's `WebView` instances. +/// +/// See https://developer.android.com/reference/android/webkit/CookieManager. +class CookieManager extends PigeonInternalProxyApiBaseClass { + /// Constructs [CookieManager] without creating the associated native object. + /// + /// This should only be used by subclasses created by this library or to + /// create copies for an [PigeonInstanceManager]. + @protected + CookieManager.pigeon_detached({ + super.pigeon_binaryMessenger, + super.pigeon_instanceManager, + }); + + late final _PigeonInternalProxyApiBaseCodec _pigeonVar_codecCookieManager = + _PigeonInternalProxyApiBaseCodec(pigeon_instanceManager); + + static final CookieManager instance = pigeonVar_instance(); + + static void pigeon_setUpMessageHandlers({ + bool pigeon_clearHandlers = false, + BinaryMessenger? pigeon_binaryMessenger, + PigeonInstanceManager? pigeon_instanceManager, + CookieManager Function()? pigeon_newInstance, + }) { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _PigeonInternalProxyApiBaseCodec( + pigeon_instanceManager ?? PigeonInstanceManager.instance); + final BinaryMessenger? binaryMessenger = pigeon_binaryMessenger; + { + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.webview_flutter_android.CookieManager.pigeon_newInstance', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (pigeon_clearHandlers) { + pigeonVar_channel.setMessageHandler(null); + } else { + pigeonVar_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.CookieManager.pigeon_newInstance was null.'); + final List args = (message as List?)!; + final int? arg_pigeon_instanceIdentifier = (args[0] as int?); + assert(arg_pigeon_instanceIdentifier != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.CookieManager.pigeon_newInstance was null, expected non-null int.'); + try { + (pigeon_instanceManager ?? PigeonInstanceManager.instance) + .addHostCreatedInstance( + pigeon_newInstance?.call() ?? + CookieManager.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + ), + arg_pigeon_instanceIdentifier!, + ); + return wrapResponse(empty: true); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } + } + + static CookieManager pigeonVar_instance() { + final CookieManager pigeonVar_instance = CookieManager.pigeon_detached(); + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _PigeonInternalProxyApiBaseCodec(PigeonInstanceManager.instance); + final BinaryMessenger pigeonVar_binaryMessenger = + ServicesBinding.instance.defaultBinaryMessenger; + final int pigeonVar_instanceIdentifier = PigeonInstanceManager.instance + .addDartCreatedInstance(pigeonVar_instance); + () async { + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_android.CookieManager.instance'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = await pigeonVar_channel + .send([pigeonVar_instanceIdentifier]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return; + } + }(); + return pigeonVar_instance; + } + + /// Sets a single cookie (key-value pair) for the given URL. + Future setCookie( + String url, + String value, + ) async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecCookieManager; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_android.CookieManager.setCookie'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = await pigeonVar_channel + .send([this, url, value]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return; + } + } + + /// Removes all cookies. + Future removeAllCookies() async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecCookieManager; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_android.CookieManager.removeAllCookies'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = + await pigeonVar_channel.send([this]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else if (pigeonVar_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (pigeonVar_replyList[0] as bool?)!; + } + } + + /// Sets whether the `WebView` should allow third party cookies to be set. + Future setAcceptThirdPartyCookies( + WebView webView, + bool accept, + ) async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecCookieManager; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_android.CookieManager.setAcceptThirdPartyCookies'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = await pigeonVar_channel + .send([this, webView, accept]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return; + } + } + + @override + CookieManager pigeon_copy() { + return CookieManager.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + ); + } +} + +/// A View that displays web pages. +/// +/// See https://developer.android.com/reference/android/webkit/WebView. +class WebView extends View { + WebView({ + super.pigeon_binaryMessenger, + super.pigeon_instanceManager, + this.onScrollChanged, + }) : super.pigeon_detached() { + final int pigeonVar_instanceIdentifier = + pigeon_instanceManager.addDartCreatedInstance(this); + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecWebView; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + () async { + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_android.WebView.pigeon_defaultConstructor'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = await pigeonVar_channel + .send([pigeonVar_instanceIdentifier]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return; + } + }(); + } + + /// Constructs [WebView] without creating the associated native object. + /// + /// This should only be used by subclasses created by this library or to + /// create copies for an [PigeonInstanceManager]. + @protected + WebView.pigeon_detached({ + super.pigeon_binaryMessenger, + super.pigeon_instanceManager, + this.onScrollChanged, + }) : super.pigeon_detached(); + + late final _PigeonInternalProxyApiBaseCodec _pigeonVar_codecWebView = + _PigeonInternalProxyApiBaseCodec(pigeon_instanceManager); + + /// This is called in response to an internal scroll in this view (i.e., the + /// view scrolled its own contents). + /// + /// For the associated Native object to be automatically garbage collected, + /// it is required that the implementation of this `Function` doesn't have a + /// strong reference to the encapsulating class instance. When this `Function` + /// references a non-local variable, it is strongly recommended to access it + /// with a `WeakReference`: + /// + /// ```dart + /// final WeakReference weakMyVariable = WeakReference(myVariable); + /// final WebView instance = WebView( + /// onScrollChanged: (WebView pigeon_instance, ...) { + /// print(weakMyVariable?.target); + /// }, + /// ); + /// ``` + /// + /// Alternatively, [PigeonInstanceManager.removeWeakReference] can be used to + /// release the associated Native object manually. + final void Function( + WebView pigeon_instance, + int left, + int top, + int oldLeft, + int oldTop, + )? onScrollChanged; + + /// The WebSettings object used to control the settings for this WebView. + late final WebSettings settings = pigeonVar_settings(); + + static void pigeon_setUpMessageHandlers({ + bool pigeon_clearHandlers = false, + BinaryMessenger? pigeon_binaryMessenger, + PigeonInstanceManager? pigeon_instanceManager, + WebView Function()? pigeon_newInstance, + void Function( + WebView pigeon_instance, + int left, + int top, + int oldLeft, + int oldTop, + )? onScrollChanged, + }) { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _PigeonInternalProxyApiBaseCodec( + pigeon_instanceManager ?? PigeonInstanceManager.instance); + final BinaryMessenger? binaryMessenger = pigeon_binaryMessenger; + { + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.webview_flutter_android.WebView.pigeon_newInstance', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (pigeon_clearHandlers) { + pigeonVar_channel.setMessageHandler(null); + } else { + pigeonVar_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebView.pigeon_newInstance was null.'); + final List args = (message as List?)!; + final int? arg_pigeon_instanceIdentifier = (args[0] as int?); + assert(arg_pigeon_instanceIdentifier != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebView.pigeon_newInstance was null, expected non-null int.'); + try { + (pigeon_instanceManager ?? PigeonInstanceManager.instance) + .addHostCreatedInstance( + pigeon_newInstance?.call() ?? + WebView.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + ), + arg_pigeon_instanceIdentifier!, + ); + return wrapResponse(empty: true); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } + + { + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.webview_flutter_android.WebView.onScrollChanged', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (pigeon_clearHandlers) { + pigeonVar_channel.setMessageHandler(null); + } else { + pigeonVar_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebView.onScrollChanged was null.'); + final List args = (message as List?)!; + final WebView? arg_pigeon_instance = (args[0] as WebView?); + assert(arg_pigeon_instance != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebView.onScrollChanged was null, expected non-null WebView.'); + final int? arg_left = (args[1] as int?); + assert(arg_left != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebView.onScrollChanged was null, expected non-null int.'); + final int? arg_top = (args[2] as int?); + assert(arg_top != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebView.onScrollChanged was null, expected non-null int.'); + final int? arg_oldLeft = (args[3] as int?); + assert(arg_oldLeft != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebView.onScrollChanged was null, expected non-null int.'); + final int? arg_oldTop = (args[4] as int?); + assert(arg_oldTop != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebView.onScrollChanged was null, expected non-null int.'); + try { + (onScrollChanged ?? arg_pigeon_instance!.onScrollChanged)?.call( + arg_pigeon_instance!, + arg_left!, + arg_top!, + arg_oldLeft!, + arg_oldTop!); + return wrapResponse(empty: true); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } + } + + WebSettings pigeonVar_settings() { + final WebSettings pigeonVar_instance = WebSettings.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + ); + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecWebView; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + final int pigeonVar_instanceIdentifier = + pigeon_instanceManager.addDartCreatedInstance(pigeonVar_instance); + () async { + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_android.WebView.settings'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = await pigeonVar_channel + .send([this, pigeonVar_instanceIdentifier]) + as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return; + } + }(); + return pigeonVar_instance; + } + + /// Loads the given data into this WebView using a 'data' scheme URL. + Future loadData( + String data, + String? mimeType, + String? encoding, + ) async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecWebView; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_android.WebView.loadData'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = await pigeonVar_channel + .send([this, data, mimeType, encoding]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return; + } + } + + /// Loads the given data into this WebView, using baseUrl as the base URL for + /// the content. + Future loadDataWithBaseUrl( + String? baseUrl, + String data, + String? mimeType, + String? encoding, + String? historyUrl, + ) async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecWebView; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_android.WebView.loadDataWithBaseUrl'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = await pigeonVar_channel.send( + [this, baseUrl, data, mimeType, encoding, historyUrl]) + as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return; + } + } + + /// Loads the given URL. + Future loadUrl( + String url, + Map headers, + ) async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecWebView; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_android.WebView.loadUrl'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = await pigeonVar_channel + .send([this, url, headers]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return; + } + } + + /// Loads the URL with postData using "POST" method into this WebView. + Future postUrl( + String url, + Uint8List data, + ) async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecWebView; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_android.WebView.postUrl'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = await pigeonVar_channel + .send([this, url, data]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return; + } + } + + /// Gets the URL for the current page. + Future getUrl() async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecWebView; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_android.WebView.getUrl'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = + await pigeonVar_channel.send([this]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return (pigeonVar_replyList[0] as String?); + } + } + + /// Gets whether this WebView has a back history item. + Future canGoBack() async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecWebView; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_android.WebView.canGoBack'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = + await pigeonVar_channel.send([this]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else if (pigeonVar_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (pigeonVar_replyList[0] as bool?)!; + } + } + + /// Gets whether this WebView has a forward history item. + Future canGoForward() async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecWebView; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_android.WebView.canGoForward'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = + await pigeonVar_channel.send([this]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else if (pigeonVar_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (pigeonVar_replyList[0] as bool?)!; + } + } + + /// Goes back in the history of this WebView. + Future goBack() async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecWebView; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_android.WebView.goBack'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = + await pigeonVar_channel.send([this]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return; + } + } + + /// Goes forward in the history of this WebView. + Future goForward() async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecWebView; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_android.WebView.goForward'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = + await pigeonVar_channel.send([this]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return; + } + } + + /// Reloads the current URL. + Future reload() async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecWebView; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_android.WebView.reload'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = + await pigeonVar_channel.send([this]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return; + } + } + + /// Clears the resource cache. + Future clearCache(bool includeDiskFiles) async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecWebView; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_android.WebView.clearCache'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = await pigeonVar_channel + .send([this, includeDiskFiles]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return; + } + } + + /// Asynchronously evaluates JavaScript in the context of the currently + /// displayed page. + Future evaluateJavascript(String javascriptString) async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecWebView; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_android.WebView.evaluateJavascript'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = await pigeonVar_channel + .send([this, javascriptString]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return (pigeonVar_replyList[0] as String?); + } + } + + /// Gets the title for the current page. + Future getTitle() async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecWebView; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_android.WebView.getTitle'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = + await pigeonVar_channel.send([this]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return (pigeonVar_replyList[0] as String?); + } + } + + /// Enables debugging of web contents (HTML / CSS / JavaScript) loaded into + /// any WebViews of this application. + static Future setWebContentsDebuggingEnabled( + bool enabled, { + BinaryMessenger? pigeon_binaryMessenger, + PigeonInstanceManager? pigeon_instanceManager, + }) async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _PigeonInternalProxyApiBaseCodec( + pigeon_instanceManager ?? PigeonInstanceManager.instance); + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_android.WebView.setWebContentsDebuggingEnabled'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = + await pigeonVar_channel.send([enabled]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return; + } + } + + /// Sets the WebViewClient that will receive various notifications and + /// requests. + Future setWebViewClient(WebViewClient? client) async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecWebView; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_android.WebView.setWebViewClient'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = + await pigeonVar_channel.send([this, client]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return; + } + } + + /// Injects the supplied Java object into this WebView. + Future addJavaScriptChannel(JavaScriptChannel channel) async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecWebView; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_android.WebView.addJavaScriptChannel'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = await pigeonVar_channel + .send([this, channel]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return; + } + } + + /// Removes a previously injected Java object from this WebView. + Future removeJavaScriptChannel(String name) async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecWebView; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_android.WebView.removeJavaScriptChannel'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = + await pigeonVar_channel.send([this, name]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return; + } + } + + /// Registers the interface to be used when content can not be handled by the + /// rendering engine, and should be downloaded instead. + Future setDownloadListener(DownloadListener? listener) async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecWebView; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_android.WebView.setDownloadListener'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = await pigeonVar_channel + .send([this, listener]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return; + } + } + + /// Sets the chrome handler. + Future setWebChromeClient(WebChromeClient? client) async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecWebView; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_android.WebView.setWebChromeClient'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = + await pigeonVar_channel.send([this, client]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return; + } + } + + /// Sets the background color for this view. + Future setBackgroundColor(int color) async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecWebView; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_android.WebView.setBackgroundColor'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = + await pigeonVar_channel.send([this, color]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return; + } + } + + /// Destroys the internal state of this WebView. + Future destroy() async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecWebView; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_android.WebView.destroy'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = + await pigeonVar_channel.send([this]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return; + } + } + + @override + WebView pigeon_copy() { + return WebView.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + onScrollChanged: onScrollChanged, + ); + } +} + +/// Manages settings state for a `WebView`. +/// +/// See https://developer.android.com/reference/android/webkit/WebSettings. +class WebSettings extends PigeonInternalProxyApiBaseClass { + /// Constructs [WebSettings] without creating the associated native object. + /// + /// This should only be used by subclasses created by this library or to + /// create copies for an [PigeonInstanceManager]. + @protected + WebSettings.pigeon_detached({ + super.pigeon_binaryMessenger, + super.pigeon_instanceManager, + }); + + late final _PigeonInternalProxyApiBaseCodec _pigeonVar_codecWebSettings = + _PigeonInternalProxyApiBaseCodec(pigeon_instanceManager); + + static void pigeon_setUpMessageHandlers({ + bool pigeon_clearHandlers = false, + BinaryMessenger? pigeon_binaryMessenger, + PigeonInstanceManager? pigeon_instanceManager, + WebSettings Function()? pigeon_newInstance, + }) { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _PigeonInternalProxyApiBaseCodec( + pigeon_instanceManager ?? PigeonInstanceManager.instance); + final BinaryMessenger? binaryMessenger = pigeon_binaryMessenger; + { + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.webview_flutter_android.WebSettings.pigeon_newInstance', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (pigeon_clearHandlers) { + pigeonVar_channel.setMessageHandler(null); + } else { + pigeonVar_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebSettings.pigeon_newInstance was null.'); + final List args = (message as List?)!; + final int? arg_pigeon_instanceIdentifier = (args[0] as int?); + assert(arg_pigeon_instanceIdentifier != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebSettings.pigeon_newInstance was null, expected non-null int.'); + try { + (pigeon_instanceManager ?? PigeonInstanceManager.instance) + .addHostCreatedInstance( + pigeon_newInstance?.call() ?? + WebSettings.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + ), + arg_pigeon_instanceIdentifier!, + ); + return wrapResponse(empty: true); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } + } + + /// Sets whether the DOM storage API is enabled. + Future setDomStorageEnabled(bool flag) async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecWebSettings; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_android.WebSettings.setDomStorageEnabled'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = + await pigeonVar_channel.send([this, flag]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return; + } + } + + /// Tells JavaScript to open windows automatically. + Future setJavaScriptCanOpenWindowsAutomatically(bool flag) async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecWebSettings; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_android.WebSettings.setJavaScriptCanOpenWindowsAutomatically'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = + await pigeonVar_channel.send([this, flag]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return; + } + } + + /// Sets whether the WebView whether supports multiple windows. + Future setSupportMultipleWindows(bool support) async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecWebSettings; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_android.WebSettings.setSupportMultipleWindows'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = await pigeonVar_channel + .send([this, support]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return; + } + } + + /// Tells the WebView to enable JavaScript execution. + Future setJavaScriptEnabled(bool flag) async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecWebSettings; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_android.WebSettings.setJavaScriptEnabled'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = + await pigeonVar_channel.send([this, flag]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return; + } + } + + /// Sets the WebView's user-agent string. + Future setUserAgentString(String? userAgentString) async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecWebSettings; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_android.WebSettings.setUserAgentString'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = await pigeonVar_channel + .send([this, userAgentString]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return; + } + } + + /// Sets whether the WebView requires a user gesture to play media. + Future setMediaPlaybackRequiresUserGesture(bool require) async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecWebSettings; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_android.WebSettings.setMediaPlaybackRequiresUserGesture'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = await pigeonVar_channel + .send([this, require]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return; + } + } + + /// Sets whether the WebView should support zooming using its on-screen zoom + /// controls and gestures. + Future setSupportZoom(bool support) async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecWebSettings; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_android.WebSettings.setSupportZoom'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = await pigeonVar_channel + .send([this, support]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return; + } + } + + /// Sets whether the WebView loads pages in overview mode, that is, zooms out + /// the content to fit on screen by width. + Future setLoadWithOverviewMode(bool overview) async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecWebSettings; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_android.WebSettings.setLoadWithOverviewMode'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = await pigeonVar_channel + .send([this, overview]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return; + } + } + + /// Sets whether the WebView should enable support for the "viewport" HTML + /// meta tag or should use a wide viewport. + Future setUseWideViewPort(bool use) async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecWebSettings; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_android.WebSettings.setUseWideViewPort'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = + await pigeonVar_channel.send([this, use]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return; + } + } + + /// Sets whether the WebView should display on-screen zoom controls when using + /// the built-in zoom mechanisms. + Future setDisplayZoomControls(bool enabled) async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecWebSettings; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_android.WebSettings.setDisplayZoomControls'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = await pigeonVar_channel + .send([this, enabled]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return; + } + } + + /// Sets whether the WebView should display on-screen zoom controls when using + /// the built-in zoom mechanisms. + Future setBuiltInZoomControls(bool enabled) async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecWebSettings; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_android.WebSettings.setBuiltInZoomControls'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = await pigeonVar_channel + .send([this, enabled]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return; + } + } + + /// Enables or disables file access within WebView. + Future setAllowFileAccess(bool enabled) async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecWebSettings; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_android.WebSettings.setAllowFileAccess'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = await pigeonVar_channel + .send([this, enabled]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return; + } + } + + /// Sets the text zoom of the page in percent. + Future setTextZoom(int textZoom) async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecWebSettings; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_android.WebSettings.setTextZoom'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = await pigeonVar_channel + .send([this, textZoom]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return; + } + } + + /// Gets the WebView's user-agent string. + Future getUserAgentString() async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecWebSettings; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_android.WebSettings.getUserAgentString'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = + await pigeonVar_channel.send([this]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else if (pigeonVar_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (pigeonVar_replyList[0] as String?)!; + } + } + + @override + WebSettings pigeon_copy() { + return WebSettings.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + ); + } +} + +/// A JavaScript interface for exposing Javascript callbacks to Dart. +/// +/// This is a custom class for the wrapper that is annotated with +/// [JavascriptInterface](https://developer.android.com/reference/android/webkit/JavascriptInterface). +class JavaScriptChannel extends PigeonInternalProxyApiBaseClass { + JavaScriptChannel({ + super.pigeon_binaryMessenger, + super.pigeon_instanceManager, + required this.channelName, + required this.postMessage, + }) { + final int pigeonVar_instanceIdentifier = + pigeon_instanceManager.addDartCreatedInstance(this); + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecJavaScriptChannel; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + () async { + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_android.JavaScriptChannel.pigeon_defaultConstructor'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = await pigeonVar_channel + .send([pigeonVar_instanceIdentifier, channelName]) + as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return; + } + }(); + } + + /// Constructs [JavaScriptChannel] without creating the associated native object. + /// + /// This should only be used by subclasses created by this library or to + /// create copies for an [PigeonInstanceManager]. + @protected + JavaScriptChannel.pigeon_detached({ + super.pigeon_binaryMessenger, + super.pigeon_instanceManager, + required this.channelName, + required this.postMessage, + }); + + late final _PigeonInternalProxyApiBaseCodec + _pigeonVar_codecJavaScriptChannel = + _PigeonInternalProxyApiBaseCodec(pigeon_instanceManager); + + final String channelName; + + /// Handles callbacks messages from JavaScript. + /// + /// For the associated Native object to be automatically garbage collected, + /// it is required that the implementation of this `Function` doesn't have a + /// strong reference to the encapsulating class instance. When this `Function` + /// references a non-local variable, it is strongly recommended to access it + /// with a `WeakReference`: + /// + /// ```dart + /// final WeakReference weakMyVariable = WeakReference(myVariable); + /// final JavaScriptChannel instance = JavaScriptChannel( + /// postMessage: (JavaScriptChannel pigeon_instance, ...) { + /// print(weakMyVariable?.target); + /// }, + /// ); + /// ``` + /// + /// Alternatively, [PigeonInstanceManager.removeWeakReference] can be used to + /// release the associated Native object manually. + final void Function( + JavaScriptChannel pigeon_instance, + String message, + ) postMessage; + + static void pigeon_setUpMessageHandlers({ + bool pigeon_clearHandlers = false, + BinaryMessenger? pigeon_binaryMessenger, + PigeonInstanceManager? pigeon_instanceManager, + void Function( + JavaScriptChannel pigeon_instance, + String message, + )? postMessage, + }) { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _PigeonInternalProxyApiBaseCodec( + pigeon_instanceManager ?? PigeonInstanceManager.instance); + final BinaryMessenger? binaryMessenger = pigeon_binaryMessenger; + { + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.webview_flutter_android.JavaScriptChannel.postMessage', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (pigeon_clearHandlers) { + pigeonVar_channel.setMessageHandler(null); + } else { + pigeonVar_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.JavaScriptChannel.postMessage was null.'); + final List args = (message as List?)!; + final JavaScriptChannel? arg_pigeon_instance = + (args[0] as JavaScriptChannel?); + assert(arg_pigeon_instance != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.JavaScriptChannel.postMessage was null, expected non-null JavaScriptChannel.'); + final String? arg_message = (args[1] as String?); + assert(arg_message != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.JavaScriptChannel.postMessage was null, expected non-null String.'); + try { + (postMessage ?? arg_pigeon_instance!.postMessage) + .call(arg_pigeon_instance!, arg_message!); + return wrapResponse(empty: true); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } + } + + @override + JavaScriptChannel pigeon_copy() { + return JavaScriptChannel.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + channelName: channelName, + postMessage: postMessage, + ); + } +} + +/// Receives various notifications and requests from a `WebView`. +/// +/// See https://developer.android.com/reference/android/webkit/WebViewClient. +class WebViewClient extends PigeonInternalProxyApiBaseClass { + WebViewClient({ + super.pigeon_binaryMessenger, + super.pigeon_instanceManager, + this.onPageStarted, + this.onPageFinished, + this.onReceivedHttpError, + this.onReceivedRequestError, + this.onReceivedRequestErrorCompat, + this.onReceivedError, + this.requestLoading, + this.urlLoading, + this.doUpdateVisitedHistory, + this.onReceivedHttpAuthRequest, + }) { + final int pigeonVar_instanceIdentifier = + pigeon_instanceManager.addDartCreatedInstance(this); + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecWebViewClient; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + () async { + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_android.WebViewClient.pigeon_defaultConstructor'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = await pigeonVar_channel + .send([pigeonVar_instanceIdentifier]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return; + } + }(); + } + + /// Constructs [WebViewClient] without creating the associated native object. + /// + /// This should only be used by subclasses created by this library or to + /// create copies for an [PigeonInstanceManager]. + @protected + WebViewClient.pigeon_detached({ + super.pigeon_binaryMessenger, + super.pigeon_instanceManager, + this.onPageStarted, + this.onPageFinished, + this.onReceivedHttpError, + this.onReceivedRequestError, + this.onReceivedRequestErrorCompat, + this.onReceivedError, + this.requestLoading, + this.urlLoading, + this.doUpdateVisitedHistory, + this.onReceivedHttpAuthRequest, + }); + + late final _PigeonInternalProxyApiBaseCodec _pigeonVar_codecWebViewClient = + _PigeonInternalProxyApiBaseCodec(pigeon_instanceManager); + + /// Notify the host application that a page has started loading. + /// + /// For the associated Native object to be automatically garbage collected, + /// it is required that the implementation of this `Function` doesn't have a + /// strong reference to the encapsulating class instance. When this `Function` + /// references a non-local variable, it is strongly recommended to access it + /// with a `WeakReference`: + /// + /// ```dart + /// final WeakReference weakMyVariable = WeakReference(myVariable); + /// final WebViewClient instance = WebViewClient( + /// onPageStarted: (WebViewClient pigeon_instance, ...) { + /// print(weakMyVariable?.target); + /// }, + /// ); + /// ``` + /// + /// Alternatively, [PigeonInstanceManager.removeWeakReference] can be used to + /// release the associated Native object manually. + final void Function( + WebViewClient pigeon_instance, + WebView webView, + String url, + )? onPageStarted; + + /// Notify the host application that a page has finished loading. + /// + /// For the associated Native object to be automatically garbage collected, + /// it is required that the implementation of this `Function` doesn't have a + /// strong reference to the encapsulating class instance. When this `Function` + /// references a non-local variable, it is strongly recommended to access it + /// with a `WeakReference`: + /// + /// ```dart + /// final WeakReference weakMyVariable = WeakReference(myVariable); + /// final WebViewClient instance = WebViewClient( + /// onPageFinished: (WebViewClient pigeon_instance, ...) { + /// print(weakMyVariable?.target); + /// }, + /// ); + /// ``` + /// + /// Alternatively, [PigeonInstanceManager.removeWeakReference] can be used to + /// release the associated Native object manually. + final void Function( + WebViewClient pigeon_instance, + WebView webView, + String url, + )? onPageFinished; + + /// Notify the host application that an HTTP error has been received from the + /// server while loading a resource. + /// + /// For the associated Native object to be automatically garbage collected, + /// it is required that the implementation of this `Function` doesn't have a + /// strong reference to the encapsulating class instance. When this `Function` + /// references a non-local variable, it is strongly recommended to access it + /// with a `WeakReference`: + /// + /// ```dart + /// final WeakReference weakMyVariable = WeakReference(myVariable); + /// final WebViewClient instance = WebViewClient( + /// onReceivedHttpError: (WebViewClient pigeon_instance, ...) { + /// print(weakMyVariable?.target); + /// }, + /// ); + /// ``` + /// + /// Alternatively, [PigeonInstanceManager.removeWeakReference] can be used to + /// release the associated Native object manually. + final void Function( + WebViewClient pigeon_instance, + WebView webView, + WebResourceRequest request, + WebResourceResponse response, + )? onReceivedHttpError; + + /// Report web resource loading error to the host application. + /// + /// For the associated Native object to be automatically garbage collected, + /// it is required that the implementation of this `Function` doesn't have a + /// strong reference to the encapsulating class instance. When this `Function` + /// references a non-local variable, it is strongly recommended to access it + /// with a `WeakReference`: + /// + /// ```dart + /// final WeakReference weakMyVariable = WeakReference(myVariable); + /// final WebViewClient instance = WebViewClient( + /// onReceivedRequestError: (WebViewClient pigeon_instance, ...) { + /// print(weakMyVariable?.target); + /// }, + /// ); + /// ``` + /// + /// Alternatively, [PigeonInstanceManager.removeWeakReference] can be used to + /// release the associated Native object manually. + final void Function( + WebViewClient pigeon_instance, + WebView webView, + WebResourceRequest request, + WebResourceError error, + )? onReceivedRequestError; + + /// Report web resource loading error to the host application. + /// + /// For the associated Native object to be automatically garbage collected, + /// it is required that the implementation of this `Function` doesn't have a + /// strong reference to the encapsulating class instance. When this `Function` + /// references a non-local variable, it is strongly recommended to access it + /// with a `WeakReference`: + /// + /// ```dart + /// final WeakReference weakMyVariable = WeakReference(myVariable); + /// final WebViewClient instance = WebViewClient( + /// onReceivedRequestErrorCompat: (WebViewClient pigeon_instance, ...) { + /// print(weakMyVariable?.target); + /// }, + /// ); + /// ``` + /// + /// Alternatively, [PigeonInstanceManager.removeWeakReference] can be used to + /// release the associated Native object manually. + final void Function( + WebViewClient pigeon_instance, + WebView webView, + WebResourceRequest request, + WebResourceErrorCompat error, + )? onReceivedRequestErrorCompat; + + /// Report an error to the host application. + /// + /// For the associated Native object to be automatically garbage collected, + /// it is required that the implementation of this `Function` doesn't have a + /// strong reference to the encapsulating class instance. When this `Function` + /// references a non-local variable, it is strongly recommended to access it + /// with a `WeakReference`: + /// + /// ```dart + /// final WeakReference weakMyVariable = WeakReference(myVariable); + /// final WebViewClient instance = WebViewClient( + /// onReceivedError: (WebViewClient pigeon_instance, ...) { + /// print(weakMyVariable?.target); + /// }, + /// ); + /// ``` + /// + /// Alternatively, [PigeonInstanceManager.removeWeakReference] can be used to + /// release the associated Native object manually. + final void Function( + WebViewClient pigeon_instance, + WebView webView, + int errorCode, + String description, + String failingUrl, + )? onReceivedError; + + /// Give the host application a chance to take control when a URL is about to + /// be loaded in the current WebView. + /// + /// For the associated Native object to be automatically garbage collected, + /// it is required that the implementation of this `Function` doesn't have a + /// strong reference to the encapsulating class instance. When this `Function` + /// references a non-local variable, it is strongly recommended to access it + /// with a `WeakReference`: + /// + /// ```dart + /// final WeakReference weakMyVariable = WeakReference(myVariable); + /// final WebViewClient instance = WebViewClient( + /// requestLoading: (WebViewClient pigeon_instance, ...) { + /// print(weakMyVariable?.target); + /// }, + /// ); + /// ``` + /// + /// Alternatively, [PigeonInstanceManager.removeWeakReference] can be used to + /// release the associated Native object manually. + final void Function( + WebViewClient pigeon_instance, + WebView webView, + WebResourceRequest request, + )? requestLoading; + + /// Give the host application a chance to take control when a URL is about to + /// be loaded in the current WebView. + /// + /// For the associated Native object to be automatically garbage collected, + /// it is required that the implementation of this `Function` doesn't have a + /// strong reference to the encapsulating class instance. When this `Function` + /// references a non-local variable, it is strongly recommended to access it + /// with a `WeakReference`: + /// + /// ```dart + /// final WeakReference weakMyVariable = WeakReference(myVariable); + /// final WebViewClient instance = WebViewClient( + /// urlLoading: (WebViewClient pigeon_instance, ...) { + /// print(weakMyVariable?.target); + /// }, + /// ); + /// ``` + /// + /// Alternatively, [PigeonInstanceManager.removeWeakReference] can be used to + /// release the associated Native object manually. + final void Function( + WebViewClient pigeon_instance, + WebView webView, + String url, + )? urlLoading; + + /// Notify the host application to update its visited links database. + /// + /// For the associated Native object to be automatically garbage collected, + /// it is required that the implementation of this `Function` doesn't have a + /// strong reference to the encapsulating class instance. When this `Function` + /// references a non-local variable, it is strongly recommended to access it + /// with a `WeakReference`: + /// + /// ```dart + /// final WeakReference weakMyVariable = WeakReference(myVariable); + /// final WebViewClient instance = WebViewClient( + /// doUpdateVisitedHistory: (WebViewClient pigeon_instance, ...) { + /// print(weakMyVariable?.target); + /// }, + /// ); + /// ``` + /// + /// Alternatively, [PigeonInstanceManager.removeWeakReference] can be used to + /// release the associated Native object manually. + final void Function( + WebViewClient pigeon_instance, + WebView webView, + String url, + bool isReload, + )? doUpdateVisitedHistory; + + /// Notifies the host application that the WebView received an HTTP + /// authentication request. + /// + /// For the associated Native object to be automatically garbage collected, + /// it is required that the implementation of this `Function` doesn't have a + /// strong reference to the encapsulating class instance. When this `Function` + /// references a non-local variable, it is strongly recommended to access it + /// with a `WeakReference`: + /// + /// ```dart + /// final WeakReference weakMyVariable = WeakReference(myVariable); + /// final WebViewClient instance = WebViewClient( + /// onReceivedHttpAuthRequest: (WebViewClient pigeon_instance, ...) { + /// print(weakMyVariable?.target); + /// }, + /// ); + /// ``` + /// + /// Alternatively, [PigeonInstanceManager.removeWeakReference] can be used to + /// release the associated Native object manually. + final void Function( + WebViewClient pigeon_instance, + WebView webView, + HttpAuthHandler handler, + String host, + String realm, + )? onReceivedHttpAuthRequest; + + static void pigeon_setUpMessageHandlers({ + bool pigeon_clearHandlers = false, + BinaryMessenger? pigeon_binaryMessenger, + PigeonInstanceManager? pigeon_instanceManager, + WebViewClient Function()? pigeon_newInstance, + void Function( + WebViewClient pigeon_instance, + WebView webView, + String url, + )? onPageStarted, + void Function( + WebViewClient pigeon_instance, + WebView webView, + String url, + )? onPageFinished, + void Function( + WebViewClient pigeon_instance, + WebView webView, + WebResourceRequest request, + WebResourceResponse response, + )? onReceivedHttpError, + void Function( + WebViewClient pigeon_instance, + WebView webView, + WebResourceRequest request, + WebResourceError error, + )? onReceivedRequestError, + void Function( + WebViewClient pigeon_instance, + WebView webView, + WebResourceRequest request, + WebResourceErrorCompat error, + )? onReceivedRequestErrorCompat, + void Function( + WebViewClient pigeon_instance, + WebView webView, + int errorCode, + String description, + String failingUrl, + )? onReceivedError, + void Function( + WebViewClient pigeon_instance, + WebView webView, + WebResourceRequest request, + )? requestLoading, + void Function( + WebViewClient pigeon_instance, + WebView webView, + String url, + )? urlLoading, + void Function( + WebViewClient pigeon_instance, + WebView webView, + String url, + bool isReload, + )? doUpdateVisitedHistory, + void Function( + WebViewClient pigeon_instance, + WebView webView, + HttpAuthHandler handler, + String host, + String realm, + )? onReceivedHttpAuthRequest, + }) { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _PigeonInternalProxyApiBaseCodec( + pigeon_instanceManager ?? PigeonInstanceManager.instance); + final BinaryMessenger? binaryMessenger = pigeon_binaryMessenger; + { + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.webview_flutter_android.WebViewClient.pigeon_newInstance', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (pigeon_clearHandlers) { + pigeonVar_channel.setMessageHandler(null); + } else { + pigeonVar_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewClient.pigeon_newInstance was null.'); + final List args = (message as List?)!; + final int? arg_pigeon_instanceIdentifier = (args[0] as int?); + assert(arg_pigeon_instanceIdentifier != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewClient.pigeon_newInstance was null, expected non-null int.'); + try { + (pigeon_instanceManager ?? PigeonInstanceManager.instance) + .addHostCreatedInstance( + pigeon_newInstance?.call() ?? + WebViewClient.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + ), + arg_pigeon_instanceIdentifier!, + ); + return wrapResponse(empty: true); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } + + { + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.webview_flutter_android.WebViewClient.onPageStarted', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (pigeon_clearHandlers) { + pigeonVar_channel.setMessageHandler(null); + } else { + pigeonVar_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewClient.onPageStarted was null.'); + final List args = (message as List?)!; + final WebViewClient? arg_pigeon_instance = + (args[0] as WebViewClient?); + assert(arg_pigeon_instance != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewClient.onPageStarted was null, expected non-null WebViewClient.'); + final WebView? arg_webView = (args[1] as WebView?); + assert(arg_webView != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewClient.onPageStarted was null, expected non-null WebView.'); + final String? arg_url = (args[2] as String?); + assert(arg_url != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewClient.onPageStarted was null, expected non-null String.'); + try { + (onPageStarted ?? arg_pigeon_instance!.onPageStarted) + ?.call(arg_pigeon_instance!, arg_webView!, arg_url!); + return wrapResponse(empty: true); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } + + { + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.webview_flutter_android.WebViewClient.onPageFinished', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (pigeon_clearHandlers) { + pigeonVar_channel.setMessageHandler(null); + } else { + pigeonVar_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewClient.onPageFinished was null.'); + final List args = (message as List?)!; + final WebViewClient? arg_pigeon_instance = + (args[0] as WebViewClient?); + assert(arg_pigeon_instance != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewClient.onPageFinished was null, expected non-null WebViewClient.'); + final WebView? arg_webView = (args[1] as WebView?); + assert(arg_webView != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewClient.onPageFinished was null, expected non-null WebView.'); + final String? arg_url = (args[2] as String?); + assert(arg_url != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewClient.onPageFinished was null, expected non-null String.'); + try { + (onPageFinished ?? arg_pigeon_instance!.onPageFinished) + ?.call(arg_pigeon_instance!, arg_webView!, arg_url!); + return wrapResponse(empty: true); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } + + { + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.webview_flutter_android.WebViewClient.onReceivedHttpError', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (pigeon_clearHandlers) { + pigeonVar_channel.setMessageHandler(null); + } else { + pigeonVar_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewClient.onReceivedHttpError was null.'); + final List args = (message as List?)!; + final WebViewClient? arg_pigeon_instance = + (args[0] as WebViewClient?); + assert(arg_pigeon_instance != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewClient.onReceivedHttpError was null, expected non-null WebViewClient.'); + final WebView? arg_webView = (args[1] as WebView?); + assert(arg_webView != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewClient.onReceivedHttpError was null, expected non-null WebView.'); + final WebResourceRequest? arg_request = + (args[2] as WebResourceRequest?); + assert(arg_request != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewClient.onReceivedHttpError was null, expected non-null WebResourceRequest.'); + final WebResourceResponse? arg_response = + (args[3] as WebResourceResponse?); + assert(arg_response != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewClient.onReceivedHttpError was null, expected non-null WebResourceResponse.'); + try { + (onReceivedHttpError ?? arg_pigeon_instance!.onReceivedHttpError) + ?.call(arg_pigeon_instance!, arg_webView!, arg_request!, + arg_response!); + return wrapResponse(empty: true); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } + + { + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.webview_flutter_android.WebViewClient.onReceivedRequestError', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (pigeon_clearHandlers) { + pigeonVar_channel.setMessageHandler(null); + } else { + pigeonVar_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewClient.onReceivedRequestError was null.'); + final List args = (message as List?)!; + final WebViewClient? arg_pigeon_instance = + (args[0] as WebViewClient?); + assert(arg_pigeon_instance != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewClient.onReceivedRequestError was null, expected non-null WebViewClient.'); + final WebView? arg_webView = (args[1] as WebView?); + assert(arg_webView != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewClient.onReceivedRequestError was null, expected non-null WebView.'); + final WebResourceRequest? arg_request = + (args[2] as WebResourceRequest?); + assert(arg_request != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewClient.onReceivedRequestError was null, expected non-null WebResourceRequest.'); + final WebResourceError? arg_error = (args[3] as WebResourceError?); + assert(arg_error != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewClient.onReceivedRequestError was null, expected non-null WebResourceError.'); + try { + (onReceivedRequestError ?? + arg_pigeon_instance!.onReceivedRequestError) + ?.call(arg_pigeon_instance!, arg_webView!, arg_request!, + arg_error!); + return wrapResponse(empty: true); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } + + { + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.webview_flutter_android.WebViewClient.onReceivedRequestErrorCompat', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (pigeon_clearHandlers) { + pigeonVar_channel.setMessageHandler(null); + } else { + pigeonVar_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewClient.onReceivedRequestErrorCompat was null.'); + final List args = (message as List?)!; + final WebViewClient? arg_pigeon_instance = + (args[0] as WebViewClient?); + assert(arg_pigeon_instance != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewClient.onReceivedRequestErrorCompat was null, expected non-null WebViewClient.'); + final WebView? arg_webView = (args[1] as WebView?); + assert(arg_webView != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewClient.onReceivedRequestErrorCompat was null, expected non-null WebView.'); + final WebResourceRequest? arg_request = + (args[2] as WebResourceRequest?); + assert(arg_request != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewClient.onReceivedRequestErrorCompat was null, expected non-null WebResourceRequest.'); + final WebResourceErrorCompat? arg_error = + (args[3] as WebResourceErrorCompat?); + assert(arg_error != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewClient.onReceivedRequestErrorCompat was null, expected non-null WebResourceErrorCompat.'); + try { + (onReceivedRequestErrorCompat ?? + arg_pigeon_instance!.onReceivedRequestErrorCompat) + ?.call(arg_pigeon_instance!, arg_webView!, arg_request!, + arg_error!); + return wrapResponse(empty: true); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } + + { + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.webview_flutter_android.WebViewClient.onReceivedError', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (pigeon_clearHandlers) { + pigeonVar_channel.setMessageHandler(null); + } else { + pigeonVar_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewClient.onReceivedError was null.'); + final List args = (message as List?)!; + final WebViewClient? arg_pigeon_instance = + (args[0] as WebViewClient?); + assert(arg_pigeon_instance != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewClient.onReceivedError was null, expected non-null WebViewClient.'); + final WebView? arg_webView = (args[1] as WebView?); + assert(arg_webView != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewClient.onReceivedError was null, expected non-null WebView.'); + final int? arg_errorCode = (args[2] as int?); + assert(arg_errorCode != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewClient.onReceivedError was null, expected non-null int.'); + final String? arg_description = (args[3] as String?); + assert(arg_description != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewClient.onReceivedError was null, expected non-null String.'); + final String? arg_failingUrl = (args[4] as String?); + assert(arg_failingUrl != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewClient.onReceivedError was null, expected non-null String.'); + try { + (onReceivedError ?? arg_pigeon_instance!.onReceivedError)?.call( + arg_pigeon_instance!, + arg_webView!, + arg_errorCode!, + arg_description!, + arg_failingUrl!); + return wrapResponse(empty: true); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } + + { + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.webview_flutter_android.WebViewClient.requestLoading', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (pigeon_clearHandlers) { + pigeonVar_channel.setMessageHandler(null); + } else { + pigeonVar_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewClient.requestLoading was null.'); + final List args = (message as List?)!; + final WebViewClient? arg_pigeon_instance = + (args[0] as WebViewClient?); + assert(arg_pigeon_instance != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewClient.requestLoading was null, expected non-null WebViewClient.'); + final WebView? arg_webView = (args[1] as WebView?); + assert(arg_webView != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewClient.requestLoading was null, expected non-null WebView.'); + final WebResourceRequest? arg_request = + (args[2] as WebResourceRequest?); + assert(arg_request != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewClient.requestLoading was null, expected non-null WebResourceRequest.'); + try { + (requestLoading ?? arg_pigeon_instance!.requestLoading) + ?.call(arg_pigeon_instance!, arg_webView!, arg_request!); + return wrapResponse(empty: true); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } + + { + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.webview_flutter_android.WebViewClient.urlLoading', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (pigeon_clearHandlers) { + pigeonVar_channel.setMessageHandler(null); + } else { + pigeonVar_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewClient.urlLoading was null.'); + final List args = (message as List?)!; + final WebViewClient? arg_pigeon_instance = + (args[0] as WebViewClient?); + assert(arg_pigeon_instance != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewClient.urlLoading was null, expected non-null WebViewClient.'); + final WebView? arg_webView = (args[1] as WebView?); + assert(arg_webView != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewClient.urlLoading was null, expected non-null WebView.'); + final String? arg_url = (args[2] as String?); + assert(arg_url != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewClient.urlLoading was null, expected non-null String.'); + try { + (urlLoading ?? arg_pigeon_instance!.urlLoading) + ?.call(arg_pigeon_instance!, arg_webView!, arg_url!); + return wrapResponse(empty: true); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } + + { + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.webview_flutter_android.WebViewClient.doUpdateVisitedHistory', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (pigeon_clearHandlers) { + pigeonVar_channel.setMessageHandler(null); + } else { + pigeonVar_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewClient.doUpdateVisitedHistory was null.'); + final List args = (message as List?)!; + final WebViewClient? arg_pigeon_instance = + (args[0] as WebViewClient?); + assert(arg_pigeon_instance != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewClient.doUpdateVisitedHistory was null, expected non-null WebViewClient.'); + final WebView? arg_webView = (args[1] as WebView?); + assert(arg_webView != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewClient.doUpdateVisitedHistory was null, expected non-null WebView.'); + final String? arg_url = (args[2] as String?); + assert(arg_url != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewClient.doUpdateVisitedHistory was null, expected non-null String.'); + final bool? arg_isReload = (args[3] as bool?); + assert(arg_isReload != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewClient.doUpdateVisitedHistory was null, expected non-null bool.'); + try { + (doUpdateVisitedHistory ?? + arg_pigeon_instance!.doUpdateVisitedHistory) + ?.call(arg_pigeon_instance!, arg_webView!, arg_url!, + arg_isReload!); + return wrapResponse(empty: true); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } + + { + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.webview_flutter_android.WebViewClient.onReceivedHttpAuthRequest', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (pigeon_clearHandlers) { + pigeonVar_channel.setMessageHandler(null); + } else { + pigeonVar_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewClient.onReceivedHttpAuthRequest was null.'); + final List args = (message as List?)!; + final WebViewClient? arg_pigeon_instance = + (args[0] as WebViewClient?); + assert(arg_pigeon_instance != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewClient.onReceivedHttpAuthRequest was null, expected non-null WebViewClient.'); + final WebView? arg_webView = (args[1] as WebView?); + assert(arg_webView != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewClient.onReceivedHttpAuthRequest was null, expected non-null WebView.'); + final HttpAuthHandler? arg_handler = (args[2] as HttpAuthHandler?); + assert(arg_handler != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewClient.onReceivedHttpAuthRequest was null, expected non-null HttpAuthHandler.'); + final String? arg_host = (args[3] as String?); + assert(arg_host != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewClient.onReceivedHttpAuthRequest was null, expected non-null String.'); + final String? arg_realm = (args[4] as String?); + assert(arg_realm != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewClient.onReceivedHttpAuthRequest was null, expected non-null String.'); + try { + (onReceivedHttpAuthRequest ?? + arg_pigeon_instance!.onReceivedHttpAuthRequest) + ?.call(arg_pigeon_instance!, arg_webView!, arg_handler!, + arg_host!, arg_realm!); + return wrapResponse(empty: true); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } + } + + /// Sets the required synchronous return value for the Java method, + /// `WebViewClient.shouldOverrideUrlLoading(...)`. + /// + /// The Java method, `WebViewClient.shouldOverrideUrlLoading(...)`, requires + /// a boolean to be returned and this method sets the returned value for all + /// calls to the Java method. + /// + /// Setting this to true causes the current [WebView] to abort loading any URL + /// received by [requestLoading] or [urlLoading], while setting this to false + /// causes the [WebView] to continue loading a URL as usual. + /// + /// Defaults to false. + Future setSynchronousReturnValueForShouldOverrideUrlLoading( + bool value) async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecWebViewClient; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_android.WebViewClient.setSynchronousReturnValueForShouldOverrideUrlLoading'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = + await pigeonVar_channel.send([this, value]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return; + } + } + + @override + WebViewClient pigeon_copy() { + return WebViewClient.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + onPageStarted: onPageStarted, + onPageFinished: onPageFinished, + onReceivedHttpError: onReceivedHttpError, + onReceivedRequestError: onReceivedRequestError, + onReceivedRequestErrorCompat: onReceivedRequestErrorCompat, + onReceivedError: onReceivedError, + requestLoading: requestLoading, + urlLoading: urlLoading, + doUpdateVisitedHistory: doUpdateVisitedHistory, + onReceivedHttpAuthRequest: onReceivedHttpAuthRequest, + ); + } +} + +/// Handles notifications that a file should be downloaded. +/// +/// See https://developer.android.com/reference/android/webkit/DownloadListener. +class DownloadListener extends PigeonInternalProxyApiBaseClass { + DownloadListener({ + super.pigeon_binaryMessenger, + super.pigeon_instanceManager, + required this.onDownloadStart, + }) { + final int pigeonVar_instanceIdentifier = + pigeon_instanceManager.addDartCreatedInstance(this); + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecDownloadListener; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + () async { + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_android.DownloadListener.pigeon_defaultConstructor'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = await pigeonVar_channel + .send([pigeonVar_instanceIdentifier]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return; + } + }(); + } + + /// Constructs [DownloadListener] without creating the associated native object. + /// + /// This should only be used by subclasses created by this library or to + /// create copies for an [PigeonInstanceManager]. + @protected + DownloadListener.pigeon_detached({ + super.pigeon_binaryMessenger, + super.pigeon_instanceManager, + required this.onDownloadStart, + }); + + late final _PigeonInternalProxyApiBaseCodec _pigeonVar_codecDownloadListener = + _PigeonInternalProxyApiBaseCodec(pigeon_instanceManager); + + /// Notify the host application that a file should be downloaded. + /// + /// For the associated Native object to be automatically garbage collected, + /// it is required that the implementation of this `Function` doesn't have a + /// strong reference to the encapsulating class instance. When this `Function` + /// references a non-local variable, it is strongly recommended to access it + /// with a `WeakReference`: + /// + /// ```dart + /// final WeakReference weakMyVariable = WeakReference(myVariable); + /// final DownloadListener instance = DownloadListener( + /// onDownloadStart: (DownloadListener pigeon_instance, ...) { + /// print(weakMyVariable?.target); + /// }, + /// ); + /// ``` + /// + /// Alternatively, [PigeonInstanceManager.removeWeakReference] can be used to + /// release the associated Native object manually. + final void Function( + DownloadListener pigeon_instance, + String url, + String userAgent, + String contentDisposition, + String mimetype, + int contentLength, + ) onDownloadStart; + + static void pigeon_setUpMessageHandlers({ + bool pigeon_clearHandlers = false, + BinaryMessenger? pigeon_binaryMessenger, + PigeonInstanceManager? pigeon_instanceManager, + void Function( + DownloadListener pigeon_instance, + String url, + String userAgent, + String contentDisposition, + String mimetype, + int contentLength, + )? onDownloadStart, + }) { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _PigeonInternalProxyApiBaseCodec( + pigeon_instanceManager ?? PigeonInstanceManager.instance); + final BinaryMessenger? binaryMessenger = pigeon_binaryMessenger; + { + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.webview_flutter_android.DownloadListener.onDownloadStart', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (pigeon_clearHandlers) { + pigeonVar_channel.setMessageHandler(null); + } else { + pigeonVar_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.DownloadListener.onDownloadStart was null.'); + final List args = (message as List?)!; + final DownloadListener? arg_pigeon_instance = + (args[0] as DownloadListener?); + assert(arg_pigeon_instance != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.DownloadListener.onDownloadStart was null, expected non-null DownloadListener.'); + final String? arg_url = (args[1] as String?); + assert(arg_url != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.DownloadListener.onDownloadStart was null, expected non-null String.'); + final String? arg_userAgent = (args[2] as String?); + assert(arg_userAgent != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.DownloadListener.onDownloadStart was null, expected non-null String.'); + final String? arg_contentDisposition = (args[3] as String?); + assert(arg_contentDisposition != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.DownloadListener.onDownloadStart was null, expected non-null String.'); + final String? arg_mimetype = (args[4] as String?); + assert(arg_mimetype != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.DownloadListener.onDownloadStart was null, expected non-null String.'); + final int? arg_contentLength = (args[5] as int?); + assert(arg_contentLength != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.DownloadListener.onDownloadStart was null, expected non-null int.'); + try { + (onDownloadStart ?? arg_pigeon_instance!.onDownloadStart).call( + arg_pigeon_instance!, + arg_url!, + arg_userAgent!, + arg_contentDisposition!, + arg_mimetype!, + arg_contentLength!); + return wrapResponse(empty: true); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } + } + + @override + DownloadListener pigeon_copy() { + return DownloadListener.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + onDownloadStart: onDownloadStart, + ); + } +} + +/// Handles notification of JavaScript dialogs, favicons, titles, and the +/// progress. +/// +/// See https://developer.android.com/reference/android/webkit/WebChromeClient. +class WebChromeClient extends PigeonInternalProxyApiBaseClass { + WebChromeClient({ + super.pigeon_binaryMessenger, + super.pigeon_instanceManager, + this.onProgressChanged, + this.onShowFileChooser, + this.onPermissionRequest, + this.onShowCustomView, + this.onHideCustomView, + this.onGeolocationPermissionsShowPrompt, + this.onGeolocationPermissionsHidePrompt, + this.onConsoleMessage, + this.onJsAlert, + this.onJsConfirm, + this.onJsPrompt, + }) { + final int pigeonVar_instanceIdentifier = + pigeon_instanceManager.addDartCreatedInstance(this); + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecWebChromeClient; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + () async { + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_android.WebChromeClient.pigeon_defaultConstructor'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = await pigeonVar_channel + .send([pigeonVar_instanceIdentifier]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return; + } + }(); + } + + /// Constructs [WebChromeClient] without creating the associated native object. + /// + /// This should only be used by subclasses created by this library or to + /// create copies for an [PigeonInstanceManager]. + @protected + WebChromeClient.pigeon_detached({ + super.pigeon_binaryMessenger, + super.pigeon_instanceManager, + this.onProgressChanged, + this.onShowFileChooser, + this.onPermissionRequest, + this.onShowCustomView, + this.onHideCustomView, + this.onGeolocationPermissionsShowPrompt, + this.onGeolocationPermissionsHidePrompt, + this.onConsoleMessage, + this.onJsAlert, + this.onJsConfirm, + this.onJsPrompt, + }); + + late final _PigeonInternalProxyApiBaseCodec _pigeonVar_codecWebChromeClient = + _PigeonInternalProxyApiBaseCodec(pigeon_instanceManager); + + /// Tell the host application the current progress of loading a page. + /// + /// For the associated Native object to be automatically garbage collected, + /// it is required that the implementation of this `Function` doesn't have a + /// strong reference to the encapsulating class instance. When this `Function` + /// references a non-local variable, it is strongly recommended to access it + /// with a `WeakReference`: + /// + /// ```dart + /// final WeakReference weakMyVariable = WeakReference(myVariable); + /// final WebChromeClient instance = WebChromeClient( + /// onProgressChanged: (WebChromeClient pigeon_instance, ...) { + /// print(weakMyVariable?.target); + /// }, + /// ); + /// ``` + /// + /// Alternatively, [PigeonInstanceManager.removeWeakReference] can be used to + /// release the associated Native object manually. + final void Function( + WebChromeClient pigeon_instance, + WebView webView, + int progress, + )? onProgressChanged; + + /// Tell the client to show a file chooser. + /// + /// For the associated Native object to be automatically garbage collected, + /// it is required that the implementation of this `Function` doesn't have a + /// strong reference to the encapsulating class instance. When this `Function` + /// references a non-local variable, it is strongly recommended to access it + /// with a `WeakReference`: + /// + /// ```dart + /// final WeakReference weakMyVariable = WeakReference(myVariable); + /// final WebChromeClient instance = WebChromeClient( + /// onShowFileChooser: (WebChromeClient pigeon_instance, ...) { + /// print(weakMyVariable?.target); + /// }, + /// ); + /// ``` + /// + /// Alternatively, [PigeonInstanceManager.removeWeakReference] can be used to + /// release the associated Native object manually. + final Future> Function( + WebChromeClient pigeon_instance, + WebView webView, + FileChooserParams params, + )? onShowFileChooser; + + /// Notify the host application that web content is requesting permission to + /// access the specified resources and the permission currently isn't granted + /// or denied. + /// + /// For the associated Native object to be automatically garbage collected, + /// it is required that the implementation of this `Function` doesn't have a + /// strong reference to the encapsulating class instance. When this `Function` + /// references a non-local variable, it is strongly recommended to access it + /// with a `WeakReference`: + /// + /// ```dart + /// final WeakReference weakMyVariable = WeakReference(myVariable); + /// final WebChromeClient instance = WebChromeClient( + /// onPermissionRequest: (WebChromeClient pigeon_instance, ...) { + /// print(weakMyVariable?.target); + /// }, + /// ); + /// ``` + /// + /// Alternatively, [PigeonInstanceManager.removeWeakReference] can be used to + /// release the associated Native object manually. + final void Function( + WebChromeClient pigeon_instance, + PermissionRequest request, + )? onPermissionRequest; + + /// Callback to Dart function `WebChromeClient.onShowCustomView`. + /// + /// For the associated Native object to be automatically garbage collected, + /// it is required that the implementation of this `Function` doesn't have a + /// strong reference to the encapsulating class instance. When this `Function` + /// references a non-local variable, it is strongly recommended to access it + /// with a `WeakReference`: + /// + /// ```dart + /// final WeakReference weakMyVariable = WeakReference(myVariable); + /// final WebChromeClient instance = WebChromeClient( + /// onShowCustomView: (WebChromeClient pigeon_instance, ...) { + /// print(weakMyVariable?.target); + /// }, + /// ); + /// ``` + /// + /// Alternatively, [PigeonInstanceManager.removeWeakReference] can be used to + /// release the associated Native object manually. + final void Function( + WebChromeClient pigeon_instance, + View view, + CustomViewCallback callback, + )? onShowCustomView; + + /// Notify the host application that the current page has entered full screen + /// mode. + /// + /// For the associated Native object to be automatically garbage collected, + /// it is required that the implementation of this `Function` doesn't have a + /// strong reference to the encapsulating class instance. When this `Function` + /// references a non-local variable, it is strongly recommended to access it + /// with a `WeakReference`: + /// + /// ```dart + /// final WeakReference weakMyVariable = WeakReference(myVariable); + /// final WebChromeClient instance = WebChromeClient( + /// onHideCustomView: (WebChromeClient pigeon_instance, ...) { + /// print(weakMyVariable?.target); + /// }, + /// ); + /// ``` + /// + /// Alternatively, [PigeonInstanceManager.removeWeakReference] can be used to + /// release the associated Native object manually. + final void Function(WebChromeClient pigeon_instance)? onHideCustomView; + + /// Notify the host application that web content from the specified origin is + /// attempting to use the Geolocation API, but no permission state is + /// currently set for that origin. + /// + /// For the associated Native object to be automatically garbage collected, + /// it is required that the implementation of this `Function` doesn't have a + /// strong reference to the encapsulating class instance. When this `Function` + /// references a non-local variable, it is strongly recommended to access it + /// with a `WeakReference`: + /// + /// ```dart + /// final WeakReference weakMyVariable = WeakReference(myVariable); + /// final WebChromeClient instance = WebChromeClient( + /// onGeolocationPermissionsShowPrompt: (WebChromeClient pigeon_instance, ...) { + /// print(weakMyVariable?.target); + /// }, + /// ); + /// ``` + /// + /// Alternatively, [PigeonInstanceManager.removeWeakReference] can be used to + /// release the associated Native object manually. + final void Function( + WebChromeClient pigeon_instance, + String origin, + GeolocationPermissionsCallback callback, + )? onGeolocationPermissionsShowPrompt; + + /// Notify the host application that a request for Geolocation permissions, + /// made with a previous call to `onGeolocationPermissionsShowPrompt` has been + /// canceled. + /// + /// For the associated Native object to be automatically garbage collected, + /// it is required that the implementation of this `Function` doesn't have a + /// strong reference to the encapsulating class instance. When this `Function` + /// references a non-local variable, it is strongly recommended to access it + /// with a `WeakReference`: + /// + /// ```dart + /// final WeakReference weakMyVariable = WeakReference(myVariable); + /// final WebChromeClient instance = WebChromeClient( + /// onGeolocationPermissionsHidePrompt: (WebChromeClient pigeon_instance, ...) { + /// print(weakMyVariable?.target); + /// }, + /// ); + /// ``` + /// + /// Alternatively, [PigeonInstanceManager.removeWeakReference] can be used to + /// release the associated Native object manually. + final void Function(WebChromeClient pigeon_instance)? + onGeolocationPermissionsHidePrompt; + + /// Report a JavaScript console message to the host application. + /// + /// For the associated Native object to be automatically garbage collected, + /// it is required that the implementation of this `Function` doesn't have a + /// strong reference to the encapsulating class instance. When this `Function` + /// references a non-local variable, it is strongly recommended to access it + /// with a `WeakReference`: + /// + /// ```dart + /// final WeakReference weakMyVariable = WeakReference(myVariable); + /// final WebChromeClient instance = WebChromeClient( + /// onConsoleMessage: (WebChromeClient pigeon_instance, ...) { + /// print(weakMyVariable?.target); + /// }, + /// ); + /// ``` + /// + /// Alternatively, [PigeonInstanceManager.removeWeakReference] can be used to + /// release the associated Native object manually. + final void Function( + WebChromeClient pigeon_instance, + ConsoleMessage message, + )? onConsoleMessage; + + /// Notify the host application that the web page wants to display a + /// JavaScript `alert()` dialog. + /// + /// For the associated Native object to be automatically garbage collected, + /// it is required that the implementation of this `Function` doesn't have a + /// strong reference to the encapsulating class instance. When this `Function` + /// references a non-local variable, it is strongly recommended to access it + /// with a `WeakReference`: + /// + /// ```dart + /// final WeakReference weakMyVariable = WeakReference(myVariable); + /// final WebChromeClient instance = WebChromeClient( + /// onJsAlert: (WebChromeClient pigeon_instance, ...) { + /// print(weakMyVariable?.target); + /// }, + /// ); + /// ``` + /// + /// Alternatively, [PigeonInstanceManager.removeWeakReference] can be used to + /// release the associated Native object manually. + final Future Function( + WebChromeClient pigeon_instance, + WebView webView, + String url, + String message, + )? onJsAlert; + + /// Notify the host application that the web page wants to display a + /// JavaScript `confirm()` dialog. + /// + /// For the associated Native object to be automatically garbage collected, + /// it is required that the implementation of this `Function` doesn't have a + /// strong reference to the encapsulating class instance. When this `Function` + /// references a non-local variable, it is strongly recommended to access it + /// with a `WeakReference`: + /// + /// ```dart + /// final WeakReference weakMyVariable = WeakReference(myVariable); + /// final WebChromeClient instance = WebChromeClient( + /// onJsConfirm: (WebChromeClient pigeon_instance, ...) { + /// print(weakMyVariable?.target); + /// }, + /// ); + /// ``` + /// + /// Alternatively, [PigeonInstanceManager.removeWeakReference] can be used to + /// release the associated Native object manually. + final Future Function( + WebChromeClient pigeon_instance, + WebView webView, + String url, + String message, + )? onJsConfirm; + + /// Notify the host application that the web page wants to display a + /// JavaScript `prompt()` dialog. + /// + /// For the associated Native object to be automatically garbage collected, + /// it is required that the implementation of this `Function` doesn't have a + /// strong reference to the encapsulating class instance. When this `Function` + /// references a non-local variable, it is strongly recommended to access it + /// with a `WeakReference`: + /// + /// ```dart + /// final WeakReference weakMyVariable = WeakReference(myVariable); + /// final WebChromeClient instance = WebChromeClient( + /// onJsPrompt: (WebChromeClient pigeon_instance, ...) { + /// print(weakMyVariable?.target); + /// }, + /// ); + /// ``` + /// + /// Alternatively, [PigeonInstanceManager.removeWeakReference] can be used to + /// release the associated Native object manually. + final Future Function( + WebChromeClient pigeon_instance, + WebView webView, + String url, + String message, + String defaultValue, + )? onJsPrompt; + + static void pigeon_setUpMessageHandlers({ + bool pigeon_clearHandlers = false, + BinaryMessenger? pigeon_binaryMessenger, + PigeonInstanceManager? pigeon_instanceManager, + WebChromeClient Function()? pigeon_newInstance, + void Function( + WebChromeClient pigeon_instance, + WebView webView, + int progress, + )? onProgressChanged, + Future> Function( + WebChromeClient pigeon_instance, + WebView webView, + FileChooserParams params, + )? onShowFileChooser, + void Function( + WebChromeClient pigeon_instance, + PermissionRequest request, + )? onPermissionRequest, + void Function( + WebChromeClient pigeon_instance, + View view, + CustomViewCallback callback, + )? onShowCustomView, + void Function(WebChromeClient pigeon_instance)? onHideCustomView, + void Function( + WebChromeClient pigeon_instance, + String origin, + GeolocationPermissionsCallback callback, + )? onGeolocationPermissionsShowPrompt, + void Function(WebChromeClient pigeon_instance)? + onGeolocationPermissionsHidePrompt, + void Function( + WebChromeClient pigeon_instance, + ConsoleMessage message, + )? onConsoleMessage, + Future Function( + WebChromeClient pigeon_instance, + WebView webView, + String url, + String message, + )? onJsAlert, + Future Function( + WebChromeClient pigeon_instance, + WebView webView, + String url, + String message, + )? onJsConfirm, + Future Function( + WebChromeClient pigeon_instance, + WebView webView, + String url, + String message, + String defaultValue, + )? onJsPrompt, + }) { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _PigeonInternalProxyApiBaseCodec( + pigeon_instanceManager ?? PigeonInstanceManager.instance); + final BinaryMessenger? binaryMessenger = pigeon_binaryMessenger; + { + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.webview_flutter_android.WebChromeClient.pigeon_newInstance', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (pigeon_clearHandlers) { + pigeonVar_channel.setMessageHandler(null); + } else { + pigeonVar_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebChromeClient.pigeon_newInstance was null.'); + final List args = (message as List?)!; + final int? arg_pigeon_instanceIdentifier = (args[0] as int?); + assert(arg_pigeon_instanceIdentifier != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebChromeClient.pigeon_newInstance was null, expected non-null int.'); + try { + (pigeon_instanceManager ?? PigeonInstanceManager.instance) + .addHostCreatedInstance( + pigeon_newInstance?.call() ?? + WebChromeClient.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + ), + arg_pigeon_instanceIdentifier!, + ); + return wrapResponse(empty: true); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } + + { + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.webview_flutter_android.WebChromeClient.onProgressChanged', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (pigeon_clearHandlers) { + pigeonVar_channel.setMessageHandler(null); + } else { + pigeonVar_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebChromeClient.onProgressChanged was null.'); + final List args = (message as List?)!; + final WebChromeClient? arg_pigeon_instance = + (args[0] as WebChromeClient?); + assert(arg_pigeon_instance != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebChromeClient.onProgressChanged was null, expected non-null WebChromeClient.'); + final WebView? arg_webView = (args[1] as WebView?); + assert(arg_webView != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebChromeClient.onProgressChanged was null, expected non-null WebView.'); + final int? arg_progress = (args[2] as int?); + assert(arg_progress != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebChromeClient.onProgressChanged was null, expected non-null int.'); + try { + (onProgressChanged ?? arg_pigeon_instance!.onProgressChanged) + ?.call(arg_pigeon_instance!, arg_webView!, arg_progress!); + return wrapResponse(empty: true); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } + + { + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.webview_flutter_android.WebChromeClient.onShowFileChooser', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (pigeon_clearHandlers) { + pigeonVar_channel.setMessageHandler(null); + } else { + pigeonVar_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebChromeClient.onShowFileChooser was null.'); + final List args = (message as List?)!; + final WebChromeClient? arg_pigeon_instance = + (args[0] as WebChromeClient?); + assert(arg_pigeon_instance != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebChromeClient.onShowFileChooser was null, expected non-null WebChromeClient.'); + final WebView? arg_webView = (args[1] as WebView?); + assert(arg_webView != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebChromeClient.onShowFileChooser was null, expected non-null WebView.'); + final FileChooserParams? arg_params = (args[2] as FileChooserParams?); + assert(arg_params != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebChromeClient.onShowFileChooser was null, expected non-null FileChooserParams.'); + try { + final List? output = await (onShowFileChooser ?? + arg_pigeon_instance!.onShowFileChooser) + ?.call(arg_pigeon_instance!, arg_webView!, arg_params!); + return wrapResponse(result: output); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } + + { + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.webview_flutter_android.WebChromeClient.onPermissionRequest', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (pigeon_clearHandlers) { + pigeonVar_channel.setMessageHandler(null); + } else { + pigeonVar_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebChromeClient.onPermissionRequest was null.'); + final List args = (message as List?)!; + final WebChromeClient? arg_pigeon_instance = + (args[0] as WebChromeClient?); + assert(arg_pigeon_instance != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebChromeClient.onPermissionRequest was null, expected non-null WebChromeClient.'); + final PermissionRequest? arg_request = + (args[1] as PermissionRequest?); + assert(arg_request != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebChromeClient.onPermissionRequest was null, expected non-null PermissionRequest.'); + try { + (onPermissionRequest ?? arg_pigeon_instance!.onPermissionRequest) + ?.call(arg_pigeon_instance!, arg_request!); + return wrapResponse(empty: true); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } + + { + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.webview_flutter_android.WebChromeClient.onShowCustomView', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (pigeon_clearHandlers) { + pigeonVar_channel.setMessageHandler(null); + } else { + pigeonVar_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebChromeClient.onShowCustomView was null.'); + final List args = (message as List?)!; + final WebChromeClient? arg_pigeon_instance = + (args[0] as WebChromeClient?); + assert(arg_pigeon_instance != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebChromeClient.onShowCustomView was null, expected non-null WebChromeClient.'); + final View? arg_view = (args[1] as View?); + assert(arg_view != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebChromeClient.onShowCustomView was null, expected non-null View.'); + final CustomViewCallback? arg_callback = + (args[2] as CustomViewCallback?); + assert(arg_callback != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebChromeClient.onShowCustomView was null, expected non-null CustomViewCallback.'); + try { + (onShowCustomView ?? arg_pigeon_instance!.onShowCustomView) + ?.call(arg_pigeon_instance!, arg_view!, arg_callback!); + return wrapResponse(empty: true); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } + + { + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.webview_flutter_android.WebChromeClient.onHideCustomView', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (pigeon_clearHandlers) { + pigeonVar_channel.setMessageHandler(null); + } else { + pigeonVar_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebChromeClient.onHideCustomView was null.'); + final List args = (message as List?)!; + final WebChromeClient? arg_pigeon_instance = + (args[0] as WebChromeClient?); + assert(arg_pigeon_instance != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebChromeClient.onHideCustomView was null, expected non-null WebChromeClient.'); + try { + (onHideCustomView ?? arg_pigeon_instance!.onHideCustomView) + ?.call(arg_pigeon_instance!); + return wrapResponse(empty: true); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } + + { + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.webview_flutter_android.WebChromeClient.onGeolocationPermissionsShowPrompt', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (pigeon_clearHandlers) { + pigeonVar_channel.setMessageHandler(null); + } else { + pigeonVar_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebChromeClient.onGeolocationPermissionsShowPrompt was null.'); + final List args = (message as List?)!; + final WebChromeClient? arg_pigeon_instance = + (args[0] as WebChromeClient?); + assert(arg_pigeon_instance != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebChromeClient.onGeolocationPermissionsShowPrompt was null, expected non-null WebChromeClient.'); + final String? arg_origin = (args[1] as String?); + assert(arg_origin != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebChromeClient.onGeolocationPermissionsShowPrompt was null, expected non-null String.'); + final GeolocationPermissionsCallback? arg_callback = + (args[2] as GeolocationPermissionsCallback?); + assert(arg_callback != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebChromeClient.onGeolocationPermissionsShowPrompt was null, expected non-null GeolocationPermissionsCallback.'); + try { + (onGeolocationPermissionsShowPrompt ?? + arg_pigeon_instance!.onGeolocationPermissionsShowPrompt) + ?.call(arg_pigeon_instance!, arg_origin!, arg_callback!); + return wrapResponse(empty: true); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } + + { + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.webview_flutter_android.WebChromeClient.onGeolocationPermissionsHidePrompt', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (pigeon_clearHandlers) { + pigeonVar_channel.setMessageHandler(null); + } else { + pigeonVar_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebChromeClient.onGeolocationPermissionsHidePrompt was null.'); + final List args = (message as List?)!; + final WebChromeClient? arg_pigeon_instance = + (args[0] as WebChromeClient?); + assert(arg_pigeon_instance != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebChromeClient.onGeolocationPermissionsHidePrompt was null, expected non-null WebChromeClient.'); + try { + (onGeolocationPermissionsHidePrompt ?? + arg_pigeon_instance!.onGeolocationPermissionsHidePrompt) + ?.call(arg_pigeon_instance!); + return wrapResponse(empty: true); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } + + { + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.webview_flutter_android.WebChromeClient.onConsoleMessage', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (pigeon_clearHandlers) { + pigeonVar_channel.setMessageHandler(null); + } else { + pigeonVar_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebChromeClient.onConsoleMessage was null.'); + final List args = (message as List?)!; + final WebChromeClient? arg_pigeon_instance = + (args[0] as WebChromeClient?); + assert(arg_pigeon_instance != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebChromeClient.onConsoleMessage was null, expected non-null WebChromeClient.'); + final ConsoleMessage? arg_message = (args[1] as ConsoleMessage?); + assert(arg_message != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebChromeClient.onConsoleMessage was null, expected non-null ConsoleMessage.'); + try { + (onConsoleMessage ?? arg_pigeon_instance!.onConsoleMessage) + ?.call(arg_pigeon_instance!, arg_message!); + return wrapResponse(empty: true); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } + + { + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.webview_flutter_android.WebChromeClient.onJsAlert', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (pigeon_clearHandlers) { + pigeonVar_channel.setMessageHandler(null); + } else { + pigeonVar_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebChromeClient.onJsAlert was null.'); + final List args = (message as List?)!; + final WebChromeClient? arg_pigeon_instance = + (args[0] as WebChromeClient?); + assert(arg_pigeon_instance != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebChromeClient.onJsAlert was null, expected non-null WebChromeClient.'); + final WebView? arg_webView = (args[1] as WebView?); + assert(arg_webView != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebChromeClient.onJsAlert was null, expected non-null WebView.'); + final String? arg_url = (args[2] as String?); + assert(arg_url != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebChromeClient.onJsAlert was null, expected non-null String.'); + final String? arg_message = (args[3] as String?); + assert(arg_message != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebChromeClient.onJsAlert was null, expected non-null String.'); + try { + await (onJsAlert ?? arg_pigeon_instance!.onJsAlert)?.call( + arg_pigeon_instance!, arg_webView!, arg_url!, arg_message!); + return wrapResponse(empty: true); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } + + { + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.webview_flutter_android.WebChromeClient.onJsConfirm', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (pigeon_clearHandlers) { + pigeonVar_channel.setMessageHandler(null); + } else { + pigeonVar_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebChromeClient.onJsConfirm was null.'); + final List args = (message as List?)!; + final WebChromeClient? arg_pigeon_instance = + (args[0] as WebChromeClient?); + assert(arg_pigeon_instance != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebChromeClient.onJsConfirm was null, expected non-null WebChromeClient.'); + final WebView? arg_webView = (args[1] as WebView?); + assert(arg_webView != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebChromeClient.onJsConfirm was null, expected non-null WebView.'); + final String? arg_url = (args[2] as String?); + assert(arg_url != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebChromeClient.onJsConfirm was null, expected non-null String.'); + final String? arg_message = (args[3] as String?); + assert(arg_message != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebChromeClient.onJsConfirm was null, expected non-null String.'); + try { + final bool? output = + await (onJsConfirm ?? arg_pigeon_instance!.onJsConfirm)?.call( + arg_pigeon_instance!, arg_webView!, arg_url!, arg_message!); + return wrapResponse(result: output); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } + + { + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.webview_flutter_android.WebChromeClient.onJsPrompt', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (pigeon_clearHandlers) { + pigeonVar_channel.setMessageHandler(null); + } else { + pigeonVar_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebChromeClient.onJsPrompt was null.'); + final List args = (message as List?)!; + final WebChromeClient? arg_pigeon_instance = + (args[0] as WebChromeClient?); + assert(arg_pigeon_instance != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebChromeClient.onJsPrompt was null, expected non-null WebChromeClient.'); + final WebView? arg_webView = (args[1] as WebView?); + assert(arg_webView != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebChromeClient.onJsPrompt was null, expected non-null WebView.'); + final String? arg_url = (args[2] as String?); + assert(arg_url != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebChromeClient.onJsPrompt was null, expected non-null String.'); + final String? arg_message = (args[3] as String?); + assert(arg_message != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebChromeClient.onJsPrompt was null, expected non-null String.'); + final String? arg_defaultValue = (args[4] as String?); + assert(arg_defaultValue != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebChromeClient.onJsPrompt was null, expected non-null String.'); + try { + final String? output = + await (onJsPrompt ?? arg_pigeon_instance!.onJsPrompt)?.call( + arg_pigeon_instance!, + arg_webView!, + arg_url!, + arg_message!, + arg_defaultValue!); + return wrapResponse(result: output); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } + } + + /// Sets the required synchronous return value for the Java method, + /// `WebChromeClient.onShowFileChooser(...)`. + /// + /// The Java method, `WebChromeClient.onShowFileChooser(...)`, requires + /// a boolean to be returned and this method sets the returned value for all + /// calls to the Java method. + /// + /// Setting this to true indicates that all file chooser requests should be + /// handled by `onShowFileChooser` and the returned list of Strings will be + /// returned to the WebView. Otherwise, the client will use the default + /// handling and the returned value in `onShowFileChooser` will be ignored. + /// + /// Requires `onShowFileChooser` to be nonnull. + /// + /// Defaults to false. + Future setSynchronousReturnValueForOnShowFileChooser(bool value) async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecWebChromeClient; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_android.WebChromeClient.setSynchronousReturnValueForOnShowFileChooser'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = + await pigeonVar_channel.send([this, value]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return; + } + } + + /// Sets the required synchronous return value for the Java method, + /// `WebChromeClient.onConsoleMessage(...)`. + /// + /// The Java method, `WebChromeClient.onConsoleMessage(...)`, requires + /// a boolean to be returned and this method sets the returned value for all + /// calls to the Java method. + /// + /// Setting this to true indicates that the client is handling all console + /// messages. + /// + /// Requires `onConsoleMessage` to be nonnull. + /// + /// Defaults to false. + Future setSynchronousReturnValueForOnConsoleMessage(bool value) async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecWebChromeClient; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_android.WebChromeClient.setSynchronousReturnValueForOnConsoleMessage'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = + await pigeonVar_channel.send([this, value]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return; + } + } + + /// Sets the required synchronous return value for the Java method, + /// `WebChromeClient.onJsAlert(...)`. + /// + /// The Java method, `WebChromeClient.onJsAlert(...)`, requires a boolean to + /// be returned and this method sets the returned value for all calls to the + /// Java method. + /// + /// Setting this to true indicates that the client is handling all console + /// messages. + /// + /// Requires `onJsAlert` to be nonnull. + /// + /// Defaults to false. + Future setSynchronousReturnValueForOnJsAlert(bool value) async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecWebChromeClient; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_android.WebChromeClient.setSynchronousReturnValueForOnJsAlert'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = + await pigeonVar_channel.send([this, value]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return; + } + } + + /// Sets the required synchronous return value for the Java method, + /// `WebChromeClient.onJsConfirm(...)`. + /// + /// The Java method, `WebChromeClient.onJsConfirm(...)`, requires a boolean to + /// be returned and this method sets the returned value for all calls to the + /// Java method. + /// + /// Setting this to true indicates that the client is handling all console + /// messages. + /// + /// Requires `onJsConfirm` to be nonnull. + /// + /// Defaults to false. + Future setSynchronousReturnValueForOnJsConfirm(bool value) async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecWebChromeClient; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_android.WebChromeClient.setSynchronousReturnValueForOnJsConfirm'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = + await pigeonVar_channel.send([this, value]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return; + } + } + + /// Sets the required synchronous return value for the Java method, + /// `WebChromeClient.onJsPrompt(...)`. + /// + /// The Java method, `WebChromeClient.onJsPrompt(...)`, requires a boolean to + /// be returned and this method sets the returned value for all calls to the + /// Java method. + /// + /// Setting this to true indicates that the client is handling all console + /// messages. + /// + /// Requires `onJsPrompt` to be nonnull. + /// + /// Defaults to false. + Future setSynchronousReturnValueForOnJsPrompt(bool value) async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecWebChromeClient; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_android.WebChromeClient.setSynchronousReturnValueForOnJsPrompt'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = + await pigeonVar_channel.send([this, value]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return; + } + } + + @override + WebChromeClient pigeon_copy() { + return WebChromeClient.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + onProgressChanged: onProgressChanged, + onShowFileChooser: onShowFileChooser, + onPermissionRequest: onPermissionRequest, + onShowCustomView: onShowCustomView, + onHideCustomView: onHideCustomView, + onGeolocationPermissionsShowPrompt: onGeolocationPermissionsShowPrompt, + onGeolocationPermissionsHidePrompt: onGeolocationPermissionsHidePrompt, + onConsoleMessage: onConsoleMessage, + onJsAlert: onJsAlert, + onJsConfirm: onJsConfirm, + onJsPrompt: onJsPrompt, + ); + } +} + +/// Provides access to the assets registered as part of the App bundle. +/// +/// Convenience class for accessing Flutter asset resources. +class FlutterAssetManager extends PigeonInternalProxyApiBaseClass { + /// Constructs [FlutterAssetManager] without creating the associated native object. + /// + /// This should only be used by subclasses created by this library or to + /// create copies for an [PigeonInstanceManager]. + @protected + FlutterAssetManager.pigeon_detached({ + super.pigeon_binaryMessenger, + super.pigeon_instanceManager, + }); + + late final _PigeonInternalProxyApiBaseCodec + _pigeonVar_codecFlutterAssetManager = + _PigeonInternalProxyApiBaseCodec(pigeon_instanceManager); + + /// The global instance of the `FlutterAssetManager`. + static final FlutterAssetManager instance = pigeonVar_instance(); + + static void pigeon_setUpMessageHandlers({ + bool pigeon_clearHandlers = false, + BinaryMessenger? pigeon_binaryMessenger, + PigeonInstanceManager? pigeon_instanceManager, + FlutterAssetManager Function()? pigeon_newInstance, + }) { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _PigeonInternalProxyApiBaseCodec( + pigeon_instanceManager ?? PigeonInstanceManager.instance); + final BinaryMessenger? binaryMessenger = pigeon_binaryMessenger; + { + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.webview_flutter_android.FlutterAssetManager.pigeon_newInstance', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (pigeon_clearHandlers) { + pigeonVar_channel.setMessageHandler(null); + } else { + pigeonVar_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.FlutterAssetManager.pigeon_newInstance was null.'); + final List args = (message as List?)!; + final int? arg_pigeon_instanceIdentifier = (args[0] as int?); + assert(arg_pigeon_instanceIdentifier != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.FlutterAssetManager.pigeon_newInstance was null, expected non-null int.'); + try { + (pigeon_instanceManager ?? PigeonInstanceManager.instance) + .addHostCreatedInstance( + pigeon_newInstance?.call() ?? + FlutterAssetManager.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + ), + arg_pigeon_instanceIdentifier!, + ); + return wrapResponse(empty: true); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } + } + + static FlutterAssetManager pigeonVar_instance() { + final FlutterAssetManager pigeonVar_instance = + FlutterAssetManager.pigeon_detached(); + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _PigeonInternalProxyApiBaseCodec(PigeonInstanceManager.instance); + final BinaryMessenger pigeonVar_binaryMessenger = + ServicesBinding.instance.defaultBinaryMessenger; + final int pigeonVar_instanceIdentifier = PigeonInstanceManager.instance + .addDartCreatedInstance(pigeonVar_instance); + () async { + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_android.FlutterAssetManager.instance'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = await pigeonVar_channel + .send([pigeonVar_instanceIdentifier]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return; + } + }(); + return pigeonVar_instance; + } + + /// Returns a String array of all the assets at the given path. + /// + /// Throws an IOException in case I/O operations were interrupted. + Future> list(String path) async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecFlutterAssetManager; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_android.FlutterAssetManager.list'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = + await pigeonVar_channel.send([this, path]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else if (pigeonVar_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (pigeonVar_replyList[0] as List?)!.cast(); + } + } + + /// Gets the relative file path to the Flutter asset with the given name, including the file's + /// extension, e.g., "myImage.jpg". + /// + /// The returned file path is relative to the Android app's standard asset's + /// directory. Therefore, the returned path is appropriate to pass to + /// Android's AssetManager, but the path is not appropriate to load as an + /// absolute path. + Future getAssetFilePathByName(String name) async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecFlutterAssetManager; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_android.FlutterAssetManager.getAssetFilePathByName'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = + await pigeonVar_channel.send([this, name]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else if (pigeonVar_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (pigeonVar_replyList[0] as String?)!; + } + } + + @override + FlutterAssetManager pigeon_copy() { + return FlutterAssetManager.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + ); + } +} + +/// This class is used to manage the JavaScript storage APIs provided by the +/// WebView. +/// +/// See https://developer.android.com/reference/android/webkit/WebStorage. +class WebStorage extends PigeonInternalProxyApiBaseClass { + /// Constructs [WebStorage] without creating the associated native object. + /// + /// This should only be used by subclasses created by this library or to + /// create copies for an [PigeonInstanceManager]. + @protected + WebStorage.pigeon_detached({ + super.pigeon_binaryMessenger, + super.pigeon_instanceManager, + }); + + late final _PigeonInternalProxyApiBaseCodec _pigeonVar_codecWebStorage = + _PigeonInternalProxyApiBaseCodec(pigeon_instanceManager); + + static final WebStorage instance = pigeonVar_instance(); + + static void pigeon_setUpMessageHandlers({ + bool pigeon_clearHandlers = false, + BinaryMessenger? pigeon_binaryMessenger, + PigeonInstanceManager? pigeon_instanceManager, + WebStorage Function()? pigeon_newInstance, + }) { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _PigeonInternalProxyApiBaseCodec( + pigeon_instanceManager ?? PigeonInstanceManager.instance); + final BinaryMessenger? binaryMessenger = pigeon_binaryMessenger; + { + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.webview_flutter_android.WebStorage.pigeon_newInstance', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (pigeon_clearHandlers) { + pigeonVar_channel.setMessageHandler(null); + } else { + pigeonVar_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebStorage.pigeon_newInstance was null.'); + final List args = (message as List?)!; + final int? arg_pigeon_instanceIdentifier = (args[0] as int?); + assert(arg_pigeon_instanceIdentifier != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.WebStorage.pigeon_newInstance was null, expected non-null int.'); + try { + (pigeon_instanceManager ?? PigeonInstanceManager.instance) + .addHostCreatedInstance( + pigeon_newInstance?.call() ?? + WebStorage.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + ), + arg_pigeon_instanceIdentifier!, + ); + return wrapResponse(empty: true); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } + } + + static WebStorage pigeonVar_instance() { + final WebStorage pigeonVar_instance = WebStorage.pigeon_detached(); + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _PigeonInternalProxyApiBaseCodec(PigeonInstanceManager.instance); + final BinaryMessenger pigeonVar_binaryMessenger = + ServicesBinding.instance.defaultBinaryMessenger; + final int pigeonVar_instanceIdentifier = PigeonInstanceManager.instance + .addDartCreatedInstance(pigeonVar_instance); + () async { + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_android.WebStorage.instance'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = await pigeonVar_channel + .send([pigeonVar_instanceIdentifier]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return; + } + }(); + return pigeonVar_instance; + } + + /// Clears all storage currently being used by the JavaScript storage APIs. + Future deleteAllData() async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecWebStorage; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_android.WebStorage.deleteAllData'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = + await pigeonVar_channel.send([this]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return; + } + } + + @override + WebStorage pigeon_copy() { + return WebStorage.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + ); + } +} + +/// Parameters used in the `WebChromeClient.onShowFileChooser` method. +/// +/// See https://developer.android.com/reference/android/webkit/WebChromeClient.FileChooserParams. +class FileChooserParams extends PigeonInternalProxyApiBaseClass { + /// Constructs [FileChooserParams] without creating the associated native object. + /// + /// This should only be used by subclasses created by this library or to + /// create copies for an [PigeonInstanceManager]. + @protected + FileChooserParams.pigeon_detached({ + super.pigeon_binaryMessenger, + super.pigeon_instanceManager, + required this.isCaptureEnabled, + required this.acceptTypes, + required this.mode, + this.filenameHint, + }); + + /// Preference for a live media captured value (e.g. Camera, Microphone). + final bool isCaptureEnabled; + + /// An array of acceptable MIME types. + final List acceptTypes; + + /// File chooser mode. + final FileChooserMode mode; + + /// File name of a default selection if specified, or null. + final String? filenameHint; + + static void pigeon_setUpMessageHandlers({ + bool pigeon_clearHandlers = false, + BinaryMessenger? pigeon_binaryMessenger, + PigeonInstanceManager? pigeon_instanceManager, + FileChooserParams Function( + bool isCaptureEnabled, + List acceptTypes, + FileChooserMode mode, + String? filenameHint, + )? pigeon_newInstance, + }) { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _PigeonInternalProxyApiBaseCodec( + pigeon_instanceManager ?? PigeonInstanceManager.instance); + final BinaryMessenger? binaryMessenger = pigeon_binaryMessenger; + { + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.webview_flutter_android.FileChooserParams.pigeon_newInstance', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (pigeon_clearHandlers) { + pigeonVar_channel.setMessageHandler(null); + } else { + pigeonVar_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.FileChooserParams.pigeon_newInstance was null.'); + final List args = (message as List?)!; + final int? arg_pigeon_instanceIdentifier = (args[0] as int?); + assert(arg_pigeon_instanceIdentifier != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.FileChooserParams.pigeon_newInstance was null, expected non-null int.'); + final bool? arg_isCaptureEnabled = (args[1] as bool?); + assert(arg_isCaptureEnabled != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.FileChooserParams.pigeon_newInstance was null, expected non-null bool.'); + final List? arg_acceptTypes = + (args[2] as List?)?.cast(); + assert(arg_acceptTypes != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.FileChooserParams.pigeon_newInstance was null, expected non-null List.'); + final FileChooserMode? arg_mode = (args[3] as FileChooserMode?); + assert(arg_mode != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.FileChooserParams.pigeon_newInstance was null, expected non-null FileChooserMode.'); + final String? arg_filenameHint = (args[4] as String?); + try { + (pigeon_instanceManager ?? PigeonInstanceManager.instance) + .addHostCreatedInstance( + pigeon_newInstance?.call(arg_isCaptureEnabled!, arg_acceptTypes!, + arg_mode!, arg_filenameHint) ?? + FileChooserParams.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + isCaptureEnabled: arg_isCaptureEnabled!, + acceptTypes: arg_acceptTypes!, + mode: arg_mode!, + filenameHint: arg_filenameHint, + ), + arg_pigeon_instanceIdentifier!, + ); + return wrapResponse(empty: true); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } + } + + @override + FileChooserParams pigeon_copy() { + return FileChooserParams.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + isCaptureEnabled: isCaptureEnabled, + acceptTypes: acceptTypes, + mode: mode, + filenameHint: filenameHint, + ); + } +} + +/// This class defines a permission request and is used when web content +/// requests access to protected resources. +/// +/// See https://developer.android.com/reference/android/webkit/PermissionRequest. +class PermissionRequest extends PigeonInternalProxyApiBaseClass { + /// Constructs [PermissionRequest] without creating the associated native object. + /// + /// This should only be used by subclasses created by this library or to + /// create copies for an [PigeonInstanceManager]. + @protected + PermissionRequest.pigeon_detached({ + super.pigeon_binaryMessenger, + super.pigeon_instanceManager, + required this.resources, + }); + + late final _PigeonInternalProxyApiBaseCodec + _pigeonVar_codecPermissionRequest = + _PigeonInternalProxyApiBaseCodec(pigeon_instanceManager); + + final List resources; + + static void pigeon_setUpMessageHandlers({ + bool pigeon_clearHandlers = false, + BinaryMessenger? pigeon_binaryMessenger, + PigeonInstanceManager? pigeon_instanceManager, + PermissionRequest Function(List resources)? pigeon_newInstance, + }) { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _PigeonInternalProxyApiBaseCodec( + pigeon_instanceManager ?? PigeonInstanceManager.instance); + final BinaryMessenger? binaryMessenger = pigeon_binaryMessenger; + { + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.webview_flutter_android.PermissionRequest.pigeon_newInstance', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (pigeon_clearHandlers) { + pigeonVar_channel.setMessageHandler(null); + } else { + pigeonVar_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.PermissionRequest.pigeon_newInstance was null.'); + final List args = (message as List?)!; + final int? arg_pigeon_instanceIdentifier = (args[0] as int?); + assert(arg_pigeon_instanceIdentifier != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.PermissionRequest.pigeon_newInstance was null, expected non-null int.'); + final List? arg_resources = + (args[1] as List?)?.cast(); + assert(arg_resources != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.PermissionRequest.pigeon_newInstance was null, expected non-null List.'); + try { + (pigeon_instanceManager ?? PigeonInstanceManager.instance) + .addHostCreatedInstance( + pigeon_newInstance?.call(arg_resources!) ?? + PermissionRequest.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + resources: arg_resources!, + ), + arg_pigeon_instanceIdentifier!, + ); + return wrapResponse(empty: true); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } + } + + /// Call this method to grant origin the permission to access the given + /// resources. + Future grant(List resources) async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecPermissionRequest; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_android.PermissionRequest.grant'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = await pigeonVar_channel + .send([this, resources]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return; + } + } + + /// Call this method to deny the request. + Future deny() async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecPermissionRequest; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_android.PermissionRequest.deny'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = + await pigeonVar_channel.send([this]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return; + } + } + + @override + PermissionRequest pigeon_copy() { + return PermissionRequest.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + resources: resources, + ); + } +} + +/// A callback interface used by the host application to notify the current page +/// that its custom view has been dismissed. +/// +/// See https://developer.android.com/reference/android/webkit/WebChromeClient.CustomViewCallback. +class CustomViewCallback extends PigeonInternalProxyApiBaseClass { + /// Constructs [CustomViewCallback] without creating the associated native object. + /// + /// This should only be used by subclasses created by this library or to + /// create copies for an [PigeonInstanceManager]. + @protected + CustomViewCallback.pigeon_detached({ + super.pigeon_binaryMessenger, + super.pigeon_instanceManager, + }); + + late final _PigeonInternalProxyApiBaseCodec + _pigeonVar_codecCustomViewCallback = + _PigeonInternalProxyApiBaseCodec(pigeon_instanceManager); + + static void pigeon_setUpMessageHandlers({ + bool pigeon_clearHandlers = false, + BinaryMessenger? pigeon_binaryMessenger, + PigeonInstanceManager? pigeon_instanceManager, + CustomViewCallback Function()? pigeon_newInstance, + }) { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _PigeonInternalProxyApiBaseCodec( + pigeon_instanceManager ?? PigeonInstanceManager.instance); + final BinaryMessenger? binaryMessenger = pigeon_binaryMessenger; + { + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.webview_flutter_android.CustomViewCallback.pigeon_newInstance', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (pigeon_clearHandlers) { + pigeonVar_channel.setMessageHandler(null); + } else { + pigeonVar_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.CustomViewCallback.pigeon_newInstance was null.'); + final List args = (message as List?)!; + final int? arg_pigeon_instanceIdentifier = (args[0] as int?); + assert(arg_pigeon_instanceIdentifier != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.CustomViewCallback.pigeon_newInstance was null, expected non-null int.'); + try { + (pigeon_instanceManager ?? PigeonInstanceManager.instance) + .addHostCreatedInstance( + pigeon_newInstance?.call() ?? + CustomViewCallback.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + ), + arg_pigeon_instanceIdentifier!, + ); + return wrapResponse(empty: true); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } + } + + /// Invoked when the host application dismisses the custom view. + Future onCustomViewHidden() async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecCustomViewCallback; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_android.CustomViewCallback.onCustomViewHidden'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = + await pigeonVar_channel.send([this]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return; + } + } + + @override + CustomViewCallback pigeon_copy() { + return CustomViewCallback.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + ); + } +} + +/// This class represents the basic building block for user interface +/// components. +/// +/// See https://developer.android.com/reference/android/view/View. +class View extends PigeonInternalProxyApiBaseClass { + /// Constructs [View] without creating the associated native object. + /// + /// This should only be used by subclasses created by this library or to + /// create copies for an [PigeonInstanceManager]. + @protected + View.pigeon_detached({ + super.pigeon_binaryMessenger, + super.pigeon_instanceManager, + }); + + late final _PigeonInternalProxyApiBaseCodec _pigeonVar_codecView = + _PigeonInternalProxyApiBaseCodec(pigeon_instanceManager); + + static void pigeon_setUpMessageHandlers({ + bool pigeon_clearHandlers = false, + BinaryMessenger? pigeon_binaryMessenger, + PigeonInstanceManager? pigeon_instanceManager, + View Function()? pigeon_newInstance, + }) { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _PigeonInternalProxyApiBaseCodec( + pigeon_instanceManager ?? PigeonInstanceManager.instance); + final BinaryMessenger? binaryMessenger = pigeon_binaryMessenger; + { + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.webview_flutter_android.View.pigeon_newInstance', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (pigeon_clearHandlers) { + pigeonVar_channel.setMessageHandler(null); + } else { + pigeonVar_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.View.pigeon_newInstance was null.'); + final List args = (message as List?)!; + final int? arg_pigeon_instanceIdentifier = (args[0] as int?); + assert(arg_pigeon_instanceIdentifier != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.View.pigeon_newInstance was null, expected non-null int.'); + try { + (pigeon_instanceManager ?? PigeonInstanceManager.instance) + .addHostCreatedInstance( + pigeon_newInstance?.call() ?? + View.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + ), + arg_pigeon_instanceIdentifier!, + ); + return wrapResponse(empty: true); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } + } + + /// Set the scrolled position of your view. + Future scrollTo( + int x, + int y, + ) async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecView; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_android.View.scrollTo'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = + await pigeonVar_channel.send([this, x, y]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return; + } + } + + /// Move the scrolled position of your view. + Future scrollBy( + int x, + int y, + ) async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecView; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_android.View.scrollBy'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = + await pigeonVar_channel.send([this, x, y]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return; + } + } + + /// Return the scrolled position of this view. + Future getScrollPosition() async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecView; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_android.View.getScrollPosition'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = + await pigeonVar_channel.send([this]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else if (pigeonVar_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (pigeonVar_replyList[0] as WebViewPoint?)!; + } + } + + @override + View pigeon_copy() { + return View.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + ); + } +} + +/// A callback interface used by the host application to set the Geolocation +/// permission state for an origin. +/// +/// See https://developer.android.com/reference/android/webkit/GeolocationPermissions.Callback. +class GeolocationPermissionsCallback extends PigeonInternalProxyApiBaseClass { + /// Constructs [GeolocationPermissionsCallback] without creating the associated native object. + /// + /// This should only be used by subclasses created by this library or to + /// create copies for an [PigeonInstanceManager]. + @protected + GeolocationPermissionsCallback.pigeon_detached({ + super.pigeon_binaryMessenger, + super.pigeon_instanceManager, + }); + + late final _PigeonInternalProxyApiBaseCodec + _pigeonVar_codecGeolocationPermissionsCallback = + _PigeonInternalProxyApiBaseCodec(pigeon_instanceManager); + + static void pigeon_setUpMessageHandlers({ + bool pigeon_clearHandlers = false, + BinaryMessenger? pigeon_binaryMessenger, + PigeonInstanceManager? pigeon_instanceManager, + GeolocationPermissionsCallback Function()? pigeon_newInstance, + }) { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _PigeonInternalProxyApiBaseCodec( + pigeon_instanceManager ?? PigeonInstanceManager.instance); + final BinaryMessenger? binaryMessenger = pigeon_binaryMessenger; + { + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.webview_flutter_android.GeolocationPermissionsCallback.pigeon_newInstance', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (pigeon_clearHandlers) { + pigeonVar_channel.setMessageHandler(null); + } else { + pigeonVar_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.GeolocationPermissionsCallback.pigeon_newInstance was null.'); + final List args = (message as List?)!; + final int? arg_pigeon_instanceIdentifier = (args[0] as int?); + assert(arg_pigeon_instanceIdentifier != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.GeolocationPermissionsCallback.pigeon_newInstance was null, expected non-null int.'); + try { + (pigeon_instanceManager ?? PigeonInstanceManager.instance) + .addHostCreatedInstance( + pigeon_newInstance?.call() ?? + GeolocationPermissionsCallback.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + ), + arg_pigeon_instanceIdentifier!, + ); + return wrapResponse(empty: true); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } + } + + /// Sets the Geolocation permission state for the supplied origin. + Future invoke( + String origin, + bool allow, + bool retain, + ) async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecGeolocationPermissionsCallback; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_android.GeolocationPermissionsCallback.invoke'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = await pigeonVar_channel + .send([this, origin, allow, retain]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return; + } + } + + @override + GeolocationPermissionsCallback pigeon_copy() { + return GeolocationPermissionsCallback.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + ); + } +} + +/// Represents a request for HTTP authentication. +/// +/// See https://developer.android.com/reference/android/webkit/HttpAuthHandler. +class HttpAuthHandler extends PigeonInternalProxyApiBaseClass { + /// Constructs [HttpAuthHandler] without creating the associated native object. + /// + /// This should only be used by subclasses created by this library or to + /// create copies for an [PigeonInstanceManager]. + @protected + HttpAuthHandler.pigeon_detached({ + super.pigeon_binaryMessenger, + super.pigeon_instanceManager, + }); + + late final _PigeonInternalProxyApiBaseCodec _pigeonVar_codecHttpAuthHandler = + _PigeonInternalProxyApiBaseCodec(pigeon_instanceManager); + + static void pigeon_setUpMessageHandlers({ + bool pigeon_clearHandlers = false, + BinaryMessenger? pigeon_binaryMessenger, + PigeonInstanceManager? pigeon_instanceManager, + HttpAuthHandler Function()? pigeon_newInstance, + }) { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _PigeonInternalProxyApiBaseCodec( + pigeon_instanceManager ?? PigeonInstanceManager.instance); + final BinaryMessenger? binaryMessenger = pigeon_binaryMessenger; + { + final BasicMessageChannel< + Object?> pigeonVar_channel = BasicMessageChannel< + Object?>( + 'dev.flutter.pigeon.webview_flutter_android.HttpAuthHandler.pigeon_newInstance', + pigeonChannelCodec, + binaryMessenger: binaryMessenger); + if (pigeon_clearHandlers) { + pigeonVar_channel.setMessageHandler(null); + } else { + pigeonVar_channel.setMessageHandler((Object? message) async { + assert(message != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.HttpAuthHandler.pigeon_newInstance was null.'); + final List args = (message as List?)!; + final int? arg_pigeon_instanceIdentifier = (args[0] as int?); + assert(arg_pigeon_instanceIdentifier != null, + 'Argument for dev.flutter.pigeon.webview_flutter_android.HttpAuthHandler.pigeon_newInstance was null, expected non-null int.'); + try { + (pigeon_instanceManager ?? PigeonInstanceManager.instance) + .addHostCreatedInstance( + pigeon_newInstance?.call() ?? + HttpAuthHandler.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + ), + arg_pigeon_instanceIdentifier!, + ); + return wrapResponse(empty: true); + } on PlatformException catch (e) { + return wrapResponse(error: e); + } catch (e) { + return wrapResponse( + error: PlatformException(code: 'error', message: e.toString())); + } + }); + } + } + } + + /// Gets whether the credentials stored for the current host (i.e. the host + /// for which `WebViewClient.onReceivedHttpAuthRequest` was called) are + /// suitable for use. + Future useHttpAuthUsernamePassword() async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecHttpAuthHandler; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_android.HttpAuthHandler.useHttpAuthUsernamePassword'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = + await pigeonVar_channel.send([this]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else if (pigeonVar_replyList[0] == null) { + throw PlatformException( + code: 'null-error', + message: 'Host platform returned null value for non-null return value.', + ); + } else { + return (pigeonVar_replyList[0] as bool?)!; + } + } + + /// Instructs the WebView to cancel the authentication request.. + Future cancel() async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecHttpAuthHandler; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_android.HttpAuthHandler.cancel'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = + await pigeonVar_channel.send([this]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return; + } + } + + /// Instructs the WebView to proceed with the authentication with the given + /// credentials. + Future proceed( + String username, + String password, + ) async { + final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec = + _pigeonVar_codecHttpAuthHandler; + final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger; + const String pigeonVar_channelName = + 'dev.flutter.pigeon.webview_flutter_android.HttpAuthHandler.proceed'; + final BasicMessageChannel pigeonVar_channel = + BasicMessageChannel( + pigeonVar_channelName, + pigeonChannelCodec, + binaryMessenger: pigeonVar_binaryMessenger, + ); + final List? pigeonVar_replyList = await pigeonVar_channel + .send([this, username, password]) as List?; + if (pigeonVar_replyList == null) { + throw _createConnectionError(pigeonVar_channelName); + } else if (pigeonVar_replyList.length > 1) { + throw PlatformException( + code: pigeonVar_replyList[0]! as String, + message: pigeonVar_replyList[1] as String?, + details: pigeonVar_replyList[2], + ); + } else { + return; + } + } + + @override + HttpAuthHandler pigeon_copy() { + return HttpAuthHandler.pigeon_detached( + pigeon_binaryMessenger: pigeon_binaryMessenger, + pigeon_instanceManager: pigeon_instanceManager, + ); + } +} diff --git a/packages/webview_flutter/webview_flutter_android/lib/src/android_webkit_constants.dart b/packages/webview_flutter/webview_flutter_android/lib/src/android_webkit_constants.dart new file mode 100644 index 000000000000..81cd06c7176b --- /dev/null +++ b/packages/webview_flutter/webview_flutter_android/lib/src/android_webkit_constants.dart @@ -0,0 +1,119 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'android_webkit.g.dart'; + +/// Class constants for [PermissionRequest]. +/// +/// Since the Dart [PermissionRequest] is generated, the constants for the class +/// are added here. +class PermissionRequestConstants { + /// Resource belongs to audio capture device, like microphone. + /// + /// See https://developer.android.com/reference/android/webkit/PermissionRequest#RESOURCE_AUDIO_CAPTURE. + static const String audioCapture = 'android.webkit.resource.AUDIO_CAPTURE'; + + /// Resource will allow sysex messages to be sent to or received from MIDI + /// devices. + /// + /// See https://developer.android.com/reference/android/webkit/PermissionRequest#RESOURCE_MIDI_SYSEX. + static const String midiSysex = 'android.webkit.resource.MIDI_SYSEX'; + + /// Resource belongs to video capture device, like camera. + /// + /// See https://developer.android.com/reference/android/webkit/PermissionRequest#RESOURCE_VIDEO_CAPTURE. + static const String videoCapture = 'android.webkit.resource.VIDEO_CAPTURE'; + + /// Resource belongs to protected media identifier. + /// + /// See https://developer.android.com/reference/android/webkit/PermissionRequest#RESOURCE_VIDEO_CAPTURE. + static const String protectedMediaId = + 'android.webkit.resource.PROTECTED_MEDIA_ID'; +} + +/// Class constants for [WebViewClient]. +/// +/// Since the Dart [WebViewClient] is generated, the constants for the class +/// are added here. +class WebViewClientConstants { + /// User authentication failed on server. + /// + /// See https://developer.android.com/reference/android/webkit/WebViewClient#ERROR_AUTHENTICATION + static const int errorAuthentication = -4; + + /// Malformed URL. + /// + /// See https://developer.android.com/reference/android/webkit/WebViewClient#ERROR_BAD_URL + static const int errorBadUrl = -12; + + /// Failed to connect to the server. + /// + /// See https://developer.android.com/reference/android/webkit/WebViewClient#ERROR_CONNECT + static const int errorConnect = -6; + + /// Failed to perform SSL handshake. + /// + /// See https://developer.android.com/reference/android/webkit/WebViewClient#ERROR_FAILED_SSL_HANDSHAKE + static const int errorFailedSslHandshake = -11; + + /// Generic file error. + /// + /// See https://developer.android.com/reference/android/webkit/WebViewClient#ERROR_FILE + static const int errorFile = -13; + + /// File not found. + /// + /// See https://developer.android.com/reference/android/webkit/WebViewClient#ERROR_FILE_NOT_FOUND + static const int errorFileNotFound = -14; + + /// Server or proxy hostname lookup failed. + /// + /// See https://developer.android.com/reference/android/webkit/WebViewClient#ERROR_HOST_LOOKUP + static const int errorHostLookup = -2; + + /// Failed to read or write to the server. + /// + /// See https://developer.android.com/reference/android/webkit/WebViewClient#ERROR_IO + static const int errorIO = -7; + + /// User authentication failed on proxy. + /// + /// See https://developer.android.com/reference/android/webkit/WebViewClient#ERROR_PROXY_AUTHENTICATION + static const int errorProxyAuthentication = -5; + + /// Too many redirects. + /// + /// See https://developer.android.com/reference/android/webkit/WebViewClient#ERROR_REDIRECT_LOOP + static const int errorRedirectLoop = -9; + + /// Connection timed out. + /// + /// See https://developer.android.com/reference/android/webkit/WebViewClient#ERROR_TIMEOUT + static const int errorTimeout = -8; + + /// Too many requests during this load. + /// + /// See https://developer.android.com/reference/android/webkit/WebViewClient#ERROR_TOO_MANY_REQUESTS + static const int errorTooManyRequests = -15; + + /// Generic error. + /// + /// See https://developer.android.com/reference/android/webkit/WebViewClient#ERROR_UNKNOWN + static const int errorUnknown = -1; + + /// Resource load was canceled by Safe Browsing. + /// + /// See https://developer.android.com/reference/android/webkit/WebViewClient#ERROR_UNSAFE_RESOURCE + static const int errorUnsafeResource = -16; + + /// Unsupported authentication scheme (not basic or digest). + /// + /// See https://developer.android.com/reference/android/webkit/WebViewClient#ERROR_UNSUPPORTED_AUTH_SCHEME + static const int errorUnsupportedAuthScheme = -3; + + /// Unsupported URI scheme. + /// + /// See https://developer.android.com/reference/android/webkit/WebViewClient#ERROR_UNSUPPORTED_SCHEME + static const int errorUnsupportedScheme = -10; +} diff --git a/packages/webview_flutter/webview_flutter_android/lib/src/android_webview.dart b/packages/webview_flutter/webview_flutter_android/lib/src/android_webview.dart deleted file mode 100644 index 61174ccbf639..000000000000 --- a/packages/webview_flutter/webview_flutter_android/lib/src/android_webview.dart +++ /dev/null @@ -1,1677 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -import 'dart:ui'; - -import 'package:flutter/foundation.dart'; -import 'package:flutter/services.dart' show BinaryMessenger; - -import 'package:flutter/widgets.dart' show WidgetsFlutterBinding; - -import 'android_webview.g.dart'; -import 'android_webview_api_impls.dart'; -import 'instance_manager.dart'; - -export 'android_webview_api_impls.dart' - show ConsoleMessage, ConsoleMessageLevel, FileChooserMode; - -/// Root of the Java class hierarchy. -/// -/// See https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html. -class JavaObject with Copyable { - /// Constructs a [JavaObject] without creating the associated Java object. - /// - /// This should only be used by subclasses created by this library or to - /// create copies. - @protected - JavaObject.detached({ - BinaryMessenger? binaryMessenger, - InstanceManager? instanceManager, - }) : _api = JavaObjectHostApiImpl( - binaryMessenger: binaryMessenger, - instanceManager: instanceManager, - ); - - /// Global instance of [InstanceManager]. - static final InstanceManager globalInstanceManager = _initInstanceManager(); - - static InstanceManager _initInstanceManager() { - WidgetsFlutterBinding.ensureInitialized(); - // Clears the native `InstanceManager` on initial use of the Dart one. - InstanceManagerHostApi().clear(); - return InstanceManager( - onWeakReferenceRemoved: (int identifier) { - JavaObjectHostApiImpl().dispose(identifier); - }, - ); - } - - /// Pigeon Host Api implementation for [JavaObject]. - final JavaObjectHostApiImpl _api; - - /// Release the reference to a native Java instance. - static void dispose(JavaObject instance) { - instance._api.instanceManager.removeWeakReference(instance); - } - - @override - JavaObject copy() { - return JavaObject.detached(); - } -} - -/// A callback interface used by the host application to set the Geolocation -/// permission state for an origin. -/// -/// See https://developer.android.com/reference/android/webkit/GeolocationPermissions.Callback. -@immutable -class GeolocationPermissionsCallback extends JavaObject { - /// Instantiates a [GeolocationPermissionsCallback] without creating and - /// attaching to an instance of the associated native class. - /// - /// This should only be used outside of tests by subclasses created by this - /// library or to create a copy. - @protected - GeolocationPermissionsCallback.detached({ - super.binaryMessenger, - super.instanceManager, - }) : _geolocationPermissionsCallbackApi = - GeolocationPermissionsCallbackHostApiImpl( - binaryMessenger: binaryMessenger, - instanceManager: instanceManager, - ), - super.detached(); - - final GeolocationPermissionsCallbackHostApiImpl - _geolocationPermissionsCallbackApi; - - /// Sets the Geolocation permission state for the supplied origin. - /// - /// [origin]: The origin for which permissions are set. - /// - /// [allow]: Whether or not the origin should be allowed to use the Geolocation API. - /// - /// [retain]: Whether the permission should be retained beyond the lifetime of - /// a page currently being displayed by a WebView. - Future invoke(String origin, bool allow, bool retain) { - return _geolocationPermissionsCallbackApi.invokeFromInstances( - this, - origin, - allow, - retain, - ); - } - - @override - GeolocationPermissionsCallback copy() { - return GeolocationPermissionsCallback.detached( - binaryMessenger: _geolocationPermissionsCallbackApi.binaryMessenger, - instanceManager: _geolocationPermissionsCallbackApi.instanceManager, - ); - } -} - -/// An Android View that displays web pages. -/// -/// **Basic usage** -/// In most cases, we recommend using a standard web browser, like Chrome, to -/// deliver content to the user. To learn more about web browsers, read the -/// guide on invoking a browser with -/// [url_launcher](https://pub.dev/packages/url_launcher). -/// -/// WebView objects allow you to display web content as part of your widget -/// layout, but lack some of the features of fully-developed browsers. A WebView -/// is useful when you need increased control over the UI and advanced -/// configuration options that will allow you to embed web pages in a -/// specially-designed environment for your app. -/// -/// To learn more about WebView and alternatives for serving web content, read -/// the documentation on -/// [Web-based content](https://developer.android.com/guide/webapps). -/// -/// When a [WebView] is no longer needed [release] must be called. -class WebView extends View { - /// Constructs a new WebView. - WebView({ - this.onScrollChanged, - @visibleForTesting super.binaryMessenger, - @visibleForTesting super.instanceManager, - }) : super.detached() { - api.createFromInstance(this); - } - - /// Constructs a [WebView] without creating the associated Java object. - /// - /// This should only be used by subclasses created by this library or to - /// create copies. - @protected - WebView.detached({ - this.onScrollChanged, - super.binaryMessenger, - super.instanceManager, - }) : super.detached(); - - /// Pigeon Host Api implementation for [WebView]. - @visibleForTesting - static WebViewHostApiImpl api = WebViewHostApiImpl(); - - /// The [WebSettings] object used to control the settings for this WebView. - late final WebSettings settings = WebSettings(this); - - /// Called in response to an internal scroll in this view - /// (i.e., the view scrolled its own contents). - /// - /// This is typically as a result of [scrollBy] or [scrollTo] - /// having been called. - final void Function( - int left, - int top, - int oldLeft, - int oldTop, - )? onScrollChanged; - - /// Enables debugging of web contents (HTML / CSS / JavaScript) loaded into any WebViews of this application. - /// - /// This flag can be enabled in order to facilitate debugging of web layouts - /// and JavaScript code running inside WebViews. Please refer to [WebView] - /// documentation for the debugging guide. The default is false. - static Future setWebContentsDebuggingEnabled(bool enabled) { - return api.setWebContentsDebuggingEnabled(enabled); - } - - /// Loads the given data into this WebView using a 'data' scheme URL. - /// - /// Note that JavaScript's same origin policy means that script running in a - /// page loaded using this method will be unable to access content loaded - /// using any scheme other than 'data', including 'http(s)'. To avoid this - /// restriction, use [loadDataWithBaseURL()] with an appropriate base URL. - /// - /// The [encoding] parameter specifies whether the data is base64 or URL - /// encoded. If the data is base64 encoded, the value of the encoding - /// parameter must be `'base64'`. HTML can be encoded with - /// `base64.encode(bytes)` like so: - /// ```dart - /// import 'dart:convert'; - /// - /// final unencodedHtml = ''' - /// '%28' is the code for '(' - /// '''; - /// final encodedHtml = base64.encode(utf8.encode(unencodedHtml)); - /// print(encodedHtml); - /// ``` - /// - /// The [mimeType] parameter specifies the format of the data. If WebView - /// can't handle the specified MIME type, it will download the data. If - /// `null`, defaults to 'text/html'. - Future loadData({ - required String data, - String? mimeType, - String? encoding, - }) { - return api.loadDataFromInstance( - this, - data, - mimeType, - encoding, - ); - } - - /// Loads the given data into this WebView. - /// - /// The [baseUrl] is used as base URL for the content. It is used both to - /// resolve relative URLs and when applying JavaScript's same origin policy. - /// - /// The [historyUrl] is used for the history entry. - /// - /// The [mimeType] parameter specifies the format of the data. If WebView - /// can't handle the specified MIME type, it will download the data. If - /// `null`, defaults to 'text/html'. - /// - /// Note that content specified in this way can access local device files (via - /// 'file' scheme URLs) only if baseUrl specifies a scheme other than 'http', - /// 'https', 'ftp', 'ftps', 'about' or 'javascript'. - /// - /// If the base URL uses the data scheme, this method is equivalent to calling - /// [loadData] and the [historyUrl] is ignored, and the data will be treated - /// as part of a data: URL, including the requirement that the content be - /// URL-encoded or base64 encoded. If the base URL uses any other scheme, then - /// the data will be loaded into the WebView as a plain string (i.e. not part - /// of a data URL) and any URL-encoded entities in the string will not be - /// decoded. - /// - /// Note that the [baseUrl] is sent in the 'Referer' HTTP header when - /// requesting subresources (images, etc.) of the page loaded using this - /// method. - /// - /// If a valid HTTP or HTTPS base URL is not specified in [baseUrl], then - /// content loaded using this method will have a `window.origin` value of - /// `"null"`. This must not be considered to be a trusted origin by the - /// application or by any JavaScript code running inside the WebView (for - /// example, event sources in DOM event handlers or web messages), because - /// malicious content can also create frames with a null origin. If you need - /// to identify the main frame's origin in a trustworthy way, you should use a - /// valid HTTP or HTTPS base URL to set the origin. - Future loadDataWithBaseUrl({ - String? baseUrl, - required String data, - String? mimeType, - String? encoding, - String? historyUrl, - }) { - return api.loadDataWithBaseUrlFromInstance( - this, - baseUrl, - data, - mimeType, - encoding, - historyUrl, - ); - } - - /// Loads the given URL with additional HTTP headers, specified as a map from name to value. - /// - /// Note that if this map contains any of the headers that are set by default - /// by this WebView, such as those controlling caching, accept types or the - /// User-Agent, their values may be overridden by this WebView's defaults. - /// - /// Also see compatibility note on [evaluateJavascript]. - Future loadUrl(String url, Map headers) { - return api.loadUrlFromInstance(this, url, headers); - } - - /// Loads the URL with postData using "POST" method into this WebView. - /// - /// If url is not a network URL, it will be loaded with [loadUrl] instead, ignoring the postData param. - Future postUrl(String url, Uint8List data) { - return api.postUrlFromInstance(this, url, data); - } - - /// Gets the URL for the current page. - /// - /// This is not always the same as the URL passed to - /// [WebViewClient.onPageStarted] because although the load for that URL has - /// begun, the current page may not have changed. - /// - /// Returns null if no page has been loaded. - Future getUrl() { - return api.getUrlFromInstance(this); - } - - /// Whether this WebView has a back history item. - Future canGoBack() { - return api.canGoBackFromInstance(this); - } - - /// Whether this WebView has a forward history item. - Future canGoForward() { - return api.canGoForwardFromInstance(this); - } - - /// Goes back in the history of this WebView. - Future goBack() { - return api.goBackFromInstance(this); - } - - /// Goes forward in the history of this WebView. - Future goForward() { - return api.goForwardFromInstance(this); - } - - /// Reloads the current URL. - Future reload() { - return api.reloadFromInstance(this); - } - - /// Clears the resource cache. - /// - /// Note that the cache is per-application, so this will clear the cache for - /// all WebViews used. - Future clearCache(bool includeDiskFiles) { - return api.clearCacheFromInstance(this, includeDiskFiles); - } - - // TODO(bparrishMines): Update documentation once addJavascriptInterface is added. - /// Asynchronously evaluates JavaScript in the context of the currently displayed page. - /// - /// If non-null, the returned value will be any result returned from that - /// execution. - /// - /// Compatibility note. Applications targeting Android versions N or later, - /// JavaScript state from an empty WebView is no longer persisted across - /// navigations like [loadUrl]. For example, global variables and functions - /// defined before calling [loadUrl]) will not exist in the loaded page. - Future evaluateJavascript(String javascriptString) { - return api.evaluateJavascriptFromInstance( - this, - javascriptString, - ); - } - - // TODO(bparrishMines): Update documentation when WebViewClient.onReceivedTitle is added. - /// Gets the title for the current page. - /// - /// Returns null if no page has been loaded. - Future getTitle() { - return api.getTitleFromInstance(this); - } - - // TODO(bparrishMines): Update documentation when onScrollChanged is added. - /// Set the scrolled position of your view. - Future scrollTo(int x, int y) { - return api.scrollToFromInstance(this, x, y); - } - - // TODO(bparrishMines): Update documentation when onScrollChanged is added. - /// Move the scrolled position of your view. - Future scrollBy(int x, int y) { - return api.scrollByFromInstance(this, x, y); - } - - /// Return the scrolled left position of this view. - /// - /// This is the left edge of the displayed part of your view. You do not - /// need to draw any pixels farther left, since those are outside of the frame - /// of your view on screen. - Future getScrollX() { - return api.getScrollXFromInstance(this); - } - - /// Return the scrolled top position of this view. - /// - /// This is the top edge of the displayed part of your view. You do not need - /// to draw any pixels above it, since those are outside of the frame of your - /// view on screen. - Future getScrollY() { - return api.getScrollYFromInstance(this); - } - - /// Returns the X and Y scroll position of this view. - Future getScrollPosition() { - return api.getScrollPositionFromInstance(this); - } - - /// Sets the [WebViewClient] that will receive various notifications and requests. - /// - /// This will replace the current handler. - Future setWebViewClient(WebViewClient webViewClient) { - return api.setWebViewClientFromInstance(this, webViewClient); - } - - /// Injects the supplied [JavascriptChannel] into this WebView. - /// - /// The object is injected into all frames of the web page, including all the - /// iframes, using the supplied name. This allows the object's methods to - /// be accessed from JavaScript. - /// - /// Note that injected objects will not appear in JavaScript until the page is - /// next (re)loaded. JavaScript should be enabled before injecting the object. - /// For example: - /// - /// ```dart - /// webview.settings.setJavaScriptEnabled(true); - /// webView.addJavascriptChannel(JavScriptChannel("injectedObject")); - /// webView.loadUrl("about:blank", {}); - /// webView.loadUrl("javascript:injectedObject.postMessage("Hello, World!")", {}); - /// ``` - /// - /// **Important** - /// * Because the object is exposed to all the frames, any frame could obtain - /// the object name and call methods on it. There is no way to tell the - /// calling frame's origin from the app side, so the app must not assume that - /// the caller is trustworthy unless the app can guarantee that no third party - /// content is ever loaded into the WebView even inside an iframe. - Future addJavaScriptChannel(JavaScriptChannel javaScriptChannel) { - JavaScriptChannel.api.createFromInstance(javaScriptChannel); - return api.addJavaScriptChannelFromInstance(this, javaScriptChannel); - } - - /// Removes a previously injected [JavaScriptChannel] from this WebView. - /// - /// Note that the removal will not be reflected in JavaScript until the page - /// is next (re)loaded. See [addJavaScriptChannel]. - Future removeJavaScriptChannel(JavaScriptChannel javaScriptChannel) { - JavaScriptChannel.api.createFromInstance(javaScriptChannel); - return api.removeJavaScriptChannelFromInstance(this, javaScriptChannel); - } - - /// Registers the interface to be used when content can not be handled by the rendering engine, and should be downloaded instead. - /// - /// This will replace the current handler. - Future setDownloadListener(DownloadListener? listener) { - return api.setDownloadListenerFromInstance(this, listener); - } - - /// Sets the chrome handler. - /// - /// This is an implementation of [WebChromeClient] for use in handling - /// JavaScript dialogs, favicons, titles, and the progress. This will replace - /// the current handler. - Future setWebChromeClient(WebChromeClient? client) { - return api.setWebChromeClientFromInstance(this, client); - } - - /// Sets the background color of this WebView. - Future setBackgroundColor(Color color) { - return api.setBackgroundColorFromInstance(this, color.value); - } - - @override - WebView copy() { - return WebView.detached( - onScrollChanged: onScrollChanged, - binaryMessenger: _api.binaryMessenger, - instanceManager: _api.instanceManager, - ); - } -} - -/// Manages cookies globally for all webviews. -/// -/// See https://developer.android.com/reference/android/webkit/CookieManager. -class CookieManager extends JavaObject { - /// Instantiates a [CookieManager] without creating and attaching to an - /// instance of the associated native class. - /// - /// This should only be used outside of tests by subclasses created by this - /// library or to create a copy for an [InstanceManager]. - @protected - CookieManager.detached({super.binaryMessenger, super.instanceManager}) - : _cookieManagerApi = CookieManagerHostApiImpl( - binaryMessenger: binaryMessenger, - instanceManager: instanceManager, - ), - super.detached(); - - static final CookieManager _instance = - CookieManagerHostApiImpl().attachInstanceFromInstances( - CookieManager.detached(), - ); - - final CookieManagerHostApiImpl _cookieManagerApi; - - /// Access a static field synchronously. - static CookieManager get instance { - AndroidWebViewFlutterApis.instance.ensureSetUp(); - return _instance; - } - - /// Sets a single cookie (key-value pair) for the given URL. Any existing - /// cookie with the same host, path and name will be replaced with the new - /// cookie. The cookie being set will be ignored if it is expired. To set - /// multiple cookies, your application should invoke this method multiple - /// times. - /// - /// The value parameter must follow the format of the Set-Cookie HTTP - /// response header defined by RFC6265bis. This is a key-value pair of the - /// form "key=value", optionally followed by a list of cookie attributes - /// delimited with semicolons (ex. "key=value; Max-Age=123"). Please consult - /// the RFC specification for a list of valid attributes. - /// - /// Note: if specifying a value containing the "Secure" attribute, url must - /// use the "https://" scheme. - /// - /// Params: - /// url – the URL for which the cookie is to be set - /// value – the cookie as a string, using the format of the 'Set-Cookie' HTTP response header - Future setCookie(String url, String value) { - return _cookieManagerApi.setCookieFromInstances(this, url, value); - } - - /// Removes all cookies. - /// - /// The returned future resolves to true if any cookies were removed. - Future removeAllCookies() { - return _cookieManagerApi.removeAllCookiesFromInstances(this); - } - - /// Sets whether the WebView should allow third party cookies to be set. - /// - /// Apps that target `Build.VERSION_CODES.KITKAT` or below default to allowing - /// third party cookies. Apps targeting `Build.VERSION_CODES.LOLLIPOP` or - /// later default to disallowing third party cookies. - Future setAcceptThirdPartyCookies(WebView webView, bool accept) { - return _cookieManagerApi.setAcceptThirdPartyCookiesFromInstances( - this, - webView, - accept, - ); - } - - @override - CookieManager copy() { - return CookieManager.detached( - binaryMessenger: _cookieManagerApi.binaryMessenger, - instanceManager: _cookieManagerApi.instanceManager, - ); - } -} - -/// Manages settings state for a [WebView]. -/// -/// When a WebView is first created, it obtains a set of default settings. These -/// default settings will be returned from any getter call. A WebSettings object -/// obtained from [WebView.settings] is tied to the life of the WebView. If a -/// WebView has been destroyed, any method call on [WebSettings] will throw an -/// Exception. -class WebSettings extends JavaObject { - /// Constructs a [WebSettings]. - /// - /// This constructor is only used for testing. An instance should be obtained - /// with [WebView.settings]. - @visibleForTesting - WebSettings( - WebView webView, { - @visibleForTesting super.binaryMessenger, - @visibleForTesting super.instanceManager, - }) : super.detached() { - api.createFromInstance(this, webView); - } - - /// Constructs a [WebSettings] without creating the associated Java object. - /// - /// This should only be used by subclasses created by this library or to - /// create copies. - @protected - WebSettings.detached({ - super.binaryMessenger, - super.instanceManager, - }) : super.detached(); - - /// Pigeon Host Api implementation for [WebSettings]. - @visibleForTesting - static WebSettingsHostApiImpl api = WebSettingsHostApiImpl(); - - /// Sets whether the DOM storage API is enabled. - /// - /// The default value is false. - Future setDomStorageEnabled(bool flag) { - return api.setDomStorageEnabledFromInstance(this, flag); - } - - /// Tells JavaScript to open windows automatically. - /// - /// This applies to the JavaScript function `window.open()`. The default is - /// false. - Future setJavaScriptCanOpenWindowsAutomatically(bool flag) { - return api.setJavaScriptCanOpenWindowsAutomaticallyFromInstance( - this, - flag, - ); - } - - // TODO(bparrishMines): Update documentation when WebChromeClient.onCreateWindow is added. - /// Sets whether the WebView should supports multiple windows. - /// - /// The default is false. - Future setSupportMultipleWindows(bool support) { - return api.setSupportMultipleWindowsFromInstance(this, support); - } - - /// Tells the WebView to enable JavaScript execution. - /// - /// The default is false. - Future setJavaScriptEnabled(bool flag) { - return api.setJavaScriptEnabledFromInstance(this, flag); - } - - /// Sets the WebView's user-agent string. - /// - /// If the string is empty, the system default value will be used. Note that - /// starting from KITKAT Android version, changing the user-agent while - /// loading a web page causes WebView to initiate loading once again. - Future setUserAgentString(String? userAgentString) { - return api.setUserAgentStringFromInstance(this, userAgentString); - } - - /// Sets whether the WebView requires a user gesture to play media. - /// - /// The default is true. - Future setMediaPlaybackRequiresUserGesture(bool require) { - return api.setMediaPlaybackRequiresUserGestureFromInstance(this, require); - } - - // TODO(bparrishMines): Update documentation when WebView.zoomIn and WebView.zoomOut are added. - /// Sets whether the WebView should support zooming using its on-screen zoom controls and gestures. - /// - /// The particular zoom mechanisms that should be used can be set with - /// [setBuiltInZoomControls]. - /// - /// The default is true. - Future setSupportZoom(bool support) { - return api.setSupportZoomFromInstance(this, support); - } - - /// Sets whether the WebView loads pages in overview mode, that is, zooms out the content to fit on screen by width. - /// - /// This setting is taken into account when the content width is greater than - /// the width of the WebView control, for example, when [setUseWideViewPort] - /// is enabled. - /// - /// The default is false. - Future setLoadWithOverviewMode(bool overview) { - return api.setLoadWithOverviewModeFromInstance(this, overview); - } - - /// Sets whether the WebView should enable support for the "viewport" HTML meta tag or should use a wide viewport. - /// - /// When the value of the setting is false, the layout width is always set to - /// the width of the WebView control in device-independent (CSS) pixels. When - /// the value is true and the page contains the viewport meta tag, the value - /// of the width specified in the tag is used. If the page does not contain - /// the tag or does not provide a width, then a wide viewport will be used. - Future setUseWideViewPort(bool use) { - return api.setUseWideViewPortFromInstance(this, use); - } - - // TODO(bparrishMines): Update documentation when ZoomButtonsController is added. - /// Sets whether the WebView should display on-screen zoom controls when using the built-in zoom mechanisms. - /// - /// See [setBuiltInZoomControls]. The default is true. However, on-screen zoom - /// controls are deprecated in Android so it's recommended to set this to - /// false. - Future setDisplayZoomControls(bool enabled) { - return api.setDisplayZoomControlsFromInstance(this, enabled); - } - - // TODO(bparrishMines): Update documentation when ZoomButtonsController is added. - /// Sets whether the WebView should use its built-in zoom mechanisms. - /// - /// The built-in zoom mechanisms comprise on-screen zoom controls, which are - /// displayed over the WebView's content, and the use of a pinch gesture to - /// control zooming. Whether or not these on-screen controls are displayed can - /// be set with [setDisplayZoomControls]. The default is false. - /// - /// The built-in mechanisms are the only currently supported zoom mechanisms, - /// so it is recommended that this setting is always enabled. However, - /// on-screen zoom controls are deprecated in Android so it's recommended to - /// disable [setDisplayZoomControls]. - Future setBuiltInZoomControls(bool enabled) { - return api.setBuiltInZoomControlsFromInstance(this, enabled); - } - - /// Enables or disables file access within WebView. - /// - /// This enables or disables file system access only. Assets and resources are - /// still accessible using file:///android_asset and file:///android_res. The - /// default value is true for apps targeting Build.VERSION_CODES.Q and below, - /// and false when targeting Build.VERSION_CODES.R and above. - Future setAllowFileAccess(bool enabled) { - return api.setAllowFileAccessFromInstance(this, enabled); - } - - /// Sets the text zoom of the page in percent. - /// - /// The default is 100. See https://developer.android.com/reference/android/webkit/WebSettings#setTextZoom(int) - Future setTextZoom(int textZoom) { - return api.setSetTextZoomFromInstance(this, textZoom); - } - - /// Gets the WebView's user-agent string. - Future getUserAgentString() { - return api.getUserAgentStringFromInstance(this); - } - - @override - WebSettings copy() { - return WebSettings.detached( - binaryMessenger: _api.binaryMessenger, - instanceManager: _api.instanceManager, - ); - } -} - -/// Exposes a channel to receive calls from javaScript. -/// -/// See [WebView.addJavaScriptChannel]. -class JavaScriptChannel extends JavaObject { - /// Constructs a [JavaScriptChannel]. - JavaScriptChannel( - this.channelName, { - required this.postMessage, - @visibleForTesting super.binaryMessenger, - @visibleForTesting super.instanceManager, - }) : super.detached() { - AndroidWebViewFlutterApis.instance.ensureSetUp(); - api.createFromInstance(this); - } - - /// Constructs a [JavaScriptChannel] without creating the associated Java - /// object. - /// - /// This should only be used by subclasses created by this library or to - /// create copies. - @protected - JavaScriptChannel.detached( - this.channelName, { - required this.postMessage, - super.binaryMessenger, - super.instanceManager, - }) : super.detached(); - - /// Pigeon Host Api implementation for [JavaScriptChannel]. - @visibleForTesting - static JavaScriptChannelHostApiImpl api = JavaScriptChannelHostApiImpl(); - - /// Used to identify this object to receive messages from javaScript. - final String channelName; - - /// Callback method when javaScript calls `postMessage` on the object instance passed. - final void Function(String message) postMessage; - - @override - JavaScriptChannel copy() { - return JavaScriptChannel.detached( - channelName, - postMessage: postMessage, - binaryMessenger: _api.binaryMessenger, - instanceManager: _api.instanceManager, - ); - } -} - -/// Receive various notifications and requests for [WebView]. -class WebViewClient extends JavaObject { - /// Constructs a [WebViewClient]. - WebViewClient({ - this.onPageStarted, - this.onPageFinished, - this.onReceivedHttpError, - this.onReceivedRequestError, - @Deprecated('Only called on Android version < 23.') this.onReceivedError, - this.requestLoading, - this.urlLoading, - this.doUpdateVisitedHistory, - this.onReceivedHttpAuthRequest, - @visibleForTesting super.binaryMessenger, - @visibleForTesting super.instanceManager, - }) : super.detached() { - AndroidWebViewFlutterApis.instance.ensureSetUp(); - api.createFromInstance(this); - } - - /// Constructs a [WebViewClient] without creating the associated Java object. - /// - /// This should only be used by subclasses created by this library or to - /// create copies. - @protected - WebViewClient.detached({ - this.onPageStarted, - this.onPageFinished, - this.onReceivedHttpError, - this.onReceivedRequestError, - @Deprecated('Only called on Android version < 23.') this.onReceivedError, - this.requestLoading, - this.urlLoading, - this.doUpdateVisitedHistory, - this.onReceivedHttpAuthRequest, - super.binaryMessenger, - super.instanceManager, - }) : super.detached(); - - /// User authentication failed on server. - /// - /// See https://developer.android.com/reference/android/webkit/WebViewClient#ERROR_AUTHENTICATION - static const int errorAuthentication = -4; - - /// Malformed URL. - /// - /// See https://developer.android.com/reference/android/webkit/WebViewClient#ERROR_BAD_URL - static const int errorBadUrl = -12; - - /// Failed to connect to the server. - /// - /// See https://developer.android.com/reference/android/webkit/WebViewClient#ERROR_CONNECT - static const int errorConnect = -6; - - /// Failed to perform SSL handshake. - /// - /// See https://developer.android.com/reference/android/webkit/WebViewClient#ERROR_FAILED_SSL_HANDSHAKE - static const int errorFailedSslHandshake = -11; - - /// Generic file error. - /// - /// See https://developer.android.com/reference/android/webkit/WebViewClient#ERROR_FILE - static const int errorFile = -13; - - /// File not found. - /// - /// See https://developer.android.com/reference/android/webkit/WebViewClient#ERROR_FILE_NOT_FOUND - static const int errorFileNotFound = -14; - - /// Server or proxy hostname lookup failed. - /// - /// See https://developer.android.com/reference/android/webkit/WebViewClient#ERROR_HOST_LOOKUP - static const int errorHostLookup = -2; - - /// Failed to read or write to the server. - /// - /// See https://developer.android.com/reference/android/webkit/WebViewClient#ERROR_IO - static const int errorIO = -7; - - /// User authentication failed on proxy. - /// - /// See https://developer.android.com/reference/android/webkit/WebViewClient#ERROR_PROXY_AUTHENTICATION - static const int errorProxyAuthentication = -5; - - /// Too many redirects. - /// - /// See https://developer.android.com/reference/android/webkit/WebViewClient#ERROR_REDIRECT_LOOP - static const int errorRedirectLoop = -9; - - /// Connection timed out. - /// - /// See https://developer.android.com/reference/android/webkit/WebViewClient#ERROR_TIMEOUT - static const int errorTimeout = -8; - - /// Too many requests during this load. - /// - /// See https://developer.android.com/reference/android/webkit/WebViewClient#ERROR_TOO_MANY_REQUESTS - static const int errorTooManyRequests = -15; - - /// Generic error. - /// - /// See https://developer.android.com/reference/android/webkit/WebViewClient#ERROR_UNKNOWN - static const int errorUnknown = -1; - - /// Resource load was canceled by Safe Browsing. - /// - /// See https://developer.android.com/reference/android/webkit/WebViewClient#ERROR_UNSAFE_RESOURCE - static const int errorUnsafeResource = -16; - - /// Unsupported authentication scheme (not basic or digest). - /// - /// See https://developer.android.com/reference/android/webkit/WebViewClient#ERROR_UNSUPPORTED_AUTH_SCHEME - static const int errorUnsupportedAuthScheme = -3; - - /// Unsupported URI scheme. - /// - /// See https://developer.android.com/reference/android/webkit/WebViewClient#ERROR_UNSUPPORTED_SCHEME - static const int errorUnsupportedScheme = -10; - - /// Pigeon Host Api implementation for [WebViewClient]. - @visibleForTesting - static WebViewClientHostApiImpl api = WebViewClientHostApiImpl(); - - /// Notify the host application that a page has started loading. - /// - /// This method is called once for each main frame load so a page with iframes - /// or framesets will call onPageStarted one time for the main frame. This - /// also means that [onPageStarted] will not be called when the contents of an - /// embedded frame changes, i.e. clicking a link whose target is an iframe, it - /// will also not be called for fragment navigations (navigations to - /// #fragment_id). - final void Function(WebView webView, String url)? onPageStarted; - - // TODO(bparrishMines): Update documentation when WebView.postVisualStateCallback is added. - /// Notify the host application that a page has finished loading. - /// - /// This method is called only for main frame. Receiving an [onPageFinished] - /// callback does not guarantee that the next frame drawn by WebView will - /// reflect the state of the DOM at this point. - final void Function(WebView webView, String url)? onPageFinished; - - /// Notify the host application that an HTTP error has been received from the - /// server while loading a resource. - /// - /// HTTP errors have status codes >= 400. This callback will be called for any - /// resource (iframe, image, etc.), not just for the main page. Thus, it is - /// recommended to perform minimum required work in this callback. - final void Function(WebView webView, WebResourceRequest request, - WebResourceResponse response)? onReceivedHttpError; - - /// Report web resource loading error to the host application. - /// - /// These errors usually indicate inability to connect to the server. Note - /// that unlike the deprecated version of the callback, the new version will - /// be called for any resource (iframe, image, etc.), not just for the main - /// page. Thus, it is recommended to perform minimum required work in this - /// callback. - final void Function( - WebView webView, - WebResourceRequest request, - WebResourceError error, - )? onReceivedRequestError; - - /// Report an error to the host application. - /// - /// These errors are unrecoverable (i.e. the main resource is unavailable). - /// The errorCode parameter corresponds to one of the error* constants. - @Deprecated('Only called on Android version < 23.') - final void Function( - WebView webView, - int errorCode, - String description, - String failingUrl, - )? onReceivedError; - - /// When the current [WebView] wants to load a URL. - /// - /// The value set by [setSynchronousReturnValueForShouldOverrideUrlLoading] - /// indicates whether the [WebView] loaded the request. - final void Function(WebView webView, WebResourceRequest request)? - requestLoading; - - /// When the current [WebView] wants to load a URL. - /// - /// The value set by [setSynchronousReturnValueForShouldOverrideUrlLoading] - /// indicates whether the [WebView] loaded the URL. - final void Function(WebView webView, String url)? urlLoading; - - /// Notify the host application to update its visited links database. - final void Function(WebView webView, String url, bool isReload)? - doUpdateVisitedHistory; - - /// This callback is only called for requests that require HTTP authentication. - final void Function( - WebView webView, - HttpAuthHandler handler, - String host, - String realm, - )? onReceivedHttpAuthRequest; - - /// Sets the required synchronous return value for the Java method, - /// `WebViewClient.shouldOverrideUrlLoading(...)`. - /// - /// The Java method, `WebViewClient.shouldOverrideUrlLoading(...)`, requires - /// a boolean to be returned and this method sets the returned value for all - /// calls to the Java method. - /// - /// Setting this to true causes the current [WebView] to abort loading any URL - /// received by [requestLoading] or [urlLoading], while setting this to false - /// causes the [WebView] to continue loading a URL as usual. - /// - /// Defaults to false. - Future setSynchronousReturnValueForShouldOverrideUrlLoading( - bool value, - ) { - return api.setShouldOverrideUrlLoadingReturnValueFromInstance(this, value); - } - - @override - WebViewClient copy() { - return WebViewClient.detached( - onPageStarted: onPageStarted, - onPageFinished: onPageFinished, - onReceivedHttpError: onReceivedHttpError, - onReceivedRequestError: onReceivedRequestError, - onReceivedError: onReceivedError, - requestLoading: requestLoading, - urlLoading: urlLoading, - doUpdateVisitedHistory: doUpdateVisitedHistory, - onReceivedHttpAuthRequest: onReceivedHttpAuthRequest, - binaryMessenger: _api.binaryMessenger, - instanceManager: _api.instanceManager, - ); - } -} - -/// The interface to be used when content can not be handled by the rendering -/// engine for [WebView], and should be downloaded instead. -class DownloadListener extends JavaObject { - /// Constructs a [DownloadListener]. - DownloadListener({ - required this.onDownloadStart, - @visibleForTesting super.binaryMessenger, - @visibleForTesting super.instanceManager, - }) : super.detached() { - AndroidWebViewFlutterApis.instance.ensureSetUp(); - api.createFromInstance(this); - } - - /// Constructs a [DownloadListener] without creating the associated Java - /// object. - /// - /// This should only be used by subclasses created by this library or to - /// create copies. - @protected - DownloadListener.detached({ - required this.onDownloadStart, - super.binaryMessenger, - super.instanceManager, - }) : super.detached(); - - /// Pigeon Host Api implementation for [DownloadListener]. - @visibleForTesting - static DownloadListenerHostApiImpl api = DownloadListenerHostApiImpl(); - - /// Notify the host application that a file should be downloaded. - final void Function( - String url, - String userAgent, - String contentDisposition, - String mimetype, - int contentLength, - ) onDownloadStart; - - @override - DownloadListener copy() { - return DownloadListener.detached( - onDownloadStart: onDownloadStart, - binaryMessenger: _api.binaryMessenger, - instanceManager: _api.instanceManager, - ); - } -} - -/// Responsible for request the Geolocation API. -typedef GeolocationPermissionsShowPrompt = Future Function( - String origin, - GeolocationPermissionsCallback callback, -); - -/// Responsible for request the Geolocation API is Cancel. -typedef GeolocationPermissionsHidePrompt = void Function( - WebChromeClient instance, -); - -/// Signature for the callback that is responsible for showing a custom view. -typedef ShowCustomViewCallback = void Function( - WebChromeClient instance, - View view, - CustomViewCallback callback, -); - -/// Signature for the callback that is responsible for hiding a custom view. -typedef HideCustomViewCallback = void Function( - WebChromeClient instance, -); - -/// Handles JavaScript dialogs, favicons, titles, and the progress for [WebView]. -class WebChromeClient extends JavaObject { - /// Constructs a [WebChromeClient]. - WebChromeClient({ - this.onProgressChanged, - this.onShowFileChooser, - this.onPermissionRequest, - this.onGeolocationPermissionsShowPrompt, - this.onGeolocationPermissionsHidePrompt, - this.onShowCustomView, - this.onHideCustomView, - this.onConsoleMessage, - this.onJsAlert, - this.onJsConfirm, - this.onJsPrompt, - @visibleForTesting super.binaryMessenger, - @visibleForTesting super.instanceManager, - }) : super.detached() { - AndroidWebViewFlutterApis.instance.ensureSetUp(); - api.createFromInstance(this); - } - - /// Constructs a [WebChromeClient] without creating the associated Java - /// object. - /// - /// This should only be used by subclasses created by this library or to - /// create copies. - @protected - WebChromeClient.detached({ - this.onProgressChanged, - this.onShowFileChooser, - this.onPermissionRequest, - this.onGeolocationPermissionsShowPrompt, - this.onGeolocationPermissionsHidePrompt, - this.onShowCustomView, - this.onHideCustomView, - this.onConsoleMessage, - this.onJsAlert, - this.onJsConfirm, - this.onJsPrompt, - super.binaryMessenger, - super.instanceManager, - }) : super.detached(); - - /// Pigeon Host Api implementation for [WebChromeClient]. - @visibleForTesting - static WebChromeClientHostApiImpl api = WebChromeClientHostApiImpl(); - - /// Notify the host application that a file should be downloaded. - final void Function(WebView webView, int progress)? onProgressChanged; - - /// Indicates the client should show a file chooser. - /// - /// To handle the request for a file chooser with this callback, passing true - /// to [setSynchronousReturnValueForOnShowFileChooser] is required. Otherwise, - /// the returned list of strings will be ignored and the client will use the - /// default handling of a file chooser request. - /// - /// Only invoked on Android versions 21+. - final Future> Function( - WebView webView, - FileChooserParams params, - )? onShowFileChooser; - - /// Notify the host application that web content is requesting permission to - /// access the specified resources and the permission currently isn't granted - /// or denied. - /// - /// Only invoked on Android versions 21+. - final void Function( - WebChromeClient instance, - PermissionRequest request, - )? onPermissionRequest; - - /// Indicates the client should handle geolocation permissions. - final GeolocationPermissionsShowPrompt? onGeolocationPermissionsShowPrompt; - - /// Notify the host application that a request for Geolocation permissions, - /// made with a previous call to [onGeolocationPermissionsShowPrompt] has been - /// canceled. - final GeolocationPermissionsHidePrompt? onGeolocationPermissionsHidePrompt; - - /// Notify the host application that the current page has entered full screen - /// mode. - /// - /// After this call, web content will no longer be rendered in the WebView, - /// but will instead be rendered in `view`. - final ShowCustomViewCallback? onShowCustomView; - - /// Notify the host application that the current page has exited full screen - /// mode. - final HideCustomViewCallback? onHideCustomView; - - /// Report a JavaScript console message to the host application. - final void Function(WebChromeClient instance, ConsoleMessage message)? - onConsoleMessage; - - /// Notify the host application that the web page wants to display a - /// JavaScript alert() dialog. - final Future Function(String url, String message)? onJsAlert; - - /// Notify the host application that the web page wants to display a - /// JavaScript confirm() dialog. - final Future Function(String url, String message)? onJsConfirm; - - /// Notify the host application that the web page wants to display a - /// JavaScript prompt() dialog. - final Future Function( - String url, String message, String defaultValue)? onJsPrompt; - - /// Sets the required synchronous return value for the Java method, - /// `WebChromeClient.onShowFileChooser(...)`. - /// - /// The Java method, `WebChromeClient.onShowFileChooser(...)`, requires - /// a boolean to be returned and this method sets the returned value for all - /// calls to the Java method. - /// - /// Setting this to true indicates that all file chooser requests should be - /// handled by [onShowFileChooser] and the returned list of Strings will be - /// returned to the WebView. Otherwise, the client will use the default - /// handling and the returned value in [onShowFileChooser] will be ignored. - /// - /// Requires [onShowFileChooser] to be nonnull. - /// - /// Defaults to false. - Future setSynchronousReturnValueForOnShowFileChooser( - bool value, - ) { - if (value && onShowFileChooser == null) { - throw StateError( - 'Setting this to true requires `onShowFileChooser` to be nonnull.', - ); - } - return api.setSynchronousReturnValueForOnShowFileChooserFromInstance( - this, - value, - ); - } - - /// Sets the required synchronous return value for the Java method, - /// `WebChromeClient.onShowFileChooser(...)`. - /// - /// The Java method, `WebChromeClient.onConsoleMessage(...)`, requires - /// a boolean to be returned and this method sets the returned value for all - /// calls to the Java method. - /// - /// Setting this to true indicates that the client is handling all console - /// messages. - /// - /// Requires [onConsoleMessage] to be nonnull. - /// - /// Defaults to false. - Future setSynchronousReturnValueForOnConsoleMessage( - bool value, - ) { - if (value && onConsoleMessage == null) { - throw StateError( - 'Setting this to true requires `onConsoleMessage` to be nonnull.', - ); - } - return api.setSynchronousReturnValueForOnConsoleMessageFromInstance( - this, - value, - ); - } - - /// Sets the required synchronous return value for the Java method, - /// `WebChromeClient.onJsAlert(...)`. - /// - /// The Java method, `WebChromeClient.onJsAlert(...)`, requires - /// a boolean to be returned and this method sets the returned value for all - /// calls to the Java method. - /// - /// Setting this to true indicates that the client is handling all console - /// messages. - /// - /// Requires [onJsAlert] to be nonnull. - /// - /// Defaults to false. - Future setSynchronousReturnValueForOnJsAlert( - bool value, - ) { - if (value && onJsAlert == null) { - throw StateError( - 'Setting this to true requires `onJsAlert` to be nonnull.', - ); - } - return api.setSynchronousReturnValueForOnJsAlertFromInstance(this, value); - } - - /// Sets the required synchronous return value for the Java method, - /// `WebChromeClient.onJsConfirm(...)`. - /// - /// The Java method, `WebChromeClient.onJsConfirm(...)`, requires - /// a boolean to be returned and this method sets the returned value for all - /// calls to the Java method. - /// - /// Setting this to true indicates that the client is handling all console - /// messages. - /// - /// Requires [onJsConfirm] to be nonnull. - /// - /// Defaults to false. - Future setSynchronousReturnValueForOnJsConfirm( - bool value, - ) { - if (value && onJsConfirm == null) { - throw StateError( - 'Setting this to true requires `onJsConfirm` to be nonnull.', - ); - } - return api.setSynchronousReturnValueForOnJsConfirmFromInstance(this, value); - } - - /// Sets the required synchronous return value for the Java method, - /// `WebChromeClient.onJsPrompt(...)`. - /// - /// The Java method, `WebChromeClient.onJsPrompt(...)`, requires - /// a boolean to be returned and this method sets the returned value for all - /// calls to the Java method. - /// - /// Setting this to true indicates that the client is handling all console - /// messages. - /// - /// Requires [onJsPrompt] to be nonnull. - /// - /// Defaults to false. - Future setSynchronousReturnValueForOnJsPrompt( - bool value, - ) { - if (value && onJsPrompt == null) { - throw StateError( - 'Setting this to true requires `onJsPrompt` to be nonnull.', - ); - } - return api.setSynchronousReturnValueForOnJsPromptFromInstance(this, value); - } - - @override - WebChromeClient copy() { - return WebChromeClient.detached( - onProgressChanged: onProgressChanged, - onShowFileChooser: onShowFileChooser, - onPermissionRequest: onPermissionRequest, - onGeolocationPermissionsShowPrompt: onGeolocationPermissionsShowPrompt, - onGeolocationPermissionsHidePrompt: onGeolocationPermissionsHidePrompt, - onShowCustomView: onShowCustomView, - onHideCustomView: onHideCustomView, - onConsoleMessage: onConsoleMessage, - onJsAlert: onJsAlert, - onJsConfirm: onJsConfirm, - onJsPrompt: onJsPrompt, - binaryMessenger: _api.binaryMessenger, - instanceManager: _api.instanceManager, - ); - } -} - -/// This class defines a permission request and is used when web content -/// requests access to protected resources. -/// -/// Only supported on Android versions >= 21. -/// -/// See https://developer.android.com/reference/android/webkit/PermissionRequest. -class PermissionRequest extends JavaObject { - /// Instantiates a [PermissionRequest] without creating and attaching to an - /// instance of the associated native class. - /// - /// This should only be used outside of tests by subclasses created by this - /// library or to create a copy for an [InstanceManager]. - @protected - PermissionRequest.detached({ - required this.resources, - required super.binaryMessenger, - required super.instanceManager, - }) : _permissionRequestApi = PermissionRequestHostApiImpl( - binaryMessenger: binaryMessenger, - instanceManager: instanceManager, - ), - super.detached(); - - /// Resource belongs to audio capture device, like microphone. - /// - /// See https://developer.android.com/reference/android/webkit/PermissionRequest#RESOURCE_AUDIO_CAPTURE. - static const String audioCapture = 'android.webkit.resource.AUDIO_CAPTURE'; - - /// Resource will allow sysex messages to be sent to or received from MIDI - /// devices. - /// - /// See https://developer.android.com/reference/android/webkit/PermissionRequest#RESOURCE_MIDI_SYSEX. - static const String midiSysex = 'android.webkit.resource.MIDI_SYSEX'; - - /// Resource belongs to video capture device, like camera. - /// - /// See https://developer.android.com/reference/android/webkit/PermissionRequest#RESOURCE_VIDEO_CAPTURE. - static const String videoCapture = 'android.webkit.resource.VIDEO_CAPTURE'; - - /// Resource belongs to protected media identifier. - /// - /// See https://developer.android.com/reference/android/webkit/PermissionRequest#RESOURCE_VIDEO_CAPTURE. - static const String protectedMediaId = - 'android.webkit.resource.PROTECTED_MEDIA_ID'; - - final PermissionRequestHostApiImpl _permissionRequestApi; - - /// Resources the web page is trying to access. - final List resources; - - /// Call this method to get the resources the web page is trying to access. - Future grant(List resources) { - return _permissionRequestApi.grantFromInstances(this, resources); - } - - /// Call this method to grant origin the permission to access the given - /// resources. - Future deny() { - return _permissionRequestApi.denyFromInstances(this); - } - - @override - PermissionRequest copy() { - return PermissionRequest.detached( - resources: resources, - binaryMessenger: _permissionRequestApi.binaryMessenger, - instanceManager: _permissionRequestApi.instanceManager, - ); - } -} - -/// Parameters received when a [WebChromeClient] should show a file chooser. -/// -/// See https://developer.android.com/reference/android/webkit/WebChromeClient.FileChooserParams. -class FileChooserParams extends JavaObject { - /// Constructs a [FileChooserParams] without creating the associated Java - /// object. - /// - /// This should only be used by subclasses created by this library or to - /// create copies. - @protected - FileChooserParams.detached({ - required this.isCaptureEnabled, - required this.acceptTypes, - required this.filenameHint, - required this.mode, - super.binaryMessenger, - super.instanceManager, - }) : super.detached(); - - /// Preference for a live media captured value (e.g. Camera, Microphone). - final bool isCaptureEnabled; - - /// A list of acceptable MIME types. - final List acceptTypes; - - /// The file name of a default selection if specified, or null. - final String? filenameHint; - - /// Mode of how to select files for a file chooser. - final FileChooserMode mode; - - @override - FileChooserParams copy() { - return FileChooserParams.detached( - isCaptureEnabled: isCaptureEnabled, - acceptTypes: acceptTypes, - filenameHint: filenameHint, - mode: mode, - binaryMessenger: _api.binaryMessenger, - instanceManager: _api.instanceManager, - ); - } -} - -/// Encompasses parameters to the [WebViewClient.requestLoading] method. -class WebResourceRequest { - /// Constructs a [WebResourceRequest]. - WebResourceRequest({ - required this.url, - required this.isForMainFrame, - required this.isRedirect, - required this.hasGesture, - required this.method, - required this.requestHeaders, - }); - - /// The URL for which the resource request was made. - final String url; - - /// Whether the request was made in order to fetch the main frame's document. - final bool isForMainFrame; - - /// Whether the request was a result of a server-side redirect. - /// - /// Only supported on Android version >= 24. - final bool? isRedirect; - - /// Whether a gesture (such as a click) was associated with the request. - final bool hasGesture; - - /// The method associated with the request, for example "GET". - final String method; - - /// The headers associated with the request. - final Map requestHeaders; -} - -/// Encapsulates information about the web resource response. -/// -/// See [WebViewClient.onReceivedHttpError]. -class WebResourceResponse { - /// Constructs a [WebResourceResponse]. - WebResourceResponse({ - required this.statusCode, - }); - - /// The HTTP status code associated with the response. - final int statusCode; -} - -/// Encapsulates information about errors occurred during loading of web resources. -/// -/// See [WebViewClient.onReceivedRequestError]. -class WebResourceError { - /// Constructs a [WebResourceError]. - WebResourceError({ - required this.errorCode, - required this.description, - }); - - /// The integer code of the error (e.g. [WebViewClient.errorAuthentication]. - final int errorCode; - - /// Describes the error. - final String description; -} - -/// Manages Flutter assets that are part of Android's app bundle. -class FlutterAssetManager { - /// Constructs the [FlutterAssetManager]. - const FlutterAssetManager(); - - /// Pigeon Host Api implementation for [FlutterAssetManager]. - @visibleForTesting - static FlutterAssetManagerHostApi api = FlutterAssetManagerHostApi(); - - /// Lists all assets at the given path. - /// - /// The assets are returned as a `List`. The `List` only - /// contains files which are direct childs - Future> list(String path) => api.list(path); - - /// Gets the relative file path to the Flutter asset with the given name. - Future getAssetFilePathByName(String name) => - api.getAssetFilePathByName(name); -} - -/// Manages the JavaScript storage APIs provided by the [WebView]. -/// -/// Wraps [WebStorage](https://developer.android.com/reference/android/webkit/WebStorage). -class WebStorage extends JavaObject { - /// Constructs a [WebStorage]. - /// - /// This constructor is only used for testing. An instance should be obtained - /// with [WebStorage.instance]. - @visibleForTesting - WebStorage({ - @visibleForTesting super.binaryMessenger, - @visibleForTesting super.instanceManager, - }) : super.detached() { - AndroidWebViewFlutterApis.instance.ensureSetUp(); - api.createFromInstance(this); - } - - /// Constructs a [WebStorage] without creating the associated Java object. - /// - /// This should only be used by subclasses created by this library or to - /// create copies. - @protected - WebStorage.detached({ - super.binaryMessenger, - super.instanceManager, - }) : super.detached(); - - /// Pigeon Host Api implementation for [WebStorage]. - @visibleForTesting - static WebStorageHostApiImpl api = WebStorageHostApiImpl(); - - /// The singleton instance of this class. - static WebStorage instance = WebStorage(); - - /// Clears all storage currently being used by the JavaScript storage APIs. - Future deleteAllData() { - return api.deleteAllDataFromInstance(this); - } - - @override - WebStorage copy() { - return WebStorage.detached( - binaryMessenger: _api.binaryMessenger, - instanceManager: _api.instanceManager, - ); - } -} - -/// The basic building block for user interface components. -/// -/// See https://developer.android.com/reference/android/view/View. -class View extends JavaObject { - /// Instantiates a [View] without creating and attaching to an - /// instance of the associated native class. - /// - /// This should only be used outside of tests by subclasses created by this - /// library or to create a copy for an [InstanceManager]. - @protected - View.detached({super.binaryMessenger, super.instanceManager}) - : super.detached(); - - @override - View copy() { - return View.detached( - binaryMessenger: _api.binaryMessenger, - instanceManager: _api.instanceManager, - ); - } -} - -/// A callback interface used by the host application to notify the current page -/// that its custom view has been dismissed. -/// -/// See https://developer.android.com/reference/android/webkit/WebChromeClient.CustomViewCallback. -class CustomViewCallback extends JavaObject { - /// Instantiates a [CustomViewCallback] without creating and attaching to an - /// instance of the associated native class. - /// - /// This should only be used outside of tests by subclasses created by this - /// library or to create a copy for an [InstanceManager]. - @protected - CustomViewCallback.detached({ - super.binaryMessenger, - super.instanceManager, - }) : _customViewCallbackApi = CustomViewCallbackHostApiImpl( - binaryMessenger: binaryMessenger, - instanceManager: instanceManager, - ), - super.detached(); - - final CustomViewCallbackHostApiImpl _customViewCallbackApi; - - /// Invoked when the host application dismisses the custom view. - Future onCustomViewHidden() { - return _customViewCallbackApi.onCustomViewHiddenFromInstances(this); - } - - @override - CustomViewCallback copy() { - return CustomViewCallback.detached( - binaryMessenger: _customViewCallbackApi.binaryMessenger, - instanceManager: _customViewCallbackApi.instanceManager, - ); - } -} - -/// Represents a request for HTTP authentication. -/// -/// Instances of this class are created by the [WebView] and passed to -/// [WebViewClient.onReceivedHttpAuthRequest]. The host application must call -/// either [HttpAuthHandler.proceed] or [HttpAuthHandler.cancel] to set the -/// WebView's response to the request. -class HttpAuthHandler extends JavaObject { - /// Constructs a [HttpAuthHandler]. - HttpAuthHandler({ - super.binaryMessenger, - super.instanceManager, - }) : super.detached(); - - /// Pigeon Host Api implementation for [HttpAuthHandler]. - @visibleForTesting - static HttpAuthHandlerHostApiImpl api = HttpAuthHandlerHostApiImpl(); - - /// Instructs the WebView to cancel the authentication request. - Future cancel() { - return api.cancelFromInstance(this); - } - - /// Instructs the WebView to proceed with the authentication with the provided - /// credentials. - Future proceed(String username, String password) { - return api.proceedFromInstance(this, username, password); - } - - /// Gets whether the credentials stored for the current host are suitable for - /// use. - /// - /// Credentials are not suitable if they have previously been rejected by the - /// server for the current request. - Future useHttpAuthUsernamePassword() { - return api.useHttpAuthUsernamePasswordFromInstance(this); - } -} diff --git a/packages/webview_flutter/webview_flutter_android/lib/src/android_webview.g.dart b/packages/webview_flutter/webview_flutter_android/lib/src/android_webview.g.dart deleted file mode 100644 index 5d2707f9472f..000000000000 --- a/packages/webview_flutter/webview_flutter_android/lib/src/android_webview.g.dart +++ /dev/null @@ -1,3231 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -// Autogenerated from Pigeon (v11.0.1), do not edit directly. -// See also: https://pub.dev/packages/pigeon -// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import - -import 'dart:async'; -import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List; - -import 'package:flutter/foundation.dart' show ReadBuffer, WriteBuffer; -import 'package:flutter/services.dart'; - -/// Mode of how to select files for a file chooser. -/// -/// See https://developer.android.com/reference/android/webkit/WebChromeClient.FileChooserParams. -enum FileChooserMode { - /// Open single file and requires that the file exists before allowing the - /// user to pick it. - /// - /// See https://developer.android.com/reference/android/webkit/WebChromeClient.FileChooserParams#MODE_OPEN. - open, - - /// Similar to [open] but allows multiple files to be selected. - /// - /// See https://developer.android.com/reference/android/webkit/WebChromeClient.FileChooserParams#MODE_OPEN_MULTIPLE. - openMultiple, - - /// Allows picking a nonexistent file and saving it. - /// - /// See https://developer.android.com/reference/android/webkit/WebChromeClient.FileChooserParams#MODE_SAVE. - save, -} - -/// Indicates the type of message logged to the console. -/// -/// See https://developer.android.com/reference/android/webkit/ConsoleMessage.MessageLevel. -enum ConsoleMessageLevel { - /// Indicates a message is logged for debugging. - /// - /// See https://developer.android.com/reference/android/webkit/ConsoleMessage.MessageLevel#DEBUG. - debug, - - /// Indicates a message is provided as an error. - /// - /// See https://developer.android.com/reference/android/webkit/ConsoleMessage.MessageLevel#ERROR. - error, - - /// Indicates a message is provided as a basic log message. - /// - /// See https://developer.android.com/reference/android/webkit/ConsoleMessage.MessageLevel#LOG. - log, - - /// Indicates a message is provided as a tip. - /// - /// See https://developer.android.com/reference/android/webkit/ConsoleMessage.MessageLevel#TIP. - tip, - - /// Indicates a message is provided as a warning. - /// - /// See https://developer.android.com/reference/android/webkit/ConsoleMessage.MessageLevel#WARNING. - warning, - - /// Indicates a message with an unknown level. - /// - /// This does not represent an actual value provided by the platform and only - /// indicates a value was provided that isn't currently supported. - unknown, -} - -class WebResourceRequestData { - WebResourceRequestData({ - required this.url, - required this.isForMainFrame, - this.isRedirect, - required this.hasGesture, - required this.method, - required this.requestHeaders, - }); - - String url; - - bool isForMainFrame; - - bool? isRedirect; - - bool hasGesture; - - String method; - - Map requestHeaders; - - Object encode() { - return [ - url, - isForMainFrame, - isRedirect, - hasGesture, - method, - requestHeaders, - ]; - } - - static WebResourceRequestData decode(Object result) { - result as List; - return WebResourceRequestData( - url: result[0]! as String, - isForMainFrame: result[1]! as bool, - isRedirect: result[2] as bool?, - hasGesture: result[3]! as bool, - method: result[4]! as String, - requestHeaders: - (result[5] as Map?)!.cast(), - ); - } -} - -class WebResourceResponseData { - WebResourceResponseData({ - required this.statusCode, - }); - - int statusCode; - - Object encode() { - return [ - statusCode, - ]; - } - - static WebResourceResponseData decode(Object result) { - result as List; - return WebResourceResponseData( - statusCode: result[0]! as int, - ); - } -} - -class WebResourceErrorData { - WebResourceErrorData({ - required this.errorCode, - required this.description, - }); - - int errorCode; - - String description; - - Object encode() { - return [ - errorCode, - description, - ]; - } - - static WebResourceErrorData decode(Object result) { - result as List; - return WebResourceErrorData( - errorCode: result[0]! as int, - description: result[1]! as String, - ); - } -} - -class WebViewPoint { - WebViewPoint({ - required this.x, - required this.y, - }); - - int x; - - int y; - - Object encode() { - return [ - x, - y, - ]; - } - - static WebViewPoint decode(Object result) { - result as List; - return WebViewPoint( - x: result[0]! as int, - y: result[1]! as int, - ); - } -} - -/// Represents a JavaScript console message from WebCore. -/// -/// See https://developer.android.com/reference/android/webkit/ConsoleMessage -class ConsoleMessage { - ConsoleMessage({ - required this.lineNumber, - required this.message, - required this.level, - required this.sourceId, - }); - - int lineNumber; - - String message; - - ConsoleMessageLevel level; - - String sourceId; - - Object encode() { - return [ - lineNumber, - message, - level.index, - sourceId, - ]; - } - - static ConsoleMessage decode(Object result) { - result as List; - return ConsoleMessage( - lineNumber: result[0]! as int, - message: result[1]! as String, - level: ConsoleMessageLevel.values[result[2]! as int], - sourceId: result[3]! as String, - ); - } -} - -/// Host API for managing the native `InstanceManager`. -class InstanceManagerHostApi { - /// Constructor for [InstanceManagerHostApi]. The [binaryMessenger] named argument is - /// available for dependency injection. If it is left null, the default - /// BinaryMessenger will be used which routes to the host platform. - InstanceManagerHostApi({BinaryMessenger? binaryMessenger}) - : _binaryMessenger = binaryMessenger; - final BinaryMessenger? _binaryMessenger; - - static const MessageCodec codec = StandardMessageCodec(); - - /// Clear the native `InstanceManager`. - /// - /// This is typically only used after a hot restart. - Future clear() async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.InstanceManagerHostApi.clear', - codec, - binaryMessenger: _binaryMessenger); - final List? replyList = await channel.send(null) as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { - throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], - ); - } else { - return; - } - } -} - -/// Handles methods calls to the native Java Object class. -/// -/// Also handles calls to remove the reference to an instance with `dispose`. -/// -/// See https://docs.oracle.com/javase/7/docs/api/java/lang/Object.html. -class JavaObjectHostApi { - /// Constructor for [JavaObjectHostApi]. The [binaryMessenger] named argument is - /// available for dependency injection. If it is left null, the default - /// BinaryMessenger will be used which routes to the host platform. - JavaObjectHostApi({BinaryMessenger? binaryMessenger}) - : _binaryMessenger = binaryMessenger; - final BinaryMessenger? _binaryMessenger; - - static const MessageCodec codec = StandardMessageCodec(); - - Future dispose(int arg_identifier) async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.JavaObjectHostApi.dispose', - codec, - binaryMessenger: _binaryMessenger); - final List? replyList = - await channel.send([arg_identifier]) as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { - throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], - ); - } else { - return; - } - } -} - -/// Handles callbacks methods for the native Java Object class. -/// -/// See https://docs.oracle.com/javase/7/docs/api/java/lang/Object.html. -abstract class JavaObjectFlutterApi { - static const MessageCodec codec = StandardMessageCodec(); - - void dispose(int identifier); - - static void setup(JavaObjectFlutterApi? api, - {BinaryMessenger? binaryMessenger}) { - { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.JavaObjectFlutterApi.dispose', - codec, - binaryMessenger: binaryMessenger); - if (api == null) { - channel.setMessageHandler(null); - } else { - channel.setMessageHandler((Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.JavaObjectFlutterApi.dispose was null.'); - final List args = (message as List?)!; - final int? arg_identifier = (args[0] as int?); - assert(arg_identifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.JavaObjectFlutterApi.dispose was null, expected non-null int.'); - api.dispose(arg_identifier!); - return; - }); - } - } - } -} - -/// Host API for `CookieManager`. -/// -/// This class may handle instantiating and adding native object instances that -/// are attached to a Dart instance or handle method calls on the associated -/// native class or an instance of the class. -class CookieManagerHostApi { - /// Constructor for [CookieManagerHostApi]. The [binaryMessenger] named argument is - /// available for dependency injection. If it is left null, the default - /// BinaryMessenger will be used which routes to the host platform. - CookieManagerHostApi({BinaryMessenger? binaryMessenger}) - : _binaryMessenger = binaryMessenger; - final BinaryMessenger? _binaryMessenger; - - static const MessageCodec codec = StandardMessageCodec(); - - /// Handles attaching `CookieManager.instance` to a native instance. - Future attachInstance(int arg_instanceIdentifier) async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.CookieManagerHostApi.attachInstance', - codec, - binaryMessenger: _binaryMessenger); - final List? replyList = - await channel.send([arg_instanceIdentifier]) as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { - throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], - ); - } else { - return; - } - } - - /// Handles Dart method `CookieManager.setCookie`. - Future setCookie( - int arg_identifier, String arg_url, String arg_value) async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.CookieManagerHostApi.setCookie', - codec, - binaryMessenger: _binaryMessenger); - final List? replyList = await channel - .send([arg_identifier, arg_url, arg_value]) as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { - throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], - ); - } else { - return; - } - } - - /// Handles Dart method `CookieManager.removeAllCookies`. - Future removeAllCookies(int arg_identifier) async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.CookieManagerHostApi.removeAllCookies', - codec, - binaryMessenger: _binaryMessenger); - final List? replyList = - await channel.send([arg_identifier]) as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { - throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], - ); - } else if (replyList[0] == null) { - throw PlatformException( - code: 'null-error', - message: 'Host platform returned null value for non-null return value.', - ); - } else { - return (replyList[0] as bool?)!; - } - } - - /// Handles Dart method `CookieManager.setAcceptThirdPartyCookies`. - Future setAcceptThirdPartyCookies( - int arg_identifier, int arg_webViewIdentifier, bool arg_accept) async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.CookieManagerHostApi.setAcceptThirdPartyCookies', - codec, - binaryMessenger: _binaryMessenger); - final List? replyList = await channel - .send([arg_identifier, arg_webViewIdentifier, arg_accept]) - as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { - throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], - ); - } else { - return; - } - } -} - -class _WebViewHostApiCodec extends StandardMessageCodec { - const _WebViewHostApiCodec(); - @override - void writeValue(WriteBuffer buffer, Object? value) { - if (value is WebViewPoint) { - buffer.putUint8(128); - writeValue(buffer, value.encode()); - } else { - super.writeValue(buffer, value); - } - } - - @override - Object? readValueOfType(int type, ReadBuffer buffer) { - switch (type) { - case 128: - return WebViewPoint.decode(readValue(buffer)!); - default: - return super.readValueOfType(type, buffer); - } - } -} - -class WebViewHostApi { - /// Constructor for [WebViewHostApi]. The [binaryMessenger] named argument is - /// available for dependency injection. If it is left null, the default - /// BinaryMessenger will be used which routes to the host platform. - WebViewHostApi({BinaryMessenger? binaryMessenger}) - : _binaryMessenger = binaryMessenger; - final BinaryMessenger? _binaryMessenger; - - static const MessageCodec codec = _WebViewHostApiCodec(); - - Future create(int arg_instanceId) async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.create', - codec, - binaryMessenger: _binaryMessenger); - final List? replyList = - await channel.send([arg_instanceId]) as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { - throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], - ); - } else { - return; - } - } - - Future loadData(int arg_instanceId, String arg_data, - String? arg_mimeType, String? arg_encoding) async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.loadData', - codec, - binaryMessenger: _binaryMessenger); - final List? replyList = await channel.send( - [arg_instanceId, arg_data, arg_mimeType, arg_encoding]) - as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { - throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], - ); - } else { - return; - } - } - - Future loadDataWithBaseUrl( - int arg_instanceId, - String? arg_baseUrl, - String arg_data, - String? arg_mimeType, - String? arg_encoding, - String? arg_historyUrl) async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.loadDataWithBaseUrl', - codec, - binaryMessenger: _binaryMessenger); - final List? replyList = await channel.send([ - arg_instanceId, - arg_baseUrl, - arg_data, - arg_mimeType, - arg_encoding, - arg_historyUrl - ]) as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { - throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], - ); - } else { - return; - } - } - - Future loadUrl(int arg_instanceId, String arg_url, - Map arg_headers) async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.loadUrl', - codec, - binaryMessenger: _binaryMessenger); - final List? replyList = - await channel.send([arg_instanceId, arg_url, arg_headers]) - as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { - throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], - ); - } else { - return; - } - } - - Future postUrl( - int arg_instanceId, String arg_url, Uint8List arg_data) async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.postUrl', - codec, - binaryMessenger: _binaryMessenger); - final List? replyList = await channel - .send([arg_instanceId, arg_url, arg_data]) as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { - throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], - ); - } else { - return; - } - } - - Future getUrl(int arg_instanceId) async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.getUrl', - codec, - binaryMessenger: _binaryMessenger); - final List? replyList = - await channel.send([arg_instanceId]) as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { - throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], - ); - } else { - return (replyList[0] as String?); - } - } - - Future canGoBack(int arg_instanceId) async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.canGoBack', - codec, - binaryMessenger: _binaryMessenger); - final List? replyList = - await channel.send([arg_instanceId]) as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { - throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], - ); - } else if (replyList[0] == null) { - throw PlatformException( - code: 'null-error', - message: 'Host platform returned null value for non-null return value.', - ); - } else { - return (replyList[0] as bool?)!; - } - } - - Future canGoForward(int arg_instanceId) async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.canGoForward', - codec, - binaryMessenger: _binaryMessenger); - final List? replyList = - await channel.send([arg_instanceId]) as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { - throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], - ); - } else if (replyList[0] == null) { - throw PlatformException( - code: 'null-error', - message: 'Host platform returned null value for non-null return value.', - ); - } else { - return (replyList[0] as bool?)!; - } - } - - Future goBack(int arg_instanceId) async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.goBack', - codec, - binaryMessenger: _binaryMessenger); - final List? replyList = - await channel.send([arg_instanceId]) as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { - throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], - ); - } else { - return; - } - } - - Future goForward(int arg_instanceId) async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.goForward', - codec, - binaryMessenger: _binaryMessenger); - final List? replyList = - await channel.send([arg_instanceId]) as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { - throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], - ); - } else { - return; - } - } - - Future reload(int arg_instanceId) async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.reload', - codec, - binaryMessenger: _binaryMessenger); - final List? replyList = - await channel.send([arg_instanceId]) as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { - throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], - ); - } else { - return; - } - } - - Future clearCache(int arg_instanceId, bool arg_includeDiskFiles) async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.clearCache', - codec, - binaryMessenger: _binaryMessenger); - final List? replyList = - await channel.send([arg_instanceId, arg_includeDiskFiles]) - as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { - throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], - ); - } else { - return; - } - } - - Future evaluateJavascript( - int arg_instanceId, String arg_javascriptString) async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.evaluateJavascript', - codec, - binaryMessenger: _binaryMessenger); - final List? replyList = - await channel.send([arg_instanceId, arg_javascriptString]) - as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { - throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], - ); - } else { - return (replyList[0] as String?); - } - } - - Future getTitle(int arg_instanceId) async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.getTitle', - codec, - binaryMessenger: _binaryMessenger); - final List? replyList = - await channel.send([arg_instanceId]) as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { - throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], - ); - } else { - return (replyList[0] as String?); - } - } - - Future scrollTo(int arg_instanceId, int arg_x, int arg_y) async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.scrollTo', - codec, - binaryMessenger: _binaryMessenger); - final List? replyList = await channel - .send([arg_instanceId, arg_x, arg_y]) as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { - throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], - ); - } else { - return; - } - } - - Future scrollBy(int arg_instanceId, int arg_x, int arg_y) async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.scrollBy', - codec, - binaryMessenger: _binaryMessenger); - final List? replyList = await channel - .send([arg_instanceId, arg_x, arg_y]) as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { - throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], - ); - } else { - return; - } - } - - Future getScrollX(int arg_instanceId) async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.getScrollX', - codec, - binaryMessenger: _binaryMessenger); - final List? replyList = - await channel.send([arg_instanceId]) as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { - throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], - ); - } else if (replyList[0] == null) { - throw PlatformException( - code: 'null-error', - message: 'Host platform returned null value for non-null return value.', - ); - } else { - return (replyList[0] as int?)!; - } - } - - Future getScrollY(int arg_instanceId) async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.getScrollY', - codec, - binaryMessenger: _binaryMessenger); - final List? replyList = - await channel.send([arg_instanceId]) as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { - throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], - ); - } else if (replyList[0] == null) { - throw PlatformException( - code: 'null-error', - message: 'Host platform returned null value for non-null return value.', - ); - } else { - return (replyList[0] as int?)!; - } - } - - Future getScrollPosition(int arg_instanceId) async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.getScrollPosition', - codec, - binaryMessenger: _binaryMessenger); - final List? replyList = - await channel.send([arg_instanceId]) as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { - throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], - ); - } else if (replyList[0] == null) { - throw PlatformException( - code: 'null-error', - message: 'Host platform returned null value for non-null return value.', - ); - } else { - return (replyList[0] as WebViewPoint?)!; - } - } - - Future setWebContentsDebuggingEnabled(bool arg_enabled) async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.setWebContentsDebuggingEnabled', - codec, - binaryMessenger: _binaryMessenger); - final List? replyList = - await channel.send([arg_enabled]) as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { - throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], - ); - } else { - return; - } - } - - Future setWebViewClient( - int arg_instanceId, int arg_webViewClientInstanceId) async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.setWebViewClient', - codec, - binaryMessenger: _binaryMessenger); - final List? replyList = await channel - .send([arg_instanceId, arg_webViewClientInstanceId]) - as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { - throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], - ); - } else { - return; - } - } - - Future addJavaScriptChannel( - int arg_instanceId, int arg_javaScriptChannelInstanceId) async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.addJavaScriptChannel', - codec, - binaryMessenger: _binaryMessenger); - final List? replyList = await channel - .send([arg_instanceId, arg_javaScriptChannelInstanceId]) - as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { - throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], - ); - } else { - return; - } - } - - Future removeJavaScriptChannel( - int arg_instanceId, int arg_javaScriptChannelInstanceId) async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.removeJavaScriptChannel', - codec, - binaryMessenger: _binaryMessenger); - final List? replyList = await channel - .send([arg_instanceId, arg_javaScriptChannelInstanceId]) - as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { - throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], - ); - } else { - return; - } - } - - Future setDownloadListener( - int arg_instanceId, int? arg_listenerInstanceId) async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.setDownloadListener', - codec, - binaryMessenger: _binaryMessenger); - final List? replyList = - await channel.send([arg_instanceId, arg_listenerInstanceId]) - as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { - throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], - ); - } else { - return; - } - } - - Future setWebChromeClient( - int arg_instanceId, int? arg_clientInstanceId) async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.setWebChromeClient', - codec, - binaryMessenger: _binaryMessenger); - final List? replyList = - await channel.send([arg_instanceId, arg_clientInstanceId]) - as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { - throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], - ); - } else { - return; - } - } - - Future setBackgroundColor(int arg_instanceId, int arg_color) async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.setBackgroundColor', - codec, - binaryMessenger: _binaryMessenger); - final List? replyList = await channel - .send([arg_instanceId, arg_color]) as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { - throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], - ); - } else { - return; - } - } -} - -/// Flutter API for `WebView`. -/// -/// This class may handle instantiating and adding Dart instances that are -/// attached to a native instance or receiving callback methods from an -/// overridden native class. -/// -/// See https://developer.android.com/reference/android/webkit/WebView. -abstract class WebViewFlutterApi { - static const MessageCodec codec = StandardMessageCodec(); - - /// Create a new Dart instance and add it to the `InstanceManager`. - void create(int identifier); - - void onScrollChanged( - int webViewInstanceId, int left, int top, int oldLeft, int oldTop); - - static void setup(WebViewFlutterApi? api, - {BinaryMessenger? binaryMessenger}) { - { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebViewFlutterApi.create', - codec, - binaryMessenger: binaryMessenger); - if (api == null) { - channel.setMessageHandler(null); - } else { - channel.setMessageHandler((Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewFlutterApi.create was null.'); - final List args = (message as List?)!; - final int? arg_identifier = (args[0] as int?); - assert(arg_identifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewFlutterApi.create was null, expected non-null int.'); - api.create(arg_identifier!); - return; - }); - } - } - { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebViewFlutterApi.onScrollChanged', - codec, - binaryMessenger: binaryMessenger); - if (api == null) { - channel.setMessageHandler(null); - } else { - channel.setMessageHandler((Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewFlutterApi.onScrollChanged was null.'); - final List args = (message as List?)!; - final int? arg_webViewInstanceId = (args[0] as int?); - assert(arg_webViewInstanceId != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewFlutterApi.onScrollChanged was null, expected non-null int.'); - final int? arg_left = (args[1] as int?); - assert(arg_left != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewFlutterApi.onScrollChanged was null, expected non-null int.'); - final int? arg_top = (args[2] as int?); - assert(arg_top != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewFlutterApi.onScrollChanged was null, expected non-null int.'); - final int? arg_oldLeft = (args[3] as int?); - assert(arg_oldLeft != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewFlutterApi.onScrollChanged was null, expected non-null int.'); - final int? arg_oldTop = (args[4] as int?); - assert(arg_oldTop != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewFlutterApi.onScrollChanged was null, expected non-null int.'); - api.onScrollChanged(arg_webViewInstanceId!, arg_left!, arg_top!, - arg_oldLeft!, arg_oldTop!); - return; - }); - } - } - } -} - -class WebSettingsHostApi { - /// Constructor for [WebSettingsHostApi]. The [binaryMessenger] named argument is - /// available for dependency injection. If it is left null, the default - /// BinaryMessenger will be used which routes to the host platform. - WebSettingsHostApi({BinaryMessenger? binaryMessenger}) - : _binaryMessenger = binaryMessenger; - final BinaryMessenger? _binaryMessenger; - - static const MessageCodec codec = StandardMessageCodec(); - - Future create(int arg_instanceId, int arg_webViewInstanceId) async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebSettingsHostApi.create', - codec, - binaryMessenger: _binaryMessenger); - final List? replyList = - await channel.send([arg_instanceId, arg_webViewInstanceId]) - as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { - throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], - ); - } else { - return; - } - } - - Future setDomStorageEnabled(int arg_instanceId, bool arg_flag) async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebSettingsHostApi.setDomStorageEnabled', - codec, - binaryMessenger: _binaryMessenger); - final List? replyList = await channel - .send([arg_instanceId, arg_flag]) as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { - throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], - ); - } else { - return; - } - } - - Future setJavaScriptCanOpenWindowsAutomatically( - int arg_instanceId, bool arg_flag) async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebSettingsHostApi.setJavaScriptCanOpenWindowsAutomatically', - codec, - binaryMessenger: _binaryMessenger); - final List? replyList = await channel - .send([arg_instanceId, arg_flag]) as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { - throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], - ); - } else { - return; - } - } - - Future setSupportMultipleWindows( - int arg_instanceId, bool arg_support) async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebSettingsHostApi.setSupportMultipleWindows', - codec, - binaryMessenger: _binaryMessenger); - final List? replyList = await channel - .send([arg_instanceId, arg_support]) as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { - throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], - ); - } else { - return; - } - } - - Future setJavaScriptEnabled(int arg_instanceId, bool arg_flag) async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebSettingsHostApi.setJavaScriptEnabled', - codec, - binaryMessenger: _binaryMessenger); - final List? replyList = await channel - .send([arg_instanceId, arg_flag]) as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { - throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], - ); - } else { - return; - } - } - - Future setUserAgentString( - int arg_instanceId, String? arg_userAgentString) async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebSettingsHostApi.setUserAgentString', - codec, - binaryMessenger: _binaryMessenger); - final List? replyList = await channel - .send([arg_instanceId, arg_userAgentString]) as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { - throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], - ); - } else { - return; - } - } - - Future setMediaPlaybackRequiresUserGesture( - int arg_instanceId, bool arg_require) async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebSettingsHostApi.setMediaPlaybackRequiresUserGesture', - codec, - binaryMessenger: _binaryMessenger); - final List? replyList = await channel - .send([arg_instanceId, arg_require]) as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { - throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], - ); - } else { - return; - } - } - - Future setSupportZoom(int arg_instanceId, bool arg_support) async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebSettingsHostApi.setSupportZoom', - codec, - binaryMessenger: _binaryMessenger); - final List? replyList = await channel - .send([arg_instanceId, arg_support]) as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { - throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], - ); - } else { - return; - } - } - - Future setLoadWithOverviewMode( - int arg_instanceId, bool arg_overview) async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebSettingsHostApi.setLoadWithOverviewMode', - codec, - binaryMessenger: _binaryMessenger); - final List? replyList = await channel - .send([arg_instanceId, arg_overview]) as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { - throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], - ); - } else { - return; - } - } - - Future setUseWideViewPort(int arg_instanceId, bool arg_use) async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebSettingsHostApi.setUseWideViewPort', - codec, - binaryMessenger: _binaryMessenger); - final List? replyList = await channel - .send([arg_instanceId, arg_use]) as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { - throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], - ); - } else { - return; - } - } - - Future setDisplayZoomControls( - int arg_instanceId, bool arg_enabled) async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebSettingsHostApi.setDisplayZoomControls', - codec, - binaryMessenger: _binaryMessenger); - final List? replyList = await channel - .send([arg_instanceId, arg_enabled]) as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { - throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], - ); - } else { - return; - } - } - - Future setBuiltInZoomControls( - int arg_instanceId, bool arg_enabled) async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebSettingsHostApi.setBuiltInZoomControls', - codec, - binaryMessenger: _binaryMessenger); - final List? replyList = await channel - .send([arg_instanceId, arg_enabled]) as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { - throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], - ); - } else { - return; - } - } - - Future setAllowFileAccess(int arg_instanceId, bool arg_enabled) async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebSettingsHostApi.setAllowFileAccess', - codec, - binaryMessenger: _binaryMessenger); - final List? replyList = await channel - .send([arg_instanceId, arg_enabled]) as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { - throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], - ); - } else { - return; - } - } - - Future setTextZoom(int arg_instanceId, int arg_textZoom) async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebSettingsHostApi.setTextZoom', - codec, - binaryMessenger: _binaryMessenger); - final List? replyList = await channel - .send([arg_instanceId, arg_textZoom]) as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { - throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], - ); - } else { - return; - } - } - - Future getUserAgentString(int arg_instanceId) async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebSettingsHostApi.getUserAgentString', - codec, - binaryMessenger: _binaryMessenger); - final List? replyList = - await channel.send([arg_instanceId]) as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { - throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], - ); - } else if (replyList[0] == null) { - throw PlatformException( - code: 'null-error', - message: 'Host platform returned null value for non-null return value.', - ); - } else { - return (replyList[0] as String?)!; - } - } -} - -class JavaScriptChannelHostApi { - /// Constructor for [JavaScriptChannelHostApi]. The [binaryMessenger] named argument is - /// available for dependency injection. If it is left null, the default - /// BinaryMessenger will be used which routes to the host platform. - JavaScriptChannelHostApi({BinaryMessenger? binaryMessenger}) - : _binaryMessenger = binaryMessenger; - final BinaryMessenger? _binaryMessenger; - - static const MessageCodec codec = StandardMessageCodec(); - - Future create(int arg_instanceId, String arg_channelName) async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.JavaScriptChannelHostApi.create', - codec, - binaryMessenger: _binaryMessenger); - final List? replyList = await channel - .send([arg_instanceId, arg_channelName]) as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { - throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], - ); - } else { - return; - } - } -} - -abstract class JavaScriptChannelFlutterApi { - static const MessageCodec codec = StandardMessageCodec(); - - void postMessage(int instanceId, String message); - - static void setup(JavaScriptChannelFlutterApi? api, - {BinaryMessenger? binaryMessenger}) { - { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.JavaScriptChannelFlutterApi.postMessage', - codec, - binaryMessenger: binaryMessenger); - if (api == null) { - channel.setMessageHandler(null); - } else { - channel.setMessageHandler((Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.JavaScriptChannelFlutterApi.postMessage was null.'); - final List args = (message as List?)!; - final int? arg_instanceId = (args[0] as int?); - assert(arg_instanceId != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.JavaScriptChannelFlutterApi.postMessage was null, expected non-null int.'); - final String? arg_message = (args[1] as String?); - assert(arg_message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.JavaScriptChannelFlutterApi.postMessage was null, expected non-null String.'); - api.postMessage(arg_instanceId!, arg_message!); - return; - }); - } - } - } -} - -class WebViewClientHostApi { - /// Constructor for [WebViewClientHostApi]. The [binaryMessenger] named argument is - /// available for dependency injection. If it is left null, the default - /// BinaryMessenger will be used which routes to the host platform. - WebViewClientHostApi({BinaryMessenger? binaryMessenger}) - : _binaryMessenger = binaryMessenger; - final BinaryMessenger? _binaryMessenger; - - static const MessageCodec codec = StandardMessageCodec(); - - Future create(int arg_instanceId) async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebViewClientHostApi.create', - codec, - binaryMessenger: _binaryMessenger); - final List? replyList = - await channel.send([arg_instanceId]) as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { - throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], - ); - } else { - return; - } - } - - Future setSynchronousReturnValueForShouldOverrideUrlLoading( - int arg_instanceId, bool arg_value) async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebViewClientHostApi.setSynchronousReturnValueForShouldOverrideUrlLoading', - codec, - binaryMessenger: _binaryMessenger); - final List? replyList = await channel - .send([arg_instanceId, arg_value]) as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { - throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], - ); - } else { - return; - } - } -} - -class _WebViewClientFlutterApiCodec extends StandardMessageCodec { - const _WebViewClientFlutterApiCodec(); - @override - void writeValue(WriteBuffer buffer, Object? value) { - if (value is WebResourceErrorData) { - buffer.putUint8(128); - writeValue(buffer, value.encode()); - } else if (value is WebResourceRequestData) { - buffer.putUint8(129); - writeValue(buffer, value.encode()); - } else if (value is WebResourceResponseData) { - buffer.putUint8(130); - writeValue(buffer, value.encode()); - } else { - super.writeValue(buffer, value); - } - } - - @override - Object? readValueOfType(int type, ReadBuffer buffer) { - switch (type) { - case 128: - return WebResourceErrorData.decode(readValue(buffer)!); - case 129: - return WebResourceRequestData.decode(readValue(buffer)!); - case 130: - return WebResourceResponseData.decode(readValue(buffer)!); - default: - return super.readValueOfType(type, buffer); - } - } -} - -abstract class WebViewClientFlutterApi { - static const MessageCodec codec = _WebViewClientFlutterApiCodec(); - - void onPageStarted(int instanceId, int webViewInstanceId, String url); - - void onPageFinished(int instanceId, int webViewInstanceId, String url); - - void onReceivedHttpError(int instanceId, int webViewInstanceId, - WebResourceRequestData request, WebResourceResponseData response); - - void onReceivedRequestError(int instanceId, int webViewInstanceId, - WebResourceRequestData request, WebResourceErrorData error); - - void onReceivedError(int instanceId, int webViewInstanceId, int errorCode, - String description, String failingUrl); - - void requestLoading( - int instanceId, int webViewInstanceId, WebResourceRequestData request); - - void urlLoading(int instanceId, int webViewInstanceId, String url); - - void doUpdateVisitedHistory( - int instanceId, int webViewInstanceId, String url, bool isReload); - - void onReceivedHttpAuthRequest(int instanceId, int webViewInstanceId, - int httpAuthHandlerInstanceId, String host, String realm); - - static void setup(WebViewClientFlutterApi? api, - {BinaryMessenger? binaryMessenger}) { - { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebViewClientFlutterApi.onPageStarted', - codec, - binaryMessenger: binaryMessenger); - if (api == null) { - channel.setMessageHandler(null); - } else { - channel.setMessageHandler((Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewClientFlutterApi.onPageStarted was null.'); - final List args = (message as List?)!; - final int? arg_instanceId = (args[0] as int?); - assert(arg_instanceId != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewClientFlutterApi.onPageStarted was null, expected non-null int.'); - final int? arg_webViewInstanceId = (args[1] as int?); - assert(arg_webViewInstanceId != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewClientFlutterApi.onPageStarted was null, expected non-null int.'); - final String? arg_url = (args[2] as String?); - assert(arg_url != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewClientFlutterApi.onPageStarted was null, expected non-null String.'); - api.onPageStarted(arg_instanceId!, arg_webViewInstanceId!, arg_url!); - return; - }); - } - } - { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebViewClientFlutterApi.onPageFinished', - codec, - binaryMessenger: binaryMessenger); - if (api == null) { - channel.setMessageHandler(null); - } else { - channel.setMessageHandler((Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewClientFlutterApi.onPageFinished was null.'); - final List args = (message as List?)!; - final int? arg_instanceId = (args[0] as int?); - assert(arg_instanceId != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewClientFlutterApi.onPageFinished was null, expected non-null int.'); - final int? arg_webViewInstanceId = (args[1] as int?); - assert(arg_webViewInstanceId != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewClientFlutterApi.onPageFinished was null, expected non-null int.'); - final String? arg_url = (args[2] as String?); - assert(arg_url != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewClientFlutterApi.onPageFinished was null, expected non-null String.'); - api.onPageFinished(arg_instanceId!, arg_webViewInstanceId!, arg_url!); - return; - }); - } - } - { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebViewClientFlutterApi.onReceivedHttpError', - codec, - binaryMessenger: binaryMessenger); - if (api == null) { - channel.setMessageHandler(null); - } else { - channel.setMessageHandler((Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewClientFlutterApi.onReceivedHttpError was null.'); - final List args = (message as List?)!; - final int? arg_instanceId = (args[0] as int?); - assert(arg_instanceId != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewClientFlutterApi.onReceivedHttpError was null, expected non-null int.'); - final int? arg_webViewInstanceId = (args[1] as int?); - assert(arg_webViewInstanceId != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewClientFlutterApi.onReceivedHttpError was null, expected non-null int.'); - final WebResourceRequestData? arg_request = - (args[2] as WebResourceRequestData?); - assert(arg_request != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewClientFlutterApi.onReceivedHttpError was null, expected non-null WebResourceRequestData.'); - final WebResourceResponseData? arg_response = - (args[3] as WebResourceResponseData?); - assert(arg_response != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewClientFlutterApi.onReceivedHttpError was null, expected non-null WebResourceResponseData.'); - api.onReceivedHttpError(arg_instanceId!, arg_webViewInstanceId!, - arg_request!, arg_response!); - return; - }); - } - } - { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebViewClientFlutterApi.onReceivedRequestError', - codec, - binaryMessenger: binaryMessenger); - if (api == null) { - channel.setMessageHandler(null); - } else { - channel.setMessageHandler((Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewClientFlutterApi.onReceivedRequestError was null.'); - final List args = (message as List?)!; - final int? arg_instanceId = (args[0] as int?); - assert(arg_instanceId != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewClientFlutterApi.onReceivedRequestError was null, expected non-null int.'); - final int? arg_webViewInstanceId = (args[1] as int?); - assert(arg_webViewInstanceId != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewClientFlutterApi.onReceivedRequestError was null, expected non-null int.'); - final WebResourceRequestData? arg_request = - (args[2] as WebResourceRequestData?); - assert(arg_request != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewClientFlutterApi.onReceivedRequestError was null, expected non-null WebResourceRequestData.'); - final WebResourceErrorData? arg_error = - (args[3] as WebResourceErrorData?); - assert(arg_error != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewClientFlutterApi.onReceivedRequestError was null, expected non-null WebResourceErrorData.'); - api.onReceivedRequestError(arg_instanceId!, arg_webViewInstanceId!, - arg_request!, arg_error!); - return; - }); - } - } - { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebViewClientFlutterApi.onReceivedError', - codec, - binaryMessenger: binaryMessenger); - if (api == null) { - channel.setMessageHandler(null); - } else { - channel.setMessageHandler((Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewClientFlutterApi.onReceivedError was null.'); - final List args = (message as List?)!; - final int? arg_instanceId = (args[0] as int?); - assert(arg_instanceId != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewClientFlutterApi.onReceivedError was null, expected non-null int.'); - final int? arg_webViewInstanceId = (args[1] as int?); - assert(arg_webViewInstanceId != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewClientFlutterApi.onReceivedError was null, expected non-null int.'); - final int? arg_errorCode = (args[2] as int?); - assert(arg_errorCode != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewClientFlutterApi.onReceivedError was null, expected non-null int.'); - final String? arg_description = (args[3] as String?); - assert(arg_description != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewClientFlutterApi.onReceivedError was null, expected non-null String.'); - final String? arg_failingUrl = (args[4] as String?); - assert(arg_failingUrl != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewClientFlutterApi.onReceivedError was null, expected non-null String.'); - api.onReceivedError(arg_instanceId!, arg_webViewInstanceId!, - arg_errorCode!, arg_description!, arg_failingUrl!); - return; - }); - } - } - { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebViewClientFlutterApi.requestLoading', - codec, - binaryMessenger: binaryMessenger); - if (api == null) { - channel.setMessageHandler(null); - } else { - channel.setMessageHandler((Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewClientFlutterApi.requestLoading was null.'); - final List args = (message as List?)!; - final int? arg_instanceId = (args[0] as int?); - assert(arg_instanceId != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewClientFlutterApi.requestLoading was null, expected non-null int.'); - final int? arg_webViewInstanceId = (args[1] as int?); - assert(arg_webViewInstanceId != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewClientFlutterApi.requestLoading was null, expected non-null int.'); - final WebResourceRequestData? arg_request = - (args[2] as WebResourceRequestData?); - assert(arg_request != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewClientFlutterApi.requestLoading was null, expected non-null WebResourceRequestData.'); - api.requestLoading( - arg_instanceId!, arg_webViewInstanceId!, arg_request!); - return; - }); - } - } - { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebViewClientFlutterApi.urlLoading', - codec, - binaryMessenger: binaryMessenger); - if (api == null) { - channel.setMessageHandler(null); - } else { - channel.setMessageHandler((Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewClientFlutterApi.urlLoading was null.'); - final List args = (message as List?)!; - final int? arg_instanceId = (args[0] as int?); - assert(arg_instanceId != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewClientFlutterApi.urlLoading was null, expected non-null int.'); - final int? arg_webViewInstanceId = (args[1] as int?); - assert(arg_webViewInstanceId != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewClientFlutterApi.urlLoading was null, expected non-null int.'); - final String? arg_url = (args[2] as String?); - assert(arg_url != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewClientFlutterApi.urlLoading was null, expected non-null String.'); - api.urlLoading(arg_instanceId!, arg_webViewInstanceId!, arg_url!); - return; - }); - } - } - { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebViewClientFlutterApi.doUpdateVisitedHistory', - codec, - binaryMessenger: binaryMessenger); - if (api == null) { - channel.setMessageHandler(null); - } else { - channel.setMessageHandler((Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewClientFlutterApi.doUpdateVisitedHistory was null.'); - final List args = (message as List?)!; - final int? arg_instanceId = (args[0] as int?); - assert(arg_instanceId != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewClientFlutterApi.doUpdateVisitedHistory was null, expected non-null int.'); - final int? arg_webViewInstanceId = (args[1] as int?); - assert(arg_webViewInstanceId != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewClientFlutterApi.doUpdateVisitedHistory was null, expected non-null int.'); - final String? arg_url = (args[2] as String?); - assert(arg_url != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewClientFlutterApi.doUpdateVisitedHistory was null, expected non-null String.'); - final bool? arg_isReload = (args[3] as bool?); - assert(arg_isReload != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewClientFlutterApi.doUpdateVisitedHistory was null, expected non-null bool.'); - api.doUpdateVisitedHistory( - arg_instanceId!, arg_webViewInstanceId!, arg_url!, arg_isReload!); - return; - }); - } - } - { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebViewClientFlutterApi.onReceivedHttpAuthRequest', - codec, - binaryMessenger: binaryMessenger); - if (api == null) { - channel.setMessageHandler(null); - } else { - channel.setMessageHandler((Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewClientFlutterApi.onReceivedHttpAuthRequest was null.'); - final List args = (message as List?)!; - final int? arg_instanceId = (args[0] as int?); - assert(arg_instanceId != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewClientFlutterApi.onReceivedHttpAuthRequest was null, expected non-null int.'); - final int? arg_webViewInstanceId = (args[1] as int?); - assert(arg_webViewInstanceId != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewClientFlutterApi.onReceivedHttpAuthRequest was null, expected non-null int.'); - final int? arg_httpAuthHandlerInstanceId = (args[2] as int?); - assert(arg_httpAuthHandlerInstanceId != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewClientFlutterApi.onReceivedHttpAuthRequest was null, expected non-null int.'); - final String? arg_host = (args[3] as String?); - assert(arg_host != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewClientFlutterApi.onReceivedHttpAuthRequest was null, expected non-null String.'); - final String? arg_realm = (args[4] as String?); - assert(arg_realm != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewClientFlutterApi.onReceivedHttpAuthRequest was null, expected non-null String.'); - api.onReceivedHttpAuthRequest(arg_instanceId!, arg_webViewInstanceId!, - arg_httpAuthHandlerInstanceId!, arg_host!, arg_realm!); - return; - }); - } - } - } -} - -class DownloadListenerHostApi { - /// Constructor for [DownloadListenerHostApi]. The [binaryMessenger] named argument is - /// available for dependency injection. If it is left null, the default - /// BinaryMessenger will be used which routes to the host platform. - DownloadListenerHostApi({BinaryMessenger? binaryMessenger}) - : _binaryMessenger = binaryMessenger; - final BinaryMessenger? _binaryMessenger; - - static const MessageCodec codec = StandardMessageCodec(); - - Future create(int arg_instanceId) async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.DownloadListenerHostApi.create', - codec, - binaryMessenger: _binaryMessenger); - final List? replyList = - await channel.send([arg_instanceId]) as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { - throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], - ); - } else { - return; - } - } -} - -abstract class DownloadListenerFlutterApi { - static const MessageCodec codec = StandardMessageCodec(); - - void onDownloadStart(int instanceId, String url, String userAgent, - String contentDisposition, String mimetype, int contentLength); - - static void setup(DownloadListenerFlutterApi? api, - {BinaryMessenger? binaryMessenger}) { - { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.DownloadListenerFlutterApi.onDownloadStart', - codec, - binaryMessenger: binaryMessenger); - if (api == null) { - channel.setMessageHandler(null); - } else { - channel.setMessageHandler((Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.DownloadListenerFlutterApi.onDownloadStart was null.'); - final List args = (message as List?)!; - final int? arg_instanceId = (args[0] as int?); - assert(arg_instanceId != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.DownloadListenerFlutterApi.onDownloadStart was null, expected non-null int.'); - final String? arg_url = (args[1] as String?); - assert(arg_url != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.DownloadListenerFlutterApi.onDownloadStart was null, expected non-null String.'); - final String? arg_userAgent = (args[2] as String?); - assert(arg_userAgent != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.DownloadListenerFlutterApi.onDownloadStart was null, expected non-null String.'); - final String? arg_contentDisposition = (args[3] as String?); - assert(arg_contentDisposition != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.DownloadListenerFlutterApi.onDownloadStart was null, expected non-null String.'); - final String? arg_mimetype = (args[4] as String?); - assert(arg_mimetype != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.DownloadListenerFlutterApi.onDownloadStart was null, expected non-null String.'); - final int? arg_contentLength = (args[5] as int?); - assert(arg_contentLength != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.DownloadListenerFlutterApi.onDownloadStart was null, expected non-null int.'); - api.onDownloadStart(arg_instanceId!, arg_url!, arg_userAgent!, - arg_contentDisposition!, arg_mimetype!, arg_contentLength!); - return; - }); - } - } - } -} - -class WebChromeClientHostApi { - /// Constructor for [WebChromeClientHostApi]. The [binaryMessenger] named argument is - /// available for dependency injection. If it is left null, the default - /// BinaryMessenger will be used which routes to the host platform. - WebChromeClientHostApi({BinaryMessenger? binaryMessenger}) - : _binaryMessenger = binaryMessenger; - final BinaryMessenger? _binaryMessenger; - - static const MessageCodec codec = StandardMessageCodec(); - - Future create(int arg_instanceId) async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebChromeClientHostApi.create', - codec, - binaryMessenger: _binaryMessenger); - final List? replyList = - await channel.send([arg_instanceId]) as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { - throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], - ); - } else { - return; - } - } - - Future setSynchronousReturnValueForOnShowFileChooser( - int arg_instanceId, bool arg_value) async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebChromeClientHostApi.setSynchronousReturnValueForOnShowFileChooser', - codec, - binaryMessenger: _binaryMessenger); - final List? replyList = await channel - .send([arg_instanceId, arg_value]) as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { - throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], - ); - } else { - return; - } - } - - Future setSynchronousReturnValueForOnConsoleMessage( - int arg_instanceId, bool arg_value) async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebChromeClientHostApi.setSynchronousReturnValueForOnConsoleMessage', - codec, - binaryMessenger: _binaryMessenger); - final List? replyList = await channel - .send([arg_instanceId, arg_value]) as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { - throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], - ); - } else { - return; - } - } - - Future setSynchronousReturnValueForOnJsAlert( - int arg_instanceId, bool arg_value) async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebChromeClientHostApi.setSynchronousReturnValueForOnJsAlert', - codec, - binaryMessenger: _binaryMessenger); - final List? replyList = await channel - .send([arg_instanceId, arg_value]) as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { - throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], - ); - } else { - return; - } - } - - Future setSynchronousReturnValueForOnJsConfirm( - int arg_instanceId, bool arg_value) async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebChromeClientHostApi.setSynchronousReturnValueForOnJsConfirm', - codec, - binaryMessenger: _binaryMessenger); - final List? replyList = await channel - .send([arg_instanceId, arg_value]) as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { - throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], - ); - } else { - return; - } - } - - Future setSynchronousReturnValueForOnJsPrompt( - int arg_instanceId, bool arg_value) async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebChromeClientHostApi.setSynchronousReturnValueForOnJsPrompt', - codec, - binaryMessenger: _binaryMessenger); - final List? replyList = await channel - .send([arg_instanceId, arg_value]) as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { - throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], - ); - } else { - return; - } - } -} - -class FlutterAssetManagerHostApi { - /// Constructor for [FlutterAssetManagerHostApi]. The [binaryMessenger] named argument is - /// available for dependency injection. If it is left null, the default - /// BinaryMessenger will be used which routes to the host platform. - FlutterAssetManagerHostApi({BinaryMessenger? binaryMessenger}) - : _binaryMessenger = binaryMessenger; - final BinaryMessenger? _binaryMessenger; - - static const MessageCodec codec = StandardMessageCodec(); - - Future> list(String arg_path) async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.FlutterAssetManagerHostApi.list', - codec, - binaryMessenger: _binaryMessenger); - final List? replyList = - await channel.send([arg_path]) as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { - throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], - ); - } else if (replyList[0] == null) { - throw PlatformException( - code: 'null-error', - message: 'Host platform returned null value for non-null return value.', - ); - } else { - return (replyList[0] as List?)!.cast(); - } - } - - Future getAssetFilePathByName(String arg_name) async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.FlutterAssetManagerHostApi.getAssetFilePathByName', - codec, - binaryMessenger: _binaryMessenger); - final List? replyList = - await channel.send([arg_name]) as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { - throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], - ); - } else if (replyList[0] == null) { - throw PlatformException( - code: 'null-error', - message: 'Host platform returned null value for non-null return value.', - ); - } else { - return (replyList[0] as String?)!; - } - } -} - -class _WebChromeClientFlutterApiCodec extends StandardMessageCodec { - const _WebChromeClientFlutterApiCodec(); - @override - void writeValue(WriteBuffer buffer, Object? value) { - if (value is ConsoleMessage) { - buffer.putUint8(128); - writeValue(buffer, value.encode()); - } else { - super.writeValue(buffer, value); - } - } - - @override - Object? readValueOfType(int type, ReadBuffer buffer) { - switch (type) { - case 128: - return ConsoleMessage.decode(readValue(buffer)!); - default: - return super.readValueOfType(type, buffer); - } - } -} - -abstract class WebChromeClientFlutterApi { - static const MessageCodec codec = _WebChromeClientFlutterApiCodec(); - - void onProgressChanged(int instanceId, int webViewInstanceId, int progress); - - Future> onShowFileChooser( - int instanceId, int webViewInstanceId, int paramsInstanceId); - - /// Callback to Dart function `WebChromeClient.onPermissionRequest`. - void onPermissionRequest(int instanceId, int requestInstanceId); - - /// Callback to Dart function `WebChromeClient.onShowCustomView`. - void onShowCustomView( - int instanceId, int viewIdentifier, int callbackIdentifier); - - /// Callback to Dart function `WebChromeClient.onHideCustomView`. - void onHideCustomView(int instanceId); - - /// Callback to Dart function `WebChromeClient.onGeolocationPermissionsShowPrompt`. - void onGeolocationPermissionsShowPrompt( - int instanceId, int paramsInstanceId, String origin); - - /// Callback to Dart function `WebChromeClient.onGeolocationPermissionsHidePrompt`. - void onGeolocationPermissionsHidePrompt(int identifier); - - /// Callback to Dart function `WebChromeClient.onConsoleMessage`. - void onConsoleMessage(int instanceId, ConsoleMessage message); - - Future onJsAlert(int instanceId, String url, String message); - - Future onJsConfirm(int instanceId, String url, String message); - - Future onJsPrompt( - int instanceId, String url, String message, String defaultValue); - - static void setup(WebChromeClientFlutterApi? api, - {BinaryMessenger? binaryMessenger}) { - { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebChromeClientFlutterApi.onProgressChanged', - codec, - binaryMessenger: binaryMessenger); - if (api == null) { - channel.setMessageHandler(null); - } else { - channel.setMessageHandler((Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebChromeClientFlutterApi.onProgressChanged was null.'); - final List args = (message as List?)!; - final int? arg_instanceId = (args[0] as int?); - assert(arg_instanceId != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebChromeClientFlutterApi.onProgressChanged was null, expected non-null int.'); - final int? arg_webViewInstanceId = (args[1] as int?); - assert(arg_webViewInstanceId != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebChromeClientFlutterApi.onProgressChanged was null, expected non-null int.'); - final int? arg_progress = (args[2] as int?); - assert(arg_progress != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebChromeClientFlutterApi.onProgressChanged was null, expected non-null int.'); - api.onProgressChanged( - arg_instanceId!, arg_webViewInstanceId!, arg_progress!); - return; - }); - } - } - { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebChromeClientFlutterApi.onShowFileChooser', - codec, - binaryMessenger: binaryMessenger); - if (api == null) { - channel.setMessageHandler(null); - } else { - channel.setMessageHandler((Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebChromeClientFlutterApi.onShowFileChooser was null.'); - final List args = (message as List?)!; - final int? arg_instanceId = (args[0] as int?); - assert(arg_instanceId != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebChromeClientFlutterApi.onShowFileChooser was null, expected non-null int.'); - final int? arg_webViewInstanceId = (args[1] as int?); - assert(arg_webViewInstanceId != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebChromeClientFlutterApi.onShowFileChooser was null, expected non-null int.'); - final int? arg_paramsInstanceId = (args[2] as int?); - assert(arg_paramsInstanceId != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebChromeClientFlutterApi.onShowFileChooser was null, expected non-null int.'); - final List output = await api.onShowFileChooser( - arg_instanceId!, arg_webViewInstanceId!, arg_paramsInstanceId!); - return output; - }); - } - } - { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebChromeClientFlutterApi.onPermissionRequest', - codec, - binaryMessenger: binaryMessenger); - if (api == null) { - channel.setMessageHandler(null); - } else { - channel.setMessageHandler((Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebChromeClientFlutterApi.onPermissionRequest was null.'); - final List args = (message as List?)!; - final int? arg_instanceId = (args[0] as int?); - assert(arg_instanceId != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebChromeClientFlutterApi.onPermissionRequest was null, expected non-null int.'); - final int? arg_requestInstanceId = (args[1] as int?); - assert(arg_requestInstanceId != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebChromeClientFlutterApi.onPermissionRequest was null, expected non-null int.'); - api.onPermissionRequest(arg_instanceId!, arg_requestInstanceId!); - return; - }); - } - } - { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebChromeClientFlutterApi.onShowCustomView', - codec, - binaryMessenger: binaryMessenger); - if (api == null) { - channel.setMessageHandler(null); - } else { - channel.setMessageHandler((Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebChromeClientFlutterApi.onShowCustomView was null.'); - final List args = (message as List?)!; - final int? arg_instanceId = (args[0] as int?); - assert(arg_instanceId != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebChromeClientFlutterApi.onShowCustomView was null, expected non-null int.'); - final int? arg_viewIdentifier = (args[1] as int?); - assert(arg_viewIdentifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebChromeClientFlutterApi.onShowCustomView was null, expected non-null int.'); - final int? arg_callbackIdentifier = (args[2] as int?); - assert(arg_callbackIdentifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebChromeClientFlutterApi.onShowCustomView was null, expected non-null int.'); - api.onShowCustomView( - arg_instanceId!, arg_viewIdentifier!, arg_callbackIdentifier!); - return; - }); - } - } - { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebChromeClientFlutterApi.onHideCustomView', - codec, - binaryMessenger: binaryMessenger); - if (api == null) { - channel.setMessageHandler(null); - } else { - channel.setMessageHandler((Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebChromeClientFlutterApi.onHideCustomView was null.'); - final List args = (message as List?)!; - final int? arg_instanceId = (args[0] as int?); - assert(arg_instanceId != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebChromeClientFlutterApi.onHideCustomView was null, expected non-null int.'); - api.onHideCustomView(arg_instanceId!); - return; - }); - } - } - { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebChromeClientFlutterApi.onGeolocationPermissionsShowPrompt', - codec, - binaryMessenger: binaryMessenger); - if (api == null) { - channel.setMessageHandler(null); - } else { - channel.setMessageHandler((Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebChromeClientFlutterApi.onGeolocationPermissionsShowPrompt was null.'); - final List args = (message as List?)!; - final int? arg_instanceId = (args[0] as int?); - assert(arg_instanceId != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebChromeClientFlutterApi.onGeolocationPermissionsShowPrompt was null, expected non-null int.'); - final int? arg_paramsInstanceId = (args[1] as int?); - assert(arg_paramsInstanceId != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebChromeClientFlutterApi.onGeolocationPermissionsShowPrompt was null, expected non-null int.'); - final String? arg_origin = (args[2] as String?); - assert(arg_origin != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebChromeClientFlutterApi.onGeolocationPermissionsShowPrompt was null, expected non-null String.'); - api.onGeolocationPermissionsShowPrompt( - arg_instanceId!, arg_paramsInstanceId!, arg_origin!); - return; - }); - } - } - { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebChromeClientFlutterApi.onGeolocationPermissionsHidePrompt', - codec, - binaryMessenger: binaryMessenger); - if (api == null) { - channel.setMessageHandler(null); - } else { - channel.setMessageHandler((Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebChromeClientFlutterApi.onGeolocationPermissionsHidePrompt was null.'); - final List args = (message as List?)!; - final int? arg_identifier = (args[0] as int?); - assert(arg_identifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebChromeClientFlutterApi.onGeolocationPermissionsHidePrompt was null, expected non-null int.'); - api.onGeolocationPermissionsHidePrompt(arg_identifier!); - return; - }); - } - } - { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebChromeClientFlutterApi.onConsoleMessage', - codec, - binaryMessenger: binaryMessenger); - if (api == null) { - channel.setMessageHandler(null); - } else { - channel.setMessageHandler((Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebChromeClientFlutterApi.onConsoleMessage was null.'); - final List args = (message as List?)!; - final int? arg_instanceId = (args[0] as int?); - assert(arg_instanceId != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebChromeClientFlutterApi.onConsoleMessage was null, expected non-null int.'); - final ConsoleMessage? arg_message = (args[1] as ConsoleMessage?); - assert(arg_message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebChromeClientFlutterApi.onConsoleMessage was null, expected non-null ConsoleMessage.'); - api.onConsoleMessage(arg_instanceId!, arg_message!); - return; - }); - } - } - { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebChromeClientFlutterApi.onJsAlert', - codec, - binaryMessenger: binaryMessenger); - if (api == null) { - channel.setMessageHandler(null); - } else { - channel.setMessageHandler((Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebChromeClientFlutterApi.onJsAlert was null.'); - final List args = (message as List?)!; - final int? arg_instanceId = (args[0] as int?); - assert(arg_instanceId != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebChromeClientFlutterApi.onJsAlert was null, expected non-null int.'); - final String? arg_url = (args[1] as String?); - assert(arg_url != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebChromeClientFlutterApi.onJsAlert was null, expected non-null String.'); - final String? arg_message = (args[2] as String?); - assert(arg_message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebChromeClientFlutterApi.onJsAlert was null, expected non-null String.'); - await api.onJsAlert(arg_instanceId!, arg_url!, arg_message!); - return; - }); - } - } - { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebChromeClientFlutterApi.onJsConfirm', - codec, - binaryMessenger: binaryMessenger); - if (api == null) { - channel.setMessageHandler(null); - } else { - channel.setMessageHandler((Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebChromeClientFlutterApi.onJsConfirm was null.'); - final List args = (message as List?)!; - final int? arg_instanceId = (args[0] as int?); - assert(arg_instanceId != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebChromeClientFlutterApi.onJsConfirm was null, expected non-null int.'); - final String? arg_url = (args[1] as String?); - assert(arg_url != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebChromeClientFlutterApi.onJsConfirm was null, expected non-null String.'); - final String? arg_message = (args[2] as String?); - assert(arg_message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebChromeClientFlutterApi.onJsConfirm was null, expected non-null String.'); - final bool output = - await api.onJsConfirm(arg_instanceId!, arg_url!, arg_message!); - return output; - }); - } - } - { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebChromeClientFlutterApi.onJsPrompt', - codec, - binaryMessenger: binaryMessenger); - if (api == null) { - channel.setMessageHandler(null); - } else { - channel.setMessageHandler((Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebChromeClientFlutterApi.onJsPrompt was null.'); - final List args = (message as List?)!; - final int? arg_instanceId = (args[0] as int?); - assert(arg_instanceId != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebChromeClientFlutterApi.onJsPrompt was null, expected non-null int.'); - final String? arg_url = (args[1] as String?); - assert(arg_url != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebChromeClientFlutterApi.onJsPrompt was null, expected non-null String.'); - final String? arg_message = (args[2] as String?); - assert(arg_message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebChromeClientFlutterApi.onJsPrompt was null, expected non-null String.'); - final String? arg_defaultValue = (args[3] as String?); - assert(arg_defaultValue != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebChromeClientFlutterApi.onJsPrompt was null, expected non-null String.'); - final String output = await api.onJsPrompt( - arg_instanceId!, arg_url!, arg_message!, arg_defaultValue!); - return output; - }); - } - } - } -} - -class WebStorageHostApi { - /// Constructor for [WebStorageHostApi]. The [binaryMessenger] named argument is - /// available for dependency injection. If it is left null, the default - /// BinaryMessenger will be used which routes to the host platform. - WebStorageHostApi({BinaryMessenger? binaryMessenger}) - : _binaryMessenger = binaryMessenger; - final BinaryMessenger? _binaryMessenger; - - static const MessageCodec codec = StandardMessageCodec(); - - Future create(int arg_instanceId) async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebStorageHostApi.create', - codec, - binaryMessenger: _binaryMessenger); - final List? replyList = - await channel.send([arg_instanceId]) as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { - throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], - ); - } else { - return; - } - } - - Future deleteAllData(int arg_instanceId) async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebStorageHostApi.deleteAllData', - codec, - binaryMessenger: _binaryMessenger); - final List? replyList = - await channel.send([arg_instanceId]) as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { - throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], - ); - } else { - return; - } - } -} - -/// Handles callbacks methods for the native Java FileChooserParams class. -/// -/// See https://developer.android.com/reference/android/webkit/WebChromeClient.FileChooserParams. -abstract class FileChooserParamsFlutterApi { - static const MessageCodec codec = StandardMessageCodec(); - - void create(int instanceId, bool isCaptureEnabled, List acceptTypes, - FileChooserMode mode, String? filenameHint); - - static void setup(FileChooserParamsFlutterApi? api, - {BinaryMessenger? binaryMessenger}) { - { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.FileChooserParamsFlutterApi.create', - codec, - binaryMessenger: binaryMessenger); - if (api == null) { - channel.setMessageHandler(null); - } else { - channel.setMessageHandler((Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.FileChooserParamsFlutterApi.create was null.'); - final List args = (message as List?)!; - final int? arg_instanceId = (args[0] as int?); - assert(arg_instanceId != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.FileChooserParamsFlutterApi.create was null, expected non-null int.'); - final bool? arg_isCaptureEnabled = (args[1] as bool?); - assert(arg_isCaptureEnabled != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.FileChooserParamsFlutterApi.create was null, expected non-null bool.'); - final List? arg_acceptTypes = - (args[2] as List?)?.cast(); - assert(arg_acceptTypes != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.FileChooserParamsFlutterApi.create was null, expected non-null List.'); - final FileChooserMode? arg_mode = - args[3] == null ? null : FileChooserMode.values[args[3]! as int]; - assert(arg_mode != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.FileChooserParamsFlutterApi.create was null, expected non-null FileChooserMode.'); - final String? arg_filenameHint = (args[4] as String?); - api.create(arg_instanceId!, arg_isCaptureEnabled!, arg_acceptTypes!, - arg_mode!, arg_filenameHint); - return; - }); - } - } - } -} - -/// Host API for `PermissionRequest`. -/// -/// This class may handle instantiating and adding native object instances that -/// are attached to a Dart instance or handle method calls on the associated -/// native class or an instance of the class. -/// -/// See https://developer.android.com/reference/android/webkit/PermissionRequest. -class PermissionRequestHostApi { - /// Constructor for [PermissionRequestHostApi]. The [binaryMessenger] named argument is - /// available for dependency injection. If it is left null, the default - /// BinaryMessenger will be used which routes to the host platform. - PermissionRequestHostApi({BinaryMessenger? binaryMessenger}) - : _binaryMessenger = binaryMessenger; - final BinaryMessenger? _binaryMessenger; - - static const MessageCodec codec = StandardMessageCodec(); - - /// Handles Dart method `PermissionRequest.grant`. - Future grant(int arg_instanceId, List arg_resources) async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.PermissionRequestHostApi.grant', - codec, - binaryMessenger: _binaryMessenger); - final List? replyList = await channel - .send([arg_instanceId, arg_resources]) as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { - throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], - ); - } else { - return; - } - } - - /// Handles Dart method `PermissionRequest.deny`. - Future deny(int arg_instanceId) async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.PermissionRequestHostApi.deny', - codec, - binaryMessenger: _binaryMessenger); - final List? replyList = - await channel.send([arg_instanceId]) as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { - throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], - ); - } else { - return; - } - } -} - -/// Flutter API for `PermissionRequest`. -/// -/// This class may handle instantiating and adding Dart instances that are -/// attached to a native instance or receiving callback methods from an -/// overridden native class. -/// -/// See https://developer.android.com/reference/android/webkit/PermissionRequest. -abstract class PermissionRequestFlutterApi { - static const MessageCodec codec = StandardMessageCodec(); - - /// Create a new Dart instance and add it to the `InstanceManager`. - void create(int instanceId, List resources); - - static void setup(PermissionRequestFlutterApi? api, - {BinaryMessenger? binaryMessenger}) { - { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.PermissionRequestFlutterApi.create', - codec, - binaryMessenger: binaryMessenger); - if (api == null) { - channel.setMessageHandler(null); - } else { - channel.setMessageHandler((Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.PermissionRequestFlutterApi.create was null.'); - final List args = (message as List?)!; - final int? arg_instanceId = (args[0] as int?); - assert(arg_instanceId != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.PermissionRequestFlutterApi.create was null, expected non-null int.'); - final List? arg_resources = - (args[1] as List?)?.cast(); - assert(arg_resources != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.PermissionRequestFlutterApi.create was null, expected non-null List.'); - api.create(arg_instanceId!, arg_resources!); - return; - }); - } - } - } -} - -/// Host API for `CustomViewCallback`. -/// -/// This class may handle instantiating and adding native object instances that -/// are attached to a Dart instance or handle method calls on the associated -/// native class or an instance of the class. -/// -/// See https://developer.android.com/reference/android/webkit/WebChromeClient.CustomViewCallback. -class CustomViewCallbackHostApi { - /// Constructor for [CustomViewCallbackHostApi]. The [binaryMessenger] named argument is - /// available for dependency injection. If it is left null, the default - /// BinaryMessenger will be used which routes to the host platform. - CustomViewCallbackHostApi({BinaryMessenger? binaryMessenger}) - : _binaryMessenger = binaryMessenger; - final BinaryMessenger? _binaryMessenger; - - static const MessageCodec codec = StandardMessageCodec(); - - /// Handles Dart method `CustomViewCallback.onCustomViewHidden`. - Future onCustomViewHidden(int arg_identifier) async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.CustomViewCallbackHostApi.onCustomViewHidden', - codec, - binaryMessenger: _binaryMessenger); - final List? replyList = - await channel.send([arg_identifier]) as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { - throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], - ); - } else { - return; - } - } -} - -/// Flutter API for `CustomViewCallback`. -/// -/// This class may handle instantiating and adding Dart instances that are -/// attached to a native instance or receiving callback methods from an -/// overridden native class. -/// -/// See https://developer.android.com/reference/android/webkit/WebChromeClient.CustomViewCallback. -abstract class CustomViewCallbackFlutterApi { - static const MessageCodec codec = StandardMessageCodec(); - - /// Create a new Dart instance and add it to the `InstanceManager`. - void create(int identifier); - - static void setup(CustomViewCallbackFlutterApi? api, - {BinaryMessenger? binaryMessenger}) { - { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.CustomViewCallbackFlutterApi.create', - codec, - binaryMessenger: binaryMessenger); - if (api == null) { - channel.setMessageHandler(null); - } else { - channel.setMessageHandler((Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.CustomViewCallbackFlutterApi.create was null.'); - final List args = (message as List?)!; - final int? arg_identifier = (args[0] as int?); - assert(arg_identifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.CustomViewCallbackFlutterApi.create was null, expected non-null int.'); - api.create(arg_identifier!); - return; - }); - } - } - } -} - -/// Flutter API for `View`. -/// -/// This class may handle instantiating and adding Dart instances that are -/// attached to a native instance or receiving callback methods from an -/// overridden native class. -/// -/// See https://developer.android.com/reference/android/view/View. -abstract class ViewFlutterApi { - static const MessageCodec codec = StandardMessageCodec(); - - /// Create a new Dart instance and add it to the `InstanceManager`. - void create(int identifier); - - static void setup(ViewFlutterApi? api, {BinaryMessenger? binaryMessenger}) { - { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.ViewFlutterApi.create', - codec, - binaryMessenger: binaryMessenger); - if (api == null) { - channel.setMessageHandler(null); - } else { - channel.setMessageHandler((Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.ViewFlutterApi.create was null.'); - final List args = (message as List?)!; - final int? arg_identifier = (args[0] as int?); - assert(arg_identifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.ViewFlutterApi.create was null, expected non-null int.'); - api.create(arg_identifier!); - return; - }); - } - } - } -} - -/// Host API for `GeolocationPermissionsCallback`. -/// -/// This class may handle instantiating and adding native object instances that -/// are attached to a Dart instance or handle method calls on the associated -/// native class or an instance of the class. -/// -/// See https://developer.android.com/reference/android/webkit/GeolocationPermissions.Callback. -class GeolocationPermissionsCallbackHostApi { - /// Constructor for [GeolocationPermissionsCallbackHostApi]. The [binaryMessenger] named argument is - /// available for dependency injection. If it is left null, the default - /// BinaryMessenger will be used which routes to the host platform. - GeolocationPermissionsCallbackHostApi({BinaryMessenger? binaryMessenger}) - : _binaryMessenger = binaryMessenger; - final BinaryMessenger? _binaryMessenger; - - static const MessageCodec codec = StandardMessageCodec(); - - /// Handles Dart method `GeolocationPermissionsCallback.invoke`. - Future invoke(int arg_instanceId, String arg_origin, bool arg_allow, - bool arg_retain) async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.GeolocationPermissionsCallbackHostApi.invoke', - codec, - binaryMessenger: _binaryMessenger); - final List? replyList = await channel - .send([arg_instanceId, arg_origin, arg_allow, arg_retain]) - as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { - throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], - ); - } else { - return; - } - } -} - -/// Flutter API for `GeolocationPermissionsCallback`. -/// -/// This class may handle instantiating and adding Dart instances that are -/// attached to a native instance or receiving callback methods from an -/// overridden native class. -/// -/// See https://developer.android.com/reference/android/webkit/GeolocationPermissions.Callback. -abstract class GeolocationPermissionsCallbackFlutterApi { - static const MessageCodec codec = StandardMessageCodec(); - - /// Create a new Dart instance and add it to the `InstanceManager`. - void create(int instanceId); - - static void setup(GeolocationPermissionsCallbackFlutterApi? api, - {BinaryMessenger? binaryMessenger}) { - { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.GeolocationPermissionsCallbackFlutterApi.create', - codec, - binaryMessenger: binaryMessenger); - if (api == null) { - channel.setMessageHandler(null); - } else { - channel.setMessageHandler((Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.GeolocationPermissionsCallbackFlutterApi.create was null.'); - final List args = (message as List?)!; - final int? arg_instanceId = (args[0] as int?); - assert(arg_instanceId != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.GeolocationPermissionsCallbackFlutterApi.create was null, expected non-null int.'); - api.create(arg_instanceId!); - return; - }); - } - } - } -} - -/// Host API for `HttpAuthHandler`. -/// -/// This class may handle instantiating and adding native object instances that -/// are attached to a Dart instance or handle method calls on the associated -/// native class or an instance of the class. -/// -/// See https://developer.android.com/reference/android/webkit/HttpAuthHandler. -class HttpAuthHandlerHostApi { - /// Constructor for [HttpAuthHandlerHostApi]. The [binaryMessenger] named argument is - /// available for dependency injection. If it is left null, the default - /// BinaryMessenger will be used which routes to the host platform. - HttpAuthHandlerHostApi({BinaryMessenger? binaryMessenger}) - : _binaryMessenger = binaryMessenger; - final BinaryMessenger? _binaryMessenger; - - static const MessageCodec codec = StandardMessageCodec(); - - /// Handles Dart method `HttpAuthHandler.useHttpAuthUsernamePassword`. - Future useHttpAuthUsernamePassword(int arg_instanceId) async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.HttpAuthHandlerHostApi.useHttpAuthUsernamePassword', - codec, - binaryMessenger: _binaryMessenger); - final List? replyList = - await channel.send([arg_instanceId]) as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { - throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], - ); - } else if (replyList[0] == null) { - throw PlatformException( - code: 'null-error', - message: 'Host platform returned null value for non-null return value.', - ); - } else { - return (replyList[0] as bool?)!; - } - } - - /// Handles Dart method `HttpAuthHandler.cancel`. - Future cancel(int arg_instanceId) async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.HttpAuthHandlerHostApi.cancel', - codec, - binaryMessenger: _binaryMessenger); - final List? replyList = - await channel.send([arg_instanceId]) as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { - throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], - ); - } else { - return; - } - } - - /// Handles Dart method `HttpAuthHandler.proceed`. - Future proceed( - int arg_instanceId, String arg_username, String arg_password) async { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.HttpAuthHandlerHostApi.proceed', - codec, - binaryMessenger: _binaryMessenger); - final List? replyList = await channel - .send([arg_instanceId, arg_username, arg_password]) - as List?; - if (replyList == null) { - throw PlatformException( - code: 'channel-error', - message: 'Unable to establish connection on channel.', - ); - } else if (replyList.length > 1) { - throw PlatformException( - code: replyList[0]! as String, - message: replyList[1] as String?, - details: replyList[2], - ); - } else { - return; - } - } -} - -/// Flutter API for `HttpAuthHandler`. -/// -/// This class may handle instantiating and adding Dart instances that are -/// attached to a native instance or receiving callback methods from an -/// overridden native class. -/// -/// See https://developer.android.com/reference/android/webkit/HttpAuthHandler. -abstract class HttpAuthHandlerFlutterApi { - static const MessageCodec codec = StandardMessageCodec(); - - /// Create a new Dart instance and add it to the `InstanceManager`. - void create(int instanceId); - - static void setup(HttpAuthHandlerFlutterApi? api, - {BinaryMessenger? binaryMessenger}) { - { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.HttpAuthHandlerFlutterApi.create', - codec, - binaryMessenger: binaryMessenger); - if (api == null) { - channel.setMessageHandler(null); - } else { - channel.setMessageHandler((Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.HttpAuthHandlerFlutterApi.create was null.'); - final List args = (message as List?)!; - final int? arg_instanceId = (args[0] as int?); - assert(arg_instanceId != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.HttpAuthHandlerFlutterApi.create was null, expected non-null int.'); - api.create(arg_instanceId!); - return; - }); - } - } - } -} diff --git a/packages/webview_flutter/webview_flutter_android/lib/src/android_webview_api_impls.dart b/packages/webview_flutter/webview_flutter_android/lib/src/android_webview_api_impls.dart deleted file mode 100644 index c6f3c29c1b83..000000000000 --- a/packages/webview_flutter/webview_flutter_android/lib/src/android_webview_api_impls.dart +++ /dev/null @@ -1,1594 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -import 'dart:ui'; - -import 'package:flutter/services.dart' show BinaryMessenger, Uint8List; - -import 'android_webview.dart'; -import 'android_webview.g.dart'; -import 'instance_manager.dart'; - -export 'android_webview.g.dart' - show ConsoleMessage, ConsoleMessageLevel, FileChooserMode; - -/// Converts [WebResourceRequestData] to [WebResourceRequest] -WebResourceRequest _toWebResourceRequest(WebResourceRequestData data) { - return WebResourceRequest( - url: data.url, - isForMainFrame: data.isForMainFrame, - isRedirect: data.isRedirect, - hasGesture: data.hasGesture, - method: data.method, - requestHeaders: data.requestHeaders.cast(), - ); -} - -/// Converts [WebResourceResponseData] to [WebResourceResponse] -WebResourceResponse _toWebResourceResponse(WebResourceResponseData data) { - return WebResourceResponse( - statusCode: data.statusCode, - ); -} - -/// Converts [WebResourceErrorData] to [WebResourceError]. -WebResourceError _toWebResourceError(WebResourceErrorData data) { - return WebResourceError( - errorCode: data.errorCode, - description: data.description, - ); -} - -/// Handles initialization of Flutter APIs for Android WebView. -class AndroidWebViewFlutterApis { - /// Creates a [AndroidWebViewFlutterApis]. - AndroidWebViewFlutterApis({ - JavaObjectFlutterApiImpl? javaObjectFlutterApi, - DownloadListenerFlutterApiImpl? downloadListenerFlutterApi, - WebViewClientFlutterApiImpl? webViewClientFlutterApi, - WebChromeClientFlutterApiImpl? webChromeClientFlutterApi, - JavaScriptChannelFlutterApiImpl? javaScriptChannelFlutterApi, - FileChooserParamsFlutterApiImpl? fileChooserParamsFlutterApi, - GeolocationPermissionsCallbackFlutterApiImpl? - geolocationPermissionsCallbackFlutterApi, - WebViewFlutterApiImpl? webViewFlutterApi, - PermissionRequestFlutterApiImpl? permissionRequestFlutterApi, - CustomViewCallbackFlutterApiImpl? customViewCallbackFlutterApi, - ViewFlutterApiImpl? viewFlutterApi, - HttpAuthHandlerFlutterApiImpl? httpAuthHandlerFlutterApi, - }) { - this.javaObjectFlutterApi = - javaObjectFlutterApi ?? JavaObjectFlutterApiImpl(); - this.downloadListenerFlutterApi = - downloadListenerFlutterApi ?? DownloadListenerFlutterApiImpl(); - this.webViewClientFlutterApi = - webViewClientFlutterApi ?? WebViewClientFlutterApiImpl(); - this.webChromeClientFlutterApi = - webChromeClientFlutterApi ?? WebChromeClientFlutterApiImpl(); - this.javaScriptChannelFlutterApi = - javaScriptChannelFlutterApi ?? JavaScriptChannelFlutterApiImpl(); - this.fileChooserParamsFlutterApi = - fileChooserParamsFlutterApi ?? FileChooserParamsFlutterApiImpl(); - this.geolocationPermissionsCallbackFlutterApi = - geolocationPermissionsCallbackFlutterApi ?? - GeolocationPermissionsCallbackFlutterApiImpl(); - this.webViewFlutterApi = webViewFlutterApi ?? WebViewFlutterApiImpl(); - this.permissionRequestFlutterApi = - permissionRequestFlutterApi ?? PermissionRequestFlutterApiImpl(); - this.customViewCallbackFlutterApi = - customViewCallbackFlutterApi ?? CustomViewCallbackFlutterApiImpl(); - this.viewFlutterApi = viewFlutterApi ?? ViewFlutterApiImpl(); - this.httpAuthHandlerFlutterApi = - httpAuthHandlerFlutterApi ?? HttpAuthHandlerFlutterApiImpl(); - } - - static bool _haveBeenSetUp = false; - - /// Mutable instance containing all Flutter Apis for Android WebView. - /// - /// This should only be changed for testing purposes. - static AndroidWebViewFlutterApis instance = AndroidWebViewFlutterApis(); - - /// Handles callbacks methods for the native Java Object class. - late final JavaObjectFlutterApi javaObjectFlutterApi; - - /// Flutter Api for [DownloadListener]. - late final DownloadListenerFlutterApiImpl downloadListenerFlutterApi; - - /// Flutter Api for [WebViewClient]. - late final WebViewClientFlutterApiImpl webViewClientFlutterApi; - - /// Flutter Api for [WebChromeClient]. - late final WebChromeClientFlutterApiImpl webChromeClientFlutterApi; - - /// Flutter Api for [JavaScriptChannel]. - late final JavaScriptChannelFlutterApiImpl javaScriptChannelFlutterApi; - - /// Flutter Api for [FileChooserParams]. - late final FileChooserParamsFlutterApiImpl fileChooserParamsFlutterApi; - - /// Flutter Api for [GeolocationPermissionsCallback]. - late final GeolocationPermissionsCallbackFlutterApiImpl - geolocationPermissionsCallbackFlutterApi; - - /// Flutter Api for [WebView]. - late final WebViewFlutterApiImpl webViewFlutterApi; - - /// Flutter Api for [PermissionRequest]. - late final PermissionRequestFlutterApiImpl permissionRequestFlutterApi; - - /// Flutter Api for [CustomViewCallback]. - late final CustomViewCallbackFlutterApiImpl customViewCallbackFlutterApi; - - /// Flutter Api for [View]. - late final ViewFlutterApiImpl viewFlutterApi; - - /// Flutter Api for [HttpAuthHandler]. - late final HttpAuthHandlerFlutterApiImpl httpAuthHandlerFlutterApi; - - /// Ensures all the Flutter APIs have been setup to receive calls from native code. - void ensureSetUp() { - if (!_haveBeenSetUp) { - JavaObjectFlutterApi.setup(javaObjectFlutterApi); - DownloadListenerFlutterApi.setup(downloadListenerFlutterApi); - WebViewClientFlutterApi.setup(webViewClientFlutterApi); - WebChromeClientFlutterApi.setup(webChromeClientFlutterApi); - JavaScriptChannelFlutterApi.setup(javaScriptChannelFlutterApi); - FileChooserParamsFlutterApi.setup(fileChooserParamsFlutterApi); - GeolocationPermissionsCallbackFlutterApi.setup( - geolocationPermissionsCallbackFlutterApi); - WebViewFlutterApi.setup(webViewFlutterApi); - PermissionRequestFlutterApi.setup(permissionRequestFlutterApi); - CustomViewCallbackFlutterApi.setup(customViewCallbackFlutterApi); - ViewFlutterApi.setup(viewFlutterApi); - HttpAuthHandlerFlutterApi.setup(httpAuthHandlerFlutterApi); - _haveBeenSetUp = true; - } - } -} - -/// Handles methods calls to the native Java Object class. -class JavaObjectHostApiImpl extends JavaObjectHostApi { - /// Constructs a [JavaObjectHostApiImpl]. - JavaObjectHostApiImpl({ - this.binaryMessenger, - InstanceManager? instanceManager, - }) : instanceManager = instanceManager ?? JavaObject.globalInstanceManager, - super(binaryMessenger: binaryMessenger); - - /// Receives binary data across the Flutter platform barrier. - /// - /// If it is null, the default BinaryMessenger will be used which routes to - /// the host platform. - final BinaryMessenger? binaryMessenger; - - /// Maintains instances stored to communicate with native language objects. - final InstanceManager instanceManager; -} - -/// Handles callbacks methods for the native Java Object class. -class JavaObjectFlutterApiImpl implements JavaObjectFlutterApi { - /// Constructs a [JavaObjectFlutterApiImpl]. - JavaObjectFlutterApiImpl({InstanceManager? instanceManager}) - : instanceManager = instanceManager ?? JavaObject.globalInstanceManager; - - /// Maintains instances stored to communicate with native language objects. - final InstanceManager instanceManager; - - @override - void dispose(int identifier) { - instanceManager.remove(identifier); - } -} - -/// Host api implementation for [WebView]. -class WebViewHostApiImpl extends WebViewHostApi { - /// Constructs a [WebViewHostApiImpl]. - WebViewHostApiImpl({ - super.binaryMessenger, - InstanceManager? instanceManager, - }) : instanceManager = instanceManager ?? JavaObject.globalInstanceManager; - - /// Maintains instances stored to communicate with java objects. - final InstanceManager instanceManager; - - /// Helper method to convert instances ids to objects. - Future createFromInstance(WebView instance) { - return create(instanceManager.addDartCreatedInstance(instance)); - } - - /// Helper method to convert the instances ids to objects. - Future loadDataFromInstance( - WebView instance, - String data, - String? mimeType, - String? encoding, - ) { - return loadData( - instanceManager.getIdentifier(instance)!, - data, - mimeType, - encoding, - ); - } - - /// Helper method to convert instances ids to objects. - Future loadDataWithBaseUrlFromInstance( - WebView instance, - String? baseUrl, - String data, - String? mimeType, - String? encoding, - String? historyUrl, - ) { - return loadDataWithBaseUrl( - instanceManager.getIdentifier(instance)!, - baseUrl, - data, - mimeType, - encoding, - historyUrl, - ); - } - - /// Helper method to convert instances ids to objects. - Future loadUrlFromInstance( - WebView instance, - String url, - Map headers, - ) { - return loadUrl(instanceManager.getIdentifier(instance)!, url, headers); - } - - /// Helper method to convert instances ids to objects. - Future postUrlFromInstance( - WebView instance, - String url, - Uint8List data, - ) { - return postUrl(instanceManager.getIdentifier(instance)!, url, data); - } - - /// Helper method to convert instances ids to objects. - Future getUrlFromInstance(WebView instance) { - return getUrl(instanceManager.getIdentifier(instance)!); - } - - /// Helper method to convert instances ids to objects. - Future canGoBackFromInstance(WebView instance) { - return canGoBack(instanceManager.getIdentifier(instance)!); - } - - /// Helper method to convert instances ids to objects. - Future canGoForwardFromInstance(WebView instance) { - return canGoForward(instanceManager.getIdentifier(instance)!); - } - - /// Helper method to convert instances ids to objects. - Future goBackFromInstance(WebView instance) { - return goBack(instanceManager.getIdentifier(instance)!); - } - - /// Helper method to convert instances ids to objects. - Future goForwardFromInstance(WebView instance) { - return goForward(instanceManager.getIdentifier(instance)!); - } - - /// Helper method to convert instances ids to objects. - Future reloadFromInstance(WebView instance) { - return reload(instanceManager.getIdentifier(instance)!); - } - - /// Helper method to convert instances ids to objects. - Future clearCacheFromInstance(WebView instance, bool includeDiskFiles) { - return clearCache( - instanceManager.getIdentifier(instance)!, - includeDiskFiles, - ); - } - - /// Helper method to convert instances ids to objects. - Future evaluateJavascriptFromInstance( - WebView instance, - String javascriptString, - ) { - return evaluateJavascript( - instanceManager.getIdentifier(instance)!, - javascriptString, - ); - } - - /// Helper method to convert instances ids to objects. - Future getTitleFromInstance(WebView instance) { - return getTitle(instanceManager.getIdentifier(instance)!); - } - - /// Helper method to convert instances ids to objects. - Future scrollToFromInstance(WebView instance, int x, int y) { - return scrollTo(instanceManager.getIdentifier(instance)!, x, y); - } - - /// Helper method to convert instances ids to objects. - Future scrollByFromInstance(WebView instance, int x, int y) { - return scrollBy(instanceManager.getIdentifier(instance)!, x, y); - } - - /// Helper method to convert instances ids to objects. - Future getScrollXFromInstance(WebView instance) { - return getScrollX(instanceManager.getIdentifier(instance)!); - } - - /// Helper method to convert instances ids to objects. - Future getScrollYFromInstance(WebView instance) { - return getScrollY(instanceManager.getIdentifier(instance)!); - } - - /// Helper method to convert instances ids to objects. - Future getScrollPositionFromInstance(WebView instance) async { - final WebViewPoint position = - await getScrollPosition(instanceManager.getIdentifier(instance)!); - return Offset(position.x.toDouble(), position.y.toDouble()); - } - - /// Helper method to convert instances ids to objects. - Future setWebViewClientFromInstance( - WebView instance, - WebViewClient webViewClient, - ) { - return setWebViewClient( - instanceManager.getIdentifier(instance)!, - instanceManager.getIdentifier(webViewClient)!, - ); - } - - /// Helper method to convert instances ids to objects. - Future addJavaScriptChannelFromInstance( - WebView instance, - JavaScriptChannel javaScriptChannel, - ) { - return addJavaScriptChannel( - instanceManager.getIdentifier(instance)!, - instanceManager.getIdentifier(javaScriptChannel)!, - ); - } - - /// Helper method to convert instances ids to objects. - Future removeJavaScriptChannelFromInstance( - WebView instance, - JavaScriptChannel javaScriptChannel, - ) { - return removeJavaScriptChannel( - instanceManager.getIdentifier(instance)!, - instanceManager.getIdentifier(javaScriptChannel)!, - ); - } - - /// Helper method to convert instances ids to objects. - Future setDownloadListenerFromInstance( - WebView instance, - DownloadListener? listener, - ) { - return setDownloadListener( - instanceManager.getIdentifier(instance)!, - listener != null ? instanceManager.getIdentifier(listener) : null, - ); - } - - /// Helper method to convert instances ids to objects. - Future setWebChromeClientFromInstance( - WebView instance, - WebChromeClient? client, - ) { - return setWebChromeClient( - instanceManager.getIdentifier(instance)!, - client != null ? instanceManager.getIdentifier(client) : null, - ); - } - - /// Helper method to convert instances ids to objects. - Future setBackgroundColorFromInstance(WebView instance, int color) { - return setBackgroundColor(instanceManager.getIdentifier(instance)!, color); - } -} - -/// Flutter API implementation for [WebView]. -/// -/// This class may handle instantiating and adding Dart instances that are -/// attached to a native instance or receiving callback methods from an -/// overridden native class. -class WebViewFlutterApiImpl implements WebViewFlutterApi { - /// Constructs a [WebViewFlutterApiImpl]. - WebViewFlutterApiImpl({ - this.binaryMessenger, - InstanceManager? instanceManager, - }) : instanceManager = instanceManager ?? JavaObject.globalInstanceManager; - - /// Receives binary data across the Flutter platform barrier. - /// - /// If it is null, the default BinaryMessenger will be used which routes to - /// the host platform. - final BinaryMessenger? binaryMessenger; - - /// Maintains instances stored to communicate with native language objects. - final InstanceManager instanceManager; - - @override - void create(int identifier) { - instanceManager.addHostCreatedInstance(WebView.detached(), identifier); - } - - @override - void onScrollChanged( - int webViewInstanceId, int left, int top, int oldLeft, int oldTop) { - final WebView? webViewInstance = instanceManager - .getInstanceWithWeakReference(webViewInstanceId) as WebView?; - assert( - webViewInstance != null, - 'InstanceManager does not contain a WebView with instanceId: $webViewInstanceId', - ); - webViewInstance!.onScrollChanged?.call(left, top, oldLeft, oldTop); - } -} - -/// Host api implementation for [WebSettings]. -class WebSettingsHostApiImpl extends WebSettingsHostApi { - /// Constructs a [WebSettingsHostApiImpl]. - WebSettingsHostApiImpl({ - super.binaryMessenger, - InstanceManager? instanceManager, - }) : instanceManager = instanceManager ?? JavaObject.globalInstanceManager; - - /// Maintains instances stored to communicate with java objects. - final InstanceManager instanceManager; - - /// Helper method to convert instances ids to objects. - Future createFromInstance(WebSettings instance, WebView webView) { - return create( - instanceManager.addDartCreatedInstance(instance), - instanceManager.getIdentifier(webView)!, - ); - } - - /// Helper method to convert instances ids to objects. - Future setDomStorageEnabledFromInstance( - WebSettings instance, - bool flag, - ) { - return setDomStorageEnabled(instanceManager.getIdentifier(instance)!, flag); - } - - /// Helper method to convert instances ids to objects. - Future setJavaScriptCanOpenWindowsAutomaticallyFromInstance( - WebSettings instance, - bool flag, - ) { - return setJavaScriptCanOpenWindowsAutomatically( - instanceManager.getIdentifier(instance)!, - flag, - ); - } - - /// Helper method to convert instances ids to objects. - Future setSupportMultipleWindowsFromInstance( - WebSettings instance, - bool support, - ) { - return setSupportMultipleWindows( - instanceManager.getIdentifier(instance)!, support); - } - - /// Helper method to convert instances ids to objects. - Future setJavaScriptEnabledFromInstance( - WebSettings instance, - bool flag, - ) { - return setJavaScriptEnabled( - instanceManager.getIdentifier(instance)!, - flag, - ); - } - - /// Helper method to convert instances ids to objects. - Future setUserAgentStringFromInstance( - WebSettings instance, - String? userAgentString, - ) { - return setUserAgentString( - instanceManager.getIdentifier(instance)!, - userAgentString, - ); - } - - /// Helper method to convert instances ids to objects. - Future setMediaPlaybackRequiresUserGestureFromInstance( - WebSettings instance, - bool require, - ) { - return setMediaPlaybackRequiresUserGesture( - instanceManager.getIdentifier(instance)!, - require, - ); - } - - /// Helper method to convert instances ids to objects. - Future setSupportZoomFromInstance( - WebSettings instance, - bool support, - ) { - return setSupportZoom(instanceManager.getIdentifier(instance)!, support); - } - - /// Helper method to convert instances ids to objects. - Future setSetTextZoomFromInstance( - WebSettings instance, - int textZoom, - ) { - return setTextZoom(instanceManager.getIdentifier(instance)!, textZoom); - } - - /// Helper method to convert instances ids to objects. - Future setLoadWithOverviewModeFromInstance( - WebSettings instance, - bool overview, - ) { - return setLoadWithOverviewMode( - instanceManager.getIdentifier(instance)!, - overview, - ); - } - - /// Helper method to convert instances ids to objects. - Future setUseWideViewPortFromInstance( - WebSettings instance, - bool use, - ) { - return setUseWideViewPort(instanceManager.getIdentifier(instance)!, use); - } - - /// Helper method to convert instances ids to objects. - Future setDisplayZoomControlsFromInstance( - WebSettings instance, - bool enabled, - ) { - return setDisplayZoomControls( - instanceManager.getIdentifier(instance)!, - enabled, - ); - } - - /// Helper method to convert instances ids to objects. - Future setBuiltInZoomControlsFromInstance( - WebSettings instance, - bool enabled, - ) { - return setBuiltInZoomControls( - instanceManager.getIdentifier(instance)!, - enabled, - ); - } - - /// Helper method to convert instances ids to objects. - Future setAllowFileAccessFromInstance( - WebSettings instance, - bool enabled, - ) { - return setAllowFileAccess( - instanceManager.getIdentifier(instance)!, - enabled, - ); - } - - /// Helper method to convert instances ids to objects. - Future getUserAgentStringFromInstance(WebSettings instance) { - return getUserAgentString(instanceManager.getIdentifier(instance)!); - } -} - -/// Host api implementation for [JavaScriptChannel]. -class JavaScriptChannelHostApiImpl extends JavaScriptChannelHostApi { - /// Constructs a [JavaScriptChannelHostApiImpl]. - JavaScriptChannelHostApiImpl({ - super.binaryMessenger, - InstanceManager? instanceManager, - }) : instanceManager = instanceManager ?? JavaObject.globalInstanceManager; - - /// Maintains instances stored to communicate with java objects. - final InstanceManager instanceManager; - - /// Helper method to convert instances ids to objects. - Future createFromInstance(JavaScriptChannel instance) async { - if (instanceManager.getIdentifier(instance) == null) { - final int identifier = instanceManager.addDartCreatedInstance(instance); - await create( - identifier, - instance.channelName, - ); - } - } -} - -/// Flutter api implementation for [JavaScriptChannel]. -class JavaScriptChannelFlutterApiImpl extends JavaScriptChannelFlutterApi { - /// Constructs a [JavaScriptChannelFlutterApiImpl]. - JavaScriptChannelFlutterApiImpl({InstanceManager? instanceManager}) - : instanceManager = instanceManager ?? JavaObject.globalInstanceManager; - - /// Maintains instances stored to communicate with java objects. - final InstanceManager instanceManager; - - @override - void postMessage(int instanceId, String message) { - final JavaScriptChannel? instance = instanceManager - .getInstanceWithWeakReference(instanceId) as JavaScriptChannel?; - assert( - instance != null, - 'InstanceManager does not contain a JavaScriptChannel with instanceId: $instanceId', - ); - instance!.postMessage(message); - } -} - -/// Host api implementation for [WebViewClient]. -class WebViewClientHostApiImpl extends WebViewClientHostApi { - /// Constructs a [WebViewClientHostApiImpl]. - WebViewClientHostApiImpl({ - super.binaryMessenger, - InstanceManager? instanceManager, - }) : instanceManager = instanceManager ?? JavaObject.globalInstanceManager; - - /// Maintains instances stored to communicate with java objects. - final InstanceManager instanceManager; - - /// Helper method to convert instances ids to objects. - Future createFromInstance(WebViewClient instance) async { - if (instanceManager.getIdentifier(instance) == null) { - final int identifier = instanceManager.addDartCreatedInstance(instance); - return create(identifier); - } - } - - /// Helper method to convert instances ids to objects. - Future setShouldOverrideUrlLoadingReturnValueFromInstance( - WebViewClient instance, - bool value, - ) { - return setSynchronousReturnValueForShouldOverrideUrlLoading( - instanceManager.getIdentifier(instance)!, - value, - ); - } -} - -/// Flutter api implementation for [WebViewClient]. -class WebViewClientFlutterApiImpl extends WebViewClientFlutterApi { - /// Constructs a [WebViewClientFlutterApiImpl]. - WebViewClientFlutterApiImpl({InstanceManager? instanceManager}) - : instanceManager = instanceManager ?? JavaObject.globalInstanceManager; - - /// Maintains instances stored to communicate with java objects. - final InstanceManager instanceManager; - - @override - void onPageFinished(int instanceId, int webViewInstanceId, String url) { - final WebViewClient? instance = instanceManager - .getInstanceWithWeakReference(instanceId) as WebViewClient?; - final WebView? webViewInstance = instanceManager - .getInstanceWithWeakReference(webViewInstanceId) as WebView?; - assert( - instance != null, - 'InstanceManager does not contain a WebViewClient with instanceId: $instanceId', - ); - assert( - webViewInstance != null, - 'InstanceManager does not contain a WebView with instanceId: $webViewInstanceId', - ); - if (instance!.onPageFinished != null) { - instance.onPageFinished!(webViewInstance!, url); - } - } - - @override - void onPageStarted(int instanceId, int webViewInstanceId, String url) { - final WebViewClient? instance = instanceManager - .getInstanceWithWeakReference(instanceId) as WebViewClient?; - final WebView? webViewInstance = instanceManager - .getInstanceWithWeakReference(webViewInstanceId) as WebView?; - assert( - instance != null, - 'InstanceManager does not contain a WebViewClient with instanceId: $instanceId', - ); - assert( - webViewInstance != null, - 'InstanceManager does not contain a WebView with instanceId: $webViewInstanceId', - ); - if (instance!.onPageStarted != null) { - instance.onPageStarted!(webViewInstance!, url); - } - } - - @override - void onReceivedHttpError( - int instanceId, - int webViewInstanceId, - WebResourceRequestData request, - WebResourceResponseData response, - ) { - final WebViewClient? instance = instanceManager - .getInstanceWithWeakReference(instanceId) as WebViewClient?; - final WebView? webViewInstance = instanceManager - .getInstanceWithWeakReference(webViewInstanceId) as WebView?; - assert( - instance != null, - 'InstanceManager does not contain an WebViewClient with instanceId: $instanceId', - ); - assert( - webViewInstance != null, - 'InstanceManager does not contain an WebView with instanceId: $webViewInstanceId', - ); - if (instance!.onReceivedHttpError != null) { - instance.onReceivedHttpError!( - webViewInstance!, - _toWebResourceRequest(request), - _toWebResourceResponse(response), - ); - } - } - - @override - void onReceivedError( - int instanceId, - int webViewInstanceId, - int errorCode, - String description, - String failingUrl, - ) { - final WebViewClient? instance = instanceManager - .getInstanceWithWeakReference(instanceId) as WebViewClient?; - final WebView? webViewInstance = instanceManager - .getInstanceWithWeakReference(webViewInstanceId) as WebView?; - assert( - instance != null, - 'InstanceManager does not contain a WebViewClient with instanceId: $instanceId', - ); - assert( - webViewInstance != null, - 'InstanceManager does not contain a WebView with instanceId: $webViewInstanceId', - ); - if (instance!.onReceivedError != null) { - instance.onReceivedError!( - webViewInstance!, - errorCode, - description, - failingUrl, - ); - } - } - - @override - void onReceivedRequestError( - int instanceId, - int webViewInstanceId, - WebResourceRequestData request, - WebResourceErrorData error, - ) { - final WebViewClient? instance = instanceManager - .getInstanceWithWeakReference(instanceId) as WebViewClient?; - final WebView? webViewInstance = instanceManager - .getInstanceWithWeakReference(webViewInstanceId) as WebView?; - assert( - instance != null, - 'InstanceManager does not contain a WebViewClient with instanceId: $instanceId', - ); - assert( - webViewInstance != null, - 'InstanceManager does not contain a WebView with instanceId: $webViewInstanceId', - ); - if (instance!.onReceivedRequestError != null) { - instance.onReceivedRequestError!( - webViewInstance!, - _toWebResourceRequest(request), - _toWebResourceError(error), - ); - } - } - - @override - void requestLoading( - int instanceId, - int webViewInstanceId, - WebResourceRequestData request, - ) { - final WebViewClient? instance = instanceManager - .getInstanceWithWeakReference(instanceId) as WebViewClient?; - final WebView? webViewInstance = instanceManager - .getInstanceWithWeakReference(webViewInstanceId) as WebView?; - assert( - instance != null, - 'InstanceManager does not contain a WebViewClient with instanceId: $instanceId', - ); - assert( - webViewInstance != null, - 'InstanceManager does not contain a WebView with instanceId: $webViewInstanceId', - ); - if (instance!.requestLoading != null) { - instance.requestLoading!( - webViewInstance!, - _toWebResourceRequest(request), - ); - } - } - - @override - void urlLoading( - int instanceId, - int webViewInstanceId, - String url, - ) { - final WebViewClient? instance = instanceManager - .getInstanceWithWeakReference(instanceId) as WebViewClient?; - final WebView? webViewInstance = instanceManager - .getInstanceWithWeakReference(webViewInstanceId) as WebView?; - assert( - instance != null, - 'InstanceManager does not contain a WebViewClient with instanceId: $instanceId', - ); - assert( - webViewInstance != null, - 'InstanceManager does not contain a WebView with instanceId: $webViewInstanceId', - ); - if (instance!.urlLoading != null) { - instance.urlLoading!(webViewInstance!, url); - } - } - - @override - void doUpdateVisitedHistory( - int instanceId, - int webViewInstanceId, - String url, - bool isReload, - ) { - final WebViewClient? instance = instanceManager - .getInstanceWithWeakReference(instanceId) as WebViewClient?; - final WebView? webViewInstance = instanceManager - .getInstanceWithWeakReference(webViewInstanceId) as WebView?; - assert( - instance != null, - 'InstanceManager does not contain a WebViewClient with instanceId: $instanceId', - ); - assert( - webViewInstance != null, - 'InstanceManager does not contain a WebView with instanceId: $webViewInstanceId', - ); - if (instance!.doUpdateVisitedHistory != null) { - instance.doUpdateVisitedHistory!(webViewInstance!, url, isReload); - } - } - - @override - void onReceivedHttpAuthRequest( - int instanceId, - int webViewInstanceId, - int httpAuthHandlerInstanceId, - String host, - String realm, - ) { - final WebViewClient? instance = instanceManager - .getInstanceWithWeakReference(instanceId) as WebViewClient?; - final WebView? webViewInstance = instanceManager - .getInstanceWithWeakReference(webViewInstanceId) as WebView?; - final HttpAuthHandler? httpAuthHandlerInstance = - instanceManager.getInstanceWithWeakReference(httpAuthHandlerInstanceId) - as HttpAuthHandler?; - assert( - instance != null, - 'InstanceManager does not contain a WebViewClient with instanceId: $instanceId', - ); - assert( - webViewInstance != null, - 'InstanceManager does not contain a WebView with instanceId: $webViewInstanceId', - ); - assert( - httpAuthHandlerInstance != null, - 'InstanceManager does not contain a HttpAuthHandler with instanceId: $httpAuthHandlerInstanceId', - ); - if (instance!.onReceivedHttpAuthRequest != null) { - return instance.onReceivedHttpAuthRequest!( - webViewInstance!, httpAuthHandlerInstance!, host, realm); - } - } -} - -/// Host api implementation for [DownloadListener]. -class DownloadListenerHostApiImpl extends DownloadListenerHostApi { - /// Constructs a [DownloadListenerHostApiImpl]. - DownloadListenerHostApiImpl({ - super.binaryMessenger, - InstanceManager? instanceManager, - }) : instanceManager = instanceManager ?? JavaObject.globalInstanceManager; - - /// Maintains instances stored to communicate with java objects. - final InstanceManager instanceManager; - - /// Helper method to convert instances ids to objects. - Future createFromInstance(DownloadListener instance) async { - if (instanceManager.getIdentifier(instance) == null) { - final int identifier = instanceManager.addDartCreatedInstance(instance); - return create(identifier); - } - } -} - -/// Flutter api implementation for [DownloadListener]. -class DownloadListenerFlutterApiImpl extends DownloadListenerFlutterApi { - /// Constructs a [DownloadListenerFlutterApiImpl]. - DownloadListenerFlutterApiImpl({InstanceManager? instanceManager}) - : instanceManager = instanceManager ?? JavaObject.globalInstanceManager; - - /// Maintains instances stored to communicate with java objects. - final InstanceManager instanceManager; - - @override - void onDownloadStart( - int instanceId, - String url, - String userAgent, - String contentDisposition, - String mimetype, - int contentLength, - ) { - final DownloadListener? instance = instanceManager - .getInstanceWithWeakReference(instanceId) as DownloadListener?; - assert( - instance != null, - 'InstanceManager does not contain a DownloadListener with instanceId: $instanceId', - ); - instance!.onDownloadStart( - url, - userAgent, - contentDisposition, - mimetype, - contentLength, - ); - } -} - -/// Host api implementation for [DownloadListener]. -class WebChromeClientHostApiImpl extends WebChromeClientHostApi { - /// Constructs a [WebChromeClientHostApiImpl]. - WebChromeClientHostApiImpl({ - super.binaryMessenger, - InstanceManager? instanceManager, - }) : instanceManager = instanceManager ?? JavaObject.globalInstanceManager; - - /// Maintains instances stored to communicate with java objects. - final InstanceManager instanceManager; - - /// Helper method to convert instances ids to objects. - Future createFromInstance(WebChromeClient instance) async { - if (instanceManager.getIdentifier(instance) == null) { - final int identifier = instanceManager.addDartCreatedInstance(instance); - return create(identifier); - } - } - - /// Helper method to convert instances ids to objects. - Future setSynchronousReturnValueForOnShowFileChooserFromInstance( - WebChromeClient instance, - bool value, - ) { - return setSynchronousReturnValueForOnShowFileChooser( - instanceManager.getIdentifier(instance)!, - value, - ); - } - - /// Helper method to convert instances ids to objects. - Future setSynchronousReturnValueForOnConsoleMessageFromInstance( - WebChromeClient instance, - bool value, - ) { - return setSynchronousReturnValueForOnConsoleMessage( - instanceManager.getIdentifier(instance)!, - value, - ); - } - - /// Helper method to convert instances ids to objects. - Future setSynchronousReturnValueForOnJsAlertFromInstance( - WebChromeClient instance, - bool value, - ) { - return setSynchronousReturnValueForOnJsAlert( - instanceManager.getIdentifier(instance)!, value); - } - - /// Helper method to convert instances ids to objects. - Future setSynchronousReturnValueForOnJsConfirmFromInstance( - WebChromeClient instance, - bool value, - ) { - return setSynchronousReturnValueForOnJsConfirm( - instanceManager.getIdentifier(instance)!, value); - } - - /// Helper method to convert instances ids to objects. - Future setSynchronousReturnValueForOnJsPromptFromInstance( - WebChromeClient instance, - bool value, - ) { - return setSynchronousReturnValueForOnJsPrompt( - instanceManager.getIdentifier(instance)!, value); - } -} - -/// Flutter api implementation for [DownloadListener]. -class WebChromeClientFlutterApiImpl extends WebChromeClientFlutterApi { - /// Constructs a [DownloadListenerFlutterApiImpl]. - WebChromeClientFlutterApiImpl({InstanceManager? instanceManager}) - : instanceManager = instanceManager ?? JavaObject.globalInstanceManager; - - /// Maintains instances stored to communicate with java objects. - final InstanceManager instanceManager; - - @override - void onProgressChanged(int instanceId, int webViewInstanceId, int progress) { - final WebChromeClient? instance = instanceManager - .getInstanceWithWeakReference(instanceId) as WebChromeClient?; - final WebView? webViewInstance = instanceManager - .getInstanceWithWeakReference(webViewInstanceId) as WebView?; - assert( - instance != null, - 'InstanceManager does not contain a WebChromeClient with instanceId: $instanceId', - ); - assert( - webViewInstance != null, - 'InstanceManager does not contain a WebView with instanceId: $webViewInstanceId', - ); - if (instance!.onProgressChanged != null) { - instance.onProgressChanged!(webViewInstance!, progress); - } - } - - @override - Future> onShowFileChooser( - int instanceId, - int webViewInstanceId, - int paramsInstanceId, - ) { - final WebChromeClient instance = - instanceManager.getInstanceWithWeakReference(instanceId)!; - if (instance.onShowFileChooser != null) { - return instance.onShowFileChooser!( - instanceManager.getInstanceWithWeakReference(webViewInstanceId)! - as WebView, - instanceManager.getInstanceWithWeakReference(paramsInstanceId)! - as FileChooserParams, - ); - } - - return Future>.value(const []); - } - - @override - void onGeolocationPermissionsShowPrompt( - int instanceId, int paramsInstanceId, String origin) { - final WebChromeClient instance = - instanceManager.getInstanceWithWeakReference(instanceId)!; - final GeolocationPermissionsCallback callback = - instanceManager.getInstanceWithWeakReference(paramsInstanceId)! - as GeolocationPermissionsCallback; - final GeolocationPermissionsShowPrompt? onShowPrompt = - instance.onGeolocationPermissionsShowPrompt; - if (onShowPrompt != null) { - onShowPrompt(origin, callback); - } - } - - @override - void onGeolocationPermissionsHidePrompt(int identifier) { - final WebChromeClient instance = - instanceManager.getInstanceWithWeakReference(identifier)!; - final GeolocationPermissionsHidePrompt? onHidePrompt = - instance.onGeolocationPermissionsHidePrompt; - if (onHidePrompt != null) { - return onHidePrompt(instance); - } - } - - @override - void onPermissionRequest( - int instanceId, - int requestInstanceId, - ) { - final WebChromeClient instance = - instanceManager.getInstanceWithWeakReference(instanceId)!; - if (instance.onPermissionRequest != null) { - instance.onPermissionRequest!( - instance, - instanceManager.getInstanceWithWeakReference(requestInstanceId)!, - ); - } else { - // The method requires calling grant or deny if the Java method is - // overridden, so this calls deny by default if `onPermissionRequest` is - // null. - final PermissionRequest request = - instanceManager.getInstanceWithWeakReference(requestInstanceId)!; - request.deny(); - } - } - - @override - void onShowCustomView( - int instanceId, - int viewIdentifier, - int callbackIdentifier, - ) { - final WebChromeClient instance = - instanceManager.getInstanceWithWeakReference(instanceId)!; - if (instance.onShowCustomView != null) { - return instance.onShowCustomView!( - instance, - instanceManager.getInstanceWithWeakReference(viewIdentifier)!, - instanceManager.getInstanceWithWeakReference(callbackIdentifier)!, - ); - } - } - - @override - void onHideCustomView(int instanceId) { - final WebChromeClient instance = - instanceManager.getInstanceWithWeakReference(instanceId)!; - if (instance.onHideCustomView != null) { - return instance.onHideCustomView!( - instance, - ); - } - } - - @override - void onConsoleMessage(int instanceId, ConsoleMessage message) { - final WebChromeClient instance = - instanceManager.getInstanceWithWeakReference(instanceId)!; - instance.onConsoleMessage?.call(instance, message); - } - - @override - Future onJsAlert(int instanceId, String url, String message) { - final WebChromeClient instance = - instanceManager.getInstanceWithWeakReference(instanceId)!; - - return instance.onJsAlert!(url, message); - } - - @override - Future onJsConfirm(int instanceId, String url, String message) { - final WebChromeClient instance = - instanceManager.getInstanceWithWeakReference(instanceId)!; - - return instance.onJsConfirm!(url, message); - } - - @override - Future onJsPrompt( - int instanceId, String url, String message, String defaultValue) { - final WebChromeClient instance = - instanceManager.getInstanceWithWeakReference(instanceId)!; - - return instance.onJsPrompt!(url, message, defaultValue); - } -} - -/// Host api implementation for [WebStorage]. -class WebStorageHostApiImpl extends WebStorageHostApi { - /// Constructs a [WebStorageHostApiImpl]. - WebStorageHostApiImpl({ - super.binaryMessenger, - InstanceManager? instanceManager, - }) : instanceManager = instanceManager ?? JavaObject.globalInstanceManager; - - /// Maintains instances stored to communicate with java objects. - final InstanceManager instanceManager; - - /// Helper method to convert instances ids to objects. - Future createFromInstance(WebStorage instance) async { - if (instanceManager.getIdentifier(instance) == null) { - final int identifier = instanceManager.addDartCreatedInstance(instance); - return create(identifier); - } - } - - /// Helper method to convert instances ids to objects. - Future deleteAllDataFromInstance(WebStorage instance) { - return deleteAllData(instanceManager.getIdentifier(instance)!); - } -} - -/// Flutter api implementation for [FileChooserParams]. -class FileChooserParamsFlutterApiImpl extends FileChooserParamsFlutterApi { - /// Constructs a [FileChooserParamsFlutterApiImpl]. - FileChooserParamsFlutterApiImpl({ - this.binaryMessenger, - InstanceManager? instanceManager, - }) : instanceManager = instanceManager ?? JavaObject.globalInstanceManager; - - /// Receives binary data across the Flutter platform barrier. - /// - /// If it is null, the default BinaryMessenger will be used which routes to - /// the host platform. - final BinaryMessenger? binaryMessenger; - - /// Maintains instances stored to communicate with java objects. - final InstanceManager instanceManager; - - @override - void create( - int instanceId, - bool isCaptureEnabled, - List acceptTypes, - FileChooserMode mode, - String? filenameHint, - ) { - instanceManager.addHostCreatedInstance( - FileChooserParams.detached( - isCaptureEnabled: isCaptureEnabled, - acceptTypes: acceptTypes.cast(), - mode: mode, - filenameHint: filenameHint, - binaryMessenger: binaryMessenger, - instanceManager: instanceManager, - ), - instanceId, - ); - } -} - -/// Host api implementation for [GeolocationPermissionsCallback]. -class GeolocationPermissionsCallbackHostApiImpl - extends GeolocationPermissionsCallbackHostApi { - /// Constructs a [GeolocationPermissionsCallbackHostApiImpl]. - GeolocationPermissionsCallbackHostApiImpl({ - this.binaryMessenger, - InstanceManager? instanceManager, - }) : instanceManager = instanceManager ?? JavaObject.globalInstanceManager, - super(binaryMessenger: binaryMessenger); - - /// Sends binary data across the Flutter platform barrier. - /// - /// If it is null, the default BinaryMessenger will be used which routes to - /// the host platform. - final BinaryMessenger? binaryMessenger; - - /// Maintains instances stored to communicate with java objects. - final InstanceManager instanceManager; - - /// Helper method to convert instances ids to objects. - Future invokeFromInstances( - GeolocationPermissionsCallback instance, - String origin, - bool allow, - bool retain, - ) { - return invoke( - instanceManager.getIdentifier(instance)!, - origin, - allow, - retain, - ); - } -} - -/// Flutter API implementation for [GeolocationPermissionsCallback]. -/// -/// This class may handle instantiating and adding Dart instances that are -/// attached to a native instance or receiving callback methods from an -/// overridden native class. -class GeolocationPermissionsCallbackFlutterApiImpl - implements GeolocationPermissionsCallbackFlutterApi { - /// Constructs a [GeolocationPermissionsCallbackFlutterApiImpl]. - GeolocationPermissionsCallbackFlutterApiImpl({ - this.binaryMessenger, - InstanceManager? instanceManager, - }) : instanceManager = instanceManager ?? JavaObject.globalInstanceManager; - - /// Receives binary data across the Flutter platform barrier. - /// - /// If it is null, the default BinaryMessenger will be used which routes to - /// the host platform. - final BinaryMessenger? binaryMessenger; - - /// Maintains instances stored to communicate with native language objects. - final InstanceManager instanceManager; - - @override - void create(int instanceId) { - instanceManager.addHostCreatedInstance( - GeolocationPermissionsCallback.detached( - binaryMessenger: binaryMessenger, - instanceManager: instanceManager, - ), - instanceId, - ); - } -} - -/// Host api implementation for [PermissionRequest]. -class PermissionRequestHostApiImpl extends PermissionRequestHostApi { - /// Constructs a [PermissionRequestHostApiImpl]. - PermissionRequestHostApiImpl({ - this.binaryMessenger, - InstanceManager? instanceManager, - }) : instanceManager = instanceManager ?? JavaObject.globalInstanceManager, - super(binaryMessenger: binaryMessenger); - - /// Sends binary data across the Flutter platform barrier. - /// - /// If it is null, the default BinaryMessenger will be used which routes to - /// the host platform. - final BinaryMessenger? binaryMessenger; - - /// Maintains instances stored to communicate with native language objects. - final InstanceManager instanceManager; - - /// Helper method to convert instance ids to objects. - Future grantFromInstances( - PermissionRequest instance, - List resources, - ) { - return grant(instanceManager.getIdentifier(instance)!, resources); - } - - /// Helper method to convert instance ids to objects. - Future denyFromInstances(PermissionRequest instance) { - return deny(instanceManager.getIdentifier(instance)!); - } -} - -/// Flutter API implementation for [PermissionRequest]. -/// -/// This class may handle instantiating and adding Dart instances that are -/// attached to a native instance or receiving callback methods from an -/// overridden native class. -class PermissionRequestFlutterApiImpl implements PermissionRequestFlutterApi { - /// Constructs a [PermissionRequestFlutterApiImpl]. - PermissionRequestFlutterApiImpl({ - this.binaryMessenger, - InstanceManager? instanceManager, - }) : instanceManager = instanceManager ?? JavaObject.globalInstanceManager; - - /// Receives binary data across the Flutter platform barrier. - /// - /// If it is null, the default BinaryMessenger will be used which routes to - /// the host platform. - final BinaryMessenger? binaryMessenger; - - /// Maintains instances stored to communicate with native language objects. - final InstanceManager instanceManager; - - @override - void create( - int identifier, - List resources, - ) { - instanceManager.addHostCreatedInstance( - PermissionRequest.detached( - resources: resources.cast(), - binaryMessenger: binaryMessenger, - instanceManager: instanceManager, - ), - identifier, - ); - } -} - -/// Host api implementation for [CustomViewCallback]. -class CustomViewCallbackHostApiImpl extends CustomViewCallbackHostApi { - /// Constructs a [CustomViewCallbackHostApiImpl]. - CustomViewCallbackHostApiImpl({ - this.binaryMessenger, - InstanceManager? instanceManager, - }) : instanceManager = instanceManager ?? JavaObject.globalInstanceManager, - super(binaryMessenger: binaryMessenger); - - /// Sends binary data across the Flutter platform barrier. - /// - /// If it is null, the default BinaryMessenger will be used which routes to - /// the host platform. - final BinaryMessenger? binaryMessenger; - - /// Maintains instances stored to communicate with native language objects. - final InstanceManager instanceManager; - - /// Helper method to convert instance ids to objects. - Future onCustomViewHiddenFromInstances(CustomViewCallback instance) { - return onCustomViewHidden(instanceManager.getIdentifier(instance)!); - } -} - -/// Flutter API implementation for [CustomViewCallback]. -/// -/// This class may handle instantiating and adding Dart instances that are -/// attached to a native instance or receiving callback methods from an -/// overridden native class. -class CustomViewCallbackFlutterApiImpl implements CustomViewCallbackFlutterApi { - /// Constructs a [CustomViewCallbackFlutterApiImpl]. - CustomViewCallbackFlutterApiImpl({ - this.binaryMessenger, - InstanceManager? instanceManager, - }) : instanceManager = instanceManager ?? JavaObject.globalInstanceManager; - - /// Receives binary data across the Flutter platform barrier. - /// - /// If it is null, the default BinaryMessenger will be used which routes to - /// the host platform. - final BinaryMessenger? binaryMessenger; - - /// Maintains instances stored to communicate with native language objects. - final InstanceManager instanceManager; - - @override - void create(int identifier) { - instanceManager.addHostCreatedInstance( - CustomViewCallback.detached( - binaryMessenger: binaryMessenger, - instanceManager: instanceManager, - ), - identifier, - ); - } -} - -/// Flutter API implementation for [View]. -/// -/// This class may handle instantiating and adding Dart instances that are -/// attached to a native instance or receiving callback methods from an -/// overridden native class. -class ViewFlutterApiImpl implements ViewFlutterApi { - /// Constructs a [ViewFlutterApiImpl]. - ViewFlutterApiImpl({ - this.binaryMessenger, - InstanceManager? instanceManager, - }) : instanceManager = instanceManager ?? JavaObject.globalInstanceManager; - - /// Receives binary data across the Flutter platform barrier. - /// - /// If it is null, the default BinaryMessenger will be used which routes to - /// the host platform. - final BinaryMessenger? binaryMessenger; - - /// Maintains instances stored to communicate with native language objects. - final InstanceManager instanceManager; - - @override - void create(int identifier) { - instanceManager.addHostCreatedInstance( - View.detached( - binaryMessenger: binaryMessenger, - instanceManager: instanceManager, - ), - identifier, - ); - } -} - -/// Host api implementation for [CookieManager]. -class CookieManagerHostApiImpl extends CookieManagerHostApi { - /// Constructs a [CookieManagerHostApiImpl]. - CookieManagerHostApiImpl({ - this.binaryMessenger, - InstanceManager? instanceManager, - }) : instanceManager = instanceManager ?? JavaObject.globalInstanceManager, - super(binaryMessenger: binaryMessenger); - - /// Sends binary data across the Flutter platform barrier. - /// - /// If it is null, the default BinaryMessenger will be used which routes to - /// the host platform. - final BinaryMessenger? binaryMessenger; - - /// Maintains instances stored to communicate with native language objects. - final InstanceManager instanceManager; - - /// Helper method to convert instance ids to objects. - CookieManager attachInstanceFromInstances(CookieManager instance) { - attachInstance(instanceManager.addDartCreatedInstance(instance)); - return instance; - } - - /// Helper method to convert instance ids to objects. - Future setCookieFromInstances( - CookieManager instance, - String url, - String value, - ) { - return setCookie( - instanceManager.getIdentifier(instance)!, - url, - value, - ); - } - - /// Helper method to convert instance ids to objects. - Future removeAllCookiesFromInstances(CookieManager instance) { - return removeAllCookies(instanceManager.getIdentifier(instance)!); - } - - /// Helper method to convert instance ids to objects. - Future setAcceptThirdPartyCookiesFromInstances( - CookieManager instance, - WebView webView, - bool accept, - ) { - return setAcceptThirdPartyCookies( - instanceManager.getIdentifier(instance)!, - instanceManager.getIdentifier(webView)!, - accept, - ); - } -} - -/// Host api implementation for [HttpAuthHandler]. -class HttpAuthHandlerHostApiImpl extends HttpAuthHandlerHostApi { - /// Constructs a [HttpAuthHandlerHostApiImpl]. - HttpAuthHandlerHostApiImpl({ - super.binaryMessenger, - InstanceManager? instanceManager, - }) : _instanceManager = instanceManager ?? JavaObject.globalInstanceManager; - - /// Maintains instances stored to communicate with native language objects. - final InstanceManager _instanceManager; - - /// Helper method to convert instance ids to objects. - Future cancelFromInstance(HttpAuthHandler instance) { - return cancel(_instanceManager.getIdentifier(instance)!); - } - - /// Helper method to convert instance ids to objects. - Future proceedFromInstance( - HttpAuthHandler instance, - String username, - String password, - ) { - return proceed( - _instanceManager.getIdentifier(instance)!, - username, - password, - ); - } - - /// Helper method to convert instance ids to objects. - Future useHttpAuthUsernamePasswordFromInstance( - HttpAuthHandler instance, - ) { - return useHttpAuthUsernamePassword( - _instanceManager.getIdentifier(instance)!, - ); - } -} - -/// Flutter API implementation for [HttpAuthHandler]. -class HttpAuthHandlerFlutterApiImpl extends HttpAuthHandlerFlutterApi { - /// Constructs a [HttpAuthHandlerFlutterApiImpl]. - HttpAuthHandlerFlutterApiImpl({ - this.binaryMessenger, - InstanceManager? instanceManager, - }) : instanceManager = instanceManager ?? JavaObject.globalInstanceManager; - - /// Receives binary data across the Flutter platform barrier. - /// - /// If it is null, the default BinaryMessenger will be used which routes to - /// the host platform. - final BinaryMessenger? binaryMessenger; - - /// Maintains instances stored to communicate with native language objects. - final InstanceManager instanceManager; - - @override - void create(int instanceId) { - instanceManager.addHostCreatedInstance( - HttpAuthHandler(), - instanceId, - ); - } -} diff --git a/packages/webview_flutter/webview_flutter_android/lib/src/android_webview_controller.dart b/packages/webview_flutter/webview_flutter_android/lib/src/android_webview_controller.dart index 3a410362af21..c250a87d36a9 100644 --- a/packages/webview_flutter/webview_flutter_android/lib/src/android_webview_controller.dart +++ b/packages/webview_flutter/webview_flutter_android/lib/src/android_webview_controller.dart @@ -12,9 +12,8 @@ import 'package:flutter/services.dart'; import 'package:webview_flutter_platform_interface/webview_flutter_platform_interface.dart'; import 'android_proxy.dart'; -import 'android_webview.dart' as android_webview; -import 'android_webview_api_impls.dart'; -import 'instance_manager.dart'; +import 'android_webkit.g.dart' as android_webview; +import 'android_webkit_constants.dart'; import 'platform_views_service_proxy.dart'; import 'weak_reference_utils.dart'; @@ -99,10 +98,10 @@ class AndroidWebViewController extends PlatformWebViewController { /// The native [android_webview.WebView] being controlled. late final android_webview.WebView _webView = - _androidWebViewParams.androidWebViewProxy.createAndroidWebView( + _androidWebViewParams.androidWebViewProxy.newWebView( onScrollChanged: withWeakReferenceTo(this, (WeakReference weakReference) { - return (int left, int top, int oldLeft, int oldTop) async { + return (_, int left, int top, int oldLeft, int oldTop) async { final void Function(ScrollPositionChange)? callback = weakReference.target?._onScrollPositionChangedCallback; callback?.call(ScrollPositionChange(left.toDouble(), top.toDouble())); @@ -110,10 +109,10 @@ class AndroidWebViewController extends PlatformWebViewController { })); late final android_webview.WebChromeClient _webChromeClient = - _androidWebViewParams.androidWebViewProxy.createAndroidWebChromeClient( + _androidWebViewParams.androidWebViewProxy.newWebChromeClient( onProgressChanged: withWeakReferenceTo(this, (WeakReference weakReference) { - return (android_webview.WebView webView, int progress) { + return (_, android_webview.WebView webView, int progress) { if (weakReference.target?._currentNavigationDelegate?._onProgress != null) { weakReference @@ -123,7 +122,7 @@ class AndroidWebViewController extends PlatformWebViewController { }), onGeolocationPermissionsShowPrompt: withWeakReferenceTo(this, (WeakReference weakReference) { - return (String origin, + return (_, String origin, android_webview.GeolocationPermissionsCallback callback) async { final OnGeolocationPermissionsShowPrompt? onShowPrompt = weakReference.target?._onGeolocationPermissionsShowPrompt; @@ -168,6 +167,8 @@ class AndroidWebViewController extends PlatformWebViewController { AndroidCustomViewWidget.private( controller: webViewController, customView: view, + // ignore: invalid_use_of_protected_member + instanceManager: view.pigeon_instanceManager, ), () => callback.onCustomViewHidden(), ); @@ -186,7 +187,7 @@ class AndroidWebViewController extends PlatformWebViewController { onShowFileChooser: withWeakReferenceTo( this, (WeakReference weakReference) { - return (android_webview.WebView webView, + return (_, android_webview.WebView webView, android_webview.FileChooserParams params) async { if (weakReference.target?._onShowFileSelectorCallback != null) { return weakReference.target!._onShowFileSelectorCallback!( @@ -209,15 +210,15 @@ class AndroidWebViewController extends PlatformWebViewController { switch (consoleMessage.level) { // Android maps `console.debug` to `MessageLevel.TIP`, it seems // `MessageLevel.DEBUG` if not being used. - case ConsoleMessageLevel.debug: - case ConsoleMessageLevel.tip: + case android_webview.ConsoleMessageLevel.debug: + case android_webview.ConsoleMessageLevel.tip: logLevel = JavaScriptLogLevel.debug; - case ConsoleMessageLevel.error: + case android_webview.ConsoleMessageLevel.error: logLevel = JavaScriptLogLevel.error; - case ConsoleMessageLevel.warning: + case android_webview.ConsoleMessageLevel.warning: logLevel = JavaScriptLogLevel.warning; - case ConsoleMessageLevel.unknown: - case ConsoleMessageLevel.log: + case android_webview.ConsoleMessageLevel.unknown: + case android_webview.ConsoleMessageLevel.log: logLevel = JavaScriptLogLevel.log; } @@ -238,25 +239,26 @@ class AndroidWebViewController extends PlatformWebViewController { if (callback == null) { return request.deny(); } else { - final Set types = request.resources - .map((String type) { - switch (type) { - case android_webview.PermissionRequest.videoCapture: - return WebViewPermissionResourceType.camera; - case android_webview.PermissionRequest.audioCapture: - return WebViewPermissionResourceType.microphone; - case android_webview.PermissionRequest.midiSysex: - return AndroidWebViewPermissionResourceType.midiSysex; - case android_webview.PermissionRequest.protectedMediaId: - return AndroidWebViewPermissionResourceType - .protectedMediaId; - } - - // Type not supported. - return null; - }) - .whereType() - .toSet(); + final Set types = + request.resources.nonNulls + .map((String type) { + switch (type) { + case PermissionRequestConstants.videoCapture: + return WebViewPermissionResourceType.camera; + case PermissionRequestConstants.audioCapture: + return WebViewPermissionResourceType.microphone; + case PermissionRequestConstants.midiSysex: + return AndroidWebViewPermissionResourceType.midiSysex; + case PermissionRequestConstants.protectedMediaId: + return AndroidWebViewPermissionResourceType + .protectedMediaId; + } + + // Type not supported. + return null; + }) + .whereType() + .toSet(); // If the request didn't contain any permissions recognized by the // implementation, deny by default. @@ -274,7 +276,7 @@ class AndroidWebViewController extends PlatformWebViewController { ), onJsAlert: withWeakReferenceTo(this, (WeakReference weakReference) { - return (String url, String message) async { + return (_, __, String url, String message) async { final Future Function(JavaScriptAlertDialogRequest)? callback = weakReference.target?._onJavaScriptAlert; if (callback != null) { @@ -288,7 +290,7 @@ class AndroidWebViewController extends PlatformWebViewController { }), onJsConfirm: withWeakReferenceTo(this, (WeakReference weakReference) { - return (String url, String message) async { + return (_, __, String url, String message) async { final Future Function(JavaScriptConfirmDialogRequest)? callback = weakReference.target?._onJavaScriptConfirm; if (callback != null) { @@ -302,7 +304,7 @@ class AndroidWebViewController extends PlatformWebViewController { }), onJsPrompt: withWeakReferenceTo(this, (WeakReference weakReference) { - return (String url, String message, String defaultValue) async { + return (_, __, String url, String message, String defaultValue) async { final Future Function(JavaScriptTextInputDialogRequest)? callback = weakReference.target?._onJavaScriptPrompt; if (callback != null) { @@ -319,7 +321,7 @@ class AndroidWebViewController extends PlatformWebViewController { /// The native [android_webview.FlutterAssetManager] allows managing assets. late final android_webview.FlutterAssetManager _flutterAssetManager = - _androidWebViewParams.androidWebViewProxy.createFlutterAssetManager(); + _androidWebViewParams.androidWebViewProxy.instanceFlutterAssetManager(); final Map _javaScriptChannelParams = {}; @@ -359,18 +361,18 @@ class AndroidWebViewController extends PlatformWebViewController { @visibleForTesting AndroidWebViewProxy webViewProxy = const AndroidWebViewProxy(), }) { - return webViewProxy.setWebContentsDebuggingEnabled(enabled); + return webViewProxy.setWebContentsDebuggingEnabledWebView(enabled); } - /// Identifier used to retrieve the underlying native `WKWebView`. + /// Identifier used to retrieve the underlying native `WebView`. /// /// This is typically used by other plugins to retrieve the native `WebView` /// from an `InstanceManager`. /// /// See Java method `WebViewFlutterPlugin.getWebView`. int get webViewIdentifier => - // ignore: invalid_use_of_visible_for_testing_member - android_webview.WebView.api.instanceManager.getIdentifier(_webView)!; + // ignore: invalid_use_of_protected_member + _webView.pigeon_instanceManager.getIdentifier(_webView)!; @override Future loadFile( @@ -414,9 +416,11 @@ class AndroidWebViewController extends PlatformWebViewController { String? baseUrl, }) { return _webView.loadDataWithBaseUrl( - baseUrl: baseUrl, - data: html, - mimeType: 'text/html', + baseUrl, + html, + 'text/html', + null, + null, ); } @@ -515,8 +519,7 @@ class AndroidWebViewController extends PlatformWebViewController { // When JavaScript channel with the same name exists make sure to remove it // before registering the new channel. if (_javaScriptChannelParams.containsKey(androidJavaScriptParams.name)) { - _webView - .removeJavaScriptChannel(androidJavaScriptParams._javaScriptChannel); + _webView.removeJavaScriptChannel(androidJavaScriptParams.name); } _javaScriptChannelParams[androidJavaScriptParams.name] = @@ -535,8 +538,7 @@ class AndroidWebViewController extends PlatformWebViewController { } _javaScriptChannelParams.remove(javaScriptChannelName); - return _webView - .removeJavaScriptChannel(javaScriptChannelParams._javaScriptChannel); + return _webView.removeJavaScriptChannel(javaScriptChannelParams.name); } @override @@ -549,8 +551,10 @@ class AndroidWebViewController extends PlatformWebViewController { Future scrollBy(int x, int y) => _webView.scrollBy(x, y); @override - Future getScrollPosition() { - return _webView.getScrollPosition(); + Future getScrollPosition() async { + final android_webview.WebViewPoint point = + await _webView.getScrollPosition(); + return Offset(point.x.toDouble(), point.y.toDouble()); } @override @@ -559,7 +563,7 @@ class AndroidWebViewController extends PlatformWebViewController { @override Future setBackgroundColor(Color color) => - _webView.setBackgroundColor(color); + _webView.setBackgroundColor(color.value); @override Future setJavaScriptMode(JavaScriptMode javaScriptMode) => @@ -725,13 +729,13 @@ class AndroidWebViewPermissionRequest extends PlatformWebViewPermissionRequest { .grant(types.map((WebViewPermissionResourceType type) { switch (type) { case WebViewPermissionResourceType.camera: - return android_webview.PermissionRequest.videoCapture; + return PermissionRequestConstants.videoCapture; case WebViewPermissionResourceType.microphone: - return android_webview.PermissionRequest.audioCapture; + return PermissionRequestConstants.audioCapture; case AndroidWebViewPermissionResourceType.midiSysex: - return android_webview.PermissionRequest.midiSysex; + return PermissionRequestConstants.midiSysex; case AndroidWebViewPermissionResourceType.protectedMediaId: - return android_webview.PermissionRequest.protectedMediaId; + return PermissionRequestConstants.protectedMediaId; } throw UnsupportedError( @@ -828,11 +832,15 @@ class FileSelectorParams { mode = FileSelectorMode.openMultiple; case android_webview.FileChooserMode.save: mode = FileSelectorMode.save; + case android_webview.FileChooserMode.unknown: + throw UnsupportedError( + 'FileSelectorParams could not be instantiated because it received an unsupported mode.', + ); } return FileSelectorParams( isCaptureEnabled: params.isCaptureEnabled, - acceptTypes: params.acceptTypes, + acceptTypes: params.acceptTypes.nonNulls.toList(), mode: mode, filenameHint: params.filenameHint, ); @@ -863,14 +871,12 @@ class AndroidJavaScriptChannelParams extends JavaScriptChannelParams { @visibleForTesting AndroidWebViewProxy webViewProxy = const AndroidWebViewProxy(), }) : assert(name.isNotEmpty), - _javaScriptChannel = webViewProxy.createJavaScriptChannel( - name, + _javaScriptChannel = webViewProxy.newJavaScriptChannel( + channelName: name, postMessage: withWeakReferenceTo( onMessageReceived, (WeakReference weakReference) { - return ( - String message, - ) { + return (_, String message) { if (weakReference.target != null) { weakReference.target!( JavaScriptMessage(message: message), @@ -911,18 +917,18 @@ class AndroidWebViewWidgetCreationParams super.layoutDirection, super.gestureRecognizers, this.displayWithHybridComposition = false, - @visibleForTesting InstanceManager? instanceManager, + @visibleForTesting android_webview.PigeonInstanceManager? instanceManager, @visibleForTesting this.platformViewsServiceProxy = const PlatformViewsServiceProxy(), }) : instanceManager = - instanceManager ?? android_webview.JavaObject.globalInstanceManager; + instanceManager ?? android_webview.PigeonInstanceManager.instance; /// Constructs a [WebKitWebViewWidgetCreationParams] using a /// [PlatformWebViewWidgetCreationParams]. AndroidWebViewWidgetCreationParams.fromPlatformWebViewWidgetCreationParams( PlatformWebViewWidgetCreationParams params, { bool displayWithHybridComposition = false, - @visibleForTesting InstanceManager? instanceManager, + @visibleForTesting android_webview.PigeonInstanceManager? instanceManager, @visibleForTesting PlatformViewsServiceProxy platformViewsServiceProxy = const PlatformViewsServiceProxy(), }) : this( @@ -941,7 +947,7 @@ class AndroidWebViewWidgetCreationParams /// This field is exposed for testing purposes only and should not be used /// outside of tests. @visibleForTesting - final InstanceManager instanceManager; + final android_webview.PigeonInstanceManager instanceManager; /// Proxy that provides access to the platform views service. /// @@ -1079,11 +1085,11 @@ class AndroidCustomViewWidget extends StatelessWidget { super.key, required this.controller, required this.customView, - @visibleForTesting InstanceManager? instanceManager, + @visibleForTesting android_webview.PigeonInstanceManager? instanceManager, @visibleForTesting this.platformViewsServiceProxy = const PlatformViewsServiceProxy(), }) : instanceManager = - instanceManager ?? android_webview.JavaObject.globalInstanceManager; + instanceManager ?? android_webview.PigeonInstanceManager.instance; /// The reference to the Android native view that should be shown. final android_webview.View customView; @@ -1098,7 +1104,7 @@ class AndroidCustomViewWidget extends StatelessWidget { /// This field is exposed for testing purposes only and should not be used /// outside of tests. @visibleForTesting - final InstanceManager instanceManager; + final android_webview.PigeonInstanceManager instanceManager; /// Proxy that provides access to the platform views service. /// @@ -1141,17 +1147,17 @@ AndroidViewController _initAndroidView( required bool displayWithHybridComposition, required PlatformViewsServiceProxy platformViewsServiceProxy, required android_webview.View view, - required InstanceManager instanceManager, + required android_webview.PigeonInstanceManager instanceManager, TextDirection layoutDirection = TextDirection.ltr, }) { - final int? instanceId = instanceManager.getIdentifier(view); + final int identifier = instanceManager.getIdentifier(view)!; if (displayWithHybridComposition) { return platformViewsServiceProxy.initExpensiveAndroidView( id: params.id, viewType: 'plugins.flutter.io/webview', layoutDirection: layoutDirection, - creationParams: instanceId, + creationParams: identifier, creationParamsCodec: const StandardMessageCodec(), ); } else { @@ -1159,7 +1165,7 @@ AndroidViewController _initAndroidView( id: params.id, viewType: 'plugins.flutter.io/webview', layoutDirection: layoutDirection, - creationParams: instanceId, + creationParams: identifier, creationParamsCodec: const StandardMessageCodec(), ); } @@ -1189,37 +1195,37 @@ class AndroidWebResourceError extends WebResourceError { static WebResourceErrorType? _errorCodeToErrorType(int errorCode) { switch (errorCode) { - case android_webview.WebViewClient.errorAuthentication: + case WebViewClientConstants.errorAuthentication: return WebResourceErrorType.authentication; - case android_webview.WebViewClient.errorBadUrl: + case WebViewClientConstants.errorBadUrl: return WebResourceErrorType.badUrl; - case android_webview.WebViewClient.errorConnect: + case WebViewClientConstants.errorConnect: return WebResourceErrorType.connect; - case android_webview.WebViewClient.errorFailedSslHandshake: + case WebViewClientConstants.errorFailedSslHandshake: return WebResourceErrorType.failedSslHandshake; - case android_webview.WebViewClient.errorFile: + case WebViewClientConstants.errorFile: return WebResourceErrorType.file; - case android_webview.WebViewClient.errorFileNotFound: + case WebViewClientConstants.errorFileNotFound: return WebResourceErrorType.fileNotFound; - case android_webview.WebViewClient.errorHostLookup: + case WebViewClientConstants.errorHostLookup: return WebResourceErrorType.hostLookup; - case android_webview.WebViewClient.errorIO: + case WebViewClientConstants.errorIO: return WebResourceErrorType.io; - case android_webview.WebViewClient.errorProxyAuthentication: + case WebViewClientConstants.errorProxyAuthentication: return WebResourceErrorType.proxyAuthentication; - case android_webview.WebViewClient.errorRedirectLoop: + case WebViewClientConstants.errorRedirectLoop: return WebResourceErrorType.redirectLoop; - case android_webview.WebViewClient.errorTimeout: + case WebViewClientConstants.errorTimeout: return WebResourceErrorType.timeout; - case android_webview.WebViewClient.errorTooManyRequests: + case WebViewClientConstants.errorTooManyRequests: return WebResourceErrorType.tooManyRequests; - case android_webview.WebViewClient.errorUnknown: + case WebViewClientConstants.errorUnknown: return WebResourceErrorType.unknown; - case android_webview.WebViewClient.errorUnsafeResource: + case WebViewClientConstants.errorUnsafeResource: return WebResourceErrorType.unsafeResource; - case android_webview.WebViewClient.errorUnsupportedAuthScheme: + case WebViewClientConstants.errorUnsupportedAuthScheme: return WebResourceErrorType.unsupportedAuthScheme; - case android_webview.WebViewClient.errorUnsupportedScheme: + case WebViewClientConstants.errorUnsupportedScheme: return WebResourceErrorType.unsupportedScheme; } @@ -1284,20 +1290,21 @@ class AndroidNavigationDelegate extends PlatformNavigationDelegate { _webViewClient = (this.params as AndroidNavigationDelegateCreationParams) .androidWebViewProxy - .createAndroidWebViewClient( - onPageFinished: (android_webview.WebView webView, String url) { + .newWebViewClient( + onPageFinished: (_, android_webview.WebView webView, String url) { final PageEventCallback? callback = weakThis.target?._onPageFinished; if (callback != null) { callback(url); } }, - onPageStarted: (android_webview.WebView webView, String url) { + onPageStarted: (_, android_webview.WebView webView, String url) { final PageEventCallback? callback = weakThis.target?._onPageStarted; if (callback != null) { callback(url); } }, onReceivedHttpError: ( + _, android_webview.WebView webView, android_webview.WebResourceRequest request, android_webview.WebResourceResponse response, @@ -1317,6 +1324,7 @@ class AndroidNavigationDelegate extends PlatformNavigationDelegate { } }, onReceivedRequestError: ( + _, android_webview.WebView webView, android_webview.WebResourceRequest request, android_webview.WebResourceError error, @@ -1332,7 +1340,25 @@ class AndroidNavigationDelegate extends PlatformNavigationDelegate { )); } }, + onReceivedRequestErrorCompat: ( + _, + android_webview.WebView webView, + android_webview.WebResourceRequest request, + android_webview.WebResourceErrorCompat error, + ) { + final WebResourceErrorCallback? callback = + weakThis.target?._onWebResourceError; + if (callback != null) { + callback(AndroidWebResourceError._( + errorCode: error.errorCode, + description: error.description, + url: request.url, + isForMainFrame: request.isForMainFrame, + )); + } + }, onReceivedError: ( + _, android_webview.WebView webView, int errorCode, String description, @@ -1350,19 +1376,26 @@ class AndroidNavigationDelegate extends PlatformNavigationDelegate { } }, requestLoading: ( + _, android_webview.WebView webView, android_webview.WebResourceRequest request, ) { weakThis.target?._handleNavigation( request.url, - headers: request.requestHeaders, + headers: request.requestHeaders?.map( + (String? key, String? value) { + return MapEntry(key!, value!); + }, + ) ?? + {}, isForMainFrame: request.isForMainFrame, ); }, - urlLoading: (android_webview.WebView webView, String url) { + urlLoading: (_, android_webview.WebView webView, String url) { weakThis.target?._handleNavigation(url, isForMainFrame: true); }, doUpdateVisitedHistory: ( + _, android_webview.WebView webView, String url, bool isReload, @@ -1373,6 +1406,7 @@ class AndroidNavigationDelegate extends PlatformNavigationDelegate { } }, onReceivedHttpAuthRequest: ( + _, android_webview.WebView webView, android_webview.HttpAuthHandler httpAuthHandler, String host, @@ -1401,8 +1435,9 @@ class AndroidNavigationDelegate extends PlatformNavigationDelegate { _downloadListener = (this.params as AndroidNavigationDelegateCreationParams) .androidWebViewProxy - .createDownloadListener( + .newDownloadListener( onDownloadStart: ( + _, String url, String userAgent, String contentDisposition, @@ -1420,7 +1455,7 @@ class AndroidNavigationDelegate extends PlatformNavigationDelegate { params as AndroidNavigationDelegateCreationParams; late final android_webview.WebChromeClient _webChromeClient = - _androidParams.androidWebViewProxy.createAndroidWebChromeClient(); + _androidParams.androidWebViewProxy.newWebChromeClient(); /// Gets the native [android_webview.WebChromeClient] that is bridged by this [AndroidNavigationDelegate]. /// diff --git a/packages/webview_flutter/webview_flutter_android/lib/src/android_webview_cookie_manager.dart b/packages/webview_flutter/webview_flutter_android/lib/src/android_webview_cookie_manager.dart index 0c1be7c178e6..ae199327a856 100644 --- a/packages/webview_flutter/webview_flutter_android/lib/src/android_webview_cookie_manager.dart +++ b/packages/webview_flutter/webview_flutter_android/lib/src/android_webview_cookie_manager.dart @@ -5,7 +5,7 @@ import 'package:flutter/foundation.dart'; import 'package:webview_flutter_platform_interface/webview_flutter_platform_interface.dart'; -import 'android_webview.dart'; +import 'android_webkit.g.dart'; import 'android_webview_controller.dart'; /// Object specifying creation parameters for creating a [AndroidWebViewCookieManager]. @@ -82,8 +82,8 @@ class AndroidWebViewCookieManager extends PlatformWebViewCookieManager { AndroidWebViewController controller, bool accept, ) { - // ignore: invalid_use_of_visible_for_testing_member - final WebView webView = WebView.api.instanceManager + // ignore: invalid_use_of_protected_member + final WebView webView = _cookieManager.pigeon_instanceManager .getInstanceWithWeakReference(controller.webViewIdentifier)!; return _cookieManager.setAcceptThirdPartyCookies(webView, accept); } diff --git a/packages/webview_flutter/webview_flutter_android/lib/src/instance_manager.dart b/packages/webview_flutter/webview_flutter_android/lib/src/instance_manager.dart deleted file mode 100644 index cdba6738582f..000000000000 --- a/packages/webview_flutter/webview_flutter_android/lib/src/instance_manager.dart +++ /dev/null @@ -1,197 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -import 'package:flutter/foundation.dart'; - -/// An immutable object that can provide functional copies of itself. -/// -/// All implementers are expected to be immutable as defined by the annotation. -@immutable -mixin Copyable { - /// Instantiates and returns a functionally identical object to oneself. - /// - /// Outside of tests, this method should only ever be called by - /// [InstanceManager]. - /// - /// Subclasses should always override their parent's implementation of this - /// method. - @protected - Copyable copy(); -} - -/// Maintains instances used to communicate with the native objects they -/// represent. -/// -/// Added instances are stored as weak references and their copies are stored -/// as strong references to maintain access to their variables and callback -/// methods. Both are stored with the same identifier. -/// -/// When a weak referenced instance becomes inaccessible, -/// [onWeakReferenceRemoved] is called with its associated identifier. -/// -/// If an instance is retrieved and has the possibility to be used, -/// (e.g. calling [getInstanceWithWeakReference]) a copy of the strong reference -/// is added as a weak reference with the same identifier. This prevents a -/// scenario where the weak referenced instance was released and then later -/// returned by the host platform. -class InstanceManager { - /// Constructs an [InstanceManager]. - InstanceManager({required void Function(int) onWeakReferenceRemoved}) { - this.onWeakReferenceRemoved = (int identifier) { - _weakInstances.remove(identifier); - onWeakReferenceRemoved(identifier); - }; - _finalizer = Finalizer(this.onWeakReferenceRemoved); - } - - // Identifiers are locked to a specific range to avoid collisions with objects - // created simultaneously by the host platform. - // Host uses identifiers >= 2^16 and Dart is expected to use values n where, - // 0 <= n < 2^16. - static const int _maxDartCreatedIdentifier = 65536; - - // Expando is used because it doesn't prevent its keys from becoming - // inaccessible. This allows the manager to efficiently retrieve an identifier - // of an instance without holding a strong reference to that instance. - // - // It also doesn't use `==` to search for identifiers, which would lead to an - // infinite loop when comparing an object to its copy. (i.e. which was caused - // by calling instanceManager.getIdentifier() inside of `==` while this was a - // HashMap). - final Expando _identifiers = Expando(); - final Map> _weakInstances = - >{}; - final Map _strongInstances = {}; - late final Finalizer _finalizer; - int _nextIdentifier = 0; - - /// Called when a weak referenced instance is removed by [removeWeakReference] - /// or becomes inaccessible. - late final void Function(int) onWeakReferenceRemoved; - - /// Adds a new instance that was instantiated by Dart. - /// - /// In other words, Dart wants to add a new instance that will represent - /// an object that will be instantiated on the host platform. - /// - /// Throws assertion error if the instance has already been added. - /// - /// Returns the randomly generated id of the [instance] added. - int addDartCreatedInstance(Copyable instance) { - final int identifier = _nextUniqueIdentifier(); - _addInstanceWithIdentifier(instance, identifier); - return identifier; - } - - /// Removes the instance, if present, and call [onWeakReferenceRemoved] with - /// its identifier. - /// - /// Returns the identifier associated with the removed instance. Otherwise, - /// `null` if the instance was not found in this manager. - /// - /// This does not remove the strong referenced instance associated with - /// [instance]. This can be done with [remove]. - int? removeWeakReference(Copyable instance) { - final int? identifier = getIdentifier(instance); - if (identifier == null) { - return null; - } - - _identifiers[instance] = null; - _finalizer.detach(instance); - onWeakReferenceRemoved(identifier); - - return identifier; - } - - /// Removes [identifier] and its associated strongly referenced instance, if - /// present, from the manager. - /// - /// Returns the strong referenced instance associated with [identifier] before - /// it was removed. Returns `null` if [identifier] was not associated with - /// any strong reference. - /// - /// This does not remove the weak referenced instance associated with - /// [identifier]. This can be done with [removeWeakReference]. - T? remove(int identifier) { - return _strongInstances.remove(identifier) as T?; - } - - /// Retrieves the instance associated with identifier. - /// - /// The value returned is chosen from the following order: - /// - /// 1. A weakly referenced instance associated with identifier. - /// 2. If the only instance associated with identifier is a strongly - /// referenced instance, a copy of the instance is added as a weak reference - /// with the same identifier. Returning the newly created copy. - /// 3. If no instance is associated with identifier, returns null. - /// - /// This method also expects the host `InstanceManager` to have a strong - /// reference to the instance the identifier is associated with. - T? getInstanceWithWeakReference(int identifier) { - final Copyable? weakInstance = _weakInstances[identifier]?.target; - - if (weakInstance == null) { - final Copyable? strongInstance = _strongInstances[identifier]; - if (strongInstance != null) { - final Copyable copy = strongInstance.copy(); - _identifiers[copy] = identifier; - _weakInstances[identifier] = WeakReference(copy); - _finalizer.attach(copy, identifier, detach: copy); - return copy as T; - } - return strongInstance as T?; - } - - return weakInstance as T; - } - - /// Retrieves the identifier associated with instance. - int? getIdentifier(Copyable instance) { - return _identifiers[instance]; - } - - /// Adds a new instance that was instantiated by the host platform. - /// - /// In other words, the host platform wants to add a new instance that - /// represents an object on the host platform. Stored with [identifier]. - /// - /// Throws assertion error if the instance or its identifier has already been - /// added. - /// - /// Returns unique identifier of the [instance] added. - void addHostCreatedInstance(Copyable instance, int identifier) { - _addInstanceWithIdentifier(instance, identifier); - } - - void _addInstanceWithIdentifier(Copyable instance, int identifier) { - assert(!containsIdentifier(identifier)); - assert(getIdentifier(instance) == null); - assert(identifier >= 0); - - _identifiers[instance] = identifier; - _weakInstances[identifier] = WeakReference(instance); - _finalizer.attach(instance, identifier, detach: instance); - - final Copyable copy = instance.copy(); - _identifiers[copy] = identifier; - _strongInstances[identifier] = copy; - } - - /// Whether this manager contains the given [identifier]. - bool containsIdentifier(int identifier) { - return _weakInstances.containsKey(identifier) || - _strongInstances.containsKey(identifier); - } - - int _nextUniqueIdentifier() { - late int identifier; - do { - identifier = _nextIdentifier; - _nextIdentifier = (_nextIdentifier + 1) % _maxDartCreatedIdentifier; - } while (containsIdentifier(identifier)); - return identifier; - } -} diff --git a/packages/webview_flutter/webview_flutter_android/lib/src/legacy/webview_android.dart b/packages/webview_flutter/webview_flutter_android/lib/src/legacy/webview_android.dart index 5ad2eefa4dbf..cbfeadad5aab 100644 --- a/packages/webview_flutter/webview_flutter_android/lib/src/legacy/webview_android.dart +++ b/packages/webview_flutter/webview_flutter_android/lib/src/legacy/webview_android.dart @@ -11,8 +11,7 @@ import 'package:flutter/widgets.dart'; // ignore: implementation_imports import 'package:webview_flutter_platform_interface/src/webview_flutter_platform_interface_legacy.dart'; -import '../android_webview.dart'; -import '../instance_manager.dart'; +import '../android_webkit.g.dart'; import 'webview_android_widget.dart'; /// Builds an Android webview. @@ -22,13 +21,13 @@ import 'webview_android_widget.dart'; /// communicate with the platform code. class AndroidWebView implements WebViewPlatform { /// Constructs an [AndroidWebView]. - AndroidWebView({@visibleForTesting InstanceManager? instanceManager}) - : instanceManager = instanceManager ?? JavaObject.globalInstanceManager; + AndroidWebView({@visibleForTesting PigeonInstanceManager? instanceManager}) + : instanceManager = instanceManager ?? PigeonInstanceManager.instance; /// Maintains instances used to communicate with the native objects they /// represent. @protected - final InstanceManager instanceManager; + final PigeonInstanceManager instanceManager; @override Widget build({ diff --git a/packages/webview_flutter/webview_flutter_android/lib/src/legacy/webview_android_cookie_manager.dart b/packages/webview_flutter/webview_flutter_android/lib/src/legacy/webview_android_cookie_manager.dart index a24f625d8787..a65605c87a3c 100644 --- a/packages/webview_flutter/webview_flutter_android/lib/src/legacy/webview_android_cookie_manager.dart +++ b/packages/webview_flutter/webview_flutter_android/lib/src/legacy/webview_android_cookie_manager.dart @@ -6,7 +6,7 @@ import 'package:flutter/foundation.dart'; // ignore: implementation_imports import 'package:webview_flutter_platform_interface/src/webview_flutter_platform_interface_legacy.dart'; -import '../android_webview.dart' as android_webview; +import '../android_webkit.g.dart' as android_webview; /// Handles all cookie operations for the current platform. class WebViewAndroidCookieManager extends WebViewCookieManagerPlatform { diff --git a/packages/webview_flutter/webview_flutter_android/lib/src/legacy/webview_android_widget.dart b/packages/webview_flutter/webview_flutter_android/lib/src/legacy/webview_android_widget.dart index ef9545427ef1..e17e50ec6dfa 100644 --- a/packages/webview_flutter/webview_flutter_android/lib/src/legacy/webview_android_widget.dart +++ b/packages/webview_flutter/webview_flutter_android/lib/src/legacy/webview_android_widget.dart @@ -9,24 +9,25 @@ import 'package:flutter/widgets.dart'; // ignore: implementation_imports import 'package:webview_flutter_platform_interface/src/webview_flutter_platform_interface_legacy.dart'; -import '../android_webview.dart' as android_webview; +import '../android_webkit.g.dart' as android_webview; +import '../android_webkit_constants.dart'; import '../weak_reference_utils.dart'; import 'webview_android_cookie_manager.dart'; /// Creates a [Widget] with a [android_webview.WebView]. class WebViewAndroidWidget extends StatefulWidget { /// Constructs a [WebViewAndroidWidget]. - const WebViewAndroidWidget({ + WebViewAndroidWidget({ super.key, required this.creationParams, required this.callbacksHandler, required this.javascriptChannelRegistry, required this.onBuildWidget, @visibleForTesting this.webViewProxy = const WebViewProxy(), - @visibleForTesting - this.flutterAssetManager = const android_webview.FlutterAssetManager(), + @visibleForTesting android_webview.FlutterAssetManager? flutterAssetManager, @visibleForTesting this.webStorage, - }); + }) : flutterAssetManager = + flutterAssetManager ?? android_webview.FlutterAssetManager.instance; /// Initial parameters used to setup the WebView. final CreationParams creationParams; @@ -88,10 +89,11 @@ class WebViewAndroidPlatformController extends WebViewPlatformController { required this.callbacksHandler, required this.javascriptChannelRegistry, @visibleForTesting this.webViewProxy = const WebViewProxy(), - @visibleForTesting - this.flutterAssetManager = const android_webview.FlutterAssetManager(), + @visibleForTesting android_webview.FlutterAssetManager? flutterAssetManager, @visibleForTesting android_webview.WebStorage? webStorage, }) : webStorage = webStorage ?? android_webview.WebStorage.instance, + flutterAssetManager = + flutterAssetManager ?? android_webview.FlutterAssetManager.instance, assert(creationParams.webSettings?.hasNavigationDelegate != null), super(callbacksHandler) { webView = webViewProxy.createWebView(); @@ -123,14 +125,14 @@ class WebViewAndroidPlatformController extends WebViewPlatformController { onPageStarted: withWeakReferenceTo(this, ( WeakReference weakReference, ) { - return (_, String url) { + return (_, __, String url) { weakReference.target?.callbacksHandler.onPageStarted(url); }; }), onPageFinished: withWeakReferenceTo(this, ( WeakReference weakReference, ) { - return (_, String url) { + return (_, __, String url) { weakReference.target?.callbacksHandler.onPageFinished(url); }; }), @@ -139,6 +141,7 @@ class WebViewAndroidPlatformController extends WebViewPlatformController { ) { return ( _, + __, int errorCode, String description, String failingUrl, @@ -157,6 +160,7 @@ class WebViewAndroidPlatformController extends WebViewPlatformController { ) { return ( _, + __, android_webview.WebResourceRequest request, android_webview.WebResourceError error, ) { @@ -174,7 +178,7 @@ class WebViewAndroidPlatformController extends WebViewPlatformController { urlLoading: withWeakReferenceTo(this, ( WeakReference weakReference, ) { - return (_, String url) { + return (_, __, String url) { weakReference.target?._handleNavigationRequest( url: url, isForMainFrame: true, @@ -184,7 +188,7 @@ class WebViewAndroidPlatformController extends WebViewPlatformController { requestLoading: withWeakReferenceTo(this, ( WeakReference weakReference, ) { - return (_, android_webview.WebResourceRequest request) { + return (_, __, android_webview.WebResourceRequest request) { weakReference.target?._handleNavigationRequest( url: request.url, isForMainFrame: request.isForMainFrame, @@ -223,6 +227,7 @@ class WebViewAndroidPlatformController extends WebViewPlatformController { this, (WeakReference weakReference) { return ( + _, String url, String userAgent, String contentDisposition, @@ -245,7 +250,7 @@ class WebViewAndroidPlatformController extends WebViewPlatformController { onProgressChanged: withWeakReferenceTo( this, (WeakReference weakReference) { - return (_, int progress) { + return (_, __, int progress) { final WebViewAndroidPlatformController? controller = weakReference.target; if (controller != null && controller._hasProgressTracking) { @@ -264,11 +269,7 @@ class WebViewAndroidPlatformController extends WebViewPlatformController { @override Future loadHtmlString(String html, {String? baseUrl}) { - return webView.loadDataWithBaseUrl( - baseUrl: baseUrl, - data: html, - mimeType: 'text/html', - ); + return webView.loadDataWithBaseUrl(baseUrl, html, 'text/html', null, null); } @override @@ -404,7 +405,9 @@ class WebViewAndroidPlatformController extends WebViewPlatformController { (String channelName) { final WebViewAndroidJavaScriptChannel javaScriptChannel = WebViewAndroidJavaScriptChannel( - channelName, javascriptChannelRegistry); + channelName: channelName, + javascriptChannelRegistry: javascriptChannelRegistry, + ); _javaScriptChannels[channelName] = javaScriptChannel; return webView.addJavaScriptChannel(javaScriptChannel); }, @@ -423,10 +426,8 @@ class WebViewAndroidPlatformController extends WebViewPlatformController { }, ).map>( (String channelName) { - final WebViewAndroidJavaScriptChannel javaScriptChannel = - _javaScriptChannels[channelName]!; _javaScriptChannels.remove(channelName); - return webView.removeJavaScriptChannel(javaScriptChannel); + return webView.removeJavaScriptChannel(channelName); }, ), ); @@ -442,10 +443,10 @@ class WebViewAndroidPlatformController extends WebViewPlatformController { Future scrollBy(int x, int y) => webView.scrollBy(x, y); @override - Future getScrollX() => webView.getScrollX(); + Future getScrollX() async => (await webView.getScrollPosition()).x; @override - Future getScrollY() => webView.getScrollY(); + Future getScrollY() async => (await webView.getScrollPosition()).y; void _setCreationParams(CreationParams creationParams) { final WebSettings? webSettings = creationParams.webSettings; @@ -465,7 +466,7 @@ class WebViewAndroidPlatformController extends WebViewPlatformController { final Color? backgroundColor = creationParams.backgroundColor; if (backgroundColor != null) { - webView.setBackgroundColor(backgroundColor); + webView.setBackgroundColor(backgroundColor.value); } addJavascriptChannels(creationParams.javascriptChannelNames); @@ -514,37 +515,37 @@ class WebViewAndroidPlatformController extends WebViewPlatformController { static WebResourceErrorType _errorCodeToErrorType(int errorCode) { switch (errorCode) { - case android_webview.WebViewClient.errorAuthentication: + case WebViewClientConstants.errorAuthentication: return WebResourceErrorType.authentication; - case android_webview.WebViewClient.errorBadUrl: + case WebViewClientConstants.errorBadUrl: return WebResourceErrorType.badUrl; - case android_webview.WebViewClient.errorConnect: + case WebViewClientConstants.errorConnect: return WebResourceErrorType.connect; - case android_webview.WebViewClient.errorFailedSslHandshake: + case WebViewClientConstants.errorFailedSslHandshake: return WebResourceErrorType.failedSslHandshake; - case android_webview.WebViewClient.errorFile: + case WebViewClientConstants.errorFile: return WebResourceErrorType.file; - case android_webview.WebViewClient.errorFileNotFound: + case WebViewClientConstants.errorFileNotFound: return WebResourceErrorType.fileNotFound; - case android_webview.WebViewClient.errorHostLookup: + case WebViewClientConstants.errorHostLookup: return WebResourceErrorType.hostLookup; - case android_webview.WebViewClient.errorIO: + case WebViewClientConstants.errorIO: return WebResourceErrorType.io; - case android_webview.WebViewClient.errorProxyAuthentication: + case WebViewClientConstants.errorProxyAuthentication: return WebResourceErrorType.proxyAuthentication; - case android_webview.WebViewClient.errorRedirectLoop: + case WebViewClientConstants.errorRedirectLoop: return WebResourceErrorType.redirectLoop; - case android_webview.WebViewClient.errorTimeout: + case WebViewClientConstants.errorTimeout: return WebResourceErrorType.timeout; - case android_webview.WebViewClient.errorTooManyRequests: + case WebViewClientConstants.errorTooManyRequests: return WebResourceErrorType.tooManyRequests; - case android_webview.WebViewClient.errorUnknown: + case WebViewClientConstants.errorUnknown: return WebResourceErrorType.unknown; - case android_webview.WebViewClient.errorUnsafeResource: + case WebViewClientConstants.errorUnsafeResource: return WebResourceErrorType.unsafeResource; - case android_webview.WebViewClient.errorUnsupportedAuthScheme: + case WebViewClientConstants.errorUnsupportedAuthScheme: return WebResourceErrorType.unsupportedAuthScheme; - case android_webview.WebViewClient.errorUnsupportedScheme: + case WebViewClientConstants.errorUnsupportedScheme: return WebResourceErrorType.unsupportedScheme; } @@ -582,14 +583,14 @@ class WebViewAndroidPlatformController extends WebViewPlatformController { class WebViewAndroidJavaScriptChannel extends android_webview.JavaScriptChannel { /// Creates a [WebViewAndroidJavaScriptChannel]. - WebViewAndroidJavaScriptChannel( - super.channelName, - this.javascriptChannelRegistry, - ) : super( + WebViewAndroidJavaScriptChannel({ + required super.channelName, + required this.javascriptChannelRegistry, + }) : super( postMessage: withWeakReferenceTo( javascriptChannelRegistry, (WeakReference weakReference) { - return (String message) { + return (_, String message) { weakReference.target?.onJavascriptChannelMessage( channelName, message, @@ -618,23 +619,39 @@ class WebViewProxy { /// Constructs a [android_webview.WebViewClient]. android_webview.WebViewClient createWebViewClient({ - void Function(android_webview.WebView webView, String url)? onPageStarted, - void Function(android_webview.WebView webView, String url)? onPageFinished, void Function( + android_webview.WebViewClient, + android_webview.WebView webView, + String url, + )? onPageStarted, + void Function( + android_webview.WebViewClient, + android_webview.WebView webView, + String url, + )? onPageFinished, + void Function( + android_webview.WebViewClient, android_webview.WebView webView, android_webview.WebResourceRequest request, android_webview.WebResourceError error, )? onReceivedRequestError, void Function( + android_webview.WebViewClient, android_webview.WebView webView, int errorCode, String description, String failingUrl, )? onReceivedError, - void Function(android_webview.WebView webView, - android_webview.WebResourceRequest request)? - requestLoading, - void Function(android_webview.WebView webView, String url)? urlLoading, + void Function( + android_webview.WebViewClient, + android_webview.WebView webView, + android_webview.WebResourceRequest request, + )? requestLoading, + void Function( + android_webview.WebViewClient, + android_webview.WebView webView, + String url, + )? urlLoading, }) { return android_webview.WebViewClient( onPageStarted: onPageStarted, diff --git a/packages/webview_flutter/webview_flutter_android/lib/src/legacy/webview_surface_android.dart b/packages/webview_flutter/webview_flutter_android/lib/src/legacy/webview_surface_android.dart index 37434673cc54..7a0ac4c382cc 100644 --- a/packages/webview_flutter/webview_flutter_android/lib/src/legacy/webview_surface_android.dart +++ b/packages/webview_flutter/webview_flutter_android/lib/src/legacy/webview_surface_android.dart @@ -10,7 +10,7 @@ import 'package:flutter/widgets.dart'; // ignore: implementation_imports import 'package:webview_flutter_platform_interface/src/webview_flutter_platform_interface_legacy.dart'; -import '../android_webview.dart'; +import '../android_webkit.g.dart'; import 'webview_android.dart'; import 'webview_android_widget.dart'; diff --git a/packages/webview_flutter/webview_flutter_android/pigeons/android_webkit.dart b/packages/webview_flutter/webview_flutter_android/pigeons/android_webkit.dart new file mode 100644 index 000000000000..22435d5b97d2 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_android/pigeons/android_webkit.dart @@ -0,0 +1,796 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:pigeon/pigeon.dart'; + +@ConfigurePigeon( + PigeonOptions( + copyrightHeader: 'pigeons/copyright.txt', + dartOut: 'lib/src/android_webkit.g.dart', + kotlinOut: + 'android/src/main/java/io/flutter/plugins/webviewflutter/AndroidWebkitLibrary.g.kt', + kotlinOptions: KotlinOptions( + package: 'io.flutter.plugins.webviewflutter', + errorClassName: 'AndroidWebKitError', + ), + ), +) + +/// Mode of how to select files for a file chooser. +/// +/// See https://developer.android.com/reference/android/webkit/WebChromeClient.FileChooserParams. +enum FileChooserMode { + /// Open single file and requires that the file exists before allowing the + /// user to pick it. + /// + /// See https://developer.android.com/reference/android/webkit/WebChromeClient.FileChooserParams#MODE_OPEN. + open, + + /// Similar to [open] but allows multiple files to be selected. + /// + /// See https://developer.android.com/reference/android/webkit/WebChromeClient.FileChooserParams#MODE_OPEN_MULTIPLE. + openMultiple, + + /// Allows picking a nonexistent file and saving it. + /// + /// See https://developer.android.com/reference/android/webkit/WebChromeClient.FileChooserParams#MODE_SAVE. + save, + + /// Indicates a `FileChooserMode` with an unknown mode. + /// + /// This does not represent an actual value provided by the platform and only + /// indicates a value was provided that isn't currently supported. + unknown, +} + +/// Indicates the type of message logged to the console. +/// +/// See https://developer.android.com/reference/android/webkit/ConsoleMessage.MessageLevel. +enum ConsoleMessageLevel { + /// Indicates a message is logged for debugging. + /// + /// See https://developer.android.com/reference/android/webkit/ConsoleMessage.MessageLevel#DEBUG. + debug, + + /// Indicates a message is provided as an error. + /// + /// See https://developer.android.com/reference/android/webkit/ConsoleMessage.MessageLevel#ERROR. + error, + + /// Indicates a message is provided as a basic log message. + /// + /// See https://developer.android.com/reference/android/webkit/ConsoleMessage.MessageLevel#LOG. + log, + + /// Indicates a message is provided as a tip. + /// + /// See https://developer.android.com/reference/android/webkit/ConsoleMessage.MessageLevel#TIP. + tip, + + /// Indicates a message is provided as a warning. + /// + /// See https://developer.android.com/reference/android/webkit/ConsoleMessage.MessageLevel#WARNING. + warning, + + /// Indicates a message with an unknown level. + /// + /// This does not represent an actual value provided by the platform and only + /// indicates a value was provided that isn't currently supported. + unknown, +} + +/// Encompasses parameters to the `WebViewClient.shouldInterceptRequest` method. +/// +/// See https://developer.android.com/reference/android/webkit/WebResourceRequest. +@ProxyApi( + kotlinOptions: KotlinProxyApiOptions( + fullClassName: 'android.webkit.WebResourceRequest', + ), +) +abstract class WebResourceRequest { + /// The URL for which the resource request was made. + late String url; + + /// Whether the request was made in order to fetch the main frame's document. + late bool isForMainFrame; + + /// Whether the request was a result of a server-side redirect. + late bool? isRedirect; + + /// Whether a gesture (such as a click) was associated with the request. + late bool hasGesture; + + /// The method associated with the request, for example "GET". + late String method; + + /// The headers associated with the request. + late Map? requestHeaders; +} + +/// Encapsulates a resource response. +/// +/// See https://developer.android.com/reference/android/webkit/WebResourceResponse. +@ProxyApi( + kotlinOptions: KotlinProxyApiOptions( + fullClassName: 'android.webkit.WebResourceResponse', + ), +) +abstract class WebResourceResponse { + /// The resource response's status code. + late int statusCode; +} + +/// Encapsulates information about errors that occurred during loading of web +/// resources. +/// +/// See https://developer.android.com/reference/android/webkit/WebResourceError. +@ProxyApi( + kotlinOptions: KotlinProxyApiOptions( + fullClassName: 'android.webkit.WebResourceError', + minAndroidApi: 23, + ), +) +abstract class WebResourceError { + /// The error code of the error. + late int errorCode; + + /// The string describing the error. + late String description; +} + +/// Encapsulates information about errors that occurred during loading of web +/// resources. +/// +/// See https://developer.android.com/reference/androidx/webkit/WebResourceErrorCompat. +@ProxyApi( + kotlinOptions: KotlinProxyApiOptions( + fullClassName: 'androidx.webkit.WebResourceErrorCompat', + ), +) +abstract class WebResourceErrorCompat { + /// The error code of the error. + late int errorCode; + + /// The string describing the error. + late String description; +} + +/// Represents a position on a web page. +/// +/// This is a custom class created for convenience of the wrapper. +@ProxyApi() +abstract class WebViewPoint { + late int x; + late int y; +} + +/// Represents a JavaScript console message from WebCore. +/// +/// See https://developer.android.com/reference/android/webkit/ConsoleMessage +@ProxyApi( + kotlinOptions: KotlinProxyApiOptions( + fullClassName: 'android.webkit.ConsoleMessage', + ), +) +abstract class ConsoleMessage { + late int lineNumber; + late String message; + late ConsoleMessageLevel level; + late String sourceId; +} + +/// Manages the cookies used by an application's `WebView` instances. +/// +/// See https://developer.android.com/reference/android/webkit/CookieManager. +@ProxyApi( + kotlinOptions: KotlinProxyApiOptions( + fullClassName: 'android.webkit.CookieManager', + ), +) +abstract class CookieManager { + @static + late CookieManager instance; + + /// Sets a single cookie (key-value pair) for the given URL. + void setCookie(String url, String value); + + /// Removes all cookies. + @async + bool removeAllCookies(); + + /// Sets whether the `WebView` should allow third party cookies to be set. + void setAcceptThirdPartyCookies(WebView webView, bool accept); +} + +/// A View that displays web pages. +/// +/// See https://developer.android.com/reference/android/webkit/WebView. +@ProxyApi( + kotlinOptions: KotlinProxyApiOptions( + fullClassName: 'android.webkit.WebView', + ), +) +abstract class WebView extends View { + WebView(); + + /// This is called in response to an internal scroll in this view (i.e., the + /// view scrolled its own contents). + late void Function( + int left, + int top, + int oldLeft, + int oldTop, + )? onScrollChanged; + + /// The WebSettings object used to control the settings for this WebView. + @attached + late WebSettings settings; + + /// Loads the given data into this WebView using a 'data' scheme URL. + void loadData(String data, String? mimeType, String? encoding); + + /// Loads the given data into this WebView, using baseUrl as the base URL for + /// the content. + void loadDataWithBaseUrl( + String? baseUrl, + String data, + String? mimeType, + String? encoding, + String? historyUrl, + ); + + /// Loads the given URL. + void loadUrl(String url, Map headers); + + /// Loads the URL with postData using "POST" method into this WebView. + void postUrl(String url, Uint8List data); + + /// Gets the URL for the current page. + String? getUrl(); + + /// Gets whether this WebView has a back history item. + bool canGoBack(); + + /// Gets whether this WebView has a forward history item. + bool canGoForward(); + + /// Goes back in the history of this WebView. + void goBack(); + + /// Goes forward in the history of this WebView. + void goForward(); + + /// Reloads the current URL. + void reload(); + + /// Clears the resource cache. + void clearCache(bool includeDiskFiles); + + /// Asynchronously evaluates JavaScript in the context of the currently + /// displayed page. + @async + String? evaluateJavascript(String javascriptString); + + /// Gets the title for the current page. + String? getTitle(); + + /// Enables debugging of web contents (HTML / CSS / JavaScript) loaded into + /// any WebViews of this application. + @static + void setWebContentsDebuggingEnabled(bool enabled); + + /// Sets the WebViewClient that will receive various notifications and + /// requests. + void setWebViewClient(WebViewClient? client); + + /// Injects the supplied Java object into this WebView. + void addJavaScriptChannel(JavaScriptChannel channel); + + /// Removes a previously injected Java object from this WebView. + void removeJavaScriptChannel(String name); + + /// Registers the interface to be used when content can not be handled by the + /// rendering engine, and should be downloaded instead. + void setDownloadListener(DownloadListener? listener); + + /// Sets the chrome handler. + void setWebChromeClient(WebChromeClient? client); + + /// Sets the background color for this view. + void setBackgroundColor(int color); + + /// Destroys the internal state of this WebView. + void destroy(); +} + +/// Manages settings state for a `WebView`. +/// +/// See https://developer.android.com/reference/android/webkit/WebSettings. +@ProxyApi( + kotlinOptions: KotlinProxyApiOptions( + fullClassName: 'android.webkit.WebSettings', + ), +) +abstract class WebSettings { + /// Sets whether the DOM storage API is enabled. + void setDomStorageEnabled(bool flag); + + /// Tells JavaScript to open windows automatically. + void setJavaScriptCanOpenWindowsAutomatically(bool flag); + + /// Sets whether the WebView whether supports multiple windows. + void setSupportMultipleWindows(bool support); + + /// Tells the WebView to enable JavaScript execution. + void setJavaScriptEnabled(bool flag); + + /// Sets the WebView's user-agent string. + void setUserAgentString(String? userAgentString); + + /// Sets whether the WebView requires a user gesture to play media. + void setMediaPlaybackRequiresUserGesture(bool require); + + /// Sets whether the WebView should support zooming using its on-screen zoom + /// controls and gestures. + void setSupportZoom(bool support); + + /// Sets whether the WebView loads pages in overview mode, that is, zooms out + /// the content to fit on screen by width. + void setLoadWithOverviewMode(bool overview); + + /// Sets whether the WebView should enable support for the "viewport" HTML + /// meta tag or should use a wide viewport. + void setUseWideViewPort(bool use); + + /// Sets whether the WebView should display on-screen zoom controls when using + /// the built-in zoom mechanisms. + void setDisplayZoomControls(bool enabled); + + /// Sets whether the WebView should display on-screen zoom controls when using + /// the built-in zoom mechanisms. + void setBuiltInZoomControls(bool enabled); + + /// Enables or disables file access within WebView. + void setAllowFileAccess(bool enabled); + + /// Sets the text zoom of the page in percent. + void setTextZoom(int textZoom); + + /// Gets the WebView's user-agent string. + String getUserAgentString(); +} + +/// A JavaScript interface for exposing Javascript callbacks to Dart. +/// +/// This is a custom class for the wrapper that is annotated with +/// [JavascriptInterface](https://developer.android.com/reference/android/webkit/JavascriptInterface). +@ProxyApi() +abstract class JavaScriptChannel { + // ignore: avoid_unused_constructor_parameters + JavaScriptChannel(); + + late final String channelName; + + /// Handles callbacks messages from JavaScript. + late void Function(String message) postMessage; +} + +/// Receives various notifications and requests from a `WebView`. +/// +/// See https://developer.android.com/reference/android/webkit/WebViewClient. +@ProxyApi( + kotlinOptions: KotlinProxyApiOptions( + fullClassName: 'android.webkit.WebViewClient', + ), +) +abstract class WebViewClient { + WebViewClient(); + + /// Notify the host application that a page has started loading. + late void Function(WebView webView, String url)? onPageStarted; + + /// Notify the host application that a page has finished loading. + late void Function(WebView webView, String url)? onPageFinished; + + /// Notify the host application that an HTTP error has been received from the + /// server while loading a resource. + late void Function( + WebView webView, + WebResourceRequest request, + WebResourceResponse response, + )? onReceivedHttpError; + + /// Report web resource loading error to the host application. + late void Function( + WebView webView, + WebResourceRequest request, + WebResourceError error, + )? onReceivedRequestError; + + /// Report web resource loading error to the host application. + late void Function( + WebView webView, + WebResourceRequest request, + WebResourceErrorCompat error, + )? onReceivedRequestErrorCompat; + + /// Report an error to the host application. + late void Function( + WebView webView, + int errorCode, + String description, + String failingUrl, + )? onReceivedError; + + /// Give the host application a chance to take control when a URL is about to + /// be loaded in the current WebView. + late void Function( + WebView webView, + WebResourceRequest request, + )? requestLoading; + + /// Give the host application a chance to take control when a URL is about to + /// be loaded in the current WebView. + late void Function(WebView webView, String url)? urlLoading; + + /// Notify the host application to update its visited links database. + late void Function( + WebView webView, + String url, + bool isReload, + )? doUpdateVisitedHistory; + + /// Notifies the host application that the WebView received an HTTP + /// authentication request. + late void Function( + WebView webView, + HttpAuthHandler handler, + String host, + String realm, + )? onReceivedHttpAuthRequest; + + /// Sets the required synchronous return value for the Java method, + /// `WebViewClient.shouldOverrideUrlLoading(...)`. + /// + /// The Java method, `WebViewClient.shouldOverrideUrlLoading(...)`, requires + /// a boolean to be returned and this method sets the returned value for all + /// calls to the Java method. + /// + /// Setting this to true causes the current [WebView] to abort loading any URL + /// received by [requestLoading] or [urlLoading], while setting this to false + /// causes the [WebView] to continue loading a URL as usual. + /// + /// Defaults to false. + void setSynchronousReturnValueForShouldOverrideUrlLoading(bool value); +} + +/// Handles notifications that a file should be downloaded. +/// +/// See https://developer.android.com/reference/android/webkit/DownloadListener. +@ProxyApi( + kotlinOptions: KotlinProxyApiOptions( + fullClassName: 'android.webkit.DownloadListener', + ), +) +abstract class DownloadListener { + DownloadListener(); + + /// Notify the host application that a file should be downloaded. + late void Function( + String url, + String userAgent, + String contentDisposition, + String mimetype, + int contentLength, + ) onDownloadStart; +} + +/// Handles notification of JavaScript dialogs, favicons, titles, and the +/// progress. +/// +/// See https://developer.android.com/reference/android/webkit/WebChromeClient. +@ProxyApi( + kotlinOptions: KotlinProxyApiOptions( + fullClassName: + 'io.flutter.plugins.webviewflutter.WebChromeClientProxyApi.WebChromeClientImpl', + ), +) +abstract class WebChromeClient { + WebChromeClient(); + + /// Tell the host application the current progress of loading a page. + late void Function(WebView webView, int progress)? onProgressChanged; + + /// Tell the client to show a file chooser. + @async + late List Function( + WebView webView, + FileChooserParams params, + )? onShowFileChooser; + + /// Notify the host application that web content is requesting permission to + /// access the specified resources and the permission currently isn't granted + /// or denied. + late void Function(PermissionRequest request)? onPermissionRequest; + + /// Callback to Dart function `WebChromeClient.onShowCustomView`. + late void Function( + View view, + CustomViewCallback callback, + )? onShowCustomView; + + /// Notify the host application that the current page has entered full screen + /// mode. + late void Function()? onHideCustomView; + + /// Notify the host application that web content from the specified origin is + /// attempting to use the Geolocation API, but no permission state is + /// currently set for that origin. + late void Function( + String origin, + GeolocationPermissionsCallback callback, + )? onGeolocationPermissionsShowPrompt; + + /// Notify the host application that a request for Geolocation permissions, + /// made with a previous call to `onGeolocationPermissionsShowPrompt` has been + /// canceled. + late void Function()? onGeolocationPermissionsHidePrompt; + + /// Report a JavaScript console message to the host application. + late void Function(ConsoleMessage message)? onConsoleMessage; + + /// Notify the host application that the web page wants to display a + /// JavaScript `alert()` dialog. + @async + late void Function(WebView webView, String url, String message)? onJsAlert; + + /// Notify the host application that the web page wants to display a + /// JavaScript `confirm()` dialog. + @async + late bool Function(WebView webView, String url, String message)? onJsConfirm; + + /// Notify the host application that the web page wants to display a + /// JavaScript `prompt()` dialog. + @async + late String? Function( + WebView webView, + String url, + String message, + String defaultValue, + )? onJsPrompt; + + /// Sets the required synchronous return value for the Java method, + /// `WebChromeClient.onShowFileChooser(...)`. + /// + /// The Java method, `WebChromeClient.onShowFileChooser(...)`, requires + /// a boolean to be returned and this method sets the returned value for all + /// calls to the Java method. + /// + /// Setting this to true indicates that all file chooser requests should be + /// handled by `onShowFileChooser` and the returned list of Strings will be + /// returned to the WebView. Otherwise, the client will use the default + /// handling and the returned value in `onShowFileChooser` will be ignored. + /// + /// Requires `onShowFileChooser` to be nonnull. + /// + /// Defaults to false. + void setSynchronousReturnValueForOnShowFileChooser(bool value); + + /// Sets the required synchronous return value for the Java method, + /// `WebChromeClient.onConsoleMessage(...)`. + /// + /// The Java method, `WebChromeClient.onConsoleMessage(...)`, requires + /// a boolean to be returned and this method sets the returned value for all + /// calls to the Java method. + /// + /// Setting this to true indicates that the client is handling all console + /// messages. + /// + /// Requires `onConsoleMessage` to be nonnull. + /// + /// Defaults to false. + void setSynchronousReturnValueForOnConsoleMessage(bool value); + + /// Sets the required synchronous return value for the Java method, + /// `WebChromeClient.onJsAlert(...)`. + /// + /// The Java method, `WebChromeClient.onJsAlert(...)`, requires a boolean to + /// be returned and this method sets the returned value for all calls to the + /// Java method. + /// + /// Setting this to true indicates that the client is handling all console + /// messages. + /// + /// Requires `onJsAlert` to be nonnull. + /// + /// Defaults to false. + void setSynchronousReturnValueForOnJsAlert(bool value); + + /// Sets the required synchronous return value for the Java method, + /// `WebChromeClient.onJsConfirm(...)`. + /// + /// The Java method, `WebChromeClient.onJsConfirm(...)`, requires a boolean to + /// be returned and this method sets the returned value for all calls to the + /// Java method. + /// + /// Setting this to true indicates that the client is handling all console + /// messages. + /// + /// Requires `onJsConfirm` to be nonnull. + /// + /// Defaults to false. + void setSynchronousReturnValueForOnJsConfirm(bool value); + + /// Sets the required synchronous return value for the Java method, + /// `WebChromeClient.onJsPrompt(...)`. + /// + /// The Java method, `WebChromeClient.onJsPrompt(...)`, requires a boolean to + /// be returned and this method sets the returned value for all calls to the + /// Java method. + /// + /// Setting this to true indicates that the client is handling all console + /// messages. + /// + /// Requires `onJsPrompt` to be nonnull. + /// + /// Defaults to false. + void setSynchronousReturnValueForOnJsPrompt(bool value); +} + +/// Provides access to the assets registered as part of the App bundle. +/// +/// Convenience class for accessing Flutter asset resources. +@ProxyApi( + kotlinOptions: KotlinProxyApiOptions( + fullClassName: 'io.flutter.plugins.webviewflutter.FlutterAssetManager', + ), +) +abstract class FlutterAssetManager { + /// The global instance of the `FlutterAssetManager`. + @static + late FlutterAssetManager instance; + + /// Returns a String array of all the assets at the given path. + /// + /// Throws an IOException in case I/O operations were interrupted. + List list(String path); + + /// Gets the relative file path to the Flutter asset with the given name, including the file's + /// extension, e.g., "myImage.jpg". + /// + /// The returned file path is relative to the Android app's standard asset's + /// directory. Therefore, the returned path is appropriate to pass to + /// Android's AssetManager, but the path is not appropriate to load as an + /// absolute path. + String getAssetFilePathByName(String name); +} + +/// This class is used to manage the JavaScript storage APIs provided by the +/// WebView. +/// +/// See https://developer.android.com/reference/android/webkit/WebStorage. +@ProxyApi( + kotlinOptions: KotlinProxyApiOptions( + fullClassName: 'android.webkit.WebStorage', + ), +) +abstract class WebStorage { + @static + late WebStorage instance; + + /// Clears all storage currently being used by the JavaScript storage APIs. + void deleteAllData(); +} + +/// Parameters used in the `WebChromeClient.onShowFileChooser` method. +/// +/// See https://developer.android.com/reference/android/webkit/WebChromeClient.FileChooserParams. +@ProxyApi( + kotlinOptions: KotlinProxyApiOptions( + fullClassName: 'android.webkit.WebChromeClient.FileChooserParams', + ), +) +abstract class FileChooserParams { + /// Preference for a live media captured value (e.g. Camera, Microphone). + late bool isCaptureEnabled; + + /// An array of acceptable MIME types. + late List acceptTypes; + + /// File chooser mode. + late FileChooserMode mode; + + /// File name of a default selection if specified, or null. + late String? filenameHint; +} + +/// This class defines a permission request and is used when web content +/// requests access to protected resources. +/// +/// See https://developer.android.com/reference/android/webkit/PermissionRequest. +@ProxyApi( + kotlinOptions: KotlinProxyApiOptions( + fullClassName: 'android.webkit.PermissionRequest', + ), +) +abstract class PermissionRequest { + late List resources; + + /// Call this method to grant origin the permission to access the given + /// resources. + void grant(List resources); + + /// Call this method to deny the request. + void deny(); +} + +/// A callback interface used by the host application to notify the current page +/// that its custom view has been dismissed. +/// +/// See https://developer.android.com/reference/android/webkit/WebChromeClient.CustomViewCallback. +@ProxyApi( + kotlinOptions: KotlinProxyApiOptions( + fullClassName: 'android.webkit.WebChromeClient.CustomViewCallback', + ), +) +abstract class CustomViewCallback { + /// Invoked when the host application dismisses the custom view. + void onCustomViewHidden(); +} + +/// This class represents the basic building block for user interface +/// components. +/// +/// See https://developer.android.com/reference/android/view/View. +@ProxyApi( + kotlinOptions: KotlinProxyApiOptions( + fullClassName: 'android.view.View', + ), +) +abstract class View { + /// Set the scrolled position of your view. + void scrollTo(int x, int y); + + /// Move the scrolled position of your view. + void scrollBy(int x, int y); + + /// Return the scrolled position of this view. + WebViewPoint getScrollPosition(); +} + +/// A callback interface used by the host application to set the Geolocation +/// permission state for an origin. +/// +/// See https://developer.android.com/reference/android/webkit/GeolocationPermissions.Callback. +@ProxyApi( + kotlinOptions: KotlinProxyApiOptions( + fullClassName: 'android.webkit.GeolocationPermissions.Callback', + ), +) +abstract class GeolocationPermissionsCallback { + /// Sets the Geolocation permission state for the supplied origin. + void invoke(String origin, bool allow, bool retain); +} + +/// Represents a request for HTTP authentication. +/// +/// See https://developer.android.com/reference/android/webkit/HttpAuthHandler. +@ProxyApi( + kotlinOptions: KotlinProxyApiOptions( + fullClassName: 'android.webkit.HttpAuthHandler', + ), +) +abstract class HttpAuthHandler { + /// Gets whether the credentials stored for the current host (i.e. the host + /// for which `WebViewClient.onReceivedHttpAuthRequest` was called) are + /// suitable for use. + bool useHttpAuthUsernamePassword(); + + /// Instructs the WebView to cancel the authentication request.. + void cancel(); + + /// Instructs the WebView to proceed with the authentication with the given + /// credentials. + void proceed(String username, String password); +} diff --git a/packages/webview_flutter/webview_flutter_android/pigeons/android_webview.dart b/packages/webview_flutter/webview_flutter_android/pigeons/android_webview.dart deleted file mode 100644 index 73b8093d05eb..000000000000 --- a/packages/webview_flutter/webview_flutter_android/pigeons/android_webview.dart +++ /dev/null @@ -1,641 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -import 'package:pigeon/pigeon.dart'; - -@ConfigurePigeon( - PigeonOptions( - dartOut: 'lib/src/android_webview.g.dart', - dartTestOut: 'test/test_android_webview.g.dart', - dartOptions: DartOptions(copyrightHeader: [ - 'Copyright 2013 The Flutter Authors. All rights reserved.', - 'Use of this source code is governed by a BSD-style license that can be', - 'found in the LICENSE file.', - ]), - javaOut: - 'android/src/main/java/io/flutter/plugins/webviewflutter/GeneratedAndroidWebView.java', - javaOptions: JavaOptions( - package: 'io.flutter.plugins.webviewflutter', - className: 'GeneratedAndroidWebView', - copyrightHeader: [ - 'Copyright 2013 The Flutter Authors. All rights reserved.', - 'Use of this source code is governed by a BSD-style license that can be', - 'found in the LICENSE file.', - ], - ), - ), -) - -/// Host API for managing the native `InstanceManager`. -@HostApi(dartHostTestHandler: 'TestInstanceManagerHostApi') -abstract class InstanceManagerHostApi { - /// Clear the native `InstanceManager`. - /// - /// This is typically only used after a hot restart. - void clear(); -} - -/// Mode of how to select files for a file chooser. -/// -/// See https://developer.android.com/reference/android/webkit/WebChromeClient.FileChooserParams. -enum FileChooserMode { - /// Open single file and requires that the file exists before allowing the - /// user to pick it. - /// - /// See https://developer.android.com/reference/android/webkit/WebChromeClient.FileChooserParams#MODE_OPEN. - open, - - /// Similar to [open] but allows multiple files to be selected. - /// - /// See https://developer.android.com/reference/android/webkit/WebChromeClient.FileChooserParams#MODE_OPEN_MULTIPLE. - openMultiple, - - /// Allows picking a nonexistent file and saving it. - /// - /// See https://developer.android.com/reference/android/webkit/WebChromeClient.FileChooserParams#MODE_SAVE. - save, -} - -/// Indicates the type of message logged to the console. -/// -/// See https://developer.android.com/reference/android/webkit/ConsoleMessage.MessageLevel. -enum ConsoleMessageLevel { - /// Indicates a message is logged for debugging. - /// - /// See https://developer.android.com/reference/android/webkit/ConsoleMessage.MessageLevel#DEBUG. - debug, - - /// Indicates a message is provided as an error. - /// - /// See https://developer.android.com/reference/android/webkit/ConsoleMessage.MessageLevel#ERROR. - error, - - /// Indicates a message is provided as a basic log message. - /// - /// See https://developer.android.com/reference/android/webkit/ConsoleMessage.MessageLevel#LOG. - log, - - /// Indicates a message is provided as a tip. - /// - /// See https://developer.android.com/reference/android/webkit/ConsoleMessage.MessageLevel#TIP. - tip, - - /// Indicates a message is provided as a warning. - /// - /// See https://developer.android.com/reference/android/webkit/ConsoleMessage.MessageLevel#WARNING. - warning, - - /// Indicates a message with an unknown level. - /// - /// This does not represent an actual value provided by the platform and only - /// indicates a value was provided that isn't currently supported. - unknown, -} - -class WebResourceRequestData { - WebResourceRequestData( - this.url, - this.isForMainFrame, - this.isRedirect, - this.hasGesture, - this.method, - this.requestHeaders, - ); - - String url; - bool isForMainFrame; - bool? isRedirect; - bool hasGesture; - String method; - Map requestHeaders; -} - -class WebResourceResponseData { - WebResourceResponseData( - this.statusCode, - ); - - int statusCode; -} - -class WebResourceErrorData { - WebResourceErrorData(this.errorCode, this.description); - - int errorCode; - String description; -} - -class WebViewPoint { - WebViewPoint(this.x, this.y); - - int x; - int y; -} - -/// Represents a JavaScript console message from WebCore. -/// -/// See https://developer.android.com/reference/android/webkit/ConsoleMessage -class ConsoleMessage { - late int lineNumber; - late String message; - late ConsoleMessageLevel level; - late String sourceId; -} - -/// Handles methods calls to the native Java Object class. -/// -/// Also handles calls to remove the reference to an instance with `dispose`. -/// -/// See https://docs.oracle.com/javase/7/docs/api/java/lang/Object.html. -@HostApi(dartHostTestHandler: 'TestJavaObjectHostApi') -abstract class JavaObjectHostApi { - void dispose(int identifier); -} - -/// Handles callbacks methods for the native Java Object class. -/// -/// See https://docs.oracle.com/javase/7/docs/api/java/lang/Object.html. -@FlutterApi() -abstract class JavaObjectFlutterApi { - void dispose(int identifier); -} - -/// Host API for `CookieManager`. -/// -/// This class may handle instantiating and adding native object instances that -/// are attached to a Dart instance or handle method calls on the associated -/// native class or an instance of the class. -@HostApi(dartHostTestHandler: 'TestCookieManagerHostApi') -abstract class CookieManagerHostApi { - /// Handles attaching `CookieManager.instance` to a native instance. - void attachInstance(int instanceIdentifier); - - /// Handles Dart method `CookieManager.setCookie`. - void setCookie(int identifier, String url, String value); - - /// Handles Dart method `CookieManager.removeAllCookies`. - @async - bool removeAllCookies(int identifier); - - /// Handles Dart method `CookieManager.setAcceptThirdPartyCookies`. - void setAcceptThirdPartyCookies( - int identifier, - int webViewIdentifier, - bool accept, - ); -} - -@HostApi(dartHostTestHandler: 'TestWebViewHostApi') -abstract class WebViewHostApi { - void create(int instanceId); - - void loadData( - int instanceId, - String data, - String? mimeType, - String? encoding, - ); - - void loadDataWithBaseUrl( - int instanceId, - String? baseUrl, - String data, - String? mimeType, - String? encoding, - String? historyUrl, - ); - - void loadUrl( - int instanceId, - String url, - Map headers, - ); - - void postUrl( - int instanceId, - String url, - Uint8List data, - ); - - String? getUrl(int instanceId); - - bool canGoBack(int instanceId); - - bool canGoForward(int instanceId); - - void goBack(int instanceId); - - void goForward(int instanceId); - - void reload(int instanceId); - - void clearCache(int instanceId, bool includeDiskFiles); - - @async - String? evaluateJavascript( - int instanceId, - String javascriptString, - ); - - String? getTitle(int instanceId); - - void scrollTo(int instanceId, int x, int y); - - void scrollBy(int instanceId, int x, int y); - - int getScrollX(int instanceId); - - int getScrollY(int instanceId); - - WebViewPoint getScrollPosition(int instanceId); - - void setWebContentsDebuggingEnabled(bool enabled); - - void setWebViewClient(int instanceId, int webViewClientInstanceId); - - void addJavaScriptChannel(int instanceId, int javaScriptChannelInstanceId); - - void removeJavaScriptChannel(int instanceId, int javaScriptChannelInstanceId); - - void setDownloadListener(int instanceId, int? listenerInstanceId); - - void setWebChromeClient(int instanceId, int? clientInstanceId); - - void setBackgroundColor(int instanceId, int color); -} - -/// Flutter API for `WebView`. -/// -/// This class may handle instantiating and adding Dart instances that are -/// attached to a native instance or receiving callback methods from an -/// overridden native class. -/// -/// See https://developer.android.com/reference/android/webkit/WebView. -@FlutterApi() -abstract class WebViewFlutterApi { - /// Create a new Dart instance and add it to the `InstanceManager`. - void create(int identifier); - - void onScrollChanged( - int webViewInstanceId, - int left, - int top, - int oldLeft, - int oldTop, - ); -} - -@HostApi(dartHostTestHandler: 'TestWebSettingsHostApi') -abstract class WebSettingsHostApi { - void create(int instanceId, int webViewInstanceId); - - void setDomStorageEnabled(int instanceId, bool flag); - - void setJavaScriptCanOpenWindowsAutomatically(int instanceId, bool flag); - - void setSupportMultipleWindows(int instanceId, bool support); - - void setJavaScriptEnabled(int instanceId, bool flag); - - void setUserAgentString(int instanceId, String? userAgentString); - - void setMediaPlaybackRequiresUserGesture(int instanceId, bool require); - - void setSupportZoom(int instanceId, bool support); - - void setLoadWithOverviewMode(int instanceId, bool overview); - - void setUseWideViewPort(int instanceId, bool use); - - void setDisplayZoomControls(int instanceId, bool enabled); - - void setBuiltInZoomControls(int instanceId, bool enabled); - - void setAllowFileAccess(int instanceId, bool enabled); - - void setTextZoom(int instanceId, int textZoom); - - String getUserAgentString(int instanceId); -} - -@HostApi(dartHostTestHandler: 'TestJavaScriptChannelHostApi') -abstract class JavaScriptChannelHostApi { - void create(int instanceId, String channelName); -} - -@FlutterApi() -abstract class JavaScriptChannelFlutterApi { - void postMessage(int instanceId, String message); -} - -@HostApi(dartHostTestHandler: 'TestWebViewClientHostApi') -abstract class WebViewClientHostApi { - void create(int instanceId); - - void setSynchronousReturnValueForShouldOverrideUrlLoading( - int instanceId, - bool value, - ); -} - -@FlutterApi() -abstract class WebViewClientFlutterApi { - void onPageStarted(int instanceId, int webViewInstanceId, String url); - - void onPageFinished(int instanceId, int webViewInstanceId, String url); - - void onReceivedHttpError( - int instanceId, - int webViewInstanceId, - WebResourceRequestData request, - WebResourceResponseData response, - ); - - void onReceivedRequestError( - int instanceId, - int webViewInstanceId, - WebResourceRequestData request, - WebResourceErrorData error, - ); - - void onReceivedError( - int instanceId, - int webViewInstanceId, - int errorCode, - String description, - String failingUrl, - ); - - void requestLoading( - int instanceId, - int webViewInstanceId, - WebResourceRequestData request, - ); - - void urlLoading(int instanceId, int webViewInstanceId, String url); - - void doUpdateVisitedHistory( - int instanceId, - int webViewInstanceId, - String url, - bool isReload, - ); - - void onReceivedHttpAuthRequest( - int instanceId, - int webViewInstanceId, - int httpAuthHandlerInstanceId, - String host, - String realm, - ); -} - -@HostApi(dartHostTestHandler: 'TestDownloadListenerHostApi') -abstract class DownloadListenerHostApi { - void create(int instanceId); -} - -@FlutterApi() -abstract class DownloadListenerFlutterApi { - void onDownloadStart( - int instanceId, - String url, - String userAgent, - String contentDisposition, - String mimetype, - int contentLength, - ); -} - -@HostApi(dartHostTestHandler: 'TestWebChromeClientHostApi') -abstract class WebChromeClientHostApi { - void create(int instanceId); - - void setSynchronousReturnValueForOnShowFileChooser( - int instanceId, - bool value, - ); - - void setSynchronousReturnValueForOnConsoleMessage( - int instanceId, - bool value, - ); - - void setSynchronousReturnValueForOnJsAlert( - int instanceId, - bool value, - ); - - void setSynchronousReturnValueForOnJsConfirm( - int instanceId, - bool value, - ); - - void setSynchronousReturnValueForOnJsPrompt( - int instanceId, - bool value, - ); -} - -@HostApi(dartHostTestHandler: 'TestAssetManagerHostApi') -abstract class FlutterAssetManagerHostApi { - List list(String path); - - String getAssetFilePathByName(String name); -} - -@FlutterApi() -abstract class WebChromeClientFlutterApi { - void onProgressChanged(int instanceId, int webViewInstanceId, int progress); - - @async - List onShowFileChooser( - int instanceId, - int webViewInstanceId, - int paramsInstanceId, - ); - - /// Callback to Dart function `WebChromeClient.onPermissionRequest`. - void onPermissionRequest(int instanceId, int requestInstanceId); - - /// Callback to Dart function `WebChromeClient.onShowCustomView`. - void onShowCustomView( - int instanceId, - int viewIdentifier, - int callbackIdentifier, - ); - - /// Callback to Dart function `WebChromeClient.onHideCustomView`. - void onHideCustomView(int instanceId); - - /// Callback to Dart function `WebChromeClient.onGeolocationPermissionsShowPrompt`. - void onGeolocationPermissionsShowPrompt( - int instanceId, - int paramsInstanceId, - String origin, - ); - - /// Callback to Dart function `WebChromeClient.onGeolocationPermissionsHidePrompt`. - void onGeolocationPermissionsHidePrompt(int identifier); - - /// Callback to Dart function `WebChromeClient.onConsoleMessage`. - void onConsoleMessage(int instanceId, ConsoleMessage message); - - @async - void onJsAlert(int instanceId, String url, String message); - - @async - bool onJsConfirm(int instanceId, String url, String message); - - @async - String onJsPrompt( - int instanceId, String url, String message, String defaultValue); -} - -@HostApi(dartHostTestHandler: 'TestWebStorageHostApi') -abstract class WebStorageHostApi { - void create(int instanceId); - - void deleteAllData(int instanceId); -} - -/// Handles callbacks methods for the native Java FileChooserParams class. -/// -/// See https://developer.android.com/reference/android/webkit/WebChromeClient.FileChooserParams. -@FlutterApi() -abstract class FileChooserParamsFlutterApi { - void create( - int instanceId, - bool isCaptureEnabled, - List acceptTypes, - FileChooserMode mode, - String? filenameHint, - ); -} - -/// Host API for `PermissionRequest`. -/// -/// This class may handle instantiating and adding native object instances that -/// are attached to a Dart instance or handle method calls on the associated -/// native class or an instance of the class. -/// -/// See https://developer.android.com/reference/android/webkit/PermissionRequest. -@HostApi(dartHostTestHandler: 'TestPermissionRequestHostApi') -abstract class PermissionRequestHostApi { - /// Handles Dart method `PermissionRequest.grant`. - void grant(int instanceId, List resources); - - /// Handles Dart method `PermissionRequest.deny`. - void deny(int instanceId); -} - -/// Flutter API for `PermissionRequest`. -/// -/// This class may handle instantiating and adding Dart instances that are -/// attached to a native instance or receiving callback methods from an -/// overridden native class. -/// -/// See https://developer.android.com/reference/android/webkit/PermissionRequest. -@FlutterApi() -abstract class PermissionRequestFlutterApi { - /// Create a new Dart instance and add it to the `InstanceManager`. - void create(int instanceId, List resources); -} - -/// Host API for `CustomViewCallback`. -/// -/// This class may handle instantiating and adding native object instances that -/// are attached to a Dart instance or handle method calls on the associated -/// native class or an instance of the class. -/// -/// See https://developer.android.com/reference/android/webkit/WebChromeClient.CustomViewCallback. -@HostApi(dartHostTestHandler: 'TestCustomViewCallbackHostApi') -abstract class CustomViewCallbackHostApi { - /// Handles Dart method `CustomViewCallback.onCustomViewHidden`. - void onCustomViewHidden(int identifier); -} - -/// Flutter API for `CustomViewCallback`. -/// -/// This class may handle instantiating and adding Dart instances that are -/// attached to a native instance or receiving callback methods from an -/// overridden native class. -/// -/// See https://developer.android.com/reference/android/webkit/WebChromeClient.CustomViewCallback. -@FlutterApi() -abstract class CustomViewCallbackFlutterApi { - /// Create a new Dart instance and add it to the `InstanceManager`. - void create(int identifier); -} - -/// Flutter API for `View`. -/// -/// This class may handle instantiating and adding Dart instances that are -/// attached to a native instance or receiving callback methods from an -/// overridden native class. -/// -/// See https://developer.android.com/reference/android/view/View. -@FlutterApi() -abstract class ViewFlutterApi { - /// Create a new Dart instance and add it to the `InstanceManager`. - void create(int identifier); -} - -/// Host API for `GeolocationPermissionsCallback`. -/// -/// This class may handle instantiating and adding native object instances that -/// are attached to a Dart instance or handle method calls on the associated -/// native class or an instance of the class. -/// -/// See https://developer.android.com/reference/android/webkit/GeolocationPermissions.Callback. -@HostApi(dartHostTestHandler: 'TestGeolocationPermissionsCallbackHostApi') -abstract class GeolocationPermissionsCallbackHostApi { - /// Handles Dart method `GeolocationPermissionsCallback.invoke`. - void invoke(int instanceId, String origin, bool allow, bool retain); -} - -/// Flutter API for `GeolocationPermissionsCallback`. -/// -/// This class may handle instantiating and adding Dart instances that are -/// attached to a native instance or receiving callback methods from an -/// overridden native class. -/// -/// See https://developer.android.com/reference/android/webkit/GeolocationPermissions.Callback. -@FlutterApi() -abstract class GeolocationPermissionsCallbackFlutterApi { - /// Create a new Dart instance and add it to the `InstanceManager`. - void create(int instanceId); -} - -/// Host API for `HttpAuthHandler`. -/// -/// This class may handle instantiating and adding native object instances that -/// are attached to a Dart instance or handle method calls on the associated -/// native class or an instance of the class. -/// -/// See https://developer.android.com/reference/android/webkit/HttpAuthHandler. -@HostApi(dartHostTestHandler: 'TestHttpAuthHandlerHostApi') -abstract class HttpAuthHandlerHostApi { - /// Handles Dart method `HttpAuthHandler.useHttpAuthUsernamePassword`. - bool useHttpAuthUsernamePassword(int instanceId); - - /// Handles Dart method `HttpAuthHandler.cancel`. - void cancel(int instanceId); - - /// Handles Dart method `HttpAuthHandler.proceed`. - void proceed(int instanceId, String username, String password); -} - -/// Flutter API for `HttpAuthHandler`. -/// -/// This class may handle instantiating and adding Dart instances that are -/// attached to a native instance or receiving callback methods from an -/// overridden native class. -/// -/// See https://developer.android.com/reference/android/webkit/HttpAuthHandler. -@FlutterApi() -abstract class HttpAuthHandlerFlutterApi { - /// Create a new Dart instance and add it to the `InstanceManager`. - void create(int instanceId); -} diff --git a/packages/webview_flutter/webview_flutter_android/pigeons/copyright.txt b/packages/webview_flutter/webview_flutter_android/pigeons/copyright.txt new file mode 100644 index 000000000000..fb682b1ab965 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_android/pigeons/copyright.txt @@ -0,0 +1,3 @@ +Copyright 2013 The Flutter Authors. All rights reserved. +Use of this source code is governed by a BSD-style license that can be +found in the LICENSE file. \ No newline at end of file diff --git a/packages/webview_flutter/webview_flutter_android/pubspec.yaml b/packages/webview_flutter/webview_flutter_android/pubspec.yaml index 5d9f440a5b18..4ff9b6166a6d 100644 --- a/packages/webview_flutter/webview_flutter_android/pubspec.yaml +++ b/packages/webview_flutter/webview_flutter_android/pubspec.yaml @@ -2,7 +2,7 @@ name: webview_flutter_android description: A Flutter plugin that provides a WebView widget on Android. repository: https://github.com/flutter/packages/tree/main/packages/webview_flutter/webview_flutter_android issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+webview%22 -version: 4.0.3 +version: 4.1.0 environment: sdk: ^3.5.0 @@ -27,7 +27,7 @@ dev_dependencies: flutter_test: sdk: flutter mockito: ^5.4.4 - pigeon: ^11.0.0 + pigeon: ^22.5.0 topics: - html diff --git a/packages/webview_flutter/webview_flutter_android/test/android_navigation_delegate_test.dart b/packages/webview_flutter/webview_flutter_android/test/android_navigation_delegate_test.dart index 1adc7e64356c..b61e0a2561c7 100644 --- a/packages/webview_flutter/webview_flutter_android/test/android_navigation_delegate_test.dart +++ b/packages/webview_flutter/webview_flutter_android/test/android_navigation_delegate_test.dart @@ -8,24 +8,21 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:mockito/annotations.dart'; import 'package:mockito/mockito.dart'; import 'package:webview_flutter_android/src/android_proxy.dart'; -import 'package:webview_flutter_android/src/android_webview.dart' +import 'package:webview_flutter_android/src/android_webkit.g.dart' as android_webview; +import 'package:webview_flutter_android/src/android_webkit_constants.dart'; import 'package:webview_flutter_android/webview_flutter_android.dart'; import 'package:webview_flutter_platform_interface/webview_flutter_platform_interface.dart'; import 'android_navigation_delegate_test.mocks.dart'; -import 'test_android_webview.g.dart'; @GenerateMocks([ - TestInstanceManagerHostApi, android_webview.HttpAuthHandler, + android_webview.DownloadListener, ]) void main() { TestWidgetsFlutterBinding.ensureInitialized(); - // Mocks the call to clear the native InstanceManager. - TestInstanceManagerHostApi.setup(MockTestInstanceManagerHostApi()); - group('AndroidNavigationDelegate', () { test('onPageFinished', () { final AndroidNavigationDelegate androidNavigationDelegate = @@ -36,7 +33,8 @@ void main() { .setOnPageFinished((String url) => callbackUrl = url); CapturingWebViewClient.lastCreatedDelegate.onPageFinished!( - android_webview.WebView.detached(), + CapturingWebViewClient(), + TestWebView(), 'https://www.google.com', ); @@ -52,7 +50,8 @@ void main() { .setOnPageStarted((String url) => callbackUrl = url); CapturingWebViewClient.lastCreatedDelegate.onPageStarted!( - android_webview.WebView.detached(), + CapturingWebViewClient(), + TestWebView(), 'https://www.google.com', ); @@ -68,16 +67,21 @@ void main() { (HttpResponseError httpError) => callbackError = httpError); CapturingWebViewClient.lastCreatedDelegate.onReceivedHttpError!( - android_webview.WebView.detached(), - android_webview.WebResourceRequest( + CapturingWebViewClient(), + TestWebView(), + android_webview.WebResourceRequest.pigeon_detached( url: 'https://www.google.com', isForMainFrame: false, isRedirect: true, hasGesture: true, method: 'GET', - requestHeaders: {'X-Mock': 'mocking'}, + requestHeaders: const {'X-Mock': 'mocking'}, + pigeon_instanceManager: TestInstanceManager(), ), - android_webview.WebResourceResponse(statusCode: 401)); + android_webview.WebResourceResponse.pigeon_detached( + statusCode: 401, + pigeon_instanceManager: TestInstanceManager(), + )); expect(callbackError.response?.statusCode, 401); }); @@ -91,23 +95,25 @@ void main() { (WebResourceError error) => callbackError = error); CapturingWebViewClient.lastCreatedDelegate.onReceivedRequestError!( - android_webview.WebView.detached(), - android_webview.WebResourceRequest( + CapturingWebViewClient(), + TestWebView(), + android_webview.WebResourceRequest.pigeon_detached( url: 'https://www.google.com', isForMainFrame: false, isRedirect: true, hasGesture: true, method: 'GET', - requestHeaders: {'X-Mock': 'mocking'}, + requestHeaders: const {'X-Mock': 'mocking'}, + pigeon_instanceManager: TestInstanceManager(), ), - android_webview.WebResourceError( - errorCode: android_webview.WebViewClient.errorFileNotFound, + android_webview.WebResourceError.pigeon_detached( + errorCode: WebViewClientConstants.errorFileNotFound, description: 'Page not found.', + pigeon_instanceManager: TestInstanceManager(), ), ); - expect(callbackError.errorCode, - android_webview.WebViewClient.errorFileNotFound); + expect(callbackError.errorCode, WebViewClientConstants.errorFileNotFound); expect(callbackError.description, 'Page not found.'); expect(callbackError.errorType, WebResourceErrorType.fileNotFound); expect(callbackError.isForMainFrame, false); @@ -122,14 +128,14 @@ void main() { (WebResourceError error) => callbackError = error); CapturingWebViewClient.lastCreatedDelegate.onReceivedError!( - android_webview.WebView.detached(), - android_webview.WebViewClient.errorFileNotFound, + CapturingWebViewClient(), + TestWebView(), + WebViewClientConstants.errorFileNotFound, 'Page not found.', 'https://www.google.com', ); - expect(callbackError.errorCode, - android_webview.WebViewClient.errorFileNotFound); + expect(callbackError.errorCode, WebViewClientConstants.errorFileNotFound); expect(callbackError.description, 'Page not found.'); expect(callbackError.errorType, WebResourceErrorType.fileNotFound); expect(callbackError.isForMainFrame, true); @@ -149,14 +155,16 @@ void main() { }); CapturingWebViewClient.lastCreatedDelegate.requestLoading!( - android_webview.WebView.detached(), - android_webview.WebResourceRequest( + CapturingWebViewClient(), + TestWebView(), + android_webview.WebResourceRequest.pigeon_detached( url: 'https://www.google.com', isForMainFrame: true, isRedirect: true, hasGesture: true, method: 'GET', - requestHeaders: {'X-Mock': 'mocking'}, + requestHeaders: const {'X-Mock': 'mocking'}, + pigeon_instanceManager: TestInstanceManager(), ), ); @@ -179,14 +187,16 @@ void main() { androidNavigationDelegate.setOnLoadRequest((_) async {}); CapturingWebViewClient.lastCreatedDelegate.requestLoading!( - android_webview.WebView.detached(), - android_webview.WebResourceRequest( + CapturingWebViewClient(), + TestWebView(), + android_webview.WebResourceRequest.pigeon_detached( url: 'https://www.google.com', isForMainFrame: true, isRedirect: true, hasGesture: true, method: 'GET', - requestHeaders: {'X-Mock': 'mocking'}, + requestHeaders: const {'X-Mock': 'mocking'}, + pigeon_instanceManager: TestInstanceManager(), ), ); @@ -209,14 +219,16 @@ void main() { androidNavigationDelegate.setOnLoadRequest((_) async {}); CapturingWebViewClient.lastCreatedDelegate.requestLoading!( - android_webview.WebView.detached(), - android_webview.WebResourceRequest( + CapturingWebViewClient(), + TestWebView(), + android_webview.WebResourceRequest.pigeon_detached( url: 'https://www.google.com', isForMainFrame: false, isRedirect: true, hasGesture: true, method: 'GET', - requestHeaders: {'X-Mock': 'mocking'}, + requestHeaders: const {'X-Mock': 'mocking'}, + pigeon_instanceManager: TestInstanceManager(), ), ); @@ -236,14 +248,16 @@ void main() { }); CapturingWebViewClient.lastCreatedDelegate.requestLoading!( - android_webview.WebView.detached(), - android_webview.WebResourceRequest( + CapturingWebViewClient(), + TestWebView(), + android_webview.WebResourceRequest.pigeon_detached( url: 'https://www.google.com', isForMainFrame: true, isRedirect: true, hasGesture: true, method: 'GET', - requestHeaders: {'X-Mock': 'mocking'}, + requestHeaders: const {'X-Mock': 'mocking'}, + pigeon_instanceManager: TestInstanceManager(), ), ); @@ -270,14 +284,16 @@ void main() { }); CapturingWebViewClient.lastCreatedDelegate.requestLoading!( - android_webview.WebView.detached(), - android_webview.WebResourceRequest( + CapturingWebViewClient(), + TestWebView(), + android_webview.WebResourceRequest.pigeon_detached( url: 'https://www.google.com', isForMainFrame: true, isRedirect: true, hasGesture: true, method: 'GET', - requestHeaders: {'X-Mock': 'mocking'}, + requestHeaders: const {'X-Mock': 'mocking'}, + pigeon_instanceManager: TestInstanceManager(), ), ); @@ -308,14 +324,16 @@ void main() { }); CapturingWebViewClient.lastCreatedDelegate.requestLoading!( - android_webview.WebView.detached(), - android_webview.WebResourceRequest( + CapturingWebViewClient(), + TestWebView(), + android_webview.WebResourceRequest.pigeon_detached( url: 'https://www.google.com', isForMainFrame: true, isRedirect: true, hasGesture: true, method: 'GET', - requestHeaders: {'X-Mock': 'mocking'}, + requestHeaders: const {'X-Mock': 'mocking'}, + pigeon_instanceManager: TestInstanceManager(), ), ); @@ -340,7 +358,8 @@ void main() { }); CapturingWebViewClient.lastCreatedDelegate.urlLoading!( - android_webview.WebView.detached(), + CapturingWebViewClient(), + TestWebView(), 'https://www.google.com', ); @@ -360,7 +379,8 @@ void main() { }); CapturingWebViewClient.lastCreatedDelegate.urlLoading!( - android_webview.WebView.detached(), + CapturingWebViewClient(), + TestWebView(), 'https://www.google.com', ); @@ -387,7 +407,8 @@ void main() { }); CapturingWebViewClient.lastCreatedDelegate.urlLoading!( - android_webview.WebView.detached(), + CapturingWebViewClient(), + TestWebView(), 'https://www.google.com', ); @@ -418,7 +439,8 @@ void main() { }); CapturingWebViewClient.lastCreatedDelegate.urlLoading!( - android_webview.WebView.detached(), + CapturingWebViewClient(), + TestWebView(), 'https://www.google.com', ); @@ -456,6 +478,7 @@ void main() { }); CapturingDownloadListener.lastCreatedListener.onDownloadStart( + MockDownloadListener(), '', '', '', @@ -486,6 +509,7 @@ void main() { }); CapturingDownloadListener.lastCreatedListener.onDownloadStart( + MockDownloadListener(), 'https://www.google.com', '', '', @@ -520,6 +544,7 @@ void main() { }); CapturingDownloadListener.lastCreatedListener.onDownloadStart( + MockDownloadListener(), 'https://www.google.com', '', '', @@ -546,7 +571,8 @@ void main() { ); CapturingWebViewClient.lastCreatedDelegate.doUpdateVisitedHistory!( - android_webview.WebView.detached(), + CapturingWebViewClient(), + TestWebView(), 'https://www.google.com', false, ); @@ -570,8 +596,11 @@ void main() { const String expectedRealm = 'expectedRealm'; CapturingWebViewClient.lastCreatedDelegate.onReceivedHttpAuthRequest!( - android_webview.WebView.detached(), - android_webview.HttpAuthHandler(), + CapturingWebViewClient(), + TestWebView(), + android_webview.HttpAuthHandler.pigeon_detached( + pigeon_instanceManager: TestInstanceManager(), + ), expectedHost, expectedRealm, ); @@ -586,7 +615,8 @@ void main() { final MockHttpAuthHandler mockAuthHandler = MockHttpAuthHandler(); CapturingWebViewClient.lastCreatedDelegate.onReceivedHttpAuthRequest!( - android_webview.WebView.detached(), + CapturingWebViewClient(), + TestWebView(), mockAuthHandler, 'host', 'realm', @@ -602,9 +632,9 @@ AndroidNavigationDelegateCreationParams _buildCreationParams() { .fromPlatformNavigationDelegateCreationParams( const PlatformNavigationDelegateCreationParams(), androidWebViewProxy: const AndroidWebViewProxy( - createAndroidWebChromeClient: CapturingWebChromeClient.new, - createAndroidWebViewClient: CapturingWebViewClient.new, - createDownloadListener: CapturingDownloadListener.new, + newWebChromeClient: CapturingWebChromeClient.new, + newWebViewClient: CapturingWebViewClient.new, + newDownloadListener: CapturingDownloadListener.new, ), ); } @@ -618,13 +648,14 @@ class CapturingWebViewClient extends android_webview.WebViewClient { super.onReceivedHttpError, super.onReceivedError, super.onReceivedHttpAuthRequest, + super.onReceivedRequestErrorCompat, + super.doUpdateVisitedHistory, super.onReceivedRequestError, super.requestLoading, super.urlLoading, - super.doUpdateVisitedHistory, - super.binaryMessenger, - super.instanceManager, - }) : super.detached() { + }) : super.pigeon_detached( + pigeon_instanceManager: android_webview.PigeonInstanceManager( + onWeakReferenceRemoved: (_) {})) { lastCreatedDelegate = this; } @@ -653,9 +684,9 @@ class CapturingWebChromeClient extends android_webview.WebChromeClient { super.onJsAlert, super.onJsConfirm, super.onJsPrompt, - super.binaryMessenger, - super.instanceManager, - }) : super.detached() { + }) : super.pigeon_detached( + pigeon_instanceManager: android_webview.PigeonInstanceManager( + onWeakReferenceRemoved: (_) {})) { lastCreatedDelegate = this; } @@ -667,12 +698,27 @@ class CapturingWebChromeClient extends android_webview.WebChromeClient { class CapturingDownloadListener extends android_webview.DownloadListener { CapturingDownloadListener({ required super.onDownloadStart, - super.binaryMessenger, - super.instanceManager, - }) : super.detached() { + }) : super.pigeon_detached( + pigeon_instanceManager: android_webview.PigeonInstanceManager( + onWeakReferenceRemoved: (_) {})) { lastCreatedListener = this; } static CapturingDownloadListener lastCreatedListener = - CapturingDownloadListener(onDownloadStart: (_, __, ___, ____, _____) {}); + CapturingDownloadListener( + onDownloadStart: (_, __, ___, ____, _____, ______) {}, + ); +} + +class TestWebView extends android_webview.WebView { + TestWebView() + : super.pigeon_detached( + pigeon_instanceManager: android_webview.PigeonInstanceManager( + onWeakReferenceRemoved: (_) {}, + ), + ); +} + +class TestInstanceManager extends android_webview.PigeonInstanceManager { + TestInstanceManager() : super(onWeakReferenceRemoved: (_) {}); } diff --git a/packages/webview_flutter/webview_flutter_android/test/android_navigation_delegate_test.mocks.dart b/packages/webview_flutter/webview_flutter_android/test/android_navigation_delegate_test.mocks.dart index ee783f3777cf..efe2191cc974 100644 --- a/packages/webview_flutter/webview_flutter_android/test/android_navigation_delegate_test.mocks.dart +++ b/packages/webview_flutter/webview_flutter_android/test/android_navigation_delegate_test.mocks.dart @@ -3,12 +3,10 @@ // Do not manually edit this file. // ignore_for_file: no_leading_underscores_for_library_prefixes -import 'dart:async' as _i4; +import 'dart:async' as _i3; import 'package:mockito/mockito.dart' as _i1; -import 'package:webview_flutter_android/src/android_webview.dart' as _i2; - -import 'test_android_webview.g.dart' as _i3; +import 'package:webview_flutter_android/src/android_webkit.g.dart' as _i2; // ignore_for_file: type=lint // ignore_for_file: avoid_redundant_argument_values @@ -23,8 +21,9 @@ import 'test_android_webview.g.dart' as _i3; // ignore_for_file: camel_case_types // ignore_for_file: subtype_of_sealed_class -class _FakeJavaObject_0 extends _i1.SmartFake implements _i2.JavaObject { - _FakeJavaObject_0( +class _FakePigeonInstanceManager_0 extends _i1.SmartFake + implements _i2.PigeonInstanceManager { + _FakePigeonInstanceManager_0( Object parent, Invocation parentInvocation, ) : super( @@ -33,23 +32,26 @@ class _FakeJavaObject_0 extends _i1.SmartFake implements _i2.JavaObject { ); } -/// A class which mocks [TestInstanceManagerHostApi]. -/// -/// See the documentation for Mockito's code generation for more information. -class MockTestInstanceManagerHostApi extends _i1.Mock - implements _i3.TestInstanceManagerHostApi { - MockTestInstanceManagerHostApi() { - _i1.throwOnMissingStub(this); - } +class _FakeHttpAuthHandler_1 extends _i1.SmartFake + implements _i2.HttpAuthHandler { + _FakeHttpAuthHandler_1( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} - @override - void clear() => super.noSuchMethod( - Invocation.method( - #clear, - [], - ), - returnValueForMissingStub: null, - ); +class _FakeDownloadListener_2 extends _i1.SmartFake + implements _i2.DownloadListener { + _FakeDownloadListener_2( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); } /// A class which mocks [HttpAuthHandler]. @@ -61,17 +63,35 @@ class MockHttpAuthHandler extends _i1.Mock implements _i2.HttpAuthHandler { } @override - _i4.Future cancel() => (super.noSuchMethod( + _i2.PigeonInstanceManager get pigeon_instanceManager => (super.noSuchMethod( + Invocation.getter(#pigeon_instanceManager), + returnValue: _FakePigeonInstanceManager_0( + this, + Invocation.getter(#pigeon_instanceManager), + ), + ) as _i2.PigeonInstanceManager); + + @override + _i3.Future useHttpAuthUsernamePassword() => (super.noSuchMethod( + Invocation.method( + #useHttpAuthUsernamePassword, + [], + ), + returnValue: _i3.Future.value(false), + ) as _i3.Future); + + @override + _i3.Future cancel() => (super.noSuchMethod( Invocation.method( #cancel, [], ), - returnValue: _i4.Future.value(), - returnValueForMissingStub: _i4.Future.value(), - ) as _i4.Future); + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), + ) as _i3.Future); @override - _i4.Future proceed( + _i3.Future proceed( String? username, String? password, ) => @@ -83,31 +103,82 @@ class MockHttpAuthHandler extends _i1.Mock implements _i2.HttpAuthHandler { password, ], ), - returnValue: _i4.Future.value(), - returnValueForMissingStub: _i4.Future.value(), - ) as _i4.Future); + returnValue: _i3.Future.value(), + returnValueForMissingStub: _i3.Future.value(), + ) as _i3.Future); @override - _i4.Future useHttpAuthUsernamePassword() => (super.noSuchMethod( + _i2.HttpAuthHandler pigeon_copy() => (super.noSuchMethod( Invocation.method( - #useHttpAuthUsernamePassword, + #pigeon_copy, [], ), - returnValue: _i4.Future.value(false), - ) as _i4.Future); + returnValue: _FakeHttpAuthHandler_1( + this, + Invocation.method( + #pigeon_copy, + [], + ), + ), + ) as _i2.HttpAuthHandler); +} + +/// A class which mocks [DownloadListener]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockDownloadListener extends _i1.Mock implements _i2.DownloadListener { + MockDownloadListener() { + _i1.throwOnMissingStub(this); + } + + @override + void Function( + _i2.DownloadListener, + String, + String, + String, + String, + int, + ) get onDownloadStart => (super.noSuchMethod( + Invocation.getter(#onDownloadStart), + returnValue: ( + _i2.DownloadListener pigeon_instance, + String url, + String userAgent, + String contentDisposition, + String mimetype, + int contentLength, + ) {}, + ) as void Function( + _i2.DownloadListener, + String, + String, + String, + String, + int, + )); + + @override + _i2.PigeonInstanceManager get pigeon_instanceManager => (super.noSuchMethod( + Invocation.getter(#pigeon_instanceManager), + returnValue: _FakePigeonInstanceManager_0( + this, + Invocation.getter(#pigeon_instanceManager), + ), + ) as _i2.PigeonInstanceManager); @override - _i2.JavaObject copy() => (super.noSuchMethod( + _i2.DownloadListener pigeon_copy() => (super.noSuchMethod( Invocation.method( - #copy, + #pigeon_copy, [], ), - returnValue: _FakeJavaObject_0( + returnValue: _FakeDownloadListener_2( this, Invocation.method( - #copy, + #pigeon_copy, [], ), ), - ) as _i2.JavaObject); + ) as _i2.DownloadListener); } diff --git a/packages/webview_flutter/webview_flutter_android/test/android_webview_controller_test.dart b/packages/webview_flutter/webview_flutter_android/test/android_webview_controller_test.dart index dcc5b27abcd8..6879c33253e7 100644 --- a/packages/webview_flutter/webview_flutter_android/test/android_webview_controller_test.dart +++ b/packages/webview_flutter/webview_flutter_android/test/android_webview_controller_test.dart @@ -8,21 +8,15 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:mockito/annotations.dart'; import 'package:mockito/mockito.dart'; import 'package:webview_flutter_android/src/android_proxy.dart'; -import 'package:webview_flutter_android/src/android_webview.dart' +import 'package:webview_flutter_android/src/android_webkit.g.dart' as android_webview; -import 'package:webview_flutter_android/src/android_webview_api_impls.dart'; -import 'package:webview_flutter_android/src/instance_manager.dart'; +import 'package:webview_flutter_android/src/android_webkit_constants.dart'; import 'package:webview_flutter_android/src/platform_views_service_proxy.dart'; import 'package:webview_flutter_android/webview_flutter_android.dart'; import 'package:webview_flutter_platform_interface/webview_flutter_platform_interface.dart'; import 'android_navigation_delegate_test.dart'; import 'android_webview_controller_test.mocks.dart'; -import 'android_webview_test.mocks.dart' - show - MockTestCustomViewCallbackHostApi, - MockTestGeolocationPermissionsCallbackHostApi; -import 'test_android_webview.g.dart'; @GenerateNiceMocks(>[ MockSpec(), @@ -31,6 +25,7 @@ import 'test_android_webview.g.dart'; MockSpec(), MockSpec(), MockSpec(), + MockSpec(), MockSpec(), MockSpec(), MockSpec(), @@ -40,46 +35,55 @@ import 'test_android_webview.g.dart'; MockSpec(), MockSpec(), MockSpec(), - MockSpec(), - MockSpec(), ]) void main() { TestWidgetsFlutterBinding.ensureInitialized(); - // Mocks the call to clear the native InstanceManager. - TestInstanceManagerHostApi.setup(MockTestInstanceManagerHostApi()); - AndroidWebViewController createControllerWithMocks({ android_webview.FlutterAssetManager? mockFlutterAssetManager, android_webview.JavaScriptChannel? mockJavaScriptChannel, android_webview.WebChromeClient Function({ - void Function(android_webview.WebView webView, int progress)? + void Function( + android_webview.WebChromeClient, android_webview.WebView, int)? onProgressChanged, Future> Function( - android_webview.WebView webView, - android_webview.FileChooserParams params, + android_webview.WebChromeClient, + android_webview.WebView, + android_webview.FileChooserParams, )? onShowFileChooser, - android_webview.GeolocationPermissionsShowPrompt? - onGeolocationPermissionsShowPrompt, - android_webview.GeolocationPermissionsHidePrompt? - onGeolocationPermissionsHidePrompt, + void Function(android_webview.WebChromeClient, + android_webview.PermissionRequest)? + onPermissionRequest, + void Function(android_webview.WebChromeClient, android_webview.View, + android_webview.CustomViewCallback)? + onShowCustomView, + void Function(android_webview.WebChromeClient)? onHideCustomView, void Function( - android_webview.WebChromeClient instance, - android_webview.PermissionRequest request, - )? onPermissionRequest, + android_webview.WebChromeClient, + String, + android_webview.GeolocationPermissionsCallback, + )? onGeolocationPermissionsShowPrompt, + void Function(android_webview.WebChromeClient)? + onGeolocationPermissionsHidePrompt, void Function( - android_webview.WebChromeClient instance, - android_webview.View view, - android_webview.CustomViewCallback callback)? - onShowCustomView, - void Function(android_webview.WebChromeClient instance)? onHideCustomView, - void Function(android_webview.WebChromeClient instance, - android_webview.ConsoleMessage message)? + android_webview.WebChromeClient, android_webview.ConsoleMessage)? onConsoleMessage, - Future Function(String url, String message)? onJsAlert, - Future Function(String url, String message)? onJsConfirm, - Future Function(String url, String message, String defaultValue)? - onJsPrompt, + Future Function(android_webview.WebChromeClient, + android_webview.WebView, String, String)? + onJsAlert, + Future Function( + android_webview.WebChromeClient, + android_webview.WebView, + String, + String, + )? onJsConfirm, + Future Function( + android_webview.WebChromeClient, + android_webview.WebView, + String, + String, + String, + )? onJsPrompt, })? createWebChromeClient, android_webview.WebView? mockWebView, android_webview.WebViewClient? mockWebViewClient, @@ -93,94 +97,114 @@ void main() { AndroidWebViewControllerCreationParams( androidWebStorage: mockWebStorage ?? MockWebStorage(), androidWebViewProxy: AndroidWebViewProxy( - createAndroidWebChromeClient: createWebChromeClient ?? + newWebChromeClient: createWebChromeClient ?? ({ - void Function(android_webview.WebView, int)? + void Function(android_webview.WebChromeClient, + android_webview.WebView, int)? onProgressChanged, Future> Function( - android_webview.WebView webView, - android_webview.FileChooserParams params, + android_webview.WebChromeClient, + android_webview.WebView, + android_webview.FileChooserParams, )? onShowFileChooser, + void Function(android_webview.WebChromeClient, + android_webview.PermissionRequest)? + onPermissionRequest, void Function( - android_webview.WebChromeClient instance, - android_webview.PermissionRequest request, - )? onPermissionRequest, - Future Function( - String origin, - android_webview.GeolocationPermissionsCallback callback, - )? onGeolocationPermissionsShowPrompt, - void Function(android_webview.WebChromeClient instance)? - onGeolocationPermissionsHidePrompt, - void Function( - android_webview.WebChromeClient instance, - android_webview.View view, - android_webview.CustomViewCallback callback)? + android_webview.WebChromeClient, + android_webview.View, + android_webview.CustomViewCallback)? onShowCustomView, - void Function(android_webview.WebChromeClient instance)? + void Function(android_webview.WebChromeClient)? onHideCustomView, - void Function(android_webview.WebChromeClient instance, - android_webview.ConsoleMessage message)? + void Function( + android_webview.WebChromeClient, + String, + android_webview.GeolocationPermissionsCallback, + )? onGeolocationPermissionsShowPrompt, + void Function(android_webview.WebChromeClient)? + onGeolocationPermissionsHidePrompt, + void Function(android_webview.WebChromeClient, + android_webview.ConsoleMessage)? onConsoleMessage, - Future Function(String url, String message)? + Future Function(android_webview.WebChromeClient, + android_webview.WebView, String, String)? onJsAlert, - Future Function(String url, String message)? - onJsConfirm, - Future Function( - String url, String message, String defaultValue)? - onJsPrompt, + Future Function( + android_webview.WebChromeClient, + android_webview.WebView, + String, + String, + )? onJsConfirm, + Future Function( + android_webview.WebChromeClient, + android_webview.WebView, + String, + String, + String, + )? onJsPrompt, }) => MockWebChromeClient(), - createAndroidWebView: ( - {dynamic Function( - int left, int top, int oldLeft, int oldTop)? + newWebView: ( + {dynamic Function(android_webview.WebView, int left, + int top, int oldLeft, int oldTop)? onScrollChanged}) => nonNullMockWebView, - createAndroidWebViewClient: ({ - void Function(android_webview.WebView webView, String url)? - onPageFinished, - void Function(android_webview.WebView webView, String url)? + newWebViewClient: ({ + void Function(android_webview.WebViewClient, + android_webview.WebView, String)? onPageStarted, + void Function(android_webview.WebViewClient, + android_webview.WebView, String)? + onPageFinished, void Function( - android_webview.WebView webView, - android_webview.WebResourceRequest request, - android_webview.WebResourceResponse response)? - onReceivedHttpError, - @Deprecated('Only called on Android version < 23.') - void Function( - android_webview.WebView webView, - int errorCode, - String description, - String failingUrl, - )? onReceivedError, - void Function( - android_webview.WebView webView, - android_webview.HttpAuthHandler hander, - String host, - String realm, - )? onReceivedHttpAuthRequest, + android_webview.WebViewClient, + android_webview.WebView, + android_webview.WebResourceRequest, + android_webview.WebResourceResponse, + )? onReceivedHttpError, void Function( - android_webview.WebView webView, - android_webview.WebResourceRequest request, - android_webview.WebResourceError error, + android_webview.WebViewClient, + android_webview.WebView, + android_webview.WebResourceRequest, + android_webview.WebResourceError, )? onReceivedRequestError, void Function( - android_webview.WebView webView, - android_webview.WebResourceRequest request, - )? requestLoading, - void Function(android_webview.WebView webView, String url)? + android_webview.WebViewClient, + android_webview.WebView, + android_webview.WebResourceRequest, + android_webview.WebResourceErrorCompat, + )? onReceivedRequestErrorCompat, + void Function(android_webview.WebViewClient, + android_webview.WebView, int, String, String)? + onReceivedError, + void Function( + android_webview.WebViewClient, + android_webview.WebView, + android_webview.WebResourceRequest)? + requestLoading, + void Function(android_webview.WebViewClient, + android_webview.WebView, String)? urlLoading, + void Function(android_webview.WebViewClient, + android_webview.WebView, String, bool)? + doUpdateVisitedHistory, void Function( - android_webview.WebView webView, - String url, - bool isReload, - )? doUpdateVisitedHistory, + android_webview.WebViewClient, + android_webview.WebView, + android_webview.HttpAuthHandler, + String, + String)? + onReceivedHttpAuthRequest, }) => mockWebViewClient ?? MockWebViewClient(), - createFlutterAssetManager: () => + instanceFlutterAssetManager: () => mockFlutterAssetManager ?? MockFlutterAssetManager(), - createJavaScriptChannel: ( - String channelName, { - required void Function(String) postMessage, + newJavaScriptChannel: ({ + required String channelName, + required void Function( + android_webview.JavaScriptChannel, String) + postMessage, }) => mockJavaScriptChannel ?? MockJavaScriptChannel(), )); @@ -201,9 +225,10 @@ void main() { name: name ?? 'test', onMessageReceived: (JavaScriptMessage message) {}, webViewProxy: AndroidWebViewProxy( - createJavaScriptChannel: ( - String channelName, { - required void Function(String) postMessage, + newJavaScriptChannel: ({ + required String channelName, + required void Function(android_webview.JavaScriptChannel, String) + postMessage, }) => mockJavaScriptChannel ?? MockJavaScriptChannel(), )); @@ -363,8 +388,11 @@ void main() { await controller.loadHtmlString('

Hello Test!

'); verify(mockWebView.loadDataWithBaseUrl( - data: '

Hello Test!

', - mimeType: 'text/html', + null, + '

Hello Test!

', + 'text/html', + null, + null, )).called(1); }); @@ -378,9 +406,11 @@ void main() { baseUrl: 'https://flutter.dev'); verify(mockWebView.loadDataWithBaseUrl( - data: '

Hello Test!

', - baseUrl: 'https://flutter.dev', - mimeType: 'text/html', + 'https://flutter.dev', + '

Hello Test!

', + 'text/html', + null, + null, )).called(1); }); @@ -582,10 +612,9 @@ void main() { .fromPlatformNavigationDelegateCreationParams( const PlatformNavigationDelegateCreationParams(), androidWebViewProxy: const AndroidWebViewProxy( - createAndroidWebViewClient: android_webview.WebViewClient.detached, - createAndroidWebChromeClient: - android_webview.WebChromeClient.detached, - createDownloadListener: android_webview.DownloadListener.detached, + newWebViewClient: TestWebViewClient.new, + newWebChromeClient: TestWebChromeClient.new, + newDownloadListener: TestDownloadListener.new, ), ), ); @@ -600,7 +629,8 @@ void main() { controller.setPlatformNavigationDelegate(androidNavigationDelegate); CapturingWebChromeClient.lastCreatedDelegate.onProgressChanged!( - android_webview.WebView.detached(), + TestWebChromeClient(), + MockWebView(), 42, ); @@ -615,13 +645,15 @@ void main() { // Should not cause LateInitializationError CapturingWebChromeClient.lastCreatedDelegate.onProgressChanged!( - android_webview.WebView.detached(), + TestWebChromeClient(), + MockWebView(), 42, ); }); test('setOnShowFileSelector', () async { late final Future> Function( + android_webview.WebChromeClient, android_webview.WebView webView, android_webview.FileChooserParams params, ) onShowFileChooserCallback; @@ -630,6 +662,7 @@ void main() { createWebChromeClient: ({ dynamic onProgressChanged, Future> Function( + android_webview.WebChromeClient, android_webview.WebView webView, android_webview.FileChooserParams params, )? onShowFileChooser, @@ -661,12 +694,14 @@ void main() { ); await onShowFileChooserCallback( - android_webview.WebView.detached(), - android_webview.FileChooserParams.detached( + MockWebChromeClient(), + MockWebView(), + android_webview.FileChooserParams.pigeon_detached( isCaptureEnabled: false, acceptTypes: const ['png'], filenameHint: 'filenameHint', mode: android_webview.FileChooserMode.open, + pigeon_instanceManager: testInstanceManager, ), ); @@ -677,23 +712,9 @@ void main() { }); test('setGeolocationPermissionsPromptCallbacks', () async { - final MockTestGeolocationPermissionsCallbackHostApi mockApi = - MockTestGeolocationPermissionsCallbackHostApi(); - TestGeolocationPermissionsCallbackHostApi.setup(mockApi); - - final InstanceManager instanceManager = InstanceManager( - onWeakReferenceRemoved: (_) {}, - ); - - final android_webview.GeolocationPermissionsCallback testCallback = - android_webview.GeolocationPermissionsCallback.detached( - instanceManager: instanceManager, - ); - - const int instanceIdentifier = 0; - instanceManager.addHostCreatedInstance(testCallback, instanceIdentifier); - - late final Future Function(String origin, + late final Future Function( + android_webview.WebChromeClient, + String origin, android_webview.GeolocationPermissionsCallback callback) onGeoPermissionHandle; late final void Function(android_webview.WebChromeClient instance) @@ -704,9 +725,11 @@ void main() { createWebChromeClient: ({ dynamic onProgressChanged, dynamic onShowFileChooser, - Future Function(String origin, - android_webview.GeolocationPermissionsCallback callback)? - onGeolocationPermissionsShowPrompt, + void Function( + android_webview.WebChromeClient, + String origin, + android_webview.GeolocationPermissionsCallback callback, + )? onGeolocationPermissionsShowPrompt, void Function(android_webview.WebChromeClient instance)? onGeolocationPermissionsHidePrompt, dynamic onPermissionRequest, @@ -717,7 +740,12 @@ void main() { dynamic onJsConfirm, dynamic onJsPrompt, }) { - onGeoPermissionHandle = onGeolocationPermissionsShowPrompt!; + onGeoPermissionHandle = + onGeolocationPermissionsShowPrompt! as Future Function( + android_webview.WebChromeClient, + String origin, + android_webview.GeolocationPermissionsCallback callback, + ); onGeoPermissionHidePromptHandle = onGeolocationPermissionsHidePrompt!; return mockWebChromeClient; }, @@ -740,34 +768,22 @@ void main() { }, ); + final android_webview.GeolocationPermissionsCallback mockCallback = + MockGeolocationPermissionsCallback(); await onGeoPermissionHandle( + MockWebChromeClient(), allowOrigin, - testCallback, + mockCallback, ); expect(isAllow, true); + verify(mockCallback.invoke(allowOrigin, isAllow, isAllow)); onGeoPermissionHidePromptHandle(mockWebChromeClient); expect(testValue, 'changed'); }); test('setCustomViewCallbacks', () async { - final MockTestCustomViewCallbackHostApi mockApi = - MockTestCustomViewCallbackHostApi(); - TestCustomViewCallbackHostApi.setup(mockApi); - - final InstanceManager instanceManager = InstanceManager( - onWeakReferenceRemoved: (_) {}, - ); - - final android_webview.CustomViewCallback testCallback = - android_webview.CustomViewCallback.detached( - instanceManager: instanceManager, - ); - - const int instanceIdentifier = 0; - instanceManager.addHostCreatedInstance(testCallback, instanceIdentifier); - late final void Function( android_webview.WebChromeClient instance, android_webview.View view, @@ -801,7 +817,10 @@ void main() { }, ); - final android_webview.View testView = android_webview.View.detached(); + final android_webview.View testView = + android_webview.View.pigeon_detached( + pigeon_instanceManager: testInstanceManager, + ); bool showCustomViewCalled = false; bool hideCustomViewCalled = false; @@ -818,7 +837,9 @@ void main() { onShowCustomViewHandle( mockWebChromeClient, testView, - android_webview.CustomViewCallback.detached(), + android_webview.CustomViewCallback.pigeon_detached( + pigeon_instanceManager: testInstanceManager, + ), ); expect(showCustomViewCalled, true); @@ -865,7 +886,7 @@ void main() { ); final List permissionTypes = [ - android_webview.PermissionRequest.audioCapture, + PermissionRequestConstants.audioCapture, ]; final MockPermissionRequest mockPermissionRequest = @@ -873,7 +894,8 @@ void main() { when(mockPermissionRequest.resources).thenReturn(permissionTypes); onPermissionRequestCallback( - android_webview.WebChromeClient.detached(), + android_webview.WebChromeClient.pigeon_detached( + pigeon_instanceManager: testInstanceManager), mockPermissionRequest, ); @@ -926,7 +948,9 @@ void main() { when(mockPermissionRequest.resources).thenReturn(['unknownType']); onPermissionRequestCallback( - android_webview.WebChromeClient.detached(), + android_webview.WebChromeClient.pigeon_detached( + pigeon_instanceManager: testInstanceManager, + ), mockPermissionRequest, ); @@ -935,8 +959,12 @@ void main() { group('JavaScript Dialog', () { test('setOnJavaScriptAlertDialog', () async { - late final Future Function(String url, String message) - onJsAlertCallback; + late final Future Function( + android_webview.WebChromeClient, + android_webview.WebView, + String url, + String message, + ) onJsAlertCallback; final MockWebChromeClient mockWebChromeClient = MockWebChromeClient(); @@ -949,7 +977,9 @@ void main() { dynamic onPermissionRequest, dynamic onShowCustomView, dynamic onHideCustomView, - Future Function(String url, String message)? onJsAlert, + Future Function(android_webview.WebChromeClient, + android_webview.WebView, String url, String message)? + onJsAlert, dynamic onJsConfirm, dynamic onJsPrompt, dynamic onConsoleMessage, @@ -967,13 +997,21 @@ void main() { }); const String callbackMessage = 'Message'; - await onJsAlertCallback('', callbackMessage); + await onJsAlertCallback( + MockWebChromeClient(), + MockWebView(), + '', + callbackMessage, + ); expect(message, callbackMessage); }); test('setOnJavaScriptConfirmDialog', () async { - late final Future Function(String url, String message) - onJsConfirmCallback; + late final Future Function( + android_webview.WebChromeClient, + android_webview.WebView, + String url, + String message) onJsConfirmCallback; final MockWebChromeClient mockWebChromeClient = MockWebChromeClient(); @@ -987,7 +1025,9 @@ void main() { dynamic onShowCustomView, dynamic onHideCustomView, dynamic onJsAlert, - Future Function(String url, String message)? onJsConfirm, + Future Function(android_webview.WebChromeClient, + android_webview.WebView, String url, String message)? + onJsConfirm, dynamic onJsPrompt, dynamic onConsoleMessage, }) { @@ -1005,15 +1045,20 @@ void main() { }); const String callbackMessage = 'Message'; - final bool returnValue = await onJsConfirmCallback('', callbackMessage); + final bool returnValue = await onJsConfirmCallback( + MockWebChromeClient(), MockWebView(), '', callbackMessage); expect(message, callbackMessage); expect(returnValue, callbackReturnValue); }); test('setOnJavaScriptTextInputDialog', () async { - late final Future Function( - String url, String message, String defaultValue) onJsPromptCallback; + late final Future Function( + android_webview.WebChromeClient, + android_webview.WebView, + String url, + String message, + String defaultValue) onJsPromptCallback; final MockWebChromeClient mockWebChromeClient = MockWebChromeClient(); final AndroidWebViewController controller = createControllerWithMocks( @@ -1027,9 +1072,13 @@ void main() { dynamic onHideCustomView, dynamic onJsAlert, dynamic onJsConfirm, - Future Function( - String url, String message, String defaultText)? - onJsPrompt, + Future Function( + android_webview.WebChromeClient, + android_webview.WebView, + String url, + String message, + String defaultText, + )? onJsPrompt, dynamic onConsoleMessage, }) { onJsPromptCallback = onJsPrompt!; @@ -1050,8 +1099,12 @@ void main() { const String callbackMessage = 'Message'; const String callbackDefaultText = 'Default Text'; - final String returnValue = - await onJsPromptCallback('', callbackMessage, callbackDefaultText); + final String? returnValue = await onJsPromptCallback( + MockWebChromeClient(), + MockWebView(), + '', + callbackMessage, + callbackDefaultText); expect(message, callbackMessage); expect(defaultText, callbackDefaultText); @@ -1098,56 +1151,61 @@ void main() { onConsoleMessageCallback( mockWebChromeClient, - ConsoleMessage( + android_webview.ConsoleMessage.pigeon_detached( lineNumber: 42, message: 'Debug message', - level: ConsoleMessageLevel.debug, + level: android_webview.ConsoleMessageLevel.debug, sourceId: 'source', + pigeon_instanceManager: testInstanceManager, ), ); onConsoleMessageCallback( mockWebChromeClient, - ConsoleMessage( + android_webview.ConsoleMessage.pigeon_detached( lineNumber: 42, message: 'Error message', - level: ConsoleMessageLevel.error, + level: android_webview.ConsoleMessageLevel.error, sourceId: 'source', + pigeon_instanceManager: testInstanceManager, ), ); onConsoleMessageCallback( mockWebChromeClient, - ConsoleMessage( + android_webview.ConsoleMessage.pigeon_detached( lineNumber: 42, message: 'Log message', - level: ConsoleMessageLevel.log, + level: android_webview.ConsoleMessageLevel.log, sourceId: 'source', + pigeon_instanceManager: testInstanceManager, ), ); onConsoleMessageCallback( mockWebChromeClient, - ConsoleMessage( + android_webview.ConsoleMessage.pigeon_detached( lineNumber: 42, message: 'Tip message', - level: ConsoleMessageLevel.tip, + level: android_webview.ConsoleMessageLevel.tip, sourceId: 'source', + pigeon_instanceManager: testInstanceManager, ), ); onConsoleMessageCallback( mockWebChromeClient, - ConsoleMessage( - lineNumber: 42, - message: 'Warning message', - level: ConsoleMessageLevel.warning, - sourceId: 'source', - ), + android_webview.ConsoleMessage.pigeon_detached( + lineNumber: 42, + message: 'Warning message', + level: android_webview.ConsoleMessageLevel.warning, + sourceId: 'source', + pigeon_instanceManager: testInstanceManager), ); onConsoleMessageCallback( mockWebChromeClient, - ConsoleMessage( + android_webview.ConsoleMessage.pigeon_detached( lineNumber: 42, message: 'Unknown message', - level: ConsoleMessageLevel.unknown, + level: android_webview.ConsoleMessageLevel.unknown, sourceId: 'source', + pigeon_instanceManager: testInstanceManager, ), ); @@ -1276,8 +1334,7 @@ void main() { await controller.addJavaScriptChannel(paramsWithMock); verifyInOrder([ - mockWebView.removeJavaScriptChannel( - argThat(isA())), + mockWebView.removeJavaScriptChannel('test'), mockWebView.addJavaScriptChannel( argThat(isA())), ]); @@ -1308,9 +1365,7 @@ void main() { .called(1); await controller.removeJavaScriptChannel('test'); - verify(mockWebView.removeJavaScriptChannel( - argThat(isA()))) - .called(1); + verify(mockWebView.removeJavaScriptChannel('test')).called(1); }); test('getTitle', () async { @@ -1351,8 +1406,15 @@ void main() { final AndroidWebViewController controller = createControllerWithMocks( mockWebView: mockWebView, ); - when(mockWebView.getScrollPosition()) - .thenAnswer((_) => Future.value(const Offset(4, 2))); + when(mockWebView.getScrollPosition()).thenAnswer( + (_) => Future.value( + android_webview.WebViewPoint.pigeon_detached( + x: 4, + y: 2, + pigeon_instanceManager: testInstanceManager, + ), + ), + ); final Offset position = await controller.getScrollPosition(); @@ -1361,16 +1423,6 @@ void main() { expect(position.dy, 2); }); - test('enableDebugging', () async { - final MockAndroidWebViewProxy mockProxy = MockAndroidWebViewProxy(); - - await AndroidWebViewController.enableDebugging( - true, - webViewProxy: mockProxy, - ); - verify(mockProxy.setWebContentsDebuggingEnabled(true)).called(1); - }); - test('enableZoom', () async { final MockWebView mockWebView = MockWebView(); final MockWebSettings mockSettings = MockWebSettings(); @@ -1395,7 +1447,7 @@ void main() { await controller.setBackgroundColor(Colors.blue); - verify(mockWebView.setBackgroundColor(Colors.blue)).called(1); + verify(mockWebView.setBackgroundColor(Colors.blue.value)).called(1); }); test('setJavaScriptMode', () async { @@ -1476,36 +1528,41 @@ void main() { test('webViewIdentifier', () { final MockWebView mockWebView = MockWebView(); - final InstanceManager instanceManager = InstanceManager( + + final android_webview.PigeonInstanceManager instanceManager = + android_webview.PigeonInstanceManager( onWeakReferenceRemoved: (_) {}, ); instanceManager.addHostCreatedInstance(mockWebView, 0); - android_webview.WebView.api = WebViewHostApiImpl( - instanceManager: instanceManager, - ); + when(mockWebView.pigeon_instanceManager).thenReturn(instanceManager); final AndroidWebViewController controller = createControllerWithMocks( mockWebView: mockWebView, ); - expect( - controller.webViewIdentifier, - 0, - ); - - android_webview.WebView.api = WebViewHostApiImpl(); + expect(controller.webViewIdentifier, 0); }); group('AndroidWebViewWidget', () { testWidgets('Builds Android view using supplied parameters', (WidgetTester tester) async { - final AndroidWebViewController controller = createControllerWithMocks(); + final android_webview.WebView mockWebView = MockWebView(); + final AndroidWebViewController controller = createControllerWithMocks( + mockWebView: mockWebView, + ); + + final android_webview.PigeonInstanceManager instanceManager = + android_webview.PigeonInstanceManager( + onWeakReferenceRemoved: (_) {}, + ); + instanceManager.addDartCreatedInstance(mockWebView); final AndroidWebViewWidget webViewWidget = AndroidWebViewWidget( AndroidWebViewWidgetCreationParams( key: const Key('test_web_view'), controller: controller, + instanceManager: instanceManager, ), ); @@ -1519,7 +1576,16 @@ void main() { testWidgets('displayWithHybridComposition is false', (WidgetTester tester) async { - final AndroidWebViewController controller = createControllerWithMocks(); + final android_webview.WebView mockWebView = MockWebView(); + final AndroidWebViewController controller = createControllerWithMocks( + mockWebView: mockWebView, + ); + + final android_webview.PigeonInstanceManager instanceManager = + android_webview.PigeonInstanceManager( + onWeakReferenceRemoved: (_) {}, + ); + instanceManager.addDartCreatedInstance(mockWebView); final MockPlatformViewsServiceProxy mockPlatformViewsService = MockPlatformViewsServiceProxy(); @@ -1540,6 +1606,7 @@ void main() { key: const Key('test_web_view'), controller: controller, platformViewsServiceProxy: mockPlatformViewsService, + instanceManager: instanceManager, ), ); @@ -1562,7 +1629,16 @@ void main() { testWidgets('displayWithHybridComposition is true', (WidgetTester tester) async { - final AndroidWebViewController controller = createControllerWithMocks(); + final android_webview.WebView mockWebView = MockWebView(); + final AndroidWebViewController controller = createControllerWithMocks( + mockWebView: mockWebView, + ); + + final android_webview.PigeonInstanceManager instanceManager = + android_webview.PigeonInstanceManager( + onWeakReferenceRemoved: (_) {}, + ); + instanceManager.addDartCreatedInstance(mockWebView); final MockPlatformViewsServiceProxy mockPlatformViewsService = MockPlatformViewsServiceProxy(); @@ -1584,6 +1660,7 @@ void main() { controller: controller, platformViewsServiceProxy: mockPlatformViewsService, displayWithHybridComposition: true, + instanceManager: instanceManager, ), ); @@ -1614,6 +1691,13 @@ void main() { android_webview.CustomViewCallback callback)? onShowCustomViewCallback; + final android_webview.WebView mockWebView = MockWebView(); + final android_webview.PigeonInstanceManager instanceManager = + android_webview.PigeonInstanceManager( + onWeakReferenceRemoved: (_) {}, + ); + instanceManager.addDartCreatedInstance(mockWebView); + final AndroidWebViewController controller = createControllerWithMocks( createWebChromeClient: ({ dynamic onProgressChanged, @@ -1635,6 +1719,7 @@ void main() { onShowCustomViewCallback = onShowCustomView; return mockWebChromeClient; }, + mockWebView: mockWebView, ); final MockPlatformViewsServiceProxy mockPlatformViewsService = @@ -1656,6 +1741,7 @@ void main() { key: const Key('test_web_view'), controller: controller, platformViewsServiceProxy: mockPlatformViewsService, + instanceManager: instanceManager, ), ); @@ -1668,10 +1754,15 @@ void main() { ); await tester.pumpAndSettle(); + // ignore: invalid_use_of_protected_member + when(mockWebView.pigeon_instanceManager).thenReturn(instanceManager); + onShowCustomViewCallback!( MockWebChromeClient(), - android_webview.WebView.detached(), - android_webview.CustomViewCallback.detached(), + mockWebView, + android_webview.CustomViewCallback.pigeon_detached( + pigeon_instanceManager: instanceManager, + ), ); await tester.pumpAndSettle(); @@ -1680,6 +1771,13 @@ void main() { testWidgets('PlatformView is recreated when the controller changes', (WidgetTester tester) async { + final android_webview.WebView mockWebView = MockWebView(); + final android_webview.PigeonInstanceManager instanceManager = + android_webview.PigeonInstanceManager( + onWeakReferenceRemoved: (_) {}, + ); + instanceManager.addDartCreatedInstance(mockWebView); + final MockPlatformViewsServiceProxy mockPlatformViewsService = MockPlatformViewsServiceProxy(); @@ -1698,8 +1796,9 @@ void main() { builder: (BuildContext context) { return AndroidWebViewWidget( AndroidWebViewWidgetCreationParams( - controller: createControllerWithMocks(), + controller: createControllerWithMocks(mockWebView: mockWebView), platformViewsServiceProxy: mockPlatformViewsService, + instanceManager: instanceManager, ), ).build(context); }, @@ -1721,8 +1820,9 @@ void main() { builder: (BuildContext context) { return AndroidWebViewWidget( AndroidWebViewWidgetCreationParams( - controller: createControllerWithMocks(), + controller: createControllerWithMocks(mockWebView: mockWebView), platformViewsServiceProxy: mockPlatformViewsService, + instanceManager: instanceManager, ), ).build(context); }, @@ -1744,10 +1844,19 @@ void main() { testWidgets( 'PlatformView does not rebuild when creation params stay the same', (WidgetTester tester) async { + final android_webview.WebView mockWebView = MockWebView(); + final android_webview.PigeonInstanceManager instanceManager = + android_webview.PigeonInstanceManager( + onWeakReferenceRemoved: (_) {}, + ); + instanceManager.addDartCreatedInstance(mockWebView); + final MockPlatformViewsServiceProxy mockPlatformViewsService = MockPlatformViewsServiceProxy(); - final AndroidWebViewController controller = createControllerWithMocks(); + final AndroidWebViewController controller = createControllerWithMocks( + mockWebView: mockWebView, + ); when( mockPlatformViewsService.initSurfaceAndroidView( @@ -1766,6 +1875,7 @@ void main() { AndroidWebViewWidgetCreationParams( controller: controller, platformViewsServiceProxy: mockPlatformViewsService, + instanceManager: instanceManager, ), ).build(context); }, @@ -1789,6 +1899,7 @@ void main() { AndroidWebViewWidgetCreationParams( controller: controller, platformViewsServiceProxy: mockPlatformViewsService, + instanceManager: instanceManager, ), ).build(context); }, @@ -1811,13 +1922,23 @@ void main() { group('AndroidCustomViewWidget', () { testWidgets('Builds Android custom view using supplied parameters', (WidgetTester tester) async { - final AndroidWebViewController controller = createControllerWithMocks(); + final android_webview.WebView mockWebView = MockWebView(); + final android_webview.PigeonInstanceManager instanceManager = + android_webview.PigeonInstanceManager( + onWeakReferenceRemoved: (_) {}, + ); + instanceManager.addDartCreatedInstance(mockWebView); + + final AndroidWebViewController controller = createControllerWithMocks( + mockWebView: mockWebView, + ); final AndroidCustomViewWidget customViewWidget = AndroidCustomViewWidget.private( key: const Key('test_custom_view'), - customView: android_webview.View.detached(), + customView: mockWebView, controller: controller, + instanceManager: instanceManager, ); await tester.pumpWidget(Builder( @@ -1830,7 +1951,16 @@ void main() { testWidgets('displayWithHybridComposition should be false', (WidgetTester tester) async { - final AndroidWebViewController controller = createControllerWithMocks(); + final android_webview.WebView mockWebView = MockWebView(); + final android_webview.PigeonInstanceManager instanceManager = + android_webview.PigeonInstanceManager( + onWeakReferenceRemoved: (_) {}, + ); + instanceManager.addDartCreatedInstance(mockWebView); + + final AndroidWebViewController controller = createControllerWithMocks( + mockWebView: mockWebView, + ); final MockPlatformViewsServiceProxy mockPlatformViewsService = MockPlatformViewsServiceProxy(); @@ -1849,8 +1979,9 @@ void main() { final AndroidCustomViewWidget customViewWidget = AndroidCustomViewWidget.private( controller: controller, - customView: android_webview.View.detached(), + customView: mockWebView, platformViewsServiceProxy: mockPlatformViewsService, + instanceManager: instanceManager, ); await tester.pumpWidget(Builder( @@ -1871,3 +2002,58 @@ void main() { }); }); } + +/// Creates a PigeonInstanceManager that doesn't make a call to Java when an +/// object is garbage collected. Also, `PigeonInstanceManager.instance` makes +/// a call to Java, so this InstanceManager is used to prevent that. +final android_webview.PigeonInstanceManager testInstanceManager = + android_webview.PigeonInstanceManager(onWeakReferenceRemoved: (_) {}); + +class TestWebViewClient extends android_webview.WebViewClient { + TestWebViewClient({ + super.onPageStarted, + super.onPageFinished, + super.onReceivedHttpError, + super.onReceivedRequestError, + super.onReceivedRequestErrorCompat, + super.onReceivedError, + super.requestLoading, + super.urlLoading, + super.doUpdateVisitedHistory, + super.onReceivedHttpAuthRequest, + }) : super.pigeon_detached( + pigeon_instanceManager: android_webview.PigeonInstanceManager( + onWeakReferenceRemoved: (_) {}, + ), + ); +} + +class TestWebChromeClient extends android_webview.WebChromeClient { + TestWebChromeClient({ + super.onProgressChanged, + super.onShowFileChooser, + super.onPermissionRequest, + super.onShowCustomView, + super.onHideCustomView, + super.onGeolocationPermissionsShowPrompt, + super.onGeolocationPermissionsHidePrompt, + super.onConsoleMessage, + super.onJsAlert, + super.onJsConfirm, + super.onJsPrompt, + }) : super.pigeon_detached( + pigeon_instanceManager: android_webview.PigeonInstanceManager( + onWeakReferenceRemoved: (_) {}, + ), + ); +} + +class TestDownloadListener extends android_webview.DownloadListener { + TestDownloadListener({ + required super.onDownloadStart, + }) : super.pigeon_detached( + pigeon_instanceManager: android_webview.PigeonInstanceManager( + onWeakReferenceRemoved: (_) {}, + ), + ); +} diff --git a/packages/webview_flutter/webview_flutter_android/test/android_webview_controller_test.mocks.dart b/packages/webview_flutter/webview_flutter_android/test/android_webview_controller_test.mocks.dart index 73c513c8af33..d0254f2bd801 100644 --- a/packages/webview_flutter/webview_flutter_android/test/android_webview_controller_test.mocks.dart +++ b/packages/webview_flutter/webview_flutter_android/test/android_webview_controller_test.mocks.dart @@ -3,27 +3,24 @@ // Do not manually edit this file. // ignore_for_file: no_leading_underscores_for_library_prefixes -import 'dart:async' as _i9; -import 'dart:typed_data' as _i14; +import 'dart:async' as _i8; +import 'dart:typed_data' as _i13; import 'dart:ui' as _i4; -import 'package:flutter/foundation.dart' as _i11; -import 'package:flutter/gestures.dart' as _i12; -import 'package:flutter/services.dart' as _i7; +import 'package:flutter/foundation.dart' as _i10; +import 'package:flutter/gestures.dart' as _i11; +import 'package:flutter/services.dart' as _i6; import 'package:mockito/mockito.dart' as _i1; -import 'package:mockito/src/dummies.dart' as _i13; -import 'package:webview_flutter_android/src/android_proxy.dart' as _i10; -import 'package:webview_flutter_android/src/android_webview.dart' as _i2; +import 'package:mockito/src/dummies.dart' as _i12; +import 'package:webview_flutter_android/src/android_proxy.dart' as _i9; +import 'package:webview_flutter_android/src/android_webkit.g.dart' as _i2; import 'package:webview_flutter_android/src/android_webview_controller.dart' - as _i8; -import 'package:webview_flutter_android/src/instance_manager.dart' as _i5; + as _i7; import 'package:webview_flutter_android/src/platform_views_service_proxy.dart' - as _i6; + as _i5; import 'package:webview_flutter_platform_interface/webview_flutter_platform_interface.dart' as _i3; -import 'test_android_webview.g.dart' as _i15; - // ignore_for_file: type=lint // ignore_for_file: avoid_redundant_argument_values // ignore_for_file: avoid_setters_without_getters @@ -121,9 +118,30 @@ class _FakeWebView_7 extends _i1.SmartFake implements _i2.WebView { ); } -class _FakeFlutterAssetManager_8 extends _i1.SmartFake +class _FakeJavaScriptChannel_8 extends _i1.SmartFake + implements _i2.JavaScriptChannel { + _FakeJavaScriptChannel_8( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeCookieManager_9 extends _i1.SmartFake implements _i2.CookieManager { + _FakeCookieManager_9( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeFlutterAssetManager_10 extends _i1.SmartFake implements _i2.FlutterAssetManager { - _FakeFlutterAssetManager_8( + _FakeFlutterAssetManager_10( Object parent, Invocation parentInvocation, ) : super( @@ -132,9 +150,8 @@ class _FakeFlutterAssetManager_8 extends _i1.SmartFake ); } -class _FakeJavaScriptChannel_9 extends _i1.SmartFake - implements _i2.JavaScriptChannel { - _FakeJavaScriptChannel_9( +class _FakeWebStorage_11 extends _i1.SmartFake implements _i2.WebStorage { + _FakeWebStorage_11( Object parent, Invocation parentInvocation, ) : super( @@ -143,9 +160,9 @@ class _FakeJavaScriptChannel_9 extends _i1.SmartFake ); } -class _FakeInstanceManager_10 extends _i1.SmartFake - implements _i5.InstanceManager { - _FakeInstanceManager_10( +class _FakePigeonInstanceManager_12 extends _i1.SmartFake + implements _i2.PigeonInstanceManager { + _FakePigeonInstanceManager_12( Object parent, Invocation parentInvocation, ) : super( @@ -154,9 +171,9 @@ class _FakeInstanceManager_10 extends _i1.SmartFake ); } -class _FakePlatformViewsServiceProxy_11 extends _i1.SmartFake - implements _i6.PlatformViewsServiceProxy { - _FakePlatformViewsServiceProxy_11( +class _FakePlatformViewsServiceProxy_13 extends _i1.SmartFake + implements _i5.PlatformViewsServiceProxy { + _FakePlatformViewsServiceProxy_13( Object parent, Invocation parentInvocation, ) : super( @@ -165,9 +182,19 @@ class _FakePlatformViewsServiceProxy_11 extends _i1.SmartFake ); } -class _FakePlatformWebViewController_12 extends _i1.SmartFake +class _FakePlatformWebViewController_14 extends _i1.SmartFake implements _i3.PlatformWebViewController { - _FakePlatformWebViewController_12( + _FakePlatformWebViewController_14( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeSize_15 extends _i1.SmartFake implements _i4.Size { + _FakeSize_15( Object parent, Invocation parentInvocation, ) : super( @@ -176,8 +203,9 @@ class _FakePlatformWebViewController_12 extends _i1.SmartFake ); } -class _FakeSize_13 extends _i1.SmartFake implements _i4.Size { - _FakeSize_13( +class _FakeGeolocationPermissionsCallback_16 extends _i1.SmartFake + implements _i2.GeolocationPermissionsCallback { + _FakeGeolocationPermissionsCallback_16( Object parent, Invocation parentInvocation, ) : super( @@ -186,9 +214,9 @@ class _FakeSize_13 extends _i1.SmartFake implements _i4.Size { ); } -class _FakePermissionRequest_14 extends _i1.SmartFake +class _FakePermissionRequest_17 extends _i1.SmartFake implements _i2.PermissionRequest { - _FakePermissionRequest_14( + _FakePermissionRequest_17( Object parent, Invocation parentInvocation, ) : super( @@ -197,9 +225,9 @@ class _FakePermissionRequest_14 extends _i1.SmartFake ); } -class _FakeExpensiveAndroidViewController_15 extends _i1.SmartFake - implements _i7.ExpensiveAndroidViewController { - _FakeExpensiveAndroidViewController_15( +class _FakeExpensiveAndroidViewController_18 extends _i1.SmartFake + implements _i6.ExpensiveAndroidViewController { + _FakeExpensiveAndroidViewController_18( Object parent, Invocation parentInvocation, ) : super( @@ -208,9 +236,9 @@ class _FakeExpensiveAndroidViewController_15 extends _i1.SmartFake ); } -class _FakeSurfaceAndroidViewController_16 extends _i1.SmartFake - implements _i7.SurfaceAndroidViewController { - _FakeSurfaceAndroidViewController_16( +class _FakeSurfaceAndroidViewController_19 extends _i1.SmartFake + implements _i6.SurfaceAndroidViewController { + _FakeSurfaceAndroidViewController_19( Object parent, Invocation parentInvocation, ) : super( @@ -219,8 +247,8 @@ class _FakeSurfaceAndroidViewController_16 extends _i1.SmartFake ); } -class _FakeWebSettings_17 extends _i1.SmartFake implements _i2.WebSettings { - _FakeWebSettings_17( +class _FakeWebSettings_20 extends _i1.SmartFake implements _i2.WebSettings { + _FakeWebSettings_20( Object parent, Invocation parentInvocation, ) : super( @@ -229,8 +257,8 @@ class _FakeWebSettings_17 extends _i1.SmartFake implements _i2.WebSettings { ); } -class _FakeWebStorage_18 extends _i1.SmartFake implements _i2.WebStorage { - _FakeWebStorage_18( +class _FakeWebViewPoint_21 extends _i1.SmartFake implements _i2.WebViewPoint { + _FakeWebViewPoint_21( Object parent, Invocation parentInvocation, ) : super( @@ -243,7 +271,7 @@ class _FakeWebStorage_18 extends _i1.SmartFake implements _i2.WebStorage { /// /// See the documentation for Mockito's code generation for more information. class MockAndroidNavigationDelegate extends _i1.Mock - implements _i8.AndroidNavigationDelegate { + implements _i7.AndroidNavigationDelegate { @override _i2.WebChromeClient get androidWebChromeClient => (super.noSuchMethod( Invocation.getter(#androidWebChromeClient), @@ -299,113 +327,113 @@ class MockAndroidNavigationDelegate extends _i1.Mock ) as _i3.PlatformNavigationDelegateCreationParams); @override - _i9.Future setOnLoadRequest(_i8.LoadRequestCallback? onLoadRequest) => + _i8.Future setOnLoadRequest(_i7.LoadRequestCallback? onLoadRequest) => (super.noSuchMethod( Invocation.method( #setOnLoadRequest, [onLoadRequest], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i9.Future setOnNavigationRequest( + _i8.Future setOnNavigationRequest( _i3.NavigationRequestCallback? onNavigationRequest) => (super.noSuchMethod( Invocation.method( #setOnNavigationRequest, [onNavigationRequest], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i9.Future setOnPageStarted(_i3.PageEventCallback? onPageStarted) => + _i8.Future setOnPageStarted(_i3.PageEventCallback? onPageStarted) => (super.noSuchMethod( Invocation.method( #setOnPageStarted, [onPageStarted], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i9.Future setOnPageFinished(_i3.PageEventCallback? onPageFinished) => + _i8.Future setOnPageFinished(_i3.PageEventCallback? onPageFinished) => (super.noSuchMethod( Invocation.method( #setOnPageFinished, [onPageFinished], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i9.Future setOnHttpError(_i3.HttpResponseErrorCallback? onHttpError) => + _i8.Future setOnHttpError(_i3.HttpResponseErrorCallback? onHttpError) => (super.noSuchMethod( Invocation.method( #setOnHttpError, [onHttpError], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i9.Future setOnProgress(_i3.ProgressCallback? onProgress) => + _i8.Future setOnProgress(_i3.ProgressCallback? onProgress) => (super.noSuchMethod( Invocation.method( #setOnProgress, [onProgress], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i9.Future setOnWebResourceError( + _i8.Future setOnWebResourceError( _i3.WebResourceErrorCallback? onWebResourceError) => (super.noSuchMethod( Invocation.method( #setOnWebResourceError, [onWebResourceError], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i9.Future setOnUrlChange(_i3.UrlChangeCallback? onUrlChange) => + _i8.Future setOnUrlChange(_i3.UrlChangeCallback? onUrlChange) => (super.noSuchMethod( Invocation.method( #setOnUrlChange, [onUrlChange], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i9.Future setOnHttpAuthRequest( + _i8.Future setOnHttpAuthRequest( _i3.HttpAuthRequestCallback? onHttpAuthRequest) => (super.noSuchMethod( Invocation.method( #setOnHttpAuthRequest, [onHttpAuthRequest], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); } /// A class which mocks [AndroidWebViewController]. /// /// See the documentation for Mockito's code generation for more information. class MockAndroidWebViewController extends _i1.Mock - implements _i8.AndroidWebViewController { + implements _i7.AndroidWebViewController { @override int get webViewIdentifier => (super.noSuchMethod( Invocation.getter(#webViewIdentifier), @@ -428,27 +456,27 @@ class MockAndroidWebViewController extends _i1.Mock ) as _i3.PlatformWebViewControllerCreationParams); @override - _i9.Future loadFile(String? absoluteFilePath) => (super.noSuchMethod( + _i8.Future loadFile(String? absoluteFilePath) => (super.noSuchMethod( Invocation.method( #loadFile, [absoluteFilePath], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i9.Future loadFlutterAsset(String? key) => (super.noSuchMethod( + _i8.Future loadFlutterAsset(String? key) => (super.noSuchMethod( Invocation.method( #loadFlutterAsset, [key], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i9.Future loadHtmlString( + _i8.Future loadHtmlString( String? html, { String? baseUrl, }) => @@ -458,181 +486,181 @@ class MockAndroidWebViewController extends _i1.Mock [html], {#baseUrl: baseUrl}, ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i9.Future loadRequest(_i3.LoadRequestParams? params) => + _i8.Future loadRequest(_i3.LoadRequestParams? params) => (super.noSuchMethod( Invocation.method( #loadRequest, [params], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i9.Future currentUrl() => (super.noSuchMethod( + _i8.Future currentUrl() => (super.noSuchMethod( Invocation.method( #currentUrl, [], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i9.Future canGoBack() => (super.noSuchMethod( + _i8.Future canGoBack() => (super.noSuchMethod( Invocation.method( #canGoBack, [], ), - returnValue: _i9.Future.value(false), - returnValueForMissingStub: _i9.Future.value(false), - ) as _i9.Future); + returnValue: _i8.Future.value(false), + returnValueForMissingStub: _i8.Future.value(false), + ) as _i8.Future); @override - _i9.Future canGoForward() => (super.noSuchMethod( + _i8.Future canGoForward() => (super.noSuchMethod( Invocation.method( #canGoForward, [], ), - returnValue: _i9.Future.value(false), - returnValueForMissingStub: _i9.Future.value(false), - ) as _i9.Future); + returnValue: _i8.Future.value(false), + returnValueForMissingStub: _i8.Future.value(false), + ) as _i8.Future); @override - _i9.Future goBack() => (super.noSuchMethod( + _i8.Future goBack() => (super.noSuchMethod( Invocation.method( #goBack, [], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i9.Future goForward() => (super.noSuchMethod( + _i8.Future goForward() => (super.noSuchMethod( Invocation.method( #goForward, [], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i9.Future reload() => (super.noSuchMethod( + _i8.Future reload() => (super.noSuchMethod( Invocation.method( #reload, [], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i9.Future clearCache() => (super.noSuchMethod( + _i8.Future clearCache() => (super.noSuchMethod( Invocation.method( #clearCache, [], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i9.Future clearLocalStorage() => (super.noSuchMethod( + _i8.Future clearLocalStorage() => (super.noSuchMethod( Invocation.method( #clearLocalStorage, [], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i9.Future setPlatformNavigationDelegate( + _i8.Future setPlatformNavigationDelegate( _i3.PlatformNavigationDelegate? handler) => (super.noSuchMethod( Invocation.method( #setPlatformNavigationDelegate, [handler], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i9.Future runJavaScript(String? javaScript) => (super.noSuchMethod( + _i8.Future runJavaScript(String? javaScript) => (super.noSuchMethod( Invocation.method( #runJavaScript, [javaScript], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i9.Future runJavaScriptReturningResult(String? javaScript) => + _i8.Future runJavaScriptReturningResult(String? javaScript) => (super.noSuchMethod( Invocation.method( #runJavaScriptReturningResult, [javaScript], ), - returnValue: _i9.Future.value(_FakeObject_5( + returnValue: _i8.Future.value(_FakeObject_5( this, Invocation.method( #runJavaScriptReturningResult, [javaScript], ), )), - returnValueForMissingStub: _i9.Future.value(_FakeObject_5( + returnValueForMissingStub: _i8.Future.value(_FakeObject_5( this, Invocation.method( #runJavaScriptReturningResult, [javaScript], ), )), - ) as _i9.Future); + ) as _i8.Future); @override - _i9.Future addJavaScriptChannel( + _i8.Future addJavaScriptChannel( _i3.JavaScriptChannelParams? javaScriptChannelParams) => (super.noSuchMethod( Invocation.method( #addJavaScriptChannel, [javaScriptChannelParams], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i9.Future removeJavaScriptChannel(String? javaScriptChannelName) => + _i8.Future removeJavaScriptChannel(String? javaScriptChannelName) => (super.noSuchMethod( Invocation.method( #removeJavaScriptChannel, [javaScriptChannelName], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i9.Future getTitle() => (super.noSuchMethod( + _i8.Future getTitle() => (super.noSuchMethod( Invocation.method( #getTitle, [], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i9.Future scrollTo( + _i8.Future scrollTo( int? x, int? y, ) => @@ -644,12 +672,12 @@ class MockAndroidWebViewController extends _i1.Mock y, ], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i9.Future scrollBy( + _i8.Future scrollBy( int? x, int? y, ) => @@ -661,121 +689,121 @@ class MockAndroidWebViewController extends _i1.Mock y, ], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i9.Future<_i4.Offset> getScrollPosition() => (super.noSuchMethod( + _i8.Future<_i4.Offset> getScrollPosition() => (super.noSuchMethod( Invocation.method( #getScrollPosition, [], ), - returnValue: _i9.Future<_i4.Offset>.value(_FakeOffset_6( + returnValue: _i8.Future<_i4.Offset>.value(_FakeOffset_6( this, Invocation.method( #getScrollPosition, [], ), )), - returnValueForMissingStub: _i9.Future<_i4.Offset>.value(_FakeOffset_6( + returnValueForMissingStub: _i8.Future<_i4.Offset>.value(_FakeOffset_6( this, Invocation.method( #getScrollPosition, [], ), )), - ) as _i9.Future<_i4.Offset>); + ) as _i8.Future<_i4.Offset>); @override - _i9.Future enableZoom(bool? enabled) => (super.noSuchMethod( + _i8.Future enableZoom(bool? enabled) => (super.noSuchMethod( Invocation.method( #enableZoom, [enabled], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i9.Future setBackgroundColor(_i4.Color? color) => (super.noSuchMethod( + _i8.Future setBackgroundColor(_i4.Color? color) => (super.noSuchMethod( Invocation.method( #setBackgroundColor, [color], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i9.Future setJavaScriptMode(_i3.JavaScriptMode? javaScriptMode) => + _i8.Future setJavaScriptMode(_i3.JavaScriptMode? javaScriptMode) => (super.noSuchMethod( Invocation.method( #setJavaScriptMode, [javaScriptMode], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i9.Future setUserAgent(String? userAgent) => (super.noSuchMethod( + _i8.Future setUserAgent(String? userAgent) => (super.noSuchMethod( Invocation.method( #setUserAgent, [userAgent], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i9.Future setOnScrollPositionChange( + _i8.Future setOnScrollPositionChange( void Function(_i3.ScrollPositionChange)? onScrollPositionChange) => (super.noSuchMethod( Invocation.method( #setOnScrollPositionChange, [onScrollPositionChange], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i9.Future setMediaPlaybackRequiresUserGesture(bool? require) => + _i8.Future setMediaPlaybackRequiresUserGesture(bool? require) => (super.noSuchMethod( Invocation.method( #setMediaPlaybackRequiresUserGesture, [require], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i9.Future setTextZoom(int? textZoom) => (super.noSuchMethod( + _i8.Future setTextZoom(int? textZoom) => (super.noSuchMethod( Invocation.method( #setTextZoom, [textZoom], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i9.Future setOnShowFileSelector( - _i9.Future> Function(_i8.FileSelectorParams)? + _i8.Future setOnShowFileSelector( + _i8.Future> Function(_i7.FileSelectorParams)? onShowFileSelector) => (super.noSuchMethod( Invocation.method( #setOnShowFileSelector, [onShowFileSelector], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i9.Future setOnPlatformPermissionRequest( + _i8.Future setOnPlatformPermissionRequest( void Function(_i3.PlatformWebViewPermissionRequest)? onPermissionRequest) => (super.noSuchMethod( @@ -783,14 +811,14 @@ class MockAndroidWebViewController extends _i1.Mock #setOnPlatformPermissionRequest, [onPermissionRequest], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i9.Future setGeolocationPermissionsPromptCallbacks({ - _i8.OnGeolocationPermissionsShowPrompt? onShowPrompt, - _i8.OnGeolocationPermissionsHidePrompt? onHidePrompt, + _i8.Future setGeolocationPermissionsPromptCallbacks({ + _i7.OnGeolocationPermissionsShowPrompt? onShowPrompt, + _i7.OnGeolocationPermissionsHidePrompt? onHidePrompt, }) => (super.noSuchMethod( Invocation.method( @@ -801,14 +829,14 @@ class MockAndroidWebViewController extends _i1.Mock #onHidePrompt: onHidePrompt, }, ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i9.Future setCustomWidgetCallbacks({ - required _i8.OnShowCustomWidgetCallback? onShowCustomWidget, - required _i8.OnHideCustomWidgetCallback? onHideCustomWidget, + _i8.Future setCustomWidgetCallbacks({ + required _i7.OnShowCustomWidgetCallback? onShowCustomWidget, + required _i7.OnHideCustomWidgetCallback? onHideCustomWidget, }) => (super.noSuchMethod( Invocation.method( @@ -819,88 +847,90 @@ class MockAndroidWebViewController extends _i1.Mock #onHideCustomWidget: onHideCustomWidget, }, ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i9.Future setOnConsoleMessage( + _i8.Future setOnConsoleMessage( void Function(_i3.JavaScriptConsoleMessage)? onConsoleMessage) => (super.noSuchMethod( Invocation.method( #setOnConsoleMessage, [onConsoleMessage], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i9.Future getUserAgent() => (super.noSuchMethod( + _i8.Future getUserAgent() => (super.noSuchMethod( Invocation.method( #getUserAgent, [], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i9.Future setOnJavaScriptAlertDialog( - _i9.Future Function(_i3.JavaScriptAlertDialogRequest)? + _i8.Future setOnJavaScriptAlertDialog( + _i8.Future Function(_i3.JavaScriptAlertDialogRequest)? onJavaScriptAlertDialog) => (super.noSuchMethod( Invocation.method( #setOnJavaScriptAlertDialog, [onJavaScriptAlertDialog], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i9.Future setOnJavaScriptConfirmDialog( - _i9.Future Function(_i3.JavaScriptConfirmDialogRequest)? + _i8.Future setOnJavaScriptConfirmDialog( + _i8.Future Function(_i3.JavaScriptConfirmDialogRequest)? onJavaScriptConfirmDialog) => (super.noSuchMethod( Invocation.method( #setOnJavaScriptConfirmDialog, [onJavaScriptConfirmDialog], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i9.Future setOnJavaScriptTextInputDialog( - _i9.Future Function(_i3.JavaScriptTextInputDialogRequest)? + _i8.Future setOnJavaScriptTextInputDialog( + _i8.Future Function(_i3.JavaScriptTextInputDialogRequest)? onJavaScriptTextInputDialog) => (super.noSuchMethod( Invocation.method( #setOnJavaScriptTextInputDialog, [onJavaScriptTextInputDialog], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); } /// A class which mocks [AndroidWebViewProxy]. /// /// See the documentation for Mockito's code generation for more information. class MockAndroidWebViewProxy extends _i1.Mock - implements _i10.AndroidWebViewProxy { + implements _i9.AndroidWebViewProxy { @override _i2.WebView Function( {void Function( + _i2.WebView, int, int, int, int, - )? onScrollChanged}) get createAndroidWebView => (super.noSuchMethod( - Invocation.getter(#createAndroidWebView), + )? onScrollChanged}) get newWebView => (super.noSuchMethod( + Invocation.getter(#newWebView), returnValue: ( {void Function( + _i2.WebView, int, int, int, @@ -908,10 +938,11 @@ class MockAndroidWebViewProxy extends _i1.Mock )? onScrollChanged}) => _FakeWebView_7( this, - Invocation.getter(#createAndroidWebView), + Invocation.getter(#newWebView), ), returnValueForMissingStub: ( {void Function( + _i2.WebView, int, int, int, @@ -919,10 +950,11 @@ class MockAndroidWebViewProxy extends _i1.Mock )? onScrollChanged}) => _FakeWebView_7( this, - Invocation.getter(#createAndroidWebView), + Invocation.getter(#newWebView), ), ) as _i2.WebView Function( {void Function( + _i2.WebView, int, int, int, @@ -930,430 +962,309 @@ class MockAndroidWebViewProxy extends _i1.Mock )? onScrollChanged})); @override - _i2.WebChromeClient Function({ - void Function( - _i2.WebChromeClient, - _i2.ConsoleMessage, - )? onConsoleMessage, - void Function(_i2.WebChromeClient)? onGeolocationPermissionsHidePrompt, - _i9.Future Function( - String, - _i2.GeolocationPermissionsCallback, - )? onGeolocationPermissionsShowPrompt, - void Function(_i2.WebChromeClient)? onHideCustomView, - _i9.Future Function( - String, - String, - )? onJsAlert, - _i9.Future Function( - String, - String, - )? onJsConfirm, - _i9.Future Function( + _i2.JavaScriptChannel Function({ + required String channelName, + required void Function( + _i2.JavaScriptChannel, String, - String, - String, - )? onJsPrompt, - void Function( - _i2.WebChromeClient, - _i2.PermissionRequest, - )? onPermissionRequest, - void Function( - _i2.WebView, - int, - )? onProgressChanged, - void Function( - _i2.WebChromeClient, - _i2.View, - _i2.CustomViewCallback, - )? onShowCustomView, - _i9.Future> Function( - _i2.WebView, - _i2.FileChooserParams, - )? onShowFileChooser, - }) get createAndroidWebChromeClient => (super.noSuchMethod( - Invocation.getter(#createAndroidWebChromeClient), + ) postMessage, + }) get newJavaScriptChannel => (super.noSuchMethod( + Invocation.getter(#newJavaScriptChannel), returnValue: ({ - void Function( - _i2.WebChromeClient, - _i2.ConsoleMessage, - )? onConsoleMessage, - void Function(_i2.WebChromeClient)? - onGeolocationPermissionsHidePrompt, - _i9.Future Function( - String, - _i2.GeolocationPermissionsCallback, - )? onGeolocationPermissionsShowPrompt, - void Function(_i2.WebChromeClient)? onHideCustomView, - _i9.Future Function( - String, - String, - )? onJsAlert, - _i9.Future Function( - String, - String, - )? onJsConfirm, - _i9.Future Function( - String, + required String channelName, + required void Function( + _i2.JavaScriptChannel, String, - String, - )? onJsPrompt, - void Function( - _i2.WebChromeClient, - _i2.PermissionRequest, - )? onPermissionRequest, - void Function( - _i2.WebView, - int, - )? onProgressChanged, - void Function( - _i2.WebChromeClient, - _i2.View, - _i2.CustomViewCallback, - )? onShowCustomView, - _i9.Future> Function( - _i2.WebView, - _i2.FileChooserParams, - )? onShowFileChooser, + ) postMessage, }) => - _FakeWebChromeClient_0( + _FakeJavaScriptChannel_8( this, - Invocation.getter(#createAndroidWebChromeClient), + Invocation.getter(#newJavaScriptChannel), ), returnValueForMissingStub: ({ - void Function( - _i2.WebChromeClient, - _i2.ConsoleMessage, - )? onConsoleMessage, - void Function(_i2.WebChromeClient)? - onGeolocationPermissionsHidePrompt, - _i9.Future Function( - String, - _i2.GeolocationPermissionsCallback, - )? onGeolocationPermissionsShowPrompt, - void Function(_i2.WebChromeClient)? onHideCustomView, - _i9.Future Function( - String, - String, - )? onJsAlert, - _i9.Future Function( + required String channelName, + required void Function( + _i2.JavaScriptChannel, String, - String, - )? onJsConfirm, - _i9.Future Function( - String, - String, - String, - )? onJsPrompt, - void Function( - _i2.WebChromeClient, - _i2.PermissionRequest, - )? onPermissionRequest, - void Function( - _i2.WebView, - int, - )? onProgressChanged, - void Function( - _i2.WebChromeClient, - _i2.View, - _i2.CustomViewCallback, - )? onShowCustomView, - _i9.Future> Function( - _i2.WebView, - _i2.FileChooserParams, - )? onShowFileChooser, + ) postMessage, }) => - _FakeWebChromeClient_0( + _FakeJavaScriptChannel_8( this, - Invocation.getter(#createAndroidWebChromeClient), + Invocation.getter(#newJavaScriptChannel), ), - ) as _i2.WebChromeClient Function({ - void Function( - _i2.WebChromeClient, - _i2.ConsoleMessage, - )? onConsoleMessage, - void Function(_i2.WebChromeClient)? onGeolocationPermissionsHidePrompt, - _i9.Future Function( - String, - _i2.GeolocationPermissionsCallback, - )? onGeolocationPermissionsShowPrompt, - void Function(_i2.WebChromeClient)? onHideCustomView, - _i9.Future Function( - String, - String, - )? onJsAlert, - _i9.Future Function( - String, - String, - )? onJsConfirm, - _i9.Future Function( - String, + ) as _i2.JavaScriptChannel Function({ + required String channelName, + required void Function( + _i2.JavaScriptChannel, String, - String, - )? onJsPrompt, - void Function( - _i2.WebChromeClient, - _i2.PermissionRequest, - )? onPermissionRequest, - void Function( - _i2.WebView, - int, - )? onProgressChanged, - void Function( - _i2.WebChromeClient, - _i2.View, - _i2.CustomViewCallback, - )? onShowCustomView, - _i9.Future> Function( - _i2.WebView, - _i2.FileChooserParams, - )? onShowFileChooser, + ) postMessage, })); @override _i2.WebViewClient Function({ void Function( + _i2.WebViewClient, _i2.WebView, String, bool, )? doUpdateVisitedHistory, void Function( + _i2.WebViewClient, _i2.WebView, String, )? onPageFinished, void Function( + _i2.WebViewClient, _i2.WebView, String, )? onPageStarted, void Function( + _i2.WebViewClient, _i2.WebView, int, String, String, )? onReceivedError, void Function( + _i2.WebViewClient, _i2.WebView, _i2.HttpAuthHandler, String, String, )? onReceivedHttpAuthRequest, void Function( + _i2.WebViewClient, _i2.WebView, _i2.WebResourceRequest, _i2.WebResourceResponse, )? onReceivedHttpError, void Function( + _i2.WebViewClient, _i2.WebView, _i2.WebResourceRequest, _i2.WebResourceError, )? onReceivedRequestError, void Function( + _i2.WebViewClient, + _i2.WebView, + _i2.WebResourceRequest, + _i2.WebResourceErrorCompat, + )? onReceivedRequestErrorCompat, + void Function( + _i2.WebViewClient, _i2.WebView, _i2.WebResourceRequest, )? requestLoading, void Function( + _i2.WebViewClient, _i2.WebView, String, )? urlLoading, - }) get createAndroidWebViewClient => (super.noSuchMethod( - Invocation.getter(#createAndroidWebViewClient), + }) get newWebViewClient => (super.noSuchMethod( + Invocation.getter(#newWebViewClient), returnValue: ({ void Function( + _i2.WebViewClient, _i2.WebView, String, bool, )? doUpdateVisitedHistory, void Function( + _i2.WebViewClient, _i2.WebView, String, )? onPageFinished, void Function( + _i2.WebViewClient, _i2.WebView, String, )? onPageStarted, void Function( + _i2.WebViewClient, _i2.WebView, int, String, String, )? onReceivedError, void Function( + _i2.WebViewClient, _i2.WebView, _i2.HttpAuthHandler, String, String, )? onReceivedHttpAuthRequest, void Function( + _i2.WebViewClient, _i2.WebView, _i2.WebResourceRequest, _i2.WebResourceResponse, )? onReceivedHttpError, void Function( + _i2.WebViewClient, _i2.WebView, _i2.WebResourceRequest, _i2.WebResourceError, )? onReceivedRequestError, void Function( + _i2.WebViewClient, + _i2.WebView, + _i2.WebResourceRequest, + _i2.WebResourceErrorCompat, + )? onReceivedRequestErrorCompat, + void Function( + _i2.WebViewClient, _i2.WebView, _i2.WebResourceRequest, )? requestLoading, void Function( + _i2.WebViewClient, _i2.WebView, String, )? urlLoading, }) => _FakeWebViewClient_1( this, - Invocation.getter(#createAndroidWebViewClient), + Invocation.getter(#newWebViewClient), ), returnValueForMissingStub: ({ void Function( + _i2.WebViewClient, _i2.WebView, String, bool, )? doUpdateVisitedHistory, void Function( + _i2.WebViewClient, _i2.WebView, String, )? onPageFinished, void Function( + _i2.WebViewClient, _i2.WebView, String, )? onPageStarted, void Function( + _i2.WebViewClient, _i2.WebView, int, String, String, )? onReceivedError, void Function( + _i2.WebViewClient, _i2.WebView, _i2.HttpAuthHandler, String, String, )? onReceivedHttpAuthRequest, void Function( + _i2.WebViewClient, _i2.WebView, _i2.WebResourceRequest, _i2.WebResourceResponse, )? onReceivedHttpError, void Function( + _i2.WebViewClient, _i2.WebView, _i2.WebResourceRequest, _i2.WebResourceError, )? onReceivedRequestError, void Function( + _i2.WebViewClient, + _i2.WebView, + _i2.WebResourceRequest, + _i2.WebResourceErrorCompat, + )? onReceivedRequestErrorCompat, + void Function( + _i2.WebViewClient, _i2.WebView, _i2.WebResourceRequest, )? requestLoading, void Function( + _i2.WebViewClient, _i2.WebView, String, )? urlLoading, }) => _FakeWebViewClient_1( this, - Invocation.getter(#createAndroidWebViewClient), + Invocation.getter(#newWebViewClient), ), ) as _i2.WebViewClient Function({ void Function( + _i2.WebViewClient, _i2.WebView, String, bool, )? doUpdateVisitedHistory, void Function( + _i2.WebViewClient, _i2.WebView, String, )? onPageFinished, void Function( + _i2.WebViewClient, _i2.WebView, String, )? onPageStarted, void Function( + _i2.WebViewClient, _i2.WebView, int, String, String, )? onReceivedError, void Function( + _i2.WebViewClient, _i2.WebView, _i2.HttpAuthHandler, String, String, )? onReceivedHttpAuthRequest, void Function( + _i2.WebViewClient, _i2.WebView, _i2.WebResourceRequest, _i2.WebResourceResponse, )? onReceivedHttpError, void Function( + _i2.WebViewClient, _i2.WebView, _i2.WebResourceRequest, _i2.WebResourceError, )? onReceivedRequestError, void Function( + _i2.WebViewClient, + _i2.WebView, + _i2.WebResourceRequest, + _i2.WebResourceErrorCompat, + )? onReceivedRequestErrorCompat, + void Function( + _i2.WebViewClient, _i2.WebView, _i2.WebResourceRequest, )? requestLoading, void Function( + _i2.WebViewClient, _i2.WebView, String, )? urlLoading, })); - @override - _i2.FlutterAssetManager Function() get createFlutterAssetManager => - (super.noSuchMethod( - Invocation.getter(#createFlutterAssetManager), - returnValue: () => _FakeFlutterAssetManager_8( - this, - Invocation.getter(#createFlutterAssetManager), - ), - returnValueForMissingStub: () => _FakeFlutterAssetManager_8( - this, - Invocation.getter(#createFlutterAssetManager), - ), - ) as _i2.FlutterAssetManager Function()); - - @override - _i2.JavaScriptChannel Function( - String, { - required void Function(String) postMessage, - }) get createJavaScriptChannel => (super.noSuchMethod( - Invocation.getter(#createJavaScriptChannel), - returnValue: ( - String channelName, { - required void Function(String) postMessage, - }) => - _FakeJavaScriptChannel_9( - this, - Invocation.getter(#createJavaScriptChannel), - ), - returnValueForMissingStub: ( - String channelName, { - required void Function(String) postMessage, - }) => - _FakeJavaScriptChannel_9( - this, - Invocation.getter(#createJavaScriptChannel), - ), - ) as _i2.JavaScriptChannel Function( - String, { - required void Function(String) postMessage, - })); - @override _i2.DownloadListener Function( {required void Function( + _i2.DownloadListener, String, String, String, String, int, - ) onDownloadStart}) get createDownloadListener => (super.noSuchMethod( - Invocation.getter(#createDownloadListener), + ) onDownloadStart}) get newDownloadListener => (super.noSuchMethod( + Invocation.getter(#newDownloadListener), returnValue: ( {required void Function( + _i2.DownloadListener, String, String, String, @@ -1362,10 +1273,11 @@ class MockAndroidWebViewProxy extends _i1.Mock ) onDownloadStart}) => _FakeDownloadListener_2( this, - Invocation.getter(#createDownloadListener), + Invocation.getter(#newDownloadListener), ), returnValueForMissingStub: ( {required void Function( + _i2.DownloadListener, String, String, String, @@ -1374,10 +1286,11 @@ class MockAndroidWebViewProxy extends _i1.Mock ) onDownloadStart}) => _FakeDownloadListener_2( this, - Invocation.getter(#createDownloadListener), + Invocation.getter(#newDownloadListener), ), ) as _i2.DownloadListener Function( {required void Function( + _i2.DownloadListener, String, String, String, @@ -1386,92 +1299,346 @@ class MockAndroidWebViewProxy extends _i1.Mock ) onDownloadStart})); @override - _i9.Future setWebContentsDebuggingEnabled(bool? enabled) => - (super.noSuchMethod( - Invocation.method( - #setWebContentsDebuggingEnabled, - [enabled], - ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); -} - -/// A class which mocks [AndroidWebViewWidgetCreationParams]. -/// -/// See the documentation for Mockito's code generation for more information. -// ignore: must_be_immutable -class MockAndroidWebViewWidgetCreationParams extends _i1.Mock - implements _i8.AndroidWebViewWidgetCreationParams { - @override - _i5.InstanceManager get instanceManager => (super.noSuchMethod( - Invocation.getter(#instanceManager), - returnValue: _FakeInstanceManager_10( - this, - Invocation.getter(#instanceManager), - ), - returnValueForMissingStub: _FakeInstanceManager_10( - this, - Invocation.getter(#instanceManager), - ), - ) as _i5.InstanceManager); - - @override - _i6.PlatformViewsServiceProxy get platformViewsServiceProxy => - (super.noSuchMethod( - Invocation.getter(#platformViewsServiceProxy), - returnValue: _FakePlatformViewsServiceProxy_11( - this, - Invocation.getter(#platformViewsServiceProxy), - ), - returnValueForMissingStub: _FakePlatformViewsServiceProxy_11( - this, - Invocation.getter(#platformViewsServiceProxy), - ), - ) as _i6.PlatformViewsServiceProxy); - - @override - bool get displayWithHybridComposition => (super.noSuchMethod( - Invocation.getter(#displayWithHybridComposition), - returnValue: false, - returnValueForMissingStub: false, - ) as bool); - - @override - _i3.PlatformWebViewController get controller => (super.noSuchMethod( - Invocation.getter(#controller), - returnValue: _FakePlatformWebViewController_12( - this, - Invocation.getter(#controller), - ), - returnValueForMissingStub: _FakePlatformWebViewController_12( - this, - Invocation.getter(#controller), - ), - ) as _i3.PlatformWebViewController); - - @override - _i4.TextDirection get layoutDirection => (super.noSuchMethod( - Invocation.getter(#layoutDirection), - returnValue: _i4.TextDirection.rtl, - returnValueForMissingStub: _i4.TextDirection.rtl, - ) as _i4.TextDirection); - + _i2.WebChromeClient Function({ + void Function( + _i2.WebChromeClient, + _i2.ConsoleMessage, + )? onConsoleMessage, + void Function(_i2.WebChromeClient)? onGeolocationPermissionsHidePrompt, + void Function( + _i2.WebChromeClient, + String, + _i2.GeolocationPermissionsCallback, + )? onGeolocationPermissionsShowPrompt, + void Function(_i2.WebChromeClient)? onHideCustomView, + _i8.Future Function( + _i2.WebChromeClient, + _i2.WebView, + String, + String, + )? onJsAlert, + _i8.Future Function( + _i2.WebChromeClient, + _i2.WebView, + String, + String, + )? onJsConfirm, + _i8.Future Function( + _i2.WebChromeClient, + _i2.WebView, + String, + String, + String, + )? onJsPrompt, + void Function( + _i2.WebChromeClient, + _i2.PermissionRequest, + )? onPermissionRequest, + void Function( + _i2.WebChromeClient, + _i2.WebView, + int, + )? onProgressChanged, + void Function( + _i2.WebChromeClient, + _i2.View, + _i2.CustomViewCallback, + )? onShowCustomView, + _i8.Future> Function( + _i2.WebChromeClient, + _i2.WebView, + _i2.FileChooserParams, + )? onShowFileChooser, + }) get newWebChromeClient => (super.noSuchMethod( + Invocation.getter(#newWebChromeClient), + returnValue: ({ + void Function( + _i2.WebChromeClient, + _i2.ConsoleMessage, + )? onConsoleMessage, + void Function(_i2.WebChromeClient)? + onGeolocationPermissionsHidePrompt, + void Function( + _i2.WebChromeClient, + String, + _i2.GeolocationPermissionsCallback, + )? onGeolocationPermissionsShowPrompt, + void Function(_i2.WebChromeClient)? onHideCustomView, + _i8.Future Function( + _i2.WebChromeClient, + _i2.WebView, + String, + String, + )? onJsAlert, + _i8.Future Function( + _i2.WebChromeClient, + _i2.WebView, + String, + String, + )? onJsConfirm, + _i8.Future Function( + _i2.WebChromeClient, + _i2.WebView, + String, + String, + String, + )? onJsPrompt, + void Function( + _i2.WebChromeClient, + _i2.PermissionRequest, + )? onPermissionRequest, + void Function( + _i2.WebChromeClient, + _i2.WebView, + int, + )? onProgressChanged, + void Function( + _i2.WebChromeClient, + _i2.View, + _i2.CustomViewCallback, + )? onShowCustomView, + _i8.Future> Function( + _i2.WebChromeClient, + _i2.WebView, + _i2.FileChooserParams, + )? onShowFileChooser, + }) => + _FakeWebChromeClient_0( + this, + Invocation.getter(#newWebChromeClient), + ), + returnValueForMissingStub: ({ + void Function( + _i2.WebChromeClient, + _i2.ConsoleMessage, + )? onConsoleMessage, + void Function(_i2.WebChromeClient)? + onGeolocationPermissionsHidePrompt, + void Function( + _i2.WebChromeClient, + String, + _i2.GeolocationPermissionsCallback, + )? onGeolocationPermissionsShowPrompt, + void Function(_i2.WebChromeClient)? onHideCustomView, + _i8.Future Function( + _i2.WebChromeClient, + _i2.WebView, + String, + String, + )? onJsAlert, + _i8.Future Function( + _i2.WebChromeClient, + _i2.WebView, + String, + String, + )? onJsConfirm, + _i8.Future Function( + _i2.WebChromeClient, + _i2.WebView, + String, + String, + String, + )? onJsPrompt, + void Function( + _i2.WebChromeClient, + _i2.PermissionRequest, + )? onPermissionRequest, + void Function( + _i2.WebChromeClient, + _i2.WebView, + int, + )? onProgressChanged, + void Function( + _i2.WebChromeClient, + _i2.View, + _i2.CustomViewCallback, + )? onShowCustomView, + _i8.Future> Function( + _i2.WebChromeClient, + _i2.WebView, + _i2.FileChooserParams, + )? onShowFileChooser, + }) => + _FakeWebChromeClient_0( + this, + Invocation.getter(#newWebChromeClient), + ), + ) as _i2.WebChromeClient Function({ + void Function( + _i2.WebChromeClient, + _i2.ConsoleMessage, + )? onConsoleMessage, + void Function(_i2.WebChromeClient)? onGeolocationPermissionsHidePrompt, + void Function( + _i2.WebChromeClient, + String, + _i2.GeolocationPermissionsCallback, + )? onGeolocationPermissionsShowPrompt, + void Function(_i2.WebChromeClient)? onHideCustomView, + _i8.Future Function( + _i2.WebChromeClient, + _i2.WebView, + String, + String, + )? onJsAlert, + _i8.Future Function( + _i2.WebChromeClient, + _i2.WebView, + String, + String, + )? onJsConfirm, + _i8.Future Function( + _i2.WebChromeClient, + _i2.WebView, + String, + String, + String, + )? onJsPrompt, + void Function( + _i2.WebChromeClient, + _i2.PermissionRequest, + )? onPermissionRequest, + void Function( + _i2.WebChromeClient, + _i2.WebView, + int, + )? onProgressChanged, + void Function( + _i2.WebChromeClient, + _i2.View, + _i2.CustomViewCallback, + )? onShowCustomView, + _i8.Future> Function( + _i2.WebChromeClient, + _i2.WebView, + _i2.FileChooserParams, + )? onShowFileChooser, + })); + @override - Set<_i11.Factory<_i12.OneSequenceGestureRecognizer>> get gestureRecognizers => + _i8.Future Function(bool) get setWebContentsDebuggingEnabledWebView => + (super.noSuchMethod( + Invocation.getter(#setWebContentsDebuggingEnabledWebView), + returnValue: (bool __p0) => _i8.Future.value(), + returnValueForMissingStub: (bool __p0) => _i8.Future.value(), + ) as _i8.Future Function(bool)); + + @override + _i2.CookieManager Function() get instanceCookieManager => (super.noSuchMethod( + Invocation.getter(#instanceCookieManager), + returnValue: () => _FakeCookieManager_9( + this, + Invocation.getter(#instanceCookieManager), + ), + returnValueForMissingStub: () => _FakeCookieManager_9( + this, + Invocation.getter(#instanceCookieManager), + ), + ) as _i2.CookieManager Function()); + + @override + _i2.FlutterAssetManager Function() get instanceFlutterAssetManager => + (super.noSuchMethod( + Invocation.getter(#instanceFlutterAssetManager), + returnValue: () => _FakeFlutterAssetManager_10( + this, + Invocation.getter(#instanceFlutterAssetManager), + ), + returnValueForMissingStub: () => _FakeFlutterAssetManager_10( + this, + Invocation.getter(#instanceFlutterAssetManager), + ), + ) as _i2.FlutterAssetManager Function()); + + @override + _i2.WebStorage Function() get instanceWebStorage => (super.noSuchMethod( + Invocation.getter(#instanceWebStorage), + returnValue: () => _FakeWebStorage_11( + this, + Invocation.getter(#instanceWebStorage), + ), + returnValueForMissingStub: () => _FakeWebStorage_11( + this, + Invocation.getter(#instanceWebStorage), + ), + ) as _i2.WebStorage Function()); +} + +/// A class which mocks [AndroidWebViewWidgetCreationParams]. +/// +/// See the documentation for Mockito's code generation for more information. +// ignore: must_be_immutable +class MockAndroidWebViewWidgetCreationParams extends _i1.Mock + implements _i7.AndroidWebViewWidgetCreationParams { + @override + _i2.PigeonInstanceManager get instanceManager => (super.noSuchMethod( + Invocation.getter(#instanceManager), + returnValue: _FakePigeonInstanceManager_12( + this, + Invocation.getter(#instanceManager), + ), + returnValueForMissingStub: _FakePigeonInstanceManager_12( + this, + Invocation.getter(#instanceManager), + ), + ) as _i2.PigeonInstanceManager); + + @override + _i5.PlatformViewsServiceProxy get platformViewsServiceProxy => + (super.noSuchMethod( + Invocation.getter(#platformViewsServiceProxy), + returnValue: _FakePlatformViewsServiceProxy_13( + this, + Invocation.getter(#platformViewsServiceProxy), + ), + returnValueForMissingStub: _FakePlatformViewsServiceProxy_13( + this, + Invocation.getter(#platformViewsServiceProxy), + ), + ) as _i5.PlatformViewsServiceProxy); + + @override + bool get displayWithHybridComposition => (super.noSuchMethod( + Invocation.getter(#displayWithHybridComposition), + returnValue: false, + returnValueForMissingStub: false, + ) as bool); + + @override + _i3.PlatformWebViewController get controller => (super.noSuchMethod( + Invocation.getter(#controller), + returnValue: _FakePlatformWebViewController_14( + this, + Invocation.getter(#controller), + ), + returnValueForMissingStub: _FakePlatformWebViewController_14( + this, + Invocation.getter(#controller), + ), + ) as _i3.PlatformWebViewController); + + @override + _i4.TextDirection get layoutDirection => (super.noSuchMethod( + Invocation.getter(#layoutDirection), + returnValue: _i4.TextDirection.rtl, + returnValueForMissingStub: _i4.TextDirection.rtl, + ) as _i4.TextDirection); + + @override + Set<_i10.Factory<_i11.OneSequenceGestureRecognizer>> get gestureRecognizers => (super.noSuchMethod( Invocation.getter(#gestureRecognizers), - returnValue: <_i11.Factory<_i12.OneSequenceGestureRecognizer>>{}, - returnValueForMissingStub: <_i11 - .Factory<_i12.OneSequenceGestureRecognizer>>{}, - ) as Set<_i11.Factory<_i12.OneSequenceGestureRecognizer>>); + returnValue: <_i10.Factory<_i11.OneSequenceGestureRecognizer>>{}, + returnValueForMissingStub: <_i10 + .Factory<_i11.OneSequenceGestureRecognizer>>{}, + ) as Set<_i10.Factory<_i11.OneSequenceGestureRecognizer>>); } /// A class which mocks [ExpensiveAndroidViewController]. /// /// See the documentation for Mockito's code generation for more information. class MockExpensiveAndroidViewController extends _i1.Mock - implements _i7.ExpensiveAndroidViewController { + implements _i6.ExpensiveAndroidViewController { @override bool get requiresViewComposition => (super.noSuchMethod( Invocation.getter(#requiresViewComposition), @@ -1494,7 +1661,7 @@ class MockExpensiveAndroidViewController extends _i1.Mock ) as bool); @override - _i7.PointTransformer get pointTransformer => (super.noSuchMethod( + _i6.PointTransformer get pointTransformer => (super.noSuchMethod( Invocation.getter(#pointTransformer), returnValue: (_i4.Offset position) => _FakeOffset_6( this, @@ -1504,10 +1671,10 @@ class MockExpensiveAndroidViewController extends _i1.Mock this, Invocation.getter(#pointTransformer), ), - ) as _i7.PointTransformer); + ) as _i6.PointTransformer); @override - set pointTransformer(_i7.PointTransformer? transformer) => super.noSuchMethod( + set pointTransformer(_i6.PointTransformer? transformer) => super.noSuchMethod( Invocation.setter( #pointTransformer, transformer, @@ -1523,25 +1690,25 @@ class MockExpensiveAndroidViewController extends _i1.Mock ) as bool); @override - List<_i7.PlatformViewCreatedCallback> get createdCallbacks => + List<_i6.PlatformViewCreatedCallback> get createdCallbacks => (super.noSuchMethod( Invocation.getter(#createdCallbacks), - returnValue: <_i7.PlatformViewCreatedCallback>[], - returnValueForMissingStub: <_i7.PlatformViewCreatedCallback>[], - ) as List<_i7.PlatformViewCreatedCallback>); + returnValue: <_i6.PlatformViewCreatedCallback>[], + returnValueForMissingStub: <_i6.PlatformViewCreatedCallback>[], + ) as List<_i6.PlatformViewCreatedCallback>); @override - _i9.Future setOffset(_i4.Offset? off) => (super.noSuchMethod( + _i8.Future setOffset(_i4.Offset? off) => (super.noSuchMethod( Invocation.method( #setOffset, [off], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i9.Future create({ + _i8.Future create({ _i4.Size? size, _i4.Offset? position, }) => @@ -1554,46 +1721,46 @@ class MockExpensiveAndroidViewController extends _i1.Mock #position: position, }, ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i9.Future<_i4.Size> setSize(_i4.Size? size) => (super.noSuchMethod( + _i8.Future<_i4.Size> setSize(_i4.Size? size) => (super.noSuchMethod( Invocation.method( #setSize, [size], ), - returnValue: _i9.Future<_i4.Size>.value(_FakeSize_13( + returnValue: _i8.Future<_i4.Size>.value(_FakeSize_15( this, Invocation.method( #setSize, [size], ), )), - returnValueForMissingStub: _i9.Future<_i4.Size>.value(_FakeSize_13( + returnValueForMissingStub: _i8.Future<_i4.Size>.value(_FakeSize_15( this, Invocation.method( #setSize, [size], ), )), - ) as _i9.Future<_i4.Size>); + ) as _i8.Future<_i4.Size>); @override - _i9.Future sendMotionEvent(_i7.AndroidMotionEvent? event) => + _i8.Future sendMotionEvent(_i6.AndroidMotionEvent? event) => (super.noSuchMethod( Invocation.method( #sendMotionEvent, [event], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override void addOnPlatformViewCreatedListener( - _i7.PlatformViewCreatedCallback? listener) => + _i6.PlatformViewCreatedCallback? listener) => super.noSuchMethod( Invocation.method( #addOnPlatformViewCreatedListener, @@ -1604,7 +1771,7 @@ class MockExpensiveAndroidViewController extends _i1.Mock @override void removeOnPlatformViewCreatedListener( - _i7.PlatformViewCreatedCallback? listener) => + _i6.PlatformViewCreatedCallback? listener) => super.noSuchMethod( Invocation.method( #removeOnPlatformViewCreatedListener, @@ -1614,46 +1781,46 @@ class MockExpensiveAndroidViewController extends _i1.Mock ); @override - _i9.Future setLayoutDirection(_i4.TextDirection? layoutDirection) => + _i8.Future setLayoutDirection(_i4.TextDirection? layoutDirection) => (super.noSuchMethod( Invocation.method( #setLayoutDirection, [layoutDirection], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i9.Future dispatchPointerEvent(_i12.PointerEvent? event) => + _i8.Future dispatchPointerEvent(_i11.PointerEvent? event) => (super.noSuchMethod( Invocation.method( #dispatchPointerEvent, [event], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i9.Future clearFocus() => (super.noSuchMethod( + _i8.Future clearFocus() => (super.noSuchMethod( Invocation.method( #clearFocus, [], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i9.Future dispose() => (super.noSuchMethod( + _i8.Future dispose() => (super.noSuchMethod( Invocation.method( #dispose, [], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); } /// A class which mocks [FlutterAssetManager]. @@ -1662,38 +1829,133 @@ class MockExpensiveAndroidViewController extends _i1.Mock class MockFlutterAssetManager extends _i1.Mock implements _i2.FlutterAssetManager { @override - _i9.Future> list(String? path) => (super.noSuchMethod( + _i2.PigeonInstanceManager get pigeon_instanceManager => (super.noSuchMethod( + Invocation.getter(#pigeon_instanceManager), + returnValue: _FakePigeonInstanceManager_12( + this, + Invocation.getter(#pigeon_instanceManager), + ), + returnValueForMissingStub: _FakePigeonInstanceManager_12( + this, + Invocation.getter(#pigeon_instanceManager), + ), + ) as _i2.PigeonInstanceManager); + + @override + _i8.Future> list(String? path) => (super.noSuchMethod( Invocation.method( #list, [path], ), - returnValue: _i9.Future>.value([]), - returnValueForMissingStub: _i9.Future>.value([]), - ) as _i9.Future>); + returnValue: _i8.Future>.value([]), + returnValueForMissingStub: _i8.Future>.value([]), + ) as _i8.Future>); @override - _i9.Future getAssetFilePathByName(String? name) => + _i8.Future getAssetFilePathByName(String? name) => (super.noSuchMethod( Invocation.method( #getAssetFilePathByName, [name], ), - returnValue: _i9.Future.value(_i13.dummyValue( + returnValue: _i8.Future.value(_i12.dummyValue( + this, + Invocation.method( + #getAssetFilePathByName, + [name], + ), + )), + returnValueForMissingStub: + _i8.Future.value(_i12.dummyValue( this, Invocation.method( #getAssetFilePathByName, [name], ), - )), - returnValueForMissingStub: - _i9.Future.value(_i13.dummyValue( + )), + ) as _i8.Future); + + @override + _i2.FlutterAssetManager pigeon_copy() => (super.noSuchMethod( + Invocation.method( + #pigeon_copy, + [], + ), + returnValue: _FakeFlutterAssetManager_10( + this, + Invocation.method( + #pigeon_copy, + [], + ), + ), + returnValueForMissingStub: _FakeFlutterAssetManager_10( + this, + Invocation.method( + #pigeon_copy, + [], + ), + ), + ) as _i2.FlutterAssetManager); +} + +/// A class which mocks [GeolocationPermissionsCallback]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockGeolocationPermissionsCallback extends _i1.Mock + implements _i2.GeolocationPermissionsCallback { + @override + _i2.PigeonInstanceManager get pigeon_instanceManager => (super.noSuchMethod( + Invocation.getter(#pigeon_instanceManager), + returnValue: _FakePigeonInstanceManager_12( + this, + Invocation.getter(#pigeon_instanceManager), + ), + returnValueForMissingStub: _FakePigeonInstanceManager_12( + this, + Invocation.getter(#pigeon_instanceManager), + ), + ) as _i2.PigeonInstanceManager); + + @override + _i8.Future invoke( + String? origin, + bool? allow, + bool? retain, + ) => + (super.noSuchMethod( + Invocation.method( + #invoke, + [ + origin, + allow, + retain, + ], + ), + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); + + @override + _i2.GeolocationPermissionsCallback pigeon_copy() => (super.noSuchMethod( + Invocation.method( + #pigeon_copy, + [], + ), + returnValue: _FakeGeolocationPermissionsCallback_16( + this, + Invocation.method( + #pigeon_copy, + [], + ), + ), + returnValueForMissingStub: _FakeGeolocationPermissionsCallback_16( this, Invocation.method( - #getAssetFilePathByName, - [name], + #pigeon_copy, + [], ), - )), - ) as _i9.Future); + ), + ) as _i2.GeolocationPermissionsCallback); } /// A class which mocks [JavaScriptChannel]. @@ -1703,40 +1965,65 @@ class MockJavaScriptChannel extends _i1.Mock implements _i2.JavaScriptChannel { @override String get channelName => (super.noSuchMethod( Invocation.getter(#channelName), - returnValue: _i13.dummyValue( + returnValue: _i12.dummyValue( this, Invocation.getter(#channelName), ), - returnValueForMissingStub: _i13.dummyValue( + returnValueForMissingStub: _i12.dummyValue( this, Invocation.getter(#channelName), ), ) as String); @override - void Function(String) get postMessage => (super.noSuchMethod( + void Function( + _i2.JavaScriptChannel, + String, + ) get postMessage => (super.noSuchMethod( Invocation.getter(#postMessage), - returnValue: (String message) {}, - returnValueForMissingStub: (String message) {}, - ) as void Function(String)); + returnValue: ( + _i2.JavaScriptChannel pigeon_instance, + String message, + ) {}, + returnValueForMissingStub: ( + _i2.JavaScriptChannel pigeon_instance, + String message, + ) {}, + ) as void Function( + _i2.JavaScriptChannel, + String, + )); + + @override + _i2.PigeonInstanceManager get pigeon_instanceManager => (super.noSuchMethod( + Invocation.getter(#pigeon_instanceManager), + returnValue: _FakePigeonInstanceManager_12( + this, + Invocation.getter(#pigeon_instanceManager), + ), + returnValueForMissingStub: _FakePigeonInstanceManager_12( + this, + Invocation.getter(#pigeon_instanceManager), + ), + ) as _i2.PigeonInstanceManager); @override - _i2.JavaScriptChannel copy() => (super.noSuchMethod( + _i2.JavaScriptChannel pigeon_copy() => (super.noSuchMethod( Invocation.method( - #copy, + #pigeon_copy, [], ), - returnValue: _FakeJavaScriptChannel_9( + returnValue: _FakeJavaScriptChannel_8( this, Invocation.method( - #copy, + #pigeon_copy, [], ), ), - returnValueForMissingStub: _FakeJavaScriptChannel_9( + returnValueForMissingStub: _FakeJavaScriptChannel_8( this, Invocation.method( - #copy, + #pigeon_copy, [], ), ), @@ -1755,42 +2042,55 @@ class MockPermissionRequest extends _i1.Mock implements _i2.PermissionRequest { ) as List); @override - _i9.Future grant(List? resources) => (super.noSuchMethod( + _i2.PigeonInstanceManager get pigeon_instanceManager => (super.noSuchMethod( + Invocation.getter(#pigeon_instanceManager), + returnValue: _FakePigeonInstanceManager_12( + this, + Invocation.getter(#pigeon_instanceManager), + ), + returnValueForMissingStub: _FakePigeonInstanceManager_12( + this, + Invocation.getter(#pigeon_instanceManager), + ), + ) as _i2.PigeonInstanceManager); + + @override + _i8.Future grant(List? resources) => (super.noSuchMethod( Invocation.method( #grant, [resources], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i9.Future deny() => (super.noSuchMethod( + _i8.Future deny() => (super.noSuchMethod( Invocation.method( #deny, [], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i2.PermissionRequest copy() => (super.noSuchMethod( + _i2.PermissionRequest pigeon_copy() => (super.noSuchMethod( Invocation.method( - #copy, + #pigeon_copy, [], ), - returnValue: _FakePermissionRequest_14( + returnValue: _FakePermissionRequest_17( this, Invocation.method( - #copy, + #pigeon_copy, [], ), ), - returnValueForMissingStub: _FakePermissionRequest_14( + returnValueForMissingStub: _FakePermissionRequest_17( this, Invocation.method( - #copy, + #pigeon_copy, [], ), ), @@ -1802,14 +2102,14 @@ class MockPermissionRequest extends _i1.Mock implements _i2.PermissionRequest { /// See the documentation for Mockito's code generation for more information. // ignore: must_be_immutable class MockPlatformViewsServiceProxy extends _i1.Mock - implements _i6.PlatformViewsServiceProxy { + implements _i5.PlatformViewsServiceProxy { @override - _i7.ExpensiveAndroidViewController initExpensiveAndroidView({ + _i6.ExpensiveAndroidViewController initExpensiveAndroidView({ required int? id, required String? viewType, required _i4.TextDirection? layoutDirection, dynamic creationParams, - _i7.MessageCodec? creationParamsCodec, + _i6.MessageCodec? creationParamsCodec, _i4.VoidCallback? onFocus, }) => (super.noSuchMethod( @@ -1825,7 +2125,7 @@ class MockPlatformViewsServiceProxy extends _i1.Mock #onFocus: onFocus, }, ), - returnValue: _FakeExpensiveAndroidViewController_15( + returnValue: _FakeExpensiveAndroidViewController_18( this, Invocation.method( #initExpensiveAndroidView, @@ -1840,7 +2140,7 @@ class MockPlatformViewsServiceProxy extends _i1.Mock }, ), ), - returnValueForMissingStub: _FakeExpensiveAndroidViewController_15( + returnValueForMissingStub: _FakeExpensiveAndroidViewController_18( this, Invocation.method( #initExpensiveAndroidView, @@ -1855,15 +2155,15 @@ class MockPlatformViewsServiceProxy extends _i1.Mock }, ), ), - ) as _i7.ExpensiveAndroidViewController); + ) as _i6.ExpensiveAndroidViewController); @override - _i7.SurfaceAndroidViewController initSurfaceAndroidView({ + _i6.SurfaceAndroidViewController initSurfaceAndroidView({ required int? id, required String? viewType, required _i4.TextDirection? layoutDirection, dynamic creationParams, - _i7.MessageCodec? creationParamsCodec, + _i6.MessageCodec? creationParamsCodec, _i4.VoidCallback? onFocus, }) => (super.noSuchMethod( @@ -1879,7 +2179,7 @@ class MockPlatformViewsServiceProxy extends _i1.Mock #onFocus: onFocus, }, ), - returnValue: _FakeSurfaceAndroidViewController_16( + returnValue: _FakeSurfaceAndroidViewController_19( this, Invocation.method( #initSurfaceAndroidView, @@ -1894,7 +2194,7 @@ class MockPlatformViewsServiceProxy extends _i1.Mock }, ), ), - returnValueForMissingStub: _FakeSurfaceAndroidViewController_16( + returnValueForMissingStub: _FakeSurfaceAndroidViewController_19( this, Invocation.method( #initSurfaceAndroidView, @@ -1909,14 +2209,14 @@ class MockPlatformViewsServiceProxy extends _i1.Mock }, ), ), - ) as _i7.SurfaceAndroidViewController); + ) as _i6.SurfaceAndroidViewController); } /// A class which mocks [SurfaceAndroidViewController]. /// /// See the documentation for Mockito's code generation for more information. class MockSurfaceAndroidViewController extends _i1.Mock - implements _i7.SurfaceAndroidViewController { + implements _i6.SurfaceAndroidViewController { @override bool get requiresViewComposition => (super.noSuchMethod( Invocation.getter(#requiresViewComposition), @@ -1939,7 +2239,7 @@ class MockSurfaceAndroidViewController extends _i1.Mock ) as bool); @override - _i7.PointTransformer get pointTransformer => (super.noSuchMethod( + _i6.PointTransformer get pointTransformer => (super.noSuchMethod( Invocation.getter(#pointTransformer), returnValue: (_i4.Offset position) => _FakeOffset_6( this, @@ -1949,10 +2249,10 @@ class MockSurfaceAndroidViewController extends _i1.Mock this, Invocation.getter(#pointTransformer), ), - ) as _i7.PointTransformer); + ) as _i6.PointTransformer); @override - set pointTransformer(_i7.PointTransformer? transformer) => super.noSuchMethod( + set pointTransformer(_i6.PointTransformer? transformer) => super.noSuchMethod( Invocation.setter( #pointTransformer, transformer, @@ -1968,25 +2268,25 @@ class MockSurfaceAndroidViewController extends _i1.Mock ) as bool); @override - List<_i7.PlatformViewCreatedCallback> get createdCallbacks => + List<_i6.PlatformViewCreatedCallback> get createdCallbacks => (super.noSuchMethod( Invocation.getter(#createdCallbacks), - returnValue: <_i7.PlatformViewCreatedCallback>[], - returnValueForMissingStub: <_i7.PlatformViewCreatedCallback>[], - ) as List<_i7.PlatformViewCreatedCallback>); + returnValue: <_i6.PlatformViewCreatedCallback>[], + returnValueForMissingStub: <_i6.PlatformViewCreatedCallback>[], + ) as List<_i6.PlatformViewCreatedCallback>); @override - _i9.Future setOffset(_i4.Offset? off) => (super.noSuchMethod( + _i8.Future setOffset(_i4.Offset? off) => (super.noSuchMethod( Invocation.method( #setOffset, [off], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i9.Future create({ + _i8.Future create({ _i4.Size? size, _i4.Offset? position, }) => @@ -1999,46 +2299,46 @@ class MockSurfaceAndroidViewController extends _i1.Mock #position: position, }, ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i9.Future<_i4.Size> setSize(_i4.Size? size) => (super.noSuchMethod( + _i8.Future<_i4.Size> setSize(_i4.Size? size) => (super.noSuchMethod( Invocation.method( #setSize, [size], ), - returnValue: _i9.Future<_i4.Size>.value(_FakeSize_13( + returnValue: _i8.Future<_i4.Size>.value(_FakeSize_15( this, Invocation.method( #setSize, [size], ), )), - returnValueForMissingStub: _i9.Future<_i4.Size>.value(_FakeSize_13( + returnValueForMissingStub: _i8.Future<_i4.Size>.value(_FakeSize_15( this, Invocation.method( #setSize, [size], ), )), - ) as _i9.Future<_i4.Size>); + ) as _i8.Future<_i4.Size>); @override - _i9.Future sendMotionEvent(_i7.AndroidMotionEvent? event) => + _i8.Future sendMotionEvent(_i6.AndroidMotionEvent? event) => (super.noSuchMethod( Invocation.method( #sendMotionEvent, [event], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override void addOnPlatformViewCreatedListener( - _i7.PlatformViewCreatedCallback? listener) => + _i6.PlatformViewCreatedCallback? listener) => super.noSuchMethod( Invocation.method( #addOnPlatformViewCreatedListener, @@ -2049,7 +2349,7 @@ class MockSurfaceAndroidViewController extends _i1.Mock @override void removeOnPlatformViewCreatedListener( - _i7.PlatformViewCreatedCallback? listener) => + _i6.PlatformViewCreatedCallback? listener) => super.noSuchMethod( Invocation.method( #removeOnPlatformViewCreatedListener, @@ -2059,46 +2359,46 @@ class MockSurfaceAndroidViewController extends _i1.Mock ); @override - _i9.Future setLayoutDirection(_i4.TextDirection? layoutDirection) => + _i8.Future setLayoutDirection(_i4.TextDirection? layoutDirection) => (super.noSuchMethod( Invocation.method( #setLayoutDirection, [layoutDirection], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i9.Future dispatchPointerEvent(_i12.PointerEvent? event) => + _i8.Future dispatchPointerEvent(_i11.PointerEvent? event) => (super.noSuchMethod( Invocation.method( #dispatchPointerEvent, [event], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i9.Future clearFocus() => (super.noSuchMethod( + _i8.Future clearFocus() => (super.noSuchMethod( Invocation.method( #clearFocus, [], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i9.Future dispose() => (super.noSuchMethod( + _i8.Future dispose() => (super.noSuchMethod( Invocation.method( #dispose, [], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); } /// A class which mocks [WebChromeClient]. @@ -2106,77 +2406,90 @@ class MockSurfaceAndroidViewController extends _i1.Mock /// See the documentation for Mockito's code generation for more information. class MockWebChromeClient extends _i1.Mock implements _i2.WebChromeClient { @override - _i9.Future setSynchronousReturnValueForOnShowFileChooser(bool? value) => + _i2.PigeonInstanceManager get pigeon_instanceManager => (super.noSuchMethod( + Invocation.getter(#pigeon_instanceManager), + returnValue: _FakePigeonInstanceManager_12( + this, + Invocation.getter(#pigeon_instanceManager), + ), + returnValueForMissingStub: _FakePigeonInstanceManager_12( + this, + Invocation.getter(#pigeon_instanceManager), + ), + ) as _i2.PigeonInstanceManager); + + @override + _i8.Future setSynchronousReturnValueForOnShowFileChooser(bool? value) => (super.noSuchMethod( Invocation.method( #setSynchronousReturnValueForOnShowFileChooser, [value], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i9.Future setSynchronousReturnValueForOnConsoleMessage(bool? value) => + _i8.Future setSynchronousReturnValueForOnConsoleMessage(bool? value) => (super.noSuchMethod( Invocation.method( #setSynchronousReturnValueForOnConsoleMessage, [value], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i9.Future setSynchronousReturnValueForOnJsAlert(bool? value) => + _i8.Future setSynchronousReturnValueForOnJsAlert(bool? value) => (super.noSuchMethod( Invocation.method( #setSynchronousReturnValueForOnJsAlert, [value], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i9.Future setSynchronousReturnValueForOnJsConfirm(bool? value) => + _i8.Future setSynchronousReturnValueForOnJsConfirm(bool? value) => (super.noSuchMethod( Invocation.method( #setSynchronousReturnValueForOnJsConfirm, [value], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i9.Future setSynchronousReturnValueForOnJsPrompt(bool? value) => + _i8.Future setSynchronousReturnValueForOnJsPrompt(bool? value) => (super.noSuchMethod( Invocation.method( #setSynchronousReturnValueForOnJsPrompt, [value], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i2.WebChromeClient copy() => (super.noSuchMethod( + _i2.WebChromeClient pigeon_copy() => (super.noSuchMethod( Invocation.method( - #copy, + #pigeon_copy, [], ), returnValue: _FakeWebChromeClient_0( this, Invocation.method( - #copy, + #pigeon_copy, [], ), ), returnValueForMissingStub: _FakeWebChromeClient_0( this, Invocation.method( - #copy, + #pigeon_copy, [], ), ), @@ -2188,147 +2501,160 @@ class MockWebChromeClient extends _i1.Mock implements _i2.WebChromeClient { /// See the documentation for Mockito's code generation for more information. class MockWebSettings extends _i1.Mock implements _i2.WebSettings { @override - _i9.Future setDomStorageEnabled(bool? flag) => (super.noSuchMethod( + _i2.PigeonInstanceManager get pigeon_instanceManager => (super.noSuchMethod( + Invocation.getter(#pigeon_instanceManager), + returnValue: _FakePigeonInstanceManager_12( + this, + Invocation.getter(#pigeon_instanceManager), + ), + returnValueForMissingStub: _FakePigeonInstanceManager_12( + this, + Invocation.getter(#pigeon_instanceManager), + ), + ) as _i2.PigeonInstanceManager); + + @override + _i8.Future setDomStorageEnabled(bool? flag) => (super.noSuchMethod( Invocation.method( #setDomStorageEnabled, [flag], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i9.Future setJavaScriptCanOpenWindowsAutomatically(bool? flag) => + _i8.Future setJavaScriptCanOpenWindowsAutomatically(bool? flag) => (super.noSuchMethod( Invocation.method( #setJavaScriptCanOpenWindowsAutomatically, [flag], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i9.Future setSupportMultipleWindows(bool? support) => + _i8.Future setSupportMultipleWindows(bool? support) => (super.noSuchMethod( Invocation.method( #setSupportMultipleWindows, [support], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i9.Future setJavaScriptEnabled(bool? flag) => (super.noSuchMethod( + _i8.Future setJavaScriptEnabled(bool? flag) => (super.noSuchMethod( Invocation.method( #setJavaScriptEnabled, [flag], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i9.Future setUserAgentString(String? userAgentString) => + _i8.Future setUserAgentString(String? userAgentString) => (super.noSuchMethod( Invocation.method( #setUserAgentString, [userAgentString], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i9.Future setMediaPlaybackRequiresUserGesture(bool? require) => + _i8.Future setMediaPlaybackRequiresUserGesture(bool? require) => (super.noSuchMethod( Invocation.method( #setMediaPlaybackRequiresUserGesture, [require], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i9.Future setSupportZoom(bool? support) => (super.noSuchMethod( + _i8.Future setSupportZoom(bool? support) => (super.noSuchMethod( Invocation.method( #setSupportZoom, [support], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i9.Future setLoadWithOverviewMode(bool? overview) => + _i8.Future setLoadWithOverviewMode(bool? overview) => (super.noSuchMethod( Invocation.method( #setLoadWithOverviewMode, [overview], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i9.Future setUseWideViewPort(bool? use) => (super.noSuchMethod( + _i8.Future setUseWideViewPort(bool? use) => (super.noSuchMethod( Invocation.method( #setUseWideViewPort, [use], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i9.Future setDisplayZoomControls(bool? enabled) => (super.noSuchMethod( + _i8.Future setDisplayZoomControls(bool? enabled) => (super.noSuchMethod( Invocation.method( #setDisplayZoomControls, [enabled], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i9.Future setBuiltInZoomControls(bool? enabled) => (super.noSuchMethod( + _i8.Future setBuiltInZoomControls(bool? enabled) => (super.noSuchMethod( Invocation.method( #setBuiltInZoomControls, [enabled], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i9.Future setAllowFileAccess(bool? enabled) => (super.noSuchMethod( + _i8.Future setAllowFileAccess(bool? enabled) => (super.noSuchMethod( Invocation.method( #setAllowFileAccess, [enabled], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i9.Future setTextZoom(int? textZoom) => (super.noSuchMethod( + _i8.Future setTextZoom(int? textZoom) => (super.noSuchMethod( Invocation.method( #setTextZoom, [textZoom], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i9.Future getUserAgentString() => (super.noSuchMethod( + _i8.Future getUserAgentString() => (super.noSuchMethod( Invocation.method( #getUserAgentString, [], ), - returnValue: _i9.Future.value(_i13.dummyValue( + returnValue: _i8.Future.value(_i12.dummyValue( this, Invocation.method( #getUserAgentString, @@ -2336,32 +2662,32 @@ class MockWebSettings extends _i1.Mock implements _i2.WebSettings { ), )), returnValueForMissingStub: - _i9.Future.value(_i13.dummyValue( + _i8.Future.value(_i12.dummyValue( this, Invocation.method( #getUserAgentString, [], ), )), - ) as _i9.Future); + ) as _i8.Future); @override - _i2.WebSettings copy() => (super.noSuchMethod( + _i2.WebSettings pigeon_copy() => (super.noSuchMethod( Invocation.method( - #copy, + #pigeon_copy, [], ), - returnValue: _FakeWebSettings_17( + returnValue: _FakeWebSettings_20( this, Invocation.method( - #copy, + #pigeon_copy, [], ), ), - returnValueForMissingStub: _FakeWebSettings_17( + returnValueForMissingStub: _FakeWebSettings_20( this, Invocation.method( - #copy, + #pigeon_copy, [], ), ), @@ -2375,62 +2701,95 @@ class MockWebView extends _i1.Mock implements _i2.WebView { @override _i2.WebSettings get settings => (super.noSuchMethod( Invocation.getter(#settings), - returnValue: _FakeWebSettings_17( + returnValue: _FakeWebSettings_20( this, Invocation.getter(#settings), ), - returnValueForMissingStub: _FakeWebSettings_17( + returnValueForMissingStub: _FakeWebSettings_20( this, Invocation.getter(#settings), ), ) as _i2.WebSettings); @override - _i9.Future loadData({ - required String? data, + _i2.PigeonInstanceManager get pigeon_instanceManager => (super.noSuchMethod( + Invocation.getter(#pigeon_instanceManager), + returnValue: _FakePigeonInstanceManager_12( + this, + Invocation.getter(#pigeon_instanceManager), + ), + returnValueForMissingStub: _FakePigeonInstanceManager_12( + this, + Invocation.getter(#pigeon_instanceManager), + ), + ) as _i2.PigeonInstanceManager); + + @override + _i2.WebSettings pigeonVar_settings() => (super.noSuchMethod( + Invocation.method( + #pigeonVar_settings, + [], + ), + returnValue: _FakeWebSettings_20( + this, + Invocation.method( + #pigeonVar_settings, + [], + ), + ), + returnValueForMissingStub: _FakeWebSettings_20( + this, + Invocation.method( + #pigeonVar_settings, + [], + ), + ), + ) as _i2.WebSettings); + + @override + _i8.Future loadData( + String? data, String? mimeType, String? encoding, - }) => + ) => (super.noSuchMethod( Invocation.method( #loadData, - [], - { - #data: data, - #mimeType: mimeType, - #encoding: encoding, - }, + [ + data, + mimeType, + encoding, + ], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i9.Future loadDataWithBaseUrl({ + _i8.Future loadDataWithBaseUrl( String? baseUrl, - required String? data, + String? data, String? mimeType, String? encoding, String? historyUrl, - }) => + ) => (super.noSuchMethod( Invocation.method( #loadDataWithBaseUrl, - [], - { - #baseUrl: baseUrl, - #data: data, - #mimeType: mimeType, - #encoding: encoding, - #historyUrl: historyUrl, - }, + [ + baseUrl, + data, + mimeType, + encoding, + historyUrl, + ], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i9.Future loadUrl( + _i8.Future loadUrl( String? url, Map? headers, ) => @@ -2442,14 +2801,14 @@ class MockWebView extends _i1.Mock implements _i2.WebView { headers, ], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i9.Future postUrl( + _i8.Future postUrl( String? url, - _i14.Uint8List? data, + _i13.Uint8List? data, ) => (super.noSuchMethod( Invocation.method( @@ -2459,265 +2818,253 @@ class MockWebView extends _i1.Mock implements _i2.WebView { data, ], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i9.Future getUrl() => (super.noSuchMethod( + _i8.Future getUrl() => (super.noSuchMethod( Invocation.method( #getUrl, [], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i9.Future canGoBack() => (super.noSuchMethod( + _i8.Future canGoBack() => (super.noSuchMethod( Invocation.method( #canGoBack, [], ), - returnValue: _i9.Future.value(false), - returnValueForMissingStub: _i9.Future.value(false), - ) as _i9.Future); + returnValue: _i8.Future.value(false), + returnValueForMissingStub: _i8.Future.value(false), + ) as _i8.Future); @override - _i9.Future canGoForward() => (super.noSuchMethod( + _i8.Future canGoForward() => (super.noSuchMethod( Invocation.method( #canGoForward, [], ), - returnValue: _i9.Future.value(false), - returnValueForMissingStub: _i9.Future.value(false), - ) as _i9.Future); + returnValue: _i8.Future.value(false), + returnValueForMissingStub: _i8.Future.value(false), + ) as _i8.Future); @override - _i9.Future goBack() => (super.noSuchMethod( + _i8.Future goBack() => (super.noSuchMethod( Invocation.method( #goBack, [], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i9.Future goForward() => (super.noSuchMethod( + _i8.Future goForward() => (super.noSuchMethod( Invocation.method( #goForward, [], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i9.Future reload() => (super.noSuchMethod( + _i8.Future reload() => (super.noSuchMethod( Invocation.method( #reload, [], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i9.Future clearCache(bool? includeDiskFiles) => (super.noSuchMethod( + _i8.Future clearCache(bool? includeDiskFiles) => (super.noSuchMethod( Invocation.method( #clearCache, [includeDiskFiles], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i9.Future evaluateJavascript(String? javascriptString) => + _i8.Future evaluateJavascript(String? javascriptString) => (super.noSuchMethod( Invocation.method( #evaluateJavascript, [javascriptString], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i9.Future getTitle() => (super.noSuchMethod( + _i8.Future getTitle() => (super.noSuchMethod( Invocation.method( #getTitle, [], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i9.Future scrollTo( - int? x, - int? y, - ) => + _i8.Future setWebViewClient(_i2.WebViewClient? client) => (super.noSuchMethod( Invocation.method( - #scrollTo, - [ - x, - y, - ], + #setWebViewClient, + [client], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i9.Future scrollBy( - int? x, - int? y, - ) => + _i8.Future addJavaScriptChannel(_i2.JavaScriptChannel? channel) => (super.noSuchMethod( Invocation.method( - #scrollBy, - [ - x, - y, - ], - ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); - - @override - _i9.Future getScrollX() => (super.noSuchMethod( - Invocation.method( - #getScrollX, - [], + #addJavaScriptChannel, + [channel], ), - returnValue: _i9.Future.value(0), - returnValueForMissingStub: _i9.Future.value(0), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i9.Future getScrollY() => (super.noSuchMethod( + _i8.Future removeJavaScriptChannel(String? name) => (super.noSuchMethod( Invocation.method( - #getScrollY, - [], + #removeJavaScriptChannel, + [name], ), - returnValue: _i9.Future.value(0), - returnValueForMissingStub: _i9.Future.value(0), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i9.Future<_i4.Offset> getScrollPosition() => (super.noSuchMethod( + _i8.Future setDownloadListener(_i2.DownloadListener? listener) => + (super.noSuchMethod( Invocation.method( - #getScrollPosition, - [], + #setDownloadListener, + [listener], ), - returnValue: _i9.Future<_i4.Offset>.value(_FakeOffset_6( - this, - Invocation.method( - #getScrollPosition, - [], - ), - )), - returnValueForMissingStub: _i9.Future<_i4.Offset>.value(_FakeOffset_6( - this, - Invocation.method( - #getScrollPosition, - [], - ), - )), - ) as _i9.Future<_i4.Offset>); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i9.Future setWebViewClient(_i2.WebViewClient? webViewClient) => + _i8.Future setWebChromeClient(_i2.WebChromeClient? client) => (super.noSuchMethod( Invocation.method( - #setWebViewClient, - [webViewClient], + #setWebChromeClient, + [client], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i9.Future addJavaScriptChannel( - _i2.JavaScriptChannel? javaScriptChannel) => - (super.noSuchMethod( + _i8.Future setBackgroundColor(int? color) => (super.noSuchMethod( Invocation.method( - #addJavaScriptChannel, - [javaScriptChannel], + #setBackgroundColor, + [color], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i9.Future removeJavaScriptChannel( - _i2.JavaScriptChannel? javaScriptChannel) => - (super.noSuchMethod( + _i8.Future destroy() => (super.noSuchMethod( Invocation.method( - #removeJavaScriptChannel, - [javaScriptChannel], + #destroy, + [], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i9.Future setDownloadListener(_i2.DownloadListener? listener) => - (super.noSuchMethod( + _i2.WebView pigeon_copy() => (super.noSuchMethod( Invocation.method( - #setDownloadListener, - [listener], + #pigeon_copy, + [], + ), + returnValue: _FakeWebView_7( + this, + Invocation.method( + #pigeon_copy, + [], + ), + ), + returnValueForMissingStub: _FakeWebView_7( + this, + Invocation.method( + #pigeon_copy, + [], + ), ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + ) as _i2.WebView); @override - _i9.Future setWebChromeClient(_i2.WebChromeClient? client) => + _i8.Future scrollTo( + int? x, + int? y, + ) => (super.noSuchMethod( Invocation.method( - #setWebChromeClient, - [client], + #scrollTo, + [ + x, + y, + ], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i9.Future setBackgroundColor(_i4.Color? color) => (super.noSuchMethod( + _i8.Future scrollBy( + int? x, + int? y, + ) => + (super.noSuchMethod( Invocation.method( - #setBackgroundColor, - [color], + #scrollBy, + [ + x, + y, + ], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i2.WebView copy() => (super.noSuchMethod( + _i8.Future<_i2.WebViewPoint> getScrollPosition() => (super.noSuchMethod( Invocation.method( - #copy, + #getScrollPosition, [], ), - returnValue: _FakeWebView_7( + returnValue: _i8.Future<_i2.WebViewPoint>.value(_FakeWebViewPoint_21( this, Invocation.method( - #copy, + #getScrollPosition, [], ), - ), - returnValueForMissingStub: _FakeWebView_7( + )), + returnValueForMissingStub: + _i8.Future<_i2.WebViewPoint>.value(_FakeWebViewPoint_21( this, Invocation.method( - #copy, + #getScrollPosition, [], ), - ), - ) as _i2.WebView); + )), + ) as _i8.Future<_i2.WebViewPoint>); } /// A class which mocks [WebViewClient]. @@ -2725,34 +3072,47 @@ class MockWebView extends _i1.Mock implements _i2.WebView { /// See the documentation for Mockito's code generation for more information. class MockWebViewClient extends _i1.Mock implements _i2.WebViewClient { @override - _i9.Future setSynchronousReturnValueForShouldOverrideUrlLoading( + _i2.PigeonInstanceManager get pigeon_instanceManager => (super.noSuchMethod( + Invocation.getter(#pigeon_instanceManager), + returnValue: _FakePigeonInstanceManager_12( + this, + Invocation.getter(#pigeon_instanceManager), + ), + returnValueForMissingStub: _FakePigeonInstanceManager_12( + this, + Invocation.getter(#pigeon_instanceManager), + ), + ) as _i2.PigeonInstanceManager); + + @override + _i8.Future setSynchronousReturnValueForShouldOverrideUrlLoading( bool? value) => (super.noSuchMethod( Invocation.method( #setSynchronousReturnValueForShouldOverrideUrlLoading, [value], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i2.WebViewClient copy() => (super.noSuchMethod( + _i2.WebViewClient pigeon_copy() => (super.noSuchMethod( Invocation.method( - #copy, + #pigeon_copy, [], ), returnValue: _FakeWebViewClient_1( this, Invocation.method( - #copy, + #pigeon_copy, [], ), ), returnValueForMissingStub: _FakeWebViewClient_1( this, Invocation.method( - #copy, + #pigeon_copy, [], ), ), @@ -2764,144 +3124,47 @@ class MockWebViewClient extends _i1.Mock implements _i2.WebViewClient { /// See the documentation for Mockito's code generation for more information. class MockWebStorage extends _i1.Mock implements _i2.WebStorage { @override - _i9.Future deleteAllData() => (super.noSuchMethod( + _i2.PigeonInstanceManager get pigeon_instanceManager => (super.noSuchMethod( + Invocation.getter(#pigeon_instanceManager), + returnValue: _FakePigeonInstanceManager_12( + this, + Invocation.getter(#pigeon_instanceManager), + ), + returnValueForMissingStub: _FakePigeonInstanceManager_12( + this, + Invocation.getter(#pigeon_instanceManager), + ), + ) as _i2.PigeonInstanceManager); + + @override + _i8.Future deleteAllData() => (super.noSuchMethod( Invocation.method( #deleteAllData, [], ), - returnValue: _i9.Future.value(), - returnValueForMissingStub: _i9.Future.value(), - ) as _i9.Future); + returnValue: _i8.Future.value(), + returnValueForMissingStub: _i8.Future.value(), + ) as _i8.Future); @override - _i2.WebStorage copy() => (super.noSuchMethod( + _i2.WebStorage pigeon_copy() => (super.noSuchMethod( Invocation.method( - #copy, + #pigeon_copy, [], ), - returnValue: _FakeWebStorage_18( + returnValue: _FakeWebStorage_11( this, Invocation.method( - #copy, + #pigeon_copy, [], ), ), - returnValueForMissingStub: _FakeWebStorage_18( + returnValueForMissingStub: _FakeWebStorage_11( this, Invocation.method( - #copy, + #pigeon_copy, [], ), ), ) as _i2.WebStorage); } - -/// A class which mocks [InstanceManager]. -/// -/// See the documentation for Mockito's code generation for more information. -class MockInstanceManager extends _i1.Mock implements _i5.InstanceManager { - @override - void Function(int) get onWeakReferenceRemoved => (super.noSuchMethod( - Invocation.getter(#onWeakReferenceRemoved), - returnValue: (int __p0) {}, - returnValueForMissingStub: (int __p0) {}, - ) as void Function(int)); - - @override - set onWeakReferenceRemoved(void Function(int)? _onWeakReferenceRemoved) => - super.noSuchMethod( - Invocation.setter( - #onWeakReferenceRemoved, - _onWeakReferenceRemoved, - ), - returnValueForMissingStub: null, - ); - - @override - int addDartCreatedInstance(_i5.Copyable? instance) => (super.noSuchMethod( - Invocation.method( - #addDartCreatedInstance, - [instance], - ), - returnValue: 0, - returnValueForMissingStub: 0, - ) as int); - - @override - int? removeWeakReference(_i5.Copyable? instance) => (super.noSuchMethod( - Invocation.method( - #removeWeakReference, - [instance], - ), - returnValueForMissingStub: null, - ) as int?); - - @override - T? remove(int? identifier) => (super.noSuchMethod( - Invocation.method( - #remove, - [identifier], - ), - returnValueForMissingStub: null, - ) as T?); - - @override - T? getInstanceWithWeakReference(int? identifier) => - (super.noSuchMethod( - Invocation.method( - #getInstanceWithWeakReference, - [identifier], - ), - returnValueForMissingStub: null, - ) as T?); - - @override - int? getIdentifier(_i5.Copyable? instance) => (super.noSuchMethod( - Invocation.method( - #getIdentifier, - [instance], - ), - returnValueForMissingStub: null, - ) as int?); - - @override - void addHostCreatedInstance( - _i5.Copyable? instance, - int? identifier, - ) => - super.noSuchMethod( - Invocation.method( - #addHostCreatedInstance, - [ - instance, - identifier, - ], - ), - returnValueForMissingStub: null, - ); - - @override - bool containsIdentifier(int? identifier) => (super.noSuchMethod( - Invocation.method( - #containsIdentifier, - [identifier], - ), - returnValue: false, - returnValueForMissingStub: false, - ) as bool); -} - -/// A class which mocks [TestInstanceManagerHostApi]. -/// -/// See the documentation for Mockito's code generation for more information. -class MockTestInstanceManagerHostApi extends _i1.Mock - implements _i15.TestInstanceManagerHostApi { - @override - void clear() => super.noSuchMethod( - Invocation.method( - #clear, - [], - ), - returnValueForMissingStub: null, - ); -} diff --git a/packages/webview_flutter/webview_flutter_android/test/android_webview_cookie_manager_test.dart b/packages/webview_flutter/webview_flutter_android/test/android_webview_cookie_manager_test.dart index e17347a2c0ee..87c8e5c68321 100644 --- a/packages/webview_flutter/webview_flutter_android/test/android_webview_cookie_manager_test.dart +++ b/packages/webview_flutter/webview_flutter_android/test/android_webview_cookie_manager_test.dart @@ -5,27 +5,20 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:mockito/annotations.dart'; import 'package:mockito/mockito.dart'; -import 'package:webview_flutter_android/src/android_webview.dart' +import 'package:webview_flutter_android/src/android_webkit.g.dart' as android_webview; -import 'package:webview_flutter_android/src/android_webview_api_impls.dart'; -import 'package:webview_flutter_android/src/instance_manager.dart'; import 'package:webview_flutter_android/webview_flutter_android.dart'; import 'package:webview_flutter_platform_interface/webview_flutter_platform_interface.dart'; import 'android_webview_cookie_manager_test.mocks.dart'; -import 'test_android_webview.g.dart'; @GenerateMocks([ android_webview.CookieManager, AndroidWebViewController, - TestInstanceManagerHostApi, ]) void main() { TestWidgetsFlutterBinding.ensureInitialized(); - // Mocks the call to clear the native InstanceManager. - TestInstanceManagerHostApi.setup(MockTestInstanceManagerHostApi()); - test('clearCookies should call android_webview.clearCookies', () async { final android_webview.CookieManager mockCookieManager = MockCookieManager(); @@ -91,13 +84,11 @@ void main() { final MockAndroidWebViewController mockController = MockAndroidWebViewController(); - final InstanceManager instanceManager = - InstanceManager(onWeakReferenceRemoved: (_) {}); - android_webview.WebView.api = WebViewHostApiImpl( - instanceManager: instanceManager, - ); - final android_webview.WebView webView = android_webview.WebView.detached( - instanceManager: instanceManager, + final android_webview.PigeonInstanceManager instanceManager = + android_webview.PigeonInstanceManager(onWeakReferenceRemoved: (_) {}); + final android_webview.WebView webView = + android_webview.WebView.pigeon_detached( + pigeon_instanceManager: instanceManager, ); const int webViewIdentifier = 4; @@ -111,6 +102,8 @@ void main() { const PlatformWebViewCookieManagerCreationParams()); final android_webview.CookieManager mockCookieManager = MockCookieManager(); + // ignore: invalid_use_of_protected_member + when(mockCookieManager.pigeon_instanceManager).thenReturn(instanceManager); await AndroidWebViewCookieManager( params, @@ -118,7 +111,5 @@ void main() { ).setAcceptThirdPartyCookies(mockController, false); verify(mockCookieManager.setAcceptThirdPartyCookies(webView, false)); - - android_webview.WebView.api = WebViewHostApiImpl(); }); } diff --git a/packages/webview_flutter/webview_flutter_android/test/android_webview_cookie_manager_test.mocks.dart b/packages/webview_flutter/webview_flutter_android/test/android_webview_cookie_manager_test.mocks.dart index ee5e848858fe..303f54d46f64 100644 --- a/packages/webview_flutter/webview_flutter_android/test/android_webview_cookie_manager_test.mocks.dart +++ b/packages/webview_flutter/webview_flutter_android/test/android_webview_cookie_manager_test.mocks.dart @@ -7,14 +7,12 @@ import 'dart:async' as _i5; import 'dart:ui' as _i4; import 'package:mockito/mockito.dart' as _i1; -import 'package:webview_flutter_android/src/android_webview.dart' as _i2; +import 'package:webview_flutter_android/src/android_webkit.g.dart' as _i2; import 'package:webview_flutter_android/src/android_webview_controller.dart' as _i6; import 'package:webview_flutter_platform_interface/webview_flutter_platform_interface.dart' as _i3; -import 'test_android_webview.g.dart' as _i7; - // ignore_for_file: type=lint // ignore_for_file: avoid_redundant_argument_values // ignore_for_file: avoid_setters_without_getters @@ -28,8 +26,19 @@ import 'test_android_webview.g.dart' as _i7; // ignore_for_file: camel_case_types // ignore_for_file: subtype_of_sealed_class -class _FakeCookieManager_0 extends _i1.SmartFake implements _i2.CookieManager { - _FakeCookieManager_0( +class _FakePigeonInstanceManager_0 extends _i1.SmartFake + implements _i2.PigeonInstanceManager { + _FakePigeonInstanceManager_0( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeCookieManager_1 extends _i1.SmartFake implements _i2.CookieManager { + _FakeCookieManager_1( Object parent, Invocation parentInvocation, ) : super( @@ -38,9 +47,9 @@ class _FakeCookieManager_0 extends _i1.SmartFake implements _i2.CookieManager { ); } -class _FakePlatformWebViewControllerCreationParams_1 extends _i1.SmartFake +class _FakePlatformWebViewControllerCreationParams_2 extends _i1.SmartFake implements _i3.PlatformWebViewControllerCreationParams { - _FakePlatformWebViewControllerCreationParams_1( + _FakePlatformWebViewControllerCreationParams_2( Object parent, Invocation parentInvocation, ) : super( @@ -49,8 +58,8 @@ class _FakePlatformWebViewControllerCreationParams_1 extends _i1.SmartFake ); } -class _FakeObject_2 extends _i1.SmartFake implements Object { - _FakeObject_2( +class _FakeObject_3 extends _i1.SmartFake implements Object { + _FakeObject_3( Object parent, Invocation parentInvocation, ) : super( @@ -59,8 +68,8 @@ class _FakeObject_2 extends _i1.SmartFake implements Object { ); } -class _FakeOffset_3 extends _i1.SmartFake implements _i4.Offset { - _FakeOffset_3( +class _FakeOffset_4 extends _i1.SmartFake implements _i4.Offset { + _FakeOffset_4( Object parent, Invocation parentInvocation, ) : super( @@ -77,6 +86,15 @@ class MockCookieManager extends _i1.Mock implements _i2.CookieManager { _i1.throwOnMissingStub(this); } + @override + _i2.PigeonInstanceManager get pigeon_instanceManager => (super.noSuchMethod( + Invocation.getter(#pigeon_instanceManager), + returnValue: _FakePigeonInstanceManager_0( + this, + Invocation.getter(#pigeon_instanceManager), + ), + ) as _i2.PigeonInstanceManager); + @override _i5.Future setCookie( String? url, @@ -121,15 +139,15 @@ class MockCookieManager extends _i1.Mock implements _i2.CookieManager { ) as _i5.Future); @override - _i2.CookieManager copy() => (super.noSuchMethod( + _i2.CookieManager pigeon_copy() => (super.noSuchMethod( Invocation.method( - #copy, + #pigeon_copy, [], ), - returnValue: _FakeCookieManager_0( + returnValue: _FakeCookieManager_1( this, Invocation.method( - #copy, + #pigeon_copy, [], ), ), @@ -154,7 +172,7 @@ class MockAndroidWebViewController extends _i1.Mock @override _i3.PlatformWebViewControllerCreationParams get params => (super.noSuchMethod( Invocation.getter(#params), - returnValue: _FakePlatformWebViewControllerCreationParams_1( + returnValue: _FakePlatformWebViewControllerCreationParams_2( this, Invocation.getter(#params), ), @@ -312,7 +330,7 @@ class MockAndroidWebViewController extends _i1.Mock #runJavaScriptReturningResult, [javaScript], ), - returnValue: _i5.Future.value(_FakeObject_2( + returnValue: _i5.Future.value(_FakeObject_3( this, Invocation.method( #runJavaScriptReturningResult, @@ -393,7 +411,7 @@ class MockAndroidWebViewController extends _i1.Mock #getScrollPosition, [], ), - returnValue: _i5.Future<_i4.Offset>.value(_FakeOffset_3( + returnValue: _i5.Future<_i4.Offset>.value(_FakeOffset_4( this, Invocation.method( #getScrollPosition, @@ -598,22 +616,3 @@ class MockAndroidWebViewController extends _i1.Mock returnValueForMissingStub: _i5.Future.value(), ) as _i5.Future); } - -/// A class which mocks [TestInstanceManagerHostApi]. -/// -/// See the documentation for Mockito's code generation for more information. -class MockTestInstanceManagerHostApi extends _i1.Mock - implements _i7.TestInstanceManagerHostApi { - MockTestInstanceManagerHostApi() { - _i1.throwOnMissingStub(this); - } - - @override - void clear() => super.noSuchMethod( - Invocation.method( - #clear, - [], - ), - returnValueForMissingStub: null, - ); -} diff --git a/packages/webview_flutter/webview_flutter_android/test/android_webview_test.dart b/packages/webview_flutter/webview_flutter_android/test/android_webview_test.dart deleted file mode 100644 index 36b9c0343578..000000000000 --- a/packages/webview_flutter/webview_flutter_android/test/android_webview_test.dart +++ /dev/null @@ -1,1624 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -import 'package:flutter_test/flutter_test.dart'; -import 'package:mockito/annotations.dart'; -import 'package:mockito/mockito.dart'; -import 'package:webview_flutter_android/src/android_webview.dart'; -import 'package:webview_flutter_android/src/android_webview.g.dart'; -import 'package:webview_flutter_android/src/android_webview_api_impls.dart'; -import 'package:webview_flutter_android/src/instance_manager.dart'; - -import 'android_webview_test.mocks.dart'; -import 'test_android_webview.g.dart'; - -@GenerateMocks([ - CookieManagerHostApi, - DownloadListener, - JavaScriptChannel, - TestCookieManagerHostApi, - TestCustomViewCallbackHostApi, - TestDownloadListenerHostApi, - TestGeolocationPermissionsCallbackHostApi, - TestInstanceManagerHostApi, - TestJavaObjectHostApi, - TestJavaScriptChannelHostApi, - TestWebChromeClientHostApi, - TestWebSettingsHostApi, - TestWebStorageHostApi, - TestWebViewClientHostApi, - TestWebViewHostApi, - TestAssetManagerHostApi, - TestPermissionRequestHostApi, - WebChromeClient, - WebView, - WebViewClient, -]) -void main() { - TestWidgetsFlutterBinding.ensureInitialized(); - - // Mocks the calls to the native InstanceManager. - TestInstanceManagerHostApi.setup(MockTestInstanceManagerHostApi()); - TestJavaObjectHostApi.setup(MockTestJavaObjectHostApi()); - - group('Android WebView', () { - group('JavaObject', () { - late MockTestJavaObjectHostApi mockPlatformHostApi; - - setUp(() { - mockPlatformHostApi = MockTestJavaObjectHostApi(); - TestJavaObjectHostApi.setup(mockPlatformHostApi); - }); - - test('JavaObject.dispose', () async { - int? callbackIdentifier; - final InstanceManager instanceManager = InstanceManager( - onWeakReferenceRemoved: (int identifier) { - callbackIdentifier = identifier; - }, - ); - - final JavaObject object = JavaObject.detached( - instanceManager: instanceManager, - ); - instanceManager.addHostCreatedInstance(object, 0); - - JavaObject.dispose(object); - - expect(callbackIdentifier, 0); - }); - - test('JavaObjectFlutterApi.dispose', () { - final InstanceManager instanceManager = InstanceManager( - onWeakReferenceRemoved: (_) {}, - ); - - final JavaObject object = JavaObject.detached( - instanceManager: instanceManager, - ); - instanceManager.addHostCreatedInstance(object, 0); - instanceManager.removeWeakReference(object); - - expect(instanceManager.containsIdentifier(0), isTrue); - - final JavaObjectFlutterApiImpl flutterApi = JavaObjectFlutterApiImpl( - instanceManager: instanceManager, - ); - flutterApi.dispose(0); - - expect(instanceManager.containsIdentifier(0), isFalse); - }); - }); - - group('WebView', () { - late MockTestWebViewHostApi mockPlatformHostApi; - - late InstanceManager instanceManager; - - late WebView webView; - late int webViewInstanceId; - - setUp(() { - mockPlatformHostApi = MockTestWebViewHostApi(); - TestWebViewHostApi.setup(mockPlatformHostApi); - - instanceManager = InstanceManager(onWeakReferenceRemoved: (_) {}); - WebView.api = WebViewHostApiImpl(instanceManager: instanceManager); - - webView = WebView(); - webViewInstanceId = instanceManager.getIdentifier(webView)!; - }); - - test('create', () { - verify(mockPlatformHostApi.create(webViewInstanceId)); - }); - - test('setWebContentsDebuggingEnabled true', () { - WebView.setWebContentsDebuggingEnabled(true); - verify(mockPlatformHostApi.setWebContentsDebuggingEnabled(true)); - }); - - test('setWebContentsDebuggingEnabled false', () { - WebView.setWebContentsDebuggingEnabled(false); - verify(mockPlatformHostApi.setWebContentsDebuggingEnabled(false)); - }); - - test('loadData', () { - webView.loadData( - data: 'hello', - mimeType: 'text/plain', - encoding: 'base64', - ); - verify(mockPlatformHostApi.loadData( - webViewInstanceId, - 'hello', - 'text/plain', - 'base64', - )); - }); - - test('loadData with null values', () { - webView.loadData(data: 'hello'); - verify(mockPlatformHostApi.loadData( - webViewInstanceId, - 'hello', - null, - null, - )); - }); - - test('loadDataWithBaseUrl', () { - webView.loadDataWithBaseUrl( - baseUrl: 'https://base.url', - data: 'hello', - mimeType: 'text/plain', - encoding: 'base64', - historyUrl: 'https://history.url', - ); - - verify(mockPlatformHostApi.loadDataWithBaseUrl( - webViewInstanceId, - 'https://base.url', - 'hello', - 'text/plain', - 'base64', - 'https://history.url', - )); - }); - - test('loadDataWithBaseUrl with null values', () { - webView.loadDataWithBaseUrl(data: 'hello'); - verify(mockPlatformHostApi.loadDataWithBaseUrl( - webViewInstanceId, - null, - 'hello', - null, - null, - null, - )); - }); - - test('loadUrl', () { - webView.loadUrl('hello', {'a': 'header'}); - verify(mockPlatformHostApi.loadUrl( - webViewInstanceId, - 'hello', - {'a': 'header'}, - )); - }); - - test('canGoBack', () { - when(mockPlatformHostApi.canGoBack(webViewInstanceId)) - .thenReturn(false); - expect(webView.canGoBack(), completion(false)); - }); - - test('canGoForward', () { - when(mockPlatformHostApi.canGoForward(webViewInstanceId)) - .thenReturn(true); - expect(webView.canGoForward(), completion(true)); - }); - - test('goBack', () { - webView.goBack(); - verify(mockPlatformHostApi.goBack(webViewInstanceId)); - }); - - test('goForward', () { - webView.goForward(); - verify(mockPlatformHostApi.goForward(webViewInstanceId)); - }); - - test('reload', () { - webView.reload(); - verify(mockPlatformHostApi.reload(webViewInstanceId)); - }); - - test('clearCache', () { - webView.clearCache(false); - verify(mockPlatformHostApi.clearCache(webViewInstanceId, false)); - }); - - test('evaluateJavascript', () { - when( - mockPlatformHostApi.evaluateJavascript( - webViewInstanceId, 'runJavaScript'), - ).thenAnswer((_) => Future.value('returnValue')); - expect( - webView.evaluateJavascript('runJavaScript'), - completion('returnValue'), - ); - }); - - test('getTitle', () { - when(mockPlatformHostApi.getTitle(webViewInstanceId)) - .thenReturn('aTitle'); - expect(webView.getTitle(), completion('aTitle')); - }); - - test('scrollTo', () { - webView.scrollTo(12, 13); - verify(mockPlatformHostApi.scrollTo(webViewInstanceId, 12, 13)); - }); - - test('scrollBy', () { - webView.scrollBy(12, 14); - verify(mockPlatformHostApi.scrollBy(webViewInstanceId, 12, 14)); - }); - - test('getScrollX', () { - when(mockPlatformHostApi.getScrollX(webViewInstanceId)).thenReturn(67); - expect(webView.getScrollX(), completion(67)); - }); - - test('getScrollY', () { - when(mockPlatformHostApi.getScrollY(webViewInstanceId)).thenReturn(56); - expect(webView.getScrollY(), completion(56)); - }); - - test('getScrollPosition', () async { - when(mockPlatformHostApi.getScrollPosition(webViewInstanceId)) - .thenReturn(WebViewPoint(x: 2, y: 16)); - await expectLater( - webView.getScrollPosition(), - completion(const Offset(2.0, 16.0)), - ); - }); - - test('setWebViewClient', () { - TestWebViewClientHostApi.setup(MockTestWebViewClientHostApi()); - WebViewClient.api = WebViewClientHostApiImpl( - instanceManager: instanceManager, - ); - - final WebViewClient mockWebViewClient = MockWebViewClient(); - when(mockWebViewClient.copy()).thenReturn(MockWebViewClient()); - instanceManager.addDartCreatedInstance(mockWebViewClient); - webView.setWebViewClient(mockWebViewClient); - - final int webViewClientInstanceId = - instanceManager.getIdentifier(mockWebViewClient)!; - verify(mockPlatformHostApi.setWebViewClient( - webViewInstanceId, - webViewClientInstanceId, - )); - }); - - test('addJavaScriptChannel', () { - TestJavaScriptChannelHostApi.setup(MockTestJavaScriptChannelHostApi()); - JavaScriptChannel.api = JavaScriptChannelHostApiImpl( - instanceManager: instanceManager, - ); - - final JavaScriptChannel mockJavaScriptChannel = MockJavaScriptChannel(); - when(mockJavaScriptChannel.copy()).thenReturn(MockJavaScriptChannel()); - when(mockJavaScriptChannel.channelName).thenReturn('aChannel'); - - webView.addJavaScriptChannel(mockJavaScriptChannel); - - final int javaScriptChannelInstanceId = - instanceManager.getIdentifier(mockJavaScriptChannel)!; - verify(mockPlatformHostApi.addJavaScriptChannel( - webViewInstanceId, - javaScriptChannelInstanceId, - )); - }); - - test('removeJavaScriptChannel', () { - TestJavaScriptChannelHostApi.setup(MockTestJavaScriptChannelHostApi()); - JavaScriptChannel.api = JavaScriptChannelHostApiImpl( - instanceManager: instanceManager, - ); - - final JavaScriptChannel mockJavaScriptChannel = MockJavaScriptChannel(); - when(mockJavaScriptChannel.copy()).thenReturn(MockJavaScriptChannel()); - when(mockJavaScriptChannel.channelName).thenReturn('aChannel'); - - expect( - webView.removeJavaScriptChannel(mockJavaScriptChannel), - completes, - ); - - webView.addJavaScriptChannel(mockJavaScriptChannel); - webView.removeJavaScriptChannel(mockJavaScriptChannel); - - final int javaScriptChannelInstanceId = - instanceManager.getIdentifier(mockJavaScriptChannel)!; - verify(mockPlatformHostApi.removeJavaScriptChannel( - webViewInstanceId, - javaScriptChannelInstanceId, - )); - }); - - test('setDownloadListener', () { - TestDownloadListenerHostApi.setup(MockTestDownloadListenerHostApi()); - DownloadListener.api = DownloadListenerHostApiImpl( - instanceManager: instanceManager, - ); - - final DownloadListener mockDownloadListener = MockDownloadListener(); - when(mockDownloadListener.copy()).thenReturn(MockDownloadListener()); - instanceManager.addDartCreatedInstance(mockDownloadListener); - webView.setDownloadListener(mockDownloadListener); - - final int downloadListenerInstanceId = - instanceManager.getIdentifier(mockDownloadListener)!; - verify(mockPlatformHostApi.setDownloadListener( - webViewInstanceId, - downloadListenerInstanceId, - )); - }); - - test('setWebChromeClient', () { - TestWebChromeClientHostApi.setup(MockTestWebChromeClientHostApi()); - WebChromeClient.api = WebChromeClientHostApiImpl( - instanceManager: instanceManager, - ); - - final WebChromeClient mockWebChromeClient = MockWebChromeClient(); - when(mockWebChromeClient.copy()).thenReturn(MockWebChromeClient()); - instanceManager.addDartCreatedInstance(mockWebChromeClient); - webView.setWebChromeClient(mockWebChromeClient); - - final int webChromeClientInstanceId = - instanceManager.getIdentifier(mockWebChromeClient)!; - verify(mockPlatformHostApi.setWebChromeClient( - webViewInstanceId, - webChromeClientInstanceId, - )); - }); - - test('FlutterAPI create', () { - final InstanceManager instanceManager = InstanceManager( - onWeakReferenceRemoved: (_) {}, - ); - - final WebViewFlutterApiImpl api = WebViewFlutterApiImpl( - instanceManager: instanceManager, - ); - - const int instanceIdentifier = 0; - api.create(instanceIdentifier); - - expect( - instanceManager.getInstanceWithWeakReference(instanceIdentifier), - isA(), - ); - }); - - test('copy', () { - expect(webView.copy(), isA()); - }); - }); - - group('WebSettings', () { - late MockTestWebSettingsHostApi mockPlatformHostApi; - - late InstanceManager instanceManager; - - late WebSettings webSettings; - late int webSettingsInstanceId; - - setUp(() { - instanceManager = InstanceManager(onWeakReferenceRemoved: (_) {}); - - TestWebViewHostApi.setup(MockTestWebViewHostApi()); - WebView.api = WebViewHostApiImpl(instanceManager: instanceManager); - - mockPlatformHostApi = MockTestWebSettingsHostApi(); - TestWebSettingsHostApi.setup(mockPlatformHostApi); - - WebSettings.api = WebSettingsHostApiImpl( - instanceManager: instanceManager, - ); - - webSettings = WebSettings(WebView()); - webSettingsInstanceId = instanceManager.getIdentifier(webSettings)!; - }); - - test('create', () { - verify(mockPlatformHostApi.create(webSettingsInstanceId, any)); - }); - - test('setDomStorageEnabled', () { - webSettings.setDomStorageEnabled(false); - verify(mockPlatformHostApi.setDomStorageEnabled( - webSettingsInstanceId, - false, - )); - }); - - test('setJavaScriptCanOpenWindowsAutomatically', () { - webSettings.setJavaScriptCanOpenWindowsAutomatically(true); - verify(mockPlatformHostApi.setJavaScriptCanOpenWindowsAutomatically( - webSettingsInstanceId, - true, - )); - }); - - test('setSupportMultipleWindows', () { - webSettings.setSupportMultipleWindows(false); - verify(mockPlatformHostApi.setSupportMultipleWindows( - webSettingsInstanceId, - false, - )); - }); - - test('setJavaScriptEnabled', () { - webSettings.setJavaScriptEnabled(true); - verify(mockPlatformHostApi.setJavaScriptEnabled( - webSettingsInstanceId, - true, - )); - }); - - test('setUserAgentString', () { - webSettings.setUserAgentString('hola'); - verify(mockPlatformHostApi.setUserAgentString( - webSettingsInstanceId, - 'hola', - )); - }); - - test('setMediaPlaybackRequiresUserGesture', () { - webSettings.setMediaPlaybackRequiresUserGesture(false); - verify(mockPlatformHostApi.setMediaPlaybackRequiresUserGesture( - webSettingsInstanceId, - false, - )); - }); - - test('setSupportZoom', () { - webSettings.setSupportZoom(true); - verify(mockPlatformHostApi.setSupportZoom( - webSettingsInstanceId, - true, - )); - }); - - test('setLoadWithOverviewMode', () { - webSettings.setLoadWithOverviewMode(false); - verify(mockPlatformHostApi.setLoadWithOverviewMode( - webSettingsInstanceId, - false, - )); - }); - - test('setUseWideViewPort', () { - webSettings.setUseWideViewPort(true); - verify(mockPlatformHostApi.setUseWideViewPort( - webSettingsInstanceId, - true, - )); - }); - - test('setDisplayZoomControls', () { - webSettings.setDisplayZoomControls(false); - verify(mockPlatformHostApi.setDisplayZoomControls( - webSettingsInstanceId, - false, - )); - }); - - test('setBuiltInZoomControls', () { - webSettings.setBuiltInZoomControls(true); - verify(mockPlatformHostApi.setBuiltInZoomControls( - webSettingsInstanceId, - true, - )); - }); - - test('setAllowFileAccess', () { - webSettings.setAllowFileAccess(true); - verify(mockPlatformHostApi.setAllowFileAccess( - webSettingsInstanceId, - true, - )); - }); - - test('copy', () { - expect(webSettings.copy(), isA()); - }); - - test('setTextZoom', () { - webSettings.setTextZoom(100); - verify(mockPlatformHostApi.setTextZoom( - webSettingsInstanceId, - 100, - )); - }); - - test('getUserAgentString', () async { - const String userAgent = 'str'; - when(mockPlatformHostApi.getUserAgentString(webSettingsInstanceId)) - .thenReturn(userAgent); - expect(await webSettings.getUserAgentString(), userAgent); - }); - }); - - group('JavaScriptChannel', () { - late JavaScriptChannelFlutterApiImpl flutterApi; - - late InstanceManager instanceManager; - - late MockJavaScriptChannel mockJavaScriptChannel; - late int mockJavaScriptChannelInstanceId; - - setUp(() { - instanceManager = InstanceManager(onWeakReferenceRemoved: (_) {}); - flutterApi = JavaScriptChannelFlutterApiImpl( - instanceManager: instanceManager, - ); - - mockJavaScriptChannel = MockJavaScriptChannel(); - when(mockJavaScriptChannel.copy()).thenReturn(MockJavaScriptChannel()); - - mockJavaScriptChannelInstanceId = - instanceManager.addDartCreatedInstance(mockJavaScriptChannel); - }); - - test('postMessage', () { - late final String result; - when(mockJavaScriptChannel.postMessage).thenReturn((String message) { - result = message; - }); - - flutterApi.postMessage( - mockJavaScriptChannelInstanceId, - 'Hello, World!', - ); - - expect(result, 'Hello, World!'); - }); - - test('copy', () { - expect( - JavaScriptChannel.detached('channel', postMessage: (_) {}).copy(), - isA(), - ); - }); - }); - - group('WebViewClient', () { - late WebViewClientFlutterApiImpl flutterApi; - - late InstanceManager instanceManager; - - late MockWebViewClient mockWebViewClient; - late int mockWebViewClientInstanceId; - - late MockWebView mockWebView; - late int mockWebViewInstanceId; - - setUp(() { - instanceManager = InstanceManager(onWeakReferenceRemoved: (_) {}); - flutterApi = WebViewClientFlutterApiImpl( - instanceManager: instanceManager, - ); - - mockWebViewClient = MockWebViewClient(); - when(mockWebViewClient.copy()).thenReturn(MockWebViewClient()); - mockWebViewClientInstanceId = - instanceManager.addDartCreatedInstance(mockWebViewClient); - - mockWebView = MockWebView(); - when(mockWebView.copy()).thenReturn(MockWebView()); - mockWebViewInstanceId = - instanceManager.addDartCreatedInstance(mockWebView); - }); - - test('onPageStarted', () { - late final List result; - when(mockWebViewClient.onPageStarted).thenReturn( - (WebView webView, String url) { - result = [webView, url]; - }, - ); - - flutterApi.onPageStarted( - mockWebViewClientInstanceId, - mockWebViewInstanceId, - 'https://www.google.com', - ); - - expect(result, [mockWebView, 'https://www.google.com']); - }); - - test('onPageFinished', () { - late final List result; - when(mockWebViewClient.onPageFinished).thenReturn( - (WebView webView, String url) { - result = [webView, url]; - }, - ); - - flutterApi.onPageFinished( - mockWebViewClientInstanceId, - mockWebViewInstanceId, - 'https://www.google.com', - ); - - expect(result, [mockWebView, 'https://www.google.com']); - }); - - test('onReceivedHttpError', () { - late final List result; - when(mockWebViewClient.onReceivedHttpError).thenReturn( - ( - WebView webView, - WebResourceRequest request, - WebResourceResponse response, - ) { - result = [webView, request, response]; - }, - ); - - flutterApi.onReceivedHttpError( - mockWebViewClientInstanceId, - mockWebViewInstanceId, - WebResourceRequestData( - url: 'https://www.google.com', - isForMainFrame: true, - hasGesture: true, - method: 'GET', - isRedirect: false, - requestHeaders: {}, - ), - WebResourceResponseData( - statusCode: 401, - ), - ); - - expect(result, [mockWebView, isNotNull, isNotNull]); - }); - - test('onReceivedRequestError', () { - late final List result; - when(mockWebViewClient.onReceivedRequestError).thenReturn( - ( - WebView webView, - WebResourceRequest request, - WebResourceError error, - ) { - result = [webView, request, error]; - }, - ); - - flutterApi.onReceivedRequestError( - mockWebViewClientInstanceId, - mockWebViewInstanceId, - WebResourceRequestData( - url: 'https://www.google.com', - isForMainFrame: true, - hasGesture: true, - method: 'POST', - isRedirect: false, - requestHeaders: {}, - ), - WebResourceErrorData(errorCode: 34, description: 'error description'), - ); - - expect( - result, - containsAllInOrder([mockWebView, isNotNull, isNotNull]), - ); - }); - - test('onReceivedError', () { - late final List result; - when(mockWebViewClient.onReceivedError).thenReturn( - ( - WebView webView, - int errorCode, - String description, - String failingUrl, - ) { - result = [webView, errorCode, description, failingUrl]; - }, - ); - - flutterApi.onReceivedError( - mockWebViewClientInstanceId, - mockWebViewInstanceId, - 14, - 'desc', - 'https://www.google.com', - ); - - expect( - result, - containsAllInOrder( - [mockWebView, 14, 'desc', 'https://www.google.com'], - ), - ); - }); - - test('requestLoading', () { - late final List result; - when(mockWebViewClient.requestLoading).thenReturn( - (WebView webView, WebResourceRequest request) { - result = [webView, request]; - }, - ); - - flutterApi.requestLoading( - mockWebViewClientInstanceId, - mockWebViewInstanceId, - WebResourceRequestData( - url: 'https://www.google.com', - isForMainFrame: true, - hasGesture: true, - method: 'POST', - isRedirect: true, - requestHeaders: {}, - ), - ); - - expect( - result, - containsAllInOrder([mockWebView, isNotNull]), - ); - }); - - test('urlLoading', () { - late final List result; - when(mockWebViewClient.urlLoading).thenReturn( - (WebView webView, String url) { - result = [webView, url]; - }, - ); - - flutterApi.urlLoading(mockWebViewClientInstanceId, - mockWebViewInstanceId, 'https://www.google.com'); - - expect( - result, - containsAllInOrder([mockWebView, 'https://www.google.com']), - ); - }); - - test('doUpdateVisitedHistory', () { - late final List result; - when(mockWebViewClient.doUpdateVisitedHistory).thenReturn( - ( - WebView webView, - String url, - bool isReload, - ) { - result = [webView, url, isReload]; - }, - ); - - flutterApi.doUpdateVisitedHistory( - mockWebViewClientInstanceId, - mockWebViewInstanceId, - 'https://www.google.com', - false, - ); - - expect( - result, - containsAllInOrder( - [mockWebView, 'https://www.google.com', false], - ), - ); - }); - - test('copy', () { - expect(WebViewClient.detached().copy(), isA()); - }); - }); - - group('DownloadListener', () { - late DownloadListenerFlutterApiImpl flutterApi; - - late InstanceManager instanceManager; - - late MockDownloadListener mockDownloadListener; - late int mockDownloadListenerInstanceId; - - setUp(() { - instanceManager = InstanceManager(onWeakReferenceRemoved: (_) {}); - flutterApi = DownloadListenerFlutterApiImpl( - instanceManager: instanceManager, - ); - - mockDownloadListener = MockDownloadListener(); - when(mockDownloadListener.copy()).thenReturn(MockDownloadListener()); - mockDownloadListenerInstanceId = - instanceManager.addDartCreatedInstance(mockDownloadListener); - }); - - test('onDownloadStart', () { - late final List result; - when(mockDownloadListener.onDownloadStart).thenReturn( - ( - String url, - String userAgent, - String contentDisposition, - String mimetype, - int contentLength, - ) { - result = [ - url, - userAgent, - contentDisposition, - mimetype, - contentLength, - ]; - }, - ); - - flutterApi.onDownloadStart( - mockDownloadListenerInstanceId, - 'url', - 'userAgent', - 'contentDescription', - 'mimetype', - 45, - ); - - expect( - result, - containsAllInOrder([ - 'url', - 'userAgent', - 'contentDescription', - 'mimetype', - 45, - ]), - ); - }); - - test('copy', () { - expect( - DownloadListener.detached( - onDownloadStart: (_, __, ____, _____, ______) {}, - ).copy(), - isA(), - ); - }); - }); - - group('WebChromeClient', () { - late WebChromeClientFlutterApiImpl flutterApi; - - late InstanceManager instanceManager; - - late MockWebChromeClient mockWebChromeClient; - late int mockWebChromeClientInstanceId; - - late MockWebView mockWebView; - late int mockWebViewInstanceId; - - setUp(() { - instanceManager = InstanceManager(onWeakReferenceRemoved: (_) {}); - flutterApi = WebChromeClientFlutterApiImpl( - instanceManager: instanceManager, - ); - - mockWebChromeClient = MockWebChromeClient(); - when(mockWebChromeClient.copy()).thenReturn(MockWebChromeClient()); - - mockWebChromeClientInstanceId = - instanceManager.addDartCreatedInstance(mockWebChromeClient); - - mockWebView = MockWebView(); - when(mockWebView.copy()).thenReturn(MockWebView()); - mockWebViewInstanceId = - instanceManager.addDartCreatedInstance(mockWebView); - }); - - test('onProgressChanged', () { - late final List result; - when(mockWebChromeClient.onProgressChanged).thenReturn( - (WebView webView, int progress) { - result = [webView, progress]; - }, - ); - - flutterApi.onProgressChanged( - mockWebChromeClientInstanceId, - mockWebViewInstanceId, - 76, - ); - - expect(result, containsAllInOrder([mockWebView, 76])); - }); - - test('onGeolocationPermissionsShowPrompt', () async { - const String origin = 'https://www.example.com'; - final GeolocationPermissionsCallback callback = - GeolocationPermissionsCallback.detached(); - final int paramsId = instanceManager.addDartCreatedInstance(callback); - late final GeolocationPermissionsCallback outerCallback; - when(mockWebChromeClient.onGeolocationPermissionsShowPrompt).thenReturn( - (String origin, GeolocationPermissionsCallback callback) async { - outerCallback = callback; - }, - ); - flutterApi.onGeolocationPermissionsShowPrompt( - mockWebChromeClientInstanceId, - paramsId, - origin, - ); - await expectLater( - outerCallback, - callback, - ); - }); - - test('onShowFileChooser', () async { - late final List result; - when(mockWebChromeClient.onShowFileChooser).thenReturn( - (WebView webView, FileChooserParams params) { - result = [webView, params]; - return Future>.value(['fileOne', 'fileTwo']); - }, - ); - - final FileChooserParams params = FileChooserParams.detached( - isCaptureEnabled: false, - acceptTypes: [], - filenameHint: 'filenameHint', - mode: FileChooserMode.open, - ); - - instanceManager.addHostCreatedInstance(params, 3); - - await expectLater( - flutterApi.onShowFileChooser( - mockWebChromeClientInstanceId, - mockWebViewInstanceId, - 3, - ), - completion(['fileOne', 'fileTwo']), - ); - expect(result[0], mockWebView); - expect(result[1], params); - }); - - test('setSynchronousReturnValueForOnShowFileChooser', () { - final MockTestWebChromeClientHostApi mockHostApi = - MockTestWebChromeClientHostApi(); - TestWebChromeClientHostApi.setup(mockHostApi); - - WebChromeClient.api = - WebChromeClientHostApiImpl(instanceManager: instanceManager); - - final WebChromeClient webChromeClient = WebChromeClient.detached(); - instanceManager.addHostCreatedInstance(webChromeClient, 2); - - webChromeClient.setSynchronousReturnValueForOnShowFileChooser(false); - - verify( - mockHostApi.setSynchronousReturnValueForOnShowFileChooser(2, false), - ); - }); - - test( - 'setSynchronousReturnValueForOnShowFileChooser throws StateError when onShowFileChooser is null', - () { - final MockTestWebChromeClientHostApi mockHostApi = - MockTestWebChromeClientHostApi(); - TestWebChromeClientHostApi.setup(mockHostApi); - - WebChromeClient.api = - WebChromeClientHostApiImpl(instanceManager: instanceManager); - - final WebChromeClient clientWithNullCallback = - WebChromeClient.detached(); - instanceManager.addHostCreatedInstance(clientWithNullCallback, 2); - - expect( - () => clientWithNullCallback - .setSynchronousReturnValueForOnShowFileChooser(true), - throwsStateError, - ); - - final WebChromeClient clientWithNonnullCallback = - WebChromeClient.detached( - onShowFileChooser: (_, __) async => [], - ); - instanceManager.addHostCreatedInstance(clientWithNonnullCallback, 3); - - clientWithNonnullCallback - .setSynchronousReturnValueForOnShowFileChooser(true); - - verify( - mockHostApi.setSynchronousReturnValueForOnShowFileChooser(3, true), - ); - }); - - test('onPermissionRequest', () { - final InstanceManager instanceManager = InstanceManager( - onWeakReferenceRemoved: (_) {}, - ); - - const int instanceIdentifier = 0; - late final List callbackParameters; - final WebChromeClient instance = WebChromeClient.detached( - onPermissionRequest: ( - WebChromeClient instance, - PermissionRequest request, - ) { - callbackParameters = [ - instance, - request, - ]; - }, - instanceManager: instanceManager, - ); - instanceManager.addHostCreatedInstance(instance, instanceIdentifier); - - final WebChromeClientFlutterApiImpl flutterApi = - WebChromeClientFlutterApiImpl( - instanceManager: instanceManager, - ); - - final PermissionRequest request = PermissionRequest.detached( - resources: [], - binaryMessenger: null, - instanceManager: instanceManager, - ); - const int requestIdentifier = 32; - instanceManager.addHostCreatedInstance( - request, - requestIdentifier, - ); - - flutterApi.onPermissionRequest( - instanceIdentifier, - requestIdentifier, - ); - - expect(callbackParameters, [instance, request]); - }); - - test('onShowCustomView', () { - final InstanceManager instanceManager = InstanceManager( - onWeakReferenceRemoved: (_) {}, - ); - - const int instanceIdentifier = 0; - late final List callbackParameters; - final WebChromeClient instance = WebChromeClient.detached( - onShowCustomView: ( - WebChromeClient instance, - View view, - CustomViewCallback callback, - ) { - callbackParameters = [ - instance, - view, - callback, - ]; - }, - instanceManager: instanceManager, - ); - instanceManager.addHostCreatedInstance(instance, instanceIdentifier); - - final WebChromeClientFlutterApiImpl flutterApi = - WebChromeClientFlutterApiImpl( - instanceManager: instanceManager, - ); - - final View view = View.detached( - instanceManager: instanceManager, - ); - const int viewIdentifier = 50; - instanceManager.addHostCreatedInstance(view, viewIdentifier); - - final CustomViewCallback callback = CustomViewCallback.detached( - instanceManager: instanceManager, - ); - const int callbackIdentifier = 51; - instanceManager.addHostCreatedInstance(callback, callbackIdentifier); - - flutterApi.onShowCustomView( - instanceIdentifier, - viewIdentifier, - callbackIdentifier, - ); - - expect(callbackParameters, [ - instance, - view, - callback, - ]); - }); - - test('onHideCustomView', () { - final InstanceManager instanceManager = InstanceManager( - onWeakReferenceRemoved: (_) {}, - ); - - const int instanceIdentifier = 0; - late final List callbackParameters; - final WebChromeClient instance = WebChromeClient.detached( - onHideCustomView: ( - WebChromeClient instance, - ) { - callbackParameters = [ - instance, - ]; - }, - instanceManager: instanceManager, - ); - instanceManager.addHostCreatedInstance(instance, instanceIdentifier); - - final WebChromeClientFlutterApiImpl flutterApi = - WebChromeClientFlutterApiImpl( - instanceManager: instanceManager, - ); - - flutterApi.onHideCustomView(instanceIdentifier); - - expect(callbackParameters, [instance]); - }); - - test('onConsoleMessage', () async { - late final List result; - when(mockWebChromeClient.onConsoleMessage).thenReturn( - (WebChromeClient instance, ConsoleMessage message) { - result = [instance, message]; - }, - ); - - final ConsoleMessage message = ConsoleMessage( - lineNumber: 0, - message: 'message', - level: ConsoleMessageLevel.error, - sourceId: 'sourceId', - ); - - flutterApi.onConsoleMessage( - mockWebChromeClientInstanceId, - message, - ); - expect(result[0], mockWebChromeClient); - expect(result[1], message); - }); - - test('setSynchronousReturnValueForOnConsoleMessage', () { - final MockTestWebChromeClientHostApi mockHostApi = - MockTestWebChromeClientHostApi(); - TestWebChromeClientHostApi.setup(mockHostApi); - - WebChromeClient.api = - WebChromeClientHostApiImpl(instanceManager: instanceManager); - - final WebChromeClient webChromeClient = WebChromeClient.detached(); - instanceManager.addHostCreatedInstance(webChromeClient, 2); - - webChromeClient.setSynchronousReturnValueForOnConsoleMessage(false); - - verify( - mockHostApi.setSynchronousReturnValueForOnConsoleMessage(2, false), - ); - }); - - test( - 'setSynchronousReturnValueForOnConsoleMessage throws StateError when onConsoleMessage is null', - () { - final MockTestWebChromeClientHostApi mockHostApi = - MockTestWebChromeClientHostApi(); - TestWebChromeClientHostApi.setup(mockHostApi); - - WebChromeClient.api = - WebChromeClientHostApiImpl(instanceManager: instanceManager); - - final WebChromeClient clientWithNullCallback = - WebChromeClient.detached(); - instanceManager.addHostCreatedInstance(clientWithNullCallback, 2); - - expect( - () => clientWithNullCallback - .setSynchronousReturnValueForOnConsoleMessage(true), - throwsStateError, - ); - - final WebChromeClient clientWithNonnullCallback = - WebChromeClient.detached( - onConsoleMessage: (_, __) async {}, - ); - instanceManager.addHostCreatedInstance(clientWithNonnullCallback, 3); - - clientWithNonnullCallback - .setSynchronousReturnValueForOnConsoleMessage(true); - - verify( - mockHostApi.setSynchronousReturnValueForOnConsoleMessage(3, true), - ); - }); - - test('copy', () { - expect(WebChromeClient.detached().copy(), isA()); - }); - }); - - test('onGeolocationPermissionsHidePrompt', () { - final InstanceManager instanceManager = InstanceManager( - onWeakReferenceRemoved: (_) {}, - ); - - const int instanceIdentifier = 0; - late final List callbackParameters; - final WebChromeClient instance = WebChromeClient.detached( - onGeolocationPermissionsHidePrompt: (WebChromeClient instance) { - callbackParameters = [instance]; - }, - instanceManager: instanceManager, - ); - instanceManager.addHostCreatedInstance(instance, instanceIdentifier); - - final WebChromeClientFlutterApiImpl flutterApi = - WebChromeClientFlutterApiImpl(instanceManager: instanceManager); - - flutterApi.onGeolocationPermissionsHidePrompt(instanceIdentifier); - - expect(callbackParameters, [instance]); - }); - - test('copy', () { - expect(WebChromeClient.detached().copy(), isA()); - }); - }); - - group('FileChooserParams', () { - test('FlutterApi create', () { - final InstanceManager instanceManager = InstanceManager( - onWeakReferenceRemoved: (_) {}, - ); - - final FileChooserParamsFlutterApiImpl flutterApi = - FileChooserParamsFlutterApiImpl( - instanceManager: instanceManager, - ); - - flutterApi.create( - 0, - false, - const ['my', 'list'], - FileChooserMode.openMultiple, - 'filenameHint', - ); - - final FileChooserParams instance = - instanceManager.getInstanceWithWeakReference(0)! as FileChooserParams; - expect(instance.isCaptureEnabled, false); - expect(instance.acceptTypes, const ['my', 'list']); - expect(instance.mode, FileChooserMode.openMultiple); - expect(instance.filenameHint, 'filenameHint'); - }); - - group('CustomViewCallback', () { - tearDown(() { - TestCustomViewCallbackHostApi.setup(null); - }); - - test('onCustomViewHidden', () async { - final MockTestCustomViewCallbackHostApi mockApi = - MockTestCustomViewCallbackHostApi(); - TestCustomViewCallbackHostApi.setup(mockApi); - - final InstanceManager instanceManager = InstanceManager( - onWeakReferenceRemoved: (_) {}, - ); - - final CustomViewCallback instance = CustomViewCallback.detached( - instanceManager: instanceManager, - ); - const int instanceIdentifier = 0; - instanceManager.addHostCreatedInstance(instance, instanceIdentifier); - - await instance.onCustomViewHidden(); - - verify(mockApi.onCustomViewHidden(instanceIdentifier)); - }); - - test('FlutterAPI create', () { - final InstanceManager instanceManager = InstanceManager( - onWeakReferenceRemoved: (_) {}, - ); - - final CustomViewCallbackFlutterApiImpl api = - CustomViewCallbackFlutterApiImpl( - instanceManager: instanceManager, - ); - - const int instanceIdentifier = 0; - - api.create(instanceIdentifier); - - expect( - instanceManager.getInstanceWithWeakReference(instanceIdentifier), - isA(), - ); - }); - }); - - group('View', () { - test('FlutterAPI create', () { - final InstanceManager instanceManager = InstanceManager( - onWeakReferenceRemoved: (_) {}, - ); - - final ViewFlutterApiImpl api = ViewFlutterApiImpl( - instanceManager: instanceManager, - ); - - const int instanceIdentifier = 0; - - api.create(instanceIdentifier); - - expect( - instanceManager.getInstanceWithWeakReference(instanceIdentifier), - isA(), - ); - }); - }); - }); - - group('CookieManager', () { - tearDown(() { - TestCookieManagerHostApi.setup(null); - }); - - test('instance', () { - final MockTestCookieManagerHostApi mockApi = - MockTestCookieManagerHostApi(); - TestCookieManagerHostApi.setup(mockApi); - - final CookieManager instance = CookieManager.instance; - - verify(mockApi.attachInstance( - JavaObject.globalInstanceManager.getIdentifier(instance), - )); - }); - - test('setCookie', () async { - final MockTestCookieManagerHostApi mockApi = - MockTestCookieManagerHostApi(); - TestCookieManagerHostApi.setup(mockApi); - - final InstanceManager instanceManager = InstanceManager( - onWeakReferenceRemoved: (_) {}, - ); - - final CookieManager instance = CookieManager.detached( - instanceManager: instanceManager, - ); - const int instanceIdentifier = 0; - instanceManager.addHostCreatedInstance(instance, instanceIdentifier); - - const String url = 'testString'; - const String value = 'testString2'; - - await instance.setCookie(url, value); - - verify(mockApi.setCookie(instanceIdentifier, url, value)); - }); - - test('clearCookies', () async { - final MockTestCookieManagerHostApi mockApi = - MockTestCookieManagerHostApi(); - TestCookieManagerHostApi.setup(mockApi); - - final InstanceManager instanceManager = InstanceManager( - onWeakReferenceRemoved: (_) {}, - ); - - final CookieManager instance = CookieManager.detached( - instanceManager: instanceManager, - ); - const int instanceIdentifier = 0; - instanceManager.addHostCreatedInstance(instance, instanceIdentifier); - - const bool result = true; - when(mockApi.removeAllCookies( - instanceIdentifier, - )).thenAnswer((_) => Future.value(result)); - - expect(await instance.removeAllCookies(), result); - - verify(mockApi.removeAllCookies(instanceIdentifier)); - }); - - test('setAcceptThirdPartyCookies', () async { - final MockTestCookieManagerHostApi mockApi = - MockTestCookieManagerHostApi(); - TestCookieManagerHostApi.setup(mockApi); - - final InstanceManager instanceManager = InstanceManager( - onWeakReferenceRemoved: (_) {}, - ); - - final CookieManager instance = CookieManager.detached( - instanceManager: instanceManager, - ); - const int instanceIdentifier = 0; - instanceManager.addHostCreatedInstance(instance, instanceIdentifier); - - final WebView webView = WebView.detached( - instanceManager: instanceManager, - ); - const int webViewIdentifier = 4; - instanceManager.addHostCreatedInstance(webView, webViewIdentifier); - - const bool accept = true; - - await instance.setAcceptThirdPartyCookies( - webView, - accept, - ); - - verify(mockApi.setAcceptThirdPartyCookies( - instanceIdentifier, - webViewIdentifier, - accept, - )); - }); - }); - - group('WebStorage', () { - late MockTestWebStorageHostApi mockPlatformHostApi; - - late WebStorage webStorage; - late int webStorageInstanceId; - - setUp(() { - mockPlatformHostApi = MockTestWebStorageHostApi(); - TestWebStorageHostApi.setup(mockPlatformHostApi); - - webStorage = WebStorage(); - webStorageInstanceId = - WebStorage.api.instanceManager.getIdentifier(webStorage)!; - }); - - test('create', () { - verify(mockPlatformHostApi.create(webStorageInstanceId)); - }); - - test('deleteAllData', () { - webStorage.deleteAllData(); - verify(mockPlatformHostApi.deleteAllData(webStorageInstanceId)); - }); - - test('copy', () { - expect(WebStorage.detached().copy(), isA()); - }); - }); - - group('PermissionRequest', () { - setUp(() {}); - - tearDown(() { - TestPermissionRequestHostApi.setup(null); - }); - - test('grant', () async { - final MockTestPermissionRequestHostApi mockApi = - MockTestPermissionRequestHostApi(); - TestPermissionRequestHostApi.setup(mockApi); - - final InstanceManager instanceManager = InstanceManager( - onWeakReferenceRemoved: (_) {}, - ); - - final PermissionRequest instance = PermissionRequest.detached( - resources: [], - binaryMessenger: null, - instanceManager: instanceManager, - ); - const int instanceIdentifier = 0; - instanceManager.addHostCreatedInstance(instance, instanceIdentifier); - - const List resources = [PermissionRequest.audioCapture]; - - await instance.grant(resources); - - verify(mockApi.grant( - instanceIdentifier, - resources, - )); - }); - - test('deny', () async { - final MockTestPermissionRequestHostApi mockApi = - MockTestPermissionRequestHostApi(); - TestPermissionRequestHostApi.setup(mockApi); - - final InstanceManager instanceManager = InstanceManager( - onWeakReferenceRemoved: (_) {}, - ); - - final PermissionRequest instance = PermissionRequest.detached( - resources: [], - binaryMessenger: null, - instanceManager: instanceManager, - ); - const int instanceIdentifier = 0; - instanceManager.addHostCreatedInstance(instance, instanceIdentifier); - - await instance.deny(); - - verify(mockApi.deny(instanceIdentifier)); - }); - }); - - group('GeolocationPermissionsCallback', () { - tearDown(() { - TestGeolocationPermissionsCallbackHostApi.setup(null); - }); - - test('invoke', () async { - final MockTestGeolocationPermissionsCallbackHostApi mockApi = - MockTestGeolocationPermissionsCallbackHostApi(); - TestGeolocationPermissionsCallbackHostApi.setup(mockApi); - - final InstanceManager instanceManager = InstanceManager( - onWeakReferenceRemoved: (_) {}, - ); - - final GeolocationPermissionsCallback instance = - GeolocationPermissionsCallback.detached( - instanceManager: instanceManager, - ); - const int instanceIdentifier = 0; - instanceManager.addHostCreatedInstance(instance, instanceIdentifier); - - const String origin = 'testString'; - const bool allow = true; - const bool retain = true; - - await instance.invoke( - origin, - allow, - retain, - ); - - verify(mockApi.invoke(instanceIdentifier, origin, allow, retain)); - }); - - test('Geolocation FlutterAPI create', () { - final InstanceManager instanceManager = InstanceManager( - onWeakReferenceRemoved: (_) {}, - ); - - final GeolocationPermissionsCallbackFlutterApiImpl api = - GeolocationPermissionsCallbackFlutterApiImpl( - instanceManager: instanceManager, - ); - - const int instanceIdentifier = 0; - api.create(instanceIdentifier); - - expect( - instanceManager.getInstanceWithWeakReference(instanceIdentifier), - isA(), - ); - }); - - test('FlutterAPI create', () { - final InstanceManager instanceManager = InstanceManager( - onWeakReferenceRemoved: (_) {}, - ); - - final PermissionRequestFlutterApiImpl api = - PermissionRequestFlutterApiImpl( - instanceManager: instanceManager, - ); - - const int instanceIdentifier = 0; - - api.create(instanceIdentifier, []); - - expect( - instanceManager.getInstanceWithWeakReference(instanceIdentifier), - isA(), - ); - }); - }); -} diff --git a/packages/webview_flutter/webview_flutter_android/test/android_webview_test.mocks.dart b/packages/webview_flutter/webview_flutter_android/test/android_webview_test.mocks.dart deleted file mode 100644 index 54002135ab51..000000000000 --- a/packages/webview_flutter/webview_flutter_android/test/android_webview_test.mocks.dart +++ /dev/null @@ -1,1750 +0,0 @@ -// Mocks generated by Mockito 5.4.4 from annotations -// in webview_flutter_android/test/android_webview_test.dart. -// Do not manually edit this file. - -// ignore_for_file: no_leading_underscores_for_library_prefixes -import 'dart:async' as _i5; -import 'dart:typed_data' as _i8; -import 'dart:ui' as _i4; - -import 'package:mockito/mockito.dart' as _i1; -import 'package:mockito/src/dummies.dart' as _i6; -import 'package:webview_flutter_android/src/android_webview.dart' as _i2; -import 'package:webview_flutter_android/src/android_webview.g.dart' as _i3; - -import 'test_android_webview.g.dart' as _i7; - -// ignore_for_file: type=lint -// ignore_for_file: avoid_redundant_argument_values -// ignore_for_file: avoid_setters_without_getters -// ignore_for_file: comment_references -// ignore_for_file: deprecated_member_use -// ignore_for_file: deprecated_member_use_from_same_package -// ignore_for_file: implementation_imports -// ignore_for_file: invalid_use_of_visible_for_testing_member -// ignore_for_file: prefer_const_constructors -// ignore_for_file: unnecessary_parenthesis -// ignore_for_file: camel_case_types -// ignore_for_file: subtype_of_sealed_class - -class _FakeDownloadListener_0 extends _i1.SmartFake - implements _i2.DownloadListener { - _FakeDownloadListener_0( - Object parent, - Invocation parentInvocation, - ) : super( - parent, - parentInvocation, - ); -} - -class _FakeJavaScriptChannel_1 extends _i1.SmartFake - implements _i2.JavaScriptChannel { - _FakeJavaScriptChannel_1( - Object parent, - Invocation parentInvocation, - ) : super( - parent, - parentInvocation, - ); -} - -class _FakeWebViewPoint_2 extends _i1.SmartFake implements _i3.WebViewPoint { - _FakeWebViewPoint_2( - Object parent, - Invocation parentInvocation, - ) : super( - parent, - parentInvocation, - ); -} - -class _FakeWebChromeClient_3 extends _i1.SmartFake - implements _i2.WebChromeClient { - _FakeWebChromeClient_3( - Object parent, - Invocation parentInvocation, - ) : super( - parent, - parentInvocation, - ); -} - -class _FakeWebSettings_4 extends _i1.SmartFake implements _i2.WebSettings { - _FakeWebSettings_4( - Object parent, - Invocation parentInvocation, - ) : super( - parent, - parentInvocation, - ); -} - -class _FakeOffset_5 extends _i1.SmartFake implements _i4.Offset { - _FakeOffset_5( - Object parent, - Invocation parentInvocation, - ) : super( - parent, - parentInvocation, - ); -} - -class _FakeWebView_6 extends _i1.SmartFake implements _i2.WebView { - _FakeWebView_6( - Object parent, - Invocation parentInvocation, - ) : super( - parent, - parentInvocation, - ); -} - -class _FakeWebViewClient_7 extends _i1.SmartFake implements _i2.WebViewClient { - _FakeWebViewClient_7( - Object parent, - Invocation parentInvocation, - ) : super( - parent, - parentInvocation, - ); -} - -/// A class which mocks [CookieManagerHostApi]. -/// -/// See the documentation for Mockito's code generation for more information. -class MockCookieManagerHostApi extends _i1.Mock - implements _i3.CookieManagerHostApi { - MockCookieManagerHostApi() { - _i1.throwOnMissingStub(this); - } - - @override - _i5.Future attachInstance(int? arg_instanceIdentifier) => - (super.noSuchMethod( - Invocation.method( - #attachInstance, - [arg_instanceIdentifier], - ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); - - @override - _i5.Future setCookie( - int? arg_identifier, - String? arg_url, - String? arg_value, - ) => - (super.noSuchMethod( - Invocation.method( - #setCookie, - [ - arg_identifier, - arg_url, - arg_value, - ], - ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); - - @override - _i5.Future removeAllCookies(int? arg_identifier) => (super.noSuchMethod( - Invocation.method( - #removeAllCookies, - [arg_identifier], - ), - returnValue: _i5.Future.value(false), - ) as _i5.Future); - - @override - _i5.Future setAcceptThirdPartyCookies( - int? arg_identifier, - int? arg_webViewIdentifier, - bool? arg_accept, - ) => - (super.noSuchMethod( - Invocation.method( - #setAcceptThirdPartyCookies, - [ - arg_identifier, - arg_webViewIdentifier, - arg_accept, - ], - ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); -} - -/// A class which mocks [DownloadListener]. -/// -/// See the documentation for Mockito's code generation for more information. -class MockDownloadListener extends _i1.Mock implements _i2.DownloadListener { - MockDownloadListener() { - _i1.throwOnMissingStub(this); - } - - @override - void Function( - String, - String, - String, - String, - int, - ) get onDownloadStart => (super.noSuchMethod( - Invocation.getter(#onDownloadStart), - returnValue: ( - String url, - String userAgent, - String contentDisposition, - String mimetype, - int contentLength, - ) {}, - ) as void Function( - String, - String, - String, - String, - int, - )); - - @override - _i2.DownloadListener copy() => (super.noSuchMethod( - Invocation.method( - #copy, - [], - ), - returnValue: _FakeDownloadListener_0( - this, - Invocation.method( - #copy, - [], - ), - ), - ) as _i2.DownloadListener); -} - -/// A class which mocks [JavaScriptChannel]. -/// -/// See the documentation for Mockito's code generation for more information. -class MockJavaScriptChannel extends _i1.Mock implements _i2.JavaScriptChannel { - MockJavaScriptChannel() { - _i1.throwOnMissingStub(this); - } - - @override - String get channelName => (super.noSuchMethod( - Invocation.getter(#channelName), - returnValue: _i6.dummyValue( - this, - Invocation.getter(#channelName), - ), - ) as String); - - @override - void Function(String) get postMessage => (super.noSuchMethod( - Invocation.getter(#postMessage), - returnValue: (String message) {}, - ) as void Function(String)); - - @override - _i2.JavaScriptChannel copy() => (super.noSuchMethod( - Invocation.method( - #copy, - [], - ), - returnValue: _FakeJavaScriptChannel_1( - this, - Invocation.method( - #copy, - [], - ), - ), - ) as _i2.JavaScriptChannel); -} - -/// A class which mocks [TestCookieManagerHostApi]. -/// -/// See the documentation for Mockito's code generation for more information. -class MockTestCookieManagerHostApi extends _i1.Mock - implements _i7.TestCookieManagerHostApi { - MockTestCookieManagerHostApi() { - _i1.throwOnMissingStub(this); - } - - @override - void attachInstance(int? instanceIdentifier) => super.noSuchMethod( - Invocation.method( - #attachInstance, - [instanceIdentifier], - ), - returnValueForMissingStub: null, - ); - - @override - void setCookie( - int? identifier, - String? url, - String? value, - ) => - super.noSuchMethod( - Invocation.method( - #setCookie, - [ - identifier, - url, - value, - ], - ), - returnValueForMissingStub: null, - ); - - @override - _i5.Future removeAllCookies(int? identifier) => (super.noSuchMethod( - Invocation.method( - #removeAllCookies, - [identifier], - ), - returnValue: _i5.Future.value(false), - ) as _i5.Future); - - @override - void setAcceptThirdPartyCookies( - int? identifier, - int? webViewIdentifier, - bool? accept, - ) => - super.noSuchMethod( - Invocation.method( - #setAcceptThirdPartyCookies, - [ - identifier, - webViewIdentifier, - accept, - ], - ), - returnValueForMissingStub: null, - ); -} - -/// A class which mocks [TestCustomViewCallbackHostApi]. -/// -/// See the documentation for Mockito's code generation for more information. -class MockTestCustomViewCallbackHostApi extends _i1.Mock - implements _i7.TestCustomViewCallbackHostApi { - MockTestCustomViewCallbackHostApi() { - _i1.throwOnMissingStub(this); - } - - @override - void onCustomViewHidden(int? identifier) => super.noSuchMethod( - Invocation.method( - #onCustomViewHidden, - [identifier], - ), - returnValueForMissingStub: null, - ); -} - -/// A class which mocks [TestDownloadListenerHostApi]. -/// -/// See the documentation for Mockito's code generation for more information. -class MockTestDownloadListenerHostApi extends _i1.Mock - implements _i7.TestDownloadListenerHostApi { - MockTestDownloadListenerHostApi() { - _i1.throwOnMissingStub(this); - } - - @override - void create(int? instanceId) => super.noSuchMethod( - Invocation.method( - #create, - [instanceId], - ), - returnValueForMissingStub: null, - ); -} - -/// A class which mocks [TestGeolocationPermissionsCallbackHostApi]. -/// -/// See the documentation for Mockito's code generation for more information. -class MockTestGeolocationPermissionsCallbackHostApi extends _i1.Mock - implements _i7.TestGeolocationPermissionsCallbackHostApi { - MockTestGeolocationPermissionsCallbackHostApi() { - _i1.throwOnMissingStub(this); - } - - @override - void invoke( - int? instanceId, - String? origin, - bool? allow, - bool? retain, - ) => - super.noSuchMethod( - Invocation.method( - #invoke, - [ - instanceId, - origin, - allow, - retain, - ], - ), - returnValueForMissingStub: null, - ); -} - -/// A class which mocks [TestInstanceManagerHostApi]. -/// -/// See the documentation for Mockito's code generation for more information. -class MockTestInstanceManagerHostApi extends _i1.Mock - implements _i7.TestInstanceManagerHostApi { - MockTestInstanceManagerHostApi() { - _i1.throwOnMissingStub(this); - } - - @override - void clear() => super.noSuchMethod( - Invocation.method( - #clear, - [], - ), - returnValueForMissingStub: null, - ); -} - -/// A class which mocks [TestJavaObjectHostApi]. -/// -/// See the documentation for Mockito's code generation for more information. -class MockTestJavaObjectHostApi extends _i1.Mock - implements _i7.TestJavaObjectHostApi { - MockTestJavaObjectHostApi() { - _i1.throwOnMissingStub(this); - } - - @override - void dispose(int? identifier) => super.noSuchMethod( - Invocation.method( - #dispose, - [identifier], - ), - returnValueForMissingStub: null, - ); -} - -/// A class which mocks [TestJavaScriptChannelHostApi]. -/// -/// See the documentation for Mockito's code generation for more information. -class MockTestJavaScriptChannelHostApi extends _i1.Mock - implements _i7.TestJavaScriptChannelHostApi { - MockTestJavaScriptChannelHostApi() { - _i1.throwOnMissingStub(this); - } - - @override - void create( - int? instanceId, - String? channelName, - ) => - super.noSuchMethod( - Invocation.method( - #create, - [ - instanceId, - channelName, - ], - ), - returnValueForMissingStub: null, - ); -} - -/// A class which mocks [TestWebChromeClientHostApi]. -/// -/// See the documentation for Mockito's code generation for more information. -class MockTestWebChromeClientHostApi extends _i1.Mock - implements _i7.TestWebChromeClientHostApi { - MockTestWebChromeClientHostApi() { - _i1.throwOnMissingStub(this); - } - - @override - void create(int? instanceId) => super.noSuchMethod( - Invocation.method( - #create, - [instanceId], - ), - returnValueForMissingStub: null, - ); - - @override - void setSynchronousReturnValueForOnShowFileChooser( - int? instanceId, - bool? value, - ) => - super.noSuchMethod( - Invocation.method( - #setSynchronousReturnValueForOnShowFileChooser, - [ - instanceId, - value, - ], - ), - returnValueForMissingStub: null, - ); - - @override - void setSynchronousReturnValueForOnConsoleMessage( - int? instanceId, - bool? value, - ) => - super.noSuchMethod( - Invocation.method( - #setSynchronousReturnValueForOnConsoleMessage, - [ - instanceId, - value, - ], - ), - returnValueForMissingStub: null, - ); - - @override - void setSynchronousReturnValueForOnJsAlert( - int? instanceId, - bool? value, - ) => - super.noSuchMethod( - Invocation.method( - #setSynchronousReturnValueForOnJsAlert, - [ - instanceId, - value, - ], - ), - returnValueForMissingStub: null, - ); - - @override - void setSynchronousReturnValueForOnJsConfirm( - int? instanceId, - bool? value, - ) => - super.noSuchMethod( - Invocation.method( - #setSynchronousReturnValueForOnJsConfirm, - [ - instanceId, - value, - ], - ), - returnValueForMissingStub: null, - ); - - @override - void setSynchronousReturnValueForOnJsPrompt( - int? instanceId, - bool? value, - ) => - super.noSuchMethod( - Invocation.method( - #setSynchronousReturnValueForOnJsPrompt, - [ - instanceId, - value, - ], - ), - returnValueForMissingStub: null, - ); -} - -/// A class which mocks [TestWebSettingsHostApi]. -/// -/// See the documentation for Mockito's code generation for more information. -class MockTestWebSettingsHostApi extends _i1.Mock - implements _i7.TestWebSettingsHostApi { - MockTestWebSettingsHostApi() { - _i1.throwOnMissingStub(this); - } - - @override - void create( - int? instanceId, - int? webViewInstanceId, - ) => - super.noSuchMethod( - Invocation.method( - #create, - [ - instanceId, - webViewInstanceId, - ], - ), - returnValueForMissingStub: null, - ); - - @override - void setDomStorageEnabled( - int? instanceId, - bool? flag, - ) => - super.noSuchMethod( - Invocation.method( - #setDomStorageEnabled, - [ - instanceId, - flag, - ], - ), - returnValueForMissingStub: null, - ); - - @override - void setJavaScriptCanOpenWindowsAutomatically( - int? instanceId, - bool? flag, - ) => - super.noSuchMethod( - Invocation.method( - #setJavaScriptCanOpenWindowsAutomatically, - [ - instanceId, - flag, - ], - ), - returnValueForMissingStub: null, - ); - - @override - void setSupportMultipleWindows( - int? instanceId, - bool? support, - ) => - super.noSuchMethod( - Invocation.method( - #setSupportMultipleWindows, - [ - instanceId, - support, - ], - ), - returnValueForMissingStub: null, - ); - - @override - void setJavaScriptEnabled( - int? instanceId, - bool? flag, - ) => - super.noSuchMethod( - Invocation.method( - #setJavaScriptEnabled, - [ - instanceId, - flag, - ], - ), - returnValueForMissingStub: null, - ); - - @override - void setUserAgentString( - int? instanceId, - String? userAgentString, - ) => - super.noSuchMethod( - Invocation.method( - #setUserAgentString, - [ - instanceId, - userAgentString, - ], - ), - returnValueForMissingStub: null, - ); - - @override - void setMediaPlaybackRequiresUserGesture( - int? instanceId, - bool? require, - ) => - super.noSuchMethod( - Invocation.method( - #setMediaPlaybackRequiresUserGesture, - [ - instanceId, - require, - ], - ), - returnValueForMissingStub: null, - ); - - @override - void setSupportZoom( - int? instanceId, - bool? support, - ) => - super.noSuchMethod( - Invocation.method( - #setSupportZoom, - [ - instanceId, - support, - ], - ), - returnValueForMissingStub: null, - ); - - @override - void setLoadWithOverviewMode( - int? instanceId, - bool? overview, - ) => - super.noSuchMethod( - Invocation.method( - #setLoadWithOverviewMode, - [ - instanceId, - overview, - ], - ), - returnValueForMissingStub: null, - ); - - @override - void setUseWideViewPort( - int? instanceId, - bool? use, - ) => - super.noSuchMethod( - Invocation.method( - #setUseWideViewPort, - [ - instanceId, - use, - ], - ), - returnValueForMissingStub: null, - ); - - @override - void setDisplayZoomControls( - int? instanceId, - bool? enabled, - ) => - super.noSuchMethod( - Invocation.method( - #setDisplayZoomControls, - [ - instanceId, - enabled, - ], - ), - returnValueForMissingStub: null, - ); - - @override - void setBuiltInZoomControls( - int? instanceId, - bool? enabled, - ) => - super.noSuchMethod( - Invocation.method( - #setBuiltInZoomControls, - [ - instanceId, - enabled, - ], - ), - returnValueForMissingStub: null, - ); - - @override - void setAllowFileAccess( - int? instanceId, - bool? enabled, - ) => - super.noSuchMethod( - Invocation.method( - #setAllowFileAccess, - [ - instanceId, - enabled, - ], - ), - returnValueForMissingStub: null, - ); - - @override - void setTextZoom( - int? instanceId, - int? textZoom, - ) => - super.noSuchMethod( - Invocation.method( - #setTextZoom, - [ - instanceId, - textZoom, - ], - ), - returnValueForMissingStub: null, - ); - - @override - String getUserAgentString(int? instanceId) => (super.noSuchMethod( - Invocation.method( - #getUserAgentString, - [instanceId], - ), - returnValue: _i6.dummyValue( - this, - Invocation.method( - #getUserAgentString, - [instanceId], - ), - ), - ) as String); -} - -/// A class which mocks [TestWebStorageHostApi]. -/// -/// See the documentation for Mockito's code generation for more information. -class MockTestWebStorageHostApi extends _i1.Mock - implements _i7.TestWebStorageHostApi { - MockTestWebStorageHostApi() { - _i1.throwOnMissingStub(this); - } - - @override - void create(int? instanceId) => super.noSuchMethod( - Invocation.method( - #create, - [instanceId], - ), - returnValueForMissingStub: null, - ); - - @override - void deleteAllData(int? instanceId) => super.noSuchMethod( - Invocation.method( - #deleteAllData, - [instanceId], - ), - returnValueForMissingStub: null, - ); -} - -/// A class which mocks [TestWebViewClientHostApi]. -/// -/// See the documentation for Mockito's code generation for more information. -class MockTestWebViewClientHostApi extends _i1.Mock - implements _i7.TestWebViewClientHostApi { - MockTestWebViewClientHostApi() { - _i1.throwOnMissingStub(this); - } - - @override - void create(int? instanceId) => super.noSuchMethod( - Invocation.method( - #create, - [instanceId], - ), - returnValueForMissingStub: null, - ); - - @override - void setSynchronousReturnValueForShouldOverrideUrlLoading( - int? instanceId, - bool? value, - ) => - super.noSuchMethod( - Invocation.method( - #setSynchronousReturnValueForShouldOverrideUrlLoading, - [ - instanceId, - value, - ], - ), - returnValueForMissingStub: null, - ); -} - -/// A class which mocks [TestWebViewHostApi]. -/// -/// See the documentation for Mockito's code generation for more information. -class MockTestWebViewHostApi extends _i1.Mock - implements _i7.TestWebViewHostApi { - MockTestWebViewHostApi() { - _i1.throwOnMissingStub(this); - } - - @override - void create(int? instanceId) => super.noSuchMethod( - Invocation.method( - #create, - [instanceId], - ), - returnValueForMissingStub: null, - ); - - @override - void loadData( - int? instanceId, - String? data, - String? mimeType, - String? encoding, - ) => - super.noSuchMethod( - Invocation.method( - #loadData, - [ - instanceId, - data, - mimeType, - encoding, - ], - ), - returnValueForMissingStub: null, - ); - - @override - void loadDataWithBaseUrl( - int? instanceId, - String? baseUrl, - String? data, - String? mimeType, - String? encoding, - String? historyUrl, - ) => - super.noSuchMethod( - Invocation.method( - #loadDataWithBaseUrl, - [ - instanceId, - baseUrl, - data, - mimeType, - encoding, - historyUrl, - ], - ), - returnValueForMissingStub: null, - ); - - @override - void loadUrl( - int? instanceId, - String? url, - Map? headers, - ) => - super.noSuchMethod( - Invocation.method( - #loadUrl, - [ - instanceId, - url, - headers, - ], - ), - returnValueForMissingStub: null, - ); - - @override - void postUrl( - int? instanceId, - String? url, - _i8.Uint8List? data, - ) => - super.noSuchMethod( - Invocation.method( - #postUrl, - [ - instanceId, - url, - data, - ], - ), - returnValueForMissingStub: null, - ); - - @override - String? getUrl(int? instanceId) => (super.noSuchMethod(Invocation.method( - #getUrl, - [instanceId], - )) as String?); - - @override - bool canGoBack(int? instanceId) => (super.noSuchMethod( - Invocation.method( - #canGoBack, - [instanceId], - ), - returnValue: false, - ) as bool); - - @override - bool canGoForward(int? instanceId) => (super.noSuchMethod( - Invocation.method( - #canGoForward, - [instanceId], - ), - returnValue: false, - ) as bool); - - @override - void goBack(int? instanceId) => super.noSuchMethod( - Invocation.method( - #goBack, - [instanceId], - ), - returnValueForMissingStub: null, - ); - - @override - void goForward(int? instanceId) => super.noSuchMethod( - Invocation.method( - #goForward, - [instanceId], - ), - returnValueForMissingStub: null, - ); - - @override - void reload(int? instanceId) => super.noSuchMethod( - Invocation.method( - #reload, - [instanceId], - ), - returnValueForMissingStub: null, - ); - - @override - void clearCache( - int? instanceId, - bool? includeDiskFiles, - ) => - super.noSuchMethod( - Invocation.method( - #clearCache, - [ - instanceId, - includeDiskFiles, - ], - ), - returnValueForMissingStub: null, - ); - - @override - _i5.Future evaluateJavascript( - int? instanceId, - String? javascriptString, - ) => - (super.noSuchMethod( - Invocation.method( - #evaluateJavascript, - [ - instanceId, - javascriptString, - ], - ), - returnValue: _i5.Future.value(), - ) as _i5.Future); - - @override - String? getTitle(int? instanceId) => (super.noSuchMethod(Invocation.method( - #getTitle, - [instanceId], - )) as String?); - - @override - void scrollTo( - int? instanceId, - int? x, - int? y, - ) => - super.noSuchMethod( - Invocation.method( - #scrollTo, - [ - instanceId, - x, - y, - ], - ), - returnValueForMissingStub: null, - ); - - @override - void scrollBy( - int? instanceId, - int? x, - int? y, - ) => - super.noSuchMethod( - Invocation.method( - #scrollBy, - [ - instanceId, - x, - y, - ], - ), - returnValueForMissingStub: null, - ); - - @override - int getScrollX(int? instanceId) => (super.noSuchMethod( - Invocation.method( - #getScrollX, - [instanceId], - ), - returnValue: 0, - ) as int); - - @override - int getScrollY(int? instanceId) => (super.noSuchMethod( - Invocation.method( - #getScrollY, - [instanceId], - ), - returnValue: 0, - ) as int); - - @override - _i3.WebViewPoint getScrollPosition(int? instanceId) => (super.noSuchMethod( - Invocation.method( - #getScrollPosition, - [instanceId], - ), - returnValue: _FakeWebViewPoint_2( - this, - Invocation.method( - #getScrollPosition, - [instanceId], - ), - ), - ) as _i3.WebViewPoint); - - @override - void setWebContentsDebuggingEnabled(bool? enabled) => super.noSuchMethod( - Invocation.method( - #setWebContentsDebuggingEnabled, - [enabled], - ), - returnValueForMissingStub: null, - ); - - @override - void setWebViewClient( - int? instanceId, - int? webViewClientInstanceId, - ) => - super.noSuchMethod( - Invocation.method( - #setWebViewClient, - [ - instanceId, - webViewClientInstanceId, - ], - ), - returnValueForMissingStub: null, - ); - - @override - void addJavaScriptChannel( - int? instanceId, - int? javaScriptChannelInstanceId, - ) => - super.noSuchMethod( - Invocation.method( - #addJavaScriptChannel, - [ - instanceId, - javaScriptChannelInstanceId, - ], - ), - returnValueForMissingStub: null, - ); - - @override - void removeJavaScriptChannel( - int? instanceId, - int? javaScriptChannelInstanceId, - ) => - super.noSuchMethod( - Invocation.method( - #removeJavaScriptChannel, - [ - instanceId, - javaScriptChannelInstanceId, - ], - ), - returnValueForMissingStub: null, - ); - - @override - void setDownloadListener( - int? instanceId, - int? listenerInstanceId, - ) => - super.noSuchMethod( - Invocation.method( - #setDownloadListener, - [ - instanceId, - listenerInstanceId, - ], - ), - returnValueForMissingStub: null, - ); - - @override - void setWebChromeClient( - int? instanceId, - int? clientInstanceId, - ) => - super.noSuchMethod( - Invocation.method( - #setWebChromeClient, - [ - instanceId, - clientInstanceId, - ], - ), - returnValueForMissingStub: null, - ); - - @override - void setBackgroundColor( - int? instanceId, - int? color, - ) => - super.noSuchMethod( - Invocation.method( - #setBackgroundColor, - [ - instanceId, - color, - ], - ), - returnValueForMissingStub: null, - ); -} - -/// A class which mocks [TestAssetManagerHostApi]. -/// -/// See the documentation for Mockito's code generation for more information. -class MockTestAssetManagerHostApi extends _i1.Mock - implements _i7.TestAssetManagerHostApi { - MockTestAssetManagerHostApi() { - _i1.throwOnMissingStub(this); - } - - @override - List list(String? path) => (super.noSuchMethod( - Invocation.method( - #list, - [path], - ), - returnValue: [], - ) as List); - - @override - String getAssetFilePathByName(String? name) => (super.noSuchMethod( - Invocation.method( - #getAssetFilePathByName, - [name], - ), - returnValue: _i6.dummyValue( - this, - Invocation.method( - #getAssetFilePathByName, - [name], - ), - ), - ) as String); -} - -/// A class which mocks [TestPermissionRequestHostApi]. -/// -/// See the documentation for Mockito's code generation for more information. -class MockTestPermissionRequestHostApi extends _i1.Mock - implements _i7.TestPermissionRequestHostApi { - MockTestPermissionRequestHostApi() { - _i1.throwOnMissingStub(this); - } - - @override - void grant( - int? instanceId, - List? resources, - ) => - super.noSuchMethod( - Invocation.method( - #grant, - [ - instanceId, - resources, - ], - ), - returnValueForMissingStub: null, - ); - - @override - void deny(int? instanceId) => super.noSuchMethod( - Invocation.method( - #deny, - [instanceId], - ), - returnValueForMissingStub: null, - ); -} - -/// A class which mocks [WebChromeClient]. -/// -/// See the documentation for Mockito's code generation for more information. -class MockWebChromeClient extends _i1.Mock implements _i2.WebChromeClient { - MockWebChromeClient() { - _i1.throwOnMissingStub(this); - } - - @override - _i5.Future setSynchronousReturnValueForOnShowFileChooser(bool? value) => - (super.noSuchMethod( - Invocation.method( - #setSynchronousReturnValueForOnShowFileChooser, - [value], - ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); - - @override - _i5.Future setSynchronousReturnValueForOnConsoleMessage(bool? value) => - (super.noSuchMethod( - Invocation.method( - #setSynchronousReturnValueForOnConsoleMessage, - [value], - ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); - - @override - _i5.Future setSynchronousReturnValueForOnJsAlert(bool? value) => - (super.noSuchMethod( - Invocation.method( - #setSynchronousReturnValueForOnJsAlert, - [value], - ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); - - @override - _i5.Future setSynchronousReturnValueForOnJsConfirm(bool? value) => - (super.noSuchMethod( - Invocation.method( - #setSynchronousReturnValueForOnJsConfirm, - [value], - ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); - - @override - _i5.Future setSynchronousReturnValueForOnJsPrompt(bool? value) => - (super.noSuchMethod( - Invocation.method( - #setSynchronousReturnValueForOnJsPrompt, - [value], - ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); - - @override - _i2.WebChromeClient copy() => (super.noSuchMethod( - Invocation.method( - #copy, - [], - ), - returnValue: _FakeWebChromeClient_3( - this, - Invocation.method( - #copy, - [], - ), - ), - ) as _i2.WebChromeClient); -} - -/// A class which mocks [WebView]. -/// -/// See the documentation for Mockito's code generation for more information. -class MockWebView extends _i1.Mock implements _i2.WebView { - MockWebView() { - _i1.throwOnMissingStub(this); - } - - @override - _i2.WebSettings get settings => (super.noSuchMethod( - Invocation.getter(#settings), - returnValue: _FakeWebSettings_4( - this, - Invocation.getter(#settings), - ), - ) as _i2.WebSettings); - - @override - _i5.Future loadData({ - required String? data, - String? mimeType, - String? encoding, - }) => - (super.noSuchMethod( - Invocation.method( - #loadData, - [], - { - #data: data, - #mimeType: mimeType, - #encoding: encoding, - }, - ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); - - @override - _i5.Future loadDataWithBaseUrl({ - String? baseUrl, - required String? data, - String? mimeType, - String? encoding, - String? historyUrl, - }) => - (super.noSuchMethod( - Invocation.method( - #loadDataWithBaseUrl, - [], - { - #baseUrl: baseUrl, - #data: data, - #mimeType: mimeType, - #encoding: encoding, - #historyUrl: historyUrl, - }, - ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); - - @override - _i5.Future loadUrl( - String? url, - Map? headers, - ) => - (super.noSuchMethod( - Invocation.method( - #loadUrl, - [ - url, - headers, - ], - ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); - - @override - _i5.Future postUrl( - String? url, - _i8.Uint8List? data, - ) => - (super.noSuchMethod( - Invocation.method( - #postUrl, - [ - url, - data, - ], - ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); - - @override - _i5.Future getUrl() => (super.noSuchMethod( - Invocation.method( - #getUrl, - [], - ), - returnValue: _i5.Future.value(), - ) as _i5.Future); - - @override - _i5.Future canGoBack() => (super.noSuchMethod( - Invocation.method( - #canGoBack, - [], - ), - returnValue: _i5.Future.value(false), - ) as _i5.Future); - - @override - _i5.Future canGoForward() => (super.noSuchMethod( - Invocation.method( - #canGoForward, - [], - ), - returnValue: _i5.Future.value(false), - ) as _i5.Future); - - @override - _i5.Future goBack() => (super.noSuchMethod( - Invocation.method( - #goBack, - [], - ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); - - @override - _i5.Future goForward() => (super.noSuchMethod( - Invocation.method( - #goForward, - [], - ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); - - @override - _i5.Future reload() => (super.noSuchMethod( - Invocation.method( - #reload, - [], - ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); - - @override - _i5.Future clearCache(bool? includeDiskFiles) => (super.noSuchMethod( - Invocation.method( - #clearCache, - [includeDiskFiles], - ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); - - @override - _i5.Future evaluateJavascript(String? javascriptString) => - (super.noSuchMethod( - Invocation.method( - #evaluateJavascript, - [javascriptString], - ), - returnValue: _i5.Future.value(), - ) as _i5.Future); - - @override - _i5.Future getTitle() => (super.noSuchMethod( - Invocation.method( - #getTitle, - [], - ), - returnValue: _i5.Future.value(), - ) as _i5.Future); - - @override - _i5.Future scrollTo( - int? x, - int? y, - ) => - (super.noSuchMethod( - Invocation.method( - #scrollTo, - [ - x, - y, - ], - ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); - - @override - _i5.Future scrollBy( - int? x, - int? y, - ) => - (super.noSuchMethod( - Invocation.method( - #scrollBy, - [ - x, - y, - ], - ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); - - @override - _i5.Future getScrollX() => (super.noSuchMethod( - Invocation.method( - #getScrollX, - [], - ), - returnValue: _i5.Future.value(0), - ) as _i5.Future); - - @override - _i5.Future getScrollY() => (super.noSuchMethod( - Invocation.method( - #getScrollY, - [], - ), - returnValue: _i5.Future.value(0), - ) as _i5.Future); - - @override - _i5.Future<_i4.Offset> getScrollPosition() => (super.noSuchMethod( - Invocation.method( - #getScrollPosition, - [], - ), - returnValue: _i5.Future<_i4.Offset>.value(_FakeOffset_5( - this, - Invocation.method( - #getScrollPosition, - [], - ), - )), - ) as _i5.Future<_i4.Offset>); - - @override - _i5.Future setWebViewClient(_i2.WebViewClient? webViewClient) => - (super.noSuchMethod( - Invocation.method( - #setWebViewClient, - [webViewClient], - ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); - - @override - _i5.Future addJavaScriptChannel( - _i2.JavaScriptChannel? javaScriptChannel) => - (super.noSuchMethod( - Invocation.method( - #addJavaScriptChannel, - [javaScriptChannel], - ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); - - @override - _i5.Future removeJavaScriptChannel( - _i2.JavaScriptChannel? javaScriptChannel) => - (super.noSuchMethod( - Invocation.method( - #removeJavaScriptChannel, - [javaScriptChannel], - ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); - - @override - _i5.Future setDownloadListener(_i2.DownloadListener? listener) => - (super.noSuchMethod( - Invocation.method( - #setDownloadListener, - [listener], - ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); - - @override - _i5.Future setWebChromeClient(_i2.WebChromeClient? client) => - (super.noSuchMethod( - Invocation.method( - #setWebChromeClient, - [client], - ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); - - @override - _i5.Future setBackgroundColor(_i4.Color? color) => (super.noSuchMethod( - Invocation.method( - #setBackgroundColor, - [color], - ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); - - @override - _i2.WebView copy() => (super.noSuchMethod( - Invocation.method( - #copy, - [], - ), - returnValue: _FakeWebView_6( - this, - Invocation.method( - #copy, - [], - ), - ), - ) as _i2.WebView); -} - -/// A class which mocks [WebViewClient]. -/// -/// See the documentation for Mockito's code generation for more information. -class MockWebViewClient extends _i1.Mock implements _i2.WebViewClient { - MockWebViewClient() { - _i1.throwOnMissingStub(this); - } - - @override - _i5.Future setSynchronousReturnValueForShouldOverrideUrlLoading( - bool? value) => - (super.noSuchMethod( - Invocation.method( - #setSynchronousReturnValueForShouldOverrideUrlLoading, - [value], - ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); - - @override - _i2.WebViewClient copy() => (super.noSuchMethod( - Invocation.method( - #copy, - [], - ), - returnValue: _FakeWebViewClient_7( - this, - Invocation.method( - #copy, - [], - ), - ), - ) as _i2.WebViewClient); -} diff --git a/packages/webview_flutter/webview_flutter_android/test/instance_manager_test.dart b/packages/webview_flutter/webview_flutter_android/test/instance_manager_test.dart deleted file mode 100644 index 67caa96a62f4..000000000000 --- a/packages/webview_flutter/webview_flutter_android/test/instance_manager_test.dart +++ /dev/null @@ -1,166 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -import 'package:flutter_test/flutter_test.dart'; -import 'package:mockito/annotations.dart'; -import 'package:mockito/mockito.dart'; -import 'package:webview_flutter_android/src/android_webview.dart'; -import 'package:webview_flutter_android/src/instance_manager.dart'; - -import 'instance_manager_test.mocks.dart'; -import 'test_android_webview.g.dart'; - -@GenerateMocks([TestInstanceManagerHostApi]) -void main() { - TestWidgetsFlutterBinding.ensureInitialized(); - - group('InstanceManager', () { - test('addHostCreatedInstance', () { - final CopyableObject object = CopyableObject(); - - final InstanceManager instanceManager = - InstanceManager(onWeakReferenceRemoved: (_) {}); - - instanceManager.addHostCreatedInstance(object, 0); - - expect(instanceManager.getIdentifier(object), 0); - expect( - instanceManager.getInstanceWithWeakReference(0), - object, - ); - }); - - test('addHostCreatedInstance prevents already used objects and ids', () { - final CopyableObject object = CopyableObject(); - - final InstanceManager instanceManager = - InstanceManager(onWeakReferenceRemoved: (_) {}); - - instanceManager.addHostCreatedInstance(object, 0); - - expect( - () => instanceManager.addHostCreatedInstance(object, 0), - throwsAssertionError, - ); - - expect( - () => instanceManager.addHostCreatedInstance(CopyableObject(), 0), - throwsAssertionError, - ); - }); - - test('addFlutterCreatedInstance', () { - final CopyableObject object = CopyableObject(); - - final InstanceManager instanceManager = - InstanceManager(onWeakReferenceRemoved: (_) {}); - - instanceManager.addDartCreatedInstance(object); - - final int? instanceId = instanceManager.getIdentifier(object); - expect(instanceId, isNotNull); - expect( - instanceManager.getInstanceWithWeakReference(instanceId!), - object, - ); - }); - - test('removeWeakReference', () { - final CopyableObject object = CopyableObject(); - - int? weakInstanceId; - final InstanceManager instanceManager = - InstanceManager(onWeakReferenceRemoved: (int instanceId) { - weakInstanceId = instanceId; - }); - - instanceManager.addHostCreatedInstance(object, 0); - - expect(instanceManager.removeWeakReference(object), 0); - expect( - instanceManager.getInstanceWithWeakReference(0), - isA(), - ); - expect(weakInstanceId, 0); - }); - - test('removeWeakReference removes only weak reference', () { - final CopyableObject object = CopyableObject(); - - final InstanceManager instanceManager = - InstanceManager(onWeakReferenceRemoved: (_) {}); - - instanceManager.addHostCreatedInstance(object, 0); - - expect(instanceManager.removeWeakReference(object), 0); - final CopyableObject copy = instanceManager.getInstanceWithWeakReference( - 0, - )!; - expect(identical(object, copy), isFalse); - }); - - test('removeStrongReference', () { - final CopyableObject object = CopyableObject(); - - final InstanceManager instanceManager = - InstanceManager(onWeakReferenceRemoved: (_) {}); - - instanceManager.addHostCreatedInstance(object, 0); - instanceManager.removeWeakReference(object); - expect(instanceManager.remove(0), isA()); - expect(instanceManager.containsIdentifier(0), isFalse); - }); - - test('removeStrongReference removes only strong reference', () { - final CopyableObject object = CopyableObject(); - - final InstanceManager instanceManager = - InstanceManager(onWeakReferenceRemoved: (_) {}); - - instanceManager.addHostCreatedInstance(object, 0); - expect(instanceManager.remove(0), isA()); - expect( - instanceManager.getInstanceWithWeakReference(0), - object, - ); - }); - - test('getInstance can add a new weak reference', () { - final CopyableObject object = CopyableObject(); - - final InstanceManager instanceManager = - InstanceManager(onWeakReferenceRemoved: (_) {}); - - instanceManager.addHostCreatedInstance(object, 0); - instanceManager.removeWeakReference(object); - - final CopyableObject newWeakCopy = - instanceManager.getInstanceWithWeakReference( - 0, - )!; - expect(identical(object, newWeakCopy), isFalse); - }); - - test('globalInstanceManager clears native `InstanceManager`', () { - final MockTestInstanceManagerHostApi mockApi = - MockTestInstanceManagerHostApi(); - TestInstanceManagerHostApi.setup(mockApi); - - // Calls method to clear the native InstanceManager. - // ignore: unnecessary_statements - JavaObject.globalInstanceManager; - - verify(mockApi.clear()); - - TestInstanceManagerHostApi.setup(null); - }); - }); -} - -class CopyableObject with Copyable { - @override - Copyable copy() { - return CopyableObject(); - } -} diff --git a/packages/webview_flutter/webview_flutter_android/test/instance_manager_test.mocks.dart b/packages/webview_flutter/webview_flutter_android/test/instance_manager_test.mocks.dart deleted file mode 100644 index d8b4dea0fb83..000000000000 --- a/packages/webview_flutter/webview_flutter_android/test/instance_manager_test.mocks.dart +++ /dev/null @@ -1,40 +0,0 @@ -// Mocks generated by Mockito 5.4.4 from annotations -// in webview_flutter_android/test/instance_manager_test.dart. -// Do not manually edit this file. - -// ignore_for_file: no_leading_underscores_for_library_prefixes -import 'package:mockito/mockito.dart' as _i1; - -import 'test_android_webview.g.dart' as _i2; - -// ignore_for_file: type=lint -// ignore_for_file: avoid_redundant_argument_values -// ignore_for_file: avoid_setters_without_getters -// ignore_for_file: comment_references -// ignore_for_file: deprecated_member_use -// ignore_for_file: deprecated_member_use_from_same_package -// ignore_for_file: implementation_imports -// ignore_for_file: invalid_use_of_visible_for_testing_member -// ignore_for_file: prefer_const_constructors -// ignore_for_file: unnecessary_parenthesis -// ignore_for_file: camel_case_types -// ignore_for_file: subtype_of_sealed_class - -/// A class which mocks [TestInstanceManagerHostApi]. -/// -/// See the documentation for Mockito's code generation for more information. -class MockTestInstanceManagerHostApi extends _i1.Mock - implements _i2.TestInstanceManagerHostApi { - MockTestInstanceManagerHostApi() { - _i1.throwOnMissingStub(this); - } - - @override - void clear() => super.noSuchMethod( - Invocation.method( - #clear, - [], - ), - returnValueForMissingStub: null, - ); -} diff --git a/packages/webview_flutter/webview_flutter_android/test/legacy/webview_android_cookie_manager_test.dart b/packages/webview_flutter/webview_flutter_android/test/legacy/webview_android_cookie_manager_test.dart index 02576d0d653c..3738cc8959cf 100644 --- a/packages/webview_flutter/webview_flutter_android/test/legacy/webview_android_cookie_manager_test.dart +++ b/packages/webview_flutter/webview_flutter_android/test/legacy/webview_android_cookie_manager_test.dart @@ -5,7 +5,7 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:mockito/annotations.dart'; import 'package:mockito/mockito.dart'; -import 'package:webview_flutter_android/src/android_webview.dart' +import 'package:webview_flutter_android/src/android_webkit.g.dart' as android_webview; import 'package:webview_flutter_android/src/legacy/webview_android_cookie_manager.dart'; import 'package:webview_flutter_platform_interface/src/webview_flutter_platform_interface_legacy.dart'; diff --git a/packages/webview_flutter/webview_flutter_android/test/legacy/webview_android_cookie_manager_test.mocks.dart b/packages/webview_flutter/webview_flutter_android/test/legacy/webview_android_cookie_manager_test.mocks.dart index 32731152a380..28c0d95b8149 100644 --- a/packages/webview_flutter/webview_flutter_android/test/legacy/webview_android_cookie_manager_test.mocks.dart +++ b/packages/webview_flutter/webview_flutter_android/test/legacy/webview_android_cookie_manager_test.mocks.dart @@ -6,7 +6,7 @@ import 'dart:async' as _i3; import 'package:mockito/mockito.dart' as _i1; -import 'package:webview_flutter_android/src/android_webview.dart' as _i2; +import 'package:webview_flutter_android/src/android_webkit.g.dart' as _i2; // ignore_for_file: type=lint // ignore_for_file: avoid_redundant_argument_values @@ -21,8 +21,19 @@ import 'package:webview_flutter_android/src/android_webview.dart' as _i2; // ignore_for_file: camel_case_types // ignore_for_file: subtype_of_sealed_class -class _FakeCookieManager_0 extends _i1.SmartFake implements _i2.CookieManager { - _FakeCookieManager_0( +class _FakePigeonInstanceManager_0 extends _i1.SmartFake + implements _i2.PigeonInstanceManager { + _FakePigeonInstanceManager_0( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeCookieManager_1 extends _i1.SmartFake implements _i2.CookieManager { + _FakeCookieManager_1( Object parent, Invocation parentInvocation, ) : super( @@ -39,6 +50,15 @@ class MockCookieManager extends _i1.Mock implements _i2.CookieManager { _i1.throwOnMissingStub(this); } + @override + _i2.PigeonInstanceManager get pigeon_instanceManager => (super.noSuchMethod( + Invocation.getter(#pigeon_instanceManager), + returnValue: _FakePigeonInstanceManager_0( + this, + Invocation.getter(#pigeon_instanceManager), + ), + ) as _i2.PigeonInstanceManager); + @override _i3.Future setCookie( String? url, @@ -83,15 +103,15 @@ class MockCookieManager extends _i1.Mock implements _i2.CookieManager { ) as _i3.Future); @override - _i2.CookieManager copy() => (super.noSuchMethod( + _i2.CookieManager pigeon_copy() => (super.noSuchMethod( Invocation.method( - #copy, + #pigeon_copy, [], ), - returnValue: _FakeCookieManager_0( + returnValue: _FakeCookieManager_1( this, Invocation.method( - #copy, + #pigeon_copy, [], ), ), diff --git a/packages/webview_flutter/webview_flutter_android/test/legacy/webview_android_widget_test.dart b/packages/webview_flutter/webview_flutter_android/test/legacy/webview_android_widget_test.dart index 121a623e0ef7..db160b9e5b85 100644 --- a/packages/webview_flutter/webview_flutter_android/test/legacy/webview_android_widget_test.dart +++ b/packages/webview_flutter/webview_flutter_android/test/legacy/webview_android_widget_test.dart @@ -8,15 +8,12 @@ import 'package:flutter/widgets.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:mockito/annotations.dart'; import 'package:mockito/mockito.dart'; -import 'package:webview_flutter_android/src/android_webview.dart' +import 'package:webview_flutter_android/src/android_webkit.g.dart' as android_webview; -import 'package:webview_flutter_android/src/android_webview_api_impls.dart'; -import 'package:webview_flutter_android/src/instance_manager.dart'; +import 'package:webview_flutter_android/src/android_webkit_constants.dart'; import 'package:webview_flutter_android/src/legacy/webview_android_widget.dart'; import 'package:webview_flutter_platform_interface/src/webview_flutter_platform_interface_legacy.dart'; -import '../android_webview_test.mocks.dart' show MockTestWebViewHostApi; -import '../test_android_webview.g.dart'; import 'webview_android_widget_test.mocks.dart'; @GenerateMocks([ @@ -419,28 +416,35 @@ void main() { (WidgetTester tester) async { await buildWidget(tester); - const String htmlString = 'Test data.'; + const String htmlString = + 'Test data.'; await testController.loadHtmlString(htmlString); verify(mockWebView.loadDataWithBaseUrl( - data: htmlString, - mimeType: 'text/html', + null, + htmlString, + 'text/html', + null, + null, )); }); testWidgets('loadHtmlString with base URL', (WidgetTester tester) async { await buildWidget(tester); - const String htmlString = 'Test data.'; + const String htmlString = + 'Test data.'; await testController.loadHtmlString( htmlString, baseUrl: 'https://flutter.dev', ); verify(mockWebView.loadDataWithBaseUrl( - baseUrl: 'https://flutter.dev', - data: htmlString, - mimeType: 'text/html', + 'https://flutter.dev', + htmlString, + 'text/html', + null, + null, )); }); @@ -668,12 +672,8 @@ void main() { await testController.addJavascriptChannels({'c', 'd'}); await testController.removeJavascriptChannels({'c', 'd'}); - final List javaScriptChannels = - verify(mockWebView.removeJavaScriptChannel(captureAny)) - .captured - .cast(); - expect(javaScriptChannels[0].channelName, 'c'); - expect(javaScriptChannels[1].channelName, 'd'); + verify(mockWebView.removeJavaScriptChannel('c')); + verify(mockWebView.removeJavaScriptChannel('d')); }); testWidgets('getTitle', (WidgetTester tester) async { @@ -701,14 +701,22 @@ void main() { testWidgets('getScrollX', (WidgetTester tester) async { await buildWidget(tester); - when(mockWebView.getScrollX()).thenAnswer((_) => Future.value(23)); + when(mockWebView.getScrollPosition()).thenAnswer( + (_) => Future.value( + android_webview.WebViewPoint.pigeon_detached(x: 23, y: 24), + ), + ); expect(testController.getScrollX(), completion(23)); }); testWidgets('getScrollY', (WidgetTester tester) async { await buildWidget(tester); - when(mockWebView.getScrollY()).thenAnswer((_) => Future.value(25)); + when(mockWebView.getScrollPosition()).thenAnswer( + (_) => Future.value( + android_webview.WebViewPoint.pigeon_detached(x: 23, y: 25), + ), + ); expect(testController.getScrollY(), completion(25)); }); }); @@ -716,34 +724,38 @@ void main() { group('WebViewPlatformCallbacksHandler', () { testWidgets('onPageStarted', (WidgetTester tester) async { await buildWidget(tester); - final void Function(android_webview.WebView, String) onPageStarted = - verify(mockWebViewProxy.createWebViewClient( + final void Function( + android_webview.WebViewClient, android_webview.WebView, String) + onPageStarted = verify(mockWebViewProxy.createWebViewClient( onPageStarted: captureAnyNamed('onPageStarted'), onPageFinished: anyNamed('onPageFinished'), onReceivedError: anyNamed('onReceivedError'), onReceivedRequestError: anyNamed('onReceivedRequestError'), requestLoading: anyNamed('requestLoading'), urlLoading: anyNamed('urlLoading'), - )).captured.single as void Function(android_webview.WebView, String); + )).captured.single as void Function( + android_webview.WebViewClient, android_webview.WebView, String); - onPageStarted(mockWebView, 'https://google.com'); + onPageStarted(MockWebViewClient(), mockWebView, 'https://google.com'); verify(mockCallbacksHandler.onPageStarted('https://google.com')); }); testWidgets('onPageFinished', (WidgetTester tester) async { await buildWidget(tester); - final void Function(android_webview.WebView, String) onPageFinished = - verify(mockWebViewProxy.createWebViewClient( + final void Function( + android_webview.WebViewClient, android_webview.WebView, String) + onPageFinished = verify(mockWebViewProxy.createWebViewClient( onPageStarted: anyNamed('onPageStarted'), onPageFinished: captureAnyNamed('onPageFinished'), onReceivedError: anyNamed('onReceivedError'), onReceivedRequestError: anyNamed('onReceivedRequestError'), requestLoading: anyNamed('requestLoading'), urlLoading: anyNamed('urlLoading'), - )).captured.single as void Function(android_webview.WebView, String); + )).captured.single as void Function( + android_webview.WebViewClient, android_webview.WebView, String); - onPageFinished(mockWebView, 'https://google.com'); + onPageFinished(MockWebViewClient(), mockWebView, 'https://google.com'); verify(mockCallbacksHandler.onPageFinished('https://google.com')); }); @@ -751,20 +763,22 @@ void main() { (WidgetTester tester) async { await buildWidget(tester); - final void Function(android_webview.WebView, int, String, String) - onReceivedError = verify(mockWebViewProxy.createWebViewClient( + final void Function(android_webview.WebViewClient, + android_webview.WebView, int, String, String) onReceivedError = + verify(mockWebViewProxy.createWebViewClient( onPageStarted: anyNamed('onPageStarted'), onPageFinished: anyNamed('onPageFinished'), onReceivedError: captureAnyNamed('onReceivedError'), onReceivedRequestError: anyNamed('onReceivedRequestError'), requestLoading: anyNamed('requestLoading'), urlLoading: anyNamed('urlLoading'), - )).captured.single as void Function( + )).captured.single as void Function(android_webview.WebViewClient, android_webview.WebView, int, String, String); onReceivedError( + MockWebViewClient(), mockWebView, - android_webview.WebViewClient.errorAuthentication, + WebViewClientConstants.errorAuthentication, 'description', 'https://google.com', ); @@ -785,6 +799,7 @@ void main() { await buildWidget(tester); final void Function( + android_webview.WebViewClient, android_webview.WebView, android_webview.WebResourceRequest, android_webview.WebResourceError, @@ -796,23 +811,25 @@ void main() { requestLoading: anyNamed('requestLoading'), urlLoading: anyNamed('urlLoading'), )).captured.single as void Function( + android_webview.WebViewClient, android_webview.WebView, android_webview.WebResourceRequest, android_webview.WebResourceError, ); onReceivedRequestError( + MockWebViewClient(), mockWebView, - android_webview.WebResourceRequest( + android_webview.WebResourceRequest.pigeon_detached( url: 'https://google.com', isForMainFrame: true, isRedirect: false, hasGesture: false, method: 'POST', - requestHeaders: {}, + requestHeaders: const {}, ), - android_webview.WebResourceError( - errorCode: android_webview.WebViewClient.errorUnsafeResource, + android_webview.WebResourceError.pigeon_detached( + errorCode: WebViewClientConstants.errorUnsafeResource, description: 'description', ), ); @@ -836,17 +853,19 @@ void main() { url: 'https://google.com', )).thenReturn(true); - final void Function(android_webview.WebView, String) urlLoading = - verify(mockWebViewProxy.createWebViewClient( + final void Function( + android_webview.WebViewClient, android_webview.WebView, String) + urlLoading = verify(mockWebViewProxy.createWebViewClient( onPageStarted: anyNamed('onPageStarted'), onPageFinished: anyNamed('onPageFinished'), onReceivedError: anyNamed('onReceivedError'), onReceivedRequestError: anyNamed('onReceivedRequestError'), requestLoading: anyNamed('requestLoading'), urlLoading: captureAnyNamed('urlLoading'), - )).captured.single as void Function(android_webview.WebView, String); + )).captured.single as void Function( + android_webview.WebViewClient, android_webview.WebView, String); - urlLoading(mockWebView, 'https://google.com'); + urlLoading(MockWebViewClient(), mockWebView, 'https://google.com'); verify(mockCallbacksHandler.onNavigationRequest( url: 'https://google.com', isForMainFrame: true, @@ -863,6 +882,7 @@ void main() { )).thenReturn(true); final void Function( + android_webview.WebViewClient, android_webview.WebView, android_webview.WebResourceRequest, ) requestLoading = verify(mockWebViewProxy.createWebViewClient( @@ -873,19 +893,21 @@ void main() { requestLoading: captureAnyNamed('requestLoading'), urlLoading: anyNamed('urlLoading'), )).captured.single as void Function( + android_webview.WebViewClient, android_webview.WebView, android_webview.WebResourceRequest, ); requestLoading( + MockWebViewClient(), mockWebView, - android_webview.WebResourceRequest( + android_webview.WebResourceRequest.pigeon_detached( url: 'https://google.com', isForMainFrame: true, isRedirect: false, hasGesture: false, method: 'POST', - requestHeaders: {}, + requestHeaders: const {}, ), ); verify(mockCallbacksHandler.onNavigationRequest( @@ -905,7 +927,7 @@ void main() { verify(mockWebView.addJavaScriptChannel(captureAny)) .captured .single as WebViewAndroidJavaScriptChannel; - javaScriptChannel.postMessage('goodbye'); + javaScriptChannel.postMessage(javaScriptChannel, 'goodbye'); verify(mockJavascriptChannelRegistry.onJavascriptChannelMessage( 'hello', 'goodbye', @@ -914,32 +936,4 @@ void main() { }); }); }); - - group('WebViewProxy', () { - late MockTestWebViewHostApi mockPlatformHostApi; - late InstanceManager instanceManager; - - setUp(() { - // WebViewProxy calls static methods that can't be mocked, so the mocks - // have to be set up at the next layer down, by mocking the implementation - // of WebView itstelf. - mockPlatformHostApi = MockTestWebViewHostApi(); - TestWebViewHostApi.setup(mockPlatformHostApi); - instanceManager = InstanceManager(onWeakReferenceRemoved: (_) {}); - android_webview.WebView.api = - WebViewHostApiImpl(instanceManager: instanceManager); - }); - - test('setWebContentsDebuggingEnabled true', () { - const WebViewProxy webViewProxy = WebViewProxy(); - webViewProxy.setWebContentsDebuggingEnabled(true); - verify(mockPlatformHostApi.setWebContentsDebuggingEnabled(true)); - }); - - test('setWebContentsDebuggingEnabled false', () { - const WebViewProxy webViewProxy = WebViewProxy(); - webViewProxy.setWebContentsDebuggingEnabled(false); - verify(mockPlatformHostApi.setWebContentsDebuggingEnabled(false)); - }); - }); } diff --git a/packages/webview_flutter/webview_flutter_android/test/legacy/webview_android_widget_test.mocks.dart b/packages/webview_flutter/webview_flutter_android/test/legacy/webview_android_widget_test.mocks.dart index 84a778786ecc..44c8b8adb47f 100644 --- a/packages/webview_flutter/webview_flutter_android/test/legacy/webview_android_widget_test.mocks.dart +++ b/packages/webview_flutter/webview_flutter_android/test/legacy/webview_android_widget_test.mocks.dart @@ -3,17 +3,16 @@ // Do not manually edit this file. // ignore_for_file: no_leading_underscores_for_library_prefixes -import 'dart:async' as _i5; -import 'dart:typed_data' as _i7; -import 'dart:ui' as _i3; +import 'dart:async' as _i4; +import 'dart:typed_data' as _i6; import 'package:mockito/mockito.dart' as _i1; -import 'package:mockito/src/dummies.dart' as _i6; -import 'package:webview_flutter_android/src/android_webview.dart' as _i2; +import 'package:mockito/src/dummies.dart' as _i5; +import 'package:webview_flutter_android/src/android_webkit.g.dart' as _i2; import 'package:webview_flutter_android/src/legacy/webview_android_widget.dart' - as _i8; + as _i7; import 'package:webview_flutter_platform_interface/src/webview_flutter_platform_interface_legacy.dart' - as _i4; + as _i3; // ignore_for_file: type=lint // ignore_for_file: avoid_redundant_argument_values @@ -28,8 +27,9 @@ import 'package:webview_flutter_platform_interface/src/webview_flutter_platform_ // ignore_for_file: camel_case_types // ignore_for_file: subtype_of_sealed_class -class _FakeWebSettings_0 extends _i1.SmartFake implements _i2.WebSettings { - _FakeWebSettings_0( +class _FakePigeonInstanceManager_0 extends _i1.SmartFake + implements _i2.PigeonInstanceManager { + _FakePigeonInstanceManager_0( Object parent, Invocation parentInvocation, ) : super( @@ -38,8 +38,39 @@ class _FakeWebSettings_0 extends _i1.SmartFake implements _i2.WebSettings { ); } -class _FakeWebStorage_1 extends _i1.SmartFake implements _i2.WebStorage { - _FakeWebStorage_1( +class _FakeFlutterAssetManager_1 extends _i1.SmartFake + implements _i2.FlutterAssetManager { + _FakeFlutterAssetManager_1( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeWebSettings_2 extends _i1.SmartFake implements _i2.WebSettings { + _FakeWebSettings_2( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeWebStorage_3 extends _i1.SmartFake implements _i2.WebStorage { + _FakeWebStorage_3( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeWebView_4 extends _i1.SmartFake implements _i2.WebView { + _FakeWebView_4( Object parent, Invocation parentInvocation, ) : super( @@ -48,8 +79,8 @@ class _FakeWebStorage_1 extends _i1.SmartFake implements _i2.WebStorage { ); } -class _FakeOffset_2 extends _i1.SmartFake implements _i3.Offset { - _FakeOffset_2( +class _FakeWebViewPoint_5 extends _i1.SmartFake implements _i2.WebViewPoint { + _FakeWebViewPoint_5( Object parent, Invocation parentInvocation, ) : super( @@ -58,8 +89,9 @@ class _FakeOffset_2 extends _i1.SmartFake implements _i3.Offset { ); } -class _FakeWebView_3 extends _i1.SmartFake implements _i2.WebView { - _FakeWebView_3( +class _FakeWebResourceRequest_6 extends _i1.SmartFake + implements _i2.WebResourceRequest { + _FakeWebResourceRequest_6( Object parent, Invocation parentInvocation, ) : super( @@ -68,9 +100,9 @@ class _FakeWebView_3 extends _i1.SmartFake implements _i2.WebView { ); } -class _FakeDownloadListener_4 extends _i1.SmartFake +class _FakeDownloadListener_7 extends _i1.SmartFake implements _i2.DownloadListener { - _FakeDownloadListener_4( + _FakeDownloadListener_7( Object parent, Invocation parentInvocation, ) : super( @@ -79,9 +111,9 @@ class _FakeDownloadListener_4 extends _i1.SmartFake ); } -class _FakeJavascriptChannelRegistry_5 extends _i1.SmartFake - implements _i4.JavascriptChannelRegistry { - _FakeJavascriptChannelRegistry_5( +class _FakeJavascriptChannelRegistry_8 extends _i1.SmartFake + implements _i3.JavascriptChannelRegistry { + _FakeJavascriptChannelRegistry_8( Object parent, Invocation parentInvocation, ) : super( @@ -90,9 +122,9 @@ class _FakeJavascriptChannelRegistry_5 extends _i1.SmartFake ); } -class _FakeJavaScriptChannel_6 extends _i1.SmartFake +class _FakeJavaScriptChannel_9 extends _i1.SmartFake implements _i2.JavaScriptChannel { - _FakeJavaScriptChannel_6( + _FakeJavaScriptChannel_9( Object parent, Invocation parentInvocation, ) : super( @@ -101,9 +133,9 @@ class _FakeJavaScriptChannel_6 extends _i1.SmartFake ); } -class _FakeWebChromeClient_7 extends _i1.SmartFake +class _FakeWebChromeClient_10 extends _i1.SmartFake implements _i2.WebChromeClient { - _FakeWebChromeClient_7( + _FakeWebChromeClient_10( Object parent, Invocation parentInvocation, ) : super( @@ -112,8 +144,8 @@ class _FakeWebChromeClient_7 extends _i1.SmartFake ); } -class _FakeWebViewClient_8 extends _i1.SmartFake implements _i2.WebViewClient { - _FakeWebViewClient_8( +class _FakeWebViewClient_11 extends _i1.SmartFake implements _i2.WebViewClient { + _FakeWebViewClient_11( Object parent, Invocation parentInvocation, ) : super( @@ -132,29 +164,53 @@ class MockFlutterAssetManager extends _i1.Mock } @override - _i5.Future> list(String? path) => (super.noSuchMethod( + _i2.PigeonInstanceManager get pigeon_instanceManager => (super.noSuchMethod( + Invocation.getter(#pigeon_instanceManager), + returnValue: _FakePigeonInstanceManager_0( + this, + Invocation.getter(#pigeon_instanceManager), + ), + ) as _i2.PigeonInstanceManager); + + @override + _i4.Future> list(String? path) => (super.noSuchMethod( Invocation.method( #list, [path], ), - returnValue: _i5.Future>.value([]), - ) as _i5.Future>); + returnValue: _i4.Future>.value([]), + ) as _i4.Future>); @override - _i5.Future getAssetFilePathByName(String? name) => + _i4.Future getAssetFilePathByName(String? name) => (super.noSuchMethod( Invocation.method( #getAssetFilePathByName, [name], ), - returnValue: _i5.Future.value(_i6.dummyValue( + returnValue: _i4.Future.value(_i5.dummyValue( this, Invocation.method( #getAssetFilePathByName, [name], ), )), - ) as _i5.Future); + ) as _i4.Future); + + @override + _i2.FlutterAssetManager pigeon_copy() => (super.noSuchMethod( + Invocation.method( + #pigeon_copy, + [], + ), + returnValue: _FakeFlutterAssetManager_1( + this, + Invocation.method( + #pigeon_copy, + [], + ), + ), + ) as _i2.FlutterAssetManager); } /// A class which mocks [WebSettings]. @@ -166,165 +222,174 @@ class MockWebSettings extends _i1.Mock implements _i2.WebSettings { } @override - _i5.Future setDomStorageEnabled(bool? flag) => (super.noSuchMethod( + _i2.PigeonInstanceManager get pigeon_instanceManager => (super.noSuchMethod( + Invocation.getter(#pigeon_instanceManager), + returnValue: _FakePigeonInstanceManager_0( + this, + Invocation.getter(#pigeon_instanceManager), + ), + ) as _i2.PigeonInstanceManager); + + @override + _i4.Future setDomStorageEnabled(bool? flag) => (super.noSuchMethod( Invocation.method( #setDomStorageEnabled, [flag], ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); @override - _i5.Future setJavaScriptCanOpenWindowsAutomatically(bool? flag) => + _i4.Future setJavaScriptCanOpenWindowsAutomatically(bool? flag) => (super.noSuchMethod( Invocation.method( #setJavaScriptCanOpenWindowsAutomatically, [flag], ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); @override - _i5.Future setSupportMultipleWindows(bool? support) => + _i4.Future setSupportMultipleWindows(bool? support) => (super.noSuchMethod( Invocation.method( #setSupportMultipleWindows, [support], ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); @override - _i5.Future setJavaScriptEnabled(bool? flag) => (super.noSuchMethod( + _i4.Future setJavaScriptEnabled(bool? flag) => (super.noSuchMethod( Invocation.method( #setJavaScriptEnabled, [flag], ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); @override - _i5.Future setUserAgentString(String? userAgentString) => + _i4.Future setUserAgentString(String? userAgentString) => (super.noSuchMethod( Invocation.method( #setUserAgentString, [userAgentString], ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); @override - _i5.Future setMediaPlaybackRequiresUserGesture(bool? require) => + _i4.Future setMediaPlaybackRequiresUserGesture(bool? require) => (super.noSuchMethod( Invocation.method( #setMediaPlaybackRequiresUserGesture, [require], ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); @override - _i5.Future setSupportZoom(bool? support) => (super.noSuchMethod( + _i4.Future setSupportZoom(bool? support) => (super.noSuchMethod( Invocation.method( #setSupportZoom, [support], ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); @override - _i5.Future setLoadWithOverviewMode(bool? overview) => + _i4.Future setLoadWithOverviewMode(bool? overview) => (super.noSuchMethod( Invocation.method( #setLoadWithOverviewMode, [overview], ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); @override - _i5.Future setUseWideViewPort(bool? use) => (super.noSuchMethod( + _i4.Future setUseWideViewPort(bool? use) => (super.noSuchMethod( Invocation.method( #setUseWideViewPort, [use], ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); @override - _i5.Future setDisplayZoomControls(bool? enabled) => (super.noSuchMethod( + _i4.Future setDisplayZoomControls(bool? enabled) => (super.noSuchMethod( Invocation.method( #setDisplayZoomControls, [enabled], ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); @override - _i5.Future setBuiltInZoomControls(bool? enabled) => (super.noSuchMethod( + _i4.Future setBuiltInZoomControls(bool? enabled) => (super.noSuchMethod( Invocation.method( #setBuiltInZoomControls, [enabled], ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); @override - _i5.Future setAllowFileAccess(bool? enabled) => (super.noSuchMethod( + _i4.Future setAllowFileAccess(bool? enabled) => (super.noSuchMethod( Invocation.method( #setAllowFileAccess, [enabled], ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); @override - _i5.Future setTextZoom(int? textZoom) => (super.noSuchMethod( + _i4.Future setTextZoom(int? textZoom) => (super.noSuchMethod( Invocation.method( #setTextZoom, [textZoom], ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); @override - _i5.Future getUserAgentString() => (super.noSuchMethod( + _i4.Future getUserAgentString() => (super.noSuchMethod( Invocation.method( #getUserAgentString, [], ), - returnValue: _i5.Future.value(_i6.dummyValue( + returnValue: _i4.Future.value(_i5.dummyValue( this, Invocation.method( #getUserAgentString, [], ), )), - ) as _i5.Future); + ) as _i4.Future); @override - _i2.WebSettings copy() => (super.noSuchMethod( + _i2.WebSettings pigeon_copy() => (super.noSuchMethod( Invocation.method( - #copy, + #pigeon_copy, [], ), - returnValue: _FakeWebSettings_0( + returnValue: _FakeWebSettings_2( this, Invocation.method( - #copy, + #pigeon_copy, [], ), ), @@ -340,25 +405,34 @@ class MockWebStorage extends _i1.Mock implements _i2.WebStorage { } @override - _i5.Future deleteAllData() => (super.noSuchMethod( + _i2.PigeonInstanceManager get pigeon_instanceManager => (super.noSuchMethod( + Invocation.getter(#pigeon_instanceManager), + returnValue: _FakePigeonInstanceManager_0( + this, + Invocation.getter(#pigeon_instanceManager), + ), + ) as _i2.PigeonInstanceManager); + + @override + _i4.Future deleteAllData() => (super.noSuchMethod( Invocation.method( #deleteAllData, [], ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); @override - _i2.WebStorage copy() => (super.noSuchMethod( + _i2.WebStorage pigeon_copy() => (super.noSuchMethod( Invocation.method( - #copy, + #pigeon_copy, [], ), - returnValue: _FakeWebStorage_1( + returnValue: _FakeWebStorage_3( this, Invocation.method( - #copy, + #pigeon_copy, [], ), ), @@ -376,58 +450,80 @@ class MockWebView extends _i1.Mock implements _i2.WebView { @override _i2.WebSettings get settings => (super.noSuchMethod( Invocation.getter(#settings), - returnValue: _FakeWebSettings_0( + returnValue: _FakeWebSettings_2( this, Invocation.getter(#settings), ), ) as _i2.WebSettings); @override - _i5.Future loadData({ - required String? data, + _i2.PigeonInstanceManager get pigeon_instanceManager => (super.noSuchMethod( + Invocation.getter(#pigeon_instanceManager), + returnValue: _FakePigeonInstanceManager_0( + this, + Invocation.getter(#pigeon_instanceManager), + ), + ) as _i2.PigeonInstanceManager); + + @override + _i2.WebSettings pigeonVar_settings() => (super.noSuchMethod( + Invocation.method( + #pigeonVar_settings, + [], + ), + returnValue: _FakeWebSettings_2( + this, + Invocation.method( + #pigeonVar_settings, + [], + ), + ), + ) as _i2.WebSettings); + + @override + _i4.Future loadData( + String? data, String? mimeType, String? encoding, - }) => + ) => (super.noSuchMethod( Invocation.method( #loadData, - [], - { - #data: data, - #mimeType: mimeType, - #encoding: encoding, - }, + [ + data, + mimeType, + encoding, + ], ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); @override - _i5.Future loadDataWithBaseUrl({ + _i4.Future loadDataWithBaseUrl( String? baseUrl, - required String? data, + String? data, String? mimeType, String? encoding, String? historyUrl, - }) => + ) => (super.noSuchMethod( Invocation.method( #loadDataWithBaseUrl, - [], - { - #baseUrl: baseUrl, - #data: data, - #mimeType: mimeType, - #encoding: encoding, - #historyUrl: historyUrl, - }, + [ + baseUrl, + data, + mimeType, + encoding, + historyUrl, + ], ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); @override - _i5.Future loadUrl( + _i4.Future loadUrl( String? url, Map? headers, ) => @@ -439,14 +535,14 @@ class MockWebView extends _i1.Mock implements _i2.WebView { headers, ], ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); @override - _i5.Future postUrl( + _i4.Future postUrl( String? url, - _i7.Uint8List? data, + _i6.Uint8List? data, ) => (super.noSuchMethod( Invocation.method( @@ -456,244 +552,233 @@ class MockWebView extends _i1.Mock implements _i2.WebView { data, ], ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); @override - _i5.Future getUrl() => (super.noSuchMethod( + _i4.Future getUrl() => (super.noSuchMethod( Invocation.method( #getUrl, [], ), - returnValue: _i5.Future.value(), - ) as _i5.Future); + returnValue: _i4.Future.value(), + ) as _i4.Future); @override - _i5.Future canGoBack() => (super.noSuchMethod( + _i4.Future canGoBack() => (super.noSuchMethod( Invocation.method( #canGoBack, [], ), - returnValue: _i5.Future.value(false), - ) as _i5.Future); + returnValue: _i4.Future.value(false), + ) as _i4.Future); @override - _i5.Future canGoForward() => (super.noSuchMethod( + _i4.Future canGoForward() => (super.noSuchMethod( Invocation.method( #canGoForward, [], ), - returnValue: _i5.Future.value(false), - ) as _i5.Future); + returnValue: _i4.Future.value(false), + ) as _i4.Future); @override - _i5.Future goBack() => (super.noSuchMethod( + _i4.Future goBack() => (super.noSuchMethod( Invocation.method( #goBack, [], ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); @override - _i5.Future goForward() => (super.noSuchMethod( + _i4.Future goForward() => (super.noSuchMethod( Invocation.method( #goForward, [], ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); @override - _i5.Future reload() => (super.noSuchMethod( + _i4.Future reload() => (super.noSuchMethod( Invocation.method( #reload, [], ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); @override - _i5.Future clearCache(bool? includeDiskFiles) => (super.noSuchMethod( + _i4.Future clearCache(bool? includeDiskFiles) => (super.noSuchMethod( Invocation.method( #clearCache, [includeDiskFiles], ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); @override - _i5.Future evaluateJavascript(String? javascriptString) => + _i4.Future evaluateJavascript(String? javascriptString) => (super.noSuchMethod( Invocation.method( #evaluateJavascript, [javascriptString], ), - returnValue: _i5.Future.value(), - ) as _i5.Future); + returnValue: _i4.Future.value(), + ) as _i4.Future); @override - _i5.Future getTitle() => (super.noSuchMethod( + _i4.Future getTitle() => (super.noSuchMethod( Invocation.method( #getTitle, [], ), - returnValue: _i5.Future.value(), - ) as _i5.Future); + returnValue: _i4.Future.value(), + ) as _i4.Future); @override - _i5.Future scrollTo( - int? x, - int? y, - ) => + _i4.Future setWebViewClient(_i2.WebViewClient? client) => (super.noSuchMethod( Invocation.method( - #scrollTo, - [ - x, - y, - ], + #setWebViewClient, + [client], ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); @override - _i5.Future scrollBy( - int? x, - int? y, - ) => + _i4.Future addJavaScriptChannel(_i2.JavaScriptChannel? channel) => (super.noSuchMethod( Invocation.method( - #scrollBy, - [ - x, - y, - ], - ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); - - @override - _i5.Future getScrollX() => (super.noSuchMethod( - Invocation.method( - #getScrollX, - [], + #addJavaScriptChannel, + [channel], ), - returnValue: _i5.Future.value(0), - ) as _i5.Future); + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); @override - _i5.Future getScrollY() => (super.noSuchMethod( + _i4.Future removeJavaScriptChannel(String? name) => (super.noSuchMethod( Invocation.method( - #getScrollY, - [], + #removeJavaScriptChannel, + [name], ), - returnValue: _i5.Future.value(0), - ) as _i5.Future); + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); @override - _i5.Future<_i3.Offset> getScrollPosition() => (super.noSuchMethod( + _i4.Future setDownloadListener(_i2.DownloadListener? listener) => + (super.noSuchMethod( Invocation.method( - #getScrollPosition, - [], + #setDownloadListener, + [listener], ), - returnValue: _i5.Future<_i3.Offset>.value(_FakeOffset_2( - this, - Invocation.method( - #getScrollPosition, - [], - ), - )), - ) as _i5.Future<_i3.Offset>); + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); @override - _i5.Future setWebViewClient(_i2.WebViewClient? webViewClient) => + _i4.Future setWebChromeClient(_i2.WebChromeClient? client) => (super.noSuchMethod( Invocation.method( - #setWebViewClient, - [webViewClient], + #setWebChromeClient, + [client], ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); @override - _i5.Future addJavaScriptChannel( - _i2.JavaScriptChannel? javaScriptChannel) => - (super.noSuchMethod( + _i4.Future setBackgroundColor(int? color) => (super.noSuchMethod( Invocation.method( - #addJavaScriptChannel, - [javaScriptChannel], + #setBackgroundColor, + [color], ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); @override - _i5.Future removeJavaScriptChannel( - _i2.JavaScriptChannel? javaScriptChannel) => - (super.noSuchMethod( + _i4.Future destroy() => (super.noSuchMethod( Invocation.method( - #removeJavaScriptChannel, - [javaScriptChannel], + #destroy, + [], ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); @override - _i5.Future setDownloadListener(_i2.DownloadListener? listener) => - (super.noSuchMethod( + _i2.WebView pigeon_copy() => (super.noSuchMethod( Invocation.method( - #setDownloadListener, - [listener], + #pigeon_copy, + [], ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); + returnValue: _FakeWebView_4( + this, + Invocation.method( + #pigeon_copy, + [], + ), + ), + ) as _i2.WebView); @override - _i5.Future setWebChromeClient(_i2.WebChromeClient? client) => + _i4.Future scrollTo( + int? x, + int? y, + ) => (super.noSuchMethod( Invocation.method( - #setWebChromeClient, - [client], + #scrollTo, + [ + x, + y, + ], ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); @override - _i5.Future setBackgroundColor(_i3.Color? color) => (super.noSuchMethod( + _i4.Future scrollBy( + int? x, + int? y, + ) => + (super.noSuchMethod( Invocation.method( - #setBackgroundColor, - [color], + #scrollBy, + [ + x, + y, + ], ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); @override - _i2.WebView copy() => (super.noSuchMethod( + _i4.Future<_i2.WebViewPoint> getScrollPosition() => (super.noSuchMethod( Invocation.method( - #copy, + #getScrollPosition, [], ), - returnValue: _FakeWebView_3( + returnValue: _i4.Future<_i2.WebViewPoint>.value(_FakeWebViewPoint_5( this, Invocation.method( - #copy, + #getScrollPosition, [], ), - ), - ) as _i2.WebView); + )), + ) as _i4.Future<_i2.WebViewPoint>); } /// A class which mocks [WebResourceRequest]. @@ -708,7 +793,7 @@ class MockWebResourceRequest extends _i1.Mock @override String get url => (super.noSuchMethod( Invocation.getter(#url), - returnValue: _i6.dummyValue( + returnValue: _i5.dummyValue( this, Invocation.getter(#url), ), @@ -729,17 +814,35 @@ class MockWebResourceRequest extends _i1.Mock @override String get method => (super.noSuchMethod( Invocation.getter(#method), - returnValue: _i6.dummyValue( + returnValue: _i5.dummyValue( this, Invocation.getter(#method), ), ) as String); @override - Map get requestHeaders => (super.noSuchMethod( - Invocation.getter(#requestHeaders), - returnValue: {}, - ) as Map); + _i2.PigeonInstanceManager get pigeon_instanceManager => (super.noSuchMethod( + Invocation.getter(#pigeon_instanceManager), + returnValue: _FakePigeonInstanceManager_0( + this, + Invocation.getter(#pigeon_instanceManager), + ), + ) as _i2.PigeonInstanceManager); + + @override + _i2.WebResourceRequest pigeon_copy() => (super.noSuchMethod( + Invocation.method( + #pigeon_copy, + [], + ), + returnValue: _FakeWebResourceRequest_6( + this, + Invocation.method( + #pigeon_copy, + [], + ), + ), + ) as _i2.WebResourceRequest); } /// A class which mocks [DownloadListener]. @@ -752,6 +855,7 @@ class MockDownloadListener extends _i1.Mock implements _i2.DownloadListener { @override void Function( + _i2.DownloadListener, String, String, String, @@ -760,6 +864,7 @@ class MockDownloadListener extends _i1.Mock implements _i2.DownloadListener { ) get onDownloadStart => (super.noSuchMethod( Invocation.getter(#onDownloadStart), returnValue: ( + _i2.DownloadListener pigeon_instance, String url, String userAgent, String contentDisposition, @@ -767,6 +872,7 @@ class MockDownloadListener extends _i1.Mock implements _i2.DownloadListener { int contentLength, ) {}, ) as void Function( + _i2.DownloadListener, String, String, String, @@ -775,15 +881,24 @@ class MockDownloadListener extends _i1.Mock implements _i2.DownloadListener { )); @override - _i2.DownloadListener copy() => (super.noSuchMethod( + _i2.PigeonInstanceManager get pigeon_instanceManager => (super.noSuchMethod( + Invocation.getter(#pigeon_instanceManager), + returnValue: _FakePigeonInstanceManager_0( + this, + Invocation.getter(#pigeon_instanceManager), + ), + ) as _i2.PigeonInstanceManager); + + @override + _i2.DownloadListener pigeon_copy() => (super.noSuchMethod( Invocation.method( - #copy, + #pigeon_copy, [], ), - returnValue: _FakeDownloadListener_4( + returnValue: _FakeDownloadListener_7( this, Invocation.method( - #copy, + #pigeon_copy, [], ), ), @@ -794,46 +909,64 @@ class MockDownloadListener extends _i1.Mock implements _i2.DownloadListener { /// /// See the documentation for Mockito's code generation for more information. class MockWebViewAndroidJavaScriptChannel extends _i1.Mock - implements _i8.WebViewAndroidJavaScriptChannel { + implements _i7.WebViewAndroidJavaScriptChannel { MockWebViewAndroidJavaScriptChannel() { _i1.throwOnMissingStub(this); } @override - _i4.JavascriptChannelRegistry get javascriptChannelRegistry => + _i3.JavascriptChannelRegistry get javascriptChannelRegistry => (super.noSuchMethod( Invocation.getter(#javascriptChannelRegistry), - returnValue: _FakeJavascriptChannelRegistry_5( + returnValue: _FakeJavascriptChannelRegistry_8( this, Invocation.getter(#javascriptChannelRegistry), ), - ) as _i4.JavascriptChannelRegistry); + ) as _i3.JavascriptChannelRegistry); @override String get channelName => (super.noSuchMethod( Invocation.getter(#channelName), - returnValue: _i6.dummyValue( + returnValue: _i5.dummyValue( this, Invocation.getter(#channelName), ), ) as String); @override - void Function(String) get postMessage => (super.noSuchMethod( + void Function( + _i2.JavaScriptChannel, + String, + ) get postMessage => (super.noSuchMethod( Invocation.getter(#postMessage), - returnValue: (String message) {}, - ) as void Function(String)); + returnValue: ( + _i2.JavaScriptChannel pigeon_instance, + String message, + ) {}, + ) as void Function( + _i2.JavaScriptChannel, + String, + )); @override - _i2.JavaScriptChannel copy() => (super.noSuchMethod( + _i2.PigeonInstanceManager get pigeon_instanceManager => (super.noSuchMethod( + Invocation.getter(#pigeon_instanceManager), + returnValue: _FakePigeonInstanceManager_0( + this, + Invocation.getter(#pigeon_instanceManager), + ), + ) as _i2.PigeonInstanceManager); + + @override + _i2.JavaScriptChannel pigeon_copy() => (super.noSuchMethod( Invocation.method( - #copy, + #pigeon_copy, [], ), - returnValue: _FakeJavaScriptChannel_6( + returnValue: _FakeJavaScriptChannel_9( this, Invocation.method( - #copy, + #pigeon_copy, [], ), ), @@ -849,70 +982,79 @@ class MockWebChromeClient extends _i1.Mock implements _i2.WebChromeClient { } @override - _i5.Future setSynchronousReturnValueForOnShowFileChooser(bool? value) => + _i2.PigeonInstanceManager get pigeon_instanceManager => (super.noSuchMethod( + Invocation.getter(#pigeon_instanceManager), + returnValue: _FakePigeonInstanceManager_0( + this, + Invocation.getter(#pigeon_instanceManager), + ), + ) as _i2.PigeonInstanceManager); + + @override + _i4.Future setSynchronousReturnValueForOnShowFileChooser(bool? value) => (super.noSuchMethod( Invocation.method( #setSynchronousReturnValueForOnShowFileChooser, [value], ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); @override - _i5.Future setSynchronousReturnValueForOnConsoleMessage(bool? value) => + _i4.Future setSynchronousReturnValueForOnConsoleMessage(bool? value) => (super.noSuchMethod( Invocation.method( #setSynchronousReturnValueForOnConsoleMessage, [value], ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); @override - _i5.Future setSynchronousReturnValueForOnJsAlert(bool? value) => + _i4.Future setSynchronousReturnValueForOnJsAlert(bool? value) => (super.noSuchMethod( Invocation.method( #setSynchronousReturnValueForOnJsAlert, [value], ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); @override - _i5.Future setSynchronousReturnValueForOnJsConfirm(bool? value) => + _i4.Future setSynchronousReturnValueForOnJsConfirm(bool? value) => (super.noSuchMethod( Invocation.method( #setSynchronousReturnValueForOnJsConfirm, [value], ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); @override - _i5.Future setSynchronousReturnValueForOnJsPrompt(bool? value) => + _i4.Future setSynchronousReturnValueForOnJsPrompt(bool? value) => (super.noSuchMethod( Invocation.method( #setSynchronousReturnValueForOnJsPrompt, [value], ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); @override - _i2.WebChromeClient copy() => (super.noSuchMethod( + _i2.WebChromeClient pigeon_copy() => (super.noSuchMethod( Invocation.method( - #copy, + #pigeon_copy, [], ), - returnValue: _FakeWebChromeClient_7( + returnValue: _FakeWebChromeClient_10( this, Invocation.method( - #copy, + #pigeon_copy, [], ), ), @@ -928,27 +1070,36 @@ class MockWebViewClient extends _i1.Mock implements _i2.WebViewClient { } @override - _i5.Future setSynchronousReturnValueForShouldOverrideUrlLoading( + _i2.PigeonInstanceManager get pigeon_instanceManager => (super.noSuchMethod( + Invocation.getter(#pigeon_instanceManager), + returnValue: _FakePigeonInstanceManager_0( + this, + Invocation.getter(#pigeon_instanceManager), + ), + ) as _i2.PigeonInstanceManager); + + @override + _i4.Future setSynchronousReturnValueForShouldOverrideUrlLoading( bool? value) => (super.noSuchMethod( Invocation.method( #setSynchronousReturnValueForShouldOverrideUrlLoading, [value], ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); @override - _i2.WebViewClient copy() => (super.noSuchMethod( + _i2.WebViewClient pigeon_copy() => (super.noSuchMethod( Invocation.method( - #copy, + #pigeon_copy, [], ), - returnValue: _FakeWebViewClient_8( + returnValue: _FakeWebViewClient_11( this, Invocation.method( - #copy, + #pigeon_copy, [], ), ), @@ -959,16 +1110,16 @@ class MockWebViewClient extends _i1.Mock implements _i2.WebViewClient { /// /// See the documentation for Mockito's code generation for more information. class MockJavascriptChannelRegistry extends _i1.Mock - implements _i4.JavascriptChannelRegistry { + implements _i3.JavascriptChannelRegistry { MockJavascriptChannelRegistry() { _i1.throwOnMissingStub(this); } @override - Map get channels => (super.noSuchMethod( + Map get channels => (super.noSuchMethod( Invocation.getter(#channels), - returnValue: {}, - ) as Map); + returnValue: {}, + ) as Map); @override void onJavascriptChannelMessage( @@ -987,7 +1138,7 @@ class MockJavascriptChannelRegistry extends _i1.Mock ); @override - void updateJavascriptChannelsFromSet(Set<_i4.JavascriptChannel>? channels) => + void updateJavascriptChannelsFromSet(Set<_i3.JavascriptChannel>? channels) => super.noSuchMethod( Invocation.method( #updateJavascriptChannelsFromSet, @@ -1001,13 +1152,13 @@ class MockJavascriptChannelRegistry extends _i1.Mock /// /// See the documentation for Mockito's code generation for more information. class MockWebViewPlatformCallbacksHandler extends _i1.Mock - implements _i4.WebViewPlatformCallbacksHandler { + implements _i3.WebViewPlatformCallbacksHandler { MockWebViewPlatformCallbacksHandler() { _i1.throwOnMissingStub(this); } @override - _i5.FutureOr onNavigationRequest({ + _i4.FutureOr onNavigationRequest({ required String? url, required bool? isForMainFrame, }) => @@ -1020,8 +1171,8 @@ class MockWebViewPlatformCallbacksHandler extends _i1.Mock #isForMainFrame: isForMainFrame, }, ), - returnValue: _i5.Future.value(false), - ) as _i5.FutureOr); + returnValue: _i4.Future.value(false), + ) as _i4.FutureOr); @override void onPageStarted(String? url) => super.noSuchMethod( @@ -1051,7 +1202,7 @@ class MockWebViewPlatformCallbacksHandler extends _i1.Mock ); @override - void onWebResourceError(_i4.WebResourceError? error) => super.noSuchMethod( + void onWebResourceError(_i3.WebResourceError? error) => super.noSuchMethod( Invocation.method( #onWebResourceError, [error], @@ -1063,7 +1214,7 @@ class MockWebViewPlatformCallbacksHandler extends _i1.Mock /// A class which mocks [WebViewProxy]. /// /// See the documentation for Mockito's code generation for more information. -class MockWebViewProxy extends _i1.Mock implements _i8.WebViewProxy { +class MockWebViewProxy extends _i1.Mock implements _i7.WebViewProxy { MockWebViewProxy() { _i1.throwOnMissingStub(this); } @@ -1074,7 +1225,7 @@ class MockWebViewProxy extends _i1.Mock implements _i8.WebViewProxy { #createWebView, [], ), - returnValue: _FakeWebView_3( + returnValue: _FakeWebView_4( this, Invocation.method( #createWebView, @@ -1086,29 +1237,35 @@ class MockWebViewProxy extends _i1.Mock implements _i8.WebViewProxy { @override _i2.WebViewClient createWebViewClient({ void Function( + _i2.WebViewClient, _i2.WebView, String, )? onPageStarted, void Function( + _i2.WebViewClient, _i2.WebView, String, )? onPageFinished, void Function( + _i2.WebViewClient, _i2.WebView, _i2.WebResourceRequest, _i2.WebResourceError, )? onReceivedRequestError, void Function( + _i2.WebViewClient, _i2.WebView, int, String, String, )? onReceivedError, void Function( + _i2.WebViewClient, _i2.WebView, _i2.WebResourceRequest, )? requestLoading, void Function( + _i2.WebViewClient, _i2.WebView, String, )? urlLoading, @@ -1126,7 +1283,7 @@ class MockWebViewProxy extends _i1.Mock implements _i8.WebViewProxy { #urlLoading: urlLoading, }, ), - returnValue: _FakeWebViewClient_8( + returnValue: _FakeWebViewClient_11( this, Invocation.method( #createWebViewClient, @@ -1144,13 +1301,13 @@ class MockWebViewProxy extends _i1.Mock implements _i8.WebViewProxy { ) as _i2.WebViewClient); @override - _i5.Future setWebContentsDebuggingEnabled(bool? enabled) => + _i4.Future setWebContentsDebuggingEnabled(bool? enabled) => (super.noSuchMethod( Invocation.method( #setWebContentsDebuggingEnabled, [enabled], ), - returnValue: _i5.Future.value(), - returnValueForMissingStub: _i5.Future.value(), - ) as _i5.Future); + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); } diff --git a/packages/webview_flutter/webview_flutter_android/test/test_android_webview.g.dart b/packages/webview_flutter/webview_flutter_android/test/test_android_webview.g.dart deleted file mode 100644 index 41d66e0320e7..000000000000 --- a/packages/webview_flutter/webview_flutter_android/test/test_android_webview.g.dart +++ /dev/null @@ -1,2102 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -// Autogenerated from Pigeon (v11.0.1), do not edit directly. -// See also: https://pub.dev/packages/pigeon -// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, unnecessary_import -// ignore_for_file: avoid_relative_lib_imports -import 'dart:async'; -import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List; -import 'package:flutter/foundation.dart' show ReadBuffer, WriteBuffer; -import 'package:flutter/services.dart'; -import 'package:flutter_test/flutter_test.dart'; - -import 'package:webview_flutter_android/src/android_webview.g.dart'; - -/// Host API for managing the native `InstanceManager`. -abstract class TestInstanceManagerHostApi { - static TestDefaultBinaryMessengerBinding? get _testBinaryMessengerBinding => - TestDefaultBinaryMessengerBinding.instance; - static const MessageCodec codec = StandardMessageCodec(); - - /// Clear the native `InstanceManager`. - /// - /// This is typically only used after a hot restart. - void clear(); - - static void setup(TestInstanceManagerHostApi? api, - {BinaryMessenger? binaryMessenger}) { - { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.InstanceManagerHostApi.clear', - codec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, - (Object? message) async { - // ignore message - api.clear(); - return []; - }); - } - } - } -} - -/// Handles methods calls to the native Java Object class. -/// -/// Also handles calls to remove the reference to an instance with `dispose`. -/// -/// See https://docs.oracle.com/javase/7/docs/api/java/lang/Object.html. -abstract class TestJavaObjectHostApi { - static TestDefaultBinaryMessengerBinding? get _testBinaryMessengerBinding => - TestDefaultBinaryMessengerBinding.instance; - static const MessageCodec codec = StandardMessageCodec(); - - void dispose(int identifier); - - static void setup(TestJavaObjectHostApi? api, - {BinaryMessenger? binaryMessenger}) { - { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.JavaObjectHostApi.dispose', - codec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.JavaObjectHostApi.dispose was null.'); - final List args = (message as List?)!; - final int? arg_identifier = (args[0] as int?); - assert(arg_identifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.JavaObjectHostApi.dispose was null, expected non-null int.'); - api.dispose(arg_identifier!); - return []; - }); - } - } - } -} - -/// Host API for `CookieManager`. -/// -/// This class may handle instantiating and adding native object instances that -/// are attached to a Dart instance or handle method calls on the associated -/// native class or an instance of the class. -abstract class TestCookieManagerHostApi { - static TestDefaultBinaryMessengerBinding? get _testBinaryMessengerBinding => - TestDefaultBinaryMessengerBinding.instance; - static const MessageCodec codec = StandardMessageCodec(); - - /// Handles attaching `CookieManager.instance` to a native instance. - void attachInstance(int instanceIdentifier); - - /// Handles Dart method `CookieManager.setCookie`. - void setCookie(int identifier, String url, String value); - - /// Handles Dart method `CookieManager.removeAllCookies`. - Future removeAllCookies(int identifier); - - /// Handles Dart method `CookieManager.setAcceptThirdPartyCookies`. - void setAcceptThirdPartyCookies( - int identifier, int webViewIdentifier, bool accept); - - static void setup(TestCookieManagerHostApi? api, - {BinaryMessenger? binaryMessenger}) { - { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.CookieManagerHostApi.attachInstance', - codec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.CookieManagerHostApi.attachInstance was null.'); - final List args = (message as List?)!; - final int? arg_instanceIdentifier = (args[0] as int?); - assert(arg_instanceIdentifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.CookieManagerHostApi.attachInstance was null, expected non-null int.'); - api.attachInstance(arg_instanceIdentifier!); - return []; - }); - } - } - { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.CookieManagerHostApi.setCookie', - codec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.CookieManagerHostApi.setCookie was null.'); - final List args = (message as List?)!; - final int? arg_identifier = (args[0] as int?); - assert(arg_identifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.CookieManagerHostApi.setCookie was null, expected non-null int.'); - final String? arg_url = (args[1] as String?); - assert(arg_url != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.CookieManagerHostApi.setCookie was null, expected non-null String.'); - final String? arg_value = (args[2] as String?); - assert(arg_value != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.CookieManagerHostApi.setCookie was null, expected non-null String.'); - api.setCookie(arg_identifier!, arg_url!, arg_value!); - return []; - }); - } - } - { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.CookieManagerHostApi.removeAllCookies', - codec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.CookieManagerHostApi.removeAllCookies was null.'); - final List args = (message as List?)!; - final int? arg_identifier = (args[0] as int?); - assert(arg_identifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.CookieManagerHostApi.removeAllCookies was null, expected non-null int.'); - final bool output = await api.removeAllCookies(arg_identifier!); - return [output]; - }); - } - } - { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.CookieManagerHostApi.setAcceptThirdPartyCookies', - codec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.CookieManagerHostApi.setAcceptThirdPartyCookies was null.'); - final List args = (message as List?)!; - final int? arg_identifier = (args[0] as int?); - assert(arg_identifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.CookieManagerHostApi.setAcceptThirdPartyCookies was null, expected non-null int.'); - final int? arg_webViewIdentifier = (args[1] as int?); - assert(arg_webViewIdentifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.CookieManagerHostApi.setAcceptThirdPartyCookies was null, expected non-null int.'); - final bool? arg_accept = (args[2] as bool?); - assert(arg_accept != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.CookieManagerHostApi.setAcceptThirdPartyCookies was null, expected non-null bool.'); - api.setAcceptThirdPartyCookies( - arg_identifier!, arg_webViewIdentifier!, arg_accept!); - return []; - }); - } - } - } -} - -class _TestWebViewHostApiCodec extends StandardMessageCodec { - const _TestWebViewHostApiCodec(); - @override - void writeValue(WriteBuffer buffer, Object? value) { - if (value is WebViewPoint) { - buffer.putUint8(128); - writeValue(buffer, value.encode()); - } else { - super.writeValue(buffer, value); - } - } - - @override - Object? readValueOfType(int type, ReadBuffer buffer) { - switch (type) { - case 128: - return WebViewPoint.decode(readValue(buffer)!); - default: - return super.readValueOfType(type, buffer); - } - } -} - -abstract class TestWebViewHostApi { - static TestDefaultBinaryMessengerBinding? get _testBinaryMessengerBinding => - TestDefaultBinaryMessengerBinding.instance; - static const MessageCodec codec = _TestWebViewHostApiCodec(); - - void create(int instanceId); - - void loadData( - int instanceId, String data, String? mimeType, String? encoding); - - void loadDataWithBaseUrl(int instanceId, String? baseUrl, String data, - String? mimeType, String? encoding, String? historyUrl); - - void loadUrl(int instanceId, String url, Map headers); - - void postUrl(int instanceId, String url, Uint8List data); - - String? getUrl(int instanceId); - - bool canGoBack(int instanceId); - - bool canGoForward(int instanceId); - - void goBack(int instanceId); - - void goForward(int instanceId); - - void reload(int instanceId); - - void clearCache(int instanceId, bool includeDiskFiles); - - Future evaluateJavascript(int instanceId, String javascriptString); - - String? getTitle(int instanceId); - - void scrollTo(int instanceId, int x, int y); - - void scrollBy(int instanceId, int x, int y); - - int getScrollX(int instanceId); - - int getScrollY(int instanceId); - - WebViewPoint getScrollPosition(int instanceId); - - void setWebContentsDebuggingEnabled(bool enabled); - - void setWebViewClient(int instanceId, int webViewClientInstanceId); - - void addJavaScriptChannel(int instanceId, int javaScriptChannelInstanceId); - - void removeJavaScriptChannel(int instanceId, int javaScriptChannelInstanceId); - - void setDownloadListener(int instanceId, int? listenerInstanceId); - - void setWebChromeClient(int instanceId, int? clientInstanceId); - - void setBackgroundColor(int instanceId, int color); - - static void setup(TestWebViewHostApi? api, - {BinaryMessenger? binaryMessenger}) { - { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.create', - codec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.create was null.'); - final List args = (message as List?)!; - final int? arg_instanceId = (args[0] as int?); - assert(arg_instanceId != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.create was null, expected non-null int.'); - api.create(arg_instanceId!); - return []; - }); - } - } - { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.loadData', - codec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.loadData was null.'); - final List args = (message as List?)!; - final int? arg_instanceId = (args[0] as int?); - assert(arg_instanceId != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.loadData was null, expected non-null int.'); - final String? arg_data = (args[1] as String?); - assert(arg_data != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.loadData was null, expected non-null String.'); - final String? arg_mimeType = (args[2] as String?); - final String? arg_encoding = (args[3] as String?); - api.loadData(arg_instanceId!, arg_data!, arg_mimeType, arg_encoding); - return []; - }); - } - } - { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.loadDataWithBaseUrl', - codec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.loadDataWithBaseUrl was null.'); - final List args = (message as List?)!; - final int? arg_instanceId = (args[0] as int?); - assert(arg_instanceId != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.loadDataWithBaseUrl was null, expected non-null int.'); - final String? arg_baseUrl = (args[1] as String?); - final String? arg_data = (args[2] as String?); - assert(arg_data != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.loadDataWithBaseUrl was null, expected non-null String.'); - final String? arg_mimeType = (args[3] as String?); - final String? arg_encoding = (args[4] as String?); - final String? arg_historyUrl = (args[5] as String?); - api.loadDataWithBaseUrl(arg_instanceId!, arg_baseUrl, arg_data!, - arg_mimeType, arg_encoding, arg_historyUrl); - return []; - }); - } - } - { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.loadUrl', - codec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.loadUrl was null.'); - final List args = (message as List?)!; - final int? arg_instanceId = (args[0] as int?); - assert(arg_instanceId != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.loadUrl was null, expected non-null int.'); - final String? arg_url = (args[1] as String?); - assert(arg_url != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.loadUrl was null, expected non-null String.'); - final Map? arg_headers = - (args[2] as Map?)?.cast(); - assert(arg_headers != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.loadUrl was null, expected non-null Map.'); - api.loadUrl(arg_instanceId!, arg_url!, arg_headers!); - return []; - }); - } - } - { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.postUrl', - codec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.postUrl was null.'); - final List args = (message as List?)!; - final int? arg_instanceId = (args[0] as int?); - assert(arg_instanceId != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.postUrl was null, expected non-null int.'); - final String? arg_url = (args[1] as String?); - assert(arg_url != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.postUrl was null, expected non-null String.'); - final Uint8List? arg_data = (args[2] as Uint8List?); - assert(arg_data != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.postUrl was null, expected non-null Uint8List.'); - api.postUrl(arg_instanceId!, arg_url!, arg_data!); - return []; - }); - } - } - { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.getUrl', - codec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.getUrl was null.'); - final List args = (message as List?)!; - final int? arg_instanceId = (args[0] as int?); - assert(arg_instanceId != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.getUrl was null, expected non-null int.'); - final String? output = api.getUrl(arg_instanceId!); - return [output]; - }); - } - } - { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.canGoBack', - codec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.canGoBack was null.'); - final List args = (message as List?)!; - final int? arg_instanceId = (args[0] as int?); - assert(arg_instanceId != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.canGoBack was null, expected non-null int.'); - final bool output = api.canGoBack(arg_instanceId!); - return [output]; - }); - } - } - { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.canGoForward', - codec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.canGoForward was null.'); - final List args = (message as List?)!; - final int? arg_instanceId = (args[0] as int?); - assert(arg_instanceId != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.canGoForward was null, expected non-null int.'); - final bool output = api.canGoForward(arg_instanceId!); - return [output]; - }); - } - } - { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.goBack', - codec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.goBack was null.'); - final List args = (message as List?)!; - final int? arg_instanceId = (args[0] as int?); - assert(arg_instanceId != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.goBack was null, expected non-null int.'); - api.goBack(arg_instanceId!); - return []; - }); - } - } - { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.goForward', - codec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.goForward was null.'); - final List args = (message as List?)!; - final int? arg_instanceId = (args[0] as int?); - assert(arg_instanceId != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.goForward was null, expected non-null int.'); - api.goForward(arg_instanceId!); - return []; - }); - } - } - { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.reload', - codec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.reload was null.'); - final List args = (message as List?)!; - final int? arg_instanceId = (args[0] as int?); - assert(arg_instanceId != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.reload was null, expected non-null int.'); - api.reload(arg_instanceId!); - return []; - }); - } - } - { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.clearCache', - codec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.clearCache was null.'); - final List args = (message as List?)!; - final int? arg_instanceId = (args[0] as int?); - assert(arg_instanceId != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.clearCache was null, expected non-null int.'); - final bool? arg_includeDiskFiles = (args[1] as bool?); - assert(arg_includeDiskFiles != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.clearCache was null, expected non-null bool.'); - api.clearCache(arg_instanceId!, arg_includeDiskFiles!); - return []; - }); - } - } - { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.evaluateJavascript', - codec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.evaluateJavascript was null.'); - final List args = (message as List?)!; - final int? arg_instanceId = (args[0] as int?); - assert(arg_instanceId != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.evaluateJavascript was null, expected non-null int.'); - final String? arg_javascriptString = (args[1] as String?); - assert(arg_javascriptString != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.evaluateJavascript was null, expected non-null String.'); - final String? output = await api.evaluateJavascript( - arg_instanceId!, arg_javascriptString!); - return [output]; - }); - } - } - { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.getTitle', - codec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.getTitle was null.'); - final List args = (message as List?)!; - final int? arg_instanceId = (args[0] as int?); - assert(arg_instanceId != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.getTitle was null, expected non-null int.'); - final String? output = api.getTitle(arg_instanceId!); - return [output]; - }); - } - } - { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.scrollTo', - codec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.scrollTo was null.'); - final List args = (message as List?)!; - final int? arg_instanceId = (args[0] as int?); - assert(arg_instanceId != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.scrollTo was null, expected non-null int.'); - final int? arg_x = (args[1] as int?); - assert(arg_x != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.scrollTo was null, expected non-null int.'); - final int? arg_y = (args[2] as int?); - assert(arg_y != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.scrollTo was null, expected non-null int.'); - api.scrollTo(arg_instanceId!, arg_x!, arg_y!); - return []; - }); - } - } - { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.scrollBy', - codec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.scrollBy was null.'); - final List args = (message as List?)!; - final int? arg_instanceId = (args[0] as int?); - assert(arg_instanceId != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.scrollBy was null, expected non-null int.'); - final int? arg_x = (args[1] as int?); - assert(arg_x != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.scrollBy was null, expected non-null int.'); - final int? arg_y = (args[2] as int?); - assert(arg_y != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.scrollBy was null, expected non-null int.'); - api.scrollBy(arg_instanceId!, arg_x!, arg_y!); - return []; - }); - } - } - { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.getScrollX', - codec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.getScrollX was null.'); - final List args = (message as List?)!; - final int? arg_instanceId = (args[0] as int?); - assert(arg_instanceId != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.getScrollX was null, expected non-null int.'); - final int output = api.getScrollX(arg_instanceId!); - return [output]; - }); - } - } - { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.getScrollY', - codec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.getScrollY was null.'); - final List args = (message as List?)!; - final int? arg_instanceId = (args[0] as int?); - assert(arg_instanceId != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.getScrollY was null, expected non-null int.'); - final int output = api.getScrollY(arg_instanceId!); - return [output]; - }); - } - } - { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.getScrollPosition', - codec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.getScrollPosition was null.'); - final List args = (message as List?)!; - final int? arg_instanceId = (args[0] as int?); - assert(arg_instanceId != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.getScrollPosition was null, expected non-null int.'); - final WebViewPoint output = api.getScrollPosition(arg_instanceId!); - return [output]; - }); - } - } - { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.setWebContentsDebuggingEnabled', - codec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.setWebContentsDebuggingEnabled was null.'); - final List args = (message as List?)!; - final bool? arg_enabled = (args[0] as bool?); - assert(arg_enabled != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.setWebContentsDebuggingEnabled was null, expected non-null bool.'); - api.setWebContentsDebuggingEnabled(arg_enabled!); - return []; - }); - } - } - { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.setWebViewClient', - codec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.setWebViewClient was null.'); - final List args = (message as List?)!; - final int? arg_instanceId = (args[0] as int?); - assert(arg_instanceId != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.setWebViewClient was null, expected non-null int.'); - final int? arg_webViewClientInstanceId = (args[1] as int?); - assert(arg_webViewClientInstanceId != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.setWebViewClient was null, expected non-null int.'); - api.setWebViewClient(arg_instanceId!, arg_webViewClientInstanceId!); - return []; - }); - } - } - { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.addJavaScriptChannel', - codec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.addJavaScriptChannel was null.'); - final List args = (message as List?)!; - final int? arg_instanceId = (args[0] as int?); - assert(arg_instanceId != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.addJavaScriptChannel was null, expected non-null int.'); - final int? arg_javaScriptChannelInstanceId = (args[1] as int?); - assert(arg_javaScriptChannelInstanceId != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.addJavaScriptChannel was null, expected non-null int.'); - api.addJavaScriptChannel( - arg_instanceId!, arg_javaScriptChannelInstanceId!); - return []; - }); - } - } - { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.removeJavaScriptChannel', - codec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.removeJavaScriptChannel was null.'); - final List args = (message as List?)!; - final int? arg_instanceId = (args[0] as int?); - assert(arg_instanceId != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.removeJavaScriptChannel was null, expected non-null int.'); - final int? arg_javaScriptChannelInstanceId = (args[1] as int?); - assert(arg_javaScriptChannelInstanceId != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.removeJavaScriptChannel was null, expected non-null int.'); - api.removeJavaScriptChannel( - arg_instanceId!, arg_javaScriptChannelInstanceId!); - return []; - }); - } - } - { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.setDownloadListener', - codec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.setDownloadListener was null.'); - final List args = (message as List?)!; - final int? arg_instanceId = (args[0] as int?); - assert(arg_instanceId != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.setDownloadListener was null, expected non-null int.'); - final int? arg_listenerInstanceId = (args[1] as int?); - api.setDownloadListener(arg_instanceId!, arg_listenerInstanceId); - return []; - }); - } - } - { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.setWebChromeClient', - codec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.setWebChromeClient was null.'); - final List args = (message as List?)!; - final int? arg_instanceId = (args[0] as int?); - assert(arg_instanceId != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.setWebChromeClient was null, expected non-null int.'); - final int? arg_clientInstanceId = (args[1] as int?); - api.setWebChromeClient(arg_instanceId!, arg_clientInstanceId); - return []; - }); - } - } - { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.setBackgroundColor', - codec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.setBackgroundColor was null.'); - final List args = (message as List?)!; - final int? arg_instanceId = (args[0] as int?); - assert(arg_instanceId != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.setBackgroundColor was null, expected non-null int.'); - final int? arg_color = (args[1] as int?); - assert(arg_color != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewHostApi.setBackgroundColor was null, expected non-null int.'); - api.setBackgroundColor(arg_instanceId!, arg_color!); - return []; - }); - } - } - } -} - -abstract class TestWebSettingsHostApi { - static TestDefaultBinaryMessengerBinding? get _testBinaryMessengerBinding => - TestDefaultBinaryMessengerBinding.instance; - static const MessageCodec codec = StandardMessageCodec(); - - void create(int instanceId, int webViewInstanceId); - - void setDomStorageEnabled(int instanceId, bool flag); - - void setJavaScriptCanOpenWindowsAutomatically(int instanceId, bool flag); - - void setSupportMultipleWindows(int instanceId, bool support); - - void setJavaScriptEnabled(int instanceId, bool flag); - - void setUserAgentString(int instanceId, String? userAgentString); - - void setMediaPlaybackRequiresUserGesture(int instanceId, bool require); - - void setSupportZoom(int instanceId, bool support); - - void setLoadWithOverviewMode(int instanceId, bool overview); - - void setUseWideViewPort(int instanceId, bool use); - - void setDisplayZoomControls(int instanceId, bool enabled); - - void setBuiltInZoomControls(int instanceId, bool enabled); - - void setAllowFileAccess(int instanceId, bool enabled); - - void setTextZoom(int instanceId, int textZoom); - - String getUserAgentString(int instanceId); - - static void setup(TestWebSettingsHostApi? api, - {BinaryMessenger? binaryMessenger}) { - { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebSettingsHostApi.create', - codec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebSettingsHostApi.create was null.'); - final List args = (message as List?)!; - final int? arg_instanceId = (args[0] as int?); - assert(arg_instanceId != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebSettingsHostApi.create was null, expected non-null int.'); - final int? arg_webViewInstanceId = (args[1] as int?); - assert(arg_webViewInstanceId != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebSettingsHostApi.create was null, expected non-null int.'); - api.create(arg_instanceId!, arg_webViewInstanceId!); - return []; - }); - } - } - { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebSettingsHostApi.setDomStorageEnabled', - codec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebSettingsHostApi.setDomStorageEnabled was null.'); - final List args = (message as List?)!; - final int? arg_instanceId = (args[0] as int?); - assert(arg_instanceId != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebSettingsHostApi.setDomStorageEnabled was null, expected non-null int.'); - final bool? arg_flag = (args[1] as bool?); - assert(arg_flag != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebSettingsHostApi.setDomStorageEnabled was null, expected non-null bool.'); - api.setDomStorageEnabled(arg_instanceId!, arg_flag!); - return []; - }); - } - } - { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebSettingsHostApi.setJavaScriptCanOpenWindowsAutomatically', - codec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebSettingsHostApi.setJavaScriptCanOpenWindowsAutomatically was null.'); - final List args = (message as List?)!; - final int? arg_instanceId = (args[0] as int?); - assert(arg_instanceId != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebSettingsHostApi.setJavaScriptCanOpenWindowsAutomatically was null, expected non-null int.'); - final bool? arg_flag = (args[1] as bool?); - assert(arg_flag != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebSettingsHostApi.setJavaScriptCanOpenWindowsAutomatically was null, expected non-null bool.'); - api.setJavaScriptCanOpenWindowsAutomatically( - arg_instanceId!, arg_flag!); - return []; - }); - } - } - { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebSettingsHostApi.setSupportMultipleWindows', - codec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebSettingsHostApi.setSupportMultipleWindows was null.'); - final List args = (message as List?)!; - final int? arg_instanceId = (args[0] as int?); - assert(arg_instanceId != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebSettingsHostApi.setSupportMultipleWindows was null, expected non-null int.'); - final bool? arg_support = (args[1] as bool?); - assert(arg_support != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebSettingsHostApi.setSupportMultipleWindows was null, expected non-null bool.'); - api.setSupportMultipleWindows(arg_instanceId!, arg_support!); - return []; - }); - } - } - { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebSettingsHostApi.setJavaScriptEnabled', - codec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebSettingsHostApi.setJavaScriptEnabled was null.'); - final List args = (message as List?)!; - final int? arg_instanceId = (args[0] as int?); - assert(arg_instanceId != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebSettingsHostApi.setJavaScriptEnabled was null, expected non-null int.'); - final bool? arg_flag = (args[1] as bool?); - assert(arg_flag != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebSettingsHostApi.setJavaScriptEnabled was null, expected non-null bool.'); - api.setJavaScriptEnabled(arg_instanceId!, arg_flag!); - return []; - }); - } - } - { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebSettingsHostApi.setUserAgentString', - codec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebSettingsHostApi.setUserAgentString was null.'); - final List args = (message as List?)!; - final int? arg_instanceId = (args[0] as int?); - assert(arg_instanceId != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebSettingsHostApi.setUserAgentString was null, expected non-null int.'); - final String? arg_userAgentString = (args[1] as String?); - api.setUserAgentString(arg_instanceId!, arg_userAgentString); - return []; - }); - } - } - { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebSettingsHostApi.setMediaPlaybackRequiresUserGesture', - codec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebSettingsHostApi.setMediaPlaybackRequiresUserGesture was null.'); - final List args = (message as List?)!; - final int? arg_instanceId = (args[0] as int?); - assert(arg_instanceId != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebSettingsHostApi.setMediaPlaybackRequiresUserGesture was null, expected non-null int.'); - final bool? arg_require = (args[1] as bool?); - assert(arg_require != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebSettingsHostApi.setMediaPlaybackRequiresUserGesture was null, expected non-null bool.'); - api.setMediaPlaybackRequiresUserGesture( - arg_instanceId!, arg_require!); - return []; - }); - } - } - { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebSettingsHostApi.setSupportZoom', - codec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebSettingsHostApi.setSupportZoom was null.'); - final List args = (message as List?)!; - final int? arg_instanceId = (args[0] as int?); - assert(arg_instanceId != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebSettingsHostApi.setSupportZoom was null, expected non-null int.'); - final bool? arg_support = (args[1] as bool?); - assert(arg_support != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebSettingsHostApi.setSupportZoom was null, expected non-null bool.'); - api.setSupportZoom(arg_instanceId!, arg_support!); - return []; - }); - } - } - { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebSettingsHostApi.setLoadWithOverviewMode', - codec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebSettingsHostApi.setLoadWithOverviewMode was null.'); - final List args = (message as List?)!; - final int? arg_instanceId = (args[0] as int?); - assert(arg_instanceId != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebSettingsHostApi.setLoadWithOverviewMode was null, expected non-null int.'); - final bool? arg_overview = (args[1] as bool?); - assert(arg_overview != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebSettingsHostApi.setLoadWithOverviewMode was null, expected non-null bool.'); - api.setLoadWithOverviewMode(arg_instanceId!, arg_overview!); - return []; - }); - } - } - { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebSettingsHostApi.setUseWideViewPort', - codec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebSettingsHostApi.setUseWideViewPort was null.'); - final List args = (message as List?)!; - final int? arg_instanceId = (args[0] as int?); - assert(arg_instanceId != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebSettingsHostApi.setUseWideViewPort was null, expected non-null int.'); - final bool? arg_use = (args[1] as bool?); - assert(arg_use != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebSettingsHostApi.setUseWideViewPort was null, expected non-null bool.'); - api.setUseWideViewPort(arg_instanceId!, arg_use!); - return []; - }); - } - } - { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebSettingsHostApi.setDisplayZoomControls', - codec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebSettingsHostApi.setDisplayZoomControls was null.'); - final List args = (message as List?)!; - final int? arg_instanceId = (args[0] as int?); - assert(arg_instanceId != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebSettingsHostApi.setDisplayZoomControls was null, expected non-null int.'); - final bool? arg_enabled = (args[1] as bool?); - assert(arg_enabled != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebSettingsHostApi.setDisplayZoomControls was null, expected non-null bool.'); - api.setDisplayZoomControls(arg_instanceId!, arg_enabled!); - return []; - }); - } - } - { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebSettingsHostApi.setBuiltInZoomControls', - codec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebSettingsHostApi.setBuiltInZoomControls was null.'); - final List args = (message as List?)!; - final int? arg_instanceId = (args[0] as int?); - assert(arg_instanceId != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebSettingsHostApi.setBuiltInZoomControls was null, expected non-null int.'); - final bool? arg_enabled = (args[1] as bool?); - assert(arg_enabled != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebSettingsHostApi.setBuiltInZoomControls was null, expected non-null bool.'); - api.setBuiltInZoomControls(arg_instanceId!, arg_enabled!); - return []; - }); - } - } - { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebSettingsHostApi.setAllowFileAccess', - codec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebSettingsHostApi.setAllowFileAccess was null.'); - final List args = (message as List?)!; - final int? arg_instanceId = (args[0] as int?); - assert(arg_instanceId != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebSettingsHostApi.setAllowFileAccess was null, expected non-null int.'); - final bool? arg_enabled = (args[1] as bool?); - assert(arg_enabled != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebSettingsHostApi.setAllowFileAccess was null, expected non-null bool.'); - api.setAllowFileAccess(arg_instanceId!, arg_enabled!); - return []; - }); - } - } - { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebSettingsHostApi.setTextZoom', - codec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebSettingsHostApi.setTextZoom was null.'); - final List args = (message as List?)!; - final int? arg_instanceId = (args[0] as int?); - assert(arg_instanceId != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebSettingsHostApi.setTextZoom was null, expected non-null int.'); - final int? arg_textZoom = (args[1] as int?); - assert(arg_textZoom != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebSettingsHostApi.setTextZoom was null, expected non-null int.'); - api.setTextZoom(arg_instanceId!, arg_textZoom!); - return []; - }); - } - } - { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebSettingsHostApi.getUserAgentString', - codec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebSettingsHostApi.getUserAgentString was null.'); - final List args = (message as List?)!; - final int? arg_instanceId = (args[0] as int?); - assert(arg_instanceId != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebSettingsHostApi.getUserAgentString was null, expected non-null int.'); - final String output = api.getUserAgentString(arg_instanceId!); - return [output]; - }); - } - } - } -} - -abstract class TestJavaScriptChannelHostApi { - static TestDefaultBinaryMessengerBinding? get _testBinaryMessengerBinding => - TestDefaultBinaryMessengerBinding.instance; - static const MessageCodec codec = StandardMessageCodec(); - - void create(int instanceId, String channelName); - - static void setup(TestJavaScriptChannelHostApi? api, - {BinaryMessenger? binaryMessenger}) { - { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.JavaScriptChannelHostApi.create', - codec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.JavaScriptChannelHostApi.create was null.'); - final List args = (message as List?)!; - final int? arg_instanceId = (args[0] as int?); - assert(arg_instanceId != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.JavaScriptChannelHostApi.create was null, expected non-null int.'); - final String? arg_channelName = (args[1] as String?); - assert(arg_channelName != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.JavaScriptChannelHostApi.create was null, expected non-null String.'); - api.create(arg_instanceId!, arg_channelName!); - return []; - }); - } - } - } -} - -abstract class TestWebViewClientHostApi { - static TestDefaultBinaryMessengerBinding? get _testBinaryMessengerBinding => - TestDefaultBinaryMessengerBinding.instance; - static const MessageCodec codec = StandardMessageCodec(); - - void create(int instanceId); - - void setSynchronousReturnValueForShouldOverrideUrlLoading( - int instanceId, bool value); - - static void setup(TestWebViewClientHostApi? api, - {BinaryMessenger? binaryMessenger}) { - { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebViewClientHostApi.create', - codec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewClientHostApi.create was null.'); - final List args = (message as List?)!; - final int? arg_instanceId = (args[0] as int?); - assert(arg_instanceId != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewClientHostApi.create was null, expected non-null int.'); - api.create(arg_instanceId!); - return []; - }); - } - } - { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebViewClientHostApi.setSynchronousReturnValueForShouldOverrideUrlLoading', - codec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewClientHostApi.setSynchronousReturnValueForShouldOverrideUrlLoading was null.'); - final List args = (message as List?)!; - final int? arg_instanceId = (args[0] as int?); - assert(arg_instanceId != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewClientHostApi.setSynchronousReturnValueForShouldOverrideUrlLoading was null, expected non-null int.'); - final bool? arg_value = (args[1] as bool?); - assert(arg_value != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebViewClientHostApi.setSynchronousReturnValueForShouldOverrideUrlLoading was null, expected non-null bool.'); - api.setSynchronousReturnValueForShouldOverrideUrlLoading( - arg_instanceId!, arg_value!); - return []; - }); - } - } - } -} - -abstract class TestDownloadListenerHostApi { - static TestDefaultBinaryMessengerBinding? get _testBinaryMessengerBinding => - TestDefaultBinaryMessengerBinding.instance; - static const MessageCodec codec = StandardMessageCodec(); - - void create(int instanceId); - - static void setup(TestDownloadListenerHostApi? api, - {BinaryMessenger? binaryMessenger}) { - { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.DownloadListenerHostApi.create', - codec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.DownloadListenerHostApi.create was null.'); - final List args = (message as List?)!; - final int? arg_instanceId = (args[0] as int?); - assert(arg_instanceId != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.DownloadListenerHostApi.create was null, expected non-null int.'); - api.create(arg_instanceId!); - return []; - }); - } - } - } -} - -abstract class TestWebChromeClientHostApi { - static TestDefaultBinaryMessengerBinding? get _testBinaryMessengerBinding => - TestDefaultBinaryMessengerBinding.instance; - static const MessageCodec codec = StandardMessageCodec(); - - void create(int instanceId); - - void setSynchronousReturnValueForOnShowFileChooser( - int instanceId, bool value); - - void setSynchronousReturnValueForOnConsoleMessage(int instanceId, bool value); - - void setSynchronousReturnValueForOnJsAlert(int instanceId, bool value); - - void setSynchronousReturnValueForOnJsConfirm(int instanceId, bool value); - - void setSynchronousReturnValueForOnJsPrompt(int instanceId, bool value); - - static void setup(TestWebChromeClientHostApi? api, - {BinaryMessenger? binaryMessenger}) { - { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebChromeClientHostApi.create', - codec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebChromeClientHostApi.create was null.'); - final List args = (message as List?)!; - final int? arg_instanceId = (args[0] as int?); - assert(arg_instanceId != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebChromeClientHostApi.create was null, expected non-null int.'); - api.create(arg_instanceId!); - return []; - }); - } - } - { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebChromeClientHostApi.setSynchronousReturnValueForOnShowFileChooser', - codec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebChromeClientHostApi.setSynchronousReturnValueForOnShowFileChooser was null.'); - final List args = (message as List?)!; - final int? arg_instanceId = (args[0] as int?); - assert(arg_instanceId != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebChromeClientHostApi.setSynchronousReturnValueForOnShowFileChooser was null, expected non-null int.'); - final bool? arg_value = (args[1] as bool?); - assert(arg_value != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebChromeClientHostApi.setSynchronousReturnValueForOnShowFileChooser was null, expected non-null bool.'); - api.setSynchronousReturnValueForOnShowFileChooser( - arg_instanceId!, arg_value!); - return []; - }); - } - } - { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebChromeClientHostApi.setSynchronousReturnValueForOnConsoleMessage', - codec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebChromeClientHostApi.setSynchronousReturnValueForOnConsoleMessage was null.'); - final List args = (message as List?)!; - final int? arg_instanceId = (args[0] as int?); - assert(arg_instanceId != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebChromeClientHostApi.setSynchronousReturnValueForOnConsoleMessage was null, expected non-null int.'); - final bool? arg_value = (args[1] as bool?); - assert(arg_value != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebChromeClientHostApi.setSynchronousReturnValueForOnConsoleMessage was null, expected non-null bool.'); - api.setSynchronousReturnValueForOnConsoleMessage( - arg_instanceId!, arg_value!); - return []; - }); - } - } - { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebChromeClientHostApi.setSynchronousReturnValueForOnJsAlert', - codec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebChromeClientHostApi.setSynchronousReturnValueForOnJsAlert was null.'); - final List args = (message as List?)!; - final int? arg_instanceId = (args[0] as int?); - assert(arg_instanceId != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebChromeClientHostApi.setSynchronousReturnValueForOnJsAlert was null, expected non-null int.'); - final bool? arg_value = (args[1] as bool?); - assert(arg_value != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebChromeClientHostApi.setSynchronousReturnValueForOnJsAlert was null, expected non-null bool.'); - api.setSynchronousReturnValueForOnJsAlert( - arg_instanceId!, arg_value!); - return []; - }); - } - } - { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebChromeClientHostApi.setSynchronousReturnValueForOnJsConfirm', - codec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebChromeClientHostApi.setSynchronousReturnValueForOnJsConfirm was null.'); - final List args = (message as List?)!; - final int? arg_instanceId = (args[0] as int?); - assert(arg_instanceId != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebChromeClientHostApi.setSynchronousReturnValueForOnJsConfirm was null, expected non-null int.'); - final bool? arg_value = (args[1] as bool?); - assert(arg_value != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebChromeClientHostApi.setSynchronousReturnValueForOnJsConfirm was null, expected non-null bool.'); - api.setSynchronousReturnValueForOnJsConfirm( - arg_instanceId!, arg_value!); - return []; - }); - } - } - { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebChromeClientHostApi.setSynchronousReturnValueForOnJsPrompt', - codec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebChromeClientHostApi.setSynchronousReturnValueForOnJsPrompt was null.'); - final List args = (message as List?)!; - final int? arg_instanceId = (args[0] as int?); - assert(arg_instanceId != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebChromeClientHostApi.setSynchronousReturnValueForOnJsPrompt was null, expected non-null int.'); - final bool? arg_value = (args[1] as bool?); - assert(arg_value != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebChromeClientHostApi.setSynchronousReturnValueForOnJsPrompt was null, expected non-null bool.'); - api.setSynchronousReturnValueForOnJsPrompt( - arg_instanceId!, arg_value!); - return []; - }); - } - } - } -} - -abstract class TestAssetManagerHostApi { - static TestDefaultBinaryMessengerBinding? get _testBinaryMessengerBinding => - TestDefaultBinaryMessengerBinding.instance; - static const MessageCodec codec = StandardMessageCodec(); - - List list(String path); - - String getAssetFilePathByName(String name); - - static void setup(TestAssetManagerHostApi? api, - {BinaryMessenger? binaryMessenger}) { - { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.FlutterAssetManagerHostApi.list', - codec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.FlutterAssetManagerHostApi.list was null.'); - final List args = (message as List?)!; - final String? arg_path = (args[0] as String?); - assert(arg_path != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.FlutterAssetManagerHostApi.list was null, expected non-null String.'); - final List output = api.list(arg_path!); - return [output]; - }); - } - } - { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.FlutterAssetManagerHostApi.getAssetFilePathByName', - codec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.FlutterAssetManagerHostApi.getAssetFilePathByName was null.'); - final List args = (message as List?)!; - final String? arg_name = (args[0] as String?); - assert(arg_name != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.FlutterAssetManagerHostApi.getAssetFilePathByName was null, expected non-null String.'); - final String output = api.getAssetFilePathByName(arg_name!); - return [output]; - }); - } - } - } -} - -abstract class TestWebStorageHostApi { - static TestDefaultBinaryMessengerBinding? get _testBinaryMessengerBinding => - TestDefaultBinaryMessengerBinding.instance; - static const MessageCodec codec = StandardMessageCodec(); - - void create(int instanceId); - - void deleteAllData(int instanceId); - - static void setup(TestWebStorageHostApi? api, - {BinaryMessenger? binaryMessenger}) { - { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebStorageHostApi.create', - codec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebStorageHostApi.create was null.'); - final List args = (message as List?)!; - final int? arg_instanceId = (args[0] as int?); - assert(arg_instanceId != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebStorageHostApi.create was null, expected non-null int.'); - api.create(arg_instanceId!); - return []; - }); - } - } - { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.WebStorageHostApi.deleteAllData', - codec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebStorageHostApi.deleteAllData was null.'); - final List args = (message as List?)!; - final int? arg_instanceId = (args[0] as int?); - assert(arg_instanceId != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.WebStorageHostApi.deleteAllData was null, expected non-null int.'); - api.deleteAllData(arg_instanceId!); - return []; - }); - } - } - } -} - -/// Host API for `PermissionRequest`. -/// -/// This class may handle instantiating and adding native object instances that -/// are attached to a Dart instance or handle method calls on the associated -/// native class or an instance of the class. -/// -/// See https://developer.android.com/reference/android/webkit/PermissionRequest. -abstract class TestPermissionRequestHostApi { - static TestDefaultBinaryMessengerBinding? get _testBinaryMessengerBinding => - TestDefaultBinaryMessengerBinding.instance; - static const MessageCodec codec = StandardMessageCodec(); - - /// Handles Dart method `PermissionRequest.grant`. - void grant(int instanceId, List resources); - - /// Handles Dart method `PermissionRequest.deny`. - void deny(int instanceId); - - static void setup(TestPermissionRequestHostApi? api, - {BinaryMessenger? binaryMessenger}) { - { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.PermissionRequestHostApi.grant', - codec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.PermissionRequestHostApi.grant was null.'); - final List args = (message as List?)!; - final int? arg_instanceId = (args[0] as int?); - assert(arg_instanceId != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.PermissionRequestHostApi.grant was null, expected non-null int.'); - final List? arg_resources = - (args[1] as List?)?.cast(); - assert(arg_resources != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.PermissionRequestHostApi.grant was null, expected non-null List.'); - api.grant(arg_instanceId!, arg_resources!); - return []; - }); - } - } - { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.PermissionRequestHostApi.deny', - codec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.PermissionRequestHostApi.deny was null.'); - final List args = (message as List?)!; - final int? arg_instanceId = (args[0] as int?); - assert(arg_instanceId != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.PermissionRequestHostApi.deny was null, expected non-null int.'); - api.deny(arg_instanceId!); - return []; - }); - } - } - } -} - -/// Host API for `CustomViewCallback`. -/// -/// This class may handle instantiating and adding native object instances that -/// are attached to a Dart instance or handle method calls on the associated -/// native class or an instance of the class. -/// -/// See https://developer.android.com/reference/android/webkit/WebChromeClient.CustomViewCallback. -abstract class TestCustomViewCallbackHostApi { - static TestDefaultBinaryMessengerBinding? get _testBinaryMessengerBinding => - TestDefaultBinaryMessengerBinding.instance; - static const MessageCodec codec = StandardMessageCodec(); - - /// Handles Dart method `CustomViewCallback.onCustomViewHidden`. - void onCustomViewHidden(int identifier); - - static void setup(TestCustomViewCallbackHostApi? api, - {BinaryMessenger? binaryMessenger}) { - { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.CustomViewCallbackHostApi.onCustomViewHidden', - codec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.CustomViewCallbackHostApi.onCustomViewHidden was null.'); - final List args = (message as List?)!; - final int? arg_identifier = (args[0] as int?); - assert(arg_identifier != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.CustomViewCallbackHostApi.onCustomViewHidden was null, expected non-null int.'); - api.onCustomViewHidden(arg_identifier!); - return []; - }); - } - } - } -} - -/// Host API for `GeolocationPermissionsCallback`. -/// -/// This class may handle instantiating and adding native object instances that -/// are attached to a Dart instance or handle method calls on the associated -/// native class or an instance of the class. -/// -/// See https://developer.android.com/reference/android/webkit/GeolocationPermissions.Callback. -abstract class TestGeolocationPermissionsCallbackHostApi { - static TestDefaultBinaryMessengerBinding? get _testBinaryMessengerBinding => - TestDefaultBinaryMessengerBinding.instance; - static const MessageCodec codec = StandardMessageCodec(); - - /// Handles Dart method `GeolocationPermissionsCallback.invoke`. - void invoke(int instanceId, String origin, bool allow, bool retain); - - static void setup(TestGeolocationPermissionsCallbackHostApi? api, - {BinaryMessenger? binaryMessenger}) { - { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.GeolocationPermissionsCallbackHostApi.invoke', - codec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.GeolocationPermissionsCallbackHostApi.invoke was null.'); - final List args = (message as List?)!; - final int? arg_instanceId = (args[0] as int?); - assert(arg_instanceId != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.GeolocationPermissionsCallbackHostApi.invoke was null, expected non-null int.'); - final String? arg_origin = (args[1] as String?); - assert(arg_origin != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.GeolocationPermissionsCallbackHostApi.invoke was null, expected non-null String.'); - final bool? arg_allow = (args[2] as bool?); - assert(arg_allow != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.GeolocationPermissionsCallbackHostApi.invoke was null, expected non-null bool.'); - final bool? arg_retain = (args[3] as bool?); - assert(arg_retain != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.GeolocationPermissionsCallbackHostApi.invoke was null, expected non-null bool.'); - api.invoke(arg_instanceId!, arg_origin!, arg_allow!, arg_retain!); - return []; - }); - } - } - } -} - -/// Host API for `HttpAuthHandler`. -/// -/// This class may handle instantiating and adding native object instances that -/// are attached to a Dart instance or handle method calls on the associated -/// native class or an instance of the class. -/// -/// See https://developer.android.com/reference/android/webkit/HttpAuthHandler. -abstract class TestHttpAuthHandlerHostApi { - static TestDefaultBinaryMessengerBinding? get _testBinaryMessengerBinding => - TestDefaultBinaryMessengerBinding.instance; - static const MessageCodec codec = StandardMessageCodec(); - - /// Handles Dart method `HttpAuthHandler.useHttpAuthUsernamePassword`. - bool useHttpAuthUsernamePassword(int instanceId); - - /// Handles Dart method `HttpAuthHandler.cancel`. - void cancel(int instanceId); - - /// Handles Dart method `HttpAuthHandler.proceed`. - void proceed(int instanceId, String username, String password); - - static void setup(TestHttpAuthHandlerHostApi? api, - {BinaryMessenger? binaryMessenger}) { - { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.HttpAuthHandlerHostApi.useHttpAuthUsernamePassword', - codec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.HttpAuthHandlerHostApi.useHttpAuthUsernamePassword was null.'); - final List args = (message as List?)!; - final int? arg_instanceId = (args[0] as int?); - assert(arg_instanceId != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.HttpAuthHandlerHostApi.useHttpAuthUsernamePassword was null, expected non-null int.'); - final bool output = api.useHttpAuthUsernamePassword(arg_instanceId!); - return [output]; - }); - } - } - { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.HttpAuthHandlerHostApi.cancel', - codec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.HttpAuthHandlerHostApi.cancel was null.'); - final List args = (message as List?)!; - final int? arg_instanceId = (args[0] as int?); - assert(arg_instanceId != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.HttpAuthHandlerHostApi.cancel was null, expected non-null int.'); - api.cancel(arg_instanceId!); - return []; - }); - } - } - { - final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.webview_flutter_android.HttpAuthHandlerHostApi.proceed', - codec, - binaryMessenger: binaryMessenger); - if (api == null) { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, null); - } else { - _testBinaryMessengerBinding!.defaultBinaryMessenger - .setMockDecodedMessageHandler(channel, - (Object? message) async { - assert(message != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.HttpAuthHandlerHostApi.proceed was null.'); - final List args = (message as List?)!; - final int? arg_instanceId = (args[0] as int?); - assert(arg_instanceId != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.HttpAuthHandlerHostApi.proceed was null, expected non-null int.'); - final String? arg_username = (args[1] as String?); - assert(arg_username != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.HttpAuthHandlerHostApi.proceed was null, expected non-null String.'); - final String? arg_password = (args[2] as String?); - assert(arg_password != null, - 'Argument for dev.flutter.pigeon.webview_flutter_android.HttpAuthHandlerHostApi.proceed was null, expected non-null String.'); - api.proceed(arg_instanceId!, arg_username!, arg_password!); - return []; - }); - } - } - } -}