Commit 0c17e032 authored by Lorenzo Pichilli's avatar Lorenzo Pichilli

updated code docs, fixed javascript code for the ajax and fetch request event handlers

parent a59dee7c
This diff is collapsed.
......@@ -162,6 +162,7 @@ final public class InAppWebView extends InputAwareWebView {
" type: e.type," +
" loaded: e.loaded," +
" lengthComputable: e.lengthComputable" +
" total: e.total" +
" }" +
" };" +
" window." + JavaScriptBridgeInterface.name + ".callHandler('onAjaxProgress', ajaxRequest).then(function(result) {" +
......@@ -233,6 +234,7 @@ final public class InAppWebView extends InputAwareWebView {
" this.addEventListener('progress', handleEvent);" +
" this.addEventListener('error', handleEvent);" +
" this.addEventListener('abort', handleEvent);" +
" this.addEventListener('timeout', handleEvent);" +
" var ajaxRequest = {" +
" data: data," +
" method: this._flutter_inappbrowser_method," +
......@@ -405,7 +407,7 @@ final public class InAppWebView extends InputAwareWebView {
" controller.abort();" +
" break;" +
" }" +
" var resultResource = (result.resource != null) ? result.resource : resource;" +
" var resultResource = (result.url != null) ? result.url : resource;" +
" var resultInit = init;" +
" if (result.init != null) {" +
" resultInit.method = result.method;" +
......@@ -555,8 +557,13 @@ final public class InAppWebView extends InputAwareWebView {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && options.forceDark != null)
settings.setForceDark(options.forceDark);
settings.setGeolocationEnabled(options.geolocationEnabled);
if (options.layoutAlgorithm != null)
if (options.layoutAlgorithm != null) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && options.layoutAlgorithm.equals(WebSettings.LayoutAlgorithm.TEXT_AUTOSIZING)) {
settings.setLayoutAlgorithm(options.layoutAlgorithm);
} else {
settings.setLayoutAlgorithm(options.layoutAlgorithm);
}
}
settings.setLoadsImagesAutomatically(options.loadsImagesAutomatically);
settings.setMinimumFontSize(options.minimumFontSize);
settings.setMinimumLogicalFontSize(options.minimumLogicalFontSize);
......@@ -948,8 +955,13 @@ final public class InAppWebView extends InputAwareWebView {
if (newOptionsMap.get("geolocationEnabled") != null && options.geolocationEnabled != newOptions.geolocationEnabled)
settings.setGeolocationEnabled(newOptions.geolocationEnabled);
if (newOptionsMap.get("layoutAlgorithm") != null && options.layoutAlgorithm != newOptions.layoutAlgorithm)
if (newOptionsMap.get("layoutAlgorithm") != null && options.layoutAlgorithm != newOptions.layoutAlgorithm) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && newOptions.layoutAlgorithm.equals(WebSettings.LayoutAlgorithm.TEXT_AUTOSIZING)) {
settings.setLayoutAlgorithm(newOptions.layoutAlgorithm);
} else {
settings.setLayoutAlgorithm(newOptions.layoutAlgorithm);
}
}
if (newOptionsMap.get("loadWithOverviewMode") != null && options.loadWithOverviewMode != newOptions.loadWithOverviewMode)
settings.setLoadWithOverviewMode(newOptions.loadWithOverviewMode);
......
package com.pichillilorenzo.flutter_inappbrowser.InAppWebView;
import android.os.Build;
import android.util.Log;
import android.webkit.WebSettings;
import com.pichillilorenzo.flutter_inappbrowser.Options;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import static android.webkit.WebSettings.LayoutAlgorithm.NORMAL;
public class InAppWebViewOptions extends Options {
public static final String LOG_TAG = "InAppWebViewOptions";
......@@ -75,4 +80,44 @@ public class InAppWebViewOptions extends Options {
public Boolean saveFormData = true;
public Boolean thirdPartyCookiesEnabled = true;
public Boolean hardwareAcceleration = true;
@Override
public Object onParse(Map.Entry<String, Object> pair) {
if (pair.getKey().equals("layoutAlgorithm")) {
switch ((String) pair.getValue()) {
case "NORMAL":
pair.setValue(NORMAL);
return pair;
case "TEXT_AUTOSIZING":
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
return pair.setValue(WebSettings.LayoutAlgorithm.TEXT_AUTOSIZING);
} else {
pair.setValue(NORMAL);
}
return pair;
}
}
return super.onParse(pair);
}
@Override
public Object onGetHashMap(Field field) {
if (field.getName().equals("layoutAlgorithm")) {
try {
WebSettings.LayoutAlgorithm value = (WebSettings.LayoutAlgorithm) field.get(this);
switch (value) {
case NORMAL:
return "NORMAL";
default:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && value.equals(WebSettings.LayoutAlgorithm.TEXT_AUTOSIZING)) {
return "TEXT_AUTOSIZING";
}
return "NORMAL";
}
} catch (IllegalAccessException e) {
Log.d(LOG_TAG, e.getMessage());
}
}
return super.onGetHashMap(field);
}
}
......@@ -15,8 +15,9 @@ public class Options {
Iterator it = options.entrySet().iterator();
while (it.hasNext()) {
Map.Entry<String, Object> pair = (Map.Entry<String, Object>) it.next();
Object value = this.onParse(pair);
try {
this.getClass().getDeclaredField(pair.getKey()).set(this, pair.getValue());
this.getClass().getDeclaredField(pair.getKey()).set(this, value);
} catch (NoSuchFieldException e) {
Log.d(LOG_TAG, e.getMessage());
} catch (IllegalAccessException e) {
......@@ -26,16 +27,25 @@ public class Options {
return this;
}
public Object onParse(Map.Entry<String, Object> pair) {
return pair.getValue();
}
public HashMap<String, Object> getHashMap() {
HashMap<String, Object> options = new HashMap<>();
for (Field f : this.getClass().getDeclaredFields()) {
for (Field field : this.getClass().getDeclaredFields()) {
options.put(field.getName(), onGetHashMap(field));
}
return options;
}
public Object onGetHashMap(Field field) {
try {
options.put(f.getName(), f.get(this));
return field.get(this);
} catch (IllegalAccessException e) {
Log.d(LOG_TAG, e.getMessage());
}
}
return options;
return null;
}
}
......@@ -312,6 +312,7 @@ let interceptAjaxRequestsJS = """
type: e.type,
loaded: e.loaded,
lengthComputable: e.lengthComputable
total: e.total
}
};
window.\(JAVASCRIPT_BRIDGE_NAME).callHandler('onAjaxProgress', ajaxRequest).then(function(result) {
......@@ -383,6 +384,7 @@ let interceptAjaxRequestsJS = """
this.addEventListener('progress', handleEvent);
this.addEventListener('error', handleEvent);
this.addEventListener('abort', handleEvent);
this.addEventListener('timeout', handleEvent);
var ajaxRequest = {
data: data,
method: this._flutter_inappbrowser_method,
......@@ -557,7 +559,7 @@ let interceptFetchRequestsJS = """
controller.abort();
break;
}
var resultResource = (result.resource != null) ? result.resource : resource;
var resultResource = (result.url != null) ? result.url : resource;
var resultInit = init;
if (result.init != null) {
resultInit.method = result.method;
......
......@@ -466,7 +466,7 @@ class InAppBrowser {
}
///Event fires when the WebView need to perform server trust authentication (certificate validation).
///The host application must return either [ServerTrustAuthResponse.CANCEL] or [ServerTrustAuthResponse.PROCEED].
///The host application must return either [ServerTrustAuthResponse] instance with [ServerTrustAuthResponseAction.CANCEL] or [ServerTrustAuthResponseAction.PROCEED].
///
///[challenge] contains data about host, port, protocol, realm, etc. as specified in the [ServerTrustChallenge].
Future<ServerTrustAuthResponse> onReceivedServerTrustAuthRequest(ServerTrustChallenge challenge) {
......
......@@ -162,7 +162,7 @@ class InAppWebView extends StatefulWidget {
final Future<HttpAuthResponse> Function(InAppWebViewController controller, HttpAuthChallenge challenge) onReceivedHttpAuthRequest;
///Event fires when the WebView need to perform server trust authentication (certificate validation).
///The host application must return either [ServerTrustAuthResponse.CANCEL] or [ServerTrustAuthResponse.PROCEED].
///The host application must return either [ServerTrustAuthResponse] instance with [ServerTrustAuthResponseAction.CANCEL] or [ServerTrustAuthResponseAction.PROCEED].
///
///[challenge] contains data about host, port, protocol, realm, etc. as specified in the [ServerTrustChallenge].
final Future<ServerTrustAuthResponse> Function(InAppWebViewController controller, ServerTrustChallenge challenge) onReceivedServerTrustAuthRequest;
......@@ -668,7 +668,7 @@ class InAppWebViewController {
Map<dynamic, dynamic> responseHeaders = argMap["responseHeaders"];
Map<dynamic, dynamic> eventMap = argMap["event"];
AjaxRequestEvent event = AjaxRequestEvent(lengthComputable: eventMap["lengthComputable"], loaded: eventMap["loaded"], type: AjaxRequestEventType.fromValue(eventMap["type"]));
AjaxRequestEvent event = AjaxRequestEvent(lengthComputable: eventMap["lengthComputable"], loaded: eventMap["loaded"], total: eventMap["total"], type: AjaxRequestEventType.fromValue(eventMap["type"]));
var request = new AjaxRequest(data: data, method: method, url: url, isAsync: isAsync, user: user, password: password,
withCredentials: withCredentials, headers: headers, readyState: AjaxRequestReadyState.fromValue(readyState), status: status, responseURL: responseURL,
......
This diff is collapsed.
......@@ -83,7 +83,7 @@ class InAppWebViewOptions implements WebViewOptions, BrowserOptions, AndroidOpti
///
///**NOTE**: available on iOS 11.0+.
List<ContentBlocker> contentBlockers;
///Sets the content mode that the WebView needs to use. The default value is [InAppWebViewUserPreferredContentMode.RECOMMENDED].
///Sets the content mode that the WebView needs to use when loading and rendering a webpage. The default value is [InAppWebViewUserPreferredContentMode.RECOMMENDED].
///
///**NOTE**: available on iOS 13.0+.
InAppWebViewUserPreferredContentMode preferredContentMode;
......@@ -676,10 +676,16 @@ class IosSafariOptions implements ChromeSafariBrowserOptions, IosOptions {
///Set to `true` to enable bar collapsing. The default value is `false`.
bool barCollapsingEnabled;
///Set the custom style for the dismiss button. The default value is [IosSafariOptionsDismissButtonStyle.DONE].
///
///**NOTE**: available on iOS 11.0+.
IosSafariOptionsDismissButtonStyle dismissButtonStyle;
///Set the custom background color of the navigation bar and the toolbar.
///
///**NOTE**: available on iOS 10.0+.
String preferredBarTintColor;
///Set the custom color of the control buttons on the navigation bar and the toolbar.
///
///**NOTE**: available on iOS 10.0+.
String preferredControlTintColor;
///Set the custom modal presentation style when presenting the WebView. The default value is [IosWebViewOptionsPresentationStyle.FULL_SCREEN].
IosWebViewOptionsPresentationStyle presentationStyle;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment