Skip to content

Commit

Permalink
fix #225, merged #228, updated ios options naming, updated default va…
Browse files Browse the repository at this point in the history
…lue for databaseEnabled android option, added new methods and events
  • Loading branch information
pichillilorenzo committed Dec 16, 2019
1 parent 5e272c4 commit b9fb01f
Show file tree
Hide file tree
Showing 58 changed files with 1,946 additions and 943 deletions.
572 changes: 323 additions & 249 deletions .idea/workspace.xml

Large diffs are not rendered by default.

28 changes: 21 additions & 7 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
## 3.0.0

- Updated for Flutter 1.12 new Java Embedding API (Android)
- Updated `clearCache` for Android
- Added `Promise` javascript [polyfill](https://github.com/taylorhakes/promise-polyfill/blob/master/src/index.js) for webviews that doesn't support it for `window.flutter_inappwebview.callHandler`
- Added `getDefaultUserAgent` static method to `InAppWebViewController`
- Added `printCurrentPage` method to `InAppWebViewController`
- Added `onPrint` event
- Added `onUpdateVisitedHistory`, `onPrint` event
- Added `onGeolocationPermissionsHidePrompt` event for Android
- Added `supportMultipleWindows` webview option for Android
- Added `regexToCancelSubFramesLoading` webview option for Android to cancel subframe requests on `shouldOverrideUrlLoading` event based on a Regular Expression
- Updated default value for `domStorageEnabled` option to `true` for Android
- Fix for Android `InAppBrowser` for some controller methods not exposed.
- Added `getContentHeight`, `zoomBy`, `printCurrentPage`, `getScale` methods
- Added `getOriginalUrl` webview method for Android
- Added `reloadFromOrigin` webview method for iOS
- Added `automaticallyAdjustsScrollIndicatorInsets` webview options for iOS
- Added `WebStorageManager` class which manages the web storage used by WebView instances
- Updated for Flutter 1.12 new Java Embedding API (Android)
- Updated `clearCache` for Android
- Updated default value for `domStorageEnabled` and `databaseEnabled` options to `true` for Android
- Merge "Fixes null error when calling getOptions for InAppBrowser class" [#214](https://github.com/pichillilorenzo/flutter_inappwebview/pull/214) (thanks to [panndoraBoo](https://github.com/panndoraBoo))
- Added `dropDownWorkaroundEnabled` webview option for Android to enable a temporary workaround for html dropdowns (issue [#182](https://github.com/pichillilorenzo/flutter_inappwebview/issues/182))
- Merge "Fixes crash onConsoleMessage iOS forced unwrapping" [#228](https://github.com/pichillilorenzo/flutter_inappwebview/pull/228) (thanks to [tokonu](https://github.com/tokonu))
- Fix for Android and iOS `InAppBrowser` for some controller methods not exposed.
- Fixed "App Crashes after clicking on dropdown (Using inappwebview)" [#182](https://github.com/pichillilorenzo/flutter_inappwebview/issues/182)
- Fixed "webview can not be released when in ios" [#225](https://github.com/pichillilorenzo/flutter_inappwebview/issues/225). Now the iOS WebView is released from memory when it is disposed from Flutter.

### BREAKING CHANGES

Expand All @@ -21,6 +27,14 @@
- it has a return type `ShouldOverrideUrlLoadingAction` to allow or cancel navigation instead of cancel every time the request
- Renamed `onTargetBlank` to `onCreateWindow`
- Deleted `useOnTargetBlank` webview option
- Making methods available only for the specific platform more explicit: moved all the webview's controller methods for Android inside `controller.android` and all the webview's controller methods for iOS inside `controller.ios`
- Making events available only for the specific platform more explicit:
- Renamed `onSafeBrowsingHit` to `androidOnSafeBrowsingHit`
- Renamed `onGeolocationPermissionsShowPrompt` to `androidOnGeolocationPermissionsShowPrompt`
- Renamed `onPermissionRequest` to `androidOnPermissionRequest`
- Updated attribute names for `InAppWebViewWidgetOptions`, `InAppBrowserClassOptions` and `ChromeSafariBrowserClassOptions` classes
- Renamed and updated `onNavigationStateChange` to `onUpdateVisitedHistory`
- Renamed all iOS options prefix from `Ios` to `IOS`

## 2.1.0+1

Expand Down
88 changes: 73 additions & 15 deletions README.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,24 @@ public void run() {
result.success(false);
}
break;
case "getContentHeight":
result.success((webView != null) ? webView.getContentHeight() : null);
break;
case "zoomBy":
if (webView != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Float zoomFactor = (Float) call.argument("zoomFactor");
webView.zoomBy(zoomFactor);
result.success(true);
} else {
result.success(false);
}
break;
case "getOriginalUrl":
result.success((webView != null) ? webView.getOriginalUrl() : null);
break;
case "getScale":
result.success((webView != null) ? webView.getUpdatedScale() : null);
break;
default:
result.notImplemented();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
package com.pichillilorenzo.flutter_inappwebview;

import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
Expand Down Expand Up @@ -133,7 +134,7 @@ public void run() {
Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse(url));
activity.startActivity(intent);
} catch (android.content.ActivityNotFoundException e) {
} catch (ActivityNotFoundException e) {
Log.e(LOG_TAG, "Error dialing " + url + ": " + e.toString());
}
}
Expand Down Expand Up @@ -348,6 +349,22 @@ public void run() {
}
result.success(true);
break;
case "getContentHeight":
result.success(getContentHeight(uuid));
break;
case "zoomBy":
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Float zoomFactor = (Float) call.argument("zoomFactor");
zoomBy(uuid, zoomFactor);
}
result.success(true);
break;
case "getOriginalUrl":
result.success(getOriginalUrl(uuid));
break;
case "getScale":
result.success(getScale(uuid));
break;
default:
result.notImplemented();
}
Expand Down Expand Up @@ -814,6 +831,34 @@ public void printCurrentPage(String uuid) {
inAppBrowserActivity.printCurrentPage();
}

public Integer getContentHeight(String uuid) {
InAppBrowserActivity inAppBrowserActivity = webViewActivities.get(uuid);
if (inAppBrowserActivity != null)
return inAppBrowserActivity.getContentHeight();
return null;
}

@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
public void zoomBy(String uuid, Float zoomFactor) {
InAppBrowserActivity inAppBrowserActivity = webViewActivities.get(uuid);
if (inAppBrowserActivity != null)
inAppBrowserActivity.zoomBy(zoomFactor);
}

public String getOriginalUrl(String uuid) {
InAppBrowserActivity inAppBrowserActivity = webViewActivities.get(uuid);
if (inAppBrowserActivity != null)
return inAppBrowserActivity.getOriginalUrl();
return null;
}

public Float getScale(String uuid) {
InAppBrowserActivity inAppBrowserActivity = webViewActivities.get(uuid);
if (inAppBrowserActivity != null)
return inAppBrowserActivity.getScale();
return null;
}

public void dispose() {
channel.setMethodCallHandler(null);
for ( InAppBrowserActivity activity : webViewActivities.values()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -575,4 +575,27 @@ public void printCurrentPage() {
webView.printCurrentPage();
}

public Integer getContentHeight() {
if (webView != null)
return webView.getContentHeight();
return null;
}

@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
public void zoomBy(Float zoomFactor) {
if (webView != null)
webView.zoomBy(zoomFactor);
}

public String getOriginalUrl() {
if (webView != null)
return webView.getOriginalUrl();
return null;
}

public Float getScale() {
if (webView != null)
return webView.getUpdatedScale();
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1342,69 +1342,8 @@ public void printCurrentPage() {
new PrintAttributes.Builder().build());
}

public void showDropDownWorkaround(final List<Integer> selectedValues, final List<List<String>> values, final boolean isMultiSelect, final DropDownWorkaroundCallback callback) {
FrameLayout layout = new FrameLayout(Shared.activity);

final List<String> listViewValues = new ArrayList<String>();
for(List<String> value : values) {
listViewValues.add(value.get(0));
}

ListView listView = new ListView(Shared.activity);
ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<String>(Shared.activity, (!isMultiSelect) ? android.R.layout.simple_list_item_1 : android.R.layout.simple_list_item_multiple_choice, listViewValues);
spinnerArrayAdapter.setDropDownViewResource(android.R.layout.simple_list_item_multiple_choice);
listView.setAdapter(spinnerArrayAdapter);


AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(Shared.activity, R.style.Theme_AppCompat_Dialog_Alert);
final AlertDialog alertDialog = alertDialogBuilder.create();

final List<String> result = new ArrayList<>();

listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String value = values.get(position).get(1);
if (!isMultiSelect) {
result.add(value);
alertDialog.dismiss();
} else {
if (!result.contains(value)) {
result.add(value);
} else {
result.remove(value);
}
}
}
});

if (isMultiSelect) {
listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
listView.setItemsCanFocus(false);

for(Integer selectedValueIndex : selectedValues) {
listView.setItemChecked(selectedValueIndex, true);
String value = values.get(selectedValueIndex).get(1);
result.add(value);
}
}

alertDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
callback.result(result);
}
});

