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

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

Issue 248013003: Remove WebHistoryItem child usage (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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 | Annotate | Revision Log
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 "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 "third_party/WebKit/public/platform/WebHTTPBody.h" 10 #include "third_party/WebKit/public/platform/WebHTTPBody.h"
10 #include "third_party/WebKit/public/platform/WebPoint.h" 11 #include "third_party/WebKit/public/platform/WebPoint.h"
11 #include "third_party/WebKit/public/platform/WebString.h" 12 #include "third_party/WebKit/public/platform/WebString.h"
12 #include "third_party/WebKit/public/platform/WebVector.h" 13 #include "third_party/WebKit/public/platform/WebVector.h"
13 #include "third_party/WebKit/public/web/WebHistoryItem.h" 14 #include "third_party/WebKit/public/web/WebHistoryItem.h"
14 #include "third_party/WebKit/public/web/WebSerializedScriptValue.h" 15 #include "third_party/WebKit/public/web/WebSerializedScriptValue.h"
15 16
16 using blink::WebHTTPBody; 17 using blink::WebHTTPBody;
17 using blink::WebHistoryItem; 18 using blink::WebHistoryItem;
18 using blink::WebSerializedScriptValue; 19 using blink::WebSerializedScriptValue;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 element.file_start, 73 element.file_start,
73 element.file_length, 74 element.file_length,
74 element.file_modification_time); 75 element.file_modification_time);
75 break; 76 break;
76 case WebHTTPBody::Element::TypeBlob: 77 case WebHTTPBody::Element::TypeBlob:
77 http_body->appendBlob(WebString::fromUTF8(element.blob_uuid)); 78 http_body->appendBlob(WebString::fromUTF8(element.blob_uuid));
78 break; 79 break;
79 } 80 }
80 } 81 }
81 82
82 bool RecursivelyGenerateFrameState(const WebHistoryItem& item, 83 void RecursivelyGenerateFrameState(HistoryEntry::HistoryNode* node,
Charlie Reis 2014/04/28 16:29:00 Just to be sure I'm clear why it's ok for this to
Nate Chapin 2014/04/28 17:31:54 Correct, we never returned false from either of th
83 ExplodedFrameState* state) { 84 ExplodedFrameState* state) {
85 const WebHistoryItem& item = node->item();
84 state->url_string = item.urlString(); 86 state->url_string = item.urlString();
85 state->referrer = item.referrer(); 87 state->referrer = item.referrer();
86 state->referrer_policy = item.referrerPolicy(); 88 state->referrer_policy = item.referrerPolicy();
87 state->target = item.target(); 89 state->target = item.target();
88 if (!item.stateObject().isNull()) 90 if (!item.stateObject().isNull())
89 state->state_object = item.stateObject().toString(); 91 state->state_object = item.stateObject().toString();
90 state->scroll_offset = item.scrollOffset(); 92 state->scroll_offset = item.scrollOffset();
91 state->item_sequence_number = item.itemSequenceNumber(); 93 state->item_sequence_number = item.itemSequenceNumber();
92 state->document_sequence_number = 94 state->document_sequence_number =
93 item.documentSequenceNumber(); 95 item.documentSequenceNumber();
94 state->page_scale_factor = item.pageScaleFactor(); 96 state->page_scale_factor = item.pageScaleFactor();
95 ToNullableString16Vector(item.documentState(), &state->document_state); 97 ToNullableString16Vector(item.documentState(), &state->document_state);
96 98
97 state->http_body.http_content_type = item.httpContentType(); 99 state->http_body.http_content_type = item.httpContentType();
98 const WebHTTPBody& http_body = item.httpBody(); 100 const WebHTTPBody& http_body = item.httpBody();
99 if (!(state->http_body.is_null = http_body.isNull())) { 101 if (!(state->http_body.is_null = http_body.isNull())) {
100 state->http_body.identifier = http_body.identifier(); 102 state->http_body.identifier = http_body.identifier();
101 state->http_body.elements.resize(http_body.elementCount()); 103 state->http_body.elements.resize(http_body.elementCount());
102 for (size_t i = 0; i < http_body.elementCount(); ++i) { 104 for (size_t i = 0; i < http_body.elementCount(); ++i) {
103 WebHTTPBody::Element element; 105 WebHTTPBody::Element element;
104 http_body.elementAt(i, element); 106 http_body.elementAt(i, element);
105 ToExplodedHttpBodyElement(element, &state->http_body.elements[i]); 107 ToExplodedHttpBodyElement(element, &state->http_body.elements[i]);
106 } 108 }
107 state->http_body.contains_passwords = http_body.containsPasswordData(); 109 state->http_body.contains_passwords = http_body.containsPasswordData();
108 } 110 }
109 111
110 const WebVector<WebHistoryItem>& children = item.children(); 112 std::vector<HistoryEntry::HistoryNode*>& children = node->children();
111 state->children.resize(children.size()); 113 state->children.resize(children.size());
112 for (size_t i = 0; i < children.size(); ++i) { 114 for (size_t i = 0; i < children.size(); ++i)
113 if (!RecursivelyGenerateFrameState(children[i], &state->children[i])) 115 RecursivelyGenerateFrameState(children[i], &state->children[i]);
114 return false;
115 }
116
117 return true;
118 } 116 }
119 117
120 bool RecursivelyGenerateHistoryItem(const ExplodedFrameState& state, 118 void RecursivelyGenerateHistoryItem(const ExplodedFrameState& state,
121 WebHistoryItem* item) { 119 HistoryEntry::HistoryNode* node) {
122 item->setURLString(state.url_string); 120 WebHistoryItem item;
123 item->setReferrer(state.referrer, state.referrer_policy); 121 item.initialize();
124 item->setTarget(state.target); 122 item.setURLString(state.url_string);
123 item.setReferrer(state.referrer, state.referrer_policy);
124 item.setTarget(state.target);
125 if (!state.state_object.is_null()) { 125 if (!state.state_object.is_null()) {
126 item->setStateObject( 126 item.setStateObject(
127 WebSerializedScriptValue::fromString(state.state_object)); 127 WebSerializedScriptValue::fromString(state.state_object));
128 } 128 }
129 item->setDocumentState(state.document_state); 129 item.setDocumentState(state.document_state);
130 item->setScrollOffset(state.scroll_offset); 130 item.setScrollOffset(state.scroll_offset);
131 item->setPageScaleFactor(state.page_scale_factor); 131 item.setPageScaleFactor(state.page_scale_factor);
132 132
133 // These values are generated at WebHistoryItem construction time, and we 133 // These values are generated at WebHistoryItem construction time, and we
134 // only want to override those new values with old values if the old values 134 // only want to override those new values with old values if the old values
135 // are defined. A value of 0 means undefined in this context. 135 // are defined. A value of 0 means undefined in this context.
136 if (state.item_sequence_number) 136 if (state.item_sequence_number)
137 item->setItemSequenceNumber(state.item_sequence_number); 137 item.setItemSequenceNumber(state.item_sequence_number);
138 if (state.document_sequence_number) 138 if (state.document_sequence_number)
139 item->setDocumentSequenceNumber(state.document_sequence_number); 139 item.setDocumentSequenceNumber(state.document_sequence_number);
140 140
141 item->setHTTPContentType(state.http_body.http_content_type); 141 item.setHTTPContentType(state.http_body.http_content_type);
142 if (!state.http_body.is_null) { 142 if (!state.http_body.is_null) {
143 WebHTTPBody http_body; 143 WebHTTPBody http_body;
144 http_body.initialize(); 144 http_body.initialize();
145 http_body.setIdentifier(state.http_body.identifier); 145 http_body.setIdentifier(state.http_body.identifier);
146 for (size_t i = 0; i < state.http_body.elements.size(); ++i) 146 for (size_t i = 0; i < state.http_body.elements.size(); ++i)
147 AppendHTTPBodyElement(state.http_body.elements[i], &http_body); 147 AppendHTTPBodyElement(state.http_body.elements[i], &http_body);
148 item->setHTTPBody(http_body); 148 item.setHTTPBody(http_body);
149 } 149 }
150 node->set_item(item);
150 151
151 for (size_t i = 0; i < state.children.size(); ++i) { 152 for (size_t i = 0; i < state.children.size(); ++i) {
152 WebHistoryItem child_item; 153 RecursivelyGenerateHistoryItem(state.children[i],
153 child_item.initialize(); 154 node->AddChild(WebHistoryItem(),
154 if (!RecursivelyGenerateHistoryItem(state.children[i], &child_item)) 155 kInvalidFrameRoutingID));
155 return false;
156 item->appendToChildren(child_item);
157 } 156 }
158
159 return true;
160 } 157 }
161 158
162 } // namespace 159 } // namespace
163 160
164 PageState HistoryItemToPageState(const WebHistoryItem& item) { 161 PageState HistoryEntryToPageState(HistoryEntry* entry) {
165 ExplodedPageState state; 162 ExplodedPageState state;
166 ToNullableString16Vector(item.getReferencedFilePaths(), 163 ToNullableString16Vector(entry->root().getReferencedFilePaths(),
167 &state.referenced_files); 164 &state.referenced_files);
168 165
169 if (!RecursivelyGenerateFrameState(item, &state.top)) 166 RecursivelyGenerateFrameState(entry->root_history_node(), &state.top);
170 return PageState();
171 167
172 std::string encoded_data; 168 std::string encoded_data;
173 if (!EncodePageState(state, &encoded_data)) 169 if (!EncodePageState(state, &encoded_data))
174 return PageState(); 170 return PageState();
175 171
176 return PageState::CreateFromEncodedData(encoded_data); 172 return PageState::CreateFromEncodedData(encoded_data);
177 } 173 }
178 174
179 WebHistoryItem PageStateToHistoryItem(const PageState& page_state) { 175 HistoryEntry* PageStateToHistoryEntry(const PageState& page_state,
176 int main_routing_id) {
Charlie Reis 2014/04/28 16:29:00 Just want to be sure I understand the reason for p
Nate Chapin 2014/04/28 17:31:54 Right. This trick might not be 100% necessary, it'
180 ExplodedPageState state; 177 ExplodedPageState state;
181 if (!DecodePageState(page_state.ToEncodedData(), &state)) 178 if (!DecodePageState(page_state.ToEncodedData(), &state))
182 return WebHistoryItem(); 179 return 0;
Charlie Reis 2014/04/28 16:29:00 NULL
Nate Chapin 2014/04/28 17:31:54 Done.
183 180
184 WebHistoryItem item; 181 HistoryEntry* entry = new HistoryEntry(WebHistoryItem(), main_routing_id);
185 item.initialize(); 182 RecursivelyGenerateHistoryItem(state.top, entry->root_history_node());
186 if (!RecursivelyGenerateHistoryItem(state.top, &item))
187 return WebHistoryItem();
188 183
189 return item; 184 return entry;
190 } 185 }
191 186
192 } // namespace content 187 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698