From 890e12c30674d7b4dff54082e9ee879505475e19 Mon Sep 17 00:00:00 2001 From: Martin Gonzalez Date: Fri, 3 Oct 2014 00:47:13 -0500 Subject: [PATCH] CB-6837 Fix leaked window when hitting back button while alert being rendered Keep track of the last AlertDialog showed. The last dialog showed that is rendered while hitting back button it causes a leaked window. Instead of perform a full track of all dialogs created, only destroy the last one showed, this fixes the problem. close #122 --- .../org/apache/cordova/CordovaChromeClient.java | 16 +++++++++++++--- .../src/org/apache/cordova/CordovaWebView.java | 3 +++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/framework/src/org/apache/cordova/CordovaChromeClient.java b/framework/src/org/apache/cordova/CordovaChromeClient.java index 737d0b84..ff0c0f2f 100755 --- a/framework/src/org/apache/cordova/CordovaChromeClient.java +++ b/framework/src/org/apache/cordova/CordovaChromeClient.java @@ -65,6 +65,9 @@ public class CordovaChromeClient extends WebChromeClient { // the video progress view private View mVideoProgressView; + //Keep track of last AlertDialog showed + private AlertDialog lastHandledDialog; + // File Chooser public ValueCallback mUploadMessage; @@ -123,7 +126,7 @@ public class CordovaChromeClient extends WebChromeClient { return true; } }); - dlg.show(); + lastHandledDialog = dlg.show(); return true; } @@ -172,7 +175,7 @@ public class CordovaChromeClient extends WebChromeClient { return true; } }); - dlg.show(); + lastHandledDialog = dlg.show(); return true; } @@ -216,7 +219,7 @@ public class CordovaChromeClient extends WebChromeClient { res.cancel(); } }); - dlg.show(); + lastHandledDialog = dlg.show(); } return true; } @@ -328,4 +331,11 @@ public class CordovaChromeClient extends WebChromeClient { public ValueCallback getValueCallback() { return this.mUploadMessage; } + + public void destroyLastDialog(){ + if(lastHandledDialog != null){ + lastHandledDialog.cancel(); + } + } + } diff --git a/framework/src/org/apache/cordova/CordovaWebView.java b/framework/src/org/apache/cordova/CordovaWebView.java index f7a94ae2..862f2ded 100755 --- a/framework/src/org/apache/cordova/CordovaWebView.java +++ b/framework/src/org/apache/cordova/CordovaWebView.java @@ -788,6 +788,9 @@ public class CordovaWebView extends WebView { // Load blank page so that JavaScript onunload is called this.loadUrl("about:blank"); + + //Remove last AlertDialog + this.chromeClient.destroyLastDialog(); // Forward to plugins if (this.pluginManager != null) {