OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/public/common/common_param_traits.h" | 5 #include "content/public/common/common_param_traits.h" |
6 | 6 |
7 #include "content/public/common/content_constants.h" | 7 #include "content/public/common/content_constants.h" |
8 #include "content/public/common/page_state.h" | 8 #include "content/public/common/page_state.h" |
9 #include "content/public/common/referrer.h" | 9 #include "content/public/common/referrer.h" |
10 #include "net/base/host_port_pair.h" | 10 #include "net/base/host_port_pair.h" |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 return true; | 185 return true; |
186 } | 186 } |
187 | 187 |
188 void ParamTraits<gfx::PointF>::Log(const gfx::PointF& v, std::string* l) { | 188 void ParamTraits<gfx::PointF>::Log(const gfx::PointF& v, std::string* l) { |
189 l->append(base::StringPrintf("(%f, %f)", v.x(), v.y())); | 189 l->append(base::StringPrintf("(%f, %f)", v.x(), v.y())); |
190 } | 190 } |
191 | 191 |
192 void ParamTraits<gfx::Size>::Write(Message* m, const gfx::Size& p) { | 192 void ParamTraits<gfx::Size>::Write(Message* m, const gfx::Size& p) { |
193 DCHECK_GE(p.width(), 0); | 193 DCHECK_GE(p.width(), 0); |
194 DCHECK_GE(p.height(), 0); | 194 DCHECK_GE(p.height(), 0); |
195 m->WriteInt(p.width()); | 195 int values[2] = { p.width(), p.height() }; |
196 m->WriteInt(p.height()); | 196 m->WriteBytes(&values, sizeof(int) * 2); |
197 } | 197 } |
198 | 198 |
199 bool ParamTraits<gfx::Size>::Read(const Message* m, | 199 bool ParamTraits<gfx::Size>::Read(const Message* m, |
200 PickleIterator* iter, | 200 PickleIterator* iter, |
201 gfx::Size* r) { | 201 gfx::Size* r) { |
202 int w, h; | 202 const char* char_values; |
203 if (!m->ReadInt(iter, &w) || w < 0 || | 203 if (!m->ReadBytes(iter, &char_values, sizeof(int) * 2)) |
204 !m->ReadInt(iter, &h) || h < 0) | |
205 return false; | 204 return false; |
206 r->set_width(w); | 205 const int* values = reinterpret_cast<const int*>(char_values); |
207 r->set_height(h); | 206 if (values[0] < 0 || values[1] < 0) |
| 207 return false; |
| 208 r->set_width(values[0]); |
| 209 r->set_height(values[1]); |
208 return true; | 210 return true; |
209 } | 211 } |
210 | 212 |
211 void ParamTraits<gfx::Size>::Log(const gfx::Size& p, std::string* l) { | 213 void ParamTraits<gfx::Size>::Log(const gfx::Size& p, std::string* l) { |
212 l->append(base::StringPrintf("(%d, %d)", p.width(), p.height())); | 214 l->append(base::StringPrintf("(%d, %d)", p.width(), p.height())); |
213 } | 215 } |
214 | 216 |
215 void ParamTraits<gfx::SizeF>::Write(Message* m, const gfx::SizeF& p) { | 217 void ParamTraits<gfx::SizeF>::Write(Message* m, const gfx::SizeF& p) { |
216 ParamTraits<float>::Write(m, p.width()); | 218 float values[2] = { p.width(), p.height() }; |
217 ParamTraits<float>::Write(m, p.height()); | 219 m->WriteBytes(&values, sizeof(float) * 2); |
218 } | 220 } |
219 | 221 |
220 bool ParamTraits<gfx::SizeF>::Read(const Message* m, | 222 bool ParamTraits<gfx::SizeF>::Read(const Message* m, |
221 PickleIterator* iter, | 223 PickleIterator* iter, |
222 gfx::SizeF* p) { | 224 gfx::SizeF* r) { |
223 float w, h; | 225 const char* char_values; |
224 if (!ParamTraits<float>::Read(m, iter, &w) || | 226 if (!m->ReadBytes(iter, &char_values, sizeof(float) * 2)) |
225 !ParamTraits<float>::Read(m, iter, &h)) | |
226 return false; | 227 return false; |
227 p->set_width(w); | 228 const float* values = reinterpret_cast<const float*>(char_values); |
228 p->set_height(h); | 229 r->set_width(values[0]); |
| 230 r->set_height(values[1]); |
229 return true; | 231 return true; |
230 } | 232 } |
231 | 233 |
232 void ParamTraits<gfx::SizeF>::Log(const gfx::SizeF& p, std::string* l) { | 234 void ParamTraits<gfx::SizeF>::Log(const gfx::SizeF& p, std::string* l) { |
233 l->append(base::StringPrintf("(%f, %f)", p.width(), p.height())); | 235 l->append(base::StringPrintf("(%f, %f)", p.width(), p.height())); |
234 } | 236 } |
235 | 237 |
236 void ParamTraits<gfx::Vector2d>::Write(Message* m, const gfx::Vector2d& v) { | 238 void ParamTraits<gfx::Vector2d>::Write(Message* m, const gfx::Vector2d& p) { |
237 m->WriteInt(v.x()); | 239 int values[2] = { p.x(), p.y() }; |
238 m->WriteInt(v.y()); | 240 m->WriteBytes(&values, sizeof(int) * 2); |
239 } | 241 } |
240 | 242 |
241 bool ParamTraits<gfx::Vector2d>::Read(const Message* m, | 243 bool ParamTraits<gfx::Vector2d>::Read(const Message* m, |
242 PickleIterator* iter, | 244 PickleIterator* iter, |
243 gfx::Vector2d* r) { | 245 gfx::Vector2d* r) { |
244 int x, y; | 246 const char* char_values; |
245 if (!m->ReadInt(iter, &x) || | 247 if (!m->ReadBytes(iter, &char_values, sizeof(int) * 2)) |
246 !m->ReadInt(iter, &y)) | |
247 return false; | 248 return false; |
248 r->set_x(x); | 249 const int* values = reinterpret_cast<const int*>(char_values); |
249 r->set_y(y); | 250 r->set_x(values[0]); |
| 251 r->set_y(values[1]); |
250 return true; | 252 return true; |
251 } | 253 } |
252 | 254 |
253 void ParamTraits<gfx::Vector2d>::Log(const gfx::Vector2d& v, std::string* l) { | 255 void ParamTraits<gfx::Vector2d>::Log(const gfx::Vector2d& v, std::string* l) { |
254 l->append(base::StringPrintf("(%d, %d)", v.x(), v.y())); | 256 l->append(base::StringPrintf("(%d, %d)", v.x(), v.y())); |
255 } | 257 } |
256 | 258 |
257 void ParamTraits<gfx::Vector2dF>::Write(Message* m, const gfx::Vector2dF& v) { | 259 void ParamTraits<gfx::Vector2dF>::Write(Message* m, const gfx::Vector2dF& p) { |
258 ParamTraits<float>::Write(m, v.x()); | 260 float values[2] = { p.x(), p.y() }; |
259 ParamTraits<float>::Write(m, v.y()); | 261 m->WriteBytes(&values, sizeof(float) * 2); |
260 } | 262 } |
261 | 263 |
262 bool ParamTraits<gfx::Vector2dF>::Read(const Message* m, | 264 bool ParamTraits<gfx::Vector2dF>::Read(const Message* m, |
263 PickleIterator* iter, | 265 PickleIterator* iter, |
264 gfx::Vector2dF* r) { | 266 gfx::Vector2dF* r) { |
265 float x, y; | 267 const char* char_values; |
266 if (!ParamTraits<float>::Read(m, iter, &x) || | 268 if (!m->ReadBytes(iter, &char_values, sizeof(float) * 2)) |
267 !ParamTraits<float>::Read(m, iter, &y)) | |
268 return false; | 269 return false; |
269 r->set_x(x); | 270 const float* values = reinterpret_cast<const float*>(char_values); |
270 r->set_y(y); | 271 r->set_x(values[0]); |
| 272 r->set_y(values[1]); |
271 return true; | 273 return true; |
272 } | 274 } |
273 | 275 |
274 void ParamTraits<gfx::Vector2dF>::Log(const gfx::Vector2dF& v, std::string* l) { | 276 void ParamTraits<gfx::Vector2dF>::Log(const gfx::Vector2dF& v, std::string* l) { |
275 l->append(base::StringPrintf("(%f, %f)", v.x(), v.y())); | 277 l->append(base::StringPrintf("(%f, %f)", v.x(), v.y())); |
276 } | 278 } |
277 | 279 |
278 void ParamTraits<gfx::Rect>::Write(Message* m, const gfx::Rect& p) { | 280 void ParamTraits<gfx::Rect>::Write(Message* m, const gfx::Rect& p) { |
279 WriteParam(m, p.origin()); | 281 int values[4] = { p.x(), p.y(), p.width(), p.height() }; |
280 WriteParam(m, p.size()); | 282 m->WriteBytes(&values, sizeof(int) * 4); |
281 } | 283 } |
282 | 284 |
283 bool ParamTraits<gfx::Rect>::Read(const Message* m, | 285 bool ParamTraits<gfx::Rect>::Read(const Message* m, |
284 PickleIterator* iter, | 286 PickleIterator* iter, |
285 gfx::Rect* r) { | 287 gfx::Rect* r) { |
286 gfx::Point origin; | 288 const char* char_values; |
287 gfx::Size size; | 289 if (!m->ReadBytes(iter, &char_values, sizeof(int) * 4)) |
288 if (!ReadParam(m, iter, &origin) || | |
289 !ReadParam(m, iter, &size)) | |
290 return false; | 290 return false; |
291 r->set_origin(origin); | 291 const int* values = reinterpret_cast<const int*>(char_values); |
292 r->set_size(size); | 292 if (values[2] < 0 || values[3] < 0) |
| 293 return false; |
| 294 r->SetRect(values[0], values[1], values[2], values[3]); |
293 return true; | 295 return true; |
294 } | 296 } |
295 | 297 |
296 void ParamTraits<gfx::Rect>::Log(const gfx::Rect& p, std::string* l) { | 298 void ParamTraits<gfx::Rect>::Log(const gfx::Rect& p, std::string* l) { |
297 l->append(base::StringPrintf("(%d, %d, %d, %d)", p.x(), p.y(), | 299 l->append(base::StringPrintf("(%d, %d, %d, %d)", p.x(), p.y(), |
298 p.width(), p.height())); | 300 p.width(), p.height())); |
299 } | 301 } |
300 | 302 |
301 void ParamTraits<gfx::RectF>::Write(Message* m, const gfx::RectF& p) { | 303 void ParamTraits<gfx::RectF>::Write(Message* m, const gfx::RectF& p) { |
302 ParamTraits<float>::Write(m, p.x()); | 304 float values[4] = { p.x(), p.y(), p.width(), p.height() }; |
303 ParamTraits<float>::Write(m, p.y()); | 305 m->WriteBytes(&values, sizeof(float) * 4); |
304 ParamTraits<float>::Write(m, p.width()); | |
305 ParamTraits<float>::Write(m, p.height()); | |
306 } | 306 } |
307 | 307 |
308 bool ParamTraits<gfx::RectF>::Read(const Message* m, | 308 bool ParamTraits<gfx::RectF>::Read(const Message* m, |
309 PickleIterator* iter, | 309 PickleIterator* iter, |
310 gfx::RectF* r) { | 310 gfx::RectF* r) { |
311 float x, y, w, h; | 311 const char* char_values; |
312 if (!ParamTraits<float>::Read(m, iter, &x) || | 312 if (!m->ReadBytes(iter, &char_values, sizeof(float) * 4)) |
313 !ParamTraits<float>::Read(m, iter, &y) || | |
314 !ParamTraits<float>::Read(m, iter, &w) || | |
315 !ParamTraits<float>::Read(m, iter, &h)) | |
316 return false; | 313 return false; |
317 r->set_x(x); | 314 const float* values = reinterpret_cast<const float*>(char_values); |
318 r->set_y(y); | 315 r->SetRect(values[0], values[1], values[2], values[3]); |
319 r->set_width(w); | |
320 r->set_height(h); | |
321 return true; | 316 return true; |
322 } | 317 } |
323 | 318 |
324 void ParamTraits<gfx::RectF>::Log(const gfx::RectF& p, std::string* l) { | 319 void ParamTraits<gfx::RectF>::Log(const gfx::RectF& p, std::string* l) { |
325 l->append(base::StringPrintf("(%f, %f, %f, %f)", p.x(), p.y(), | 320 l->append(base::StringPrintf("(%f, %f, %f, %f)", p.x(), p.y(), |
326 p.width(), p.height())); | 321 p.width(), p.height())); |
327 } | 322 } |
328 | 323 |
329 void ParamTraits<SkBitmap>::Write(Message* m, const SkBitmap& p) { | 324 void ParamTraits<SkBitmap>::Write(Message* m, const SkBitmap& p) { |
330 size_t fixed_size = sizeof(SkBitmap_Data); | 325 size_t fixed_size = sizeof(SkBitmap_Data); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
382 #undef CONTENT_PUBLIC_COMMON_COMMON_PARAM_TRAITS_MACROS_H_ | 377 #undef CONTENT_PUBLIC_COMMON_COMMON_PARAM_TRAITS_MACROS_H_ |
383 #include "content/public/common/common_param_traits_macros.h" | 378 #include "content/public/common/common_param_traits_macros.h" |
384 } // namespace IPC | 379 } // namespace IPC |
385 | 380 |
386 // Generate param traits log methods. | 381 // Generate param traits log methods. |
387 #include "ipc/param_traits_log_macros.h" | 382 #include "ipc/param_traits_log_macros.h" |
388 namespace IPC { | 383 namespace IPC { |
389 #undef CONTENT_PUBLIC_COMMON_COMMON_PARAM_TRAITS_MACROS_H_ | 384 #undef CONTENT_PUBLIC_COMMON_COMMON_PARAM_TRAITS_MACROS_H_ |
390 #include "content/public/common/common_param_traits_macros.h" | 385 #include "content/public/common/common_param_traits_macros.h" |
391 } // namespace IPC | 386 } // namespace IPC |
OLD | NEW |