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