| 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> d = entry.GetDataForDataURL(); |
| 184 if (d.get()) { |
| 185 data = reinterpret_cast<const char*>(d->front()); |
| 186 size = d->size(); |
| 187 } |
| 188 // Even when |entry.GetDataForDataURL()| is NULL we still need to write a |
| 189 // zero-length entry to ensure the fields all line up when read back in. |
| 190 if (!pickle->WriteData(data, size)) |
| 191 return false; |
| 192 } |
| 193 |
| 180 if (!pickle->WriteString(entry.GetBaseURLForDataURL().spec())) | 194 if (!pickle->WriteString(entry.GetBaseURLForDataURL().spec())) |
| 181 return false; | 195 return false; |
| 182 | 196 |
| 183 if (!pickle->WriteBool(static_cast<int>(entry.GetIsOverridingUserAgent()))) | 197 if (!pickle->WriteBool(static_cast<int>(entry.GetIsOverridingUserAgent()))) |
| 184 return false; | 198 return false; |
| 185 | 199 |
| 186 if (!pickle->WriteInt64(entry.GetTimestamp().ToInternalValue())) | 200 if (!pickle->WriteInt64(entry.GetTimestamp().ToInternalValue())) |
| 187 return false; | 201 return false; |
| 188 | 202 |
| 189 if (!pickle->WriteInt(entry.GetHttpStatusCode())) | 203 if (!pickle->WriteInt(entry.GetHttpStatusCode())) |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 } | 262 } |
| 249 | 263 |
| 250 { | 264 { |
| 251 string original_request_url; | 265 string original_request_url; |
| 252 if (!iterator->ReadString(&original_request_url)) | 266 if (!iterator->ReadString(&original_request_url)) |
| 253 return false; | 267 return false; |
| 254 entry->SetOriginalRequestURL(GURL(original_request_url)); | 268 entry->SetOriginalRequestURL(GURL(original_request_url)); |
| 255 } | 269 } |
| 256 | 270 |
| 257 { | 271 { |
| 272 const char* data; |
| 273 int len; |
| 274 if (!iterator->ReadData(&data, &len)) |
| 275 return false; |
| 276 if (len > 0) { |
| 277 scoped_refptr<base::RefCountedString> ref = new base::RefCountedString; |
| 278 ref->data().assign(data, len); |
| 279 entry->SetDataForDataURL(ref.get()); |
| 280 } |
| 281 } |
| 282 |
| 283 { |
| 258 string base_url_for_data_url; | 284 string base_url_for_data_url; |
| 259 if (!iterator->ReadString(&base_url_for_data_url)) | 285 if (!iterator->ReadString(&base_url_for_data_url)) |
| 260 return false; | 286 return false; |
| 261 entry->SetBaseURLForDataURL(GURL(base_url_for_data_url)); | 287 entry->SetBaseURLForDataURL(GURL(base_url_for_data_url)); |
| 262 } | 288 } |
| 263 | 289 |
| 264 { | 290 { |
| 265 bool is_overriding_user_agent; | 291 bool is_overriding_user_agent; |
| 266 if (!iterator->ReadBool(&is_overriding_user_agent)) | 292 if (!iterator->ReadBool(&is_overriding_user_agent)) |
| 267 return false; | 293 return false; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 281 return false; | 307 return false; |
| 282 entry->SetHttpStatusCode(http_status_code); | 308 entry->SetHttpStatusCode(http_status_code); |
| 283 } | 309 } |
| 284 | 310 |
| 285 return true; | 311 return true; |
| 286 } | 312 } |
| 287 | 313 |
| 288 } // namespace internal | 314 } // namespace internal |
| 289 | 315 |
| 290 } // namespace android_webview | 316 } // namespace android_webview |
| OLD | NEW |