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/ios/ios_serialized_navigation_driver.h"
7 #include "base/memory/singleton.h"
8 #include "components/sessions/serialized_navigation_entry.h"
9 #include "ios/web/public/referrer.h"
14 SerializedNavigationDriver
* SerializedNavigationDriver::Get() {
15 return IOSSerializedNavigationDriver::GetInstance();
19 IOSSerializedNavigationDriver
*
20 IOSSerializedNavigationDriver::GetInstance() {
21 return Singleton
<IOSSerializedNavigationDriver
,
22 LeakySingletonTraits
<IOSSerializedNavigationDriver
>>::get();
25 IOSSerializedNavigationDriver::IOSSerializedNavigationDriver() {
28 IOSSerializedNavigationDriver::~IOSSerializedNavigationDriver() {
31 int IOSSerializedNavigationDriver::GetDefaultReferrerPolicy() const {
32 return web::ReferrerPolicyDefault
;
36 IOSSerializedNavigationDriver::GetSanitizedPageStateForPickle(
37 const SerializedNavigationEntry
* navigation
) const {
41 void IOSSerializedNavigationDriver::Sanitize(
42 SerializedNavigationEntry
* navigation
) const {
43 web::Referrer
referrer(
44 navigation
->referrer_url_
,
45 static_cast<web::ReferrerPolicy
>(navigation
->referrer_policy_
));
47 if (!navigation
->virtual_url_
.SchemeIsHTTPOrHTTPS() ||
48 !referrer
.url
.SchemeIsHTTPOrHTTPS()) {
49 referrer
.url
= GURL();
51 switch (referrer
.policy
) {
52 case web::ReferrerPolicyDefault
:
53 if (referrer
.url
.SchemeIsSecure() &&
54 !navigation
->virtual_url_
.SchemeIsSecure()) {
55 referrer
.url
= GURL();
58 case web::ReferrerPolicyAlways
:
60 case web::ReferrerPolicyNever
:
61 referrer
.url
= GURL();
63 case web::ReferrerPolicyOrigin
:
64 referrer
.url
= referrer
.url
.GetOrigin();
72 // Reset the referrer if it has changed.
73 if (navigation
->referrer_url_
!= referrer
.url
) {
74 navigation
->referrer_url_
= GURL();
75 navigation
->referrer_policy_
= GetDefaultReferrerPolicy();
79 } // namespace sessions