Skip to content

Commit

Permalink
added onPageCommitVisible event, updated dart code for new events and…
Browse files Browse the repository at this point in the history
… methods, updated docs, fix #367
  • Loading branch information
Lorenzo Pichilli authored and Lorenzo Pichilli committed May 28, 2020
1 parent 6c97be3 commit 208d6c7
Show file tree
Hide file tree
Showing 22 changed files with 1,458 additions and 313 deletions.
7 changes: 5 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,21 @@
- Added Android keyboard workaround to hide the keyboard when clicking other HTML elements, losing the focus on the previous input
- Added `onEnterFullscreen`, `onExitFullscreen` webview events [#275](https://github.com/pichillilorenzo/flutter_inappwebview/issues/275)
- Added Android support to use camera on HTML inputs that requires it, such as `<input type="file" accept="image/*" capture>` [#353](https://github.com/pichillilorenzo/flutter_inappwebview/issues/353)
- Added `overScrollMode`, `networkAvailable`, `scrollBarStyle`, `verticalScrollbarPosition`, `scrollBarDefaultDelayBeforeFade`, `scrollbarFadingEnabled`, `scrollBarFadeDuration`, `rendererPriorityPolicy` webview options on Android
- Added `overScrollMode`, `networkAvailable`, `scrollBarStyle`, `verticalScrollbarPosition`, `scrollBarDefaultDelayBeforeFade`, `scrollbarFadingEnabled`, `scrollBarFadeDuration`, `rendererPriorityPolicy`, `useShouldInterceptRequest`, `useOnRenderProcessGone` webview options on Android
- Added `pageDown`, `pageUp`, `saveWebArchive`, `zoomIn`, `zoomOut` webview methods on Android
- Added `getCurrentWebViewPackage` static webview method on Android
- Added `shouldInterceptRequest`, `onRenderProcessUnresponsive`, `onRenderProcessResponsive`, `onRenderProcessGone`, `onFormResubmission`, `onPageCommitVisible`, `onScaleChanged` Android events
- Added `onPageCommitVisible` webview event
- Added `androidShouldInterceptRequest`, `androidOnRenderProcessUnresponsive`, `androidOnRenderProcessResponsive`, `androidOnRenderProcessGone`, `androidOnFormResubmission`, `androidOnScaleChanged` Android events
- Fixed `Print preview is not working? java.lang.IllegalStateException: Can print only from an activity` [#128](https://github.com/pichillilorenzo/flutter_inappwebview/issues/128)
- Fixed `onJsAlert`, `onJsConfirm`, `onJsPrompt` for `InAppBrowser` on Android
- Fixed `onActivityResult` for `InAppBrowser` on Android
- Fixed `InAppBrowser.openWithSystemBrowser crash on iOS` [#358](https://github.com/pichillilorenzo/flutter_inappwebview/issues/358)
- Fixed `Attempt to invoke virtual method 'java.util.Set java.util.HashMap.entrySet()' on a null object reference` [#367](https://github.com/pichillilorenzo/flutter_inappwebview/issues/367)

### BREAKING CHANGES

- Android `clearClientCertPreferences`, `getSafeBrowsingPrivacyPolicyUrl`, `setSafeBrowsingWhitelist` webview methods are static now
- Removed iOS event `onDidCommit`; it has been renamed to `onPageCommitVisible` and made cross-platform

## 3.2.0

Expand Down
35 changes: 28 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -407,13 +407,19 @@ Screenshots:
Android-specific methods can be called using the `InAppWebViewController.android` attribute.

* `startSafeBrowsing`: Starts Safe Browsing initialization.
* `setSafeBrowsingWhitelist({@required List<String> hosts})`: Sets the list of hosts (domain names/IP addresses) that are exempt from SafeBrowsing checks. The list is global for all the WebViews.
* `getSafeBrowsingPrivacyPolicyUrl`: Returns a URL pointing to the privacy policy for Safe Browsing reporting. This value will never be `null`.
* `clearSslPreferences`: Clears the SSL preferences table stored in response to proceeding with SSL certificate errors.
* `clearClientCertPreferences`: Clears the client certificate preferences stored in response to proceeding/cancelling client cert requests.
* `pause`: Does a best-effort attempt to pause any processing that can be paused safely, such as animations and geolocation. Note that this call does not pause JavaScript.
* `resume`: Resumes a WebView after a previous call to `pause()`.
* `getOriginalUrl`: Gets the URL that was originally requested for the current page.
* `pageDown({@required bool bottom})`: Scrolls the contents of this WebView down by half the page size.
* `pageUp({@required bool top})`: Scrolls the contents of this WebView up by half the view size.
* `saveWebArchive({@required String basename, @required bool autoname})`: Saves the current view as a web archive.
* `zoomIn`: Performs zoom in in this WebView.
* `zoomOut`: Performs zoom out in this WebView.
* `static clearClientCertPreferences`: Clears the client certificate preferences stored in response to proceeding/cancelling client cert requests.
* `static getSafeBrowsingPrivacyPolicyUrl`: Returns a URL pointing to the privacy policy for Safe Browsing reporting. This value will never be `null`.
* `static setSafeBrowsingWhitelist({@required List<String> hosts})`: Sets the list of hosts (domain names/IP addresses) that are exempt from SafeBrowsing checks. The list is global for all the WebViews.
* `static getCurrentWebViewPackage()`: Gets the current Android WebView package info.

##### `InAppWebViewController` iOS-specific methods

Expand Down Expand Up @@ -474,6 +480,8 @@ Instead, on the `onLoadStop` WebView event, you can use `callHandler` directly:
* `useShouldOverrideUrlLoading`: Set to `true` to be able to listen at the `shouldOverrideUrlLoading` event. The default value is `false`.
* `useOnLoadResource`: Set to `true` to be able to listen at the `onLoadResource` event. The default value is `false`.
* `useOnDownloadStart`: Set to `true` to be able to listen at the `onDownloadStart` event. The default value is `false`.
* `useShouldInterceptAjaxRequest`: Set to `true` to be able to listen at the `shouldInterceptAjaxRequest` event. The default value is `false`.
* `useShouldInterceptFetchRequest`: Set to `true` to be able to listen at the `shouldInterceptFetchRequest` event. The default value is `false`.
* `clearCache`: Set to `true` to have all the browser's cache cleared before the new window is opened. The default value is `false`.
* `userAgent`: Sets the user-agent for the WebView.
* `applicationNameForUserAgent`: Append to the existing user-agent. Setting userAgent will override this.
Expand All @@ -487,8 +495,6 @@ Instead, on the `onLoadStop` WebView event, you can use `callHandler` directly:
* `resourceCustomSchemes`: List of custom schemes that the WebView must handle. Use the `onLoadResourceCustomScheme` event to intercept resource requests with custom scheme.
* `contentBlockers`: List of `ContentBlocker` that are a set of rules used to block content in the browser window.
* `preferredContentMode`: Sets the content mode that the WebView needs to use when loading and rendering a webpage. The default value is `InAppWebViewUserPreferredContentMode.RECOMMENDED`.
* `useShouldInterceptAjaxRequest`: Set to `true` to be able to listen at the `shouldInterceptAjaxRequest` event. The default value is `false`.
* `useShouldInterceptFetchRequest`: Set to `true` to be able to listen at the `shouldInterceptFetchRequest` event. The default value is `false`.
* `incognito`: Set to `true` to open a browser window with incognito mode. The default value is `false`.
* `cacheEnabled`: Sets whether WebView should use browser caching. The default value is `true`.
* `transparentBackground`: Set to `true` to make the background of the WebView transparent. If your app has a dark theme, this can prevent a white flash on initialization. The default value is `false`.
Expand All @@ -498,6 +504,8 @@ Instead, on the `onLoadStop` WebView event, you can use `callHandler` directly:

##### `InAppWebView` Android-specific options

* `useShouldInterceptRequest`: Set to `true` to be able to listen at the `androidShouldInterceptRequest` event. The default value is `false`.
* `useOnRenderProcessGone`: Set to `true` to be able to listen at the `androidOnRenderProcessGone` event. The default value is `false`.
* `textZoom`: Sets the text zoom of the page in percent. The default value is `100`.
* `clearSessionCache`: Set to `true` to have the session cookie cache cleared before the new window is opened.
* `builtInZoomControls`: Set to `true` if the WebView should use its built-in zoom mechanisms. The default value is `false`.
Expand Down Expand Up @@ -540,6 +548,13 @@ Instead, on the `onLoadStop` WebView event, you can use `callHandler` directly:
* `hardwareAcceleration`: Boolean value to enable Hardware Acceleration in the WebView.
* `supportMultipleWindows`: Sets whether the WebView whether supports multiple windows.
* `regexToCancelSubFramesLoading`: Regular expression used by `shouldOverrideUrlLoading` event to cancel navigation for frames that are not the main frame. If the url request of a subframe matches the regular expression, then the request of that subframe is canceled.
* `overScrollMode`: Sets the WebView's over-scroll mode. The default value is `AndroidOverScrollMode.OVER_SCROLL_IF_CONTENT_SCROLLS`.
* `scrollBarStyle`: Specify the style of the scrollbars. The scrollbars can be overlaid or inset. The default value is `AndroidScrollBarStyle.SCROLLBARS_INSIDE_OVERLAY`.
* `verticalScrollbarPosition`: Set the position of the vertical scroll bar. The default value is `AndroidVerticalScrollbarPosition.SCROLLBAR_POSITION_DEFAULT`.
* `scrollBarDefaultDelayBeforeFade`: Defines the delay in milliseconds that a scrollbar waits before fade out.
* `scrollbarFadingEnabled`: Define whether scrollbars will fade when the view is not scrolling. The default value is `true`.
* `scrollBarFadeDuration`: Define the scrollbar fade duration in milliseconds.
* `rendererPriorityPolicy`: Set the renderer priority policy for this WebView.

##### `InAppWebView` iOS-specific options

Expand Down Expand Up @@ -599,12 +614,18 @@ Event names that starts with `android` or `ios` are events platform-specific.
* `onLongPressHitTestResult`: Event fired when an HTML element of the webview has been clicked and held.
* `onEnterFullscreen`: Event fired when the current page has entered full screen mode.
* `onExitFullscreen`: Event fired when the current page has exited full screen mode.
* `onPageCommitVisible`: Called when the web view begins to receive web content.
* `androidOnSafeBrowsingHit`: Event fired when the webview notifies that a loading URL has been flagged by Safe Browsing (available only on Android).
* `androidOnPermissionRequest`: Event fired when the webview is requesting permission to access the specified resources and the permission currently isn't granted or denied (available only on Android).
* `androidOnGeolocationPermissionsShowPrompt`: Event that notifies the host application that web content from the specified origin is attempting to use the Geolocation API, but no permission state is currently set for that origin (available only on Android).
* `androidOnGeolocationPermissionsHidePrompt`: Notify the host application that a request for Geolocation permissions, made with a previous call to `androidOnGeolocationPermissionsShowPrompt` has been canceled. (available only on Android).
* `androidOnGeolocationPermissionsHidePrompt`: Notify the host application that a request for Geolocation permissions, made with a previous call to `androidOnGeolocationPermissionsShowPrompt` has been canceled (available only on Android).
* `androidShouldInterceptRequest`: Notify the host application of a resource request and allow the application to return the data (available only on Android).
* `androidOnRenderProcessGone`: Event fired when the given WebView's render process has exited (available only on Android).
* `androidOnRenderProcessResponsive`: Event called once when an unresponsive renderer currently associated with the WebView becomes responsive (available only on Android).
* `androidOnRenderProcessUnresponsive`: Event called when the renderer currently associated with the WebView becomes unresponsive as a result of a long running blocking task such as the execution of JavaScript (available only on Android).
* `androidOnFormResubmission`: As the host application if the browser should resend data as the requested page was a result of a POST. The default is to not resend the data (available only on Android).
* `androidOnScaleChanged`: Event fired when the scale applied to the WebView has changed (available only on Android).
* `iosOnWebContentProcessDidTerminate`: Invoked when the web view's web content process is terminated (available only on iOS).
* `iosOnDidCommit`: Called when the web view begins to receive web content (available only on iOS).
* `iosOnDidReceiveServerRedirectForProvisionalNavigation`: Called when a web view receives a server redirect (available only on iOS).

### `ContextMenu` class
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package com.pichillilorenzo.flutter_inappwebview.InAppBrowser;

import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Picture;
import android.graphics.drawable.ColorDrawable;
import android.os.Build;
import android.os.Bundle;
Expand Down Expand Up @@ -32,8 +29,6 @@
import com.pichillilorenzo.flutter_inappwebview.R;
import com.pichillilorenzo.flutter_inappwebview.Shared;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -345,6 +340,31 @@ public void onMethodCall(final MethodCall call, final MethodChannel.Result resul
case "getHitTestResult":
result.success(getHitTestResult());
break;
case "pageDown":
{
boolean bottom = (boolean) call.argument("bottom");
result.success(pageDown(bottom));
}
break;
case "pageUp":
{
boolean top = (boolean) call.argument("top");
result.success(pageUp(top));
}
break;
case "saveWebArchive":
{
String basename = (String) call.argument("basename");
boolean autoname = (boolean) call.argument("autoname");
saveWebArchive(basename, autoname, result);
}
break;
case "zoomIn":
result.success(zoomIn());
break;
case "zoomOut":
result.success(zoomOut());
break;
default:
result.notImplemented();
}
Expand Down Expand Up @@ -852,6 +872,43 @@ public Map<String, Object> getHitTestResult() {
return null;
}

public boolean pageDown(boolean bottom) {
if (webView != null)
return webView.pageDown(bottom);
return false;
}

public boolean pageUp(boolean top) {
if (webView != null)
return webView.pageUp(top);
return false;
}

public void saveWebArchive(String basename, boolean autoname, final MethodChannel.Result result) {
if (webView != null) {
webView.saveWebArchive(basename, autoname, new ValueCallback<String>() {
@Override
public void onReceiveValue(String value) {
result.success(value);
}
});
} else {
result.success(null);
}
}

public boolean zoomIn() {
if (webView != null)
return webView.zoomIn();
return false;
}

public boolean zoomOut() {
if (webView != null)
return webView.zoomOut();
return false;
}

public void dispose() {
channel.setMethodCallHandler(null);
activityResultListeners.clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -396,9 +396,6 @@ public void onReceiveValue(Boolean success) {
result.success(null);
}
break;



case "pageDown":
if (webView != null) {
boolean bottom = (boolean) call.argument("bottom");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,8 @@ else if (options.clearSessionCache)
setRendererPriorityPolicy(
(int) options.rendererPriorityPolicy.get("rendererRequestedPriority"),
(boolean) options.rendererPriorityPolicy.get("waivedWhenNotVisible"));
} else if (options.rendererPriorityPolicy == null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
} else if ((options.rendererPriorityPolicy == null || (options.rendererPriorityPolicy != null && options.rendererPriorityPolicy.isEmpty())) &&
Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
options.rendererPriorityPolicy.put("rendererRequestedPriority", getRendererRequestedPriority());
options.rendererPriorityPolicy.put("waivedWhenNotVisible", getRendererPriorityWaivedWhenNotVisible());
}
Expand Down
Loading

0 comments on commit 208d6c7

Please sign in to comment.