| 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/pickle.h" | 9 #include "base/pickle.h" |
| 10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 | 27 |
| 28 using std::string; | 28 using std::string; |
| 29 | 29 |
| 30 namespace android_webview { | 30 namespace android_webview { |
| 31 | 31 |
| 32 namespace { | 32 namespace { |
| 33 | 33 |
| 34 // Sanity check value that we are restoring from a valid pickle. | 34 // Sanity check value that we are restoring from a valid pickle. |
| 35 // This can potentially used as an actual serialization version number in the | 35 // This can potentially used as an actual serialization version number in the |
| 36 // future if we ever decide to support restoring from older versions. | 36 // future if we ever decide to support restoring from older versions. |
| 37 const uint32 AW_STATE_VERSION = 20130814; | 37 const uint32 AW_STATE_VERSION = 20151204; |
| 38 | 38 |
| 39 } // namespace | 39 } // namespace |
| 40 | 40 |
| 41 bool WriteToPickle(const content::WebContents& web_contents, | 41 bool WriteToPickle(const content::WebContents& web_contents, |
| 42 base::Pickle* pickle) { | 42 base::Pickle* pickle) { |
| 43 DCHECK(pickle); | 43 DCHECK(pickle); |
| 44 | 44 |
| 45 if (!internal::WriteHeaderToPickle(pickle)) | 45 if (!internal::WriteHeaderToPickle(pickle)) |
| 46 return false; | 46 return false; |
| 47 | 47 |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 | 172 |
| 173 if (!pickle->WriteBool(static_cast<int>(entry.GetHasPostData()))) | 173 if (!pickle->WriteBool(static_cast<int>(entry.GetHasPostData()))) |
| 174 return false; | 174 return false; |
| 175 | 175 |
| 176 if (!pickle->WriteString(entry.GetOriginalRequestURL().spec())) | 176 if (!pickle->WriteString(entry.GetOriginalRequestURL().spec())) |
| 177 return false; | 177 return false; |
| 178 | 178 |
| 179 if (!pickle->WriteString(entry.GetBaseURLForDataURL().spec())) | 179 if (!pickle->WriteString(entry.GetBaseURLForDataURL().spec())) |
| 180 return false; | 180 return false; |
| 181 | 181 |
| 182 { |
| 183 const char* data = nullptr; |
| 184 size_t size = 0; |
| 185 scoped_refptr<const base::RefCountedString> s = entry.GetDataURLAsString(); |
| 186 if (s) { |
| 187 data = s->front_as<char>(); |
| 188 size = s->size(); |
| 189 } |
| 190 // Even when |entry.GetDataForDataURL()| is null we still need to write a |
| 191 // zero-length entry to ensure the fields all line up when read back in. |
| 192 if (!pickle->WriteData(data, size)) |
| 193 return false; |
| 194 } |
| 195 |
| 182 if (!pickle->WriteBool(static_cast<int>(entry.GetIsOverridingUserAgent()))) | 196 if (!pickle->WriteBool(static_cast<int>(entry.GetIsOverridingUserAgent()))) |
| 183 return false; | 197 return false; |
| 184 | 198 |
| 185 if (!pickle->WriteInt64(entry.GetTimestamp().ToInternalValue())) | 199 if (!pickle->WriteInt64(entry.GetTimestamp().ToInternalValue())) |
| 186 return false; | 200 return false; |
| 187 | 201 |
| 188 if (!pickle->WriteInt(entry.GetHttpStatusCode())) | 202 if (!pickle->WriteInt(entry.GetHttpStatusCode())) |
| 189 return false; | 203 return false; |
| 190 | 204 |
| 191 // Please update AW_STATE_VERSION if serialization format is changed. | 205 // Please update AW_STATE_VERSION if serialization format is changed. |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 } | 268 } |
| 255 | 269 |
| 256 { | 270 { |
| 257 string base_url_for_data_url; | 271 string base_url_for_data_url; |
| 258 if (!iterator->ReadString(&base_url_for_data_url)) | 272 if (!iterator->ReadString(&base_url_for_data_url)) |
| 259 return false; | 273 return false; |
| 260 entry->SetBaseURLForDataURL(GURL(base_url_for_data_url)); | 274 entry->SetBaseURLForDataURL(GURL(base_url_for_data_url)); |
| 261 } | 275 } |
| 262 | 276 |
| 263 { | 277 { |
| 278 const char* data; |
| 279 int size; |
| 280 if (!iterator->ReadData(&data, &size)) |
| 281 return false; |
| 282 if (size > 0) { |
| 283 scoped_refptr<base::RefCountedString> ref = new base::RefCountedString(); |
| 284 ref->data().assign(data, size); |
| 285 entry->SetDataURLAsString(ref); |
| 286 } |
| 287 } |
| 288 |
| 289 { |
| 264 bool is_overriding_user_agent; | 290 bool is_overriding_user_agent; |
| 265 if (!iterator->ReadBool(&is_overriding_user_agent)) | 291 if (!iterator->ReadBool(&is_overriding_user_agent)) |
| 266 return false; | 292 return false; |
| 267 entry->SetIsOverridingUserAgent(is_overriding_user_agent); | 293 entry->SetIsOverridingUserAgent(is_overriding_user_agent); |
| 268 } | 294 } |
| 269 | 295 |
| 270 { | 296 { |
| 271 int64 timestamp; | 297 int64 timestamp; |
| 272 if (!iterator->ReadInt64(×tamp)) | 298 if (!iterator->ReadInt64(×tamp)) |
| 273 return false; | 299 return false; |
| 274 entry->SetTimestamp(base::Time::FromInternalValue(timestamp)); | 300 entry->SetTimestamp(base::Time::FromInternalValue(timestamp)); |
| 275 } | 301 } |
| 276 | 302 |
| 277 { | 303 { |
| 278 int http_status_code; | 304 int http_status_code; |
| 279 if (!iterator->ReadInt(&http_status_code)) | 305 if (!iterator->ReadInt(&http_status_code)) |
| 280 return false; | 306 return false; |
| 281 entry->SetHttpStatusCode(http_status_code); | 307 entry->SetHttpStatusCode(http_status_code); |
| 282 } | 308 } |
| 283 | 309 |
| 284 return true; | 310 return true; |
| 285 } | 311 } |
| 286 | 312 |
| 287 } // namespace internal | 313 } // namespace internal |
| 288 | 314 |
| 289 } // namespace android_webview | 315 } // namespace android_webview |
| OLD | NEW |