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 "ui/base/models/menu_model.h"
7 // Get basic type definitions.
8 #define IPC_MESSAGE_IMPL
9 #include "chrome/common/automation_messages.h"
11 // Generate constructors.
12 #include "ipc/struct_constructor_macros.h"
13 #include "chrome/common/automation_messages.h"
15 // Generate destructors.
16 #include "ipc/struct_destructor_macros.h"
17 #include "chrome/common/automation_messages.h"
19 // Generate param traits write methods.
20 #include "ipc/param_traits_write_macros.h"
22 #include "chrome/common/automation_messages.h"
25 // Generate param traits read methods.
26 #include "ipc/param_traits_read_macros.h"
28 #include "chrome/common/automation_messages.h"
31 // Generate param traits log methods.
32 #include "ipc/param_traits_log_macros.h"
34 #include "chrome/common/automation_messages.h"
37 ContextMenuModel::ContextMenuModel() {
40 ContextMenuModel::~ContextMenuModel() {
41 for (size_t i
= 0; i
< items
.size(); ++i
)
42 delete items
[i
].submenu
;
45 ContextMenuModel::Item::Item()
46 : type(static_cast<int>(ui::MenuModel::TYPE_COMMAND
)),
55 void ParamTraits
<AutomationMouseEvent
>::Write(Message
* m
,
56 const param_type
& p
) {
57 WriteParam(m
, std::string(reinterpret_cast<const char*>(&p
.mouse_event
),
58 sizeof(p
.mouse_event
)));
59 WriteParam(m
, p
.location_script_chain
);
62 bool ParamTraits
<AutomationMouseEvent
>::Read(const Message
* m
,
65 std::string mouse_event
;
66 if (!ReadParam(m
, iter
, &mouse_event
))
68 memcpy(&p
->mouse_event
, mouse_event
.c_str(), mouse_event
.length());
69 if (!ReadParam(m
, iter
, &p
->location_script_chain
))
74 void ParamTraits
<AutomationMouseEvent
>::Log(const param_type
& p
,
77 LogParam(std::string(reinterpret_cast<const char*>(&p
.mouse_event
),
78 sizeof(p
.mouse_event
)),
81 LogParam(p
.location_script_chain
, l
);
85 void ParamTraits
<ContextMenuModel
>::Write(Message
* m
,
86 const param_type
& p
) {
87 WriteParam(m
, p
.items
.size());
88 for (size_t i
= 0; i
< p
.items
.size(); ++i
) {
89 WriteParam(m
, static_cast<int>(p
.items
[i
].type
));
90 WriteParam(m
, p
.items
[i
].item_id
);
91 WriteParam(m
, p
.items
[i
].label
);
92 WriteParam(m
, p
.items
[i
].checked
);
93 WriteParam(m
, p
.items
[i
].enabled
);
95 if (p
.items
[i
].type
== static_cast<int>(ui::MenuModel::TYPE_SUBMENU
)) {
96 Write(m
, *p
.items
[i
].submenu
);
101 bool ParamTraits
<ContextMenuModel
>::Read(const Message
* m
,
102 PickleIterator
* iter
,
104 size_t item_count
= 0;
105 if (!ReadParam(m
, iter
, &item_count
))
108 p
->items
.reserve(item_count
);
109 for (size_t i
= 0; i
< item_count
; ++i
) {
110 ContextMenuModel::Item item
;
111 if (!ReadParam(m
, iter
, &item
.type
))
113 if (!ReadParam(m
, iter
, &item
.item_id
))
115 if (!ReadParam(m
, iter
, &item
.label
))
117 if (!ReadParam(m
, iter
, &item
.checked
))
119 if (!ReadParam(m
, iter
, &item
.enabled
))
122 if (item
.type
== static_cast<int>(ui::MenuModel::TYPE_SUBMENU
)) {
123 item
.submenu
= new ContextMenuModel
;
124 if (!Read(m
, iter
, item
.submenu
)) {
131 p
->items
.push_back(item
);
137 void ParamTraits
<ContextMenuModel
>::Log(const param_type
& p
,
140 for (size_t i
= 0; i
< p
.items
.size(); ++i
) {
141 const ContextMenuModel::Item
& item
= p
.items
[i
];
145 LogParam(item
.type
, l
);
147 LogParam(item
.item_id
, l
);
149 LogParam(item
.label
, l
);
151 LogParam(item
.checked
, l
);
153 LogParam(item
.enabled
, l
);
154 if (item
.type
== ui::MenuModel::TYPE_SUBMENU
) {
156 Log(*item
.submenu
, l
);
163 // Only the net::UploadData ParamTraits<> definition needs this definition, so
164 // keep this in the implementation file so we can forward declare UploadData in
167 struct ParamTraits
<net::UploadElement
> {
168 typedef net::UploadElement param_type
;
169 static void Write(Message
* m
, const param_type
& p
) {
170 WriteParam(m
, static_cast<int>(p
.type()));
172 case net::UploadElement::TYPE_BYTES
: {
173 m
->WriteData(p
.bytes(), static_cast<int>(p
.bytes_length()));
177 DCHECK(p
.type() == net::UploadElement::TYPE_FILE
);
178 WriteParam(m
, p
.file_path());
179 WriteParam(m
, p
.file_range_offset());
180 WriteParam(m
, p
.file_range_length());
181 WriteParam(m
, p
.expected_file_modification_time());
186 static bool Read(const Message
* m
, PickleIterator
* iter
, param_type
* r
) {
188 if (!ReadParam(m
, iter
, &type
))
191 case net::UploadElement::TYPE_BYTES
: {
194 if (!m
->ReadData(iter
, &data
, &len
))
196 r
->SetToBytes(data
, len
);
200 DCHECK(type
== net::UploadElement::TYPE_FILE
);
202 uint64 offset
, length
;
203 base::Time expected_modification_time
;
204 if (!ReadParam(m
, iter
, &file_path
))
206 if (!ReadParam(m
, iter
, &offset
))
208 if (!ReadParam(m
, iter
, &length
))
210 if (!ReadParam(m
, iter
, &expected_modification_time
))
212 r
->SetToFilePathRange(file_path
, offset
, length
,
213 expected_modification_time
);
219 static void Log(const param_type
& p
, std::string
* l
) {
220 l
->append("<net::UploadElement>");
224 void ParamTraits
<scoped_refptr
<net::UploadData
> >::Write(Message
* m
,
225 const param_type
& p
) {
226 WriteParam(m
, p
.get() != NULL
);
228 WriteParam(m
, p
->elements());
229 WriteParam(m
, p
->identifier());
230 WriteParam(m
, p
->is_chunked());
231 WriteParam(m
, p
->last_chunk_appended());
235 bool ParamTraits
<scoped_refptr
<net::UploadData
> >::Read(const Message
* m
,
236 PickleIterator
* iter
,
239 if (!ReadParam(m
, iter
, &has_object
))
243 ScopedVector
<net::UploadElement
> elements
;
244 if (!ReadParam(m
, iter
, &elements
))
247 if (!ReadParam(m
, iter
, &identifier
))
249 bool is_chunked
= false;
250 if (!ReadParam(m
, iter
, &is_chunked
))
252 bool last_chunk_appended
= false;
253 if (!ReadParam(m
, iter
, &last_chunk_appended
))
255 *r
= new net::UploadData
;
256 (*r
)->swap_elements(&elements
);
257 (*r
)->set_identifier(identifier
);
258 (*r
)->set_is_chunked(is_chunked
);
259 (*r
)->set_last_chunk_appended(last_chunk_appended
);
263 void ParamTraits
<scoped_refptr
<net::UploadData
> >::Log(const param_type
& p
,
265 l
->append("<net::UploadData>");
268 void ParamTraits
<net::URLRequestStatus
>::Write(Message
* m
,
269 const param_type
& p
) {
270 WriteParam(m
, static_cast<int>(p
.status()));
271 WriteParam(m
, p
.error());
274 bool ParamTraits
<net::URLRequestStatus
>::Read(const Message
* m
,
275 PickleIterator
* iter
,
278 if (!ReadParam(m
, iter
, &status
) || !ReadParam(m
, iter
, &error
))
280 r
->set_status(static_cast<net::URLRequestStatus::Status
>(status
));
285 void ParamTraits
<net::URLRequestStatus
>::Log(const param_type
& p
,
288 switch (p
.status()) {
289 case net::URLRequestStatus::SUCCESS
:
292 case net::URLRequestStatus::IO_PENDING
:
293 status
= "IO_PENDING ";
295 case net::URLRequestStatus::CANCELED
:
298 case net::URLRequestStatus::FAILED
:
305 if (p
.status() == net::URLRequestStatus::FAILED
)
310 if (p
.status() == net::URLRequestStatus::FAILED
) {
312 LogParam(p
.error(), l
);