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" |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 // Versions 1, 2, and 3 all start with an integer. | 184 // Versions 1, 2, and 3 all start with an integer. |
185 if (!obj->pickle.ReadInt(&obj->iter, &length)) | 185 if (!obj->pickle.ReadInt(&obj->iter, &length)) |
186 return WebString(); | 186 return WebString(); |
187 | 187 |
188 // Starting with version 2, -1 means WebString(). | 188 // Starting with version 2, -1 means WebString(). |
189 if (length == -1) | 189 if (length == -1) |
190 return WebString(); | 190 return WebString(); |
191 | 191 |
192 // In version 2, the length field was the length in WebUChars. | 192 // In version 2, the length field was the length in WebUChars. |
193 // In version 1 and 3 it is the length in bytes. | 193 // In version 1 and 3 it is the length in bytes. |
194 int bytes = ((obj->version == 2) ? length * sizeof(WebUChar) : length); | 194 int bytes = length; |
| 195 if (obj->version == 2) |
| 196 bytes *= sizeof(WebUChar); |
195 | 197 |
196 const void* data; | 198 const void* data; |
197 if (!ReadBytes(obj, &data, bytes)) | 199 if (!ReadBytes(obj, &data, bytes)) |
198 return WebString(); | 200 return WebString(); |
199 return WebString(static_cast<const WebUChar*>(data), | 201 return WebString(static_cast<const WebUChar*>(data), |
200 bytes / sizeof(WebUChar)); | 202 bytes / sizeof(WebUChar)); |
201 } | 203 } |
202 | 204 |
203 // Writes a Vector of Strings into a SerializeObject for serialization. | 205 // Writes a Vector of Strings into a SerializeObject for serialization. |
204 static void WriteStringVector( | 206 static void WriteStringVector( |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
464 const WebHistoryItem& item = HistoryItemFromString(content_state, false); | 466 const WebHistoryItem& item = HistoryItemFromString(content_state, false); |
465 if (item.isNull()) { | 467 if (item.isNull()) { |
466 // Couldn't parse the string, return an empty string. | 468 // Couldn't parse the string, return an empty string. |
467 return std::string(); | 469 return std::string(); |
468 } | 470 } |
469 | 471 |
470 return HistoryItemToString(item); | 472 return HistoryItemToString(item); |
471 } | 473 } |
472 | 474 |
473 } // namespace webkit_glue | 475 } // namespace webkit_glue |
OLD | NEW |