blob: 8f813f6a836386c6eafa5199349f40428c7937f4 [file] [log] [blame]
license.botbf09a502008-08-24 00:55:551// Copyright (c) 2006-2008 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.
initial.commit09911bf2008-07-26 23:55:294
[email protected]e1981f432008-08-12 15:22:135#ifndef CHROME_COMMON_IPC_MESSAGE_UTILS_H_
6#define CHROME_COMMON_IPC_MESSAGE_UTILS_H_
initial.commit09911bf2008-07-26 23:55:297
8#include <string>
9#include <vector>
10#include <map>
11
[email protected]690a99c2009-01-06 16:48:4512#include "base/file_path.h"
initial.commit09911bf2008-07-26 23:55:2913#include "base/string_util.h"
initial.commit09911bf2008-07-26 23:55:2914#include "base/tuple.h"
[email protected]526776c2009-02-07 00:39:2615#if defined(OS_POSIX)
[email protected]d0c0b1d2009-02-12 18:32:4516#include "chrome/common/file_descriptor_set_posix.h"
[email protected]526776c2009-02-07 00:39:2617#endif
[email protected]e68e62fa2009-02-20 02:00:0418#include "chrome/common/ipc_maybe.h"
initial.commit09911bf2008-07-26 23:55:2919#include "chrome/common/ipc_sync_message.h"
20#include "chrome/common/thumbnail_score.h"
[email protected]e68e62fa2009-02-20 02:00:0421#include "chrome/common/transport_dib.h"
initial.commit09911bf2008-07-26 23:55:2922#include "webkit/glue/cache_manager.h"
23#include "webkit/glue/console_message_level.h"
[email protected]5a52f162008-08-27 04:15:3124#include "webkit/glue/find_in_page_request.h"
[email protected]4c870b42008-11-06 00:36:5225#include "webkit/glue/webcursor.h"
initial.commit09911bf2008-07-26 23:55:2926#include "webkit/glue/window_open_disposition.h"
[email protected]3178f4e22008-08-05 21:20:4127
28// Forward declarations.
29class GURL;
[email protected]e1981f432008-08-12 15:22:1330class SkBitmap;
[email protected]3178f4e22008-08-05 21:20:4131
32namespace gfx {
33class Point;
34class Rect;
35class Size;
36} // namespace gfx
37
38namespace webkit_glue {
39struct WebApplicationInfo;
40} // namespace webkit_glue
initial.commit09911bf2008-07-26 23:55:2941
[email protected]f91cb992009-02-04 20:10:1242// Used by IPC_BEGIN_MESSAGES so that each message class starts from a unique
43// base. Messages have unique IDs across channels in order for the IPC logging
44// code to figure out the message class from its ID.
45enum IPCMessageStart {
46 // By using a start value of 0 for automation messages, we keep backward
47 // compatibility with old builds.
48 AutomationMsgStart = 0,
49 ViewMsgStart,
50 ViewHostMsgStart,
51 PluginProcessMsgStart,
52 PluginProcessHostMsgStart,
53 PluginMsgStart,
54 PluginHostMsgStart,
55 NPObjectMsgStart,
56 TestMsgStart,
[email protected]503683f2009-02-26 09:13:0157 DevToolsAgentMsgStart,
58 DevToolsClientMsgStart,
[email protected]f91cb992009-02-04 20:10:1259 // NOTE: When you add a new message class, also update
60 // IPCStatusView::IPCStatusView to ensure logging works.
61 // NOTE: this enum is used by IPC_MESSAGE_MACRO to generate a unique message
62 // id. Only 4 bits are used for the message type, so if this enum needs more
63 // than 16 entries, that code needs to be updated.
64 LastMsgIndex
65};
66
67COMPILE_ASSERT(LastMsgIndex <= 16, need_to_update_IPC_MESSAGE_MACRO);
68
initial.commit09911bf2008-07-26 23:55:2969namespace IPC {
70
initial.commit09911bf2008-07-26 23:55:2971//-----------------------------------------------------------------------------
72// An iterator class for reading the fields contained within a Message.
73
74class MessageIterator {
75 public:
[email protected]e1981f432008-08-12 15:22:1376 explicit MessageIterator(const Message& m) : msg_(m), iter_(NULL) {
initial.commit09911bf2008-07-26 23:55:2977 }
78 int NextInt() const {
79 int val;
80 if (!msg_.ReadInt(&iter_, &val))
81 NOTREACHED();
82 return val;
83 }
84 intptr_t NextIntPtr() const {
85 intptr_t val;
86 if (!msg_.ReadIntPtr(&iter_, &val))
87 NOTREACHED();
88 return val;
89 }
90 const std::string NextString() const {
91 std::string val;
92 if (!msg_.ReadString(&iter_, &val))
93 NOTREACHED();
94 return val;
95 }
96 const std::wstring NextWString() const {
97 std::wstring val;
98 if (!msg_.ReadWString(&iter_, &val))
99 NOTREACHED();
100 return val;
101 }
102 const void NextData(const char** data, int* length) const {
103 if (!msg_.ReadData(&iter_, data, length)) {
104 NOTREACHED();
105 }
106 }
107 private:
108 const Message& msg_;
109 mutable void* iter_;
110};
111
112//-----------------------------------------------------------------------------
[email protected]7d5c3ac2009-02-04 08:58:19113// ParamTraits specializations, etc.
114
115template <class P> struct ParamTraits {};
116
117template <class P>
118static inline void WriteParam(Message* m, const P& p) {
119 ParamTraits<P>::Write(m, p);
120}
121
122template <class P>
123static inline bool ReadParam(const Message* m, void** iter, P* p) {
124 return ParamTraits<P>::Read(m, iter, p);
125}
126
127template <class P>
128static inline void LogParam(const P& p, std::wstring* l) {
129 ParamTraits<P>::Log(p, l);
130}
131
132template <>
133struct ParamTraits<bool> {
134 typedef bool param_type;
135 static void Write(Message* m, const param_type& p) {
136 m->WriteBool(p);
137 }
138 static bool Read(const Message* m, void** iter, param_type* r) {
139 return m->ReadBool(iter, r);
140 }
141 static void Log(const param_type& p, std::wstring* l) {
142 l->append(p ? L"true" : L"false");
143 }
144};
145
146template <>
147struct ParamTraits<int> {
148 typedef int param_type;
149 static void Write(Message* m, const param_type& p) {
150 m->WriteInt(p);
151 }
152 static bool Read(const Message* m, void** iter, param_type* r) {
153 return m->ReadInt(iter, r);
154 }
155 static void Log(const param_type& p, std::wstring* l) {
156 l->append(StringPrintf(L"%d", p));
157 }
158};
159
160template <>
161struct ParamTraits<long> {
162 typedef long param_type;
163 static void Write(Message* m, const param_type& p) {
164 m->WriteLong(p);
165 }
166 static bool Read(const Message* m, void** iter, param_type* r) {
167 return m->ReadLong(iter, r);
168 }
169 static void Log(const param_type& p, std::wstring* l) {
170 l->append(StringPrintf(L"%l", p));
171 }
172};
173
174template <>
175struct ParamTraits<size_t> {
176 typedef size_t param_type;
177 static void Write(Message* m, const param_type& p) {
178 m->WriteSize(p);
179 }
180 static bool Read(const Message* m, void** iter, param_type* r) {
181 return m->ReadSize(iter, r);
182 }
183 static void Log(const param_type& p, std::wstring* l) {
184 l->append(StringPrintf(L"%u", p));
185 }
186};
187
188#if defined(OS_MACOSX)
189// On Linux size_t & uint32 can be the same type.
190// TODO(playmobil): Fix compilation if this is not the case.
191template <>
192struct ParamTraits<uint32> {
193 typedef uint32 param_type;
194 static void Write(Message* m, const param_type& p) {
195 m->WriteUInt32(p);
196 }
197 static bool Read(const Message* m, void** iter, param_type* r) {
198 return m->ReadUInt32(iter, r);
199 }
200 static void Log(const param_type& p, std::wstring* l) {
201 l->append(StringPrintf(L"%u", p));
202 }
203};
204#endif // defined(OS_MACOSX)
205
206template <>
207struct ParamTraits<int64> {
208 typedef int64 param_type;
209 static void Write(Message* m, const param_type& p) {
210 m->WriteInt64(p);
211 }
212 static bool Read(const Message* m, void** iter, param_type* r) {
213 return m->ReadInt64(iter, r);
214 }
215 static void Log(const param_type& p, std::wstring* l) {
216 l->append(StringPrintf(L"%I64d", p));
217 }
218};
219
220template <>
221struct ParamTraits<uint64> {
222 typedef uint64 param_type;
223 static void Write(Message* m, const param_type& p) {
224 m->WriteInt64(static_cast<int64>(p));
225 }
226 static bool Read(const Message* m, void** iter, param_type* r) {
227 return m->ReadInt64(iter, reinterpret_cast<int64*>(r));
228 }
229 static void Log(const param_type& p, std::wstring* l) {
230 l->append(StringPrintf(L"%I64u", p));
231 }
232};
233
234template <>
235struct ParamTraits<double> {
236 typedef double param_type;
237 static void Write(Message* m, const param_type& p) {
238 m->WriteData(reinterpret_cast<const char*>(&p), sizeof(param_type));
239 }
240 static bool Read(const Message* m, void** iter, param_type* r) {
241 const char *data;
242 int data_size = 0;
243 bool result = m->ReadData(iter, &data, &data_size);
244 if (result && data_size == sizeof(param_type)) {
245 memcpy(r, data, sizeof(param_type));
246 } else {
247 result = false;
248 NOTREACHED();
249 }
250
251 return result;
252 }
253 static void Log(const param_type& p, std::wstring* l) {
254 l->append(StringPrintf(L"e", p));
255 }
256};
257
258template <>
259struct ParamTraits<wchar_t> {
260 typedef wchar_t param_type;
261 static void Write(Message* m, const param_type& p) {
262 m->WriteData(reinterpret_cast<const char*>(&p), sizeof(param_type));
263 }
264 static bool Read(const Message* m, void** iter, param_type* r) {
265 const char *data;
266 int data_size = 0;
267 bool result = m->ReadData(iter, &data, &data_size);
268 if (result && data_size == sizeof(param_type)) {
269 memcpy(r, data, sizeof(param_type));
270 } else {
271 result = false;
272 NOTREACHED();
273 }
274
275 return result;
276 }
277 static void Log(const param_type& p, std::wstring* l) {
278 l->append(StringPrintf(L"%lc", p));
279 }
280};
281
282template <>
283struct ParamTraits<base::Time> {
284 typedef base::Time param_type;
285 static void Write(Message* m, const param_type& p) {
286 ParamTraits<int64>::Write(m, p.ToInternalValue());
287 }
288 static bool Read(const Message* m, void** iter, param_type* r) {
289 int64 value;
290 if (!ParamTraits<int64>::Read(m, iter, &value))
291 return false;
292 *r = base::Time::FromInternalValue(value);
293 return true;
294 }
295 static void Log(const param_type& p, std::wstring* l) {
296 ParamTraits<int64>::Log(p.ToInternalValue(), l);
297 }
298};
299
300#if defined(OS_WIN)
301template <>
302struct ParamTraits<LOGFONT> {
303 typedef LOGFONT param_type;
304 static void Write(Message* m, const param_type& p) {
305 m->WriteData(reinterpret_cast<const char*>(&p), sizeof(LOGFONT));
306 }
307 static bool Read(const Message* m, void** iter, param_type* r) {
308 const char *data;
309 int data_size = 0;
310 bool result = m->ReadData(iter, &data, &data_size);
311 if (result && data_size == sizeof(LOGFONT)) {
312 memcpy(r, data, sizeof(LOGFONT));
313 } else {
314 result = false;
315 NOTREACHED();
316 }
317
318 return result;
319 }
320 static void Log(const param_type& p, std::wstring* l) {
321 l->append(StringPrintf(L"<LOGFONT>"));
322 }
323};
324
325template <>
326struct ParamTraits<MSG> {
327 typedef MSG param_type;
328 static void Write(Message* m, const param_type& p) {
329 m->WriteData(reinterpret_cast<const char*>(&p), sizeof(MSG));
330 }
331 static bool Read(const Message* m, void** iter, param_type* r) {
332 const char *data;
333 int data_size = 0;
334 bool result = m->ReadData(iter, &data, &data_size);
335 if (result && data_size == sizeof(MSG)) {
336 memcpy(r, data, sizeof(MSG));
337 } else {
338 result = false;
339 NOTREACHED();
340 }
341
342 return result;
343 }
344};
345#endif // defined(OS_WIN)
346
347template <>
348struct ParamTraits<SkBitmap> {
349 typedef SkBitmap param_type;
350 static void Write(Message* m, const param_type& p);
351
352 // Note: This function expects parameter |r| to be of type &SkBitmap since
353 // r->SetConfig() and r->SetPixels() are called.
354 static bool Read(const Message* m, void** iter, param_type* r);
355
356 static void Log(const param_type& p, std::wstring* l);
357};
358
359template <>
360struct ParamTraits<std::string> {
361 typedef std::string param_type;
362 static void Write(Message* m, const param_type& p) {
363 m->WriteString(p);
364 }
365 static bool Read(const Message* m, void** iter, param_type* r) {
366 return m->ReadString(iter, r);
367 }
368 static void Log(const param_type& p, std::wstring* l) {
369 l->append(UTF8ToWide(p));
370 }
371};
372
373template <>
374struct ParamTraits<std::vector<unsigned char> > {
375 typedef std::vector<unsigned char> param_type;
376 static void Write(Message* m, const param_type& p) {
377 if (p.size() == 0) {
378 m->WriteData(NULL, 0);
379 } else {
380 m->WriteData(reinterpret_cast<const char*>(&p.front()),
381 static_cast<int>(p.size()));
382 }
383 }
384 static bool Read(const Message* m, void** iter, param_type* r) {
385 const char *data;
386 int data_size = 0;
387 if (!m->ReadData(iter, &data, &data_size) || data_size < 0)
388 return false;
389 r->resize(data_size);
390 if (data_size)
391 memcpy(&r->front(), data, data_size);
392 return true;
393 }
394 static void Log(const param_type& p, std::wstring* l) {
395 for (size_t i = 0; i < p.size(); ++i)
396 l->push_back(p[i]);
397 }
398};
399
400template <>
401struct ParamTraits<std::vector<char> > {
402 typedef std::vector<char> param_type;
403 static void Write(Message* m, const param_type& p) {
404 if (p.size() == 0) {
405 m->WriteData(NULL, 0);
406 } else {
407 m->WriteData(&p.front(), static_cast<int>(p.size()));
408 }
409 }
410 static bool Read(const Message* m, void** iter, param_type* r) {
411 const char *data;
412 int data_size = 0;
413 if (!m->ReadData(iter, &data, &data_size) || data_size < 0)
414 return false;
415 r->resize(data_size);
416 if (data_size)
417 memcpy(&r->front(), data, data_size);
418 return true;
419 }
420 static void Log(const param_type& p, std::wstring* l) {
421 for (size_t i = 0; i < p.size(); ++i)
422 l->push_back(p[i]);
423 }
424};
425
426template <class P>
427struct ParamTraits<std::vector<P> > {
428 typedef std::vector<P> param_type;
429 static void Write(Message* m, const param_type& p) {
430 WriteParam(m, static_cast<int>(p.size()));
431 for (size_t i = 0; i < p.size(); i++)
432 WriteParam(m, p[i]);
433 }
434 static bool Read(const Message* m, void** iter, param_type* r) {
435 int size;
436 if (!m->ReadLength(iter, &size))
437 return false;
438 // Resizing beforehand is not safe, see BUG 1006367 for details.
439 if (m->IteratorHasRoomFor(*iter, size * sizeof(P))) {
440 r->resize(size);
441 for (int i = 0; i < size; i++) {
442 if (!ReadParam(m, iter, &(*r)[i]))
443 return false;
444 }
445 } else {
446 for (int i = 0; i < size; i++) {
447 P element;
448 if (!ReadParam(m, iter, &element))
449 return false;
450 r->push_back(element);
451 }
452 }
453 return true;
454 }
455 static void Log(const param_type& p, std::wstring* l) {
456 for (size_t i = 0; i < p.size(); ++i) {
457 if (i != 0)
458 l->append(L" ");
459
460 LogParam((p[i]), l);
461 }
462 }
463};
464
465template <class K, class V>
466struct ParamTraits<std::map<K, V> > {
467 typedef std::map<K, V> param_type;
468 static void Write(Message* m, const param_type& p) {
469 WriteParam(m, static_cast<int>(p.size()));
470 typename param_type::const_iterator iter;
471 for (iter = p.begin(); iter != p.end(); ++iter) {
472 WriteParam(m, iter->first);
473 WriteParam(m, iter->second);
474 }
475 }
476 static bool Read(const Message* m, void** iter, param_type* r) {
477 int size;
478 if (!ReadParam(m, iter, &size) || size < 0)
479 return false;
480 for (int i = 0; i < size; ++i) {
481 K k;
482 if (!ReadParam(m, iter, &k))
483 return false;
484 V& value = (*r)[k];
485 if (!ReadParam(m, iter, &value))
486 return false;
487 }
488 return true;
489 }
490 static void Log(const param_type& p, std::wstring* l) {
491 l->append(L"<std::map>");
492 }
493};
494
495template <>
496struct ParamTraits<std::wstring> {
497 typedef std::wstring param_type;
498 static void Write(Message* m, const param_type& p) {
499 m->WriteWString(p);
500 }
501 static bool Read(const Message* m, void** iter, param_type* r) {
502 return m->ReadWString(iter, r);
503 }
504 static void Log(const param_type& p, std::wstring* l) {
505 l->append(p);
506 }
507};
508
509template <>
510struct ParamTraits<GURL> {
511 typedef GURL param_type;
512 static void Write(Message* m, const param_type& p);
513 static bool Read(const Message* m, void** iter, param_type* p);
514 static void Log(const param_type& p, std::wstring* l);
515};
516
517// and, a few more useful types...
518#if defined(OS_WIN)
519template <>
520struct ParamTraits<HANDLE> {
521 typedef HANDLE param_type;
522 static void Write(Message* m, const param_type& p) {
523 m->WriteIntPtr(reinterpret_cast<intptr_t>(p));
524 }
525 static bool Read(const Message* m, void** iter, param_type* r) {
526 DCHECK_EQ(sizeof(param_type), sizeof(intptr_t));
527 return m->ReadIntPtr(iter, reinterpret_cast<intptr_t*>(r));
528 }
529 static void Log(const param_type& p, std::wstring* l) {
530 l->append(StringPrintf(L"0x%X", p));
531 }
532};
533
534template <>
535struct ParamTraits<HCURSOR> {
536 typedef HCURSOR param_type;
537 static void Write(Message* m, const param_type& p) {
538 m->WriteIntPtr(reinterpret_cast<intptr_t>(p));
539 }
540 static bool Read(const Message* m, void** iter, param_type* r) {
541 DCHECK_EQ(sizeof(param_type), sizeof(intptr_t));
542 return m->ReadIntPtr(iter, reinterpret_cast<intptr_t*>(r));
543 }
544 static void Log(const param_type& p, std::wstring* l) {
545 l->append(StringPrintf(L"0x%X", p));
546 }
547};
548
549template <>
550struct ParamTraits<HWND> {
551 typedef HWND param_type;
552 static void Write(Message* m, const param_type& p) {
553 m->WriteIntPtr(reinterpret_cast<intptr_t>(p));
554 }
555 static bool Read(const Message* m, void** iter, param_type* r) {
556 DCHECK_EQ(sizeof(param_type), sizeof(intptr_t));
557 return m->ReadIntPtr(iter, reinterpret_cast<intptr_t*>(r));
558 }
559 static void Log(const param_type& p, std::wstring* l) {
560 l->append(StringPrintf(L"0x%X", p));
561 }
562};
563
564template <>
565struct ParamTraits<HRGN> {
566 typedef HRGN param_type;
567 static void Write(Message* m, const param_type& p) {
568 int data_size = GetRegionData(p, 0, NULL);
569 if (data_size) {
570 char* bytes = new char[data_size];
571 GetRegionData(p, data_size, reinterpret_cast<LPRGNDATA>(bytes));
572 m->WriteData(reinterpret_cast<const char*>(bytes), data_size);
573 delete [] bytes;
574 } else {
575 m->WriteData(NULL, 0);
576 }
577 }
578 static bool Read(const Message* m, void** iter, param_type* r) {
579 bool res = FALSE;
580 const char *data;
581 int data_size = 0;
582 res = m->ReadData(iter, &data, &data_size);
583 if (data_size) {
584 *r = ExtCreateRegion(NULL, data_size,
585 reinterpret_cast<CONST RGNDATA*>(data));
586 } else {
587 res = TRUE;
588 *r = CreateRectRgn(0, 0, 0, 0);
589 }
590 return res;
591 }
592 static void Log(const param_type& p, std::wstring* l) {
593 l->append(StringPrintf(L"0x%X", p));
594 }
595};
596
597template <>
598struct ParamTraits<HACCEL> {
599 typedef HACCEL param_type;
600 static void Write(Message* m, const param_type& p) {
601 m->WriteIntPtr(reinterpret_cast<intptr_t>(p));
602 }
603 static bool Read(const Message* m, void** iter, param_type* r) {
604 DCHECK_EQ(sizeof(param_type), sizeof(intptr_t));
605 return m->ReadIntPtr(iter, reinterpret_cast<intptr_t*>(r));
606 }
607};
608
609template <>
610struct ParamTraits<POINT> {
611 typedef POINT param_type;
612 static void Write(Message* m, const param_type& p) {
613 m->WriteInt(p.x);
614 m->WriteInt(p.y);
615 }
616 static bool Read(const Message* m, void** iter, param_type* r) {
617 int x, y;
618 if (!m->ReadInt(iter, &x) || !m->ReadInt(iter, &y))
619 return false;
620 r->x = x;
621 r->y = y;
622 return true;
623 }
624 static void Log(const param_type& p, std::wstring* l) {
625 l->append(StringPrintf(L"(%d, %d)", p.x, p.y));
626 }
627};
628#endif // defined(OS_WIN)
629
630template <>
631struct ParamTraits<FilePath> {
632 typedef FilePath param_type;
633 static void Write(Message* m, const param_type& p) {
634 ParamTraits<FilePath::StringType>::Write(m, p.value());
635 }
636 static bool Read(const Message* m, void** iter, param_type* r) {
637 FilePath::StringType value;
638 if (!ParamTraits<FilePath::StringType>::Read(m, iter, &value))
639 return false;
640 *r = FilePath(value);
641 return true;
642 }
643 static void Log(const param_type& p, std::wstring* l) {
644 ParamTraits<FilePath::StringType>::Log(p.value(), l);
645 }
646};
647
648template <>
649struct ParamTraits<gfx::Point> {
650 typedef gfx::Point param_type;
651 static void Write(Message* m, const param_type& p);
652 static bool Read(const Message* m, void** iter, param_type* r);
653 static void Log(const param_type& p, std::wstring* l);
654};
655
656template <>
657struct ParamTraits<gfx::Rect> {
658 typedef gfx::Rect param_type;
659 static void Write(Message* m, const param_type& p);
660 static bool Read(const Message* m, void** iter, param_type* r);
661 static void Log(const param_type& p, std::wstring* l);
662};
663
664template <>
665struct ParamTraits<gfx::Size> {
666 typedef gfx::Size param_type;
667 static void Write(Message* m, const param_type& p);
668 static bool Read(const Message* m, void** iter, param_type* r);
669 static void Log(const param_type& p, std::wstring* l);
670};
671
[email protected]526776c2009-02-07 00:39:26672#if defined(OS_POSIX)
673
674template<>
[email protected]5fe733de2009-02-11 18:59:20675struct ParamTraits<base::FileDescriptor> {
676 typedef base::FileDescriptor param_type;
[email protected]526776c2009-02-07 00:39:26677 static void Write(Message* m, const param_type& p) {
[email protected]7135bb042009-02-12 04:05:28678 if (!m->WriteFileDescriptor(p))
679 NOTREACHED();
[email protected]526776c2009-02-07 00:39:26680 }
681 static bool Read(const Message* m, void** iter, param_type* r) {
[email protected]7135bb042009-02-12 04:05:28682 return m->ReadFileDescriptor(iter, r);
[email protected]526776c2009-02-07 00:39:26683 }
684 static void Log(const param_type& p, std::wstring* l) {
685 if (p.auto_close) {
[email protected]7135bb042009-02-12 04:05:28686 l->append(StringPrintf(L"FD(%d auto-close)", p.fd));
[email protected]526776c2009-02-07 00:39:26687 } else {
[email protected]7135bb042009-02-12 04:05:28688 l->append(StringPrintf(L"FD(%d)", p.fd));
[email protected]526776c2009-02-07 00:39:26689 }
690 }
691};
692
693#endif // defined(OS_POSIX)
694
[email protected]7d5c3ac2009-02-04 08:58:19695template<>
696struct ParamTraits<ThumbnailScore> {
697 typedef ThumbnailScore param_type;
698 static void Write(Message* m, const param_type& p) {
699 IPC::ParamTraits<double>::Write(m, p.boring_score);
700 IPC::ParamTraits<bool>::Write(m, p.good_clipping);
701 IPC::ParamTraits<bool>::Write(m, p.at_top);
702 IPC::ParamTraits<base::Time>::Write(m, p.time_at_snapshot);
703 }
704 static bool Read(const Message* m, void** iter, param_type* r) {
705 double boring_score;
706 bool good_clipping, at_top;
707 base::Time time_at_snapshot;
708 if (!IPC::ParamTraits<double>::Read(m, iter, &boring_score) ||
709 !IPC::ParamTraits<bool>::Read(m, iter, &good_clipping) ||
710 !IPC::ParamTraits<bool>::Read(m, iter, &at_top) ||
711 !IPC::ParamTraits<base::Time>::Read(m, iter, &time_at_snapshot))
712 return false;
713
714 r->boring_score = boring_score;
715 r->good_clipping = good_clipping;
716 r->at_top = at_top;
717 r->time_at_snapshot = time_at_snapshot;
718 return true;
719 }
720 static void Log(const param_type& p, std::wstring* l) {
721 l->append(StringPrintf(L"(%f, %d, %d)",
722 p.boring_score, p.good_clipping, p.at_top));
723 }
724};
725
726template <>
727struct ParamTraits<WindowOpenDisposition> {
728 typedef WindowOpenDisposition param_type;
729 static void Write(Message* m, const param_type& p) {
730 m->WriteInt(p);
731 }
732 static bool Read(const Message* m, void** iter, param_type* r) {
733 int temp;
734 bool res = m->ReadInt(iter, &temp);
735 *r = static_cast<WindowOpenDisposition>(temp);
736 return res;
737 }
738 static void Log(const param_type& p, std::wstring* l) {
739 l->append(StringPrintf(L"%d", p));
740 }
741};
742
743template <>
744struct ParamTraits<ConsoleMessageLevel> {
745 typedef ConsoleMessageLevel param_type;
746 static void Write(Message* m, const param_type& p) {
747 m->WriteInt(p);
748 }
749 static bool Read(const Message* m, void** iter, param_type* r) {
750 int temp;
751 bool res = m->ReadInt(iter, &temp);
752 *r = static_cast<ConsoleMessageLevel>(temp);
753 return res;
754 }
755 static void Log(const param_type& p, std::wstring* l) {
756 l->append(StringPrintf(L"%d", p));
757 }
758};
759
760template <>
761struct ParamTraits<CacheManager::ResourceTypeStat> {
762 typedef CacheManager::ResourceTypeStat param_type;
763 static void Write(Message* m, const param_type& p) {
764 WriteParam(m, p.count);
765 WriteParam(m, p.size);
766 WriteParam(m, p.live_size);
767 WriteParam(m, p.decoded_size);
768 }
769 static bool Read(const Message* m, void** iter, param_type* r) {
770 bool result =
771 ReadParam(m, iter, &r->count) &&
772 ReadParam(m, iter, &r->size) &&
773 ReadParam(m, iter, &r->live_size) &&
774 ReadParam(m, iter, &r->decoded_size);
775 return result;
776 }
777 static void Log(const param_type& p, std::wstring* l) {
778 l->append(StringPrintf(L"%d %d %d %d", p.count, p.size, p.live_size,
779 p.decoded_size));
780 }
781};
782
783template <>
784struct ParamTraits<CacheManager::ResourceTypeStats> {
785 typedef CacheManager::ResourceTypeStats param_type;
786 static void Write(Message* m, const param_type& p) {
787 WriteParam(m, p.images);
788 WriteParam(m, p.css_stylesheets);
789 WriteParam(m, p.scripts);
790 WriteParam(m, p.xsl_stylesheets);
791 WriteParam(m, p.fonts);
792 }
793 static bool Read(const Message* m, void** iter, param_type* r) {
794 bool result =
795 ReadParam(m, iter, &r->images) &&
796 ReadParam(m, iter, &r->css_stylesheets) &&
797 ReadParam(m, iter, &r->scripts) &&
798 ReadParam(m, iter, &r->xsl_stylesheets) &&
799 ReadParam(m, iter, &r->fonts);
800 return result;
801 }
802 static void Log(const param_type& p, std::wstring* l) {
803 l->append(L"<WebCoreStats>");
804 LogParam(p.images, l);
805 LogParam(p.css_stylesheets, l);
806 LogParam(p.scripts, l);
807 LogParam(p.xsl_stylesheets, l);
808 LogParam(p.fonts, l);
809 l->append(L"</WebCoreStats>");
810 }
811};
812
813#if defined(OS_WIN)
814template <>
815struct ParamTraits<XFORM> {
816 typedef XFORM param_type;
817 static void Write(Message* m, const param_type& p) {
818 m->WriteData(reinterpret_cast<const char*>(&p), sizeof(XFORM));
819 }
820 static bool Read(const Message* m, void** iter, param_type* r) {
821 const char *data;
822 int data_size = 0;
823 bool result = m->ReadData(iter, &data, &data_size);
824 if (result && data_size == sizeof(XFORM)) {
825 memcpy(r, data, sizeof(XFORM));
826 } else {
827 result = false;
828 NOTREACHED();
829 }
830
831 return result;
832 }
833 static void Log(const param_type& p, std::wstring* l) {
834 l->append(L"<XFORM>");
835 }
836};
837#endif // defined(OS_WIN)
838
839template <>
840struct ParamTraits<WebCursor> {
841 typedef WebCursor param_type;
842 static void Write(Message* m, const param_type& p) {
843 p.Serialize(m);
844 }
845 static bool Read(const Message* m, void** iter, param_type* r) {
846 return r->Deserialize(m, iter);
847 }
848 static void Log(const param_type& p, std::wstring* l) {
849 l->append(L"<WebCursor>");
850 }
851};
852
853struct LogData {
854 std::wstring channel;
855 uint16 type;
856 std::wstring flags;
857 int64 sent; // Time that the message was sent (i.e. at Send()).
858 int64 receive; // Time before it was dispatched (i.e. before calling
859 // OnMessageReceived).
860 int64 dispatch; // Time after it was dispatched (i.e. after calling
861 // OnMessageReceived).
[email protected]e707d5e62009-02-12 04:00:08862 std::wstring message_name;
[email protected]7d5c3ac2009-02-04 08:58:19863 std::wstring params;
864};
865
866template <>
867struct ParamTraits<LogData> {
868 typedef LogData param_type;
869 static void Write(Message* m, const param_type& p) {
870 WriteParam(m, p.channel);
871 WriteParam(m, static_cast<int>(p.type));
872 WriteParam(m, p.flags);
873 WriteParam(m, p.sent);
874 WriteParam(m, p.receive);
875 WriteParam(m, p.dispatch);
876 WriteParam(m, p.params);
877 }
878 static bool Read(const Message* m, void** iter, param_type* r) {
879 int type;
880 bool result =
881 ReadParam(m, iter, &r->channel) &&
882 ReadParam(m, iter, &type) &&
883 ReadParam(m, iter, &r->flags) &&
884 ReadParam(m, iter, &r->sent) &&
885 ReadParam(m, iter, &r->receive) &&
886 ReadParam(m, iter, &r->dispatch) &&
887 ReadParam(m, iter, &r->params);
888 r->type = static_cast<uint16>(type);
889 return result;
890 }
891 static void Log(const param_type& p, std::wstring* l) {
892 // Doesn't make sense to implement this!
893 }
894};
895
896template <>
[email protected]503683f2009-02-26 09:13:01897struct ParamTraits<Message> {
898 static void Write(Message* m, const Message& p) {
899 m->WriteInt(p.size());
900 m->WriteData(reinterpret_cast<const char*>(p.data()), p.size());
901 }
902 static bool Read(const Message* m, void** iter, Message* r) {
903 int size;
904 if (!m->ReadInt(iter, &size))
905 return false;
906 const char* data;
907 if (!m->ReadData(iter, &data, &size))
908 return false;
909 *r = Message(data, size);
910 return true;
911 }
912 static void Log(const Message& p, std::wstring* l) {
913 l->append(L"<IPC::Message>");
914 }
915};
916
917template <>
[email protected]7d5c3ac2009-02-04 08:58:19918struct ParamTraits<Tuple0> {
919 typedef Tuple0 param_type;
920 static void Write(Message* m, const param_type& p) {
921 }
922 static bool Read(const Message* m, void** iter, param_type* r) {
923 return true;
924 }
925 static void Log(const param_type& p, std::wstring* l) {
926 }
927};
928
929template <class A>
930struct ParamTraits< Tuple1<A> > {
931 typedef Tuple1<A> param_type;
932 static void Write(Message* m, const param_type& p) {
933 WriteParam(m, p.a);
934 }
935 static bool Read(const Message* m, void** iter, param_type* r) {
936 return ReadParam(m, iter, &r->a);
937 }
938 static void Log(const param_type& p, std::wstring* l) {
939 LogParam(p.a, l);
940 }
941};
942
943template <class A, class B>
944struct ParamTraits< Tuple2<A, B> > {
945 typedef Tuple2<A, B> param_type;
946 static void Write(Message* m, const param_type& p) {
947 WriteParam(m, p.a);
948 WriteParam(m, p.b);
949 }
950 static bool Read(const Message* m, void** iter, param_type* r) {
951 return (ReadParam(m, iter, &r->a) &&
952 ReadParam(m, iter, &r->b));
953 }
954 static void Log(const param_type& p, std::wstring* l) {
955 LogParam(p.a, l);
956 l->append(L", ");
957 LogParam(p.b, l);
958 }
959};
960
961template <class A, class B, class C>
962struct ParamTraits< Tuple3<A, B, C> > {
963 typedef Tuple3<A, B, C> param_type;
964 static void Write(Message* m, const param_type& p) {
965 WriteParam(m, p.a);
966 WriteParam(m, p.b);
967 WriteParam(m, p.c);
968 }
969 static bool Read(const Message* m, void** iter, param_type* r) {
970 return (ReadParam(m, iter, &r->a) &&
971 ReadParam(m, iter, &r->b) &&
972 ReadParam(m, iter, &r->c));
973 }
974 static void Log(const param_type& p, std::wstring* l) {
975 LogParam(p.a, l);
976 l->append(L", ");
977 LogParam(p.b, l);
978 l->append(L", ");
979 LogParam(p.c, l);
980 }
981};
982
983template <class A, class B, class C, class D>
984struct ParamTraits< Tuple4<A, B, C, D> > {
985 typedef Tuple4<A, B, C, D> param_type;
986 static void Write(Message* m, const param_type& p) {
987 WriteParam(m, p.a);
988 WriteParam(m, p.b);
989 WriteParam(m, p.c);
990 WriteParam(m, p.d);
991 }
992 static bool Read(const Message* m, void** iter, param_type* r) {
993 return (ReadParam(m, iter, &r->a) &&
994 ReadParam(m, iter, &r->b) &&
995 ReadParam(m, iter, &r->c) &&
996 ReadParam(m, iter, &r->d));
997 }
998 static void Log(const param_type& p, std::wstring* l) {
999 LogParam(p.a, l);
1000 l->append(L", ");
1001 LogParam(p.b, l);
1002 l->append(L", ");
1003 LogParam(p.c, l);
1004 l->append(L", ");
1005 LogParam(p.d, l);
1006 }
1007};
1008
1009template <class A, class B, class C, class D, class E>
1010struct ParamTraits< Tuple5<A, B, C, D, E> > {
1011 typedef Tuple5<A, B, C, D, E> param_type;
1012 static void Write(Message* m, const param_type& p) {
1013 WriteParam(m, p.a);
1014 WriteParam(m, p.b);
1015 WriteParam(m, p.c);
1016 WriteParam(m, p.d);
1017 WriteParam(m, p.e);
1018 }
1019 static bool Read(const Message* m, void** iter, param_type* r) {
1020 return (ReadParam(m, iter, &r->a) &&
1021 ReadParam(m, iter, &r->b) &&
1022 ReadParam(m, iter, &r->c) &&
1023 ReadParam(m, iter, &r->d) &&
1024 ReadParam(m, iter, &r->e));
1025 }
1026 static void Log(const param_type& p, std::wstring* l) {
1027 LogParam(p.a, l);
1028 l->append(L", ");
1029 LogParam(p.b, l);
1030 l->append(L", ");
1031 LogParam(p.c, l);
1032 l->append(L", ");
1033 LogParam(p.d, l);
1034 l->append(L", ");
1035 LogParam(p.e, l);
1036 }
1037};
1038
1039template <class A, class B, class C, class D, class E, class F>
1040struct ParamTraits< Tuple6<A, B, C, D, E, F> > {
1041 typedef Tuple6<A, B, C, D, E, F> param_type;
1042 static void Write(Message* m, const param_type& p) {
1043 WriteParam(m, p.a);
1044 WriteParam(m, p.b);
1045 WriteParam(m, p.c);
1046 WriteParam(m, p.d);
1047 WriteParam(m, p.e);
1048 WriteParam(m, p.f);
1049 }
1050 static bool Read(const Message* m, void** iter, param_type* r) {
1051 return (ReadParam(m, iter, &r->a) &&
1052 ReadParam(m, iter, &r->b) &&
1053 ReadParam(m, iter, &r->c) &&
1054 ReadParam(m, iter, &r->d) &&
1055 ReadParam(m, iter, &r->e) &&
1056 ReadParam(m, iter, &r->f));
1057 }
1058 static void Log(const param_type& p, std::wstring* l) {
1059 LogParam(p.a, l);
1060 l->append(L", ");
1061 LogParam(p.b, l);
1062 l->append(L", ");
1063 LogParam(p.c, l);
1064 l->append(L", ");
1065 LogParam(p.d, l);
1066 l->append(L", ");
1067 LogParam(p.e, l);
1068 l->append(L", ");
1069 LogParam(p.f, l);
1070 }
1071};
1072
[email protected]e68e62fa2009-02-20 02:00:041073#if defined(OS_WIN)
1074template<>
1075struct ParamTraits<TransportDIB::Id> {
1076 typedef TransportDIB::Id param_type;
1077 static void Write(Message* m, const param_type& p) {
1078 WriteParam(m, p.handle);
1079 WriteParam(m, p.sequence_num);
1080 }
1081 static bool Read(const Message* m, void** iter, param_type* r) {
1082 return (ReadParam(m, iter, &r->handle) &&
1083 ReadParam(m, iter, &r->sequence_num));
1084 }
1085 static void Log(const param_type& p, std::wstring* l) {
1086 l->append(L"TransportDIB(");
1087 LogParam(p.handle, l);
1088 l->append(L", ");
1089 LogParam(p.sequence_num, l);
1090 l->append(L")");
1091 }
1092};
1093#endif
1094
1095template<typename A>
1096struct ParamTraits<Maybe<A> > {
1097 typedef struct Maybe<A> param_type;
1098 static void Write(Message* m, const param_type& p) {
1099 WriteParam(m, p.valid);
1100 if (p.valid)
1101 WriteParam(m, p.value);
1102 }
1103 static bool Read(const Message* m, void** iter, param_type* r) {
1104 if (!ReadParam(m, iter, &r->valid))
1105 return false;
1106
1107 if (r->valid)
1108 return ReadParam(m, iter, &r->value);
1109 return true;
1110 }
1111 static void Log(const param_type& p, std::wstring* l) {
1112 if (p.valid) {
1113 l->append(L"Just ");
1114 ParamTraits<A>::Log(p.value, l);
1115 } else {
1116 l->append(L"Nothing");
1117 }
1118
1119 }
1120};
1121
[email protected]7d5c3ac2009-02-04 08:58:191122template <>
1123struct ParamTraits<webkit_glue::WebApplicationInfo> {
1124 typedef webkit_glue::WebApplicationInfo param_type;
1125 static void Write(Message* m, const param_type& p);
1126 static bool Read(const Message* m, void** iter, param_type* r);
1127 static void Log(const param_type& p, std::wstring* l);
1128};
1129
1130
1131//-----------------------------------------------------------------------------
initial.commit09911bf2008-07-26 23:55:291132// Generic message subclasses
1133
1134// Used for asynchronous messages.
[email protected]81a34412009-01-05 19:17:241135template <class ParamType>
initial.commit09911bf2008-07-26 23:55:291136class MessageWithTuple : public Message {
1137 public:
[email protected]81a34412009-01-05 19:17:241138 typedef ParamType Param;
1139
[email protected]d4651ff2008-12-02 16:51:581140 MessageWithTuple(int32 routing_id, uint16 type, const Param& p)
initial.commit09911bf2008-07-26 23:55:291141 : Message(routing_id, type, PRIORITY_NORMAL) {
1142 WriteParam(this, p);
1143 }
1144
[email protected]7d5c3ac2009-02-04 08:58:191145 static bool Read(const Message* msg, Param* p) {
initial.commit09911bf2008-07-26 23:55:291146 void* iter = NULL;
1147 bool rv = ReadParam(msg, &iter, p);
1148 DCHECK(rv) << "Error deserializing message " << msg->type();
1149 return rv;
1150 }
1151
1152 // Generic dispatcher. Should cover most cases.
1153 template<class T, class Method>
[email protected]7d5c3ac2009-02-04 08:58:191154 static bool Dispatch(const Message* msg, T* obj, Method func) {
initial.commit09911bf2008-07-26 23:55:291155 Param p;
1156 if (Read(msg, &p)) {
1157 DispatchToMethod(obj, func, p);
1158 return true;
1159 }
1160 return false;
1161 }
1162
1163 // The following dispatchers exist for the case where the callback function
1164 // needs the message as well. They assume that "Param" is a type of Tuple
1165 // (except the one arg case, as there is no Tuple1).
1166 template<class T, typename TA>
[email protected]7d5c3ac2009-02-04 08:58:191167 static bool Dispatch(const Message* msg, T* obj,
initial.commit09911bf2008-07-26 23:55:291168 void (T::*func)(const Message&, TA)) {
1169 Param p;
1170 if (Read(msg, &p)) {
1171 (obj->*func)(*msg, p);
1172 return true;
1173 }
1174 return false;
1175 }
1176
1177 template<class T, typename TA, typename TB>
[email protected]7d5c3ac2009-02-04 08:58:191178 static bool Dispatch(const Message* msg, T* obj,
initial.commit09911bf2008-07-26 23:55:291179 void (T::*func)(const Message&, TA, TB)) {
1180 Param p;
1181 if (Read(msg, &p)) {
1182 (obj->*func)(*msg, p.a, p.b);
1183 return true;
1184 }
1185 return false;
1186 }
1187
1188 template<class T, typename TA, typename TB, typename TC>
[email protected]7d5c3ac2009-02-04 08:58:191189 static bool Dispatch(const Message* msg, T* obj,
initial.commit09911bf2008-07-26 23:55:291190 void (T::*func)(const Message&, TA, TB, TC)) {
1191 Param p;
1192 if (Read(msg, &p)) {
1193 (obj->*func)(*msg, p.a, p.b, p.c);
1194 return true;
1195 }
1196 return false;
1197 }
1198
1199 template<class T, typename TA, typename TB, typename TC, typename TD>
[email protected]7d5c3ac2009-02-04 08:58:191200 static bool Dispatch(const Message* msg, T* obj,
initial.commit09911bf2008-07-26 23:55:291201 void (T::*func)(const Message&, TA, TB, TC, TD)) {
1202 Param p;
1203 if (Read(msg, &p)) {
1204 (obj->*func)(*msg, p.a, p.b, p.c, p.d);
1205 return true;
1206 }
1207 return false;
1208 }
1209
1210 template<class T, typename TA, typename TB, typename TC, typename TD,
1211 typename TE>
[email protected]7d5c3ac2009-02-04 08:58:191212 static bool Dispatch(const Message* msg, T* obj,
initial.commit09911bf2008-07-26 23:55:291213 void (T::*func)(const Message&, TA, TB, TC, TD, TE)) {
1214 Param p;
1215 if (Read(msg, &p)) {
1216 (obj->*func)(*msg, p.a, p.b, p.c, p.d, p.e);
1217 return true;
1218 }
1219 return false;
1220 }
1221
[email protected]7d5c3ac2009-02-04 08:58:191222 static void Log(const Message* msg, std::wstring* l) {
initial.commit09911bf2008-07-26 23:55:291223 Param p;
1224 if (Read(msg, &p))
1225 LogParam(p, l);
1226 }
[email protected]deb57402009-02-06 01:35:301227
1228 // Functions used to do manual unpacking. Only used by the automation code,
1229 // these should go away once that code uses SyncChannel.
1230 template<typename TA, typename TB>
1231 static bool Read(const IPC::Message* msg, TA* a, TB* b) {
1232 ParamType params;
1233 if (!Read(msg, &params))
1234 return false;
1235 *a = params.a;
1236 *b = params.b;
1237 return true;
1238 }
1239
1240 template<typename TA, typename TB, typename TC>
1241 static bool Read(const IPC::Message* msg, TA* a, TB* b, TC* c) {
1242 ParamType params;
1243 if (!Read(msg, &params))
1244 return false;
1245 *a = params.a;
1246 *b = params.b;
1247 *c = params.c;
1248 return true;
1249 }
1250
1251 template<typename TA, typename TB, typename TC, typename TD>
1252 static bool Read(const IPC::Message* msg, TA* a, TB* b, TC* c, TD* d) {
1253 ParamType params;
1254 if (!Read(msg, &params))
1255 return false;
1256 *a = params.a;
1257 *b = params.b;
1258 *c = params.c;
1259 *d = params.d;
1260 return true;
1261 }
1262
1263 template<typename TA, typename TB, typename TC, typename TD, typename TE>
1264 static bool Read(const IPC::Message* msg, TA* a, TB* b, TC* c, TD* d, TE* e) {
1265 ParamType params;
1266 if (!Read(msg, &params))
1267 return false;
1268 *a = params.a;
1269 *b = params.b;
1270 *c = params.c;
1271 *d = params.d;
1272 *e = params.e;
1273 return true;
1274 }
initial.commit09911bf2008-07-26 23:55:291275};
1276
1277// This class assumes that its template argument is a RefTuple (a Tuple with
1278// reference elements).
1279template <class RefTuple>
1280class ParamDeserializer : public MessageReplyDeserializer {
1281 public:
[email protected]e1981f432008-08-12 15:22:131282 explicit ParamDeserializer(const RefTuple& out) : out_(out) { }
initial.commit09911bf2008-07-26 23:55:291283
1284 bool SerializeOutputParameters(const IPC::Message& msg, void* iter) {
1285 return ReadParam(&msg, &iter, &out_);
1286 }
1287
1288 RefTuple out_;
1289};
1290
1291// defined in ipc_logging.cc
1292void GenerateLogData(const std::wstring& channel, const Message& message,
1293 LogData* data);
1294
1295// Used for synchronous messages.
1296template <class SendParam, class ReplyParam>
1297class MessageWithReply : public SyncMessage {
1298 public:
[email protected]d4651ff2008-12-02 16:51:581299 MessageWithReply(int32 routing_id, uint16 type,
initial.commit09911bf2008-07-26 23:55:291300 const SendParam& send, const ReplyParam& reply)
1301 : SyncMessage(routing_id, type, PRIORITY_NORMAL,
1302 new ParamDeserializer<ReplyParam>(reply)) {
1303 WriteParam(this, send);
1304 }
1305
[email protected]7d5c3ac2009-02-04 08:58:191306 static void Log(const Message* msg, std::wstring* l) {
initial.commit09911bf2008-07-26 23:55:291307 if (msg->is_sync()) {
1308 SendParam p;
1309 void* iter = SyncMessage::GetDataIterator(msg);
1310 ReadParam(msg, &iter, &p);
1311 LogParam(p, l);
1312
[email protected]1156f7b2008-12-04 19:13:591313#if defined(IPC_MESSAGE_LOG_ENABLED)
initial.commit09911bf2008-07-26 23:55:291314 const std::wstring& output_params = msg->output_params();
1315 if (!l->empty() && !output_params.empty())
1316 l->append(L", ");
1317
1318 l->append(output_params);
[email protected]2a34f9c2008-12-04 19:12:041319#endif
initial.commit09911bf2008-07-26 23:55:291320 } else {
1321 // This is an outgoing reply. Now that we have the output parameters, we
1322 // can finally log the message.
[email protected]d4651ff2008-12-02 16:51:581323 typename ReplyParam::ValueTuple p;
initial.commit09911bf2008-07-26 23:55:291324 void* iter = SyncMessage::GetDataIterator(msg);
1325 ReadParam(msg, &iter, &p);
1326 LogParam(p, l);
1327 }
1328 }
1329
1330 template<class T, class Method>
[email protected]7d5c3ac2009-02-04 08:58:191331 static bool Dispatch(const Message* msg, T* obj, Method func) {
initial.commit09911bf2008-07-26 23:55:291332 SendParam send_params;
1333 void* iter = GetDataIterator(msg);
1334 Message* reply = GenerateReply(msg);
1335 bool error;
1336 if (ReadParam(msg, &iter, &send_params)) {
[email protected]d4651ff2008-12-02 16:51:581337 typename ReplyParam::ValueTuple reply_params;
initial.commit09911bf2008-07-26 23:55:291338 DispatchToMethod(obj, func, send_params, &reply_params);
1339 WriteParam(reply, reply_params);
1340 error = false;
1341#ifdef IPC_MESSAGE_LOG_ENABLED
1342 if (msg->received_time() != 0) {
1343 std::wstring output_params;
1344 LogParam(reply_params, &output_params);
1345 msg->set_output_params(output_params);
1346 }
1347#endif
1348 } else {
1349 NOTREACHED() << "Error deserializing message " << msg->type();
1350 reply->set_reply_error();
1351 error = true;
1352 }
1353
1354 obj->Send(reply);
1355 return !error;
1356 }
1357
1358 template<class T, class Method>
[email protected]7d5c3ac2009-02-04 08:58:191359 static bool DispatchDelayReply(const Message* msg, T* obj, Method func) {
initial.commit09911bf2008-07-26 23:55:291360 SendParam send_params;
1361 void* iter = GetDataIterator(msg);
1362 Message* reply = GenerateReply(msg);
1363 bool error;
1364 if (ReadParam(msg, &iter, &send_params)) {
1365 Tuple1<Message&> t = MakeRefTuple(*reply);
1366
1367#ifdef IPC_MESSAGE_LOG_ENABLED
1368 if (msg->sent_time()) {
1369 // Don't log the sync message after dispatch, as we don't have the
1370 // output parameters at that point. Instead, save its data and log it
1371 // with the outgoing reply message when it's sent.
1372 LogData* data = new LogData;
1373 GenerateLogData(L"", *msg, data);
1374 msg->set_dont_log();
1375 reply->set_sync_log_data(data);
1376 }
1377#endif
1378 DispatchToMethod(obj, func, send_params, &t);
1379 error = false;
1380 } else {
1381 NOTREACHED() << "Error deserializing message " << msg->type();
1382 reply->set_reply_error();
1383 obj->Send(reply);
1384 error = true;
1385 }
1386 return !error;
1387 }
1388
1389 template<typename TA>
1390 static void WriteReplyParams(Message* reply, TA a) {
1391 ReplyParam p(a);
1392 WriteParam(reply, p);
1393 }
1394
1395 template<typename TA, typename TB>
1396 static void WriteReplyParams(Message* reply, TA a, TB b) {
1397 ReplyParam p(a, b);
1398 WriteParam(reply, p);
1399 }
1400
1401 template<typename TA, typename TB, typename TC>
1402 static void WriteReplyParams(Message* reply, TA a, TB b, TC c) {
1403 ReplyParam p(a, b, c);
1404 WriteParam(reply, p);
1405 }
1406
1407 template<typename TA, typename TB, typename TC, typename TD>
1408 static void WriteReplyParams(Message* reply, TA a, TB b, TC c, TD d) {
1409 ReplyParam p(a, b, c, d);
1410 WriteParam(reply, p);
1411 }
1412
1413 template<typename TA, typename TB, typename TC, typename TD, typename TE>
1414 static void WriteReplyParams(Message* reply, TA a, TB b, TC c, TD d, TE e) {
1415 ReplyParam p(a, b, c, d, e);
1416 WriteParam(reply, p);
1417 }
1418};
1419
[email protected]7d5c3ac2009-02-04 08:58:191420// Traits for ViewMsg_FindInPageMsg_Request structure to pack/unpack.
1421template <>
1422struct ParamTraits<FindInPageRequest> {
1423 typedef FindInPageRequest param_type;
1424 static void Write(Message* m, const param_type& p) {
1425 WriteParam(m, p.request_id);
1426 WriteParam(m, p.search_string);
1427 WriteParam(m, p.forward);
1428 WriteParam(m, p.match_case);
1429 WriteParam(m, p.find_next);
1430 }
1431 static bool Read(const Message* m, void** iter, param_type* p) {
1432 return
1433 ReadParam(m, iter, &p->request_id) &&
1434 ReadParam(m, iter, &p->search_string) &&
1435 ReadParam(m, iter, &p->forward) &&
1436 ReadParam(m, iter, &p->match_case) &&
1437 ReadParam(m, iter, &p->find_next);
1438 }
1439 static void Log(const param_type& p, std::wstring* l) {
1440 l->append(L"<FindInPageRequest>");
1441 }
1442};
1443
1444//-----------------------------------------------------------------------------
1445
[email protected]3178f4e22008-08-05 21:20:411446} // namespace IPC
initial.commit09911bf2008-07-26 23:55:291447
[email protected]e1981f432008-08-12 15:22:131448#endif // CHROME_COMMON_IPC_MESSAGE_UTILS_H_
license.botbf09a502008-08-24 00:55:551449