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

Side by Side Diff: components/sessions/content/content_serialized_navigation_driver.cc

Issue 2355543003: Invalidate the page state when restoring WebUIs (Closed)
Patch Set: fix nit Created 4 years, 2 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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/sessions/content/content_serialized_navigation_driver.h" 5 #include "components/sessions/content/content_serialized_navigation_driver.h"
6 6
7 #include "base/memory/singleton.h" 7 #include "base/memory/singleton.h"
8 #include "build/build_config.h" 8 #include "build/build_config.h"
9 #include "components/sessions/core/serialized_navigation_entry.h" 9 #include "components/sessions/core/serialized_navigation_entry.h"
10 #include "content/public/common/page_state.h" 10 #include "content/public/common/page_state.h"
11 #include "content/public/common/referrer.h" 11 #include "content/public/common/referrer.h"
12 #include "content/public/common/url_constants.h" 12 #include "content/public/common/url_constants.h"
13 13
14 namespace sessions { 14 namespace sessions {
15 15
16 namespace { 16 namespace {
17 const int kObsoleteReferrerPolicyAlways = 0; 17 const int kObsoleteReferrerPolicyAlways = 0;
18 const int kObsoleteReferrerPolicyDefault = 1; 18 const int kObsoleteReferrerPolicyDefault = 1;
19 const int kObsoleteReferrerPolicyNever = 2; 19 const int kObsoleteReferrerPolicyNever = 2;
20 const int kObsoleteReferrerPolicyOrigin = 3; 20 const int kObsoleteReferrerPolicyOrigin = 3;
21
22 bool IsUberOrUberReplacementURL(const GURL& url) {
23 return url.SchemeIs(content::kChromeUIScheme) &&
24 (url.host() == content::kChromeUIHistoryHost ||
25 url.host() == content::kChromeUIUberHost);
26 }
27
21 } // namespace 28 } // namespace
22 29
23 // static 30 // static
24 SerializedNavigationDriver* SerializedNavigationDriver::Get() { 31 SerializedNavigationDriver* SerializedNavigationDriver::Get() {
25 return ContentSerializedNavigationDriver::GetInstance(); 32 return ContentSerializedNavigationDriver::GetInstance();
26 } 33 }
27 34
28 // static 35 // static
29 ContentSerializedNavigationDriver* 36 ContentSerializedNavigationDriver*
30 ContentSerializedNavigationDriver::GetInstance() { 37 ContentSerializedNavigationDriver::GetInstance() {
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 103
97 void ContentSerializedNavigationDriver::Sanitize( 104 void ContentSerializedNavigationDriver::Sanitize(
98 SerializedNavigationEntry* navigation) const { 105 SerializedNavigationEntry* navigation) const {
99 content::Referrer old_referrer( 106 content::Referrer old_referrer(
100 navigation->referrer_url_, 107 navigation->referrer_url_,
101 static_cast<blink::WebReferrerPolicy>(navigation->referrer_policy_)); 108 static_cast<blink::WebReferrerPolicy>(navigation->referrer_policy_));
102 content::Referrer new_referrer = 109 content::Referrer new_referrer =
103 content::Referrer::SanitizeForRequest(navigation->virtual_url_, 110 content::Referrer::SanitizeForRequest(navigation->virtual_url_,
104 old_referrer); 111 old_referrer);
105 112
113 // Clear any Uber UI page state so that these pages are reloaded rather than
114 // restored from page state. This fixes session restore when WebUI URLs
115 // change.
116 if (IsUberOrUberReplacementURL(navigation->virtual_url_) &&
117 IsUberOrUberReplacementURL(navigation->original_request_url_)) {
118 navigation->encoded_page_state_ = std::string();
119 }
120
106 // No need to compare the policy, as it doesn't change during 121 // No need to compare the policy, as it doesn't change during
107 // sanitization. If there has been a change, the referrer needs to be 122 // sanitization. If there has been a change, the referrer needs to be
108 // stripped from the page state as well. 123 // stripped from the page state as well.
109 if (navigation->referrer_url_ != new_referrer.url) { 124 if (navigation->referrer_url_ != new_referrer.url) {
110 navigation->referrer_url_ = GURL(); 125 navigation->referrer_url_ = GURL();
111 navigation->referrer_policy_ = GetDefaultReferrerPolicy(); 126 navigation->referrer_policy_ = GetDefaultReferrerPolicy();
112 navigation->encoded_page_state_ = 127 navigation->encoded_page_state_ =
113 StripReferrerFromPageState(navigation->encoded_page_state_); 128 StripReferrerFromPageState(navigation->encoded_page_state_);
114 } 129 }
115 130
(...skipping 11 matching lines...) Expand all
127 } 142 }
128 143
129 std::string ContentSerializedNavigationDriver::StripReferrerFromPageState( 144 std::string ContentSerializedNavigationDriver::StripReferrerFromPageState(
130 const std::string& page_state) const { 145 const std::string& page_state) const {
131 return content::PageState::CreateFromEncodedData(page_state) 146 return content::PageState::CreateFromEncodedData(page_state)
132 .RemoveReferrer() 147 .RemoveReferrer()
133 .ToEncodedData(); 148 .ToEncodedData();
134 } 149 }
135 150
136 } // namespace sessions 151 } // namespace sessions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698