OLD | NEW |
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 "components/sessions/serialized_navigation_entry.h" | 8 #include "components/sessions/serialized_navigation_entry.h" |
9 #include "content/public/common/page_state.h" | 9 #include "content/public/common/page_state.h" |
10 #include "content/public/common/referrer.h" | 10 #include "content/public/common/referrer.h" |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 | 93 |
94 void ContentSerializedNavigationDriver::Sanitize( | 94 void ContentSerializedNavigationDriver::Sanitize( |
95 SerializedNavigationEntry* navigation) const { | 95 SerializedNavigationEntry* navigation) const { |
96 content::Referrer old_referrer( | 96 content::Referrer old_referrer( |
97 navigation->referrer_url_, | 97 navigation->referrer_url_, |
98 static_cast<blink::WebReferrerPolicy>(navigation->referrer_policy_)); | 98 static_cast<blink::WebReferrerPolicy>(navigation->referrer_policy_)); |
99 content::Referrer new_referrer = | 99 content::Referrer new_referrer = |
100 content::Referrer::SanitizeForRequest(navigation->virtual_url_, | 100 content::Referrer::SanitizeForRequest(navigation->virtual_url_, |
101 old_referrer); | 101 old_referrer); |
102 | 102 |
| 103 bool page_state_is_valid = navigation->encoded_page_state_.empty() || |
| 104 content::PageState::CreateFromEncodedData( |
| 105 navigation->encoded_page_state_).IsValid(); |
| 106 |
103 // No need to compare the policy, as it doesn't change during | 107 // No need to compare the policy, as it doesn't change during |
104 // sanitization. If there has been a change, the referrer needs to be | 108 // sanitization. If there has been a change, the referrer needs to be |
105 // stripped from the page state as well. | 109 // stripped from the page state as well. |
106 if (navigation->referrer_url_ != new_referrer.url) { | 110 if (navigation->referrer_url_ != new_referrer.url || !page_state_is_valid) { |
107 navigation->referrer_url_ = GURL(); | 111 navigation->referrer_url_ = GURL(); |
108 navigation->referrer_policy_ = GetDefaultReferrerPolicy(); | 112 navigation->referrer_policy_ = GetDefaultReferrerPolicy(); |
109 navigation->encoded_page_state_ = | 113 navigation->encoded_page_state_ = |
110 StripReferrerFromPageState(navigation->encoded_page_state_); | 114 StripReferrerFromPageState(navigation->encoded_page_state_); |
111 } | 115 } |
112 } | 116 } |
113 | 117 |
114 std::string ContentSerializedNavigationDriver::StripReferrerFromPageState( | 118 std::string ContentSerializedNavigationDriver::StripReferrerFromPageState( |
115 const std::string& page_state) const { | 119 const std::string& page_state) const { |
116 return content::PageState::CreateFromEncodedData(page_state) | 120 return content::PageState::CreateFromEncodedData(page_state) |
117 .RemoveReferrer() | 121 .RemoveReferrer() |
118 .ToEncodedData(); | 122 .ToEncodedData(); |
119 } | 123 } |
120 | 124 |
121 } // namespace sessions | 125 } // namespace sessions |
OLD | NEW |