chrome: Update expectations with same-site BFCache enabled (fixes issue #3301)

With same-site BFCache enabled every navigation can now potentially be served
via the BFCache. To support this internally a new top-level RenderFrame object
may be created for each new navigation. As a result, OnBrowserCreated may now
be called multiple times with the same browser ID in a given renderer process
(a behavior previously only seen with cross-site navigations and different
renderer processes).

BFCache navigations do not trigger the same Chromium notifications as a normal
load. To avoid breaking CEF API usage expectations we now synthetically
generate the load-related callbacks that would otherwise be missing
(OnLoadingStateChange with isLoading=true, OnLoadStart, OnLoadEnd). The
|httpStatusCode| argument to OnLoadEnd will be 0 in this case.

To test:
- Run `FrameHandlerTest.*:MessageRouterTest.*:NavigationTest.*`
- Run `NavigationTest.LoadSameOriginLoadURL` for OnBrowserCreated behavior.
- Run `NavigationTest.History` for load-related callback behavior.
This commit is contained in:
Marshall Greenblatt
2022-04-05 13:22:32 -04:00
parent a3b1dc01ea
commit 21cf732e7f
14 changed files with 479 additions and 183 deletions

View File

@ -393,6 +393,19 @@ void CefBrowserImpl::OnLoadingStateChange(bool isLoading) {
return;
}
if (was_in_bfcache_) {
// Send the expected callbacks when exiting the BFCache.
DCHECK(!isLoading);
load_handler->OnLoadingStateChange(this, /*isLoading=*/true,
canGoBack, canGoForward);
auto main_frame = GetMainFrame();
load_handler->OnLoadStart(this, main_frame, TT_EXPLICIT);
load_handler->OnLoadEnd(this, main_frame, 0);
was_in_bfcache_ = false;
}
load_handler->OnLoadingStateChange(this, isLoading, canGoBack,
canGoForward);
last_loading_state_.reset(
@ -401,3 +414,10 @@ void CefBrowserImpl::OnLoadingStateChange(bool isLoading) {
}
}
}
void CefBrowserImpl::OnEnterBFCache() {
// Reset loading state so that notifications will be resent if/when exiting
// BFCache.
was_in_bfcache_ = true;
last_loading_state_.reset();
}