OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 // NOTE: New trait definitions that will be used by Chrome Frame must be placed |
| 6 // in common_param_traits2.cc. |
| 7 |
| 8 #include "content/common/webkit_param_traits.h" |
| 9 |
| 10 #include "base/string_number_conversions.h" |
| 11 #include "content/common/common_param_traits.h" |
| 12 #include "content/common/content_constants.h" |
| 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h" |
| 14 #include "webkit/glue/password_form.h" |
| 15 #include "webkit/glue/resource_loader_bridge.h" |
| 16 |
| 17 NPIdentifier_Param::NPIdentifier_Param() |
| 18 : identifier() { |
| 19 } |
| 20 |
| 21 NPIdentifier_Param::~NPIdentifier_Param() { |
| 22 } |
| 23 |
| 24 NPVariant_Param::NPVariant_Param() |
| 25 : type(NPVARIANT_PARAM_VOID), |
| 26 bool_value(false), |
| 27 int_value(0), |
| 28 double_value(0), |
| 29 npobject_routing_id(-1) { |
| 30 } |
| 31 |
| 32 NPVariant_Param::~NPVariant_Param() { |
| 33 } |
| 34 |
| 35 namespace IPC { |
| 36 |
| 37 void ParamTraits<webkit_glue::ResourceLoadTimingInfo>::Write( |
| 38 Message* m, const param_type& p) { |
| 39 WriteParam(m, p.base_time.is_null()); |
| 40 if (p.base_time.is_null()) |
| 41 return; |
| 42 WriteParam(m, p.base_time); |
| 43 WriteParam(m, p.proxy_start); |
| 44 WriteParam(m, p.proxy_end); |
| 45 WriteParam(m, p.dns_start); |
| 46 WriteParam(m, p.dns_end); |
| 47 WriteParam(m, p.connect_start); |
| 48 WriteParam(m, p.connect_end); |
| 49 WriteParam(m, p.ssl_start); |
| 50 WriteParam(m, p.ssl_end); |
| 51 WriteParam(m, p.send_start); |
| 52 WriteParam(m, p.send_end); |
| 53 WriteParam(m, p.receive_headers_start); |
| 54 WriteParam(m, p.receive_headers_end); |
| 55 } |
| 56 |
| 57 bool ParamTraits<webkit_glue::ResourceLoadTimingInfo>::Read( |
| 58 const Message* m, void** iter, param_type* r) { |
| 59 bool is_null; |
| 60 if (!ReadParam(m, iter, &is_null)) |
| 61 return false; |
| 62 if (is_null) |
| 63 return true; |
| 64 |
| 65 return |
| 66 ReadParam(m, iter, &r->base_time) && |
| 67 ReadParam(m, iter, &r->proxy_start) && |
| 68 ReadParam(m, iter, &r->proxy_end) && |
| 69 ReadParam(m, iter, &r->dns_start) && |
| 70 ReadParam(m, iter, &r->dns_end) && |
| 71 ReadParam(m, iter, &r->connect_start) && |
| 72 ReadParam(m, iter, &r->connect_end) && |
| 73 ReadParam(m, iter, &r->ssl_start) && |
| 74 ReadParam(m, iter, &r->ssl_end) && |
| 75 ReadParam(m, iter, &r->send_start) && |
| 76 ReadParam(m, iter, &r->send_end) && |
| 77 ReadParam(m, iter, &r->receive_headers_start) && |
| 78 ReadParam(m, iter, &r->receive_headers_end); |
| 79 } |
| 80 |
| 81 void ParamTraits<webkit_glue::ResourceLoadTimingInfo>::Log(const param_type& p, |
| 82 std::string* l) { |
| 83 l->append("("); |
| 84 LogParam(p.base_time, l); |
| 85 l->append(", "); |
| 86 LogParam(p.proxy_start, l); |
| 87 l->append(", "); |
| 88 LogParam(p.proxy_end, l); |
| 89 l->append(", "); |
| 90 LogParam(p.dns_start, l); |
| 91 l->append(", "); |
| 92 LogParam(p.dns_end, l); |
| 93 l->append(", "); |
| 94 LogParam(p.connect_start, l); |
| 95 l->append(", "); |
| 96 LogParam(p.connect_end, l); |
| 97 l->append(", "); |
| 98 LogParam(p.ssl_start, l); |
| 99 l->append(", "); |
| 100 LogParam(p.ssl_end, l); |
| 101 l->append(", "); |
| 102 LogParam(p.send_start, l); |
| 103 l->append(", "); |
| 104 LogParam(p.send_end, l); |
| 105 l->append(", "); |
| 106 LogParam(p.receive_headers_start, l); |
| 107 l->append(", "); |
| 108 LogParam(p.receive_headers_end, l); |
| 109 l->append(")"); |
| 110 } |
| 111 |
| 112 void ParamTraits<scoped_refptr<webkit_glue::ResourceDevToolsInfo> >::Write( |
| 113 Message* m, const param_type& p) { |
| 114 WriteParam(m, p.get() != NULL); |
| 115 if (p.get()) { |
| 116 WriteParam(m, p->http_status_code); |
| 117 WriteParam(m, p->http_status_text); |
| 118 WriteParam(m, p->request_headers); |
| 119 WriteParam(m, p->response_headers); |
| 120 } |
| 121 } |
| 122 |
| 123 bool ParamTraits<scoped_refptr<webkit_glue::ResourceDevToolsInfo> >::Read( |
| 124 const Message* m, void** iter, param_type* r) { |
| 125 bool has_object; |
| 126 if (!ReadParam(m, iter, &has_object)) |
| 127 return false; |
| 128 if (!has_object) |
| 129 return true; |
| 130 *r = new webkit_glue::ResourceDevToolsInfo(); |
| 131 return |
| 132 ReadParam(m, iter, &(*r)->http_status_code) && |
| 133 ReadParam(m, iter, &(*r)->http_status_text) && |
| 134 ReadParam(m, iter, &(*r)->request_headers) && |
| 135 ReadParam(m, iter, &(*r)->response_headers); |
| 136 } |
| 137 |
| 138 void ParamTraits<scoped_refptr<webkit_glue::ResourceDevToolsInfo> >::Log( |
| 139 const param_type& p, std::string* l) { |
| 140 l->append("("); |
| 141 if (p) { |
| 142 LogParam(p->request_headers, l); |
| 143 l->append(", "); |
| 144 LogParam(p->response_headers, l); |
| 145 } |
| 146 l->append(")"); |
| 147 } |
| 148 |
| 149 // Only the webkit_blob::BlobData ParamTraits<> definition needs this |
| 150 // definition, so keep this in the implementation file so we can forward declare |
| 151 // BlobData in the header. |
| 152 template <> |
| 153 struct ParamTraits<webkit_blob::BlobData::Item> { |
| 154 typedef webkit_blob::BlobData::Item param_type; |
| 155 static void Write(Message* m, const param_type& p) { |
| 156 WriteParam(m, static_cast<int>(p.type())); |
| 157 if (p.type() == webkit_blob::BlobData::TYPE_DATA) { |
| 158 WriteParam(m, p.data()); |
| 159 } else if (p.type() == webkit_blob::BlobData::TYPE_FILE) { |
| 160 WriteParam(m, p.file_path()); |
| 161 WriteParam(m, p.offset()); |
| 162 WriteParam(m, p.length()); |
| 163 WriteParam(m, p.expected_modification_time()); |
| 164 } else { |
| 165 WriteParam(m, p.blob_url()); |
| 166 WriteParam(m, p.offset()); |
| 167 WriteParam(m, p.length()); |
| 168 } |
| 169 } |
| 170 static bool Read(const Message* m, void** iter, param_type* r) { |
| 171 int type; |
| 172 if (!ReadParam(m, iter, &type)) |
| 173 return false; |
| 174 if (type == webkit_blob::BlobData::TYPE_DATA) { |
| 175 std::string data; |
| 176 if (!ReadParam(m, iter, &data)) |
| 177 return false; |
| 178 r->SetToData(data); |
| 179 } else if (type == webkit_blob::BlobData::TYPE_FILE) { |
| 180 FilePath file_path; |
| 181 uint64 offset, length; |
| 182 base::Time expected_modification_time; |
| 183 if (!ReadParam(m, iter, &file_path)) |
| 184 return false; |
| 185 if (!ReadParam(m, iter, &offset)) |
| 186 return false; |
| 187 if (!ReadParam(m, iter, &length)) |
| 188 return false; |
| 189 if (!ReadParam(m, iter, &expected_modification_time)) |
| 190 return false; |
| 191 r->SetToFile(file_path, offset, length, expected_modification_time); |
| 192 } else { |
| 193 DCHECK(type == webkit_blob::BlobData::TYPE_BLOB); |
| 194 GURL blob_url; |
| 195 uint64 offset, length; |
| 196 if (!ReadParam(m, iter, &blob_url)) |
| 197 return false; |
| 198 if (!ReadParam(m, iter, &offset)) |
| 199 return false; |
| 200 if (!ReadParam(m, iter, &length)) |
| 201 return false; |
| 202 r->SetToBlob(blob_url, offset, length); |
| 203 } |
| 204 return true; |
| 205 } |
| 206 static void Log(const param_type& p, std::string* l) { |
| 207 l->append("<BlobData::Item>"); |
| 208 } |
| 209 }; |
| 210 |
| 211 void ParamTraits<scoped_refptr<webkit_blob::BlobData> >::Write( |
| 212 Message* m, const param_type& p) { |
| 213 WriteParam(m, p.get() != NULL); |
| 214 if (p) { |
| 215 WriteParam(m, p->items()); |
| 216 WriteParam(m, p->content_type()); |
| 217 WriteParam(m, p->content_disposition()); |
| 218 } |
| 219 } |
| 220 |
| 221 bool ParamTraits<scoped_refptr<webkit_blob::BlobData> >::Read( |
| 222 const Message* m, void** iter, param_type* r) { |
| 223 bool has_object; |
| 224 if (!ReadParam(m, iter, &has_object)) |
| 225 return false; |
| 226 if (!has_object) |
| 227 return true; |
| 228 std::vector<webkit_blob::BlobData::Item> items; |
| 229 if (!ReadParam(m, iter, &items)) |
| 230 return false; |
| 231 std::string content_type; |
| 232 if (!ReadParam(m, iter, &content_type)) |
| 233 return false; |
| 234 std::string content_disposition; |
| 235 if (!ReadParam(m, iter, &content_disposition)) |
| 236 return false; |
| 237 *r = new webkit_blob::BlobData; |
| 238 (*r)->swap_items(&items); |
| 239 (*r)->set_content_type(content_type); |
| 240 (*r)->set_content_disposition(content_disposition); |
| 241 return true; |
| 242 } |
| 243 |
| 244 void ParamTraits<scoped_refptr<webkit_blob::BlobData> >::Log( |
| 245 const param_type& p, std::string* l) { |
| 246 l->append("<webkit_blob::BlobData>"); |
| 247 } |
| 248 |
| 249 void ParamTraits<NPVariant_Param>::Write(Message* m, const param_type& p) { |
| 250 WriteParam(m, static_cast<int>(p.type)); |
| 251 if (p.type == NPVARIANT_PARAM_BOOL) { |
| 252 WriteParam(m, p.bool_value); |
| 253 } else if (p.type == NPVARIANT_PARAM_INT) { |
| 254 WriteParam(m, p.int_value); |
| 255 } else if (p.type == NPVARIANT_PARAM_DOUBLE) { |
| 256 WriteParam(m, p.double_value); |
| 257 } else if (p.type == NPVARIANT_PARAM_STRING) { |
| 258 WriteParam(m, p.string_value); |
| 259 } else if (p.type == NPVARIANT_PARAM_SENDER_OBJECT_ROUTING_ID || |
| 260 p.type == NPVARIANT_PARAM_RECEIVER_OBJECT_ROUTING_ID) { |
| 261 // This is the routing id used to connect NPObjectProxy in the other |
| 262 // process with NPObjectStub in this process or to identify the raw |
| 263 // npobject pointer to be used in the callee process. |
| 264 WriteParam(m, p.npobject_routing_id); |
| 265 } else { |
| 266 DCHECK(p.type == NPVARIANT_PARAM_VOID || p.type == NPVARIANT_PARAM_NULL); |
| 267 } |
| 268 } |
| 269 |
| 270 bool ParamTraits<NPVariant_Param>::Read(const Message* m, |
| 271 void** iter, |
| 272 param_type* r) { |
| 273 int type; |
| 274 if (!ReadParam(m, iter, &type)) |
| 275 return false; |
| 276 |
| 277 bool result = false; |
| 278 r->type = static_cast<NPVariant_ParamEnum>(type); |
| 279 if (r->type == NPVARIANT_PARAM_BOOL) { |
| 280 result = ReadParam(m, iter, &r->bool_value); |
| 281 } else if (r->type == NPVARIANT_PARAM_INT) { |
| 282 result = ReadParam(m, iter, &r->int_value); |
| 283 } else if (r->type == NPVARIANT_PARAM_DOUBLE) { |
| 284 result = ReadParam(m, iter, &r->double_value); |
| 285 } else if (r->type == NPVARIANT_PARAM_STRING) { |
| 286 result = ReadParam(m, iter, &r->string_value); |
| 287 } else if (r->type == NPVARIANT_PARAM_SENDER_OBJECT_ROUTING_ID || |
| 288 r->type == NPVARIANT_PARAM_RECEIVER_OBJECT_ROUTING_ID) { |
| 289 result = ReadParam(m, iter, &r->npobject_routing_id); |
| 290 } else if ((r->type == NPVARIANT_PARAM_VOID) || |
| 291 (r->type == NPVARIANT_PARAM_NULL)) { |
| 292 result = true; |
| 293 } else { |
| 294 NOTREACHED(); |
| 295 } |
| 296 |
| 297 return result; |
| 298 } |
| 299 |
| 300 void ParamTraits<NPVariant_Param>::Log(const param_type& p, std::string* l) { |
| 301 if (p.type == NPVARIANT_PARAM_BOOL) { |
| 302 LogParam(p.bool_value, l); |
| 303 } else if (p.type == NPVARIANT_PARAM_INT) { |
| 304 LogParam(p.int_value, l); |
| 305 } else if (p.type == NPVARIANT_PARAM_DOUBLE) { |
| 306 LogParam(p.double_value, l); |
| 307 } else if (p.type == NPVARIANT_PARAM_STRING) { |
| 308 LogParam(p.string_value, l); |
| 309 } else if (p.type == NPVARIANT_PARAM_SENDER_OBJECT_ROUTING_ID || |
| 310 p.type == NPVARIANT_PARAM_RECEIVER_OBJECT_ROUTING_ID) { |
| 311 LogParam(p.npobject_routing_id, l); |
| 312 } |
| 313 } |
| 314 |
| 315 void ParamTraits<NPIdentifier_Param>::Write(Message* m, const param_type& p) { |
| 316 webkit_glue::SerializeNPIdentifier(p.identifier, m); |
| 317 } |
| 318 |
| 319 bool ParamTraits<NPIdentifier_Param>::Read(const Message* m, |
| 320 void** iter, |
| 321 param_type* r) { |
| 322 return webkit_glue::DeserializeNPIdentifier(*m, iter, &r->identifier); |
| 323 } |
| 324 |
| 325 void ParamTraits<NPIdentifier_Param>::Log(const param_type& p, std::string* l) { |
| 326 if (WebKit::WebBindings::identifierIsString(p.identifier)) { |
| 327 NPUTF8* str = WebKit::WebBindings::utf8FromIdentifier(p.identifier); |
| 328 l->append(str); |
| 329 NPN_MemFree(str); |
| 330 } else { |
| 331 l->append(base::IntToString( |
| 332 WebKit::WebBindings::intFromIdentifier(p.identifier))); |
| 333 } |
| 334 } |
| 335 |
| 336 void ParamTraits<webkit_glue::PasswordForm>::Write(Message* m, |
| 337 const param_type& p) { |
| 338 WriteParam(m, p.signon_realm); |
| 339 WriteParam(m, p.origin); |
| 340 WriteParam(m, p.action); |
| 341 WriteParam(m, p.submit_element); |
| 342 WriteParam(m, p.username_element); |
| 343 WriteParam(m, p.username_value); |
| 344 WriteParam(m, p.password_element); |
| 345 WriteParam(m, p.password_value); |
| 346 WriteParam(m, p.old_password_element); |
| 347 WriteParam(m, p.old_password_value); |
| 348 WriteParam(m, p.ssl_valid); |
| 349 WriteParam(m, p.preferred); |
| 350 WriteParam(m, p.blacklisted_by_user); |
| 351 } |
| 352 |
| 353 bool ParamTraits<webkit_glue::PasswordForm>::Read(const Message* m, void** iter, |
| 354 param_type* p) { |
| 355 return |
| 356 ReadParam(m, iter, &p->signon_realm) && |
| 357 ReadParam(m, iter, &p->origin) && |
| 358 ReadParam(m, iter, &p->action) && |
| 359 ReadParam(m, iter, &p->submit_element) && |
| 360 ReadParam(m, iter, &p->username_element) && |
| 361 ReadParam(m, iter, &p->username_value) && |
| 362 ReadParam(m, iter, &p->password_element) && |
| 363 ReadParam(m, iter, &p->password_value) && |
| 364 ReadParam(m, iter, &p->old_password_element) && |
| 365 ReadParam(m, iter, &p->old_password_value) && |
| 366 ReadParam(m, iter, &p->ssl_valid) && |
| 367 ReadParam(m, iter, &p->preferred) && |
| 368 ReadParam(m, iter, &p->blacklisted_by_user); |
| 369 } |
| 370 void ParamTraits<webkit_glue::PasswordForm>::Log(const param_type& p, |
| 371 std::string* l) { |
| 372 l->append("<PasswordForm>"); |
| 373 } |
| 374 |
| 375 } // namespace IPC |
OLD | NEW |