OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/public/common/common_param_traits.h" | 5 #include "content/public/common/common_param_traits.h" |
6 | 6 |
7 #include "content/public/common/content_constants.h" | 7 #include "content/public/common/content_constants.h" |
8 #include "content/public/common/referrer.h" | 8 #include "content/public/common/referrer.h" |
9 #include "net/base/host_port_pair.h" | 9 #include "net/base/host_port_pair.h" |
10 #include "net/base/upload_data.h" | 10 #include "net/base/upload_data.h" |
11 #include "net/http/http_response_headers.h" | 11 #include "net/http/http_response_headers.h" |
12 #include "third_party/skia/include/core/SkBitmap.h" | 12 #include "third_party/skia/include/core/SkBitmap.h" |
13 #include "ui/base/range/range.h" | 13 #include "ui/base/range/range.h" |
14 #include "ui/gfx/rect.h" | 14 #include "ui/gfx/rect.h" |
15 #include "ui/gfx/rect_f.h" | 15 #include "ui/gfx/rect_f.h" |
16 #include "webkit/glue/resource_request_body.h" | |
16 | 17 |
17 namespace { | 18 namespace { |
18 | 19 |
19 struct SkBitmap_Data { | 20 struct SkBitmap_Data { |
20 // The configuration for the bitmap (bits per pixel, etc). | 21 // The configuration for the bitmap (bits per pixel, etc). |
21 SkBitmap::Config fConfig; | 22 SkBitmap::Config fConfig; |
22 | 23 |
23 // The width of the bitmap in pixels. | 24 // The width of the bitmap in pixels. |
24 uint32 fWidth; | 25 uint32 fWidth; |
25 | 26 |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
120 l->append(", "); | 121 l->append(", "); |
121 LogParam(p.error(), l); | 122 LogParam(p.error(), l); |
122 l->append(")"); | 123 l->append(")"); |
123 } | 124 } |
124 } | 125 } |
125 | 126 |
126 // Only the net::UploadData ParamTraits<> definition needs this definition, so | 127 // Only the net::UploadData ParamTraits<> definition needs this definition, so |
127 // keep this in the implementation file so we can forward declare UploadData in | 128 // keep this in the implementation file so we can forward declare UploadData in |
128 // the header. | 129 // the header. |
129 template <> | 130 template <> |
130 struct ParamTraits<net::UploadData::Element> { | 131 struct ParamTraits<net::UploadData::Element> { |
darin (slow to review)
2012/08/15 17:49:55
Who still relies on UploadData serialization?
kinuko
2012/08/16 07:13:01
Looks like AutomationURLRequest still sends this o
kinuko
2012/08/16 08:14:59
...or if we could intercept before we create URLRe
| |
131 typedef net::UploadData::Element param_type; | 132 typedef net::UploadData::Element param_type; |
132 static void Write(Message* m, const param_type& p) { | 133 static void Write(Message* m, const param_type& p) { |
133 WriteParam(m, static_cast<int>(p.type())); | 134 WriteParam(m, static_cast<int>(p.type())); |
134 switch (p.type()) { | 135 switch (p.type()) { |
135 case net::UploadData::TYPE_BYTES: { | 136 case net::UploadData::TYPE_BYTES: { |
136 m->WriteData(&p.bytes()[0], static_cast<int>(p.bytes().size())); | 137 m->WriteData(p.bytes(), static_cast<int>(p.bytes_length())); |
137 break; | 138 break; |
138 } | 139 } |
139 case net::UploadData::TYPE_CHUNK: { | 140 case net::UploadData::TYPE_CHUNK: { |
140 std::string chunk_length = StringPrintf( | 141 std::string chunk_length = StringPrintf( |
141 "%X\r\n", static_cast<unsigned int>(p.bytes().size())); | 142 "%X\r\n", static_cast<unsigned int>(p.bytes_length())); |
142 std::vector<char> bytes; | 143 std::vector<char> bytes; |
143 bytes.insert(bytes.end(), chunk_length.data(), | 144 bytes.insert(bytes.end(), chunk_length.data(), |
144 chunk_length.data() + chunk_length.length()); | 145 chunk_length.data() + chunk_length.length()); |
145 const char* data = &p.bytes()[0]; | 146 const char* data = p.bytes(); |
146 bytes.insert(bytes.end(), data, data + p.bytes().size()); | 147 bytes.insert(bytes.end(), data, data + p.bytes_length()); |
147 const char* crlf = "\r\n"; | 148 const char* crlf = "\r\n"; |
148 bytes.insert(bytes.end(), crlf, crlf + strlen(crlf)); | 149 bytes.insert(bytes.end(), crlf, crlf + strlen(crlf)); |
149 if (p.is_last_chunk()) { | 150 if (p.is_last_chunk()) { |
150 const char* end_of_data = "0\r\n\r\n"; | 151 const char* end_of_data = "0\r\n\r\n"; |
151 bytes.insert(bytes.end(), end_of_data, | 152 bytes.insert(bytes.end(), end_of_data, |
152 end_of_data + strlen(end_of_data)); | 153 end_of_data + strlen(end_of_data)); |
153 } | 154 } |
154 m->WriteData(&bytes[0], static_cast<int>(bytes.size())); | 155 m->WriteData(&bytes[0], static_cast<int>(bytes.size())); |
155 // If this element is part of a chunk upload then send over information | 156 // If this element is part of a chunk upload then send over information |
156 // indicating if this is the last chunk. | 157 // indicating if this is the last chunk. |
157 WriteParam(m, p.is_last_chunk()); | 158 WriteParam(m, p.is_last_chunk()); |
158 break; | 159 break; |
159 } | 160 } |
160 case net::UploadData::TYPE_FILE: { | 161 default: { |
162 DCHECK(p.type() == net::UploadData::TYPE_FILE); | |
161 WriteParam(m, p.file_path()); | 163 WriteParam(m, p.file_path()); |
162 WriteParam(m, p.file_range_offset()); | 164 WriteParam(m, p.file_range_offset()); |
163 WriteParam(m, p.file_range_length()); | 165 WriteParam(m, p.file_range_length()); |
164 WriteParam(m, p.expected_file_modification_time()); | 166 WriteParam(m, p.expected_file_modification_time()); |
165 break; | 167 break; |
166 } | 168 } |
167 default: { | |
168 WriteParam(m, p.blob_url()); | |
169 break; | |
170 } | |
171 } | 169 } |
172 } | 170 } |
173 static bool Read(const Message* m, PickleIterator* iter, param_type* r) { | 171 static bool Read(const Message* m, PickleIterator* iter, param_type* r) { |
174 int type; | 172 int type; |
175 if (!ReadParam(m, iter, &type)) | 173 if (!ReadParam(m, iter, &type)) |
176 return false; | 174 return false; |
177 switch (type) { | 175 switch (type) { |
178 case net::UploadData::TYPE_BYTES: { | 176 case net::UploadData::TYPE_BYTES: { |
179 const char* data; | 177 const char* data; |
180 int len; | 178 int len; |
(...skipping 10 matching lines...) Expand all Loading... | |
191 r->SetToBytes(data, len); | 189 r->SetToBytes(data, len); |
192 // If this element is part of a chunk upload then we need to explicitly | 190 // If this element is part of a chunk upload then we need to explicitly |
193 // set the type of the element and whether it is the last chunk. | 191 // set the type of the element and whether it is the last chunk. |
194 bool is_last_chunk = false; | 192 bool is_last_chunk = false; |
195 if (!ReadParam(m, iter, &is_last_chunk)) | 193 if (!ReadParam(m, iter, &is_last_chunk)) |
196 return false; | 194 return false; |
197 r->set_type(net::UploadData::TYPE_CHUNK); | 195 r->set_type(net::UploadData::TYPE_CHUNK); |
198 r->set_is_last_chunk(is_last_chunk); | 196 r->set_is_last_chunk(is_last_chunk); |
199 break; | 197 break; |
200 } | 198 } |
201 case net::UploadData::TYPE_FILE: { | 199 default: { |
200 DCHECK(type == net::UploadData::TYPE_FILE); | |
202 FilePath file_path; | 201 FilePath file_path; |
203 uint64 offset, length; | 202 uint64 offset, length; |
204 base::Time expected_modification_time; | 203 base::Time expected_modification_time; |
205 if (!ReadParam(m, iter, &file_path)) | 204 if (!ReadParam(m, iter, &file_path)) |
206 return false; | 205 return false; |
207 if (!ReadParam(m, iter, &offset)) | 206 if (!ReadParam(m, iter, &offset)) |
208 return false; | 207 return false; |
209 if (!ReadParam(m, iter, &length)) | 208 if (!ReadParam(m, iter, &length)) |
210 return false; | 209 return false; |
211 if (!ReadParam(m, iter, &expected_modification_time)) | 210 if (!ReadParam(m, iter, &expected_modification_time)) |
212 return false; | 211 return false; |
213 r->SetToFilePathRange(file_path, offset, length, | 212 r->SetToFilePathRange(file_path, offset, length, |
214 expected_modification_time); | 213 expected_modification_time); |
215 break; | 214 break; |
216 } | 215 } |
217 default: { | |
218 DCHECK(type == net::UploadData::TYPE_BLOB); | |
219 GURL blob_url; | |
220 if (!ReadParam(m, iter, &blob_url)) | |
221 return false; | |
222 r->SetToBlobUrl(blob_url); | |
223 break; | |
224 } | |
225 } | 216 } |
226 return true; | 217 return true; |
227 } | 218 } |
228 static void Log(const param_type& p, std::string* l) { | 219 static void Log(const param_type& p, std::string* l) { |
229 l->append("<net::UploadData::Element>"); | 220 l->append("<net::UploadData::Element>"); |
230 } | 221 } |
231 }; | 222 }; |
232 | 223 |
233 void ParamTraits<scoped_refptr<net::UploadData> >::Write(Message* m, | 224 void ParamTraits<scoped_refptr<net::UploadData> >::Write(Message* m, |
234 const param_type& p) { | 225 const param_type& p) { |
(...skipping 27 matching lines...) Expand all Loading... | |
262 (*r)->set_identifier(identifier); | 253 (*r)->set_identifier(identifier); |
263 (*r)->set_is_chunked(is_chunked); | 254 (*r)->set_is_chunked(is_chunked); |
264 return true; | 255 return true; |
265 } | 256 } |
266 | 257 |
267 void ParamTraits<scoped_refptr<net::UploadData> >::Log(const param_type& p, | 258 void ParamTraits<scoped_refptr<net::UploadData> >::Log(const param_type& p, |
268 std::string* l) { | 259 std::string* l) { |
269 l->append("<net::UploadData>"); | 260 l->append("<net::UploadData>"); |
270 } | 261 } |
271 | 262 |
263 template <> | |
264 struct ParamTraits<webkit_glue::ResourceRequestBody::Element> { | |
265 typedef webkit_glue::ResourceRequestBody::Element param_type; | |
266 static void Write(Message* m, const param_type& p) { | |
267 WriteParam(m, static_cast<int>(p.type())); | |
268 switch (p.type()) { | |
269 case webkit_glue::ResourceRequestBody::TYPE_BYTES: { | |
270 m->WriteData(p.bytes(), static_cast<int>(p.bytes_length())); | |
271 break; | |
272 } | |
273 case webkit_glue::ResourceRequestBody::TYPE_FILE: { | |
274 WriteParam(m, p.file_path()); | |
275 WriteParam(m, p.file_range_offset()); | |
276 WriteParam(m, p.file_range_length()); | |
277 WriteParam(m, p.expected_file_modification_time()); | |
278 break; | |
279 } | |
280 default: { | |
281 WriteParam(m, p.blob_url()); | |
282 break; | |
283 } | |
284 } | |
285 } | |
286 static bool Read(const Message* m, PickleIterator* iter, param_type* r) { | |
287 int type; | |
288 if (!ReadParam(m, iter, &type)) | |
289 return false; | |
290 switch (type) { | |
291 case webkit_glue::ResourceRequestBody::TYPE_BYTES: { | |
292 const char* data; | |
293 int len; | |
294 if (!m->ReadData(iter, &data, &len)) | |
295 return false; | |
296 r->SetToBytes(data, len); | |
297 break; | |
298 } | |
299 case webkit_glue::ResourceRequestBody::TYPE_FILE: { | |
300 FilePath file_path; | |
301 uint64 offset, length; | |
302 base::Time expected_modification_time; | |
303 if (!ReadParam(m, iter, &file_path)) | |
304 return false; | |
305 if (!ReadParam(m, iter, &offset)) | |
306 return false; | |
307 if (!ReadParam(m, iter, &length)) | |
308 return false; | |
309 if (!ReadParam(m, iter, &expected_modification_time)) | |
310 return false; | |
311 r->SetToFilePathRange(file_path, offset, length, | |
312 expected_modification_time); | |
313 break; | |
314 } | |
315 default: { | |
316 DCHECK(type == webkit_glue::ResourceRequestBody::TYPE_BLOB); | |
317 GURL blob_url; | |
318 if (!ReadParam(m, iter, &blob_url)) | |
319 return false; | |
320 r->SetToBlobUrl(blob_url); | |
321 break; | |
322 } | |
323 } | |
324 return true; | |
325 } | |
326 static void Log(const param_type& p, std::string* l) { | |
327 l->append("<webkit_glue::ResourceRequestBody::Element>"); | |
328 } | |
329 }; | |
330 | |
331 void ParamTraits<scoped_refptr<webkit_glue::ResourceRequestBody> >::Write( | |
332 Message* m, | |
333 const param_type& p) { | |
334 WriteParam(m, p.get() != NULL); | |
335 if (p) { | |
336 WriteParam(m, *p->elements()); | |
337 WriteParam(m, p->identifier()); | |
338 } | |
339 } | |
340 | |
341 bool ParamTraits<scoped_refptr<webkit_glue::ResourceRequestBody> >::Read( | |
342 const Message* m, | |
343 PickleIterator* iter, | |
344 param_type* r) { | |
345 bool has_object; | |
346 if (!ReadParam(m, iter, &has_object)) | |
347 return false; | |
348 if (!has_object) | |
349 return true; | |
350 std::vector<webkit_glue::ResourceRequestBody::Element> elements; | |
351 if (!ReadParam(m, iter, &elements)) | |
352 return false; | |
353 int64 identifier; | |
354 if (!ReadParam(m, iter, &identifier)) | |
355 return false; | |
356 *r = new webkit_glue::ResourceRequestBody; | |
357 (*r)->swap_elements(&elements); | |
358 (*r)->set_identifier(identifier); | |
359 return true; | |
360 } | |
361 | |
362 void ParamTraits<scoped_refptr<webkit_glue::ResourceRequestBody> >::Log( | |
363 const param_type& p, std::string* l) { | |
364 l->append("<webkit_glue::ResourceRequestBody>"); | |
365 } | |
366 | |
272 void ParamTraits<net::HostPortPair>::Write(Message* m, const param_type& p) { | 367 void ParamTraits<net::HostPortPair>::Write(Message* m, const param_type& p) { |
273 WriteParam(m, p.host()); | 368 WriteParam(m, p.host()); |
274 WriteParam(m, p.port()); | 369 WriteParam(m, p.port()); |
275 } | 370 } |
276 | 371 |
277 bool ParamTraits<net::HostPortPair>::Read(const Message* m, | 372 bool ParamTraits<net::HostPortPair>::Read(const Message* m, |
278 PickleIterator* iter, | 373 PickleIterator* iter, |
279 param_type* r) { | 374 param_type* r) { |
280 std::string host; | 375 std::string host; |
281 uint16 port; | 376 uint16 port; |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
527 #undef CONTENT_PUBLIC_COMMON_COMMON_PARAM_TRAITS_MACROS_H_ | 622 #undef CONTENT_PUBLIC_COMMON_COMMON_PARAM_TRAITS_MACROS_H_ |
528 #include "content/public/common/common_param_traits_macros.h" | 623 #include "content/public/common/common_param_traits_macros.h" |
529 } // namespace IPC | 624 } // namespace IPC |
530 | 625 |
531 // Generate param traits log methods. | 626 // Generate param traits log methods. |
532 #include "ipc/param_traits_log_macros.h" | 627 #include "ipc/param_traits_log_macros.h" |
533 namespace IPC { | 628 namespace IPC { |
534 #undef CONTENT_PUBLIC_COMMON_COMMON_PARAM_TRAITS_MACROS_H_ | 629 #undef CONTENT_PUBLIC_COMMON_COMMON_PARAM_TRAITS_MACROS_H_ |
535 #include "content/public/common/common_param_traits_macros.h" | 630 #include "content/public/common/common_param_traits_macros.h" |
536 } // namespace IPC | 631 } // namespace IPC |
OLD | NEW |