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.
5 #include "content/public/common/common_param_traits.h"
9 #include "content/public/common/content_constants.h"
10 #include "content/public/common/page_state.h"
11 #include "content/public/common/referrer.h"
12 #include "content/public/common/url_utils.h"
13 #include "net/base/host_port_pair.h"
14 #include "net/base/ip_endpoint.h"
18 void ParamTraits
<GURL
>::Write(Message
* m
, const GURL
& p
) {
19 DCHECK(p
.possibly_invalid_spec().length() <= content::GetMaxURLChars());
21 // Beware of print-parse inconsistency which would change an invalid
22 // URL into a valid one. Ideally, the message would contain this flag
23 // so that the read side could make the check, but performing it here
24 // avoids changing the on-the-wire representation of such a fundamental
25 // type as GURL. See https://crbug.com/166486 for additional work in
28 m
->WriteString(std::string());
32 m
->WriteString(p
.possibly_invalid_spec());
33 // TODO(brettw) bug 684583: Add encoding for query params.
36 bool ParamTraits
<GURL
>::Read(const Message
* m
, PickleIterator
* iter
, GURL
* p
) {
38 if (!m
->ReadString(iter
, &s
) || s
.length() > content::GetMaxURLChars()) {
43 if (!s
.empty() && !p
->is_valid()) {
50 void ParamTraits
<GURL
>::Log(const GURL
& p
, std::string
* l
) {
54 void ParamTraits
<url::Origin
>::Write(Message
* m
,
55 const url::Origin
& p
) {
56 m
->WriteString(p
.string());
59 bool ParamTraits
<url::Origin
>::Read(const Message
* m
,
63 if (!m
->ReadString(iter
, &s
)) {
71 void ParamTraits
<url::Origin
>::Log(const url::Origin
& p
, std::string
* l
) {
72 l
->append(p
.string());
75 void ParamTraits
<net::HostPortPair
>::Write(Message
* m
, const param_type
& p
) {
76 WriteParam(m
, p
.host());
77 WriteParam(m
, p
.port());
80 bool ParamTraits
<net::HostPortPair
>::Read(const Message
* m
,
85 if (!ReadParam(m
, iter
, &host
) || !ReadParam(m
, iter
, &port
))
93 void ParamTraits
<net::HostPortPair
>::Log(const param_type
& p
, std::string
* l
) {
94 l
->append(p
.ToString());
97 void ParamTraits
<net::IPEndPoint
>::Write(Message
* m
, const param_type
& p
) {
98 WriteParam(m
, p
.address());
99 WriteParam(m
, p
.port());
102 bool ParamTraits
<net::IPEndPoint
>::Read(const Message
* m
, PickleIterator
* iter
,
104 net::IPAddressNumber address
;
106 if (!ReadParam(m
, iter
, &address
) || !ReadParam(m
, iter
, &port
))
108 if (address
.size() &&
109 address
.size() != net::kIPv4AddressSize
&&
110 address
.size() != net::kIPv6AddressSize
) {
113 *p
= net::IPEndPoint(address
, port
);
117 void ParamTraits
<net::IPEndPoint
>::Log(const param_type
& p
, std::string
* l
) {
118 LogParam("IPEndPoint:" + p
.ToString(), l
);
121 void ParamTraits
<content::PageState
>::Write(
122 Message
* m
, const param_type
& p
) {
123 WriteParam(m
, p
.ToEncodedData());
126 bool ParamTraits
<content::PageState
>::Read(
127 const Message
* m
, PickleIterator
* iter
, param_type
* r
) {
129 if (!ReadParam(m
, iter
, &data
))
131 *r
= content::PageState::CreateFromEncodedData(data
);
135 void ParamTraits
<content::PageState
>::Log(
136 const param_type
& p
, std::string
* l
) {
138 LogParam(p
.ToEncodedData(), l
);
144 // Generate param traits write methods.
145 #include "ipc/param_traits_write_macros.h"
147 #undef CONTENT_PUBLIC_COMMON_COMMON_PARAM_TRAITS_MACROS_H_
148 #include "content/public/common/common_param_traits_macros.h"
151 // Generate param traits read methods.
152 #include "ipc/param_traits_read_macros.h"
154 #undef CONTENT_PUBLIC_COMMON_COMMON_PARAM_TRAITS_MACROS_H_
155 #include "content/public/common/common_param_traits_macros.h"
158 // Generate param traits log methods.
159 #include "ipc/param_traits_log_macros.h"
161 #undef CONTENT_PUBLIC_COMMON_COMMON_PARAM_TRAITS_MACROS_H_
162 #include "content/public/common/common_param_traits_macros.h"