| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/strings/nullable_string16.h" | 9 #include "base/strings/nullable_string16.h" |
| 10 #include "content/child/web_url_request_util.h" | 10 #include "content/child/web_url_request_util.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 using blink::WebString; | 27 using blink::WebString; |
| 28 using blink::WebVector; | 28 using blink::WebVector; |
| 29 | 29 |
| 30 namespace content { | 30 namespace content { |
| 31 namespace { | 31 namespace { |
| 32 | 32 |
| 33 void ToNullableString16Vector(const WebVector<WebString>& input, | 33 void ToNullableString16Vector(const WebVector<WebString>& input, |
| 34 std::vector<base::NullableString16>* output) { | 34 std::vector<base::NullableString16>* output) { |
| 35 output->reserve(output->size() + input.size()); | 35 output->reserve(output->size() + input.size()); |
| 36 for (size_t i = 0; i < input.size(); ++i) | 36 for (size_t i = 0; i < input.size(); ++i) |
| 37 output->push_back(input[i]); | 37 output->push_back(WebString::toNullableString16(input[i])); |
| 38 } | 38 } |
| 39 | 39 |
| 40 void GenerateFrameStateFromItem(const WebHistoryItem& item, | 40 void GenerateFrameStateFromItem(const WebHistoryItem& item, |
| 41 ExplodedFrameState* state) { | 41 ExplodedFrameState* state) { |
| 42 state->url_string = item.urlString(); | 42 state->url_string = WebString::toNullableString16(item.urlString()); |
| 43 state->referrer = item.referrer(); | 43 state->referrer = WebString::toNullableString16(item.referrer()); |
| 44 state->referrer_policy = item.getReferrerPolicy(); | 44 state->referrer_policy = item.getReferrerPolicy(); |
| 45 state->target = item.target(); | 45 state->target = WebString::toNullableString16(item.target()); |
| 46 if (!item.stateObject().isNull()) | 46 if (!item.stateObject().isNull()) { |
| 47 state->state_object = item.stateObject().toString(); | 47 state->state_object = |
| 48 WebString::toNullableString16(item.stateObject().toString()); |
| 49 } |
| 48 state->scroll_restoration_type = item.scrollRestorationType(); | 50 state->scroll_restoration_type = item.scrollRestorationType(); |
| 49 state->visual_viewport_scroll_offset = item.visualViewportScrollOffset(); | 51 state->visual_viewport_scroll_offset = item.visualViewportScrollOffset(); |
| 50 state->scroll_offset = item.getScrollOffset(); | 52 state->scroll_offset = item.getScrollOffset(); |
| 51 state->item_sequence_number = item.itemSequenceNumber(); | 53 state->item_sequence_number = item.itemSequenceNumber(); |
| 52 state->document_sequence_number = | 54 state->document_sequence_number = |
| 53 item.documentSequenceNumber(); | 55 item.documentSequenceNumber(); |
| 54 state->page_scale_factor = item.pageScaleFactor(); | 56 state->page_scale_factor = item.pageScaleFactor(); |
| 55 ToNullableString16Vector(item.getDocumentState(), &state->document_state); | 57 ToNullableString16Vector(item.getDocumentState(), &state->document_state); |
| 56 | 58 |
| 57 state->http_body.http_content_type = item.httpContentType(); | 59 state->http_body.http_content_type = |
| 60 WebString::toNullableString16(item.httpContentType()); |
| 58 const WebHTTPBody& http_body = item.httpBody(); | 61 const WebHTTPBody& http_body = item.httpBody(); |
| 59 if (!http_body.isNull()) { | 62 if (!http_body.isNull()) { |
| 60 state->http_body.request_body = GetRequestBodyForWebHTTPBody(http_body); | 63 state->http_body.request_body = GetRequestBodyForWebHTTPBody(http_body); |
| 61 state->http_body.contains_passwords = http_body.containsPasswordData(); | 64 state->http_body.contains_passwords = http_body.containsPasswordData(); |
| 62 } | 65 } |
| 63 } | 66 } |
| 64 | 67 |
| 65 void RecursivelyGenerateFrameState( | 68 void RecursivelyGenerateFrameState( |
| 66 HistoryEntry::HistoryNode* node, | 69 HistoryEntry::HistoryNode* node, |
| 67 ExplodedFrameState* state, | 70 ExplodedFrameState* state, |
| 68 std::vector<base::NullableString16>* referenced_files) { | 71 std::vector<base::NullableString16>* referenced_files) { |
| 69 GenerateFrameStateFromItem(node->item(), state); | 72 GenerateFrameStateFromItem(node->item(), state); |
| 70 ToNullableString16Vector(node->item().getReferencedFilePaths(), | 73 ToNullableString16Vector(node->item().getReferencedFilePaths(), |
| 71 referenced_files); | 74 referenced_files); |
| 72 | 75 |
| 73 std::vector<HistoryEntry::HistoryNode*>& children = node->children(); | 76 std::vector<HistoryEntry::HistoryNode*>& children = node->children(); |
| 74 state->children.resize(children.size()); | 77 state->children.resize(children.size()); |
| 75 for (size_t i = 0; i < children.size(); ++i) { | 78 for (size_t i = 0; i < children.size(); ++i) { |
| 76 RecursivelyGenerateFrameState(children[i], &state->children[i], | 79 RecursivelyGenerateFrameState(children[i], &state->children[i], |
| 77 referenced_files); | 80 referenced_files); |
| 78 } | 81 } |
| 79 } | 82 } |
| 80 | 83 |
| 81 void RecursivelyGenerateHistoryItem(const ExplodedFrameState& state, | 84 void RecursivelyGenerateHistoryItem(const ExplodedFrameState& state, |
| 82 HistoryEntry::HistoryNode* node) { | 85 HistoryEntry::HistoryNode* node) { |
| 83 WebHistoryItem item; | 86 WebHistoryItem item; |
| 84 item.initialize(); | 87 item.initialize(); |
| 85 item.setURLString(state.url_string); | 88 item.setURLString(WebString::fromUTF16(state.url_string)); |
| 86 item.setReferrer(state.referrer, state.referrer_policy); | 89 item.setReferrer(WebString::fromUTF16(state.referrer), state.referrer_policy); |
| 87 item.setTarget(state.target); | 90 item.setTarget(WebString::fromUTF16(state.target)); |
| 88 if (!state.state_object.is_null()) { | 91 if (!state.state_object.is_null()) { |
| 89 item.setStateObject( | 92 item.setStateObject(WebSerializedScriptValue::fromString( |
| 90 WebSerializedScriptValue::fromString(state.state_object)); | 93 WebString::fromUTF16(state.state_object))); |
| 91 } | 94 } |
| 92 item.setDocumentState(state.document_state); | 95 WebVector<WebString> document_state(state.document_state.size()); |
| 96 std::transform(state.document_state.begin(), state.document_state.end(), |
| 97 document_state.begin(), [](const base::NullableString16& s) { |
| 98 return WebString::fromUTF16(s); |
| 99 }); |
| 100 item.setDocumentState(document_state); |
| 93 item.setScrollRestorationType(state.scroll_restoration_type); | 101 item.setScrollRestorationType(state.scroll_restoration_type); |
| 94 item.setVisualViewportScrollOffset(state.visual_viewport_scroll_offset); | 102 item.setVisualViewportScrollOffset(state.visual_viewport_scroll_offset); |
| 95 item.setScrollOffset(state.scroll_offset); | 103 item.setScrollOffset(state.scroll_offset); |
| 96 item.setPageScaleFactor(state.page_scale_factor); | 104 item.setPageScaleFactor(state.page_scale_factor); |
| 97 | 105 |
| 98 // These values are generated at WebHistoryItem construction time, and we | 106 // These values are generated at WebHistoryItem construction time, and we |
| 99 // only want to override those new values with old values if the old values | 107 // only want to override those new values with old values if the old values |
| 100 // are defined. A value of 0 means undefined in this context. | 108 // are defined. A value of 0 means undefined in this context. |
| 101 if (state.item_sequence_number) | 109 if (state.item_sequence_number) |
| 102 item.setItemSequenceNumber(state.item_sequence_number); | 110 item.setItemSequenceNumber(state.item_sequence_number); |
| 103 if (state.document_sequence_number) | 111 if (state.document_sequence_number) |
| 104 item.setDocumentSequenceNumber(state.document_sequence_number); | 112 item.setDocumentSequenceNumber(state.document_sequence_number); |
| 105 | 113 |
| 106 item.setHTTPContentType(state.http_body.http_content_type); | 114 item.setHTTPContentType( |
| 115 WebString::fromUTF16(state.http_body.http_content_type)); |
| 107 if (state.http_body.request_body != nullptr) { | 116 if (state.http_body.request_body != nullptr) { |
| 108 item.setHTTPBody( | 117 item.setHTTPBody( |
| 109 GetWebHTTPBodyForRequestBody(state.http_body.request_body)); | 118 GetWebHTTPBodyForRequestBody(state.http_body.request_body)); |
| 110 } | 119 } |
| 111 node->set_item(item); | 120 node->set_item(item); |
| 112 | 121 |
| 113 for (size_t i = 0; i < state.children.size(); ++i) | 122 for (size_t i = 0; i < state.children.size(); ++i) |
| 114 RecursivelyGenerateHistoryItem(state.children[i], node->AddChild()); | 123 RecursivelyGenerateHistoryItem(state.children[i], node->AddChild()); |
| 115 } | 124 } |
| 116 | 125 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 143 if (!DecodePageState(page_state.ToEncodedData(), &state)) | 152 if (!DecodePageState(page_state.ToEncodedData(), &state)) |
| 144 return std::unique_ptr<HistoryEntry>(); | 153 return std::unique_ptr<HistoryEntry>(); |
| 145 | 154 |
| 146 std::unique_ptr<HistoryEntry> entry(new HistoryEntry()); | 155 std::unique_ptr<HistoryEntry> entry(new HistoryEntry()); |
| 147 RecursivelyGenerateHistoryItem(state.top, entry->root_history_node()); | 156 RecursivelyGenerateHistoryItem(state.top, entry->root_history_node()); |
| 148 | 157 |
| 149 return entry; | 158 return entry; |
| 150 } | 159 } |
| 151 | 160 |
| 152 } // namespace content | 161 } // namespace content |
| OLD | NEW |