Commit 63c93050 authored by Lukasz Anforowicz's avatar Lukasz Anforowicz Committed by Commit Bot

Changes by ChromeSerializedNavigationDriver need to be self-consistent.

ChromeSerializedNavigationDriver::Sanitize may rewrite some session
restore entries stored in sessions::SerializedNavigationEntry.
Such rewrite needs to leave the data in a self-consistent state.
This becomes more important now, because r698995 introduced extra
DCHECKs that enforce the self-consistency.

Before this CL, ChromeSerializedNavigationDriver::Sanitize
would modify PageState (which contains the URL, Referrer and other
pieces of data), but would not modify the referrer stored in
the SerializedNavigationEntry.  This CL fixes this.

Bug: 1007532
Change-Id: I0e8722914f1d7a7283a1d87b26b645e058b1c18b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1825461
Commit-Queue: Łukasz Anforowicz <lukasza@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#699996}
parent bc0c54be
...@@ -15,6 +15,28 @@ ...@@ -15,6 +15,28 @@
#include "content/public/common/page_state.h" #include "content/public/common/page_state.h"
#endif #endif
namespace {
#if defined(OS_ANDROID)
// Mutates |navigation| so that it targets |new_destination_url| and has no
// referrer information.
void ChangeDestination(const GURL& new_destination_url,
sessions::SerializedNavigationEntry* navigation) {
navigation->set_virtual_url(new_destination_url);
navigation->set_original_request_url(new_destination_url);
navigation->set_encoded_page_state(
content::PageState::CreateFromURL(new_destination_url).ToEncodedData());
// Make sure the referrer stored in the PageState (above) and in the
// SerializedNavigationEntry (below) are in-sync.
navigation->set_referrer_url(GURL());
navigation->set_referrer_policy(
static_cast<int>(network::mojom::ReferrerPolicy::kDefault));
}
#endif // defined(OS_ANDROID)
} // namespace
ChromeSerializedNavigationDriver::~ChromeSerializedNavigationDriver() {} ChromeSerializedNavigationDriver::~ChromeSerializedNavigationDriver() {}
// static // static
...@@ -49,21 +71,12 @@ void ChromeSerializedNavigationDriver::Sanitize( ...@@ -49,21 +71,12 @@ void ChromeSerializedNavigationDriver::Sanitize(
if (navigation->virtual_url().SchemeIs(content::kChromeUIScheme) && if (navigation->virtual_url().SchemeIs(content::kChromeUIScheme) &&
(navigation->virtual_url().host_piece() == chrome::kChromeUIWelcomeHost || (navigation->virtual_url().host_piece() == chrome::kChromeUIWelcomeHost ||
navigation->virtual_url().host_piece() == chrome::kChromeUINewTabHost)) { navigation->virtual_url().host_piece() == chrome::kChromeUINewTabHost)) {
navigation->set_virtual_url(GURL(chrome::kChromeUINativeNewTabURL)); ChangeDestination(GURL(chrome::kChromeUINativeNewTabURL), navigation);
navigation->set_original_request_url(navigation->virtual_url());
navigation->set_encoded_page_state(
content::PageState::CreateFromURL(navigation->virtual_url())
.ToEncodedData());
} }
if (navigation->virtual_url().SchemeIs(content::kChromeUIScheme) && if (navigation->virtual_url().SchemeIs(content::kChromeUIScheme) &&
navigation->virtual_url().host_piece() == chrome::kChromeUIHistoryHost) { navigation->virtual_url().host_piece() == chrome::kChromeUIHistoryHost) {
// Rewrite the old history Web UI to the new android native history. ChangeDestination(GURL(chrome::kChromeUINativeHistoryURL), navigation);
navigation->set_virtual_url(GURL(chrome::kChromeUINativeHistoryURL));
navigation->set_original_request_url(navigation->virtual_url());
navigation->set_encoded_page_state(
content::PageState::CreateFromURL(navigation->virtual_url())
.ToEncodedData());
} }
#endif // defined(OS_ANDROID) #endif // defined(OS_ANDROID)
} }
......
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