Skip to content

Commit

Permalink
Merge pull request #1 from pichillilorenzo/master
Browse files Browse the repository at this point in the history
upgrade origin
  • Loading branch information
crazecoder authored Nov 11, 2019
2 parents 971ac88 + f89610a commit fead4fb
Show file tree
Hide file tree
Showing 21 changed files with 1,281 additions and 680 deletions.
363 changes: 176 additions & 187 deletions .idea/workspace.xml

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
- Merge "Fix abstract method error && swift version error" [#155](https://github.com/pichillilorenzo/flutter_inappbrowser/pull/155) (thanks to [AlexVincent525](https://github.com/AlexVincent525))
- Merge "migrating to swift 5.0" [#162](https://github.com/pichillilorenzo/flutter_inappbrowser/pull/162) (thanks to [fattiger00](https://github.com/fattiger00))
- Merge "Update readme example" [#178](https://github.com/pichillilorenzo/flutter_inappbrowser/pull/178) (thanks to [SebastienBtr](https://github.com/SebastienBtr))
- Merge "handle choose file callback in android" [#183](https://github.com/pichillilorenzo/flutter_inappbrowser/pull/183) (thanks to [crazecoder](https://github.com/crazecoder))
- Merge "add initialScale in android" [#186](https://github.com/pichillilorenzo/flutter_inappbrowser/pull/186) (thanks to [crazecoder](https://github.com/crazecoder))
- Added `horizontalScrollBarEnabled` and `verticalScrollBarEnabled` options to enable/disable the corresponding scrollbar of the WebView [#165](https://github.com/pichillilorenzo/flutter_inappbrowser/issues/165)
- Added `onDownloadStart` event and `useOnDownloadStart` option: event fires when the WebView recognizes and starts a downloadable file.
- Added `onLoadResourceCustomScheme` event and `resourceCustomSchemes` option to set custom schemes that WebView must handle to load resources
Expand Down Expand Up @@ -43,6 +45,7 @@
- Renamed `injectScriptCode` to `evaluateJavascript`
- Renamed `injectStyleCode` to `injectCSSCode`
- Renamed `injectStyleFile` to `injectCSSFileFromUrl`
- No need to listen to `window.addEventListener("flutterInAppBrowserPlatformReady", fuction(){ })` javascript event anymore to call `window.flutter_inappbrowser.callHandler(handlerName <String>, ...args)` to use the JavaScript message handlers

## 1.2.1

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public void run() {
break;

case MAKE_HTTPS:
if (url.startsWith("http://")) {
if (scheme.equals("http") && (port == -1 || port == 80)) {
String urlHttps = url.replace("http://", "https://");

Request mRequest = new Request.Builder().url(urlHttps).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,10 @@ private void prepareView() {
if (!options.toolbarTop)
actionBar.hide();

if (!options.toolbarTopBackgroundColor.isEmpty())
if (options.toolbarTopBackgroundColor != null && !options.toolbarTopBackgroundColor.isEmpty())
actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor(options.toolbarTopBackgroundColor)));

if (!options.toolbarTopFixedTitle.isEmpty())
if (options.toolbarTopFixedTitle != null && !options.toolbarTopFixedTitle.isEmpty())
actionBar.setTitle(options.toolbarTopFixedTitle);

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@ final public class InAppWebView extends InputAwareWebView {
" }" +
"})(window.console);";

static final String platformReadyJS = "window.dispatchEvent(new Event('flutterInAppBrowserPlatformReady'));";

static final String variableForOnLoadResourceJS = "window._flutter_inappbrowser_useOnLoadResource";
static final String enableVariableForOnLoadResourceJS = variableForOnLoadResourceJS + " = $PLACEHOLDER_VALUE;";

Expand Down Expand Up @@ -116,6 +114,29 @@ final public class InAppWebView extends InputAwareWebView {
" ajax.prototype._flutter_inappbrowser_password = null;" +
" ajax.prototype._flutter_inappbrowser_already_onreadystatechange_wrapped = false;" +
" ajax.prototype._flutter_inappbrowser_request_headers = {};" +
" function convertRequestResponse(request, callback) {" +
" if (request.response != null && request.responseType != null) {" +
" switch (request.responseType) {" +
" case 'arraybuffer':" +
" callback(new Uint8Array(request.response));" +
" return;" +
" case 'blob':" +
" const reader = new FileReader();" +
" reader.addEventListener('loadend', function() { " +
" callback(new Uint8Array(reader.result));" +
" });" +
" reader.readAsArrayBuffer(blob);" +
" return;" +
" case 'document':" +
" callback(request.response.documentElement.outerHTML);" +
" return;" +
" case 'json':" +
" callback(request.response);" +
" return;" +
" };" +
" }" +
" callback(null);" +
" };" +
" ajax.prototype.open = function(method, url, isAsync, user, password) {" +
" isAsync = (isAsync != null) ? isAsync : true;" +
" this._flutter_inappbrowser_url = url;" +
Expand Down Expand Up @@ -143,35 +164,40 @@ final public class InAppWebView extends InputAwareWebView {
" responseHeaders[header] = value;" +
" });" +
" }" +
" var ajaxRequest = {" +
" method: this._flutter_inappbrowser_method," +
" url: this._flutter_inappbrowser_url," +
" isAsync: this._flutter_inappbrowser_isAsync," +
" user: this._flutter_inappbrowser_user," +
" password: this._flutter_inappbrowser_password," +
" withCredentials: this.withCredentials," +
" headers: this._flutter_inappbrowser_request_headers," +
" readyState: this.readyState," +
" status: this.status," +
" responseURL: this.responseURL," +
" responseType: this.responseType," +
" responseText: this.responseText," +
" statusText: this.statusText," +
" responseHeaders, responseHeaders," +
" event: {" +
" type: e.type," +
" loaded: e.loaded," +
" lengthComputable: e.lengthComputable" +
" }" +
" };" +
" window." + JavaScriptBridgeInterface.name + ".callHandler('onAjaxProgress', ajaxRequest).then(function(result) {" +
" if (result != null) {" +
" switch (result) {" +
" case 0:" +
" self.abort();" +
" return;" +
" };" +
" }" +
" convertRequestResponse(this, function(response) {" +
" var ajaxRequest = {" +
" method: self._flutter_inappbrowser_method," +
" url: self._flutter_inappbrowser_url," +
" isAsync: self._flutter_inappbrowser_isAsync," +
" user: self._flutter_inappbrowser_user," +
" password: self._flutter_inappbrowser_password," +
" withCredentials: self.withCredentials," +
" headers: self._flutter_inappbrowser_request_headers," +
" readyState: self.readyState," +
" status: self.status," +
" responseURL: self.responseURL," +
" responseType: self.responseType," +
" response: response," +
" responseText: (self.responseType == 'text' || self.responseType == '') ? self.responseText : null," +
" responseXML: (self.responseType == 'document' && self.responseXML != null) ? self.responseXML.documentElement.outerHTML : null," +
" statusText: self.statusText," +
" responseHeaders, responseHeaders," +
" event: {" +
" type: e.type," +
" loaded: e.loaded," +
" lengthComputable: e.lengthComputable," +
" total: e.total" +
" }" +
" };" +
" window." + JavaScriptBridgeInterface.name + ".callHandler('onAjaxProgress', ajaxRequest).then(function(result) {" +
" if (result != null) {" +
" switch (result) {" +
" case 0:" +
" self.abort();" +
" return;" +
" };" +
" }" +
" });" +
" });" +
" }" +
" };" +
Expand All @@ -194,33 +220,37 @@ final public class InAppWebView extends InputAwareWebView {
" responseHeaders[header] = value;" +
" });" +
" }" +
" var ajaxRequest = {" +
" method: this._flutter_inappbrowser_method," +
" url: this._flutter_inappbrowser_url," +
" isAsync: this._flutter_inappbrowser_isAsync," +
" user: this._flutter_inappbrowser_user," +
" password: this._flutter_inappbrowser_password," +
" withCredentials: this.withCredentials," +
" headers: this._flutter_inappbrowser_request_headers," +
" readyState: this.readyState," +
" status: this.status," +
" responseURL: this.responseURL," +
" responseType: this.responseType," +
" responseText: this.responseText," +
" statusText: this.statusText," +
" responseHeaders: responseHeaders" +
" };" +
" window." + JavaScriptBridgeInterface.name + ".callHandler('onAjaxReadyStateChange', ajaxRequest).then(function(result) {" +
" if (result != null) {" +
" switch (result) {" +
" case 0:" +
" self.abort();" +
" return;" +
" };" +
" }" +
" if (onreadystatechange != null) {" +
" onreadystatechange();" +
" }" +
" convertRequestResponse(this, function(response) {" +
" var ajaxRequest = {" +
" method: self._flutter_inappbrowser_method," +
" url: self._flutter_inappbrowser_url," +
" isAsync: self._flutter_inappbrowser_isAsync," +
" user: self._flutter_inappbrowser_user," +
" password: self._flutter_inappbrowser_password," +
" withCredentials: self.withCredentials," +
" headers: self._flutter_inappbrowser_request_headers," +
" readyState: self.readyState," +
" status: self.status," +
" responseURL: self.responseURL," +
" responseType: self.responseType," +
" response: response," +
" responseText: (self.responseType == 'text' || self.responseType == '') ? self.responseText : null," +
" responseXML: (self.responseType == 'document' && self.responseXML != null) ? self.responseXML.documentElement.outerHTML : null," +
" statusText: self.statusText," +
" responseHeaders: responseHeaders" +
" };" +
" window." + JavaScriptBridgeInterface.name + ".callHandler('onAjaxReadyStateChange', ajaxRequest).then(function(result) {" +
" if (result != null) {" +
" switch (result) {" +
" case 0:" +
" self.abort();" +
" return;" +
" };" +
" }" +
" if (onreadystatechange != null) {" +
" onreadystatechange();" +
" }" +
" });" +
" });" +
" } else if (onreadystatechange != null) {" +
" onreadystatechange();" +
Expand All @@ -233,6 +263,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," +
Expand All @@ -241,7 +272,8 @@ final public class InAppWebView extends InputAwareWebView {
" user: this._flutter_inappbrowser_user," +
" password: this._flutter_inappbrowser_password," +
" withCredentials: this.withCredentials," +
" headers: this._flutter_inappbrowser_request_headers" +
" headers: this._flutter_inappbrowser_request_headers," +
" responseType: this.responseType" +
" };" +
" window." + JavaScriptBridgeInterface.name + ".callHandler('shouldInterceptAjaxRequest', ajaxRequest).then(function(result) {" +
" if (result != null) {" +
Expand All @@ -252,6 +284,9 @@ final public class InAppWebView extends InputAwareWebView {
" };" +
" data = result.data;" +
" self.withCredentials = result.withCredentials;" +
" if (result.responseType != null) {" +
" self.responseType = result.responseType;" +
" };" +
" for (var header in result.headers) {" +
" var value = result.headers[header];" +
" self.setRequestHeader(header, value);" +
Expand Down Expand Up @@ -405,7 +440,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;" +
Expand Down Expand Up @@ -555,14 +590,17 @@ else if (options.clearSessionCache)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && options.forceDark != null)
settings.setForceDark(options.forceDark);
settings.setGeolocationEnabled(options.geolocationEnabled);
if (options.layoutAlgorithm != null)
settings.setLayoutAlgorithm(options.layoutAlgorithm);
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);
if(options.initialScale != null)
setInitialScale(options.initialScale);

setInitialScale(options.initialScale);
settings.setNeedInitialFocus(options.needInitialFocus);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
settings.setOffscreenPreRaster(options.offscreenPreRaster);
Expand All @@ -575,9 +613,8 @@ else if (options.clearSessionCache)
setDesktopMode(true);
break;
case MOBILE:
setDesktopMode(false);
break;
case RECOMMENDED:
setDesktopMode(false);
break;
}
}
Expand Down Expand Up @@ -951,8 +988,13 @@ else if (newOptionsMap.get("clearSessionCache") != null && newOptions.clearSessi
if (newOptionsMap.get("geolocationEnabled") != null && options.geolocationEnabled != newOptions.geolocationEnabled)
settings.setGeolocationEnabled(newOptions.geolocationEnabled);

if (newOptionsMap.get("layoutAlgorithm") != null && options.layoutAlgorithm != newOptions.layoutAlgorithm)
settings.setLayoutAlgorithm(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);
Expand Down Expand Up @@ -985,6 +1027,18 @@ else if (newOptionsMap.get("clearSessionCache") != null && newOptions.clearSessi
if (newOptionsMap.get("standardFontFamily") != null && !options.standardFontFamily.equals(newOptions.standardFontFamily))
settings.setStandardFontFamily(newOptions.standardFontFamily);

if (newOptionsMap.get("preferredContentMode") != null && !options.preferredContentMode.equals(newOptions.preferredContentMode)) {
switch (fromValue(newOptions.preferredContentMode)) {
case DESKTOP:
setDesktopMode(true);
break;
case MOBILE:
case RECOMMENDED:
setDesktopMode(false);
break;
}
}

if (newOptionsMap.get("saveFormData") != null && options.saveFormData != newOptions.saveFormData)
settings.setSaveFormData(newOptions.saveFormData);

Expand Down
Loading

0 comments on commit fead4fb

Please sign in to comment.