| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/common_param_traits.h" | 5 #include "chrome/common/common_param_traits.h" |
| 6 | 6 |
| 7 #include "base/time.h" | 7 #include "base/time.h" |
| 8 #include "chrome/common/chrome_constants.h" | 8 #include "chrome/common/chrome_constants.h" |
| 9 #include "chrome/common/content_settings.h" | 9 #include "chrome/common/content_settings.h" |
| 10 #include "chrome/common/geoposition.h" | 10 #include "chrome/common/geoposition.h" |
| 11 #include "chrome/common/thumbnail_score.h" | 11 #include "chrome/common/thumbnail_score.h" |
| 12 #include "chrome/common/web_apps.h" | 12 #include "chrome/common/web_apps.h" |
| 13 #include "content/common/common_param_traits.h" | 13 #include "content/common/common_param_traits.h" |
| 14 #include "googleurl/src/gurl.h" | 14 #include "googleurl/src/gurl.h" |
| 15 #include "net/base/host_port_pair.h" | |
| 16 #include "net/base/upload_data.h" | |
| 17 #include "printing/backend/print_backend.h" | 15 #include "printing/backend/print_backend.h" |
| 18 #include "printing/native_metafile.h" | 16 #include "printing/native_metafile.h" |
| 19 #include "printing/page_range.h" | 17 #include "printing/page_range.h" |
| 20 #include "ui/gfx/rect.h" | 18 #include "ui/gfx/rect.h" |
| 21 | 19 |
| 22 #ifndef EXCLUDE_SKIA_DEPENDENCIES | 20 #ifndef EXCLUDE_SKIA_DEPENDENCIES |
| 23 #include "third_party/skia/include/core/SkBitmap.h" | 21 #include "third_party/skia/include/core/SkBitmap.h" |
| 24 #endif | 22 #endif |
| 25 #include "webkit/glue/password_form.h" | 23 #include "webkit/glue/password_form.h" |
| 26 | 24 |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 } | 264 } |
| 267 | 265 |
| 268 return true; | 266 return true; |
| 269 } | 267 } |
| 270 | 268 |
| 271 void ParamTraits<WebApplicationInfo>::Log(const WebApplicationInfo& p, | 269 void ParamTraits<WebApplicationInfo>::Log(const WebApplicationInfo& p, |
| 272 std::string* l) { | 270 std::string* l) { |
| 273 l->append("<WebApplicationInfo>"); | 271 l->append("<WebApplicationInfo>"); |
| 274 } | 272 } |
| 275 | 273 |
| 276 void ParamTraits<net::HostPortPair>::Write(Message* m, const param_type& p) { | |
| 277 WriteParam(m, p.host()); | |
| 278 WriteParam(m, p.port()); | |
| 279 } | |
| 280 | |
| 281 bool ParamTraits<net::HostPortPair>::Read(const Message* m, void** iter, | |
| 282 param_type* r) { | |
| 283 std::string host; | |
| 284 uint16 port; | |
| 285 if (!ReadParam(m, iter, &host) || !ReadParam(m, iter, &port)) | |
| 286 return false; | |
| 287 | |
| 288 r->set_host(host); | |
| 289 r->set_port(port); | |
| 290 return true; | |
| 291 } | |
| 292 | |
| 293 void ParamTraits<net::HostPortPair>::Log(const param_type& p, std::string* l) { | |
| 294 l->append(p.ToString()); | |
| 295 } | |
| 296 | |
| 297 void ParamTraits<net::URLRequestStatus>::Write(Message* m, | |
| 298 const param_type& p) { | |
| 299 WriteParam(m, static_cast<int>(p.status())); | |
| 300 WriteParam(m, p.os_error()); | |
| 301 } | |
| 302 | |
| 303 bool ParamTraits<net::URLRequestStatus>::Read(const Message* m, void** iter, | |
| 304 param_type* r) { | |
| 305 int status, os_error; | |
| 306 if (!ReadParam(m, iter, &status) || | |
| 307 !ReadParam(m, iter, &os_error)) | |
| 308 return false; | |
| 309 r->set_status(static_cast<net::URLRequestStatus::Status>(status)); | |
| 310 r->set_os_error(os_error); | |
| 311 return true; | |
| 312 } | |
| 313 | |
| 314 void ParamTraits<net::URLRequestStatus>::Log(const param_type& p, | |
| 315 std::string* l) { | |
| 316 std::string status; | |
| 317 switch (p.status()) { | |
| 318 case net::URLRequestStatus::SUCCESS: | |
| 319 status = "SUCCESS"; | |
| 320 break; | |
| 321 case net::URLRequestStatus::IO_PENDING: | |
| 322 status = "IO_PENDING "; | |
| 323 break; | |
| 324 case net::URLRequestStatus::HANDLED_EXTERNALLY: | |
| 325 status = "HANDLED_EXTERNALLY"; | |
| 326 break; | |
| 327 case net::URLRequestStatus::CANCELED: | |
| 328 status = "CANCELED"; | |
| 329 break; | |
| 330 case net::URLRequestStatus::FAILED: | |
| 331 status = "FAILED"; | |
| 332 break; | |
| 333 default: | |
| 334 status = "UNKNOWN"; | |
| 335 break; | |
| 336 } | |
| 337 if (p.status() == net::URLRequestStatus::FAILED) | |
| 338 l->append("("); | |
| 339 | |
| 340 LogParam(status, l); | |
| 341 | |
| 342 if (p.status() == net::URLRequestStatus::FAILED) { | |
| 343 l->append(", "); | |
| 344 LogParam(p.os_error(), l); | |
| 345 l->append(")"); | |
| 346 } | |
| 347 } | |
| 348 | |
| 349 // Only the net::UploadData ParamTraits<> definition needs this definition, so | |
| 350 // keep this in the implementation file so we can forward declare UploadData in | |
| 351 // the header. | |
| 352 template <> | |
| 353 struct ParamTraits<net::UploadData::Element> { | |
| 354 typedef net::UploadData::Element param_type; | |
| 355 static void Write(Message* m, const param_type& p) { | |
| 356 WriteParam(m, static_cast<int>(p.type())); | |
| 357 switch (p.type()) { | |
| 358 case net::UploadData::TYPE_BYTES: { | |
| 359 m->WriteData(&p.bytes()[0], static_cast<int>(p.bytes().size())); | |
| 360 break; | |
| 361 } | |
| 362 case net::UploadData::TYPE_CHUNK: { | |
| 363 std::string chunk_length = StringPrintf( | |
| 364 "%X\r\n", static_cast<unsigned int>(p.bytes().size())); | |
| 365 std::vector<char> bytes; | |
| 366 bytes.insert(bytes.end(), chunk_length.data(), | |
| 367 chunk_length.data() + chunk_length.length()); | |
| 368 const char* data = &p.bytes()[0]; | |
| 369 bytes.insert(bytes.end(), data, data + p.bytes().size()); | |
| 370 const char* crlf = "\r\n"; | |
| 371 bytes.insert(bytes.end(), crlf, crlf + strlen(crlf)); | |
| 372 if (p.is_last_chunk()) { | |
| 373 const char* end_of_data = "0\r\n\r\n"; | |
| 374 bytes.insert(bytes.end(), end_of_data, | |
| 375 end_of_data + strlen(end_of_data)); | |
| 376 } | |
| 377 m->WriteData(&bytes[0], static_cast<int>(bytes.size())); | |
| 378 // If this element is part of a chunk upload then send over information | |
| 379 // indicating if this is the last chunk. | |
| 380 WriteParam(m, p.is_last_chunk()); | |
| 381 break; | |
| 382 } | |
| 383 case net::UploadData::TYPE_FILE: { | |
| 384 WriteParam(m, p.file_path()); | |
| 385 WriteParam(m, p.file_range_offset()); | |
| 386 WriteParam(m, p.file_range_length()); | |
| 387 WriteParam(m, p.expected_file_modification_time()); | |
| 388 break; | |
| 389 } | |
| 390 default: { | |
| 391 WriteParam(m, p.blob_url()); | |
| 392 break; | |
| 393 } | |
| 394 } | |
| 395 } | |
| 396 static bool Read(const Message* m, void** iter, param_type* r) { | |
| 397 int type; | |
| 398 if (!ReadParam(m, iter, &type)) | |
| 399 return false; | |
| 400 switch (type) { | |
| 401 case net::UploadData::TYPE_BYTES: { | |
| 402 const char* data; | |
| 403 int len; | |
| 404 if (!m->ReadData(iter, &data, &len)) | |
| 405 return false; | |
| 406 r->SetToBytes(data, len); | |
| 407 break; | |
| 408 } | |
| 409 case net::UploadData::TYPE_CHUNK: { | |
| 410 const char* data; | |
| 411 int len; | |
| 412 if (!m->ReadData(iter, &data, &len)) | |
| 413 return false; | |
| 414 r->SetToBytes(data, len); | |
| 415 // If this element is part of a chunk upload then we need to explicitly | |
| 416 // set the type of the element and whether it is the last chunk. | |
| 417 bool is_last_chunk = false; | |
| 418 if (!ReadParam(m, iter, &is_last_chunk)) | |
| 419 return false; | |
| 420 r->set_type(net::UploadData::TYPE_CHUNK); | |
| 421 r->set_is_last_chunk(is_last_chunk); | |
| 422 break; | |
| 423 } | |
| 424 case net::UploadData::TYPE_FILE: { | |
| 425 FilePath file_path; | |
| 426 uint64 offset, length; | |
| 427 base::Time expected_modification_time; | |
| 428 if (!ReadParam(m, iter, &file_path)) | |
| 429 return false; | |
| 430 if (!ReadParam(m, iter, &offset)) | |
| 431 return false; | |
| 432 if (!ReadParam(m, iter, &length)) | |
| 433 return false; | |
| 434 if (!ReadParam(m, iter, &expected_modification_time)) | |
| 435 return false; | |
| 436 r->SetToFilePathRange(file_path, offset, length, | |
| 437 expected_modification_time); | |
| 438 break; | |
| 439 } | |
| 440 default: { | |
| 441 DCHECK(type == net::UploadData::TYPE_BLOB); | |
| 442 GURL blob_url; | |
| 443 if (!ReadParam(m, iter, &blob_url)) | |
| 444 return false; | |
| 445 r->SetToBlobUrl(blob_url); | |
| 446 break; | |
| 447 } | |
| 448 } | |
| 449 return true; | |
| 450 } | |
| 451 static void Log(const param_type& p, std::string* l) { | |
| 452 l->append("<net::UploadData::Element>"); | |
| 453 } | |
| 454 }; | |
| 455 | |
| 456 void ParamTraits<scoped_refptr<net::UploadData> >::Write(Message* m, | |
| 457 const param_type& p) { | |
| 458 WriteParam(m, p.get() != NULL); | |
| 459 if (p) { | |
| 460 WriteParam(m, *p->elements()); | |
| 461 WriteParam(m, p->identifier()); | |
| 462 WriteParam(m, p->is_chunked()); | |
| 463 } | |
| 464 } | |
| 465 | |
| 466 bool ParamTraits<scoped_refptr<net::UploadData> >::Read(const Message* m, | |
| 467 void** iter, | |
| 468 param_type* r) { | |
| 469 bool has_object; | |
| 470 if (!ReadParam(m, iter, &has_object)) | |
| 471 return false; | |
| 472 if (!has_object) | |
| 473 return true; | |
| 474 std::vector<net::UploadData::Element> elements; | |
| 475 if (!ReadParam(m, iter, &elements)) | |
| 476 return false; | |
| 477 int64 identifier; | |
| 478 if (!ReadParam(m, iter, &identifier)) | |
| 479 return false; | |
| 480 bool is_chunked = false; | |
| 481 if (!ReadParam(m, iter, &is_chunked)) | |
| 482 return false; | |
| 483 *r = new net::UploadData; | |
| 484 (*r)->swap_elements(&elements); | |
| 485 (*r)->set_identifier(identifier); | |
| 486 (*r)->set_is_chunked(is_chunked); | |
| 487 return true; | |
| 488 } | |
| 489 | |
| 490 void ParamTraits<scoped_refptr<net::UploadData> >::Log(const param_type& p, | |
| 491 std::string* l) { | |
| 492 l->append("<net::UploadData>"); | |
| 493 } | |
| 494 | |
| 495 void ParamTraits<ThumbnailScore>::Write(Message* m, const param_type& p) { | 274 void ParamTraits<ThumbnailScore>::Write(Message* m, const param_type& p) { |
| 496 IPC::ParamTraits<double>::Write(m, p.boring_score); | 275 IPC::ParamTraits<double>::Write(m, p.boring_score); |
| 497 IPC::ParamTraits<bool>::Write(m, p.good_clipping); | 276 IPC::ParamTraits<bool>::Write(m, p.good_clipping); |
| 498 IPC::ParamTraits<bool>::Write(m, p.at_top); | 277 IPC::ParamTraits<bool>::Write(m, p.at_top); |
| 499 IPC::ParamTraits<base::Time>::Write(m, p.time_at_snapshot); | 278 IPC::ParamTraits<base::Time>::Write(m, p.time_at_snapshot); |
| 500 } | 279 } |
| 501 | 280 |
| 502 bool ParamTraits<ThumbnailScore>::Read(const Message* m, void** iter, | 281 bool ParamTraits<ThumbnailScore>::Read(const Message* m, void** iter, |
| 503 param_type* r) { | 282 param_type* r) { |
| 504 double boring_score; | 283 double boring_score; |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 732 l->append(","); | 511 l->append(","); |
| 733 LogParam(p.caps_mime_type, l); | 512 LogParam(p.caps_mime_type, l); |
| 734 l->append(","); | 513 l->append(","); |
| 735 LogParam(p.printer_defaults, l); | 514 LogParam(p.printer_defaults, l); |
| 736 l->append(","); | 515 l->append(","); |
| 737 LogParam(p.defaults_mime_type, l); | 516 LogParam(p.defaults_mime_type, l); |
| 738 l->append(")"); | 517 l->append(")"); |
| 739 } | 518 } |
| 740 | 519 |
| 741 } // namespace IPC | 520 } // namespace IPC |
| OLD | NEW |