Linux: Depend on liberation-fonts package for RPMs.
[chromium-blink-merge.git] / components / sessions / ios / ios_serialized_navigation_driver.cc
blobab04209e6c3bdfd21f253332f02cd05dcab45512
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"
11 namespace sessions {
13 namespace {
14 const int kObsoleteReferrerPolicyAlways = 0;
15 const int kObsoleteReferrerPolicyDefault = 1;
16 const int kObsoleteReferrerPolicyNever = 2;
17 const int kObsoleteReferrerPolicyOrigin = 3;
18 } // namespace
20 // static
21 SerializedNavigationDriver* SerializedNavigationDriver::Get() {
22 return IOSSerializedNavigationDriver::GetInstance();
25 // static
26 IOSSerializedNavigationDriver*
27 IOSSerializedNavigationDriver::GetInstance() {
28 return base::Singleton<
29 IOSSerializedNavigationDriver,
30 base::LeakySingletonTraits<IOSSerializedNavigationDriver>>::get();
33 IOSSerializedNavigationDriver::IOSSerializedNavigationDriver() {
36 IOSSerializedNavigationDriver::~IOSSerializedNavigationDriver() {
39 int IOSSerializedNavigationDriver::GetDefaultReferrerPolicy() const {
40 return web::ReferrerPolicyDefault;
43 bool IOSSerializedNavigationDriver::MapReferrerPolicyToOldValues(
44 int referrer_policy,
45 int* mapped_referrer_policy) const {
46 switch (referrer_policy) {
47 case web::ReferrerPolicyAlways:
48 case web::ReferrerPolicyDefault:
49 // "always" and "default" are the same value in all versions.
50 *mapped_referrer_policy = referrer_policy;
51 return true;
53 case web::ReferrerPolicyOrigin:
54 // "origin" exists in the old encoding.
55 *mapped_referrer_policy = kObsoleteReferrerPolicyOrigin;
56 return true;
58 default:
59 // Everything else is mapped to never.
60 *mapped_referrer_policy = kObsoleteReferrerPolicyNever;
61 return false;
65 bool IOSSerializedNavigationDriver::MapReferrerPolicyToNewValues(
66 int referrer_policy,
67 int* mapped_referrer_policy) const {
68 switch (referrer_policy) {
69 case kObsoleteReferrerPolicyAlways:
70 case kObsoleteReferrerPolicyDefault:
71 // "always" and "default" are the same value in all versions.
72 *mapped_referrer_policy = referrer_policy;
73 return true;
75 default:
76 // Since we don't know what encoding was used, we map the rest to "never".
77 *mapped_referrer_policy = web::ReferrerPolicyNever;
78 return false;
82 std::string
83 IOSSerializedNavigationDriver::GetSanitizedPageStateForPickle(
84 const SerializedNavigationEntry* navigation) const {
85 return std::string();
88 void IOSSerializedNavigationDriver::Sanitize(
89 SerializedNavigationEntry* navigation) const {
90 web::Referrer referrer(
91 navigation->referrer_url_,
92 static_cast<web::ReferrerPolicy>(navigation->referrer_policy_));
94 if (!navigation->virtual_url_.SchemeIsHTTPOrHTTPS() ||
95 !referrer.url.SchemeIsHTTPOrHTTPS()) {
96 referrer.url = GURL();
97 } else {
98 if (referrer.policy < 0 || referrer.policy > web::ReferrerPolicyLast) {
99 NOTREACHED();
100 referrer.policy = web::ReferrerPolicyNever;
102 bool is_downgrade = referrer.url.SchemeIsCryptographic() &&
103 !navigation->virtual_url_.SchemeIsCryptographic();
104 switch (referrer.policy) {
105 case web::ReferrerPolicyDefault:
106 if (is_downgrade)
107 referrer.url = GURL();
108 break;
109 case web::ReferrerPolicyNoReferrerWhenDowngrade:
110 if (is_downgrade)
111 referrer.url = GURL();
112 case web::ReferrerPolicyAlways:
113 break;
114 case web::ReferrerPolicyNever:
115 referrer.url = GURL();
116 break;
117 case web::ReferrerPolicyOrigin:
118 referrer.url = referrer.url.GetOrigin();
119 break;
120 case web::ReferrerPolicyOriginWhenCrossOrigin:
121 if (navigation->virtual_url_.GetOrigin() != referrer.url.GetOrigin())
122 referrer.url = referrer.url.GetOrigin();
123 break;
127 // Reset the referrer if it has changed.
128 if (navigation->referrer_url_ != referrer.url) {
129 navigation->referrer_url_ = GURL();
130 navigation->referrer_policy_ = GetDefaultReferrerPolicy();
134 std::string IOSSerializedNavigationDriver::StripReferrerFromPageState(
135 const std::string& page_state) const {
136 return std::string();
139 } // namespace sessions