| 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 // NOTE: New trait definitions that will be used by Chrome Frame must be placed |
| 6 // in common_param_traits2.cc. |
| 7 |
| 5 #include "content/common/common_param_traits.h" | 8 #include "content/common/common_param_traits.h" |
| 6 | 9 |
| 7 #include "content/common/content_constants.h" | 10 #include "content/common/content_constants.h" |
| 8 #include "net/base/host_port_pair.h" | |
| 9 #include "net/base/upload_data.h" | |
| 10 #include "net/http/http_response_headers.h" | 11 #include "net/http/http_response_headers.h" |
| 11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h" | 12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h" |
| 12 #include "third_party/skia/include/core/SkBitmap.h" | 13 #include "third_party/skia/include/core/SkBitmap.h" |
| 13 #include "ui/gfx/rect.h" | |
| 14 #include "webkit/glue/password_form.h" | 14 #include "webkit/glue/password_form.h" |
| 15 #include "webkit/glue/resource_loader_bridge.h" | 15 #include "webkit/glue/resource_loader_bridge.h" |
| 16 | 16 |
| 17 namespace { | 17 namespace { |
| 18 | 18 |
| 19 struct SkBitmap_Data { | 19 struct SkBitmap_Data { |
| 20 // The configuration for the bitmap (bits per pixel, etc). | 20 // The configuration for the bitmap (bits per pixel, etc). |
| 21 SkBitmap::Config fConfig; | 21 SkBitmap::Config fConfig; |
| 22 | 22 |
| 23 // The width of the bitmap in pixels. | 23 // The width of the bitmap in pixels. |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 int_value(0), | 62 int_value(0), |
| 63 double_value(0), | 63 double_value(0), |
| 64 npobject_routing_id(-1) { | 64 npobject_routing_id(-1) { |
| 65 } | 65 } |
| 66 | 66 |
| 67 NPVariant_Param::~NPVariant_Param() { | 67 NPVariant_Param::~NPVariant_Param() { |
| 68 } | 68 } |
| 69 | 69 |
| 70 namespace IPC { | 70 namespace IPC { |
| 71 | 71 |
| 72 void ParamTraits<GURL>::Write(Message* m, const GURL& p) { | |
| 73 m->WriteString(p.possibly_invalid_spec()); | |
| 74 // TODO(brettw) bug 684583: Add encoding for query params. | |
| 75 } | |
| 76 | |
| 77 bool ParamTraits<GURL>::Read(const Message* m, void** iter, GURL* p) { | |
| 78 std::string s; | |
| 79 if (!m->ReadString(iter, &s) || s.length() > content::kMaxURLChars) { | |
| 80 *p = GURL(); | |
| 81 return false; | |
| 82 } | |
| 83 *p = GURL(s); | |
| 84 return true; | |
| 85 } | |
| 86 | |
| 87 void ParamTraits<GURL>::Log(const GURL& p, std::string* l) { | |
| 88 l->append(p.spec()); | |
| 89 } | |
| 90 | |
| 91 | |
| 92 void ParamTraits<ResourceType::Type>::Write(Message* m, const param_type& p) { | 72 void ParamTraits<ResourceType::Type>::Write(Message* m, const param_type& p) { |
| 93 m->WriteInt(p); | 73 m->WriteInt(p); |
| 94 } | 74 } |
| 95 | 75 |
| 96 bool ParamTraits<ResourceType::Type>::Read(const Message* m, | 76 bool ParamTraits<ResourceType::Type>::Read(const Message* m, |
| 97 void** iter, | 77 void** iter, |
| 98 param_type* p) { | 78 param_type* p) { |
| 99 int type; | 79 int type; |
| 100 if (!m->ReadInt(iter, &type) || !ResourceType::ValidType(type)) | 80 if (!m->ReadInt(iter, &type) || !ResourceType::ValidType(type)) |
| 101 return false; | 81 return false; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 type = "FAVICON"; | 126 type = "FAVICON"; |
| 147 break; | 127 break; |
| 148 default: | 128 default: |
| 149 type = "UNKNOWN"; | 129 type = "UNKNOWN"; |
| 150 break; | 130 break; |
| 151 } | 131 } |
| 152 | 132 |
| 153 LogParam(type, l); | 133 LogParam(type, l); |
| 154 } | 134 } |
| 155 | 135 |
| 156 void ParamTraits<net::URLRequestStatus>::Write(Message* m, | |
| 157 const param_type& p) { | |
| 158 WriteParam(m, static_cast<int>(p.status())); | |
| 159 WriteParam(m, p.os_error()); | |
| 160 } | |
| 161 | |
| 162 bool ParamTraits<net::URLRequestStatus>::Read(const Message* m, void** iter, | |
| 163 param_type* r) { | |
| 164 int status, os_error; | |
| 165 if (!ReadParam(m, iter, &status) || | |
| 166 !ReadParam(m, iter, &os_error)) | |
| 167 return false; | |
| 168 r->set_status(static_cast<net::URLRequestStatus::Status>(status)); | |
| 169 r->set_os_error(os_error); | |
| 170 return true; | |
| 171 } | |
| 172 | |
| 173 void ParamTraits<net::URLRequestStatus>::Log(const param_type& p, | |
| 174 std::string* l) { | |
| 175 std::string status; | |
| 176 switch (p.status()) { | |
| 177 case net::URLRequestStatus::SUCCESS: | |
| 178 status = "SUCCESS"; | |
| 179 break; | |
| 180 case net::URLRequestStatus::IO_PENDING: | |
| 181 status = "IO_PENDING "; | |
| 182 break; | |
| 183 case net::URLRequestStatus::HANDLED_EXTERNALLY: | |
| 184 status = "HANDLED_EXTERNALLY"; | |
| 185 break; | |
| 186 case net::URLRequestStatus::CANCELED: | |
| 187 status = "CANCELED"; | |
| 188 break; | |
| 189 case net::URLRequestStatus::FAILED: | |
| 190 status = "FAILED"; | |
| 191 break; | |
| 192 default: | |
| 193 status = "UNKNOWN"; | |
| 194 break; | |
| 195 } | |
| 196 if (p.status() == net::URLRequestStatus::FAILED) | |
| 197 l->append("("); | |
| 198 | |
| 199 LogParam(status, l); | |
| 200 | |
| 201 if (p.status() == net::URLRequestStatus::FAILED) { | |
| 202 l->append(", "); | |
| 203 LogParam(p.os_error(), l); | |
| 204 l->append(")"); | |
| 205 } | |
| 206 } | |
| 207 | |
| 208 // Only the net::UploadData ParamTraits<> definition needs this definition, so | |
| 209 // keep this in the implementation file so we can forward declare UploadData in | |
| 210 // the header. | |
| 211 template <> | |
| 212 struct ParamTraits<net::UploadData::Element> { | |
| 213 typedef net::UploadData::Element param_type; | |
| 214 static void Write(Message* m, const param_type& p) { | |
| 215 WriteParam(m, static_cast<int>(p.type())); | |
| 216 switch (p.type()) { | |
| 217 case net::UploadData::TYPE_BYTES: { | |
| 218 m->WriteData(&p.bytes()[0], static_cast<int>(p.bytes().size())); | |
| 219 break; | |
| 220 } | |
| 221 case net::UploadData::TYPE_CHUNK: { | |
| 222 std::string chunk_length = StringPrintf( | |
| 223 "%X\r\n", static_cast<unsigned int>(p.bytes().size())); | |
| 224 std::vector<char> bytes; | |
| 225 bytes.insert(bytes.end(), chunk_length.data(), | |
| 226 chunk_length.data() + chunk_length.length()); | |
| 227 const char* data = &p.bytes()[0]; | |
| 228 bytes.insert(bytes.end(), data, data + p.bytes().size()); | |
| 229 const char* crlf = "\r\n"; | |
| 230 bytes.insert(bytes.end(), crlf, crlf + strlen(crlf)); | |
| 231 if (p.is_last_chunk()) { | |
| 232 const char* end_of_data = "0\r\n\r\n"; | |
| 233 bytes.insert(bytes.end(), end_of_data, | |
| 234 end_of_data + strlen(end_of_data)); | |
| 235 } | |
| 236 m->WriteData(&bytes[0], static_cast<int>(bytes.size())); | |
| 237 // If this element is part of a chunk upload then send over information | |
| 238 // indicating if this is the last chunk. | |
| 239 WriteParam(m, p.is_last_chunk()); | |
| 240 break; | |
| 241 } | |
| 242 case net::UploadData::TYPE_FILE: { | |
| 243 WriteParam(m, p.file_path()); | |
| 244 WriteParam(m, p.file_range_offset()); | |
| 245 WriteParam(m, p.file_range_length()); | |
| 246 WriteParam(m, p.expected_file_modification_time()); | |
| 247 break; | |
| 248 } | |
| 249 default: { | |
| 250 WriteParam(m, p.blob_url()); | |
| 251 break; | |
| 252 } | |
| 253 } | |
| 254 } | |
| 255 static bool Read(const Message* m, void** iter, param_type* r) { | |
| 256 int type; | |
| 257 if (!ReadParam(m, iter, &type)) | |
| 258 return false; | |
| 259 switch (type) { | |
| 260 case net::UploadData::TYPE_BYTES: { | |
| 261 const char* data; | |
| 262 int len; | |
| 263 if (!m->ReadData(iter, &data, &len)) | |
| 264 return false; | |
| 265 r->SetToBytes(data, len); | |
| 266 break; | |
| 267 } | |
| 268 case net::UploadData::TYPE_CHUNK: { | |
| 269 const char* data; | |
| 270 int len; | |
| 271 if (!m->ReadData(iter, &data, &len)) | |
| 272 return false; | |
| 273 r->SetToBytes(data, len); | |
| 274 // If this element is part of a chunk upload then we need to explicitly | |
| 275 // set the type of the element and whether it is the last chunk. | |
| 276 bool is_last_chunk = false; | |
| 277 if (!ReadParam(m, iter, &is_last_chunk)) | |
| 278 return false; | |
| 279 r->set_type(net::UploadData::TYPE_CHUNK); | |
| 280 r->set_is_last_chunk(is_last_chunk); | |
| 281 break; | |
| 282 } | |
| 283 case net::UploadData::TYPE_FILE: { | |
| 284 FilePath file_path; | |
| 285 uint64 offset, length; | |
| 286 base::Time expected_modification_time; | |
| 287 if (!ReadParam(m, iter, &file_path)) | |
| 288 return false; | |
| 289 if (!ReadParam(m, iter, &offset)) | |
| 290 return false; | |
| 291 if (!ReadParam(m, iter, &length)) | |
| 292 return false; | |
| 293 if (!ReadParam(m, iter, &expected_modification_time)) | |
| 294 return false; | |
| 295 r->SetToFilePathRange(file_path, offset, length, | |
| 296 expected_modification_time); | |
| 297 break; | |
| 298 } | |
| 299 default: { | |
| 300 DCHECK(type == net::UploadData::TYPE_BLOB); | |
| 301 GURL blob_url; | |
| 302 if (!ReadParam(m, iter, &blob_url)) | |
| 303 return false; | |
| 304 r->SetToBlobUrl(blob_url); | |
| 305 break; | |
| 306 } | |
| 307 } | |
| 308 return true; | |
| 309 } | |
| 310 static void Log(const param_type& p, std::string* l) { | |
| 311 l->append("<net::UploadData::Element>"); | |
| 312 } | |
| 313 }; | |
| 314 | |
| 315 void ParamTraits<scoped_refptr<net::UploadData> >::Write(Message* m, | |
| 316 const param_type& p) { | |
| 317 WriteParam(m, p.get() != NULL); | |
| 318 if (p) { | |
| 319 WriteParam(m, *p->elements()); | |
| 320 WriteParam(m, p->identifier()); | |
| 321 WriteParam(m, p->is_chunked()); | |
| 322 } | |
| 323 } | |
| 324 | |
| 325 bool ParamTraits<scoped_refptr<net::UploadData> >::Read(const Message* m, | |
| 326 void** iter, | |
| 327 param_type* r) { | |
| 328 bool has_object; | |
| 329 if (!ReadParam(m, iter, &has_object)) | |
| 330 return false; | |
| 331 if (!has_object) | |
| 332 return true; | |
| 333 std::vector<net::UploadData::Element> elements; | |
| 334 if (!ReadParam(m, iter, &elements)) | |
| 335 return false; | |
| 336 int64 identifier; | |
| 337 if (!ReadParam(m, iter, &identifier)) | |
| 338 return false; | |
| 339 bool is_chunked = false; | |
| 340 if (!ReadParam(m, iter, &is_chunked)) | |
| 341 return false; | |
| 342 *r = new net::UploadData; | |
| 343 (*r)->swap_elements(&elements); | |
| 344 (*r)->set_identifier(identifier); | |
| 345 (*r)->set_is_chunked(is_chunked); | |
| 346 return true; | |
| 347 } | |
| 348 | |
| 349 void ParamTraits<scoped_refptr<net::UploadData> >::Log(const param_type& p, | |
| 350 std::string* l) { | |
| 351 l->append("<net::UploadData>"); | |
| 352 } | |
| 353 | |
| 354 void ParamTraits<net::HostPortPair>::Write(Message* m, const param_type& p) { | |
| 355 WriteParam(m, p.host()); | |
| 356 WriteParam(m, p.port()); | |
| 357 } | |
| 358 | |
| 359 bool ParamTraits<net::HostPortPair>::Read(const Message* m, void** iter, | |
| 360 param_type* r) { | |
| 361 std::string host; | |
| 362 uint16 port; | |
| 363 if (!ReadParam(m, iter, &host) || !ReadParam(m, iter, &port)) | |
| 364 return false; | |
| 365 | |
| 366 r->set_host(host); | |
| 367 r->set_port(port); | |
| 368 return true; | |
| 369 } | |
| 370 | |
| 371 void ParamTraits<net::HostPortPair>::Log(const param_type& p, std::string* l) { | |
| 372 l->append(p.ToString()); | |
| 373 } | |
| 374 | |
| 375 void ParamTraits<scoped_refptr<net::HttpResponseHeaders> >::Write( | 136 void ParamTraits<scoped_refptr<net::HttpResponseHeaders> >::Write( |
| 376 Message* m, const param_type& p) { | 137 Message* m, const param_type& p) { |
| 377 WriteParam(m, p.get() != NULL); | 138 WriteParam(m, p.get() != NULL); |
| 378 if (p) { | 139 if (p) { |
| 379 // Do not disclose Set-Cookie headers over IPC. | 140 // Do not disclose Set-Cookie headers over IPC. |
| 380 p->Persist(m, net::HttpResponseHeaders::PERSIST_SANS_COOKIES); | 141 p->Persist(m, net::HttpResponseHeaders::PERSIST_SANS_COOKIES); |
| 381 } | 142 } |
| 382 } | 143 } |
| 383 | 144 |
| 384 bool ParamTraits<scoped_refptr<net::HttpResponseHeaders> >::Read( | 145 bool ParamTraits<scoped_refptr<net::HttpResponseHeaders> >::Read( |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 563 LogParam(p.is_directory, l); | 324 LogParam(p.is_directory, l); |
| 564 l->append(","); | 325 l->append(","); |
| 565 LogParam(p.last_modified.ToDoubleT(), l); | 326 LogParam(p.last_modified.ToDoubleT(), l); |
| 566 l->append(","); | 327 l->append(","); |
| 567 LogParam(p.last_accessed.ToDoubleT(), l); | 328 LogParam(p.last_accessed.ToDoubleT(), l); |
| 568 l->append(","); | 329 l->append(","); |
| 569 LogParam(p.creation_time.ToDoubleT(), l); | 330 LogParam(p.creation_time.ToDoubleT(), l); |
| 570 l->append(")"); | 331 l->append(")"); |
| 571 } | 332 } |
| 572 | 333 |
| 573 void ParamTraits<gfx::Point>::Write(Message* m, const gfx::Point& p) { | |
| 574 m->WriteInt(p.x()); | |
| 575 m->WriteInt(p.y()); | |
| 576 } | |
| 577 | |
| 578 bool ParamTraits<gfx::Point>::Read(const Message* m, void** iter, | |
| 579 gfx::Point* r) { | |
| 580 int x, y; | |
| 581 if (!m->ReadInt(iter, &x) || | |
| 582 !m->ReadInt(iter, &y)) | |
| 583 return false; | |
| 584 r->set_x(x); | |
| 585 r->set_y(y); | |
| 586 return true; | |
| 587 } | |
| 588 | |
| 589 void ParamTraits<gfx::Point>::Log(const gfx::Point& p, std::string* l) { | |
| 590 l->append(base::StringPrintf("(%d, %d)", p.x(), p.y())); | |
| 591 } | |
| 592 | |
| 593 void ParamTraits<gfx::Size>::Write(Message* m, const gfx::Size& p) { | 334 void ParamTraits<gfx::Size>::Write(Message* m, const gfx::Size& p) { |
| 594 m->WriteInt(p.width()); | 335 m->WriteInt(p.width()); |
| 595 m->WriteInt(p.height()); | 336 m->WriteInt(p.height()); |
| 596 } | 337 } |
| 597 | 338 |
| 598 bool ParamTraits<gfx::Size>::Read(const Message* m, void** iter, gfx::Size* r) { | 339 bool ParamTraits<gfx::Size>::Read(const Message* m, void** iter, gfx::Size* r) { |
| 599 int w, h; | 340 int w, h; |
| 600 if (!m->ReadInt(iter, &w) || | 341 if (!m->ReadInt(iter, &w) || |
| 601 !m->ReadInt(iter, &h)) | 342 !m->ReadInt(iter, &h)) |
| 602 return false; | 343 return false; |
| 603 r->set_width(w); | 344 r->set_width(w); |
| 604 r->set_height(h); | 345 r->set_height(h); |
| 605 return true; | 346 return true; |
| 606 } | 347 } |
| 607 | 348 |
| 608 void ParamTraits<gfx::Size>::Log(const gfx::Size& p, std::string* l) { | 349 void ParamTraits<gfx::Size>::Log(const gfx::Size& p, std::string* l) { |
| 609 l->append(base::StringPrintf("(%d, %d)", p.width(), p.height())); | 350 l->append(base::StringPrintf("(%d, %d)", p.width(), p.height())); |
| 610 } | 351 } |
| 611 | 352 |
| 612 void ParamTraits<gfx::Rect>::Write(Message* m, const gfx::Rect& p) { | |
| 613 m->WriteInt(p.x()); | |
| 614 m->WriteInt(p.y()); | |
| 615 m->WriteInt(p.width()); | |
| 616 m->WriteInt(p.height()); | |
| 617 } | |
| 618 | |
| 619 bool ParamTraits<gfx::Rect>::Read(const Message* m, void** iter, gfx::Rect* r) { | |
| 620 int x, y, w, h; | |
| 621 if (!m->ReadInt(iter, &x) || | |
| 622 !m->ReadInt(iter, &y) || | |
| 623 !m->ReadInt(iter, &w) || | |
| 624 !m->ReadInt(iter, &h)) | |
| 625 return false; | |
| 626 r->set_x(x); | |
| 627 r->set_y(y); | |
| 628 r->set_width(w); | |
| 629 r->set_height(h); | |
| 630 return true; | |
| 631 } | |
| 632 | |
| 633 void ParamTraits<gfx::Rect>::Log(const gfx::Rect& p, std::string* l) { | |
| 634 l->append(base::StringPrintf("(%d, %d, %d, %d)", p.x(), p.y(), | |
| 635 p.width(), p.height())); | |
| 636 } | |
| 637 | |
| 638 // Only the webkit_blob::BlobData ParamTraits<> definition needs this | 353 // Only the webkit_blob::BlobData ParamTraits<> definition needs this |
| 639 // definition, so keep this in the implementation file so we can forward declare | 354 // definition, so keep this in the implementation file so we can forward declare |
| 640 // BlobData in the header. | 355 // BlobData in the header. |
| 641 template <> | 356 template <> |
| 642 struct ParamTraits<webkit_blob::BlobData::Item> { | 357 struct ParamTraits<webkit_blob::BlobData::Item> { |
| 643 typedef webkit_blob::BlobData::Item param_type; | 358 typedef webkit_blob::BlobData::Item param_type; |
| 644 static void Write(Message* m, const param_type& p) { | 359 static void Write(Message* m, const param_type& p) { |
| 645 WriteParam(m, static_cast<int>(p.type())); | 360 WriteParam(m, static_cast<int>(p.type())); |
| 646 if (p.type() == webkit_blob::BlobData::TYPE_DATA) { | 361 if (p.type() == webkit_blob::BlobData::TYPE_DATA) { |
| 647 WriteParam(m, p.data()); | 362 WriteParam(m, p.data()); |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 894 ReadParam(m, iter, &p->ssl_valid) && | 609 ReadParam(m, iter, &p->ssl_valid) && |
| 895 ReadParam(m, iter, &p->preferred) && | 610 ReadParam(m, iter, &p->preferred) && |
| 896 ReadParam(m, iter, &p->blacklisted_by_user); | 611 ReadParam(m, iter, &p->blacklisted_by_user); |
| 897 } | 612 } |
| 898 void ParamTraits<webkit_glue::PasswordForm>::Log(const param_type& p, | 613 void ParamTraits<webkit_glue::PasswordForm>::Log(const param_type& p, |
| 899 std::string* l) { | 614 std::string* l) { |
| 900 l->append("<PasswordForm>"); | 615 l->append("<PasswordForm>"); |
| 901 } | 616 } |
| 902 | 617 |
| 903 } // namespace IPC | 618 } // namespace IPC |
| OLD | NEW |