OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "webkit/glue/glue_serialize.h" | 5 #include "webkit/glue/glue_serialize.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/pickle.h" | 9 #include "base/pickle.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
11 #include "googleurl/src/gurl.h" | 11 #include "googleurl/src/gurl.h" |
12 #include "third_party/WebKit/WebKit/chromium/public/WebData.h" | 12 #include "third_party/WebKit/WebKit/chromium/public/WebData.h" |
13 #include "third_party/WebKit/WebKit/chromium/public/WebHistoryItem.h" | 13 #include "third_party/WebKit/WebKit/chromium/public/WebHistoryItem.h" |
14 #include "third_party/WebKit/WebKit/chromium/public/WebHTTPBody.h" | 14 #include "third_party/WebKit/WebKit/chromium/public/WebHTTPBody.h" |
15 #include "third_party/WebKit/WebKit/chromium/public/WebPoint.h" | 15 #include "third_party/WebKit/WebKit/chromium/public/WebPoint.h" |
16 #include "third_party/WebKit/WebKit/chromium/public/WebSerializedScriptValue.h" | 16 #include "third_party/WebKit/WebKit/chromium/public/WebSerializedScriptValue.h" |
17 #include "third_party/WebKit/WebKit/chromium/public/WebString.h" | 17 #include "third_party/WebKit/WebKit/chromium/public/WebString.h" |
18 #include "third_party/WebKit/WebKit/chromium/public/WebVector.h" | 18 #include "third_party/WebKit/WebKit/chromium/public/WebVector.h" |
19 #include "webkit/glue/webkit_glue.h" | 19 #include "webkit/glue/webkit_glue.h" |
20 | 20 |
21 using WebKit::WebData; | 21 using WebKit::WebData; |
| 22 using WebKit::WebFileInfo; |
22 using WebKit::WebHistoryItem; | 23 using WebKit::WebHistoryItem; |
23 using WebKit::WebHTTPBody; | 24 using WebKit::WebHTTPBody; |
24 using WebKit::WebPoint; | 25 using WebKit::WebPoint; |
25 using WebKit::WebSerializedScriptValue; | 26 using WebKit::WebSerializedScriptValue; |
26 using WebKit::WebString; | 27 using WebKit::WebString; |
27 using WebKit::WebUChar; | 28 using WebKit::WebUChar; |
28 using WebKit::WebVector; | 29 using WebKit::WebVector; |
29 | 30 |
30 namespace webkit_glue { | 31 namespace webkit_glue { |
31 | 32 |
(...skipping 14 matching lines...) Expand all Loading... |
46 // Version ID used in reading/writing history items. | 47 // Version ID used in reading/writing history items. |
47 // 1: Initial revision. | 48 // 1: Initial revision. |
48 // 2: Added case for NULL string versus "". Version 2 code can read Version 1 | 49 // 2: Added case for NULL string versus "". Version 2 code can read Version 1 |
49 // data, but not vice versa. | 50 // data, but not vice versa. |
50 // 3: Version 2 was broken, it stored number of WebUChars, not number of bytes. | 51 // 3: Version 2 was broken, it stored number of WebUChars, not number of bytes. |
51 // This version checks and reads v1 and v2 correctly. | 52 // This version checks and reads v1 and v2 correctly. |
52 // 4: Adds support for storing FormData::identifier(). | 53 // 4: Adds support for storing FormData::identifier(). |
53 // 5: Adds support for empty FormData | 54 // 5: Adds support for empty FormData |
54 // 6: Adds support for documentSequenceNumbers | 55 // 6: Adds support for documentSequenceNumbers |
55 // 7: Adds support for stateObject | 56 // 7: Adds support for stateObject |
| 57 // 8: Adds support for file range and modification time |
56 // Should be const, but unit tests may modify it. | 58 // Should be const, but unit tests may modify it. |
57 // | 59 // |
58 // NOTE: If the version is -1, then the pickle contains only a URL string. | 60 // NOTE: If the version is -1, then the pickle contains only a URL string. |
59 // See CreateHistoryStateForURL. | 61 // See CreateHistoryStateForURL. |
60 // | 62 // |
61 int kVersion = 7; | 63 int kVersion = 8; |
62 | 64 |
63 // A bunch of convenience functions to read/write to SerializeObjects. | 65 // A bunch of convenience functions to read/write to SerializeObjects. |
64 // The serializers assume the input data is in the correct format and so does | 66 // The serializers assume the input data is in the correct format and so does |
65 // no error checking. | 67 // no error checking. |
66 inline void WriteData(const void* data, int length, SerializeObject* obj) { | 68 inline void WriteData(const void* data, int length, SerializeObject* obj) { |
67 obj->pickle.WriteData(static_cast<const char*>(data), length); | 69 obj->pickle.WriteData(static_cast<const char*>(data), length); |
68 } | 70 } |
69 | 71 |
70 inline void ReadData(const SerializeObject* obj, const void** data, | 72 inline void ReadData(const SerializeObject* obj, const void** data, |
71 int* length) { | 73 int* length) { |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 | 225 |
224 WriteInteger(static_cast<int>(http_body.elementCount()), obj); | 226 WriteInteger(static_cast<int>(http_body.elementCount()), obj); |
225 WebHTTPBody::Element element; | 227 WebHTTPBody::Element element; |
226 for (size_t i = 0; http_body.elementAt(i, element); ++i) { | 228 for (size_t i = 0; http_body.elementAt(i, element); ++i) { |
227 WriteInteger(element.type, obj); | 229 WriteInteger(element.type, obj); |
228 if (element.type == WebHTTPBody::Element::TypeData) { | 230 if (element.type == WebHTTPBody::Element::TypeData) { |
229 WriteData(element.data.data(), static_cast<int>(element.data.size()), | 231 WriteData(element.data.data(), static_cast<int>(element.data.size()), |
230 obj); | 232 obj); |
231 } else { | 233 } else { |
232 WriteString(element.filePath, obj); | 234 WriteString(element.filePath, obj); |
| 235 WriteInteger64(element.fileStart, obj); |
| 236 WriteInteger64(element.fileLength, obj); |
| 237 WriteReal(element.fileInfo.modificationTime, obj); |
233 } | 238 } |
234 } | 239 } |
235 WriteInteger64(http_body.identifier(), obj); | 240 WriteInteger64(http_body.identifier(), obj); |
236 } | 241 } |
237 | 242 |
238 static WebHTTPBody ReadFormData(const SerializeObject* obj) { | 243 static WebHTTPBody ReadFormData(const SerializeObject* obj) { |
239 // In newer versions, an initial boolean indicates if we have form data. | 244 // In newer versions, an initial boolean indicates if we have form data. |
240 if (obj->version >= 5 && !ReadBoolean(obj)) | 245 if (obj->version >= 5 && !ReadBoolean(obj)) |
241 return WebHTTPBody(); | 246 return WebHTTPBody(); |
242 | 247 |
243 // In older versions, 0 elements implied no form data. | 248 // In older versions, 0 elements implied no form data. |
244 int num_elements = ReadInteger(obj); | 249 int num_elements = ReadInteger(obj); |
245 if (num_elements == 0 && obj->version < 5) | 250 if (num_elements == 0 && obj->version < 5) |
246 return WebHTTPBody(); | 251 return WebHTTPBody(); |
247 | 252 |
248 WebHTTPBody http_body; | 253 WebHTTPBody http_body; |
249 http_body.initialize(); | 254 http_body.initialize(); |
250 | 255 |
251 for (int i = 0; i < num_elements; ++i) { | 256 for (int i = 0; i < num_elements; ++i) { |
252 int type = ReadInteger(obj); | 257 int type = ReadInteger(obj); |
253 if (type == WebHTTPBody::Element::TypeData) { | 258 if (type == WebHTTPBody::Element::TypeData) { |
254 const void* data; | 259 const void* data; |
255 int length = -1; | 260 int length = -1; |
256 ReadData(obj, &data, &length); | 261 ReadData(obj, &data, &length); |
257 if (length >= 0) | 262 if (length >= 0) |
258 http_body.appendData(WebData(static_cast<const char*>(data), length)); | 263 http_body.appendData(WebData(static_cast<const char*>(data), length)); |
259 } else { | 264 } else { |
260 http_body.appendFile(ReadString(obj)); | 265 WebString file_path = ReadString(obj); |
| 266 long long file_start = 0; |
| 267 long long file_length = -1; |
| 268 WebFileInfo file_info; |
| 269 if (obj->version >= 8) { |
| 270 file_start = ReadInteger64(obj); |
| 271 file_length = ReadInteger64(obj); |
| 272 file_info.modificationTime = ReadReal(obj); |
| 273 } |
| 274 http_body.appendFileRange(file_path, file_start, file_length, file_info); |
261 } | 275 } |
262 } | 276 } |
263 if (obj->version >= 4) | 277 if (obj->version >= 4) |
264 http_body.setIdentifier(ReadInteger64(obj)); | 278 http_body.setIdentifier(ReadInteger64(obj)); |
265 | 279 |
266 return http_body; | 280 return http_body; |
267 } | 281 } |
268 | 282 |
269 // Writes the HistoryItem data into the SerializeObject object for | 283 // Writes the HistoryItem data into the SerializeObject object for |
270 // serialization. | 284 // serialization. |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
444 const WebHistoryItem& item = HistoryItemFromString(content_state, false); | 458 const WebHistoryItem& item = HistoryItemFromString(content_state, false); |
445 if (item.isNull()) { | 459 if (item.isNull()) { |
446 // Couldn't parse the string, return an empty string. | 460 // Couldn't parse the string, return an empty string. |
447 return std::string(); | 461 return std::string(); |
448 } | 462 } |
449 | 463 |
450 return HistoryItemToString(item); | 464 return HistoryItemToString(item); |
451 } | 465 } |
452 | 466 |
453 } // namespace webkit_glue | 467 } // namespace webkit_glue |
OLD | NEW |