Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0406e48d authored by Ben Murdoch's avatar Ben Murdoch
Browse files

Work around race condition in CallBackProxy.

If WebCore requests two (or more) alert/prompt/confirm dialogs
in quick succeession, we have a race that when the dialog is dismissed
the WebView does not have it's focus restored before the next dialog
is requested to be shown and we early out of displaying the dialog (i.e.
we do not show it).

Work around this by no longer verifying that the Activity has focus as
this check seems to be redundant anyway (see 3166409).

Bug: 3151825, 3166409

Change-Id: I7f650b066ee63da92bc9a620b8e190c91b306d3e
parent dfe7fd17
Loading
Loading
Loading
Loading
+14 −16
Original line number Diff line number Diff line
@@ -496,10 +496,7 @@ class CallbackProxy extends Handler {
                    String url = msg.getData().getString("url");
                    if (!mWebChromeClient.onJsAlert(mWebView, url, message,
                            res)) {
                        // only display the alert dialog if the mContext is
                        // Activity and its window has the focus.
                        if (!(mContext instanceof Activity)
                                || !((Activity) mContext).hasWindowFocus()) {
                        if (!canShowAlertDialog()) {
                            res.cancel();
                            res.setReady();
                            break;
@@ -535,10 +532,7 @@ class CallbackProxy extends Handler {
                    String url = msg.getData().getString("url");
                    if (!mWebChromeClient.onJsConfirm(mWebView, url, message,
                            res)) {
                        // only display the alert dialog if the mContext is
                        // Activity and its window has the focus.
                        if (!(mContext instanceof Activity)
                                || !((Activity) mContext).hasWindowFocus()) {
                        if (!canShowAlertDialog()) {
                            res.cancel();
                            res.setReady();
                            break;
@@ -583,10 +577,7 @@ class CallbackProxy extends Handler {
                    String url = msg.getData().getString("url");
                    if (!mWebChromeClient.onJsPrompt(mWebView, url, message,
                                defaultVal, res)) {
                        // only display the alert dialog if the mContext is
                        // Activity and its window has the focus.
                        if (!(mContext instanceof Activity)
                                || !((Activity) mContext).hasWindowFocus()) {
                        if (!canShowAlertDialog()) {
                            res.cancel();
                            res.setReady();
                            break;
@@ -642,10 +633,7 @@ class CallbackProxy extends Handler {
                    String url = msg.getData().getString("url");
                    if (!mWebChromeClient.onJsBeforeUnload(mWebView, url,
                            message, res)) {
                        // only display the alert dialog if the mContext is
                        // Activity and its window has the focus.
                        if (!(mContext instanceof Activity)
                                || !((Activity) mContext).hasWindowFocus()) {
                        if (!canShowAlertDialog()) {
                            res.cancel();
                            res.setReady();
                            break;
@@ -1555,4 +1543,14 @@ class CallbackProxy extends Handler {
        }
        sendMessage(obtainMessage(SET_INSTALLABLE_WEBAPP));
    }

    boolean canShowAlertDialog() {
        // We can only display the alert dialog if mContext is
        // an Activity context.
        // FIXME: Should we display dialogs if mContext does
        // not have the window focus (e.g. if the user is viewing
        // another Activity when the alert should be displayed?
        // See bug 3166409
        return mContext instanceof Activity;
    }
}