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>");
37 void ParamTraits
<webkit_common::DataElement
>::Write(
38 Message
* m
, const param_type
& p
) {
39 WriteParam(m
, static_cast<int>(p
.type()));
41 case webkit_common::DataElement::TYPE_BYTES
: {
42 m
->WriteData(p
.bytes(), static_cast<int>(p
.length()));
45 case webkit_common::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());
52 case webkit_common::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());
60 DCHECK(p
.type() == webkit_common::DataElement::TYPE_BLOB
);
61 WriteParam(m
, p
.blob_uuid());
62 WriteParam(m
, p
.offset());
63 WriteParam(m
, p
.length());
69 bool ParamTraits
<webkit_common::DataElement
>::Read(
70 const Message
* m
, PickleIterator
* iter
, param_type
* r
) {
72 if (!ReadParam(m
, iter
, &type
))
75 case webkit_common::DataElement::TYPE_BYTES
: {
78 if (!m
->ReadData(iter
, &data
, &len
))
80 r
->SetToBytes(data
, len
);
83 case webkit_common::DataElement::TYPE_FILE
: {
84 base::FilePath file_path
;
85 uint64 offset
, length
;
86 base::Time expected_modification_time
;
87 if (!ReadParam(m
, iter
, &file_path
))
89 if (!ReadParam(m
, iter
, &offset
))
91 if (!ReadParam(m
, iter
, &length
))
93 if (!ReadParam(m
, iter
, &expected_modification_time
))
95 r
->SetToFilePathRange(file_path
, offset
, length
,
96 expected_modification_time
);
99 case webkit_common::DataElement::TYPE_FILE_FILESYSTEM
: {
100 GURL file_system_url
;
101 uint64 offset
, length
;
102 base::Time expected_modification_time
;
103 if (!ReadParam(m
, iter
, &file_system_url
))
105 if (!ReadParam(m
, iter
, &offset
))
107 if (!ReadParam(m
, iter
, &length
))
109 if (!ReadParam(m
, iter
, &expected_modification_time
))
111 r
->SetToFileSystemUrlRange(file_system_url
, offset
, length
,
112 expected_modification_time
);
116 DCHECK(type
== webkit_common::DataElement::TYPE_BLOB
);
117 std::string blob_uuid
;
118 uint64 offset
, length
;
119 if (!ReadParam(m
, iter
, &blob_uuid
))
121 if (!ReadParam(m
, iter
, &offset
))
123 if (!ReadParam(m
, iter
, &length
))
125 r
->SetToBlobRange(blob_uuid
, offset
, length
);
132 void ParamTraits
<webkit_common::DataElement
>::Log(
133 const param_type
& p
, std::string
* l
) {
134 l
->append("<webkit_common::DataElement>");
137 void ParamTraits
<scoped_refptr
<webkit_glue::ResourceDevToolsInfo
> >::Write(
138 Message
* m
, const param_type
& p
) {
139 WriteParam(m
, p
.get() != NULL
);
141 WriteParam(m
, p
->http_status_code
);
142 WriteParam(m
, p
->http_status_text
);
143 WriteParam(m
, p
->request_headers
);
144 WriteParam(m
, p
->response_headers
);
145 WriteParam(m
, p
->request_headers_text
);
146 WriteParam(m
, p
->response_headers_text
);
150 bool ParamTraits
<scoped_refptr
<webkit_glue::ResourceDevToolsInfo
> >::Read(
151 const Message
* m
, PickleIterator
* iter
, param_type
* r
) {
153 if (!ReadParam(m
, iter
, &has_object
))
157 *r
= new webkit_glue::ResourceDevToolsInfo();
159 ReadParam(m
, iter
, &(*r
)->http_status_code
) &&
160 ReadParam(m
, iter
, &(*r
)->http_status_text
) &&
161 ReadParam(m
, iter
, &(*r
)->request_headers
) &&
162 ReadParam(m
, iter
, &(*r
)->response_headers
) &&
163 ReadParam(m
, iter
, &(*r
)->request_headers_text
) &&
164 ReadParam(m
, iter
, &(*r
)->response_headers_text
);
167 void ParamTraits
<scoped_refptr
<webkit_glue::ResourceDevToolsInfo
> >::Log(
168 const param_type
& p
, std::string
* l
) {
171 LogParam(p
->request_headers
, l
);
173 LogParam(p
->response_headers
, l
);
178 void ParamTraits
<net::LoadTimingInfo
>::Write(
179 Message
* m
, const param_type
& p
) {
180 WriteParam(m
, p
.socket_log_id
);
181 WriteParam(m
, p
.socket_reused
);
182 WriteParam(m
, p
.request_start_time
.is_null());
183 if (p
.request_start_time
.is_null())
185 WriteParam(m
, p
.request_start_time
);
186 WriteParam(m
, p
.request_start
);
187 WriteParam(m
, p
.proxy_resolve_start
);
188 WriteParam(m
, p
.proxy_resolve_end
);
189 WriteParam(m
, p
.connect_timing
.dns_start
);
190 WriteParam(m
, p
.connect_timing
.dns_end
);
191 WriteParam(m
, p
.connect_timing
.connect_start
);
192 WriteParam(m
, p
.connect_timing
.connect_end
);
193 WriteParam(m
, p
.connect_timing
.ssl_start
);
194 WriteParam(m
, p
.connect_timing
.ssl_end
);
195 WriteParam(m
, p
.send_start
);
196 WriteParam(m
, p
.send_end
);
197 WriteParam(m
, p
.receive_headers_end
);
200 bool ParamTraits
<net::LoadTimingInfo
>::Read(
201 const Message
* m
, PickleIterator
* iter
, param_type
* r
) {
203 if (!ReadParam(m
, iter
, &r
->socket_log_id
) ||
204 !ReadParam(m
, iter
, &r
->socket_reused
) ||
205 !ReadParam(m
, iter
, &has_no_times
)) {
212 ReadParam(m
, iter
, &r
->request_start_time
) &&
213 ReadParam(m
, iter
, &r
->request_start
) &&
214 ReadParam(m
, iter
, &r
->proxy_resolve_start
) &&
215 ReadParam(m
, iter
, &r
->proxy_resolve_end
) &&
216 ReadParam(m
, iter
, &r
->connect_timing
.dns_start
) &&
217 ReadParam(m
, iter
, &r
->connect_timing
.dns_end
) &&
218 ReadParam(m
, iter
, &r
->connect_timing
.connect_start
) &&
219 ReadParam(m
, iter
, &r
->connect_timing
.connect_end
) &&
220 ReadParam(m
, iter
, &r
->connect_timing
.ssl_start
) &&
221 ReadParam(m
, iter
, &r
->connect_timing
.ssl_end
) &&
222 ReadParam(m
, iter
, &r
->send_start
) &&
223 ReadParam(m
, iter
, &r
->send_end
) &&
224 ReadParam(m
, iter
, &r
->receive_headers_end
);
227 void ParamTraits
<net::LoadTimingInfo
>::Log(const param_type
& p
,
230 LogParam(p
.socket_log_id
, l
);
232 LogParam(p
.socket_reused
, l
);
234 LogParam(p
.request_start_time
, l
);
236 LogParam(p
.request_start
, l
);
238 LogParam(p
.proxy_resolve_start
, l
);
240 LogParam(p
.proxy_resolve_end
, l
);
242 LogParam(p
.connect_timing
.dns_start
, l
);
244 LogParam(p
.connect_timing
.dns_end
, l
);
246 LogParam(p
.connect_timing
.connect_start
, l
);
248 LogParam(p
.connect_timing
.connect_end
, l
);
250 LogParam(p
.connect_timing
.ssl_start
, l
);
252 LogParam(p
.connect_timing
.ssl_end
, l
);
254 LogParam(p
.send_start
, l
);
256 LogParam(p
.send_end
, l
);
258 LogParam(p
.receive_headers_end
, l
);
262 void ParamTraits
<scoped_refptr
<content::ResourceRequestBody
> >::Write(
264 const param_type
& p
) {
265 WriteParam(m
, p
.get() != NULL
);
267 WriteParam(m
, *p
->elements());
268 WriteParam(m
, p
->identifier());
272 bool ParamTraits
<scoped_refptr
<content::ResourceRequestBody
> >::Read(
274 PickleIterator
* iter
,
277 if (!ReadParam(m
, iter
, &has_object
))
281 std::vector
<webkit_common::DataElement
> elements
;
282 if (!ReadParam(m
, iter
, &elements
))
285 if (!ReadParam(m
, iter
, &identifier
))
287 *r
= new content::ResourceRequestBody
;
288 (*r
)->swap_elements(&elements
);
289 (*r
)->set_identifier(identifier
);
293 void ParamTraits
<scoped_refptr
<content::ResourceRequestBody
> >::Log(
294 const param_type
& p
, std::string
* l
) {
295 l
->append("<ResourceRequestBody>");