| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/ipc_message_utils.h" | 5 #include "chrome/common/ipc_message_utils.h" |
| 6 | 6 |
| 7 #include "base/gfx/rect.h" | 7 #include "base/gfx/rect.h" |
| 8 #include "googleurl/src/gurl.h" | 8 #include "googleurl/src/gurl.h" |
| 9 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
| 10 #include "webkit/glue/dom_operations.h" | 10 #include "webkit/glue/dom_operations.h" |
| 11 | 11 |
| 12 namespace IPC { |
| 13 |
| 12 namespace { | 14 namespace { |
| 13 | 15 |
| 14 struct SkBitmap_Data { | 16 struct SkBitmap_Data { |
| 15 // The configuration for the bitmap (bits per pixel, etc). | 17 // The configuration for the bitmap (bits per pixel, etc). |
| 16 SkBitmap::Config fConfig; | 18 SkBitmap::Config fConfig; |
| 17 | 19 |
| 18 // The width of the bitmap in pixels. | 20 // The width of the bitmap in pixels. |
| 19 uint32 fWidth; | 21 uint32 fWidth; |
| 20 | 22 |
| 21 // The height of the bitmap in pixels. | 23 // The height of the bitmap in pixels. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 37 bitmap->setConfig(fConfig, fWidth, fHeight, fRowBytes); | 39 bitmap->setConfig(fConfig, fWidth, fHeight, fRowBytes); |
| 38 bitmap->allocPixels(); | 40 bitmap->allocPixels(); |
| 39 memcpy(bitmap->getPixels(), pixels, total_pixels); | 41 memcpy(bitmap->getPixels(), pixels, total_pixels); |
| 40 } | 42 } |
| 41 } | 43 } |
| 42 }; | 44 }; |
| 43 | 45 |
| 44 } // namespace | 46 } // namespace |
| 45 | 47 |
| 46 | 48 |
| 47 void ParamTraits<SkBitmap>::Write(IPC::Message* m, const SkBitmap& p) { | 49 void ParamTraits<SkBitmap>::Write(Message* m, const SkBitmap& p) { |
| 48 size_t fixed_size = sizeof(SkBitmap_Data); | 50 size_t fixed_size = sizeof(SkBitmap_Data); |
| 49 SkBitmap_Data bmp_data; | 51 SkBitmap_Data bmp_data; |
| 50 bmp_data.InitSkBitmapDataForTransfer(p); | 52 bmp_data.InitSkBitmapDataForTransfer(p); |
| 51 m->WriteData(reinterpret_cast<const char*>(&bmp_data), | 53 m->WriteData(reinterpret_cast<const char*>(&bmp_data), |
| 52 static_cast<int>(fixed_size)); | 54 static_cast<int>(fixed_size)); |
| 53 size_t pixel_size = p.getSize(); | 55 size_t pixel_size = p.getSize(); |
| 54 SkAutoLockPixels p_lock(p); | 56 SkAutoLockPixels p_lock(p); |
| 55 m->WriteData(reinterpret_cast<const char*>(p.getPixels()), | 57 m->WriteData(reinterpret_cast<const char*>(p.getPixels()), |
| 56 static_cast<int>(pixel_size)); | 58 static_cast<int>(pixel_size)); |
| 57 } | 59 } |
| 58 | 60 |
| 59 bool ParamTraits<SkBitmap>::Read(const IPC::Message* m, void** iter, SkBitmap* r
) { | 61 bool ParamTraits<SkBitmap>::Read(const Message* m, void** iter, SkBitmap* r) { |
| 60 const char* fixed_data; | 62 const char* fixed_data; |
| 61 int fixed_data_size = 0; | 63 int fixed_data_size = 0; |
| 62 if (!m->ReadData(iter, &fixed_data, &fixed_data_size) || | 64 if (!m->ReadData(iter, &fixed_data, &fixed_data_size) || |
| 63 (fixed_data_size <= 0)) { | 65 (fixed_data_size <= 0)) { |
| 64 NOTREACHED(); | 66 NOTREACHED(); |
| 65 return false; | 67 return false; |
| 66 } | 68 } |
| 67 if (fixed_data_size != sizeof(SkBitmap_Data)) | 69 if (fixed_data_size != sizeof(SkBitmap_Data)) |
| 68 return false; // Message is malformed. | 70 return false; // Message is malformed. |
| 69 | 71 |
| 70 const char* variable_data; | 72 const char* variable_data; |
| 71 int variable_data_size = 0; | 73 int variable_data_size = 0; |
| 72 if (!m->ReadData(iter, &variable_data, &variable_data_size) || | 74 if (!m->ReadData(iter, &variable_data, &variable_data_size) || |
| 73 (variable_data_size < 0)) { | 75 (variable_data_size < 0)) { |
| 74 NOTREACHED(); | 76 NOTREACHED(); |
| 75 return false; | 77 return false; |
| 76 } | 78 } |
| 77 const SkBitmap_Data* bmp_data = | 79 const SkBitmap_Data* bmp_data = |
| 78 reinterpret_cast<const SkBitmap_Data*>(fixed_data); | 80 reinterpret_cast<const SkBitmap_Data*>(fixed_data); |
| 79 bmp_data->InitSkBitmapFromData(r, variable_data, variable_data_size); | 81 bmp_data->InitSkBitmapFromData(r, variable_data, variable_data_size); |
| 80 return true; | 82 return true; |
| 81 } | 83 } |
| 82 | 84 |
| 83 void ParamTraits<SkBitmap>::Log(const SkBitmap& p, std::wstring* l) { | 85 void ParamTraits<SkBitmap>::Log(const SkBitmap& p, std::wstring* l) { |
| 84 l->append(StringPrintf(L"<SkBitmap>")); | 86 l->append(StringPrintf(L"<SkBitmap>")); |
| 85 } | 87 } |
| 86 | 88 |
| 87 | 89 |
| 88 void ParamTraits<GURL>::Write(IPC::Message* m, const GURL& p) { | 90 void ParamTraits<GURL>::Write(Message* m, const GURL& p) { |
| 89 m->WriteString(p.possibly_invalid_spec()); | 91 m->WriteString(p.possibly_invalid_spec()); |
| 90 // TODO(brettw) bug 684583: Add encoding for query params. | 92 // TODO(brettw) bug 684583: Add encoding for query params. |
| 91 } | 93 } |
| 92 | 94 |
| 93 bool ParamTraits<GURL>::Read(const IPC::Message* m, void** iter, GURL* p) { | 95 bool ParamTraits<GURL>::Read(const Message* m, void** iter, GURL* p) { |
| 94 std::string s; | 96 std::string s; |
| 95 if (!m->ReadString(iter, &s)) { | 97 if (!m->ReadString(iter, &s)) { |
| 96 *p = GURL(); | 98 *p = GURL(); |
| 97 return false; | 99 return false; |
| 98 } | 100 } |
| 99 *p = GURL(s); | 101 *p = GURL(s); |
| 100 return true; | 102 return true; |
| 101 } | 103 } |
| 102 | 104 |
| 103 void ParamTraits<GURL>::Log(const GURL& p, std::wstring* l) { | 105 void ParamTraits<GURL>::Log(const GURL& p, std::wstring* l) { |
| 104 l->append(UTF8ToWide(p.spec())); | 106 l->append(UTF8ToWide(p.spec())); |
| 105 } | 107 } |
| 106 | 108 |
| 107 | 109 |
| 108 void ParamTraits<gfx::Point>::Write(IPC::Message* m, const gfx::Point& p) { | 110 void ParamTraits<gfx::Point>::Write(Message* m, const gfx::Point& p) { |
| 109 m->WriteInt(p.x()); | 111 m->WriteInt(p.x()); |
| 110 m->WriteInt(p.y()); | 112 m->WriteInt(p.y()); |
| 111 } | 113 } |
| 112 | 114 |
| 113 bool ParamTraits<gfx::Point>::Read(const IPC::Message* m, void** iter, | 115 bool ParamTraits<gfx::Point>::Read(const Message* m, void** iter, |
| 114 gfx::Point* r) { | 116 gfx::Point* r) { |
| 115 int x, y; | 117 int x, y; |
| 116 if (!m->ReadInt(iter, &x) || | 118 if (!m->ReadInt(iter, &x) || |
| 117 !m->ReadInt(iter, &y)) | 119 !m->ReadInt(iter, &y)) |
| 118 return false; | 120 return false; |
| 119 r->set_x(x); | 121 r->set_x(x); |
| 120 r->set_y(y); | 122 r->set_y(y); |
| 121 return true; | 123 return true; |
| 122 } | 124 } |
| 123 | 125 |
| 124 void ParamTraits<gfx::Point>::Log(const gfx::Point& p, std::wstring* l) { | 126 void ParamTraits<gfx::Point>::Log(const gfx::Point& p, std::wstring* l) { |
| 125 l->append(StringPrintf(L"(%d, %d)", p.x(), p.y())); | 127 l->append(StringPrintf(L"(%d, %d)", p.x(), p.y())); |
| 126 } | 128 } |
| 127 | 129 |
| 128 | 130 |
| 129 void ParamTraits<gfx::Rect>::Write(IPC::Message* m, const gfx::Rect& p) { | 131 void ParamTraits<gfx::Rect>::Write(Message* m, const gfx::Rect& p) { |
| 130 m->WriteInt(p.x()); | 132 m->WriteInt(p.x()); |
| 131 m->WriteInt(p.y()); | 133 m->WriteInt(p.y()); |
| 132 m->WriteInt(p.width()); | 134 m->WriteInt(p.width()); |
| 133 m->WriteInt(p.height()); | 135 m->WriteInt(p.height()); |
| 134 } | 136 } |
| 135 | 137 |
| 136 bool ParamTraits<gfx::Rect>::Read(const IPC::Message* m, void** iter, gfx::Rect*
r) { | 138 bool ParamTraits<gfx::Rect>::Read(const Message* m, void** iter, gfx::Rect* r) { |
| 137 int x, y, w, h; | 139 int x, y, w, h; |
| 138 if (!m->ReadInt(iter, &x) || | 140 if (!m->ReadInt(iter, &x) || |
| 139 !m->ReadInt(iter, &y) || | 141 !m->ReadInt(iter, &y) || |
| 140 !m->ReadInt(iter, &w) || | 142 !m->ReadInt(iter, &w) || |
| 141 !m->ReadInt(iter, &h)) | 143 !m->ReadInt(iter, &h)) |
| 142 return false; | 144 return false; |
| 143 r->set_x(x); | 145 r->set_x(x); |
| 144 r->set_y(y); | 146 r->set_y(y); |
| 145 r->set_width(w); | 147 r->set_width(w); |
| 146 r->set_height(h); | 148 r->set_height(h); |
| 147 return true; | 149 return true; |
| 148 } | 150 } |
| 149 | 151 |
| 150 void ParamTraits<gfx::Rect>::Log(const gfx::Rect& p, std::wstring* l) { | 152 void ParamTraits<gfx::Rect>::Log(const gfx::Rect& p, std::wstring* l) { |
| 151 l->append(StringPrintf(L"(%d, %d, %d, %d)", p.x(), p.y(), | 153 l->append(StringPrintf(L"(%d, %d, %d, %d)", p.x(), p.y(), |
| 152 p.width(), p.height())); | 154 p.width(), p.height())); |
| 153 } | 155 } |
| 154 | 156 |
| 155 | 157 |
| 156 void ParamTraits<gfx::Size>::Write(IPC::Message* m, const gfx::Size& p) { | 158 void ParamTraits<gfx::Size>::Write(Message* m, const gfx::Size& p) { |
| 157 m->WriteInt(p.width()); | 159 m->WriteInt(p.width()); |
| 158 m->WriteInt(p.height()); | 160 m->WriteInt(p.height()); |
| 159 } | 161 } |
| 160 | 162 |
| 161 bool ParamTraits<gfx::Size>::Read(const IPC::Message* m, void** iter, gfx::Size*
r) { | 163 bool ParamTraits<gfx::Size>::Read(const Message* m, void** iter, gfx::Size* r) { |
| 162 int w, h; | 164 int w, h; |
| 163 if (!m->ReadInt(iter, &w) || | 165 if (!m->ReadInt(iter, &w) || |
| 164 !m->ReadInt(iter, &h)) | 166 !m->ReadInt(iter, &h)) |
| 165 return false; | 167 return false; |
| 166 r->set_width(w); | 168 r->set_width(w); |
| 167 r->set_height(h); | 169 r->set_height(h); |
| 168 return true; | 170 return true; |
| 169 } | 171 } |
| 170 | 172 |
| 171 void ParamTraits<gfx::Size>::Log(const gfx::Size& p, std::wstring* l) { | 173 void ParamTraits<gfx::Size>::Log(const gfx::Size& p, std::wstring* l) { |
| 172 l->append(StringPrintf(L"(%d, %d)", p.width(), p.height())); | 174 l->append(StringPrintf(L"(%d, %d)", p.width(), p.height())); |
| 173 } | 175 } |
| 174 | 176 |
| 175 void ParamTraits<webkit_glue::WebApplicationInfo>::Write( | 177 void ParamTraits<webkit_glue::WebApplicationInfo>::Write( |
| 176 IPC::Message* m, const webkit_glue::WebApplicationInfo& p) { | 178 Message* m, const webkit_glue::WebApplicationInfo& p) { |
| 177 WriteParam(m, p.title); | 179 WriteParam(m, p.title); |
| 178 WriteParam(m, p.description); | 180 WriteParam(m, p.description); |
| 179 WriteParam(m, p.app_url); | 181 WriteParam(m, p.app_url); |
| 180 WriteParam(m, p.icons.size()); | 182 WriteParam(m, p.icons.size()); |
| 181 for (size_t i = 0; i < p.icons.size(); ++i) { | 183 for (size_t i = 0; i < p.icons.size(); ++i) { |
| 182 WriteParam(m, p.icons[i].url); | 184 WriteParam(m, p.icons[i].url); |
| 183 WriteParam(m, p.icons[i].width); | 185 WriteParam(m, p.icons[i].width); |
| 184 WriteParam(m, p.icons[i].height); | 186 WriteParam(m, p.icons[i].height); |
| 185 } | 187 } |
| 186 } | 188 } |
| 187 | 189 |
| 188 bool ParamTraits<webkit_glue::WebApplicationInfo>::Read( | 190 bool ParamTraits<webkit_glue::WebApplicationInfo>::Read( |
| 189 const IPC::Message* m, void** iter, webkit_glue::WebApplicationInfo* r) { | 191 const Message* m, void** iter, webkit_glue::WebApplicationInfo* r) { |
| 190 size_t icon_count; | 192 size_t icon_count; |
| 191 bool result = | 193 bool result = |
| 192 ReadParam(m, iter, &r->title) && | 194 ReadParam(m, iter, &r->title) && |
| 193 ReadParam(m, iter, &r->description) && | 195 ReadParam(m, iter, &r->description) && |
| 194 ReadParam(m, iter, &r->app_url) && | 196 ReadParam(m, iter, &r->app_url) && |
| 195 ReadParam(m, iter, &icon_count); | 197 ReadParam(m, iter, &icon_count); |
| 196 if (!result) | 198 if (!result) |
| 197 return false; | 199 return false; |
| 198 for (size_t i = 0; i < icon_count && result; ++i) { | 200 for (size_t i = 0; i < icon_count && result; ++i) { |
| 199 param_type::IconInfo icon_info; | 201 param_type::IconInfo icon_info; |
| 200 result = | 202 result = |
| 201 ReadParam(m, iter, &icon_info.url) && | 203 ReadParam(m, iter, &icon_info.url) && |
| 202 ReadParam(m, iter, &icon_info.width) && | 204 ReadParam(m, iter, &icon_info.width) && |
| 203 ReadParam(m, iter, &icon_info.height); | 205 ReadParam(m, iter, &icon_info.height); |
| 204 r->icons.push_back(icon_info); | 206 r->icons.push_back(icon_info); |
| 205 } | 207 } |
| 206 return result; | 208 return result; |
| 207 } | 209 } |
| 208 | 210 |
| 209 void ParamTraits<webkit_glue::WebApplicationInfo>::Log( | 211 void ParamTraits<webkit_glue::WebApplicationInfo>::Log( |
| 210 const webkit_glue::WebApplicationInfo& p, std::wstring* l) { | 212 const webkit_glue::WebApplicationInfo& p, std::wstring* l) { |
| 211 l->append(L"<WebApplicationInfo>"); | 213 l->append(L"<WebApplicationInfo>"); |
| 212 } | 214 } |
| 215 |
| 216 } // namespace IPC |
| 217 |
| OLD | NEW |