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/common/content_param_traits.h"
7 #include "base/strings/string_number_conversions.h"
8 #include "net/base/ip_endpoint.h"
9 #include "ui/gfx/range/range.h"
13 int WebInputEventSizeForType(WebKit::WebInputEvent::Type type
) {
14 if (WebKit::WebInputEvent::isMouseEventType(type
))
15 return sizeof(WebKit::WebMouseEvent
);
16 if (type
== WebKit::WebInputEvent::MouseWheel
)
17 return sizeof(WebKit::WebMouseWheelEvent
);
18 if (WebKit::WebInputEvent::isKeyboardEventType(type
))
19 return sizeof(WebKit::WebKeyboardEvent
);
20 if (WebKit::WebInputEvent::isTouchEventType(type
))
21 return sizeof(WebKit::WebTouchEvent
);
22 if (WebKit::WebInputEvent::isGestureEventType(type
))
23 return sizeof(WebKit::WebGestureEvent
);
24 NOTREACHED() << "Unknown webkit event type " << type
;
32 void ParamTraits
<net::IPEndPoint
>::Write(Message
* m
, const param_type
& p
) {
33 WriteParam(m
, p
.address());
34 WriteParam(m
, p
.port());
37 bool ParamTraits
<net::IPEndPoint
>::Read(const Message
* m
, PickleIterator
* iter
,
39 net::IPAddressNumber address
;
41 if (!ReadParam(m
, iter
, &address
) || !ReadParam(m
, iter
, &port
))
43 *p
= net::IPEndPoint(address
, port
);
47 void ParamTraits
<net::IPEndPoint
>::Log(const param_type
& p
, std::string
* l
) {
48 LogParam("IPEndPoint:" + p
.ToString(), l
);
51 void ParamTraits
<gfx::Range
>::Write(Message
* m
, const gfx::Range
& r
) {
52 m
->WriteUInt64(r
.start());
53 m
->WriteUInt64(r
.end());
56 bool ParamTraits
<gfx::Range
>::Read(const Message
* m
,
60 if (!m
->ReadUInt64(iter
, &start
) || !m
->ReadUInt64(iter
, &end
))
67 void ParamTraits
<gfx::Range
>::Log(const gfx::Range
& r
, std::string
* l
) {
68 l
->append(base::StringPrintf("(%" PRIuS
", %" PRIuS
")", r
.start(), r
.end()));
71 void ParamTraits
<WebInputEventPointer
>::Write(Message
* m
, const param_type
& p
) {
72 m
->WriteData(reinterpret_cast<const char*>(p
), p
->size
);
75 bool ParamTraits
<WebInputEventPointer
>::Read(const Message
* m
,
80 if (!m
->ReadData(iter
, &data
, &data_length
)) {
84 if (data_length
< static_cast<int>(sizeof(WebKit::WebInputEvent
))) {
88 param_type event
= reinterpret_cast<param_type
>(data
);
89 // Check that the data size matches that of the event.
90 if (data_length
!= static_cast<int>(event
->size
)) {
94 if (data_length
!= WebInputEventSizeForType(event
->type
)) {
102 void ParamTraits
<WebInputEventPointer
>::Log(const param_type
& p
,
105 LogParam(p
->size
, l
);
107 LogParam(p
->type
, l
);
109 LogParam(p
->timeStampSeconds
, l
);
115 // Generate param traits write methods.
116 #include "ipc/param_traits_write_macros.h"
118 #undef CONTENT_COMMON_CONTENT_PARAM_TRAITS_MACROS_H_
119 #include "content/common/content_param_traits_macros.h"
122 // Generate param traits read methods.
123 #include "ipc/param_traits_read_macros.h"
125 #undef CONTENT_COMMON_CONTENT_PARAM_TRAITS_MACROS_H_
126 #include "content/common/content_param_traits_macros.h"
129 // Generate param traits log methods.
130 #include "ipc/param_traits_log_macros.h"
132 #undef CONTENT_COMMON_CONTENT_PARAM_TRAITS_MACROS_H_
133 #include "content/common/content_param_traits_macros.h"