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

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

Issue 16867005: Re-implement PageState serialization without a Blink API dependency. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Improvements based on Tom's feedback. 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..54c00e3dc01849a98bd36598aabc046dee86fd2c 100644
--- a/content/public/common/page_state.cc
+++ b/content/public/common/page_state.cc
@@ -4,13 +4,97 @@
#include "content/public/common/page_state.h"
+#include "base/files/file_path.h"
+#include "base/strings/utf_string_conversions.h"
+#include "content/common/page_state_serialization.h"
+
namespace content {
+namespace {
+
+base::NullableString16 ToNullableString16(const std::string& utf8) {
+ return base::NullableString16(UTF8ToUTF16(utf8), false);
+}
+
+base::FilePath ToFilePath(const base::NullableString16& s) {
+ return base::FilePath::FromUTF16Unsafe(s.string());
+}
+
+void ToFilePathVector(const std::vector<base::NullableString16>& input,
+ std::vector<base::FilePath>* output) {
+ output->clear();
+ output->reserve(input.size());
+ for (size_t i = 0; i < input.size(); ++i)
+ output->push_back(ToFilePath(input[i]));
+}
+
+PageState ToPageState(const ExplodedPageState& state) {
+ std::string encoded_data;
+ if (!EncodePageState(state, &encoded_data))
+ return PageState();
+
+ return PageState::CreateFromEncodedData(encoded_data);
+}
+
+void RecursivelyRemovePasswordData(ExplodedFrameState* state) {
+ if (state->http_body.contains_passwords)
+ state->http_body = ExplodedHttpBody();
+}
+
+void RecursivelyRemoveScrollOffset(ExplodedFrameState* state) {
+ 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 state;
+
+ state.top.url_string = state.top.original_url_string =
+ ToNullableString16(url.possibly_invalid_spec());
+
+ return ToPageState(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 state;
+
+ state.top.url_string = state.top.original_url_string =
+ ToNullableString16(url.possibly_invalid_spec());
+
+ if (optional_body_data || optional_body_file_path) {
+ state.top.http_body.is_null = false;
+ if (optional_body_data) {
+ ExplodedHttpBodyElement element;
+ element.type = WebKit::WebHTTPBody::Element::TypeData;
+ element.data = optional_body_data;
+ state.top.http_body.elements.push_back(element);
+ }
+ if (optional_body_file_path) {
+ ExplodedHttpBodyElement element;
+ element.type = WebKit::WebHTTPBody::Element::TypeFile;
+ element.file_path =
+ ToNullableString16(optional_body_file_path->AsUTF8Unsafe());
+ state.top.http_body.elements.push_back(element);
+ state.referenced_files.push_back(element.file_path);
+ }
+ state.top.http_body.contains_passwords =
+ body_contains_password_data;
+ }
+
+ return ToPageState(state);
+}
+
PageState::PageState() {
}
@@ -26,6 +110,36 @@ const std::string& PageState::ToEncodedData() const {
return data_;
}
+std::vector<base::FilePath> PageState::GetReferencedFiles() const {
+ std::vector<base::FilePath> results;
+
+ ExplodedPageState state;
+ if (DecodePageState(data_, &state))
+ ToFilePathVector(state.referenced_files, &results);
+
+ return results;
+}
+
+PageState PageState::RemovePasswordData() const {
+ ExplodedPageState state;
+ if (!DecodePageState(data_, &state))
+ return PageState(); // Oops!
+
+ RecursivelyRemovePasswordData(&state.top);
+
+ return ToPageState(state);
+}
+
+PageState PageState::RemoveScrollOffset() const {
+ ExplodedPageState state;
+ if (!DecodePageState(data_, &state))
+ return PageState(); // Oops!
+
+ RecursivelyRemoveScrollOffset(&state.top);
+
+ return ToPageState(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