OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "android_webview/native/state_serializer.h" | 5 #include "android_webview/native/state_serializer.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/memory/scoped_vector.h" | 9 #include "base/memory/scoped_vector.h" |
10 #include "base/pickle.h" | 10 #include "base/pickle.h" |
(...skipping 22 matching lines...) Expand all Loading... |
33 namespace { | 33 namespace { |
34 | 34 |
35 // Sanity check value that we are restoring from a valid pickle. | 35 // Sanity check value that we are restoring from a valid pickle. |
36 // This can potentially used as an actual serialization version number in the | 36 // This can potentially used as an actual serialization version number in the |
37 // future if we ever decide to support restoring from older versions. | 37 // future if we ever decide to support restoring from older versions. |
38 const uint32 AW_STATE_VERSION = 20130814; | 38 const uint32 AW_STATE_VERSION = 20130814; |
39 | 39 |
40 } // namespace | 40 } // namespace |
41 | 41 |
42 bool WriteToPickle(const content::WebContents& web_contents, | 42 bool WriteToPickle(const content::WebContents& web_contents, |
43 Pickle* pickle) { | 43 base::Pickle* pickle) { |
44 DCHECK(pickle); | 44 DCHECK(pickle); |
45 | 45 |
46 if (!internal::WriteHeaderToPickle(pickle)) | 46 if (!internal::WriteHeaderToPickle(pickle)) |
47 return false; | 47 return false; |
48 | 48 |
49 const content::NavigationController& controller = | 49 const content::NavigationController& controller = |
50 web_contents.GetController(); | 50 web_contents.GetController(); |
51 const int entry_count = controller.GetEntryCount(); | 51 const int entry_count = controller.GetEntryCount(); |
52 const int selected_entry = controller.GetCurrentEntryIndex(); | 52 const int selected_entry = controller.GetCurrentEntryIndex(); |
53 DCHECK_GE(entry_count, 0); | 53 DCHECK_GE(entry_count, 0); |
(...skipping 10 matching lines...) Expand all Loading... |
64 if (!internal::WriteNavigationEntryToPickle(*controller.GetEntryAtIndex(i), | 64 if (!internal::WriteNavigationEntryToPickle(*controller.GetEntryAtIndex(i), |
65 pickle)) | 65 pickle)) |
66 return false; | 66 return false; |
67 } | 67 } |
68 | 68 |
69 // Please update AW_STATE_VERSION if serialization format is changed. | 69 // Please update AW_STATE_VERSION if serialization format is changed. |
70 | 70 |
71 return true; | 71 return true; |
72 } | 72 } |
73 | 73 |
74 bool RestoreFromPickle(PickleIterator* iterator, | 74 bool RestoreFromPickle(base::PickleIterator* iterator, |
75 content::WebContents* web_contents) { | 75 content::WebContents* web_contents) { |
76 DCHECK(iterator); | 76 DCHECK(iterator); |
77 DCHECK(web_contents); | 77 DCHECK(web_contents); |
78 | 78 |
79 if (!internal::RestoreHeaderFromPickle(iterator)) | 79 if (!internal::RestoreHeaderFromPickle(iterator)) |
80 return false; | 80 return false; |
81 | 81 |
82 int entry_count = -1; | 82 int entry_count = -1; |
83 int selected_entry = -2; // -1 is a valid value | 83 int selected_entry = -2; // -1 is a valid value |
84 | 84 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 } | 129 } |
130 } | 130 } |
131 | 131 |
132 controller.LoadIfNecessary(); | 132 controller.LoadIfNecessary(); |
133 | 133 |
134 return true; | 134 return true; |
135 } | 135 } |
136 | 136 |
137 namespace internal { | 137 namespace internal { |
138 | 138 |
139 bool WriteHeaderToPickle(Pickle* pickle) { | 139 bool WriteHeaderToPickle(base::Pickle* pickle) { |
140 return pickle->WriteUInt32(AW_STATE_VERSION); | 140 return pickle->WriteUInt32(AW_STATE_VERSION); |
141 } | 141 } |
142 | 142 |
143 bool RestoreHeaderFromPickle(PickleIterator* iterator) { | 143 bool RestoreHeaderFromPickle(base::PickleIterator* iterator) { |
144 uint32 state_version = -1; | 144 uint32 state_version = -1; |
145 if (!iterator->ReadUInt32(&state_version)) | 145 if (!iterator->ReadUInt32(&state_version)) |
146 return false; | 146 return false; |
147 | 147 |
148 if (AW_STATE_VERSION != state_version) | 148 if (AW_STATE_VERSION != state_version) |
149 return false; | 149 return false; |
150 | 150 |
151 return true; | 151 return true; |
152 } | 152 } |
153 | 153 |
154 bool WriteNavigationEntryToPickle(const content::NavigationEntry& entry, | 154 bool WriteNavigationEntryToPickle(const content::NavigationEntry& entry, |
155 Pickle* pickle) { | 155 base::Pickle* pickle) { |
156 if (!pickle->WriteString(entry.GetURL().spec())) | 156 if (!pickle->WriteString(entry.GetURL().spec())) |
157 return false; | 157 return false; |
158 | 158 |
159 if (!pickle->WriteString(entry.GetVirtualURL().spec())) | 159 if (!pickle->WriteString(entry.GetVirtualURL().spec())) |
160 return false; | 160 return false; |
161 | 161 |
162 const content::Referrer& referrer = entry.GetReferrer(); | 162 const content::Referrer& referrer = entry.GetReferrer(); |
163 if (!pickle->WriteString(referrer.url.spec())) | 163 if (!pickle->WriteString(referrer.url.spec())) |
164 return false; | 164 return false; |
165 if (!pickle->WriteInt(static_cast<int>(referrer.policy))) | 165 if (!pickle->WriteInt(static_cast<int>(referrer.policy))) |
(...skipping 21 matching lines...) Expand all Loading... |
187 return false; | 187 return false; |
188 | 188 |
189 if (!pickle->WriteInt(entry.GetHttpStatusCode())) | 189 if (!pickle->WriteInt(entry.GetHttpStatusCode())) |
190 return false; | 190 return false; |
191 | 191 |
192 // Please update AW_STATE_VERSION if serialization format is changed. | 192 // Please update AW_STATE_VERSION if serialization format is changed. |
193 | 193 |
194 return true; | 194 return true; |
195 } | 195 } |
196 | 196 |
197 bool RestoreNavigationEntryFromPickle(PickleIterator* iterator, | 197 bool RestoreNavigationEntryFromPickle(base::PickleIterator* iterator, |
198 content::NavigationEntry* entry) { | 198 content::NavigationEntry* entry) { |
199 { | 199 { |
200 string url; | 200 string url; |
201 if (!iterator->ReadString(&url)) | 201 if (!iterator->ReadString(&url)) |
202 return false; | 202 return false; |
203 entry->SetURL(GURL(url)); | 203 entry->SetURL(GURL(url)); |
204 } | 204 } |
205 | 205 |
206 { | 206 { |
207 string virtual_url; | 207 string virtual_url; |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 return false; | 281 return false; |
282 entry->SetHttpStatusCode(http_status_code); | 282 entry->SetHttpStatusCode(http_status_code); |
283 } | 283 } |
284 | 284 |
285 return true; | 285 return true; |
286 } | 286 } |
287 | 287 |
288 } // namespace internal | 288 } // namespace internal |
289 | 289 |
290 } // namespace android_webview | 290 } // namespace android_webview |
OLD | NEW |