From 62c081dc85e297581811db2cacdf73eb5d49ea24 Mon Sep 17 00:00:00 2001 From: Andrew Grieve Date: Tue, 3 Mar 2015 09:51:39 -0500 Subject: [PATCH] CB-8592 Fix NPE if lifecycle events reach CordovaWebView before `init()` has been called --- .../apache/cordova/CordovaWebViewImpl.java | 36 +++++++++---------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/framework/src/org/apache/cordova/CordovaWebViewImpl.java b/framework/src/org/apache/cordova/CordovaWebViewImpl.java index d6004408..3b5aecd9 100644 --- a/framework/src/org/apache/cordova/CordovaWebViewImpl.java +++ b/framework/src/org/apache/cordova/CordovaWebViewImpl.java @@ -423,14 +423,12 @@ public class CordovaWebViewImpl implements CordovaWebView { } @Override public void handlePause(boolean keepRunning) { - LOG.d(TAG, "Handle the pause"); - // Send pause event to JavaScript - sendJavascriptEvent("pause"); - - // Forward to plugins - if (pluginManager != null) { - pluginManager.onPause(keepRunning); + if (!isInitialized()) { + return; } + LOG.d(TAG, "Handle the pause"); + sendJavascriptEvent("pause"); + pluginManager.onPause(keepRunning); // If app doesn't want to run in background if (!keepRunning) { @@ -439,29 +437,27 @@ public class CordovaWebViewImpl implements CordovaWebView { } } @Override - public void handleResume(boolean keepRunning) - { + public void handleResume(boolean keepRunning) { + if (!isInitialized()) { + return; + } + // Resume JavaScript timers. This affects all webviews within the app! engine.setPaused(false); - sendJavascriptEvent("resume"); - - // Forward to plugins - if (this.pluginManager != null) { - this.pluginManager.onResume(keepRunning); - } + this.pluginManager.onResume(keepRunning); } @Override - public void handleDestroy() - { + public void handleDestroy() { + if (!isInitialized()) { + return; + } // Cancel pending timeout timer. loadUrlTimeout++; // Forward to plugins - if (this.pluginManager != null) { - this.pluginManager.onDestroy(); - } + this.pluginManager.onDestroy(); // Load blank page so that JavaScript onunload is called this.loadUrl("about:blank");