diff options
author | marja@chromium.org <marja@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-10 11:01:35 +0000 |
---|---|---|
committer | marja@chromium.org <marja@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-10 11:01:35 +0000 |
commit | a93cde20da906d918255a5162898fa51728e2937 (patch) | |
tree | e5e2b023b9a127bee2f09a00258571d23db634fc /webkit | |
parent | 74697dc407d245a4d5f908db1ab7730415cbb614 (diff) | |
download | chromium_src-a93cde20da906d918255a5162898fa51728e2937.zip chromium_src-a93cde20da906d918255a5162898fa51728e2937.tar.gz chromium_src-a93cde20da906d918255a5162898fa51728e2937.tar.bz2 |
Session restore: save and restore HTTP body for POST requests.
BUG=104293
TEST=GlueSerializeTest.(RemoveFormData|FilePathsFromHistoryState), SessionServiceTest.(Keep|Remove)PostData, SessionServiceTest.CompressAndDecompressData
Review URL: http://codereview.chromium.org/8952017
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@121429 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r-- | webkit/glue/glue_serialize.cc | 25 | ||||
-rw-r--r-- | webkit/glue/glue_serialize.h | 8 | ||||
-rw-r--r-- | webkit/glue/glue_serialize_unittest.cc | 59 |
3 files changed, 87 insertions, 5 deletions
diff --git a/webkit/glue/glue_serialize.cc b/webkit/glue/glue_serialize.cc index 9ee14f9..04a4ac4 100644 --- a/webkit/glue/glue_serialize.cc +++ b/webkit/glue/glue_serialize.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// 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. @@ -498,6 +498,29 @@ WebHistoryItem HistoryItemFromString(const std::string& serialized_item) { return HistoryItemFromString(serialized_item, true, true); } +std::vector<FilePath> FilePathsFromHistoryState( + const std::string& content_state) { + std::vector<FilePath> to_return; + // 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, true, true); + if (item.isNull()) { + // Couldn't parse the string. + return to_return; + } + const WebHTTPBody& http_body = item.httpBody(); + if (!http_body.isNull()) { + WebHTTPBody::Element element; + for (size_t i = 0; i < http_body.elementCount(); ++i) { + http_body.elementAt(i, element); + if (element.type == WebHTTPBody::Element::TypeFile) + to_return.push_back(WebStringToFilePath(element.filePath)); + } + } + return to_return; +} + // For testing purposes only. void HistoryItemToVersionedString(const WebHistoryItem& item, int version, std::string* serialized_item) { diff --git a/webkit/glue/glue_serialize.h b/webkit/glue/glue_serialize.h index 6e4c575..8d8ad2e 100644 --- a/webkit/glue/glue_serialize.h +++ b/webkit/glue/glue_serialize.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// 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. // @@ -11,6 +11,8 @@ #define WEBKIT_GLUE_GLUE_SERIALIZE_H_ #include <string> + +#include "base/file_path.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebHistoryItem.h" #include "webkit/glue/webkit_glue_export.h" @@ -22,6 +24,10 @@ WEBKIT_GLUE_EXPORT std::string HistoryItemToString( WEBKIT_GLUE_EXPORT WebKit::WebHistoryItem HistoryItemFromString( const std::string& serialized_item); +// Reads file paths from the HTTP body of a serialized WebHistoryItem. +WEBKIT_GLUE_EXPORT std::vector<FilePath> FilePathsFromHistoryState( + const std::string& content_state); + // For testing purposes only. WEBKIT_GLUE_EXPORT void HistoryItemToVersionedString( const WebKit::WebHistoryItem& item, diff --git a/webkit/glue/glue_serialize_unittest.cc b/webkit/glue/glue_serialize_unittest.cc index 54a3540..1d88c8d 100644 --- a/webkit/glue/glue_serialize_unittest.cc +++ b/webkit/glue/glue_serialize_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// 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. @@ -11,6 +11,7 @@ #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPoint.h" #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h" #include "webkit/glue/glue_serialize.h" +#include "webkit/glue/webkit_glue.h" #include "webkit/glue/web_io_operators.h" using WebKit::WebData; @@ -83,6 +84,13 @@ class GlueSerializeTest : public testing::Test { // Checks that a == b. void HistoryItemExpectEqual(const WebHistoryItem& a, const WebHistoryItem& b) { + HistoryItemExpectBaseDataEqual(a, b); + HistoryItemExpectFormDataEqual(a, b); + HistoryItemExpectChildrenEqual(a, b); + } + + void HistoryItemExpectBaseDataEqual(const WebHistoryItem& a, + const WebHistoryItem& b) { EXPECT_EQ(string16(a.urlString()), string16(b.urlString())); EXPECT_EQ(string16(a.originalURLString()), string16(b.originalURLString())); EXPECT_EQ(string16(a.target()), string16(b.target())); @@ -101,8 +109,10 @@ class GlueSerializeTest : public testing::Test { EXPECT_EQ(a_docstate.size(), b_docstate.size()); for (size_t i = 0, c = a_docstate.size(); i < c; ++i) EXPECT_EQ(string16(a_docstate[i]), string16(b_docstate[i])); + } - // Form Data + 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()); @@ -121,8 +131,10 @@ class GlueSerializeTest : public testing::Test { } } EXPECT_EQ(string16(a.httpContentType()), string16(b.httpContentType())); + } - // Children + 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()); @@ -199,4 +211,45 @@ TEST_F(GlueSerializeTest, BadMessagesTest) { } } +TEST_F(GlueSerializeTest, RemoveFormData) { + const WebHistoryItem& item1 = MakeHistoryItem(true, true); + std::string serialized_item = webkit_glue::HistoryItemToString(item1); + serialized_item = + webkit_glue::RemoveFormDataFromHistoryState(serialized_item); + const WebHistoryItem& item2 = + webkit_glue::HistoryItemFromString(serialized_item); + + ASSERT_FALSE(item1.isNull()); + ASSERT_FALSE(item2.isNull()); + + HistoryItemExpectBaseDataEqual(item1, item2); + HistoryItemExpectChildrenEqual(item1, item2); + + // Form data was removed. + const WebHTTPBody& body1 = item1.httpBody(); + const WebHTTPBody& body2 = item2.httpBody(); + EXPECT_FALSE(body1.isNull()); + EXPECT_TRUE(body2.isNull()); +} + +TEST_F(GlueSerializeTest, FilePathsFromHistoryState) { + WebHistoryItem item = MakeHistoryItem(false, true); + + // Append file paths to item. + FilePath file_path1(FILE_PATH_LITERAL("file.txt")); + FilePath file_path2(FILE_PATH_LITERAL("another_file")); + WebHTTPBody http_body; + http_body.initialize(); + http_body.appendFile(webkit_glue::FilePathToWebString(file_path1)); + http_body.appendFile(webkit_glue::FilePathToWebString(file_path2)); + item.setHTTPBody(http_body); + + std::string serialized_item = webkit_glue::HistoryItemToString(item); + const std::vector<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]); +} + } // namespace |