Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1019)

Side by Side Diff: webkit/glue/glue_serialize.cc

Issue 2811007: Add support for serializing WebHistoryItem::itemSequenceNumber.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 // 1: Initial revision. 48 // 1: Initial revision.
49 // 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
50 // data, but not vice versa. 50 // data, but not vice versa.
51 // 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.
52 // This version checks and reads v1 and v2 correctly. 52 // This version checks and reads v1 and v2 correctly.
53 // 4: Adds support for storing FormData::identifier(). 53 // 4: Adds support for storing FormData::identifier().
54 // 5: Adds support for empty FormData 54 // 5: Adds support for empty FormData
55 // 6: Adds support for documentSequenceNumbers 55 // 6: Adds support for documentSequenceNumbers
56 // 7: Adds support for stateObject 56 // 7: Adds support for stateObject
57 // 8: Adds support for file range and modification time 57 // 8: Adds support for file range and modification time
58 // 9: Adds support for itemSequenceNumbers
58 // Should be const, but unit tests may modify it. 59 // Should be const, but unit tests may modify it.
59 // 60 //
60 // NOTE: If the version is -1, then the pickle contains only a URL string. 61 // NOTE: If the version is -1, then the pickle contains only a URL string.
61 // See CreateHistoryStateForURL. 62 // See CreateHistoryStateForURL.
62 // 63 //
64 #if defined(WEBKIT_BUG_40451_IS_FIXED)
65 int kVersion = 9;
66 #else
63 int kVersion = 8; 67 int kVersion = 8;
68 #endif
64 69
65 // A bunch of convenience functions to read/write to SerializeObjects. 70 // A bunch of convenience functions to read/write to SerializeObjects.
66 // The serializers assume the input data is in the correct format and so does 71 // The serializers assume the input data is in the correct format and so does
67 // no error checking. 72 // no error checking.
68 inline void WriteData(const void* data, int length, SerializeObject* obj) { 73 inline void WriteData(const void* data, int length, SerializeObject* obj) {
69 obj->pickle.WriteData(static_cast<const char*>(data), length); 74 obj->pickle.WriteData(static_cast<const char*>(data), length);
70 } 75 }
71 76
72 inline void ReadData(const SerializeObject* obj, const void** data, 77 inline void ReadData(const SerializeObject* obj, const void** data,
73 int* length) { 78 int* length) {
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 if (length == -1) 193 if (length == -1)
189 return WebString(); 194 return WebString();
190 195
191 // In version 2, the length field was the length in WebUChars. 196 // In version 2, the length field was the length in WebUChars.
192 // In version 1 and 3 it is the length in bytes. 197 // In version 1 and 3 it is the length in bytes.
193 int bytes = ((obj->version == 2) ? length * sizeof(WebUChar) : length); 198 int bytes = ((obj->version == 2) ? length * sizeof(WebUChar) : length);
194 199
195 const void* data; 200 const void* data;
196 if (!ReadBytes(obj, &data, bytes)) 201 if (!ReadBytes(obj, &data, bytes))
197 return WebString(); 202 return WebString();
198 return WebString(static_cast<const WebUChar*>(data), bytes / sizeof(WebUChar)) ; 203 return WebString(static_cast<const WebUChar*>(data),
204 bytes / sizeof(WebUChar));
199 } 205 }
200 206
201 // Writes a Vector of Strings into a SerializeObject for serialization. 207 // Writes a Vector of Strings into a SerializeObject for serialization.
202 static void WriteStringVector( 208 static void WriteStringVector(
203 const WebVector<WebString>& data, SerializeObject* obj) { 209 const WebVector<WebString>& data, SerializeObject* obj) {
204 WriteInteger(static_cast<int>(data.size()), obj); 210 WriteInteger(static_cast<int>(data.size()), obj);
205 for (size_t i = 0, c = data.size(); i < c; ++i) { 211 for (size_t i = 0, c = data.size(); i < c; ++i) {
206 unsigned ui = static_cast<unsigned>(i); // sigh 212 unsigned ui = static_cast<unsigned>(i); // sigh
207 WriteString(data[ui], obj); 213 WriteString(data[ui], obj);
208 } 214 }
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 WriteString(item.alternateTitle(), obj); 304 WriteString(item.alternateTitle(), obj);
299 WriteReal(item.lastVisitedTime(), obj); 305 WriteReal(item.lastVisitedTime(), obj);
300 WriteInteger(item.scrollOffset().x, obj); 306 WriteInteger(item.scrollOffset().x, obj);
301 WriteInteger(item.scrollOffset().y, obj); 307 WriteInteger(item.scrollOffset().y, obj);
302 WriteBoolean(item.isTargetItem(), obj); 308 WriteBoolean(item.isTargetItem(), obj);
303 WriteInteger(item.visitCount(), obj); 309 WriteInteger(item.visitCount(), obj);
304 WriteString(item.referrer(), obj); 310 WriteString(item.referrer(), obj);
305 311
306 WriteStringVector(item.documentState(), obj); 312 WriteStringVector(item.documentState(), obj);
307 313
314 #if defined(WEBKIT_BUG_40451_IS_FIXED)
315 if (kVersion >= 9)
316 WriteInteger64(item.itemSequenceNumber(), obj);
317 #endif
308 if (kVersion >= 6) 318 if (kVersion >= 6)
309 WriteInteger64(item.documentSequenceNumber(), obj); 319 WriteInteger64(item.documentSequenceNumber(), obj);
310 if (kVersion >= 7) { 320 if (kVersion >= 7) {
311 bool has_state_object = !item.stateObject().isNull(); 321 bool has_state_object = !item.stateObject().isNull();
312 WriteBoolean(has_state_object, obj); 322 WriteBoolean(has_state_object, obj);
313 if (has_state_object) 323 if (has_state_object)
314 WriteString(item.stateObject().toString(), obj); 324 WriteString(item.stateObject().toString(), obj);
315 } 325 }
316 326
317 // Yes, the referrer is written twice. This is for backwards 327 // Yes, the referrer is written twice. This is for backwards
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 item.setLastVisitedTime(ReadReal(obj)); 367 item.setLastVisitedTime(ReadReal(obj));
358 int x = ReadInteger(obj); 368 int x = ReadInteger(obj);
359 int y = ReadInteger(obj); 369 int y = ReadInteger(obj);
360 item.setScrollOffset(WebPoint(x, y)); 370 item.setScrollOffset(WebPoint(x, y));
361 item.setIsTargetItem(ReadBoolean(obj)); 371 item.setIsTargetItem(ReadBoolean(obj));
362 item.setVisitCount(ReadInteger(obj)); 372 item.setVisitCount(ReadInteger(obj));
363 item.setReferrer(ReadString(obj)); 373 item.setReferrer(ReadString(obj));
364 374
365 item.setDocumentState(ReadStringVector(obj)); 375 item.setDocumentState(ReadStringVector(obj));
366 376
377 #if defined(WEBKIT_BUG_40451_IS_FIXED)
378 if (obj->version >= 9)
379 item.setItemSequenceNumber(ReadInteger64(obj));
380 #endif
367 if (obj->version >= 6) 381 if (obj->version >= 6)
368 item.setDocumentSequenceNumber(ReadInteger64(obj)); 382 item.setDocumentSequenceNumber(ReadInteger64(obj));
369 if (obj->version >= 7) { 383 if (obj->version >= 7) {
370 bool has_state_object = ReadBoolean(obj); 384 bool has_state_object = ReadBoolean(obj);
371 if (has_state_object) { 385 if (has_state_object) {
372 item.setStateObject( 386 item.setStateObject(
373 WebSerializedScriptValue::fromString(ReadString(obj))); 387 WebSerializedScriptValue::fromString(ReadString(obj)));
374 } 388 }
375 } 389 }
376 390
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 const WebHistoryItem& item = HistoryItemFromString(content_state, false); 472 const WebHistoryItem& item = HistoryItemFromString(content_state, false);
459 if (item.isNull()) { 473 if (item.isNull()) {
460 // Couldn't parse the string, return an empty string. 474 // Couldn't parse the string, return an empty string.
461 return std::string(); 475 return std::string();
462 } 476 }
463 477
464 return HistoryItemToString(item); 478 return HistoryItemToString(item);
465 } 479 }
466 480
467 } // namespace webkit_glue 481 } // namespace webkit_glue
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698