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

Side by Side Diff: content/renderer/history_serialization.cc

Issue 1987053002: Deduplicating code performing WebHTTPBody::Element conversions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: s/data/test_body/g Created 4 years, 7 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
« no previous file with comments | « content/public/common/page_state.cc ('k') | content/renderer/http_body_conversions.h » ('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 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 "content/common/page_state_serialization.h" 10 #include "content/common/page_state_serialization.h"
10 #include "content/public/common/page_state.h" 11 #include "content/public/common/page_state.h"
11 #include "content/renderer/history_entry.h" 12 #include "content/renderer/history_entry.h"
13 #include "content/renderer/http_body_conversions.h"
14 #include "third_party/WebKit/public/platform/WebData.h"
12 #include "third_party/WebKit/public/platform/WebFloatPoint.h" 15 #include "third_party/WebKit/public/platform/WebFloatPoint.h"
13 #include "third_party/WebKit/public/platform/WebHTTPBody.h" 16 #include "third_party/WebKit/public/platform/WebHTTPBody.h"
14 #include "third_party/WebKit/public/platform/WebPoint.h" 17 #include "third_party/WebKit/public/platform/WebPoint.h"
15 #include "third_party/WebKit/public/platform/WebString.h" 18 #include "third_party/WebKit/public/platform/WebString.h"
16 #include "third_party/WebKit/public/platform/WebVector.h" 19 #include "third_party/WebKit/public/platform/WebVector.h"
17 #include "third_party/WebKit/public/web/WebHistoryItem.h" 20 #include "third_party/WebKit/public/web/WebHistoryItem.h"
18 #include "third_party/WebKit/public/web/WebSerializedScriptValue.h" 21 #include "third_party/WebKit/public/web/WebSerializedScriptValue.h"
19 22
23 using blink::WebData;
20 using blink::WebHTTPBody; 24 using blink::WebHTTPBody;
21 using blink::WebHistoryItem; 25 using blink::WebHistoryItem;
22 using blink::WebSerializedScriptValue; 26 using blink::WebSerializedScriptValue;
23 using blink::WebString; 27 using blink::WebString;
24 using blink::WebVector; 28 using blink::WebVector;
25 29
26 namespace content { 30 namespace content {
27 namespace { 31 namespace {
28 32
29 void ToNullableString16Vector(const WebVector<WebString>& input, 33 void ToNullableString16Vector(const WebVector<WebString>& input,
30 std::vector<base::NullableString16>* output) { 34 std::vector<base::NullableString16>* output) {
31 output->reserve(output->size() + input.size()); 35 output->reserve(output->size() + input.size());
32 for (size_t i = 0; i < input.size(); ++i) 36 for (size_t i = 0; i < input.size(); ++i)
33 output->push_back(input[i]); 37 output->push_back(input[i]);
34 } 38 }
35 39
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
86 void GenerateFrameStateFromItem(const WebHistoryItem& item, 40 void GenerateFrameStateFromItem(const WebHistoryItem& item,
87 ExplodedFrameState* state) { 41 ExplodedFrameState* state) {
88 state->url_string = item.urlString(); 42 state->url_string = item.urlString();
89 state->referrer = item.referrer(); 43 state->referrer = item.referrer();
90 state->referrer_policy = item.referrerPolicy(); 44 state->referrer_policy = item.referrerPolicy();
91 state->target = item.target(); 45 state->target = item.target();
92 if (!item.stateObject().isNull()) 46 if (!item.stateObject().isNull())
93 state->state_object = item.stateObject().toString(); 47 state->state_object = item.stateObject().toString();
94 state->scroll_restoration_type = item.scrollRestorationType(); 48 state->scroll_restoration_type = item.scrollRestorationType();
95 state->visual_viewport_scroll_offset = item.visualViewportScrollOffset(); 49 state->visual_viewport_scroll_offset = item.visualViewportScrollOffset();
96 state->scroll_offset = item.scrollOffset(); 50 state->scroll_offset = item.scrollOffset();
97 state->item_sequence_number = item.itemSequenceNumber(); 51 state->item_sequence_number = item.itemSequenceNumber();
98 state->document_sequence_number = 52 state->document_sequence_number =
99 item.documentSequenceNumber(); 53 item.documentSequenceNumber();
100 state->page_scale_factor = item.pageScaleFactor(); 54 state->page_scale_factor = item.pageScaleFactor();
101 ToNullableString16Vector(item.documentState(), &state->document_state); 55 ToNullableString16Vector(item.documentState(), &state->document_state);
102 56
103 state->http_body.http_content_type = item.httpContentType(); 57 state->http_body.http_content_type = item.httpContentType();
104 const WebHTTPBody& http_body = item.httpBody(); 58 const WebHTTPBody& http_body = item.httpBody();
105 state->http_body.is_null = http_body.isNull(); 59 state->http_body.is_null = http_body.isNull();
106 if (!state->http_body.is_null) { 60 if (!state->http_body.is_null) {
107 state->http_body.identifier = http_body.identifier(); 61 state->http_body.identifier = http_body.identifier();
108 state->http_body.elements.resize(http_body.elementCount()); 62 state->http_body.elements.resize(http_body.elementCount());
109 for (size_t i = 0; i < http_body.elementCount(); ++i) { 63 for (size_t i = 0; i < http_body.elementCount(); ++i) {
110 WebHTTPBody::Element element; 64 WebHTTPBody::Element element;
111 http_body.elementAt(i, element); 65 http_body.elementAt(i, element);
112 ToExplodedHttpBodyElement(element, &state->http_body.elements[i]); 66 ConvertToHttpBodyElement(element, &state->http_body.elements[i]);
113 } 67 }
114 state->http_body.contains_passwords = http_body.containsPasswordData(); 68 state->http_body.contains_passwords = http_body.containsPasswordData();
115 } 69 }
116 } 70 }
117 71
118 void RecursivelyGenerateFrameState( 72 void RecursivelyGenerateFrameState(
119 HistoryEntry::HistoryNode* node, 73 HistoryEntry::HistoryNode* node,
120 ExplodedFrameState* state, 74 ExplodedFrameState* state,
121 std::vector<base::NullableString16>* referenced_files) { 75 std::vector<base::NullableString16>* referenced_files) {
122 GenerateFrameStateFromItem(node->item(), state); 76 GenerateFrameStateFromItem(node->item(), state);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 item.setItemSequenceNumber(state.item_sequence_number); 109 item.setItemSequenceNumber(state.item_sequence_number);
156 if (state.document_sequence_number) 110 if (state.document_sequence_number)
157 item.setDocumentSequenceNumber(state.document_sequence_number); 111 item.setDocumentSequenceNumber(state.document_sequence_number);
158 112
159 item.setHTTPContentType(state.http_body.http_content_type); 113 item.setHTTPContentType(state.http_body.http_content_type);
160 if (!state.http_body.is_null) { 114 if (!state.http_body.is_null) {
161 WebHTTPBody http_body; 115 WebHTTPBody http_body;
162 http_body.initialize(); 116 http_body.initialize();
163 http_body.setIdentifier(state.http_body.identifier); 117 http_body.setIdentifier(state.http_body.identifier);
164 for (size_t i = 0; i < state.http_body.elements.size(); ++i) 118 for (size_t i = 0; i < state.http_body.elements.size(); ++i)
165 AppendHTTPBodyElement(state.http_body.elements[i], &http_body); 119 AppendHttpBodyElement(state.http_body.elements[i], &http_body);
166 item.setHTTPBody(http_body); 120 item.setHTTPBody(http_body);
167 } 121 }
168 node->set_item(item); 122 node->set_item(item);
169 123
170 for (size_t i = 0; i < state.children.size(); ++i) 124 for (size_t i = 0; i < state.children.size(); ++i)
171 RecursivelyGenerateHistoryItem(state.children[i], node->AddChild()); 125 RecursivelyGenerateHistoryItem(state.children[i], node->AddChild());
172 } 126 }
173 127
174 } // namespace 128 } // namespace
175 129
(...skipping 28 matching lines...) Expand all
204 if (!DecodePageState(page_state.ToEncodedData(), &state)) 158 if (!DecodePageState(page_state.ToEncodedData(), &state))
205 return std::unique_ptr<HistoryEntry>(); 159 return std::unique_ptr<HistoryEntry>();
206 160
207 std::unique_ptr<HistoryEntry> entry(new HistoryEntry()); 161 std::unique_ptr<HistoryEntry> entry(new HistoryEntry());
208 RecursivelyGenerateHistoryItem(state.top, entry->root_history_node()); 162 RecursivelyGenerateHistoryItem(state.top, entry->root_history_node());
209 163
210 return entry; 164 return entry;
211 } 165 }
212 166
213 } // namespace content 167 } // namespace content
OLDNEW
« no previous file with comments | « content/public/common/page_state.cc ('k') | content/renderer/http_body_conversions.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698