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());
60 DCHECK(p
.type() == storage::DataElement::TYPE_BLOB
);
61 WriteParam(m
, p
.blob_uuid());
62 WriteParam(m
, p
.offset());
63 WriteParam(m
, p
.length());
69 bool ParamTraits
<storage::DataElement
>::Read(const Message
* m
,
70 base::PickleIterator
* iter
,
73 if (!ReadParam(m
, iter
, &type
))
76 case storage::DataElement::TYPE_BYTES
: {
79 if (!iter
->ReadData(&data
, &len
))
81 r
->SetToBytes(data
, len
);
84 case storage::DataElement::TYPE_FILE
: {
85 base::FilePath file_path
;
86 uint64 offset
, length
;
87 base::Time expected_modification_time
;
88 if (!ReadParam(m
, iter
, &file_path
))
90 if (!ReadParam(m
, iter
, &offset
))
92 if (!ReadParam(m
, iter
, &length
))
94 if (!ReadParam(m
, iter
, &expected_modification_time
))
96 r
->SetToFilePathRange(file_path
, offset
, length
,
97 expected_modification_time
);
100 case storage::DataElement::TYPE_FILE_FILESYSTEM
: {
101 GURL file_system_url
;
102 uint64 offset
, length
;
103 base::Time expected_modification_time
;
104 if (!ReadParam(m
, iter
, &file_system_url
))
106 if (!ReadParam(m
, iter
, &offset
))
108 if (!ReadParam(m
, iter
, &length
))
110 if (!ReadParam(m
, iter
, &expected_modification_time
))
112 r
->SetToFileSystemUrlRange(file_system_url
, offset
, length
,
113 expected_modification_time
);
117 DCHECK(type
== storage::DataElement::TYPE_BLOB
);
118 std::string blob_uuid
;
119 uint64 offset
, length
;
120 if (!ReadParam(m
, iter
, &blob_uuid
))
122 if (!ReadParam(m
, iter
, &offset
))
124 if (!ReadParam(m
, iter
, &length
))
126 r
->SetToBlobRange(blob_uuid
, offset
, length
);
133 void ParamTraits
<storage::DataElement
>::Log(const param_type
& p
,
135 l
->append("<storage::DataElement>");
138 void ParamTraits
<scoped_refptr
<content::ResourceDevToolsInfo
> >::Write(
139 Message
* m
, const param_type
& p
) {
140 WriteParam(m
, p
.get() != NULL
);
142 WriteParam(m
, p
->http_status_code
);
143 WriteParam(m
, p
->http_status_text
);
144 WriteParam(m
, p
->request_headers
);
145 WriteParam(m
, p
->response_headers
);
146 WriteParam(m
, p
->request_headers_text
);
147 WriteParam(m
, p
->response_headers_text
);
151 bool ParamTraits
<scoped_refptr
<content::ResourceDevToolsInfo
>>::Read(
153 base::PickleIterator
* iter
,
156 if (!ReadParam(m
, iter
, &has_object
))
160 *r
= new content::ResourceDevToolsInfo();
162 ReadParam(m
, iter
, &(*r
)->http_status_code
) &&
163 ReadParam(m
, iter
, &(*r
)->http_status_text
) &&
164 ReadParam(m
, iter
, &(*r
)->request_headers
) &&
165 ReadParam(m
, iter
, &(*r
)->response_headers
) &&
166 ReadParam(m
, iter
, &(*r
)->request_headers_text
) &&
167 ReadParam(m
, iter
, &(*r
)->response_headers_text
);
170 void ParamTraits
<scoped_refptr
<content::ResourceDevToolsInfo
> >::Log(
171 const param_type
& p
, std::string
* l
) {
174 LogParam(p
->request_headers
, l
);
176 LogParam(p
->response_headers
, l
);
181 void ParamTraits
<net::LoadTimingInfo
>::Write(
182 Message
* m
, const param_type
& p
) {
183 WriteParam(m
, p
.socket_log_id
);
184 WriteParam(m
, p
.socket_reused
);
185 WriteParam(m
, p
.request_start_time
.is_null());
186 if (p
.request_start_time
.is_null())
188 WriteParam(m
, p
.request_start_time
);
189 WriteParam(m
, p
.request_start
);
190 WriteParam(m
, p
.proxy_resolve_start
);
191 WriteParam(m
, p
.proxy_resolve_end
);
192 WriteParam(m
, p
.connect_timing
.dns_start
);
193 WriteParam(m
, p
.connect_timing
.dns_end
);
194 WriteParam(m
, p
.connect_timing
.connect_start
);
195 WriteParam(m
, p
.connect_timing
.connect_end
);
196 WriteParam(m
, p
.connect_timing
.ssl_start
);
197 WriteParam(m
, p
.connect_timing
.ssl_end
);
198 WriteParam(m
, p
.send_start
);
199 WriteParam(m
, p
.send_end
);
200 WriteParam(m
, p
.receive_headers_end
);
203 bool ParamTraits
<net::LoadTimingInfo
>::Read(const Message
* m
,
204 base::PickleIterator
* iter
,
207 if (!ReadParam(m
, iter
, &r
->socket_log_id
) ||
208 !ReadParam(m
, iter
, &r
->socket_reused
) ||
209 !ReadParam(m
, iter
, &has_no_times
)) {
216 ReadParam(m
, iter
, &r
->request_start_time
) &&
217 ReadParam(m
, iter
, &r
->request_start
) &&
218 ReadParam(m
, iter
, &r
->proxy_resolve_start
) &&
219 ReadParam(m
, iter
, &r
->proxy_resolve_end
) &&
220 ReadParam(m
, iter
, &r
->connect_timing
.dns_start
) &&
221 ReadParam(m
, iter
, &r
->connect_timing
.dns_end
) &&
222 ReadParam(m
, iter
, &r
->connect_timing
.connect_start
) &&
223 ReadParam(m
, iter
, &r
->connect_timing
.connect_end
) &&
224 ReadParam(m
, iter
, &r
->connect_timing
.ssl_start
) &&
225 ReadParam(m
, iter
, &r
->connect_timing
.ssl_end
) &&
226 ReadParam(m
, iter
, &r
->send_start
) &&
227 ReadParam(m
, iter
, &r
->send_end
) &&
228 ReadParam(m
, iter
, &r
->receive_headers_end
);
231 void ParamTraits
<net::LoadTimingInfo
>::Log(const param_type
& p
,
234 LogParam(p
.socket_log_id
, l
);
236 LogParam(p
.socket_reused
, l
);
238 LogParam(p
.request_start_time
, l
);
240 LogParam(p
.request_start
, l
);
242 LogParam(p
.proxy_resolve_start
, l
);
244 LogParam(p
.proxy_resolve_end
, l
);
246 LogParam(p
.connect_timing
.dns_start
, l
);
248 LogParam(p
.connect_timing
.dns_end
, l
);
250 LogParam(p
.connect_timing
.connect_start
, l
);
252 LogParam(p
.connect_timing
.connect_end
, l
);
254 LogParam(p
.connect_timing
.ssl_start
, l
);
256 LogParam(p
.connect_timing
.ssl_end
, l
);
258 LogParam(p
.send_start
, l
);
260 LogParam(p
.send_end
, l
);
262 LogParam(p
.receive_headers_end
, l
);
266 void ParamTraits
<scoped_refptr
<content::ResourceRequestBody
> >::Write(
268 const param_type
& p
) {
269 WriteParam(m
, p
.get() != NULL
);
271 WriteParam(m
, *p
->elements());
272 WriteParam(m
, p
->identifier());
276 bool ParamTraits
<scoped_refptr
<content::ResourceRequestBody
>>::Read(
278 base::PickleIterator
* iter
,
281 if (!ReadParam(m
, iter
, &has_object
))
285 std::vector
<storage::DataElement
> elements
;
286 if (!ReadParam(m
, iter
, &elements
))
289 if (!ReadParam(m
, iter
, &identifier
))
291 *r
= new content::ResourceRequestBody
;
292 (*r
)->swap_elements(&elements
);
293 (*r
)->set_identifier(identifier
);
297 void ParamTraits
<scoped_refptr
<content::ResourceRequestBody
> >::Log(
298 const param_type
& p
, std::string
* l
) {
299 l
->append("<ResourceRequestBody>");