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/webupload_data.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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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<WebUploadData::Element> { |
| 265 typedef WebUploadData::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 WebUploadData::TYPE_BYTES: { |
| 270 m->WriteData(&p.bytes()[0], static_cast<int>(p.bytes().size())); |
| 271 break; |
| 272 } |
| 273 case WebUploadData::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 WebUploadData::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 WebUploadData::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 == WebUploadData::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("<WebUploadData::Element>"); |
| 328 } |
| 329 }; |
| 330 |
| 331 void ParamTraits<scoped_refptr<WebUploadData> >::Write(Message* m, |
| 332 const param_type& p) { |
| 333 WriteParam(m, p.get() != NULL); |
| 334 if (p) { |
| 335 WriteParam(m, *p->elements()); |
| 336 WriteParam(m, p->identifier()); |
| 337 } |
| 338 } |
| 339 |
| 340 bool ParamTraits<scoped_refptr<WebUploadData> >::Read(const Message* m, |
| 341 PickleIterator* iter, |
| 342 param_type* r) { |
| 343 bool has_object; |
| 344 if (!ReadParam(m, iter, &has_object)) |
| 345 return false; |
| 346 if (!has_object) |
| 347 return true; |
| 348 std::vector<WebUploadData::Element> elements; |
| 349 if (!ReadParam(m, iter, &elements)) |
| 350 return false; |
| 351 int64 identifier; |
| 352 if (!ReadParam(m, iter, &identifier)) |
| 353 return false; |
| 354 *r = new WebUploadData; |
| 355 (*r)->swap_elements(&elements); |
| 356 (*r)->set_identifier(identifier); |
| 357 return true; |
| 358 } |
| 359 |
| 360 void ParamTraits<scoped_refptr<WebUploadData> >::Log(const param_type& p, |
| 361 std::string* l) { |
| 362 l->append("<WebUploadData>"); |
| 363 } |
| 364 |
272 void ParamTraits<net::HostPortPair>::Write(Message* m, const param_type& p) { | 365 void ParamTraits<net::HostPortPair>::Write(Message* m, const param_type& p) { |
273 WriteParam(m, p.host()); | 366 WriteParam(m, p.host()); |
274 WriteParam(m, p.port()); | 367 WriteParam(m, p.port()); |
275 } | 368 } |
276 | 369 |
277 bool ParamTraits<net::HostPortPair>::Read(const Message* m, | 370 bool ParamTraits<net::HostPortPair>::Read(const Message* m, |
278 PickleIterator* iter, | 371 PickleIterator* iter, |
279 param_type* r) { | 372 param_type* r) { |
280 std::string host; | 373 std::string host; |
281 uint16 port; | 374 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_ | 620 #undef CONTENT_PUBLIC_COMMON_COMMON_PARAM_TRAITS_MACROS_H_ |
528 #include "content/public/common/common_param_traits_macros.h" | 621 #include "content/public/common/common_param_traits_macros.h" |
529 } // namespace IPC | 622 } // namespace IPC |
530 | 623 |
531 // Generate param traits log methods. | 624 // Generate param traits log methods. |
532 #include "ipc/param_traits_log_macros.h" | 625 #include "ipc/param_traits_log_macros.h" |
533 namespace IPC { | 626 namespace IPC { |
534 #undef CONTENT_PUBLIC_COMMON_COMMON_PARAM_TRAITS_MACROS_H_ | 627 #undef CONTENT_PUBLIC_COMMON_COMMON_PARAM_TRAITS_MACROS_H_ |
535 #include "content/public/common/common_param_traits_macros.h" | 628 #include "content/public/common/common_param_traits_macros.h" |
536 } // namespace IPC | 629 } // namespace IPC |
OLD | NEW |