Skip to content

Commit

Permalink
fix #1159
Browse files Browse the repository at this point in the history
  • Loading branch information
pichillilorenzo committed Apr 28, 2022
1 parent 9aa812e commit ad04812
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 20 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 5.4.3+1

- Fixed "Latest version 5.4.3 crashes on Android" [#1159](https://github.com/pichillilorenzo/flutter_inappwebview/issues/1159)

## 5.4.3

- Added Bitwise OR operator support for `AndroidActionModeMenuItem` class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ public class ChromeCustomTabsActivity extends Activity implements MethodChannel.
public String id;
public CustomTabsIntent.Builder builder;
public ChromeCustomTabsOptions options;
public CustomTabActivityHelper customTabActivityHelper;
public CustomTabActivityHelper customTabActivityHelper = new CustomTabActivityHelper();
@Nullable
public CustomTabsSession customTabsSession;
protected final int CHROME_CUSTOM_TAB_REQUEST_CODE = 100;
protected boolean onChromeSafariBrowserOpened = false;
Expand All @@ -60,7 +61,8 @@ protected void onCreate(Bundle savedInstanceState) {
id = b.getString("id");

String managerId = b.getString("managerId");
manager = (ChromeSafariBrowserManager) ChromeSafariBrowserManager.shared.get(managerId);
manager = ChromeSafariBrowserManager.shared.get(managerId);
if (manager == null || manager.plugin == null|| manager.plugin.messenger == null) return;

channel = new MethodChannel(manager.plugin.messenger, "com.pichillilorenzo/flutter_chromesafaribrowser_" + id);
channel.setMethodCallHandler(this);
Expand All @@ -77,7 +79,6 @@ protected void onCreate(Bundle savedInstanceState) {

final ChromeCustomTabsActivity chromeCustomTabsActivity = this;

customTabActivityHelper = new CustomTabActivityHelper();
customTabActivityHelper.setConnectionCallback(new CustomTabActivityHelper.ConnectionCallback() {
@Override
public void onCustomTabsConnected() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@ public void onMethodCall(MethodCall call, @NonNull MethodChannel.Result result)
break;
case "clearAllAuthCredentials":
credentialDatabase.clearAllAuthCredentials();
WebViewDatabase.getInstance(plugin.applicationContext).clearHttpAuthUsernamePassword();
if (plugin != null && plugin.applicationContext != null) {
WebViewDatabase.getInstance(plugin.applicationContext).clearHttpAuthUsernamePassword();
}
result.success(true);
break;
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,16 @@ public Size2D getSize() {

public void dispose() {
channel.setMethodCallHandler(null);
HeadlessInAppWebViewManager.webViews.remove(id);
if (HeadlessInAppWebViewManager.webViews.containsKey(id)) {
HeadlessInAppWebViewManager.webViews.put(id, null);
}
if (plugin != null && plugin.activity != null) {
ViewGroup contentView = (ViewGroup) plugin.activity.findViewById(android.R.id.content);
ViewGroup mainView = (ViewGroup) (contentView).getChildAt(0);
if (mainView != null && flutterWebView != null) {
mainView.removeView(flutterWebView.getView());
if (contentView != null) {
ViewGroup mainView = (ViewGroup) (contentView).getChildAt(0);
if (mainView != null && flutterWebView != null) {
mainView.removeView(flutterWebView.getView());
}
}
}
if (flutterWebView != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import com.pichillilorenzo.flutter_inappwebview.InAppWebViewFlutterPlugin;
import com.pichillilorenzo.flutter_inappwebview.in_app_webview.FlutterWebView;

import org.jetbrains.annotations.NotNull;

import java.util.Collection;
import java.util.HashMap;
import java.util.List;
Expand All @@ -50,7 +52,7 @@ public HeadlessInAppWebViewManager(final InAppWebViewFlutterPlugin plugin) {
}

@Override
public void onMethodCall(final MethodCall call, final Result result) {
public void onMethodCall(final MethodCall call, @NotNull final Result result) {
final String id = (String) call.argument("id");

switch (call.method) {
Expand All @@ -64,10 +66,11 @@ public void onMethodCall(final MethodCall call, final Result result) {
default:
result.notImplemented();
}

}

public void run(String id, HashMap<String, Object> params) {
if (plugin == null || plugin.activity == null) return;

FlutterWebView flutterWebView = new FlutterWebView(plugin, plugin.activity, id, params);
HeadlessInAppWebView headlessInAppWebView = new HeadlessInAppWebView(plugin, id, flutterWebView);
HeadlessInAppWebViewManager.webViews.put(id, headlessInAppWebView);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ protected void onCreate(Bundle savedInstanceState) {
id = b.getString("id");

String managerId = b.getString("managerId");
manager = (InAppBrowserManager) InAppBrowserManager.shared.get(managerId);
manager = InAppBrowserManager.shared.get(managerId);
if (manager == null || manager.plugin == null|| manager.plugin.messenger == null) return;

windowId = b.getInt("windowId");

Expand Down Expand Up @@ -500,7 +501,7 @@ public void dispose() {
methodCallDelegate = null;
}
if (webView != null) {
if (manager.plugin.activityPluginBinding != null) {
if (manager != null && manager.plugin != null && manager.plugin.activityPluginBinding != null) {
manager.plugin.activityPluginBinding.removeActivityResultListener(webView.inAppWebViewChromeClient);
}
ViewGroup vg = (ViewGroup) (webView.getParent());
Expand Down
18 changes: 18 additions & 0 deletions example/ios/Flutter/Flutter.podspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#
# NOTE: This podspec is NOT to be published. It is only used as a local source!
# This is a generated file; do not edit or check into version control.
#

Pod::Spec.new do |s|
s.name = 'Flutter'
s.version = '1.0.0'
s.summary = 'High-performance, high-fidelity mobile apps.'
s.homepage = 'https://flutter.io'
s.license = { :type => 'MIT' }
s.author = { 'Flutter Dev Team' => '[email protected]' }
s.source = { :git => 'https://github.com/flutter/engine', :tag => s.version.to_s }
s.ios.deployment_target = '9.0'
# Framework linking is handled by Flutter tooling, not CocoaPods.
# Add a placeholder to satisfy `s.dependency 'Flutter'` plugin podspecs.
s.vendored_frameworks = 'path/to/nothing'
end
7 changes: 4 additions & 3 deletions example/ios/Flutter/flutter_export_environment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
export "FLUTTER_ROOT=/Users/lorenzopichilli/fvm/versions/2.10.4"
export "FLUTTER_APPLICATION_PATH=/Users/lorenzopichilli/Desktop/flutter_inappwebview/example"
export "COCOAPODS_PARALLEL_CODE_SIGN=true"
export "FLUTTER_TARGET=lib/main.dart"
export "FLUTTER_TARGET=integration_test/webview_flutter_test.dart"
export "FLUTTER_BUILD_DIR=build"
export "FLUTTER_BUILD_NAME=1.0.0"
export "FLUTTER_BUILD_NUMBER=1"
export "DART_DEFINES=RkxVVFRFUl9XRUJfQVVUT19ERVRFQ1Q9dHJ1ZQ=="
export "DART_OBFUSCATION=false"
export "TRACK_WIDGET_CREATION=false"
export "TRACK_WIDGET_CREATION=true"
export "TREE_SHAKE_ICONS=false"
export "PACKAGE_CONFIG=.packages"
export "PACKAGE_CONFIG=/Users/lorenzopichilli/Desktop/flutter_inappwebview/example/.dart_tool/package_config.json"
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public class HeadlessInAppWebView : FlutterMethodCallDelegate {
public func dispose() {
channel?.setMethodCallHandler(nil)
channel = nil
HeadlessInAppWebViewManager.webViews.removeValue(forKey: id)
HeadlessInAppWebViewManager.webViews[id] = nil
flutterWebView = nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import AVFoundation
public class HeadlessInAppWebViewManager: NSObject, FlutterPlugin {
static var registrar: FlutterPluginRegistrar?
static var channel: FlutterMethodChannel?
static var webViews: [String: HeadlessInAppWebView] = [:]
static var webViews: [String: HeadlessInAppWebView?] = [:]

public static func register(with registrar: FlutterPluginRegistrar) {

Expand Down Expand Up @@ -63,8 +63,8 @@ public class HeadlessInAppWebViewManager: NSObject, FlutterPlugin {
HeadlessInAppWebViewManager.channel = nil
HeadlessInAppWebViewManager.registrar = nil
let headlessWebViews = HeadlessInAppWebViewManager.webViews.values
headlessWebViews.forEach { (headlessWebView: HeadlessInAppWebView) in
headlessWebView.dispose()
headlessWebViews.forEach { (headlessWebView: HeadlessInAppWebView?) in
headlessWebView?.dispose()
}
HeadlessInAppWebViewManager.webViews.removeAll()
}
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: flutter_inappwebview
description: A Flutter plugin that allows you to add an inline webview, to use an headless webview, and to open an in-app browser window.
version: 5.4.3
version: 5.4.3+1
homepage: https://github.com/pichillilorenzo/flutter_inappwebview

environment:
Expand Down

0 comments on commit ad04812

Please sign in to comment.