OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/renderer/history_serialization.h" | 5 #include "content/renderer/history_serialization.h" |
6 | 6 |
7 #include "content/common/page_state_serialization.h" | 7 #include "content/common/page_state_serialization.h" |
8 #include "content/public/common/page_state.h" | 8 #include "content/public/common/page_state.h" |
9 #include "content/renderer/history_entry.h" | 9 #include "content/renderer/history_entry.h" |
10 #include "third_party/WebKit/public/platform/WebFloatPoint.h" | 10 #include "third_party/WebKit/public/platform/WebFloatPoint.h" |
11 #include "third_party/WebKit/public/platform/WebHTTPBody.h" | 11 #include "third_party/WebKit/public/platform/WebHTTPBody.h" |
12 #include "third_party/WebKit/public/platform/WebPoint.h" | 12 #include "third_party/WebKit/public/platform/WebPoint.h" |
13 #include "third_party/WebKit/public/platform/WebString.h" | 13 #include "third_party/WebKit/public/platform/WebString.h" |
14 #include "third_party/WebKit/public/platform/WebVector.h" | 14 #include "third_party/WebKit/public/platform/WebVector.h" |
15 #include "third_party/WebKit/public/web/WebHistoryItem.h" | 15 #include "third_party/WebKit/public/web/WebHistoryItem.h" |
16 #include "third_party/WebKit/public/web/WebSerializedScriptValue.h" | 16 #include "third_party/WebKit/public/web/WebSerializedScriptValue.h" |
17 | 17 |
18 using blink::WebHTTPBody; | 18 using blink::WebHTTPBody; |
19 using blink::WebHistoryItem; | 19 using blink::WebHistoryItem; |
20 using blink::WebSerializedScriptValue; | 20 using blink::WebSerializedScriptValue; |
21 using blink::WebString; | 21 using blink::WebString; |
22 using blink::WebVector; | 22 using blink::WebVector; |
23 | 23 |
24 namespace content { | 24 namespace content { |
25 namespace { | 25 namespace { |
26 | 26 |
27 void ToNullableString16Vector(const WebVector<WebString>& input, | 27 void ToNullableString16Vector(const WebVector<WebString>& input, |
28 std::vector<base::NullableString16>* output) { | 28 std::vector<base::NullableString16>* output) { |
29 output->reserve(input.size()); | 29 output->reserve(output->size() + input.size()); |
30 for (size_t i = 0; i < input.size(); ++i) | 30 for (size_t i = 0; i < input.size(); ++i) |
31 output->push_back(input[i]); | 31 output->push_back(input[i]); |
32 } | 32 } |
33 | 33 |
34 void ToExplodedHttpBodyElement(const WebHTTPBody::Element& input, | 34 void ToExplodedHttpBodyElement(const WebHTTPBody::Element& input, |
35 ExplodedHttpBodyElement* output) { | 35 ExplodedHttpBodyElement* output) { |
36 switch (input.type) { | 36 switch (input.type) { |
37 case WebHTTPBody::Element::TypeData: | 37 case WebHTTPBody::Element::TypeData: |
38 output->data.assign(input.data.data(), input.data.size()); | 38 output->data.assign(input.data.data(), input.data.size()); |
39 break; | 39 break; |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 state->http_body.elements.resize(http_body.elementCount()); | 107 state->http_body.elements.resize(http_body.elementCount()); |
108 for (size_t i = 0; i < http_body.elementCount(); ++i) { | 108 for (size_t i = 0; i < http_body.elementCount(); ++i) { |
109 WebHTTPBody::Element element; | 109 WebHTTPBody::Element element; |
110 http_body.elementAt(i, element); | 110 http_body.elementAt(i, element); |
111 ToExplodedHttpBodyElement(element, &state->http_body.elements[i]); | 111 ToExplodedHttpBodyElement(element, &state->http_body.elements[i]); |
112 } | 112 } |
113 state->http_body.contains_passwords = http_body.containsPasswordData(); | 113 state->http_body.contains_passwords = http_body.containsPasswordData(); |
114 } | 114 } |
115 } | 115 } |
116 | 116 |
117 void RecursivelyGenerateFrameState(HistoryEntry::HistoryNode* node, | 117 void RecursivelyGenerateFrameState( |
118 ExplodedFrameState* state) { | 118 HistoryEntry::HistoryNode* node, |
| 119 ExplodedFrameState* state, |
| 120 std::vector<base::NullableString16>* referenced_files) { |
119 GenerateFrameStateFromItem(node->item(), state); | 121 GenerateFrameStateFromItem(node->item(), state); |
| 122 ToNullableString16Vector(node->item().getReferencedFilePaths(), |
| 123 referenced_files); |
120 | 124 |
121 std::vector<HistoryEntry::HistoryNode*>& children = node->children(); | 125 std::vector<HistoryEntry::HistoryNode*>& children = node->children(); |
122 state->children.resize(children.size()); | 126 state->children.resize(children.size()); |
123 for (size_t i = 0; i < children.size(); ++i) | 127 for (size_t i = 0; i < children.size(); ++i) { |
124 RecursivelyGenerateFrameState(children[i], &state->children[i]); | 128 RecursivelyGenerateFrameState(children[i], &state->children[i], |
| 129 referenced_files); |
| 130 } |
125 } | 131 } |
126 | 132 |
127 void RecursivelyGenerateHistoryItem(const ExplodedFrameState& state, | 133 void RecursivelyGenerateHistoryItem(const ExplodedFrameState& state, |
128 HistoryEntry::HistoryNode* node) { | 134 HistoryEntry::HistoryNode* node) { |
129 WebHistoryItem item; | 135 WebHistoryItem item; |
130 item.initialize(); | 136 item.initialize(); |
131 item.setURLString(state.url_string); | 137 item.setURLString(state.url_string); |
132 item.setReferrer(state.referrer, state.referrer_policy); | 138 item.setReferrer(state.referrer, state.referrer_policy); |
133 item.setTarget(state.target); | 139 item.setTarget(state.target); |
134 if (!state.state_object.is_null()) { | 140 if (!state.state_object.is_null()) { |
(...skipping 27 matching lines...) Expand all Loading... |
162 node->set_item(item); | 168 node->set_item(item); |
163 | 169 |
164 for (size_t i = 0; i < state.children.size(); ++i) | 170 for (size_t i = 0; i < state.children.size(); ++i) |
165 RecursivelyGenerateHistoryItem(state.children[i], node->AddChild()); | 171 RecursivelyGenerateHistoryItem(state.children[i], node->AddChild()); |
166 } | 172 } |
167 | 173 |
168 } // namespace | 174 } // namespace |
169 | 175 |
170 PageState HistoryEntryToPageState(HistoryEntry* entry) { | 176 PageState HistoryEntryToPageState(HistoryEntry* entry) { |
171 ExplodedPageState state; | 177 ExplodedPageState state; |
172 ToNullableString16Vector(entry->root().getReferencedFilePaths(), | 178 RecursivelyGenerateFrameState(entry->root_history_node(), &state.top, |
173 &state.referenced_files); | 179 &state.referenced_files); |
174 | |
175 RecursivelyGenerateFrameState(entry->root_history_node(), &state.top); | |
176 | 180 |
177 std::string encoded_data; | 181 std::string encoded_data; |
178 if (!EncodePageState(state, &encoded_data)) | 182 if (!EncodePageState(state, &encoded_data)) |
179 return PageState(); | 183 return PageState(); |
180 | 184 |
181 return PageState::CreateFromEncodedData(encoded_data); | 185 return PageState::CreateFromEncodedData(encoded_data); |
182 } | 186 } |
183 | 187 |
184 PageState SingleHistoryItemToPageState(const WebHistoryItem& item) { | 188 PageState SingleHistoryItemToPageState(const WebHistoryItem& item) { |
185 ExplodedPageState state; | 189 ExplodedPageState state; |
(...skipping 13 matching lines...) Expand all Loading... |
199 if (!DecodePageState(page_state.ToEncodedData(), &state)) | 203 if (!DecodePageState(page_state.ToEncodedData(), &state)) |
200 return scoped_ptr<HistoryEntry>(); | 204 return scoped_ptr<HistoryEntry>(); |
201 | 205 |
202 scoped_ptr<HistoryEntry> entry(new HistoryEntry()); | 206 scoped_ptr<HistoryEntry> entry(new HistoryEntry()); |
203 RecursivelyGenerateHistoryItem(state.top, entry->root_history_node()); | 207 RecursivelyGenerateHistoryItem(state.top, entry->root_history_node()); |
204 | 208 |
205 return entry.Pass(); | 209 return entry.Pass(); |
206 } | 210 } |
207 | 211 |
208 } // namespace content | 212 } // namespace content |
OLD | NEW |