Commit 9edf0cc0 authored by Alexander Timin's avatar Alexander Timin Committed by Commit Bot

[bfcache] Always call CanStoreDocument for the main frame

Ensure that we always pass the main document to CanStoreDocument as
CanStoreDocument always returns false for non-main documents, which
then will lead to eviction even when we still can store the document
in the cache.

R=arthursonzogni@chromium.org,hajimehoshi@chromium.org

Change-Id: I021ef8fa0505c9d8eef0d423cde319439f4c612e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1905688
Commit-Queue: Alexander Timin <altimin@chromium.org>
Reviewed-by: default avatarArthur Sonzogni <arthursonzogni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#717500}
parent 81e2a101
......@@ -3921,4 +3921,39 @@ IN_PROC_BROWSER_TEST_F(SensorBackForwardCacheBrowserTest,
FROM_HERE);
}
IN_PROC_BROWSER_TEST_F(BackForwardCacheBrowserTest,
AllowedFeaturesForSubframesDoNotEvict) {
// The main purpose of this test is to check that when a state of a subframe
// is updated, CanStoreDocument is still called for the main frame - otherwise
// we would always evict the document, even when the feature is allowed as
// CanStoreDocument always returns false for non-main frames.
ASSERT_TRUE(embedded_test_server()->Start());
GURL url_a(embedded_test_server()->GetURL(
"a.com", "/cross_site_iframe_factory.html?a(b)"));
GURL url_c(embedded_test_server()->GetURL("c.com", "/title1.html"));
// 1) Navigate to A.
ASSERT_TRUE(NavigateToURL(shell(), url_a));
RenderFrameHostImpl* rfh_a = current_frame_host();
RenderFrameHostImpl* rfh_b = rfh_a->child_at(0)->current_frame_host();
RenderFrameDeletedObserver delete_observer_rfh_b(rfh_b);
// 2) Navigate to C.
ASSERT_TRUE(NavigateToURL(shell(), url_c));
// 3) No-op feature update on a subframe while in cache, should be no-op.
ASSERT_FALSE(delete_observer_rfh_b.deleted());
static_cast<blink::mojom::LocalFrameHost*>(rfh_b)
->DidChangeActiveSchedulerTrackedFeatures(0);
// 4) Go back.
web_contents()->GetController().GoBack();
EXPECT_TRUE(WaitForLoadStop(shell()->web_contents()));
EXPECT_EQ(current_frame_host(), rfh_a);
ExpectOutcome(BackForwardCacheMetrics::HistoryNavigationOutcome::kRestored,
FROM_HERE);
}
} // namespace content
......@@ -7821,9 +7821,14 @@ void RenderFrameHostImpl::MaybeEvictFromBackForwardCache() {
if (!is_in_back_forward_cache_)
return;
RenderFrameHostImpl* top_document = this;
while (RenderFrameHostImpl* parent = top_document->GetParent())
top_document = parent;
NavigationControllerImpl* controller = static_cast<NavigationControllerImpl*>(
frame_tree_node_->navigator()->GetController());
auto can_store = controller->GetBackForwardCache().CanStoreDocument(this);
auto can_store =
controller->GetBackForwardCache().CanStoreDocument(top_document);
TRACE_EVENT1("navigation",
"RenderFrameHostImpl::MaybeEvictFromBackForwardCache",
"can_store", can_store.ToString());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment