Home | History | Annotate | Download | only in common
      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
      3 // found in the LICENSE file.
      4 
      5 #include "content/common/resource_messages.h"
      6 
      7 #include "net/base/load_timing_info.h"
      8 #include "net/http/http_response_headers.h"
      9 
     10 namespace IPC {
     11 
     12 void ParamTraits<scoped_refptr<net::HttpResponseHeaders> >::Write(
     13     Message* m, const param_type& p) {
     14   WriteParam(m, p.get() != NULL);
     15   if (p.get()) {
     16     // Do not disclose Set-Cookie headers over IPC.
     17     p->Persist(m, net::HttpResponseHeaders::PERSIST_SANS_COOKIES);
     18   }
     19 }
     20 
     21 bool ParamTraits<scoped_refptr<net::HttpResponseHeaders> >::Read(
     22     const Message* m, PickleIterator* iter, param_type* r) {
     23   bool has_object;
     24   if (!ReadParam(m, iter, &has_object))
     25     return false;
     26   if (has_object)
     27     *r = new net::HttpResponseHeaders(*m, iter);
     28   return true;
     29 }
     30 
     31 void ParamTraits<scoped_refptr<net::HttpResponseHeaders> >::Log(
     32     const param_type& p, std::string* l) {
     33   l->append("<HttpResponseHeaders>");
     34 }
     35 
     36 
     37 void ParamTraits<webkit_common::DataElement>::Write(
     38     Message* m, const param_type& p) {
     39   WriteParam(m, static_cast<int>(p.type()));
     40   switch (p.type()) {
     41     case webkit_common::DataElement::TYPE_BYTES: {
     42       m->WriteData(p.bytes(), static_cast<int>(p.length()));
     43       break;
     44     }
     45     case webkit_common::DataElement::TYPE_FILE: {
     46       WriteParam(m, p.path());
     47       WriteParam(m, p.offset());
     48       WriteParam(m, p.length());
     49       WriteParam(m, p.expected_modification_time());
     50       break;
     51     }
     52     case webkit_common::DataElement::TYPE_FILE_FILESYSTEM: {
     53       WriteParam(m, p.filesystem_url());
     54       WriteParam(m, p.offset());
     55       WriteParam(m, p.length());
     56       WriteParam(m, p.expected_modification_time());
     57       break;
     58     }
     59     default: {
     60       DCHECK(p.type() == webkit_common::DataElement::TYPE_BLOB);
     61       WriteParam(m, p.blob_uuid());
     62       WriteParam(m, p.offset());
     63       WriteParam(m, p.length());
     64       break;
     65     }
     66   }
     67 }
     68 
     69 bool ParamTraits<webkit_common::DataElement>::Read(
     70     const Message* m, PickleIterator* iter, param_type* r) {
     71   int type;
     72   if (!ReadParam(m, iter, &type))
     73     return false;
     74   switch (type) {
     75     case webkit_common::DataElement::TYPE_BYTES: {
     76       const char* data;
     77       int len;
     78       if (!m->ReadData(iter, &data, &len))
     79         return false;
     80       r->SetToBytes(data, len);
     81       break;
     82     }
     83     case webkit_common::DataElement::TYPE_FILE: {
     84       base::FilePath file_path;
     85       uint64 offset, length;
     86       base::Time expected_modification_time;
     87       if (!ReadParam(m, iter, &file_path))
     88         return false;
     89       if (!ReadParam(m, iter, &offset))
     90         return false;
     91       if (!ReadParam(m, iter, &length))
     92         return false;
     93       if (!ReadParam(m, iter, &expected_modification_time))
     94         return false;
     95       r->SetToFilePathRange(file_path, offset, length,
     96                             expected_modification_time);
     97       break;
     98     }
     99     case webkit_common::DataElement::TYPE_FILE_FILESYSTEM: {
    100       GURL file_system_url;
    101       uint64 offset, length;
    102       base::Time expected_modification_time;
    103       if (!ReadParam(m, iter, &file_system_url))
    104         return false;
    105       if (!ReadParam(m, iter, &offset))
    106         return false;
    107       if (!ReadParam(m, iter, &length))
    108         return false;
    109       if (!ReadParam(m, iter, &expected_modification_time))
    110         return false;
    111       r->SetToFileSystemUrlRange(file_system_url, offset, length,
    112                                  expected_modification_time);
    113       break;
    114     }
    115     default: {
    116       DCHECK(type == webkit_common::DataElement::TYPE_BLOB);
    117       std::string blob_uuid;
    118       uint64 offset, length;
    119       if (!ReadParam(m, iter, &blob_uuid))
    120         return false;
    121       if (!ReadParam(m, iter, &offset))
    122         return false;
    123       if (!ReadParam(m, iter, &length))
    124         return false;
    125       r->SetToBlobRange(blob_uuid, offset, length);
    126       break;
    127     }
    128   }
    129   return true;
    130 }
    131 
    132 void ParamTraits<webkit_common::DataElement>::Log(
    133     const param_type& p, std::string* l) {
    134   l->append("<webkit_common::DataElement>");
    135 }
    136 
    137 void ParamTraits<scoped_refptr<webkit_glue::ResourceDevToolsInfo> >::Write(
    138     Message* m, const param_type& p) {
    139   WriteParam(m, p.get() != NULL);
    140   if (p.get()) {
    141     WriteParam(m, p->http_status_code);
    142     WriteParam(m, p->http_status_text);
    143     WriteParam(m, p->request_headers);
    144     WriteParam(m, p->response_headers);
    145     WriteParam(m, p->request_headers_text);
    146     WriteParam(m, p->response_headers_text);
    147   }
    148 }
    149 
    150 bool ParamTraits<scoped_refptr<webkit_glue::ResourceDevToolsInfo> >::Read(
    151     const Message* m, PickleIterator* iter, param_type* r) {
    152   bool has_object;
    153   if (!ReadParam(m, iter, &has_object))
    154     return false;
    155   if (!has_object)
    156     return true;
    157   *r = new webkit_glue::ResourceDevToolsInfo();
    158   return
    159       ReadParam(m, iter, &(*r)->http_status_code) &&
    160       ReadParam(m, iter, &(*r)->http_status_text) &&
    161       ReadParam(m, iter, &(*r)->request_headers) &&
    162       ReadParam(m, iter, &(*r)->response_headers) &&
    163       ReadParam(m, iter, &(*r)->request_headers_text) &&
    164       ReadParam(m, iter, &(*r)->response_headers_text);
    165 }
    166 
    167 void ParamTraits<scoped_refptr<webkit_glue::ResourceDevToolsInfo> >::Log(
    168     const param_type& p, std::string* l) {
    169   l->append("(");
    170   if (p.get()) {
    171     LogParam(p->request_headers, l);
    172     l->append(", ");
    173     LogParam(p->response_headers, l);
    174   }
    175   l->append(")");
    176 }
    177 
    178 void ParamTraits<net::LoadTimingInfo>::Write(
    179     Message* m, const param_type& p) {
    180   WriteParam(m, p.socket_log_id);
    181   WriteParam(m, p.socket_reused);
    182   WriteParam(m, p.request_start_time.is_null());
    183   if (p.request_start_time.is_null())
    184     return;
    185   WriteParam(m, p.request_start_time);
    186   WriteParam(m, p.request_start);
    187   WriteParam(m, p.proxy_resolve_start);
    188   WriteParam(m, p.proxy_resolve_end);
    189   WriteParam(m, p.connect_timing.dns_start);
    190   WriteParam(m, p.connect_timing.dns_end);
    191   WriteParam(m, p.connect_timing.connect_start);
    192   WriteParam(m, p.connect_timing.connect_end);
    193   WriteParam(m, p.connect_timing.ssl_start);
    194   WriteParam(m, p.connect_timing.ssl_end);
    195   WriteParam(m, p.send_start);
    196   WriteParam(m, p.send_end);
    197   WriteParam(m, p.receive_headers_end);
    198 }
    199 
    200 bool ParamTraits<net::LoadTimingInfo>::Read(
    201     const Message* m, PickleIterator* iter, param_type* r) {
    202   bool has_no_times;
    203   if (!ReadParam(m, iter, &r->socket_log_id) ||
    204       !ReadParam(m, iter, &r->socket_reused) ||
    205       !ReadParam(m, iter, &has_no_times)) {
    206     return false;
    207   }
    208   if (has_no_times)
    209     return true;
    210 
    211   return
    212       ReadParam(m, iter, &r->request_start_time) &&
    213       ReadParam(m, iter, &r->request_start) &&
    214       ReadParam(m, iter, &r->proxy_resolve_start) &&
    215       ReadParam(m, iter, &r->proxy_resolve_end) &&
    216       ReadParam(m, iter, &r->connect_timing.dns_start) &&
    217       ReadParam(m, iter, &r->connect_timing.dns_end) &&
    218       ReadParam(m, iter, &r->connect_timing.connect_start) &&
    219       ReadParam(m, iter, &r->connect_timing.connect_end) &&
    220       ReadParam(m, iter, &r->connect_timing.ssl_start) &&
    221       ReadParam(m, iter, &r->connect_timing.ssl_end) &&
    222       ReadParam(m, iter, &r->send_start) &&
    223       ReadParam(m, iter, &r->send_end) &&
    224       ReadParam(m, iter, &r->receive_headers_end);
    225 }
    226 
    227 void ParamTraits<net::LoadTimingInfo>::Log(const param_type& p,
    228                                            std::string* l) {
    229   l->append("(");
    230   LogParam(p.socket_log_id, l);
    231   l->append(",");
    232   LogParam(p.socket_reused, l);
    233   l->append(",");
    234   LogParam(p.request_start_time, l);
    235   l->append(", ");
    236   LogParam(p.request_start, l);
    237   l->append(", ");
    238   LogParam(p.proxy_resolve_start, l);
    239   l->append(", ");
    240   LogParam(p.proxy_resolve_end, l);
    241   l->append(", ");
    242   LogParam(p.connect_timing.dns_start, l);
    243   l->append(", ");
    244   LogParam(p.connect_timing.dns_end, l);
    245   l->append(", ");
    246   LogParam(p.connect_timing.connect_start, l);
    247   l->append(", ");
    248   LogParam(p.connect_timing.connect_end, l);
    249   l->append(", ");
    250   LogParam(p.connect_timing.ssl_start, l);
    251   l->append(", ");
    252   LogParam(p.connect_timing.ssl_end, l);
    253   l->append(", ");
    254   LogParam(p.send_start, l);
    255   l->append(", ");
    256   LogParam(p.send_end, l);
    257   l->append(", ");
    258   LogParam(p.receive_headers_end, l);
    259   l->append(")");
    260 }
    261 
    262 void ParamTraits<scoped_refptr<webkit_glue::ResourceRequestBody> >::Write(
    263     Message* m,
    264     const param_type& p) {
    265   WriteParam(m, p.get() != NULL);
    266   if (p.get()) {
    267     WriteParam(m, *p->elements());
    268     WriteParam(m, p->identifier());
    269   }
    270 }
    271 
    272 bool ParamTraits<scoped_refptr<webkit_glue::ResourceRequestBody> >::Read(
    273     const Message* m,
    274     PickleIterator* iter,
    275     param_type* r) {
    276   bool has_object;
    277   if (!ReadParam(m, iter, &has_object))
    278     return false;
    279   if (!has_object)
    280     return true;
    281   std::vector<webkit_common::DataElement> elements;
    282   if (!ReadParam(m, iter, &elements))
    283     return false;
    284   int64 identifier;
    285   if (!ReadParam(m, iter, &identifier))
    286     return false;
    287   *r = new webkit_glue::ResourceRequestBody;
    288   (*r)->swap_elements(&elements);
    289   (*r)->set_identifier(identifier);
    290   return true;
    291 }
    292 
    293 void ParamTraits<scoped_refptr<webkit_glue::ResourceRequestBody> >::Log(
    294     const param_type& p, std::string* l) {
    295   l->append("<webkit_glue::ResourceRequestBody>");
    296 }
    297 
    298 }  // namespace IPC
    299