Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(912)

Side by Side Diff: chrome/browser/sessions/chrome_serialized_navigation_driver.cc

Issue 2759333002: Move chrome-specific SerializedNavigation code to chrome/. (Closed)
Patch Set: bad export Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/sessions/chrome_serialized_navigation_driver.h"
6
7 #include "base/memory/singleton.h"
8 #include "build/build_config.h"
9 #include "chrome/common/url_constants.h"
10 #include "components/sessions/core/serialized_navigation_entry.h"
11 #include "content/public/common/referrer.h"
12
13 #if defined(OS_ANDROID)
14 #include "content/public/common/content_features.h"
15 #include "content/public/common/page_state.h"
16 #endif
17
18 namespace {
19
20 bool IsUberOrUberReplacementURL(const GURL& url) {
21 return url.SchemeIs(content::kChromeUIScheme) &&
22 (url.host_piece() == chrome::kChromeUIHistoryHost ||
23 url.host_piece() == chrome::kChromeUIUberHost);
24 }
25
26 } // namespace
27
28 // static
29 ChromeSerializedNavigationDriver*
30 ChromeSerializedNavigationDriver::GetInstance() {
31 return base::Singleton<
32 ChromeSerializedNavigationDriver,
33 base::LeakySingletonTraits<ChromeSerializedNavigationDriver>>::get();
34 }
35
36 void ChromeSerializedNavigationDriver::Sanitize(
37 sessions::SerializedNavigationEntry* navigation) const {
38 content::Referrer old_referrer(
39 navigation->referrer_url(),
40 static_cast<blink::WebReferrerPolicy>(navigation->referrer_policy()));
41 content::Referrer new_referrer = content::Referrer::SanitizeForRequest(
42 navigation->virtual_url(), old_referrer);
43
44 // Clear any Uber UI page state so that these pages are reloaded rather than
45 // restored from page state. This fixes session restore when WebUI URLs
46 // change.
47 if (IsUberOrUberReplacementURL(navigation->virtual_url()) &&
48 IsUberOrUberReplacementURL(navigation->original_request_url())) {
49 navigation->set_encoded_page_state(std::string());
50 }
51
52 // No need to compare the policy, as it doesn't change during
53 // sanitization. If there has been a change, the referrer needs to be
54 // stripped from the page state as well.
55 if (navigation->referrer_url() != new_referrer.url) {
56 auto* driver = sessions::SerializedNavigationDriver::Get();
57 navigation->set_referrer_url(GURL());
58 navigation->set_referrer_policy(driver->GetDefaultReferrerPolicy());
59 navigation->set_encoded_page_state(
60 driver->StripReferrerFromPageState(navigation->encoded_page_state()));
61 }
62
63 #if defined(OS_ANDROID)
64 // Rewrite the old new tab and welcome page URLs to the new NTP URL.
65 if (navigation->virtual_url().SchemeIs(content::kChromeUIScheme) &&
66 (navigation->virtual_url().host_piece() == chrome::kChromeUIWelcomeHost ||
67 navigation->virtual_url().host_piece() == chrome::kChromeUINewTabHost)) {
68 navigation->set_virtual_url(GURL(chrome::kChromeUINativeNewTabURL));
69 navigation->set_original_request_url(navigation->virtual_url());
70 navigation->set_encoded_page_state(
71 content::PageState::CreateFromURL(navigation->virtual_url())
72 .ToEncodedData());
73 }
74
75 if (base::FeatureList::IsEnabled(features::kNativeAndroidHistoryManager) &&
76 navigation->virtual_url().SchemeIs(content::kChromeUIScheme) &&
77 (navigation->virtual_url().host_piece() == chrome::kChromeUIHistoryHost ||
78 navigation->virtual_url().host_piece() ==
79 chrome::kChromeUIHistoryFrameHost)) {
80 // Rewrite the old history Web UI to the new android native history.
81 navigation->set_virtual_url(GURL(chrome::kChromeUINativeHistoryURL));
82 navigation->set_original_request_url(navigation->virtual_url());
83 navigation->set_encoded_page_state(
84 content::PageState::CreateFromURL(navigation->virtual_url())
85 .ToEncodedData());
86 } else if (!base::FeatureList::IsEnabled(
87 features::kNativeAndroidHistoryManager) &&
88 navigation->virtual_url().SchemeIs(
89 chrome::kChromeUINativeScheme) &&
90 navigation->virtual_url().host_piece() ==
91 chrome::kChromeUIHistoryHost) {
92 // If the android native history UI has been disabled, redirect
93 // chrome-native://history to the old web UI.
94 navigation->set_virtual_url(GURL(chrome::kChromeUIHistoryURL));
95 navigation->set_original_request_url(navigation->virtual_url());
96 navigation->set_encoded_page_state(std::string());
97 }
98 #endif // defined(OS_ANDROID)
99 }
100
101 ChromeSerializedNavigationDriver::ChromeSerializedNavigationDriver() {}
102
103 ChromeSerializedNavigationDriver::~ChromeSerializedNavigationDriver() {}
sky 2017/03/22 04:00:31 Make Definition/declaration order match.
Lei Zhang 2017/03/22 05:59:05 Done.
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698