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
3 // found in the LICENSE file.
5 #include "components/sessions/content/content_serialized_navigation_driver.h"
7 #include "base/memory/singleton.h"
8 #include "components/sessions/serialized_navigation_entry.h"
9 #include "content/public/common/page_state.h"
10 #include "content/public/common/referrer.h"
15 SerializedNavigationDriver
* SerializedNavigationDriver::Get() {
16 return ContentSerializedNavigationDriver::GetInstance();
20 ContentSerializedNavigationDriver
*
21 ContentSerializedNavigationDriver::GetInstance() {
22 return Singleton
<ContentSerializedNavigationDriver
,
23 LeakySingletonTraits
<ContentSerializedNavigationDriver
>>::get();
26 ContentSerializedNavigationDriver::ContentSerializedNavigationDriver() {
29 ContentSerializedNavigationDriver::~ContentSerializedNavigationDriver() {
32 int ContentSerializedNavigationDriver::GetDefaultReferrerPolicy() const {
33 return blink::WebReferrerPolicyDefault
;
37 ContentSerializedNavigationDriver::GetSanitizedPageStateForPickle(
38 const SerializedNavigationEntry
* navigation
) const {
39 if (!navigation
->has_post_data_
) {
40 return navigation
->encoded_page_state_
;
42 content::PageState page_state
=
43 content::PageState::CreateFromEncodedData(
44 navigation
->encoded_page_state_
);
45 return page_state
.RemovePasswordData().ToEncodedData();
48 void ContentSerializedNavigationDriver::Sanitize(
49 SerializedNavigationEntry
* navigation
) const {
50 content::Referrer
old_referrer(
51 navigation
->referrer_url_
,
52 static_cast<blink::WebReferrerPolicy
>(navigation
->referrer_policy_
));
53 content::Referrer new_referrer
=
54 content::Referrer::SanitizeForRequest(navigation
->virtual_url_
,
57 // No need to compare the policy, as it doesn't change during
58 // sanitization. If there has been a change, the referrer needs to be
59 // stripped from the page state as well.
60 if (navigation
->referrer_url_
!= new_referrer
.url
) {
61 navigation
->referrer_url_
= GURL();
62 navigation
->referrer_policy_
= GetDefaultReferrerPolicy();
63 navigation
->encoded_page_state_
=
64 content::PageState::CreateFromEncodedData(
65 navigation
->encoded_page_state_
)
71 } // namespace sessions