Roll src/third_party/WebKit eac3800:0237a66 (svn 202606:202607)
[chromium-blink-merge.git] / content / common / resource_messages.cc
blobc4169ba6454e6914ca29983f850b1bf75ccd8a70
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"
12 namespace content {
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)
16 return;
17 ResourceMsg_DataReceived::Schema::Param arg;
18 bool success = ResourceMsg_DataReceived::Read(message, &arg);
19 CHECK(success);
20 int data_offset = base::get<1>(arg);
21 CHECK_LE(data_offset, 512 * 1024);
22 base::debug::Alias(&data_offset);
26 namespace IPC {
28 void ParamTraits<scoped_refptr<net::HttpResponseHeaders> >::Write(
29 Message* m, const param_type& p) {
30 WriteParam(m, p.get() != NULL);
31 if (p.get()) {
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(
38 const Message* m,
39 base::PickleIterator* iter,
40 param_type* r) {
41 bool has_object;
42 if (!ReadParam(m, iter, &has_object))
43 return false;
44 if (has_object)
45 *r = new net::HttpResponseHeaders(iter);
46 return true;
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()));
56 switch (p.type()) {
57 case storage::DataElement::TYPE_BYTES: {
58 m->WriteData(p.bytes(), static_cast<int>(p.length()));
59 break;
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());
66 break;
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());
73 break;
75 case storage::DataElement::TYPE_BLOB: {
76 WriteParam(m, p.blob_uuid());
77 WriteParam(m, p.offset());
78 WriteParam(m, p.length());
79 break;
81 case storage::DataElement::TYPE_DISK_CACHE_ENTRY: {
82 NOTREACHED() << "Can't be sent by IPC.";
83 break;
85 case storage::DataElement::TYPE_UNKNOWN: {
86 NOTREACHED();
87 break;
92 bool ParamTraits<storage::DataElement>::Read(const Message* m,
93 base::PickleIterator* iter,
94 param_type* r) {
95 int type;
96 if (!ReadParam(m, iter, &type))
97 return false;
98 switch (type) {
99 case storage::DataElement::TYPE_BYTES: {
100 const char* data;
101 int len;
102 if (!iter->ReadData(&data, &len))
103 return false;
104 r->SetToBytes(data, len);
105 break;
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))
112 return false;
113 if (!ReadParam(m, iter, &offset))
114 return false;
115 if (!ReadParam(m, iter, &length))
116 return false;
117 if (!ReadParam(m, iter, &expected_modification_time))
118 return false;
119 r->SetToFilePathRange(file_path, offset, length,
120 expected_modification_time);
121 break;
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))
128 return false;
129 if (!ReadParam(m, iter, &offset))
130 return false;
131 if (!ReadParam(m, iter, &length))
132 return false;
133 if (!ReadParam(m, iter, &expected_modification_time))
134 return false;
135 r->SetToFileSystemUrlRange(file_system_url, offset, length,
136 expected_modification_time);
137 break;
139 case storage::DataElement::TYPE_BLOB: {
140 std::string blob_uuid;
141 uint64 offset, length;
142 if (!ReadParam(m, iter, &blob_uuid))
143 return false;
144 if (!ReadParam(m, iter, &offset))
145 return false;
146 if (!ReadParam(m, iter, &length))
147 return false;
148 r->SetToBlobRange(blob_uuid, offset, length);
149 break;
151 case storage::DataElement::TYPE_DISK_CACHE_ENTRY: {
152 NOTREACHED() << "Can't be sent by IPC.";
153 break;
155 case storage::DataElement::TYPE_UNKNOWN: {
156 NOTREACHED();
157 break;
160 return true;
163 void ParamTraits<storage::DataElement>::Log(const param_type& p,
164 std::string* l) {
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);
171 if (p.get()) {
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(
182 const Message* m,
183 base::PickleIterator* iter,
184 param_type* r) {
185 bool has_object;
186 if (!ReadParam(m, iter, &has_object))
187 return false;
188 if (!has_object)
189 return true;
190 *r = new content::ResourceDevToolsInfo();
191 return
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) {
202 l->append("(");
203 if (p.get()) {
204 LogParam(p->request_headers, l);
205 l->append(", ");
206 LogParam(p->response_headers, l);
208 l->append(")");
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())
217 return;
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,
235 param_type* r) {
236 bool has_no_times;
237 if (!ReadParam(m, iter, &r->socket_log_id) ||
238 !ReadParam(m, iter, &r->socket_reused) ||
239 !ReadParam(m, iter, &has_no_times)) {
240 return false;
242 if (has_no_times)
243 return true;
245 return
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,
262 std::string* l) {
263 l->append("(");
264 LogParam(p.socket_log_id, l);
265 l->append(",");
266 LogParam(p.socket_reused, l);
267 l->append(",");
268 LogParam(p.request_start_time, l);
269 l->append(", ");
270 LogParam(p.request_start, l);
271 l->append(", ");
272 LogParam(p.proxy_resolve_start, l);
273 l->append(", ");
274 LogParam(p.proxy_resolve_end, l);
275 l->append(", ");
276 LogParam(p.connect_timing.dns_start, l);
277 l->append(", ");
278 LogParam(p.connect_timing.dns_end, l);
279 l->append(", ");
280 LogParam(p.connect_timing.connect_start, l);
281 l->append(", ");
282 LogParam(p.connect_timing.connect_end, l);
283 l->append(", ");
284 LogParam(p.connect_timing.ssl_start, l);
285 l->append(", ");
286 LogParam(p.connect_timing.ssl_end, l);
287 l->append(", ");
288 LogParam(p.send_start, l);
289 l->append(", ");
290 LogParam(p.send_end, l);
291 l->append(", ");
292 LogParam(p.receive_headers_end, l);
293 l->append(")");
296 void ParamTraits<scoped_refptr<content::ResourceRequestBody> >::Write(
297 Message* m,
298 const param_type& p) {
299 WriteParam(m, p.get() != NULL);
300 if (p.get()) {
301 WriteParam(m, *p->elements());
302 WriteParam(m, p->identifier());
306 bool ParamTraits<scoped_refptr<content::ResourceRequestBody>>::Read(
307 const Message* m,
308 base::PickleIterator* iter,
309 param_type* r) {
310 bool has_object;
311 if (!ReadParam(m, iter, &has_object))
312 return false;
313 if (!has_object)
314 return true;
315 std::vector<storage::DataElement> elements;
316 if (!ReadParam(m, iter, &elements))
317 return false;
318 int64 identifier;
319 if (!ReadParam(m, iter, &identifier))
320 return false;
321 *r = new content::ResourceRequestBody;
322 (*r)->swap_elements(&elements);
323 (*r)->set_identifier(identifier);
324 return true;
327 void ParamTraits<scoped_refptr<content::ResourceRequestBody> >::Log(
328 const param_type& p, std::string* l) {
329 l->append("<ResourceRequestBody>");
332 } // namespace IPC