Update V8 to version 4.7.42.
[chromium-blink-merge.git] / content / common / resource_messages.cc
blob9cadbfffd7f2cec29e134f80a85c27d49d851b96
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/common/resource_messages.h"
7 #include "net/base/load_timing_info.h"
8 #include "net/http/http_response_headers.h"
10 namespace IPC {
12 void ParamTraits<scoped_refptr<net::HttpResponseHeaders> >::Write(
13 Message* m, const param_type& p) {
14 WriteParam(m, p.get() != NULL);
15 if (p.get()) {
16 // Do not disclose Set-Cookie headers over IPC.
17 p->Persist(m, net::HttpResponseHeaders::PERSIST_SANS_COOKIES);
21 bool ParamTraits<scoped_refptr<net::HttpResponseHeaders>>::Read(
22 const Message* m,
23 base::PickleIterator* iter,
24 param_type* r) {
25 bool has_object;
26 if (!ReadParam(m, iter, &has_object))
27 return false;
28 if (has_object)
29 *r = new net::HttpResponseHeaders(iter);
30 return true;
33 void ParamTraits<scoped_refptr<net::HttpResponseHeaders> >::Log(
34 const param_type& p, std::string* l) {
35 l->append("<HttpResponseHeaders>");
38 void ParamTraits<storage::DataElement>::Write(Message* m, const param_type& p) {
39 WriteParam(m, static_cast<int>(p.type()));
40 switch (p.type()) {
41 case storage::DataElement::TYPE_BYTES: {
42 m->WriteData(p.bytes(), static_cast<int>(p.length()));
43 break;
45 case storage::DataElement::TYPE_FILE: {
46 WriteParam(m, p.path());
47 WriteParam(m, p.offset());
48 WriteParam(m, p.length());
49 WriteParam(m, p.expected_modification_time());
50 break;
52 case storage::DataElement::TYPE_FILE_FILESYSTEM: {
53 WriteParam(m, p.filesystem_url());
54 WriteParam(m, p.offset());
55 WriteParam(m, p.length());
56 WriteParam(m, p.expected_modification_time());
57 break;
59 case storage::DataElement::TYPE_BLOB: {
60 WriteParam(m, p.blob_uuid());
61 WriteParam(m, p.offset());
62 WriteParam(m, p.length());
63 break;
65 case storage::DataElement::TYPE_DISK_CACHE_ENTRY: {
66 NOTREACHED() << "Can't be sent by IPC.";
67 break;
69 case storage::DataElement::TYPE_UNKNOWN: {
70 NOTREACHED();
71 break;
76 bool ParamTraits<storage::DataElement>::Read(const Message* m,
77 base::PickleIterator* iter,
78 param_type* r) {
79 int type;
80 if (!ReadParam(m, iter, &type))
81 return false;
82 switch (type) {
83 case storage::DataElement::TYPE_BYTES: {
84 const char* data;
85 int len;
86 if (!iter->ReadData(&data, &len))
87 return false;
88 r->SetToBytes(data, len);
89 break;
91 case storage::DataElement::TYPE_FILE: {
92 base::FilePath file_path;
93 uint64 offset, length;
94 base::Time expected_modification_time;
95 if (!ReadParam(m, iter, &file_path))
96 return false;
97 if (!ReadParam(m, iter, &offset))
98 return false;
99 if (!ReadParam(m, iter, &length))
100 return false;
101 if (!ReadParam(m, iter, &expected_modification_time))
102 return false;
103 r->SetToFilePathRange(file_path, offset, length,
104 expected_modification_time);
105 break;
107 case storage::DataElement::TYPE_FILE_FILESYSTEM: {
108 GURL file_system_url;
109 uint64 offset, length;
110 base::Time expected_modification_time;
111 if (!ReadParam(m, iter, &file_system_url))
112 return false;
113 if (!ReadParam(m, iter, &offset))
114 return false;
115 if (!ReadParam(m, iter, &length))
116 return false;
117 if (!ReadParam(m, iter, &expected_modification_time))
118 return false;
119 r->SetToFileSystemUrlRange(file_system_url, offset, length,
120 expected_modification_time);
121 break;
123 case storage::DataElement::TYPE_BLOB: {
124 std::string blob_uuid;
125 uint64 offset, length;
126 if (!ReadParam(m, iter, &blob_uuid))
127 return false;
128 if (!ReadParam(m, iter, &offset))
129 return false;
130 if (!ReadParam(m, iter, &length))
131 return false;
132 r->SetToBlobRange(blob_uuid, offset, length);
133 break;
135 case storage::DataElement::TYPE_DISK_CACHE_ENTRY: {
136 NOTREACHED() << "Can't be sent by IPC.";
137 break;
139 case storage::DataElement::TYPE_UNKNOWN: {
140 NOTREACHED();
141 break;
144 return true;
147 void ParamTraits<storage::DataElement>::Log(const param_type& p,
148 std::string* l) {
149 l->append("<storage::DataElement>");
152 void ParamTraits<scoped_refptr<content::ResourceDevToolsInfo> >::Write(
153 Message* m, const param_type& p) {
154 WriteParam(m, p.get() != NULL);
155 if (p.get()) {
156 WriteParam(m, p->http_status_code);
157 WriteParam(m, p->http_status_text);
158 WriteParam(m, p->request_headers);
159 WriteParam(m, p->response_headers);
160 WriteParam(m, p->request_headers_text);
161 WriteParam(m, p->response_headers_text);
165 bool ParamTraits<scoped_refptr<content::ResourceDevToolsInfo>>::Read(
166 const Message* m,
167 base::PickleIterator* iter,
168 param_type* r) {
169 bool has_object;
170 if (!ReadParam(m, iter, &has_object))
171 return false;
172 if (!has_object)
173 return true;
174 *r = new content::ResourceDevToolsInfo();
175 return
176 ReadParam(m, iter, &(*r)->http_status_code) &&
177 ReadParam(m, iter, &(*r)->http_status_text) &&
178 ReadParam(m, iter, &(*r)->request_headers) &&
179 ReadParam(m, iter, &(*r)->response_headers) &&
180 ReadParam(m, iter, &(*r)->request_headers_text) &&
181 ReadParam(m, iter, &(*r)->response_headers_text);
184 void ParamTraits<scoped_refptr<content::ResourceDevToolsInfo> >::Log(
185 const param_type& p, std::string* l) {
186 l->append("(");
187 if (p.get()) {
188 LogParam(p->request_headers, l);
189 l->append(", ");
190 LogParam(p->response_headers, l);
192 l->append(")");
195 void ParamTraits<net::LoadTimingInfo>::Write(
196 Message* m, const param_type& p) {
197 WriteParam(m, p.socket_log_id);
198 WriteParam(m, p.socket_reused);
199 WriteParam(m, p.request_start_time.is_null());
200 if (p.request_start_time.is_null())
201 return;
202 WriteParam(m, p.request_start_time);
203 WriteParam(m, p.request_start);
204 WriteParam(m, p.proxy_resolve_start);
205 WriteParam(m, p.proxy_resolve_end);
206 WriteParam(m, p.connect_timing.dns_start);
207 WriteParam(m, p.connect_timing.dns_end);
208 WriteParam(m, p.connect_timing.connect_start);
209 WriteParam(m, p.connect_timing.connect_end);
210 WriteParam(m, p.connect_timing.ssl_start);
211 WriteParam(m, p.connect_timing.ssl_end);
212 WriteParam(m, p.send_start);
213 WriteParam(m, p.send_end);
214 WriteParam(m, p.receive_headers_end);
217 bool ParamTraits<net::LoadTimingInfo>::Read(const Message* m,
218 base::PickleIterator* iter,
219 param_type* r) {
220 bool has_no_times;
221 if (!ReadParam(m, iter, &r->socket_log_id) ||
222 !ReadParam(m, iter, &r->socket_reused) ||
223 !ReadParam(m, iter, &has_no_times)) {
224 return false;
226 if (has_no_times)
227 return true;
229 return
230 ReadParam(m, iter, &r->request_start_time) &&
231 ReadParam(m, iter, &r->request_start) &&
232 ReadParam(m, iter, &r->proxy_resolve_start) &&
233 ReadParam(m, iter, &r->proxy_resolve_end) &&
234 ReadParam(m, iter, &r->connect_timing.dns_start) &&
235 ReadParam(m, iter, &r->connect_timing.dns_end) &&
236 ReadParam(m, iter, &r->connect_timing.connect_start) &&
237 ReadParam(m, iter, &r->connect_timing.connect_end) &&
238 ReadParam(m, iter, &r->connect_timing.ssl_start) &&
239 ReadParam(m, iter, &r->connect_timing.ssl_end) &&
240 ReadParam(m, iter, &r->send_start) &&
241 ReadParam(m, iter, &r->send_end) &&
242 ReadParam(m, iter, &r->receive_headers_end);
245 void ParamTraits<net::LoadTimingInfo>::Log(const param_type& p,
246 std::string* l) {
247 l->append("(");
248 LogParam(p.socket_log_id, l);
249 l->append(",");
250 LogParam(p.socket_reused, l);
251 l->append(",");
252 LogParam(p.request_start_time, l);
253 l->append(", ");
254 LogParam(p.request_start, l);
255 l->append(", ");
256 LogParam(p.proxy_resolve_start, l);
257 l->append(", ");
258 LogParam(p.proxy_resolve_end, l);
259 l->append(", ");
260 LogParam(p.connect_timing.dns_start, l);
261 l->append(", ");
262 LogParam(p.connect_timing.dns_end, l);
263 l->append(", ");
264 LogParam(p.connect_timing.connect_start, l);
265 l->append(", ");
266 LogParam(p.connect_timing.connect_end, l);
267 l->append(", ");
268 LogParam(p.connect_timing.ssl_start, l);
269 l->append(", ");
270 LogParam(p.connect_timing.ssl_end, l);
271 l->append(", ");
272 LogParam(p.send_start, l);
273 l->append(", ");
274 LogParam(p.send_end, l);
275 l->append(", ");
276 LogParam(p.receive_headers_end, l);
277 l->append(")");
280 void ParamTraits<scoped_refptr<content::ResourceRequestBody> >::Write(
281 Message* m,
282 const param_type& p) {
283 WriteParam(m, p.get() != NULL);
284 if (p.get()) {
285 WriteParam(m, *p->elements());
286 WriteParam(m, p->identifier());
290 bool ParamTraits<scoped_refptr<content::ResourceRequestBody>>::Read(
291 const Message* m,
292 base::PickleIterator* iter,
293 param_type* r) {
294 bool has_object;
295 if (!ReadParam(m, iter, &has_object))
296 return false;
297 if (!has_object)
298 return true;
299 std::vector<storage::DataElement> elements;
300 if (!ReadParam(m, iter, &elements))
301 return false;
302 int64 identifier;
303 if (!ReadParam(m, iter, &identifier))
304 return false;
305 *r = new content::ResourceRequestBody;
306 (*r)->swap_elements(&elements);
307 (*r)->set_identifier(identifier);
308 return true;
311 void ParamTraits<scoped_refptr<content::ResourceRequestBody> >::Log(
312 const param_type& p, std::string* l) {
313 l->append("<ResourceRequestBody>");
316 } // namespace IPC