| Index: chrome/browser/sessions/session_common_utils.cc
|
| diff --git a/chrome/browser/sessions/session_common_utils.cc b/chrome/browser/sessions/session_common_utils.cc
|
| index 938b6e978d636128d85ec32c0e3742b240704012..b0e52b8183aa9660f545a087b4631395506c53bc 100644
|
| --- a/chrome/browser/sessions/session_common_utils.cc
|
| +++ b/chrome/browser/sessions/session_common_utils.cc
|
| @@ -7,10 +7,28 @@
|
| #include <algorithm>
|
| #include <string>
|
|
|
| +#include "build/build_config.h"
|
| #include "chrome/common/url_constants.h"
|
| +#include "components/sessions/core/serialized_navigation_driver.h"
|
| #include "components/sessions/core/session_types.h"
|
| +#include "content/public/common/referrer.h"
|
| #include "url/gurl.h"
|
|
|
| +#if defined(OS_ANDROID)
|
| +#include "content/public/common/content_features.h"
|
| +#include "content/public/common/page_state.h"
|
| +#endif
|
| +
|
| +namespace {
|
| +
|
| +bool IsUberOrUberReplacementURL(const GURL& url) {
|
| + return url.SchemeIs(content::kChromeUIScheme) &&
|
| + (url.host_piece() == chrome::kChromeUIHistoryHost ||
|
| + url.host_piece() == chrome::kChromeUIUberHost);
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| bool ShouldTrackURLForRestore(const GURL& url) {
|
| return url.is_valid() &&
|
| !(url.SchemeIs(content::kChromeUIScheme) &&
|
| @@ -40,3 +58,67 @@ int GetNavigationIndexToSelect(const sessions::SessionTab& tab) {
|
|
|
| return selected_index;
|
| }
|
| +
|
| +void SanitizeNavigation(sessions::SerializedNavigationEntry* navigation) {
|
| + content::Referrer old_referrer(
|
| + navigation->referrer_url(),
|
| + static_cast<blink::WebReferrerPolicy>(navigation->referrer_policy()));
|
| + content::Referrer new_referrer = content::Referrer::SanitizeForRequest(
|
| + navigation->virtual_url(), old_referrer);
|
| +
|
| + // Clear any Uber UI page state so that these pages are reloaded rather than
|
| + // restored from page state. This fixes session restore when WebUI URLs
|
| + // change.
|
| + if (IsUberOrUberReplacementURL(navigation->virtual_url()) &&
|
| + IsUberOrUberReplacementURL(navigation->original_request_url())) {
|
| + navigation->set_encoded_page_state(std::string());
|
| + }
|
| +
|
| + // No need to compare the policy, as it doesn't change during
|
| + // sanitization. If there has been a change, the referrer needs to be
|
| + // stripped from the page state as well.
|
| + if (navigation->referrer_url() != new_referrer.url) {
|
| + auto* driver = sessions::SerializedNavigationDriver::Get();
|
| + navigation->set_referrer_url(GURL());
|
| + navigation->set_referrer_policy(driver->GetDefaultReferrerPolicy());
|
| + navigation->set_encoded_page_state(
|
| + driver->StripReferrerFromPageState(navigation->encoded_page_state()));
|
| + }
|
| +
|
| +#if defined(OS_ANDROID)
|
| + // Rewrite the old new tab and welcome page URLs to the new NTP URL.
|
| + if (navigation->virtual_url().SchemeIs(content::kChromeUIScheme) &&
|
| + (navigation->virtual_url().host_piece() == chrome::kChromeUIWelcomeHost ||
|
| + navigation->virtual_url().host_piece() == chrome::kChromeUINewTabHost)) {
|
| + navigation->set_virtual_url(GURL(chrome::kChromeUINativeNewTabURL));
|
| + navigation->set_original_request_url(navigation->virtual_url());
|
| + navigation->set_encoded_page_state(
|
| + content::PageState::CreateFromURL(navigation->virtual_url())
|
| + .ToEncodedData());
|
| + }
|
| +
|
| + if (base::FeatureList::IsEnabled(features::kNativeAndroidHistoryManager) &&
|
| + navigation->virtual_url().SchemeIs(content::kChromeUIScheme) &&
|
| + (navigation->virtual_url().host_piece() == chrome::kChromeUIHistoryHost ||
|
| + navigation->virtual_url().host_piece() ==
|
| + chrome::kChromeUIHistoryFrameHost)) {
|
| + // Rewrite the old history Web UI to the new android native history.
|
| + 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());
|
| + } else if (!base::FeatureList::IsEnabled(
|
| + features::kNativeAndroidHistoryManager) &&
|
| + navigation->virtual_url().SchemeIs(
|
| + chrome::kChromeUINativeScheme) &&
|
| + navigation->virtual_url().host_piece() ==
|
| + chrome::kChromeUIHistoryHost) {
|
| + // If the android native history UI has been disabled, redirect
|
| + // chrome-native://history to the old web UI.
|
| + navigation->set_virtual_url(GURL(chrome::kChromeUIHistoryURL));
|
| + navigation->set_original_request_url(navigation->virtual_url());
|
| + navigation->set_encoded_page_state(std::string());
|
| + }
|
| +#endif // defined(OS_ANDROID)
|
| +}
|
|
|