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/WebString.h" | 17 #include "third_party/WebKit/WebKit/chromium/public/WebString.h" |
17 #include "third_party/WebKit/WebKit/chromium/public/WebVector.h" | 18 #include "third_party/WebKit/WebKit/chromium/public/WebVector.h" |
18 #include "webkit/glue/webkit_glue.h" | 19 #include "webkit/glue/webkit_glue.h" |
19 | 20 |
20 using WebKit::WebData; | 21 using WebKit::WebData; |
21 using WebKit::WebHistoryItem; | 22 using WebKit::WebHistoryItem; |
22 using WebKit::WebHTTPBody; | 23 using WebKit::WebHTTPBody; |
23 using WebKit::WebPoint; | 24 using WebKit::WebPoint; |
| 25 using WebKit::WebSerializedScriptValue; |
24 using WebKit::WebString; | 26 using WebKit::WebString; |
25 using WebKit::WebUChar; | 27 using WebKit::WebUChar; |
26 using WebKit::WebVector; | 28 using WebKit::WebVector; |
27 | 29 |
28 namespace webkit_glue { | 30 namespace webkit_glue { |
29 | 31 |
30 struct SerializeObject { | 32 struct SerializeObject { |
31 SerializeObject() : iter(NULL) {} | 33 SerializeObject() : iter(NULL) {} |
32 SerializeObject(const char* data, int len) : pickle(data, len), iter(NULL) {} | 34 SerializeObject(const char* data, int len) : pickle(data, len), iter(NULL) {} |
33 | 35 |
34 std::string GetAsString() { | 36 std::string GetAsString() { |
35 return std::string(static_cast<const char*>(pickle.data()), pickle.size()); | 37 return std::string(static_cast<const char*>(pickle.data()), pickle.size()); |
36 } | 38 } |
37 | 39 |
38 Pickle pickle; | 40 Pickle pickle; |
39 mutable void* iter; | 41 mutable void* iter; |
40 mutable int version; | 42 mutable int version; |
41 }; | 43 }; |
42 | 44 |
43 // TODO(mpcomplete): obsolete versions 1 and 2 after 1/1/2008. | 45 // TODO(mpcomplete): obsolete versions 1 and 2 after 1/1/2008. |
44 // Version ID used in reading/writing history items. | 46 // Version ID used in reading/writing history items. |
45 // 1: Initial revision. | 47 // 1: Initial revision. |
46 // 2: Added case for NULL string versus "". Version 2 code can read Version 1 | 48 // 2: Added case for NULL string versus "". Version 2 code can read Version 1 |
47 // data, but not vice versa. | 49 // data, but not vice versa. |
48 // 3: Version 2 was broken, it stored number of WebUChars, not number of bytes. | 50 // 3: Version 2 was broken, it stored number of WebUChars, not number of bytes. |
49 // This version checks and reads v1 and v2 correctly. | 51 // This version checks and reads v1 and v2 correctly. |
50 // 4: Adds support for storing FormData::identifier(). | 52 // 4: Adds support for storing FormData::identifier(). |
51 // 5: Adds support for empty FormData | 53 // 5: Adds support for empty FormData |
52 // 6: Adds support for documentSequenceNumbers | 54 // 6: Adds support for documentSequenceNumbers |
| 55 // 7: Adds support for stateObject |
53 // Should be const, but unit tests may modify it. | 56 // Should be const, but unit tests may modify it. |
54 // | 57 // |
55 // NOTE: If the version is -1, then the pickle contains only a URL string. | 58 // NOTE: If the version is -1, then the pickle contains only a URL string. |
56 // See CreateHistoryStateForURL. | 59 // See CreateHistoryStateForURL. |
57 // | 60 // |
58 int kVersion = 6; | 61 int kVersion = 7; |
59 | 62 |
60 // A bunch of convenience functions to read/write to SerializeObjects. | 63 // A bunch of convenience functions to read/write to SerializeObjects. |
61 // The serializers assume the input data is in the correct format and so does | 64 // The serializers assume the input data is in the correct format and so does |
62 // no error checking. | 65 // no error checking. |
63 inline void WriteData(const void* data, int length, SerializeObject* obj) { | 66 inline void WriteData(const void* data, int length, SerializeObject* obj) { |
64 obj->pickle.WriteData(static_cast<const char*>(data), length); | 67 obj->pickle.WriteData(static_cast<const char*>(data), length); |
65 } | 68 } |
66 | 69 |
67 inline void ReadData(const SerializeObject* obj, const void** data, | 70 inline void ReadData(const SerializeObject* obj, const void** data, |
68 int* length) { | 71 int* length) { |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 WriteInteger(item.scrollOffset().x, obj); | 286 WriteInteger(item.scrollOffset().x, obj); |
284 WriteInteger(item.scrollOffset().y, obj); | 287 WriteInteger(item.scrollOffset().y, obj); |
285 WriteBoolean(item.isTargetItem(), obj); | 288 WriteBoolean(item.isTargetItem(), obj); |
286 WriteInteger(item.visitCount(), obj); | 289 WriteInteger(item.visitCount(), obj); |
287 WriteString(item.referrer(), obj); | 290 WriteString(item.referrer(), obj); |
288 | 291 |
289 WriteStringVector(item.documentState(), obj); | 292 WriteStringVector(item.documentState(), obj); |
290 | 293 |
291 if (kVersion >= 6) | 294 if (kVersion >= 6) |
292 WriteInteger64(item.documentSequenceNumber(), obj); | 295 WriteInteger64(item.documentSequenceNumber(), obj); |
| 296 if (kVersion >= 7) { |
| 297 bool has_state_object = !item.stateObject().isNull(); |
| 298 WriteBoolean(has_state_object, obj); |
| 299 if (has_state_object) |
| 300 WriteString(item.stateObject().toString(), obj); |
| 301 } |
293 | 302 |
294 // Yes, the referrer is written twice. This is for backwards | 303 // Yes, the referrer is written twice. This is for backwards |
295 // compatibility with the format. | 304 // compatibility with the format. |
296 WriteFormData(item.httpBody(), obj); | 305 WriteFormData(item.httpBody(), obj); |
297 WriteString(item.httpContentType(), obj); | 306 WriteString(item.httpContentType(), obj); |
298 WriteString(item.referrer(), obj); | 307 WriteString(item.referrer(), obj); |
299 | 308 |
300 // Subitems | 309 // Subitems |
301 const WebVector<WebHistoryItem>& children = item.children(); | 310 const WebVector<WebHistoryItem>& children = item.children(); |
302 WriteInteger(static_cast<int>(children.size()), obj); | 311 WriteInteger(static_cast<int>(children.size()), obj); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 int y = ReadInteger(obj); | 345 int y = ReadInteger(obj); |
337 item.setScrollOffset(WebPoint(x, y)); | 346 item.setScrollOffset(WebPoint(x, y)); |
338 item.setIsTargetItem(ReadBoolean(obj)); | 347 item.setIsTargetItem(ReadBoolean(obj)); |
339 item.setVisitCount(ReadInteger(obj)); | 348 item.setVisitCount(ReadInteger(obj)); |
340 item.setReferrer(ReadString(obj)); | 349 item.setReferrer(ReadString(obj)); |
341 | 350 |
342 item.setDocumentState(ReadStringVector(obj)); | 351 item.setDocumentState(ReadStringVector(obj)); |
343 | 352 |
344 if (obj->version >= 6) | 353 if (obj->version >= 6) |
345 item.setDocumentSequenceNumber(ReadInteger64(obj)); | 354 item.setDocumentSequenceNumber(ReadInteger64(obj)); |
| 355 if (obj->version >= 7) { |
| 356 bool has_state_object = ReadBoolean(obj); |
| 357 if (has_state_object) { |
| 358 item.setStateObject( |
| 359 WebSerializedScriptValue::fromString(ReadString(obj))); |
| 360 } |
| 361 } |
346 | 362 |
347 // The extra referrer string is read for backwards compat. | 363 // The extra referrer string is read for backwards compat. |
348 const WebHTTPBody& http_body = ReadFormData(obj); | 364 const WebHTTPBody& http_body = ReadFormData(obj); |
349 const WebString& http_content_type = ReadString(obj); | 365 const WebString& http_content_type = ReadString(obj); |
350 ALLOW_UNUSED const WebString& unused_referrer = ReadString(obj); | 366 ALLOW_UNUSED const WebString& unused_referrer = ReadString(obj); |
351 if (include_form_data) { | 367 if (include_form_data) { |
352 item.setHTTPBody(http_body); | 368 item.setHTTPBody(http_body); |
353 item.setHTTPContentType(http_content_type); | 369 item.setHTTPContentType(http_content_type); |
354 } | 370 } |
355 | 371 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
428 const WebHistoryItem& item = HistoryItemFromString(content_state, false); | 444 const WebHistoryItem& item = HistoryItemFromString(content_state, false); |
429 if (item.isNull()) { | 445 if (item.isNull()) { |
430 // Couldn't parse the string, return an empty string. | 446 // Couldn't parse the string, return an empty string. |
431 return std::string(); | 447 return std::string(); |
432 } | 448 } |
433 | 449 |
434 return HistoryItemToString(item); | 450 return HistoryItemToString(item); |
435 } | 451 } |
436 | 452 |
437 } // namespace webkit_glue | 453 } // namespace webkit_glue |
OLD | NEW |