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"
12 void ParamTraits
<scoped_refptr
<net::HttpResponseHeaders
> >::Write(
13 Message
* m
, const param_type
& p
) {
14 WriteParam(m
, p
.get() != NULL
);
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
, PickleIterator
* iter
, param_type
* r
) {
24 if (!ReadParam(m
, iter
, &has_object
))
27 *r
= new net::HttpResponseHeaders(*m
, iter
);
31 void ParamTraits
<scoped_refptr
<net::HttpResponseHeaders
> >::Log(
32 const param_type
& p
, std::string
* l
) {
33 l
->append("<HttpResponseHeaders>");
36 void ParamTraits
<storage::DataElement
>::Write(Message
* m
, const param_type
& p
) {
37 WriteParam(m
, static_cast<int>(p
.type()));
39 case storage::DataElement::TYPE_BYTES
: {
40 m
->WriteData(p
.bytes(), static_cast<int>(p
.length()));
43 case storage::DataElement::TYPE_FILE
: {
44 WriteParam(m
, p
.path());
45 WriteParam(m
, p
.offset());
46 WriteParam(m
, p
.length());
47 WriteParam(m
, p
.expected_modification_time());
50 case storage::DataElement::TYPE_FILE_FILESYSTEM
: {
51 WriteParam(m
, p
.filesystem_url());
52 WriteParam(m
, p
.offset());
53 WriteParam(m
, p
.length());
54 WriteParam(m
, p
.expected_modification_time());
58 DCHECK(p
.type() == storage::DataElement::TYPE_BLOB
);
59 WriteParam(m
, p
.blob_uuid());
60 WriteParam(m
, p
.offset());
61 WriteParam(m
, p
.length());
67 bool ParamTraits
<storage::DataElement
>::Read(const Message
* m
,
71 if (!ReadParam(m
, iter
, &type
))
74 case storage::DataElement::TYPE_BYTES
: {
77 if (!m
->ReadData(iter
, &data
, &len
))
79 r
->SetToBytes(data
, len
);
82 case storage::DataElement::TYPE_FILE
: {
83 base::FilePath file_path
;
84 uint64 offset
, length
;
85 base::Time expected_modification_time
;
86 if (!ReadParam(m
, iter
, &file_path
))
88 if (!ReadParam(m
, iter
, &offset
))
90 if (!ReadParam(m
, iter
, &length
))
92 if (!ReadParam(m
, iter
, &expected_modification_time
))
94 r
->SetToFilePathRange(file_path
, offset
, length
,
95 expected_modification_time
);
98 case storage::DataElement::TYPE_FILE_FILESYSTEM
: {
100 uint64 offset
, length
;
101 base::Time expected_modification_time
;
102 if (!ReadParam(m
, iter
, &file_system_url
))
104 if (!ReadParam(m
, iter
, &offset
))
106 if (!ReadParam(m
, iter
, &length
))
108 if (!ReadParam(m
, iter
, &expected_modification_time
))
110 r
->SetToFileSystemUrlRange(file_system_url
, offset
, length
,
111 expected_modification_time
);
115 DCHECK(type
== storage::DataElement::TYPE_BLOB
);
116 std::string blob_uuid
;
117 uint64 offset
, length
;
118 if (!ReadParam(m
, iter
, &blob_uuid
))
120 if (!ReadParam(m
, iter
, &offset
))
122 if (!ReadParam(m
, iter
, &length
))
124 r
->SetToBlobRange(blob_uuid
, offset
, length
);
131 void ParamTraits
<storage::DataElement
>::Log(const param_type
& p
,
133 l
->append("<storage::DataElement>");
136 void ParamTraits
<scoped_refptr
<content::ResourceDevToolsInfo
> >::Write(
137 Message
* m
, const param_type
& p
) {
138 WriteParam(m
, p
.get() != NULL
);
140 WriteParam(m
, p
->http_status_code
);
141 WriteParam(m
, p
->http_status_text
);
142 WriteParam(m
, p
->request_headers
);
143 WriteParam(m
, p
->response_headers
);
144 WriteParam(m
, p
->request_headers_text
);
145 WriteParam(m
, p
->response_headers_text
);
149 bool ParamTraits
<scoped_refptr
<content::ResourceDevToolsInfo
> >::Read(
150 const Message
* m
, PickleIterator
* iter
, param_type
* r
) {
152 if (!ReadParam(m
, iter
, &has_object
))
156 *r
= new content::ResourceDevToolsInfo();
158 ReadParam(m
, iter
, &(*r
)->http_status_code
) &&
159 ReadParam(m
, iter
, &(*r
)->http_status_text
) &&
160 ReadParam(m
, iter
, &(*r
)->request_headers
) &&
161 ReadParam(m
, iter
, &(*r
)->response_headers
) &&
162 ReadParam(m
, iter
, &(*r
)->request_headers_text
) &&
163 ReadParam(m
, iter
, &(*r
)->response_headers_text
);
166 void ParamTraits
<scoped_refptr
<content::ResourceDevToolsInfo
> >::Log(
167 const param_type
& p
, std::string
* l
) {
170 LogParam(p
->request_headers
, l
);
172 LogParam(p
->response_headers
, l
);
177 void ParamTraits
<net::LoadTimingInfo
>::Write(
178 Message
* m
, const param_type
& p
) {
179 WriteParam(m
, p
.socket_log_id
);
180 WriteParam(m
, p
.socket_reused
);
181 WriteParam(m
, p
.request_start_time
.is_null());
182 if (p
.request_start_time
.is_null())
184 WriteParam(m
, p
.request_start_time
);
185 WriteParam(m
, p
.request_start
);
186 WriteParam(m
, p
.proxy_resolve_start
);
187 WriteParam(m
, p
.proxy_resolve_end
);
188 WriteParam(m
, p
.connect_timing
.dns_start
);
189 WriteParam(m
, p
.connect_timing
.dns_end
);
190 WriteParam(m
, p
.connect_timing
.connect_start
);
191 WriteParam(m
, p
.connect_timing
.connect_end
);
192 WriteParam(m
, p
.connect_timing
.ssl_start
);
193 WriteParam(m
, p
.connect_timing
.ssl_end
);
194 WriteParam(m
, p
.send_start
);
195 WriteParam(m
, p
.send_end
);
196 WriteParam(m
, p
.receive_headers_end
);
199 bool ParamTraits
<net::LoadTimingInfo
>::Read(
200 const Message
* m
, PickleIterator
* iter
, param_type
* r
) {
202 if (!ReadParam(m
, iter
, &r
->socket_log_id
) ||
203 !ReadParam(m
, iter
, &r
->socket_reused
) ||
204 !ReadParam(m
, iter
, &has_no_times
)) {
211 ReadParam(m
, iter
, &r
->request_start_time
) &&
212 ReadParam(m
, iter
, &r
->request_start
) &&
213 ReadParam(m
, iter
, &r
->proxy_resolve_start
) &&
214 ReadParam(m
, iter
, &r
->proxy_resolve_end
) &&
215 ReadParam(m
, iter
, &r
->connect_timing
.dns_start
) &&
216 ReadParam(m
, iter
, &r
->connect_timing
.dns_end
) &&
217 ReadParam(m
, iter
, &r
->connect_timing
.connect_start
) &&
218 ReadParam(m
, iter
, &r
->connect_timing
.connect_end
) &&
219 ReadParam(m
, iter
, &r
->connect_timing
.ssl_start
) &&
220 ReadParam(m
, iter
, &r
->connect_timing
.ssl_end
) &&
221 ReadParam(m
, iter
, &r
->send_start
) &&
222 ReadParam(m
, iter
, &r
->send_end
) &&
223 ReadParam(m
, iter
, &r
->receive_headers_end
);
226 void ParamTraits
<net::LoadTimingInfo
>::Log(const param_type
& p
,
229 LogParam(p
.socket_log_id
, l
);
231 LogParam(p
.socket_reused
, l
);
233 LogParam(p
.request_start_time
, l
);
235 LogParam(p
.request_start
, l
);
237 LogParam(p
.proxy_resolve_start
, l
);
239 LogParam(p
.proxy_resolve_end
, l
);
241 LogParam(p
.connect_timing
.dns_start
, l
);
243 LogParam(p
.connect_timing
.dns_end
, l
);
245 LogParam(p
.connect_timing
.connect_start
, l
);
247 LogParam(p
.connect_timing
.connect_end
, l
);
249 LogParam(p
.connect_timing
.ssl_start
, l
);
251 LogParam(p
.connect_timing
.ssl_end
, l
);
253 LogParam(p
.send_start
, l
);
255 LogParam(p
.send_end
, l
);
257 LogParam(p
.receive_headers_end
, l
);
261 void ParamTraits
<scoped_refptr
<content::ResourceRequestBody
> >::Write(
263 const param_type
& p
) {
264 WriteParam(m
, p
.get() != NULL
);
266 WriteParam(m
, *p
->elements());
267 WriteParam(m
, p
->identifier());
271 bool ParamTraits
<scoped_refptr
<content::ResourceRequestBody
> >::Read(
273 PickleIterator
* iter
,
276 if (!ReadParam(m
, iter
, &has_object
))
280 std::vector
<storage::DataElement
> elements
;
281 if (!ReadParam(m
, iter
, &elements
))
284 if (!ReadParam(m
, iter
, &identifier
))
286 *r
= new content::ResourceRequestBody
;
287 (*r
)->swap_elements(&elements
);
288 (*r
)->set_identifier(identifier
);
292 void ParamTraits
<scoped_refptr
<content::ResourceRequestBody
> >::Log(
293 const param_type
& p
, std::string
* l
) {
294 l
->append("<ResourceRequestBody>");