From eaae468632b6dd56a9ffe50fe443eb82f73dac20 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Wed, 22 Feb 2023 12:57:41 -0500 Subject: [PATCH 01/24] add changed files --- .../GeneratedAndroidWebView.java | 782 ++++++------------ .../lib/src/android_webview.dart | 118 +-- .../lib/src/android_webview.g.dart | 43 +- .../lib/src/android_webview_api_impls.dart | 64 +- .../lib/src/instance_manager.dart | 88 +- .../pigeons/android_webview.dart | 9 + .../webview_flutter_android/pubspec.yaml | 2 +- .../test/test_android_webview.g.dart | 222 +++-- 8 files changed, 573 insertions(+), 755 deletions(-) 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 index 425f6c1415b..b4e05f945b3 100644 --- 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 @@ -1,7 +1,7 @@ // 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 (v4.2.14), do not edit directly. +// Autogenerated from Pigeon (v9.0.0), do not edit directly. // See also: https://pub.dev/packages/pigeon package io.flutter.plugins.webviewflutter; @@ -18,39 +18,46 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; +import java.util.HashMap; import java.util.List; import java.util.Map; /** Generated class from Pigeon. */ @SuppressWarnings({"unused", "unchecked", "CodeBlock2Expr", "RedundantSuppression"}) public class GeneratedAndroidWebView { + @NonNull + private static ArrayList wrapError(@NonNull Throwable exception) { + ArrayList errorList = new ArrayList(3); + 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. + * 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. + * 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. + * 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. + * 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. + * See https://developer.android.com/reference/android/webkit/WebChromeClient.FileChooserParams#MODE_SAVE. */ SAVE(2); @@ -62,7 +69,7 @@ private FileChooserMode(final int index) { } /** Generated class from Pigeon that represents data sent in messages. */ - public static class FileChooserModeEnumData { + public static final class FileChooserModeEnumData { private @NonNull FileChooserMode value; public @NonNull FileChooserMode getValue() { @@ -80,6 +87,7 @@ public void setValue(@NonNull FileChooserMode setterArg) { private FileChooserModeEnumData() {} public static final class Builder { + private @Nullable FileChooserMode value; public @NonNull Builder setValue(@NonNull FileChooserMode setterArg) { @@ -110,7 +118,7 @@ ArrayList toList() { } /** Generated class from Pigeon that represents data sent in messages. */ - public static class WebResourceRequestData { + public static final class WebResourceRequestData { private @NonNull String url; public @NonNull String getUrl() { @@ -190,6 +198,7 @@ public void setRequestHeaders(@NonNull Map setterArg) { private WebResourceRequestData() {} public static final class Builder { + private @Nullable String url; public @NonNull Builder setUrl(@NonNull String setterArg) { @@ -275,7 +284,7 @@ ArrayList toList() { } /** Generated class from Pigeon that represents data sent in messages. */ - public static class WebResourceErrorData { + public static final class WebResourceErrorData { private @NonNull Long errorCode; public @NonNull Long getErrorCode() { @@ -306,6 +315,7 @@ public void setDescription(@NonNull String setterArg) { private WebResourceErrorData() {} public static final class Builder { + private @Nullable Long errorCode; public @NonNull Builder setErrorCode(@NonNull Long setterArg) { @@ -339,10 +349,7 @@ ArrayList toList() { 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)); + pigeonResult.setErrorCode((errorCode == null) ? null : ((errorCode instanceof Integer) ? (Integer) errorCode : (Long) errorCode)); Object description = list.get(1); pigeonResult.setDescription((String) description); return pigeonResult; @@ -350,7 +357,7 @@ ArrayList toList() { } /** Generated class from Pigeon that represents data sent in messages. */ - public static class WebViewPoint { + public static final class WebViewPoint { private @NonNull Long x; public @NonNull Long getX() { @@ -381,6 +388,7 @@ public void setY(@NonNull Long setterArg) { private WebViewPoint() {} public static final class Builder { + private @Nullable Long x; public @NonNull Builder setX(@NonNull Long setterArg) { @@ -426,25 +434,66 @@ public interface Result { void error(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 MessageCodec getCodec() { + return new StandardMessageCodec(); + } + /**Sets up an instance of `InstanceManagerHostApi` to handle messages through the `binaryMessenger`. */ + static void setup(BinaryMessenger binaryMessenger, InstanceManagerHostApi api) { + { + BasicMessageChannel channel = + new BasicMessageChannel<>( + binaryMessenger, "dev.flutter.pigeon.InstanceManagerHostApi.clear", getCodec()); + if (api != null) { + channel.setMessageHandler( + (message, reply) -> { + ArrayList wrapped = new ArrayList(); + try { + api.clear(); + wrapped.add(0, null); + } catch (Error | RuntimeException 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`. + * 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. + * 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. + * 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 MessageCodec getCodec() { return new StandardMessageCodec(); } - /** - * Sets up an instance of `JavaObjectHostApi` to handle messages through the `binaryMessenger`. - */ + /**Sets up an instance of `JavaObjectHostApi` to handle messages through the `binaryMessenger`. */ static void setup(BinaryMessenger binaryMessenger, JavaObjectHostApi api) { { BasicMessageChannel channel = @@ -453,7 +502,7 @@ static void setup(BinaryMessenger binaryMessenger, JavaObjectHostApi api) { if (api != null) { channel.setMessageHandler( (message, reply) -> { - ArrayList wrapped = new ArrayList<>(); + ArrayList wrapped = new ArrayList(); try { ArrayList args = (ArrayList) message; assert args != null; @@ -478,9 +527,9 @@ static void setup(BinaryMessenger binaryMessenger, JavaObjectHostApi api) { /** * Handles callbacks methods for the native Java Object class. * - *

See https://docs.oracle.com/javase/7/docs/api/java/lang/Object.html. + * 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. + * Generated class from Pigeon that represents Flutter messages that can be called from Java. */ public static class JavaObjectFlutterApi { private final BinaryMessenger binaryMessenger; @@ -489,27 +538,25 @@ public JavaObjectFlutterApi(BinaryMessenger argBinaryMessenger) { this.binaryMessenger = argBinaryMessenger; } - public interface Reply { + /** Public interface for sending reply. */ public interface Reply { void reply(T reply); } /** The codec used by JavaObjectFlutterApi. */ static MessageCodec getCodec() { return new StandardMessageCodec(); } - public void dispose(@NonNull Long identifierArg, Reply callback) { BasicMessageChannel channel = new BasicMessageChannel<>( binaryMessenger, "dev.flutter.pigeon.JavaObjectFlutterApi.dispose", getCodec()); channel.send( new ArrayList(Collections.singletonList(identifierArg)), - channelReply -> { - callback.reply(null); - }); + channelReply -> callback.reply(null)); } } /** Generated interface from Pigeon that represents a handler of messages from Flutter. */ public interface CookieManagerHostApi { + void clearCookies(Result result); void setCookie(@NonNull String url, @NonNull String value); @@ -518,23 +565,18 @@ public interface CookieManagerHostApi { static MessageCodec getCodec() { return new StandardMessageCodec(); } - /** - * Sets up an instance of `CookieManagerHostApi` to handle messages through the - * `binaryMessenger`. - */ + /**Sets up an instance of `CookieManagerHostApi` to handle messages through the `binaryMessenger`. */ static void setup(BinaryMessenger binaryMessenger, CookieManagerHostApi api) { { BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.CookieManagerHostApi.clearCookies", - getCodec()); + binaryMessenger, "dev.flutter.pigeon.CookieManagerHostApi.clearCookies", getCodec()); if (api != null) { channel.setMessageHandler( (message, reply) -> { - ArrayList wrapped = new ArrayList<>(); + ArrayList wrapped = new ArrayList(); try { - Result resultCallback = + Result resultCallback = new Result() { public void success(Boolean result) { wrapped.add(0, result); @@ -564,7 +606,7 @@ public void error(Throwable error) { if (api != null) { channel.setMessageHandler( (message, reply) -> { - ArrayList wrapped = new ArrayList<>(); + ArrayList wrapped = new ArrayList(); try { ArrayList args = (ArrayList) message; assert args != null; @@ -601,7 +643,6 @@ 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); } @@ -620,34 +661,24 @@ protected void writeValue(@NonNull ByteArrayOutputStream stream, Object value) { /** Generated interface from Pigeon that represents a handler of messages from Flutter. */ public interface WebViewHostApi { + void create(@NonNull Long instanceId, @NonNull Boolean useHybridComposition); - void loadData( - @NonNull Long instanceId, - @NonNull String data, - @Nullable String mimeType, - @Nullable String encoding); + 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 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 loadUrl(@NonNull Long instanceId, @NonNull String url, @NonNull Map headers); void postUrl(@NonNull Long instanceId, @NonNull String url, @NonNull byte[] data); - @Nullable + @Nullable String getUrl(@NonNull Long instanceId); - @NonNull + @NonNull Boolean canGoBack(@NonNull Long instanceId); - @NonNull + @NonNull Boolean canGoForward(@NonNull Long instanceId); void goBack(@NonNull Long instanceId); @@ -658,23 +689,22 @@ void loadUrl( void clearCache(@NonNull Long instanceId, @NonNull Boolean includeDiskFiles); - void evaluateJavascript( - @NonNull Long instanceId, @NonNull String javascriptString, Result result); + void evaluateJavascript(@NonNull Long instanceId, @NonNull String javascriptString, Result result); - @Nullable + @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 + @NonNull Long getScrollX(@NonNull Long instanceId); - @NonNull + @NonNull Long getScrollY(@NonNull Long instanceId); - @NonNull + @NonNull WebViewPoint getScrollPosition(@NonNull Long instanceId); void setWebContentsDebuggingEnabled(@NonNull Boolean enabled); @@ -683,8 +713,7 @@ void evaluateJavascript( void addJavaScriptChannel(@NonNull Long instanceId, @NonNull Long javaScriptChannelInstanceId); - void removeJavaScriptChannel( - @NonNull Long instanceId, @NonNull Long javaScriptChannelInstanceId); + void removeJavaScriptChannel(@NonNull Long instanceId, @NonNull Long javaScriptChannelInstanceId); void setDownloadListener(@NonNull Long instanceId, @Nullable Long listenerInstanceId); @@ -696,7 +725,7 @@ void removeJavaScriptChannel( static MessageCodec getCodec() { return WebViewHostApiCodec.INSTANCE; } - /** Sets up an instance of `WebViewHostApi` to handle messages through the `binaryMessenger`. */ + /**Sets up an instance of `WebViewHostApi` to handle messages through the `binaryMessenger`. */ static void setup(BinaryMessenger binaryMessenger, WebViewHostApi api) { { BasicMessageChannel channel = @@ -705,7 +734,7 @@ static void setup(BinaryMessenger binaryMessenger, WebViewHostApi api) { if (api != null) { channel.setMessageHandler( (message, reply) -> { - ArrayList wrapped = new ArrayList<>(); + ArrayList wrapped = new ArrayList(); try { ArrayList args = (ArrayList) message; assert args != null; @@ -717,9 +746,7 @@ static void setup(BinaryMessenger binaryMessenger, WebViewHostApi api) { if (useHybridCompositionArg == null) { throw new NullPointerException("useHybridCompositionArg unexpectedly null."); } - api.create( - (instanceIdArg == null) ? null : instanceIdArg.longValue(), - useHybridCompositionArg); + api.create((instanceIdArg == null) ? null : instanceIdArg.longValue(), useHybridCompositionArg); wrapped.add(0, null); } catch (Error | RuntimeException exception) { ArrayList wrappedError = wrapError(exception); @@ -738,7 +765,7 @@ static void setup(BinaryMessenger binaryMessenger, WebViewHostApi api) { if (api != null) { channel.setMessageHandler( (message, reply) -> { - ArrayList wrapped = new ArrayList<>(); + ArrayList wrapped = new ArrayList(); try { ArrayList args = (ArrayList) message; assert args != null; @@ -752,11 +779,7 @@ static void setup(BinaryMessenger binaryMessenger, WebViewHostApi api) { } String mimeTypeArg = (String) args.get(2); String encodingArg = (String) args.get(3); - api.loadData( - (instanceIdArg == null) ? null : instanceIdArg.longValue(), - dataArg, - mimeTypeArg, - encodingArg); + api.loadData((instanceIdArg == null) ? null : instanceIdArg.longValue(), dataArg, mimeTypeArg, encodingArg); wrapped.add(0, null); } catch (Error | RuntimeException exception) { ArrayList wrappedError = wrapError(exception); @@ -771,13 +794,11 @@ static void setup(BinaryMessenger binaryMessenger, WebViewHostApi api) { { BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.WebViewHostApi.loadDataWithBaseUrl", - getCodec()); + binaryMessenger, "dev.flutter.pigeon.WebViewHostApi.loadDataWithBaseUrl", getCodec()); if (api != null) { channel.setMessageHandler( (message, reply) -> { - ArrayList wrapped = new ArrayList<>(); + ArrayList wrapped = new ArrayList(); try { ArrayList args = (ArrayList) message; assert args != null; @@ -793,13 +814,7 @@ static void setup(BinaryMessenger binaryMessenger, WebViewHostApi api) { String mimeTypeArg = (String) args.get(3); String encodingArg = (String) args.get(4); String historyUrlArg = (String) args.get(5); - api.loadDataWithBaseUrl( - (instanceIdArg == null) ? null : instanceIdArg.longValue(), - baseUrlArg, - dataArg, - mimeTypeArg, - encodingArg, - historyUrlArg); + api.loadDataWithBaseUrl((instanceIdArg == null) ? null : instanceIdArg.longValue(), baseUrlArg, dataArg, mimeTypeArg, encodingArg, historyUrlArg); wrapped.add(0, null); } catch (Error | RuntimeException exception) { ArrayList wrappedError = wrapError(exception); @@ -818,7 +833,7 @@ static void setup(BinaryMessenger binaryMessenger, WebViewHostApi api) { if (api != null) { channel.setMessageHandler( (message, reply) -> { - ArrayList wrapped = new ArrayList<>(); + ArrayList wrapped = new ArrayList(); try { ArrayList args = (ArrayList) message; assert args != null; @@ -834,10 +849,7 @@ static void setup(BinaryMessenger binaryMessenger, WebViewHostApi api) { if (headersArg == null) { throw new NullPointerException("headersArg unexpectedly null."); } - api.loadUrl( - (instanceIdArg == null) ? null : instanceIdArg.longValue(), - urlArg, - headersArg); + api.loadUrl((instanceIdArg == null) ? null : instanceIdArg.longValue(), urlArg, headersArg); wrapped.add(0, null); } catch (Error | RuntimeException exception) { ArrayList wrappedError = wrapError(exception); @@ -856,7 +868,7 @@ static void setup(BinaryMessenger binaryMessenger, WebViewHostApi api) { if (api != null) { channel.setMessageHandler( (message, reply) -> { - ArrayList wrapped = new ArrayList<>(); + ArrayList wrapped = new ArrayList(); try { ArrayList args = (ArrayList) message; assert args != null; @@ -872,8 +884,7 @@ static void setup(BinaryMessenger binaryMessenger, WebViewHostApi api) { if (dataArg == null) { throw new NullPointerException("dataArg unexpectedly null."); } - api.postUrl( - (instanceIdArg == null) ? null : instanceIdArg.longValue(), urlArg, dataArg); + api.postUrl((instanceIdArg == null) ? null : instanceIdArg.longValue(), urlArg, dataArg); wrapped.add(0, null); } catch (Error | RuntimeException exception) { ArrayList wrappedError = wrapError(exception); @@ -892,7 +903,7 @@ static void setup(BinaryMessenger binaryMessenger, WebViewHostApi api) { if (api != null) { channel.setMessageHandler( (message, reply) -> { - ArrayList wrapped = new ArrayList<>(); + ArrayList wrapped = new ArrayList(); try { ArrayList args = (ArrayList) message; assert args != null; @@ -900,8 +911,7 @@ static void setup(BinaryMessenger binaryMessenger, WebViewHostApi api) { if (instanceIdArg == null) { throw new NullPointerException("instanceIdArg unexpectedly null."); } - String output = - api.getUrl((instanceIdArg == null) ? null : instanceIdArg.longValue()); + String output = api.getUrl((instanceIdArg == null) ? null : instanceIdArg.longValue()); wrapped.add(0, output); } catch (Error | RuntimeException exception) { ArrayList wrappedError = wrapError(exception); @@ -920,7 +930,7 @@ static void setup(BinaryMessenger binaryMessenger, WebViewHostApi api) { if (api != null) { channel.setMessageHandler( (message, reply) -> { - ArrayList wrapped = new ArrayList<>(); + ArrayList wrapped = new ArrayList(); try { ArrayList args = (ArrayList) message; assert args != null; @@ -928,8 +938,7 @@ static void setup(BinaryMessenger binaryMessenger, WebViewHostApi api) { if (instanceIdArg == null) { throw new NullPointerException("instanceIdArg unexpectedly null."); } - Boolean output = - api.canGoBack((instanceIdArg == null) ? null : instanceIdArg.longValue()); + Boolean output = api.canGoBack((instanceIdArg == null) ? null : instanceIdArg.longValue()); wrapped.add(0, output); } catch (Error | RuntimeException exception) { ArrayList wrappedError = wrapError(exception); @@ -948,7 +957,7 @@ static void setup(BinaryMessenger binaryMessenger, WebViewHostApi api) { if (api != null) { channel.setMessageHandler( (message, reply) -> { - ArrayList wrapped = new ArrayList<>(); + ArrayList wrapped = new ArrayList(); try { ArrayList args = (ArrayList) message; assert args != null; @@ -956,8 +965,7 @@ static void setup(BinaryMessenger binaryMessenger, WebViewHostApi api) { if (instanceIdArg == null) { throw new NullPointerException("instanceIdArg unexpectedly null."); } - Boolean output = - api.canGoForward((instanceIdArg == null) ? null : instanceIdArg.longValue()); + Boolean output = api.canGoForward((instanceIdArg == null) ? null : instanceIdArg.longValue()); wrapped.add(0, output); } catch (Error | RuntimeException exception) { ArrayList wrappedError = wrapError(exception); @@ -976,7 +984,7 @@ static void setup(BinaryMessenger binaryMessenger, WebViewHostApi api) { if (api != null) { channel.setMessageHandler( (message, reply) -> { - ArrayList wrapped = new ArrayList<>(); + ArrayList wrapped = new ArrayList(); try { ArrayList args = (ArrayList) message; assert args != null; @@ -1003,7 +1011,7 @@ static void setup(BinaryMessenger binaryMessenger, WebViewHostApi api) { if (api != null) { channel.setMessageHandler( (message, reply) -> { - ArrayList wrapped = new ArrayList<>(); + ArrayList wrapped = new ArrayList(); try { ArrayList args = (ArrayList) message; assert args != null; @@ -1030,7 +1038,7 @@ static void setup(BinaryMessenger binaryMessenger, WebViewHostApi api) { if (api != null) { channel.setMessageHandler( (message, reply) -> { - ArrayList wrapped = new ArrayList<>(); + ArrayList wrapped = new ArrayList(); try { ArrayList args = (ArrayList) message; assert args != null; @@ -1057,7 +1065,7 @@ static void setup(BinaryMessenger binaryMessenger, WebViewHostApi api) { if (api != null) { channel.setMessageHandler( (message, reply) -> { - ArrayList wrapped = new ArrayList<>(); + ArrayList wrapped = new ArrayList(); try { ArrayList args = (ArrayList) message; assert args != null; @@ -1069,9 +1077,7 @@ static void setup(BinaryMessenger binaryMessenger, WebViewHostApi api) { if (includeDiskFilesArg == null) { throw new NullPointerException("includeDiskFilesArg unexpectedly null."); } - api.clearCache( - (instanceIdArg == null) ? null : instanceIdArg.longValue(), - includeDiskFilesArg); + api.clearCache((instanceIdArg == null) ? null : instanceIdArg.longValue(), includeDiskFilesArg); wrapped.add(0, null); } catch (Error | RuntimeException exception) { ArrayList wrappedError = wrapError(exception); @@ -1086,13 +1092,11 @@ static void setup(BinaryMessenger binaryMessenger, WebViewHostApi api) { { BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.WebViewHostApi.evaluateJavascript", - getCodec()); + binaryMessenger, "dev.flutter.pigeon.WebViewHostApi.evaluateJavascript", getCodec()); if (api != null) { channel.setMessageHandler( (message, reply) -> { - ArrayList wrapped = new ArrayList<>(); + ArrayList wrapped = new ArrayList(); try { ArrayList args = (ArrayList) message; assert args != null; @@ -1104,7 +1108,7 @@ static void setup(BinaryMessenger binaryMessenger, WebViewHostApi api) { if (javascriptStringArg == null) { throw new NullPointerException("javascriptStringArg unexpectedly null."); } - Result resultCallback = + Result resultCallback = new Result() { public void success(String result) { wrapped.add(0, result); @@ -1117,10 +1121,7 @@ public void error(Throwable error) { } }; - api.evaluateJavascript( - (instanceIdArg == null) ? null : instanceIdArg.longValue(), - javascriptStringArg, - resultCallback); + api.evaluateJavascript((instanceIdArg == null) ? null : instanceIdArg.longValue(), javascriptStringArg, resultCallback); } catch (Error | RuntimeException exception) { ArrayList wrappedError = wrapError(exception); reply.reply(wrappedError); @@ -1137,7 +1138,7 @@ public void error(Throwable error) { if (api != null) { channel.setMessageHandler( (message, reply) -> { - ArrayList wrapped = new ArrayList<>(); + ArrayList wrapped = new ArrayList(); try { ArrayList args = (ArrayList) message; assert args != null; @@ -1145,8 +1146,7 @@ public void error(Throwable error) { if (instanceIdArg == null) { throw new NullPointerException("instanceIdArg unexpectedly null."); } - String output = - api.getTitle((instanceIdArg == null) ? null : instanceIdArg.longValue()); + String output = api.getTitle((instanceIdArg == null) ? null : instanceIdArg.longValue()); wrapped.add(0, output); } catch (Error | RuntimeException exception) { ArrayList wrappedError = wrapError(exception); @@ -1165,7 +1165,7 @@ public void error(Throwable error) { if (api != null) { channel.setMessageHandler( (message, reply) -> { - ArrayList wrapped = new ArrayList<>(); + ArrayList wrapped = new ArrayList(); try { ArrayList args = (ArrayList) message; assert args != null; @@ -1181,10 +1181,7 @@ public void error(Throwable error) { if (yArg == null) { throw new NullPointerException("yArg unexpectedly null."); } - api.scrollTo( - (instanceIdArg == null) ? null : instanceIdArg.longValue(), - (xArg == null) ? null : xArg.longValue(), - (yArg == null) ? null : yArg.longValue()); + api.scrollTo((instanceIdArg == null) ? null : instanceIdArg.longValue(), (xArg == null) ? null : xArg.longValue(), (yArg == null) ? null : yArg.longValue()); wrapped.add(0, null); } catch (Error | RuntimeException exception) { ArrayList wrappedError = wrapError(exception); @@ -1203,7 +1200,7 @@ public void error(Throwable error) { if (api != null) { channel.setMessageHandler( (message, reply) -> { - ArrayList wrapped = new ArrayList<>(); + ArrayList wrapped = new ArrayList(); try { ArrayList args = (ArrayList) message; assert args != null; @@ -1219,10 +1216,7 @@ public void error(Throwable error) { if (yArg == null) { throw new NullPointerException("yArg unexpectedly null."); } - api.scrollBy( - (instanceIdArg == null) ? null : instanceIdArg.longValue(), - (xArg == null) ? null : xArg.longValue(), - (yArg == null) ? null : yArg.longValue()); + api.scrollBy((instanceIdArg == null) ? null : instanceIdArg.longValue(), (xArg == null) ? null : xArg.longValue(), (yArg == null) ? null : yArg.longValue()); wrapped.add(0, null); } catch (Error | RuntimeException exception) { ArrayList wrappedError = wrapError(exception); @@ -1241,7 +1235,7 @@ public void error(Throwable error) { if (api != null) { channel.setMessageHandler( (message, reply) -> { - ArrayList wrapped = new ArrayList<>(); + ArrayList wrapped = new ArrayList(); try { ArrayList args = (ArrayList) message; assert args != null; @@ -1249,8 +1243,7 @@ public void error(Throwable error) { if (instanceIdArg == null) { throw new NullPointerException("instanceIdArg unexpectedly null."); } - Long output = - api.getScrollX((instanceIdArg == null) ? null : instanceIdArg.longValue()); + Long output = api.getScrollX((instanceIdArg == null) ? null : instanceIdArg.longValue()); wrapped.add(0, output); } catch (Error | RuntimeException exception) { ArrayList wrappedError = wrapError(exception); @@ -1269,7 +1262,7 @@ public void error(Throwable error) { if (api != null) { channel.setMessageHandler( (message, reply) -> { - ArrayList wrapped = new ArrayList<>(); + ArrayList wrapped = new ArrayList(); try { ArrayList args = (ArrayList) message; assert args != null; @@ -1277,8 +1270,7 @@ public void error(Throwable error) { if (instanceIdArg == null) { throw new NullPointerException("instanceIdArg unexpectedly null."); } - Long output = - api.getScrollY((instanceIdArg == null) ? null : instanceIdArg.longValue()); + Long output = api.getScrollY((instanceIdArg == null) ? null : instanceIdArg.longValue()); wrapped.add(0, output); } catch (Error | RuntimeException exception) { ArrayList wrappedError = wrapError(exception); @@ -1297,7 +1289,7 @@ public void error(Throwable error) { if (api != null) { channel.setMessageHandler( (message, reply) -> { - ArrayList wrapped = new ArrayList<>(); + ArrayList wrapped = new ArrayList(); try { ArrayList args = (ArrayList) message; assert args != null; @@ -1305,9 +1297,7 @@ public void error(Throwable error) { if (instanceIdArg == null) { throw new NullPointerException("instanceIdArg unexpectedly null."); } - WebViewPoint output = - api.getScrollPosition( - (instanceIdArg == null) ? null : instanceIdArg.longValue()); + WebViewPoint output = api.getScrollPosition((instanceIdArg == null) ? null : instanceIdArg.longValue()); wrapped.add(0, output); } catch (Error | RuntimeException exception) { ArrayList wrappedError = wrapError(exception); @@ -1322,13 +1312,11 @@ public void error(Throwable error) { { BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.WebViewHostApi.setWebContentsDebuggingEnabled", - getCodec()); + binaryMessenger, "dev.flutter.pigeon.WebViewHostApi.setWebContentsDebuggingEnabled", getCodec()); if (api != null) { channel.setMessageHandler( (message, reply) -> { - ArrayList wrapped = new ArrayList<>(); + ArrayList wrapped = new ArrayList(); try { ArrayList args = (ArrayList) message; assert args != null; @@ -1355,7 +1343,7 @@ public void error(Throwable error) { if (api != null) { channel.setMessageHandler( (message, reply) -> { - ArrayList wrapped = new ArrayList<>(); + ArrayList wrapped = new ArrayList(); try { ArrayList args = (ArrayList) message; assert args != null; @@ -1367,11 +1355,7 @@ public void error(Throwable error) { if (webViewClientInstanceIdArg == null) { throw new NullPointerException("webViewClientInstanceIdArg unexpectedly null."); } - api.setWebViewClient( - (instanceIdArg == null) ? null : instanceIdArg.longValue(), - (webViewClientInstanceIdArg == null) - ? null - : webViewClientInstanceIdArg.longValue()); + api.setWebViewClient((instanceIdArg == null) ? null : instanceIdArg.longValue(), (webViewClientInstanceIdArg == null) ? null : webViewClientInstanceIdArg.longValue()); wrapped.add(0, null); } catch (Error | RuntimeException exception) { ArrayList wrappedError = wrapError(exception); @@ -1386,13 +1370,11 @@ public void error(Throwable error) { { BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.WebViewHostApi.addJavaScriptChannel", - getCodec()); + binaryMessenger, "dev.flutter.pigeon.WebViewHostApi.addJavaScriptChannel", getCodec()); if (api != null) { channel.setMessageHandler( (message, reply) -> { - ArrayList wrapped = new ArrayList<>(); + ArrayList wrapped = new ArrayList(); try { ArrayList args = (ArrayList) message; assert args != null; @@ -1402,14 +1384,9 @@ public void error(Throwable error) { } Number javaScriptChannelInstanceIdArg = (Number) args.get(1); if (javaScriptChannelInstanceIdArg == null) { - throw new NullPointerException( - "javaScriptChannelInstanceIdArg unexpectedly null."); - } - api.addJavaScriptChannel( - (instanceIdArg == null) ? null : instanceIdArg.longValue(), - (javaScriptChannelInstanceIdArg == null) - ? null - : javaScriptChannelInstanceIdArg.longValue()); + throw new NullPointerException("javaScriptChannelInstanceIdArg unexpectedly null."); + } + api.addJavaScriptChannel((instanceIdArg == null) ? null : instanceIdArg.longValue(), (javaScriptChannelInstanceIdArg == null) ? null : javaScriptChannelInstanceIdArg.longValue()); wrapped.add(0, null); } catch (Error | RuntimeException exception) { ArrayList wrappedError = wrapError(exception); @@ -1424,13 +1401,11 @@ public void error(Throwable error) { { BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.WebViewHostApi.removeJavaScriptChannel", - getCodec()); + binaryMessenger, "dev.flutter.pigeon.WebViewHostApi.removeJavaScriptChannel", getCodec()); if (api != null) { channel.setMessageHandler( (message, reply) -> { - ArrayList wrapped = new ArrayList<>(); + ArrayList wrapped = new ArrayList(); try { ArrayList args = (ArrayList) message; assert args != null; @@ -1440,14 +1415,9 @@ public void error(Throwable error) { } Number javaScriptChannelInstanceIdArg = (Number) args.get(1); if (javaScriptChannelInstanceIdArg == null) { - throw new NullPointerException( - "javaScriptChannelInstanceIdArg unexpectedly null."); - } - api.removeJavaScriptChannel( - (instanceIdArg == null) ? null : instanceIdArg.longValue(), - (javaScriptChannelInstanceIdArg == null) - ? null - : javaScriptChannelInstanceIdArg.longValue()); + throw new NullPointerException("javaScriptChannelInstanceIdArg unexpectedly null."); + } + api.removeJavaScriptChannel((instanceIdArg == null) ? null : instanceIdArg.longValue(), (javaScriptChannelInstanceIdArg == null) ? null : javaScriptChannelInstanceIdArg.longValue()); wrapped.add(0, null); } catch (Error | RuntimeException exception) { ArrayList wrappedError = wrapError(exception); @@ -1462,13 +1432,11 @@ public void error(Throwable error) { { BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.WebViewHostApi.setDownloadListener", - getCodec()); + binaryMessenger, "dev.flutter.pigeon.WebViewHostApi.setDownloadListener", getCodec()); if (api != null) { channel.setMessageHandler( (message, reply) -> { - ArrayList wrapped = new ArrayList<>(); + ArrayList wrapped = new ArrayList(); try { ArrayList args = (ArrayList) message; assert args != null; @@ -1477,9 +1445,7 @@ public void error(Throwable error) { throw new NullPointerException("instanceIdArg unexpectedly null."); } Number listenerInstanceIdArg = (Number) args.get(1); - api.setDownloadListener( - (instanceIdArg == null) ? null : instanceIdArg.longValue(), - (listenerInstanceIdArg == null) ? null : listenerInstanceIdArg.longValue()); + api.setDownloadListener((instanceIdArg == null) ? null : instanceIdArg.longValue(), (listenerInstanceIdArg == null) ? null : listenerInstanceIdArg.longValue()); wrapped.add(0, null); } catch (Error | RuntimeException exception) { ArrayList wrappedError = wrapError(exception); @@ -1494,13 +1460,11 @@ public void error(Throwable error) { { BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.WebViewHostApi.setWebChromeClient", - getCodec()); + binaryMessenger, "dev.flutter.pigeon.WebViewHostApi.setWebChromeClient", getCodec()); if (api != null) { channel.setMessageHandler( (message, reply) -> { - ArrayList wrapped = new ArrayList<>(); + ArrayList wrapped = new ArrayList(); try { ArrayList args = (ArrayList) message; assert args != null; @@ -1509,9 +1473,7 @@ public void error(Throwable error) { throw new NullPointerException("instanceIdArg unexpectedly null."); } Number clientInstanceIdArg = (Number) args.get(1); - api.setWebChromeClient( - (instanceIdArg == null) ? null : instanceIdArg.longValue(), - (clientInstanceIdArg == null) ? null : clientInstanceIdArg.longValue()); + api.setWebChromeClient((instanceIdArg == null) ? null : instanceIdArg.longValue(), (clientInstanceIdArg == null) ? null : clientInstanceIdArg.longValue()); wrapped.add(0, null); } catch (Error | RuntimeException exception) { ArrayList wrappedError = wrapError(exception); @@ -1526,13 +1488,11 @@ public void error(Throwable error) { { BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.WebViewHostApi.setBackgroundColor", - getCodec()); + binaryMessenger, "dev.flutter.pigeon.WebViewHostApi.setBackgroundColor", getCodec()); if (api != null) { channel.setMessageHandler( (message, reply) -> { - ArrayList wrapped = new ArrayList<>(); + ArrayList wrapped = new ArrayList(); try { ArrayList args = (ArrayList) message; assert args != null; @@ -1544,9 +1504,7 @@ public void error(Throwable error) { if (colorArg == null) { throw new NullPointerException("colorArg unexpectedly null."); } - api.setBackgroundColor( - (instanceIdArg == null) ? null : instanceIdArg.longValue(), - (colorArg == null) ? null : colorArg.longValue()); + api.setBackgroundColor((instanceIdArg == null) ? null : instanceIdArg.longValue(), (colorArg == null) ? null : colorArg.longValue()); wrapped.add(0, null); } catch (Error | RuntimeException exception) { ArrayList wrappedError = wrapError(exception); @@ -1562,6 +1520,7 @@ public void error(Throwable error) { } /** 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); @@ -1592,9 +1551,7 @@ public interface WebSettingsHostApi { static MessageCodec getCodec() { return new StandardMessageCodec(); } - /** - * Sets up an instance of `WebSettingsHostApi` to handle messages through the `binaryMessenger`. - */ + /**Sets up an instance of `WebSettingsHostApi` to handle messages through the `binaryMessenger`. */ static void setup(BinaryMessenger binaryMessenger, WebSettingsHostApi api) { { BasicMessageChannel channel = @@ -1603,7 +1560,7 @@ static void setup(BinaryMessenger binaryMessenger, WebSettingsHostApi api) { if (api != null) { channel.setMessageHandler( (message, reply) -> { - ArrayList wrapped = new ArrayList<>(); + ArrayList wrapped = new ArrayList(); try { ArrayList args = (ArrayList) message; assert args != null; @@ -1615,9 +1572,7 @@ static void setup(BinaryMessenger binaryMessenger, WebSettingsHostApi api) { if (webViewInstanceIdArg == null) { throw new NullPointerException("webViewInstanceIdArg unexpectedly null."); } - api.create( - (instanceIdArg == null) ? null : instanceIdArg.longValue(), - (webViewInstanceIdArg == null) ? null : webViewInstanceIdArg.longValue()); + api.create((instanceIdArg == null) ? null : instanceIdArg.longValue(), (webViewInstanceIdArg == null) ? null : webViewInstanceIdArg.longValue()); wrapped.add(0, null); } catch (Error | RuntimeException exception) { ArrayList wrappedError = wrapError(exception); @@ -1632,13 +1587,11 @@ static void setup(BinaryMessenger binaryMessenger, WebSettingsHostApi api) { { BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.WebSettingsHostApi.setDomStorageEnabled", - getCodec()); + binaryMessenger, "dev.flutter.pigeon.WebSettingsHostApi.setDomStorageEnabled", getCodec()); if (api != null) { channel.setMessageHandler( (message, reply) -> { - ArrayList wrapped = new ArrayList<>(); + ArrayList wrapped = new ArrayList(); try { ArrayList args = (ArrayList) message; assert args != null; @@ -1650,8 +1603,7 @@ static void setup(BinaryMessenger binaryMessenger, WebSettingsHostApi api) { if (flagArg == null) { throw new NullPointerException("flagArg unexpectedly null."); } - api.setDomStorageEnabled( - (instanceIdArg == null) ? null : instanceIdArg.longValue(), flagArg); + api.setDomStorageEnabled((instanceIdArg == null) ? null : instanceIdArg.longValue(), flagArg); wrapped.add(0, null); } catch (Error | RuntimeException exception) { ArrayList wrappedError = wrapError(exception); @@ -1666,13 +1618,11 @@ static void setup(BinaryMessenger binaryMessenger, WebSettingsHostApi api) { { BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.WebSettingsHostApi.setJavaScriptCanOpenWindowsAutomatically", - getCodec()); + binaryMessenger, "dev.flutter.pigeon.WebSettingsHostApi.setJavaScriptCanOpenWindowsAutomatically", getCodec()); if (api != null) { channel.setMessageHandler( (message, reply) -> { - ArrayList wrapped = new ArrayList<>(); + ArrayList wrapped = new ArrayList(); try { ArrayList args = (ArrayList) message; assert args != null; @@ -1684,8 +1634,7 @@ static void setup(BinaryMessenger binaryMessenger, WebSettingsHostApi api) { if (flagArg == null) { throw new NullPointerException("flagArg unexpectedly null."); } - api.setJavaScriptCanOpenWindowsAutomatically( - (instanceIdArg == null) ? null : instanceIdArg.longValue(), flagArg); + api.setJavaScriptCanOpenWindowsAutomatically((instanceIdArg == null) ? null : instanceIdArg.longValue(), flagArg); wrapped.add(0, null); } catch (Error | RuntimeException exception) { ArrayList wrappedError = wrapError(exception); @@ -1700,13 +1649,11 @@ static void setup(BinaryMessenger binaryMessenger, WebSettingsHostApi api) { { BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.WebSettingsHostApi.setSupportMultipleWindows", - getCodec()); + binaryMessenger, "dev.flutter.pigeon.WebSettingsHostApi.setSupportMultipleWindows", getCodec()); if (api != null) { channel.setMessageHandler( (message, reply) -> { - ArrayList wrapped = new ArrayList<>(); + ArrayList wrapped = new ArrayList(); try { ArrayList args = (ArrayList) message; assert args != null; @@ -1718,8 +1665,7 @@ static void setup(BinaryMessenger binaryMessenger, WebSettingsHostApi api) { if (supportArg == null) { throw new NullPointerException("supportArg unexpectedly null."); } - api.setSupportMultipleWindows( - (instanceIdArg == null) ? null : instanceIdArg.longValue(), supportArg); + api.setSupportMultipleWindows((instanceIdArg == null) ? null : instanceIdArg.longValue(), supportArg); wrapped.add(0, null); } catch (Error | RuntimeException exception) { ArrayList wrappedError = wrapError(exception); @@ -1734,13 +1680,11 @@ static void setup(BinaryMessenger binaryMessenger, WebSettingsHostApi api) { { BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.WebSettingsHostApi.setJavaScriptEnabled", - getCodec()); + binaryMessenger, "dev.flutter.pigeon.WebSettingsHostApi.setJavaScriptEnabled", getCodec()); if (api != null) { channel.setMessageHandler( (message, reply) -> { - ArrayList wrapped = new ArrayList<>(); + ArrayList wrapped = new ArrayList(); try { ArrayList args = (ArrayList) message; assert args != null; @@ -1752,8 +1696,7 @@ static void setup(BinaryMessenger binaryMessenger, WebSettingsHostApi api) { if (flagArg == null) { throw new NullPointerException("flagArg unexpectedly null."); } - api.setJavaScriptEnabled( - (instanceIdArg == null) ? null : instanceIdArg.longValue(), flagArg); + api.setJavaScriptEnabled((instanceIdArg == null) ? null : instanceIdArg.longValue(), flagArg); wrapped.add(0, null); } catch (Error | RuntimeException exception) { ArrayList wrappedError = wrapError(exception); @@ -1768,13 +1711,11 @@ static void setup(BinaryMessenger binaryMessenger, WebSettingsHostApi api) { { BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.WebSettingsHostApi.setUserAgentString", - getCodec()); + binaryMessenger, "dev.flutter.pigeon.WebSettingsHostApi.setUserAgentString", getCodec()); if (api != null) { channel.setMessageHandler( (message, reply) -> { - ArrayList wrapped = new ArrayList<>(); + ArrayList wrapped = new ArrayList(); try { ArrayList args = (ArrayList) message; assert args != null; @@ -1783,9 +1724,7 @@ static void setup(BinaryMessenger binaryMessenger, WebSettingsHostApi api) { throw new NullPointerException("instanceIdArg unexpectedly null."); } String userAgentStringArg = (String) args.get(1); - api.setUserAgentString( - (instanceIdArg == null) ? null : instanceIdArg.longValue(), - userAgentStringArg); + api.setUserAgentString((instanceIdArg == null) ? null : instanceIdArg.longValue(), userAgentStringArg); wrapped.add(0, null); } catch (Error | RuntimeException exception) { ArrayList wrappedError = wrapError(exception); @@ -1800,13 +1739,11 @@ static void setup(BinaryMessenger binaryMessenger, WebSettingsHostApi api) { { BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.WebSettingsHostApi.setMediaPlaybackRequiresUserGesture", - getCodec()); + binaryMessenger, "dev.flutter.pigeon.WebSettingsHostApi.setMediaPlaybackRequiresUserGesture", getCodec()); if (api != null) { channel.setMessageHandler( (message, reply) -> { - ArrayList wrapped = new ArrayList<>(); + ArrayList wrapped = new ArrayList(); try { ArrayList args = (ArrayList) message; assert args != null; @@ -1818,8 +1755,7 @@ static void setup(BinaryMessenger binaryMessenger, WebSettingsHostApi api) { if (requireArg == null) { throw new NullPointerException("requireArg unexpectedly null."); } - api.setMediaPlaybackRequiresUserGesture( - (instanceIdArg == null) ? null : instanceIdArg.longValue(), requireArg); + api.setMediaPlaybackRequiresUserGesture((instanceIdArg == null) ? null : instanceIdArg.longValue(), requireArg); wrapped.add(0, null); } catch (Error | RuntimeException exception) { ArrayList wrappedError = wrapError(exception); @@ -1834,13 +1770,11 @@ static void setup(BinaryMessenger binaryMessenger, WebSettingsHostApi api) { { BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.WebSettingsHostApi.setSupportZoom", - getCodec()); + binaryMessenger, "dev.flutter.pigeon.WebSettingsHostApi.setSupportZoom", getCodec()); if (api != null) { channel.setMessageHandler( (message, reply) -> { - ArrayList wrapped = new ArrayList<>(); + ArrayList wrapped = new ArrayList(); try { ArrayList args = (ArrayList) message; assert args != null; @@ -1852,8 +1786,7 @@ static void setup(BinaryMessenger binaryMessenger, WebSettingsHostApi api) { if (supportArg == null) { throw new NullPointerException("supportArg unexpectedly null."); } - api.setSupportZoom( - (instanceIdArg == null) ? null : instanceIdArg.longValue(), supportArg); + api.setSupportZoom((instanceIdArg == null) ? null : instanceIdArg.longValue(), supportArg); wrapped.add(0, null); } catch (Error | RuntimeException exception) { ArrayList wrappedError = wrapError(exception); @@ -1868,13 +1801,11 @@ static void setup(BinaryMessenger binaryMessenger, WebSettingsHostApi api) { { BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.WebSettingsHostApi.setLoadWithOverviewMode", - getCodec()); + binaryMessenger, "dev.flutter.pigeon.WebSettingsHostApi.setLoadWithOverviewMode", getCodec()); if (api != null) { channel.setMessageHandler( (message, reply) -> { - ArrayList wrapped = new ArrayList<>(); + ArrayList wrapped = new ArrayList(); try { ArrayList args = (ArrayList) message; assert args != null; @@ -1886,8 +1817,7 @@ static void setup(BinaryMessenger binaryMessenger, WebSettingsHostApi api) { if (overviewArg == null) { throw new NullPointerException("overviewArg unexpectedly null."); } - api.setLoadWithOverviewMode( - (instanceIdArg == null) ? null : instanceIdArg.longValue(), overviewArg); + api.setLoadWithOverviewMode((instanceIdArg == null) ? null : instanceIdArg.longValue(), overviewArg); wrapped.add(0, null); } catch (Error | RuntimeException exception) { ArrayList wrappedError = wrapError(exception); @@ -1902,13 +1832,11 @@ static void setup(BinaryMessenger binaryMessenger, WebSettingsHostApi api) { { BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.WebSettingsHostApi.setUseWideViewPort", - getCodec()); + binaryMessenger, "dev.flutter.pigeon.WebSettingsHostApi.setUseWideViewPort", getCodec()); if (api != null) { channel.setMessageHandler( (message, reply) -> { - ArrayList wrapped = new ArrayList<>(); + ArrayList wrapped = new ArrayList(); try { ArrayList args = (ArrayList) message; assert args != null; @@ -1920,8 +1848,7 @@ static void setup(BinaryMessenger binaryMessenger, WebSettingsHostApi api) { if (useArg == null) { throw new NullPointerException("useArg unexpectedly null."); } - api.setUseWideViewPort( - (instanceIdArg == null) ? null : instanceIdArg.longValue(), useArg); + api.setUseWideViewPort((instanceIdArg == null) ? null : instanceIdArg.longValue(), useArg); wrapped.add(0, null); } catch (Error | RuntimeException exception) { ArrayList wrappedError = wrapError(exception); @@ -1936,13 +1863,11 @@ static void setup(BinaryMessenger binaryMessenger, WebSettingsHostApi api) { { BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.WebSettingsHostApi.setDisplayZoomControls", - getCodec()); + binaryMessenger, "dev.flutter.pigeon.WebSettingsHostApi.setDisplayZoomControls", getCodec()); if (api != null) { channel.setMessageHandler( (message, reply) -> { - ArrayList wrapped = new ArrayList<>(); + ArrayList wrapped = new ArrayList(); try { ArrayList args = (ArrayList) message; assert args != null; @@ -1954,8 +1879,7 @@ static void setup(BinaryMessenger binaryMessenger, WebSettingsHostApi api) { if (enabledArg == null) { throw new NullPointerException("enabledArg unexpectedly null."); } - api.setDisplayZoomControls( - (instanceIdArg == null) ? null : instanceIdArg.longValue(), enabledArg); + api.setDisplayZoomControls((instanceIdArg == null) ? null : instanceIdArg.longValue(), enabledArg); wrapped.add(0, null); } catch (Error | RuntimeException exception) { ArrayList wrappedError = wrapError(exception); @@ -1970,13 +1894,11 @@ static void setup(BinaryMessenger binaryMessenger, WebSettingsHostApi api) { { BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.WebSettingsHostApi.setBuiltInZoomControls", - getCodec()); + binaryMessenger, "dev.flutter.pigeon.WebSettingsHostApi.setBuiltInZoomControls", getCodec()); if (api != null) { channel.setMessageHandler( (message, reply) -> { - ArrayList wrapped = new ArrayList<>(); + ArrayList wrapped = new ArrayList(); try { ArrayList args = (ArrayList) message; assert args != null; @@ -1988,8 +1910,7 @@ static void setup(BinaryMessenger binaryMessenger, WebSettingsHostApi api) { if (enabledArg == null) { throw new NullPointerException("enabledArg unexpectedly null."); } - api.setBuiltInZoomControls( - (instanceIdArg == null) ? null : instanceIdArg.longValue(), enabledArg); + api.setBuiltInZoomControls((instanceIdArg == null) ? null : instanceIdArg.longValue(), enabledArg); wrapped.add(0, null); } catch (Error | RuntimeException exception) { ArrayList wrappedError = wrapError(exception); @@ -2004,13 +1925,11 @@ static void setup(BinaryMessenger binaryMessenger, WebSettingsHostApi api) { { BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.WebSettingsHostApi.setAllowFileAccess", - getCodec()); + binaryMessenger, "dev.flutter.pigeon.WebSettingsHostApi.setAllowFileAccess", getCodec()); if (api != null) { channel.setMessageHandler( (message, reply) -> { - ArrayList wrapped = new ArrayList<>(); + ArrayList wrapped = new ArrayList(); try { ArrayList args = (ArrayList) message; assert args != null; @@ -2022,8 +1941,7 @@ static void setup(BinaryMessenger binaryMessenger, WebSettingsHostApi api) { if (enabledArg == null) { throw new NullPointerException("enabledArg unexpectedly null."); } - api.setAllowFileAccess( - (instanceIdArg == null) ? null : instanceIdArg.longValue(), enabledArg); + api.setAllowFileAccess((instanceIdArg == null) ? null : instanceIdArg.longValue(), enabledArg); wrapped.add(0, null); } catch (Error | RuntimeException exception) { ArrayList wrappedError = wrapError(exception); @@ -2039,16 +1957,14 @@ static void setup(BinaryMessenger binaryMessenger, WebSettingsHostApi api) { } /** 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 MessageCodec getCodec() { return new StandardMessageCodec(); } - /** - * Sets up an instance of `JavaScriptChannelHostApi` to handle messages through the - * `binaryMessenger`. - */ + /**Sets up an instance of `JavaScriptChannelHostApi` to handle messages through the `binaryMessenger`. */ static void setup(BinaryMessenger binaryMessenger, JavaScriptChannelHostApi api) { { BasicMessageChannel channel = @@ -2057,7 +1973,7 @@ static void setup(BinaryMessenger binaryMessenger, JavaScriptChannelHostApi api) if (api != null) { channel.setMessageHandler( (message, reply) -> { - ArrayList wrapped = new ArrayList<>(); + ArrayList wrapped = new ArrayList(); try { ArrayList args = (ArrayList) message; assert args != null; @@ -2069,8 +1985,7 @@ static void setup(BinaryMessenger binaryMessenger, JavaScriptChannelHostApi api) if (channelNameArg == null) { throw new NullPointerException("channelNameArg unexpectedly null."); } - api.create( - (instanceIdArg == null) ? null : instanceIdArg.longValue(), channelNameArg); + api.create((instanceIdArg == null) ? null : instanceIdArg.longValue(), channelNameArg); wrapped.add(0, null); } catch (Error | RuntimeException exception) { ArrayList wrappedError = wrapError(exception); @@ -2092,43 +2007,34 @@ public JavaScriptChannelFlutterApi(BinaryMessenger argBinaryMessenger) { this.binaryMessenger = argBinaryMessenger; } - public interface Reply { + /** Public interface for sending reply. */ public interface Reply { void reply(T reply); } /** The codec used by JavaScriptChannelFlutterApi. */ static MessageCodec getCodec() { return new StandardMessageCodec(); } - - public void postMessage( - @NonNull Long instanceIdArg, @NonNull String messageArg, Reply callback) { + public void postMessage(@NonNull Long instanceIdArg, @NonNull String messageArg, Reply callback) { BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.JavaScriptChannelFlutterApi.postMessage", - getCodec()); + binaryMessenger, "dev.flutter.pigeon.JavaScriptChannelFlutterApi.postMessage", getCodec()); channel.send( new ArrayList(Arrays.asList(instanceIdArg, messageArg)), - channelReply -> { - callback.reply(null); - }); + 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); + void setSynchronousReturnValueForShouldOverrideUrlLoading(@NonNull Long instanceId, @NonNull Boolean value); /** The codec used by WebViewClientHostApi. */ static MessageCodec getCodec() { return new StandardMessageCodec(); } - /** - * Sets up an instance of `WebViewClientHostApi` to handle messages through the - * `binaryMessenger`. - */ + /**Sets up an instance of `WebViewClientHostApi` to handle messages through the `binaryMessenger`. */ static void setup(BinaryMessenger binaryMessenger, WebViewClientHostApi api) { { BasicMessageChannel channel = @@ -2137,7 +2043,7 @@ static void setup(BinaryMessenger binaryMessenger, WebViewClientHostApi api) { if (api != null) { channel.setMessageHandler( (message, reply) -> { - ArrayList wrapped = new ArrayList<>(); + ArrayList wrapped = new ArrayList(); try { ArrayList args = (ArrayList) message; assert args != null; @@ -2160,13 +2066,11 @@ static void setup(BinaryMessenger binaryMessenger, WebViewClientHostApi api) { { BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.WebViewClientHostApi.setSynchronousReturnValueForShouldOverrideUrlLoading", - getCodec()); + binaryMessenger, "dev.flutter.pigeon.WebViewClientHostApi.setSynchronousReturnValueForShouldOverrideUrlLoading", getCodec()); if (api != null) { channel.setMessageHandler( (message, reply) -> { - ArrayList wrapped = new ArrayList<>(); + ArrayList wrapped = new ArrayList(); try { ArrayList args = (ArrayList) message; assert args != null; @@ -2178,8 +2082,7 @@ static void setup(BinaryMessenger binaryMessenger, WebViewClientHostApi api) { if (valueArg == null) { throw new NullPointerException("valueArg unexpectedly null."); } - api.setSynchronousReturnValueForShouldOverrideUrlLoading( - (instanceIdArg == null) ? null : instanceIdArg.longValue(), valueArg); + api.setSynchronousReturnValueForShouldOverrideUrlLoading((instanceIdArg == null) ? null : instanceIdArg.longValue(), valueArg); wrapped.add(0, null); } catch (Error | RuntimeException exception) { ArrayList wrappedError = wrapError(exception); @@ -2204,10 +2107,8 @@ 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)); - default: return super.readValueOfType(type, buffer); } @@ -2235,136 +2136,72 @@ public WebViewClientFlutterApi(BinaryMessenger argBinaryMessenger) { this.binaryMessenger = argBinaryMessenger; } - public interface Reply { + /** Public interface for sending reply. */ public interface Reply { void reply(T reply); } /** The codec used by WebViewClientFlutterApi. */ static MessageCodec getCodec() { return WebViewClientFlutterApiCodec.INSTANCE; } - - public void onPageStarted( - @NonNull Long instanceIdArg, - @NonNull Long webViewInstanceIdArg, - @NonNull String urlArg, - Reply callback) { + public void onPageStarted(@NonNull Long instanceIdArg, @NonNull Long webViewInstanceIdArg, @NonNull String urlArg, Reply callback) { BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.WebViewClientFlutterApi.onPageStarted", - getCodec()); + binaryMessenger, "dev.flutter.pigeon.WebViewClientFlutterApi.onPageStarted", getCodec()); channel.send( new ArrayList(Arrays.asList(instanceIdArg, webViewInstanceIdArg, urlArg)), - channelReply -> { - callback.reply(null); - }); + channelReply -> callback.reply(null)); } - - public void onPageFinished( - @NonNull Long instanceIdArg, - @NonNull Long webViewInstanceIdArg, - @NonNull String urlArg, - Reply callback) { + public void onPageFinished(@NonNull Long instanceIdArg, @NonNull Long webViewInstanceIdArg, @NonNull String urlArg, Reply callback) { BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.WebViewClientFlutterApi.onPageFinished", - getCodec()); + binaryMessenger, "dev.flutter.pigeon.WebViewClientFlutterApi.onPageFinished", getCodec()); channel.send( new ArrayList(Arrays.asList(instanceIdArg, webViewInstanceIdArg, urlArg)), - channelReply -> { - callback.reply(null); - }); + channelReply -> callback.reply(null)); } - - public void onReceivedRequestError( - @NonNull Long instanceIdArg, - @NonNull Long webViewInstanceIdArg, - @NonNull WebResourceRequestData requestArg, - @NonNull WebResourceErrorData errorArg, - Reply callback) { + public void onReceivedRequestError(@NonNull Long instanceIdArg, @NonNull Long webViewInstanceIdArg, @NonNull WebResourceRequestData requestArg, @NonNull WebResourceErrorData errorArg, Reply callback) { BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.WebViewClientFlutterApi.onReceivedRequestError", - getCodec()); + binaryMessenger, "dev.flutter.pigeon.WebViewClientFlutterApi.onReceivedRequestError", getCodec()); channel.send( - new ArrayList( - Arrays.asList(instanceIdArg, webViewInstanceIdArg, requestArg, errorArg)), - channelReply -> { - callback.reply(null); - }); + 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, - Reply callback) { + public void onReceivedError(@NonNull Long instanceIdArg, @NonNull Long webViewInstanceIdArg, @NonNull Long errorCodeArg, @NonNull String descriptionArg, @NonNull String failingUrlArg, Reply callback) { BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.WebViewClientFlutterApi.onReceivedError", - getCodec()); + binaryMessenger, "dev.flutter.pigeon.WebViewClientFlutterApi.onReceivedError", getCodec()); channel.send( - new ArrayList( - Arrays.asList( - instanceIdArg, - webViewInstanceIdArg, - errorCodeArg, - descriptionArg, - failingUrlArg)), - channelReply -> { - callback.reply(null); - }); + 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, - Reply callback) { + public void requestLoading(@NonNull Long instanceIdArg, @NonNull Long webViewInstanceIdArg, @NonNull WebResourceRequestData requestArg, Reply callback) { BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.WebViewClientFlutterApi.requestLoading", - getCodec()); + binaryMessenger, "dev.flutter.pigeon.WebViewClientFlutterApi.requestLoading", getCodec()); channel.send( new ArrayList(Arrays.asList(instanceIdArg, webViewInstanceIdArg, requestArg)), - channelReply -> { - callback.reply(null); - }); + channelReply -> callback.reply(null)); } - - public void urlLoading( - @NonNull Long instanceIdArg, - @NonNull Long webViewInstanceIdArg, - @NonNull String urlArg, - Reply callback) { + public void urlLoading(@NonNull Long instanceIdArg, @NonNull Long webViewInstanceIdArg, @NonNull String urlArg, Reply callback) { BasicMessageChannel channel = new BasicMessageChannel<>( binaryMessenger, "dev.flutter.pigeon.WebViewClientFlutterApi.urlLoading", getCodec()); channel.send( new ArrayList(Arrays.asList(instanceIdArg, webViewInstanceIdArg, urlArg)), - channelReply -> { - callback.reply(null); - }); + 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 MessageCodec getCodec() { return new StandardMessageCodec(); } - /** - * Sets up an instance of `DownloadListenerHostApi` to handle messages through the - * `binaryMessenger`. - */ + /**Sets up an instance of `DownloadListenerHostApi` to handle messages through the `binaryMessenger`. */ static void setup(BinaryMessenger binaryMessenger, DownloadListenerHostApi api) { { BasicMessageChannel channel = @@ -2373,7 +2210,7 @@ static void setup(BinaryMessenger binaryMessenger, DownloadListenerHostApi api) if (api != null) { channel.setMessageHandler( (message, reply) -> { - ArrayList wrapped = new ArrayList<>(); + ArrayList wrapped = new ArrayList(); try { ArrayList args = (ArrayList) message; assert args != null; @@ -2403,56 +2240,34 @@ public DownloadListenerFlutterApi(BinaryMessenger argBinaryMessenger) { this.binaryMessenger = argBinaryMessenger; } - public interface Reply { + /** Public interface for sending reply. */ public interface Reply { void reply(T reply); } /** The codec used by DownloadListenerFlutterApi. */ static 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, - Reply callback) { + public void onDownloadStart(@NonNull Long instanceIdArg, @NonNull String urlArg, @NonNull String userAgentArg, @NonNull String contentDispositionArg, @NonNull String mimetypeArg, @NonNull Long contentLengthArg, Reply callback) { BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.DownloadListenerFlutterApi.onDownloadStart", - getCodec()); + binaryMessenger, "dev.flutter.pigeon.DownloadListenerFlutterApi.onDownloadStart", getCodec()); channel.send( - new ArrayList( - Arrays.asList( - instanceIdArg, - urlArg, - userAgentArg, - contentDispositionArg, - mimetypeArg, - contentLengthArg)), - channelReply -> { - callback.reply(null); - }); + 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 setSynchronousReturnValueForOnShowFileChooser(@NonNull Long instanceId, @NonNull Boolean value); /** The codec used by WebChromeClientHostApi. */ static MessageCodec getCodec() { return new StandardMessageCodec(); } - /** - * Sets up an instance of `WebChromeClientHostApi` to handle messages through the - * `binaryMessenger`. - */ + /**Sets up an instance of `WebChromeClientHostApi` to handle messages through the `binaryMessenger`. */ static void setup(BinaryMessenger binaryMessenger, WebChromeClientHostApi api) { { BasicMessageChannel channel = @@ -2461,7 +2276,7 @@ static void setup(BinaryMessenger binaryMessenger, WebChromeClientHostApi api) { if (api != null) { channel.setMessageHandler( (message, reply) -> { - ArrayList wrapped = new ArrayList<>(); + ArrayList wrapped = new ArrayList(); try { ArrayList args = (ArrayList) message; assert args != null; @@ -2484,13 +2299,11 @@ static void setup(BinaryMessenger binaryMessenger, WebChromeClientHostApi api) { { BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.WebChromeClientHostApi.setSynchronousReturnValueForOnShowFileChooser", - getCodec()); + binaryMessenger, "dev.flutter.pigeon.WebChromeClientHostApi.setSynchronousReturnValueForOnShowFileChooser", getCodec()); if (api != null) { channel.setMessageHandler( (message, reply) -> { - ArrayList wrapped = new ArrayList<>(); + ArrayList wrapped = new ArrayList(); try { ArrayList args = (ArrayList) message; assert args != null; @@ -2502,8 +2315,7 @@ static void setup(BinaryMessenger binaryMessenger, WebChromeClientHostApi api) { if (valueArg == null) { throw new NullPointerException("valueArg unexpectedly null."); } - api.setSynchronousReturnValueForOnShowFileChooser( - (instanceIdArg == null) ? null : instanceIdArg.longValue(), valueArg); + api.setSynchronousReturnValueForOnShowFileChooser((instanceIdArg == null) ? null : instanceIdArg.longValue(), valueArg); wrapped.add(0, null); } catch (Error | RuntimeException exception) { ArrayList wrappedError = wrapError(exception); @@ -2519,20 +2331,18 @@ static void setup(BinaryMessenger binaryMessenger, WebChromeClientHostApi api) { } /** Generated interface from Pigeon that represents a handler of messages from Flutter. */ public interface FlutterAssetManagerHostApi { - @NonNull + + @NonNull List list(@NonNull String path); - @NonNull + @NonNull String getAssetFilePathByName(@NonNull String name); /** The codec used by FlutterAssetManagerHostApi. */ static MessageCodec getCodec() { return new StandardMessageCodec(); } - /** - * Sets up an instance of `FlutterAssetManagerHostApi` to handle messages through the - * `binaryMessenger`. - */ + /**Sets up an instance of `FlutterAssetManagerHostApi` to handle messages through the `binaryMessenger`. */ static void setup(BinaryMessenger binaryMessenger, FlutterAssetManagerHostApi api) { { BasicMessageChannel channel = @@ -2541,7 +2351,7 @@ static void setup(BinaryMessenger binaryMessenger, FlutterAssetManagerHostApi ap if (api != null) { channel.setMessageHandler( (message, reply) -> { - ArrayList wrapped = new ArrayList<>(); + ArrayList wrapped = new ArrayList(); try { ArrayList args = (ArrayList) message; assert args != null; @@ -2564,13 +2374,11 @@ static void setup(BinaryMessenger binaryMessenger, FlutterAssetManagerHostApi ap { BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.FlutterAssetManagerHostApi.getAssetFilePathByName", - getCodec()); + binaryMessenger, "dev.flutter.pigeon.FlutterAssetManagerHostApi.getAssetFilePathByName", getCodec()); if (api != null) { channel.setMessageHandler( (message, reply) -> { - ArrayList wrapped = new ArrayList<>(); + ArrayList wrapped = new ArrayList(); try { ArrayList args = (ArrayList) message; assert args != null; @@ -2600,44 +2408,27 @@ public WebChromeClientFlutterApi(BinaryMessenger argBinaryMessenger) { this.binaryMessenger = argBinaryMessenger; } - public interface Reply { + /** Public interface for sending reply. */ public interface Reply { void reply(T reply); } /** The codec used by WebChromeClientFlutterApi. */ static MessageCodec getCodec() { return new StandardMessageCodec(); } - - public void onProgressChanged( - @NonNull Long instanceIdArg, - @NonNull Long webViewInstanceIdArg, - @NonNull Long progressArg, - Reply callback) { + public void onProgressChanged(@NonNull Long instanceIdArg, @NonNull Long webViewInstanceIdArg, @NonNull Long progressArg, Reply callback) { BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.WebChromeClientFlutterApi.onProgressChanged", - getCodec()); + binaryMessenger, "dev.flutter.pigeon.WebChromeClientFlutterApi.onProgressChanged", getCodec()); channel.send( new ArrayList(Arrays.asList(instanceIdArg, webViewInstanceIdArg, progressArg)), - channelReply -> { - callback.reply(null); - }); + channelReply -> callback.reply(null)); } - - public void onShowFileChooser( - @NonNull Long instanceIdArg, - @NonNull Long webViewInstanceIdArg, - @NonNull Long paramsInstanceIdArg, - Reply> callback) { + public void onShowFileChooser(@NonNull Long instanceIdArg, @NonNull Long webViewInstanceIdArg, @NonNull Long paramsInstanceIdArg, Reply> callback) { BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, - "dev.flutter.pigeon.WebChromeClientFlutterApi.onShowFileChooser", - getCodec()); + binaryMessenger, "dev.flutter.pigeon.WebChromeClientFlutterApi.onShowFileChooser", getCodec()); channel.send( - new ArrayList( - Arrays.asList(instanceIdArg, webViewInstanceIdArg, paramsInstanceIdArg)), + new ArrayList(Arrays.asList(instanceIdArg, webViewInstanceIdArg, paramsInstanceIdArg)), channelReply -> { @SuppressWarnings("ConstantConditions") List output = (List) channelReply; @@ -2647,6 +2438,7 @@ public void onShowFileChooser( } /** 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); @@ -2655,9 +2447,7 @@ public interface WebStorageHostApi { static MessageCodec getCodec() { return new StandardMessageCodec(); } - /** - * Sets up an instance of `WebStorageHostApi` to handle messages through the `binaryMessenger`. - */ + /**Sets up an instance of `WebStorageHostApi` to handle messages through the `binaryMessenger`. */ static void setup(BinaryMessenger binaryMessenger, WebStorageHostApi api) { { BasicMessageChannel channel = @@ -2666,7 +2456,7 @@ static void setup(BinaryMessenger binaryMessenger, WebStorageHostApi api) { if (api != null) { channel.setMessageHandler( (message, reply) -> { - ArrayList wrapped = new ArrayList<>(); + ArrayList wrapped = new ArrayList(); try { ArrayList args = (ArrayList) message; assert args != null; @@ -2693,7 +2483,7 @@ static void setup(BinaryMessenger binaryMessenger, WebStorageHostApi api) { if (api != null) { channel.setMessageHandler( (message, reply) -> { - ArrayList wrapped = new ArrayList<>(); + ArrayList wrapped = new ArrayList(); try { ArrayList args = (ArrayList) message; assert args != null; @@ -2717,8 +2507,7 @@ static void setup(BinaryMessenger binaryMessenger, WebStorageHostApi api) { } private static class FileChooserParamsFlutterApiCodec extends StandardMessageCodec { - public static final FileChooserParamsFlutterApiCodec INSTANCE = - new FileChooserParamsFlutterApiCodec(); + public static final FileChooserParamsFlutterApiCodec INSTANCE = new FileChooserParamsFlutterApiCodec(); private FileChooserParamsFlutterApiCodec() {} @@ -2727,7 +2516,6 @@ protected Object readValueOfType(byte type, @NonNull ByteBuffer buffer) { switch (type) { case (byte) 128: return FileChooserModeEnumData.fromList((ArrayList) readValue(buffer)); - default: return super.readValueOfType(type, buffer); } @@ -2747,10 +2535,9 @@ protected void writeValue(@NonNull ByteArrayOutputStream stream, Object value) { /** * Handles callbacks methods for the native Java FileChooserParams class. * - *

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

Generated class from Pigeon that represents Flutter messages that can be called from Java. + * Generated class from Pigeon that represents Flutter messages that can be called from Java. */ public static class FileChooserParamsFlutterApi { private final BinaryMessenger binaryMessenger; @@ -2759,41 +2546,20 @@ public FileChooserParamsFlutterApi(BinaryMessenger argBinaryMessenger) { this.binaryMessenger = argBinaryMessenger; } - public interface Reply { + /** Public interface for sending reply. */ public interface Reply { void reply(T reply); } /** The codec used by FileChooserParamsFlutterApi. */ static MessageCodec getCodec() { return FileChooserParamsFlutterApiCodec.INSTANCE; } - - public void create( - @NonNull Long instanceIdArg, - @NonNull Boolean isCaptureEnabledArg, - @NonNull List acceptTypesArg, - @NonNull FileChooserModeEnumData modeArg, - @Nullable String filenameHintArg, - Reply callback) { + public void create(@NonNull Long instanceIdArg, @NonNull Boolean isCaptureEnabledArg, @NonNull List acceptTypesArg, @NonNull FileChooserModeEnumData modeArg, @Nullable String filenameHintArg, Reply callback) { BasicMessageChannel channel = new BasicMessageChannel<>( binaryMessenger, "dev.flutter.pigeon.FileChooserParamsFlutterApi.create", getCodec()); channel.send( - new ArrayList( - Arrays.asList( - instanceIdArg, isCaptureEnabledArg, acceptTypesArg, modeArg, filenameHintArg)), - channelReply -> { - callback.reply(null); - }); + new ArrayList(Arrays.asList(instanceIdArg, isCaptureEnabledArg, acceptTypesArg, modeArg, filenameHintArg)), + channelReply -> callback.reply(null)); } } - - @NonNull - private static ArrayList wrapError(@NonNull Throwable exception) { - ArrayList errorList = new ArrayList<>(3); - errorList.add(exception.toString()); - errorList.add(exception.getClass().getSimpleName()); - errorList.add( - "Cause: " + exception.getCause() + ", Stacktrace: " + Log.getStackTraceString(exception)); - return errorList; - } } 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 index 1ab30a9ea1f..0d97f9096b8 100644 --- a/packages/webview_flutter/webview_flutter_android/lib/src/android_webview.dart +++ b/packages/webview_flutter/webview_flutter_android/lib/src/android_webview.dart @@ -14,7 +14,8 @@ import 'dart:ui'; import 'package:flutter/foundation.dart'; import 'package:flutter/services.dart' show BinaryMessenger; -import 'package:flutter/widgets.dart' show AndroidViewSurface; +import 'package:flutter/widgets.dart' + show AndroidViewSurface, WidgetsFlutterBinding; import 'android_webview.g.dart'; import 'android_webview_api_impls.dart'; @@ -25,25 +26,36 @@ export 'android_webview_api_impls.dart' show FileChooserMode; /// Root of the Java class hierarchy. /// /// See https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html. -class JavaObject with Copyable { +@immutable +class JavaObject { /// Constructs a [JavaObject] without creating the associated Java object. /// /// This should only be used by subclasses created by this library or to /// create copies. JavaObject.detached({ - BinaryMessenger? binaryMessenger, - InstanceManager? instanceManager, + required BinaryMessenger? binaryMessenger, + required InstanceManager? instanceManager, }) : _api = JavaObjectHostApiImpl( binaryMessenger: binaryMessenger, instanceManager: instanceManager, ); + static InstanceManager? _globalInstanceManager; + /// Global instance of [InstanceManager]. - static final InstanceManager globalInstanceManager = InstanceManager( - onWeakReferenceRemoved: (int identifier) { - JavaObjectHostApiImpl().dispose(identifier); - }, - ); + static InstanceManager get globalInstanceManager { + if (_globalInstanceManager == null) { + WidgetsFlutterBinding.ensureInitialized(); + // Clears the native `InstanceManager` on initial use of the Dart one. + InstanceManagerHostApi().clear(); + _globalInstanceManager = InstanceManager( + onWeakReferenceRemoved: (int identifier) { + JavaObjectHostApiImpl().dispose(identifier); + }, + ); + } + return _globalInstanceManager!; + } /// Pigeon Host Api implementation for [JavaObject]. final JavaObjectHostApiImpl _api; @@ -52,11 +64,6 @@ class JavaObject with Copyable { static void dispose(JavaObject instance) { instance._api.instanceManager.removeWeakReference(instance); } - - @override - JavaObject copy() { - return JavaObject.detached(); - } } /// An Android View that displays web pages. @@ -78,13 +85,18 @@ class JavaObject with Copyable { /// [Web-based content](https://developer.android.com/guide/webapps). /// /// When a [WebView] is no longer needed [release] must be called. +@immutable class WebView extends JavaObject { /// Constructs a new WebView. /// /// Due to changes in Flutter 3.0 the [useHybridComposition] doesn't have /// any effect and should not be exposed publicly. More info here: /// https://github.com/flutter/flutter/issues/108106 - WebView({this.useHybridComposition = false}) : super.detached() { + WebView({ + this.useHybridComposition = false, + @visibleForTesting super.binaryMessenger, + @visibleForTesting super.instanceManager, + }) : super.detached() { api.createFromInstance(this); } @@ -92,7 +104,12 @@ class WebView extends JavaObject { /// /// This should only be used by subclasses created by this library or to /// create copies. - WebView.detached({this.useHybridComposition = false}) : super.detached(); + @protected + WebView.detached({ + this.useHybridComposition = false, + required super.binaryMessenger, + required super.instanceManager, + }) : super.detached(); /// Pigeon Host Api implementation for [WebView]. @visibleForTesting @@ -396,11 +413,6 @@ class WebView extends JavaObject { Future setBackgroundColor(Color color) { return api.setBackgroundColorFromInstance(this, color.value); } - - @override - WebView copy() { - return WebView.detached(useHybridComposition: useHybridComposition); - } } /// Manages cookies globally for all webviews. @@ -453,13 +465,15 @@ class CookieManager { /// 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. +@immutable 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) : super.detached() { + WebSettings(WebView webView, {super.binaryMessenger, super.instanceManager}) + : super.detached() { api.createFromInstance(this, webView); } @@ -467,7 +481,8 @@ class WebSettings extends JavaObject { /// /// This should only be used by subclasses created by this library or to /// create copies. - WebSettings.detached() : super.detached(); + WebSettings.detached({required super.binaryMessenger, required super.instanceManager}) + : super.detached(); /// Pigeon Host Api implementation for [WebSettings]. @visibleForTesting @@ -590,21 +605,18 @@ class WebSettings extends JavaObject { Future setAllowFileAccess(bool enabled) { return api.setAllowFileAccessFromInstance(this, enabled); } - - @override - WebSettings copy() { - return WebSettings.detached(); - } } /// Exposes a channel to receive calls from javaScript. /// /// See [WebView.addJavaScriptChannel]. +@immutable class JavaScriptChannel extends JavaObject { /// Constructs a [JavaScriptChannel]. JavaScriptChannel( this.channelName, { required this.postMessage, + super.binaryMessenger, super.instanceManager }) : super.detached() { AndroidWebViewFlutterApis.instance.ensureSetUp(); api.createFromInstance(this); @@ -629,14 +641,10 @@ class JavaScriptChannel extends JavaObject { /// 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); - } } /// Receive various notifications and requests for [WebView]. +@immutable class WebViewClient extends JavaObject { /// Constructs a [WebViewClient]. WebViewClient({ @@ -821,22 +829,11 @@ class WebViewClient extends JavaObject { ) { return api.setShouldOverrideUrlLoadingReturnValueFromInstance(this, value); } - - @override - WebViewClient copy() { - return WebViewClient.detached( - onPageStarted: onPageStarted, - onPageFinished: onPageFinished, - onReceivedRequestError: onReceivedRequestError, - onReceivedError: onReceivedError, - requestLoading: requestLoading, - urlLoading: urlLoading, - ); - } } /// The interface to be used when content can not be handled by the rendering /// engine for [WebView], and should be downloaded instead. +@immutable class DownloadListener extends JavaObject { /// Constructs a [DownloadListener]. DownloadListener({required this.onDownloadStart}) : super.detached() { @@ -863,14 +860,10 @@ class DownloadListener extends JavaObject { String mimetype, int contentLength, ) onDownloadStart; - - @override - DownloadListener copy() { - return DownloadListener.detached(onDownloadStart: onDownloadStart); - } } /// Handles JavaScript dialogs, favicons, titles, and the progress for [WebView]. +@immutable class WebChromeClient extends JavaObject { /// Constructs a [WebChromeClient]. WebChromeClient({this.onProgressChanged, this.onShowFileChooser}) @@ -937,19 +930,12 @@ class WebChromeClient extends JavaObject { value, ); } - - @override - WebChromeClient copy() { - return WebChromeClient.detached( - onProgressChanged: onProgressChanged, - onShowFileChooser: onShowFileChooser, - ); - } } /// Parameters received when a [WebChromeClient] should show a file chooser. /// /// See https://developer.android.com/reference/android/webkit/WebChromeClient.FileChooserParams. +@immutable class FileChooserParams extends JavaObject { /// Constructs a [FileChooserParams] without creating the associated Java /// object. @@ -976,16 +962,6 @@ class FileChooserParams extends JavaObject { /// 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, - ); - } } /// Encompasses parameters to the [WebViewClient.requestLoading] method. @@ -1061,6 +1037,7 @@ class FlutterAssetManager { /// Manages the JavaScript storage APIs provided by the [WebView]. /// /// Wraps [WebStorage](https://developer.android.com/reference/android/webkit/WebStorage). +@immutable class WebStorage extends JavaObject { /// Constructs a [WebStorage]. /// @@ -1089,9 +1066,4 @@ class WebStorage extends JavaObject { Future deleteAllData() { return api.deleteAllDataFromInstance(this); } - - @override - WebStorage copy() { - return WebStorage.detached(); - } } 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 index d3c306a1023..41bbf39c044 100644 --- 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 @@ -1,9 +1,10 @@ // 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 (v4.2.14), do not edit directly. +// Autogenerated from Pigeon (v9.0.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 + import 'dart:async'; import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List; @@ -151,6 +152,42 @@ class WebViewPoint { } } +/// 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.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`. @@ -297,7 +334,6 @@ class _WebViewHostApiCodec extends StandardMessageCodec { switch (type) { case 128: return WebViewPoint.decode(readValue(buffer)!); - default: return super.readValueOfType(type, buffer); } @@ -1394,10 +1430,8 @@ class _WebViewClientFlutterApiCodec extends StandardMessageCodec { switch (type) { case 128: return WebResourceErrorData.decode(readValue(buffer)!); - case 129: return WebResourceRequestData.decode(readValue(buffer)!); - default: return super.readValueOfType(type, buffer); } @@ -1935,7 +1969,6 @@ class _FileChooserParamsFlutterApiCodec extends StandardMessageCodec { switch (type) { case 128: return FileChooserModeEnumData.decode(readValue(buffer)!); - default: return super.readValueOfType(type, buffer); } 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 index 127a2fa58ef..24aabb2aac2 100644 --- 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 @@ -147,7 +147,12 @@ class WebViewHostApiImpl extends WebViewHostApi { /// Helper method to convert instances ids to objects. Future createFromInstance(WebView instance) { return create( - instanceManager.addDartCreatedInstance(instance), + instanceManager.addDartCreatedInstance( + instance, + onCopy: (WebView original) => WebView.detached( + useHybridComposition: original.useHybridComposition, + ), + ), instance.useHybridComposition, ); } @@ -360,7 +365,12 @@ class WebSettingsHostApiImpl extends WebSettingsHostApi { /// Helper method to convert instances ids to objects. Future createFromInstance(WebSettings instance, WebView webView) { return create( - instanceManager.addDartCreatedInstance(instance), + instanceManager.addDartCreatedInstance( + instance, + onCopy: (WebSettings original) { + return WebSettings.detached(); + }, + ), instanceManager.getIdentifier(webView)!, ); } @@ -501,7 +511,13 @@ class JavaScriptChannelHostApiImpl extends JavaScriptChannelHostApi { /// Helper method to convert instances ids to objects. Future createFromInstance(JavaScriptChannel instance) async { if (instanceManager.getIdentifier(instance) == null) { - final int identifier = instanceManager.addDartCreatedInstance(instance); + final int identifier = instanceManager.addDartCreatedInstance( + instance, + onCopy: (JavaScriptChannel original) => JavaScriptChannel.detached( + original.channelName, + postMessage: original.postMessage, + ), + ); await create( identifier, instance.channelName, @@ -545,7 +561,10 @@ class WebViewClientHostApiImpl extends WebViewClientHostApi { /// Helper method to convert instances ids to objects. Future createFromInstance(WebViewClient instance) async { if (instanceManager.getIdentifier(instance) == null) { - final int identifier = instanceManager.addDartCreatedInstance(instance); + final int identifier = instanceManager.addDartCreatedInstance( + instance, + onCopy: (WebViewClient original) => WebViewClient.detached(), + ); return create(identifier); } } @@ -732,7 +751,12 @@ class DownloadListenerHostApiImpl extends DownloadListenerHostApi { /// Helper method to convert instances ids to objects. Future createFromInstance(DownloadListener instance) async { if (instanceManager.getIdentifier(instance) == null) { - final int identifier = instanceManager.addDartCreatedInstance(instance); + final int identifier = instanceManager.addDartCreatedInstance( + instance, + onCopy: (DownloadListener original) => DownloadListener.detached( + onDownloadStart: original.onDownloadStart, + ), + ); return create(identifier); } } @@ -786,7 +810,10 @@ class WebChromeClientHostApiImpl extends WebChromeClientHostApi { /// Helper method to convert instances ids to objects. Future createFromInstance(WebChromeClient instance) async { if (instanceManager.getIdentifier(instance) == null) { - final int identifier = instanceManager.addDartCreatedInstance(instance); + final int identifier = instanceManager.addDartCreatedInstance( + instance, + onCopy: (WebChromeClient original) => WebChromeClient.detached(), + ); return create(identifier); } } @@ -866,7 +893,10 @@ class WebStorageHostApiImpl extends WebStorageHostApi { /// Helper method to convert instances ids to objects. Future createFromInstance(WebStorage instance) async { if (instanceManager.getIdentifier(instance) == null) { - final int identifier = instanceManager.addDartCreatedInstance(instance); + final int identifier = instanceManager.addDartCreatedInstance( + instance, + onCopy: (WebStorage original) => WebStorage.detached(), + ); return create(identifier); } } @@ -880,8 +910,16 @@ class WebStorageHostApiImpl extends WebStorageHostApi { /// Flutter api implementation for [FileChooserParams]. class FileChooserParamsFlutterApiImpl extends FileChooserParamsFlutterApi { /// Constructs a [FileChooserParamsFlutterApiImpl]. - FileChooserParamsFlutterApiImpl({InstanceManager? instanceManager}) - : instanceManager = instanceManager ?? JavaObject.globalInstanceManager; + 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; @@ -902,6 +940,14 @@ class FileChooserParamsFlutterApiImpl extends FileChooserParamsFlutterApi { filenameHint: filenameHint, ), instanceId, + onCopy: (FileChooserParams original) => FileChooserParams.detached( + isCaptureEnabled: isCaptureEnabled, + acceptTypes: acceptTypes.cast(), + mode: mode.value, + filenameHint: filenameHint, + binaryMessenger: binaryMessenger, + instanceManager: instanceManager, + ), ); } } 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 index 5892823aabd..ac9856a6367 100644 --- a/packages/webview_flutter/webview_flutter_android/lib/src/instance_manager.dart +++ b/packages/webview_flutter/webview_flutter_android/lib/src/instance_manager.dart @@ -2,27 +2,6 @@ // 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. -// TODO(bparrishMines): Uncomment annotation once -// https://github.com/flutter/plugins/pull/5831 lands or when making a breaking -// change for https://github.com/flutter/flutter/issues/107199. -// @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. /// @@ -63,9 +42,10 @@ class InstanceManager { // by calling instanceManager.getIdentifier() inside of `==` while this was a // HashMap). final Expando _identifiers = Expando(); - final Map> _weakInstances = - >{}; - final Map _strongInstances = {}; + final Map> _weakInstances = + >{}; + final Map _strongInstances = {}; + final Map _copyCallbacks = {}; late final Finalizer _finalizer; int _nextIdentifier = 0; @@ -81,11 +61,12 @@ class InstanceManager { /// Throws assertion error if the instance has already been added. /// /// Returns the randomly generated id of the [instance] added. - int addDartCreatedInstance(Copyable instance) { - assert(getIdentifier(instance) == null); - + int addDartCreatedInstance( + T instance, { + required T Function(T original) onCopy, + }) { final int identifier = _nextUniqueIdentifier(); - _addInstanceWithIdentifier(instance, identifier); + _addInstanceWithIdentifier(instance, identifier, onCopy: onCopy); return identifier; } @@ -97,7 +78,7 @@ class InstanceManager { /// /// This does not remove the the strong referenced instance associated with /// [instance]. This can be done with [remove]. - int? removeWeakReference(Copyable instance) { + int? removeWeakReference(Object instance) { final int? identifier = getIdentifier(instance); if (identifier == null) { return null; @@ -119,7 +100,8 @@ class InstanceManager { /// /// This does not remove the the weak referenced instance associtated with /// [identifier]. This can be done with [removeWeakReference]. - T? remove(int identifier) { + T? remove(int identifier) { + _copyCallbacks.remove(identifier); return _strongInstances.remove(identifier) as T?; } @@ -135,26 +117,31 @@ class InstanceManager { /// /// 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; + T? getInstanceWithWeakReference(int identifier) { + final T? weakInstance = _weakInstances[identifier]?.target as T?; if (weakInstance == null) { - final Copyable? strongInstance = _strongInstances[identifier]; + final T? strongInstance = _strongInstances[identifier] as T?; if (strongInstance != null) { - final Copyable copy = strongInstance.copy(); + // This cast is safe since it matches the argument type for + // _addInstanceWithIdentifier, which is the only place _copyCallbacks + // is populated. + final T Function(T) copyCallback = + _copyCallbacks[identifier]! as T Function(T); + final T copy = copyCallback(strongInstance); _identifiers[copy] = identifier; - _weakInstances[identifier] = WeakReference(copy); + _weakInstances[identifier] = WeakReference(copy); _finalizer.attach(copy, identifier, detach: copy); - return copy as T; + return copy; } - return strongInstance as T?; + return strongInstance; } - return weakInstance as T; + return weakInstance; } /// Retrieves the identifier associated with instance. - int? getIdentifier(Copyable instance) { + int? getIdentifier(Object instance) { return _identifiers[instance]; } @@ -167,21 +154,30 @@ class InstanceManager { /// added. /// /// Returns unique identifier of the [instance] added. - void addHostCreatedInstance(Copyable instance, int identifier) { + void addHostCreatedInstance( + T instance, + int identifier, { + required T Function(T original) onCopy, + }) { + _addInstanceWithIdentifier(instance, identifier, onCopy: onCopy); + } + + void _addInstanceWithIdentifier( + T instance, + int identifier, { + required T Function(T original) onCopy, + }) { assert(!containsIdentifier(identifier)); assert(getIdentifier(instance) == null); assert(identifier >= 0); - _addInstanceWithIdentifier(instance, identifier); - } - - void _addInstanceWithIdentifier(Copyable instance, int identifier) { _identifiers[instance] = identifier; - _weakInstances[identifier] = WeakReference(instance); + _weakInstances[identifier] = WeakReference(instance); _finalizer.attach(instance, identifier, detach: instance); - final Copyable copy = instance.copy(); + final Object copy = onCopy(instance); _identifiers[copy] = identifier; _strongInstances[identifier] = copy; + _copyCallbacks[identifier] = onCopy; } /// Whether this manager contains the given [identifier]. diff --git a/packages/webview_flutter/webview_flutter_android/pigeons/android_webview.dart b/packages/webview_flutter/webview_flutter_android/pigeons/android_webview.dart index 7f4d362c927..28ac47c6d60 100644 --- a/packages/webview_flutter/webview_flutter_android/pigeons/android_webview.dart +++ b/packages/webview_flutter/webview_flutter_android/pigeons/android_webview.dart @@ -27,6 +27,15 @@ import 'package:pigeon/pigeon.dart'; ), ) +/// 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. diff --git a/packages/webview_flutter/webview_flutter_android/pubspec.yaml b/packages/webview_flutter/webview_flutter_android/pubspec.yaml index ac8971006ba..a14c5fc2c9c 100644 --- a/packages/webview_flutter/webview_flutter_android/pubspec.yaml +++ b/packages/webview_flutter/webview_flutter_android/pubspec.yaml @@ -29,4 +29,4 @@ dev_dependencies: flutter_test: sdk: flutter mockito: ^5.3.2 - pigeon: ^4.2.14 + pigeon: ^9.0.0 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 index 56ba79a6662..f2a07af1089 100644 --- 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 @@ -1,7 +1,7 @@ // 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 (v4.2.14), do not edit directly. +// Autogenerated from Pigeon (v9.0.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, unnecessary_import // ignore_for_file: avoid_relative_lib_imports @@ -13,6 +13,33 @@ 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 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.InstanceManagerHostApi.clear', codec, + binaryMessenger: binaryMessenger); + if (api == null) { + channel.setMockMessageHandler(null); + } else { + channel.setMockMessageHandler((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`. @@ -23,8 +50,7 @@ abstract class TestJavaObjectHostApi { void dispose(int identifier); - static void setup(TestJavaObjectHostApi? api, - {BinaryMessenger? binaryMessenger}) { + static void setup(TestJavaObjectHostApi? api, {BinaryMessenger? binaryMessenger}) { { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.JavaObjectHostApi.dispose', codec, @@ -34,7 +60,7 @@ abstract class TestJavaObjectHostApi { } else { channel.setMockMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.JavaObjectHostApi.dispose was null.'); + 'Argument for dev.flutter.pigeon.JavaObjectHostApi.dispose was null.'); final List args = (message as List?)!; final int? arg_identifier = (args[0] as int?); assert(arg_identifier != null, @@ -62,9 +88,8 @@ class _TestWebViewHostApiCodec extends StandardMessageCodec { @override Object? readValueOfType(int type, ReadBuffer buffer) { switch (type) { - case 128: + case 128: return WebViewPoint.decode(readValue(buffer)!); - default: return super.readValueOfType(type, buffer); } @@ -76,11 +101,9 @@ abstract class TestWebViewHostApi { void create(int instanceId, bool useHybridComposition); - void loadData( - int instanceId, String data, String? mimeType, String? encoding); + 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 loadDataWithBaseUrl(int instanceId, String? baseUrl, String data, String? mimeType, String? encoding, String? historyUrl); void loadUrl(int instanceId, String url, Map headers); @@ -128,8 +151,7 @@ abstract class TestWebViewHostApi { void setBackgroundColor(int instanceId, int color); - static void setup(TestWebViewHostApi? api, - {BinaryMessenger? binaryMessenger}) { + static void setup(TestWebViewHostApi? api, {BinaryMessenger? binaryMessenger}) { { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.WebViewHostApi.create', codec, @@ -139,7 +161,7 @@ abstract class TestWebViewHostApi { } else { channel.setMockMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.WebViewHostApi.create was null.'); + 'Argument for dev.flutter.pigeon.WebViewHostApi.create was null.'); final List args = (message as List?)!; final int? arg_instanceId = (args[0] as int?); assert(arg_instanceId != null, @@ -161,7 +183,7 @@ abstract class TestWebViewHostApi { } else { channel.setMockMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.WebViewHostApi.loadData was null.'); + 'Argument for dev.flutter.pigeon.WebViewHostApi.loadData was null.'); final List args = (message as List?)!; final int? arg_instanceId = (args[0] as int?); assert(arg_instanceId != null, @@ -185,7 +207,7 @@ abstract class TestWebViewHostApi { } else { channel.setMockMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.WebViewHostApi.loadDataWithBaseUrl was null.'); + 'Argument for dev.flutter.pigeon.WebViewHostApi.loadDataWithBaseUrl was null.'); final List args = (message as List?)!; final int? arg_instanceId = (args[0] as int?); assert(arg_instanceId != null, @@ -197,8 +219,7 @@ abstract class TestWebViewHostApi { 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); + api.loadDataWithBaseUrl(arg_instanceId!, arg_baseUrl, arg_data!, arg_mimeType, arg_encoding, arg_historyUrl); return []; }); } @@ -212,7 +233,7 @@ abstract class TestWebViewHostApi { } else { channel.setMockMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.WebViewHostApi.loadUrl was null.'); + 'Argument for dev.flutter.pigeon.WebViewHostApi.loadUrl was null.'); final List args = (message as List?)!; final int? arg_instanceId = (args[0] as int?); assert(arg_instanceId != null, @@ -220,8 +241,7 @@ abstract class TestWebViewHostApi { final String? arg_url = (args[1] as String?); assert(arg_url != null, 'Argument for dev.flutter.pigeon.WebViewHostApi.loadUrl was null, expected non-null String.'); - final Map? arg_headers = - (args[2] as Map?)?.cast(); + final Map? arg_headers = (args[2] as Map?)?.cast(); assert(arg_headers != null, 'Argument for dev.flutter.pigeon.WebViewHostApi.loadUrl was null, expected non-null Map.'); api.loadUrl(arg_instanceId!, arg_url!, arg_headers!); @@ -238,7 +258,7 @@ abstract class TestWebViewHostApi { } else { channel.setMockMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.WebViewHostApi.postUrl was null.'); + 'Argument for dev.flutter.pigeon.WebViewHostApi.postUrl was null.'); final List args = (message as List?)!; final int? arg_instanceId = (args[0] as int?); assert(arg_instanceId != null, @@ -263,7 +283,7 @@ abstract class TestWebViewHostApi { } else { channel.setMockMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.WebViewHostApi.getUrl was null.'); + 'Argument for dev.flutter.pigeon.WebViewHostApi.getUrl was null.'); final List args = (message as List?)!; final int? arg_instanceId = (args[0] as int?); assert(arg_instanceId != null, @@ -282,7 +302,7 @@ abstract class TestWebViewHostApi { } else { channel.setMockMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.WebViewHostApi.canGoBack was null.'); + 'Argument for dev.flutter.pigeon.WebViewHostApi.canGoBack was null.'); final List args = (message as List?)!; final int? arg_instanceId = (args[0] as int?); assert(arg_instanceId != null, @@ -301,7 +321,7 @@ abstract class TestWebViewHostApi { } else { channel.setMockMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.WebViewHostApi.canGoForward was null.'); + 'Argument for dev.flutter.pigeon.WebViewHostApi.canGoForward was null.'); final List args = (message as List?)!; final int? arg_instanceId = (args[0] as int?); assert(arg_instanceId != null, @@ -320,7 +340,7 @@ abstract class TestWebViewHostApi { } else { channel.setMockMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.WebViewHostApi.goBack was null.'); + 'Argument for dev.flutter.pigeon.WebViewHostApi.goBack was null.'); final List args = (message as List?)!; final int? arg_instanceId = (args[0] as int?); assert(arg_instanceId != null, @@ -339,7 +359,7 @@ abstract class TestWebViewHostApi { } else { channel.setMockMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.WebViewHostApi.goForward was null.'); + 'Argument for dev.flutter.pigeon.WebViewHostApi.goForward was null.'); final List args = (message as List?)!; final int? arg_instanceId = (args[0] as int?); assert(arg_instanceId != null, @@ -358,7 +378,7 @@ abstract class TestWebViewHostApi { } else { channel.setMockMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.WebViewHostApi.reload was null.'); + 'Argument for dev.flutter.pigeon.WebViewHostApi.reload was null.'); final List args = (message as List?)!; final int? arg_instanceId = (args[0] as int?); assert(arg_instanceId != null, @@ -377,7 +397,7 @@ abstract class TestWebViewHostApi { } else { channel.setMockMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.WebViewHostApi.clearCache was null.'); + 'Argument for dev.flutter.pigeon.WebViewHostApi.clearCache was null.'); final List args = (message as List?)!; final int? arg_instanceId = (args[0] as int?); assert(arg_instanceId != null, @@ -399,7 +419,7 @@ abstract class TestWebViewHostApi { } else { channel.setMockMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.WebViewHostApi.evaluateJavascript was null.'); + 'Argument for dev.flutter.pigeon.WebViewHostApi.evaluateJavascript was null.'); final List args = (message as List?)!; final int? arg_instanceId = (args[0] as int?); assert(arg_instanceId != null, @@ -407,8 +427,7 @@ abstract class TestWebViewHostApi { final String? arg_javascriptString = (args[1] as String?); assert(arg_javascriptString != null, 'Argument for dev.flutter.pigeon.WebViewHostApi.evaluateJavascript was null, expected non-null String.'); - final String? output = await api.evaluateJavascript( - arg_instanceId!, arg_javascriptString!); + final String? output = await api.evaluateJavascript(arg_instanceId!, arg_javascriptString!); return [output]; }); } @@ -422,7 +441,7 @@ abstract class TestWebViewHostApi { } else { channel.setMockMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.WebViewHostApi.getTitle was null.'); + 'Argument for dev.flutter.pigeon.WebViewHostApi.getTitle was null.'); final List args = (message as List?)!; final int? arg_instanceId = (args[0] as int?); assert(arg_instanceId != null, @@ -441,7 +460,7 @@ abstract class TestWebViewHostApi { } else { channel.setMockMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.WebViewHostApi.scrollTo was null.'); + 'Argument for dev.flutter.pigeon.WebViewHostApi.scrollTo was null.'); final List args = (message as List?)!; final int? arg_instanceId = (args[0] as int?); assert(arg_instanceId != null, @@ -466,7 +485,7 @@ abstract class TestWebViewHostApi { } else { channel.setMockMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.WebViewHostApi.scrollBy was null.'); + 'Argument for dev.flutter.pigeon.WebViewHostApi.scrollBy was null.'); final List args = (message as List?)!; final int? arg_instanceId = (args[0] as int?); assert(arg_instanceId != null, @@ -491,7 +510,7 @@ abstract class TestWebViewHostApi { } else { channel.setMockMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.WebViewHostApi.getScrollX was null.'); + 'Argument for dev.flutter.pigeon.WebViewHostApi.getScrollX was null.'); final List args = (message as List?)!; final int? arg_instanceId = (args[0] as int?); assert(arg_instanceId != null, @@ -510,7 +529,7 @@ abstract class TestWebViewHostApi { } else { channel.setMockMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.WebViewHostApi.getScrollY was null.'); + 'Argument for dev.flutter.pigeon.WebViewHostApi.getScrollY was null.'); final List args = (message as List?)!; final int? arg_instanceId = (args[0] as int?); assert(arg_instanceId != null, @@ -529,7 +548,7 @@ abstract class TestWebViewHostApi { } else { channel.setMockMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.WebViewHostApi.getScrollPosition was null.'); + 'Argument for dev.flutter.pigeon.WebViewHostApi.getScrollPosition was null.'); final List args = (message as List?)!; final int? arg_instanceId = (args[0] as int?); assert(arg_instanceId != null, @@ -541,15 +560,14 @@ abstract class TestWebViewHostApi { } { final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.WebViewHostApi.setWebContentsDebuggingEnabled', - codec, + 'dev.flutter.pigeon.WebViewHostApi.setWebContentsDebuggingEnabled', codec, binaryMessenger: binaryMessenger); if (api == null) { channel.setMockMessageHandler(null); } else { channel.setMockMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.WebViewHostApi.setWebContentsDebuggingEnabled was null.'); + 'Argument for dev.flutter.pigeon.WebViewHostApi.setWebContentsDebuggingEnabled was null.'); final List args = (message as List?)!; final bool? arg_enabled = (args[0] as bool?); assert(arg_enabled != null, @@ -568,7 +586,7 @@ abstract class TestWebViewHostApi { } else { channel.setMockMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.WebViewHostApi.setWebViewClient was null.'); + 'Argument for dev.flutter.pigeon.WebViewHostApi.setWebViewClient was null.'); final List args = (message as List?)!; final int? arg_instanceId = (args[0] as int?); assert(arg_instanceId != null, @@ -590,7 +608,7 @@ abstract class TestWebViewHostApi { } else { channel.setMockMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.WebViewHostApi.addJavaScriptChannel was null.'); + 'Argument for dev.flutter.pigeon.WebViewHostApi.addJavaScriptChannel was null.'); final List args = (message as List?)!; final int? arg_instanceId = (args[0] as int?); assert(arg_instanceId != null, @@ -598,8 +616,7 @@ abstract class TestWebViewHostApi { final int? arg_javaScriptChannelInstanceId = (args[1] as int?); assert(arg_javaScriptChannelInstanceId != null, 'Argument for dev.flutter.pigeon.WebViewHostApi.addJavaScriptChannel was null, expected non-null int.'); - api.addJavaScriptChannel( - arg_instanceId!, arg_javaScriptChannelInstanceId!); + api.addJavaScriptChannel(arg_instanceId!, arg_javaScriptChannelInstanceId!); return []; }); } @@ -613,7 +630,7 @@ abstract class TestWebViewHostApi { } else { channel.setMockMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.WebViewHostApi.removeJavaScriptChannel was null.'); + 'Argument for dev.flutter.pigeon.WebViewHostApi.removeJavaScriptChannel was null.'); final List args = (message as List?)!; final int? arg_instanceId = (args[0] as int?); assert(arg_instanceId != null, @@ -621,8 +638,7 @@ abstract class TestWebViewHostApi { final int? arg_javaScriptChannelInstanceId = (args[1] as int?); assert(arg_javaScriptChannelInstanceId != null, 'Argument for dev.flutter.pigeon.WebViewHostApi.removeJavaScriptChannel was null, expected non-null int.'); - api.removeJavaScriptChannel( - arg_instanceId!, arg_javaScriptChannelInstanceId!); + api.removeJavaScriptChannel(arg_instanceId!, arg_javaScriptChannelInstanceId!); return []; }); } @@ -636,7 +652,7 @@ abstract class TestWebViewHostApi { } else { channel.setMockMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.WebViewHostApi.setDownloadListener was null.'); + 'Argument for dev.flutter.pigeon.WebViewHostApi.setDownloadListener was null.'); final List args = (message as List?)!; final int? arg_instanceId = (args[0] as int?); assert(arg_instanceId != null, @@ -656,7 +672,7 @@ abstract class TestWebViewHostApi { } else { channel.setMockMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.WebViewHostApi.setWebChromeClient was null.'); + 'Argument for dev.flutter.pigeon.WebViewHostApi.setWebChromeClient was null.'); final List args = (message as List?)!; final int? arg_instanceId = (args[0] as int?); assert(arg_instanceId != null, @@ -676,7 +692,7 @@ abstract class TestWebViewHostApi { } else { channel.setMockMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.WebViewHostApi.setBackgroundColor was null.'); + 'Argument for dev.flutter.pigeon.WebViewHostApi.setBackgroundColor was null.'); final List args = (message as List?)!; final int? arg_instanceId = (args[0] as int?); assert(arg_instanceId != null, @@ -721,8 +737,7 @@ abstract class TestWebSettingsHostApi { void setAllowFileAccess(int instanceId, bool enabled); - static void setup(TestWebSettingsHostApi? api, - {BinaryMessenger? binaryMessenger}) { + static void setup(TestWebSettingsHostApi? api, {BinaryMessenger? binaryMessenger}) { { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.WebSettingsHostApi.create', codec, @@ -732,7 +747,7 @@ abstract class TestWebSettingsHostApi { } else { channel.setMockMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.WebSettingsHostApi.create was null.'); + 'Argument for dev.flutter.pigeon.WebSettingsHostApi.create was null.'); final List args = (message as List?)!; final int? arg_instanceId = (args[0] as int?); assert(arg_instanceId != null, @@ -754,7 +769,7 @@ abstract class TestWebSettingsHostApi { } else { channel.setMockMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.WebSettingsHostApi.setDomStorageEnabled was null.'); + 'Argument for dev.flutter.pigeon.WebSettingsHostApi.setDomStorageEnabled was null.'); final List args = (message as List?)!; final int? arg_instanceId = (args[0] as int?); assert(arg_instanceId != null, @@ -769,15 +784,14 @@ abstract class TestWebSettingsHostApi { } { final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.WebSettingsHostApi.setJavaScriptCanOpenWindowsAutomatically', - codec, + 'dev.flutter.pigeon.WebSettingsHostApi.setJavaScriptCanOpenWindowsAutomatically', codec, binaryMessenger: binaryMessenger); if (api == null) { channel.setMockMessageHandler(null); } else { channel.setMockMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.WebSettingsHostApi.setJavaScriptCanOpenWindowsAutomatically was null.'); + 'Argument for dev.flutter.pigeon.WebSettingsHostApi.setJavaScriptCanOpenWindowsAutomatically was null.'); final List args = (message as List?)!; final int? arg_instanceId = (args[0] as int?); assert(arg_instanceId != null, @@ -785,23 +799,21 @@ abstract class TestWebSettingsHostApi { final bool? arg_flag = (args[1] as bool?); assert(arg_flag != null, 'Argument for dev.flutter.pigeon.WebSettingsHostApi.setJavaScriptCanOpenWindowsAutomatically was null, expected non-null bool.'); - api.setJavaScriptCanOpenWindowsAutomatically( - arg_instanceId!, arg_flag!); + api.setJavaScriptCanOpenWindowsAutomatically(arg_instanceId!, arg_flag!); return []; }); } } { final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.WebSettingsHostApi.setSupportMultipleWindows', - codec, + 'dev.flutter.pigeon.WebSettingsHostApi.setSupportMultipleWindows', codec, binaryMessenger: binaryMessenger); if (api == null) { channel.setMockMessageHandler(null); } else { channel.setMockMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.WebSettingsHostApi.setSupportMultipleWindows was null.'); + 'Argument for dev.flutter.pigeon.WebSettingsHostApi.setSupportMultipleWindows was null.'); final List args = (message as List?)!; final int? arg_instanceId = (args[0] as int?); assert(arg_instanceId != null, @@ -823,7 +835,7 @@ abstract class TestWebSettingsHostApi { } else { channel.setMockMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.WebSettingsHostApi.setJavaScriptEnabled was null.'); + 'Argument for dev.flutter.pigeon.WebSettingsHostApi.setJavaScriptEnabled was null.'); final List args = (message as List?)!; final int? arg_instanceId = (args[0] as int?); assert(arg_instanceId != null, @@ -845,7 +857,7 @@ abstract class TestWebSettingsHostApi { } else { channel.setMockMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.WebSettingsHostApi.setUserAgentString was null.'); + 'Argument for dev.flutter.pigeon.WebSettingsHostApi.setUserAgentString was null.'); final List args = (message as List?)!; final int? arg_instanceId = (args[0] as int?); assert(arg_instanceId != null, @@ -858,15 +870,14 @@ abstract class TestWebSettingsHostApi { } { final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.WebSettingsHostApi.setMediaPlaybackRequiresUserGesture', - codec, + 'dev.flutter.pigeon.WebSettingsHostApi.setMediaPlaybackRequiresUserGesture', codec, binaryMessenger: binaryMessenger); if (api == null) { channel.setMockMessageHandler(null); } else { channel.setMockMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.WebSettingsHostApi.setMediaPlaybackRequiresUserGesture was null.'); + 'Argument for dev.flutter.pigeon.WebSettingsHostApi.setMediaPlaybackRequiresUserGesture was null.'); final List args = (message as List?)!; final int? arg_instanceId = (args[0] as int?); assert(arg_instanceId != null, @@ -874,8 +885,7 @@ abstract class TestWebSettingsHostApi { final bool? arg_require = (args[1] as bool?); assert(arg_require != null, 'Argument for dev.flutter.pigeon.WebSettingsHostApi.setMediaPlaybackRequiresUserGesture was null, expected non-null bool.'); - api.setMediaPlaybackRequiresUserGesture( - arg_instanceId!, arg_require!); + api.setMediaPlaybackRequiresUserGesture(arg_instanceId!, arg_require!); return []; }); } @@ -889,7 +899,7 @@ abstract class TestWebSettingsHostApi { } else { channel.setMockMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.WebSettingsHostApi.setSupportZoom was null.'); + 'Argument for dev.flutter.pigeon.WebSettingsHostApi.setSupportZoom was null.'); final List args = (message as List?)!; final int? arg_instanceId = (args[0] as int?); assert(arg_instanceId != null, @@ -904,15 +914,14 @@ abstract class TestWebSettingsHostApi { } { final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.WebSettingsHostApi.setLoadWithOverviewMode', - codec, + 'dev.flutter.pigeon.WebSettingsHostApi.setLoadWithOverviewMode', codec, binaryMessenger: binaryMessenger); if (api == null) { channel.setMockMessageHandler(null); } else { channel.setMockMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.WebSettingsHostApi.setLoadWithOverviewMode was null.'); + 'Argument for dev.flutter.pigeon.WebSettingsHostApi.setLoadWithOverviewMode was null.'); final List args = (message as List?)!; final int? arg_instanceId = (args[0] as int?); assert(arg_instanceId != null, @@ -934,7 +943,7 @@ abstract class TestWebSettingsHostApi { } else { channel.setMockMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.WebSettingsHostApi.setUseWideViewPort was null.'); + 'Argument for dev.flutter.pigeon.WebSettingsHostApi.setUseWideViewPort was null.'); final List args = (message as List?)!; final int? arg_instanceId = (args[0] as int?); assert(arg_instanceId != null, @@ -956,7 +965,7 @@ abstract class TestWebSettingsHostApi { } else { channel.setMockMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.WebSettingsHostApi.setDisplayZoomControls was null.'); + 'Argument for dev.flutter.pigeon.WebSettingsHostApi.setDisplayZoomControls was null.'); final List args = (message as List?)!; final int? arg_instanceId = (args[0] as int?); assert(arg_instanceId != null, @@ -978,7 +987,7 @@ abstract class TestWebSettingsHostApi { } else { channel.setMockMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.WebSettingsHostApi.setBuiltInZoomControls was null.'); + 'Argument for dev.flutter.pigeon.WebSettingsHostApi.setBuiltInZoomControls was null.'); final List args = (message as List?)!; final int? arg_instanceId = (args[0] as int?); assert(arg_instanceId != null, @@ -1000,7 +1009,7 @@ abstract class TestWebSettingsHostApi { } else { channel.setMockMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.WebSettingsHostApi.setAllowFileAccess was null.'); + 'Argument for dev.flutter.pigeon.WebSettingsHostApi.setAllowFileAccess was null.'); final List args = (message as List?)!; final int? arg_instanceId = (args[0] as int?); assert(arg_instanceId != null, @@ -1021,8 +1030,7 @@ abstract class TestJavaScriptChannelHostApi { void create(int instanceId, String channelName); - static void setup(TestJavaScriptChannelHostApi? api, - {BinaryMessenger? binaryMessenger}) { + static void setup(TestJavaScriptChannelHostApi? api, {BinaryMessenger? binaryMessenger}) { { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.JavaScriptChannelHostApi.create', codec, @@ -1032,7 +1040,7 @@ abstract class TestJavaScriptChannelHostApi { } else { channel.setMockMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.JavaScriptChannelHostApi.create was null.'); + 'Argument for dev.flutter.pigeon.JavaScriptChannelHostApi.create was null.'); final List args = (message as List?)!; final int? arg_instanceId = (args[0] as int?); assert(arg_instanceId != null, @@ -1053,11 +1061,9 @@ abstract class TestWebViewClientHostApi { void create(int instanceId); - void setSynchronousReturnValueForShouldOverrideUrlLoading( - int instanceId, bool value); + void setSynchronousReturnValueForShouldOverrideUrlLoading(int instanceId, bool value); - static void setup(TestWebViewClientHostApi? api, - {BinaryMessenger? binaryMessenger}) { + static void setup(TestWebViewClientHostApi? api, {BinaryMessenger? binaryMessenger}) { { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.WebViewClientHostApi.create', codec, @@ -1067,7 +1073,7 @@ abstract class TestWebViewClientHostApi { } else { channel.setMockMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.WebViewClientHostApi.create was null.'); + 'Argument for dev.flutter.pigeon.WebViewClientHostApi.create was null.'); final List args = (message as List?)!; final int? arg_instanceId = (args[0] as int?); assert(arg_instanceId != null, @@ -1079,15 +1085,14 @@ abstract class TestWebViewClientHostApi { } { final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.WebViewClientHostApi.setSynchronousReturnValueForShouldOverrideUrlLoading', - codec, + 'dev.flutter.pigeon.WebViewClientHostApi.setSynchronousReturnValueForShouldOverrideUrlLoading', codec, binaryMessenger: binaryMessenger); if (api == null) { channel.setMockMessageHandler(null); } else { channel.setMockMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.WebViewClientHostApi.setSynchronousReturnValueForShouldOverrideUrlLoading was null.'); + 'Argument for dev.flutter.pigeon.WebViewClientHostApi.setSynchronousReturnValueForShouldOverrideUrlLoading was null.'); final List args = (message as List?)!; final int? arg_instanceId = (args[0] as int?); assert(arg_instanceId != null, @@ -1095,8 +1100,7 @@ abstract class TestWebViewClientHostApi { final bool? arg_value = (args[1] as bool?); assert(arg_value != null, 'Argument for dev.flutter.pigeon.WebViewClientHostApi.setSynchronousReturnValueForShouldOverrideUrlLoading was null, expected non-null bool.'); - api.setSynchronousReturnValueForShouldOverrideUrlLoading( - arg_instanceId!, arg_value!); + api.setSynchronousReturnValueForShouldOverrideUrlLoading(arg_instanceId!, arg_value!); return []; }); } @@ -1109,8 +1113,7 @@ abstract class TestDownloadListenerHostApi { void create(int instanceId); - static void setup(TestDownloadListenerHostApi? api, - {BinaryMessenger? binaryMessenger}) { + static void setup(TestDownloadListenerHostApi? api, {BinaryMessenger? binaryMessenger}) { { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.DownloadListenerHostApi.create', codec, @@ -1120,7 +1123,7 @@ abstract class TestDownloadListenerHostApi { } else { channel.setMockMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.DownloadListenerHostApi.create was null.'); + 'Argument for dev.flutter.pigeon.DownloadListenerHostApi.create was null.'); final List args = (message as List?)!; final int? arg_instanceId = (args[0] as int?); assert(arg_instanceId != null, @@ -1138,11 +1141,9 @@ abstract class TestWebChromeClientHostApi { void create(int instanceId); - void setSynchronousReturnValueForOnShowFileChooser( - int instanceId, bool value); + void setSynchronousReturnValueForOnShowFileChooser(int instanceId, bool value); - static void setup(TestWebChromeClientHostApi? api, - {BinaryMessenger? binaryMessenger}) { + static void setup(TestWebChromeClientHostApi? api, {BinaryMessenger? binaryMessenger}) { { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.WebChromeClientHostApi.create', codec, @@ -1152,7 +1153,7 @@ abstract class TestWebChromeClientHostApi { } else { channel.setMockMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.WebChromeClientHostApi.create was null.'); + 'Argument for dev.flutter.pigeon.WebChromeClientHostApi.create was null.'); final List args = (message as List?)!; final int? arg_instanceId = (args[0] as int?); assert(arg_instanceId != null, @@ -1164,15 +1165,14 @@ abstract class TestWebChromeClientHostApi { } { final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.WebChromeClientHostApi.setSynchronousReturnValueForOnShowFileChooser', - codec, + 'dev.flutter.pigeon.WebChromeClientHostApi.setSynchronousReturnValueForOnShowFileChooser', codec, binaryMessenger: binaryMessenger); if (api == null) { channel.setMockMessageHandler(null); } else { channel.setMockMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.WebChromeClientHostApi.setSynchronousReturnValueForOnShowFileChooser was null.'); + 'Argument for dev.flutter.pigeon.WebChromeClientHostApi.setSynchronousReturnValueForOnShowFileChooser was null.'); final List args = (message as List?)!; final int? arg_instanceId = (args[0] as int?); assert(arg_instanceId != null, @@ -1180,8 +1180,7 @@ abstract class TestWebChromeClientHostApi { final bool? arg_value = (args[1] as bool?); assert(arg_value != null, 'Argument for dev.flutter.pigeon.WebChromeClientHostApi.setSynchronousReturnValueForOnShowFileChooser was null, expected non-null bool.'); - api.setSynchronousReturnValueForOnShowFileChooser( - arg_instanceId!, arg_value!); + api.setSynchronousReturnValueForOnShowFileChooser(arg_instanceId!, arg_value!); return []; }); } @@ -1196,8 +1195,7 @@ abstract class TestAssetManagerHostApi { String getAssetFilePathByName(String name); - static void setup(TestAssetManagerHostApi? api, - {BinaryMessenger? binaryMessenger}) { + static void setup(TestAssetManagerHostApi? api, {BinaryMessenger? binaryMessenger}) { { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.FlutterAssetManagerHostApi.list', codec, @@ -1207,7 +1205,7 @@ abstract class TestAssetManagerHostApi { } else { channel.setMockMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.FlutterAssetManagerHostApi.list was null.'); + 'Argument for dev.flutter.pigeon.FlutterAssetManagerHostApi.list was null.'); final List args = (message as List?)!; final String? arg_path = (args[0] as String?); assert(arg_path != null, @@ -1219,15 +1217,14 @@ abstract class TestAssetManagerHostApi { } { final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.FlutterAssetManagerHostApi.getAssetFilePathByName', - codec, + 'dev.flutter.pigeon.FlutterAssetManagerHostApi.getAssetFilePathByName', codec, binaryMessenger: binaryMessenger); if (api == null) { channel.setMockMessageHandler(null); } else { channel.setMockMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.FlutterAssetManagerHostApi.getAssetFilePathByName was null.'); + 'Argument for dev.flutter.pigeon.FlutterAssetManagerHostApi.getAssetFilePathByName was null.'); final List args = (message as List?)!; final String? arg_name = (args[0] as String?); assert(arg_name != null, @@ -1247,8 +1244,7 @@ abstract class TestWebStorageHostApi { void deleteAllData(int instanceId); - static void setup(TestWebStorageHostApi? api, - {BinaryMessenger? binaryMessenger}) { + static void setup(TestWebStorageHostApi? api, {BinaryMessenger? binaryMessenger}) { { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.WebStorageHostApi.create', codec, @@ -1258,7 +1254,7 @@ abstract class TestWebStorageHostApi { } else { channel.setMockMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.WebStorageHostApi.create was null.'); + 'Argument for dev.flutter.pigeon.WebStorageHostApi.create was null.'); final List args = (message as List?)!; final int? arg_instanceId = (args[0] as int?); assert(arg_instanceId != null, @@ -1277,7 +1273,7 @@ abstract class TestWebStorageHostApi { } else { channel.setMockMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.WebStorageHostApi.deleteAllData was null.'); + 'Argument for dev.flutter.pigeon.WebStorageHostApi.deleteAllData was null.'); final List args = (message as List?)!; final int? arg_instanceId = (args[0] as int?); assert(arg_instanceId != null, From 9d90d9f207b42ba8e54bf358dfc573a083abae3c Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Wed, 22 Feb 2023 20:55:04 -0500 Subject: [PATCH 02/24] some more changes --- .../lib/src/android_webview.dart | 70 +++++++++++--- .../lib/src/android_webview_api_impls.dart | 94 ++++++++++++++++--- .../android_navigation_delegate_test.dart | 67 ++++++++++--- .../test/android_webview_test.dart | 12 --- 4 files changed, 191 insertions(+), 52 deletions(-) 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 index 0d97f9096b8..ed424ea902c 100644 --- a/packages/webview_flutter/webview_flutter_android/lib/src/android_webview.dart +++ b/packages/webview_flutter/webview_flutter_android/lib/src/android_webview.dart @@ -32,6 +32,7 @@ class JavaObject { /// /// This should only be used by subclasses created by this library or to /// create copies. + @protected JavaObject.detached({ required BinaryMessenger? binaryMessenger, required InstanceManager? instanceManager, @@ -472,8 +473,11 @@ class WebSettings extends JavaObject { /// This constructor is only used for testing. An instance should be obtained /// with [WebView.settings]. @visibleForTesting - WebSettings(WebView webView, {super.binaryMessenger, super.instanceManager}) - : super.detached() { + WebSettings( + WebView webView, { + @visibleForTesting super.binaryMessenger, + @visibleForTesting super.instanceManager, + }) : super.detached() { api.createFromInstance(this, webView); } @@ -481,8 +485,11 @@ class WebSettings extends JavaObject { /// /// This should only be used by subclasses created by this library or to /// create copies. - WebSettings.detached({required super.binaryMessenger, required super.instanceManager}) - : super.detached(); + @protected + WebSettings.detached({ + required super.binaryMessenger, + required super.instanceManager, + }) : super.detached(); /// Pigeon Host Api implementation for [WebSettings]. @visibleForTesting @@ -616,7 +623,8 @@ class JavaScriptChannel extends JavaObject { JavaScriptChannel( this.channelName, { required this.postMessage, - super.binaryMessenger, super.instanceManager + @visibleForTesting super.binaryMessenger, + @visibleForTesting super.instanceManager, }) : super.detached() { AndroidWebViewFlutterApis.instance.ensureSetUp(); api.createFromInstance(this); @@ -627,9 +635,12 @@ class JavaScriptChannel extends JavaObject { /// /// This should only be used by subclasses created by this library or to /// create copies. + @protected JavaScriptChannel.detached( this.channelName, { required this.postMessage, + required super.binaryMessenger, + required super.instanceManager, }) : super.detached(); /// Pigeon Host Api implementation for [JavaScriptChannel]. @@ -654,6 +665,8 @@ class WebViewClient extends JavaObject { @Deprecated('Only called on Android version < 23.') this.onReceivedError, this.requestLoading, this.urlLoading, + @visibleForTesting super.binaryMessenger, + @visibleForTesting super.instanceManager, }) : super.detached() { AndroidWebViewFlutterApis.instance.ensureSetUp(); api.createFromInstance(this); @@ -663,6 +676,7 @@ class WebViewClient extends JavaObject { /// /// This should only be used by subclasses created by this library or to /// create copies. + @protected WebViewClient.detached({ this.onPageStarted, this.onPageFinished, @@ -670,6 +684,8 @@ class WebViewClient extends JavaObject { @Deprecated('Only called on Android version < 23.') this.onReceivedError, this.requestLoading, this.urlLoading, + required super.binaryMessenger, + required super.instanceManager, }) : super.detached(); /// User authentication failed on server. @@ -836,7 +852,11 @@ class WebViewClient extends JavaObject { @immutable class DownloadListener extends JavaObject { /// Constructs a [DownloadListener]. - DownloadListener({required this.onDownloadStart}) : super.detached() { + DownloadListener({ + required this.onDownloadStart, + @visibleForTesting super.binaryMessenger, + @visibleForTesting super.instanceManager, + }) : super.detached() { AndroidWebViewFlutterApis.instance.ensureSetUp(); api.createFromInstance(this); } @@ -846,7 +866,12 @@ class DownloadListener extends JavaObject { /// /// This should only be used by subclasses created by this library or to /// create copies. - DownloadListener.detached({required this.onDownloadStart}) : super.detached(); + @protected + DownloadListener.detached({ + required this.onDownloadStart, + required super.binaryMessenger, + required super.instanceManager, + }) : super.detached(); /// Pigeon Host Api implementation for [DownloadListener]. @visibleForTesting @@ -866,8 +891,12 @@ class DownloadListener extends JavaObject { @immutable class WebChromeClient extends JavaObject { /// Constructs a [WebChromeClient]. - WebChromeClient({this.onProgressChanged, this.onShowFileChooser}) - : super.detached() { + WebChromeClient({ + this.onProgressChanged, + this.onShowFileChooser, + @visibleForTesting super.binaryMessenger, + @visibleForTesting super.instanceManager, + }) : super.detached() { AndroidWebViewFlutterApis.instance.ensureSetUp(); api.createFromInstance(this); } @@ -877,9 +906,12 @@ class WebChromeClient extends JavaObject { /// /// This should only be used by subclasses created by this library or to /// create copies. + @protected WebChromeClient.detached({ - this.onProgressChanged, - this.onShowFileChooser, + required this.onProgressChanged, + required this.onShowFileChooser, + required super.binaryMessenger, + required super.instanceManager, }) : super.detached(); /// Pigeon Host Api implementation for [WebChromeClient]. @@ -942,13 +974,14 @@ class FileChooserParams extends JavaObject { /// /// 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, + required super.binaryMessenger, + required super.instanceManager, }) : super.detached(); /// Preference for a live media captured value (e.g. Camera, Microphone). @@ -1044,7 +1077,10 @@ class WebStorage extends JavaObject { /// This constructor is only used for testing. An instance should be obtained /// with [WebStorage.instance]. @visibleForTesting - WebStorage() : super.detached() { + WebStorage({ + @visibleForTesting super.binaryMessenger, + @visibleForTesting super.instanceManager, + }) : super.detached() { AndroidWebViewFlutterApis.instance.ensureSetUp(); api.createFromInstance(this); } @@ -1053,7 +1089,11 @@ class WebStorage extends JavaObject { /// /// This should only be used by subclasses created by this library or to /// create copies. - WebStorage.detached() : super.detached(); + @protected + WebStorage.detached({ + required super.binaryMessenger, + required super.instanceManager, + }) : super.detached(); /// Pigeon Host Api implementation for [WebStorage]. @visibleForTesting 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 index 24aabb2aac2..91eceae5e77 100644 --- 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 @@ -137,9 +137,16 @@ class JavaObjectFlutterApiImpl implements JavaObjectFlutterApi { class WebViewHostApiImpl extends WebViewHostApi { /// Constructs a [WebViewHostApiImpl]. WebViewHostApiImpl({ - super.binaryMessenger, + this.binaryMessenger, InstanceManager? instanceManager, - }) : instanceManager = instanceManager ?? JavaObject.globalInstanceManager; + }) : 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; @@ -151,6 +158,8 @@ class WebViewHostApiImpl extends WebViewHostApi { instance, onCopy: (WebView original) => WebView.detached( useHybridComposition: original.useHybridComposition, + binaryMessenger: binaryMessenger, + instanceManager: instanceManager, ), ), instance.useHybridComposition, @@ -355,10 +364,16 @@ class WebViewHostApiImpl extends WebViewHostApi { class WebSettingsHostApiImpl extends WebSettingsHostApi { /// Constructs a [WebSettingsHostApiImpl]. WebSettingsHostApiImpl({ - super.binaryMessenger, + this.binaryMessenger, InstanceManager? instanceManager, }) : instanceManager = instanceManager ?? JavaObject.globalInstanceManager; + /// 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; @@ -368,7 +383,10 @@ class WebSettingsHostApiImpl extends WebSettingsHostApi { instanceManager.addDartCreatedInstance( instance, onCopy: (WebSettings original) { - return WebSettings.detached(); + return WebSettings.detached( + binaryMessenger: binaryMessenger, + instanceManager: instanceManager, + ); }, ), instanceManager.getIdentifier(webView)!, @@ -501,10 +519,16 @@ class WebSettingsHostApiImpl extends WebSettingsHostApi { class JavaScriptChannelHostApiImpl extends JavaScriptChannelHostApi { /// Constructs a [JavaScriptChannelHostApiImpl]. JavaScriptChannelHostApiImpl({ - super.binaryMessenger, + this.binaryMessenger, InstanceManager? instanceManager, }) : instanceManager = instanceManager ?? JavaObject.globalInstanceManager; + /// 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; @@ -516,6 +540,8 @@ class JavaScriptChannelHostApiImpl extends JavaScriptChannelHostApi { onCopy: (JavaScriptChannel original) => JavaScriptChannel.detached( original.channelName, postMessage: original.postMessage, + binaryMessenger: binaryMessenger, + instanceManager: instanceManager, ), ); await create( @@ -551,10 +577,16 @@ class JavaScriptChannelFlutterApiImpl extends JavaScriptChannelFlutterApi { class WebViewClientHostApiImpl extends WebViewClientHostApi { /// Constructs a [WebViewClientHostApiImpl]. WebViewClientHostApiImpl({ - super.binaryMessenger, + this.binaryMessenger, InstanceManager? instanceManager, }) : instanceManager = instanceManager ?? JavaObject.globalInstanceManager; + /// 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; @@ -563,7 +595,12 @@ class WebViewClientHostApiImpl extends WebViewClientHostApi { if (instanceManager.getIdentifier(instance) == null) { final int identifier = instanceManager.addDartCreatedInstance( instance, - onCopy: (WebViewClient original) => WebViewClient.detached(), + onCopy: (WebViewClient original) { + return WebViewClient.detached( + binaryMessenger: binaryMessenger, + instanceManager: instanceManager, + ); + }, ); return create(identifier); } @@ -741,10 +778,16 @@ class WebViewClientFlutterApiImpl extends WebViewClientFlutterApi { class DownloadListenerHostApiImpl extends DownloadListenerHostApi { /// Constructs a [DownloadListenerHostApiImpl]. DownloadListenerHostApiImpl({ - super.binaryMessenger, + this.binaryMessenger, InstanceManager? instanceManager, }) : instanceManager = instanceManager ?? JavaObject.globalInstanceManager; + /// 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; @@ -755,6 +798,8 @@ class DownloadListenerHostApiImpl extends DownloadListenerHostApi { instance, onCopy: (DownloadListener original) => DownloadListener.detached( onDownloadStart: original.onDownloadStart, + binaryMessenger: binaryMessenger, + instanceManager: instanceManager, ), ); return create(identifier); @@ -800,10 +845,16 @@ class DownloadListenerFlutterApiImpl extends DownloadListenerFlutterApi { class WebChromeClientHostApiImpl extends WebChromeClientHostApi { /// Constructs a [WebChromeClientHostApiImpl]. WebChromeClientHostApiImpl({ - super.binaryMessenger, + this.binaryMessenger, InstanceManager? instanceManager, }) : instanceManager = instanceManager ?? JavaObject.globalInstanceManager; + /// 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; @@ -812,7 +863,12 @@ class WebChromeClientHostApiImpl extends WebChromeClientHostApi { if (instanceManager.getIdentifier(instance) == null) { final int identifier = instanceManager.addDartCreatedInstance( instance, - onCopy: (WebChromeClient original) => WebChromeClient.detached(), + onCopy: (WebChromeClient original) => WebChromeClient.detached( + onProgressChanged: original.onProgressChanged, + onShowFileChooser: original.onShowFileChooser, + binaryMessenger: binaryMessenger, + instanceManager: instanceManager, + ), ); return create(identifier); } @@ -883,9 +939,16 @@ class WebChromeClientFlutterApiImpl extends WebChromeClientFlutterApi { class WebStorageHostApiImpl extends WebStorageHostApi { /// Constructs a [WebStorageHostApiImpl]. WebStorageHostApiImpl({ - super.binaryMessenger, + this.binaryMessenger, InstanceManager? instanceManager, - }) : instanceManager = instanceManager ?? JavaObject.globalInstanceManager; + }) : 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; @@ -895,7 +958,10 @@ class WebStorageHostApiImpl extends WebStorageHostApi { if (instanceManager.getIdentifier(instance) == null) { final int identifier = instanceManager.addDartCreatedInstance( instance, - onCopy: (WebStorage original) => WebStorage.detached(), + onCopy: (WebStorage original) => WebStorage.detached( + binaryMessenger: binaryMessenger, + instanceManager: instanceManager, + ), ); return create(identifier); } @@ -938,6 +1004,8 @@ class FileChooserParamsFlutterApiImpl extends FileChooserParamsFlutterApi { acceptTypes: acceptTypes.cast(), mode: mode.value, filenameHint: filenameHint, + binaryMessenger: binaryMessenger, + instanceManager: instanceManager, ), instanceId, onCopy: (FileChooserParams original) => FileChooserParams.detached( 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 dac7c69a84f..5672c51cd94 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 @@ -22,7 +22,10 @@ void main() { .setOnPageFinished((String url) => callbackUrl = url); CapturingWebViewClient.lastCreatedDelegate.onPageFinished!( - android_webview.WebView.detached(), + android_webview.WebView.detached( + binaryMessenger: null, + instanceManager: null, + ), 'https://www.google.com', ); @@ -38,7 +41,10 @@ void main() { .setOnPageStarted((String url) => callbackUrl = url); CapturingWebViewClient.lastCreatedDelegate.onPageStarted!( - android_webview.WebView.detached(), + android_webview.WebView.detached( + binaryMessenger: null, + instanceManager: null, + ), 'https://www.google.com', ); @@ -54,7 +60,10 @@ void main() { (WebResourceError error) => callbackError = error); CapturingWebViewClient.lastCreatedDelegate.onReceivedRequestError!( - android_webview.WebView.detached(), + android_webview.WebView.detached( + binaryMessenger: null, + instanceManager: null, + ), android_webview.WebResourceRequest( url: 'https://www.google.com', isForMainFrame: false, @@ -85,7 +94,10 @@ void main() { (WebResourceError error) => callbackError = error); CapturingWebViewClient.lastCreatedDelegate.onReceivedError!( - android_webview.WebView.detached(), + android_webview.WebView.detached( + binaryMessenger: null, + instanceManager: null, + ), android_webview.WebViewClient.errorFileNotFound, 'Page not found.', 'https://www.google.com', @@ -112,7 +124,10 @@ void main() { }); CapturingWebViewClient.lastCreatedDelegate.requestLoading!( - android_webview.WebView.detached(), + android_webview.WebView.detached( + binaryMessenger: null, + instanceManager: null, + ), android_webview.WebResourceRequest( url: 'https://www.google.com', isForMainFrame: true, @@ -139,7 +154,10 @@ void main() { }); CapturingWebViewClient.lastCreatedDelegate.requestLoading!( - android_webview.WebView.detached(), + android_webview.WebView.detached( + binaryMessenger: null, + instanceManager: null, + ), android_webview.WebResourceRequest( url: 'https://www.google.com', isForMainFrame: true, @@ -173,7 +191,10 @@ void main() { }); CapturingWebViewClient.lastCreatedDelegate.requestLoading!( - android_webview.WebView.detached(), + android_webview.WebView.detached( + binaryMessenger: null, + instanceManager: null, + ), android_webview.WebResourceRequest( url: 'https://www.google.com', isForMainFrame: true, @@ -211,7 +232,10 @@ void main() { }); CapturingWebViewClient.lastCreatedDelegate.requestLoading!( - android_webview.WebView.detached(), + android_webview.WebView.detached( + binaryMessenger: null, + instanceManager: null, + ), android_webview.WebResourceRequest( url: 'https://www.google.com', isForMainFrame: true, @@ -243,7 +267,10 @@ void main() { }); CapturingWebViewClient.lastCreatedDelegate.urlLoading!( - android_webview.WebView.detached(), + android_webview.WebView.detached( + binaryMessenger: null, + instanceManager: null, + ), 'https://www.google.com', ); @@ -263,7 +290,10 @@ void main() { }); CapturingWebViewClient.lastCreatedDelegate.urlLoading!( - android_webview.WebView.detached(), + android_webview.WebView.detached( + binaryMessenger: null, + instanceManager: null, + ), 'https://www.google.com', ); @@ -290,7 +320,10 @@ void main() { }); CapturingWebViewClient.lastCreatedDelegate.urlLoading!( - android_webview.WebView.detached(), + android_webview.WebView.detached( + binaryMessenger: null, + instanceManager: null, + ), 'https://www.google.com', ); @@ -321,7 +354,10 @@ void main() { }); CapturingWebViewClient.lastCreatedDelegate.urlLoading!( - android_webview.WebView.detached(), + android_webview.WebView.detached( + binaryMessenger: null, + instanceManager: null, + ), 'https://www.google.com', ); @@ -452,6 +488,7 @@ AndroidNavigationDelegateCreationParams _buildCreationParams() { } // Records the last created instance of itself. +// ignore: must_be_immutable class CapturingWebViewClient extends android_webview.WebViewClient { CapturingWebViewClient({ super.onPageFinished, @@ -460,6 +497,8 @@ class CapturingWebViewClient extends android_webview.WebViewClient { super.onReceivedRequestError, super.requestLoading, super.urlLoading, + super.binaryMessenger, + super.instanceManager, }) : super.detached() { lastCreatedDelegate = this; } @@ -480,6 +519,8 @@ class CapturingWebChromeClient extends android_webview.WebChromeClient { CapturingWebChromeClient({ super.onProgressChanged, super.onShowFileChooser, + super.binaryMessenger, + super.instanceManager, }) : super.detached() { lastCreatedDelegate = this; } @@ -491,6 +532,8 @@ class CapturingWebChromeClient extends android_webview.WebChromeClient { class CapturingDownloadListener extends android_webview.DownloadListener { CapturingDownloadListener({ required super.onDownloadStart, + super.binaryMessenger, + super.instanceManager, }) : super.detached() { lastCreatedListener = this; } 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 index 236d87da44e..2566d140ee0 100644 --- a/packages/webview_flutter/webview_flutter_android/test/android_webview_test.dart +++ b/packages/webview_flutter/webview_flutter_android/test/android_webview_test.dart @@ -493,10 +493,6 @@ void main() { true, )); }); - - test('copy', () { - expect(webSettings.copy(), isA()); - }); }); group('JavaScriptChannel', () { @@ -912,10 +908,6 @@ void main() { mockHostApi.setSynchronousReturnValueForOnShowFileChooser(3, true), ); }); - - test('copy', () { - expect(WebChromeClient.detached().copy(), isA()); - }); }); group('FileChooserParams', () { @@ -986,9 +978,5 @@ void main() { webStorage.deleteAllData(); verify(mockPlatformHostApi.deleteAllData(webStorageInstanceId)); }); - - test('copy', () { - expect(WebStorage.detached().copy(), isA()); - }); }); } From 10946208bcedb6d64adee373eb1f71e5b3411b0f Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Thu, 23 Feb 2023 10:23:32 -0500 Subject: [PATCH 03/24] update tests --- .../GeneratedAndroidWebView.java | 562 +++++++++++++----- .../legacy/webview_flutter_test.dart | 15 +- .../webview_flutter_test.dart | 17 +- .../lib/src/android_webview.dart | 40 +- .../test/android_webview_controller_test.dart | 11 +- .../test/android_webview_test.dart | 159 +++-- .../test/instance_manager_test.dart | 115 +++- .../test/test_android_webview.g.dart | 195 +++--- 8 files changed, 768 insertions(+), 346 deletions(-) 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 index b4e05f945b3..e72940de095 100644 --- 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 @@ -18,7 +18,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; -import java.util.HashMap; import java.util.List; import java.util.Map; @@ -31,33 +30,36 @@ private static ArrayList wrapError(@NonNull Throwable exception) { errorList.add(exception.toString()); errorList.add(exception.getClass().getSimpleName()); errorList.add( - "Cause: " + exception.getCause() + ", Stacktrace: " + Log.getStackTraceString(exception)); + "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. + *

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. + * 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. + *

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. + *

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. + *

See + * https://developer.android.com/reference/android/webkit/WebChromeClient.FileChooserParams#MODE_SAVE. */ SAVE(2); @@ -349,7 +351,10 @@ ArrayList toList() { 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)); + pigeonResult.setErrorCode( + (errorCode == null) + ? null + : ((errorCode instanceof Integer) ? (Integer) errorCode : (Long) errorCode)); Object description = list.get(1); pigeonResult.setDescription((String) description); return pigeonResult; @@ -437,13 +442,13 @@ public interface Result { /** * Host API for managing the native `InstanceManager`. * - * Generated interface from Pigeon that represents a handler of messages from Flutter. + *

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. + *

This is typically only used after a hot restart. */ void clear(); @@ -451,7 +456,10 @@ public interface InstanceManagerHostApi { static MessageCodec getCodec() { return new StandardMessageCodec(); } - /**Sets up an instance of `InstanceManagerHostApi` to handle messages through the `binaryMessenger`. */ + /** + * Sets up an instance of `InstanceManagerHostApi` to handle messages through the + * `binaryMessenger`. + */ static void setup(BinaryMessenger binaryMessenger, InstanceManagerHostApi api) { { BasicMessageChannel channel = @@ -479,11 +487,11 @@ static void setup(BinaryMessenger binaryMessenger, InstanceManagerHostApi api) { /** * Handles methods calls to the native Java Object class. * - * Also handles calls to remove the reference to an instance with `dispose`. + *

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. + *

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. + *

Generated interface from Pigeon that represents a handler of messages from Flutter. */ public interface JavaObjectHostApi { @@ -493,7 +501,9 @@ public interface JavaObjectHostApi { static MessageCodec getCodec() { return new StandardMessageCodec(); } - /**Sets up an instance of `JavaObjectHostApi` to handle messages through the `binaryMessenger`. */ + /** + * Sets up an instance of `JavaObjectHostApi` to handle messages through the `binaryMessenger`. + */ static void setup(BinaryMessenger binaryMessenger, JavaObjectHostApi api) { { BasicMessageChannel channel = @@ -527,9 +537,9 @@ static void setup(BinaryMessenger binaryMessenger, JavaObjectHostApi api) { /** * Handles callbacks methods for the native Java Object class. * - * See https://docs.oracle.com/javase/7/docs/api/java/lang/Object.html. + *

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. + *

Generated class from Pigeon that represents Flutter messages that can be called from Java. */ public static class JavaObjectFlutterApi { private final BinaryMessenger binaryMessenger; @@ -538,13 +548,15 @@ public JavaObjectFlutterApi(BinaryMessenger argBinaryMessenger) { this.binaryMessenger = argBinaryMessenger; } - /** Public interface for sending reply. */ public interface Reply { + /** Public interface for sending reply. */ + public interface Reply { void reply(T reply); } /** The codec used by JavaObjectFlutterApi. */ static MessageCodec getCodec() { return new StandardMessageCodec(); } + public void dispose(@NonNull Long identifierArg, Reply callback) { BasicMessageChannel channel = new BasicMessageChannel<>( @@ -565,18 +577,23 @@ public interface CookieManagerHostApi { static MessageCodec getCodec() { return new StandardMessageCodec(); } - /**Sets up an instance of `CookieManagerHostApi` to handle messages through the `binaryMessenger`. */ + /** + * Sets up an instance of `CookieManagerHostApi` to handle messages through the + * `binaryMessenger`. + */ static void setup(BinaryMessenger binaryMessenger, CookieManagerHostApi api) { { BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, "dev.flutter.pigeon.CookieManagerHostApi.clearCookies", getCodec()); + binaryMessenger, + "dev.flutter.pigeon.CookieManagerHostApi.clearCookies", + getCodec()); if (api != null) { channel.setMessageHandler( (message, reply) -> { ArrayList wrapped = new ArrayList(); try { - Result resultCallback = + Result resultCallback = new Result() { public void success(Boolean result) { wrapped.add(0, result); @@ -664,21 +681,32 @@ public interface WebViewHostApi { void create(@NonNull Long instanceId, @NonNull Boolean useHybridComposition); - void loadData(@NonNull Long instanceId, @NonNull String data, @Nullable String mimeType, @Nullable String encoding); + 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 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 loadUrl( + @NonNull Long instanceId, @NonNull String url, @NonNull Map headers); void postUrl(@NonNull Long instanceId, @NonNull String url, @NonNull byte[] data); - @Nullable + @Nullable String getUrl(@NonNull Long instanceId); - @NonNull + @NonNull Boolean canGoBack(@NonNull Long instanceId); - @NonNull + @NonNull Boolean canGoForward(@NonNull Long instanceId); void goBack(@NonNull Long instanceId); @@ -689,22 +717,23 @@ public interface WebViewHostApi { void clearCache(@NonNull Long instanceId, @NonNull Boolean includeDiskFiles); - void evaluateJavascript(@NonNull Long instanceId, @NonNull String javascriptString, Result result); + void evaluateJavascript( + @NonNull Long instanceId, @NonNull String javascriptString, Result result); - @Nullable + @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 + @NonNull Long getScrollX(@NonNull Long instanceId); - @NonNull + @NonNull Long getScrollY(@NonNull Long instanceId); - @NonNull + @NonNull WebViewPoint getScrollPosition(@NonNull Long instanceId); void setWebContentsDebuggingEnabled(@NonNull Boolean enabled); @@ -713,7 +742,8 @@ public interface WebViewHostApi { void addJavaScriptChannel(@NonNull Long instanceId, @NonNull Long javaScriptChannelInstanceId); - void removeJavaScriptChannel(@NonNull Long instanceId, @NonNull Long javaScriptChannelInstanceId); + void removeJavaScriptChannel( + @NonNull Long instanceId, @NonNull Long javaScriptChannelInstanceId); void setDownloadListener(@NonNull Long instanceId, @Nullable Long listenerInstanceId); @@ -725,7 +755,7 @@ public interface WebViewHostApi { static MessageCodec getCodec() { return WebViewHostApiCodec.INSTANCE; } - /**Sets up an instance of `WebViewHostApi` to handle messages through the `binaryMessenger`. */ + /** Sets up an instance of `WebViewHostApi` to handle messages through the `binaryMessenger`. */ static void setup(BinaryMessenger binaryMessenger, WebViewHostApi api) { { BasicMessageChannel channel = @@ -746,7 +776,9 @@ static void setup(BinaryMessenger binaryMessenger, WebViewHostApi api) { if (useHybridCompositionArg == null) { throw new NullPointerException("useHybridCompositionArg unexpectedly null."); } - api.create((instanceIdArg == null) ? null : instanceIdArg.longValue(), useHybridCompositionArg); + api.create( + (instanceIdArg == null) ? null : instanceIdArg.longValue(), + useHybridCompositionArg); wrapped.add(0, null); } catch (Error | RuntimeException exception) { ArrayList wrappedError = wrapError(exception); @@ -779,7 +811,11 @@ static void setup(BinaryMessenger binaryMessenger, WebViewHostApi api) { } String mimeTypeArg = (String) args.get(2); String encodingArg = (String) args.get(3); - api.loadData((instanceIdArg == null) ? null : instanceIdArg.longValue(), dataArg, mimeTypeArg, encodingArg); + api.loadData( + (instanceIdArg == null) ? null : instanceIdArg.longValue(), + dataArg, + mimeTypeArg, + encodingArg); wrapped.add(0, null); } catch (Error | RuntimeException exception) { ArrayList wrappedError = wrapError(exception); @@ -794,7 +830,9 @@ static void setup(BinaryMessenger binaryMessenger, WebViewHostApi api) { { BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, "dev.flutter.pigeon.WebViewHostApi.loadDataWithBaseUrl", getCodec()); + binaryMessenger, + "dev.flutter.pigeon.WebViewHostApi.loadDataWithBaseUrl", + getCodec()); if (api != null) { channel.setMessageHandler( (message, reply) -> { @@ -814,7 +852,13 @@ static void setup(BinaryMessenger binaryMessenger, WebViewHostApi api) { String mimeTypeArg = (String) args.get(3); String encodingArg = (String) args.get(4); String historyUrlArg = (String) args.get(5); - api.loadDataWithBaseUrl((instanceIdArg == null) ? null : instanceIdArg.longValue(), baseUrlArg, dataArg, mimeTypeArg, encodingArg, historyUrlArg); + api.loadDataWithBaseUrl( + (instanceIdArg == null) ? null : instanceIdArg.longValue(), + baseUrlArg, + dataArg, + mimeTypeArg, + encodingArg, + historyUrlArg); wrapped.add(0, null); } catch (Error | RuntimeException exception) { ArrayList wrappedError = wrapError(exception); @@ -849,7 +893,10 @@ static void setup(BinaryMessenger binaryMessenger, WebViewHostApi api) { if (headersArg == null) { throw new NullPointerException("headersArg unexpectedly null."); } - api.loadUrl((instanceIdArg == null) ? null : instanceIdArg.longValue(), urlArg, headersArg); + api.loadUrl( + (instanceIdArg == null) ? null : instanceIdArg.longValue(), + urlArg, + headersArg); wrapped.add(0, null); } catch (Error | RuntimeException exception) { ArrayList wrappedError = wrapError(exception); @@ -884,7 +931,8 @@ static void setup(BinaryMessenger binaryMessenger, WebViewHostApi api) { if (dataArg == null) { throw new NullPointerException("dataArg unexpectedly null."); } - api.postUrl((instanceIdArg == null) ? null : instanceIdArg.longValue(), urlArg, dataArg); + api.postUrl( + (instanceIdArg == null) ? null : instanceIdArg.longValue(), urlArg, dataArg); wrapped.add(0, null); } catch (Error | RuntimeException exception) { ArrayList wrappedError = wrapError(exception); @@ -911,7 +959,8 @@ static void setup(BinaryMessenger binaryMessenger, WebViewHostApi api) { if (instanceIdArg == null) { throw new NullPointerException("instanceIdArg unexpectedly null."); } - String output = api.getUrl((instanceIdArg == null) ? null : instanceIdArg.longValue()); + String output = + api.getUrl((instanceIdArg == null) ? null : instanceIdArg.longValue()); wrapped.add(0, output); } catch (Error | RuntimeException exception) { ArrayList wrappedError = wrapError(exception); @@ -938,7 +987,8 @@ static void setup(BinaryMessenger binaryMessenger, WebViewHostApi api) { if (instanceIdArg == null) { throw new NullPointerException("instanceIdArg unexpectedly null."); } - Boolean output = api.canGoBack((instanceIdArg == null) ? null : instanceIdArg.longValue()); + Boolean output = + api.canGoBack((instanceIdArg == null) ? null : instanceIdArg.longValue()); wrapped.add(0, output); } catch (Error | RuntimeException exception) { ArrayList wrappedError = wrapError(exception); @@ -965,7 +1015,8 @@ static void setup(BinaryMessenger binaryMessenger, WebViewHostApi api) { if (instanceIdArg == null) { throw new NullPointerException("instanceIdArg unexpectedly null."); } - Boolean output = api.canGoForward((instanceIdArg == null) ? null : instanceIdArg.longValue()); + Boolean output = + api.canGoForward((instanceIdArg == null) ? null : instanceIdArg.longValue()); wrapped.add(0, output); } catch (Error | RuntimeException exception) { ArrayList wrappedError = wrapError(exception); @@ -1077,7 +1128,9 @@ static void setup(BinaryMessenger binaryMessenger, WebViewHostApi api) { if (includeDiskFilesArg == null) { throw new NullPointerException("includeDiskFilesArg unexpectedly null."); } - api.clearCache((instanceIdArg == null) ? null : instanceIdArg.longValue(), includeDiskFilesArg); + api.clearCache( + (instanceIdArg == null) ? null : instanceIdArg.longValue(), + includeDiskFilesArg); wrapped.add(0, null); } catch (Error | RuntimeException exception) { ArrayList wrappedError = wrapError(exception); @@ -1092,7 +1145,9 @@ static void setup(BinaryMessenger binaryMessenger, WebViewHostApi api) { { BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, "dev.flutter.pigeon.WebViewHostApi.evaluateJavascript", getCodec()); + binaryMessenger, + "dev.flutter.pigeon.WebViewHostApi.evaluateJavascript", + getCodec()); if (api != null) { channel.setMessageHandler( (message, reply) -> { @@ -1108,7 +1163,7 @@ static void setup(BinaryMessenger binaryMessenger, WebViewHostApi api) { if (javascriptStringArg == null) { throw new NullPointerException("javascriptStringArg unexpectedly null."); } - Result resultCallback = + Result resultCallback = new Result() { public void success(String result) { wrapped.add(0, result); @@ -1121,7 +1176,10 @@ public void error(Throwable error) { } }; - api.evaluateJavascript((instanceIdArg == null) ? null : instanceIdArg.longValue(), javascriptStringArg, resultCallback); + api.evaluateJavascript( + (instanceIdArg == null) ? null : instanceIdArg.longValue(), + javascriptStringArg, + resultCallback); } catch (Error | RuntimeException exception) { ArrayList wrappedError = wrapError(exception); reply.reply(wrappedError); @@ -1146,7 +1204,8 @@ public void error(Throwable error) { if (instanceIdArg == null) { throw new NullPointerException("instanceIdArg unexpectedly null."); } - String output = api.getTitle((instanceIdArg == null) ? null : instanceIdArg.longValue()); + String output = + api.getTitle((instanceIdArg == null) ? null : instanceIdArg.longValue()); wrapped.add(0, output); } catch (Error | RuntimeException exception) { ArrayList wrappedError = wrapError(exception); @@ -1181,7 +1240,10 @@ public void error(Throwable error) { if (yArg == null) { throw new NullPointerException("yArg unexpectedly null."); } - api.scrollTo((instanceIdArg == null) ? null : instanceIdArg.longValue(), (xArg == null) ? null : xArg.longValue(), (yArg == null) ? null : yArg.longValue()); + api.scrollTo( + (instanceIdArg == null) ? null : instanceIdArg.longValue(), + (xArg == null) ? null : xArg.longValue(), + (yArg == null) ? null : yArg.longValue()); wrapped.add(0, null); } catch (Error | RuntimeException exception) { ArrayList wrappedError = wrapError(exception); @@ -1216,7 +1278,10 @@ public void error(Throwable error) { if (yArg == null) { throw new NullPointerException("yArg unexpectedly null."); } - api.scrollBy((instanceIdArg == null) ? null : instanceIdArg.longValue(), (xArg == null) ? null : xArg.longValue(), (yArg == null) ? null : yArg.longValue()); + api.scrollBy( + (instanceIdArg == null) ? null : instanceIdArg.longValue(), + (xArg == null) ? null : xArg.longValue(), + (yArg == null) ? null : yArg.longValue()); wrapped.add(0, null); } catch (Error | RuntimeException exception) { ArrayList wrappedError = wrapError(exception); @@ -1243,7 +1308,8 @@ public void error(Throwable error) { if (instanceIdArg == null) { throw new NullPointerException("instanceIdArg unexpectedly null."); } - Long output = api.getScrollX((instanceIdArg == null) ? null : instanceIdArg.longValue()); + Long output = + api.getScrollX((instanceIdArg == null) ? null : instanceIdArg.longValue()); wrapped.add(0, output); } catch (Error | RuntimeException exception) { ArrayList wrappedError = wrapError(exception); @@ -1270,7 +1336,8 @@ public void error(Throwable error) { if (instanceIdArg == null) { throw new NullPointerException("instanceIdArg unexpectedly null."); } - Long output = api.getScrollY((instanceIdArg == null) ? null : instanceIdArg.longValue()); + Long output = + api.getScrollY((instanceIdArg == null) ? null : instanceIdArg.longValue()); wrapped.add(0, output); } catch (Error | RuntimeException exception) { ArrayList wrappedError = wrapError(exception); @@ -1297,7 +1364,9 @@ public void error(Throwable error) { if (instanceIdArg == null) { throw new NullPointerException("instanceIdArg unexpectedly null."); } - WebViewPoint output = api.getScrollPosition((instanceIdArg == null) ? null : instanceIdArg.longValue()); + WebViewPoint output = + api.getScrollPosition( + (instanceIdArg == null) ? null : instanceIdArg.longValue()); wrapped.add(0, output); } catch (Error | RuntimeException exception) { ArrayList wrappedError = wrapError(exception); @@ -1312,7 +1381,9 @@ public void error(Throwable error) { { BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, "dev.flutter.pigeon.WebViewHostApi.setWebContentsDebuggingEnabled", getCodec()); + binaryMessenger, + "dev.flutter.pigeon.WebViewHostApi.setWebContentsDebuggingEnabled", + getCodec()); if (api != null) { channel.setMessageHandler( (message, reply) -> { @@ -1355,7 +1426,11 @@ public void error(Throwable error) { if (webViewClientInstanceIdArg == null) { throw new NullPointerException("webViewClientInstanceIdArg unexpectedly null."); } - api.setWebViewClient((instanceIdArg == null) ? null : instanceIdArg.longValue(), (webViewClientInstanceIdArg == null) ? null : webViewClientInstanceIdArg.longValue()); + api.setWebViewClient( + (instanceIdArg == null) ? null : instanceIdArg.longValue(), + (webViewClientInstanceIdArg == null) + ? null + : webViewClientInstanceIdArg.longValue()); wrapped.add(0, null); } catch (Error | RuntimeException exception) { ArrayList wrappedError = wrapError(exception); @@ -1370,7 +1445,9 @@ public void error(Throwable error) { { BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, "dev.flutter.pigeon.WebViewHostApi.addJavaScriptChannel", getCodec()); + binaryMessenger, + "dev.flutter.pigeon.WebViewHostApi.addJavaScriptChannel", + getCodec()); if (api != null) { channel.setMessageHandler( (message, reply) -> { @@ -1384,9 +1461,14 @@ public void error(Throwable error) { } Number javaScriptChannelInstanceIdArg = (Number) args.get(1); if (javaScriptChannelInstanceIdArg == null) { - throw new NullPointerException("javaScriptChannelInstanceIdArg unexpectedly null."); - } - api.addJavaScriptChannel((instanceIdArg == null) ? null : instanceIdArg.longValue(), (javaScriptChannelInstanceIdArg == null) ? null : javaScriptChannelInstanceIdArg.longValue()); + throw new NullPointerException( + "javaScriptChannelInstanceIdArg unexpectedly null."); + } + api.addJavaScriptChannel( + (instanceIdArg == null) ? null : instanceIdArg.longValue(), + (javaScriptChannelInstanceIdArg == null) + ? null + : javaScriptChannelInstanceIdArg.longValue()); wrapped.add(0, null); } catch (Error | RuntimeException exception) { ArrayList wrappedError = wrapError(exception); @@ -1401,7 +1483,9 @@ public void error(Throwable error) { { BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, "dev.flutter.pigeon.WebViewHostApi.removeJavaScriptChannel", getCodec()); + binaryMessenger, + "dev.flutter.pigeon.WebViewHostApi.removeJavaScriptChannel", + getCodec()); if (api != null) { channel.setMessageHandler( (message, reply) -> { @@ -1415,9 +1499,14 @@ public void error(Throwable error) { } Number javaScriptChannelInstanceIdArg = (Number) args.get(1); if (javaScriptChannelInstanceIdArg == null) { - throw new NullPointerException("javaScriptChannelInstanceIdArg unexpectedly null."); - } - api.removeJavaScriptChannel((instanceIdArg == null) ? null : instanceIdArg.longValue(), (javaScriptChannelInstanceIdArg == null) ? null : javaScriptChannelInstanceIdArg.longValue()); + throw new NullPointerException( + "javaScriptChannelInstanceIdArg unexpectedly null."); + } + api.removeJavaScriptChannel( + (instanceIdArg == null) ? null : instanceIdArg.longValue(), + (javaScriptChannelInstanceIdArg == null) + ? null + : javaScriptChannelInstanceIdArg.longValue()); wrapped.add(0, null); } catch (Error | RuntimeException exception) { ArrayList wrappedError = wrapError(exception); @@ -1432,7 +1521,9 @@ public void error(Throwable error) { { BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, "dev.flutter.pigeon.WebViewHostApi.setDownloadListener", getCodec()); + binaryMessenger, + "dev.flutter.pigeon.WebViewHostApi.setDownloadListener", + getCodec()); if (api != null) { channel.setMessageHandler( (message, reply) -> { @@ -1445,7 +1536,9 @@ public void error(Throwable error) { throw new NullPointerException("instanceIdArg unexpectedly null."); } Number listenerInstanceIdArg = (Number) args.get(1); - api.setDownloadListener((instanceIdArg == null) ? null : instanceIdArg.longValue(), (listenerInstanceIdArg == null) ? null : listenerInstanceIdArg.longValue()); + api.setDownloadListener( + (instanceIdArg == null) ? null : instanceIdArg.longValue(), + (listenerInstanceIdArg == null) ? null : listenerInstanceIdArg.longValue()); wrapped.add(0, null); } catch (Error | RuntimeException exception) { ArrayList wrappedError = wrapError(exception); @@ -1460,7 +1553,9 @@ public void error(Throwable error) { { BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, "dev.flutter.pigeon.WebViewHostApi.setWebChromeClient", getCodec()); + binaryMessenger, + "dev.flutter.pigeon.WebViewHostApi.setWebChromeClient", + getCodec()); if (api != null) { channel.setMessageHandler( (message, reply) -> { @@ -1473,7 +1568,9 @@ public void error(Throwable error) { throw new NullPointerException("instanceIdArg unexpectedly null."); } Number clientInstanceIdArg = (Number) args.get(1); - api.setWebChromeClient((instanceIdArg == null) ? null : instanceIdArg.longValue(), (clientInstanceIdArg == null) ? null : clientInstanceIdArg.longValue()); + api.setWebChromeClient( + (instanceIdArg == null) ? null : instanceIdArg.longValue(), + (clientInstanceIdArg == null) ? null : clientInstanceIdArg.longValue()); wrapped.add(0, null); } catch (Error | RuntimeException exception) { ArrayList wrappedError = wrapError(exception); @@ -1488,7 +1585,9 @@ public void error(Throwable error) { { BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, "dev.flutter.pigeon.WebViewHostApi.setBackgroundColor", getCodec()); + binaryMessenger, + "dev.flutter.pigeon.WebViewHostApi.setBackgroundColor", + getCodec()); if (api != null) { channel.setMessageHandler( (message, reply) -> { @@ -1504,7 +1603,9 @@ public void error(Throwable error) { if (colorArg == null) { throw new NullPointerException("colorArg unexpectedly null."); } - api.setBackgroundColor((instanceIdArg == null) ? null : instanceIdArg.longValue(), (colorArg == null) ? null : colorArg.longValue()); + api.setBackgroundColor( + (instanceIdArg == null) ? null : instanceIdArg.longValue(), + (colorArg == null) ? null : colorArg.longValue()); wrapped.add(0, null); } catch (Error | RuntimeException exception) { ArrayList wrappedError = wrapError(exception); @@ -1551,7 +1652,9 @@ public interface WebSettingsHostApi { static MessageCodec getCodec() { return new StandardMessageCodec(); } - /**Sets up an instance of `WebSettingsHostApi` to handle messages through the `binaryMessenger`. */ + /** + * Sets up an instance of `WebSettingsHostApi` to handle messages through the `binaryMessenger`. + */ static void setup(BinaryMessenger binaryMessenger, WebSettingsHostApi api) { { BasicMessageChannel channel = @@ -1572,7 +1675,9 @@ static void setup(BinaryMessenger binaryMessenger, WebSettingsHostApi api) { if (webViewInstanceIdArg == null) { throw new NullPointerException("webViewInstanceIdArg unexpectedly null."); } - api.create((instanceIdArg == null) ? null : instanceIdArg.longValue(), (webViewInstanceIdArg == null) ? null : webViewInstanceIdArg.longValue()); + api.create( + (instanceIdArg == null) ? null : instanceIdArg.longValue(), + (webViewInstanceIdArg == null) ? null : webViewInstanceIdArg.longValue()); wrapped.add(0, null); } catch (Error | RuntimeException exception) { ArrayList wrappedError = wrapError(exception); @@ -1587,7 +1692,9 @@ static void setup(BinaryMessenger binaryMessenger, WebSettingsHostApi api) { { BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, "dev.flutter.pigeon.WebSettingsHostApi.setDomStorageEnabled", getCodec()); + binaryMessenger, + "dev.flutter.pigeon.WebSettingsHostApi.setDomStorageEnabled", + getCodec()); if (api != null) { channel.setMessageHandler( (message, reply) -> { @@ -1603,7 +1710,8 @@ static void setup(BinaryMessenger binaryMessenger, WebSettingsHostApi api) { if (flagArg == null) { throw new NullPointerException("flagArg unexpectedly null."); } - api.setDomStorageEnabled((instanceIdArg == null) ? null : instanceIdArg.longValue(), flagArg); + api.setDomStorageEnabled( + (instanceIdArg == null) ? null : instanceIdArg.longValue(), flagArg); wrapped.add(0, null); } catch (Error | RuntimeException exception) { ArrayList wrappedError = wrapError(exception); @@ -1618,7 +1726,9 @@ static void setup(BinaryMessenger binaryMessenger, WebSettingsHostApi api) { { BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, "dev.flutter.pigeon.WebSettingsHostApi.setJavaScriptCanOpenWindowsAutomatically", getCodec()); + binaryMessenger, + "dev.flutter.pigeon.WebSettingsHostApi.setJavaScriptCanOpenWindowsAutomatically", + getCodec()); if (api != null) { channel.setMessageHandler( (message, reply) -> { @@ -1634,7 +1744,8 @@ static void setup(BinaryMessenger binaryMessenger, WebSettingsHostApi api) { if (flagArg == null) { throw new NullPointerException("flagArg unexpectedly null."); } - api.setJavaScriptCanOpenWindowsAutomatically((instanceIdArg == null) ? null : instanceIdArg.longValue(), flagArg); + api.setJavaScriptCanOpenWindowsAutomatically( + (instanceIdArg == null) ? null : instanceIdArg.longValue(), flagArg); wrapped.add(0, null); } catch (Error | RuntimeException exception) { ArrayList wrappedError = wrapError(exception); @@ -1649,7 +1760,9 @@ static void setup(BinaryMessenger binaryMessenger, WebSettingsHostApi api) { { BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, "dev.flutter.pigeon.WebSettingsHostApi.setSupportMultipleWindows", getCodec()); + binaryMessenger, + "dev.flutter.pigeon.WebSettingsHostApi.setSupportMultipleWindows", + getCodec()); if (api != null) { channel.setMessageHandler( (message, reply) -> { @@ -1665,7 +1778,8 @@ static void setup(BinaryMessenger binaryMessenger, WebSettingsHostApi api) { if (supportArg == null) { throw new NullPointerException("supportArg unexpectedly null."); } - api.setSupportMultipleWindows((instanceIdArg == null) ? null : instanceIdArg.longValue(), supportArg); + api.setSupportMultipleWindows( + (instanceIdArg == null) ? null : instanceIdArg.longValue(), supportArg); wrapped.add(0, null); } catch (Error | RuntimeException exception) { ArrayList wrappedError = wrapError(exception); @@ -1680,7 +1794,9 @@ static void setup(BinaryMessenger binaryMessenger, WebSettingsHostApi api) { { BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, "dev.flutter.pigeon.WebSettingsHostApi.setJavaScriptEnabled", getCodec()); + binaryMessenger, + "dev.flutter.pigeon.WebSettingsHostApi.setJavaScriptEnabled", + getCodec()); if (api != null) { channel.setMessageHandler( (message, reply) -> { @@ -1696,7 +1812,8 @@ static void setup(BinaryMessenger binaryMessenger, WebSettingsHostApi api) { if (flagArg == null) { throw new NullPointerException("flagArg unexpectedly null."); } - api.setJavaScriptEnabled((instanceIdArg == null) ? null : instanceIdArg.longValue(), flagArg); + api.setJavaScriptEnabled( + (instanceIdArg == null) ? null : instanceIdArg.longValue(), flagArg); wrapped.add(0, null); } catch (Error | RuntimeException exception) { ArrayList wrappedError = wrapError(exception); @@ -1711,7 +1828,9 @@ static void setup(BinaryMessenger binaryMessenger, WebSettingsHostApi api) { { BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, "dev.flutter.pigeon.WebSettingsHostApi.setUserAgentString", getCodec()); + binaryMessenger, + "dev.flutter.pigeon.WebSettingsHostApi.setUserAgentString", + getCodec()); if (api != null) { channel.setMessageHandler( (message, reply) -> { @@ -1724,7 +1843,9 @@ static void setup(BinaryMessenger binaryMessenger, WebSettingsHostApi api) { throw new NullPointerException("instanceIdArg unexpectedly null."); } String userAgentStringArg = (String) args.get(1); - api.setUserAgentString((instanceIdArg == null) ? null : instanceIdArg.longValue(), userAgentStringArg); + api.setUserAgentString( + (instanceIdArg == null) ? null : instanceIdArg.longValue(), + userAgentStringArg); wrapped.add(0, null); } catch (Error | RuntimeException exception) { ArrayList wrappedError = wrapError(exception); @@ -1739,7 +1860,9 @@ static void setup(BinaryMessenger binaryMessenger, WebSettingsHostApi api) { { BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, "dev.flutter.pigeon.WebSettingsHostApi.setMediaPlaybackRequiresUserGesture", getCodec()); + binaryMessenger, + "dev.flutter.pigeon.WebSettingsHostApi.setMediaPlaybackRequiresUserGesture", + getCodec()); if (api != null) { channel.setMessageHandler( (message, reply) -> { @@ -1755,7 +1878,8 @@ static void setup(BinaryMessenger binaryMessenger, WebSettingsHostApi api) { if (requireArg == null) { throw new NullPointerException("requireArg unexpectedly null."); } - api.setMediaPlaybackRequiresUserGesture((instanceIdArg == null) ? null : instanceIdArg.longValue(), requireArg); + api.setMediaPlaybackRequiresUserGesture( + (instanceIdArg == null) ? null : instanceIdArg.longValue(), requireArg); wrapped.add(0, null); } catch (Error | RuntimeException exception) { ArrayList wrappedError = wrapError(exception); @@ -1770,7 +1894,9 @@ static void setup(BinaryMessenger binaryMessenger, WebSettingsHostApi api) { { BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, "dev.flutter.pigeon.WebSettingsHostApi.setSupportZoom", getCodec()); + binaryMessenger, + "dev.flutter.pigeon.WebSettingsHostApi.setSupportZoom", + getCodec()); if (api != null) { channel.setMessageHandler( (message, reply) -> { @@ -1786,7 +1912,8 @@ static void setup(BinaryMessenger binaryMessenger, WebSettingsHostApi api) { if (supportArg == null) { throw new NullPointerException("supportArg unexpectedly null."); } - api.setSupportZoom((instanceIdArg == null) ? null : instanceIdArg.longValue(), supportArg); + api.setSupportZoom( + (instanceIdArg == null) ? null : instanceIdArg.longValue(), supportArg); wrapped.add(0, null); } catch (Error | RuntimeException exception) { ArrayList wrappedError = wrapError(exception); @@ -1801,7 +1928,9 @@ static void setup(BinaryMessenger binaryMessenger, WebSettingsHostApi api) { { BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, "dev.flutter.pigeon.WebSettingsHostApi.setLoadWithOverviewMode", getCodec()); + binaryMessenger, + "dev.flutter.pigeon.WebSettingsHostApi.setLoadWithOverviewMode", + getCodec()); if (api != null) { channel.setMessageHandler( (message, reply) -> { @@ -1817,7 +1946,8 @@ static void setup(BinaryMessenger binaryMessenger, WebSettingsHostApi api) { if (overviewArg == null) { throw new NullPointerException("overviewArg unexpectedly null."); } - api.setLoadWithOverviewMode((instanceIdArg == null) ? null : instanceIdArg.longValue(), overviewArg); + api.setLoadWithOverviewMode( + (instanceIdArg == null) ? null : instanceIdArg.longValue(), overviewArg); wrapped.add(0, null); } catch (Error | RuntimeException exception) { ArrayList wrappedError = wrapError(exception); @@ -1832,7 +1962,9 @@ static void setup(BinaryMessenger binaryMessenger, WebSettingsHostApi api) { { BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, "dev.flutter.pigeon.WebSettingsHostApi.setUseWideViewPort", getCodec()); + binaryMessenger, + "dev.flutter.pigeon.WebSettingsHostApi.setUseWideViewPort", + getCodec()); if (api != null) { channel.setMessageHandler( (message, reply) -> { @@ -1848,7 +1980,8 @@ static void setup(BinaryMessenger binaryMessenger, WebSettingsHostApi api) { if (useArg == null) { throw new NullPointerException("useArg unexpectedly null."); } - api.setUseWideViewPort((instanceIdArg == null) ? null : instanceIdArg.longValue(), useArg); + api.setUseWideViewPort( + (instanceIdArg == null) ? null : instanceIdArg.longValue(), useArg); wrapped.add(0, null); } catch (Error | RuntimeException exception) { ArrayList wrappedError = wrapError(exception); @@ -1863,7 +1996,9 @@ static void setup(BinaryMessenger binaryMessenger, WebSettingsHostApi api) { { BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, "dev.flutter.pigeon.WebSettingsHostApi.setDisplayZoomControls", getCodec()); + binaryMessenger, + "dev.flutter.pigeon.WebSettingsHostApi.setDisplayZoomControls", + getCodec()); if (api != null) { channel.setMessageHandler( (message, reply) -> { @@ -1879,7 +2014,8 @@ static void setup(BinaryMessenger binaryMessenger, WebSettingsHostApi api) { if (enabledArg == null) { throw new NullPointerException("enabledArg unexpectedly null."); } - api.setDisplayZoomControls((instanceIdArg == null) ? null : instanceIdArg.longValue(), enabledArg); + api.setDisplayZoomControls( + (instanceIdArg == null) ? null : instanceIdArg.longValue(), enabledArg); wrapped.add(0, null); } catch (Error | RuntimeException exception) { ArrayList wrappedError = wrapError(exception); @@ -1894,7 +2030,9 @@ static void setup(BinaryMessenger binaryMessenger, WebSettingsHostApi api) { { BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, "dev.flutter.pigeon.WebSettingsHostApi.setBuiltInZoomControls", getCodec()); + binaryMessenger, + "dev.flutter.pigeon.WebSettingsHostApi.setBuiltInZoomControls", + getCodec()); if (api != null) { channel.setMessageHandler( (message, reply) -> { @@ -1910,7 +2048,8 @@ static void setup(BinaryMessenger binaryMessenger, WebSettingsHostApi api) { if (enabledArg == null) { throw new NullPointerException("enabledArg unexpectedly null."); } - api.setBuiltInZoomControls((instanceIdArg == null) ? null : instanceIdArg.longValue(), enabledArg); + api.setBuiltInZoomControls( + (instanceIdArg == null) ? null : instanceIdArg.longValue(), enabledArg); wrapped.add(0, null); } catch (Error | RuntimeException exception) { ArrayList wrappedError = wrapError(exception); @@ -1925,7 +2064,9 @@ static void setup(BinaryMessenger binaryMessenger, WebSettingsHostApi api) { { BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, "dev.flutter.pigeon.WebSettingsHostApi.setAllowFileAccess", getCodec()); + binaryMessenger, + "dev.flutter.pigeon.WebSettingsHostApi.setAllowFileAccess", + getCodec()); if (api != null) { channel.setMessageHandler( (message, reply) -> { @@ -1941,7 +2082,8 @@ static void setup(BinaryMessenger binaryMessenger, WebSettingsHostApi api) { if (enabledArg == null) { throw new NullPointerException("enabledArg unexpectedly null."); } - api.setAllowFileAccess((instanceIdArg == null) ? null : instanceIdArg.longValue(), enabledArg); + api.setAllowFileAccess( + (instanceIdArg == null) ? null : instanceIdArg.longValue(), enabledArg); wrapped.add(0, null); } catch (Error | RuntimeException exception) { ArrayList wrappedError = wrapError(exception); @@ -1964,7 +2106,10 @@ public interface JavaScriptChannelHostApi { static MessageCodec getCodec() { return new StandardMessageCodec(); } - /**Sets up an instance of `JavaScriptChannelHostApi` to handle messages through the `binaryMessenger`. */ + /** + * Sets up an instance of `JavaScriptChannelHostApi` to handle messages through the + * `binaryMessenger`. + */ static void setup(BinaryMessenger binaryMessenger, JavaScriptChannelHostApi api) { { BasicMessageChannel channel = @@ -1985,7 +2130,8 @@ static void setup(BinaryMessenger binaryMessenger, JavaScriptChannelHostApi api) if (channelNameArg == null) { throw new NullPointerException("channelNameArg unexpectedly null."); } - api.create((instanceIdArg == null) ? null : instanceIdArg.longValue(), channelNameArg); + api.create( + (instanceIdArg == null) ? null : instanceIdArg.longValue(), channelNameArg); wrapped.add(0, null); } catch (Error | RuntimeException exception) { ArrayList wrappedError = wrapError(exception); @@ -2007,17 +2153,22 @@ public JavaScriptChannelFlutterApi(BinaryMessenger argBinaryMessenger) { this.binaryMessenger = argBinaryMessenger; } - /** Public interface for sending reply. */ public interface Reply { + /** Public interface for sending reply. */ + public interface Reply { void reply(T reply); } /** The codec used by JavaScriptChannelFlutterApi. */ static MessageCodec getCodec() { return new StandardMessageCodec(); } - public void postMessage(@NonNull Long instanceIdArg, @NonNull String messageArg, Reply callback) { + + public void postMessage( + @NonNull Long instanceIdArg, @NonNull String messageArg, Reply callback) { BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, "dev.flutter.pigeon.JavaScriptChannelFlutterApi.postMessage", getCodec()); + binaryMessenger, + "dev.flutter.pigeon.JavaScriptChannelFlutterApi.postMessage", + getCodec()); channel.send( new ArrayList(Arrays.asList(instanceIdArg, messageArg)), channelReply -> callback.reply(null)); @@ -2028,13 +2179,17 @@ public interface WebViewClientHostApi { void create(@NonNull Long instanceId); - void setSynchronousReturnValueForShouldOverrideUrlLoading(@NonNull Long instanceId, @NonNull Boolean value); + void setSynchronousReturnValueForShouldOverrideUrlLoading( + @NonNull Long instanceId, @NonNull Boolean value); /** The codec used by WebViewClientHostApi. */ static MessageCodec getCodec() { return new StandardMessageCodec(); } - /**Sets up an instance of `WebViewClientHostApi` to handle messages through the `binaryMessenger`. */ + /** + * Sets up an instance of `WebViewClientHostApi` to handle messages through the + * `binaryMessenger`. + */ static void setup(BinaryMessenger binaryMessenger, WebViewClientHostApi api) { { BasicMessageChannel channel = @@ -2066,7 +2221,9 @@ static void setup(BinaryMessenger binaryMessenger, WebViewClientHostApi api) { { BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, "dev.flutter.pigeon.WebViewClientHostApi.setSynchronousReturnValueForShouldOverrideUrlLoading", getCodec()); + binaryMessenger, + "dev.flutter.pigeon.WebViewClientHostApi.setSynchronousReturnValueForShouldOverrideUrlLoading", + getCodec()); if (api != null) { channel.setMessageHandler( (message, reply) -> { @@ -2082,7 +2239,8 @@ static void setup(BinaryMessenger binaryMessenger, WebViewClientHostApi api) { if (valueArg == null) { throw new NullPointerException("valueArg unexpectedly null."); } - api.setSynchronousReturnValueForShouldOverrideUrlLoading((instanceIdArg == null) ? null : instanceIdArg.longValue(), valueArg); + api.setSynchronousReturnValueForShouldOverrideUrlLoading( + (instanceIdArg == null) ? null : instanceIdArg.longValue(), valueArg); wrapped.add(0, null); } catch (Error | RuntimeException exception) { ArrayList wrappedError = wrapError(exception); @@ -2136,54 +2294,105 @@ public WebViewClientFlutterApi(BinaryMessenger argBinaryMessenger) { this.binaryMessenger = argBinaryMessenger; } - /** Public interface for sending reply. */ public interface Reply { + /** Public interface for sending reply. */ + public interface Reply { void reply(T reply); } /** The codec used by WebViewClientFlutterApi. */ static MessageCodec getCodec() { return WebViewClientFlutterApiCodec.INSTANCE; } - public void onPageStarted(@NonNull Long instanceIdArg, @NonNull Long webViewInstanceIdArg, @NonNull String urlArg, Reply callback) { + + public void onPageStarted( + @NonNull Long instanceIdArg, + @NonNull Long webViewInstanceIdArg, + @NonNull String urlArg, + Reply callback) { BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, "dev.flutter.pigeon.WebViewClientFlutterApi.onPageStarted", getCodec()); + binaryMessenger, + "dev.flutter.pigeon.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, Reply callback) { + + public void onPageFinished( + @NonNull Long instanceIdArg, + @NonNull Long webViewInstanceIdArg, + @NonNull String urlArg, + Reply callback) { BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, "dev.flutter.pigeon.WebViewClientFlutterApi.onPageFinished", getCodec()); + binaryMessenger, + "dev.flutter.pigeon.WebViewClientFlutterApi.onPageFinished", + getCodec()); channel.send( new ArrayList(Arrays.asList(instanceIdArg, webViewInstanceIdArg, urlArg)), channelReply -> callback.reply(null)); } - public void onReceivedRequestError(@NonNull Long instanceIdArg, @NonNull Long webViewInstanceIdArg, @NonNull WebResourceRequestData requestArg, @NonNull WebResourceErrorData errorArg, Reply callback) { + + public void onReceivedRequestError( + @NonNull Long instanceIdArg, + @NonNull Long webViewInstanceIdArg, + @NonNull WebResourceRequestData requestArg, + @NonNull WebResourceErrorData errorArg, + Reply callback) { BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, "dev.flutter.pigeon.WebViewClientFlutterApi.onReceivedRequestError", getCodec()); + binaryMessenger, + "dev.flutter.pigeon.WebViewClientFlutterApi.onReceivedRequestError", + getCodec()); channel.send( - new ArrayList(Arrays.asList(instanceIdArg, webViewInstanceIdArg, requestArg, errorArg)), + 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, Reply callback) { + + public void onReceivedError( + @NonNull Long instanceIdArg, + @NonNull Long webViewInstanceIdArg, + @NonNull Long errorCodeArg, + @NonNull String descriptionArg, + @NonNull String failingUrlArg, + Reply callback) { BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, "dev.flutter.pigeon.WebViewClientFlutterApi.onReceivedError", getCodec()); + binaryMessenger, + "dev.flutter.pigeon.WebViewClientFlutterApi.onReceivedError", + getCodec()); channel.send( - new ArrayList(Arrays.asList(instanceIdArg, webViewInstanceIdArg, errorCodeArg, descriptionArg, failingUrlArg)), + 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, Reply callback) { + + public void requestLoading( + @NonNull Long instanceIdArg, + @NonNull Long webViewInstanceIdArg, + @NonNull WebResourceRequestData requestArg, + Reply callback) { BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, "dev.flutter.pigeon.WebViewClientFlutterApi.requestLoading", getCodec()); + binaryMessenger, + "dev.flutter.pigeon.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, Reply callback) { + + public void urlLoading( + @NonNull Long instanceIdArg, + @NonNull Long webViewInstanceIdArg, + @NonNull String urlArg, + Reply callback) { BasicMessageChannel channel = new BasicMessageChannel<>( binaryMessenger, "dev.flutter.pigeon.WebViewClientFlutterApi.urlLoading", getCodec()); @@ -2201,7 +2410,10 @@ public interface DownloadListenerHostApi { static MessageCodec getCodec() { return new StandardMessageCodec(); } - /**Sets up an instance of `DownloadListenerHostApi` to handle messages through the `binaryMessenger`. */ + /** + * Sets up an instance of `DownloadListenerHostApi` to handle messages through the + * `binaryMessenger`. + */ static void setup(BinaryMessenger binaryMessenger, DownloadListenerHostApi api) { { BasicMessageChannel channel = @@ -2240,19 +2452,37 @@ public DownloadListenerFlutterApi(BinaryMessenger argBinaryMessenger) { this.binaryMessenger = argBinaryMessenger; } - /** Public interface for sending reply. */ public interface Reply { + /** Public interface for sending reply. */ + public interface Reply { void reply(T reply); } /** The codec used by DownloadListenerFlutterApi. */ static 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, Reply callback) { + + public void onDownloadStart( + @NonNull Long instanceIdArg, + @NonNull String urlArg, + @NonNull String userAgentArg, + @NonNull String contentDispositionArg, + @NonNull String mimetypeArg, + @NonNull Long contentLengthArg, + Reply callback) { BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, "dev.flutter.pigeon.DownloadListenerFlutterApi.onDownloadStart", getCodec()); + binaryMessenger, + "dev.flutter.pigeon.DownloadListenerFlutterApi.onDownloadStart", + getCodec()); channel.send( - new ArrayList(Arrays.asList(instanceIdArg, urlArg, userAgentArg, contentDispositionArg, mimetypeArg, contentLengthArg)), + new ArrayList( + Arrays.asList( + instanceIdArg, + urlArg, + userAgentArg, + contentDispositionArg, + mimetypeArg, + contentLengthArg)), channelReply -> callback.reply(null)); } } @@ -2261,13 +2491,17 @@ public interface WebChromeClientHostApi { void create(@NonNull Long instanceId); - void setSynchronousReturnValueForOnShowFileChooser(@NonNull Long instanceId, @NonNull Boolean value); + void setSynchronousReturnValueForOnShowFileChooser( + @NonNull Long instanceId, @NonNull Boolean value); /** The codec used by WebChromeClientHostApi. */ static MessageCodec getCodec() { return new StandardMessageCodec(); } - /**Sets up an instance of `WebChromeClientHostApi` to handle messages through the `binaryMessenger`. */ + /** + * Sets up an instance of `WebChromeClientHostApi` to handle messages through the + * `binaryMessenger`. + */ static void setup(BinaryMessenger binaryMessenger, WebChromeClientHostApi api) { { BasicMessageChannel channel = @@ -2299,7 +2533,9 @@ static void setup(BinaryMessenger binaryMessenger, WebChromeClientHostApi api) { { BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, "dev.flutter.pigeon.WebChromeClientHostApi.setSynchronousReturnValueForOnShowFileChooser", getCodec()); + binaryMessenger, + "dev.flutter.pigeon.WebChromeClientHostApi.setSynchronousReturnValueForOnShowFileChooser", + getCodec()); if (api != null) { channel.setMessageHandler( (message, reply) -> { @@ -2315,7 +2551,8 @@ static void setup(BinaryMessenger binaryMessenger, WebChromeClientHostApi api) { if (valueArg == null) { throw new NullPointerException("valueArg unexpectedly null."); } - api.setSynchronousReturnValueForOnShowFileChooser((instanceIdArg == null) ? null : instanceIdArg.longValue(), valueArg); + api.setSynchronousReturnValueForOnShowFileChooser( + (instanceIdArg == null) ? null : instanceIdArg.longValue(), valueArg); wrapped.add(0, null); } catch (Error | RuntimeException exception) { ArrayList wrappedError = wrapError(exception); @@ -2332,17 +2569,20 @@ static void setup(BinaryMessenger binaryMessenger, WebChromeClientHostApi api) { /** Generated interface from Pigeon that represents a handler of messages from Flutter. */ public interface FlutterAssetManagerHostApi { - @NonNull + @NonNull List list(@NonNull String path); - @NonNull + @NonNull String getAssetFilePathByName(@NonNull String name); /** The codec used by FlutterAssetManagerHostApi. */ static MessageCodec getCodec() { return new StandardMessageCodec(); } - /**Sets up an instance of `FlutterAssetManagerHostApi` to handle messages through the `binaryMessenger`. */ + /** + * Sets up an instance of `FlutterAssetManagerHostApi` to handle messages through the + * `binaryMessenger`. + */ static void setup(BinaryMessenger binaryMessenger, FlutterAssetManagerHostApi api) { { BasicMessageChannel channel = @@ -2374,7 +2614,9 @@ static void setup(BinaryMessenger binaryMessenger, FlutterAssetManagerHostApi ap { BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, "dev.flutter.pigeon.FlutterAssetManagerHostApi.getAssetFilePathByName", getCodec()); + binaryMessenger, + "dev.flutter.pigeon.FlutterAssetManagerHostApi.getAssetFilePathByName", + getCodec()); if (api != null) { channel.setMessageHandler( (message, reply) -> { @@ -2408,27 +2650,43 @@ public WebChromeClientFlutterApi(BinaryMessenger argBinaryMessenger) { this.binaryMessenger = argBinaryMessenger; } - /** Public interface for sending reply. */ public interface Reply { + /** Public interface for sending reply. */ + public interface Reply { void reply(T reply); } /** The codec used by WebChromeClientFlutterApi. */ static MessageCodec getCodec() { return new StandardMessageCodec(); } - public void onProgressChanged(@NonNull Long instanceIdArg, @NonNull Long webViewInstanceIdArg, @NonNull Long progressArg, Reply callback) { + + public void onProgressChanged( + @NonNull Long instanceIdArg, + @NonNull Long webViewInstanceIdArg, + @NonNull Long progressArg, + Reply callback) { BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, "dev.flutter.pigeon.WebChromeClientFlutterApi.onProgressChanged", getCodec()); + binaryMessenger, + "dev.flutter.pigeon.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, Reply> callback) { + + public void onShowFileChooser( + @NonNull Long instanceIdArg, + @NonNull Long webViewInstanceIdArg, + @NonNull Long paramsInstanceIdArg, + Reply> callback) { BasicMessageChannel channel = new BasicMessageChannel<>( - binaryMessenger, "dev.flutter.pigeon.WebChromeClientFlutterApi.onShowFileChooser", getCodec()); + binaryMessenger, + "dev.flutter.pigeon.WebChromeClientFlutterApi.onShowFileChooser", + getCodec()); channel.send( - new ArrayList(Arrays.asList(instanceIdArg, webViewInstanceIdArg, paramsInstanceIdArg)), + new ArrayList( + Arrays.asList(instanceIdArg, webViewInstanceIdArg, paramsInstanceIdArg)), channelReply -> { @SuppressWarnings("ConstantConditions") List output = (List) channelReply; @@ -2447,7 +2705,9 @@ public interface WebStorageHostApi { static MessageCodec getCodec() { return new StandardMessageCodec(); } - /**Sets up an instance of `WebStorageHostApi` to handle messages through the `binaryMessenger`. */ + /** + * Sets up an instance of `WebStorageHostApi` to handle messages through the `binaryMessenger`. + */ static void setup(BinaryMessenger binaryMessenger, WebStorageHostApi api) { { BasicMessageChannel channel = @@ -2507,7 +2767,8 @@ static void setup(BinaryMessenger binaryMessenger, WebStorageHostApi api) { } private static class FileChooserParamsFlutterApiCodec extends StandardMessageCodec { - public static final FileChooserParamsFlutterApiCodec INSTANCE = new FileChooserParamsFlutterApiCodec(); + public static final FileChooserParamsFlutterApiCodec INSTANCE = + new FileChooserParamsFlutterApiCodec(); private FileChooserParamsFlutterApiCodec() {} @@ -2535,9 +2796,10 @@ protected void writeValue(@NonNull ByteArrayOutputStream stream, Object value) { /** * Handles callbacks methods for the native Java FileChooserParams class. * - * See https://developer.android.com/reference/android/webkit/WebChromeClient.FileChooserParams. + *

See + * https://developer.android.com/reference/android/webkit/WebChromeClient.FileChooserParams. * - * Generated class from Pigeon that represents Flutter messages that can be called from Java. + *

Generated class from Pigeon that represents Flutter messages that can be called from Java. */ public static class FileChooserParamsFlutterApi { private final BinaryMessenger binaryMessenger; @@ -2546,19 +2808,29 @@ public FileChooserParamsFlutterApi(BinaryMessenger argBinaryMessenger) { this.binaryMessenger = argBinaryMessenger; } - /** Public interface for sending reply. */ public interface Reply { + /** Public interface for sending reply. */ + public interface Reply { void reply(T reply); } /** The codec used by FileChooserParamsFlutterApi. */ static MessageCodec getCodec() { return FileChooserParamsFlutterApiCodec.INSTANCE; } - public void create(@NonNull Long instanceIdArg, @NonNull Boolean isCaptureEnabledArg, @NonNull List acceptTypesArg, @NonNull FileChooserModeEnumData modeArg, @Nullable String filenameHintArg, Reply callback) { + + public void create( + @NonNull Long instanceIdArg, + @NonNull Boolean isCaptureEnabledArg, + @NonNull List acceptTypesArg, + @NonNull FileChooserModeEnumData modeArg, + @Nullable String filenameHintArg, + Reply callback) { BasicMessageChannel channel = new BasicMessageChannel<>( binaryMessenger, "dev.flutter.pigeon.FileChooserParamsFlutterApi.create", getCodec()); channel.send( - new ArrayList(Arrays.asList(instanceIdArg, isCaptureEnabledArg, acceptTypesArg, modeArg, filenameHintArg)), + new ArrayList( + Arrays.asList( + instanceIdArg, isCaptureEnabledArg, acceptTypesArg, modeArg, filenameHintArg)), channelReply -> callback.reply(null)); } } diff --git a/packages/webview_flutter/webview_flutter_android/example/integration_test/legacy/webview_flutter_test.dart b/packages/webview_flutter/webview_flutter_android/example/integration_test/legacy/webview_flutter_test.dart index cbec6b76795..f3688313834 100644 --- a/packages/webview_flutter/webview_flutter_android/example/integration_test/legacy/webview_flutter_test.dart +++ b/packages/webview_flutter/webview_flutter_android/example/integration_test/legacy/webview_flutter_test.dart @@ -113,7 +113,13 @@ Future main() async { ); ClassWithCallbackClass? instance = ClassWithCallbackClass(); - instanceManager.addHostCreatedInstance(instance.callbackClass, 0); + instanceManager.addHostCreatedInstance( + instance.callbackClass, + 0, + onCopy: (CopyableObjectWithCallback original) { + return CopyableObjectWithCallback(original.callback); + }, + ); instance = null; // Force garbage collection. @@ -1543,15 +1549,10 @@ class ResizableWebViewState extends State { } } -class CopyableObjectWithCallback with Copyable { +class CopyableObjectWithCallback { CopyableObjectWithCallback(this.callback); final VoidCallback callback; - - @override - CopyableObjectWithCallback copy() { - return CopyableObjectWithCallback(callback); - } } class ClassWithCallbackClass { 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 af144e55efb..917870b6b4f 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 @@ -83,7 +83,13 @@ Future main() async { ); ClassWithCallbackClass? instance = ClassWithCallbackClass(); - instanceManager.addHostCreatedInstance(instance.callbackClass, 0); + instanceManager.addHostCreatedInstance( + instance.callbackClass, + 0, + onCopy: (CopyableObjectWithCallback original) { + return CopyableObjectWithCallback(original.callback); + }, + ); instance = null; // Force garbage collection. @@ -104,7 +110,7 @@ Future main() async { late final InstanceManager instanceManager; instanceManager = InstanceManager(onWeakReferenceRemoved: (int identifier) { - final Copyable instance = + final Object instance = instanceManager.getInstanceWithWeakReference(identifier)!; if (instance is android.WebView && !webViewGCCompleter.isCompleted) { webViewGCCompleter.complete(); @@ -1222,15 +1228,10 @@ class ResizableWebViewState extends State { } } -class CopyableObjectWithCallback with Copyable { +class CopyableObjectWithCallback { CopyableObjectWithCallback(this.callback); final VoidCallback callback; - - @override - CopyableObjectWithCallback copy() { - return CopyableObjectWithCallback(callback); - } } class ClassWithCallbackClass { 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 index ed424ea902c..ef930e55982 100644 --- a/packages/webview_flutter/webview_flutter_android/lib/src/android_webview.dart +++ b/packages/webview_flutter/webview_flutter_android/lib/src/android_webview.dart @@ -34,8 +34,8 @@ class JavaObject { /// create copies. @protected JavaObject.detached({ - required BinaryMessenger? binaryMessenger, - required InstanceManager? instanceManager, + BinaryMessenger? binaryMessenger, + InstanceManager? instanceManager, }) : _api = JavaObjectHostApiImpl( binaryMessenger: binaryMessenger, instanceManager: instanceManager, @@ -108,8 +108,8 @@ class WebView extends JavaObject { @protected WebView.detached({ this.useHybridComposition = false, - required super.binaryMessenger, - required super.instanceManager, + super.binaryMessenger, + super.instanceManager, }) : super.detached(); /// Pigeon Host Api implementation for [WebView]. @@ -487,8 +487,8 @@ class WebSettings extends JavaObject { /// create copies. @protected WebSettings.detached({ - required super.binaryMessenger, - required super.instanceManager, + super.binaryMessenger, + super.instanceManager, }) : super.detached(); /// Pigeon Host Api implementation for [WebSettings]. @@ -639,8 +639,8 @@ class JavaScriptChannel extends JavaObject { JavaScriptChannel.detached( this.channelName, { required this.postMessage, - required super.binaryMessenger, - required super.instanceManager, + super.binaryMessenger, + super.instanceManager, }) : super.detached(); /// Pigeon Host Api implementation for [JavaScriptChannel]. @@ -684,8 +684,8 @@ class WebViewClient extends JavaObject { @Deprecated('Only called on Android version < 23.') this.onReceivedError, this.requestLoading, this.urlLoading, - required super.binaryMessenger, - required super.instanceManager, + super.binaryMessenger, + super.instanceManager, }) : super.detached(); /// User authentication failed on server. @@ -869,8 +869,8 @@ class DownloadListener extends JavaObject { @protected DownloadListener.detached({ required this.onDownloadStart, - required super.binaryMessenger, - required super.instanceManager, + super.binaryMessenger, + super.instanceManager, }) : super.detached(); /// Pigeon Host Api implementation for [DownloadListener]. @@ -908,10 +908,10 @@ class WebChromeClient extends JavaObject { /// create copies. @protected WebChromeClient.detached({ - required this.onProgressChanged, - required this.onShowFileChooser, - required super.binaryMessenger, - required super.instanceManager, + this.onProgressChanged, + this.onShowFileChooser, + super.binaryMessenger, + super.instanceManager, }) : super.detached(); /// Pigeon Host Api implementation for [WebChromeClient]. @@ -980,8 +980,8 @@ class FileChooserParams extends JavaObject { required this.acceptTypes, required this.filenameHint, required this.mode, - required super.binaryMessenger, - required super.instanceManager, + super.binaryMessenger, + super.instanceManager, }) : super.detached(); /// Preference for a live media captured value (e.g. Camera, Microphone). @@ -1091,8 +1091,8 @@ class WebStorage extends JavaObject { /// create copies. @protected WebStorage.detached({ - required super.binaryMessenger, - required super.instanceManager, + super.binaryMessenger, + super.instanceManager, }) : super.detached(); /// Pigeon Host Api implementation for [WebStorage]. 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 43bab384e0c..efa22071b30 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 @@ -589,7 +589,7 @@ void main() { android_webview.WebView.detached(), android_webview.FileChooserParams.detached( isCaptureEnabled: false, - acceptTypes: ['png'], + acceptTypes: const ['png'], filenameHint: 'filenameHint', mode: android_webview.FileChooserMode.open, ), @@ -890,7 +890,14 @@ void main() { final InstanceManager instanceManager = InstanceManager( onWeakReferenceRemoved: (_) {}, ); - instanceManager.addHostCreatedInstance(mockWebView, 0); + instanceManager.addHostCreatedInstance( + mockWebView, + 0, + onCopy: (android_webview.WebView original) { + return android_webview.WebView.detached( + instanceManager: instanceManager); + }, + ); android_webview.WebView.api = WebViewHostApiImpl( instanceManager: instanceManager, 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 index 2566d140ee0..b5c97f291c6 100644 --- a/packages/webview_flutter/webview_flutter_android/test/android_webview_test.dart +++ b/packages/webview_flutter/webview_flutter_android/test/android_webview_test.dart @@ -57,7 +57,13 @@ void main() { final JavaObject object = JavaObject.detached( instanceManager: instanceManager, ); - instanceManager.addHostCreatedInstance(object, 0); + instanceManager.addHostCreatedInstance( + object, + 0, + onCopy: (JavaObject original) { + return JavaObject.detached(instanceManager: instanceManager); + }, + ); JavaObject.dispose(object); @@ -72,7 +78,13 @@ void main() { final JavaObject object = JavaObject.detached( instanceManager: instanceManager, ); - instanceManager.addHostCreatedInstance(object, 0); + instanceManager.addHostCreatedInstance( + object, + 0, + onCopy: (JavaObject original) { + return JavaObject.detached(instanceManager: instanceManager); + }, + ); instanceManager.removeWeakReference(object); expect(instanceManager.containsIdentifier(0), isTrue); @@ -268,8 +280,12 @@ void main() { ); final WebViewClient mockWebViewClient = MockWebViewClient(); - when(mockWebViewClient.copy()).thenReturn(MockWebViewClient()); - instanceManager.addDartCreatedInstance(mockWebViewClient); + instanceManager.addDartCreatedInstance( + mockWebViewClient, + onCopy: (WebViewClient original) { + return WebViewClient.detached(); + }, + ); webView.setWebViewClient(mockWebViewClient); final int webViewClientInstanceId = @@ -287,7 +303,6 @@ void main() { ); final JavaScriptChannel mockJavaScriptChannel = MockJavaScriptChannel(); - when(mockJavaScriptChannel.copy()).thenReturn(MockJavaScriptChannel()); when(mockJavaScriptChannel.channelName).thenReturn('aChannel'); webView.addJavaScriptChannel(mockJavaScriptChannel); @@ -307,7 +322,6 @@ void main() { ); final JavaScriptChannel mockJavaScriptChannel = MockJavaScriptChannel(); - when(mockJavaScriptChannel.copy()).thenReturn(MockJavaScriptChannel()); when(mockJavaScriptChannel.channelName).thenReturn('aChannel'); expect( @@ -333,8 +347,14 @@ void main() { ); final DownloadListener mockDownloadListener = MockDownloadListener(); - when(mockDownloadListener.copy()).thenReturn(MockDownloadListener()); - instanceManager.addDartCreatedInstance(mockDownloadListener); + instanceManager.addDartCreatedInstance( + mockDownloadListener, + onCopy: (DownloadListener original) { + return DownloadListener.detached( + onDownloadStart: original.onDownloadStart, + ); + }, + ); webView.setDownloadListener(mockDownloadListener); final int downloadListenerInstanceId = @@ -352,8 +372,12 @@ void main() { ); final WebChromeClient mockWebChromeClient = MockWebChromeClient(); - when(mockWebChromeClient.copy()).thenReturn(MockWebChromeClient()); - instanceManager.addDartCreatedInstance(mockWebChromeClient); + instanceManager.addDartCreatedInstance( + mockWebChromeClient, + onCopy: (WebChromeClient original) { + return WebChromeClient.detached(); + }, + ); webView.setWebChromeClient(mockWebChromeClient); final int webChromeClientInstanceId = @@ -363,10 +387,6 @@ void main() { webChromeClientInstanceId, )); }); - - test('copy', () { - expect(webView.copy(), isA()); - }); }); group('WebSettings', () { @@ -513,7 +533,15 @@ void main() { when(mockJavaScriptChannel.copy()).thenReturn(MockJavaScriptChannel()); mockJavaScriptChannelInstanceId = - instanceManager.addDartCreatedInstance(mockJavaScriptChannel); + instanceManager.addDartCreatedInstance( + mockJavaScriptChannel, + onCopy: (JavaScriptChannel original) { + return JavaScriptChannel.detached( + original.channelName, + postMessage: original.postMessage, + ); + }, + ); }); test('postMessage', () { @@ -529,13 +557,6 @@ void main() { expect(result, 'Hello, World!'); }); - - test('copy', () { - expect( - JavaScriptChannel.detached('channel', postMessage: (_) {}).copy(), - isA(), - ); - }); }); group('WebViewClient', () { @@ -557,13 +578,21 @@ void main() { mockWebViewClient = MockWebViewClient(); when(mockWebViewClient.copy()).thenReturn(MockWebViewClient()); - mockWebViewClientInstanceId = - instanceManager.addDartCreatedInstance(mockWebViewClient); + mockWebViewClientInstanceId = instanceManager.addDartCreatedInstance( + mockWebViewClient, + onCopy: (WebViewClient original) { + return WebViewClient.detached(); + }, + ); mockWebView = MockWebView(); when(mockWebView.copy()).thenReturn(MockWebView()); - mockWebViewInstanceId = - instanceManager.addDartCreatedInstance(mockWebView); + mockWebViewInstanceId = instanceManager.addDartCreatedInstance( + mockWebView, + onCopy: (WebView original) { + return WebView.detached(); + }, + ); }); test('onPageStarted', () { @@ -704,10 +733,6 @@ void main() { containsAllInOrder([mockWebView, 'https://www.google.com']), ); }); - - test('copy', () { - expect(WebViewClient.detached().copy(), isA()); - }); }); group('DownloadListener', () { @@ -726,8 +751,14 @@ void main() { mockDownloadListener = MockDownloadListener(); when(mockDownloadListener.copy()).thenReturn(MockDownloadListener()); - mockDownloadListenerInstanceId = - instanceManager.addDartCreatedInstance(mockDownloadListener); + mockDownloadListenerInstanceId = instanceManager.addDartCreatedInstance( + mockDownloadListener, + onCopy: (DownloadListener original) { + return DownloadListener.detached( + onDownloadStart: original.onDownloadStart, + ); + }, + ); }); test('onDownloadStart', () { @@ -770,15 +801,6 @@ void main() { ]), ); }); - - test('copy', () { - expect( - DownloadListener.detached( - onDownloadStart: (_, __, ____, _____, ______) {}, - ).copy(), - isA(), - ); - }); }); group('WebChromeClient', () { @@ -801,13 +823,21 @@ void main() { mockWebChromeClient = MockWebChromeClient(); when(mockWebChromeClient.copy()).thenReturn(MockWebChromeClient()); - mockWebChromeClientInstanceId = - instanceManager.addDartCreatedInstance(mockWebChromeClient); + mockWebChromeClientInstanceId = instanceManager.addDartCreatedInstance( + mockWebChromeClient, + onCopy: (WebChromeClient original) { + return WebChromeClient.detached(); + }, + ); mockWebView = MockWebView(); when(mockWebView.copy()).thenReturn(MockWebView()); - mockWebViewInstanceId = - instanceManager.addDartCreatedInstance(mockWebView); + mockWebViewInstanceId = instanceManager.addDartCreatedInstance( + mockWebView, + onCopy: (WebView original) { + return WebView.detached(); + }, + ); }); test('onProgressChanged', () { @@ -838,12 +868,23 @@ void main() { final FileChooserParams params = FileChooserParams.detached( isCaptureEnabled: false, - acceptTypes: [], + acceptTypes: const [], filenameHint: 'filenameHint', mode: FileChooserMode.open, ); - instanceManager.addHostCreatedInstance(params, 3); + instanceManager.addHostCreatedInstance( + params, + 3, + onCopy: (FileChooserParams original) { + return FileChooserParams.detached( + acceptTypes: original.acceptTypes, + filenameHint: original.filenameHint, + isCaptureEnabled: original.isCaptureEnabled, + mode: original.mode, + ); + }, + ); await expectLater( flutterApi.onShowFileChooser( @@ -866,7 +907,13 @@ void main() { WebChromeClientHostApiImpl(instanceManager: instanceManager); final WebChromeClient webChromeClient = WebChromeClient.detached(); - instanceManager.addHostCreatedInstance(webChromeClient, 2); + instanceManager.addHostCreatedInstance( + webChromeClient, + 2, + onCopy: (WebChromeClient original) { + return WebChromeClient.detached(); + }, + ); webChromeClient.setSynchronousReturnValueForOnShowFileChooser(false); @@ -887,7 +934,13 @@ void main() { final WebChromeClient clientWithNullCallback = WebChromeClient.detached(); - instanceManager.addHostCreatedInstance(clientWithNullCallback, 2); + instanceManager.addHostCreatedInstance( + clientWithNullCallback, + 2, + onCopy: (WebChromeClient original) { + return WebChromeClient.detached(); + }, + ); expect( () => clientWithNullCallback @@ -899,7 +952,13 @@ void main() { WebChromeClient.detached( onShowFileChooser: (_, __) async => [], ); - instanceManager.addHostCreatedInstance(clientWithNonnullCallback, 3); + instanceManager.addHostCreatedInstance( + clientWithNonnullCallback, + 3, + onCopy: (WebChromeClient original) { + return WebChromeClient.detached(); + }, + ); clientWithNonnullCallback .setSynchronousReturnValueForOnShowFileChooser(true); 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 index dd3dcca29fe..02ca60ba2b3 100644 --- a/packages/webview_flutter/webview_flutter_android/test/instance_manager_test.dart +++ b/packages/webview_flutter/webview_flutter_android/test/instance_manager_test.dart @@ -3,17 +3,29 @@ // 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/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 Object object = Object(); final InstanceManager instanceManager = InstanceManager(onWeakReferenceRemoved: (_) {}); - instanceManager.addHostCreatedInstance(object, 0); + instanceManager.addHostCreatedInstance( + object, + 0, + onCopy: (_) => Object(), + ); expect(instanceManager.getIdentifier(object), 0); expect( @@ -23,31 +35,46 @@ void main() { }); test('addHostCreatedInstance prevents already used objects and ids', () { - final CopyableObject object = CopyableObject(); + final Object object = Object(); final InstanceManager instanceManager = InstanceManager(onWeakReferenceRemoved: (_) {}); - instanceManager.addHostCreatedInstance(object, 0); + instanceManager.addHostCreatedInstance( + object, + 0, + onCopy: (_) => Object(), + ); expect( - () => instanceManager.addHostCreatedInstance(object, 0), + () => instanceManager.addHostCreatedInstance( + object, + 0, + onCopy: (_) => Object(), + ), throwsAssertionError, ); expect( - () => instanceManager.addHostCreatedInstance(CopyableObject(), 0), + () => instanceManager.addHostCreatedInstance( + Object(), + 0, + onCopy: (_) => Object(), + ), throwsAssertionError, ); }); - test('addFlutterCreatedInstance', () { - final CopyableObject object = CopyableObject(); + test('addDartCreatedInstance', () { + final Object object = Object(); final InstanceManager instanceManager = InstanceManager(onWeakReferenceRemoved: (_) {}); - instanceManager.addDartCreatedInstance(object); + instanceManager.addDartCreatedInstance( + object, + onCopy: (_) => Object(), + ); final int? instanceId = instanceManager.getIdentifier(object); expect(instanceId, isNotNull); @@ -58,7 +85,7 @@ void main() { }); test('removeWeakReference', () { - final CopyableObject object = CopyableObject(); + final Object object = Object(); int? weakInstanceId; final InstanceManager instanceManager = @@ -66,51 +93,67 @@ void main() { weakInstanceId = instanceId; }); - instanceManager.addHostCreatedInstance(object, 0); + instanceManager.addHostCreatedInstance( + object, + 0, + onCopy: (_) => Object(), + ); expect(instanceManager.removeWeakReference(object), 0); expect( instanceManager.getInstanceWithWeakReference(0), - isA(), + isA(), ); expect(weakInstanceId, 0); }); test('removeWeakReference removes only weak reference', () { - final CopyableObject object = CopyableObject(); + final Object object = Object(); final InstanceManager instanceManager = InstanceManager(onWeakReferenceRemoved: (_) {}); - instanceManager.addHostCreatedInstance(object, 0); + instanceManager.addHostCreatedInstance( + object, + 0, + onCopy: (_) => Object(), + ); expect(instanceManager.removeWeakReference(object), 0); - final CopyableObject copy = instanceManager.getInstanceWithWeakReference( + final Object copy = instanceManager.getInstanceWithWeakReference( 0, )!; expect(identical(object, copy), isFalse); }); test('removeStrongReference', () { - final CopyableObject object = CopyableObject(); + final Object object = Object(); final InstanceManager instanceManager = InstanceManager(onWeakReferenceRemoved: (_) {}); - instanceManager.addHostCreatedInstance(object, 0); + instanceManager.addHostCreatedInstance( + object, + 0, + onCopy: (_) => Object(), + ); instanceManager.removeWeakReference(object); - expect(instanceManager.remove(0), isA()); + expect(instanceManager.remove(0), isA()); expect(instanceManager.containsIdentifier(0), isFalse); }); test('removeStrongReference removes only strong reference', () { - final CopyableObject object = CopyableObject(); + final Object object = Object(); final InstanceManager instanceManager = InstanceManager(onWeakReferenceRemoved: (_) {}); - instanceManager.addHostCreatedInstance(object, 0); - expect(instanceManager.remove(0), isA()); + instanceManager.addHostCreatedInstance( + object, + 0, + onCopy: (_) => Object(), + ); + expect(instanceManager.remove(0), isA()); expect( instanceManager.getInstanceWithWeakReference(0), object, @@ -118,26 +161,34 @@ void main() { }); test('getInstance can add a new weak reference', () { - final CopyableObject object = CopyableObject(); + final Object object = Object(); final InstanceManager instanceManager = InstanceManager(onWeakReferenceRemoved: (_) {}); - instanceManager.addHostCreatedInstance(object, 0); + instanceManager.addHostCreatedInstance( + object, + 0, + onCopy: (_) => Object(), + ); instanceManager.removeWeakReference(object); - final CopyableObject newWeakCopy = - instanceManager.getInstanceWithWeakReference( + final Object newWeakCopy = instanceManager.getInstanceWithWeakReference( 0, )!; expect(identical(object, newWeakCopy), isFalse); }); - }); -} -class CopyableObject with Copyable { - @override - Copyable copy() { - return CopyableObject(); - } + test('globalInstanceManager clears native `InstanceManager`', () { + final MockTestInstanceManagerHostApi mockApi = + MockTestInstanceManagerHostApi(); + TestInstanceManagerHostApi.setup(mockApi); + + BaseObject.globalInstanceManager; + + verify(mockApi.clear()); + + TestInstanceManagerHostApi.setup(null); + }); + }); } 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 index f2a07af1089..b2a056201f3 100644 --- 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 @@ -22,7 +22,8 @@ abstract class TestInstanceManagerHostApi { /// This is typically only used after a hot restart. void clear(); - static void setup(TestInstanceManagerHostApi? api, {BinaryMessenger? binaryMessenger}) { + static void setup(TestInstanceManagerHostApi? api, + {BinaryMessenger? binaryMessenger}) { { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.InstanceManagerHostApi.clear', codec, @@ -50,7 +51,8 @@ abstract class TestJavaObjectHostApi { void dispose(int identifier); - static void setup(TestJavaObjectHostApi? api, {BinaryMessenger? binaryMessenger}) { + static void setup(TestJavaObjectHostApi? api, + {BinaryMessenger? binaryMessenger}) { { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.JavaObjectHostApi.dispose', codec, @@ -60,7 +62,7 @@ abstract class TestJavaObjectHostApi { } else { channel.setMockMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.JavaObjectHostApi.dispose was null.'); + 'Argument for dev.flutter.pigeon.JavaObjectHostApi.dispose was null.'); final List args = (message as List?)!; final int? arg_identifier = (args[0] as int?); assert(arg_identifier != null, @@ -88,7 +90,7 @@ class _TestWebViewHostApiCodec extends StandardMessageCodec { @override Object? readValueOfType(int type, ReadBuffer buffer) { switch (type) { - case 128: + case 128: return WebViewPoint.decode(readValue(buffer)!); default: return super.readValueOfType(type, buffer); @@ -101,9 +103,11 @@ abstract class TestWebViewHostApi { void create(int instanceId, bool useHybridComposition); - void loadData(int instanceId, String data, String? mimeType, String? encoding); + 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 loadDataWithBaseUrl(int instanceId, String? baseUrl, String data, + String? mimeType, String? encoding, String? historyUrl); void loadUrl(int instanceId, String url, Map headers); @@ -151,7 +155,8 @@ abstract class TestWebViewHostApi { void setBackgroundColor(int instanceId, int color); - static void setup(TestWebViewHostApi? api, {BinaryMessenger? binaryMessenger}) { + static void setup(TestWebViewHostApi? api, + {BinaryMessenger? binaryMessenger}) { { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.WebViewHostApi.create', codec, @@ -161,7 +166,7 @@ abstract class TestWebViewHostApi { } else { channel.setMockMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.WebViewHostApi.create was null.'); + 'Argument for dev.flutter.pigeon.WebViewHostApi.create was null.'); final List args = (message as List?)!; final int? arg_instanceId = (args[0] as int?); assert(arg_instanceId != null, @@ -183,7 +188,7 @@ abstract class TestWebViewHostApi { } else { channel.setMockMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.WebViewHostApi.loadData was null.'); + 'Argument for dev.flutter.pigeon.WebViewHostApi.loadData was null.'); final List args = (message as List?)!; final int? arg_instanceId = (args[0] as int?); assert(arg_instanceId != null, @@ -207,7 +212,7 @@ abstract class TestWebViewHostApi { } else { channel.setMockMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.WebViewHostApi.loadDataWithBaseUrl was null.'); + 'Argument for dev.flutter.pigeon.WebViewHostApi.loadDataWithBaseUrl was null.'); final List args = (message as List?)!; final int? arg_instanceId = (args[0] as int?); assert(arg_instanceId != null, @@ -219,7 +224,8 @@ abstract class TestWebViewHostApi { 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); + api.loadDataWithBaseUrl(arg_instanceId!, arg_baseUrl, arg_data!, + arg_mimeType, arg_encoding, arg_historyUrl); return []; }); } @@ -233,7 +239,7 @@ abstract class TestWebViewHostApi { } else { channel.setMockMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.WebViewHostApi.loadUrl was null.'); + 'Argument for dev.flutter.pigeon.WebViewHostApi.loadUrl was null.'); final List args = (message as List?)!; final int? arg_instanceId = (args[0] as int?); assert(arg_instanceId != null, @@ -241,7 +247,8 @@ abstract class TestWebViewHostApi { final String? arg_url = (args[1] as String?); assert(arg_url != null, 'Argument for dev.flutter.pigeon.WebViewHostApi.loadUrl was null, expected non-null String.'); - final Map? arg_headers = (args[2] as Map?)?.cast(); + final Map? arg_headers = + (args[2] as Map?)?.cast(); assert(arg_headers != null, 'Argument for dev.flutter.pigeon.WebViewHostApi.loadUrl was null, expected non-null Map.'); api.loadUrl(arg_instanceId!, arg_url!, arg_headers!); @@ -258,7 +265,7 @@ abstract class TestWebViewHostApi { } else { channel.setMockMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.WebViewHostApi.postUrl was null.'); + 'Argument for dev.flutter.pigeon.WebViewHostApi.postUrl was null.'); final List args = (message as List?)!; final int? arg_instanceId = (args[0] as int?); assert(arg_instanceId != null, @@ -283,7 +290,7 @@ abstract class TestWebViewHostApi { } else { channel.setMockMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.WebViewHostApi.getUrl was null.'); + 'Argument for dev.flutter.pigeon.WebViewHostApi.getUrl was null.'); final List args = (message as List?)!; final int? arg_instanceId = (args[0] as int?); assert(arg_instanceId != null, @@ -302,7 +309,7 @@ abstract class TestWebViewHostApi { } else { channel.setMockMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.WebViewHostApi.canGoBack was null.'); + 'Argument for dev.flutter.pigeon.WebViewHostApi.canGoBack was null.'); final List args = (message as List?)!; final int? arg_instanceId = (args[0] as int?); assert(arg_instanceId != null, @@ -321,7 +328,7 @@ abstract class TestWebViewHostApi { } else { channel.setMockMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.WebViewHostApi.canGoForward was null.'); + 'Argument for dev.flutter.pigeon.WebViewHostApi.canGoForward was null.'); final List args = (message as List?)!; final int? arg_instanceId = (args[0] as int?); assert(arg_instanceId != null, @@ -340,7 +347,7 @@ abstract class TestWebViewHostApi { } else { channel.setMockMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.WebViewHostApi.goBack was null.'); + 'Argument for dev.flutter.pigeon.WebViewHostApi.goBack was null.'); final List args = (message as List?)!; final int? arg_instanceId = (args[0] as int?); assert(arg_instanceId != null, @@ -359,7 +366,7 @@ abstract class TestWebViewHostApi { } else { channel.setMockMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.WebViewHostApi.goForward was null.'); + 'Argument for dev.flutter.pigeon.WebViewHostApi.goForward was null.'); final List args = (message as List?)!; final int? arg_instanceId = (args[0] as int?); assert(arg_instanceId != null, @@ -378,7 +385,7 @@ abstract class TestWebViewHostApi { } else { channel.setMockMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.WebViewHostApi.reload was null.'); + 'Argument for dev.flutter.pigeon.WebViewHostApi.reload was null.'); final List args = (message as List?)!; final int? arg_instanceId = (args[0] as int?); assert(arg_instanceId != null, @@ -397,7 +404,7 @@ abstract class TestWebViewHostApi { } else { channel.setMockMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.WebViewHostApi.clearCache was null.'); + 'Argument for dev.flutter.pigeon.WebViewHostApi.clearCache was null.'); final List args = (message as List?)!; final int? arg_instanceId = (args[0] as int?); assert(arg_instanceId != null, @@ -419,7 +426,7 @@ abstract class TestWebViewHostApi { } else { channel.setMockMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.WebViewHostApi.evaluateJavascript was null.'); + 'Argument for dev.flutter.pigeon.WebViewHostApi.evaluateJavascript was null.'); final List args = (message as List?)!; final int? arg_instanceId = (args[0] as int?); assert(arg_instanceId != null, @@ -427,7 +434,8 @@ abstract class TestWebViewHostApi { final String? arg_javascriptString = (args[1] as String?); assert(arg_javascriptString != null, 'Argument for dev.flutter.pigeon.WebViewHostApi.evaluateJavascript was null, expected non-null String.'); - final String? output = await api.evaluateJavascript(arg_instanceId!, arg_javascriptString!); + final String? output = await api.evaluateJavascript( + arg_instanceId!, arg_javascriptString!); return [output]; }); } @@ -441,7 +449,7 @@ abstract class TestWebViewHostApi { } else { channel.setMockMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.WebViewHostApi.getTitle was null.'); + 'Argument for dev.flutter.pigeon.WebViewHostApi.getTitle was null.'); final List args = (message as List?)!; final int? arg_instanceId = (args[0] as int?); assert(arg_instanceId != null, @@ -460,7 +468,7 @@ abstract class TestWebViewHostApi { } else { channel.setMockMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.WebViewHostApi.scrollTo was null.'); + 'Argument for dev.flutter.pigeon.WebViewHostApi.scrollTo was null.'); final List args = (message as List?)!; final int? arg_instanceId = (args[0] as int?); assert(arg_instanceId != null, @@ -485,7 +493,7 @@ abstract class TestWebViewHostApi { } else { channel.setMockMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.WebViewHostApi.scrollBy was null.'); + 'Argument for dev.flutter.pigeon.WebViewHostApi.scrollBy was null.'); final List args = (message as List?)!; final int? arg_instanceId = (args[0] as int?); assert(arg_instanceId != null, @@ -510,7 +518,7 @@ abstract class TestWebViewHostApi { } else { channel.setMockMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.WebViewHostApi.getScrollX was null.'); + 'Argument for dev.flutter.pigeon.WebViewHostApi.getScrollX was null.'); final List args = (message as List?)!; final int? arg_instanceId = (args[0] as int?); assert(arg_instanceId != null, @@ -529,7 +537,7 @@ abstract class TestWebViewHostApi { } else { channel.setMockMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.WebViewHostApi.getScrollY was null.'); + 'Argument for dev.flutter.pigeon.WebViewHostApi.getScrollY was null.'); final List args = (message as List?)!; final int? arg_instanceId = (args[0] as int?); assert(arg_instanceId != null, @@ -548,7 +556,7 @@ abstract class TestWebViewHostApi { } else { channel.setMockMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.WebViewHostApi.getScrollPosition was null.'); + 'Argument for dev.flutter.pigeon.WebViewHostApi.getScrollPosition was null.'); final List args = (message as List?)!; final int? arg_instanceId = (args[0] as int?); assert(arg_instanceId != null, @@ -560,14 +568,15 @@ abstract class TestWebViewHostApi { } { final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.WebViewHostApi.setWebContentsDebuggingEnabled', codec, + 'dev.flutter.pigeon.WebViewHostApi.setWebContentsDebuggingEnabled', + codec, binaryMessenger: binaryMessenger); if (api == null) { channel.setMockMessageHandler(null); } else { channel.setMockMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.WebViewHostApi.setWebContentsDebuggingEnabled was null.'); + 'Argument for dev.flutter.pigeon.WebViewHostApi.setWebContentsDebuggingEnabled was null.'); final List args = (message as List?)!; final bool? arg_enabled = (args[0] as bool?); assert(arg_enabled != null, @@ -586,7 +595,7 @@ abstract class TestWebViewHostApi { } else { channel.setMockMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.WebViewHostApi.setWebViewClient was null.'); + 'Argument for dev.flutter.pigeon.WebViewHostApi.setWebViewClient was null.'); final List args = (message as List?)!; final int? arg_instanceId = (args[0] as int?); assert(arg_instanceId != null, @@ -608,7 +617,7 @@ abstract class TestWebViewHostApi { } else { channel.setMockMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.WebViewHostApi.addJavaScriptChannel was null.'); + 'Argument for dev.flutter.pigeon.WebViewHostApi.addJavaScriptChannel was null.'); final List args = (message as List?)!; final int? arg_instanceId = (args[0] as int?); assert(arg_instanceId != null, @@ -616,7 +625,8 @@ abstract class TestWebViewHostApi { final int? arg_javaScriptChannelInstanceId = (args[1] as int?); assert(arg_javaScriptChannelInstanceId != null, 'Argument for dev.flutter.pigeon.WebViewHostApi.addJavaScriptChannel was null, expected non-null int.'); - api.addJavaScriptChannel(arg_instanceId!, arg_javaScriptChannelInstanceId!); + api.addJavaScriptChannel( + arg_instanceId!, arg_javaScriptChannelInstanceId!); return []; }); } @@ -630,7 +640,7 @@ abstract class TestWebViewHostApi { } else { channel.setMockMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.WebViewHostApi.removeJavaScriptChannel was null.'); + 'Argument for dev.flutter.pigeon.WebViewHostApi.removeJavaScriptChannel was null.'); final List args = (message as List?)!; final int? arg_instanceId = (args[0] as int?); assert(arg_instanceId != null, @@ -638,7 +648,8 @@ abstract class TestWebViewHostApi { final int? arg_javaScriptChannelInstanceId = (args[1] as int?); assert(arg_javaScriptChannelInstanceId != null, 'Argument for dev.flutter.pigeon.WebViewHostApi.removeJavaScriptChannel was null, expected non-null int.'); - api.removeJavaScriptChannel(arg_instanceId!, arg_javaScriptChannelInstanceId!); + api.removeJavaScriptChannel( + arg_instanceId!, arg_javaScriptChannelInstanceId!); return []; }); } @@ -652,7 +663,7 @@ abstract class TestWebViewHostApi { } else { channel.setMockMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.WebViewHostApi.setDownloadListener was null.'); + 'Argument for dev.flutter.pigeon.WebViewHostApi.setDownloadListener was null.'); final List args = (message as List?)!; final int? arg_instanceId = (args[0] as int?); assert(arg_instanceId != null, @@ -672,7 +683,7 @@ abstract class TestWebViewHostApi { } else { channel.setMockMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.WebViewHostApi.setWebChromeClient was null.'); + 'Argument for dev.flutter.pigeon.WebViewHostApi.setWebChromeClient was null.'); final List args = (message as List?)!; final int? arg_instanceId = (args[0] as int?); assert(arg_instanceId != null, @@ -692,7 +703,7 @@ abstract class TestWebViewHostApi { } else { channel.setMockMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.WebViewHostApi.setBackgroundColor was null.'); + 'Argument for dev.flutter.pigeon.WebViewHostApi.setBackgroundColor was null.'); final List args = (message as List?)!; final int? arg_instanceId = (args[0] as int?); assert(arg_instanceId != null, @@ -737,7 +748,8 @@ abstract class TestWebSettingsHostApi { void setAllowFileAccess(int instanceId, bool enabled); - static void setup(TestWebSettingsHostApi? api, {BinaryMessenger? binaryMessenger}) { + static void setup(TestWebSettingsHostApi? api, + {BinaryMessenger? binaryMessenger}) { { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.WebSettingsHostApi.create', codec, @@ -747,7 +759,7 @@ abstract class TestWebSettingsHostApi { } else { channel.setMockMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.WebSettingsHostApi.create was null.'); + 'Argument for dev.flutter.pigeon.WebSettingsHostApi.create was null.'); final List args = (message as List?)!; final int? arg_instanceId = (args[0] as int?); assert(arg_instanceId != null, @@ -769,7 +781,7 @@ abstract class TestWebSettingsHostApi { } else { channel.setMockMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.WebSettingsHostApi.setDomStorageEnabled was null.'); + 'Argument for dev.flutter.pigeon.WebSettingsHostApi.setDomStorageEnabled was null.'); final List args = (message as List?)!; final int? arg_instanceId = (args[0] as int?); assert(arg_instanceId != null, @@ -784,14 +796,15 @@ abstract class TestWebSettingsHostApi { } { final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.WebSettingsHostApi.setJavaScriptCanOpenWindowsAutomatically', codec, + 'dev.flutter.pigeon.WebSettingsHostApi.setJavaScriptCanOpenWindowsAutomatically', + codec, binaryMessenger: binaryMessenger); if (api == null) { channel.setMockMessageHandler(null); } else { channel.setMockMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.WebSettingsHostApi.setJavaScriptCanOpenWindowsAutomatically was null.'); + 'Argument for dev.flutter.pigeon.WebSettingsHostApi.setJavaScriptCanOpenWindowsAutomatically was null.'); final List args = (message as List?)!; final int? arg_instanceId = (args[0] as int?); assert(arg_instanceId != null, @@ -799,21 +812,23 @@ abstract class TestWebSettingsHostApi { final bool? arg_flag = (args[1] as bool?); assert(arg_flag != null, 'Argument for dev.flutter.pigeon.WebSettingsHostApi.setJavaScriptCanOpenWindowsAutomatically was null, expected non-null bool.'); - api.setJavaScriptCanOpenWindowsAutomatically(arg_instanceId!, arg_flag!); + api.setJavaScriptCanOpenWindowsAutomatically( + arg_instanceId!, arg_flag!); return []; }); } } { final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.WebSettingsHostApi.setSupportMultipleWindows', codec, + 'dev.flutter.pigeon.WebSettingsHostApi.setSupportMultipleWindows', + codec, binaryMessenger: binaryMessenger); if (api == null) { channel.setMockMessageHandler(null); } else { channel.setMockMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.WebSettingsHostApi.setSupportMultipleWindows was null.'); + 'Argument for dev.flutter.pigeon.WebSettingsHostApi.setSupportMultipleWindows was null.'); final List args = (message as List?)!; final int? arg_instanceId = (args[0] as int?); assert(arg_instanceId != null, @@ -835,7 +850,7 @@ abstract class TestWebSettingsHostApi { } else { channel.setMockMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.WebSettingsHostApi.setJavaScriptEnabled was null.'); + 'Argument for dev.flutter.pigeon.WebSettingsHostApi.setJavaScriptEnabled was null.'); final List args = (message as List?)!; final int? arg_instanceId = (args[0] as int?); assert(arg_instanceId != null, @@ -857,7 +872,7 @@ abstract class TestWebSettingsHostApi { } else { channel.setMockMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.WebSettingsHostApi.setUserAgentString was null.'); + 'Argument for dev.flutter.pigeon.WebSettingsHostApi.setUserAgentString was null.'); final List args = (message as List?)!; final int? arg_instanceId = (args[0] as int?); assert(arg_instanceId != null, @@ -870,14 +885,15 @@ abstract class TestWebSettingsHostApi { } { final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.WebSettingsHostApi.setMediaPlaybackRequiresUserGesture', codec, + 'dev.flutter.pigeon.WebSettingsHostApi.setMediaPlaybackRequiresUserGesture', + codec, binaryMessenger: binaryMessenger); if (api == null) { channel.setMockMessageHandler(null); } else { channel.setMockMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.WebSettingsHostApi.setMediaPlaybackRequiresUserGesture was null.'); + 'Argument for dev.flutter.pigeon.WebSettingsHostApi.setMediaPlaybackRequiresUserGesture was null.'); final List args = (message as List?)!; final int? arg_instanceId = (args[0] as int?); assert(arg_instanceId != null, @@ -885,7 +901,8 @@ abstract class TestWebSettingsHostApi { final bool? arg_require = (args[1] as bool?); assert(arg_require != null, 'Argument for dev.flutter.pigeon.WebSettingsHostApi.setMediaPlaybackRequiresUserGesture was null, expected non-null bool.'); - api.setMediaPlaybackRequiresUserGesture(arg_instanceId!, arg_require!); + api.setMediaPlaybackRequiresUserGesture( + arg_instanceId!, arg_require!); return []; }); } @@ -899,7 +916,7 @@ abstract class TestWebSettingsHostApi { } else { channel.setMockMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.WebSettingsHostApi.setSupportZoom was null.'); + 'Argument for dev.flutter.pigeon.WebSettingsHostApi.setSupportZoom was null.'); final List args = (message as List?)!; final int? arg_instanceId = (args[0] as int?); assert(arg_instanceId != null, @@ -914,14 +931,15 @@ abstract class TestWebSettingsHostApi { } { final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.WebSettingsHostApi.setLoadWithOverviewMode', codec, + 'dev.flutter.pigeon.WebSettingsHostApi.setLoadWithOverviewMode', + codec, binaryMessenger: binaryMessenger); if (api == null) { channel.setMockMessageHandler(null); } else { channel.setMockMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.WebSettingsHostApi.setLoadWithOverviewMode was null.'); + 'Argument for dev.flutter.pigeon.WebSettingsHostApi.setLoadWithOverviewMode was null.'); final List args = (message as List?)!; final int? arg_instanceId = (args[0] as int?); assert(arg_instanceId != null, @@ -943,7 +961,7 @@ abstract class TestWebSettingsHostApi { } else { channel.setMockMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.WebSettingsHostApi.setUseWideViewPort was null.'); + 'Argument for dev.flutter.pigeon.WebSettingsHostApi.setUseWideViewPort was null.'); final List args = (message as List?)!; final int? arg_instanceId = (args[0] as int?); assert(arg_instanceId != null, @@ -965,7 +983,7 @@ abstract class TestWebSettingsHostApi { } else { channel.setMockMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.WebSettingsHostApi.setDisplayZoomControls was null.'); + 'Argument for dev.flutter.pigeon.WebSettingsHostApi.setDisplayZoomControls was null.'); final List args = (message as List?)!; final int? arg_instanceId = (args[0] as int?); assert(arg_instanceId != null, @@ -987,7 +1005,7 @@ abstract class TestWebSettingsHostApi { } else { channel.setMockMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.WebSettingsHostApi.setBuiltInZoomControls was null.'); + 'Argument for dev.flutter.pigeon.WebSettingsHostApi.setBuiltInZoomControls was null.'); final List args = (message as List?)!; final int? arg_instanceId = (args[0] as int?); assert(arg_instanceId != null, @@ -1009,7 +1027,7 @@ abstract class TestWebSettingsHostApi { } else { channel.setMockMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.WebSettingsHostApi.setAllowFileAccess was null.'); + 'Argument for dev.flutter.pigeon.WebSettingsHostApi.setAllowFileAccess was null.'); final List args = (message as List?)!; final int? arg_instanceId = (args[0] as int?); assert(arg_instanceId != null, @@ -1030,7 +1048,8 @@ abstract class TestJavaScriptChannelHostApi { void create(int instanceId, String channelName); - static void setup(TestJavaScriptChannelHostApi? api, {BinaryMessenger? binaryMessenger}) { + static void setup(TestJavaScriptChannelHostApi? api, + {BinaryMessenger? binaryMessenger}) { { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.JavaScriptChannelHostApi.create', codec, @@ -1040,7 +1059,7 @@ abstract class TestJavaScriptChannelHostApi { } else { channel.setMockMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.JavaScriptChannelHostApi.create was null.'); + 'Argument for dev.flutter.pigeon.JavaScriptChannelHostApi.create was null.'); final List args = (message as List?)!; final int? arg_instanceId = (args[0] as int?); assert(arg_instanceId != null, @@ -1061,9 +1080,11 @@ abstract class TestWebViewClientHostApi { void create(int instanceId); - void setSynchronousReturnValueForShouldOverrideUrlLoading(int instanceId, bool value); + void setSynchronousReturnValueForShouldOverrideUrlLoading( + int instanceId, bool value); - static void setup(TestWebViewClientHostApi? api, {BinaryMessenger? binaryMessenger}) { + static void setup(TestWebViewClientHostApi? api, + {BinaryMessenger? binaryMessenger}) { { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.WebViewClientHostApi.create', codec, @@ -1073,7 +1094,7 @@ abstract class TestWebViewClientHostApi { } else { channel.setMockMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.WebViewClientHostApi.create was null.'); + 'Argument for dev.flutter.pigeon.WebViewClientHostApi.create was null.'); final List args = (message as List?)!; final int? arg_instanceId = (args[0] as int?); assert(arg_instanceId != null, @@ -1085,14 +1106,15 @@ abstract class TestWebViewClientHostApi { } { final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.WebViewClientHostApi.setSynchronousReturnValueForShouldOverrideUrlLoading', codec, + 'dev.flutter.pigeon.WebViewClientHostApi.setSynchronousReturnValueForShouldOverrideUrlLoading', + codec, binaryMessenger: binaryMessenger); if (api == null) { channel.setMockMessageHandler(null); } else { channel.setMockMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.WebViewClientHostApi.setSynchronousReturnValueForShouldOverrideUrlLoading was null.'); + 'Argument for dev.flutter.pigeon.WebViewClientHostApi.setSynchronousReturnValueForShouldOverrideUrlLoading was null.'); final List args = (message as List?)!; final int? arg_instanceId = (args[0] as int?); assert(arg_instanceId != null, @@ -1100,7 +1122,8 @@ abstract class TestWebViewClientHostApi { final bool? arg_value = (args[1] as bool?); assert(arg_value != null, 'Argument for dev.flutter.pigeon.WebViewClientHostApi.setSynchronousReturnValueForShouldOverrideUrlLoading was null, expected non-null bool.'); - api.setSynchronousReturnValueForShouldOverrideUrlLoading(arg_instanceId!, arg_value!); + api.setSynchronousReturnValueForShouldOverrideUrlLoading( + arg_instanceId!, arg_value!); return []; }); } @@ -1113,7 +1136,8 @@ abstract class TestDownloadListenerHostApi { void create(int instanceId); - static void setup(TestDownloadListenerHostApi? api, {BinaryMessenger? binaryMessenger}) { + static void setup(TestDownloadListenerHostApi? api, + {BinaryMessenger? binaryMessenger}) { { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.DownloadListenerHostApi.create', codec, @@ -1123,7 +1147,7 @@ abstract class TestDownloadListenerHostApi { } else { channel.setMockMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.DownloadListenerHostApi.create was null.'); + 'Argument for dev.flutter.pigeon.DownloadListenerHostApi.create was null.'); final List args = (message as List?)!; final int? arg_instanceId = (args[0] as int?); assert(arg_instanceId != null, @@ -1141,9 +1165,11 @@ abstract class TestWebChromeClientHostApi { void create(int instanceId); - void setSynchronousReturnValueForOnShowFileChooser(int instanceId, bool value); + void setSynchronousReturnValueForOnShowFileChooser( + int instanceId, bool value); - static void setup(TestWebChromeClientHostApi? api, {BinaryMessenger? binaryMessenger}) { + static void setup(TestWebChromeClientHostApi? api, + {BinaryMessenger? binaryMessenger}) { { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.WebChromeClientHostApi.create', codec, @@ -1153,7 +1179,7 @@ abstract class TestWebChromeClientHostApi { } else { channel.setMockMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.WebChromeClientHostApi.create was null.'); + 'Argument for dev.flutter.pigeon.WebChromeClientHostApi.create was null.'); final List args = (message as List?)!; final int? arg_instanceId = (args[0] as int?); assert(arg_instanceId != null, @@ -1165,14 +1191,15 @@ abstract class TestWebChromeClientHostApi { } { final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.WebChromeClientHostApi.setSynchronousReturnValueForOnShowFileChooser', codec, + 'dev.flutter.pigeon.WebChromeClientHostApi.setSynchronousReturnValueForOnShowFileChooser', + codec, binaryMessenger: binaryMessenger); if (api == null) { channel.setMockMessageHandler(null); } else { channel.setMockMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.WebChromeClientHostApi.setSynchronousReturnValueForOnShowFileChooser was null.'); + 'Argument for dev.flutter.pigeon.WebChromeClientHostApi.setSynchronousReturnValueForOnShowFileChooser was null.'); final List args = (message as List?)!; final int? arg_instanceId = (args[0] as int?); assert(arg_instanceId != null, @@ -1180,7 +1207,8 @@ abstract class TestWebChromeClientHostApi { final bool? arg_value = (args[1] as bool?); assert(arg_value != null, 'Argument for dev.flutter.pigeon.WebChromeClientHostApi.setSynchronousReturnValueForOnShowFileChooser was null, expected non-null bool.'); - api.setSynchronousReturnValueForOnShowFileChooser(arg_instanceId!, arg_value!); + api.setSynchronousReturnValueForOnShowFileChooser( + arg_instanceId!, arg_value!); return []; }); } @@ -1195,7 +1223,8 @@ abstract class TestAssetManagerHostApi { String getAssetFilePathByName(String name); - static void setup(TestAssetManagerHostApi? api, {BinaryMessenger? binaryMessenger}) { + static void setup(TestAssetManagerHostApi? api, + {BinaryMessenger? binaryMessenger}) { { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.FlutterAssetManagerHostApi.list', codec, @@ -1205,7 +1234,7 @@ abstract class TestAssetManagerHostApi { } else { channel.setMockMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.FlutterAssetManagerHostApi.list was null.'); + 'Argument for dev.flutter.pigeon.FlutterAssetManagerHostApi.list was null.'); final List args = (message as List?)!; final String? arg_path = (args[0] as String?); assert(arg_path != null, @@ -1217,14 +1246,15 @@ abstract class TestAssetManagerHostApi { } { final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.FlutterAssetManagerHostApi.getAssetFilePathByName', codec, + 'dev.flutter.pigeon.FlutterAssetManagerHostApi.getAssetFilePathByName', + codec, binaryMessenger: binaryMessenger); if (api == null) { channel.setMockMessageHandler(null); } else { channel.setMockMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.FlutterAssetManagerHostApi.getAssetFilePathByName was null.'); + 'Argument for dev.flutter.pigeon.FlutterAssetManagerHostApi.getAssetFilePathByName was null.'); final List args = (message as List?)!; final String? arg_name = (args[0] as String?); assert(arg_name != null, @@ -1244,7 +1274,8 @@ abstract class TestWebStorageHostApi { void deleteAllData(int instanceId); - static void setup(TestWebStorageHostApi? api, {BinaryMessenger? binaryMessenger}) { + static void setup(TestWebStorageHostApi? api, + {BinaryMessenger? binaryMessenger}) { { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.WebStorageHostApi.create', codec, @@ -1254,7 +1285,7 @@ abstract class TestWebStorageHostApi { } else { channel.setMockMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.WebStorageHostApi.create was null.'); + 'Argument for dev.flutter.pigeon.WebStorageHostApi.create was null.'); final List args = (message as List?)!; final int? arg_instanceId = (args[0] as int?); assert(arg_instanceId != null, @@ -1273,7 +1304,7 @@ abstract class TestWebStorageHostApi { } else { channel.setMockMessageHandler((Object? message) async { assert(message != null, - 'Argument for dev.flutter.pigeon.WebStorageHostApi.deleteAllData was null.'); + 'Argument for dev.flutter.pigeon.WebStorageHostApi.deleteAllData was null.'); final List args = (message as List?)!; final int? arg_instanceId = (args[0] as int?); assert(arg_instanceId != null, From ce1634c1f1bbbaeb987aa7bfc139e70a8579f2db Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Thu, 23 Feb 2023 12:57:39 -0500 Subject: [PATCH 04/24] fix tests --- .../android_navigation_delegate_test.dart | 70 ++---- ...ndroid_navigation_delegate_test.mocks.dart | 38 ++++ .../test/android_webview_controller_test.dart | 5 + ...android_webview_controller_test.mocks.dart | 194 +++++------------ .../test/android_webview_test.dart | 87 ++++---- .../test/android_webview_test.mocks.dart | 199 +++++------------- .../test/instance_manager_test.dart | 3 +- .../test/instance_manager_test.mocks.dart | 38 ++++ .../webview_android_widget_test.mocks.dart | 167 ++------------- 9 files changed, 267 insertions(+), 534 deletions(-) create mode 100644 packages/webview_flutter/webview_flutter_android/test/android_navigation_delegate_test.mocks.dart create mode 100644 packages/webview_flutter/webview_flutter_android/test/instance_manager_test.mocks.dart 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 5672c51cd94..2bf563b293d 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 @@ -5,13 +5,23 @@ import 'dart:async'; import 'package:flutter_test/flutter_test.dart'; +import 'package:mockito/annotations.dart'; import 'package:webview_flutter_android/src/android_proxy.dart'; import 'package:webview_flutter_android/src/android_webview.dart' as android_webview; 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]) void main() { + TestWidgetsFlutterBinding.ensureInitialized(); + + // Mocks the call to clear the native InstanceManager. + TestInstanceManagerHostApi.setup(MockTestInstanceManagerHostApi()); + group('AndroidNavigationDelegate', () { test('onPageFinished', () { final AndroidNavigationDelegate androidNavigationDelegate = @@ -22,10 +32,7 @@ void main() { .setOnPageFinished((String url) => callbackUrl = url); CapturingWebViewClient.lastCreatedDelegate.onPageFinished!( - android_webview.WebView.detached( - binaryMessenger: null, - instanceManager: null, - ), + android_webview.WebView.detached(), 'https://www.google.com', ); @@ -41,10 +48,7 @@ void main() { .setOnPageStarted((String url) => callbackUrl = url); CapturingWebViewClient.lastCreatedDelegate.onPageStarted!( - android_webview.WebView.detached( - binaryMessenger: null, - instanceManager: null, - ), + android_webview.WebView.detached(), 'https://www.google.com', ); @@ -60,10 +64,7 @@ void main() { (WebResourceError error) => callbackError = error); CapturingWebViewClient.lastCreatedDelegate.onReceivedRequestError!( - android_webview.WebView.detached( - binaryMessenger: null, - instanceManager: null, - ), + android_webview.WebView.detached(), android_webview.WebResourceRequest( url: 'https://www.google.com', isForMainFrame: false, @@ -94,10 +95,7 @@ void main() { (WebResourceError error) => callbackError = error); CapturingWebViewClient.lastCreatedDelegate.onReceivedError!( - android_webview.WebView.detached( - binaryMessenger: null, - instanceManager: null, - ), + android_webview.WebView.detached(), android_webview.WebViewClient.errorFileNotFound, 'Page not found.', 'https://www.google.com', @@ -124,10 +122,7 @@ void main() { }); CapturingWebViewClient.lastCreatedDelegate.requestLoading!( - android_webview.WebView.detached( - binaryMessenger: null, - instanceManager: null, - ), + android_webview.WebView.detached(), android_webview.WebResourceRequest( url: 'https://www.google.com', isForMainFrame: true, @@ -154,10 +149,7 @@ void main() { }); CapturingWebViewClient.lastCreatedDelegate.requestLoading!( - android_webview.WebView.detached( - binaryMessenger: null, - instanceManager: null, - ), + android_webview.WebView.detached(), android_webview.WebResourceRequest( url: 'https://www.google.com', isForMainFrame: true, @@ -191,10 +183,7 @@ void main() { }); CapturingWebViewClient.lastCreatedDelegate.requestLoading!( - android_webview.WebView.detached( - binaryMessenger: null, - instanceManager: null, - ), + android_webview.WebView.detached(), android_webview.WebResourceRequest( url: 'https://www.google.com', isForMainFrame: true, @@ -232,10 +221,7 @@ void main() { }); CapturingWebViewClient.lastCreatedDelegate.requestLoading!( - android_webview.WebView.detached( - binaryMessenger: null, - instanceManager: null, - ), + android_webview.WebView.detached(), android_webview.WebResourceRequest( url: 'https://www.google.com', isForMainFrame: true, @@ -267,10 +253,7 @@ void main() { }); CapturingWebViewClient.lastCreatedDelegate.urlLoading!( - android_webview.WebView.detached( - binaryMessenger: null, - instanceManager: null, - ), + android_webview.WebView.detached(), 'https://www.google.com', ); @@ -290,10 +273,7 @@ void main() { }); CapturingWebViewClient.lastCreatedDelegate.urlLoading!( - android_webview.WebView.detached( - binaryMessenger: null, - instanceManager: null, - ), + android_webview.WebView.detached(), 'https://www.google.com', ); @@ -320,10 +300,7 @@ void main() { }); CapturingWebViewClient.lastCreatedDelegate.urlLoading!( - android_webview.WebView.detached( - binaryMessenger: null, - instanceManager: null, - ), + android_webview.WebView.detached(), 'https://www.google.com', ); @@ -354,10 +331,7 @@ void main() { }); CapturingWebViewClient.lastCreatedDelegate.urlLoading!( - android_webview.WebView.detached( - binaryMessenger: null, - instanceManager: null, - ), + android_webview.WebView.detached(), 'https://www.google.com', ); 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 new file mode 100644 index 00000000000..25e2d424a44 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_android/test/android_navigation_delegate_test.mocks.dart @@ -0,0 +1,38 @@ +// Mocks generated by Mockito 5.3.2 from annotations +// in webview_flutter_android/test/android_navigation_delegate_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: 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/android_webview_controller_test.dart b/packages/webview_flutter/webview_flutter_android/test/android_webview_controller_test.dart index efa22071b30..49ab1ac496d 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 @@ -22,6 +22,7 @@ import 'package:webview_flutter_platform_interface/src/webview_platform.dart'; import 'android_navigation_delegate_test.dart'; import 'android_webview_controller_test.mocks.dart'; +import 'test_android_webview.g.dart'; @GenerateNiceMocks(>[ MockSpec(), @@ -39,10 +40,14 @@ import 'android_webview_controller_test.mocks.dart'; 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, 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 01885caff54..50b297f8578 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 @@ -22,6 +22,8 @@ import 'package:webview_flutter_android/src/platform_views_service_proxy.dart' 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 @@ -214,16 +216,6 @@ class _FakeWebSettings_16 extends _i1.SmartFake implements _i2.WebSettings { ); } -class _FakeWebStorage_17 extends _i1.SmartFake implements _i2.WebStorage { - _FakeWebStorage_17( - Object parent, - Invocation parentInvocation, - ) : super( - parent, - parentInvocation, - ); -} - /// A class which mocks [AndroidNavigationDelegate]. /// /// See the documentation for Mockito's code generation for more information. @@ -349,6 +341,12 @@ class MockAndroidNavigationDelegate extends _i1.Mock class MockAndroidWebViewController extends _i1.Mock implements _i8.AndroidWebViewController { @override + int get webViewIdentifier => (super.noSuchMethod( + Invocation.getter(#webViewIdentifier), + returnValue: 0, + returnValueForMissingStub: 0, + ) as int); + @override _i3.PlatformWebViewControllerCreationParams get params => (super.noSuchMethod( Invocation.getter(#params), returnValue: _FakePlatformWebViewControllerCreationParams_4( @@ -650,11 +648,11 @@ class MockAndroidWebViewController extends _i1.Mock @override _i9.Future setOnShowFileSelector( _i9.Future> Function(_i8.FileSelectorParams)? - onShowFileSelectorCallback) => + onShowFileSelector) => (super.noSuchMethod( Invocation.method( #setOnShowFileSelector, - [onShowFileSelectorCallback], + [onShowFileSelector], ), returnValue: _i9.Future.value(), returnValueForMissingStub: _i9.Future.value(), @@ -1253,6 +1251,7 @@ class MockFlutterAssetManager extends _i1.Mock /// A class which mocks [JavaScriptChannel]. /// /// See the documentation for Mockito's code generation for more information. +// ignore: must_be_immutable class MockJavaScriptChannel extends _i1.Mock implements _i2.JavaScriptChannel { @override String get channelName => (super.noSuchMethod( @@ -1266,27 +1265,6 @@ class MockJavaScriptChannel extends _i1.Mock implements _i2.JavaScriptChannel { returnValue: (String message) {}, returnValueForMissingStub: (String message) {}, ) as void Function(String)); - @override - _i2.JavaScriptChannel copy() => (super.noSuchMethod( - Invocation.method( - #copy, - [], - ), - returnValue: _FakeJavaScriptChannel_9( - this, - Invocation.method( - #copy, - [], - ), - ), - returnValueForMissingStub: _FakeJavaScriptChannel_9( - this, - Invocation.method( - #copy, - [], - ), - ), - ) as _i2.JavaScriptChannel); } /// A class which mocks [PlatformViewsServiceProxy]. @@ -1579,6 +1557,7 @@ class MockSurfaceAndroidViewController extends _i1.Mock /// A class which mocks [WebChromeClient]. /// /// See the documentation for Mockito's code generation for more information. +// ignore: must_be_immutable class MockWebChromeClient extends _i1.Mock implements _i2.WebChromeClient { @override _i9.Future setSynchronousReturnValueForOnShowFileChooser(bool? value) => @@ -1590,32 +1569,12 @@ class MockWebChromeClient extends _i1.Mock implements _i2.WebChromeClient { returnValue: _i9.Future.value(), returnValueForMissingStub: _i9.Future.value(), ) as _i9.Future); - @override - _i2.WebChromeClient copy() => (super.noSuchMethod( - Invocation.method( - #copy, - [], - ), - returnValue: _FakeWebChromeClient_0( - this, - Invocation.method( - #copy, - [], - ), - ), - returnValueForMissingStub: _FakeWebChromeClient_0( - this, - Invocation.method( - #copy, - [], - ), - ), - ) as _i2.WebChromeClient); } /// A class which mocks [WebSettings]. /// /// See the documentation for Mockito's code generation for more information. +// ignore: must_be_immutable class MockWebSettings extends _i1.Mock implements _i2.WebSettings { @override _i9.Future setDomStorageEnabled(bool? flag) => (super.noSuchMethod( @@ -1730,32 +1689,12 @@ class MockWebSettings extends _i1.Mock implements _i2.WebSettings { returnValue: _i9.Future.value(), returnValueForMissingStub: _i9.Future.value(), ) as _i9.Future); - @override - _i2.WebSettings copy() => (super.noSuchMethod( - Invocation.method( - #copy, - [], - ), - returnValue: _FakeWebSettings_16( - this, - Invocation.method( - #copy, - [], - ), - ), - returnValueForMissingStub: _FakeWebSettings_16( - this, - Invocation.method( - #copy, - [], - ), - ), - ) as _i2.WebSettings); } /// A class which mocks [WebView]. /// /// See the documentation for Mockito's code generation for more information. +// ignore: must_be_immutable class MockWebView extends _i1.Mock implements _i2.WebView { @override bool get useHybridComposition => (super.noSuchMethod( @@ -2063,32 +2002,12 @@ class MockWebView extends _i1.Mock implements _i2.WebView { returnValue: _i9.Future.value(), returnValueForMissingStub: _i9.Future.value(), ) as _i9.Future); - @override - _i2.WebView copy() => (super.noSuchMethod( - Invocation.method( - #copy, - [], - ), - returnValue: _FakeWebView_7( - this, - Invocation.method( - #copy, - [], - ), - ), - returnValueForMissingStub: _FakeWebView_7( - this, - Invocation.method( - #copy, - [], - ), - ), - ) as _i2.WebView); } /// A class which mocks [WebViewClient]. /// /// See the documentation for Mockito's code generation for more information. +// ignore: must_be_immutable class MockWebViewClient extends _i1.Mock implements _i2.WebViewClient { @override _i9.Future setSynchronousReturnValueForShouldOverrideUrlLoading( @@ -2101,32 +2020,12 @@ class MockWebViewClient extends _i1.Mock implements _i2.WebViewClient { returnValue: _i9.Future.value(), returnValueForMissingStub: _i9.Future.value(), ) as _i9.Future); - @override - _i2.WebViewClient copy() => (super.noSuchMethod( - Invocation.method( - #copy, - [], - ), - returnValue: _FakeWebViewClient_1( - this, - Invocation.method( - #copy, - [], - ), - ), - returnValueForMissingStub: _FakeWebViewClient_1( - this, - Invocation.method( - #copy, - [], - ), - ), - ) as _i2.WebViewClient); } /// A class which mocks [WebStorage]. /// /// See the documentation for Mockito's code generation for more information. +// ignore: must_be_immutable class MockWebStorage extends _i1.Mock implements _i2.WebStorage { @override _i9.Future deleteAllData() => (super.noSuchMethod( @@ -2137,27 +2036,6 @@ class MockWebStorage extends _i1.Mock implements _i2.WebStorage { returnValue: _i9.Future.value(), returnValueForMissingStub: _i9.Future.value(), ) as _i9.Future); - @override - _i2.WebStorage copy() => (super.noSuchMethod( - Invocation.method( - #copy, - [], - ), - returnValue: _FakeWebStorage_17( - this, - Invocation.method( - #copy, - [], - ), - ), - returnValueForMissingStub: _FakeWebStorage_17( - this, - Invocation.method( - #copy, - [], - ), - ), - ) as _i2.WebStorage); } /// A class which mocks [InstanceManager]. @@ -2180,16 +2058,21 @@ class MockInstanceManager extends _i1.Mock implements _i5.InstanceManager { returnValueForMissingStub: null, ); @override - int addDartCreatedInstance(_i5.Copyable? instance) => (super.noSuchMethod( + int addDartCreatedInstance( + T? instance, { + required T Function(T)? onCopy, + }) => + (super.noSuchMethod( Invocation.method( #addDartCreatedInstance, [instance], + {#onCopy: onCopy}, ), returnValue: 0, returnValueForMissingStub: 0, ) as int); @override - int? removeWeakReference(_i5.Copyable? instance) => (super.noSuchMethod( + int? removeWeakReference(Object? instance) => (super.noSuchMethod( Invocation.method( #removeWeakReference, [instance], @@ -2197,7 +2080,7 @@ class MockInstanceManager extends _i1.Mock implements _i5.InstanceManager { returnValueForMissingStub: null, ) as int?); @override - T? remove(int? identifier) => (super.noSuchMethod( + T? remove(int? identifier) => (super.noSuchMethod( Invocation.method( #remove, [identifier], @@ -2205,7 +2088,7 @@ class MockInstanceManager extends _i1.Mock implements _i5.InstanceManager { returnValueForMissingStub: null, ) as T?); @override - T? getInstanceWithWeakReference(int? identifier) => + T? getInstanceWithWeakReference(int? identifier) => (super.noSuchMethod( Invocation.method( #getInstanceWithWeakReference, @@ -2214,7 +2097,7 @@ class MockInstanceManager extends _i1.Mock implements _i5.InstanceManager { returnValueForMissingStub: null, ) as T?); @override - int? getIdentifier(_i5.Copyable? instance) => (super.noSuchMethod( + int? getIdentifier(Object? instance) => (super.noSuchMethod( Invocation.method( #getIdentifier, [instance], @@ -2222,10 +2105,11 @@ class MockInstanceManager extends _i1.Mock implements _i5.InstanceManager { returnValueForMissingStub: null, ) as int?); @override - void addHostCreatedInstance( - _i5.Copyable? instance, - int? identifier, - ) => + void addHostCreatedInstance( + T? instance, + int? identifier, { + required T Function(T)? onCopy, + }) => super.noSuchMethod( Invocation.method( #addHostCreatedInstance, @@ -2233,6 +2117,7 @@ class MockInstanceManager extends _i1.Mock implements _i5.InstanceManager { instance, identifier, ], + {#onCopy: onCopy}, ), returnValueForMissingStub: null, ); @@ -2246,3 +2131,18 @@ class MockInstanceManager extends _i1.Mock implements _i5.InstanceManager { 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_test.dart b/packages/webview_flutter/webview_flutter_android/test/android_webview_test.dart index b5c97f291c6..6191e804bea 100644 --- a/packages/webview_flutter/webview_flutter_android/test/android_webview_test.dart +++ b/packages/webview_flutter/webview_flutter_android/test/android_webview_test.dart @@ -18,6 +18,7 @@ import 'test_android_webview.g.dart'; DownloadListener, JavaScriptChannel, TestDownloadListenerHostApi, + TestInstanceManagerHostApi, TestJavaObjectHostApi, TestJavaScriptChannelHostApi, TestWebChromeClientHostApi, @@ -33,6 +34,9 @@ import 'test_android_webview.g.dart'; void main() { TestWidgetsFlutterBinding.ensureInitialized(); + // Mocks the call to clear the native InstanceManager. + TestInstanceManagerHostApi.setup(MockTestInstanceManagerHostApi()); + group('Android WebView', () { group('JavaObject', () { late MockTestJavaObjectHostApi mockPlatformHostApi; @@ -302,13 +306,25 @@ void main() { instanceManager: instanceManager, ); - final JavaScriptChannel mockJavaScriptChannel = MockJavaScriptChannel(); - when(mockJavaScriptChannel.channelName).thenReturn('aChannel'); + const int javaScriptChannelInstanceId = 5; + final JavaScriptChannel javaScriptChannel = JavaScriptChannel.detached( + 'aChannel', + postMessage: (_) {}, + instanceManager: instanceManager, + ); + instanceManager.addHostCreatedInstance( + javaScriptChannel, + javaScriptChannelInstanceId, + onCopy: (JavaScriptChannel original) { + return JavaScriptChannel.detached( + original.channelName, + postMessage: original.postMessage, + ); + }, + ); - webView.addJavaScriptChannel(mockJavaScriptChannel); + webView.addJavaScriptChannel(javaScriptChannel); - final int javaScriptChannelInstanceId = - instanceManager.getIdentifier(mockJavaScriptChannel)!; verify(mockPlatformHostApi.addJavaScriptChannel( webViewInstanceId, javaScriptChannelInstanceId, @@ -321,19 +337,26 @@ void main() { instanceManager: instanceManager, ); - final JavaScriptChannel mockJavaScriptChannel = MockJavaScriptChannel(); - when(mockJavaScriptChannel.channelName).thenReturn('aChannel'); - - expect( - webView.removeJavaScriptChannel(mockJavaScriptChannel), - completes, + const int javaScriptChannelInstanceId = 5; + final JavaScriptChannel javaScriptChannel = JavaScriptChannel.detached( + 'aChannel', + postMessage: (_) {}, + instanceManager: instanceManager, + ); + instanceManager.addHostCreatedInstance( + javaScriptChannel, + javaScriptChannelInstanceId, + onCopy: (JavaScriptChannel original) { + return JavaScriptChannel.detached( + original.channelName, + postMessage: original.postMessage, + ); + }, ); - webView.addJavaScriptChannel(mockJavaScriptChannel); - webView.removeJavaScriptChannel(mockJavaScriptChannel); + webView.addJavaScriptChannel(javaScriptChannel); + webView.removeJavaScriptChannel(javaScriptChannel); - final int javaScriptChannelInstanceId = - instanceManager.getIdentifier(mockJavaScriptChannel)!; verify(mockPlatformHostApi.removeJavaScriptChannel( webViewInstanceId, javaScriptChannelInstanceId, @@ -346,19 +369,22 @@ void main() { instanceManager: instanceManager, ); - final DownloadListener mockDownloadListener = MockDownloadListener(); - instanceManager.addDartCreatedInstance( - mockDownloadListener, + const int downloadListenerInstanceId = 5; + final DownloadListener downloadListener = DownloadListener.detached( + onDownloadStart: (_, __, ___, ____, _____) {}, + instanceManager: instanceManager, + ); + instanceManager.addHostCreatedInstance( + downloadListener, + downloadListenerInstanceId, onCopy: (DownloadListener original) { return DownloadListener.detached( onDownloadStart: original.onDownloadStart, ); }, ); - webView.setDownloadListener(mockDownloadListener); + webView.setDownloadListener(downloadListener); - final int downloadListenerInstanceId = - instanceManager.getIdentifier(mockDownloadListener)!; verify(mockPlatformHostApi.setDownloadListener( webViewInstanceId, downloadListenerInstanceId, @@ -530,17 +556,11 @@ void main() { ); mockJavaScriptChannel = MockJavaScriptChannel(); - when(mockJavaScriptChannel.copy()).thenReturn(MockJavaScriptChannel()); mockJavaScriptChannelInstanceId = instanceManager.addDartCreatedInstance( mockJavaScriptChannel, - onCopy: (JavaScriptChannel original) { - return JavaScriptChannel.detached( - original.channelName, - postMessage: original.postMessage, - ); - }, + onCopy: (_) => MockJavaScriptChannel(), ); }); @@ -577,7 +597,6 @@ void main() { ); mockWebViewClient = MockWebViewClient(); - when(mockWebViewClient.copy()).thenReturn(MockWebViewClient()); mockWebViewClientInstanceId = instanceManager.addDartCreatedInstance( mockWebViewClient, onCopy: (WebViewClient original) { @@ -586,7 +605,6 @@ void main() { ); mockWebView = MockWebView(); - when(mockWebView.copy()).thenReturn(MockWebView()); mockWebViewInstanceId = instanceManager.addDartCreatedInstance( mockWebView, onCopy: (WebView original) { @@ -750,14 +768,9 @@ void main() { ); mockDownloadListener = MockDownloadListener(); - when(mockDownloadListener.copy()).thenReturn(MockDownloadListener()); mockDownloadListenerInstanceId = instanceManager.addDartCreatedInstance( mockDownloadListener, - onCopy: (DownloadListener original) { - return DownloadListener.detached( - onDownloadStart: original.onDownloadStart, - ); - }, + onCopy: (_) => MockDownloadListener(), ); }); @@ -821,7 +834,6 @@ void main() { ); mockWebChromeClient = MockWebChromeClient(); - when(mockWebChromeClient.copy()).thenReturn(MockWebChromeClient()); mockWebChromeClientInstanceId = instanceManager.addDartCreatedInstance( mockWebChromeClient, @@ -831,7 +843,6 @@ void main() { ); mockWebView = MockWebView(); - when(mockWebView.copy()).thenReturn(MockWebView()); mockWebViewInstanceId = instanceManager.addDartCreatedInstance( mockWebView, onCopy: (WebView original) { 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 index 0b5afbaf5b1..210ec15b4c9 100644 --- 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 @@ -8,8 +8,8 @@ import 'dart:typed_data' as _i7; 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_webview.g.dart' as _i3; +import 'package:webview_flutter_android/src/android_webview.dart' as _i3; +import 'package:webview_flutter_android/src/android_webview.g.dart' as _i2; import 'test_android_webview.g.dart' as _i6; @@ -24,9 +24,8 @@ import 'test_android_webview.g.dart' as _i6; // ignore_for_file: camel_case_types // ignore_for_file: subtype_of_sealed_class -class _FakeDownloadListener_0 extends _i1.SmartFake - implements _i2.DownloadListener { - _FakeDownloadListener_0( +class _FakeWebViewPoint_0 extends _i1.SmartFake implements _i2.WebViewPoint { + _FakeWebViewPoint_0( Object parent, Invocation parentInvocation, ) : super( @@ -35,9 +34,8 @@ class _FakeDownloadListener_0 extends _i1.SmartFake ); } -class _FakeJavaScriptChannel_1 extends _i1.SmartFake - implements _i2.JavaScriptChannel { - _FakeJavaScriptChannel_1( +class _FakeWebSettings_1 extends _i1.SmartFake implements _i3.WebSettings { + _FakeWebSettings_1( Object parent, Invocation parentInvocation, ) : super( @@ -46,59 +44,8 @@ class _FakeJavaScriptChannel_1 extends _i1.SmartFake ); } -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( +class _FakeOffset_2 extends _i1.SmartFake implements _i4.Offset { + _FakeOffset_2( Object parent, Invocation parentInvocation, ) : super( @@ -111,7 +58,7 @@ class _FakeWebViewClient_7 extends _i1.SmartFake implements _i2.WebViewClient { /// /// See the documentation for Mockito's code generation for more information. class MockCookieManagerHostApi extends _i1.Mock - implements _i3.CookieManagerHostApi { + implements _i2.CookieManagerHostApi { MockCookieManagerHostApi() { _i1.throwOnMissingStub(this); } @@ -145,7 +92,8 @@ class MockCookieManagerHostApi extends _i1.Mock /// A class which mocks [DownloadListener]. /// /// See the documentation for Mockito's code generation for more information. -class MockDownloadListener extends _i1.Mock implements _i2.DownloadListener { +// ignore: must_be_immutable +class MockDownloadListener extends _i1.Mock implements _i3.DownloadListener { MockDownloadListener() { _i1.throwOnMissingStub(this); } @@ -173,26 +121,13 @@ class MockDownloadListener extends _i1.Mock implements _i2.DownloadListener { 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 { +// ignore: must_be_immutable +class MockJavaScriptChannel extends _i1.Mock implements _i3.JavaScriptChannel { MockJavaScriptChannel() { _i1.throwOnMissingStub(this); } @@ -207,20 +142,6 @@ class MockJavaScriptChannel extends _i1.Mock implements _i2.JavaScriptChannel { 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 [TestDownloadListenerHostApi]. @@ -242,6 +163,25 @@ class MockTestDownloadListenerHostApi extends _i1.Mock ); } +/// A class which mocks [TestInstanceManagerHostApi]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockTestInstanceManagerHostApi extends _i1.Mock + implements _i6.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. @@ -819,19 +759,19 @@ class MockTestWebViewHostApi extends _i1.Mock returnValue: 0, ) as int); @override - _i3.WebViewPoint getScrollPosition(int? instanceId) => (super.noSuchMethod( + _i2.WebViewPoint getScrollPosition(int? instanceId) => (super.noSuchMethod( Invocation.method( #getScrollPosition, [instanceId], ), - returnValue: _FakeWebViewPoint_2( + returnValue: _FakeWebViewPoint_0( this, Invocation.method( #getScrollPosition, [instanceId], ), ), - ) as _i3.WebViewPoint); + ) as _i2.WebViewPoint); @override void setWebContentsDebuggingEnabled(bool? enabled) => super.noSuchMethod( Invocation.method( @@ -962,7 +902,8 @@ class MockTestAssetManagerHostApi extends _i1.Mock /// A class which mocks [WebChromeClient]. /// /// See the documentation for Mockito's code generation for more information. -class MockWebChromeClient extends _i1.Mock implements _i2.WebChromeClient { +// ignore: must_be_immutable +class MockWebChromeClient extends _i1.Mock implements _i3.WebChromeClient { MockWebChromeClient() { _i1.throwOnMissingStub(this); } @@ -977,26 +918,13 @@ class MockWebChromeClient extends _i1.Mock implements _i2.WebChromeClient { 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 { +// ignore: must_be_immutable +class MockWebView extends _i1.Mock implements _i3.WebView { MockWebView() { _i1.throwOnMissingStub(this); } @@ -1007,13 +935,13 @@ class MockWebView extends _i1.Mock implements _i2.WebView { returnValue: false, ) as bool); @override - _i2.WebSettings get settings => (super.noSuchMethod( + _i3.WebSettings get settings => (super.noSuchMethod( Invocation.getter(#settings), - returnValue: _FakeWebSettings_4( + returnValue: _FakeWebSettings_1( this, Invocation.getter(#settings), ), - ) as _i2.WebSettings); + ) as _i3.WebSettings); @override _i5.Future loadData({ required String? data, @@ -1219,7 +1147,7 @@ class MockWebView extends _i1.Mock implements _i2.WebView { #getScrollPosition, [], ), - returnValue: _i5.Future<_i4.Offset>.value(_FakeOffset_5( + returnValue: _i5.Future<_i4.Offset>.value(_FakeOffset_2( this, Invocation.method( #getScrollPosition, @@ -1228,7 +1156,7 @@ class MockWebView extends _i1.Mock implements _i2.WebView { )), ) as _i5.Future<_i4.Offset>); @override - _i5.Future setWebViewClient(_i2.WebViewClient? webViewClient) => + _i5.Future setWebViewClient(_i3.WebViewClient? webViewClient) => (super.noSuchMethod( Invocation.method( #setWebViewClient, @@ -1239,7 +1167,7 @@ class MockWebView extends _i1.Mock implements _i2.WebView { ) as _i5.Future); @override _i5.Future addJavaScriptChannel( - _i2.JavaScriptChannel? javaScriptChannel) => + _i3.JavaScriptChannel? javaScriptChannel) => (super.noSuchMethod( Invocation.method( #addJavaScriptChannel, @@ -1250,7 +1178,7 @@ class MockWebView extends _i1.Mock implements _i2.WebView { ) as _i5.Future); @override _i5.Future removeJavaScriptChannel( - _i2.JavaScriptChannel? javaScriptChannel) => + _i3.JavaScriptChannel? javaScriptChannel) => (super.noSuchMethod( Invocation.method( #removeJavaScriptChannel, @@ -1260,7 +1188,7 @@ class MockWebView extends _i1.Mock implements _i2.WebView { returnValueForMissingStub: _i5.Future.value(), ) as _i5.Future); @override - _i5.Future setDownloadListener(_i2.DownloadListener? listener) => + _i5.Future setDownloadListener(_i3.DownloadListener? listener) => (super.noSuchMethod( Invocation.method( #setDownloadListener, @@ -1270,7 +1198,7 @@ class MockWebView extends _i1.Mock implements _i2.WebView { returnValueForMissingStub: _i5.Future.value(), ) as _i5.Future); @override - _i5.Future setWebChromeClient(_i2.WebChromeClient? client) => + _i5.Future setWebChromeClient(_i3.WebChromeClient? client) => (super.noSuchMethod( Invocation.method( #setWebChromeClient, @@ -1288,26 +1216,13 @@ class MockWebView extends _i1.Mock implements _i2.WebView { 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 { +// ignore: must_be_immutable +class MockWebViewClient extends _i1.Mock implements _i3.WebViewClient { MockWebViewClient() { _i1.throwOnMissingStub(this); } @@ -1323,18 +1238,4 @@ class MockWebViewClient extends _i1.Mock implements _i2.WebViewClient { 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 index 02ca60ba2b3..75c8e1b9602 100644 --- a/packages/webview_flutter/webview_flutter_android/test/instance_manager_test.dart +++ b/packages/webview_flutter/webview_flutter_android/test/instance_manager_test.dart @@ -5,6 +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/instance_manager.dart'; import 'instance_manager_test.mocks.dart'; @@ -184,7 +185,7 @@ void main() { MockTestInstanceManagerHostApi(); TestInstanceManagerHostApi.setup(mockApi); - BaseObject.globalInstanceManager; + JavaObject.globalInstanceManager; verify(mockApi.clear()); 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 new file mode 100644 index 00000000000..b474bf1ff56 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_android/test/instance_manager_test.mocks.dart @@ -0,0 +1,38 @@ +// Mocks generated by Mockito 5.3.2 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: 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_widget_test.mocks.dart b/packages/webview_flutter/webview_flutter_android/test/legacy/webview_android_widget_test.mocks.dart index 03489ce5c1e..9034eab7dae 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 @@ -35,8 +35,8 @@ class _FakeWebSettings_0 extends _i1.SmartFake implements _i2.WebSettings { ); } -class _FakeWebStorage_1 extends _i1.SmartFake implements _i2.WebStorage { - _FakeWebStorage_1( +class _FakeOffset_1 extends _i1.SmartFake implements _i3.Offset { + _FakeOffset_1( Object parent, Invocation parentInvocation, ) : super( @@ -45,8 +45,9 @@ class _FakeWebStorage_1 extends _i1.SmartFake implements _i2.WebStorage { ); } -class _FakeOffset_2 extends _i1.SmartFake implements _i3.Offset { - _FakeOffset_2( +class _FakeJavascriptChannelRegistry_2 extends _i1.SmartFake + implements _i4.JavascriptChannelRegistry { + _FakeJavascriptChannelRegistry_2( Object parent, Invocation parentInvocation, ) : super( @@ -65,52 +66,8 @@ class _FakeWebView_3 extends _i1.SmartFake implements _i2.WebView { ); } -class _FakeDownloadListener_4 extends _i1.SmartFake - implements _i2.DownloadListener { - _FakeDownloadListener_4( - Object parent, - Invocation parentInvocation, - ) : super( - parent, - parentInvocation, - ); -} - -class _FakeJavascriptChannelRegistry_5 extends _i1.SmartFake - implements _i4.JavascriptChannelRegistry { - _FakeJavascriptChannelRegistry_5( - Object parent, - Invocation parentInvocation, - ) : super( - parent, - parentInvocation, - ); -} - -class _FakeJavaScriptChannel_6 extends _i1.SmartFake - implements _i2.JavaScriptChannel { - _FakeJavaScriptChannel_6( - Object parent, - Invocation parentInvocation, - ) : super( - parent, - parentInvocation, - ); -} - -class _FakeWebChromeClient_7 extends _i1.SmartFake - implements _i2.WebChromeClient { - _FakeWebChromeClient_7( - Object parent, - Invocation parentInvocation, - ) : super( - parent, - parentInvocation, - ); -} - -class _FakeWebViewClient_8 extends _i1.SmartFake implements _i2.WebViewClient { - _FakeWebViewClient_8( +class _FakeWebViewClient_4 extends _i1.SmartFake implements _i2.WebViewClient { + _FakeWebViewClient_4( Object parent, Invocation parentInvocation, ) : super( @@ -150,6 +107,7 @@ class MockFlutterAssetManager extends _i1.Mock /// A class which mocks [WebSettings]. /// /// See the documentation for Mockito's code generation for more information. +// ignore: must_be_immutable class MockWebSettings extends _i1.Mock implements _i2.WebSettings { MockWebSettings() { _i1.throwOnMissingStub(this); @@ -268,25 +226,12 @@ class MockWebSettings extends _i1.Mock implements _i2.WebSettings { returnValue: _i5.Future.value(), returnValueForMissingStub: _i5.Future.value(), ) as _i5.Future); - @override - _i2.WebSettings copy() => (super.noSuchMethod( - Invocation.method( - #copy, - [], - ), - returnValue: _FakeWebSettings_0( - this, - Invocation.method( - #copy, - [], - ), - ), - ) as _i2.WebSettings); } /// A class which mocks [WebStorage]. /// /// See the documentation for Mockito's code generation for more information. +// ignore: must_be_immutable class MockWebStorage extends _i1.Mock implements _i2.WebStorage { MockWebStorage() { _i1.throwOnMissingStub(this); @@ -301,25 +246,12 @@ class MockWebStorage extends _i1.Mock implements _i2.WebStorage { returnValue: _i5.Future.value(), returnValueForMissingStub: _i5.Future.value(), ) as _i5.Future); - @override - _i2.WebStorage copy() => (super.noSuchMethod( - Invocation.method( - #copy, - [], - ), - returnValue: _FakeWebStorage_1( - this, - Invocation.method( - #copy, - [], - ), - ), - ) as _i2.WebStorage); } /// A class which mocks [WebView]. /// /// See the documentation for Mockito's code generation for more information. +// ignore: must_be_immutable class MockWebView extends _i1.Mock implements _i2.WebView { MockWebView() { _i1.throwOnMissingStub(this); @@ -543,7 +475,7 @@ class MockWebView extends _i1.Mock implements _i2.WebView { #getScrollPosition, [], ), - returnValue: _i5.Future<_i3.Offset>.value(_FakeOffset_2( + returnValue: _i5.Future<_i3.Offset>.value(_FakeOffset_1( this, Invocation.method( #getScrollPosition, @@ -612,20 +544,6 @@ class MockWebView extends _i1.Mock implements _i2.WebView { returnValue: _i5.Future.value(), returnValueForMissingStub: _i5.Future.value(), ) as _i5.Future); - @override - _i2.WebView copy() => (super.noSuchMethod( - Invocation.method( - #copy, - [], - ), - returnValue: _FakeWebView_3( - this, - Invocation.method( - #copy, - [], - ), - ), - ) as _i2.WebView); } /// A class which mocks [WebResourceRequest]. @@ -667,6 +585,7 @@ class MockWebResourceRequest extends _i1.Mock /// A class which mocks [DownloadListener]. /// /// See the documentation for Mockito's code generation for more information. +// ignore: must_be_immutable class MockDownloadListener extends _i1.Mock implements _i2.DownloadListener { MockDownloadListener() { _i1.throwOnMissingStub(this); @@ -695,20 +614,6 @@ class MockDownloadListener extends _i1.Mock implements _i2.DownloadListener { String, int, )); - @override - _i2.DownloadListener copy() => (super.noSuchMethod( - Invocation.method( - #copy, - [], - ), - returnValue: _FakeDownloadListener_4( - this, - Invocation.method( - #copy, - [], - ), - ), - ) as _i2.DownloadListener); } /// A class which mocks [WebViewAndroidJavaScriptChannel]. @@ -724,7 +629,7 @@ class MockWebViewAndroidJavaScriptChannel extends _i1.Mock _i4.JavascriptChannelRegistry get javascriptChannelRegistry => (super.noSuchMethod( Invocation.getter(#javascriptChannelRegistry), - returnValue: _FakeJavascriptChannelRegistry_5( + returnValue: _FakeJavascriptChannelRegistry_2( this, Invocation.getter(#javascriptChannelRegistry), ), @@ -739,25 +644,12 @@ class MockWebViewAndroidJavaScriptChannel extends _i1.Mock Invocation.getter(#postMessage), returnValue: (String message) {}, ) as void Function(String)); - @override - _i2.JavaScriptChannel copy() => (super.noSuchMethod( - Invocation.method( - #copy, - [], - ), - returnValue: _FakeJavaScriptChannel_6( - this, - Invocation.method( - #copy, - [], - ), - ), - ) as _i2.JavaScriptChannel); } /// A class which mocks [WebChromeClient]. /// /// See the documentation for Mockito's code generation for more information. +// ignore: must_be_immutable class MockWebChromeClient extends _i1.Mock implements _i2.WebChromeClient { MockWebChromeClient() { _i1.throwOnMissingStub(this); @@ -773,25 +665,12 @@ class MockWebChromeClient extends _i1.Mock implements _i2.WebChromeClient { returnValue: _i5.Future.value(), returnValueForMissingStub: _i5.Future.value(), ) as _i5.Future); - @override - _i2.WebChromeClient copy() => (super.noSuchMethod( - Invocation.method( - #copy, - [], - ), - returnValue: _FakeWebChromeClient_7( - this, - Invocation.method( - #copy, - [], - ), - ), - ) as _i2.WebChromeClient); } /// A class which mocks [WebViewClient]. /// /// See the documentation for Mockito's code generation for more information. +// ignore: must_be_immutable class MockWebViewClient extends _i1.Mock implements _i2.WebViewClient { MockWebViewClient() { _i1.throwOnMissingStub(this); @@ -808,20 +687,6 @@ class MockWebViewClient extends _i1.Mock implements _i2.WebViewClient { returnValue: _i5.Future.value(), returnValueForMissingStub: _i5.Future.value(), ) as _i5.Future); - @override - _i2.WebViewClient copy() => (super.noSuchMethod( - Invocation.method( - #copy, - [], - ), - returnValue: _FakeWebViewClient_8( - this, - Invocation.method( - #copy, - [], - ), - ), - ) as _i2.WebViewClient); } /// A class which mocks [JavascriptChannelRegistry]. @@ -997,7 +862,7 @@ class MockWebViewProxy extends _i1.Mock implements _i7.WebViewProxy { #urlLoading: urlLoading, }, ), - returnValue: _FakeWebViewClient_8( + returnValue: _FakeWebViewClient_4( this, Invocation.method( #createWebViewClient, From 44e6f8124796fe4510e0a1bc9f6c2bf2b6601cec Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Thu, 23 Feb 2023 13:07:16 -0500 Subject: [PATCH 05/24] update instancemanager --- .../webviewflutter/InstanceManager.java | 47 ++++++++++---- .../webviewflutter/WebViewFlutterPlugin.java | 3 + .../webviewflutter/InstanceManagerTest.java | 63 +++++++++++++++++++ 3 files changed, 101 insertions(+), 12 deletions(-) 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 index 55775a914c5..a82e9932a92 100644 --- 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 @@ -97,8 +97,14 @@ public T remove(long identifier) { /** * Retrieves the identifier paired with an instance. * - *

If the manager contains `instance`, as a strong or weak reference, the strong reference to - * `instance` will be recreated and will need to be removed again with {@link #remove(long)}. + *

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 @@ -120,14 +126,15 @@ public Long getIdentifierForStrongReference(Object instance) { /** * Adds a new instance that was instantiated from Dart. * - *

If an instance or identifier has already been added, it will be replaced by the new values. - * The Dart InstanceManager is considered the source of truth and has the capability to overwrite - * stored pairs in response to hot restarts. + *

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. * - *

If the manager is closed, the addition is ignored. + *

If the manager is closed, the addition is ignored and a warning is logged. * * @param instance the instance to be stored. - * @param identifier the identifier to be paired with instance. This value must be >= 0. + * @param identifier the identifier to be paired with instance. This value must be >= 0 and + * unique. */ public void addDartCreatedInstance(Object instance, long identifier) { if (isClosed()) { @@ -140,13 +147,16 @@ public void addDartCreatedInstance(Object instance, long identifier) { /** * Adds a new instance that was instantiated from the host platform. * - * @param instance the instance to be stored. + * @param instance the instance to be stored. This must be unique to all other added instances. * @return the unique identifier stored with instance. If the manager is closed, returns -1. */ public long addHostCreatedInstance(Object instance) { if (isClosed()) { Log.w(TAG, CLOSED_WARNING); return -1; + } else if (containsInstance(instance)) { + throw new IllegalArgumentException( + String.format("Instance of `%s` has already been added.", instance.getClass())); } final long identifier = nextIdentifier++; addInstance(instance, identifier); @@ -156,7 +166,7 @@ public long addHostCreatedInstance(Object instance) { /** * Retrieves the instance associated with identifier. * - * @param identifier the identifier paired to an instance. + * @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 or the manager is closed. @@ -171,7 +181,7 @@ public T getInstance(long identifier) { if (instance != null) { return instance.get(); } - return (T) strongInstances.get(identifier); + return null; } /** @@ -197,6 +207,15 @@ public boolean containsInstance(Object instance) { public void close() { handler.removeCallbacks(this::releaseAllFinalizedInstances); isClosed = true; + clear(); + } + + /** + * 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(); @@ -204,7 +223,7 @@ public void close() { } /** - * Whether the manager has released resources and is not longer usable. + * Whether the manager has released resources and is no longer usable. * *

See {@link #close()}. */ @@ -228,7 +247,11 @@ private void releaseAllFinalizedInstances() { private void addInstance(Object instance, long identifier) { if (identifier < 0) { - throw new IllegalArgumentException("Identifier must be >= 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); 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 04a9735e028..c30e956c893 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 @@ -17,6 +17,7 @@ import io.flutter.plugins.webviewflutter.GeneratedAndroidWebView.CookieManagerHostApi; import io.flutter.plugins.webviewflutter.GeneratedAndroidWebView.DownloadListenerHostApi; import io.flutter.plugins.webviewflutter.GeneratedAndroidWebView.FlutterAssetManagerHostApi; +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.WebChromeClientHostApi; @@ -84,6 +85,8 @@ private void setUp( new GeneratedAndroidWebView.JavaObjectFlutterApi(binaryMessenger) .dispose(identifier, reply -> {})); + InstanceManagerHostApi.setup(binaryMessenger, () -> instanceManager.clear()); + viewRegistry.registerViewFactory( "plugins.flutter.io/webview", new FlutterWebViewFactory(instanceManager)); 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 index 6a19c883548..2bda2d12c75 100644 --- 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 @@ -108,4 +108,67 @@ public void containsInstanceReturnsFalseWhenClosed() { assertFalse(instanceManager.containsInstance(object)); } + + @Test + public void clear() { + final InstanceManager instanceManager = InstanceManager.open(identifier -> {}); + + final Object instance = new Object(); + + instanceManager.addDartCreatedInstance(instance, 0); + assertTrue(instanceManager.containsInstance(instance)); + + instanceManager.clear(); + assertFalse(instanceManager.containsInstance(instance)); + + instanceManager.close(); + } + + @Test + public void canAddSameObjectWithAddDartCreatedInstance() { + final InstanceManager instanceManager = InstanceManager.open(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.close(); + } + + @Test(expected = IllegalArgumentException.class) + public void cannotAddSameObjectsWithAddHostCreatedInstance() { + final InstanceManager instanceManager = InstanceManager.open(identifier -> {}); + + final Object instance = new Object(); + + instanceManager.addHostCreatedInstance(instance); + instanceManager.addHostCreatedInstance(instance); + + instanceManager.close(); + } + + @Test(expected = IllegalArgumentException.class) + public void cannotUseIdentifierLessThanZero() { + final InstanceManager instanceManager = InstanceManager.open(identifier -> {}); + + instanceManager.addDartCreatedInstance(new Object(), -1); + + instanceManager.close(); + } + + @Test(expected = IllegalArgumentException.class) + public void identifiersMustBeUnique() { + final InstanceManager instanceManager = InstanceManager.open(identifier -> {}); + + instanceManager.addDartCreatedInstance(new Object(), 0); + instanceManager.addDartCreatedInstance(new Object(), 0); + + instanceManager.close(); + } } From ce6550bdf7f5d0119ebb96b8b8c3934e409d8649 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Thu, 23 Feb 2023 13:12:10 -0500 Subject: [PATCH 06/24] ensure callback methods are passed to copy --- .../lib/src/android_webview_api_impls.dart | 6 ++++++ 1 file changed, 6 insertions(+) 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 index 91eceae5e77..04aa8e69130 100644 --- 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 @@ -597,6 +597,12 @@ class WebViewClientHostApiImpl extends WebViewClientHostApi { instance, onCopy: (WebViewClient original) { return WebViewClient.detached( + onPageStarted: original.onPageStarted, + onPageFinished: original.onPageFinished, + onReceivedRequestError: original.onReceivedRequestError, + onReceivedError: original.onReceivedError, + requestLoading: original.requestLoading, + urlLoading: original.urlLoading, binaryMessenger: binaryMessenger, instanceManager: instanceManager, ); From def8956b1a2c4227ec5c2d17d53b8af00f40f7f1 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Thu, 23 Feb 2023 13:27:10 -0500 Subject: [PATCH 07/24] version bump --- .../webview_flutter/webview_flutter_android/CHANGELOG.md | 5 +++++ .../webview_flutter/webview_flutter_android/pubspec.yaml | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/webview_flutter/webview_flutter_android/CHANGELOG.md b/packages/webview_flutter/webview_flutter_android/CHANGELOG.md index 983ff4cdabb..caa173f2628 100644 --- a/packages/webview_flutter/webview_flutter_android/CHANGELOG.md +++ b/packages/webview_flutter/webview_flutter_android/CHANGELOG.md @@ -1,3 +1,8 @@ +## 3.3.2 + +* Updates internal Java InstanceManager to be cleared on hot restart. +* Updates internal Dart InstanceManager to handle creating copies of objects. + ## 3.3.1 * Updates links for the merge of flutter/plugins into flutter/packages. diff --git a/packages/webview_flutter/webview_flutter_android/pubspec.yaml b/packages/webview_flutter/webview_flutter_android/pubspec.yaml index 0ee96cbe5dd..bb9d5683567 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: 3.3.1 +version: 3.3.2 environment: sdk: ">=2.17.0 <3.0.0" From ca9993e17bcd3d1d76860cd364ff3c45b32522fd Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Thu, 23 Feb 2023 16:14:45 -0500 Subject: [PATCH 08/24] update tests since objects can't be added multiple times --- .../io/flutter/plugins/webviewflutter/WebViewClientTest.java | 4 ++-- .../java/io/flutter/plugins/webviewflutter/WebViewTest.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) 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 index 3267291b2e9..46ea90f6902 100644 --- 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 @@ -120,8 +120,8 @@ public WebViewClient createWebViewClient(WebViewClientFlutterApiImpl flutterApi) }, mockFlutterApi); - instanceManager.addDartCreatedInstance(mockWebViewClient, 0); - webViewClientHostApi.setSynchronousReturnValueForShouldOverrideUrlLoading(0L, false); + instanceManager.addDartCreatedInstance(mockWebViewClient, 2); + webViewClientHostApi.setSynchronousReturnValueForShouldOverrideUrlLoading(2L, false); verify(mockWebViewClient).setReturnValueForShouldOverrideUrlLoading(false); } 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 1721ccdce8e..02700fbc315 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 @@ -308,9 +308,9 @@ public void destroy() { } }; - testInstanceManager.addDartCreatedInstance(webView, 0); + testInstanceManager.addDartCreatedInstance(webView, 1); final JavaObjectHostApiImpl javaObjectHostApi = new JavaObjectHostApiImpl(testInstanceManager); - javaObjectHostApi.dispose(0L); + javaObjectHostApi.dispose(1L); assertTrue(destroyCalled[0]); } From 1c48779fbaf26fc66eeea9a6dd4db6e415d93c54 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Tue, 28 Feb 2023 10:16:20 -0500 Subject: [PATCH 09/24] fix test --- .../webview_flutter_test.dart | 6 +++++ .../lib/src/instance_manager.dart | 24 ++++++++++++++----- .../webview_flutter_android/pubspec.yaml | 1 + 3 files changed, 25 insertions(+), 6 deletions(-) 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 917870b6b4f..c4413441919 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 @@ -18,6 +18,7 @@ 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/weak_reference_utils.dart'; @@ -117,6 +118,11 @@ Future main() async { } }); + // 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, ); 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 index ac9856a6367..7f5f2723aa3 100644 --- a/packages/webview_flutter/webview_flutter_android/lib/src/instance_manager.dart +++ b/packages/webview_flutter/webview_flutter_android/lib/src/instance_manager.dart @@ -2,6 +2,10 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +// ignore_for_file: public_member_api_docs + +import 'package:meta/meta.dart'; + /// Maintains instances used to communicate with the native objects they /// represent. /// @@ -45,6 +49,7 @@ class InstanceManager { final Map> _weakInstances = >{}; final Map _strongInstances = {}; + // The function type is Object Function(Object), but final Map _copyCallbacks = {}; late final Finalizer _finalizer; int _nextIdentifier = 0; @@ -123,12 +128,12 @@ class InstanceManager { if (weakInstance == null) { final T? strongInstance = _strongInstances[identifier] as T?; if (strongInstance != null) { - // This cast is safe since it matches the argument type for - // _addInstanceWithIdentifier, which is the only place _copyCallbacks - // is populated. - final T Function(T) copyCallback = - _copyCallbacks[identifier]! as T Function(T); - final T copy = copyCallback(strongInstance); + final Function copyCallback = _copyCallbacks[identifier]!; + // A dynamic call is used because Function types don't work with + // inheritance. For example WebView Function(WebView) can't be casted to + // Object Function(Object). + // ignore: avoid_dynamic_calls + final T copy = copyCallback(strongInstance) as T; _identifiers[copy] = identifier; _weakInstances[identifier] = WeakReference(copy); _finalizer.attach(copy, identifier, detach: copy); @@ -195,3 +200,10 @@ class InstanceManager { return identifier; } } + +class A { + @mustBeOverridden + void t() { + + } +} diff --git a/packages/webview_flutter/webview_flutter_android/pubspec.yaml b/packages/webview_flutter/webview_flutter_android/pubspec.yaml index bb9d5683567..4ea928c105e 100644 --- a/packages/webview_flutter/webview_flutter_android/pubspec.yaml +++ b/packages/webview_flutter/webview_flutter_android/pubspec.yaml @@ -20,6 +20,7 @@ flutter: dependencies: flutter: sdk: flutter + meta: ^1.9.0 webview_flutter_platform_interface: ^2.0.0 dev_dependencies: From a552de98b45703373988253fe8135b9a335ba64d Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Tue, 28 Feb 2023 10:53:48 -0500 Subject: [PATCH 10/24] change back to using copyable --- .../lib/src/android_webview.dart | 152 +++++++++++++----- .../lib/src/android_webview_api_impls.dart | 80 +-------- .../lib/src/instance_manager.dart | 94 +++++------ .../webview_flutter_android/pubspec.yaml | 2 +- 4 files changed, 162 insertions(+), 166 deletions(-) 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 index ef930e55982..c2c0d83846e 100644 --- a/packages/webview_flutter/webview_flutter_android/lib/src/android_webview.dart +++ b/packages/webview_flutter/webview_flutter_android/lib/src/android_webview.dart @@ -2,11 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// TODO(bparrishMines): Replace unused callback methods in constructors with -// variables once automatic garbage collection is fully implemented. See -// https://github.com/flutter/flutter/issues/107199. -// ignore_for_file: avoid_unused_constructor_parameters - // TODO(a14n): remove this import once Flutter 3.1 or later reaches stable (including flutter/flutter#104231) // ignore: unnecessary_import import 'dart:typed_data'; @@ -26,8 +21,7 @@ export 'android_webview_api_impls.dart' show FileChooserMode; /// Root of the Java class hierarchy. /// /// See https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html. -@immutable -class JavaObject { +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 @@ -65,6 +59,11 @@ class JavaObject { static void dispose(JavaObject instance) { instance._api.instanceManager.removeWeakReference(instance); } + + @override + JavaObject copy() { + return JavaObject.detached(); + } } /// An Android View that displays web pages. @@ -86,7 +85,6 @@ class JavaObject { /// [Web-based content](https://developer.android.com/guide/webapps). /// /// When a [WebView] is no longer needed [release] must be called. -@immutable class WebView extends JavaObject { /// Constructs a new WebView. /// @@ -107,9 +105,9 @@ class WebView extends JavaObject { /// create copies. @protected WebView.detached({ - this.useHybridComposition = false, - super.binaryMessenger, - super.instanceManager, + required this.useHybridComposition, + required super.binaryMessenger, + required super.instanceManager, }) : super.detached(); /// Pigeon Host Api implementation for [WebView]. @@ -414,6 +412,15 @@ class WebView extends JavaObject { Future setBackgroundColor(Color color) { return api.setBackgroundColorFromInstance(this, color.value); } + + @override + WebView copy() { + return WebView.detached( + useHybridComposition: useHybridComposition, + binaryMessenger: _api.binaryMessenger, + instanceManager: _api.instanceManager, + ); + } } /// Manages cookies globally for all webviews. @@ -466,7 +473,6 @@ class CookieManager { /// 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. -@immutable class WebSettings extends JavaObject { /// Constructs a [WebSettings]. /// @@ -487,8 +493,8 @@ class WebSettings extends JavaObject { /// create copies. @protected WebSettings.detached({ - super.binaryMessenger, - super.instanceManager, + required super.binaryMessenger, + required super.instanceManager, }) : super.detached(); /// Pigeon Host Api implementation for [WebSettings]. @@ -612,12 +618,19 @@ class WebSettings extends JavaObject { Future setAllowFileAccess(bool enabled) { return api.setAllowFileAccessFromInstance(this, enabled); } + + @override + WebSettings copy() { + return WebSettings.detached( + binaryMessenger: _api.binaryMessenger, + instanceManager: _api.instanceManager, + ); + } } /// Exposes a channel to receive calls from javaScript. /// /// See [WebView.addJavaScriptChannel]. -@immutable class JavaScriptChannel extends JavaObject { /// Constructs a [JavaScriptChannel]. JavaScriptChannel( @@ -639,8 +652,8 @@ class JavaScriptChannel extends JavaObject { JavaScriptChannel.detached( this.channelName, { required this.postMessage, - super.binaryMessenger, - super.instanceManager, + required super.binaryMessenger, + required super.instanceManager, }) : super.detached(); /// Pigeon Host Api implementation for [JavaScriptChannel]. @@ -652,10 +665,19 @@ class JavaScriptChannel extends JavaObject { /// 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]. -@immutable class WebViewClient extends JavaObject { /// Constructs a [WebViewClient]. WebViewClient({ @@ -678,14 +700,15 @@ class WebViewClient extends JavaObject { /// create copies. @protected WebViewClient.detached({ - this.onPageStarted, - this.onPageFinished, - this.onReceivedRequestError, - @Deprecated('Only called on Android version < 23.') this.onReceivedError, - this.requestLoading, - this.urlLoading, - super.binaryMessenger, - super.instanceManager, + required this.onPageStarted, + required this.onPageFinished, + required this.onReceivedRequestError, + @Deprecated('Only called on Android version < 23.') + required this.onReceivedError, + required this.requestLoading, + required this.urlLoading, + required super.binaryMessenger, + required super.instanceManager, }) : super.detached(); /// User authentication failed on server. @@ -845,11 +868,24 @@ class WebViewClient extends JavaObject { ) { return api.setShouldOverrideUrlLoadingReturnValueFromInstance(this, value); } + + @override + WebViewClient copy() { + return WebViewClient.detached( + onPageStarted: onPageStarted, + onPageFinished: onPageFinished, + onReceivedRequestError: onReceivedRequestError, + onReceivedError: onReceivedError, + requestLoading: requestLoading, + urlLoading: urlLoading, + 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. -@immutable class DownloadListener extends JavaObject { /// Constructs a [DownloadListener]. DownloadListener({ @@ -869,8 +905,8 @@ class DownloadListener extends JavaObject { @protected DownloadListener.detached({ required this.onDownloadStart, - super.binaryMessenger, - super.instanceManager, + required super.binaryMessenger, + required super.instanceManager, }) : super.detached(); /// Pigeon Host Api implementation for [DownloadListener]. @@ -885,10 +921,18 @@ class DownloadListener extends JavaObject { String mimetype, int contentLength, ) onDownloadStart; + + @override + DownloadListener copy() { + return DownloadListener.detached( + onDownloadStart: onDownloadStart, + binaryMessenger: _api.binaryMessenger, + instanceManager: _api.instanceManager, + ); + } } /// Handles JavaScript dialogs, favicons, titles, and the progress for [WebView]. -@immutable class WebChromeClient extends JavaObject { /// Constructs a [WebChromeClient]. WebChromeClient({ @@ -908,10 +952,10 @@ class WebChromeClient extends JavaObject { /// create copies. @protected WebChromeClient.detached({ - this.onProgressChanged, - this.onShowFileChooser, - super.binaryMessenger, - super.instanceManager, + required this.onProgressChanged, + required this.onShowFileChooser, + required super.binaryMessenger, + required super.instanceManager, }) : super.detached(); /// Pigeon Host Api implementation for [WebChromeClient]. @@ -962,12 +1006,21 @@ class WebChromeClient extends JavaObject { value, ); } + + @override + WebChromeClient copy() { + return WebChromeClient.detached( + onProgressChanged: onProgressChanged, + onShowFileChooser: onShowFileChooser, + binaryMessenger: _api.binaryMessenger, + instanceManager: _api.instanceManager, + ); + } } /// Parameters received when a [WebChromeClient] should show a file chooser. /// /// See https://developer.android.com/reference/android/webkit/WebChromeClient.FileChooserParams. -@immutable class FileChooserParams extends JavaObject { /// Constructs a [FileChooserParams] without creating the associated Java /// object. @@ -980,8 +1033,8 @@ class FileChooserParams extends JavaObject { required this.acceptTypes, required this.filenameHint, required this.mode, - super.binaryMessenger, - super.instanceManager, + required super.binaryMessenger, + required super.instanceManager, }) : super.detached(); /// Preference for a live media captured value (e.g. Camera, Microphone). @@ -995,6 +1048,18 @@ class FileChooserParams extends JavaObject { /// 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. @@ -1070,7 +1135,6 @@ class FlutterAssetManager { /// Manages the JavaScript storage APIs provided by the [WebView]. /// /// Wraps [WebStorage](https://developer.android.com/reference/android/webkit/WebStorage). -@immutable class WebStorage extends JavaObject { /// Constructs a [WebStorage]. /// @@ -1091,8 +1155,8 @@ class WebStorage extends JavaObject { /// create copies. @protected WebStorage.detached({ - super.binaryMessenger, - super.instanceManager, + required super.binaryMessenger, + required super.instanceManager, }) : super.detached(); /// Pigeon Host Api implementation for [WebStorage]. @@ -1106,4 +1170,12 @@ class WebStorage extends JavaObject { Future deleteAllData() { return api.deleteAllDataFromInstance(this); } + + @override + WebStorage copy() { + return WebStorage.detached( + binaryMessenger: _api.binaryMessenger, + instanceManager: _api.instanceManager, + ); + } } 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 index 04aa8e69130..667bb425a03 100644 --- 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 @@ -154,14 +154,7 @@ class WebViewHostApiImpl extends WebViewHostApi { /// Helper method to convert instances ids to objects. Future createFromInstance(WebView instance) { return create( - instanceManager.addDartCreatedInstance( - instance, - onCopy: (WebView original) => WebView.detached( - useHybridComposition: original.useHybridComposition, - binaryMessenger: binaryMessenger, - instanceManager: instanceManager, - ), - ), + instanceManager.addDartCreatedInstance(instance), instance.useHybridComposition, ); } @@ -380,15 +373,7 @@ class WebSettingsHostApiImpl extends WebSettingsHostApi { /// Helper method to convert instances ids to objects. Future createFromInstance(WebSettings instance, WebView webView) { return create( - instanceManager.addDartCreatedInstance( - instance, - onCopy: (WebSettings original) { - return WebSettings.detached( - binaryMessenger: binaryMessenger, - instanceManager: instanceManager, - ); - }, - ), + instanceManager.addDartCreatedInstance(instance), instanceManager.getIdentifier(webView)!, ); } @@ -535,15 +520,7 @@ class JavaScriptChannelHostApiImpl extends JavaScriptChannelHostApi { /// Helper method to convert instances ids to objects. Future createFromInstance(JavaScriptChannel instance) async { if (instanceManager.getIdentifier(instance) == null) { - final int identifier = instanceManager.addDartCreatedInstance( - instance, - onCopy: (JavaScriptChannel original) => JavaScriptChannel.detached( - original.channelName, - postMessage: original.postMessage, - binaryMessenger: binaryMessenger, - instanceManager: instanceManager, - ), - ); + final int identifier = instanceManager.addDartCreatedInstance(instance); await create( identifier, instance.channelName, @@ -593,21 +570,7 @@ class WebViewClientHostApiImpl extends WebViewClientHostApi { /// Helper method to convert instances ids to objects. Future createFromInstance(WebViewClient instance) async { if (instanceManager.getIdentifier(instance) == null) { - final int identifier = instanceManager.addDartCreatedInstance( - instance, - onCopy: (WebViewClient original) { - return WebViewClient.detached( - onPageStarted: original.onPageStarted, - onPageFinished: original.onPageFinished, - onReceivedRequestError: original.onReceivedRequestError, - onReceivedError: original.onReceivedError, - requestLoading: original.requestLoading, - urlLoading: original.urlLoading, - binaryMessenger: binaryMessenger, - instanceManager: instanceManager, - ); - }, - ); + final int identifier = instanceManager.addDartCreatedInstance(instance); return create(identifier); } } @@ -800,14 +763,7 @@ class DownloadListenerHostApiImpl extends DownloadListenerHostApi { /// Helper method to convert instances ids to objects. Future createFromInstance(DownloadListener instance) async { if (instanceManager.getIdentifier(instance) == null) { - final int identifier = instanceManager.addDartCreatedInstance( - instance, - onCopy: (DownloadListener original) => DownloadListener.detached( - onDownloadStart: original.onDownloadStart, - binaryMessenger: binaryMessenger, - instanceManager: instanceManager, - ), - ); + final int identifier = instanceManager.addDartCreatedInstance(instance); return create(identifier); } } @@ -867,15 +823,7 @@ class WebChromeClientHostApiImpl extends WebChromeClientHostApi { /// Helper method to convert instances ids to objects. Future createFromInstance(WebChromeClient instance) async { if (instanceManager.getIdentifier(instance) == null) { - final int identifier = instanceManager.addDartCreatedInstance( - instance, - onCopy: (WebChromeClient original) => WebChromeClient.detached( - onProgressChanged: original.onProgressChanged, - onShowFileChooser: original.onShowFileChooser, - binaryMessenger: binaryMessenger, - instanceManager: instanceManager, - ), - ); + final int identifier = instanceManager.addDartCreatedInstance(instance); return create(identifier); } } @@ -962,13 +910,7 @@ class WebStorageHostApiImpl extends WebStorageHostApi { /// Helper method to convert instances ids to objects. Future createFromInstance(WebStorage instance) async { if (instanceManager.getIdentifier(instance) == null) { - final int identifier = instanceManager.addDartCreatedInstance( - instance, - onCopy: (WebStorage original) => WebStorage.detached( - binaryMessenger: binaryMessenger, - instanceManager: instanceManager, - ), - ); + final int identifier = instanceManager.addDartCreatedInstance(instance); return create(identifier); } } @@ -1014,14 +956,6 @@ class FileChooserParamsFlutterApiImpl extends FileChooserParamsFlutterApi { instanceManager: instanceManager, ), instanceId, - onCopy: (FileChooserParams original) => FileChooserParams.detached( - isCaptureEnabled: isCaptureEnabled, - acceptTypes: acceptTypes.cast(), - mode: mode.value, - filenameHint: filenameHint, - binaryMessenger: binaryMessenger, - instanceManager: instanceManager, - ), ); } } 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 index 7f5f2723aa3..86b0c04304b 100644 --- a/packages/webview_flutter/webview_flutter_android/lib/src/instance_manager.dart +++ b/packages/webview_flutter/webview_flutter_android/lib/src/instance_manager.dart @@ -2,10 +2,25 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// ignore_for_file: public_member_api_docs - import 'package:meta/meta.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 + @mustBeOverridden + Copyable copy(); +} + /// Maintains instances used to communicate with the native objects they /// represent. /// @@ -46,11 +61,9 @@ class InstanceManager { // by calling instanceManager.getIdentifier() inside of `==` while this was a // HashMap). final Expando _identifiers = Expando(); - final Map> _weakInstances = - >{}; - final Map _strongInstances = {}; - // The function type is Object Function(Object), but - final Map _copyCallbacks = {}; + final Map> _weakInstances = + >{}; + final Map _strongInstances = {}; late final Finalizer _finalizer; int _nextIdentifier = 0; @@ -66,12 +79,11 @@ class InstanceManager { /// Throws assertion error if the instance has already been added. /// /// Returns the randomly generated id of the [instance] added. - int addDartCreatedInstance( - T instance, { - required T Function(T original) onCopy, - }) { + int addDartCreatedInstance(Copyable instance) { + assert(getIdentifier(instance) == null); + final int identifier = _nextUniqueIdentifier(); - _addInstanceWithIdentifier(instance, identifier, onCopy: onCopy); + _addInstanceWithIdentifier(instance, identifier); return identifier; } @@ -83,7 +95,7 @@ class InstanceManager { /// /// This does not remove the the strong referenced instance associated with /// [instance]. This can be done with [remove]. - int? removeWeakReference(Object instance) { + int? removeWeakReference(Copyable instance) { final int? identifier = getIdentifier(instance); if (identifier == null) { return null; @@ -105,8 +117,7 @@ class InstanceManager { /// /// This does not remove the the weak referenced instance associtated with /// [identifier]. This can be done with [removeWeakReference]. - T? remove(int identifier) { - _copyCallbacks.remove(identifier); + T? remove(int identifier) { return _strongInstances.remove(identifier) as T?; } @@ -122,31 +133,26 @@ class InstanceManager { /// /// 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 T? weakInstance = _weakInstances[identifier]?.target as T?; + T? getInstanceWithWeakReference(int identifier) { + final Copyable? weakInstance = _weakInstances[identifier]?.target; if (weakInstance == null) { - final T? strongInstance = _strongInstances[identifier] as T?; + final Copyable? strongInstance = _strongInstances[identifier]; if (strongInstance != null) { - final Function copyCallback = _copyCallbacks[identifier]!; - // A dynamic call is used because Function types don't work with - // inheritance. For example WebView Function(WebView) can't be casted to - // Object Function(Object). - // ignore: avoid_dynamic_calls - final T copy = copyCallback(strongInstance) as T; + final Copyable copy = strongInstance.copy(); _identifiers[copy] = identifier; - _weakInstances[identifier] = WeakReference(copy); + _weakInstances[identifier] = WeakReference(copy); _finalizer.attach(copy, identifier, detach: copy); - return copy; + return copy as T; } - return strongInstance; + return strongInstance as T?; } - return weakInstance; + return weakInstance as T; } /// Retrieves the identifier associated with instance. - int? getIdentifier(Object instance) { + int? getIdentifier(Copyable instance) { return _identifiers[instance]; } @@ -159,30 +165,21 @@ class InstanceManager { /// added. /// /// Returns unique identifier of the [instance] added. - void addHostCreatedInstance( - T instance, - int identifier, { - required T Function(T original) onCopy, - }) { - _addInstanceWithIdentifier(instance, identifier, onCopy: onCopy); - } - - void _addInstanceWithIdentifier( - T instance, - int identifier, { - required T Function(T original) onCopy, - }) { + void addHostCreatedInstance(Copyable instance, int identifier) { assert(!containsIdentifier(identifier)); assert(getIdentifier(instance) == null); assert(identifier >= 0); + _addInstanceWithIdentifier(instance, identifier); + } + + void _addInstanceWithIdentifier(Copyable instance, int identifier) { _identifiers[instance] = identifier; - _weakInstances[identifier] = WeakReference(instance); + _weakInstances[identifier] = WeakReference(instance); _finalizer.attach(instance, identifier, detach: instance); - final Object copy = onCopy(instance); + final Copyable copy = instance.copy(); _identifiers[copy] = identifier; _strongInstances[identifier] = copy; - _copyCallbacks[identifier] = onCopy; } /// Whether this manager contains the given [identifier]. @@ -200,10 +197,3 @@ class InstanceManager { return identifier; } } - -class A { - @mustBeOverridden - void t() { - - } -} diff --git a/packages/webview_flutter/webview_flutter_android/pubspec.yaml b/packages/webview_flutter/webview_flutter_android/pubspec.yaml index 4ea928c105e..3c6e7a3cecc 100644 --- a/packages/webview_flutter/webview_flutter_android/pubspec.yaml +++ b/packages/webview_flutter/webview_flutter_android/pubspec.yaml @@ -20,7 +20,7 @@ flutter: dependencies: flutter: sdk: flutter - meta: ^1.9.0 + meta: ^1.8.0 webview_flutter_platform_interface: ^2.0.0 dev_dependencies: From 9d58bd8dc3bee9991809ab6de713784e197555ed Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Tue, 28 Feb 2023 11:25:40 -0500 Subject: [PATCH 11/24] probably fix tests --- .../lib/src/android_webview.dart | 51 +++++----- .../android_navigation_delegate_test.dart | 15 +++ .../test/android_webview_controller_test.dart | 9 +- .../test/android_webview_test.dart | 88 ++--------------- .../test/instance_manager_test.dart | 97 ++++++------------- 5 files changed, 80 insertions(+), 180 deletions(-) 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 index c2c0d83846e..ac7f179156c 100644 --- a/packages/webview_flutter/webview_flutter_android/lib/src/android_webview.dart +++ b/packages/webview_flutter/webview_flutter_android/lib/src/android_webview.dart @@ -105,9 +105,9 @@ class WebView extends JavaObject { /// create copies. @protected WebView.detached({ - required this.useHybridComposition, - required super.binaryMessenger, - required super.instanceManager, + this.useHybridComposition = false, + super.binaryMessenger, + super.instanceManager, }) : super.detached(); /// Pigeon Host Api implementation for [WebView]. @@ -493,8 +493,8 @@ class WebSettings extends JavaObject { /// create copies. @protected WebSettings.detached({ - required super.binaryMessenger, - required super.instanceManager, + super.binaryMessenger, + super.instanceManager, }) : super.detached(); /// Pigeon Host Api implementation for [WebSettings]. @@ -652,8 +652,8 @@ class JavaScriptChannel extends JavaObject { JavaScriptChannel.detached( this.channelName, { required this.postMessage, - required super.binaryMessenger, - required super.instanceManager, + super.binaryMessenger, + super.instanceManager, }) : super.detached(); /// Pigeon Host Api implementation for [JavaScriptChannel]. @@ -700,15 +700,14 @@ class WebViewClient extends JavaObject { /// create copies. @protected WebViewClient.detached({ - required this.onPageStarted, - required this.onPageFinished, - required this.onReceivedRequestError, - @Deprecated('Only called on Android version < 23.') - required this.onReceivedError, - required this.requestLoading, - required this.urlLoading, - required super.binaryMessenger, - required super.instanceManager, + this.onPageStarted, + this.onPageFinished, + this.onReceivedRequestError, + @Deprecated('Only called on Android version < 23.') this.onReceivedError, + this.requestLoading, + this.urlLoading, + super.binaryMessenger, + super.instanceManager, }) : super.detached(); /// User authentication failed on server. @@ -905,8 +904,8 @@ class DownloadListener extends JavaObject { @protected DownloadListener.detached({ required this.onDownloadStart, - required super.binaryMessenger, - required super.instanceManager, + super.binaryMessenger, + super.instanceManager, }) : super.detached(); /// Pigeon Host Api implementation for [DownloadListener]. @@ -952,10 +951,10 @@ class WebChromeClient extends JavaObject { /// create copies. @protected WebChromeClient.detached({ - required this.onProgressChanged, - required this.onShowFileChooser, - required super.binaryMessenger, - required super.instanceManager, + this.onProgressChanged, + this.onShowFileChooser, + super.binaryMessenger, + super.instanceManager, }) : super.detached(); /// Pigeon Host Api implementation for [WebChromeClient]. @@ -1033,8 +1032,8 @@ class FileChooserParams extends JavaObject { required this.acceptTypes, required this.filenameHint, required this.mode, - required super.binaryMessenger, - required super.instanceManager, + super.binaryMessenger, + super.instanceManager, }) : super.detached(); /// Preference for a live media captured value (e.g. Camera, Microphone). @@ -1155,8 +1154,8 @@ class WebStorage extends JavaObject { /// create copies. @protected WebStorage.detached({ - required super.binaryMessenger, - required super.instanceManager, + super.binaryMessenger, + super.instanceManager, }) : super.detached(); /// Pigeon Host Api implementation for [WebStorage]. 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 2bf563b293d..c0d84a17348 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 @@ -486,6 +486,11 @@ class CapturingWebViewClient extends android_webview.WebViewClient { bool value) async { synchronousReturnValueForShouldOverrideUrlLoading = value; } + + @override + CapturingWebViewClient copy() { + return CapturingWebViewClient(); + } } // Records the last created instance of itself. @@ -500,6 +505,11 @@ class CapturingWebChromeClient extends android_webview.WebChromeClient { } static CapturingWebChromeClient lastCreatedDelegate = CapturingWebChromeClient(); + + @override + CapturingWebChromeClient copy() { + return CapturingWebChromeClient(); + } } // Records the last created instance of itself. @@ -513,4 +523,9 @@ class CapturingDownloadListener extends android_webview.DownloadListener { } static CapturingDownloadListener lastCreatedListener = CapturingDownloadListener(onDownloadStart: (_, __, ___, ____, _____) {}); + + @override + CapturingDownloadListener copy() { + return CapturingDownloadListener(onDownloadStart: onDownloadStart); + } } 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 49ab1ac496d..30e7ae06abd 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 @@ -895,14 +895,7 @@ void main() { final InstanceManager instanceManager = InstanceManager( onWeakReferenceRemoved: (_) {}, ); - instanceManager.addHostCreatedInstance( - mockWebView, - 0, - onCopy: (android_webview.WebView original) { - return android_webview.WebView.detached( - instanceManager: instanceManager); - }, - ); + instanceManager.addHostCreatedInstance(mockWebView, 0); android_webview.WebView.api = WebViewHostApiImpl( instanceManager: instanceManager, 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 index 6191e804bea..b561de3e3fb 100644 --- a/packages/webview_flutter/webview_flutter_android/test/android_webview_test.dart +++ b/packages/webview_flutter/webview_flutter_android/test/android_webview_test.dart @@ -61,13 +61,7 @@ void main() { final JavaObject object = JavaObject.detached( instanceManager: instanceManager, ); - instanceManager.addHostCreatedInstance( - object, - 0, - onCopy: (JavaObject original) { - return JavaObject.detached(instanceManager: instanceManager); - }, - ); + instanceManager.addHostCreatedInstance(object, 0); JavaObject.dispose(object); @@ -82,13 +76,7 @@ void main() { final JavaObject object = JavaObject.detached( instanceManager: instanceManager, ); - instanceManager.addHostCreatedInstance( - object, - 0, - onCopy: (JavaObject original) { - return JavaObject.detached(instanceManager: instanceManager); - }, - ); + instanceManager.addHostCreatedInstance(object, 0); instanceManager.removeWeakReference(object); expect(instanceManager.containsIdentifier(0), isTrue); @@ -284,12 +272,7 @@ void main() { ); final WebViewClient mockWebViewClient = MockWebViewClient(); - instanceManager.addDartCreatedInstance( - mockWebViewClient, - onCopy: (WebViewClient original) { - return WebViewClient.detached(); - }, - ); + instanceManager.addDartCreatedInstance(mockWebViewClient); webView.setWebViewClient(mockWebViewClient); final int webViewClientInstanceId = @@ -315,12 +298,6 @@ void main() { instanceManager.addHostCreatedInstance( javaScriptChannel, javaScriptChannelInstanceId, - onCopy: (JavaScriptChannel original) { - return JavaScriptChannel.detached( - original.channelName, - postMessage: original.postMessage, - ); - }, ); webView.addJavaScriptChannel(javaScriptChannel); @@ -346,12 +323,6 @@ void main() { instanceManager.addHostCreatedInstance( javaScriptChannel, javaScriptChannelInstanceId, - onCopy: (JavaScriptChannel original) { - return JavaScriptChannel.detached( - original.channelName, - postMessage: original.postMessage, - ); - }, ); webView.addJavaScriptChannel(javaScriptChannel); @@ -377,11 +348,6 @@ void main() { instanceManager.addHostCreatedInstance( downloadListener, downloadListenerInstanceId, - onCopy: (DownloadListener original) { - return DownloadListener.detached( - onDownloadStart: original.onDownloadStart, - ); - }, ); webView.setDownloadListener(downloadListener); @@ -400,9 +366,6 @@ void main() { final WebChromeClient mockWebChromeClient = MockWebChromeClient(); instanceManager.addDartCreatedInstance( mockWebChromeClient, - onCopy: (WebChromeClient original) { - return WebChromeClient.detached(); - }, ); webView.setWebChromeClient(mockWebChromeClient); @@ -560,7 +523,6 @@ void main() { mockJavaScriptChannelInstanceId = instanceManager.addDartCreatedInstance( mockJavaScriptChannel, - onCopy: (_) => MockJavaScriptChannel(), ); }); @@ -599,17 +561,11 @@ void main() { mockWebViewClient = MockWebViewClient(); mockWebViewClientInstanceId = instanceManager.addDartCreatedInstance( mockWebViewClient, - onCopy: (WebViewClient original) { - return WebViewClient.detached(); - }, ); mockWebView = MockWebView(); mockWebViewInstanceId = instanceManager.addDartCreatedInstance( mockWebView, - onCopy: (WebView original) { - return WebView.detached(); - }, ); }); @@ -770,7 +726,6 @@ void main() { mockDownloadListener = MockDownloadListener(); mockDownloadListenerInstanceId = instanceManager.addDartCreatedInstance( mockDownloadListener, - onCopy: (_) => MockDownloadListener(), ); }); @@ -837,17 +792,11 @@ void main() { mockWebChromeClientInstanceId = instanceManager.addDartCreatedInstance( mockWebChromeClient, - onCopy: (WebChromeClient original) { - return WebChromeClient.detached(); - }, ); mockWebView = MockWebView(); mockWebViewInstanceId = instanceManager.addDartCreatedInstance( mockWebView, - onCopy: (WebView original) { - return WebView.detached(); - }, ); }); @@ -884,18 +833,7 @@ void main() { mode: FileChooserMode.open, ); - instanceManager.addHostCreatedInstance( - params, - 3, - onCopy: (FileChooserParams original) { - return FileChooserParams.detached( - acceptTypes: original.acceptTypes, - filenameHint: original.filenameHint, - isCaptureEnabled: original.isCaptureEnabled, - mode: original.mode, - ); - }, - ); + instanceManager.addHostCreatedInstance(params, 3); await expectLater( flutterApi.onShowFileChooser( @@ -920,10 +858,7 @@ void main() { final WebChromeClient webChromeClient = WebChromeClient.detached(); instanceManager.addHostCreatedInstance( webChromeClient, - 2, - onCopy: (WebChromeClient original) { - return WebChromeClient.detached(); - }, + 2 ); webChromeClient.setSynchronousReturnValueForOnShowFileChooser(false); @@ -945,13 +880,7 @@ void main() { final WebChromeClient clientWithNullCallback = WebChromeClient.detached(); - instanceManager.addHostCreatedInstance( - clientWithNullCallback, - 2, - onCopy: (WebChromeClient original) { - return WebChromeClient.detached(); - }, - ); + instanceManager.addHostCreatedInstance(clientWithNullCallback, 2); expect( () => clientWithNullCallback @@ -965,10 +894,7 @@ void main() { ); instanceManager.addHostCreatedInstance( clientWithNonnullCallback, - 3, - onCopy: (WebChromeClient original) { - return WebChromeClient.detached(); - }, + 3 ); clientWithNonnullCallback 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 index 75c8e1b9602..e8bf248ade2 100644 --- a/packages/webview_flutter/webview_flutter_android/test/instance_manager_test.dart +++ b/packages/webview_flutter/webview_flutter_android/test/instance_manager_test.dart @@ -13,20 +13,14 @@ import 'test_android_webview.g.dart'; @GenerateMocks([TestInstanceManagerHostApi]) void main() { - TestWidgetsFlutterBinding.ensureInitialized(); - group('InstanceManager', () { test('addHostCreatedInstance', () { - final Object object = Object(); + final CopyableObject object = CopyableObject(); final InstanceManager instanceManager = InstanceManager(onWeakReferenceRemoved: (_) {}); - instanceManager.addHostCreatedInstance( - object, - 0, - onCopy: (_) => Object(), - ); + instanceManager.addHostCreatedInstance(object, 0); expect(instanceManager.getIdentifier(object), 0); expect( @@ -36,46 +30,31 @@ void main() { }); test('addHostCreatedInstance prevents already used objects and ids', () { - final Object object = Object(); + final CopyableObject object = CopyableObject(); final InstanceManager instanceManager = InstanceManager(onWeakReferenceRemoved: (_) {}); - instanceManager.addHostCreatedInstance( - object, - 0, - onCopy: (_) => Object(), - ); + instanceManager.addHostCreatedInstance(object, 0); expect( - () => instanceManager.addHostCreatedInstance( - object, - 0, - onCopy: (_) => Object(), - ), + () => instanceManager.addHostCreatedInstance(object, 0), throwsAssertionError, ); expect( - () => instanceManager.addHostCreatedInstance( - Object(), - 0, - onCopy: (_) => Object(), - ), + () => instanceManager.addHostCreatedInstance(CopyableObject(), 0), throwsAssertionError, ); }); - test('addDartCreatedInstance', () { - final Object object = Object(); + test('addFlutterCreatedInstance', () { + final CopyableObject object = CopyableObject(); final InstanceManager instanceManager = InstanceManager(onWeakReferenceRemoved: (_) {}); - instanceManager.addDartCreatedInstance( - object, - onCopy: (_) => Object(), - ); + instanceManager.addDartCreatedInstance(object); final int? instanceId = instanceManager.getIdentifier(object); expect(instanceId, isNotNull); @@ -86,7 +65,7 @@ void main() { }); test('removeWeakReference', () { - final Object object = Object(); + final CopyableObject object = CopyableObject(); int? weakInstanceId; final InstanceManager instanceManager = @@ -94,67 +73,51 @@ void main() { weakInstanceId = instanceId; }); - instanceManager.addHostCreatedInstance( - object, - 0, - onCopy: (_) => Object(), - ); + instanceManager.addHostCreatedInstance(object, 0); expect(instanceManager.removeWeakReference(object), 0); expect( instanceManager.getInstanceWithWeakReference(0), - isA(), + isA(), ); expect(weakInstanceId, 0); }); test('removeWeakReference removes only weak reference', () { - final Object object = Object(); + final CopyableObject object = CopyableObject(); final InstanceManager instanceManager = InstanceManager(onWeakReferenceRemoved: (_) {}); - instanceManager.addHostCreatedInstance( - object, - 0, - onCopy: (_) => Object(), - ); + instanceManager.addHostCreatedInstance(object, 0); expect(instanceManager.removeWeakReference(object), 0); - final Object copy = instanceManager.getInstanceWithWeakReference( + final CopyableObject copy = instanceManager.getInstanceWithWeakReference( 0, )!; expect(identical(object, copy), isFalse); }); test('removeStrongReference', () { - final Object object = Object(); + final CopyableObject object = CopyableObject(); final InstanceManager instanceManager = InstanceManager(onWeakReferenceRemoved: (_) {}); - instanceManager.addHostCreatedInstance( - object, - 0, - onCopy: (_) => Object(), - ); + instanceManager.addHostCreatedInstance(object, 0); instanceManager.removeWeakReference(object); - expect(instanceManager.remove(0), isA()); + expect(instanceManager.remove(0), isA()); expect(instanceManager.containsIdentifier(0), isFalse); }); test('removeStrongReference removes only strong reference', () { - final Object object = Object(); + final CopyableObject object = CopyableObject(); final InstanceManager instanceManager = InstanceManager(onWeakReferenceRemoved: (_) {}); - instanceManager.addHostCreatedInstance( - object, - 0, - onCopy: (_) => Object(), - ); - expect(instanceManager.remove(0), isA()); + instanceManager.addHostCreatedInstance(object, 0); + expect(instanceManager.remove(0), isA()); expect( instanceManager.getInstanceWithWeakReference(0), object, @@ -162,19 +125,16 @@ void main() { }); test('getInstance can add a new weak reference', () { - final Object object = Object(); + final CopyableObject object = CopyableObject(); final InstanceManager instanceManager = InstanceManager(onWeakReferenceRemoved: (_) {}); - instanceManager.addHostCreatedInstance( - object, - 0, - onCopy: (_) => Object(), - ); + instanceManager.addHostCreatedInstance(object, 0); instanceManager.removeWeakReference(object); - final Object newWeakCopy = instanceManager.getInstanceWithWeakReference( + final CopyableObject newWeakCopy = + instanceManager.getInstanceWithWeakReference( 0, )!; expect(identical(object, newWeakCopy), isFalse); @@ -193,3 +153,10 @@ void main() { }); }); } + +class CopyableObject with Copyable { + @override + Copyable copy() { + return CopyableObject(); + } +} From 2a05f7c12e7dd7d15587fb8d9dda2a87239497e1 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Tue, 28 Feb 2023 11:32:25 -0500 Subject: [PATCH 12/24] some reverts --- .../legacy/webview_flutter_test.dart | 15 +- .../webview_flutter_test.dart | 17 +- ...android_webview_controller_test.mocks.dart | 167 +++++++++++++--- .../test/android_webview_test.dart | 144 ++++++++------ .../test/android_webview_test.mocks.dart | 180 +++++++++++++++--- .../test/instance_manager_test.dart | 2 + .../webview_android_widget_test.mocks.dart | 167 ++++++++++++++-- 7 files changed, 544 insertions(+), 148 deletions(-) diff --git a/packages/webview_flutter/webview_flutter_android/example/integration_test/legacy/webview_flutter_test.dart b/packages/webview_flutter/webview_flutter_android/example/integration_test/legacy/webview_flutter_test.dart index f3688313834..cbec6b76795 100644 --- a/packages/webview_flutter/webview_flutter_android/example/integration_test/legacy/webview_flutter_test.dart +++ b/packages/webview_flutter/webview_flutter_android/example/integration_test/legacy/webview_flutter_test.dart @@ -113,13 +113,7 @@ Future main() async { ); ClassWithCallbackClass? instance = ClassWithCallbackClass(); - instanceManager.addHostCreatedInstance( - instance.callbackClass, - 0, - onCopy: (CopyableObjectWithCallback original) { - return CopyableObjectWithCallback(original.callback); - }, - ); + instanceManager.addHostCreatedInstance(instance.callbackClass, 0); instance = null; // Force garbage collection. @@ -1549,10 +1543,15 @@ class ResizableWebViewState extends State { } } -class CopyableObjectWithCallback { +class CopyableObjectWithCallback with Copyable { CopyableObjectWithCallback(this.callback); final VoidCallback callback; + + @override + CopyableObjectWithCallback copy() { + return CopyableObjectWithCallback(callback); + } } class ClassWithCallbackClass { 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 c4413441919..fa6d976728f 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 @@ -84,13 +84,7 @@ Future main() async { ); ClassWithCallbackClass? instance = ClassWithCallbackClass(); - instanceManager.addHostCreatedInstance( - instance.callbackClass, - 0, - onCopy: (CopyableObjectWithCallback original) { - return CopyableObjectWithCallback(original.callback); - }, - ); + instanceManager.addHostCreatedInstance(instance.callbackClass, 0); instance = null; // Force garbage collection. @@ -111,7 +105,7 @@ Future main() async { late final InstanceManager instanceManager; instanceManager = InstanceManager(onWeakReferenceRemoved: (int identifier) { - final Object instance = + final Copyable instance = instanceManager.getInstanceWithWeakReference(identifier)!; if (instance is android.WebView && !webViewGCCompleter.isCompleted) { webViewGCCompleter.complete(); @@ -1234,10 +1228,15 @@ class ResizableWebViewState extends State { } } -class CopyableObjectWithCallback { +class CopyableObjectWithCallback with Copyable { CopyableObjectWithCallback(this.callback); final VoidCallback callback; + + @override + CopyableObjectWithCallback copy() { + return CopyableObjectWithCallback(callback); + } } class ClassWithCallbackClass { 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 50b297f8578..4b2843ea4a8 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 @@ -216,6 +216,16 @@ class _FakeWebSettings_16 extends _i1.SmartFake implements _i2.WebSettings { ); } +class _FakeWebStorage_17 extends _i1.SmartFake implements _i2.WebStorage { + _FakeWebStorage_17( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + /// A class which mocks [AndroidNavigationDelegate]. /// /// See the documentation for Mockito's code generation for more information. @@ -1251,7 +1261,6 @@ class MockFlutterAssetManager extends _i1.Mock /// A class which mocks [JavaScriptChannel]. /// /// See the documentation for Mockito's code generation for more information. -// ignore: must_be_immutable class MockJavaScriptChannel extends _i1.Mock implements _i2.JavaScriptChannel { @override String get channelName => (super.noSuchMethod( @@ -1265,6 +1274,27 @@ class MockJavaScriptChannel extends _i1.Mock implements _i2.JavaScriptChannel { returnValue: (String message) {}, returnValueForMissingStub: (String message) {}, ) as void Function(String)); + @override + _i2.JavaScriptChannel copy() => (super.noSuchMethod( + Invocation.method( + #copy, + [], + ), + returnValue: _FakeJavaScriptChannel_9( + this, + Invocation.method( + #copy, + [], + ), + ), + returnValueForMissingStub: _FakeJavaScriptChannel_9( + this, + Invocation.method( + #copy, + [], + ), + ), + ) as _i2.JavaScriptChannel); } /// A class which mocks [PlatformViewsServiceProxy]. @@ -1557,7 +1587,6 @@ class MockSurfaceAndroidViewController extends _i1.Mock /// A class which mocks [WebChromeClient]. /// /// See the documentation for Mockito's code generation for more information. -// ignore: must_be_immutable class MockWebChromeClient extends _i1.Mock implements _i2.WebChromeClient { @override _i9.Future setSynchronousReturnValueForOnShowFileChooser(bool? value) => @@ -1569,12 +1598,32 @@ class MockWebChromeClient extends _i1.Mock implements _i2.WebChromeClient { returnValue: _i9.Future.value(), returnValueForMissingStub: _i9.Future.value(), ) as _i9.Future); + @override + _i2.WebChromeClient copy() => (super.noSuchMethod( + Invocation.method( + #copy, + [], + ), + returnValue: _FakeWebChromeClient_0( + this, + Invocation.method( + #copy, + [], + ), + ), + returnValueForMissingStub: _FakeWebChromeClient_0( + this, + Invocation.method( + #copy, + [], + ), + ), + ) as _i2.WebChromeClient); } /// A class which mocks [WebSettings]. /// /// See the documentation for Mockito's code generation for more information. -// ignore: must_be_immutable class MockWebSettings extends _i1.Mock implements _i2.WebSettings { @override _i9.Future setDomStorageEnabled(bool? flag) => (super.noSuchMethod( @@ -1689,12 +1738,32 @@ class MockWebSettings extends _i1.Mock implements _i2.WebSettings { returnValue: _i9.Future.value(), returnValueForMissingStub: _i9.Future.value(), ) as _i9.Future); + @override + _i2.WebSettings copy() => (super.noSuchMethod( + Invocation.method( + #copy, + [], + ), + returnValue: _FakeWebSettings_16( + this, + Invocation.method( + #copy, + [], + ), + ), + returnValueForMissingStub: _FakeWebSettings_16( + this, + Invocation.method( + #copy, + [], + ), + ), + ) as _i2.WebSettings); } /// A class which mocks [WebView]. /// /// See the documentation for Mockito's code generation for more information. -// ignore: must_be_immutable class MockWebView extends _i1.Mock implements _i2.WebView { @override bool get useHybridComposition => (super.noSuchMethod( @@ -2002,12 +2071,32 @@ class MockWebView extends _i1.Mock implements _i2.WebView { returnValue: _i9.Future.value(), returnValueForMissingStub: _i9.Future.value(), ) as _i9.Future); + @override + _i2.WebView copy() => (super.noSuchMethod( + Invocation.method( + #copy, + [], + ), + returnValue: _FakeWebView_7( + this, + Invocation.method( + #copy, + [], + ), + ), + returnValueForMissingStub: _FakeWebView_7( + this, + Invocation.method( + #copy, + [], + ), + ), + ) as _i2.WebView); } /// A class which mocks [WebViewClient]. /// /// See the documentation for Mockito's code generation for more information. -// ignore: must_be_immutable class MockWebViewClient extends _i1.Mock implements _i2.WebViewClient { @override _i9.Future setSynchronousReturnValueForShouldOverrideUrlLoading( @@ -2020,12 +2109,32 @@ class MockWebViewClient extends _i1.Mock implements _i2.WebViewClient { returnValue: _i9.Future.value(), returnValueForMissingStub: _i9.Future.value(), ) as _i9.Future); + @override + _i2.WebViewClient copy() => (super.noSuchMethod( + Invocation.method( + #copy, + [], + ), + returnValue: _FakeWebViewClient_1( + this, + Invocation.method( + #copy, + [], + ), + ), + returnValueForMissingStub: _FakeWebViewClient_1( + this, + Invocation.method( + #copy, + [], + ), + ), + ) as _i2.WebViewClient); } /// A class which mocks [WebStorage]. /// /// See the documentation for Mockito's code generation for more information. -// ignore: must_be_immutable class MockWebStorage extends _i1.Mock implements _i2.WebStorage { @override _i9.Future deleteAllData() => (super.noSuchMethod( @@ -2036,6 +2145,27 @@ class MockWebStorage extends _i1.Mock implements _i2.WebStorage { returnValue: _i9.Future.value(), returnValueForMissingStub: _i9.Future.value(), ) as _i9.Future); + @override + _i2.WebStorage copy() => (super.noSuchMethod( + Invocation.method( + #copy, + [], + ), + returnValue: _FakeWebStorage_17( + this, + Invocation.method( + #copy, + [], + ), + ), + returnValueForMissingStub: _FakeWebStorage_17( + this, + Invocation.method( + #copy, + [], + ), + ), + ) as _i2.WebStorage); } /// A class which mocks [InstanceManager]. @@ -2058,21 +2188,16 @@ class MockInstanceManager extends _i1.Mock implements _i5.InstanceManager { returnValueForMissingStub: null, ); @override - int addDartCreatedInstance( - T? instance, { - required T Function(T)? onCopy, - }) => - (super.noSuchMethod( + int addDartCreatedInstance(_i5.Copyable? instance) => (super.noSuchMethod( Invocation.method( #addDartCreatedInstance, [instance], - {#onCopy: onCopy}, ), returnValue: 0, returnValueForMissingStub: 0, ) as int); @override - int? removeWeakReference(Object? instance) => (super.noSuchMethod( + int? removeWeakReference(_i5.Copyable? instance) => (super.noSuchMethod( Invocation.method( #removeWeakReference, [instance], @@ -2080,7 +2205,7 @@ class MockInstanceManager extends _i1.Mock implements _i5.InstanceManager { returnValueForMissingStub: null, ) as int?); @override - T? remove(int? identifier) => (super.noSuchMethod( + T? remove(int? identifier) => (super.noSuchMethod( Invocation.method( #remove, [identifier], @@ -2088,7 +2213,7 @@ class MockInstanceManager extends _i1.Mock implements _i5.InstanceManager { returnValueForMissingStub: null, ) as T?); @override - T? getInstanceWithWeakReference(int? identifier) => + T? getInstanceWithWeakReference(int? identifier) => (super.noSuchMethod( Invocation.method( #getInstanceWithWeakReference, @@ -2097,7 +2222,7 @@ class MockInstanceManager extends _i1.Mock implements _i5.InstanceManager { returnValueForMissingStub: null, ) as T?); @override - int? getIdentifier(Object? instance) => (super.noSuchMethod( + int? getIdentifier(_i5.Copyable? instance) => (super.noSuchMethod( Invocation.method( #getIdentifier, [instance], @@ -2105,11 +2230,10 @@ class MockInstanceManager extends _i1.Mock implements _i5.InstanceManager { returnValueForMissingStub: null, ) as int?); @override - void addHostCreatedInstance( - T? instance, - int? identifier, { - required T Function(T)? onCopy, - }) => + void addHostCreatedInstance( + _i5.Copyable? instance, + int? identifier, + ) => super.noSuchMethod( Invocation.method( #addHostCreatedInstance, @@ -2117,7 +2241,6 @@ class MockInstanceManager extends _i1.Mock implements _i5.InstanceManager { instance, identifier, ], - {#onCopy: onCopy}, ), 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 index b561de3e3fb..025d8e08597 100644 --- a/packages/webview_flutter/webview_flutter_android/test/android_webview_test.dart +++ b/packages/webview_flutter/webview_flutter_android/test/android_webview_test.dart @@ -272,6 +272,7 @@ void main() { ); final WebViewClient mockWebViewClient = MockWebViewClient(); + when(mockWebViewClient.copy()).thenReturn(MockWebViewClient()); instanceManager.addDartCreatedInstance(mockWebViewClient); webView.setWebViewClient(mockWebViewClient); @@ -289,19 +290,14 @@ void main() { instanceManager: instanceManager, ); - const int javaScriptChannelInstanceId = 5; - final JavaScriptChannel javaScriptChannel = JavaScriptChannel.detached( - 'aChannel', - postMessage: (_) {}, - instanceManager: instanceManager, - ); - instanceManager.addHostCreatedInstance( - javaScriptChannel, - javaScriptChannelInstanceId, - ); + final JavaScriptChannel mockJavaScriptChannel = MockJavaScriptChannel(); + when(mockJavaScriptChannel.copy()).thenReturn(MockJavaScriptChannel()); + when(mockJavaScriptChannel.channelName).thenReturn('aChannel'); - webView.addJavaScriptChannel(javaScriptChannel); + webView.addJavaScriptChannel(mockJavaScriptChannel); + final int javaScriptChannelInstanceId = + instanceManager.getIdentifier(mockJavaScriptChannel)!; verify(mockPlatformHostApi.addJavaScriptChannel( webViewInstanceId, javaScriptChannelInstanceId, @@ -314,20 +310,20 @@ void main() { instanceManager: instanceManager, ); - const int javaScriptChannelInstanceId = 5; - final JavaScriptChannel javaScriptChannel = JavaScriptChannel.detached( - 'aChannel', - postMessage: (_) {}, - instanceManager: instanceManager, - ); - instanceManager.addHostCreatedInstance( - javaScriptChannel, - javaScriptChannelInstanceId, + final JavaScriptChannel mockJavaScriptChannel = MockJavaScriptChannel(); + when(mockJavaScriptChannel.copy()).thenReturn(MockJavaScriptChannel()); + when(mockJavaScriptChannel.channelName).thenReturn('aChannel'); + + expect( + webView.removeJavaScriptChannel(mockJavaScriptChannel), + completes, ); - webView.addJavaScriptChannel(javaScriptChannel); - webView.removeJavaScriptChannel(javaScriptChannel); + webView.addJavaScriptChannel(mockJavaScriptChannel); + webView.removeJavaScriptChannel(mockJavaScriptChannel); + final int javaScriptChannelInstanceId = + instanceManager.getIdentifier(mockJavaScriptChannel)!; verify(mockPlatformHostApi.removeJavaScriptChannel( webViewInstanceId, javaScriptChannelInstanceId, @@ -340,17 +336,13 @@ void main() { instanceManager: instanceManager, ); - const int downloadListenerInstanceId = 5; - final DownloadListener downloadListener = DownloadListener.detached( - onDownloadStart: (_, __, ___, ____, _____) {}, - instanceManager: instanceManager, - ); - instanceManager.addHostCreatedInstance( - downloadListener, - downloadListenerInstanceId, - ); - webView.setDownloadListener(downloadListener); + 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, @@ -364,9 +356,8 @@ void main() { ); final WebChromeClient mockWebChromeClient = MockWebChromeClient(); - instanceManager.addDartCreatedInstance( - mockWebChromeClient, - ); + when(mockWebChromeClient.copy()).thenReturn(MockWebChromeClient()); + instanceManager.addDartCreatedInstance(mockWebChromeClient); webView.setWebChromeClient(mockWebChromeClient); final int webChromeClientInstanceId = @@ -376,6 +367,10 @@ void main() { webChromeClientInstanceId, )); }); + + test('copy', () { + expect(webView.copy(), isA()); + }); }); group('WebSettings', () { @@ -502,6 +497,10 @@ void main() { true, )); }); + + test('copy', () { + expect(webSettings.copy(), isA()); + }); }); group('JavaScriptChannel', () { @@ -519,11 +518,10 @@ void main() { ); mockJavaScriptChannel = MockJavaScriptChannel(); + when(mockJavaScriptChannel.copy()).thenReturn(MockJavaScriptChannel()); mockJavaScriptChannelInstanceId = - instanceManager.addDartCreatedInstance( - mockJavaScriptChannel, - ); + instanceManager.addDartCreatedInstance(mockJavaScriptChannel); }); test('postMessage', () { @@ -539,6 +537,13 @@ void main() { expect(result, 'Hello, World!'); }); + + test('copy', () { + expect( + JavaScriptChannel.detached('channel', postMessage: (_) {}).copy(), + isA(), + ); + }); }); group('WebViewClient', () { @@ -559,14 +564,14 @@ void main() { ); mockWebViewClient = MockWebViewClient(); - mockWebViewClientInstanceId = instanceManager.addDartCreatedInstance( - mockWebViewClient, - ); + when(mockWebViewClient.copy()).thenReturn(MockWebViewClient()); + mockWebViewClientInstanceId = + instanceManager.addDartCreatedInstance(mockWebViewClient); mockWebView = MockWebView(); - mockWebViewInstanceId = instanceManager.addDartCreatedInstance( - mockWebView, - ); + when(mockWebView.copy()).thenReturn(MockWebView()); + mockWebViewInstanceId = + instanceManager.addDartCreatedInstance(mockWebView); }); test('onPageStarted', () { @@ -707,6 +712,10 @@ void main() { containsAllInOrder([mockWebView, 'https://www.google.com']), ); }); + + test('copy', () { + expect(WebViewClient.detached().copy(), isA()); + }); }); group('DownloadListener', () { @@ -724,9 +733,9 @@ void main() { ); mockDownloadListener = MockDownloadListener(); - mockDownloadListenerInstanceId = instanceManager.addDartCreatedInstance( - mockDownloadListener, - ); + when(mockDownloadListener.copy()).thenReturn(MockDownloadListener()); + mockDownloadListenerInstanceId = + instanceManager.addDartCreatedInstance(mockDownloadListener); }); test('onDownloadStart', () { @@ -769,6 +778,15 @@ void main() { ]), ); }); + + test('copy', () { + expect( + DownloadListener.detached( + onDownloadStart: (_, __, ____, _____, ______) {}, + ).copy(), + isA(), + ); + }); }); group('WebChromeClient', () { @@ -789,15 +807,15 @@ void main() { ); mockWebChromeClient = MockWebChromeClient(); + when(mockWebChromeClient.copy()).thenReturn(MockWebChromeClient()); - mockWebChromeClientInstanceId = instanceManager.addDartCreatedInstance( - mockWebChromeClient, - ); + mockWebChromeClientInstanceId = + instanceManager.addDartCreatedInstance(mockWebChromeClient); mockWebView = MockWebView(); - mockWebViewInstanceId = instanceManager.addDartCreatedInstance( - mockWebView, - ); + when(mockWebView.copy()).thenReturn(MockWebView()); + mockWebViewInstanceId = + instanceManager.addDartCreatedInstance(mockWebView); }); test('onProgressChanged', () { @@ -828,7 +846,7 @@ void main() { final FileChooserParams params = FileChooserParams.detached( isCaptureEnabled: false, - acceptTypes: const [], + acceptTypes: [], filenameHint: 'filenameHint', mode: FileChooserMode.open, ); @@ -856,10 +874,7 @@ void main() { WebChromeClientHostApiImpl(instanceManager: instanceManager); final WebChromeClient webChromeClient = WebChromeClient.detached(); - instanceManager.addHostCreatedInstance( - webChromeClient, - 2 - ); + instanceManager.addHostCreatedInstance(webChromeClient, 2); webChromeClient.setSynchronousReturnValueForOnShowFileChooser(false); @@ -892,10 +907,7 @@ void main() { WebChromeClient.detached( onShowFileChooser: (_, __) async => [], ); - instanceManager.addHostCreatedInstance( - clientWithNonnullCallback, - 3 - ); + instanceManager.addHostCreatedInstance(clientWithNonnullCallback, 3); clientWithNonnullCallback .setSynchronousReturnValueForOnShowFileChooser(true); @@ -904,6 +916,10 @@ void main() { mockHostApi.setSynchronousReturnValueForOnShowFileChooser(3, true), ); }); + + test('copy', () { + expect(WebChromeClient.detached().copy(), isA()); + }); }); group('FileChooserParams', () { @@ -974,5 +990,9 @@ void main() { webStorage.deleteAllData(); verify(mockPlatformHostApi.deleteAllData(webStorageInstanceId)); }); + + test('copy', () { + expect(WebStorage.detached().copy(), 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 index 210ec15b4c9..d33876b522b 100644 --- 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 @@ -8,8 +8,8 @@ import 'dart:typed_data' as _i7; import 'dart:ui' as _i4; import 'package:mockito/mockito.dart' as _i1; -import 'package:webview_flutter_android/src/android_webview.dart' as _i3; -import 'package:webview_flutter_android/src/android_webview.g.dart' as _i2; +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 _i6; @@ -24,8 +24,9 @@ import 'test_android_webview.g.dart' as _i6; // ignore_for_file: camel_case_types // ignore_for_file: subtype_of_sealed_class -class _FakeWebViewPoint_0 extends _i1.SmartFake implements _i2.WebViewPoint { - _FakeWebViewPoint_0( +class _FakeDownloadListener_0 extends _i1.SmartFake + implements _i2.DownloadListener { + _FakeDownloadListener_0( Object parent, Invocation parentInvocation, ) : super( @@ -34,8 +35,9 @@ class _FakeWebViewPoint_0 extends _i1.SmartFake implements _i2.WebViewPoint { ); } -class _FakeWebSettings_1 extends _i1.SmartFake implements _i3.WebSettings { - _FakeWebSettings_1( +class _FakeJavaScriptChannel_1 extends _i1.SmartFake + implements _i2.JavaScriptChannel { + _FakeJavaScriptChannel_1( Object parent, Invocation parentInvocation, ) : super( @@ -44,8 +46,59 @@ class _FakeWebSettings_1 extends _i1.SmartFake implements _i3.WebSettings { ); } -class _FakeOffset_2 extends _i1.SmartFake implements _i4.Offset { - _FakeOffset_2( +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( @@ -58,7 +111,7 @@ class _FakeOffset_2 extends _i1.SmartFake implements _i4.Offset { /// /// See the documentation for Mockito's code generation for more information. class MockCookieManagerHostApi extends _i1.Mock - implements _i2.CookieManagerHostApi { + implements _i3.CookieManagerHostApi { MockCookieManagerHostApi() { _i1.throwOnMissingStub(this); } @@ -92,8 +145,7 @@ class MockCookieManagerHostApi extends _i1.Mock /// A class which mocks [DownloadListener]. /// /// See the documentation for Mockito's code generation for more information. -// ignore: must_be_immutable -class MockDownloadListener extends _i1.Mock implements _i3.DownloadListener { +class MockDownloadListener extends _i1.Mock implements _i2.DownloadListener { MockDownloadListener() { _i1.throwOnMissingStub(this); } @@ -121,13 +173,26 @@ class MockDownloadListener extends _i1.Mock implements _i3.DownloadListener { 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. -// ignore: must_be_immutable -class MockJavaScriptChannel extends _i1.Mock implements _i3.JavaScriptChannel { +class MockJavaScriptChannel extends _i1.Mock implements _i2.JavaScriptChannel { MockJavaScriptChannel() { _i1.throwOnMissingStub(this); } @@ -142,6 +207,20 @@ class MockJavaScriptChannel extends _i1.Mock implements _i3.JavaScriptChannel { 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 [TestDownloadListenerHostApi]. @@ -759,19 +838,19 @@ class MockTestWebViewHostApi extends _i1.Mock returnValue: 0, ) as int); @override - _i2.WebViewPoint getScrollPosition(int? instanceId) => (super.noSuchMethod( + _i3.WebViewPoint getScrollPosition(int? instanceId) => (super.noSuchMethod( Invocation.method( #getScrollPosition, [instanceId], ), - returnValue: _FakeWebViewPoint_0( + returnValue: _FakeWebViewPoint_2( this, Invocation.method( #getScrollPosition, [instanceId], ), ), - ) as _i2.WebViewPoint); + ) as _i3.WebViewPoint); @override void setWebContentsDebuggingEnabled(bool? enabled) => super.noSuchMethod( Invocation.method( @@ -902,8 +981,7 @@ class MockTestAssetManagerHostApi extends _i1.Mock /// A class which mocks [WebChromeClient]. /// /// See the documentation for Mockito's code generation for more information. -// ignore: must_be_immutable -class MockWebChromeClient extends _i1.Mock implements _i3.WebChromeClient { +class MockWebChromeClient extends _i1.Mock implements _i2.WebChromeClient { MockWebChromeClient() { _i1.throwOnMissingStub(this); } @@ -918,13 +996,26 @@ class MockWebChromeClient extends _i1.Mock implements _i3.WebChromeClient { 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. -// ignore: must_be_immutable -class MockWebView extends _i1.Mock implements _i3.WebView { +class MockWebView extends _i1.Mock implements _i2.WebView { MockWebView() { _i1.throwOnMissingStub(this); } @@ -935,13 +1026,13 @@ class MockWebView extends _i1.Mock implements _i3.WebView { returnValue: false, ) as bool); @override - _i3.WebSettings get settings => (super.noSuchMethod( + _i2.WebSettings get settings => (super.noSuchMethod( Invocation.getter(#settings), - returnValue: _FakeWebSettings_1( + returnValue: _FakeWebSettings_4( this, Invocation.getter(#settings), ), - ) as _i3.WebSettings); + ) as _i2.WebSettings); @override _i5.Future loadData({ required String? data, @@ -1147,7 +1238,7 @@ class MockWebView extends _i1.Mock implements _i3.WebView { #getScrollPosition, [], ), - returnValue: _i5.Future<_i4.Offset>.value(_FakeOffset_2( + returnValue: _i5.Future<_i4.Offset>.value(_FakeOffset_5( this, Invocation.method( #getScrollPosition, @@ -1156,7 +1247,7 @@ class MockWebView extends _i1.Mock implements _i3.WebView { )), ) as _i5.Future<_i4.Offset>); @override - _i5.Future setWebViewClient(_i3.WebViewClient? webViewClient) => + _i5.Future setWebViewClient(_i2.WebViewClient? webViewClient) => (super.noSuchMethod( Invocation.method( #setWebViewClient, @@ -1167,7 +1258,7 @@ class MockWebView extends _i1.Mock implements _i3.WebView { ) as _i5.Future); @override _i5.Future addJavaScriptChannel( - _i3.JavaScriptChannel? javaScriptChannel) => + _i2.JavaScriptChannel? javaScriptChannel) => (super.noSuchMethod( Invocation.method( #addJavaScriptChannel, @@ -1178,7 +1269,7 @@ class MockWebView extends _i1.Mock implements _i3.WebView { ) as _i5.Future); @override _i5.Future removeJavaScriptChannel( - _i3.JavaScriptChannel? javaScriptChannel) => + _i2.JavaScriptChannel? javaScriptChannel) => (super.noSuchMethod( Invocation.method( #removeJavaScriptChannel, @@ -1188,7 +1279,7 @@ class MockWebView extends _i1.Mock implements _i3.WebView { returnValueForMissingStub: _i5.Future.value(), ) as _i5.Future); @override - _i5.Future setDownloadListener(_i3.DownloadListener? listener) => + _i5.Future setDownloadListener(_i2.DownloadListener? listener) => (super.noSuchMethod( Invocation.method( #setDownloadListener, @@ -1198,7 +1289,7 @@ class MockWebView extends _i1.Mock implements _i3.WebView { returnValueForMissingStub: _i5.Future.value(), ) as _i5.Future); @override - _i5.Future setWebChromeClient(_i3.WebChromeClient? client) => + _i5.Future setWebChromeClient(_i2.WebChromeClient? client) => (super.noSuchMethod( Invocation.method( #setWebChromeClient, @@ -1216,13 +1307,26 @@ class MockWebView extends _i1.Mock implements _i3.WebView { 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. -// ignore: must_be_immutable -class MockWebViewClient extends _i1.Mock implements _i3.WebViewClient { +class MockWebViewClient extends _i1.Mock implements _i2.WebViewClient { MockWebViewClient() { _i1.throwOnMissingStub(this); } @@ -1238,4 +1342,18 @@ class MockWebViewClient extends _i1.Mock implements _i3.WebViewClient { 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 index e8bf248ade2..8c44e8cc986 100644 --- a/packages/webview_flutter/webview_flutter_android/test/instance_manager_test.dart +++ b/packages/webview_flutter/webview_flutter_android/test/instance_manager_test.dart @@ -13,6 +13,8 @@ import 'test_android_webview.g.dart'; @GenerateMocks([TestInstanceManagerHostApi]) void main() { + TestWidgetsFlutterBinding.ensureInitialized(); + group('InstanceManager', () { test('addHostCreatedInstance', () { final CopyableObject object = CopyableObject(); 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 9034eab7dae..03489ce5c1e 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 @@ -35,8 +35,8 @@ class _FakeWebSettings_0 extends _i1.SmartFake implements _i2.WebSettings { ); } -class _FakeOffset_1 extends _i1.SmartFake implements _i3.Offset { - _FakeOffset_1( +class _FakeWebStorage_1 extends _i1.SmartFake implements _i2.WebStorage { + _FakeWebStorage_1( Object parent, Invocation parentInvocation, ) : super( @@ -45,9 +45,8 @@ class _FakeOffset_1 extends _i1.SmartFake implements _i3.Offset { ); } -class _FakeJavascriptChannelRegistry_2 extends _i1.SmartFake - implements _i4.JavascriptChannelRegistry { - _FakeJavascriptChannelRegistry_2( +class _FakeOffset_2 extends _i1.SmartFake implements _i3.Offset { + _FakeOffset_2( Object parent, Invocation parentInvocation, ) : super( @@ -66,8 +65,52 @@ class _FakeWebView_3 extends _i1.SmartFake implements _i2.WebView { ); } -class _FakeWebViewClient_4 extends _i1.SmartFake implements _i2.WebViewClient { - _FakeWebViewClient_4( +class _FakeDownloadListener_4 extends _i1.SmartFake + implements _i2.DownloadListener { + _FakeDownloadListener_4( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeJavascriptChannelRegistry_5 extends _i1.SmartFake + implements _i4.JavascriptChannelRegistry { + _FakeJavascriptChannelRegistry_5( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeJavaScriptChannel_6 extends _i1.SmartFake + implements _i2.JavaScriptChannel { + _FakeJavaScriptChannel_6( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeWebChromeClient_7 extends _i1.SmartFake + implements _i2.WebChromeClient { + _FakeWebChromeClient_7( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeWebViewClient_8 extends _i1.SmartFake implements _i2.WebViewClient { + _FakeWebViewClient_8( Object parent, Invocation parentInvocation, ) : super( @@ -107,7 +150,6 @@ class MockFlutterAssetManager extends _i1.Mock /// A class which mocks [WebSettings]. /// /// See the documentation for Mockito's code generation for more information. -// ignore: must_be_immutable class MockWebSettings extends _i1.Mock implements _i2.WebSettings { MockWebSettings() { _i1.throwOnMissingStub(this); @@ -226,12 +268,25 @@ class MockWebSettings extends _i1.Mock implements _i2.WebSettings { returnValue: _i5.Future.value(), returnValueForMissingStub: _i5.Future.value(), ) as _i5.Future); + @override + _i2.WebSettings copy() => (super.noSuchMethod( + Invocation.method( + #copy, + [], + ), + returnValue: _FakeWebSettings_0( + this, + Invocation.method( + #copy, + [], + ), + ), + ) as _i2.WebSettings); } /// A class which mocks [WebStorage]. /// /// See the documentation for Mockito's code generation for more information. -// ignore: must_be_immutable class MockWebStorage extends _i1.Mock implements _i2.WebStorage { MockWebStorage() { _i1.throwOnMissingStub(this); @@ -246,12 +301,25 @@ class MockWebStorage extends _i1.Mock implements _i2.WebStorage { returnValue: _i5.Future.value(), returnValueForMissingStub: _i5.Future.value(), ) as _i5.Future); + @override + _i2.WebStorage copy() => (super.noSuchMethod( + Invocation.method( + #copy, + [], + ), + returnValue: _FakeWebStorage_1( + this, + Invocation.method( + #copy, + [], + ), + ), + ) as _i2.WebStorage); } /// A class which mocks [WebView]. /// /// See the documentation for Mockito's code generation for more information. -// ignore: must_be_immutable class MockWebView extends _i1.Mock implements _i2.WebView { MockWebView() { _i1.throwOnMissingStub(this); @@ -475,7 +543,7 @@ class MockWebView extends _i1.Mock implements _i2.WebView { #getScrollPosition, [], ), - returnValue: _i5.Future<_i3.Offset>.value(_FakeOffset_1( + returnValue: _i5.Future<_i3.Offset>.value(_FakeOffset_2( this, Invocation.method( #getScrollPosition, @@ -544,6 +612,20 @@ class MockWebView extends _i1.Mock implements _i2.WebView { returnValue: _i5.Future.value(), returnValueForMissingStub: _i5.Future.value(), ) as _i5.Future); + @override + _i2.WebView copy() => (super.noSuchMethod( + Invocation.method( + #copy, + [], + ), + returnValue: _FakeWebView_3( + this, + Invocation.method( + #copy, + [], + ), + ), + ) as _i2.WebView); } /// A class which mocks [WebResourceRequest]. @@ -585,7 +667,6 @@ class MockWebResourceRequest extends _i1.Mock /// A class which mocks [DownloadListener]. /// /// See the documentation for Mockito's code generation for more information. -// ignore: must_be_immutable class MockDownloadListener extends _i1.Mock implements _i2.DownloadListener { MockDownloadListener() { _i1.throwOnMissingStub(this); @@ -614,6 +695,20 @@ class MockDownloadListener extends _i1.Mock implements _i2.DownloadListener { String, int, )); + @override + _i2.DownloadListener copy() => (super.noSuchMethod( + Invocation.method( + #copy, + [], + ), + returnValue: _FakeDownloadListener_4( + this, + Invocation.method( + #copy, + [], + ), + ), + ) as _i2.DownloadListener); } /// A class which mocks [WebViewAndroidJavaScriptChannel]. @@ -629,7 +724,7 @@ class MockWebViewAndroidJavaScriptChannel extends _i1.Mock _i4.JavascriptChannelRegistry get javascriptChannelRegistry => (super.noSuchMethod( Invocation.getter(#javascriptChannelRegistry), - returnValue: _FakeJavascriptChannelRegistry_2( + returnValue: _FakeJavascriptChannelRegistry_5( this, Invocation.getter(#javascriptChannelRegistry), ), @@ -644,12 +739,25 @@ class MockWebViewAndroidJavaScriptChannel extends _i1.Mock Invocation.getter(#postMessage), returnValue: (String message) {}, ) as void Function(String)); + @override + _i2.JavaScriptChannel copy() => (super.noSuchMethod( + Invocation.method( + #copy, + [], + ), + returnValue: _FakeJavaScriptChannel_6( + this, + Invocation.method( + #copy, + [], + ), + ), + ) as _i2.JavaScriptChannel); } /// A class which mocks [WebChromeClient]. /// /// See the documentation for Mockito's code generation for more information. -// ignore: must_be_immutable class MockWebChromeClient extends _i1.Mock implements _i2.WebChromeClient { MockWebChromeClient() { _i1.throwOnMissingStub(this); @@ -665,12 +773,25 @@ class MockWebChromeClient extends _i1.Mock implements _i2.WebChromeClient { returnValue: _i5.Future.value(), returnValueForMissingStub: _i5.Future.value(), ) as _i5.Future); + @override + _i2.WebChromeClient copy() => (super.noSuchMethod( + Invocation.method( + #copy, + [], + ), + returnValue: _FakeWebChromeClient_7( + this, + Invocation.method( + #copy, + [], + ), + ), + ) as _i2.WebChromeClient); } /// A class which mocks [WebViewClient]. /// /// See the documentation for Mockito's code generation for more information. -// ignore: must_be_immutable class MockWebViewClient extends _i1.Mock implements _i2.WebViewClient { MockWebViewClient() { _i1.throwOnMissingStub(this); @@ -687,6 +808,20 @@ class MockWebViewClient extends _i1.Mock implements _i2.WebViewClient { returnValue: _i5.Future.value(), returnValueForMissingStub: _i5.Future.value(), ) as _i5.Future); + @override + _i2.WebViewClient copy() => (super.noSuchMethod( + Invocation.method( + #copy, + [], + ), + returnValue: _FakeWebViewClient_8( + this, + Invocation.method( + #copy, + [], + ), + ), + ) as _i2.WebViewClient); } /// A class which mocks [JavascriptChannelRegistry]. @@ -862,7 +997,7 @@ class MockWebViewProxy extends _i1.Mock implements _i7.WebViewProxy { #urlLoading: urlLoading, }, ), - returnValue: _FakeWebViewClient_4( + returnValue: _FakeWebViewClient_8( this, Invocation.method( #createWebViewClient, From 73ea79424d1342293deca86dc16d364cf0c9027a Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Tue, 28 Feb 2023 11:36:54 -0500 Subject: [PATCH 13/24] update changelog --- packages/webview_flutter/webview_flutter_android/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/webview_flutter/webview_flutter_android/CHANGELOG.md b/packages/webview_flutter/webview_flutter_android/CHANGELOG.md index caa173f2628..15d42b7173a 100644 --- a/packages/webview_flutter/webview_flutter_android/CHANGELOG.md +++ b/packages/webview_flutter/webview_flutter_android/CHANGELOG.md @@ -1,7 +1,7 @@ ## 3.3.2 * Updates internal Java InstanceManager to be cleared on hot restart. -* Updates internal Dart InstanceManager to handle creating copies of objects. +* Updates internal Copyable mixin to be immutable and require `copy` to be overridden by subclasses. ## 3.3.1 From 32ff598070e77dbc0aec487ffd183f3a6e67ae12 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Tue, 28 Feb 2023 11:47:00 -0500 Subject: [PATCH 14/24] add a copy --- .../lib/src/legacy/webview_android_widget.dart | 8 ++++++++ 1 file changed, 8 insertions(+) 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 cd4ba820cf4..6b06be7bb36 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 @@ -595,6 +595,14 @@ class WebViewAndroidJavaScriptChannel /// Manages named JavaScript channels and forwarding incoming messages on the correct channel. final JavascriptChannelRegistry javascriptChannelRegistry; + + @override + android_webview.JavaScriptChannel copy() { + return WebViewAndroidJavaScriptChannel( + channelName, + javascriptChannelRegistry, + ); + } } /// Handles constructing [android_webview.WebView]s and calling static methods. From b848c1fa136af4326440a5eb2d486e9bf065698f Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Tue, 28 Feb 2023 11:52:17 -0500 Subject: [PATCH 15/24] raise minimum meta version --- packages/webview_flutter/webview_flutter_android/pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/webview_flutter/webview_flutter_android/pubspec.yaml b/packages/webview_flutter/webview_flutter_android/pubspec.yaml index 3c6e7a3cecc..4ea928c105e 100644 --- a/packages/webview_flutter/webview_flutter_android/pubspec.yaml +++ b/packages/webview_flutter/webview_flutter_android/pubspec.yaml @@ -20,7 +20,7 @@ flutter: dependencies: flutter: sdk: flutter - meta: ^1.8.0 + meta: ^1.9.0 webview_flutter_platform_interface: ^2.0.0 dev_dependencies: From 8efddc9d4a0e6b062be8010090ee04afef3c787d Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Tue, 28 Feb 2023 12:12:11 -0500 Subject: [PATCH 16/24] remove meta --- packages/webview_flutter/webview_flutter_android/CHANGELOG.md | 2 +- .../webview_flutter_android/lib/src/instance_manager.dart | 3 +-- packages/webview_flutter/webview_flutter_android/pubspec.yaml | 1 - 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/packages/webview_flutter/webview_flutter_android/CHANGELOG.md b/packages/webview_flutter/webview_flutter_android/CHANGELOG.md index 15d42b7173a..03bb8133cf3 100644 --- a/packages/webview_flutter/webview_flutter_android/CHANGELOG.md +++ b/packages/webview_flutter/webview_flutter_android/CHANGELOG.md @@ -1,7 +1,7 @@ ## 3.3.2 * Updates internal Java InstanceManager to be cleared on hot restart. -* Updates internal Copyable mixin to be immutable and require `copy` to be overridden by subclasses. +* Updates internal Copyable mixin to be immutable. ## 3.3.1 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 index 86b0c04304b..3cc100aebd4 100644 --- a/packages/webview_flutter/webview_flutter_android/lib/src/instance_manager.dart +++ b/packages/webview_flutter/webview_flutter_android/lib/src/instance_manager.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 'package:meta/meta.dart'; +import 'package:flutter/foundation.dart'; /// An immutable object that can provide functional copies of itself. /// @@ -17,7 +17,6 @@ mixin Copyable { /// Subclasses should always override their parent's implementation of this /// method. @protected - @mustBeOverridden Copyable copy(); } diff --git a/packages/webview_flutter/webview_flutter_android/pubspec.yaml b/packages/webview_flutter/webview_flutter_android/pubspec.yaml index 4ea928c105e..bb9d5683567 100644 --- a/packages/webview_flutter/webview_flutter_android/pubspec.yaml +++ b/packages/webview_flutter/webview_flutter_android/pubspec.yaml @@ -20,7 +20,6 @@ flutter: dependencies: flutter: sdk: flutter - meta: ^1.9.0 webview_flutter_platform_interface: ^2.0.0 dev_dependencies: From e2b53b1a2704fd41a93a901a1d087ab2f6d343c2 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Tue, 28 Feb 2023 12:24:06 -0500 Subject: [PATCH 17/24] remove copy override --- .../lib/src/legacy/webview_android_widget.dart | 8 -------- .../test/legacy/webview_android_widget_test.dart | 1 + 2 files changed, 1 insertion(+), 8 deletions(-) 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 6b06be7bb36..cd4ba820cf4 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 @@ -595,14 +595,6 @@ class WebViewAndroidJavaScriptChannel /// Manages named JavaScript channels and forwarding incoming messages on the correct channel. final JavascriptChannelRegistry javascriptChannelRegistry; - - @override - android_webview.JavaScriptChannel copy() { - return WebViewAndroidJavaScriptChannel( - channelName, - javascriptChannelRegistry, - ); - } } /// Handles constructing [android_webview.WebView]s and calling static methods. 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 44cc1851090..d5d4dd097e6 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 @@ -199,6 +199,7 @@ void main() { }); testWidgets('javascriptChannelNames', (WidgetTester tester) async { + print('here'); await buildWidget( tester, creationParams: CreationParams( From a9a9aa6f0e69fa6e70f7bb62d4c88c1cc1556528 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Tue, 28 Feb 2023 13:31:19 -0500 Subject: [PATCH 18/24] remove print --- .../test/legacy/webview_android_widget_test.dart | 1 - 1 file changed, 1 deletion(-) 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 d5d4dd097e6..44cc1851090 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 @@ -199,7 +199,6 @@ void main() { }); testWidgets('javascriptChannelNames', (WidgetTester tester) async { - print('here'); await buildWidget( tester, creationParams: CreationParams( From 0ea91f7a1a81d8ce2e1a34690a71cd77b87b1cf0 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Tue, 28 Feb 2023 13:49:14 -0500 Subject: [PATCH 19/24] remove unneeded changes --- .../lib/src/android_webview_api_impls.dart | 62 +++---------------- .../android_navigation_delegate_test.dart | 15 ----- 2 files changed, 9 insertions(+), 68 deletions(-) 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 index 667bb425a03..fb332df2d19 100644 --- 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 @@ -137,16 +137,9 @@ class JavaObjectFlutterApiImpl implements JavaObjectFlutterApi { class WebViewHostApiImpl extends WebViewHostApi { /// Constructs a [WebViewHostApiImpl]. WebViewHostApiImpl({ - this.binaryMessenger, + super.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; + }) : instanceManager = instanceManager ?? JavaObject.globalInstanceManager; /// Maintains instances stored to communicate with java objects. final InstanceManager instanceManager; @@ -357,16 +350,10 @@ class WebViewHostApiImpl extends WebViewHostApi { class WebSettingsHostApiImpl extends WebSettingsHostApi { /// Constructs a [WebSettingsHostApiImpl]. WebSettingsHostApiImpl({ - this.binaryMessenger, + super.binaryMessenger, InstanceManager? instanceManager, }) : instanceManager = instanceManager ?? JavaObject.globalInstanceManager; - /// 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; @@ -504,16 +491,10 @@ class WebSettingsHostApiImpl extends WebSettingsHostApi { class JavaScriptChannelHostApiImpl extends JavaScriptChannelHostApi { /// Constructs a [JavaScriptChannelHostApiImpl]. JavaScriptChannelHostApiImpl({ - this.binaryMessenger, + super.binaryMessenger, InstanceManager? instanceManager, }) : instanceManager = instanceManager ?? JavaObject.globalInstanceManager; - /// 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; @@ -554,16 +535,10 @@ class JavaScriptChannelFlutterApiImpl extends JavaScriptChannelFlutterApi { class WebViewClientHostApiImpl extends WebViewClientHostApi { /// Constructs a [WebViewClientHostApiImpl]. WebViewClientHostApiImpl({ - this.binaryMessenger, + super.binaryMessenger, InstanceManager? instanceManager, }) : instanceManager = instanceManager ?? JavaObject.globalInstanceManager; - /// 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; @@ -747,16 +722,10 @@ class WebViewClientFlutterApiImpl extends WebViewClientFlutterApi { class DownloadListenerHostApiImpl extends DownloadListenerHostApi { /// Constructs a [DownloadListenerHostApiImpl]. DownloadListenerHostApiImpl({ - this.binaryMessenger, + super.binaryMessenger, InstanceManager? instanceManager, }) : instanceManager = instanceManager ?? JavaObject.globalInstanceManager; - /// 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; @@ -807,16 +776,10 @@ class DownloadListenerFlutterApiImpl extends DownloadListenerFlutterApi { class WebChromeClientHostApiImpl extends WebChromeClientHostApi { /// Constructs a [WebChromeClientHostApiImpl]. WebChromeClientHostApiImpl({ - this.binaryMessenger, + super.binaryMessenger, InstanceManager? instanceManager, }) : instanceManager = instanceManager ?? JavaObject.globalInstanceManager; - /// 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; @@ -893,16 +856,9 @@ class WebChromeClientFlutterApiImpl extends WebChromeClientFlutterApi { class WebStorageHostApiImpl extends WebStorageHostApi { /// Constructs a [WebStorageHostApiImpl]. WebStorageHostApiImpl({ - this.binaryMessenger, + super.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; + }) : instanceManager = instanceManager ?? JavaObject.globalInstanceManager; /// Maintains instances stored to communicate with java objects. final InstanceManager instanceManager; 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 c0d84a17348..2bf563b293d 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 @@ -486,11 +486,6 @@ class CapturingWebViewClient extends android_webview.WebViewClient { bool value) async { synchronousReturnValueForShouldOverrideUrlLoading = value; } - - @override - CapturingWebViewClient copy() { - return CapturingWebViewClient(); - } } // Records the last created instance of itself. @@ -505,11 +500,6 @@ class CapturingWebChromeClient extends android_webview.WebChromeClient { } static CapturingWebChromeClient lastCreatedDelegate = CapturingWebChromeClient(); - - @override - CapturingWebChromeClient copy() { - return CapturingWebChromeClient(); - } } // Records the last created instance of itself. @@ -523,9 +513,4 @@ class CapturingDownloadListener extends android_webview.DownloadListener { } static CapturingDownloadListener lastCreatedListener = CapturingDownloadListener(onDownloadStart: (_, __, ___, ____, _____) {}); - - @override - CapturingDownloadListener copy() { - return CapturingDownloadListener(onDownloadStart: onDownloadStart); - } } From 8141e9a33284ae57fca8be0b539ec3e2bf324878 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Tue, 28 Feb 2023 15:16:30 -0500 Subject: [PATCH 20/24] include raising of pigeon version --- packages/webview_flutter/webview_flutter_android/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/webview_flutter/webview_flutter_android/CHANGELOG.md b/packages/webview_flutter/webview_flutter_android/CHANGELOG.md index 03bb8133cf3..6c8f0f711f0 100644 --- a/packages/webview_flutter/webview_flutter_android/CHANGELOG.md +++ b/packages/webview_flutter/webview_flutter_android/CHANGELOG.md @@ -2,6 +2,7 @@ * Updates internal Java InstanceManager to be cleared on hot restart. * Updates internal Copyable mixin to be immutable. +* Raises `pigeon` version to `9.0.0`. ## 3.3.1 From f1967711e7d733ade2e25013524ac44919790cfe Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Mon, 6 Mar 2023 16:53:08 -0500 Subject: [PATCH 21/24] update globalInstanceManager --- .../lib/src/android_webview.dart | 25 ++++++++----------- 1 file changed, 11 insertions(+), 14 deletions(-) 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 index ac7f179156c..01757c2d78c 100644 --- a/packages/webview_flutter/webview_flutter_android/lib/src/android_webview.dart +++ b/packages/webview_flutter/webview_flutter_android/lib/src/android_webview.dart @@ -35,21 +35,18 @@ class JavaObject with Copyable { instanceManager: instanceManager, ); - static InstanceManager? _globalInstanceManager; - /// Global instance of [InstanceManager]. - static InstanceManager get globalInstanceManager { - if (_globalInstanceManager == null) { - WidgetsFlutterBinding.ensureInitialized(); - // Clears the native `InstanceManager` on initial use of the Dart one. - InstanceManagerHostApi().clear(); - _globalInstanceManager = InstanceManager( - onWeakReferenceRemoved: (int identifier) { - JavaObjectHostApiImpl().dispose(identifier); - }, - ); - } - return _globalInstanceManager!; + 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]. From 7e3278715a63b9a44706d74d4609b076d8cfdcb1 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Mon, 6 Mar 2023 16:59:06 -0500 Subject: [PATCH 22/24] move location of asserts --- .../lib/src/instance_manager.dart | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) 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 index 3cc100aebd4..732e2e631ad 100644 --- a/packages/webview_flutter/webview_flutter_android/lib/src/instance_manager.dart +++ b/packages/webview_flutter/webview_flutter_android/lib/src/instance_manager.dart @@ -79,8 +79,6 @@ class InstanceManager { /// /// Returns the randomly generated id of the [instance] added. int addDartCreatedInstance(Copyable instance) { - assert(getIdentifier(instance) == null); - final int identifier = _nextUniqueIdentifier(); _addInstanceWithIdentifier(instance, identifier); return identifier; @@ -165,13 +163,14 @@ class InstanceManager { /// /// Returns unique identifier of the [instance] added. void addHostCreatedInstance(Copyable instance, int identifier) { - assert(!containsIdentifier(identifier)); - assert(getIdentifier(instance) == null); - assert(identifier >= 0); _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); From 1062ddb536090b852f3684434e2a1edef39f5fa3 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Thu, 9 Mar 2023 16:40:49 -0500 Subject: [PATCH 23/24] lint --- .../webview_flutter_android/test/instance_manager_test.dart | 2 ++ 1 file changed, 2 insertions(+) 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 index 8c44e8cc986..67caa96a62f 100644 --- a/packages/webview_flutter/webview_flutter_android/test/instance_manager_test.dart +++ b/packages/webview_flutter/webview_flutter_android/test/instance_manager_test.dart @@ -147,6 +147,8 @@ void main() { MockTestInstanceManagerHostApi(); TestInstanceManagerHostApi.setup(mockApi); + // Calls method to clear the native InstanceManager. + // ignore: unnecessary_statements JavaObject.globalInstanceManager; verify(mockApi.clear()); From 96055701d6bb6f733a081d022054343b0d377a36 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Thu, 16 Mar 2023 15:01:40 -0400 Subject: [PATCH 24/24] use a constant --- .../webviewflutter/InstanceManager.java | 37 ++++++++++++------- 1 file changed, 23 insertions(+), 14 deletions(-) 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 index a82e9932a92..de51ebd0482 100644 --- 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 @@ -30,6 +30,9 @@ */ @SuppressWarnings("unchecked") public class InstanceManager { + /// Constant returned from #addHostCreatedInstance() if the manager is closed. + public static final int INSTANCE_CLOSED = -1; + // 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, @@ -87,8 +90,7 @@ private InstanceManager(FinalizationListener finalizationListener) { */ @Nullable public T remove(long identifier) { - if (isClosed()) { - Log.w(TAG, CLOSED_WARNING); + if (assertNotClosed()) { return null; } return (T) strongInstances.remove(identifier); @@ -112,8 +114,7 @@ public T remove(long identifier) { */ @Nullable public Long getIdentifierForStrongReference(Object instance) { - if (isClosed()) { - Log.w(TAG, CLOSED_WARNING); + if (assertNotClosed()) { return null; } final Long identifier = identifiers.get(instance); @@ -137,8 +138,7 @@ public Long getIdentifierForStrongReference(Object instance) { * unique. */ public void addDartCreatedInstance(Object instance, long identifier) { - if (isClosed()) { - Log.w(TAG, CLOSED_WARNING); + if (assertNotClosed()) { return; } addInstance(instance, identifier); @@ -149,12 +149,14 @@ public void addDartCreatedInstance(Object instance, long identifier) { * * @param instance the instance to be stored. This must be unique to all other added instances. * @return the unique identifier stored with instance. If the manager is closed, returns -1. + * Otherwise, returns a value >= 0. */ public long addHostCreatedInstance(Object instance) { - if (isClosed()) { - Log.w(TAG, CLOSED_WARNING); - return -1; - } else if (containsInstance(instance)) { + if (assertNotClosed()) { + return INSTANCE_CLOSED; + } + + if (containsInstance(instance)) { throw new IllegalArgumentException( String.format("Instance of `%s` has already been added.", instance.getClass())); } @@ -173,10 +175,10 @@ public long addHostCreatedInstance(Object instance) { */ @Nullable public T getInstance(long identifier) { - if (isClosed()) { - Log.w(TAG, CLOSED_WARNING); + if (assertNotClosed()) { return null; } + final WeakReference instance = (WeakReference) weakInstances.get(identifier); if (instance != null) { return instance.get(); @@ -192,8 +194,7 @@ public T getInstance(long identifier) { * `false`. */ public boolean containsInstance(Object instance) { - if (isClosed()) { - Log.w(TAG, CLOSED_WARNING); + if (assertNotClosed()) { return false; } return identifiers.containsKey(instance); @@ -259,4 +260,12 @@ private void addInstance(Object instance, long identifier) { weakReferencesToIdentifiers.put(weakReference, identifier); strongInstances.put(identifier, instance); } + + private boolean assertNotClosed() { + if (isClosed()) { + Log.w(TAG, CLOSED_WARNING); + return true; + } + return false; + } }