layout.addView(listView);
alertDialog.setView(layout);
alertDialog.show();
}

public static class DropDownWorkaroundCallback {
public void result(List<String> value) {

}
public Float getUpdatedScale() {
return scale;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -411,10 +411,13 @@ public void onCancel(DialogInterface dialog) {
}

@Override
public boolean onCreateWindow(WebView view, boolean isDialog, boolean userGesture, final Message resultMsg) {
public boolean onCreateWindow(WebView view, boolean isDialog, boolean isUserGesture, final Message resultMsg) {
final Map<String, Object> obj = new HashMap<>();
if (inAppBrowserActivity != null)
obj.put("uuid", inAppBrowserActivity.uuid);
obj.put("androidIsDialog", isDialog);
obj.put("androidIsUserGesture", isUserGesture);
obj.put("iosWKNavigationType", null);

WebView.HitTestResult result = view.getHitTestResult();
String data = result.getExtra();
Expand Down Expand Up @@ -478,6 +481,14 @@ public void notImplemented() {
});
}

@Override
public void onGeolocationPermissionsHidePrompt() {
Map<String, Object> obj = new HashMap<>();
if (inAppBrowserActivity != null)
obj.put("uuid", inAppBrowserActivity.uuid);
getChannel().invokeMethod("onGeolocationPermissionsHidePrompt", obj);
}

@Override
public boolean onConsoleMessage(ConsoleMessage consoleMessage) {
Map<String, Object> obj = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import android.webkit.ValueCallback;
import android.webkit.WebResourceRequest;
import android.webkit.WebResourceResponse;
import android.webkit.WebStorage;
import android.webkit.WebView;
import android.webkit.WebViewClient;

Expand Down Expand Up @@ -54,7 +55,6 @@ public class InAppWebViewClient extends WebViewClient {
private InAppBrowserActivity inAppBrowserActivity;
private static int previousAuthRequestFailureCount = 0;
private static List<Credential> credentialsProposed = null;
private String onPageStartedURL = "";

public InAppWebViewClient(Object obj) {
super();
Expand Down Expand Up @@ -188,7 +188,6 @@ public void onPageStarted(WebView view, String url, Bitmap favicon) {
webView.loadUrl("javascript:" + js);
}

onPageStartedURL = url;
super.onPageStarted(view, url, favicon);

webView.isLoading = true;
Expand Down Expand Up @@ -241,16 +240,14 @@ public void onPageFinished(WebView view, String url) {

@Override
public void doUpdateVisitedHistory (WebView view, String url, boolean isReload) {
super.doUpdateVisitedHistory(view, url, isReload);
Map<String, Object> obj = new HashMap<>();
if (inAppBrowserActivity != null)
obj.put("uuid", inAppBrowserActivity.uuid);
obj.put("url", url);
obj.put("androidIsReload", isReload);
getChannel().invokeMethod("onUpdateVisitedHistory", obj);

if (!isReload && !url.equals(onPageStartedURL)) {
onPageStartedURL = "";
Map<String, Object> obj = new HashMap<>();
if (inAppBrowserActivity != null)
obj.put("uuid", inAppBrowserActivity.uuid);
obj.put("url", url);
getChannel().invokeMethod("onNavigationStateChange", obj);
}
super.doUpdateVisitedHistory(view, url, isReload);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class InAppWebViewFlutterPlugin implements FlutterPlugin, ActivityAware {
public static InAppWebViewStatic inAppWebViewStatic;
public static MyCookieManager myCookieManager;
public static CredentialDatabaseHandler credentialDatabaseHandler;
public static MyWebStorage myWebStorage;
public static ValueCallback<Uri[]> uploadMessageArray;

public InAppWebViewFlutterPlugin() {}
Expand Down Expand Up @@ -52,6 +53,7 @@ private void onAttachedToEngine(Context applicationContext, BinaryMessenger mess
"com.pichillilorenzo/flutter_inappwebview", new FlutterWebViewFactory(messenger, flutterView));
inAppWebViewStatic = new InAppWebViewStatic(messenger);
myCookieManager = new MyCookieManager(messenger);
myWebStorage = new MyWebStorage(messenger);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
credentialDatabaseHandler = new CredentialDatabaseHandler(messenger);
}
Expand All @@ -67,6 +69,10 @@ public void onDetachedFromEngine(FlutterPluginBinding binding) {
myCookieManager.dispose();
myCookieManager = null;
}
if (myWebStorage != null) {
myWebStorage.dispose();
myWebStorage = null;
}
if (credentialDatabaseHandler != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
credentialDatabaseHandler.dispose();
credentialDatabaseHandler = null;
Expand Down
Loading

0 comments on commit b9fb01f

Please sign in to comment.