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(
23 base::PickleIterator
* iter
,
26 if (!ReadParam(m
, iter
, &has_object
))
29 *r
= new net::HttpResponseHeaders(iter
);
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()));
41 case storage::DataElement::TYPE_BYTES
: {
42 m
->WriteData(p
.bytes(), static_cast<int>(p
.length()));
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());
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());
59 case storage::DataElement::TYPE_BLOB
: {
60 WriteParam(m
, p
.blob_uuid());
61 WriteParam(m
, p
.offset());
62 WriteParam(m
, p
.length());
65 case storage::DataElement::TYPE_DISK_CACHE_ENTRY
: {
66 NOTREACHED() << "Can't be sent by IPC.";
69 case storage::DataElement::TYPE_UNKNOWN
: {
76 bool ParamTraits
<storage::DataElement
>::Read(const Message
* m
,
77 base::PickleIterator
* iter
,
80 if (!ReadParam(m
, iter
, &type
))
83 case storage::DataElement::TYPE_BYTES
: {
86 if (!iter
->ReadData(&data
, &len
))
88 r
->SetToBytes(data
, len
);
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
))
97 if (!ReadParam(m
, iter
, &offset
))
99 if (!ReadParam(m
, iter
, &length
))
101 if (!ReadParam(m
, iter
, &expected_modification_time
))
103 r
->SetToFilePathRange(file_path
, offset
, length
,
104 expected_modification_time
);
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
))
113 if (!ReadParam(m
, iter
, &offset
))
115 if (!ReadParam(m
, iter
, &length
))
117 if (!ReadParam(m
, iter
, &expected_modification_time
))
119 r
->SetToFileSystemUrlRange(file_system_url
, offset
, length
,
120 expected_modification_time
);
123 case storage::DataElement::TYPE_BLOB
: {
124 std::string blob_uuid
;
125 uint64 offset
, length
;
126 if (!ReadParam(m
, iter
, &blob_uuid
))
128 if (!ReadParam(m
, iter
, &offset
))
130 if (!ReadParam(m
, iter
, &length
))
132 r
->SetToBlobRange(blob_uuid
, offset
, length
);
135 case storage::DataElement::TYPE_DISK_CACHE_ENTRY
: {
136 NOTREACHED() << "Can't be sent by IPC.";
139 case storage::DataElement::TYPE_UNKNOWN
: {
147 void ParamTraits
<storage::DataElement
>::Log(const param_type
& p
,
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
);
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(
167 base::PickleIterator
* iter
,
170 if (!ReadParam(m
, iter
, &has_object
))
174 *r
= new content::ResourceDevToolsInfo();
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
) {
188 LogParam(p
->request_headers
, l
);
190 LogParam(p
->response_headers
, l
);
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())
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
,
221 if (!ReadParam(m
, iter
, &r
->socket_log_id
) ||
222 !ReadParam(m
, iter
, &r
->socket_reused
) ||
223 !ReadParam(m
, iter
, &has_no_times
)) {
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
,
248 LogParam(p
.socket_log_id
, l
);
250 LogParam(p
.socket_reused
, l
);
252 LogParam(p
.request_start_time
, l
);
254 LogParam(p
.request_start
, l
);
256 LogParam(p
.proxy_resolve_start
, l
);
258 LogParam(p
.proxy_resolve_end
, l
);
260 LogParam(p
.connect_timing
.dns_start
, l
);
262 LogParam(p
.connect_timing
.dns_end
, l
);
264 LogParam(p
.connect_timing
.connect_start
, l
);
266 LogParam(p
.connect_timing
.connect_end
, l
);
268 LogParam(p
.connect_timing
.ssl_start
, l
);
270 LogParam(p
.connect_timing
.ssl_end
, l
);
272 LogParam(p
.send_start
, l
);
274 LogParam(p
.send_end
, l
);
276 LogParam(p
.receive_headers_end
, l
);
280 void ParamTraits
<scoped_refptr
<content::ResourceRequestBody
> >::Write(
282 const param_type
& p
) {
283 WriteParam(m
, p
.get() != NULL
);
285 WriteParam(m
, *p
->elements());
286 WriteParam(m
, p
->identifier());
290 bool ParamTraits
<scoped_refptr
<content::ResourceRequestBody
>>::Read(
292 base::PickleIterator
* iter
,
295 if (!ReadParam(m
, iter
, &has_object
))
299 std::vector
<storage::DataElement
> elements
;
300 if (!ReadParam(m
, iter
, &elements
))
303 if (!ReadParam(m
, iter
, &identifier
))
305 *r
= new content::ResourceRequestBody
;
306 (*r
)->swap_elements(&elements
);
307 (*r
)->set_identifier(identifier
);
311 void ParamTraits
<scoped_refptr
<content::ResourceRequestBody
> >::Log(
312 const param_type
& p
, std::string
* l
) {
313 l
->append("<ResourceRequestBody>");