Commit f1adddf6 authored by Alexander Timin's avatar Alexander Timin Committed by Commit Bot

[bfcache] Do not cache offline pages.

Do not put offline pages in back-forward cache as if we have network,
we should reload the full page and if there is no network, offline page
will be reloaded.

R=jianli@chromium.org
CC=bfcache-bugs@chromium.org
BUG=1001087

Change-Id: I2dd9fea312a4ced6355ad3aaa052aeb44ca99779
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1837625Reviewed-by: default avatarJian Li <jianli@chromium.org>
Reviewed-by: default avatarKouhei Ueno <kouhei@chromium.org>
Commit-Queue: Alexander Timin <altimin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#704106}
parent 78835090
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
#include "components/offline_pages/core/prefetch/offline_metrics_collector.h" #include "components/offline_pages/core/prefetch/offline_metrics_collector.h"
#include "components/offline_pages/core/prefetch/prefetch_service.h" #include "components/offline_pages/core/prefetch/prefetch_service.h"
#include "components/offline_pages/core/request_header/offline_page_header.h" #include "components/offline_pages/core/request_header/offline_page_header.h"
#include "content/public/browser/back_forward_cache.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "content/public/browser/navigation_controller.h" #include "content/public/browser/navigation_controller.h"
#include "content/public/browser/navigation_entry.h" #include "content/public/browser/navigation_entry.h"
...@@ -184,6 +185,15 @@ void OfflinePageTabHelper::DidFinishNavigation( ...@@ -184,6 +185,15 @@ void OfflinePageTabHelper::DidFinishNavigation(
if (navigation_handle->IsSameDocument()) if (navigation_handle->IsSameDocument())
return; return;
if (offline_info_.IsValid()) {
// Do not store the offline page we are navigating away from in bfcache.
// If we managed to establish a network connection, we should reload the
// full page on back navigation. If not, offline page is fast to load,
// so back-forward cache is not going to be useful here.
content::BackForwardCache::DisableForRenderFrameHost(
navigation_handle->GetPreviousRenderFrameHostId(), "OfflinePage");
}
// This is a new navigation so we can invalidate any previously scheduled // This is a new navigation so we can invalidate any previously scheduled
// operations. // operations.
weak_ptr_factory_.InvalidateWeakPtrs(); weak_ptr_factory_.InvalidateWeakPtrs();
......
...@@ -19,7 +19,9 @@ ...@@ -19,7 +19,9 @@
#include "components/offline_pages/core/prefetch/offline_metrics_collector.h" #include "components/offline_pages/core/prefetch/offline_metrics_collector.h"
#include "components/offline_pages/core/prefetch/prefetch_service.h" #include "components/offline_pages/core/prefetch/prefetch_service.h"
#include "components/offline_pages/core/prefetch/prefetch_service_test_taco.h" #include "components/offline_pages/core/prefetch/prefetch_service_test_taco.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "content/public/test/back_forward_cache_util.h"
#include "content/public/test/navigation_simulator.h" #include "content/public/test/navigation_simulator.h"
#include "content/public/test/test_renderer_host.h" #include "content/public/test/test_renderer_host.h"
#include "content/public/test/web_contents_tester.h" #include "content/public/test/web_contents_tester.h"
...@@ -425,5 +427,24 @@ TEST_F(OfflinePageTabHelperTest, AbortedNavigationDoesNotResetOfflineInfo) { ...@@ -425,5 +427,24 @@ TEST_F(OfflinePageTabHelperTest, AbortedNavigationDoesNotResetOfflineInfo) {
EXPECT_TRUE(tab_helper()->offline_page()); EXPECT_TRUE(tab_helper()->offline_page());
} }
TEST_F(OfflinePageTabHelperTest, OfflinePageIsNotStoredInBackForwardCache) {
content::BackForwardCacheDisabledTester back_forward_cache_tester;
CreateNavigationSimulator(kTestPageUrl);
navigation_simulator()->Start();
SimulateOfflinePageLoad(kTestPageUrl, kTestMhtmlCreationTime,
MHTMLLoadResult::kSuccess);
int process_id = web_contents()->GetMainFrame()->GetProcess()->GetID();
int main_frame_id = web_contents()->GetMainFrame()->GetRoutingID();
// Navigate away.
content::NavigationSimulator::NavigateAndCommitFromBrowser(web_contents(),
kTestPageUrl);
EXPECT_TRUE(back_forward_cache_tester.IsDisabledForFrameWithReason(
process_id, main_frame_id, "OfflinePage"));
}
} // namespace } // namespace
} // namespace offline_pages } // namespace offline_pages
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