| 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/referrer.h" | 8 #include "content/public/common/referrer.h" |
| 9 #include "net/base/host_port_pair.h" | 9 #include "net/base/host_port_pair.h" |
| 10 #include "net/base/upload_data.h" | |
| 11 #include "net/http/http_response_headers.h" | |
| 12 #include "third_party/skia/include/core/SkBitmap.h" | 10 #include "third_party/skia/include/core/SkBitmap.h" |
| 13 #include "ui/base/range/range.h" | |
| 14 #include "ui/gfx/rect.h" | 11 #include "ui/gfx/rect.h" |
| 15 #include "ui/gfx/rect_f.h" | 12 #include "ui/gfx/rect_f.h" |
| 16 #include "webkit/glue/resource_request_body.h" | |
| 17 | 13 |
| 18 namespace { | 14 namespace { |
| 19 | 15 |
| 20 struct SkBitmap_Data { | 16 struct SkBitmap_Data { |
| 21 // The configuration for the bitmap (bits per pixel, etc). | 17 // The configuration for the bitmap (bits per pixel, etc). |
| 22 SkBitmap::Config fConfig; | 18 SkBitmap::Config fConfig; |
| 23 | 19 |
| 24 // The width of the bitmap in pixels. | 20 // The width of the bitmap in pixels. |
| 25 uint32 fWidth; | 21 uint32 fWidth; |
| 26 | 22 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 return false; | 61 return false; |
| 66 } | 62 } |
| 67 *p = GURL(s); | 63 *p = GURL(s); |
| 68 return true; | 64 return true; |
| 69 } | 65 } |
| 70 | 66 |
| 71 void ParamTraits<GURL>::Log(const GURL& p, std::string* l) { | 67 void ParamTraits<GURL>::Log(const GURL& p, std::string* l) { |
| 72 l->append(p.spec()); | 68 l->append(p.spec()); |
| 73 } | 69 } |
| 74 | 70 |
| 75 void ParamTraits<net::URLRequestStatus>::Write(Message* m, | |
| 76 const param_type& p) { | |
| 77 WriteParam(m, static_cast<int>(p.status())); | |
| 78 WriteParam(m, p.error()); | |
| 79 } | |
| 80 | |
| 81 bool ParamTraits<net::URLRequestStatus>::Read(const Message* m, | |
| 82 PickleIterator* iter, | |
| 83 param_type* r) { | |
| 84 int status, error; | |
| 85 if (!ReadParam(m, iter, &status) || !ReadParam(m, iter, &error)) | |
| 86 return false; | |
| 87 r->set_status(static_cast<net::URLRequestStatus::Status>(status)); | |
| 88 r->set_error(error); | |
| 89 return true; | |
| 90 } | |
| 91 | |
| 92 void ParamTraits<net::URLRequestStatus>::Log(const param_type& p, | |
| 93 std::string* l) { | |
| 94 std::string status; | |
| 95 switch (p.status()) { | |
| 96 case net::URLRequestStatus::SUCCESS: | |
| 97 status = "SUCCESS"; | |
| 98 break; | |
| 99 case net::URLRequestStatus::IO_PENDING: | |
| 100 status = "IO_PENDING "; | |
| 101 break; | |
| 102 case net::URLRequestStatus::CANCELED: | |
| 103 status = "CANCELED"; | |
| 104 break; | |
| 105 case net::URLRequestStatus::FAILED: | |
| 106 status = "FAILED"; | |
| 107 break; | |
| 108 default: | |
| 109 status = "UNKNOWN"; | |
| 110 break; | |
| 111 } | |
| 112 if (p.status() == net::URLRequestStatus::FAILED) | |
| 113 l->append("("); | |
| 114 | |
| 115 LogParam(status, l); | |
| 116 | |
| 117 if (p.status() == net::URLRequestStatus::FAILED) { | |
| 118 l->append(", "); | |
| 119 LogParam(p.error(), l); | |
| 120 l->append(")"); | |
| 121 } | |
| 122 } | |
| 123 | |
| 124 // Only the net::UploadData ParamTraits<> definition needs this definition, so | |
| 125 // keep this in the implementation file so we can forward declare UploadData in | |
| 126 // the header. | |
| 127 template <> | |
| 128 struct ParamTraits<net::UploadElement> { | |
| 129 typedef net::UploadElement param_type; | |
| 130 static void Write(Message* m, const param_type& p) { | |
| 131 WriteParam(m, static_cast<int>(p.type())); | |
| 132 switch (p.type()) { | |
| 133 case net::UploadElement::TYPE_BYTES: { | |
| 134 m->WriteData(p.bytes(), static_cast<int>(p.bytes_length())); | |
| 135 break; | |
| 136 } | |
| 137 default: { | |
| 138 DCHECK(p.type() == net::UploadElement::TYPE_FILE); | |
| 139 WriteParam(m, p.file_path()); | |
| 140 WriteParam(m, p.file_range_offset()); | |
| 141 WriteParam(m, p.file_range_length()); | |
| 142 WriteParam(m, p.expected_file_modification_time()); | |
| 143 break; | |
| 144 } | |
| 145 } | |
| 146 } | |
| 147 static bool Read(const Message* m, PickleIterator* iter, param_type* r) { | |
| 148 int type; | |
| 149 if (!ReadParam(m, iter, &type)) | |
| 150 return false; | |
| 151 switch (type) { | |
| 152 case net::UploadElement::TYPE_BYTES: { | |
| 153 const char* data; | |
| 154 int len; | |
| 155 if (!m->ReadData(iter, &data, &len)) | |
| 156 return false; | |
| 157 r->SetToBytes(data, len); | |
| 158 break; | |
| 159 } | |
| 160 default: { | |
| 161 DCHECK(type == net::UploadElement::TYPE_FILE); | |
| 162 FilePath file_path; | |
| 163 uint64 offset, length; | |
| 164 base::Time expected_modification_time; | |
| 165 if (!ReadParam(m, iter, &file_path)) | |
| 166 return false; | |
| 167 if (!ReadParam(m, iter, &offset)) | |
| 168 return false; | |
| 169 if (!ReadParam(m, iter, &length)) | |
| 170 return false; | |
| 171 if (!ReadParam(m, iter, &expected_modification_time)) | |
| 172 return false; | |
| 173 r->SetToFilePathRange(file_path, offset, length, | |
| 174 expected_modification_time); | |
| 175 break; | |
| 176 } | |
| 177 } | |
| 178 return true; | |
| 179 } | |
| 180 static void Log(const param_type& p, std::string* l) { | |
| 181 l->append("<net::UploadElement>"); | |
| 182 } | |
| 183 }; | |
| 184 | |
| 185 void ParamTraits<scoped_refptr<net::UploadData> >::Write(Message* m, | |
| 186 const param_type& p) { | |
| 187 WriteParam(m, p.get() != NULL); | |
| 188 if (p) { | |
| 189 WriteParam(m, *p->elements()); | |
| 190 WriteParam(m, p->identifier()); | |
| 191 WriteParam(m, p->is_chunked()); | |
| 192 WriteParam(m, p->last_chunk_appended()); | |
| 193 } | |
| 194 } | |
| 195 | |
| 196 bool ParamTraits<scoped_refptr<net::UploadData> >::Read(const Message* m, | |
| 197 PickleIterator* iter, | |
| 198 param_type* r) { | |
| 199 bool has_object; | |
| 200 if (!ReadParam(m, iter, &has_object)) | |
| 201 return false; | |
| 202 if (!has_object) | |
| 203 return true; | |
| 204 std::vector<net::UploadElement> elements; | |
| 205 if (!ReadParam(m, iter, &elements)) | |
| 206 return false; | |
| 207 int64 identifier; | |
| 208 if (!ReadParam(m, iter, &identifier)) | |
| 209 return false; | |
| 210 bool is_chunked = false; | |
| 211 if (!ReadParam(m, iter, &is_chunked)) | |
| 212 return false; | |
| 213 bool last_chunk_appended = false; | |
| 214 if (!ReadParam(m, iter, &last_chunk_appended)) | |
| 215 return false; | |
| 216 *r = new net::UploadData; | |
| 217 (*r)->swap_elements(&elements); | |
| 218 (*r)->set_identifier(identifier); | |
| 219 (*r)->set_is_chunked(is_chunked); | |
| 220 (*r)->set_last_chunk_appended(last_chunk_appended); | |
| 221 return true; | |
| 222 } | |
| 223 | |
| 224 void ParamTraits<scoped_refptr<net::UploadData> >::Log(const param_type& p, | |
| 225 std::string* l) { | |
| 226 l->append("<net::UploadData>"); | |
| 227 } | |
| 228 | |
| 229 void ParamTraits<webkit_base::DataElement>::Write( | |
| 230 Message* m, const param_type& p) { | |
| 231 WriteParam(m, static_cast<int>(p.type())); | |
| 232 switch (p.type()) { | |
| 233 case webkit_base::DataElement::TYPE_BYTES: { | |
| 234 m->WriteData(p.bytes(), static_cast<int>(p.length())); | |
| 235 break; | |
| 236 } | |
| 237 case webkit_base::DataElement::TYPE_FILE: { | |
| 238 WriteParam(m, p.path()); | |
| 239 WriteParam(m, p.offset()); | |
| 240 WriteParam(m, p.length()); | |
| 241 WriteParam(m, p.expected_modification_time()); | |
| 242 break; | |
| 243 } | |
| 244 case webkit_base::DataElement::TYPE_FILE_FILESYSTEM: { | |
| 245 WriteParam(m, p.url()); | |
| 246 WriteParam(m, p.offset()); | |
| 247 WriteParam(m, p.length()); | |
| 248 WriteParam(m, p.expected_modification_time()); | |
| 249 break; | |
| 250 } | |
| 251 default: { | |
| 252 DCHECK(p.type() == webkit_base::DataElement::TYPE_BLOB); | |
| 253 WriteParam(m, p.url()); | |
| 254 WriteParam(m, p.offset()); | |
| 255 WriteParam(m, p.length()); | |
| 256 break; | |
| 257 } | |
| 258 } | |
| 259 } | |
| 260 | |
| 261 bool ParamTraits<webkit_base::DataElement>::Read( | |
| 262 const Message* m, PickleIterator* iter, param_type* r) { | |
| 263 int type; | |
| 264 if (!ReadParam(m, iter, &type)) | |
| 265 return false; | |
| 266 switch (type) { | |
| 267 case webkit_base::DataElement::TYPE_BYTES: { | |
| 268 const char* data; | |
| 269 int len; | |
| 270 if (!m->ReadData(iter, &data, &len)) | |
| 271 return false; | |
| 272 r->SetToBytes(data, len); | |
| 273 break; | |
| 274 } | |
| 275 case webkit_base::DataElement::TYPE_FILE: { | |
| 276 FilePath file_path; | |
| 277 uint64 offset, length; | |
| 278 base::Time expected_modification_time; | |
| 279 if (!ReadParam(m, iter, &file_path)) | |
| 280 return false; | |
| 281 if (!ReadParam(m, iter, &offset)) | |
| 282 return false; | |
| 283 if (!ReadParam(m, iter, &length)) | |
| 284 return false; | |
| 285 if (!ReadParam(m, iter, &expected_modification_time)) | |
| 286 return false; | |
| 287 r->SetToFilePathRange(file_path, offset, length, | |
| 288 expected_modification_time); | |
| 289 break; | |
| 290 } | |
| 291 case webkit_base::DataElement::TYPE_FILE_FILESYSTEM: { | |
| 292 GURL file_system_url; | |
| 293 uint64 offset, length; | |
| 294 base::Time expected_modification_time; | |
| 295 if (!ReadParam(m, iter, &file_system_url)) | |
| 296 return false; | |
| 297 if (!ReadParam(m, iter, &offset)) | |
| 298 return false; | |
| 299 if (!ReadParam(m, iter, &length)) | |
| 300 return false; | |
| 301 if (!ReadParam(m, iter, &expected_modification_time)) | |
| 302 return false; | |
| 303 r->SetToFileSystemUrlRange(file_system_url, offset, length, | |
| 304 expected_modification_time); | |
| 305 break; | |
| 306 } | |
| 307 default: { | |
| 308 DCHECK(type == webkit_base::DataElement::TYPE_BLOB); | |
| 309 GURL blob_url; | |
| 310 uint64 offset, length; | |
| 311 if (!ReadParam(m, iter, &blob_url)) | |
| 312 return false; | |
| 313 if (!ReadParam(m, iter, &offset)) | |
| 314 return false; | |
| 315 if (!ReadParam(m, iter, &length)) | |
| 316 return false; | |
| 317 r->SetToBlobUrlRange(blob_url, offset, length); | |
| 318 break; | |
| 319 } | |
| 320 } | |
| 321 return true; | |
| 322 } | |
| 323 | |
| 324 void ParamTraits<webkit_base::DataElement>::Log( | |
| 325 const param_type& p, std::string* l) { | |
| 326 l->append("<webkit_base::DataElement>"); | |
| 327 } | |
| 328 | |
| 329 void ParamTraits<scoped_refptr<webkit_glue::ResourceRequestBody> >::Write( | |
| 330 Message* m, | |
| 331 const param_type& p) { | |
| 332 WriteParam(m, p.get() != NULL); | |
| 333 if (p) { | |
| 334 WriteParam(m, *p->elements()); | |
| 335 WriteParam(m, p->identifier()); | |
| 336 } | |
| 337 } | |
| 338 | |
| 339 bool ParamTraits<scoped_refptr<webkit_glue::ResourceRequestBody> >::Read( | |
| 340 const Message* m, | |
| 341 PickleIterator* iter, | |
| 342 param_type* r) { | |
| 343 bool has_object; | |
| 344 if (!ReadParam(m, iter, &has_object)) | |
| 345 return false; | |
| 346 if (!has_object) | |
| 347 return true; | |
| 348 std::vector<webkit_base::DataElement> elements; | |
| 349 if (!ReadParam(m, iter, &elements)) | |
| 350 return false; | |
| 351 int64 identifier; | |
| 352 if (!ReadParam(m, iter, &identifier)) | |
| 353 return false; | |
| 354 *r = new webkit_glue::ResourceRequestBody; | |
| 355 (*r)->swap_elements(&elements); | |
| 356 (*r)->set_identifier(identifier); | |
| 357 return true; | |
| 358 } | |
| 359 | |
| 360 void ParamTraits<scoped_refptr<webkit_glue::ResourceRequestBody> >::Log( | |
| 361 const param_type& p, std::string* l) { | |
| 362 l->append("<webkit_glue::ResourceRequestBody>"); | |
| 363 } | |
| 364 | |
| 365 void ParamTraits<net::HostPortPair>::Write(Message* m, const param_type& p) { | 71 void ParamTraits<net::HostPortPair>::Write(Message* m, const param_type& p) { |
| 366 WriteParam(m, p.host()); | 72 WriteParam(m, p.host()); |
| 367 WriteParam(m, p.port()); | 73 WriteParam(m, p.port()); |
| 368 } | 74 } |
| 369 | 75 |
| 370 bool ParamTraits<net::HostPortPair>::Read(const Message* m, | 76 bool ParamTraits<net::HostPortPair>::Read(const Message* m, |
| 371 PickleIterator* iter, | 77 PickleIterator* iter, |
| 372 param_type* r) { | 78 param_type* r) { |
| 373 std::string host; | 79 std::string host; |
| 374 uint16 port; | 80 uint16 port; |
| 375 if (!ReadParam(m, iter, &host) || !ReadParam(m, iter, &port)) | 81 if (!ReadParam(m, iter, &host) || !ReadParam(m, iter, &port)) |
| 376 return false; | 82 return false; |
| 377 | 83 |
| 378 r->set_host(host); | 84 r->set_host(host); |
| 379 r->set_port(port); | 85 r->set_port(port); |
| 380 return true; | 86 return true; |
| 381 } | 87 } |
| 382 | 88 |
| 383 void ParamTraits<net::HostPortPair>::Log(const param_type& p, std::string* l) { | 89 void ParamTraits<net::HostPortPair>::Log(const param_type& p, std::string* l) { |
| 384 l->append(p.ToString()); | 90 l->append(p.ToString()); |
| 385 } | 91 } |
| 386 | 92 |
| 387 void ParamTraits<scoped_refptr<net::HttpResponseHeaders> >::Write( | |
| 388 Message* m, const param_type& p) { | |
| 389 WriteParam(m, p.get() != NULL); | |
| 390 if (p) { | |
| 391 // Do not disclose Set-Cookie headers over IPC. | |
| 392 p->Persist(m, net::HttpResponseHeaders::PERSIST_SANS_COOKIES); | |
| 393 } | |
| 394 } | |
| 395 | |
| 396 bool ParamTraits<scoped_refptr<net::HttpResponseHeaders> >::Read( | |
| 397 const Message* m, PickleIterator* iter, param_type* r) { | |
| 398 bool has_object; | |
| 399 if (!ReadParam(m, iter, &has_object)) | |
| 400 return false; | |
| 401 if (has_object) | |
| 402 *r = new net::HttpResponseHeaders(*m, iter); | |
| 403 return true; | |
| 404 } | |
| 405 | |
| 406 void ParamTraits<scoped_refptr<net::HttpResponseHeaders> >::Log( | |
| 407 const param_type& p, std::string* l) { | |
| 408 l->append("<HttpResponseHeaders>"); | |
| 409 } | |
| 410 | |
| 411 void ParamTraits<net::IPEndPoint>::Write(Message* m, const param_type& p) { | |
| 412 WriteParam(m, p.address()); | |
| 413 WriteParam(m, p.port()); | |
| 414 } | |
| 415 | |
| 416 bool ParamTraits<net::IPEndPoint>::Read(const Message* m, PickleIterator* iter, | |
| 417 param_type* p) { | |
| 418 net::IPAddressNumber address; | |
| 419 int port; | |
| 420 if (!ReadParam(m, iter, &address) || !ReadParam(m, iter, &port)) | |
| 421 return false; | |
| 422 *p = net::IPEndPoint(address, port); | |
| 423 return true; | |
| 424 } | |
| 425 | |
| 426 void ParamTraits<net::IPEndPoint>::Log(const param_type& p, std::string* l) { | |
| 427 LogParam("IPEndPoint:" + p.ToString(), l); | |
| 428 } | |
| 429 | |
| 430 void ParamTraits<content::Referrer>::Write( | 93 void ParamTraits<content::Referrer>::Write( |
| 431 Message* m, const param_type& p) { | 94 Message* m, const param_type& p) { |
| 432 WriteParam(m, p.url); | 95 WriteParam(m, p.url); |
| 433 WriteParam(m, p.policy); | 96 WriteParam(m, p.policy); |
| 434 } | 97 } |
| 435 | 98 |
| 436 bool ParamTraits<content::Referrer>::Read( | 99 bool ParamTraits<content::Referrer>::Read( |
| 437 const Message* m, PickleIterator* iter, param_type* r) { | 100 const Message* m, PickleIterator* iter, param_type* r) { |
| 438 return ReadParam(m, iter, &r->url) && ReadParam(m, iter, &r->policy); | 101 return ReadParam(m, iter, &r->url) && ReadParam(m, iter, &r->policy); |
| 439 } | 102 } |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 537 r->set_width(w); | 200 r->set_width(w); |
| 538 r->set_height(h); | 201 r->set_height(h); |
| 539 return true; | 202 return true; |
| 540 } | 203 } |
| 541 | 204 |
| 542 void ParamTraits<gfx::RectF>::Log(const gfx::RectF& p, std::string* l) { | 205 void ParamTraits<gfx::RectF>::Log(const gfx::RectF& p, std::string* l) { |
| 543 l->append(base::StringPrintf("(%f, %f, %f, %f)", p.x(), p.y(), | 206 l->append(base::StringPrintf("(%f, %f, %f, %f)", p.x(), p.y(), |
| 544 p.width(), p.height())); | 207 p.width(), p.height())); |
| 545 } | 208 } |
| 546 | 209 |
| 547 void ParamTraits<ui::Range>::Write(Message* m, const ui::Range& r) { | |
| 548 m->WriteUInt64(r.start()); | |
| 549 m->WriteUInt64(r.end()); | |
| 550 } | |
| 551 | |
| 552 bool ParamTraits<ui::Range>::Read(const Message* m, | |
| 553 PickleIterator* iter, | |
| 554 ui::Range* r) { | |
| 555 uint64 start, end; | |
| 556 if (!m->ReadUInt64(iter, &start) || !m->ReadUInt64(iter, &end)) | |
| 557 return false; | |
| 558 r->set_start(start); | |
| 559 r->set_end(end); | |
| 560 return true; | |
| 561 } | |
| 562 | |
| 563 void ParamTraits<ui::Range>::Log(const ui::Range& r, std::string* l) { | |
| 564 l->append(base::StringPrintf("(%"PRIuS", %"PRIuS")", r.start(), r.end())); | |
| 565 } | |
| 566 | |
| 567 void ParamTraits<SkBitmap>::Write(Message* m, const SkBitmap& p) { | 210 void ParamTraits<SkBitmap>::Write(Message* m, const SkBitmap& p) { |
| 568 size_t fixed_size = sizeof(SkBitmap_Data); | 211 size_t fixed_size = sizeof(SkBitmap_Data); |
| 569 SkBitmap_Data bmp_data; | 212 SkBitmap_Data bmp_data; |
| 570 bmp_data.InitSkBitmapDataForTransfer(p); | 213 bmp_data.InitSkBitmapDataForTransfer(p); |
| 571 m->WriteData(reinterpret_cast<const char*>(&bmp_data), | 214 m->WriteData(reinterpret_cast<const char*>(&bmp_data), |
| 572 static_cast<int>(fixed_size)); | 215 static_cast<int>(fixed_size)); |
| 573 size_t pixel_size = p.getSize(); | 216 size_t pixel_size = p.getSize(); |
| 574 SkAutoLockPixels p_lock(p); | 217 SkAutoLockPixels p_lock(p); |
| 575 m->WriteData(reinterpret_cast<const char*>(p.getPixels()), | 218 m->WriteData(reinterpret_cast<const char*>(p.getPixels()), |
| 576 static_cast<int>(pixel_size)); | 219 static_cast<int>(pixel_size)); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 620 #undef CONTENT_PUBLIC_COMMON_COMMON_PARAM_TRAITS_MACROS_H_ | 263 #undef CONTENT_PUBLIC_COMMON_COMMON_PARAM_TRAITS_MACROS_H_ |
| 621 #include "content/public/common/common_param_traits_macros.h" | 264 #include "content/public/common/common_param_traits_macros.h" |
| 622 } // namespace IPC | 265 } // namespace IPC |
| 623 | 266 |
| 624 // Generate param traits log methods. | 267 // Generate param traits log methods. |
| 625 #include "ipc/param_traits_log_macros.h" | 268 #include "ipc/param_traits_log_macros.h" |
| 626 namespace IPC { | 269 namespace IPC { |
| 627 #undef CONTENT_PUBLIC_COMMON_COMMON_PARAM_TRAITS_MACROS_H_ | 270 #undef CONTENT_PUBLIC_COMMON_COMMON_PARAM_TRAITS_MACROS_H_ |
| 628 #include "content/public/common/common_param_traits_macros.h" | 271 #include "content/public/common/common_param_traits_macros.h" |
| 629 } // namespace IPC | 272 } // namespace IPC |
| OLD | NEW |