Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(879)

Side by Side Diff: components/sessions/content/content_serialized_navigation_driver.cc

Issue 2921883003: [Sync] Ensure referrer is recorded regardless of policy conversion (Closed)
Patch Set: Tighten Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <utility> 7 #include <utility>
8 8
9 #include "base/memory/singleton.h" 9 #include "base/memory/singleton.h"
10 #include "components/sessions/core/serialized_navigation_entry.h" 10 #include "components/sessions/core/serialized_navigation_entry.h"
11 #include "content/public/common/page_state.h" 11 #include "content/public/common/page_state.h"
12 #include "third_party/WebKit/public/platform/WebReferrerPolicy.h" 12 #include "third_party/WebKit/public/platform/WebReferrerPolicy.h"
13 13
14 namespace sessions { 14 namespace sessions {
15 15
16 namespace { 16 namespace {
17 17
18 const int kObsoleteReferrerPolicyAlways = 0;
19 const int kObsoleteReferrerPolicyDefault = 1;
20 const int kObsoleteReferrerPolicyNever = 2;
21 const int kObsoleteReferrerPolicyOrigin = 3;
22
23 ContentSerializedNavigationDriver* g_instance = nullptr; 18 ContentSerializedNavigationDriver* g_instance = nullptr;
24 19
25 } // namespace 20 } // namespace
26 21
27 // static 22 // static
28 SerializedNavigationDriver* SerializedNavigationDriver::Get() { 23 SerializedNavigationDriver* SerializedNavigationDriver::Get() {
29 return ContentSerializedNavigationDriver::GetInstance(); 24 return ContentSerializedNavigationDriver::GetInstance();
30 } 25 }
31 26
32 // static 27 // static
(...skipping 19 matching lines...) Expand all
52 ContentSerializedNavigationDriver::ContentSerializedNavigationDriver() { 47 ContentSerializedNavigationDriver::ContentSerializedNavigationDriver() {
53 } 48 }
54 49
55 ContentSerializedNavigationDriver::~ContentSerializedNavigationDriver() { 50 ContentSerializedNavigationDriver::~ContentSerializedNavigationDriver() {
56 } 51 }
57 52
58 int ContentSerializedNavigationDriver::GetDefaultReferrerPolicy() const { 53 int ContentSerializedNavigationDriver::GetDefaultReferrerPolicy() const {
59 return blink::kWebReferrerPolicyDefault; 54 return blink::kWebReferrerPolicyDefault;
60 } 55 }
61 56
62 bool ContentSerializedNavigationDriver::MapReferrerPolicyToOldValues(
63 int referrer_policy,
64 int* mapped_referrer_policy) const {
65 switch (referrer_policy) {
66 case blink::kWebReferrerPolicyAlways:
67 case blink::kWebReferrerPolicyDefault:
68 // "always" and "default" are the same value in all versions.
69 *mapped_referrer_policy = referrer_policy;
70 return true;
71
72 case blink::kWebReferrerPolicyOrigin:
73 // "origin" exists in the old encoding.
74 *mapped_referrer_policy = kObsoleteReferrerPolicyOrigin;
75 return true;
76
77 default:
78 // Everything else is mapped to never.
79 *mapped_referrer_policy = kObsoleteReferrerPolicyNever;
80 return false;
81 }
82 }
83
84 bool ContentSerializedNavigationDriver::MapReferrerPolicyToNewValues(
85 int referrer_policy,
86 int* mapped_referrer_policy) const {
87 switch (referrer_policy) {
88 case kObsoleteReferrerPolicyAlways:
89 case kObsoleteReferrerPolicyDefault:
90 // "always" and "default" are the same value in all versions.
91 *mapped_referrer_policy = referrer_policy;
92 return true;
93
94 default:
95 // Since we don't know what encoding was used, we map the rest to "never".
96 *mapped_referrer_policy = blink::kWebReferrerPolicyNever;
97 return false;
98 }
99 }
100
101 std::string 57 std::string
102 ContentSerializedNavigationDriver::GetSanitizedPageStateForPickle( 58 ContentSerializedNavigationDriver::GetSanitizedPageStateForPickle(
103 const SerializedNavigationEntry* navigation) const { 59 const SerializedNavigationEntry* navigation) const {
104 if (!navigation->has_post_data()) 60 if (!navigation->has_post_data())
105 return navigation->encoded_page_state(); 61 return navigation->encoded_page_state();
106 62
107 content::PageState page_state = content::PageState::CreateFromEncodedData( 63 content::PageState page_state = content::PageState::CreateFromEncodedData(
108 navigation->encoded_page_state()); 64 navigation->encoded_page_state());
109 return page_state.RemovePasswordData().ToEncodedData(); 65 return page_state.RemovePasswordData().ToEncodedData();
110 } 66 }
(...skipping 17 matching lines...) Expand all
128 DCHECK(handler.get()); 84 DCHECK(handler.get());
129 extended_info_handler_map_[key] = std::move(handler); 85 extended_info_handler_map_[key] = std::move(handler);
130 } 86 }
131 87
132 const ContentSerializedNavigationDriver::ExtendedInfoHandlerMap& 88 const ContentSerializedNavigationDriver::ExtendedInfoHandlerMap&
133 ContentSerializedNavigationDriver::GetAllExtendedInfoHandlers() const { 89 ContentSerializedNavigationDriver::GetAllExtendedInfoHandlers() const {
134 return extended_info_handler_map_; 90 return extended_info_handler_map_;
135 } 91 }
136 92
137 } // namespace sessions 93 } // namespace sessions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698