Removing uses of X11 native key events.
[chromium-blink-merge.git] / content / common / resource_messages.cc
blob1e7632db9ea7925423f22a7a9d584004e8fa5c51
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"
10 namespace IPC {
12 void ParamTraits<scoped_refptr<net::HttpResponseHeaders> >::Write(
13 Message* m, const param_type& p) {
14 WriteParam(m, p.get() != NULL);
15 if (p.get()) {
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) {
23 bool has_object;
24 if (!ReadParam(m, iter, &has_object))
25 return false;
26 if (has_object)
27 *r = new net::HttpResponseHeaders(*m, iter);
28 return true;
31 void ParamTraits<scoped_refptr<net::HttpResponseHeaders> >::Log(
32 const param_type& p, std::string* l) {
33 l->append("<HttpResponseHeaders>");
36 void ParamTraits<storage::DataElement>::Write(Message* m, const param_type& p) {
37 WriteParam(m, static_cast<int>(p.type()));
38 switch (p.type()) {
39 case storage::DataElement::TYPE_BYTES: {
40 m->WriteData(p.bytes(), static_cast<int>(p.length()));
41 break;
43 case storage::DataElement::TYPE_FILE: {
44 WriteParam(m, p.path());
45 WriteParam(m, p.offset());
46 WriteParam(m, p.length());
47 WriteParam(m, p.expected_modification_time());
48 break;
50 case storage::DataElement::TYPE_FILE_FILESYSTEM: {
51 WriteParam(m, p.filesystem_url());
52 WriteParam(m, p.offset());
53 WriteParam(m, p.length());
54 WriteParam(m, p.expected_modification_time());
55 break;
57 default: {
58 DCHECK(p.type() == storage::DataElement::TYPE_BLOB);
59 WriteParam(m, p.blob_uuid());
60 WriteParam(m, p.offset());
61 WriteParam(m, p.length());
62 break;
67 bool ParamTraits<storage::DataElement>::Read(const Message* m,
68 PickleIterator* iter,
69 param_type* r) {
70 int type;
71 if (!ReadParam(m, iter, &type))
72 return false;
73 switch (type) {
74 case storage::DataElement::TYPE_BYTES: {
75 const char* data;
76 int len;
77 if (!m->ReadData(iter, &data, &len))
78 return false;
79 r->SetToBytes(data, len);
80 break;
82 case storage::DataElement::TYPE_FILE: {
83 base::FilePath file_path;
84 uint64 offset, length;
85 base::Time expected_modification_time;
86 if (!ReadParam(m, iter, &file_path))
87 return false;
88 if (!ReadParam(m, iter, &offset))
89 return false;
90 if (!ReadParam(m, iter, &length))
91 return false;
92 if (!ReadParam(m, iter, &expected_modification_time))
93 return false;
94 r->SetToFilePathRange(file_path, offset, length,
95 expected_modification_time);
96 break;
98 case storage::DataElement::TYPE_FILE_FILESYSTEM: {
99 GURL file_system_url;
100 uint64 offset, length;
101 base::Time expected_modification_time;
102 if (!ReadParam(m, iter, &file_system_url))
103 return false;
104 if (!ReadParam(m, iter, &offset))
105 return false;
106 if (!ReadParam(m, iter, &length))
107 return false;
108 if (!ReadParam(m, iter, &expected_modification_time))
109 return false;
110 r->SetToFileSystemUrlRange(file_system_url, offset, length,
111 expected_modification_time);
112 break;
114 default: {
115 DCHECK(type == storage::DataElement::TYPE_BLOB);
116 std::string blob_uuid;
117 uint64 offset, length;
118 if (!ReadParam(m, iter, &blob_uuid))
119 return false;
120 if (!ReadParam(m, iter, &offset))
121 return false;
122 if (!ReadParam(m, iter, &length))
123 return false;
124 r->SetToBlobRange(blob_uuid, offset, length);
125 break;
128 return true;
131 void ParamTraits<storage::DataElement>::Log(const param_type& p,
132 std::string* l) {
133 l->append("<storage::DataElement>");
136 void ParamTraits<scoped_refptr<content::ResourceDevToolsInfo> >::Write(
137 Message* m, const param_type& p) {
138 WriteParam(m, p.get() != NULL);
139 if (p.get()) {
140 WriteParam(m, p->http_status_code);
141 WriteParam(m, p->http_status_text);
142 WriteParam(m, p->request_headers);
143 WriteParam(m, p->response_headers);
144 WriteParam(m, p->request_headers_text);
145 WriteParam(m, p->response_headers_text);
149 bool ParamTraits<scoped_refptr<content::ResourceDevToolsInfo> >::Read(
150 const Message* m, PickleIterator* iter, param_type* r) {
151 bool has_object;
152 if (!ReadParam(m, iter, &has_object))
153 return false;
154 if (!has_object)
155 return true;
156 *r = new content::ResourceDevToolsInfo();
157 return
158 ReadParam(m, iter, &(*r)->http_status_code) &&
159 ReadParam(m, iter, &(*r)->http_status_text) &&
160 ReadParam(m, iter, &(*r)->request_headers) &&
161 ReadParam(m, iter, &(*r)->response_headers) &&
162 ReadParam(m, iter, &(*r)->request_headers_text) &&
163 ReadParam(m, iter, &(*r)->response_headers_text);
166 void ParamTraits<scoped_refptr<content::ResourceDevToolsInfo> >::Log(
167 const param_type& p, std::string* l) {
168 l->append("(");
169 if (p.get()) {
170 LogParam(p->request_headers, l);
171 l->append(", ");
172 LogParam(p->response_headers, l);
174 l->append(")");
177 void ParamTraits<net::LoadTimingInfo>::Write(
178 Message* m, const param_type& p) {
179 WriteParam(m, p.socket_log_id);
180 WriteParam(m, p.socket_reused);
181 WriteParam(m, p.request_start_time.is_null());
182 if (p.request_start_time.is_null())
183 return;
184 WriteParam(m, p.request_start_time);
185 WriteParam(m, p.request_start);
186 WriteParam(m, p.proxy_resolve_start);
187 WriteParam(m, p.proxy_resolve_end);
188 WriteParam(m, p.connect_timing.dns_start);
189 WriteParam(m, p.connect_timing.dns_end);
190 WriteParam(m, p.connect_timing.connect_start);
191 WriteParam(m, p.connect_timing.connect_end);
192 WriteParam(m, p.connect_timing.ssl_start);
193 WriteParam(m, p.connect_timing.ssl_end);
194 WriteParam(m, p.send_start);
195 WriteParam(m, p.send_end);
196 WriteParam(m, p.receive_headers_end);
199 bool ParamTraits<net::LoadTimingInfo>::Read(
200 const Message* m, PickleIterator* iter, param_type* r) {
201 bool has_no_times;
202 if (!ReadParam(m, iter, &r->socket_log_id) ||
203 !ReadParam(m, iter, &r->socket_reused) ||
204 !ReadParam(m, iter, &has_no_times)) {
205 return false;
207 if (has_no_times)
208 return true;
210 return
211 ReadParam(m, iter, &r->request_start_time) &&
212 ReadParam(m, iter, &r->request_start) &&
213 ReadParam(m, iter, &r->proxy_resolve_start) &&
214 ReadParam(m, iter, &r->proxy_resolve_end) &&
215 ReadParam(m, iter, &r->connect_timing.dns_start) &&
216 ReadParam(m, iter, &r->connect_timing.dns_end) &&
217 ReadParam(m, iter, &r->connect_timing.connect_start) &&
218 ReadParam(m, iter, &r->connect_timing.connect_end) &&
219 ReadParam(m, iter, &r->connect_timing.ssl_start) &&
220 ReadParam(m, iter, &r->connect_timing.ssl_end) &&
221 ReadParam(m, iter, &r->send_start) &&
222 ReadParam(m, iter, &r->send_end) &&
223 ReadParam(m, iter, &r->receive_headers_end);
226 void ParamTraits<net::LoadTimingInfo>::Log(const param_type& p,
227 std::string* l) {
228 l->append("(");
229 LogParam(p.socket_log_id, l);
230 l->append(",");
231 LogParam(p.socket_reused, l);
232 l->append(",");
233 LogParam(p.request_start_time, l);
234 l->append(", ");
235 LogParam(p.request_start, l);
236 l->append(", ");
237 LogParam(p.proxy_resolve_start, l);
238 l->append(", ");
239 LogParam(p.proxy_resolve_end, l);
240 l->append(", ");
241 LogParam(p.connect_timing.dns_start, l);
242 l->append(", ");
243 LogParam(p.connect_timing.dns_end, l);
244 l->append(", ");
245 LogParam(p.connect_timing.connect_start, l);
246 l->append(", ");
247 LogParam(p.connect_timing.connect_end, l);
248 l->append(", ");
249 LogParam(p.connect_timing.ssl_start, l);
250 l->append(", ");
251 LogParam(p.connect_timing.ssl_end, l);
252 l->append(", ");
253 LogParam(p.send_start, l);
254 l->append(", ");
255 LogParam(p.send_end, l);
256 l->append(", ");
257 LogParam(p.receive_headers_end, l);
258 l->append(")");
261 void ParamTraits<scoped_refptr<content::ResourceRequestBody> >::Write(
262 Message* m,
263 const param_type& p) {
264 WriteParam(m, p.get() != NULL);
265 if (p.get()) {
266 WriteParam(m, *p->elements());
267 WriteParam(m, p->identifier());
271 bool ParamTraits<scoped_refptr<content::ResourceRequestBody> >::Read(
272 const Message* m,
273 PickleIterator* iter,
274 param_type* r) {
275 bool has_object;
276 if (!ReadParam(m, iter, &has_object))
277 return false;
278 if (!has_object)
279 return true;
280 std::vector<storage::DataElement> elements;
281 if (!ReadParam(m, iter, &elements))
282 return false;
283 int64 identifier;
284 if (!ReadParam(m, iter, &identifier))
285 return false;
286 *r = new content::ResourceRequestBody;
287 (*r)->swap_elements(&elements);
288 (*r)->set_identifier(identifier);
289 return true;
292 void ParamTraits<scoped_refptr<content::ResourceRequestBody> >::Log(
293 const param_type& p, std::string* l) {
294 l->append("<ResourceRequestBody>");
297 } // namespace IPC