87 lines
5.2 KiB
Java
87 lines
5.2 KiB
Java
package io.flutter.plugins.webviewflutter;
|
|
|
|
import android.content.Context;
|
|
import android.os.Handler;
|
|
import android.view.View;
|
|
import io.flutter.embedding.engine.plugins.FlutterPlugin;
|
|
import io.flutter.embedding.engine.plugins.activity.ActivityAware;
|
|
import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding;
|
|
import io.flutter.plugin.common.BinaryMessenger;
|
|
import io.flutter.plugin.common.PluginRegistry;
|
|
import io.flutter.plugin.platform.PlatformViewRegistry;
|
|
import io.flutter.plugins.webviewflutter.DownloadListenerHostApiImpl;
|
|
import io.flutter.plugins.webviewflutter.GeneratedAndroidWebView;
|
|
import io.flutter.plugins.webviewflutter.JavaScriptChannelHostApiImpl;
|
|
import io.flutter.plugins.webviewflutter.WebChromeClientHostApiImpl;
|
|
import io.flutter.plugins.webviewflutter.WebSettingsHostApiImpl;
|
|
import io.flutter.plugins.webviewflutter.WebViewClientHostApiImpl;
|
|
import io.flutter.plugins.webviewflutter.WebViewHostApiImpl;
|
|
|
|
/* loaded from: classes6.dex */
|
|
public class WebViewFlutterPlugin implements FlutterPlugin, ActivityAware {
|
|
private FlutterCookieManager flutterCookieManager;
|
|
private JavaScriptChannelHostApiImpl javaScriptChannelHostApi;
|
|
private FlutterPlugin.FlutterPluginBinding pluginBinding;
|
|
private WebViewHostApiImpl webViewHostApi;
|
|
|
|
public static void registerWith(PluginRegistry.Registrar registrar) {
|
|
new WebViewFlutterPlugin().setUp(registrar.messenger(), registrar.platformViewRegistry(), registrar.activity(), registrar.view());
|
|
new FlutterCookieManager(registrar.messenger());
|
|
}
|
|
|
|
private void setUp(BinaryMessenger binaryMessenger, PlatformViewRegistry platformViewRegistry, Context context, View view) {
|
|
new FlutterCookieManager(binaryMessenger);
|
|
InstanceManager instanceManager = new InstanceManager();
|
|
platformViewRegistry.registerViewFactory("plugins.flutter.io/webview", new FlutterWebViewFactory(instanceManager));
|
|
this.webViewHostApi = new WebViewHostApiImpl(instanceManager, new WebViewHostApiImpl.WebViewProxy(), context, view);
|
|
this.javaScriptChannelHostApi = new JavaScriptChannelHostApiImpl(instanceManager, new JavaScriptChannelHostApiImpl.JavaScriptChannelCreator(), new JavaScriptChannelFlutterApiImpl(binaryMessenger, instanceManager), new Handler(context.getMainLooper()));
|
|
GeneratedAndroidWebView.WebViewHostApi.setup(binaryMessenger, this.webViewHostApi);
|
|
GeneratedAndroidWebView.JavaScriptChannelHostApi.setup(binaryMessenger, this.javaScriptChannelHostApi);
|
|
GeneratedAndroidWebView.WebViewClientHostApi.setup(binaryMessenger, new WebViewClientHostApiImpl(instanceManager, new WebViewClientHostApiImpl.WebViewClientCreator(), new WebViewClientFlutterApiImpl(binaryMessenger, instanceManager)));
|
|
GeneratedAndroidWebView.WebChromeClientHostApi.setup(binaryMessenger, new WebChromeClientHostApiImpl(instanceManager, new WebChromeClientHostApiImpl.WebChromeClientCreator(), new WebChromeClientFlutterApiImpl(binaryMessenger, instanceManager)));
|
|
GeneratedAndroidWebView.DownloadListenerHostApi.setup(binaryMessenger, new DownloadListenerHostApiImpl(instanceManager, new DownloadListenerHostApiImpl.DownloadListenerCreator(), new DownloadListenerFlutterApiImpl(binaryMessenger, instanceManager)));
|
|
GeneratedAndroidWebView.WebSettingsHostApi.setup(binaryMessenger, new WebSettingsHostApiImpl(instanceManager, new WebSettingsHostApiImpl.WebSettingsCreator()));
|
|
}
|
|
|
|
@Override // io.flutter.embedding.engine.plugins.FlutterPlugin
|
|
public void onAttachedToEngine(FlutterPlugin.FlutterPluginBinding flutterPluginBinding) {
|
|
this.pluginBinding = flutterPluginBinding;
|
|
setUp(flutterPluginBinding.getBinaryMessenger(), flutterPluginBinding.getPlatformViewRegistry(), flutterPluginBinding.getApplicationContext(), null);
|
|
}
|
|
|
|
@Override // io.flutter.embedding.engine.plugins.FlutterPlugin
|
|
public void onDetachedFromEngine(FlutterPlugin.FlutterPluginBinding flutterPluginBinding) {
|
|
FlutterCookieManager flutterCookieManager = this.flutterCookieManager;
|
|
if (flutterCookieManager == null) {
|
|
return;
|
|
}
|
|
flutterCookieManager.dispose();
|
|
this.flutterCookieManager = null;
|
|
}
|
|
|
|
@Override // io.flutter.embedding.engine.plugins.activity.ActivityAware
|
|
public void onAttachedToActivity(ActivityPluginBinding activityPluginBinding) {
|
|
updateContext(activityPluginBinding.getActivity());
|
|
}
|
|
|
|
@Override // io.flutter.embedding.engine.plugins.activity.ActivityAware
|
|
public void onDetachedFromActivityForConfigChanges() {
|
|
updateContext(this.pluginBinding.getApplicationContext());
|
|
}
|
|
|
|
@Override // io.flutter.embedding.engine.plugins.activity.ActivityAware
|
|
public void onReattachedToActivityForConfigChanges(ActivityPluginBinding activityPluginBinding) {
|
|
updateContext(activityPluginBinding.getActivity());
|
|
}
|
|
|
|
@Override // io.flutter.embedding.engine.plugins.activity.ActivityAware
|
|
public void onDetachedFromActivity() {
|
|
updateContext(this.pluginBinding.getApplicationContext());
|
|
}
|
|
|
|
private void updateContext(Context context) {
|
|
this.webViewHostApi.setContext(context);
|
|
this.javaScriptChannelHostApi.setPlatformThreadHandler(new Handler(context.getMainLooper()));
|
|
}
|
|
}
|