• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "libcef/common/cef_messages.h"
6 
7 namespace IPC {
8 
9 // Extracted from chrome/common/automation_messages.cc.
10 
11 // Only the net::UploadData ParamTraits<> definition needs this definition, so
12 // keep this in the implementation file so we can forward declare UploadData in
13 // the header.
14 template <>
15 struct ParamTraits<net::UploadElement> {
16   typedef net::UploadElement param_type;
WriteIPC::ParamTraits17   static void Write(base::Pickle* m, const param_type& p) {
18     WriteParam(m, static_cast<int>(p.type()));
19     switch (p.type()) {
20       case net::UploadElement::TYPE_BYTES: {
21         m->WriteData(p.bytes(), static_cast<int>(p.bytes_length()));
22         break;
23       }
24       default: {
25         DCHECK(p.type() == net::UploadElement::TYPE_FILE);
26         WriteParam(m, p.file_path());
27         WriteParam(m, p.file_range_offset());
28         WriteParam(m, p.file_range_length());
29         WriteParam(m, p.expected_file_modification_time());
30         break;
31       }
32     }
33   }
ReadIPC::ParamTraits34   static bool Read(const base::Pickle* m,
35                    base::PickleIterator* iter,
36                    param_type* r) {
37     int type;
38     if (!ReadParam(m, iter, &type))
39       return false;
40     switch (type) {
41       case net::UploadElement::TYPE_BYTES: {
42         const char* data;
43         int len;
44         if (!iter->ReadData(&data, &len))
45           return false;
46         r->SetToBytes(data, len);
47         break;
48       }
49       default: {
50         DCHECK(type == net::UploadElement::TYPE_FILE);
51         base::FilePath file_path;
52         uint64_t offset, length;
53         base::Time expected_modification_time;
54         if (!ReadParam(m, iter, &file_path))
55           return false;
56         if (!ReadParam(m, iter, &offset))
57           return false;
58         if (!ReadParam(m, iter, &length))
59           return false;
60         if (!ReadParam(m, iter, &expected_modification_time))
61           return false;
62         r->SetToFilePathRange(file_path, offset, length,
63                               expected_modification_time);
64         break;
65       }
66     }
67     return true;
68   }
LogIPC::ParamTraits69   static void Log(const param_type& p, std::string* l) {
70     l->append("<net::UploadElement>");
71   }
72 };
73 
Write(base::Pickle * m,const param_type & p)74 void ParamTraits<scoped_refptr<net::UploadData>>::Write(base::Pickle* m,
75                                                         const param_type& p) {
76   WriteParam(m, p.get() != nullptr);
77   if (p.get()) {
78     WriteParam(m, p->elements());
79     WriteParam(m, p->identifier());
80     WriteParam(m, p->is_chunked());
81     WriteParam(m, p->last_chunk_appended());
82   }
83 }
84 
Read(const base::Pickle * m,base::PickleIterator * iter,param_type * r)85 bool ParamTraits<scoped_refptr<net::UploadData>>::Read(
86     const base::Pickle* m,
87     base::PickleIterator* iter,
88     param_type* r) {
89   bool has_object;
90   if (!ReadParam(m, iter, &has_object))
91     return false;
92   if (!has_object)
93     return true;
94   net::UploadData::ElementsVector elements;
95   if (!ReadParam(m, iter, &elements))
96     return false;
97   int64_t identifier;
98   if (!ReadParam(m, iter, &identifier))
99     return false;
100   bool is_chunked = false;
101   if (!ReadParam(m, iter, &is_chunked))
102     return false;
103   bool last_chunk_appended = false;
104   if (!ReadParam(m, iter, &last_chunk_appended))
105     return false;
106   *r = new net::UploadData;
107   (*r)->swap_elements(&elements);
108   (*r)->set_identifier(identifier);
109   (*r)->set_is_chunked(is_chunked);
110   (*r)->set_last_chunk_appended(last_chunk_appended);
111   return true;
112 }
113 
Log(const param_type & p,std::string * l)114 void ParamTraits<scoped_refptr<net::UploadData>>::Log(const param_type& p,
115                                                       std::string* l) {
116   l->append("<net::UploadData>");
117 }
118 
119 }  // namespace IPC
120