| OLD | NEW |
| 1 // Copyright (c) 2011 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 "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/skia/include/core/SkBitmap.h" | 11 #include "third_party/skia/include/core/SkBitmap.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 } // namespace | 48 } // namespace |
| 49 | 49 |
| 50 namespace IPC { | 50 namespace IPC { |
| 51 | 51 |
| 52 void ParamTraits<GURL>::Write(Message* m, const GURL& p) { | 52 void ParamTraits<GURL>::Write(Message* m, const GURL& p) { |
| 53 DCHECK(p.possibly_invalid_spec().length() <= content::kMaxURLChars); | 53 DCHECK(p.possibly_invalid_spec().length() <= content::kMaxURLChars); |
| 54 m->WriteString(p.possibly_invalid_spec()); | 54 m->WriteString(p.possibly_invalid_spec()); |
| 55 // TODO(brettw) bug 684583: Add encoding for query params. | 55 // TODO(brettw) bug 684583: Add encoding for query params. |
| 56 } | 56 } |
| 57 | 57 |
| 58 bool ParamTraits<GURL>::Read(const Message* m, void** iter, GURL* p) { | 58 bool ParamTraits<GURL>::Read(const Message* m, PickleIterator* iter, GURL* p) { |
| 59 std::string s; | 59 std::string s; |
| 60 if (!m->ReadString(iter, &s) || s.length() > content::kMaxURLChars) { | 60 if (!m->ReadString(iter, &s) || s.length() > content::kMaxURLChars) { |
| 61 *p = GURL(); | 61 *p = GURL(); |
| 62 return false; | 62 return false; |
| 63 } | 63 } |
| 64 *p = GURL(s); | 64 *p = GURL(s); |
| 65 return true; | 65 return true; |
| 66 } | 66 } |
| 67 | 67 |
| 68 void ParamTraits<GURL>::Log(const GURL& p, std::string* l) { | 68 void ParamTraits<GURL>::Log(const GURL& p, std::string* l) { |
| 69 l->append(p.spec()); | 69 l->append(p.spec()); |
| 70 } | 70 } |
| 71 | 71 |
| 72 void ParamTraits<ResourceType::Type>::Write(Message* m, const param_type& p) { | 72 void ParamTraits<ResourceType::Type>::Write(Message* m, const param_type& p) { |
| 73 m->WriteInt(p); | 73 m->WriteInt(p); |
| 74 } | 74 } |
| 75 | 75 |
| 76 bool ParamTraits<ResourceType::Type>::Read(const Message* m, | 76 bool ParamTraits<ResourceType::Type>::Read(const Message* m, |
| 77 void** iter, | 77 PickleIterator* iter, |
| 78 param_type* p) { | 78 param_type* p) { |
| 79 int type; | 79 int type; |
| 80 if (!m->ReadInt(iter, &type) || !ResourceType::ValidType(type)) | 80 if (!m->ReadInt(iter, &type) || !ResourceType::ValidType(type)) |
| 81 return false; | 81 return false; |
| 82 *p = ResourceType::FromInt(type); | 82 *p = ResourceType::FromInt(type); |
| 83 return true; | 83 return true; |
| 84 } | 84 } |
| 85 | 85 |
| 86 void ParamTraits<ResourceType::Type>::Log(const param_type& p, std::string* l) { | 86 void ParamTraits<ResourceType::Type>::Log(const param_type& p, std::string* l) { |
| 87 std::string type; | 87 std::string type; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 | 138 |
| 139 LogParam(type, l); | 139 LogParam(type, l); |
| 140 } | 140 } |
| 141 | 141 |
| 142 void ParamTraits<net::URLRequestStatus>::Write(Message* m, | 142 void ParamTraits<net::URLRequestStatus>::Write(Message* m, |
| 143 const param_type& p) { | 143 const param_type& p) { |
| 144 WriteParam(m, static_cast<int>(p.status())); | 144 WriteParam(m, static_cast<int>(p.status())); |
| 145 WriteParam(m, p.error()); | 145 WriteParam(m, p.error()); |
| 146 } | 146 } |
| 147 | 147 |
| 148 bool ParamTraits<net::URLRequestStatus>::Read(const Message* m, void** iter, | 148 bool ParamTraits<net::URLRequestStatus>::Read(const Message* m, |
| 149 PickleIterator* iter, |
| 149 param_type* r) { | 150 param_type* r) { |
| 150 int status, error; | 151 int status, error; |
| 151 if (!ReadParam(m, iter, &status) || !ReadParam(m, iter, &error)) | 152 if (!ReadParam(m, iter, &status) || !ReadParam(m, iter, &error)) |
| 152 return false; | 153 return false; |
| 153 r->set_status(static_cast<net::URLRequestStatus::Status>(status)); | 154 r->set_status(static_cast<net::URLRequestStatus::Status>(status)); |
| 154 r->set_error(error); | 155 r->set_error(error); |
| 155 return true; | 156 return true; |
| 156 } | 157 } |
| 157 | 158 |
| 158 void ParamTraits<net::URLRequestStatus>::Log(const param_type& p, | 159 void ParamTraits<net::URLRequestStatus>::Log(const param_type& p, |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 WriteParam(m, p.file_range_length()); | 231 WriteParam(m, p.file_range_length()); |
| 231 WriteParam(m, p.expected_file_modification_time()); | 232 WriteParam(m, p.expected_file_modification_time()); |
| 232 break; | 233 break; |
| 233 } | 234 } |
| 234 default: { | 235 default: { |
| 235 WriteParam(m, p.blob_url()); | 236 WriteParam(m, p.blob_url()); |
| 236 break; | 237 break; |
| 237 } | 238 } |
| 238 } | 239 } |
| 239 } | 240 } |
| 240 static bool Read(const Message* m, void** iter, param_type* r) { | 241 static bool Read(const Message* m, PickleIterator* iter, param_type* r) { |
| 241 int type; | 242 int type; |
| 242 if (!ReadParam(m, iter, &type)) | 243 if (!ReadParam(m, iter, &type)) |
| 243 return false; | 244 return false; |
| 244 switch (type) { | 245 switch (type) { |
| 245 case net::UploadData::TYPE_BYTES: { | 246 case net::UploadData::TYPE_BYTES: { |
| 246 const char* data; | 247 const char* data; |
| 247 int len; | 248 int len; |
| 248 if (!m->ReadData(iter, &data, &len)) | 249 if (!m->ReadData(iter, &data, &len)) |
| 249 return false; | 250 return false; |
| 250 r->SetToBytes(data, len); | 251 r->SetToBytes(data, len); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 301 const param_type& p) { | 302 const param_type& p) { |
| 302 WriteParam(m, p.get() != NULL); | 303 WriteParam(m, p.get() != NULL); |
| 303 if (p) { | 304 if (p) { |
| 304 WriteParam(m, *p->elements()); | 305 WriteParam(m, *p->elements()); |
| 305 WriteParam(m, p->identifier()); | 306 WriteParam(m, p->identifier()); |
| 306 WriteParam(m, p->is_chunked()); | 307 WriteParam(m, p->is_chunked()); |
| 307 } | 308 } |
| 308 } | 309 } |
| 309 | 310 |
| 310 bool ParamTraits<scoped_refptr<net::UploadData> >::Read(const Message* m, | 311 bool ParamTraits<scoped_refptr<net::UploadData> >::Read(const Message* m, |
| 311 void** iter, | 312 PickleIterator* iter, |
| 312 param_type* r) { | 313 param_type* r) { |
| 313 bool has_object; | 314 bool has_object; |
| 314 if (!ReadParam(m, iter, &has_object)) | 315 if (!ReadParam(m, iter, &has_object)) |
| 315 return false; | 316 return false; |
| 316 if (!has_object) | 317 if (!has_object) |
| 317 return true; | 318 return true; |
| 318 std::vector<net::UploadData::Element> elements; | 319 std::vector<net::UploadData::Element> elements; |
| 319 if (!ReadParam(m, iter, &elements)) | 320 if (!ReadParam(m, iter, &elements)) |
| 320 return false; | 321 return false; |
| 321 int64 identifier; | 322 int64 identifier; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 334 void ParamTraits<scoped_refptr<net::UploadData> >::Log(const param_type& p, | 335 void ParamTraits<scoped_refptr<net::UploadData> >::Log(const param_type& p, |
| 335 std::string* l) { | 336 std::string* l) { |
| 336 l->append("<net::UploadData>"); | 337 l->append("<net::UploadData>"); |
| 337 } | 338 } |
| 338 | 339 |
| 339 void ParamTraits<net::HostPortPair>::Write(Message* m, const param_type& p) { | 340 void ParamTraits<net::HostPortPair>::Write(Message* m, const param_type& p) { |
| 340 WriteParam(m, p.host()); | 341 WriteParam(m, p.host()); |
| 341 WriteParam(m, p.port()); | 342 WriteParam(m, p.port()); |
| 342 } | 343 } |
| 343 | 344 |
| 344 bool ParamTraits<net::HostPortPair>::Read(const Message* m, void** iter, | 345 bool ParamTraits<net::HostPortPair>::Read(const Message* m, |
| 346 PickleIterator* iter, |
| 345 param_type* r) { | 347 param_type* r) { |
| 346 std::string host; | 348 std::string host; |
| 347 uint16 port; | 349 uint16 port; |
| 348 if (!ReadParam(m, iter, &host) || !ReadParam(m, iter, &port)) | 350 if (!ReadParam(m, iter, &host) || !ReadParam(m, iter, &port)) |
| 349 return false; | 351 return false; |
| 350 | 352 |
| 351 r->set_host(host); | 353 r->set_host(host); |
| 352 r->set_port(port); | 354 r->set_port(port); |
| 353 return true; | 355 return true; |
| 354 } | 356 } |
| 355 | 357 |
| 356 void ParamTraits<net::HostPortPair>::Log(const param_type& p, std::string* l) { | 358 void ParamTraits<net::HostPortPair>::Log(const param_type& p, std::string* l) { |
| 357 l->append(p.ToString()); | 359 l->append(p.ToString()); |
| 358 } | 360 } |
| 359 | 361 |
| 360 void ParamTraits<scoped_refptr<net::HttpResponseHeaders> >::Write( | 362 void ParamTraits<scoped_refptr<net::HttpResponseHeaders> >::Write( |
| 361 Message* m, const param_type& p) { | 363 Message* m, const param_type& p) { |
| 362 WriteParam(m, p.get() != NULL); | 364 WriteParam(m, p.get() != NULL); |
| 363 if (p) { | 365 if (p) { |
| 364 // Do not disclose Set-Cookie headers over IPC. | 366 // Do not disclose Set-Cookie headers over IPC. |
| 365 p->Persist(m, net::HttpResponseHeaders::PERSIST_SANS_COOKIES); | 367 p->Persist(m, net::HttpResponseHeaders::PERSIST_SANS_COOKIES); |
| 366 } | 368 } |
| 367 } | 369 } |
| 368 | 370 |
| 369 bool ParamTraits<scoped_refptr<net::HttpResponseHeaders> >::Read( | 371 bool ParamTraits<scoped_refptr<net::HttpResponseHeaders> >::Read( |
| 370 const Message* m, void** iter, param_type* r) { | 372 const Message* m, PickleIterator* iter, param_type* r) { |
| 371 bool has_object; | 373 bool has_object; |
| 372 if (!ReadParam(m, iter, &has_object)) | 374 if (!ReadParam(m, iter, &has_object)) |
| 373 return false; | 375 return false; |
| 374 if (has_object) | 376 if (has_object) |
| 375 *r = new net::HttpResponseHeaders(*m, iter); | 377 *r = new net::HttpResponseHeaders(*m, iter); |
| 376 return true; | 378 return true; |
| 377 } | 379 } |
| 378 | 380 |
| 379 void ParamTraits<scoped_refptr<net::HttpResponseHeaders> >::Log( | 381 void ParamTraits<scoped_refptr<net::HttpResponseHeaders> >::Log( |
| 380 const param_type& p, std::string* l) { | 382 const param_type& p, std::string* l) { |
| 381 l->append("<HttpResponseHeaders>"); | 383 l->append("<HttpResponseHeaders>"); |
| 382 } | 384 } |
| 383 | 385 |
| 384 void ParamTraits<net::IPEndPoint>::Write(Message* m, const param_type& p) { | 386 void ParamTraits<net::IPEndPoint>::Write(Message* m, const param_type& p) { |
| 385 WriteParam(m, p.address()); | 387 WriteParam(m, p.address()); |
| 386 WriteParam(m, p.port()); | 388 WriteParam(m, p.port()); |
| 387 } | 389 } |
| 388 | 390 |
| 389 bool ParamTraits<net::IPEndPoint>::Read(const Message* m, void** iter, | 391 bool ParamTraits<net::IPEndPoint>::Read(const Message* m, PickleIterator* iter, |
| 390 param_type* p) { | 392 param_type* p) { |
| 391 net::IPAddressNumber address; | 393 net::IPAddressNumber address; |
| 392 int port; | 394 int port; |
| 393 if (!ReadParam(m, iter, &address) || !ReadParam(m, iter, &port)) | 395 if (!ReadParam(m, iter, &address) || !ReadParam(m, iter, &port)) |
| 394 return false; | 396 return false; |
| 395 *p = net::IPEndPoint(address, port); | 397 *p = net::IPEndPoint(address, port); |
| 396 return true; | 398 return true; |
| 397 } | 399 } |
| 398 | 400 |
| 399 void ParamTraits<net::IPEndPoint>::Log(const param_type& p, std::string* l) { | 401 void ParamTraits<net::IPEndPoint>::Log(const param_type& p, std::string* l) { |
| 400 LogParam("IPEndPoint:" + p.ToString(), l); | 402 LogParam("IPEndPoint:" + p.ToString(), l); |
| 401 } | 403 } |
| 402 | 404 |
| 403 void ParamTraits<base::PlatformFileInfo>::Write( | 405 void ParamTraits<base::PlatformFileInfo>::Write( |
| 404 Message* m, const param_type& p) { | 406 Message* m, const param_type& p) { |
| 405 WriteParam(m, p.size); | 407 WriteParam(m, p.size); |
| 406 WriteParam(m, p.is_directory); | 408 WriteParam(m, p.is_directory); |
| 407 WriteParam(m, p.last_modified.ToDoubleT()); | 409 WriteParam(m, p.last_modified.ToDoubleT()); |
| 408 WriteParam(m, p.last_accessed.ToDoubleT()); | 410 WriteParam(m, p.last_accessed.ToDoubleT()); |
| 409 WriteParam(m, p.creation_time.ToDoubleT()); | 411 WriteParam(m, p.creation_time.ToDoubleT()); |
| 410 } | 412 } |
| 411 | 413 |
| 412 bool ParamTraits<base::PlatformFileInfo>::Read( | 414 bool ParamTraits<base::PlatformFileInfo>::Read( |
| 413 const Message* m, void** iter, param_type* p) { | 415 const Message* m, PickleIterator* iter, param_type* p) { |
| 414 double last_modified; | 416 double last_modified; |
| 415 double last_accessed; | 417 double last_accessed; |
| 416 double creation_time; | 418 double creation_time; |
| 417 bool result = | 419 bool result = |
| 418 ReadParam(m, iter, &p->size) && | 420 ReadParam(m, iter, &p->size) && |
| 419 ReadParam(m, iter, &p->is_directory) && | 421 ReadParam(m, iter, &p->is_directory) && |
| 420 ReadParam(m, iter, &last_modified) && | 422 ReadParam(m, iter, &last_modified) && |
| 421 ReadParam(m, iter, &last_accessed) && | 423 ReadParam(m, iter, &last_accessed) && |
| 422 ReadParam(m, iter, &creation_time); | 424 ReadParam(m, iter, &creation_time); |
| 423 if (result) { | 425 if (result) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 441 l->append(","); | 443 l->append(","); |
| 442 LogParam(p.creation_time.ToDoubleT(), l); | 444 LogParam(p.creation_time.ToDoubleT(), l); |
| 443 l->append(")"); | 445 l->append(")"); |
| 444 } | 446 } |
| 445 | 447 |
| 446 void ParamTraits<gfx::Point>::Write(Message* m, const gfx::Point& p) { | 448 void ParamTraits<gfx::Point>::Write(Message* m, const gfx::Point& p) { |
| 447 m->WriteInt(p.x()); | 449 m->WriteInt(p.x()); |
| 448 m->WriteInt(p.y()); | 450 m->WriteInt(p.y()); |
| 449 } | 451 } |
| 450 | 452 |
| 451 bool ParamTraits<gfx::Point>::Read(const Message* m, void** iter, | 453 bool ParamTraits<gfx::Point>::Read(const Message* m, PickleIterator* iter, |
| 452 gfx::Point* r) { | 454 gfx::Point* r) { |
| 453 int x, y; | 455 int x, y; |
| 454 if (!m->ReadInt(iter, &x) || | 456 if (!m->ReadInt(iter, &x) || |
| 455 !m->ReadInt(iter, &y)) | 457 !m->ReadInt(iter, &y)) |
| 456 return false; | 458 return false; |
| 457 r->set_x(x); | 459 r->set_x(x); |
| 458 r->set_y(y); | 460 r->set_y(y); |
| 459 return true; | 461 return true; |
| 460 } | 462 } |
| 461 | 463 |
| 462 void ParamTraits<gfx::Point>::Log(const gfx::Point& p, std::string* l) { | 464 void ParamTraits<gfx::Point>::Log(const gfx::Point& p, std::string* l) { |
| 463 l->append(base::StringPrintf("(%d, %d)", p.x(), p.y())); | 465 l->append(base::StringPrintf("(%d, %d)", p.x(), p.y())); |
| 464 } | 466 } |
| 465 | 467 |
| 466 void ParamTraits<gfx::Size>::Write(Message* m, const gfx::Size& p) { | 468 void ParamTraits<gfx::Size>::Write(Message* m, const gfx::Size& p) { |
| 467 m->WriteInt(p.width()); | 469 m->WriteInt(p.width()); |
| 468 m->WriteInt(p.height()); | 470 m->WriteInt(p.height()); |
| 469 } | 471 } |
| 470 | 472 |
| 471 bool ParamTraits<gfx::Size>::Read(const Message* m, void** iter, gfx::Size* r) { | 473 bool ParamTraits<gfx::Size>::Read(const Message* m, |
| 474 PickleIterator* iter, |
| 475 gfx::Size* r) { |
| 472 int w, h; | 476 int w, h; |
| 473 if (!m->ReadInt(iter, &w) || | 477 if (!m->ReadInt(iter, &w) || |
| 474 !m->ReadInt(iter, &h)) | 478 !m->ReadInt(iter, &h)) |
| 475 return false; | 479 return false; |
| 476 r->set_width(w); | 480 r->set_width(w); |
| 477 r->set_height(h); | 481 r->set_height(h); |
| 478 return true; | 482 return true; |
| 479 } | 483 } |
| 480 | 484 |
| 481 void ParamTraits<gfx::Size>::Log(const gfx::Size& p, std::string* l) { | 485 void ParamTraits<gfx::Size>::Log(const gfx::Size& p, std::string* l) { |
| 482 l->append(base::StringPrintf("(%d, %d)", p.width(), p.height())); | 486 l->append(base::StringPrintf("(%d, %d)", p.width(), p.height())); |
| 483 } | 487 } |
| 484 | 488 |
| 485 void ParamTraits<gfx::Rect>::Write(Message* m, const gfx::Rect& p) { | 489 void ParamTraits<gfx::Rect>::Write(Message* m, const gfx::Rect& p) { |
| 486 m->WriteInt(p.x()); | 490 m->WriteInt(p.x()); |
| 487 m->WriteInt(p.y()); | 491 m->WriteInt(p.y()); |
| 488 m->WriteInt(p.width()); | 492 m->WriteInt(p.width()); |
| 489 m->WriteInt(p.height()); | 493 m->WriteInt(p.height()); |
| 490 } | 494 } |
| 491 | 495 |
| 492 bool ParamTraits<gfx::Rect>::Read(const Message* m, void** iter, gfx::Rect* r) { | 496 bool ParamTraits<gfx::Rect>::Read(const Message* m, |
| 497 PickleIterator* iter, |
| 498 gfx::Rect* r) { |
| 493 int x, y, w, h; | 499 int x, y, w, h; |
| 494 if (!m->ReadInt(iter, &x) || | 500 if (!m->ReadInt(iter, &x) || |
| 495 !m->ReadInt(iter, &y) || | 501 !m->ReadInt(iter, &y) || |
| 496 !m->ReadInt(iter, &w) || | 502 !m->ReadInt(iter, &w) || |
| 497 !m->ReadInt(iter, &h)) | 503 !m->ReadInt(iter, &h)) |
| 498 return false; | 504 return false; |
| 499 r->set_x(x); | 505 r->set_x(x); |
| 500 r->set_y(y); | 506 r->set_y(y); |
| 501 r->set_width(w); | 507 r->set_width(w); |
| 502 r->set_height(h); | 508 r->set_height(h); |
| 503 return true; | 509 return true; |
| 504 } | 510 } |
| 505 | 511 |
| 506 void ParamTraits<gfx::Rect>::Log(const gfx::Rect& p, std::string* l) { | 512 void ParamTraits<gfx::Rect>::Log(const gfx::Rect& p, std::string* l) { |
| 507 l->append(base::StringPrintf("(%d, %d, %d, %d)", p.x(), p.y(), | 513 l->append(base::StringPrintf("(%d, %d, %d, %d)", p.x(), p.y(), |
| 508 p.width(), p.height())); | 514 p.width(), p.height())); |
| 509 } | 515 } |
| 510 | 516 |
| 511 void ParamTraits<ui::Range>::Write(Message* m, const ui::Range& r) { | 517 void ParamTraits<ui::Range>::Write(Message* m, const ui::Range& r) { |
| 512 m->WriteSize(r.start()); | 518 m->WriteSize(r.start()); |
| 513 m->WriteSize(r.end()); | 519 m->WriteSize(r.end()); |
| 514 } | 520 } |
| 515 | 521 |
| 516 bool ParamTraits<ui::Range>::Read(const Message* m, void** iter, ui::Range* r) { | 522 bool ParamTraits<ui::Range>::Read(const Message* m, |
| 523 PickleIterator* iter, |
| 524 ui::Range* r) { |
| 517 size_t start, end; | 525 size_t start, end; |
| 518 if (!m->ReadSize(iter, &start) || !m->ReadSize(iter, &end)) | 526 if (!m->ReadSize(iter, &start) || !m->ReadSize(iter, &end)) |
| 519 return false; | 527 return false; |
| 520 r->set_start(start); | 528 r->set_start(start); |
| 521 r->set_end(end); | 529 r->set_end(end); |
| 522 return true; | 530 return true; |
| 523 } | 531 } |
| 524 | 532 |
| 525 void ParamTraits<ui::Range>::Log(const ui::Range& r, std::string* l) { | 533 void ParamTraits<ui::Range>::Log(const ui::Range& r, std::string* l) { |
| 526 l->append(base::StringPrintf("(%"PRIuS", %"PRIuS")", r.start(), r.end())); | 534 l->append(base::StringPrintf("(%"PRIuS", %"PRIuS")", r.start(), r.end())); |
| 527 } | 535 } |
| 528 | 536 |
| 529 void ParamTraits<SkBitmap>::Write(Message* m, const SkBitmap& p) { | 537 void ParamTraits<SkBitmap>::Write(Message* m, const SkBitmap& p) { |
| 530 size_t fixed_size = sizeof(SkBitmap_Data); | 538 size_t fixed_size = sizeof(SkBitmap_Data); |
| 531 SkBitmap_Data bmp_data; | 539 SkBitmap_Data bmp_data; |
| 532 bmp_data.InitSkBitmapDataForTransfer(p); | 540 bmp_data.InitSkBitmapDataForTransfer(p); |
| 533 m->WriteData(reinterpret_cast<const char*>(&bmp_data), | 541 m->WriteData(reinterpret_cast<const char*>(&bmp_data), |
| 534 static_cast<int>(fixed_size)); | 542 static_cast<int>(fixed_size)); |
| 535 size_t pixel_size = p.getSize(); | 543 size_t pixel_size = p.getSize(); |
| 536 SkAutoLockPixels p_lock(p); | 544 SkAutoLockPixels p_lock(p); |
| 537 m->WriteData(reinterpret_cast<const char*>(p.getPixels()), | 545 m->WriteData(reinterpret_cast<const char*>(p.getPixels()), |
| 538 static_cast<int>(pixel_size)); | 546 static_cast<int>(pixel_size)); |
| 539 } | 547 } |
| 540 | 548 |
| 541 bool ParamTraits<SkBitmap>::Read(const Message* m, void** iter, SkBitmap* r) { | 549 bool ParamTraits<SkBitmap>::Read(const Message* m, |
| 550 PickleIterator* iter, |
| 551 SkBitmap* r) { |
| 542 const char* fixed_data; | 552 const char* fixed_data; |
| 543 int fixed_data_size = 0; | 553 int fixed_data_size = 0; |
| 544 if (!m->ReadData(iter, &fixed_data, &fixed_data_size) || | 554 if (!m->ReadData(iter, &fixed_data, &fixed_data_size) || |
| 545 (fixed_data_size <= 0)) { | 555 (fixed_data_size <= 0)) { |
| 546 NOTREACHED(); | 556 NOTREACHED(); |
| 547 return false; | 557 return false; |
| 548 } | 558 } |
| 549 if (fixed_data_size != sizeof(SkBitmap_Data)) | 559 if (fixed_data_size != sizeof(SkBitmap_Data)) |
| 550 return false; // Message is malformed. | 560 return false; // Message is malformed. |
| 551 | 561 |
| 552 const char* variable_data; | 562 const char* variable_data; |
| 553 int variable_data_size = 0; | 563 int variable_data_size = 0; |
| 554 if (!m->ReadData(iter, &variable_data, &variable_data_size) || | 564 if (!m->ReadData(iter, &variable_data, &variable_data_size) || |
| 555 (variable_data_size < 0)) { | 565 (variable_data_size < 0)) { |
| 556 NOTREACHED(); | 566 NOTREACHED(); |
| 557 return false; | 567 return false; |
| 558 } | 568 } |
| 559 const SkBitmap_Data* bmp_data = | 569 const SkBitmap_Data* bmp_data = |
| 560 reinterpret_cast<const SkBitmap_Data*>(fixed_data); | 570 reinterpret_cast<const SkBitmap_Data*>(fixed_data); |
| 561 return bmp_data->InitSkBitmapFromData(r, variable_data, variable_data_size); | 571 return bmp_data->InitSkBitmapFromData(r, variable_data, variable_data_size); |
| 562 } | 572 } |
| 563 | 573 |
| 564 void ParamTraits<SkBitmap>::Log(const SkBitmap& p, std::string* l) { | 574 void ParamTraits<SkBitmap>::Log(const SkBitmap& p, std::string* l) { |
| 565 l->append("<SkBitmap>"); | 575 l->append("<SkBitmap>"); |
| 566 } | 576 } |
| 567 | 577 |
| 568 } // namespace IPC | 578 } // namespace IPC |
| OLD | NEW |