From 32520a24354d38df330120e885e10c42dc88d5f7 Mon Sep 17 00:00:00 2001 From: gaojianhao1 Date: Sun, 29 Sep 2024 13:37:48 +0800 Subject: [PATCH] =?UTF-8?q?FixBackForwardCache=20Favicon.=20=EF=BC=88cherr?= =?UTF-8?q?y=20picked=20commit=20from=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: gaojianhao1 --- include/cef_load_handler.h | 8 +++++ libcef/browser/browser_contents_delegate.cc | 9 ++++++ libcef/browser/browser_host_base.cc | 2 ++ .../oh_page_load_metrics_observer.cc | 31 +++++++++++++++++++ .../oh_page_load_metrics_observer.h | 23 ++++++++++++++ 5 files changed, 73 insertions(+) diff --git a/include/cef_load_handler.h b/include/cef_load_handler.h index 04c55cd7a..26d237c1e 100644 --- a/include/cef_load_handler.h +++ b/include/cef_load_handler.h @@ -210,6 +210,14 @@ class CefLoadHandler : public virtual CefBaseRefCounted { const CefString& website_host, const CefString& tracker_host) {} +#ifdef OHOS_BFCACHE + /// + /// Called when page load from bfcache. + /// + /*--cef()--*/ + virtual void UpdateFavicon(CefRefPtr browser) {} +#endif + #endif // BUILDFLAG(IS_OHOS) }; diff --git a/libcef/browser/browser_contents_delegate.cc b/libcef/browser/browser_contents_delegate.cc index 3f58f5483..8e1734072 100644 --- a/libcef/browser/browser_contents_delegate.cc +++ b/libcef/browser/browser_contents_delegate.cc @@ -858,6 +858,15 @@ void CefBrowserContentsDelegate::DidFinishNavigation( OnLoadStart(frame.get(), navigation_handle->GetPageTransition()); if (navigation_handle->IsServedFromBackForwardCache()) { // We won't get an OnLoadEnd notification from anywhere else. +#ifdef OHOS_BFCACHE + LOG(INFO) << "[Favicon] page load form bfcache."; + if (auto c = client()) { + if (auto handler = c->GetLoadHandler()) { + auto navigation_lock = browser_info_->CreateNavigationLock(); + handler->UpdateFavicon(browser()); + } + } +#endif // OHOS_BFCACHE OnLoadEnd(frame.get(), navigation_handle->GetURL(), 0); } } diff --git a/libcef/browser/browser_host_base.cc b/libcef/browser/browser_host_base.cc index 93ce007f2..539f37aae 100644 --- a/libcef/browser/browser_host_base.cc +++ b/libcef/browser/browser_host_base.cc @@ -3942,6 +3942,8 @@ void CefBrowserHostBase::SetBackForwardCacheOptions(int32_t size, int32_t timeTo return; } + LOG(INFO) << "SetBackForwardCacheOptions param size: " << size + << " timeToLive: " << timeToLive; content::NavigationController& controller = web_contents->GetController(); controller.GetBackForwardCache().SetCacheSize(size); controller.GetBackForwardCache().SetTimeToLive(timeToLive); diff --git a/libcef/browser/page_load_metrics/oh_page_load_metrics_observer.cc b/libcef/browser/page_load_metrics/oh_page_load_metrics_observer.cc index f62d6bc94..75ee2fa65 100644 --- a/libcef/browser/page_load_metrics/oh_page_load_metrics_observer.cc +++ b/libcef/browser/page_load_metrics/oh_page_load_metrics_observer.cc @@ -108,6 +108,37 @@ int64_t OhPageLoadMetricsObserver::GetNavigationStartTime() { return navigation_start_time; } +#ifdef OHOS_BFCACHE +void OhPageLoadMetricsObserver::OnRestoreFromBackForwardCache( + const page_load_metrics::mojom::PageLoadTiming& timing, + content::NavigationHandle* navigation_handle) { + back_forward_cache_navigation_ids_.push_back( + navigation_handle->GetNavigationId()); +} + +page_load_metrics::PageLoadMetricsObserver::ObservePolicy +OhPageLoadMetricsObserver::OnEnterBackForwardCache( + const page_load_metrics::mojom::PageLoadTiming& timing) { + return CONTINUE_OBSERVING; +} + +void OhPageLoadMetricsObserver:: + OnFirstContentfulPaintAfterBackForwardCacheRestoreInPage( + const page_load_metrics::mojom::BackForwardCacheTiming& timing, + size_t index) { + if (index >= back_forward_cache_navigation_ids_.size()) + return; + + int64_t first_contentful_paint_ms = + timing.first_paint_after_back_forward_cache_restore.InMilliseconds(); +#if defined(REPORT_SYS_EVENT) + web_performance_timing_.first_contentful_paint = first_contentful_paint_ms; +#endif + int64_t navigation_start_time = GetNavigationStartTime(); + ReportFirstContentfulPaint(navigation_start_time, first_contentful_paint_ms); +} +#endif + void OhPageLoadMetricsObserver::OnFirstContentfulPaintInPage( const page_load_metrics::mojom::PageLoadTiming& timing) { DCHECK_CURRENTLY_ON(content::BrowserThread::UI); diff --git a/libcef/browser/page_load_metrics/oh_page_load_metrics_observer.h b/libcef/browser/page_load_metrics/oh_page_load_metrics_observer.h index 20171f7d9..791ca75c1 100644 --- a/libcef/browser/page_load_metrics/oh_page_load_metrics_observer.h +++ b/libcef/browser/page_load_metrics/oh_page_load_metrics_observer.h @@ -32,6 +32,11 @@ class OhPageLoadMetricsObserver ObservePolicy OnStart(content::NavigationHandle* navigation_handle, const GURL& currently_committed_url, bool started_in_foreground) override; +#ifdef OHOS_BFCACHE + page_load_metrics::PageLoadMetricsObserver::ObservePolicy + OnEnterBackForwardCache( + const page_load_metrics::mojom::PageLoadTiming& timing) override; +#endif ObservePolicy OnFencedFramesStart( content::NavigationHandle* navigation_handle, const GURL& currently_committed_url) override; @@ -52,6 +57,11 @@ class OhPageLoadMetricsObserver void OnFirstMeaningfulPaintInMainFrameDocument( const page_load_metrics::mojom::PageLoadTiming& timing) override; +#if OHOS_BFCACHE + void OnFirstContentfulPaintAfterBackForwardCacheRestoreInPage( + const page_load_metrics::mojom::BackForwardCacheTiming& timing, size_t index) override; +#endif + #if defined(REPORT_SYS_EVENT) ObservePolicy OnRedirect( content::NavigationHandle* navigation_handle) override; @@ -66,6 +76,13 @@ class OhPageLoadMetricsObserver const page_load_metrics::mojom::PageLoadTiming& timing) override; static void OnNavigationStart(); #endif + +#ifdef OHOS_BFCACHE + void OnRestoreFromBackForwardCache( + const page_load_metrics::mojom::PageLoadTiming& timing, + content::NavigationHandle* navigation_handle) override; +#endif + protected: OhPageLoadMetricsObserver( network::NetworkQualityTracker* network_quality_tracker) @@ -97,6 +114,12 @@ class OhPageLoadMetricsObserver OhWebPerformanceTiming web_performance_timing_; static int64_t navigation_start_timestamp_; #endif + +#ifdef OHOS_BFCACHE + // IDs for the navigations when the page is restored from the back-forward + // cache. + std::vector back_forward_cache_navigation_ids_; +#endif }; #endif // CEF_LIBCEF_BROWSER_PAGE_LOAD_METRICS_OH_PAGE_LOAD_METRICS_OBSERVER_H_ -- Gitee