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

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

Issue 6840044: Size reduction: halve npchrome_frame.dll via code motion. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 8 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 | « content/common/common_param_traits.h ('k') | content/common/content_message_generator.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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/common/common_param_traits.h" 5 #include "content/common/common_param_traits.h"
6 6
7 #include "content/common/content_constants.h" 7 #include "content/common/content_constants.h"
8 #include "net/base/host_port_pair.h" 8 #include "net/base/host_port_pair.h"
9 #include "net/base/upload_data.h" 9 #include "net/base/upload_data.h"
10 #include "net/http/http_response_headers.h" 10 #include "net/http/http_response_headers.h"
11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h"
12 #include "third_party/skia/include/core/SkBitmap.h" 11 #include "third_party/skia/include/core/SkBitmap.h"
13 #include "ui/gfx/rect.h" 12 #include "ui/gfx/rect.h"
14 #include "webkit/glue/password_form.h"
15 #include "webkit/glue/resource_loader_bridge.h"
16 13
17 namespace { 14 namespace {
18 15
19 struct SkBitmap_Data { 16 struct SkBitmap_Data {
20 // The configuration for the bitmap (bits per pixel, etc). 17 // The configuration for the bitmap (bits per pixel, etc).
21 SkBitmap::Config fConfig; 18 SkBitmap::Config fConfig;
22 19
23 // The width of the bitmap in pixels. 20 // The width of the bitmap in pixels.
24 uint32 fWidth; 21 uint32 fWidth;
25 22
(...skipping 16 matching lines...) Expand all
42 if (total_pixels != bitmap->getSize()) 39 if (total_pixels != bitmap->getSize())
43 return false; 40 return false;
44 memcpy(bitmap->getPixels(), pixels, total_pixels); 41 memcpy(bitmap->getPixels(), pixels, total_pixels);
45 } 42 }
46 return true; 43 return true;
47 } 44 }
48 }; 45 };
49 46
50 } // namespace 47 } // namespace
51 48
52 NPIdentifier_Param::NPIdentifier_Param()
53 : identifier() {
54 }
55
56 NPIdentifier_Param::~NPIdentifier_Param() {
57 }
58
59 NPVariant_Param::NPVariant_Param()
60 : type(NPVARIANT_PARAM_VOID),
61 bool_value(false),
62 int_value(0),
63 double_value(0),
64 npobject_routing_id(-1) {
65 }
66
67 NPVariant_Param::~NPVariant_Param() {
68 }
69
70 namespace IPC { 49 namespace IPC {
71 50
72 void ParamTraits<GURL>::Write(Message* m, const GURL& p) { 51 void ParamTraits<GURL>::Write(Message* m, const GURL& p) {
73 m->WriteString(p.possibly_invalid_spec()); 52 m->WriteString(p.possibly_invalid_spec());
74 // TODO(brettw) bug 684583: Add encoding for query params. 53 // TODO(brettw) bug 684583: Add encoding for query params.
75 } 54 }
76 55
77 bool ParamTraits<GURL>::Read(const Message* m, void** iter, GURL* p) { 56 bool ParamTraits<GURL>::Read(const Message* m, void** iter, GURL* p) {
78 std::string s; 57 std::string s;
79 if (!m->ReadString(iter, &s) || s.length() > content::kMaxURLChars) { 58 if (!m->ReadString(iter, &s) || s.length() > content::kMaxURLChars) {
80 *p = GURL(); 59 *p = GURL();
81 return false; 60 return false;
82 } 61 }
83 *p = GURL(s); 62 *p = GURL(s);
84 return true; 63 return true;
85 } 64 }
86 65
87 void ParamTraits<GURL>::Log(const GURL& p, std::string* l) { 66 void ParamTraits<GURL>::Log(const GURL& p, std::string* l) {
88 l->append(p.spec()); 67 l->append(p.spec());
89 } 68 }
90 69
91
92 void ParamTraits<ResourceType::Type>::Write(Message* m, const param_type& p) { 70 void ParamTraits<ResourceType::Type>::Write(Message* m, const param_type& p) {
93 m->WriteInt(p); 71 m->WriteInt(p);
94 } 72 }
95 73
96 bool ParamTraits<ResourceType::Type>::Read(const Message* m, 74 bool ParamTraits<ResourceType::Type>::Read(const Message* m,
97 void** iter, 75 void** iter,
98 param_type* p) { 76 param_type* p) {
99 int type; 77 int type;
100 if (!m->ReadInt(iter, &type) || !ResourceType::ValidType(type)) 78 if (!m->ReadInt(iter, &type) || !ResourceType::ValidType(type))
101 return false; 79 return false;
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
408 if (!ReadParam(m, iter, &address) || !ReadParam(m, iter, &port)) 386 if (!ReadParam(m, iter, &address) || !ReadParam(m, iter, &port))
409 return false; 387 return false;
410 *p = net::IPEndPoint(address, port); 388 *p = net::IPEndPoint(address, port);
411 return true; 389 return true;
412 } 390 }
413 391
414 void ParamTraits<net::IPEndPoint>::Log(const param_type& p, std::string* l) { 392 void ParamTraits<net::IPEndPoint>::Log(const param_type& p, std::string* l) {
415 LogParam("IPEndPoint:" + p.ToString(), l); 393 LogParam("IPEndPoint:" + p.ToString(), l);
416 } 394 }
417 395
418 void ParamTraits<webkit_glue::ResourceLoadTimingInfo>::Write(
419 Message* m, const param_type& p) {
420 WriteParam(m, p.base_time.is_null());
421 if (p.base_time.is_null())
422 return;
423 WriteParam(m, p.base_time);
424 WriteParam(m, p.proxy_start);
425 WriteParam(m, p.proxy_end);
426 WriteParam(m, p.dns_start);
427 WriteParam(m, p.dns_end);
428 WriteParam(m, p.connect_start);
429 WriteParam(m, p.connect_end);
430 WriteParam(m, p.ssl_start);
431 WriteParam(m, p.ssl_end);
432 WriteParam(m, p.send_start);
433 WriteParam(m, p.send_end);
434 WriteParam(m, p.receive_headers_start);
435 WriteParam(m, p.receive_headers_end);
436 }
437
438 bool ParamTraits<webkit_glue::ResourceLoadTimingInfo>::Read(
439 const Message* m, void** iter, param_type* r) {
440 bool is_null;
441 if (!ReadParam(m, iter, &is_null))
442 return false;
443 if (is_null)
444 return true;
445
446 return
447 ReadParam(m, iter, &r->base_time) &&
448 ReadParam(m, iter, &r->proxy_start) &&
449 ReadParam(m, iter, &r->proxy_end) &&
450 ReadParam(m, iter, &r->dns_start) &&
451 ReadParam(m, iter, &r->dns_end) &&
452 ReadParam(m, iter, &r->connect_start) &&
453 ReadParam(m, iter, &r->connect_end) &&
454 ReadParam(m, iter, &r->ssl_start) &&
455 ReadParam(m, iter, &r->ssl_end) &&
456 ReadParam(m, iter, &r->send_start) &&
457 ReadParam(m, iter, &r->send_end) &&
458 ReadParam(m, iter, &r->receive_headers_start) &&
459 ReadParam(m, iter, &r->receive_headers_end);
460 }
461
462 void ParamTraits<webkit_glue::ResourceLoadTimingInfo>::Log(const param_type& p,
463 std::string* l) {
464 l->append("(");
465 LogParam(p.base_time, l);
466 l->append(", ");
467 LogParam(p.proxy_start, l);
468 l->append(", ");
469 LogParam(p.proxy_end, l);
470 l->append(", ");
471 LogParam(p.dns_start, l);
472 l->append(", ");
473 LogParam(p.dns_end, l);
474 l->append(", ");
475 LogParam(p.connect_start, l);
476 l->append(", ");
477 LogParam(p.connect_end, l);
478 l->append(", ");
479 LogParam(p.ssl_start, l);
480 l->append(", ");
481 LogParam(p.ssl_end, l);
482 l->append(", ");
483 LogParam(p.send_start, l);
484 l->append(", ");
485 LogParam(p.send_end, l);
486 l->append(", ");
487 LogParam(p.receive_headers_start, l);
488 l->append(", ");
489 LogParam(p.receive_headers_end, l);
490 l->append(")");
491 }
492
493 void ParamTraits<scoped_refptr<webkit_glue::ResourceDevToolsInfo> >::Write(
494 Message* m, const param_type& p) {
495 WriteParam(m, p.get() != NULL);
496 if (p.get()) {
497 WriteParam(m, p->http_status_code);
498 WriteParam(m, p->http_status_text);
499 WriteParam(m, p->request_headers);
500 WriteParam(m, p->response_headers);
501 }
502 }
503
504 bool ParamTraits<scoped_refptr<webkit_glue::ResourceDevToolsInfo> >::Read(
505 const Message* m, void** iter, param_type* r) {
506 bool has_object;
507 if (!ReadParam(m, iter, &has_object))
508 return false;
509 if (!has_object)
510 return true;
511 *r = new webkit_glue::ResourceDevToolsInfo();
512 return
513 ReadParam(m, iter, &(*r)->http_status_code) &&
514 ReadParam(m, iter, &(*r)->http_status_text) &&
515 ReadParam(m, iter, &(*r)->request_headers) &&
516 ReadParam(m, iter, &(*r)->response_headers);
517 }
518
519 void ParamTraits<scoped_refptr<webkit_glue::ResourceDevToolsInfo> >::Log(
520 const param_type& p, std::string* l) {
521 l->append("(");
522 if (p) {
523 LogParam(p->request_headers, l);
524 l->append(", ");
525 LogParam(p->response_headers, l);
526 }
527 l->append(")");
528 }
529
530 void ParamTraits<base::PlatformFileInfo>::Write( 396 void ParamTraits<base::PlatformFileInfo>::Write(
531 Message* m, const param_type& p) { 397 Message* m, const param_type& p) {
532 WriteParam(m, p.size); 398 WriteParam(m, p.size);
533 WriteParam(m, p.is_directory); 399 WriteParam(m, p.is_directory);
534 WriteParam(m, p.last_modified.ToDoubleT()); 400 WriteParam(m, p.last_modified.ToDoubleT());
535 WriteParam(m, p.last_accessed.ToDoubleT()); 401 WriteParam(m, p.last_accessed.ToDoubleT());
536 WriteParam(m, p.creation_time.ToDoubleT()); 402 WriteParam(m, p.creation_time.ToDoubleT());
537 } 403 }
538 404
539 bool ParamTraits<base::PlatformFileInfo>::Read( 405 bool ParamTraits<base::PlatformFileInfo>::Read(
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
628 r->set_width(w); 494 r->set_width(w);
629 r->set_height(h); 495 r->set_height(h);
630 return true; 496 return true;
631 } 497 }
632 498
633 void ParamTraits<gfx::Rect>::Log(const gfx::Rect& p, std::string* l) { 499 void ParamTraits<gfx::Rect>::Log(const gfx::Rect& p, std::string* l) {
634 l->append(base::StringPrintf("(%d, %d, %d, %d)", p.x(), p.y(), 500 l->append(base::StringPrintf("(%d, %d, %d, %d)", p.x(), p.y(),
635 p.width(), p.height())); 501 p.width(), p.height()));
636 } 502 }
637 503
638 // Only the webkit_blob::BlobData ParamTraits<> definition needs this
639 // definition, so keep this in the implementation file so we can forward declare
640 // BlobData in the header.
641 template <>
642 struct ParamTraits<webkit_blob::BlobData::Item> {
643 typedef webkit_blob::BlobData::Item param_type;
644 static void Write(Message* m, const param_type& p) {
645 WriteParam(m, static_cast<int>(p.type()));
646 if (p.type() == webkit_blob::BlobData::TYPE_DATA) {
647 WriteParam(m, p.data());
648 } else if (p.type() == webkit_blob::BlobData::TYPE_FILE) {
649 WriteParam(m, p.file_path());
650 WriteParam(m, p.offset());
651 WriteParam(m, p.length());
652 WriteParam(m, p.expected_modification_time());
653 } else {
654 WriteParam(m, p.blob_url());
655 WriteParam(m, p.offset());
656 WriteParam(m, p.length());
657 }
658 }
659 static bool Read(const Message* m, void** iter, param_type* r) {
660 int type;
661 if (!ReadParam(m, iter, &type))
662 return false;
663 if (type == webkit_blob::BlobData::TYPE_DATA) {
664 std::string data;
665 if (!ReadParam(m, iter, &data))
666 return false;
667 r->SetToData(data);
668 } else if (type == webkit_blob::BlobData::TYPE_FILE) {
669 FilePath file_path;
670 uint64 offset, length;
671 base::Time expected_modification_time;
672 if (!ReadParam(m, iter, &file_path))
673 return false;
674 if (!ReadParam(m, iter, &offset))
675 return false;
676 if (!ReadParam(m, iter, &length))
677 return false;
678 if (!ReadParam(m, iter, &expected_modification_time))
679 return false;
680 r->SetToFile(file_path, offset, length, expected_modification_time);
681 } else {
682 DCHECK(type == webkit_blob::BlobData::TYPE_BLOB);
683 GURL blob_url;
684 uint64 offset, length;
685 if (!ReadParam(m, iter, &blob_url))
686 return false;
687 if (!ReadParam(m, iter, &offset))
688 return false;
689 if (!ReadParam(m, iter, &length))
690 return false;
691 r->SetToBlob(blob_url, offset, length);
692 }
693 return true;
694 }
695 static void Log(const param_type& p, std::string* l) {
696 l->append("<BlobData::Item>");
697 }
698 };
699
700 void ParamTraits<scoped_refptr<webkit_blob::BlobData> >::Write(
701 Message* m, const param_type& p) {
702 WriteParam(m, p.get() != NULL);
703 if (p) {
704 WriteParam(m, p->items());
705 WriteParam(m, p->content_type());
706 WriteParam(m, p->content_disposition());
707 }
708 }
709
710 bool ParamTraits<scoped_refptr<webkit_blob::BlobData> >::Read(
711 const Message* m, void** iter, param_type* r) {
712 bool has_object;
713 if (!ReadParam(m, iter, &has_object))
714 return false;
715 if (!has_object)
716 return true;
717 std::vector<webkit_blob::BlobData::Item> items;
718 if (!ReadParam(m, iter, &items))
719 return false;
720 std::string content_type;
721 if (!ReadParam(m, iter, &content_type))
722 return false;
723 std::string content_disposition;
724 if (!ReadParam(m, iter, &content_disposition))
725 return false;
726 *r = new webkit_blob::BlobData;
727 (*r)->swap_items(&items);
728 (*r)->set_content_type(content_type);
729 (*r)->set_content_disposition(content_disposition);
730 return true;
731 }
732
733 void ParamTraits<scoped_refptr<webkit_blob::BlobData> >::Log(
734 const param_type& p, std::string* l) {
735 l->append("<webkit_blob::BlobData>");
736 }
737
738 void ParamTraits<NPVariant_Param>::Write(Message* m, const param_type& p) {
739 WriteParam(m, static_cast<int>(p.type));
740 if (p.type == NPVARIANT_PARAM_BOOL) {
741 WriteParam(m, p.bool_value);
742 } else if (p.type == NPVARIANT_PARAM_INT) {
743 WriteParam(m, p.int_value);
744 } else if (p.type == NPVARIANT_PARAM_DOUBLE) {
745 WriteParam(m, p.double_value);
746 } else if (p.type == NPVARIANT_PARAM_STRING) {
747 WriteParam(m, p.string_value);
748 } else if (p.type == NPVARIANT_PARAM_SENDER_OBJECT_ROUTING_ID ||
749 p.type == NPVARIANT_PARAM_RECEIVER_OBJECT_ROUTING_ID) {
750 // This is the routing id used to connect NPObjectProxy in the other
751 // process with NPObjectStub in this process or to identify the raw
752 // npobject pointer to be used in the callee process.
753 WriteParam(m, p.npobject_routing_id);
754 } else {
755 DCHECK(p.type == NPVARIANT_PARAM_VOID || p.type == NPVARIANT_PARAM_NULL);
756 }
757 }
758
759 bool ParamTraits<NPVariant_Param>::Read(const Message* m,
760 void** iter,
761 param_type* r) {
762 int type;
763 if (!ReadParam(m, iter, &type))
764 return false;
765
766 bool result = false;
767 r->type = static_cast<NPVariant_ParamEnum>(type);
768 if (r->type == NPVARIANT_PARAM_BOOL) {
769 result = ReadParam(m, iter, &r->bool_value);
770 } else if (r->type == NPVARIANT_PARAM_INT) {
771 result = ReadParam(m, iter, &r->int_value);
772 } else if (r->type == NPVARIANT_PARAM_DOUBLE) {
773 result = ReadParam(m, iter, &r->double_value);
774 } else if (r->type == NPVARIANT_PARAM_STRING) {
775 result = ReadParam(m, iter, &r->string_value);
776 } else if (r->type == NPVARIANT_PARAM_SENDER_OBJECT_ROUTING_ID ||
777 r->type == NPVARIANT_PARAM_RECEIVER_OBJECT_ROUTING_ID) {
778 result = ReadParam(m, iter, &r->npobject_routing_id);
779 } else if ((r->type == NPVARIANT_PARAM_VOID) ||
780 (r->type == NPVARIANT_PARAM_NULL)) {
781 result = true;
782 } else {
783 NOTREACHED();
784 }
785
786 return result;
787 }
788
789 void ParamTraits<NPVariant_Param>::Log(const param_type& p, std::string* l) {
790 if (p.type == NPVARIANT_PARAM_BOOL) {
791 LogParam(p.bool_value, l);
792 } else if (p.type == NPVARIANT_PARAM_INT) {
793 LogParam(p.int_value, l);
794 } else if (p.type == NPVARIANT_PARAM_DOUBLE) {
795 LogParam(p.double_value, l);
796 } else if (p.type == NPVARIANT_PARAM_STRING) {
797 LogParam(p.string_value, l);
798 } else if (p.type == NPVARIANT_PARAM_SENDER_OBJECT_ROUTING_ID ||
799 p.type == NPVARIANT_PARAM_RECEIVER_OBJECT_ROUTING_ID) {
800 LogParam(p.npobject_routing_id, l);
801 }
802 }
803
804 void ParamTraits<NPIdentifier_Param>::Write(Message* m, const param_type& p) {
805 webkit_glue::SerializeNPIdentifier(p.identifier, m);
806 }
807
808 bool ParamTraits<NPIdentifier_Param>::Read(const Message* m,
809 void** iter,
810 param_type* r) {
811 return webkit_glue::DeserializeNPIdentifier(*m, iter, &r->identifier);
812 }
813
814 void ParamTraits<NPIdentifier_Param>::Log(const param_type& p, std::string* l) {
815 if (WebKit::WebBindings::identifierIsString(p.identifier)) {
816 NPUTF8* str = WebKit::WebBindings::utf8FromIdentifier(p.identifier);
817 l->append(str);
818 NPN_MemFree(str);
819 } else {
820 l->append(base::IntToString(
821 WebKit::WebBindings::intFromIdentifier(p.identifier)));
822 }
823 }
824
825 void ParamTraits<SkBitmap>::Write(Message* m, const SkBitmap& p) { 504 void ParamTraits<SkBitmap>::Write(Message* m, const SkBitmap& p) {
826 size_t fixed_size = sizeof(SkBitmap_Data); 505 size_t fixed_size = sizeof(SkBitmap_Data);
827 SkBitmap_Data bmp_data; 506 SkBitmap_Data bmp_data;
828 bmp_data.InitSkBitmapDataForTransfer(p); 507 bmp_data.InitSkBitmapDataForTransfer(p);
829 m->WriteData(reinterpret_cast<const char*>(&bmp_data), 508 m->WriteData(reinterpret_cast<const char*>(&bmp_data),
830 static_cast<int>(fixed_size)); 509 static_cast<int>(fixed_size));
831 size_t pixel_size = p.getSize(); 510 size_t pixel_size = p.getSize();
832 SkAutoLockPixels p_lock(p); 511 SkAutoLockPixels p_lock(p);
833 m->WriteData(reinterpret_cast<const char*>(p.getPixels()), 512 m->WriteData(reinterpret_cast<const char*>(p.getPixels()),
834 static_cast<int>(pixel_size)); 513 static_cast<int>(pixel_size));
(...skipping 19 matching lines...) Expand all
854 } 533 }
855 const SkBitmap_Data* bmp_data = 534 const SkBitmap_Data* bmp_data =
856 reinterpret_cast<const SkBitmap_Data*>(fixed_data); 535 reinterpret_cast<const SkBitmap_Data*>(fixed_data);
857 return bmp_data->InitSkBitmapFromData(r, variable_data, variable_data_size); 536 return bmp_data->InitSkBitmapFromData(r, variable_data, variable_data_size);
858 } 537 }
859 538
860 void ParamTraits<SkBitmap>::Log(const SkBitmap& p, std::string* l) { 539 void ParamTraits<SkBitmap>::Log(const SkBitmap& p, std::string* l) {
861 l->append("<SkBitmap>"); 540 l->append("<SkBitmap>");
862 } 541 }
863 542
864 void ParamTraits<webkit_glue::PasswordForm>::Write(Message* m,
865 const param_type& p) {
866 WriteParam(m, p.signon_realm);
867 WriteParam(m, p.origin);
868 WriteParam(m, p.action);
869 WriteParam(m, p.submit_element);
870 WriteParam(m, p.username_element);
871 WriteParam(m, p.username_value);
872 WriteParam(m, p.password_element);
873 WriteParam(m, p.password_value);
874 WriteParam(m, p.old_password_element);
875 WriteParam(m, p.old_password_value);
876 WriteParam(m, p.ssl_valid);
877 WriteParam(m, p.preferred);
878 WriteParam(m, p.blacklisted_by_user);
879 }
880
881 bool ParamTraits<webkit_glue::PasswordForm>::Read(const Message* m, void** iter,
882 param_type* p) {
883 return
884 ReadParam(m, iter, &p->signon_realm) &&
885 ReadParam(m, iter, &p->origin) &&
886 ReadParam(m, iter, &p->action) &&
887 ReadParam(m, iter, &p->submit_element) &&
888 ReadParam(m, iter, &p->username_element) &&
889 ReadParam(m, iter, &p->username_value) &&
890 ReadParam(m, iter, &p->password_element) &&
891 ReadParam(m, iter, &p->password_value) &&
892 ReadParam(m, iter, &p->old_password_element) &&
893 ReadParam(m, iter, &p->old_password_value) &&
894 ReadParam(m, iter, &p->ssl_valid) &&
895 ReadParam(m, iter, &p->preferred) &&
896 ReadParam(m, iter, &p->blacklisted_by_user);
897 }
898 void ParamTraits<webkit_glue::PasswordForm>::Log(const param_type& p,
899 std::string* l) {
900 l->append("<PasswordForm>");
901 }
902
903 } // namespace IPC 543 } // namespace IPC
OLDNEW
« no previous file with comments | « content/common/common_param_traits.h ('k') | content/common/content_message_generator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698