diff --git a/include/cef_load_handler.h b/include/cef_load_handler.h index 04c55cd7a997912670b62c613d6b497aae62e89d..26d237c1e5dab777ec127d01cfab8afed9460508 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 3f58f54839cd6a4711943660c547c233fdadeaf9..8e17340729c7e71bed3ad219d3f0d41c1f4b6bea 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 93ce007f28c2e5f50fd7567c6dbea8f5feedbe5c..539f37aaecc1cf07299601fe39652708957e9ce9 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 f62d6bc946aa4e8916cc98f90ec3e0e2637e331b..75ee2fa6598afbfc6d933bbf0e84a3553b97de23 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 20171f7d96e5ef60b48d28ef0d1d73b8a91cc8a3..791ca75c1247971a3b5e66801a4d97314694ac10 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_