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

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

Issue 2537953003: WebString: makes string16 conversions explicit (part 1: blink, content) (Closed)
Patch Set: fix Created 4 years 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/renderer/drop_data_builder.cc ('k') | content/renderer/manifest/manifest_parser.cc » ('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 #include <utility>
8 9
9 #include "base/strings/nullable_string16.h" 10 #include "base/strings/nullable_string16.h"
10 #include "content/child/web_url_request_util.h" 11 #include "content/child/web_url_request_util.h"
11 #include "content/common/page_state_serialization.h" 12 #include "content/common/page_state_serialization.h"
12 #include "content/public/common/page_state.h" 13 #include "content/public/common/page_state.h"
13 #include "content/renderer/history_entry.h" 14 #include "content/renderer/history_entry.h"
15 #include "third_party/WebKit/public/platform/StringVectorCopier.h"
14 #include "third_party/WebKit/public/platform/WebData.h" 16 #include "third_party/WebKit/public/platform/WebData.h"
15 #include "third_party/WebKit/public/platform/WebFloatPoint.h" 17 #include "third_party/WebKit/public/platform/WebFloatPoint.h"
16 #include "third_party/WebKit/public/platform/WebHTTPBody.h" 18 #include "third_party/WebKit/public/platform/WebHTTPBody.h"
17 #include "third_party/WebKit/public/platform/WebPoint.h" 19 #include "third_party/WebKit/public/platform/WebPoint.h"
18 #include "third_party/WebKit/public/platform/WebString.h" 20 #include "third_party/WebKit/public/platform/WebString.h"
19 #include "third_party/WebKit/public/platform/WebVector.h" 21 #include "third_party/WebKit/public/platform/WebVector.h"
20 #include "third_party/WebKit/public/web/WebHistoryItem.h" 22 #include "third_party/WebKit/public/web/WebHistoryItem.h"
21 #include "third_party/WebKit/public/web/WebSerializedScriptValue.h" 23 #include "third_party/WebKit/public/web/WebSerializedScriptValue.h"
22 24
23 using blink::WebData; 25 using blink::WebData;
24 using blink::WebHTTPBody; 26 using blink::WebHTTPBody;
25 using blink::WebHistoryItem; 27 using blink::WebHistoryItem;
26 using blink::WebSerializedScriptValue; 28 using blink::WebSerializedScriptValue;
27 using blink::WebString; 29 using blink::WebString;
28 using blink::WebVector; 30 using blink::WebVector;
29 31
30 namespace content { 32 namespace content {
31 namespace { 33 namespace {
32 34
33 void ToNullableString16Vector(const WebVector<WebString>& input, 35 void ToNullableString16Vector(const WebVector<WebString>& input,
34 std::vector<base::NullableString16>* output) { 36 std::vector<base::NullableString16>* output) {
35 output->reserve(output->size() + input.size()); 37 output->reserve(output->size() + input.size());
36 for (size_t i = 0; i < input.size(); ++i) 38 for (size_t i = 0; i < input.size(); ++i)
37 output->push_back(input[i]); 39 output->push_back(WebString::toNullableString16(input[i]));
38 } 40 }
39 41
40 void GenerateFrameStateFromItem(const WebHistoryItem& item, 42 void GenerateFrameStateFromItem(const WebHistoryItem& item,
41 ExplodedFrameState* state) { 43 ExplodedFrameState* state) {
42 state->url_string = item.urlString(); 44 state->url_string = WebString::toNullableString16(item.urlString());
43 state->referrer = item.referrer(); 45 state->referrer = WebString::toNullableString16(item.referrer());
44 state->referrer_policy = item.getReferrerPolicy(); 46 state->referrer_policy = item.getReferrerPolicy();
45 state->target = item.target(); 47 state->target = WebString::toNullableString16(item.target());
46 if (!item.stateObject().isNull()) 48 if (!item.stateObject().isNull()) {
47 state->state_object = item.stateObject().toString(); 49 state->state_object =
50 WebString::toNullableString16(item.stateObject().toString());
51 }
48 state->scroll_restoration_type = item.scrollRestorationType(); 52 state->scroll_restoration_type = item.scrollRestorationType();
49 state->visual_viewport_scroll_offset = item.visualViewportScrollOffset(); 53 state->visual_viewport_scroll_offset = item.visualViewportScrollOffset();
50 state->scroll_offset = item.getScrollOffset(); 54 state->scroll_offset = item.getScrollOffset();
51 state->item_sequence_number = item.itemSequenceNumber(); 55 state->item_sequence_number = item.itemSequenceNumber();
52 state->document_sequence_number = 56 state->document_sequence_number =
53 item.documentSequenceNumber(); 57 item.documentSequenceNumber();
54 state->page_scale_factor = item.pageScaleFactor(); 58 state->page_scale_factor = item.pageScaleFactor();
55 ToNullableString16Vector(item.documentState(), &state->document_state); 59 ToNullableString16Vector(item.documentState(), &state->document_state);
56 60
57 state->http_body.http_content_type = item.httpContentType(); 61 state->http_body.http_content_type =
62 WebString::toNullableString16(item.httpContentType());
58 const WebHTTPBody& http_body = item.httpBody(); 63 const WebHTTPBody& http_body = item.httpBody();
59 if (!http_body.isNull()) { 64 if (!http_body.isNull()) {
60 state->http_body.request_body = GetRequestBodyForWebHTTPBody(http_body); 65 state->http_body.request_body = GetRequestBodyForWebHTTPBody(http_body);
61 state->http_body.contains_passwords = http_body.containsPasswordData(); 66 state->http_body.contains_passwords = http_body.containsPasswordData();
62 } 67 }
63 } 68 }
64 69
65 void RecursivelyGenerateFrameState( 70 void RecursivelyGenerateFrameState(
66 HistoryEntry::HistoryNode* node, 71 HistoryEntry::HistoryNode* node,
67 ExplodedFrameState* state, 72 ExplodedFrameState* state,
68 std::vector<base::NullableString16>* referenced_files) { 73 std::vector<base::NullableString16>* referenced_files) {
69 GenerateFrameStateFromItem(node->item(), state); 74 GenerateFrameStateFromItem(node->item(), state);
70 ToNullableString16Vector(node->item().getReferencedFilePaths(), 75 ToNullableString16Vector(node->item().getReferencedFilePaths(),
71 referenced_files); 76 referenced_files);
72 77
73 std::vector<HistoryEntry::HistoryNode*>& children = node->children(); 78 std::vector<HistoryEntry::HistoryNode*>& children = node->children();
74 state->children.resize(children.size()); 79 state->children.resize(children.size());
75 for (size_t i = 0; i < children.size(); ++i) { 80 for (size_t i = 0; i < children.size(); ++i) {
76 RecursivelyGenerateFrameState(children[i], &state->children[i], 81 RecursivelyGenerateFrameState(children[i], &state->children[i],
77 referenced_files); 82 referenced_files);
78 } 83 }
79 } 84 }
80 85
81 void RecursivelyGenerateHistoryItem(const ExplodedFrameState& state, 86 void RecursivelyGenerateHistoryItem(const ExplodedFrameState& state,
82 HistoryEntry::HistoryNode* node) { 87 HistoryEntry::HistoryNode* node) {
83 WebHistoryItem item; 88 WebHistoryItem item;
84 item.initialize(); 89 item.initialize();
85 item.setURLString(state.url_string); 90 item.setURLString(WebString::fromUTF16(state.url_string));
86 item.setReferrer(state.referrer, state.referrer_policy); 91 item.setReferrer(WebString::fromUTF16(state.referrer), state.referrer_policy);
87 item.setTarget(state.target); 92 item.setTarget(WebString::fromUTF16(state.target));
88 if (!state.state_object.is_null()) { 93 if (!state.state_object.is_null()) {
89 item.setStateObject( 94 item.setStateObject(WebSerializedScriptValue::fromString(
90 WebSerializedScriptValue::fromString(state.state_object)); 95 WebString::fromUTF16(state.state_object)));
91 } 96 }
92 item.setDocumentState(state.document_state); 97 item.setDocumentState(blink::CopyStringVectorFromUTF16(state.document_state));
93 item.setScrollRestorationType(state.scroll_restoration_type); 98 item.setScrollRestorationType(state.scroll_restoration_type);
94 item.setVisualViewportScrollOffset(state.visual_viewport_scroll_offset); 99 item.setVisualViewportScrollOffset(state.visual_viewport_scroll_offset);
95 item.setScrollOffset(state.scroll_offset); 100 item.setScrollOffset(state.scroll_offset);
96 item.setPageScaleFactor(state.page_scale_factor); 101 item.setPageScaleFactor(state.page_scale_factor);
97 102
98 // These values are generated at WebHistoryItem construction time, and we 103 // 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 104 // 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. 105 // are defined. A value of 0 means undefined in this context.
101 if (state.item_sequence_number) 106 if (state.item_sequence_number)
102 item.setItemSequenceNumber(state.item_sequence_number); 107 item.setItemSequenceNumber(state.item_sequence_number);
103 if (state.document_sequence_number) 108 if (state.document_sequence_number)
104 item.setDocumentSequenceNumber(state.document_sequence_number); 109 item.setDocumentSequenceNumber(state.document_sequence_number);
105 110
106 item.setHTTPContentType(state.http_body.http_content_type); 111 item.setHTTPContentType(
112 WebString::fromUTF16(state.http_body.http_content_type));
107 if (state.http_body.request_body != nullptr) { 113 if (state.http_body.request_body != nullptr) {
108 item.setHTTPBody( 114 item.setHTTPBody(
109 GetWebHTTPBodyForRequestBody(state.http_body.request_body)); 115 GetWebHTTPBodyForRequestBody(state.http_body.request_body));
110 } 116 }
111 node->set_item(item); 117 node->set_item(item);
112 118
113 for (size_t i = 0; i < state.children.size(); ++i) 119 for (size_t i = 0; i < state.children.size(); ++i)
114 RecursivelyGenerateHistoryItem(state.children[i], node->AddChild()); 120 RecursivelyGenerateHistoryItem(state.children[i], node->AddChild());
115 } 121 }
116 122
(...skipping 26 matching lines...) Expand all
143 if (!DecodePageState(page_state.ToEncodedData(), &state)) 149 if (!DecodePageState(page_state.ToEncodedData(), &state))
144 return std::unique_ptr<HistoryEntry>(); 150 return std::unique_ptr<HistoryEntry>();
145 151
146 std::unique_ptr<HistoryEntry> entry(new HistoryEntry()); 152 std::unique_ptr<HistoryEntry> entry(new HistoryEntry());
147 RecursivelyGenerateHistoryItem(state.top, entry->root_history_node()); 153 RecursivelyGenerateHistoryItem(state.top, entry->root_history_node());
148 154
149 return entry; 155 return entry;
150 } 156 }
151 157
152 } // namespace content 158 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/drop_data_builder.cc ('k') | content/renderer/manifest/manifest_parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698