From 3227730e7d04ab5de77c6e861c1ead9425b52e6e Mon Sep 17 00:00:00 2001 From: Andrew Liventsev Date: Wed, 18 Jul 2018 15:48:09 +0300 Subject: [PATCH] Fix Issue #23: no cancel event --- src/android/InAppBrowserXwalk.java | 18 +++++++++++++++++- www/inappbrowserxwalk.js | 3 +++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/android/InAppBrowserXwalk.java b/src/android/InAppBrowserXwalk.java index bf521a0..af4fcb8 100644 --- a/src/android/InAppBrowserXwalk.java +++ b/src/android/InAppBrowserXwalk.java @@ -2,6 +2,7 @@ import com.example.plugin.InAppBrowserXwalk.BrowserDialog; +import android.content.DialogInterface; import android.content.res.Resources; import org.apache.cordova.*; import org.apache.cordova.PluginManager; @@ -14,7 +15,7 @@ import org.xwalk.core.XWalkView; import org.xwalk.core.XWalkResourceClient; import org.xwalk.core.internal.XWalkViewInternal; -import org.xwalk.core.internal.XWalkCookieManager; +import org.xwalk.core.XWalkCookieManager; import android.view.View; import android.view.Window; @@ -161,6 +162,21 @@ public void onClick(View v) { dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.getWindow().getAttributes().windowAnimations = android.R.style.Animation_Dialog; dialog.setCancelable(true); + + dialog.setOnCancelListener(new DialogInterface.OnCancelListener() { + public void onCancel(DialogInterface dialog) { + try { + JSONObject obj = new JSONObject(); + obj.put("type", "cancel"); + PluginResult result = new PluginResult(PluginResult.Status.OK, obj); + result.setKeepCallback(true); + callbackContext.sendPluginResult(result); + } catch (JSONException e) { + e.printStackTrace(); + } + } + }); + LayoutParams layoutParams = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT); dialog.addContentView(main, layoutParams); if(!openHidden) { diff --git a/www/inappbrowserxwalk.js b/www/inappbrowserxwalk.js index 1dd9aa5..1897714 100644 --- a/www/inappbrowserxwalk.js +++ b/www/inappbrowserxwalk.js @@ -34,6 +34,9 @@ var callback = function(event) { if (event.type === "exit" && callbacks['exit'] !== undefined) { callbacks['exit'](); } + if (event.type === "cancel" && callbacks['cancel'] !== undefined) { + callbacks['cancel'](); + } } module.exports = {