CB-8592 Fix NPE if lifecycle events reach CordovaWebView before init() has been called

This commit is contained in:
Andrew Grieve 2015-03-03 09:51:39 -05:00
parent 023ad9ddf8
commit 62c081dc85

View File

@ -423,14 +423,12 @@ public class CordovaWebViewImpl implements CordovaWebView {
} }
@Override @Override
public void handlePause(boolean keepRunning) { public void handlePause(boolean keepRunning) {
LOG.d(TAG, "Handle the pause"); if (!isInitialized()) {
// Send pause event to JavaScript return;
sendJavascriptEvent("pause");
// Forward to plugins
if (pluginManager != null) {
pluginManager.onPause(keepRunning);
} }
LOG.d(TAG, "Handle the pause");
sendJavascriptEvent("pause");
pluginManager.onPause(keepRunning);
// If app doesn't want to run in background // If app doesn't want to run in background
if (!keepRunning) { if (!keepRunning) {
@ -439,29 +437,27 @@ public class CordovaWebViewImpl implements CordovaWebView {
} }
} }
@Override @Override
public void handleResume(boolean keepRunning) public void handleResume(boolean keepRunning) {
{ if (!isInitialized()) {
return;
}
// Resume JavaScript timers. This affects all webviews within the app! // Resume JavaScript timers. This affects all webviews within the app!
engine.setPaused(false); engine.setPaused(false);
sendJavascriptEvent("resume"); sendJavascriptEvent("resume");
// Forward to plugins
if (this.pluginManager != null) {
this.pluginManager.onResume(keepRunning); this.pluginManager.onResume(keepRunning);
} }
}
@Override @Override
public void handleDestroy() public void handleDestroy() {
{ if (!isInitialized()) {
return;
}
// Cancel pending timeout timer. // Cancel pending timeout timer.
loadUrlTimeout++; loadUrlTimeout++;
// Forward to plugins // Forward to plugins
if (this.pluginManager != null) {
this.pluginManager.onDestroy(); this.pluginManager.onDestroy();
}
// Load blank page so that JavaScript onunload is called // Load blank page so that JavaScript onunload is called
this.loadUrl("about:blank"); this.loadUrl("about:blank");