Commit 62830e6e authored by Robert Ogden's avatar Robert Ogden Committed by Commit Bot

HTTPS Previews: Load original page on a reload

This allows the previews decision logic to run again.

This is tested by checking the existance of server_lite_page_info which
is not persisted across reloads. Note: forward/back navigations also
do not persist server_lite_page_info.

Bug: 864665
Change-Id: Ibe5d1b698a0f790474992967561ecdd81ac348f4
Reviewed-on: https://chromium-review.googlesource.com/c/1352823Reviewed-by: default avatarTarun Bansal <tbansal@chromium.org>
Commit-Queue: Robert Ogden <robertogden@chromium.org>
Cr-Commit-Position: refs/heads/master@{#611601}
parent 86563ef3
......@@ -271,6 +271,15 @@ class PreviewsLitePageServerBrowserTest : public InProcessBrowserTest {
content::NavigationEntry* entry =
GetWebContents()->GetController().GetVisibleEntry();
// server_lite_page_info does not exist on forward/back navigations.
if (!(entry->GetTransitionType() & ui::PAGE_TRANSITION_FORWARD_BACK)) {
EXPECT_TRUE(previews_data->server_lite_page_info());
EXPECT_NE(
previews_data->server_lite_page_info()->original_navigation_start,
base::TimeTicks());
}
EXPECT_EQ(content::PAGE_TYPE_NORMAL, entry->GetPageType());
const GURL virtual_url = entry->GetVirtualURL();
......@@ -803,6 +812,19 @@ IN_PROC_BROWSER_TEST_F(PreviewsLitePageServerBrowserTest,
GetWebContents()->GetController().Reload(content::ReloadType::NORMAL, false);
VerifyPreviewLoaded();
// Set the ECT so that a preview won't be triggered on the reload.
g_browser_process->network_quality_tracker()
->ReportEffectiveConnectionTypeForTesting(
net::EFFECTIVE_CONNECTION_TYPE_4G);
GetWebContents()->GetController().Reload(content::ReloadType::NORMAL, false);
VerifyPreviewNotLoaded();
// Reset ECT for future tests.
g_browser_process->network_quality_tracker()
->ReportEffectiveConnectionTypeForTesting(
net::EFFECTIVE_CONNECTION_TYPE_2G);
}
IN_PROC_BROWSER_TEST_F(PreviewsLitePageServerBrowserTest,
......
......@@ -543,6 +543,31 @@ PreviewsLitePageNavigationThrottle::MaybeNavigateToPreview() const {
content::NavigationThrottle::ThrottleCheckResult
PreviewsLitePageNavigationThrottle::WillStartRequest() {
// Check if the user is trying to navigate to a valid previews URL in the form
// of a reload. In such a case, cancel the navigation and start a new one to
// the original URL instead. We might trigger this preview again, but if so
// there will be a server_lite_page_info associated with it.
std::string original_url;
if (previews::ExtractOriginalURLFromLitePageRedirectURL(
navigation_handle()->GetURL(), &original_url) &&
navigation_handle()->GetReloadType() == content::ReloadType::NORMAL) {
// Don't use |LoadAndBypass| because we might not want to bypass.
WebContentsLifetimeHelper::CreateForWebContents(
navigation_handle()->GetWebContents());
WebContentsLifetimeHelper* helper =
WebContentsLifetimeHelper::FromWebContents(
navigation_handle()->GetWebContents());
base::PostTaskWithTraits(
FROM_HERE, {content::BrowserThread::UI},
base::BindOnce(&WebContentsLifetimeHelper::PostNewNavigation,
helper->GetWeakPtr(),
MakeOpenURLParams(navigation_handle(),
GURL(original_url), std::string()),
GetOrCreateServerLitePageInfo(navigation_handle())));
return content::NavigationThrottle::CANCEL;
}
MaybeReportNavigationRestartPenalty(navigation_handle());
return MaybeNavigateToPreview();
}
......
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