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 17 matching lines...) Expand all Loading... | |
28 | 28 |
29 using std::string; | 29 using std::string; |
30 | 30 |
31 namespace android_webview { | 31 namespace android_webview { |
32 | 32 |
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 = 20131123; |
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 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 |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
170 | 170 |
171 if (!pickle->WriteString(entry.GetPageState().ToEncodedData())) | 171 if (!pickle->WriteString(entry.GetPageState().ToEncodedData())) |
172 return false; | 172 return false; |
173 | 173 |
174 if (!pickle->WriteBool(static_cast<int>(entry.GetHasPostData()))) | 174 if (!pickle->WriteBool(static_cast<int>(entry.GetHasPostData()))) |
175 return false; | 175 return false; |
176 | 176 |
177 if (!pickle->WriteString(entry.GetOriginalRequestURL().spec())) | 177 if (!pickle->WriteString(entry.GetOriginalRequestURL().spec())) |
178 return false; | 178 return false; |
179 | 179 |
180 { | |
181 const char* data = NULL; | |
182 size_t size = 0; | |
183 scoped_refptr<base::RefCountedMemory> p = entry.GetDataForDataURL(); | |
184 if (p.get()) { | |
185 data = reinterpret_cast<const char*>(p->front()); | |
186 size = p->size(); | |
187 } | |
188 if (!pickle->WriteData(data, size)) | |
Nico
2013/11/27 05:50:59
Do you need to do this call when size is 0? If not
joth
2013/11/27 06:23:16
Yes, We need to write something even when the obje
| |
189 return false; | |
190 } | |
191 | |
180 if (!pickle->WriteString(entry.GetBaseURLForDataURL().spec())) | 192 if (!pickle->WriteString(entry.GetBaseURLForDataURL().spec())) |
181 return false; | 193 return false; |
182 | 194 |
183 if (!pickle->WriteBool(static_cast<int>(entry.GetIsOverridingUserAgent()))) | 195 if (!pickle->WriteBool(static_cast<int>(entry.GetIsOverridingUserAgent()))) |
184 return false; | 196 return false; |
185 | 197 |
186 if (!pickle->WriteInt64(entry.GetTimestamp().ToInternalValue())) | 198 if (!pickle->WriteInt64(entry.GetTimestamp().ToInternalValue())) |
187 return false; | 199 return false; |
188 | 200 |
189 if (!pickle->WriteInt(entry.GetHttpStatusCode())) | 201 if (!pickle->WriteInt(entry.GetHttpStatusCode())) |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
248 } | 260 } |
249 | 261 |
250 { | 262 { |
251 string original_request_url; | 263 string original_request_url; |
252 if (!iterator->ReadString(&original_request_url)) | 264 if (!iterator->ReadString(&original_request_url)) |
253 return false; | 265 return false; |
254 entry->SetOriginalRequestURL(GURL(original_request_url)); | 266 entry->SetOriginalRequestURL(GURL(original_request_url)); |
255 } | 267 } |
256 | 268 |
257 { | 269 { |
270 const char* data; | |
271 int len; | |
272 if (!iterator->ReadData(&data, &len)) | |
273 return false; | |
274 if (len > 0) { | |
275 scoped_refptr<base::RefCountedString> ref = new base::RefCountedString; | |
276 ref->data().assign(data, len); | |
277 entry->SetDataForDataURL(ref.get()); | |
278 } | |
279 } | |
280 | |
281 { | |
258 string base_url_for_data_url; | 282 string base_url_for_data_url; |
259 if (!iterator->ReadString(&base_url_for_data_url)) | 283 if (!iterator->ReadString(&base_url_for_data_url)) |
260 return false; | 284 return false; |
261 entry->SetBaseURLForDataURL(GURL(base_url_for_data_url)); | 285 entry->SetBaseURLForDataURL(GURL(base_url_for_data_url)); |
262 } | 286 } |
263 | 287 |
264 { | 288 { |
265 bool is_overriding_user_agent; | 289 bool is_overriding_user_agent; |
266 if (!iterator->ReadBool(&is_overriding_user_agent)) | 290 if (!iterator->ReadBool(&is_overriding_user_agent)) |
267 return false; | 291 return false; |
(...skipping 13 matching lines...) Expand all Loading... | |
281 return false; | 305 return false; |
282 entry->SetHttpStatusCode(http_status_code); | 306 entry->SetHttpStatusCode(http_status_code); |
283 } | 307 } |
284 | 308 |
285 return true; | 309 return true; |
286 } | 310 } |
287 | 311 |
288 } // namespace internal | 312 } // namespace internal |
289 | 313 |
290 } // namespace android_webview | 314 } // namespace android_webview |
OLD | NEW |