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 "base/debug/alias.h"
8 #include "ipc/ipc_message.h"
9 #include "net/base/load_timing_info.h"
10 #include "net/http/http_response_headers.h"
13 // TODO(erikchen): Temporary code to help track http://crbug.com/527588.
14 void CheckContentsOfDataReceivedMessage(const IPC::Message
* message
) {
15 if (message
->type() != ResourceMsg_DataReceived::ID
)
17 ResourceMsg_DataReceived::Schema::Param arg
;
18 bool success
= ResourceMsg_DataReceived::Read(message
, &arg
);
20 int data_offset
= base::get
<1>(arg
);
21 CHECK_LE(data_offset
, 512 * 1024);
22 base::debug::Alias(&data_offset
);
28 void ParamTraits
<scoped_refptr
<net::HttpResponseHeaders
> >::Write(
29 Message
* m
, const param_type
& p
) {
30 WriteParam(m
, p
.get() != NULL
);
32 // Do not disclose Set-Cookie headers over IPC.
33 p
->Persist(m
, net::HttpResponseHeaders::PERSIST_SANS_COOKIES
);
37 bool ParamTraits
<scoped_refptr
<net::HttpResponseHeaders
>>::Read(
39 base::PickleIterator
* iter
,
42 if (!ReadParam(m
, iter
, &has_object
))
45 *r
= new net::HttpResponseHeaders(iter
);
49 void ParamTraits
<scoped_refptr
<net::HttpResponseHeaders
> >::Log(
50 const param_type
& p
, std::string
* l
) {
51 l
->append("<HttpResponseHeaders>");
54 void ParamTraits
<storage::DataElement
>::Write(Message
* m
, const param_type
& p
) {
55 WriteParam(m
, static_cast<int>(p
.type()));
57 case storage::DataElement::TYPE_BYTES
: {
58 m
->WriteData(p
.bytes(), static_cast<int>(p
.length()));
61 case storage::DataElement::TYPE_FILE
: {
62 WriteParam(m
, p
.path());
63 WriteParam(m
, p
.offset());
64 WriteParam(m
, p
.length());
65 WriteParam(m
, p
.expected_modification_time());
68 case storage::DataElement::TYPE_FILE_FILESYSTEM
: {
69 WriteParam(m
, p
.filesystem_url());
70 WriteParam(m
, p
.offset());
71 WriteParam(m
, p
.length());
72 WriteParam(m
, p
.expected_modification_time());
75 case storage::DataElement::TYPE_BLOB
: {
76 WriteParam(m
, p
.blob_uuid());
77 WriteParam(m
, p
.offset());
78 WriteParam(m
, p
.length());
81 case storage::DataElement::TYPE_DISK_CACHE_ENTRY
: {
82 NOTREACHED() << "Can't be sent by IPC.";
85 case storage::DataElement::TYPE_UNKNOWN
: {
92 bool ParamTraits
<storage::DataElement
>::Read(const Message
* m
,
93 base::PickleIterator
* iter
,
96 if (!ReadParam(m
, iter
, &type
))
99 case storage::DataElement::TYPE_BYTES
: {
102 if (!iter
->ReadData(&data
, &len
))
104 r
->SetToBytes(data
, len
);
107 case storage::DataElement::TYPE_FILE
: {
108 base::FilePath file_path
;
109 uint64 offset
, length
;
110 base::Time expected_modification_time
;
111 if (!ReadParam(m
, iter
, &file_path
))
113 if (!ReadParam(m
, iter
, &offset
))
115 if (!ReadParam(m
, iter
, &length
))
117 if (!ReadParam(m
, iter
, &expected_modification_time
))
119 r
->SetToFilePathRange(file_path
, offset
, length
,
120 expected_modification_time
);
123 case storage::DataElement::TYPE_FILE_FILESYSTEM
: {
124 GURL file_system_url
;
125 uint64 offset
, length
;
126 base::Time expected_modification_time
;
127 if (!ReadParam(m
, iter
, &file_system_url
))
129 if (!ReadParam(m
, iter
, &offset
))
131 if (!ReadParam(m
, iter
, &length
))
133 if (!ReadParam(m
, iter
, &expected_modification_time
))
135 r
->SetToFileSystemUrlRange(file_system_url
, offset
, length
,
136 expected_modification_time
);
139 case storage::DataElement::TYPE_BLOB
: {
140 std::string blob_uuid
;
141 uint64 offset
, length
;
142 if (!ReadParam(m
, iter
, &blob_uuid
))
144 if (!ReadParam(m
, iter
, &offset
))
146 if (!ReadParam(m
, iter
, &length
))
148 r
->SetToBlobRange(blob_uuid
, offset
, length
);
151 case storage::DataElement::TYPE_DISK_CACHE_ENTRY
: {
152 NOTREACHED() << "Can't be sent by IPC.";
155 case storage::DataElement::TYPE_UNKNOWN
: {
163 void ParamTraits
<storage::DataElement
>::Log(const param_type
& p
,
165 l
->append("<storage::DataElement>");
168 void ParamTraits
<scoped_refptr
<content::ResourceDevToolsInfo
> >::Write(
169 Message
* m
, const param_type
& p
) {
170 WriteParam(m
, p
.get() != NULL
);
172 WriteParam(m
, p
->http_status_code
);
173 WriteParam(m
, p
->http_status_text
);
174 WriteParam(m
, p
->request_headers
);
175 WriteParam(m
, p
->response_headers
);
176 WriteParam(m
, p
->request_headers_text
);
177 WriteParam(m
, p
->response_headers_text
);
181 bool ParamTraits
<scoped_refptr
<content::ResourceDevToolsInfo
>>::Read(
183 base::PickleIterator
* iter
,
186 if (!ReadParam(m
, iter
, &has_object
))
190 *r
= new content::ResourceDevToolsInfo();
192 ReadParam(m
, iter
, &(*r
)->http_status_code
) &&
193 ReadParam(m
, iter
, &(*r
)->http_status_text
) &&
194 ReadParam(m
, iter
, &(*r
)->request_headers
) &&
195 ReadParam(m
, iter
, &(*r
)->response_headers
) &&
196 ReadParam(m
, iter
, &(*r
)->request_headers_text
) &&
197 ReadParam(m
, iter
, &(*r
)->response_headers_text
);
200 void ParamTraits
<scoped_refptr
<content::ResourceDevToolsInfo
> >::Log(
201 const param_type
& p
, std::string
* l
) {
204 LogParam(p
->request_headers
, l
);
206 LogParam(p
->response_headers
, l
);
211 void ParamTraits
<net::LoadTimingInfo
>::Write(
212 Message
* m
, const param_type
& p
) {
213 WriteParam(m
, p
.socket_log_id
);
214 WriteParam(m
, p
.socket_reused
);
215 WriteParam(m
, p
.request_start_time
.is_null());
216 if (p
.request_start_time
.is_null())
218 WriteParam(m
, p
.request_start_time
);
219 WriteParam(m
, p
.request_start
);
220 WriteParam(m
, p
.proxy_resolve_start
);
221 WriteParam(m
, p
.proxy_resolve_end
);
222 WriteParam(m
, p
.connect_timing
.dns_start
);
223 WriteParam(m
, p
.connect_timing
.dns_end
);
224 WriteParam(m
, p
.connect_timing
.connect_start
);
225 WriteParam(m
, p
.connect_timing
.connect_end
);
226 WriteParam(m
, p
.connect_timing
.ssl_start
);
227 WriteParam(m
, p
.connect_timing
.ssl_end
);
228 WriteParam(m
, p
.send_start
);
229 WriteParam(m
, p
.send_end
);
230 WriteParam(m
, p
.receive_headers_end
);
233 bool ParamTraits
<net::LoadTimingInfo
>::Read(const Message
* m
,
234 base::PickleIterator
* iter
,
237 if (!ReadParam(m
, iter
, &r
->socket_log_id
) ||
238 !ReadParam(m
, iter
, &r
->socket_reused
) ||
239 !ReadParam(m
, iter
, &has_no_times
)) {
246 ReadParam(m
, iter
, &r
->request_start_time
) &&
247 ReadParam(m
, iter
, &r
->request_start
) &&
248 ReadParam(m
, iter
, &r
->proxy_resolve_start
) &&
249 ReadParam(m
, iter
, &r
->proxy_resolve_end
) &&
250 ReadParam(m
, iter
, &r
->connect_timing
.dns_start
) &&
251 ReadParam(m
, iter
, &r
->connect_timing
.dns_end
) &&
252 ReadParam(m
, iter
, &r
->connect_timing
.connect_start
) &&
253 ReadParam(m
, iter
, &r
->connect_timing
.connect_end
) &&
254 ReadParam(m
, iter
, &r
->connect_timing
.ssl_start
) &&
255 ReadParam(m
, iter
, &r
->connect_timing
.ssl_end
) &&
256 ReadParam(m
, iter
, &r
->send_start
) &&
257 ReadParam(m
, iter
, &r
->send_end
) &&
258 ReadParam(m
, iter
, &r
->receive_headers_end
);
261 void ParamTraits
<net::LoadTimingInfo
>::Log(const param_type
& p
,
264 LogParam(p
.socket_log_id
, l
);
266 LogParam(p
.socket_reused
, l
);
268 LogParam(p
.request_start_time
, l
);
270 LogParam(p
.request_start
, l
);
272 LogParam(p
.proxy_resolve_start
, l
);
274 LogParam(p
.proxy_resolve_end
, l
);
276 LogParam(p
.connect_timing
.dns_start
, l
);
278 LogParam(p
.connect_timing
.dns_end
, l
);
280 LogParam(p
.connect_timing
.connect_start
, l
);
282 LogParam(p
.connect_timing
.connect_end
, l
);
284 LogParam(p
.connect_timing
.ssl_start
, l
);
286 LogParam(p
.connect_timing
.ssl_end
, l
);
288 LogParam(p
.send_start
, l
);
290 LogParam(p
.send_end
, l
);
292 LogParam(p
.receive_headers_end
, l
);
296 void ParamTraits
<scoped_refptr
<content::ResourceRequestBody
> >::Write(
298 const param_type
& p
) {
299 WriteParam(m
, p
.get() != NULL
);
301 WriteParam(m
, *p
->elements());
302 WriteParam(m
, p
->identifier());
306 bool ParamTraits
<scoped_refptr
<content::ResourceRequestBody
>>::Read(
308 base::PickleIterator
* iter
,
311 if (!ReadParam(m
, iter
, &has_object
))
315 std::vector
<storage::DataElement
> elements
;
316 if (!ReadParam(m
, iter
, &elements
))
319 if (!ReadParam(m
, iter
, &identifier
))
321 *r
= new content::ResourceRequestBody
;
322 (*r
)->swap_elements(&elements
);
323 (*r
)->set_identifier(identifier
);
327 void ParamTraits
<scoped_refptr
<content::ResourceRequestBody
> >::Log(
328 const param_type
& p
, std::string
* l
) {
329 l
->append("<ResourceRequestBody>");