summaryrefslogtreecommitdiffstats
path: root/webkit/glue
diff options
context:
space:
mode:
authordarin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-25 03:10:24 +0000
committerdarin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-25 03:10:24 +0000
commit1a852aba2fc7fcbad3ad29005c482b91631b4ef3 (patch)
tree52f169bda64c6bd996c43cf781aebe2521d03dff /webkit/glue
parent15f9fb8bc0e3f6baecf280d87b193fc36fe927e4 (diff)
downloadchromium_src-1a852aba2fc7fcbad3ad29005c482b91631b4ef3.zip
chromium_src-1a852aba2fc7fcbad3ad29005c482b91631b4ef3.tar.gz
chromium_src-1a852aba2fc7fcbad3ad29005c482b91631b4ef3.tar.bz2
Re-implement PageState serialization without a Blink API dependency.
WebHistoryItem serialization is now split into two parts. PageState (i.e., encoded string)to ExplodedPageState, and ExplodedPageState to WebHistoryItem. This way we can generate ExplodedPageState in the browser process without a dependency on Blink API. This CL drops support for version 1-10 of the format. I confirmed with laforge@ that the usage of such old versions of Chrome is minimal enough. I've included code to extract file paths from the "document state" vector of strings. This code just has to be consistent with the way document state was generated in versions 11 through 13 of the format. Version 14 has the file path vector included directly in the serialized data. Gone is the serializers ability to write out different versions of the format. That code existed to support testing as we would write out old versions and test our ability to read them. Instead, I've captured some serialized snapshots at different versions, and I just test that we can read them. I've included code for generating a snapshot as a test case that by default returns early. (This way the code doesn't bit-rot.) R=jamesr@chromium.org,tsepez@chromium.org BUG=237243 Review URL: https://chromiumcodereview.appspot.com/16867005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@208367 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/glue')
-rw-r--r--webkit/glue/glue_serialize_deprecated.cc670
-rw-r--r--webkit/glue/glue_serialize_deprecated.h57
-rw-r--r--webkit/glue/glue_serialize_unittest.cc328
-rw-r--r--webkit/glue/webkit_glue.gypi2
4 files changed, 0 insertions, 1057 deletions
diff --git a/webkit/glue/glue_serialize_deprecated.cc b/webkit/glue/glue_serialize_deprecated.cc
deleted file mode 100644
index 62d4c89..0000000
--- a/webkit/glue/glue_serialize_deprecated.cc
+++ /dev/null
@@ -1,670 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "webkit/glue/glue_serialize_deprecated.h"
-
-#include <string>
-
-#include "base/pickle.h"
-#include "base/strings/utf_string_conversions.h"
-#include "googleurl/src/gurl.h"
-#include "third_party/WebKit/public/platform/WebData.h"
-#include "third_party/WebKit/public/platform/WebHTTPBody.h"
-#include "third_party/WebKit/public/platform/WebPoint.h"
-#include "third_party/WebKit/public/platform/WebString.h"
-#include "third_party/WebKit/public/platform/WebURL.h"
-#include "third_party/WebKit/public/platform/WebVector.h"
-#include "third_party/WebKit/public/web/WebHistoryItem.h"
-#include "third_party/WebKit/public/web/WebSerializedScriptValue.h"
-#include "ui/gfx/screen.h"
-#include "webkit/base/file_path_string_conversions.h"
-
-using WebKit::WebData;
-using WebKit::WebHistoryItem;
-using WebKit::WebHTTPBody;
-using WebKit::WebPoint;
-using WebKit::WebSerializedScriptValue;
-using WebKit::WebString;
-using WebKit::WebUChar;
-using WebKit::WebVector;
-
-namespace webkit_glue {
-
-namespace {
-
-enum IncludeFormData {
- NEVER_INCLUDE_FORM_DATA,
- INCLUDE_FORM_DATA_WITHOUT_PASSWORDS,
- ALWAYS_INCLUDE_FORM_DATA
-};
-
-struct SerializeObject {
- SerializeObject() : version(0) {}
- SerializeObject(const char* data, int len)
- : pickle(data, len), version(0) { iter = PickleIterator(pickle); }
-
- std::string GetAsString() {
- return std::string(static_cast<const char*>(pickle.data()), pickle.size());
- }
-
- Pickle pickle;
- mutable PickleIterator iter;
- mutable int version;
-};
-
-// TODO(mpcomplete): obsolete versions 1 and 2 after 1/1/2008.
-// Version ID used in reading/writing history items.
-// 1: Initial revision.
-// 2: Added case for NULL string versus "". Version 2 code can read Version 1
-// data, but not vice versa.
-// 3: Version 2 was broken, it stored number of WebUChars, not number of bytes.
-// This version checks and reads v1 and v2 correctly.
-// 4: Adds support for storing FormData::identifier().
-// 5: Adds support for empty FormData
-// 6: Adds support for documentSequenceNumbers
-// 7: Adds support for stateObject
-// 8: Adds support for file range and modification time
-// 9: Adds support for itemSequenceNumbers
-// 10: Adds support for blob
-// 11: Adds support for pageScaleFactor
-// 12: Adds support for hasPasswordData in HTTP body
-// 13: Adds support for URL (FileSystem URL)
-// 14: Adds list of referenced files, version written only for first item.
-// Should be const, but unit tests may modify it.
-//
-// NOTE: If the version is -1, then the pickle contains only a URL string.
-// See CreateHistoryStateForURL.
-//
-int kVersion = 14;
-
-// A bunch of convenience functions to read/write to SerializeObjects.
-// The serializers assume the input data is in the correct format and so does
-// no error checking.
-void WriteData(const void* data, int length, SerializeObject* obj) {
- obj->pickle.WriteData(static_cast<const char*>(data), length);
-}
-
-void ReadData(const SerializeObject* obj, const void** data, int* length) {
- const char* tmp;
- if (obj->pickle.ReadData(&obj->iter, &tmp, length)) {
- *data = tmp;
- } else {
- *data = NULL;
- *length = 0;
- }
-}
-
-bool ReadBytes(const SerializeObject* obj, const void** data, int length) {
- const char *tmp;
- if (!obj->pickle.ReadBytes(&obj->iter, &tmp, length))
- return false;
- *data = tmp;
- return true;
-}
-
-void WriteInteger(int data, SerializeObject* obj) {
- obj->pickle.WriteInt(data);
-}
-
-int ReadInteger(const SerializeObject* obj) {
- int tmp;
- if (obj->pickle.ReadInt(&obj->iter, &tmp))
- return tmp;
- return 0;
-}
-
-void ConsumeInteger(const SerializeObject* obj) {
- int unused ALLOW_UNUSED = ReadInteger(obj);
-}
-
-void WriteInteger64(int64 data, SerializeObject* obj) {
- obj->pickle.WriteInt64(data);
-}
-
-int64 ReadInteger64(const SerializeObject* obj) {
- int64 tmp = 0;
- obj->pickle.ReadInt64(&obj->iter, &tmp);
- return tmp;
-}
-
-void WriteReal(double data, SerializeObject* obj) {
- WriteData(&data, sizeof(double), obj);
-}
-
-double ReadReal(const SerializeObject* obj) {
- const void* tmp = NULL;
- int length = 0;
- double value = 0.0;
- ReadData(obj, &tmp, &length);
- if (tmp && length >= static_cast<int>(sizeof(double))) {
- // Use memcpy, as tmp may not be correctly aligned.
- memcpy(&value, tmp, sizeof(double));
- }
- return value;
-}
-
-void WriteBoolean(bool data, SerializeObject* obj) {
- obj->pickle.WriteInt(data ? 1 : 0);
-}
-
-bool ReadBoolean(const SerializeObject* obj) {
- bool tmp;
- if (obj->pickle.ReadBool(&obj->iter, &tmp))
- return tmp;
- return false;
-}
-
-void WriteGURL(const GURL& url, SerializeObject* obj) {
- obj->pickle.WriteString(url.possibly_invalid_spec());
-}
-
-GURL ReadGURL(const SerializeObject* obj) {
- std::string spec;
- if (obj->pickle.ReadString(&obj->iter, &spec))
- return GURL(spec);
- return GURL();
-}
-
-// Read/WriteString pickle the WebString as <int length><WebUChar* data>.
-// If length == -1, then the WebString itself is NULL (WebString()).
-// Otherwise the length is the number of WebUChars (not bytes) in the WebString.
-void WriteString(const WebString& str, SerializeObject* obj) {
- base::string16 string = str;
- const char16* data = string.data();
- size_t length_in_uchars = string.length();
- size_t length_in_bytes = length_in_uchars * sizeof(char16);
- switch (kVersion) {
- case 1:
- // Version 1 writes <length in bytes><string data>.
- // It saves WebString() and "" as "".
- obj->pickle.WriteInt(length_in_bytes);
- obj->pickle.WriteBytes(data, length_in_bytes);
- break;
- case 2:
- // Version 2 writes <length in WebUChar><string data>.
- // It uses -1 in the length field to mean WebString().
- if (str.isNull()) {
- obj->pickle.WriteInt(-1);
- } else {
- obj->pickle.WriteInt(length_in_uchars);
- obj->pickle.WriteBytes(data, length_in_bytes);
- }
- break;
- default:
- // Version 3+ writes <length in bytes><string data>.
- // It uses -1 in the length field to mean WebString().
- if (str.isNull()) {
- obj->pickle.WriteInt(-1);
- } else {
- obj->pickle.WriteInt(length_in_bytes);
- obj->pickle.WriteBytes(data, length_in_bytes);
- }
- break;
- }
-}
-
-// This reads a serialized WebString from obj. If a string can't be read,
-// WebString() is returned.
-const WebUChar* ReadStringNoCopy(const SerializeObject* obj, int* num_chars) {
- int length;
-
- // Versions 1, 2, and 3 all start with an integer.
- if (!obj->pickle.ReadInt(&obj->iter, &length))
- return NULL;
-
- // Starting with version 2, -1 means WebString().
- if (length == -1)
- return NULL;
-
- // In version 2, the length field was the length in WebUChars.
- // In version 1 and 3 it is the length in bytes.
- int bytes = length;
- if (obj->version == 2)
- bytes *= sizeof(WebUChar);
-
- const void* data;
- if (!ReadBytes(obj, &data, bytes))
- return NULL;
-
- if (num_chars)
- *num_chars = bytes / sizeof(WebUChar);
- return static_cast<const WebUChar*>(data);
-}
-
-WebString ReadString(const SerializeObject* obj) {
- int num_chars;
- const WebUChar* chars = ReadStringNoCopy(obj, &num_chars);
- return chars ? WebString(chars, num_chars) : WebString();
-}
-
-void ConsumeString(const SerializeObject* obj) {
- const WebUChar* unused ALLOW_UNUSED = ReadStringNoCopy(obj, NULL);
-}
-
-// Writes a Vector of Strings into a SerializeObject for serialization.
-void WriteStringVector(
- const WebVector<WebString>& data, SerializeObject* obj) {
- WriteInteger(static_cast<int>(data.size()), obj);
- for (size_t i = 0, c = data.size(); i < c; ++i) {
- unsigned ui = static_cast<unsigned>(i); // sigh
- WriteString(data[ui], obj);
- }
-}
-
-WebVector<WebString> ReadStringVector(const SerializeObject* obj) {
- int num_elements = ReadInteger(obj);
- WebVector<WebString> result(static_cast<size_t>(num_elements));
- for (int i = 0; i < num_elements; ++i)
- result[i] = ReadString(obj);
- return result;
-}
-
-void ConsumeStringVector(const SerializeObject* obj) {
- int num_elements = ReadInteger(obj);
- for (int i = 0; i < num_elements; ++i)
- ConsumeString(obj);
-}
-
-// Writes a FormData object into a SerializeObject for serialization.
-void WriteFormData(const WebHTTPBody& http_body, SerializeObject* obj) {
- WriteBoolean(!http_body.isNull(), obj);
-
- if (http_body.isNull())
- return;
-
- WriteInteger(static_cast<int>(http_body.elementCount()), obj);
- WebHTTPBody::Element element;
- for (size_t i = 0; http_body.elementAt(i, element); ++i) {
- WriteInteger(element.type, obj);
- if (element.type == WebHTTPBody::Element::TypeData) {
- WriteData(element.data.data(), static_cast<int>(element.data.size()),
- obj);
- } else if (element.type == WebHTTPBody::Element::TypeFile) {
- WriteString(element.filePath, obj);
- WriteInteger64(element.fileStart, obj);
- WriteInteger64(element.fileLength, obj);
- WriteReal(element.modificationTime, obj);
- } else if (element.type == WebHTTPBody::Element::TypeURL) {
- WriteGURL(element.url, obj);
- WriteInteger64(element.fileStart, obj);
- WriteInteger64(element.fileLength, obj);
- WriteReal(element.modificationTime, obj);
- } else {
- WriteGURL(element.url, obj);
- }
- }
- WriteInteger64(http_body.identifier(), obj);
- WriteBoolean(http_body.containsPasswordData(), obj);
-}
-
-WebHTTPBody ReadFormData(const SerializeObject* obj) {
- // In newer versions, an initial boolean indicates if we have form data.
- if (obj->version >= 5 && !ReadBoolean(obj))
- return WebHTTPBody();
-
- // In older versions, 0 elements implied no form data.
- int num_elements = ReadInteger(obj);
- if (num_elements == 0 && obj->version < 5)
- return WebHTTPBody();
-
- WebHTTPBody http_body;
- http_body.initialize();
-
- for (int i = 0; i < num_elements; ++i) {
- int type = ReadInteger(obj);
- if (type == WebHTTPBody::Element::TypeData) {
- const void* data;
- int length = -1;
- ReadData(obj, &data, &length);
- if (length >= 0)
- http_body.appendData(WebData(static_cast<const char*>(data), length));
- } else if (type == WebHTTPBody::Element::TypeFile) {
- WebString file_path = ReadString(obj);
- long long file_start = 0;
- long long file_length = -1;
- double modification_time = 0.0;
- if (obj->version >= 8) {
- file_start = ReadInteger64(obj);
- file_length = ReadInteger64(obj);
- modification_time = ReadReal(obj);
- }
- http_body.appendFileRange(file_path, file_start, file_length,
- modification_time);
- } else if (type == WebHTTPBody::Element::TypeURL) {
- GURL url = ReadGURL(obj);
- long long file_start = 0;
- long long file_length = -1;
- double modification_time = 0.0;
- file_start = ReadInteger64(obj);
- file_length = ReadInteger64(obj);
- modification_time = ReadReal(obj);
- http_body.appendURLRange(url, file_start, file_length,
- modification_time);
- } else if (obj->version >= 10) {
- GURL blob_url = ReadGURL(obj);
- http_body.appendBlob(blob_url);
- }
- }
- if (obj->version >= 4)
- http_body.setIdentifier(ReadInteger64(obj));
-
- if (obj->version >= 12)
- http_body.setContainsPasswordData(ReadBoolean(obj));
-
- return http_body;
-}
-
-// Writes the HistoryItem data into the SerializeObject object for
-// serialization.
-void WriteHistoryItem(
- const WebHistoryItem& item, SerializeObject* obj, bool is_top) {
- // WARNING: This data may be persisted for later use. As such, care must be
- // taken when changing the serialized format. If a new field needs to be
- // written, only adding at the end will make it easier to deal with loading
- // older versions. Similarly, this should NOT save fields with sensitive
- // data, such as password fields.
-
- if (kVersion >= 14) {
- if (is_top) {
- WriteInteger(kVersion, obj);
-
- // Insert the list of referenced files, so they can be extracted easily
- // from the serialized data (avoiding the need to call into Blink again).
- WriteStringVector(item.getReferencedFilePaths(), obj);
- }
- } else {
- WriteInteger(kVersion, obj);
- }
-
- WriteString(item.urlString(), obj);
- WriteString(item.originalURLString(), obj);
- WriteString(item.target(), obj);
- WriteString(item.parent(), obj);
- WriteString(item.title(), obj);
- WriteString(item.alternateTitle(), obj);
- WriteReal(item.lastVisitedTime(), obj);
- WriteInteger(item.scrollOffset().x, obj);
- WriteInteger(item.scrollOffset().y, obj);
- WriteBoolean(item.isTargetItem(), obj);
- WriteInteger(item.visitCount(), obj);
- WriteString(item.referrer(), obj);
-
- WriteStringVector(item.documentState(), obj);
-
- if (kVersion >= 11)
- WriteReal(item.pageScaleFactor(), obj);
- if (kVersion >= 9)
- WriteInteger64(item.itemSequenceNumber(), obj);
- if (kVersion >= 6)
- WriteInteger64(item.documentSequenceNumber(), obj);
- if (kVersion >= 7) {
- bool has_state_object = !item.stateObject().isNull();
- WriteBoolean(has_state_object, obj);
- if (has_state_object)
- WriteString(item.stateObject().toString(), obj);
- }
-
- WriteFormData(item.httpBody(), obj);
- WriteString(item.httpContentType(), obj);
- if (kVersion < 14)
- WriteString(item.referrer(), obj);
-
- // Subitems
- const WebVector<WebHistoryItem>& children = item.children();
- WriteInteger(static_cast<int>(children.size()), obj);
- for (size_t i = 0, c = children.size(); i < c; ++i)
- WriteHistoryItem(children[i], obj, false);
-}
-
-// Creates a new HistoryItem tree based on the serialized string.
-// Assumes the data is in the format returned by WriteHistoryItem.
-WebHistoryItem ReadHistoryItem(
- const SerializeObject* obj,
- IncludeFormData include_form_data,
- bool include_scroll_offset,
- bool is_top) {
- if (is_top) {
- obj->version = ReadInteger(obj);
-
- if (obj->version == -1) {
- GURL url = ReadGURL(obj);
- WebHistoryItem item;
- item.initialize();
- item.setURLString(WebString::fromUTF8(url.possibly_invalid_spec()));
- return item;
- }
-
- if (obj->version > kVersion || obj->version < 1)
- return WebHistoryItem();
-
- if (obj->version >= 14)
- ConsumeStringVector(obj); // Skip over list of referenced files.
- } else if (obj->version < 14) {
- ConsumeInteger(obj); // Skip over redundant version field.
- }
-
- WebHistoryItem item;
- item.initialize();
-
- item.setURLString(ReadString(obj));
- item.setOriginalURLString(ReadString(obj));
- item.setTarget(ReadString(obj));
- item.setParent(ReadString(obj));
- item.setTitle(ReadString(obj));
- item.setAlternateTitle(ReadString(obj));
- item.setLastVisitedTime(ReadReal(obj));
-
- int x = ReadInteger(obj);
- int y = ReadInteger(obj);
- if (include_scroll_offset)
- item.setScrollOffset(WebPoint(x, y));
-
- item.setIsTargetItem(ReadBoolean(obj));
- item.setVisitCount(ReadInteger(obj));
- item.setReferrer(ReadString(obj));
-
- item.setDocumentState(ReadStringVector(obj));
-
- if (obj->version >= 11)
- item.setPageScaleFactor(ReadReal(obj));
- if (obj->version >= 9)
- item.setItemSequenceNumber(ReadInteger64(obj));
- if (obj->version >= 6)
- item.setDocumentSequenceNumber(ReadInteger64(obj));
- if (obj->version >= 7) {
- bool has_state_object = ReadBoolean(obj);
- if (has_state_object) {
- item.setStateObject(
- WebSerializedScriptValue::fromString(ReadString(obj)));
- }
- }
-
- // The extra referrer string is read for backwards compat.
- const WebHTTPBody& http_body = ReadFormData(obj);
- const WebString& http_content_type = ReadString(obj);
-
- if (obj->version < 14)
- ConsumeString(obj); // Skip unused referrer string.
-
- if (include_form_data == ALWAYS_INCLUDE_FORM_DATA ||
- (include_form_data == INCLUDE_FORM_DATA_WITHOUT_PASSWORDS &&
- !http_body.isNull() && !http_body.containsPasswordData())) {
- // Include the full HTTP body.
- item.setHTTPBody(http_body);
- item.setHTTPContentType(http_content_type);
- } else if (!http_body.isNull()) {
- // Don't include the data in the HTTP body, but include its identifier. This
- // enables fetching data from the cache.
- WebHTTPBody empty_http_body;
- empty_http_body.initialize();
- empty_http_body.setIdentifier(http_body.identifier());
- item.setHTTPBody(empty_http_body);
- }
-
-#if defined(OS_ANDROID)
- if (obj->version == 11) {
- // Now-unused values that shipped in this version of Chrome for Android when
- // it was on a private branch.
- ReadReal(obj);
- ReadBoolean(obj);
-
- // In this version, pageScaleFactor included deviceScaleFactor and scroll
- // offsets were premultiplied by pageScaleFactor.
- if (item.pageScaleFactor()) {
- if (include_scroll_offset)
- item.setScrollOffset(
- WebPoint(item.scrollOffset().x / item.pageScaleFactor(),
- item.scrollOffset().y / item.pageScaleFactor()));
- item.setPageScaleFactor(item.pageScaleFactor() /
- gfx::Screen::GetNativeScreen()->GetPrimaryDisplay()
- .device_scale_factor());
- }
- }
-#endif
-
- // Subitems
- int num_children = ReadInteger(obj);
- for (int i = 0; i < num_children; ++i)
- item.appendToChildren(ReadHistoryItem(obj,
- include_form_data,
- include_scroll_offset,
- false));
-
- return item;
-}
-
-// Reconstruct a HistoryItem from a string, using our JSON Value deserializer.
-// This assumes that the given serialized string has all the required key,value
-// pairs, and does minimal error checking. The form data of the post is restored
-// if |include_form_data| is |ALWAYS_INCLUDE_FORM_DATA| or if the data doesn't
-// contain passwords and |include_form_data| is
-// |INCLUDE_FORM_DATA_WITHOUT_PASSWORDS|. Otherwise the form data is empty. If
-// |include_scroll_offset| is true, the scroll offset is restored.
-WebHistoryItem HistoryItemFromString(
- const std::string& serialized_item,
- IncludeFormData include_form_data,
- bool include_scroll_offset) {
- if (serialized_item.empty())
- return WebHistoryItem();
-
- SerializeObject obj(serialized_item.data(),
- static_cast<int>(serialized_item.length()));
- return ReadHistoryItem(&obj, include_form_data, include_scroll_offset, true);
-}
-
-void ToFilePathVector(const WebVector<WebString>& input,
- std::vector<base::FilePath>* output) {
- for (size_t i = 0; i < input.size(); ++i)
- output->push_back(webkit_base::WebStringToFilePath(input[i]));
-}
-
-} // namespace
-
-// Serialize a HistoryItem to a string, using our JSON Value serializer.
-std::string HistoryItemToString(const WebHistoryItem& item) {
- if (item.isNull())
- return std::string();
-
- SerializeObject obj;
- WriteHistoryItem(item, &obj, true);
- return obj.GetAsString();
-}
-
-WebHistoryItem HistoryItemFromString(const std::string& serialized_item) {
- return HistoryItemFromString(serialized_item, ALWAYS_INCLUDE_FORM_DATA, true);
-}
-
-std::vector<base::FilePath> FilePathsFromHistoryState(
- const std::string& content_state) {
- // TODO(darin): We should avoid using the WebKit API here, so that we do not
- // need to have WebKit initialized before calling this method.
-
- std::vector<base::FilePath> result;
-
- // In newer versions of the format, the set of referenced files is computed
- // at serialization time.
- SerializeObject obj(content_state.data(),
- static_cast<int>(content_state.length()));
- obj.version = ReadInteger(&obj);
-
- if (obj.version > kVersion || obj.version < 1)
- return result;
-
- if (obj.version >= 14) {
- ToFilePathVector(ReadStringVector(&obj), &result);
- } else {
- // TODO(darin): Delete this code path after we branch for M29.
- const WebHistoryItem& item =
- HistoryItemFromString(content_state, ALWAYS_INCLUDE_FORM_DATA, true);
- if (!item.isNull())
- ToFilePathVector(item.getReferencedFilePaths(), &result);
- }
- return result;
-}
-
-// For testing purposes only.
-void HistoryItemToVersionedString(const WebHistoryItem& item, int version,
- std::string* serialized_item) {
- if (item.isNull()) {
- serialized_item->clear();
- return;
- }
-
- // Temporarily change the version.
- int real_version = kVersion;
- kVersion = version;
-
- SerializeObject obj;
- WriteHistoryItem(item, &obj, true);
- *serialized_item = obj.GetAsString();
-
- kVersion = real_version;
-}
-
-int HistoryItemCurrentVersion() {
- return kVersion;
-}
-
-std::string RemovePasswordDataFromHistoryState(
- const std::string& content_state) {
- // TODO(darin): We should avoid using the WebKit API here, so that we do not
- // need to have WebKit initialized before calling this method.
- const WebHistoryItem& item =
- HistoryItemFromString(
- content_state, INCLUDE_FORM_DATA_WITHOUT_PASSWORDS, true);
- if (item.isNull()) {
- // Couldn't parse the string, return an empty string.
- return std::string();
- }
-
- return HistoryItemToString(item);
-}
-
-std::string RemoveScrollOffsetFromHistoryState(
- const std::string& content_state) {
- // TODO(darin): We should avoid using the WebKit API here, so that we do not
- // need to have WebKit initialized before calling this method.
- const WebHistoryItem& item =
- HistoryItemFromString(content_state, ALWAYS_INCLUDE_FORM_DATA, false);
- if (item.isNull()) {
- // Couldn't parse the string, return an empty string.
- return std::string();
- }
-
- return HistoryItemToString(item);
-}
-
-std::string CreateHistoryStateForURL(const GURL& url) {
- // We avoid using the WebKit API here, so that we do not need to have WebKit
- // initialized before calling this method. Instead, we write a simple
- // serialization of the given URL with a dummy version number of -1. This
- // will be interpreted by ReadHistoryItem as a request to create a default
- // WebHistoryItem.
- SerializeObject obj;
- WriteInteger(-1, &obj);
- WriteGURL(url, &obj);
- return obj.GetAsString();
-}
-
-} // namespace webkit_glue
diff --git a/webkit/glue/glue_serialize_deprecated.h b/webkit/glue/glue_serialize_deprecated.h
deleted file mode 100644
index 5d9c8cb..0000000
--- a/webkit/glue/glue_serialize_deprecated.h
+++ /dev/null
@@ -1,57 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-//
-// This file contains (de)serialization (or if you like python, pickling)
-// methods for various objects that we want to persist.
-// In serialization, we write an object's state to a string in some opaque
-// format. Deserialization reconstructs the object's state from such a string.
-
-#ifndef WEBKIT_GLUE_GLUE_SERIALIZE_H_
-#define WEBKIT_GLUE_GLUE_SERIALIZE_H_
-
-#include <string>
-
-#include "base/files/file_path.h"
-#include "third_party/WebKit/public/web/WebHistoryItem.h"
-#include "webkit/glue/webkit_glue_export.h"
-
-class GURL;
-
-namespace webkit_glue {
-
-// HistoryItem serialization.
-WEBKIT_GLUE_EXPORT std::string HistoryItemToString(
- const WebKit::WebHistoryItem& item);
-WEBKIT_GLUE_EXPORT WebKit::WebHistoryItem HistoryItemFromString(
- const std::string& serialized_item);
-
-// Reads file paths from the HTTP body and the file input elements of a
-// serialized WebHistoryItem.
-WEBKIT_GLUE_EXPORT std::vector<base::FilePath> FilePathsFromHistoryState(
- const std::string& content_state);
-
-// For testing purposes only.
-WEBKIT_GLUE_EXPORT void HistoryItemToVersionedString(
- const WebKit::WebHistoryItem& item,
- int version,
- std::string* serialized_item);
-WEBKIT_GLUE_EXPORT int HistoryItemCurrentVersion();
-
-// Removes form data containing passwords from the history state string
-// |content_state|.
-WEBKIT_GLUE_EXPORT std::string RemovePasswordDataFromHistoryState(
- const std::string& content_state);
-
-// Removes scroll offset from the history state string |content_state|.
-WEBKIT_GLUE_EXPORT std::string RemoveScrollOffsetFromHistoryState(
- const std::string& content_state);
-
-// Creates serialized state for the specified URL. This is a variant of
-// HistoryItemToString (in glue_serialize) that is used during session restore
-// if the saved state is empty.
-WEBKIT_GLUE_EXPORT std::string CreateHistoryStateForURL(const GURL& url);
-
-} // namespace webkit_glue
-
-#endif // #ifndef WEBKIT_GLUE_GLUE_SERIALIZE_H_
diff --git a/webkit/glue/glue_serialize_unittest.cc b/webkit/glue/glue_serialize_unittest.cc
deleted file mode 100644
index 80b9680..0000000
--- a/webkit/glue/glue_serialize_unittest.cc
+++ /dev/null
@@ -1,328 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include <string>
-
-#include "base/pickle.h"
-#include "base/strings/string_util.h"
-#include "testing/gtest/include/gtest/gtest.h"
-#include "third_party/WebKit/public/platform/WebHTTPBody.h"
-#include "third_party/WebKit/public/platform/WebPoint.h"
-#include "third_party/WebKit/public/platform/WebVector.h"
-#include "ui/gfx/screen.h"
-#include "webkit/base/file_path_string_conversions.h"
-#include "webkit/glue/glue_serialize_deprecated.h"
-
-using WebKit::WebData;
-using WebKit::WebHistoryItem;
-using WebKit::WebHTTPBody;
-using WebKit::WebPoint;
-using WebKit::WebString;
-using WebKit::WebUChar;
-using WebKit::WebVector;
-
-namespace {
-class GlueSerializeTest : public testing::Test {
- public:
- // Makes a FormData with some random data.
- WebHTTPBody MakeFormData() {
- WebHTTPBody http_body;
- http_body.initialize();
-
- const char d1[] = "first data block";
- http_body.appendData(WebData(d1, sizeof(d1)-1));
-
- http_body.appendFile(WebString::fromUTF8("file.txt"));
-
- const char d2[] = "data the second";
- http_body.appendData(WebData(d2, sizeof(d2)-1));
-
- return http_body;
- }
-
- WebHTTPBody MakeFormDataWithPasswords() {
- WebHTTPBody http_body = MakeFormData();
- http_body.setContainsPasswordData(true);
- return http_body;
- }
-
- // Constructs a HistoryItem with some random data and an optional child.
- WebHistoryItem MakeHistoryItem(bool with_form_data, bool pregnant) {
- WebHistoryItem item;
- item.initialize();
-
- item.setURLString(WebString::fromUTF8("urlString"));
- item.setOriginalURLString(WebString::fromUTF8("originalURLString"));
- item.setTarget(WebString::fromUTF8("target"));
- item.setParent(WebString::fromUTF8("parent"));
- item.setTitle(WebString::fromUTF8("title"));
- item.setAlternateTitle(WebString::fromUTF8("alternateTitle"));
- item.setLastVisitedTime(13.37);
- item.setScrollOffset(WebPoint(42, -42));
- item.setIsTargetItem(true);
- item.setVisitCount(42*42);
- item.setPageScaleFactor(2.0f);
- item.setItemSequenceNumber(123);
- item.setDocumentSequenceNumber(456);
-
- WebVector<WebString> document_state(size_t(3));
- document_state[0] = WebString::fromUTF8("state1");
- document_state[1] = WebString::fromUTF8("state2");
- document_state[2] = WebString::fromUTF8("state AWESOME");
- item.setDocumentState(document_state);
-
- // Form Data
- if (with_form_data) {
- item.setHTTPBody(MakeFormData());
- item.setHTTPContentType(WebString::fromUTF8("formContentType"));
- }
-
- // Setting the FormInfo causes the referrer to be set, so we set the
- // referrer after setting the form info.
- item.setReferrer(WebString::fromUTF8("referrer"));
-
- // Children
- if (pregnant)
- item.appendToChildren(MakeHistoryItem(false, false));
-
- return item;
- }
-
- WebHistoryItem MakeHistoryItemWithPasswordData(bool pregnant) {
- WebHistoryItem item = MakeHistoryItem(false, pregnant);
- item.setHTTPBody(MakeFormDataWithPasswords());
- item.setHTTPContentType(WebString::fromUTF8("formContentType"));
- return item;
- }
-
- // Checks that a == b.
- void HistoryItemExpectEqual(const WebHistoryItem& a,
- const WebHistoryItem& b,
- int version) {
- HistoryItemExpectBaseDataEqual(a, b, version);
- HistoryItemExpectFormDataEqual(a, b);
- HistoryItemExpectChildrenEqual(a, b);
- }
-
- void HistoryItemExpectBaseDataEqual(const WebHistoryItem& a,
- const WebHistoryItem& b,
- int version) {
- float expectedPageScaleFactor = a.pageScaleFactor();
- WebPoint expectedScrollOffset = a.scrollOffset();
-#if defined(OS_ANDROID)
- if (version == 11) {
- expectedScrollOffset.x /= a.pageScaleFactor();
- expectedScrollOffset.y /= a.pageScaleFactor();
- expectedPageScaleFactor /= gfx::Screen::GetNativeScreen()
- ->GetPrimaryDisplay().device_scale_factor();
- }
-#endif
- EXPECT_EQ(base::string16(a.urlString()), base::string16(b.urlString()));
- EXPECT_EQ(base::string16(a.originalURLString()),
- base::string16(b.originalURLString()));
- EXPECT_EQ(base::string16(a.target()), base::string16(b.target()));
- EXPECT_EQ(base::string16(a.parent()), base::string16(b.parent()));
- EXPECT_EQ(base::string16(a.title()), base::string16(b.title()));
- EXPECT_EQ(base::string16(a.alternateTitle()),
- base::string16(b.alternateTitle()));
- EXPECT_EQ(a.lastVisitedTime(), b.lastVisitedTime());
- EXPECT_EQ(expectedScrollOffset, b.scrollOffset());
- EXPECT_EQ(a.isTargetItem(), b.isTargetItem());
- EXPECT_EQ(a.visitCount(), b.visitCount());
- EXPECT_EQ(base::string16(a.referrer()), base::string16(b.referrer()));
- if (version >= 11)
- EXPECT_EQ(expectedPageScaleFactor, b.pageScaleFactor());
- if (version >= 9)
- EXPECT_EQ(a.itemSequenceNumber(), b.itemSequenceNumber());
- if (version >= 6)
- EXPECT_EQ(a.documentSequenceNumber(), b.documentSequenceNumber());
-
- const WebVector<WebString>& a_docstate = a.documentState();
- const WebVector<WebString>& b_docstate = b.documentState();
- EXPECT_EQ(a_docstate.size(), b_docstate.size());
- for (size_t i = 0, c = a_docstate.size(); i < c; ++i)
- EXPECT_EQ(base::string16(a_docstate[i]), base::string16(b_docstate[i]));
- }
-
- void HistoryItemExpectFormDataEqual(const WebHistoryItem& a,
- const WebHistoryItem& b) {
- const WebHTTPBody& a_body = a.httpBody();
- const WebHTTPBody& b_body = b.httpBody();
- EXPECT_EQ(!a_body.isNull(), !b_body.isNull());
- if (!a_body.isNull() && !b_body.isNull()) {
- EXPECT_EQ(a_body.containsPasswordData(), b_body.containsPasswordData());
- EXPECT_EQ(a_body.elementCount(), b_body.elementCount());
- WebHTTPBody::Element a_elem, b_elem;
- for (size_t i = 0; a_body.elementAt(i, a_elem) &&
- b_body.elementAt(i, b_elem); ++i) {
- EXPECT_EQ(a_elem.type, b_elem.type);
- if (a_elem.type == WebHTTPBody::Element::TypeData) {
- EXPECT_EQ(std::string(a_elem.data.data(), a_elem.data.size()),
- std::string(b_elem.data.data(), b_elem.data.size()));
- } else {
- EXPECT_EQ(base::string16(a_elem.filePath),
- base::string16(b_elem.filePath));
- }
- }
- }
- EXPECT_EQ(base::string16(a.httpContentType()),
- base::string16(b.httpContentType()));
- }
-
- void HistoryItemExpectChildrenEqual(const WebHistoryItem& a,
- const WebHistoryItem& b) {
- const WebVector<WebHistoryItem>& a_children = a.children();
- const WebVector<WebHistoryItem>& b_children = b.children();
- EXPECT_EQ(a_children.size(), b_children.size());
- for (size_t i = 0, c = a_children.size(); i < c; ++i)
- HistoryItemExpectEqual(a_children[i], b_children[i],
- webkit_glue::HistoryItemCurrentVersion());
- }
-};
-
-// Test old versions of serialized data to ensure that newer versions of code
-// can still read history items written by previous versions.
-TEST_F(GlueSerializeTest, BackwardsCompatibleTest) {
- const WebHistoryItem& item = MakeHistoryItem(false, false);
-
- // Make sure current version can read all previous versions.
- for (int i = 1; i < webkit_glue::HistoryItemCurrentVersion(); i++) {
- std::string serialized_item;
- webkit_glue::HistoryItemToVersionedString(item, i, &serialized_item);
- const WebHistoryItem& deserialized_item =
- webkit_glue::HistoryItemFromString(serialized_item);
- ASSERT_FALSE(item.isNull());
- ASSERT_FALSE(deserialized_item.isNull());
- HistoryItemExpectEqual(item, deserialized_item, i);
- }
-}
-
-// Makes sure that a HistoryItem remains intact after being serialized and
-// deserialized.
-TEST_F(GlueSerializeTest, HistoryItemSerializeTest) {
- const WebHistoryItem& item = MakeHistoryItem(true, true);
- const std::string& serialized_item = webkit_glue::HistoryItemToString(item);
- const WebHistoryItem& deserialized_item =
- webkit_glue::HistoryItemFromString(serialized_item);
-
- ASSERT_FALSE(item.isNull());
- ASSERT_FALSE(deserialized_item.isNull());
- HistoryItemExpectEqual(item, deserialized_item,
- webkit_glue::HistoryItemCurrentVersion());
-}
-
-// Checks that broken messages don't take out our process.
-TEST_F(GlueSerializeTest, BadMessagesTest) {
- {
- Pickle p;
- // Version 1
- p.WriteInt(1);
- // Empty strings.
- for (int i = 0; i < 6; ++i)
- p.WriteInt(-1);
- // Bad real number.
- p.WriteInt(-1);
- std::string s(static_cast<const char*>(p.data()), p.size());
- webkit_glue::HistoryItemFromString(s);
- }
- {
- double d = 0;
- Pickle p;
- // Version 1
- p.WriteInt(1);
- // Empty strings.
- for (int i = 0; i < 6; ++i)
- p.WriteInt(-1);
- // More misc fields.
- p.WriteData(reinterpret_cast<const char*>(&d), sizeof(d));
- p.WriteInt(1);
- p.WriteInt(1);
- p.WriteInt(0);
- p.WriteInt(0);
- p.WriteInt(-1);
- p.WriteInt(0);
- // WebForm
- p.WriteInt(1);
- p.WriteInt(WebHTTPBody::Element::TypeData);
- std::string s(static_cast<const char*>(p.data()), p.size());
- webkit_glue::HistoryItemFromString(s);
- }
-}
-
-TEST_F(GlueSerializeTest, FilePathsFromHistoryState) {
- WebHistoryItem item = MakeHistoryItem(false, true);
-
- // Append file paths to item.
- base::FilePath file_path1(FILE_PATH_LITERAL("file.txt"));
- base::FilePath file_path2(FILE_PATH_LITERAL("another_file"));
- WebHTTPBody http_body;
- http_body.initialize();
- http_body.appendFile(webkit_base::FilePathToWebString(file_path1));
- http_body.appendFile(webkit_base::FilePathToWebString(file_path2));
- item.setHTTPBody(http_body);
-
- std::string serialized_item = webkit_glue::HistoryItemToString(item);
- const std::vector<base::FilePath>& file_paths =
- webkit_glue::FilePathsFromHistoryState(serialized_item);
- ASSERT_EQ(2U, file_paths.size());
- EXPECT_EQ(file_path1, file_paths[0]);
- EXPECT_EQ(file_path2, file_paths[1]);
-}
-
-// Makes sure that a HistoryItem containing password data remains intact after
-// being serialized and deserialized.
-TEST_F(GlueSerializeTest, HistoryItemWithPasswordsSerializeTest) {
- const WebHistoryItem& item = MakeHistoryItemWithPasswordData(true);
- const std::string& serialized_item = webkit_glue::HistoryItemToString(item);
- const WebHistoryItem& deserialized_item =
- webkit_glue::HistoryItemFromString(serialized_item);
-
- ASSERT_FALSE(item.isNull());
- ASSERT_FALSE(deserialized_item.isNull());
- HistoryItemExpectEqual(item, deserialized_item,
- webkit_glue::HistoryItemCurrentVersion());
-}
-
-TEST_F(GlueSerializeTest, RemovePasswordData) {
- const WebHistoryItem& item1 = MakeHistoryItemWithPasswordData(true);
- std::string serialized_item = webkit_glue::HistoryItemToString(item1);
- serialized_item =
- webkit_glue::RemovePasswordDataFromHistoryState(serialized_item);
- const WebHistoryItem& item2 =
- webkit_glue::HistoryItemFromString(serialized_item);
-
- ASSERT_FALSE(item1.isNull());
- ASSERT_FALSE(item2.isNull());
-
- HistoryItemExpectBaseDataEqual(item1, item2,
- webkit_glue::HistoryItemCurrentVersion());
- HistoryItemExpectChildrenEqual(item1, item2);
-
- // Form data was removed, but the identifier was kept.
- const WebHTTPBody& body1 = item1.httpBody();
- const WebHTTPBody& body2 = item2.httpBody();
- EXPECT_FALSE(body1.isNull());
- EXPECT_FALSE(body2.isNull());
- EXPECT_GT(body1.elementCount(), 0U);
- EXPECT_EQ(0U, body2.elementCount());
- EXPECT_EQ(body1.identifier(), body2.identifier());
-}
-
-TEST_F(GlueSerializeTest, RemovePasswordDataWithNoPasswordData) {
- const WebHistoryItem& item1 = MakeHistoryItem(true, true);
- std::string serialized_item = webkit_glue::HistoryItemToString(item1);
- serialized_item =
- webkit_glue::RemovePasswordDataFromHistoryState(serialized_item);
- const WebHistoryItem& item2 =
- webkit_glue::HistoryItemFromString(serialized_item);
-
- ASSERT_FALSE(item1.isNull());
- ASSERT_FALSE(item2.isNull());
-
- // Form data was not removed.
- HistoryItemExpectEqual(item1, item2,
- webkit_glue::HistoryItemCurrentVersion());
-}
-
-} // namespace
diff --git a/webkit/glue/webkit_glue.gypi b/webkit/glue/webkit_glue.gypi
index ceb346a..e40cb85 100644
--- a/webkit/glue/webkit_glue.gypi
+++ b/webkit/glue/webkit_glue.gypi
@@ -275,8 +275,6 @@
'sources': [
'ftp_directory_listing_response_delegate.cc',
'ftp_directory_listing_response_delegate.h',
- 'glue_serialize_deprecated.cc',
- 'glue_serialize_deprecated.h',
'image_decoder.cc',
'image_decoder.h',
'network_list_observer.h',