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

Unified Diff: content/public/common/page_state.cc

Issue 16335022: Re-implement PageState serialization without a Blink API dependency. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/content_tests.gypi ('k') | content/public/common/page_state_ios.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/public/common/page_state.cc
diff --git a/content/public/common/page_state.cc b/content/public/common/page_state.cc
index 7daaaac6546e046ac83bbd7968413e0bbba4b6ae..34771a680c247713ac17700fda24c71279dd3863 100644
--- a/content/public/common/page_state.cc
+++ b/content/public/common/page_state.cc
@@ -4,13 +4,81 @@
#include "content/public/common/page_state.h"
+#include "base/strings/utf_string_conversions.h"
+#include "content/common/page_state_serialization.h"
+
namespace content {
+namespace {
+
+PageState ToPageState(const ExplodedPageState& exploded) {
+ std::string encoded_data;
+ if (!EncodePageState(exploded, &encoded_data))
+ return PageState();
+
+ return PageState::CreateFromEncodedData(encoded_data);
+}
+
+void RecursivelyRemovePasswordData(ExplodedFrameState* frame_state) {
+ if (frame_state->http_body.contains_passwords)
+ frame_state->http_body = ExplodedHttpBody();
+}
+
+void RecursivelyRemoveScrollOffset(ExplodedFrameState* frame_state) {
+ frame_state->scroll_offset = gfx::Point();
+}
+
+} // namespace
// static
PageState PageState::CreateFromEncodedData(const std::string& data) {
return PageState(data);
}
+// static
+PageState PageState::CreateFromURL(const GURL& url) {
+ ExplodedPageState exploded_page_state;
+
+ exploded_page_state.top.url_string =
+ exploded_page_state.top.original_url_string =
+ NullableString16(UTF8ToUTF16(url.possibly_invalid_spec()), false);
+
+ return ToPageState(exploded_page_state);
+}
+
+// static
+PageState PageState::CreateForTesting(
+ const GURL& url,
+ bool body_contains_password_data,
+ const char* optional_body_data,
+ const base::FilePath* optional_body_file_path) {
+ ExplodedPageState exploded_page_state;
+
+ exploded_page_state.top.url_string =
+ exploded_page_state.top.original_url_string =
+ NullableString16(UTF8ToUTF16(url.possibly_invalid_spec()), false);
+
+ if (optional_body_data || optional_body_file_path) {
+ exploded_page_state.top.http_body.is_null = false;
+ if (optional_body_data) {
+ ExplodedHttpBodyElement element;
+ element.type = WebKit::WebHTTPBody::Element::TypeData;
+ element.data = optional_body_data;
+ exploded_page_state.top.http_body.elements.push_back(element);
+ }
+ if (optional_body_file_path) {
+ ExplodedHttpBodyElement element;
+ element.type = WebKit::WebHTTPBody::Element::TypeFile;
+ element.file_path = *optional_body_file_path;
+ exploded_page_state.top.http_body.elements.push_back(element);
+ exploded_page_state.referenced_files.push_back(*optional_body_file_path);
+ }
+ exploded_page_state.top.http_body.contains_passwords =
+ body_contains_password_data;
+ }
+
+ return ToPageState(exploded_page_state);
+}
+
PageState::PageState() {
}
@@ -26,6 +94,34 @@ const std::string& PageState::ToEncodedData() const {
return data_;
}
+std::vector<base::FilePath> PageState::GetReferencedFiles() const {
+ ExplodedPageState exploded_page_state;
+ if (!DecodePageState(data_, &exploded_page_state))
+ return std::vector<base::FilePath>();
+
+ return exploded_page_state.referenced_files;
+}
+
+PageState PageState::RemovePasswordData() const {
+ ExplodedPageState exploded_page_state;
+ if (!DecodePageState(data_, &exploded_page_state))
+ return PageState(); // Oops!
+
+ RecursivelyRemovePasswordData(&exploded_page_state.top);
+
+ return ToPageState(exploded_page_state);
+}
+
+PageState PageState::RemoveScrollOffset() const {
+ ExplodedPageState exploded_page_state;
+ if (!DecodePageState(data_, &exploded_page_state))
+ return PageState(); // Oops!
+
+ RecursivelyRemoveScrollOffset(&exploded_page_state.top);
+
+ return ToPageState(exploded_page_state);
+}
+
PageState::PageState(const std::string& data)
: data_(data) {
// TODO(darin): Enable this DCHECK once tests have been fixed up to not pass
« no previous file with comments | « content/content_tests.gypi ('k') | content/public/common/page_state_ios.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698