OLD | NEW |
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" | 11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h" |
| 12 #include "third_party/skia/include/core/SkBitmap.h" |
12 #include "ui/gfx/rect.h" | 13 #include "ui/gfx/rect.h" |
13 #include "webkit/glue/resource_loader_bridge.h" | 14 #include "webkit/glue/resource_loader_bridge.h" |
14 | 15 |
| 16 namespace { |
| 17 |
| 18 struct SkBitmap_Data { |
| 19 // The configuration for the bitmap (bits per pixel, etc). |
| 20 SkBitmap::Config fConfig; |
| 21 |
| 22 // The width of the bitmap in pixels. |
| 23 uint32 fWidth; |
| 24 |
| 25 // The height of the bitmap in pixels. |
| 26 uint32 fHeight; |
| 27 |
| 28 void InitSkBitmapDataForTransfer(const SkBitmap& bitmap) { |
| 29 fConfig = bitmap.config(); |
| 30 fWidth = bitmap.width(); |
| 31 fHeight = bitmap.height(); |
| 32 } |
| 33 |
| 34 // Returns whether |bitmap| successfully initialized. |
| 35 bool InitSkBitmapFromData(SkBitmap* bitmap, const char* pixels, |
| 36 size_t total_pixels) const { |
| 37 if (total_pixels) { |
| 38 bitmap->setConfig(fConfig, fWidth, fHeight, 0); |
| 39 if (!bitmap->allocPixels()) |
| 40 return false; |
| 41 if (total_pixels != bitmap->getSize()) |
| 42 return false; |
| 43 memcpy(bitmap->getPixels(), pixels, total_pixels); |
| 44 } |
| 45 return true; |
| 46 } |
| 47 }; |
| 48 |
| 49 } // namespace |
| 50 |
15 NPIdentifier_Param::NPIdentifier_Param() | 51 NPIdentifier_Param::NPIdentifier_Param() |
16 : identifier() { | 52 : identifier() { |
17 } | 53 } |
18 | 54 |
19 NPIdentifier_Param::~NPIdentifier_Param() { | 55 NPIdentifier_Param::~NPIdentifier_Param() { |
20 } | 56 } |
21 | 57 |
22 NPVariant_Param::NPVariant_Param() | 58 NPVariant_Param::NPVariant_Param() |
23 : type(NPVARIANT_PARAM_VOID), | 59 : type(NPVARIANT_PARAM_VOID), |
24 bool_value(false), | 60 bool_value(false), |
(...skipping 729 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
754 if (WebKit::WebBindings::identifierIsString(p.identifier)) { | 790 if (WebKit::WebBindings::identifierIsString(p.identifier)) { |
755 NPUTF8* str = WebKit::WebBindings::utf8FromIdentifier(p.identifier); | 791 NPUTF8* str = WebKit::WebBindings::utf8FromIdentifier(p.identifier); |
756 l->append(str); | 792 l->append(str); |
757 NPN_MemFree(str); | 793 NPN_MemFree(str); |
758 } else { | 794 } else { |
759 l->append(base::IntToString( | 795 l->append(base::IntToString( |
760 WebKit::WebBindings::intFromIdentifier(p.identifier))); | 796 WebKit::WebBindings::intFromIdentifier(p.identifier))); |
761 } | 797 } |
762 } | 798 } |
763 | 799 |
| 800 void ParamTraits<SkBitmap>::Write(Message* m, const SkBitmap& p) { |
| 801 size_t fixed_size = sizeof(SkBitmap_Data); |
| 802 SkBitmap_Data bmp_data; |
| 803 bmp_data.InitSkBitmapDataForTransfer(p); |
| 804 m->WriteData(reinterpret_cast<const char*>(&bmp_data), |
| 805 static_cast<int>(fixed_size)); |
| 806 size_t pixel_size = p.getSize(); |
| 807 SkAutoLockPixels p_lock(p); |
| 808 m->WriteData(reinterpret_cast<const char*>(p.getPixels()), |
| 809 static_cast<int>(pixel_size)); |
| 810 } |
| 811 |
| 812 bool ParamTraits<SkBitmap>::Read(const Message* m, void** iter, SkBitmap* r) { |
| 813 const char* fixed_data; |
| 814 int fixed_data_size = 0; |
| 815 if (!m->ReadData(iter, &fixed_data, &fixed_data_size) || |
| 816 (fixed_data_size <= 0)) { |
| 817 NOTREACHED(); |
| 818 return false; |
| 819 } |
| 820 if (fixed_data_size != sizeof(SkBitmap_Data)) |
| 821 return false; // Message is malformed. |
| 822 |
| 823 const char* variable_data; |
| 824 int variable_data_size = 0; |
| 825 if (!m->ReadData(iter, &variable_data, &variable_data_size) || |
| 826 (variable_data_size < 0)) { |
| 827 NOTREACHED(); |
| 828 return false; |
| 829 } |
| 830 const SkBitmap_Data* bmp_data = |
| 831 reinterpret_cast<const SkBitmap_Data*>(fixed_data); |
| 832 return bmp_data->InitSkBitmapFromData(r, variable_data, variable_data_size); |
| 833 } |
| 834 |
| 835 void ParamTraits<SkBitmap>::Log(const SkBitmap& p, std::string* l) { |
| 836 l->append("<SkBitmap>"); |
| 837 } |
| 838 |
764 } // namespace IPC | 839 } // namespace IPC |
OLD | NEW |