Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(140)

Side by Side Diff: chrome/common/common_param_traits.cc

Issue 3108042: Support sending BlobData to browser process. Also support sending UploadData... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/common/common_param_traits.h ('k') | chrome/common/render_messages.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "chrome/common/common_param_traits.h" 5 #include "chrome/common/common_param_traits.h"
6 6
7 #include "chrome/common/chrome_constants.h" 7 #include "chrome/common/chrome_constants.h"
8 #include "chrome/common/content_settings.h" 8 #include "chrome/common/content_settings.h"
9 #include "chrome/common/geoposition.h" 9 #include "chrome/common/geoposition.h"
10 #include "chrome/common/thumbnail_score.h" 10 #include "chrome/common/thumbnail_score.h"
11 #include "gfx/rect.h" 11 #include "gfx/rect.h"
12 #include "googleurl/src/gurl.h" 12 #include "googleurl/src/gurl.h"
13 #include "net/base/upload_data.h" 13 #include "net/base/upload_data.h"
14 #include "printing/native_metafile.h" 14 #include "printing/native_metafile.h"
15 #include "printing/page_range.h" 15 #include "printing/page_range.h"
16 16
17 #ifndef EXCLUDE_SKIA_DEPENDENCIES 17 #ifndef EXCLUDE_SKIA_DEPENDENCIES
18 #include "third_party/skia/include/core/SkBitmap.h" 18 #include "third_party/skia/include/core/SkBitmap.h"
19 #endif 19 #endif
20 #include "webkit/blob/blob_data.h"
20 #include "webkit/glue/dom_operations.h" 21 #include "webkit/glue/dom_operations.h"
21 #include "webkit/glue/password_form.h" 22 #include "webkit/glue/password_form.h"
22 23
23 namespace IPC { 24 namespace IPC {
24 25
25 #ifndef EXCLUDE_SKIA_DEPENDENCIES 26 #ifndef EXCLUDE_SKIA_DEPENDENCIES
26 27
27 namespace { 28 namespace {
28 29
29 struct SkBitmap_Data { 30 struct SkBitmap_Data {
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 // Only the net::UploadData ParamTraits<> definition needs this definition, so 321 // Only the net::UploadData ParamTraits<> definition needs this definition, so
321 // keep this in the implementation file so we can forward declare UploadData in 322 // keep this in the implementation file so we can forward declare UploadData in
322 // the header. 323 // the header.
323 template <> 324 template <>
324 struct ParamTraits<net::UploadData::Element> { 325 struct ParamTraits<net::UploadData::Element> {
325 typedef net::UploadData::Element param_type; 326 typedef net::UploadData::Element param_type;
326 static void Write(Message* m, const param_type& p) { 327 static void Write(Message* m, const param_type& p) {
327 WriteParam(m, static_cast<int>(p.type())); 328 WriteParam(m, static_cast<int>(p.type()));
328 if (p.type() == net::UploadData::TYPE_BYTES) { 329 if (p.type() == net::UploadData::TYPE_BYTES) {
329 m->WriteData(&p.bytes()[0], static_cast<int>(p.bytes().size())); 330 m->WriteData(&p.bytes()[0], static_cast<int>(p.bytes().size()));
330 } else { 331 } else if (p.type() == net::UploadData::TYPE_FILE) {
331 WriteParam(m, p.file_path()); 332 WriteParam(m, p.file_path());
332 WriteParam(m, p.file_range_offset()); 333 WriteParam(m, p.file_range_offset());
333 WriteParam(m, p.file_range_length()); 334 WriteParam(m, p.file_range_length());
334 WriteParam(m, p.expected_file_modification_time()); 335 WriteParam(m, p.expected_file_modification_time());
336 } else {
337 WriteParam(m, p.blob_url());
335 } 338 }
336 } 339 }
337 static bool Read(const Message* m, void** iter, param_type* r) { 340 static bool Read(const Message* m, void** iter, param_type* r) {
338 int type; 341 int type;
339 if (!ReadParam(m, iter, &type)) 342 if (!ReadParam(m, iter, &type))
340 return false; 343 return false;
341 if (type == net::UploadData::TYPE_BYTES) { 344 if (type == net::UploadData::TYPE_BYTES) {
342 const char* data; 345 const char* data;
343 int len; 346 int len;
344 if (!m->ReadData(iter, &data, &len)) 347 if (!m->ReadData(iter, &data, &len))
345 return false; 348 return false;
346 r->SetToBytes(data, len); 349 r->SetToBytes(data, len);
347 } else { 350 } else if (type == net::UploadData::TYPE_FILE) {
348 DCHECK(type == net::UploadData::TYPE_FILE);
349 FilePath file_path; 351 FilePath file_path;
350 uint64 offset, length; 352 uint64 offset, length;
351 base::Time expected_modification_time; 353 base::Time expected_modification_time;
352 if (!ReadParam(m, iter, &file_path)) 354 if (!ReadParam(m, iter, &file_path))
353 return false; 355 return false;
354 if (!ReadParam(m, iter, &offset)) 356 if (!ReadParam(m, iter, &offset))
355 return false; 357 return false;
356 if (!ReadParam(m, iter, &length)) 358 if (!ReadParam(m, iter, &length))
357 return false; 359 return false;
358 if (!ReadParam(m, iter, &expected_modification_time)) 360 if (!ReadParam(m, iter, &expected_modification_time))
359 return false; 361 return false;
360 r->SetToFilePathRange(file_path, offset, length, 362 r->SetToFilePathRange(file_path, offset, length,
361 expected_modification_time); 363 expected_modification_time);
364 } else {
365 DCHECK(type == net::UploadData::TYPE_BLOB);
366 GURL blob_url;
367 if (!ReadParam(m, iter, &blob_url))
368 return false;
369 r->SetToBlobUrl(blob_url);
362 } 370 }
363 return true; 371 return true;
364 } 372 }
365 static void Log(const param_type& p, std::string* l) { 373 static void Log(const param_type& p, std::string* l) {
366 l->append("<net::UploadData::Element>"); 374 l->append("<net::UploadData::Element>");
367 } 375 }
368 }; 376 };
369 377
370 void ParamTraits<scoped_refptr<net::UploadData> >::Write(Message* m, 378 void ParamTraits<scoped_refptr<net::UploadData> >::Write(Message* m,
371 const param_type& p) { 379 const param_type& p) {
(...skipping 22 matching lines...) Expand all
394 (*r)->swap_elements(&elements); 402 (*r)->swap_elements(&elements);
395 (*r)->set_identifier(identifier); 403 (*r)->set_identifier(identifier);
396 return true; 404 return true;
397 } 405 }
398 406
399 void ParamTraits<scoped_refptr<net::UploadData> >::Log(const param_type& p, 407 void ParamTraits<scoped_refptr<net::UploadData> >::Log(const param_type& p,
400 std::string* l) { 408 std::string* l) {
401 l->append("<net::UploadData>"); 409 l->append("<net::UploadData>");
402 } 410 }
403 411
412 // Only the webkit_blob::BlobData ParamTraits<> definition needs this
413 // definition, so keep this in the implementation file so we can forward declare
414 // BlobData in the header.
415 template <>
416 struct ParamTraits<webkit_blob::BlobData::Item> {
417 typedef webkit_blob::BlobData::Item param_type;
418 static void Write(Message* m, const param_type& p) {
419 WriteParam(m, static_cast<int>(p.type()));
420 if (p.type() == webkit_blob::BlobData::TYPE_DATA) {
421 WriteParam(m, p.data());
422 } else if (p.type() == webkit_blob::BlobData::TYPE_FILE) {
423 WriteParam(m, p.file_path());
424 WriteParam(m, p.offset());
425 WriteParam(m, p.length());
426 WriteParam(m, p.expected_modification_time());
427 } else {
428 WriteParam(m, p.blob_url());
429 WriteParam(m, p.offset());
430 WriteParam(m, p.length());
431 }
432 }
433 static bool Read(const Message* m, void** iter, param_type* r) {
434 int type;
435 if (!ReadParam(m, iter, &type))
436 return false;
437 if (type == webkit_blob::BlobData::TYPE_DATA) {
438 std::string data;
439 if (!ReadParam(m, iter, &data))
440 return false;
441 r->SetToData(data);
442 } else if (type == webkit_blob::BlobData::TYPE_FILE) {
443 FilePath file_path;
444 uint64 offset, length;
445 base::Time expected_modification_time;
446 if (!ReadParam(m, iter, &file_path))
447 return false;
448 if (!ReadParam(m, iter, &offset))
449 return false;
450 if (!ReadParam(m, iter, &length))
451 return false;
452 if (!ReadParam(m, iter, &expected_modification_time))
453 return false;
454 r->SetToFile(file_path, offset, length, expected_modification_time);
455 } else {
456 DCHECK(type == webkit_blob::BlobData::TYPE_BLOB);
457 GURL blob_url;
458 uint64 offset, length;
459 if (!ReadParam(m, iter, &blob_url))
460 return false;
461 if (!ReadParam(m, iter, &offset))
462 return false;
463 if (!ReadParam(m, iter, &length))
464 return false;
465 r->SetToBlob(blob_url, offset, length);
466 }
467 return true;
468 }
469 static void Log(const param_type& p, std::string* l) {
470 l->append("<BlobData::Item>");
471 }
472 };
473
474 void ParamTraits<scoped_refptr<webkit_blob::BlobData> >::Write(
475 Message* m, const param_type& p) {
476 WriteParam(m, p.get() != NULL);
477 if (p) {
478 WriteParam(m, p->items());
479 WriteParam(m, p->content_type());
480 WriteParam(m, p->content_disposition());
481 }
482 }
483
484 bool ParamTraits<scoped_refptr<webkit_blob::BlobData> >::Read(
485 const Message* m, void** iter, param_type* r) {
486 bool has_object;
487 if (!ReadParam(m, iter, &has_object))
488 return false;
489 if (!has_object)
490 return true;
491 std::vector<webkit_blob::BlobData::Item> items;
492 if (!ReadParam(m, iter, &items))
493 return false;
494 std::string content_type;
495 if (!ReadParam(m, iter, &content_type))
496 return false;
497 std::string content_disposition;
498 if (!ReadParam(m, iter, &content_disposition))
499 return false;
500 *r = new webkit_blob::BlobData;
501 (*r)->swap_items(&items);
502 (*r)->set_content_type(content_type);
503 (*r)->set_content_disposition(content_disposition);
504 return true;
505 }
506
507 void ParamTraits<scoped_refptr<webkit_blob::BlobData> >::Log(
508 const param_type& p, std::string* l) {
509 l->append("<webkit_blob::BlobData>");
510 }
511
404 void ParamTraits<ThumbnailScore>::Write(Message* m, const param_type& p) { 512 void ParamTraits<ThumbnailScore>::Write(Message* m, const param_type& p) {
405 IPC::ParamTraits<double>::Write(m, p.boring_score); 513 IPC::ParamTraits<double>::Write(m, p.boring_score);
406 IPC::ParamTraits<bool>::Write(m, p.good_clipping); 514 IPC::ParamTraits<bool>::Write(m, p.good_clipping);
407 IPC::ParamTraits<bool>::Write(m, p.at_top); 515 IPC::ParamTraits<bool>::Write(m, p.at_top);
408 IPC::ParamTraits<base::Time>::Write(m, p.time_at_snapshot); 516 IPC::ParamTraits<base::Time>::Write(m, p.time_at_snapshot);
409 } 517 }
410 518
411 bool ParamTraits<ThumbnailScore>::Read(const Message* m, void** iter, 519 bool ParamTraits<ThumbnailScore>::Read(const Message* m, void** iter,
412 param_type* r) { 520 param_type* r) {
413 double boring_score; 521 double boring_score;
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
573 p->Init(&buffer.front(), static_cast<uint32>(buffer.size())); 681 p->Init(&buffer.front(), static_cast<uint32>(buffer.size()));
574 #endif // defined(OS_WIN) 682 #endif // defined(OS_WIN)
575 } 683 }
576 684
577 void ParamTraits<printing::NativeMetafile>::Log( 685 void ParamTraits<printing::NativeMetafile>::Log(
578 const param_type& p, std::string* l) { 686 const param_type& p, std::string* l) {
579 l->append("<printing::NativeMetafile>"); 687 l->append("<printing::NativeMetafile>");
580 } 688 }
581 689
582 } // namespace IPC 690 } // namespace IPC
OLDNEW
« no previous file with comments | « chrome/common/common_param_traits.h ('k') | chrome/common/render_messages.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698