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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/content_tests.gypi ('k') | content/public/common/page_state_ios.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 "content/public/common/page_state.h" 5 #include "content/public/common/page_state.h"
6 6
7 #include "base/strings/utf_string_conversions.h"
8 #include "content/common/page_state_serialization.h"
9
7 namespace content { 10 namespace content {
11 namespace {
12
13 PageState ToPageState(const ExplodedPageState& exploded) {
14 std::string encoded_data;
15 if (!EncodePageState(exploded, &encoded_data))
16 return PageState();
17
18 return PageState::CreateFromEncodedData(encoded_data);
19 }
20
21 void RecursivelyRemovePasswordData(ExplodedFrameState* frame_state) {
22 if (frame_state->http_body.contains_passwords)
23 frame_state->http_body = ExplodedHttpBody();
24 }
25
26 void RecursivelyRemoveScrollOffset(ExplodedFrameState* frame_state) {
27 frame_state->scroll_offset = gfx::Point();
28 }
29
30 } // namespace
8 31
9 // static 32 // static
10 PageState PageState::CreateFromEncodedData(const std::string& data) { 33 PageState PageState::CreateFromEncodedData(const std::string& data) {
11 return PageState(data); 34 return PageState(data);
12 } 35 }
13 36
37 // static
38 PageState PageState::CreateFromURL(const GURL& url) {
39 ExplodedPageState exploded_page_state;
40
41 exploded_page_state.top.url_string =
42 exploded_page_state.top.original_url_string =
43 NullableString16(UTF8ToUTF16(url.possibly_invalid_spec()), false);
44
45 return ToPageState(exploded_page_state);
46 }
47
48 // static
49 PageState PageState::CreateForTesting(
50 const GURL& url,
51 bool body_contains_password_data,
52 const char* optional_body_data,
53 const base::FilePath* optional_body_file_path) {
54 ExplodedPageState exploded_page_state;
55
56 exploded_page_state.top.url_string =
57 exploded_page_state.top.original_url_string =
58 NullableString16(UTF8ToUTF16(url.possibly_invalid_spec()), false);
59
60 if (optional_body_data || optional_body_file_path) {
61 exploded_page_state.top.http_body.is_null = false;
62 if (optional_body_data) {
63 ExplodedHttpBodyElement element;
64 element.type = WebKit::WebHTTPBody::Element::TypeData;
65 element.data = optional_body_data;
66 exploded_page_state.top.http_body.elements.push_back(element);
67 }
68 if (optional_body_file_path) {
69 ExplodedHttpBodyElement element;
70 element.type = WebKit::WebHTTPBody::Element::TypeFile;
71 element.file_path = *optional_body_file_path;
72 exploded_page_state.top.http_body.elements.push_back(element);
73 exploded_page_state.referenced_files.push_back(*optional_body_file_path);
74 }
75 exploded_page_state.top.http_body.contains_passwords =
76 body_contains_password_data;
77 }
78
79 return ToPageState(exploded_page_state);
80 }
81
14 PageState::PageState() { 82 PageState::PageState() {
15 } 83 }
16 84
17 bool PageState::IsValid() const { 85 bool PageState::IsValid() const {
18 return !data_.empty(); 86 return !data_.empty();
19 } 87 }
20 88
21 bool PageState::Equals(const PageState& other) const { 89 bool PageState::Equals(const PageState& other) const {
22 return data_ == other.data_; 90 return data_ == other.data_;
23 } 91 }
24 92
25 const std::string& PageState::ToEncodedData() const { 93 const std::string& PageState::ToEncodedData() const {
26 return data_; 94 return data_;
27 } 95 }
28 96
97 std::vector<base::FilePath> PageState::GetReferencedFiles() const {
98 ExplodedPageState exploded_page_state;
99 if (!DecodePageState(data_, &exploded_page_state))
100 return std::vector<base::FilePath>();
101
102 return exploded_page_state.referenced_files;
103 }
104
105 PageState PageState::RemovePasswordData() const {
106 ExplodedPageState exploded_page_state;
107 if (!DecodePageState(data_, &exploded_page_state))
108 return PageState(); // Oops!
109
110 RecursivelyRemovePasswordData(&exploded_page_state.top);
111
112 return ToPageState(exploded_page_state);
113 }
114
115 PageState PageState::RemoveScrollOffset() const {
116 ExplodedPageState exploded_page_state;
117 if (!DecodePageState(data_, &exploded_page_state))
118 return PageState(); // Oops!
119
120 RecursivelyRemoveScrollOffset(&exploded_page_state.top);
121
122 return ToPageState(exploded_page_state);
123 }
124
29 PageState::PageState(const std::string& data) 125 PageState::PageState(const std::string& data)
30 : data_(data) { 126 : data_(data) {
31 // TODO(darin): Enable this DCHECK once tests have been fixed up to not pass 127 // TODO(darin): Enable this DCHECK once tests have been fixed up to not pass
32 // bogus encoded data to CreateFromEncodedData. 128 // bogus encoded data to CreateFromEncodedData.
33 //DCHECK(IsValid()); 129 //DCHECK(IsValid());
34 } 130 }
35 131
36 } // namespace content 132 } // namespace content
OLDNEW
« 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