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

Commit 9217c458 authored by Grace Kloba's avatar Grace Kloba
Browse files

When we destroy a WebView, RESUME_TIMERS/PAUSE_TIMERS may be still in the queue.

We need to pass them to WebViewCore as they are per process base. If we drop
them, the counter in the JWebCoreJavaBridge can be out of order.

Part 2 of fixing http://b/issue?id=2087410
parent 485e6dca
Loading
Loading
Loading
Loading
+25 −0
Original line number Diff line number Diff line
@@ -1244,6 +1244,18 @@ final class WebViewCore {
            }
        }

        private synchronized boolean hasMessages(int what) {
            if (mBlockMessages) {
                return false;
            }
            if (mMessages != null) {
                Log.w(LOGTAG, "hasMessages() is not supported in this case.");
                return false;
            } else {
                return mHandler.hasMessages(what);
            }
        }

        private synchronized void sendMessageDelayed(Message msg, long delay) {
            if (mBlockMessages) {
                return;
@@ -1355,9 +1367,22 @@ final class WebViewCore {
        // We don't want anyone to post a message between removing pending
        // messages and sending the destroy message.
        synchronized (mEventHub) {
            // RESUME_TIMERS and PAUSE_TIMERS are per process base. They need to
            // be preserved even the WebView is destroyed.
            // Note: we should not have more than one RESUME_TIMERS/PAUSE_TIMERS
            boolean hasResume = mEventHub.hasMessages(EventHub.RESUME_TIMERS);
            boolean hasPause = mEventHub.hasMessages(EventHub.PAUSE_TIMERS);
            mEventHub.removeMessages();
            mEventHub.sendMessageAtFrontOfQueue(
                    Message.obtain(null, EventHub.DESTROY));
            if (hasPause) {
                mEventHub.sendMessageAtFrontOfQueue(
                        Message.obtain(null, EventHub.PAUSE_TIMERS));
            }
            if (hasResume) {
                mEventHub.sendMessageAtFrontOfQueue(
                        Message.obtain(null, EventHub.RESUME_TIMERS));
            }
            mEventHub.blockMessages();
            mWebView = null;
        }