2012-10-04 21:17:13 +02:00
|
|
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#include "libcef/common/cef_messages.h"
|
|
|
|
|
|
|
|
namespace IPC {
|
|
|
|
|
|
|
|
// Extracted from chrome/common/automation_messages.cc.
|
|
|
|
|
|
|
|
// Only the net::UploadData ParamTraits<> definition needs this definition, so
|
|
|
|
// keep this in the implementation file so we can forward declare UploadData in
|
|
|
|
// the header.
|
|
|
|
template <>
|
|
|
|
struct ParamTraits<net::UploadElement> {
|
|
|
|
typedef net::UploadElement param_type;
|
|
|
|
static void Write(Message* m, const param_type& p) {
|
|
|
|
WriteParam(m, static_cast<int>(p.type()));
|
|
|
|
switch (p.type()) {
|
|
|
|
case net::UploadElement::TYPE_BYTES: {
|
|
|
|
m->WriteData(p.bytes(), static_cast<int>(p.bytes_length()));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
DCHECK(p.type() == net::UploadElement::TYPE_FILE);
|
|
|
|
WriteParam(m, p.file_path());
|
|
|
|
WriteParam(m, p.file_range_offset());
|
|
|
|
WriteParam(m, p.file_range_length());
|
|
|
|
WriteParam(m, p.expected_file_modification_time());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-06-06 00:06:48 +02:00
|
|
|
static bool Read(const Message* m,
|
|
|
|
base::PickleIterator* iter,
|
|
|
|
param_type* r) {
|
2012-10-04 21:17:13 +02:00
|
|
|
int type;
|
|
|
|
if (!ReadParam(m, iter, &type))
|
|
|
|
return false;
|
|
|
|
switch (type) {
|
|
|
|
case net::UploadElement::TYPE_BYTES: {
|
|
|
|
const char* data;
|
|
|
|
int len;
|
2015-01-09 18:22:10 +01:00
|
|
|
if (!iter->ReadData(&data, &len))
|
2012-10-04 21:17:13 +02:00
|
|
|
return false;
|
|
|
|
r->SetToBytes(data, len);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
DCHECK(type == net::UploadElement::TYPE_FILE);
|
2013-02-23 01:43:28 +01:00
|
|
|
base::FilePath file_path;
|
2012-10-04 21:17:13 +02:00
|
|
|
uint64 offset, length;
|
|
|
|
base::Time expected_modification_time;
|
|
|
|
if (!ReadParam(m, iter, &file_path))
|
|
|
|
return false;
|
|
|
|
if (!ReadParam(m, iter, &offset))
|
|
|
|
return false;
|
|
|
|
if (!ReadParam(m, iter, &length))
|
|
|
|
return false;
|
|
|
|
if (!ReadParam(m, iter, &expected_modification_time))
|
|
|
|
return false;
|
|
|
|
r->SetToFilePathRange(file_path, offset, length,
|
|
|
|
expected_modification_time);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
static void Log(const param_type& p, std::string* l) {
|
|
|
|
l->append("<net::UploadElement>");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
void ParamTraits<scoped_refptr<net::UploadData> >::Write(Message* m,
|
|
|
|
const param_type& p) {
|
|
|
|
WriteParam(m, p.get() != NULL);
|
2014-09-27 01:48:19 +02:00
|
|
|
if (p.get()) {
|
2012-11-16 03:58:25 +01:00
|
|
|
WriteParam(m, p->elements());
|
2012-10-04 21:17:13 +02:00
|
|
|
WriteParam(m, p->identifier());
|
|
|
|
WriteParam(m, p->is_chunked());
|
|
|
|
WriteParam(m, p->last_chunk_appended());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-06 00:06:48 +02:00
|
|
|
bool ParamTraits<scoped_refptr<net::UploadData> >::Read(
|
|
|
|
const Message* m,
|
|
|
|
base::PickleIterator* iter,
|
|
|
|
param_type* r) {
|
2012-10-04 21:17:13 +02:00
|
|
|
bool has_object;
|
|
|
|
if (!ReadParam(m, iter, &has_object))
|
|
|
|
return false;
|
|
|
|
if (!has_object)
|
|
|
|
return true;
|
2012-11-16 03:58:25 +01:00
|
|
|
ScopedVector<net::UploadElement> elements;
|
2012-10-04 21:17:13 +02:00
|
|
|
if (!ReadParam(m, iter, &elements))
|
|
|
|
return false;
|
|
|
|
int64 identifier;
|
|
|
|
if (!ReadParam(m, iter, &identifier))
|
|
|
|
return false;
|
|
|
|
bool is_chunked = false;
|
|
|
|
if (!ReadParam(m, iter, &is_chunked))
|
|
|
|
return false;
|
|
|
|
bool last_chunk_appended = false;
|
|
|
|
if (!ReadParam(m, iter, &last_chunk_appended))
|
|
|
|
return false;
|
|
|
|
*r = new net::UploadData;
|
|
|
|
(*r)->swap_elements(&elements);
|
|
|
|
(*r)->set_identifier(identifier);
|
|
|
|
(*r)->set_is_chunked(is_chunked);
|
|
|
|
(*r)->set_last_chunk_appended(last_chunk_appended);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ParamTraits<scoped_refptr<net::UploadData> >::Log(const param_type& p,
|
|
|
|
std::string* l) {
|
|
|
|
l->append("<net::UploadData>");
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace IPC
|