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 | |
107 // No need to compare the policy, as it doesn't change during | 103 // No need to compare the policy, as it doesn't change during |
108 // sanitization. If there has been a change, the referrer needs to be | 104 // sanitization. If there has been a change, the referrer needs to be |
109 // stripped from the page state as well. | 105 // stripped from the page state as well. |
110 if (navigation->referrer_url_ != new_referrer.url || !page_state_is_valid) { | 106 if (navigation->referrer_url_ != new_referrer.url) { |
111 navigation->referrer_url_ = GURL(); | 107 navigation->referrer_url_ = GURL(); |
112 navigation->referrer_policy_ = GetDefaultReferrerPolicy(); | 108 navigation->referrer_policy_ = GetDefaultReferrerPolicy(); |
113 navigation->encoded_page_state_ = | 109 navigation->encoded_page_state_ = |
114 StripReferrerFromPageState(navigation->encoded_page_state_); | 110 StripReferrerFromPageState(navigation->encoded_page_state_); |
115 } | 111 } |
116 } | 112 } |
117 | 113 |
118 std::string ContentSerializedNavigationDriver::StripReferrerFromPageState( | 114 std::string ContentSerializedNavigationDriver::StripReferrerFromPageState( |
119 const std::string& page_state) const { | 115 const std::string& page_state) const { |
120 return content::PageState::CreateFromEncodedData(page_state) | 116 return content::PageState::CreateFromEncodedData(page_state) |
121 .RemoveReferrer() | 117 .RemoveReferrer() |
122 .ToEncodedData(); | 118 .ToEncodedData(); |
123 } | 119 } |
124 | 120 |
125 } // namespace sessions | 121 } // namespace sessions |
OLD | NEW |