ServiceWorker: Consolidate version manipulation functions in SWProviderContext
[chromium-blink-merge.git] / components / sessions / ios / ios_serialized_navigation_driver.cc
blobf6324ab35fb00a1e3413c2ea6a0362798f418380
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 // static
14 SerializedNavigationDriver* SerializedNavigationDriver::Get() {
15 return IOSSerializedNavigationDriver::GetInstance();
18 // static
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;
35 std::string
36 IOSSerializedNavigationDriver::GetSanitizedPageStateForPickle(
37 const SerializedNavigationEntry* navigation) const {
38 return std::string();
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();
50 } else {
51 switch (referrer.policy) {
52 case web::ReferrerPolicyDefault:
53 if (referrer.url.SchemeIsSecure() &&
54 !navigation->virtual_url_.SchemeIsSecure()) {
55 referrer.url = GURL();
57 break;
58 case web::ReferrerPolicyAlways:
59 break;
60 case web::ReferrerPolicyNever:
61 referrer.url = GURL();
62 break;
63 case web::ReferrerPolicyOrigin:
64 referrer.url = referrer.url.GetOrigin();
65 break;
66 default:
67 NOTREACHED();
68 break;
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