From ec4a8b733732a05f42b42a90939d0f53ba4f1d38 Mon Sep 17 00:00:00 2001 From: Sergio Villar Senin Date: Thu, 21 Nov 2024 11:00:44 +0100 Subject: [PATCH] Emit onFirstContentfulPaint paint for cached pages The FCP event is not emitted by GeckoView if the page is loaded from the cache (either HTTP or back/forward). As a result many things are not properly set up in Wolvic, like the current active session, resulting in many cases in web contents not visible on app start. In those cases we should generate and emit it to get things working. --- .../com/igalia/wolvic/browser/engine/Session.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/src/common/shared/com/igalia/wolvic/browser/engine/Session.java b/app/src/common/shared/com/igalia/wolvic/browser/engine/Session.java index 905e2a2782..37a2f269d1 100644 --- a/app/src/common/shared/com/igalia/wolvic/browser/engine/Session.java +++ b/app/src/common/shared/com/igalia/wolvic/browser/engine/Session.java @@ -12,6 +12,9 @@ import android.content.SharedPreferences; import android.graphics.Bitmap; import androidx.preference.PreferenceManager; + +import android.os.Handler; +import android.os.Looper; import android.util.Log; import android.view.Surface; import android.view.inputmethod.CursorAnchorInfo; @@ -1364,6 +1367,13 @@ public void onFirstComposite(@NonNull WSession aSession) { for (WSession.ContentDelegate listener : mContentListeners) { listener.onFirstContentfulPaint(aSession); } + } else if (!mState.mIsLoading) { + new Handler(Looper.getMainLooper()).postDelayed(() -> { + // onFirstContentfulPaint is not emitted sometimes when loading a page from + // the cache. This is a workaround to ensure that the event is emitted. + if (!mFirstContentfulPaint) + onFirstContentfulPaint(aSession); + }, 500); } } }