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" | |
10 #include "content/common/page_state_serialization.h" | 9 #include "content/common/page_state_serialization.h" |
11 #include "content/public/common/page_state.h" | 10 #include "content/public/common/page_state.h" |
12 #include "content/renderer/history_entry.h" | 11 #include "content/renderer/history_entry.h" |
13 #include "content/renderer/http_body_conversions.h" | |
14 #include "third_party/WebKit/public/platform/WebData.h" | |
15 #include "third_party/WebKit/public/platform/WebFloatPoint.h" | 12 #include "third_party/WebKit/public/platform/WebFloatPoint.h" |
16 #include "third_party/WebKit/public/platform/WebHTTPBody.h" | 13 #include "third_party/WebKit/public/platform/WebHTTPBody.h" |
17 #include "third_party/WebKit/public/platform/WebPoint.h" | 14 #include "third_party/WebKit/public/platform/WebPoint.h" |
18 #include "third_party/WebKit/public/platform/WebString.h" | 15 #include "third_party/WebKit/public/platform/WebString.h" |
19 #include "third_party/WebKit/public/platform/WebVector.h" | 16 #include "third_party/WebKit/public/platform/WebVector.h" |
20 #include "third_party/WebKit/public/web/WebHistoryItem.h" | 17 #include "third_party/WebKit/public/web/WebHistoryItem.h" |
21 #include "third_party/WebKit/public/web/WebSerializedScriptValue.h" | 18 #include "third_party/WebKit/public/web/WebSerializedScriptValue.h" |
22 | 19 |
23 using blink::WebData; | |
24 using blink::WebHTTPBody; | 20 using blink::WebHTTPBody; |
25 using blink::WebHistoryItem; | 21 using blink::WebHistoryItem; |
26 using blink::WebSerializedScriptValue; | 22 using blink::WebSerializedScriptValue; |
27 using blink::WebString; | 23 using blink::WebString; |
28 using blink::WebVector; | 24 using blink::WebVector; |
29 | 25 |
30 namespace content { | 26 namespace content { |
31 namespace { | 27 namespace { |
32 | 28 |
33 void ToNullableString16Vector(const WebVector<WebString>& input, | 29 void ToNullableString16Vector(const WebVector<WebString>& input, |
34 std::vector<base::NullableString16>* output) { | 30 std::vector<base::NullableString16>* output) { |
35 output->reserve(output->size() + input.size()); | 31 output->reserve(output->size() + input.size()); |
36 for (size_t i = 0; i < input.size(); ++i) | 32 for (size_t i = 0; i < input.size(); ++i) |
37 output->push_back(input[i]); | 33 output->push_back(input[i]); |
38 } | 34 } |
39 | 35 |
| 36 void ToExplodedHttpBodyElement(const WebHTTPBody::Element& input, |
| 37 ExplodedHttpBodyElement* output) { |
| 38 switch (input.type) { |
| 39 case WebHTTPBody::Element::TypeData: |
| 40 output->data.assign(input.data.data(), input.data.size()); |
| 41 break; |
| 42 case WebHTTPBody::Element::TypeFile: |
| 43 output->file_path = input.filePath; |
| 44 output->file_start = input.fileStart; |
| 45 output->file_length = input.fileLength; |
| 46 output->file_modification_time = input.modificationTime; |
| 47 break; |
| 48 case WebHTTPBody::Element::TypeFileSystemURL: |
| 49 output->filesystem_url = input.fileSystemURL; |
| 50 output->file_start = input.fileStart; |
| 51 output->file_length = input.fileLength; |
| 52 output->file_modification_time = input.modificationTime; |
| 53 break; |
| 54 case WebHTTPBody::Element::TypeBlob: |
| 55 output->blob_uuid = input.blobUUID.utf8(); |
| 56 break; |
| 57 } |
| 58 } |
| 59 |
| 60 void AppendHTTPBodyElement(const ExplodedHttpBodyElement& element, |
| 61 WebHTTPBody* http_body) { |
| 62 switch (element.type) { |
| 63 case WebHTTPBody::Element::TypeData: |
| 64 http_body->appendData(element.data); |
| 65 break; |
| 66 case WebHTTPBody::Element::TypeFile: |
| 67 http_body->appendFileRange( |
| 68 element.file_path, |
| 69 element.file_start, |
| 70 element.file_length, |
| 71 element.file_modification_time); |
| 72 break; |
| 73 case WebHTTPBody::Element::TypeFileSystemURL: |
| 74 http_body->appendFileSystemURLRange( |
| 75 element.filesystem_url, |
| 76 element.file_start, |
| 77 element.file_length, |
| 78 element.file_modification_time); |
| 79 break; |
| 80 case WebHTTPBody::Element::TypeBlob: |
| 81 http_body->appendBlob(WebString::fromUTF8(element.blob_uuid)); |
| 82 break; |
| 83 } |
| 84 } |
| 85 |
40 void GenerateFrameStateFromItem(const WebHistoryItem& item, | 86 void GenerateFrameStateFromItem(const WebHistoryItem& item, |
41 ExplodedFrameState* state) { | 87 ExplodedFrameState* state) { |
42 state->url_string = item.urlString(); | 88 state->url_string = item.urlString(); |
43 state->referrer = item.referrer(); | 89 state->referrer = item.referrer(); |
44 state->referrer_policy = item.referrerPolicy(); | 90 state->referrer_policy = item.referrerPolicy(); |
45 state->target = item.target(); | 91 state->target = item.target(); |
46 if (!item.stateObject().isNull()) | 92 if (!item.stateObject().isNull()) |
47 state->state_object = item.stateObject().toString(); | 93 state->state_object = item.stateObject().toString(); |
48 state->scroll_restoration_type = item.scrollRestorationType(); | 94 state->scroll_restoration_type = item.scrollRestorationType(); |
49 state->visual_viewport_scroll_offset = item.visualViewportScrollOffset(); | 95 state->visual_viewport_scroll_offset = item.visualViewportScrollOffset(); |
50 state->scroll_offset = item.scrollOffset(); | 96 state->scroll_offset = item.scrollOffset(); |
51 state->item_sequence_number = item.itemSequenceNumber(); | 97 state->item_sequence_number = item.itemSequenceNumber(); |
52 state->document_sequence_number = | 98 state->document_sequence_number = |
53 item.documentSequenceNumber(); | 99 item.documentSequenceNumber(); |
54 state->page_scale_factor = item.pageScaleFactor(); | 100 state->page_scale_factor = item.pageScaleFactor(); |
55 ToNullableString16Vector(item.documentState(), &state->document_state); | 101 ToNullableString16Vector(item.documentState(), &state->document_state); |
56 | 102 |
57 state->http_body.http_content_type = item.httpContentType(); | 103 state->http_body.http_content_type = item.httpContentType(); |
58 const WebHTTPBody& http_body = item.httpBody(); | 104 const WebHTTPBody& http_body = item.httpBody(); |
59 state->http_body.is_null = http_body.isNull(); | 105 state->http_body.is_null = http_body.isNull(); |
60 if (!state->http_body.is_null) { | 106 if (!state->http_body.is_null) { |
61 state->http_body.identifier = http_body.identifier(); | 107 state->http_body.identifier = http_body.identifier(); |
62 state->http_body.elements.resize(http_body.elementCount()); | 108 state->http_body.elements.resize(http_body.elementCount()); |
63 for (size_t i = 0; i < http_body.elementCount(); ++i) { | 109 for (size_t i = 0; i < http_body.elementCount(); ++i) { |
64 WebHTTPBody::Element element; | 110 WebHTTPBody::Element element; |
65 http_body.elementAt(i, element); | 111 http_body.elementAt(i, element); |
66 ConvertToHttpBodyElement(element, &state->http_body.elements[i]); | 112 ToExplodedHttpBodyElement(element, &state->http_body.elements[i]); |
67 } | 113 } |
68 state->http_body.contains_passwords = http_body.containsPasswordData(); | 114 state->http_body.contains_passwords = http_body.containsPasswordData(); |
69 } | 115 } |
70 } | 116 } |
71 | 117 |
72 void RecursivelyGenerateFrameState( | 118 void RecursivelyGenerateFrameState( |
73 HistoryEntry::HistoryNode* node, | 119 HistoryEntry::HistoryNode* node, |
74 ExplodedFrameState* state, | 120 ExplodedFrameState* state, |
75 std::vector<base::NullableString16>* referenced_files) { | 121 std::vector<base::NullableString16>* referenced_files) { |
76 GenerateFrameStateFromItem(node->item(), state); | 122 GenerateFrameStateFromItem(node->item(), state); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 item.setItemSequenceNumber(state.item_sequence_number); | 155 item.setItemSequenceNumber(state.item_sequence_number); |
110 if (state.document_sequence_number) | 156 if (state.document_sequence_number) |
111 item.setDocumentSequenceNumber(state.document_sequence_number); | 157 item.setDocumentSequenceNumber(state.document_sequence_number); |
112 | 158 |
113 item.setHTTPContentType(state.http_body.http_content_type); | 159 item.setHTTPContentType(state.http_body.http_content_type); |
114 if (!state.http_body.is_null) { | 160 if (!state.http_body.is_null) { |
115 WebHTTPBody http_body; | 161 WebHTTPBody http_body; |
116 http_body.initialize(); | 162 http_body.initialize(); |
117 http_body.setIdentifier(state.http_body.identifier); | 163 http_body.setIdentifier(state.http_body.identifier); |
118 for (size_t i = 0; i < state.http_body.elements.size(); ++i) | 164 for (size_t i = 0; i < state.http_body.elements.size(); ++i) |
119 AppendHttpBodyElement(state.http_body.elements[i], &http_body); | 165 AppendHTTPBodyElement(state.http_body.elements[i], &http_body); |
120 item.setHTTPBody(http_body); | 166 item.setHTTPBody(http_body); |
121 } | 167 } |
122 node->set_item(item); | 168 node->set_item(item); |
123 | 169 |
124 for (size_t i = 0; i < state.children.size(); ++i) | 170 for (size_t i = 0; i < state.children.size(); ++i) |
125 RecursivelyGenerateHistoryItem(state.children[i], node->AddChild()); | 171 RecursivelyGenerateHistoryItem(state.children[i], node->AddChild()); |
126 } | 172 } |
127 | 173 |
128 } // namespace | 174 } // namespace |
129 | 175 |
(...skipping 28 matching lines...) Expand all Loading... |
158 if (!DecodePageState(page_state.ToEncodedData(), &state)) | 204 if (!DecodePageState(page_state.ToEncodedData(), &state)) |
159 return std::unique_ptr<HistoryEntry>(); | 205 return std::unique_ptr<HistoryEntry>(); |
160 | 206 |
161 std::unique_ptr<HistoryEntry> entry(new HistoryEntry()); | 207 std::unique_ptr<HistoryEntry> entry(new HistoryEntry()); |
162 RecursivelyGenerateHistoryItem(state.top, entry->root_history_node()); | 208 RecursivelyGenerateHistoryItem(state.top, entry->root_history_node()); |
163 | 209 |
164 return entry; | 210 return entry; |
165 } | 211 } |
166 | 212 |
167 } // namespace content | 213 } // namespace content |
OLD | NEW |