1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
|
// 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 "content/public/common/common_param_traits.h"
#include <string>
#include "content/public/common/content_constants.h"
#include "content/public/common/page_state.h"
#include "content/public/common/referrer.h"
#include "content/public/common/url_utils.h"
#include "net/base/host_port_pair.h"
#include "net/base/ip_endpoint.h"
namespace IPC {
void ParamTraits<GURL>::Write(Message* m, const GURL& p) {
if (p.possibly_invalid_spec().length() > content::GetMaxURLChars()) {
m->WriteString(std::string());
return;
}
// Beware of print-parse inconsistency which would change an invalid
// URL into a valid one. Ideally, the message would contain this flag
// so that the read side could make the check, but performing it here
// avoids changing the on-the-wire representation of such a fundamental
// type as GURL. See https://crbug.com/166486 for additional work in
// this area.
if (!p.is_valid()) {
m->WriteString(std::string());
return;
}
m->WriteString(p.possibly_invalid_spec());
// TODO(brettw) bug 684583: Add encoding for query params.
}
bool ParamTraits<GURL>::Read(const Message* m,
base::PickleIterator* iter,
GURL* p) {
std::string s;
if (!iter->ReadString(&s) || s.length() > content::GetMaxURLChars()) {
*p = GURL();
return false;
}
*p = GURL(s);
if (!s.empty() && !p->is_valid()) {
*p = GURL();
return false;
}
return true;
}
void ParamTraits<GURL>::Log(const GURL& p, std::string* l) {
l->append(p.spec());
}
void ParamTraits<url::Origin>::Write(Message* m,
const url::Origin& p) {
m->WriteString(p.string());
}
bool ParamTraits<url::Origin>::Read(const Message* m,
base::PickleIterator* iter,
url::Origin* p) {
std::string s;
if (!iter->ReadString(&s)) {
*p = url::Origin();
return false;
}
*p = url::Origin(s);
return true;
}
void ParamTraits<url::Origin>::Log(const url::Origin& p, std::string* l) {
l->append(p.string());
}
void ParamTraits<net::HostPortPair>::Write(Message* m, const param_type& p) {
WriteParam(m, p.host());
WriteParam(m, p.port());
}
bool ParamTraits<net::HostPortPair>::Read(const Message* m,
base::PickleIterator* iter,
param_type* r) {
std::string host;
uint16 port;
if (!ReadParam(m, iter, &host) || !ReadParam(m, iter, &port))
return false;
r->set_host(host);
r->set_port(port);
return true;
}
void ParamTraits<net::HostPortPair>::Log(const param_type& p, std::string* l) {
l->append(p.ToString());
}
void ParamTraits<net::IPEndPoint>::Write(Message* m, const param_type& p) {
WriteParam(m, p.address());
WriteParam(m, p.port());
}
bool ParamTraits<net::IPEndPoint>::Read(const Message* m,
base::PickleIterator* iter,
param_type* p) {
net::IPAddressNumber address;
uint16 port;
if (!ReadParam(m, iter, &address) || !ReadParam(m, iter, &port))
return false;
if (address.size() &&
address.size() != net::kIPv4AddressSize &&
address.size() != net::kIPv6AddressSize) {
return false;
}
*p = net::IPEndPoint(address, port);
return true;
}
void ParamTraits<net::IPEndPoint>::Log(const param_type& p, std::string* l) {
LogParam("IPEndPoint:" + p.ToString(), l);
}
void ParamTraits<content::PageState>::Write(
Message* m, const param_type& p) {
WriteParam(m, p.ToEncodedData());
}
bool ParamTraits<content::PageState>::Read(const Message* m,
base::PickleIterator* iter,
param_type* r) {
std::string data;
if (!ReadParam(m, iter, &data))
return false;
*r = content::PageState::CreateFromEncodedData(data);
return true;
}
void ParamTraits<content::PageState>::Log(
const param_type& p, std::string* l) {
l->append("(");
LogParam(p.ToEncodedData(), l);
l->append(")");
}
} // namespace IPC
// Generate param traits write methods.
#include "ipc/param_traits_write_macros.h"
namespace IPC {
#undef CONTENT_PUBLIC_COMMON_COMMON_PARAM_TRAITS_MACROS_H_
#include "content/public/common/common_param_traits_macros.h"
} // namespace IPC
// Generate param traits read methods.
#include "ipc/param_traits_read_macros.h"
namespace IPC {
#undef CONTENT_PUBLIC_COMMON_COMMON_PARAM_TRAITS_MACROS_H_
#include "content/public/common/common_param_traits_macros.h"
} // namespace IPC
// Generate param traits log methods.
#include "ipc/param_traits_log_macros.h"
namespace IPC {
#undef CONTENT_PUBLIC_COMMON_COMMON_PARAM_TRAITS_MACROS_H_
#include "content/public/common/common_param_traits_macros.h"
} // namespace IPC
|