| 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 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 int values[2] = { p.width(), p.height() }; | 195 int values[2] = { p.width(), p.height() }; |
| 196 m->WriteBytes(&values, sizeof(int) * 2); | 196 m->WritePODArray<2>(values); |
| 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 const char* char_values; | 202 const int* values; |
| 203 if (!m->ReadBytes(iter, &char_values, sizeof(int) * 2)) | 203 if (!m->ReadPODArray<2>(iter, &values)) |
| 204 return false; | 204 return false; |
| 205 const int* values = reinterpret_cast<const int*>(char_values); | |
| 206 if (values[0] < 0 || values[1] < 0) | 205 if (values[0] < 0 || values[1] < 0) |
| 207 return false; | 206 return false; |
| 208 r->set_width(values[0]); | 207 r->set_width(values[0]); |
| 209 r->set_height(values[1]); | 208 r->set_height(values[1]); |
| 210 return true; | 209 return true; |
| 211 } | 210 } |
| 212 | 211 |
| 213 void ParamTraits<gfx::Size>::Log(const gfx::Size& p, std::string* l) { | 212 void ParamTraits<gfx::Size>::Log(const gfx::Size& p, std::string* l) { |
| 214 l->append(base::StringPrintf("(%d, %d)", p.width(), p.height())); | 213 l->append(base::StringPrintf("(%d, %d)", p.width(), p.height())); |
| 215 } | 214 } |
| 216 | 215 |
| 217 void ParamTraits<gfx::SizeF>::Write(Message* m, const gfx::SizeF& p) { | 216 void ParamTraits<gfx::SizeF>::Write(Message* m, const gfx::SizeF& p) { |
| 218 float values[2] = { p.width(), p.height() }; | 217 float values[2] = { p.width(), p.height() }; |
| 219 m->WriteBytes(&values, sizeof(float) * 2); | 218 m->WritePODArray<2>(values); |
| 220 } | 219 } |
| 221 | 220 |
| 222 bool ParamTraits<gfx::SizeF>::Read(const Message* m, | 221 bool ParamTraits<gfx::SizeF>::Read(const Message* m, |
| 223 PickleIterator* iter, | 222 PickleIterator* iter, |
| 224 gfx::SizeF* r) { | 223 gfx::SizeF* r) { |
| 225 const char* char_values; | 224 const float* values; |
| 226 if (!m->ReadBytes(iter, &char_values, sizeof(float) * 2)) | 225 if (!m->ReadPODArray<2>(iter, &values)) |
| 227 return false; | 226 return false; |
| 228 const float* values = reinterpret_cast<const float*>(char_values); | |
| 229 r->set_width(values[0]); | 227 r->set_width(values[0]); |
| 230 r->set_height(values[1]); | 228 r->set_height(values[1]); |
| 231 return true; | 229 return true; |
| 232 } | 230 } |
| 233 | 231 |
| 234 void ParamTraits<gfx::SizeF>::Log(const gfx::SizeF& p, std::string* l) { | 232 void ParamTraits<gfx::SizeF>::Log(const gfx::SizeF& p, std::string* l) { |
| 235 l->append(base::StringPrintf("(%f, %f)", p.width(), p.height())); | 233 l->append(base::StringPrintf("(%f, %f)", p.width(), p.height())); |
| 236 } | 234 } |
| 237 | 235 |
| 238 void ParamTraits<gfx::Vector2d>::Write(Message* m, const gfx::Vector2d& p) { | 236 void ParamTraits<gfx::Vector2d>::Write(Message* m, const gfx::Vector2d& p) { |
| 239 int values[2] = { p.x(), p.y() }; | 237 int values[2] = { p.x(), p.y() }; |
| 240 m->WriteBytes(&values, sizeof(int) * 2); | 238 m->WritePODArray<2>(values); |
| 241 } | 239 } |
| 242 | 240 |
| 243 bool ParamTraits<gfx::Vector2d>::Read(const Message* m, | 241 bool ParamTraits<gfx::Vector2d>::Read(const Message* m, |
| 244 PickleIterator* iter, | 242 PickleIterator* iter, |
| 245 gfx::Vector2d* r) { | 243 gfx::Vector2d* r) { |
| 246 const char* char_values; | 244 const int* values; |
| 247 if (!m->ReadBytes(iter, &char_values, sizeof(int) * 2)) | 245 if (!m->ReadPODArray<2>(iter, &values)) |
| 248 return false; | 246 return false; |
| 249 const int* values = reinterpret_cast<const int*>(char_values); | |
| 250 r->set_x(values[0]); | 247 r->set_x(values[0]); |
| 251 r->set_y(values[1]); | 248 r->set_y(values[1]); |
| 252 return true; | 249 return true; |
| 253 } | 250 } |
| 254 | 251 |
| 255 void ParamTraits<gfx::Vector2d>::Log(const gfx::Vector2d& v, std::string* l) { | 252 void ParamTraits<gfx::Vector2d>::Log(const gfx::Vector2d& v, std::string* l) { |
| 256 l->append(base::StringPrintf("(%d, %d)", v.x(), v.y())); | 253 l->append(base::StringPrintf("(%d, %d)", v.x(), v.y())); |
| 257 } | 254 } |
| 258 | 255 |
| 259 void ParamTraits<gfx::Vector2dF>::Write(Message* m, const gfx::Vector2dF& p) { | 256 void ParamTraits<gfx::Vector2dF>::Write(Message* m, const gfx::Vector2dF& p) { |
| 260 float values[2] = { p.x(), p.y() }; | 257 float values[2] = { p.x(), p.y() }; |
| 261 m->WriteBytes(&values, sizeof(float) * 2); | 258 m->WritePODArray<2>(values); |
| 262 } | 259 } |
| 263 | 260 |
| 264 bool ParamTraits<gfx::Vector2dF>::Read(const Message* m, | 261 bool ParamTraits<gfx::Vector2dF>::Read(const Message* m, |
| 265 PickleIterator* iter, | 262 PickleIterator* iter, |
| 266 gfx::Vector2dF* r) { | 263 gfx::Vector2dF* r) { |
| 267 const char* char_values; | 264 const float* values; |
| 268 if (!m->ReadBytes(iter, &char_values, sizeof(float) * 2)) | 265 if (!m->ReadPODArray<2>(iter, &values)) |
| 269 return false; | 266 return false; |
| 270 const float* values = reinterpret_cast<const float*>(char_values); | |
| 271 r->set_x(values[0]); | 267 r->set_x(values[0]); |
| 272 r->set_y(values[1]); | 268 r->set_y(values[1]); |
| 273 return true; | 269 return true; |
| 274 } | 270 } |
| 275 | 271 |
| 276 void ParamTraits<gfx::Vector2dF>::Log(const gfx::Vector2dF& v, std::string* l) { | 272 void ParamTraits<gfx::Vector2dF>::Log(const gfx::Vector2dF& v, std::string* l) { |
| 277 l->append(base::StringPrintf("(%f, %f)", v.x(), v.y())); | 273 l->append(base::StringPrintf("(%f, %f)", v.x(), v.y())); |
| 278 } | 274 } |
| 279 | 275 |
| 280 void ParamTraits<gfx::Rect>::Write(Message* m, const gfx::Rect& p) { | 276 void ParamTraits<gfx::Rect>::Write(Message* m, const gfx::Rect& p) { |
| 281 int values[4] = { p.x(), p.y(), p.width(), p.height() }; | 277 int values[4] = { p.x(), p.y(), p.width(), p.height() }; |
| 282 m->WriteBytes(&values, sizeof(int) * 4); | 278 m->WritePODArray<4>(values); |
| 283 } | 279 } |
| 284 | 280 |
| 285 bool ParamTraits<gfx::Rect>::Read(const Message* m, | 281 bool ParamTraits<gfx::Rect>::Read(const Message* m, |
| 286 PickleIterator* iter, | 282 PickleIterator* iter, |
| 287 gfx::Rect* r) { | 283 gfx::Rect* r) { |
| 288 const char* char_values; | 284 const int* values; |
| 289 if (!m->ReadBytes(iter, &char_values, sizeof(int) * 4)) | 285 if (!m->ReadPODArray<4>(iter, &values)) |
| 290 return false; | 286 return false; |
| 291 const int* values = reinterpret_cast<const int*>(char_values); | |
| 292 if (values[2] < 0 || values[3] < 0) | 287 if (values[2] < 0 || values[3] < 0) |
| 293 return false; | 288 return false; |
| 294 r->SetRect(values[0], values[1], values[2], values[3]); | 289 r->SetRect(values[0], values[1], values[2], values[3]); |
| 295 return true; | 290 return true; |
| 296 } | 291 } |
| 297 | 292 |
| 298 void ParamTraits<gfx::Rect>::Log(const gfx::Rect& p, std::string* l) { | 293 void ParamTraits<gfx::Rect>::Log(const gfx::Rect& p, std::string* l) { |
| 299 l->append(base::StringPrintf("(%d, %d, %d, %d)", p.x(), p.y(), | 294 l->append(base::StringPrintf("(%d, %d, %d, %d)", p.x(), p.y(), |
| 300 p.width(), p.height())); | 295 p.width(), p.height())); |
| 301 } | 296 } |
| 302 | 297 |
| 303 void ParamTraits<gfx::RectF>::Write(Message* m, const gfx::RectF& p) { | 298 void ParamTraits<gfx::RectF>::Write(Message* m, const gfx::RectF& p) { |
| 304 float values[4] = { p.x(), p.y(), p.width(), p.height() }; | 299 float values[4] = { p.x(), p.y(), p.width(), p.height() }; |
| 305 m->WriteBytes(&values, sizeof(float) * 4); | 300 m->WritePODArray<4>(values); |
| 306 } | 301 } |
| 307 | 302 |
| 308 bool ParamTraits<gfx::RectF>::Read(const Message* m, | 303 bool ParamTraits<gfx::RectF>::Read(const Message* m, |
| 309 PickleIterator* iter, | 304 PickleIterator* iter, |
| 310 gfx::RectF* r) { | 305 gfx::RectF* r) { |
| 311 const char* char_values; | 306 const float* values; |
| 312 if (!m->ReadBytes(iter, &char_values, sizeof(float) * 4)) | 307 if (!m->ReadPODArray<4>(iter, &values)) |
| 313 return false; | 308 return false; |
| 314 const float* values = reinterpret_cast<const float*>(char_values); | |
| 315 r->SetRect(values[0], values[1], values[2], values[3]); | 309 r->SetRect(values[0], values[1], values[2], values[3]); |
| 316 return true; | 310 return true; |
| 317 } | 311 } |
| 318 | 312 |
| 319 void ParamTraits<gfx::RectF>::Log(const gfx::RectF& p, std::string* l) { | 313 void ParamTraits<gfx::RectF>::Log(const gfx::RectF& p, std::string* l) { |
| 320 l->append(base::StringPrintf("(%f, %f, %f, %f)", p.x(), p.y(), | 314 l->append(base::StringPrintf("(%f, %f, %f, %f)", p.x(), p.y(), |
| 321 p.width(), p.height())); | 315 p.width(), p.height())); |
| 322 } | 316 } |
| 323 | 317 |
| 324 void ParamTraits<SkBitmap>::Write(Message* m, const SkBitmap& p) { | 318 void ParamTraits<SkBitmap>::Write(Message* m, const SkBitmap& p) { |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 377 #undef CONTENT_PUBLIC_COMMON_COMMON_PARAM_TRAITS_MACROS_H_ | 371 #undef CONTENT_PUBLIC_COMMON_COMMON_PARAM_TRAITS_MACROS_H_ |
| 378 #include "content/public/common/common_param_traits_macros.h" | 372 #include "content/public/common/common_param_traits_macros.h" |
| 379 } // namespace IPC | 373 } // namespace IPC |
| 380 | 374 |
| 381 // Generate param traits log methods. | 375 // Generate param traits log methods. |
| 382 #include "ipc/param_traits_log_macros.h" | 376 #include "ipc/param_traits_log_macros.h" |
| 383 namespace IPC { | 377 namespace IPC { |
| 384 #undef CONTENT_PUBLIC_COMMON_COMMON_PARAM_TRAITS_MACROS_H_ | 378 #undef CONTENT_PUBLIC_COMMON_COMMON_PARAM_TRAITS_MACROS_H_ |
| 385 #include "content/public/common/common_param_traits_macros.h" | 379 #include "content/public/common/common_param_traits_macros.h" |
| 386 } // namespace IPC | 380 } // namespace IPC |
| OLD | NEW |