Skip to content

Commit

Permalink
Fix dismiss() causing crash when dialog is detached.
Browse files Browse the repository at this point in the history
Summary: If dismiss is called (especially on the spinner) after the dialog has been detached from the window, it could cause the whole app to crash. This alleviates that situation. App developers should still call dismiss() on the dialog during onPause() since this does not address the leaking window issue, but if they don't, this at least won't crash their app.

Test Plan: Tested various situations where rotation happens (during a webview load, and after posting an update).

Reviewers: mmarucheck, clang

Reviewed By: mmarucheck

Differential Revision: https://phabricator.fb.com/D643794

Task ID: 1878623
  • Loading branch information
mingflifb committed Dec 7, 2012
1 parent 4484f89 commit 6fac158
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions facebook/src/com/facebook/widget/WebDialog.java
Expand Up @@ -65,6 +65,7 @@ public class WebDialog extends Dialog {
private ImageView crossImageView;
private FrameLayout contentFrameLayout;
private boolean listenerCalled = false;
private boolean isDetached = false;

/**
* Interface that implements a listener to be called when the user's interaction with the
Expand Down Expand Up @@ -151,10 +152,24 @@ public void dismiss() {
if (webView != null) {
webView.stopLoading();
}
if (spinner.isShowing()) {
spinner.dismiss();
if (!isDetached) {
if (spinner.isShowing()) {
spinner.dismiss();
}
super.dismiss();
}
super.dismiss();
}

@Override
public void onDetachedFromWindow() {
isDetached = true;
super.onDetachedFromWindow();
}

@Override
public void onAttachedToWindow() {
isDetached = false;
super.onAttachedToWindow();
}

@Override
Expand Down Expand Up @@ -337,13 +352,17 @@ public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError e
public void onPageStarted(WebView view, String url, Bitmap favicon) {
Util.logd(LOG_TAG, "Webview loading URL: " + url);
super.onPageStarted(view, url, favicon);
spinner.show();
if (!isDetached) {
spinner.show();
}
}

@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
spinner.dismiss();
if (!isDetached) {
spinner.dismiss();
}
/*
* Once web view is fully loaded, set the contentFrameLayout background to be transparent
* and make visible the 'x' image.
Expand Down

0 comments on commit 6fac158

Please sign in to comment.