Revert my change to get the tree green. Not sure why the tests became flaky. I'll try to check them in again but in smaller chunks tomorrow.
TBR=mpcomplete
Review URL: http://codereview.chromium.org/21039
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@9132 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/chrome/common/ipc_message_utils.h b/chrome/common/ipc_message_utils.h
index 35146eee..39bb231 100644
--- a/chrome/common/ipc_message_utils.h
+++ b/chrome/common/ipc_message_utils.h
@@ -34,984 +34,16 @@
struct WebApplicationInfo;
} // namespace webkit_glue
-// Used by IPC_BEGIN_MESSAGES so that each message class starts from a unique
-// base. Messages have unique IDs across channels in order for the IPC logging
-// code to figure out the message class from its ID.
-enum IPCMessageStart {
- // By using a start value of 0 for automation messages, we keep backward
- // compatibility with old builds.
- AutomationMsgStart = 0,
- ViewMsgStart,
- ViewHostMsgStart,
- PluginProcessMsgStart,
- PluginProcessHostMsgStart,
- PluginMsgStart,
- PluginHostMsgStart,
- NPObjectMsgStart,
- TestMsgStart,
- // NOTE: When you add a new message class, also update
- // IPCStatusView::IPCStatusView to ensure logging works.
- // NOTE: this enum is used by IPC_MESSAGE_MACRO to generate a unique message
- // id. Only 4 bits are used for the message type, so if this enum needs more
- // than 16 entries, that code needs to be updated.
- LastMsgIndex
-};
-
-COMPILE_ASSERT(LastMsgIndex <= 16, need_to_update_IPC_MESSAGE_MACRO);
-
-//-----------------------------------------------------------------------------
-// ParamTraits specializations, etc.
-
-template <class P> struct ParamTraits {};
-
-template <class P>
-static inline void WriteParam(IPC::Message* m, const P& p) {
- ParamTraits<P>::Write(m, p);
-}
-
-template <class P>
-static inline bool ReadParam(const IPC::Message* m, void** iter, P* p) {
- return ParamTraits<P>::Read(m, iter, p);
-}
-
-template <class P>
-static inline void LogParam(const P& p, std::wstring* l) {
- ParamTraits<P>::Log(p, l);
-}
-
-template <>
-struct ParamTraits<bool> {
- typedef bool param_type;
- static void Write(IPC::Message* m, const param_type& p) {
- m->WriteBool(p);
- }
- static bool Read(const IPC::Message* m, void** iter, param_type* r) {
- return m->ReadBool(iter, r);
- }
- static void Log(const param_type& p, std::wstring* l) {
- l->append(p ? L"true" : L"false");
- }
-};
-
-template <>
-struct ParamTraits<int> {
- typedef int param_type;
- static void Write(IPC::Message* m, const param_type& p) {
- m->WriteInt(p);
- }
- static bool Read(const IPC::Message* m, void** iter, param_type* r) {
- return m->ReadInt(iter, r);
- }
- static void Log(const param_type& p, std::wstring* l) {
- l->append(StringPrintf(L"%d", p));
- }
-};
-
-template <>
-struct ParamTraits<long> {
- typedef long param_type;
- static void Write(IPC::Message* m, const param_type& p) {
- m->WriteLong(p);
- }
- static bool Read(const IPC::Message* m, void** iter, param_type* r) {
- return m->ReadLong(iter, r);
- }
- static void Log(const param_type& p, std::wstring* l) {
- l->append(StringPrintf(L"%l", p));
- }
-};
-
-template <>
-struct ParamTraits<size_t> {
- typedef size_t param_type;
- static void Write(IPC::Message* m, const param_type& p) {
- m->WriteSize(p);
- }
- static bool Read(const IPC::Message* m, void** iter, param_type* r) {
- return m->ReadSize(iter, r);
- }
- static void Log(const param_type& p, std::wstring* l) {
- l->append(StringPrintf(L"%u", p));
- }
-};
-
-#if defined(OS_MACOSX)
-// On Linux size_t & uint32 can be the same type.
-// TODO(playmobil): Fix compilation if this is not the case.
-template <>
-struct ParamTraits<uint32> {
- typedef uint32 param_type;
- static void Write(IPC::Message* m, const param_type& p) {
- m->WriteUInt32(p);
- }
- static bool Read(const IPC::Message* m, void** iter, param_type* r) {
- return m->ReadUInt32(iter, r);
- }
- static void Log(const param_type& p, std::wstring* l) {
- l->append(StringPrintf(L"%u", p));
- }
-};
-#endif // defined(OS_MACOSX)
-
-template <>
-struct ParamTraits<int64> {
- typedef int64 param_type;
- static void Write(IPC::Message* m, const param_type& p) {
- m->WriteInt64(p);
- }
- static bool Read(const IPC::Message* m, void** iter, param_type* r) {
- return m->ReadInt64(iter, r);
- }
- static void Log(const param_type& p, std::wstring* l) {
- l->append(StringPrintf(L"%I64d", p));
- }
-};
-
-template <>
-struct ParamTraits<uint64> {
- typedef uint64 param_type;
- static void Write(IPC::Message* m, const param_type& p) {
- m->WriteInt64(static_cast<int64>(p));
- }
- static bool Read(const IPC::Message* m, void** iter, param_type* r) {
- return m->ReadInt64(iter, reinterpret_cast<int64*>(r));
- }
- static void Log(const param_type& p, std::wstring* l) {
- l->append(StringPrintf(L"%I64u", p));
- }
-};
-
-template <>
-struct ParamTraits<double> {
- typedef double param_type;
- static void Write(IPC::Message* m, const param_type& p) {
- m->WriteData(reinterpret_cast<const char*>(&p), sizeof(param_type));
- }
- static bool Read(const IPC::Message* m, void** iter, param_type* r) {
- const char *data;
- int data_size = 0;
- bool result = m->ReadData(iter, &data, &data_size);
- if (result && data_size == sizeof(param_type)) {
- memcpy(r, data, sizeof(param_type));
- } else {
- result = false;
- NOTREACHED();
- }
-
- return result;
- }
- static void Log(const param_type& p, std::wstring* l) {
- l->append(StringPrintf(L"e", p));
- }
-};
-
-template <>
-struct ParamTraits<wchar_t> {
- typedef wchar_t param_type;
- static void Write(IPC::Message* m, const param_type& p) {
- m->WriteData(reinterpret_cast<const char*>(&p), sizeof(param_type));
- }
- static bool Read(const IPC::Message* m, void** iter, param_type* r) {
- const char *data;
- int data_size = 0;
- bool result = m->ReadData(iter, &data, &data_size);
- if (result && data_size == sizeof(param_type)) {
- memcpy(r, data, sizeof(param_type));
- } else {
- result = false;
- NOTREACHED();
- }
-
- return result;
- }
- static void Log(const param_type& p, std::wstring* l) {
- l->append(StringPrintf(L"%lc", p));
- }
-};
-
-template <>
-struct ParamTraits<base::Time> {
- typedef base::Time param_type;
- static void Write(IPC::Message* m, const param_type& p) {
- ParamTraits<int64>::Write(m, p.ToInternalValue());
- }
- static bool Read(const IPC::Message* m, void** iter, param_type* r) {
- int64 value;
- if (!ParamTraits<int64>::Read(m, iter, &value))
- return false;
- *r = base::Time::FromInternalValue(value);
- return true;
- }
- static void Log(const param_type& p, std::wstring* l) {
- ParamTraits<int64>::Log(p.ToInternalValue(), l);
- }
-};
-
-#if defined(OS_WIN)
-template <>
-struct ParamTraits<LOGFONT> {
- typedef LOGFONT param_type;
- static void Write(IPC::Message* m, const param_type& p) {
- m->WriteData(reinterpret_cast<const char*>(&p), sizeof(LOGFONT));
- }
- static bool Read(const IPC::Message* m, void** iter, param_type* r) {
- const char *data;
- int data_size = 0;
- bool result = m->ReadData(iter, &data, &data_size);
- if (result && data_size == sizeof(LOGFONT)) {
- memcpy(r, data, sizeof(LOGFONT));
- } else {
- result = false;
- NOTREACHED();
- }
-
- return result;
- }
- static void Log(const param_type& p, std::wstring* l) {
- l->append(StringPrintf(L"<LOGFONT>"));
- }
-};
-
-template <>
-struct ParamTraits<MSG> {
- typedef MSG param_type;
- static void Write(IPC::Message* m, const param_type& p) {
- m->WriteData(reinterpret_cast<const char*>(&p), sizeof(MSG));
- }
- static bool Read(const IPC::Message* m, void** iter, param_type* r) {
- const char *data;
- int data_size = 0;
- bool result = m->ReadData(iter, &data, &data_size);
- if (result && data_size == sizeof(MSG)) {
- memcpy(r, data, sizeof(MSG));
- } else {
- result = false;
- NOTREACHED();
- }
-
- return result;
- }
-};
-#endif // defined(OS_WIN)
-
-template <>
-struct ParamTraits<SkBitmap> {
- typedef SkBitmap param_type;
- static void Write(IPC::Message* m, const param_type& p);
-
- // Note: This function expects parameter |r| to be of type &SkBitmap since
- // r->SetConfig() and r->SetPixels() are called.
- static bool Read(const IPC::Message* m, void** iter, param_type* r);
-
- static void Log(const param_type& p, std::wstring* l);
-};
-
-template <>
-struct ParamTraits<std::string> {
- typedef std::string param_type;
- static void Write(IPC::Message* m, const param_type& p) {
- m->WriteString(p);
- }
- static bool Read(const IPC::Message* m, void** iter, param_type* r) {
- return m->ReadString(iter, r);
- }
- static void Log(const param_type& p, std::wstring* l) {
- l->append(UTF8ToWide(p));
- }
-};
-
-template <>
-struct ParamTraits<std::vector<unsigned char> > {
- typedef std::vector<unsigned char> param_type;
- static void Write(IPC::Message* m, const param_type& p) {
- if (p.size() == 0) {
- m->WriteData(NULL, 0);
- } else {
- m->WriteData(reinterpret_cast<const char*>(&p.front()),
- static_cast<int>(p.size()));
- }
- }
- static bool Read(const IPC::Message* m, void** iter, param_type* r) {
- const char *data;
- int data_size = 0;
- if (!m->ReadData(iter, &data, &data_size) || data_size < 0)
- return false;
- r->resize(data_size);
- if (data_size)
- memcpy(&r->front(), data, data_size);
- return true;
- }
- static void Log(const param_type& p, std::wstring* l) {
- for (size_t i = 0; i < p.size(); ++i)
- l->push_back(p[i]);
- }
-};
-
-template <>
-struct ParamTraits<std::vector<char> > {
- typedef std::vector<char> param_type;
- static void Write(IPC::Message* m, const param_type& p) {
- if (p.size() == 0) {
- m->WriteData(NULL, 0);
- } else {
- m->WriteData(&p.front(), static_cast<int>(p.size()));
- }
- }
- static bool Read(const IPC::Message* m, void** iter, param_type* r) {
- const char *data;
- int data_size = 0;
- if (!m->ReadData(iter, &data, &data_size) || data_size < 0)
- return false;
- r->resize(data_size);
- if (data_size)
- memcpy(&r->front(), data, data_size);
- return true;
- }
- static void Log(const param_type& p, std::wstring* l) {
- for (size_t i = 0; i < p.size(); ++i)
- l->push_back(p[i]);
- }
-};
-
-template <class P>
-struct ParamTraits<std::vector<P> > {
- typedef std::vector<P> param_type;
- static void Write(IPC::Message* m, const param_type& p) {
- WriteParam(m, static_cast<int>(p.size()));
- for (size_t i = 0; i < p.size(); i++)
- WriteParam(m, p[i]);
- }
- static bool Read(const IPC::Message* m, void** iter, param_type* r) {
- int size;
- if (!m->ReadLength(iter, &size))
- return false;
- // Resizing beforehand is not safe, see BUG 1006367 for details.
- if (m->IteratorHasRoomFor(*iter, size * sizeof(P))) {
- r->resize(size);
- for (int i = 0; i < size; i++) {
- if (!ReadParam(m, iter, &(*r)[i]))
- return false;
- }
- } else {
- for (int i = 0; i < size; i++) {
- P element;
- if (!ReadParam(m, iter, &element))
- return false;
- r->push_back(element);
- }
- }
- return true;
- }
- static void Log(const param_type& p, std::wstring* l) {
- for (size_t i = 0; i < p.size(); ++i) {
- if (i != 0)
- l->append(L" ");
-
- LogParam((p[i]), l);
- }
- }
-};
-
-template <class K, class V>
-struct ParamTraits<std::map<K, V> > {
- typedef std::map<K, V> param_type;
- static void Write(IPC::Message* m, const param_type& p) {
- WriteParam(m, static_cast<int>(p.size()));
- typename param_type::const_iterator iter;
- for (iter = p.begin(); iter != p.end(); ++iter) {
- WriteParam(m, iter->first);
- WriteParam(m, iter->second);
- }
- }
- static bool Read(const IPC::Message* m, void** iter, param_type* r) {
- int size;
- if (!ReadParam(m, iter, &size) || size < 0)
- return false;
- for (int i = 0; i < size; ++i) {
- K k;
- if (!ReadParam(m, iter, &k))
- return false;
- V& value = (*r)[k];
- if (!ReadParam(m, iter, &value))
- return false;
- }
- return true;
- }
- static void Log(const param_type& p, std::wstring* l) {
- l->append(L"<std::map>");
- }
-};
-
-template <>
-struct ParamTraits<std::wstring> {
- typedef std::wstring param_type;
- static void Write(IPC::Message* m, const param_type& p) {
- m->WriteWString(p);
- }
- static bool Read(const IPC::Message* m, void** iter, param_type* r) {
- return m->ReadWString(iter, r);
- }
- static void Log(const param_type& p, std::wstring* l) {
- l->append(p);
- }
-};
-
-template <>
-struct ParamTraits<GURL> {
- typedef GURL param_type;
- static void Write(IPC::Message* m, const param_type& p);
- static bool Read(const IPC::Message* m, void** iter, param_type* p);
- static void Log(const param_type& p, std::wstring* l);
-};
-
-// and, a few more useful types...
-#if defined(OS_WIN)
-template <>
-struct ParamTraits<HANDLE> {
- typedef HANDLE param_type;
- static void Write(IPC::Message* m, const param_type& p) {
- m->WriteIntPtr(reinterpret_cast<intptr_t>(p));
- }
- static bool Read(const IPC::Message* m, void** iter, param_type* r) {
- DCHECK_EQ(sizeof(param_type), sizeof(intptr_t));
- return m->ReadIntPtr(iter, reinterpret_cast<intptr_t*>(r));
- }
- static void Log(const param_type& p, std::wstring* l) {
- l->append(StringPrintf(L"0x%X", p));
- }
-};
-
-template <>
-struct ParamTraits<HCURSOR> {
- typedef HCURSOR param_type;
- static void Write(IPC::Message* m, const param_type& p) {
- m->WriteIntPtr(reinterpret_cast<intptr_t>(p));
- }
- static bool Read(const IPC::Message* m, void** iter, param_type* r) {
- DCHECK_EQ(sizeof(param_type), sizeof(intptr_t));
- return m->ReadIntPtr(iter, reinterpret_cast<intptr_t*>(r));
- }
- static void Log(const param_type& p, std::wstring* l) {
- l->append(StringPrintf(L"0x%X", p));
- }
-};
-
-template <>
-struct ParamTraits<HWND> {
- typedef HWND param_type;
- static void Write(IPC::Message* m, const param_type& p) {
- m->WriteIntPtr(reinterpret_cast<intptr_t>(p));
- }
- static bool Read(const IPC::Message* m, void** iter, param_type* r) {
- DCHECK_EQ(sizeof(param_type), sizeof(intptr_t));
- return m->ReadIntPtr(iter, reinterpret_cast<intptr_t*>(r));
- }
- static void Log(const param_type& p, std::wstring* l) {
- l->append(StringPrintf(L"0x%X", p));
- }
-};
-
-template <>
-struct ParamTraits<HRGN> {
- typedef HRGN param_type;
- static void Write(IPC::Message* m, const param_type& p) {
- int data_size = GetRegionData(p, 0, NULL);
- if (data_size) {
- char* bytes = new char[data_size];
- GetRegionData(p, data_size, reinterpret_cast<LPRGNDATA>(bytes));
- m->WriteData(reinterpret_cast<const char*>(bytes), data_size);
- delete [] bytes;
- } else {
- m->WriteData(NULL, 0);
- }
- }
- static bool Read(const IPC::Message* m, void** iter, param_type* r) {
- bool res = FALSE;
- const char *data;
- int data_size = 0;
- res = m->ReadData(iter, &data, &data_size);
- if (data_size) {
- *r = ExtCreateRegion(NULL, data_size,
- reinterpret_cast<CONST RGNDATA*>(data));
- } else {
- res = TRUE;
- *r = CreateRectRgn(0, 0, 0, 0);
- }
- return res;
- }
- static void Log(const param_type& p, std::wstring* l) {
- l->append(StringPrintf(L"0x%X", p));
- }
-};
-
-template <>
-struct ParamTraits<HACCEL> {
- typedef HACCEL param_type;
- static void Write(IPC::Message* m, const param_type& p) {
- m->WriteIntPtr(reinterpret_cast<intptr_t>(p));
- }
- static bool Read(const IPC::Message* m, void** iter, param_type* r) {
- DCHECK_EQ(sizeof(param_type), sizeof(intptr_t));
- return m->ReadIntPtr(iter, reinterpret_cast<intptr_t*>(r));
- }
-};
-
-template <>
-struct ParamTraits<POINT> {
- typedef POINT param_type;
- static void Write(IPC::Message* m, const param_type& p) {
- m->WriteInt(p.x);
- m->WriteInt(p.y);
- }
- static bool Read(const IPC::Message* m, void** iter, param_type* r) {
- int x, y;
- if (!m->ReadInt(iter, &x) || !m->ReadInt(iter, &y))
- return false;
- r->x = x;
- r->y = y;
- return true;
- }
- static void Log(const param_type& p, std::wstring* l) {
- l->append(StringPrintf(L"(%d, %d)", p.x, p.y));
- }
-};
-#endif // defined(OS_WIN)
-
-template <>
-struct ParamTraits<FilePath> {
- typedef FilePath param_type;
- static void Write(IPC::Message* m, const param_type& p) {
- ParamTraits<FilePath::StringType>::Write(m, p.value());
- }
- static bool Read(const IPC::Message* m, void** iter, param_type* r) {
- FilePath::StringType value;
- if (!ParamTraits<FilePath::StringType>::Read(m, iter, &value))
- return false;
- *r = FilePath(value);
- return true;
- }
- static void Log(const param_type& p, std::wstring* l) {
- ParamTraits<FilePath::StringType>::Log(p.value(), l);
- }
-};
-
-template <>
-struct ParamTraits<gfx::Point> {
- typedef gfx::Point param_type;
- static void Write(IPC::Message* m, const param_type& p);
- static bool Read(const IPC::Message* m, void** iter, param_type* r);
- static void Log(const param_type& p, std::wstring* l);
-};
-
-template <>
-struct ParamTraits<gfx::Rect> {
- typedef gfx::Rect param_type;
- static void Write(IPC::Message* m, const param_type& p);
- static bool Read(const IPC::Message* m, void** iter, param_type* r);
- static void Log(const param_type& p, std::wstring* l);
-};
-
-template <>
-struct ParamTraits<gfx::Size> {
- typedef gfx::Size param_type;
- static void Write(IPC::Message* m, const param_type& p);
- static bool Read(const IPC::Message* m, void** iter, param_type* r);
- static void Log(const param_type& p, std::wstring* l);
-};
-
-template<>
-struct ParamTraits<ThumbnailScore> {
- typedef ThumbnailScore param_type;
- static void Write(IPC::Message* m, const param_type& p) {
- ParamTraits<double>::Write(m, p.boring_score);
- ParamTraits<bool>::Write(m, p.good_clipping);
- ParamTraits<bool>::Write(m, p.at_top);
- ParamTraits<base::Time>::Write(m, p.time_at_snapshot);
- }
- static bool Read(const IPC::Message* m, void** iter, param_type* r) {
- double boring_score;
- bool good_clipping, at_top;
- base::Time time_at_snapshot;
- if (!ParamTraits<double>::Read(m, iter, &boring_score) ||
- !ParamTraits<bool>::Read(m, iter, &good_clipping) ||
- !ParamTraits<bool>::Read(m, iter, &at_top) ||
- !ParamTraits<base::Time>::Read(m, iter, &time_at_snapshot))
- return false;
-
- r->boring_score = boring_score;
- r->good_clipping = good_clipping;
- r->at_top = at_top;
- r->time_at_snapshot = time_at_snapshot;
- return true;
- }
- static void Log(const param_type& p, std::wstring* l) {
- l->append(StringPrintf(L"(%f, %d, %d)",
- p.boring_score, p.good_clipping, p.at_top));
- }
-};
-
-template <>
-struct ParamTraits<WindowOpenDisposition> {
- typedef WindowOpenDisposition param_type;
- static void Write(IPC::Message* m, const param_type& p) {
- m->WriteInt(p);
- }
- static bool Read(const IPC::Message* m, void** iter, param_type* r) {
- int temp;
- bool res = m->ReadInt(iter, &temp);
- *r = static_cast<WindowOpenDisposition>(temp);
- return res;
- }
- static void Log(const param_type& p, std::wstring* l) {
- l->append(StringPrintf(L"%d", p));
- }
-};
-
-template <>
-struct ParamTraits<ConsoleMessageLevel> {
- typedef ConsoleMessageLevel param_type;
- static void Write(IPC::Message* m, const param_type& p) {
- m->WriteInt(p);
- }
- static bool Read(const IPC::Message* m, void** iter, param_type* r) {
- int temp;
- bool res = m->ReadInt(iter, &temp);
- *r = static_cast<ConsoleMessageLevel>(temp);
- return res;
- }
- static void Log(const param_type& p, std::wstring* l) {
- l->append(StringPrintf(L"%d", p));
- }
-};
-
-template <>
-struct ParamTraits<CacheManager::ResourceTypeStat> {
- typedef CacheManager::ResourceTypeStat param_type;
- static void Write(IPC::Message* m, const param_type& p) {
- WriteParam(m, p.count);
- WriteParam(m, p.size);
- WriteParam(m, p.live_size);
- WriteParam(m, p.decoded_size);
- }
- static bool Read(const IPC::Message* m, void** iter, param_type* r) {
- bool result =
- ReadParam(m, iter, &r->count) &&
- ReadParam(m, iter, &r->size) &&
- ReadParam(m, iter, &r->live_size) &&
- ReadParam(m, iter, &r->decoded_size);
- return result;
- }
- static void Log(const param_type& p, std::wstring* l) {
- l->append(StringPrintf(L"%d %d %d %d", p.count, p.size, p.live_size,
- p.decoded_size));
- }
-};
-
-template <>
-struct ParamTraits<CacheManager::ResourceTypeStats> {
- typedef CacheManager::ResourceTypeStats param_type;
- static void Write(IPC::Message* m, const param_type& p) {
- WriteParam(m, p.images);
- WriteParam(m, p.css_stylesheets);
- WriteParam(m, p.scripts);
- WriteParam(m, p.xsl_stylesheets);
- WriteParam(m, p.fonts);
- }
- static bool Read(const IPC::Message* m, void** iter, param_type* r) {
- bool result =
- ReadParam(m, iter, &r->images) &&
- ReadParam(m, iter, &r->css_stylesheets) &&
- ReadParam(m, iter, &r->scripts) &&
- ReadParam(m, iter, &r->xsl_stylesheets) &&
- ReadParam(m, iter, &r->fonts);
- return result;
- }
- static void Log(const param_type& p, std::wstring* l) {
- l->append(L"<WebCoreStats>");
- LogParam(p.images, l);
- LogParam(p.css_stylesheets, l);
- LogParam(p.scripts, l);
- LogParam(p.xsl_stylesheets, l);
- LogParam(p.fonts, l);
- l->append(L"</WebCoreStats>");
- }
-};
-
-#if defined(OS_WIN)
-template <>
-struct ParamTraits<XFORM> {
- typedef XFORM param_type;
- static void Write(IPC::Message* m, const param_type& p) {
- m->WriteData(reinterpret_cast<const char*>(&p), sizeof(XFORM));
- }
- static bool Read(const IPC::Message* m, void** iter, param_type* r) {
- const char *data;
- int data_size = 0;
- bool result = m->ReadData(iter, &data, &data_size);
- if (result && data_size == sizeof(XFORM)) {
- memcpy(r, data, sizeof(XFORM));
- } else {
- result = false;
- NOTREACHED();
- }
-
- return result;
- }
- static void Log(const param_type& p, std::wstring* l) {
- l->append(L"<XFORM>");
- }
-};
-#endif // defined(OS_WIN)
-
-template <>
-struct ParamTraits<WebCursor> {
- typedef WebCursor param_type;
- static void Write(IPC::Message* m, const param_type& p) {
- p.Serialize(m);
- }
- static bool Read(const IPC::Message* m, void** iter, param_type* r) {
- return r->Deserialize(m, iter);
- }
- static void Log(const param_type& p, std::wstring* l) {
- l->append(L"<WebCursor>");
- }
-};
-
namespace IPC {
-struct LogData {
- std::wstring channel;
- uint16 type;
- std::wstring flags;
- int64 sent; // Time that the message was sent (i.e. at Send()).
- int64 receive; // Time before it was dispatched (i.e. before calling
- // OnMessageReceived).
- int64 dispatch; // Time after it was dispatched (i.e. after calling
- // OnMessageReceived).
- std::wstring params;
-};
+// Used by the message macros to register a logging function based on the
+// message class.
+typedef void (LogFunction)(uint16 type,
+ std::wstring* name,
+ const IPC::Message* msg,
+ std::wstring* params);
+void RegisterMessageLogger(int msg_start, LogFunction* func);
-}
-
-template <>
-struct ParamTraits<IPC::LogData> {
- typedef IPC::LogData param_type;
- static void Write(IPC::Message* m, const param_type& p) {
- WriteParam(m, p.channel);
- WriteParam(m, static_cast<int>(p.type));
- WriteParam(m, p.flags);
- WriteParam(m, p.sent);
- WriteParam(m, p.receive);
- WriteParam(m, p.dispatch);
- WriteParam(m, p.params);
- }
- static bool Read(const IPC::Message* m, void** iter, param_type* r) {
- int type;
- bool result =
- ReadParam(m, iter, &r->channel) &&
- ReadParam(m, iter, &type) &&
- ReadParam(m, iter, &r->flags) &&
- ReadParam(m, iter, &r->sent) &&
- ReadParam(m, iter, &r->receive) &&
- ReadParam(m, iter, &r->dispatch) &&
- ReadParam(m, iter, &r->params);
- r->type = static_cast<uint16>(type);
- return result;
- }
- static void Log(const param_type& p, std::wstring* l) {
- // Doesn't make sense to implement this!
- }
-};
-
-template <>
-struct ParamTraits<Tuple0> {
- typedef Tuple0 param_type;
- static void Write(IPC::Message* m, const param_type& p) {
- }
- static bool Read(const IPC::Message* m, void** iter, param_type* r) {
- return true;
- }
- static void Log(const param_type& p, std::wstring* l) {
- }
-};
-
-template <class A>
-struct ParamTraits< Tuple1<A> > {
- typedef Tuple1<A> param_type;
- static void Write(IPC::Message* m, const param_type& p) {
- WriteParam(m, p.a);
- }
- static bool Read(const IPC::Message* m, void** iter, param_type* r) {
- return ReadParam(m, iter, &r->a);
- }
- static void Log(const param_type& p, std::wstring* l) {
- LogParam(p.a, l);
- }
-};
-
-template <class A, class B>
-struct ParamTraits< Tuple2<A, B> > {
- typedef Tuple2<A, B> param_type;
- static void Write(IPC::Message* m, const param_type& p) {
- WriteParam(m, p.a);
- WriteParam(m, p.b);
- }
- static bool Read(const IPC::Message* m, void** iter, param_type* r) {
- return (ReadParam(m, iter, &r->a) &&
- ReadParam(m, iter, &r->b));
- }
- static void Log(const param_type& p, std::wstring* l) {
- LogParam(p.a, l);
- l->append(L", ");
- LogParam(p.b, l);
- }
-};
-
-template <class A, class B, class C>
-struct ParamTraits< Tuple3<A, B, C> > {
- typedef Tuple3<A, B, C> param_type;
- static void Write(IPC::Message* m, const param_type& p) {
- WriteParam(m, p.a);
- WriteParam(m, p.b);
- WriteParam(m, p.c);
- }
- static bool Read(const IPC::Message* m, void** iter, param_type* r) {
- return (ReadParam(m, iter, &r->a) &&
- ReadParam(m, iter, &r->b) &&
- ReadParam(m, iter, &r->c));
- }
- static void Log(const param_type& p, std::wstring* l) {
- LogParam(p.a, l);
- l->append(L", ");
- LogParam(p.b, l);
- l->append(L", ");
- LogParam(p.c, l);
- }
-};
-
-template <class A, class B, class C, class D>
-struct ParamTraits< Tuple4<A, B, C, D> > {
- typedef Tuple4<A, B, C, D> param_type;
- static void Write(IPC::Message* m, const param_type& p) {
- WriteParam(m, p.a);
- WriteParam(m, p.b);
- WriteParam(m, p.c);
- WriteParam(m, p.d);
- }
- static bool Read(const IPC::Message* m, void** iter, param_type* r) {
- return (ReadParam(m, iter, &r->a) &&
- ReadParam(m, iter, &r->b) &&
- ReadParam(m, iter, &r->c) &&
- ReadParam(m, iter, &r->d));
- }
- static void Log(const param_type& p, std::wstring* l) {
- LogParam(p.a, l);
- l->append(L", ");
- LogParam(p.b, l);
- l->append(L", ");
- LogParam(p.c, l);
- l->append(L", ");
- LogParam(p.d, l);
- }
-};
-
-template <class A, class B, class C, class D, class E>
-struct ParamTraits< Tuple5<A, B, C, D, E> > {
- typedef Tuple5<A, B, C, D, E> param_type;
- static void Write(IPC::Message* m, const param_type& p) {
- WriteParam(m, p.a);
- WriteParam(m, p.b);
- WriteParam(m, p.c);
- WriteParam(m, p.d);
- WriteParam(m, p.e);
- }
- static bool Read(const IPC::Message* m, void** iter, param_type* r) {
- return (ReadParam(m, iter, &r->a) &&
- ReadParam(m, iter, &r->b) &&
- ReadParam(m, iter, &r->c) &&
- ReadParam(m, iter, &r->d) &&
- ReadParam(m, iter, &r->e));
- }
- static void Log(const param_type& p, std::wstring* l) {
- LogParam(p.a, l);
- l->append(L", ");
- LogParam(p.b, l);
- l->append(L", ");
- LogParam(p.c, l);
- l->append(L", ");
- LogParam(p.d, l);
- l->append(L", ");
- LogParam(p.e, l);
- }
-};
-
-template <class A, class B, class C, class D, class E, class F>
-struct ParamTraits< Tuple6<A, B, C, D, E, F> > {
- typedef Tuple6<A, B, C, D, E, F> param_type;
- static void Write(IPC::Message* m, const param_type& p) {
- WriteParam(m, p.a);
- WriteParam(m, p.b);
- WriteParam(m, p.c);
- WriteParam(m, p.d);
- WriteParam(m, p.e);
- WriteParam(m, p.f);
- }
- static bool Read(const IPC::Message* m, void** iter, param_type* r) {
- return (ReadParam(m, iter, &r->a) &&
- ReadParam(m, iter, &r->b) &&
- ReadParam(m, iter, &r->c) &&
- ReadParam(m, iter, &r->d) &&
- ReadParam(m, iter, &r->e) &&
- ReadParam(m, iter, &r->f));
- }
- static void Log(const param_type& p, std::wstring* l) {
- LogParam(p.a, l);
- l->append(L", ");
- LogParam(p.b, l);
- l->append(L", ");
- LogParam(p.c, l);
- l->append(L", ");
- LogParam(p.d, l);
- l->append(L", ");
- LogParam(p.e, l);
- l->append(L", ");
- LogParam(p.f, l);
- }
-};
-
-template <>
-struct ParamTraits<webkit_glue::WebApplicationInfo> {
- typedef webkit_glue::WebApplicationInfo param_type;
- static void Write(IPC::Message* m, const param_type& p);
- static bool Read(const IPC::Message* m, void** iter, param_type* r);
- static void Log(const param_type& p, std::wstring* l);
-};
-
-// Traits for ViewMsg_FindInPageMsg_Request structure to pack/unpack.
-template <>
-struct ParamTraits<FindInPageRequest> {
- typedef FindInPageRequest param_type;
- static void Write(IPC::Message* m, const param_type& p) {
- WriteParam(m, p.request_id);
- WriteParam(m, p.search_string);
- WriteParam(m, p.forward);
- WriteParam(m, p.match_case);
- WriteParam(m, p.find_next);
- }
- static bool Read(const IPC::Message* m, void** iter, param_type* p) {
- return
- ReadParam(m, iter, &p->request_id) &&
- ReadParam(m, iter, &p->search_string) &&
- ReadParam(m, iter, &p->forward) &&
- ReadParam(m, iter, &p->match_case) &&
- ReadParam(m, iter, &p->find_next);
- }
- static void Log(const param_type& p, std::wstring* l) {
- l->append(L"<FindInPageRequest>");
- }
-};
-
-namespace IPC {
//-----------------------------------------------------------------------------
// An iterator class for reading the fields contained within a Message.
@@ -1055,6 +87,931 @@
};
//-----------------------------------------------------------------------------
+// ParamTraits specializations, etc.
+
+template <class P> struct ParamTraits {};
+
+template <class P>
+static inline void WriteParam(Message* m, const P& p) {
+ ParamTraits<P>::Write(m, p);
+}
+
+template <class P>
+static inline bool ReadParam(const Message* m, void** iter, P* p) {
+ return ParamTraits<P>::Read(m, iter, p);
+}
+
+template <class P>
+static inline void LogParam(const P& p, std::wstring* l) {
+ ParamTraits<P>::Log(p, l);
+}
+
+template <>
+struct ParamTraits<bool> {
+ typedef bool param_type;
+ static void Write(Message* m, const param_type& p) {
+ m->WriteBool(p);
+ }
+ static bool Read(const Message* m, void** iter, param_type* r) {
+ return m->ReadBool(iter, r);
+ }
+ static void Log(const param_type& p, std::wstring* l) {
+ l->append(p ? L"true" : L"false");
+ }
+};
+
+template <>
+struct ParamTraits<int> {
+ typedef int param_type;
+ static void Write(Message* m, const param_type& p) {
+ m->WriteInt(p);
+ }
+ static bool Read(const Message* m, void** iter, param_type* r) {
+ return m->ReadInt(iter, r);
+ }
+ static void Log(const param_type& p, std::wstring* l) {
+ l->append(StringPrintf(L"%d", p));
+ }
+};
+
+template <>
+struct ParamTraits<long> {
+ typedef long param_type;
+ static void Write(Message* m, const param_type& p) {
+ m->WriteLong(p);
+ }
+ static bool Read(const Message* m, void** iter, param_type* r) {
+ return m->ReadLong(iter, r);
+ }
+ static void Log(const param_type& p, std::wstring* l) {
+ l->append(StringPrintf(L"%l", p));
+ }
+};
+
+template <>
+struct ParamTraits<size_t> {
+ typedef size_t param_type;
+ static void Write(Message* m, const param_type& p) {
+ m->WriteSize(p);
+ }
+ static bool Read(const Message* m, void** iter, param_type* r) {
+ return m->ReadSize(iter, r);
+ }
+ static void Log(const param_type& p, std::wstring* l) {
+ l->append(StringPrintf(L"%u", p));
+ }
+};
+
+#if defined(OS_MACOSX)
+// On Linux size_t & uint32 can be the same type.
+// TODO(playmobil): Fix compilation if this is not the case.
+template <>
+struct ParamTraits<uint32> {
+ typedef uint32 param_type;
+ static void Write(Message* m, const param_type& p) {
+ m->WriteUInt32(p);
+ }
+ static bool Read(const Message* m, void** iter, param_type* r) {
+ return m->ReadUInt32(iter, r);
+ }
+ static void Log(const param_type& p, std::wstring* l) {
+ l->append(StringPrintf(L"%u", p));
+ }
+};
+#endif // defined(OS_MACOSX)
+
+template <>
+struct ParamTraits<int64> {
+ typedef int64 param_type;
+ static void Write(Message* m, const param_type& p) {
+ m->WriteInt64(p);
+ }
+ static bool Read(const Message* m, void** iter, param_type* r) {
+ return m->ReadInt64(iter, r);
+ }
+ static void Log(const param_type& p, std::wstring* l) {
+ l->append(StringPrintf(L"%I64d", p));
+ }
+};
+
+template <>
+struct ParamTraits<uint64> {
+ typedef uint64 param_type;
+ static void Write(Message* m, const param_type& p) {
+ m->WriteInt64(static_cast<int64>(p));
+ }
+ static bool Read(const Message* m, void** iter, param_type* r) {
+ return m->ReadInt64(iter, reinterpret_cast<int64*>(r));
+ }
+ static void Log(const param_type& p, std::wstring* l) {
+ l->append(StringPrintf(L"%I64u", p));
+ }
+};
+
+template <>
+struct ParamTraits<double> {
+ typedef double param_type;
+ static void Write(Message* m, const param_type& p) {
+ m->WriteData(reinterpret_cast<const char*>(&p), sizeof(param_type));
+ }
+ static bool Read(const Message* m, void** iter, param_type* r) {
+ const char *data;
+ int data_size = 0;
+ bool result = m->ReadData(iter, &data, &data_size);
+ if (result && data_size == sizeof(param_type)) {
+ memcpy(r, data, sizeof(param_type));
+ } else {
+ result = false;
+ NOTREACHED();
+ }
+
+ return result;
+ }
+ static void Log(const param_type& p, std::wstring* l) {
+ l->append(StringPrintf(L"e", p));
+ }
+};
+
+template <>
+struct ParamTraits<wchar_t> {
+ typedef wchar_t param_type;
+ static void Write(Message* m, const param_type& p) {
+ m->WriteData(reinterpret_cast<const char*>(&p), sizeof(param_type));
+ }
+ static bool Read(const Message* m, void** iter, param_type* r) {
+ const char *data;
+ int data_size = 0;
+ bool result = m->ReadData(iter, &data, &data_size);
+ if (result && data_size == sizeof(param_type)) {
+ memcpy(r, data, sizeof(param_type));
+ } else {
+ result = false;
+ NOTREACHED();
+ }
+
+ return result;
+ }
+ static void Log(const param_type& p, std::wstring* l) {
+ l->append(StringPrintf(L"%lc", p));
+ }
+};
+
+template <>
+struct ParamTraits<base::Time> {
+ typedef base::Time param_type;
+ static void Write(Message* m, const param_type& p) {
+ ParamTraits<int64>::Write(m, p.ToInternalValue());
+ }
+ static bool Read(const Message* m, void** iter, param_type* r) {
+ int64 value;
+ if (!ParamTraits<int64>::Read(m, iter, &value))
+ return false;
+ *r = base::Time::FromInternalValue(value);
+ return true;
+ }
+ static void Log(const param_type& p, std::wstring* l) {
+ ParamTraits<int64>::Log(p.ToInternalValue(), l);
+ }
+};
+
+#if defined(OS_WIN)
+template <>
+struct ParamTraits<LOGFONT> {
+ typedef LOGFONT param_type;
+ static void Write(Message* m, const param_type& p) {
+ m->WriteData(reinterpret_cast<const char*>(&p), sizeof(LOGFONT));
+ }
+ static bool Read(const Message* m, void** iter, param_type* r) {
+ const char *data;
+ int data_size = 0;
+ bool result = m->ReadData(iter, &data, &data_size);
+ if (result && data_size == sizeof(LOGFONT)) {
+ memcpy(r, data, sizeof(LOGFONT));
+ } else {
+ result = false;
+ NOTREACHED();
+ }
+
+ return result;
+ }
+ static void Log(const param_type& p, std::wstring* l) {
+ l->append(StringPrintf(L"<LOGFONT>"));
+ }
+};
+
+template <>
+struct ParamTraits<MSG> {
+ typedef MSG param_type;
+ static void Write(Message* m, const param_type& p) {
+ m->WriteData(reinterpret_cast<const char*>(&p), sizeof(MSG));
+ }
+ static bool Read(const Message* m, void** iter, param_type* r) {
+ const char *data;
+ int data_size = 0;
+ bool result = m->ReadData(iter, &data, &data_size);
+ if (result && data_size == sizeof(MSG)) {
+ memcpy(r, data, sizeof(MSG));
+ } else {
+ result = false;
+ NOTREACHED();
+ }
+
+ return result;
+ }
+};
+#endif // defined(OS_WIN)
+
+template <>
+struct ParamTraits<SkBitmap> {
+ typedef SkBitmap param_type;
+ static void Write(Message* m, const param_type& p);
+
+ // Note: This function expects parameter |r| to be of type &SkBitmap since
+ // r->SetConfig() and r->SetPixels() are called.
+ static bool Read(const Message* m, void** iter, param_type* r);
+
+ static void Log(const param_type& p, std::wstring* l);
+};
+
+template <>
+struct ParamTraits<std::string> {
+ typedef std::string param_type;
+ static void Write(Message* m, const param_type& p) {
+ m->WriteString(p);
+ }
+ static bool Read(const Message* m, void** iter, param_type* r) {
+ return m->ReadString(iter, r);
+ }
+ static void Log(const param_type& p, std::wstring* l) {
+ l->append(UTF8ToWide(p));
+ }
+};
+
+template <>
+struct ParamTraits<std::vector<unsigned char> > {
+ typedef std::vector<unsigned char> param_type;
+ static void Write(Message* m, const param_type& p) {
+ if (p.size() == 0) {
+ m->WriteData(NULL, 0);
+ } else {
+ m->WriteData(reinterpret_cast<const char*>(&p.front()),
+ static_cast<int>(p.size()));
+ }
+ }
+ static bool Read(const Message* m, void** iter, param_type* r) {
+ const char *data;
+ int data_size = 0;
+ if (!m->ReadData(iter, &data, &data_size) || data_size < 0)
+ return false;
+ r->resize(data_size);
+ if (data_size)
+ memcpy(&r->front(), data, data_size);
+ return true;
+ }
+ static void Log(const param_type& p, std::wstring* l) {
+ for (size_t i = 0; i < p.size(); ++i)
+ l->push_back(p[i]);
+ }
+};
+
+template <>
+struct ParamTraits<std::vector<char> > {
+ typedef std::vector<char> param_type;
+ static void Write(Message* m, const param_type& p) {
+ if (p.size() == 0) {
+ m->WriteData(NULL, 0);
+ } else {
+ m->WriteData(&p.front(), static_cast<int>(p.size()));
+ }
+ }
+ static bool Read(const Message* m, void** iter, param_type* r) {
+ const char *data;
+ int data_size = 0;
+ if (!m->ReadData(iter, &data, &data_size) || data_size < 0)
+ return false;
+ r->resize(data_size);
+ if (data_size)
+ memcpy(&r->front(), data, data_size);
+ return true;
+ }
+ static void Log(const param_type& p, std::wstring* l) {
+ for (size_t i = 0; i < p.size(); ++i)
+ l->push_back(p[i]);
+ }
+};
+
+template <class P>
+struct ParamTraits<std::vector<P> > {
+ typedef std::vector<P> param_type;
+ static void Write(Message* m, const param_type& p) {
+ WriteParam(m, static_cast<int>(p.size()));
+ for (size_t i = 0; i < p.size(); i++)
+ WriteParam(m, p[i]);
+ }
+ static bool Read(const Message* m, void** iter, param_type* r) {
+ int size;
+ if (!m->ReadLength(iter, &size))
+ return false;
+ // Resizing beforehand is not safe, see BUG 1006367 for details.
+ if (m->IteratorHasRoomFor(*iter, size * sizeof(P))) {
+ r->resize(size);
+ for (int i = 0; i < size; i++) {
+ if (!ReadParam(m, iter, &(*r)[i]))
+ return false;
+ }
+ } else {
+ for (int i = 0; i < size; i++) {
+ P element;
+ if (!ReadParam(m, iter, &element))
+ return false;
+ r->push_back(element);
+ }
+ }
+ return true;
+ }
+ static void Log(const param_type& p, std::wstring* l) {
+ for (size_t i = 0; i < p.size(); ++i) {
+ if (i != 0)
+ l->append(L" ");
+
+ LogParam((p[i]), l);
+ }
+ }
+};
+
+template <class K, class V>
+struct ParamTraits<std::map<K, V> > {
+ typedef std::map<K, V> param_type;
+ static void Write(Message* m, const param_type& p) {
+ WriteParam(m, static_cast<int>(p.size()));
+ typename param_type::const_iterator iter;
+ for (iter = p.begin(); iter != p.end(); ++iter) {
+ WriteParam(m, iter->first);
+ WriteParam(m, iter->second);
+ }
+ }
+ static bool Read(const Message* m, void** iter, param_type* r) {
+ int size;
+ if (!ReadParam(m, iter, &size) || size < 0)
+ return false;
+ for (int i = 0; i < size; ++i) {
+ K k;
+ if (!ReadParam(m, iter, &k))
+ return false;
+ V& value = (*r)[k];
+ if (!ReadParam(m, iter, &value))
+ return false;
+ }
+ return true;
+ }
+ static void Log(const param_type& p, std::wstring* l) {
+ l->append(L"<std::map>");
+ }
+};
+
+template <>
+struct ParamTraits<std::wstring> {
+ typedef std::wstring param_type;
+ static void Write(Message* m, const param_type& p) {
+ m->WriteWString(p);
+ }
+ static bool Read(const Message* m, void** iter, param_type* r) {
+ return m->ReadWString(iter, r);
+ }
+ static void Log(const param_type& p, std::wstring* l) {
+ l->append(p);
+ }
+};
+
+template <>
+struct ParamTraits<GURL> {
+ typedef GURL param_type;
+ static void Write(Message* m, const param_type& p);
+ static bool Read(const Message* m, void** iter, param_type* p);
+ static void Log(const param_type& p, std::wstring* l);
+};
+
+// and, a few more useful types...
+#if defined(OS_WIN)
+template <>
+struct ParamTraits<HANDLE> {
+ typedef HANDLE param_type;
+ static void Write(Message* m, const param_type& p) {
+ m->WriteIntPtr(reinterpret_cast<intptr_t>(p));
+ }
+ static bool Read(const Message* m, void** iter, param_type* r) {
+ DCHECK_EQ(sizeof(param_type), sizeof(intptr_t));
+ return m->ReadIntPtr(iter, reinterpret_cast<intptr_t*>(r));
+ }
+ static void Log(const param_type& p, std::wstring* l) {
+ l->append(StringPrintf(L"0x%X", p));
+ }
+};
+
+template <>
+struct ParamTraits<HCURSOR> {
+ typedef HCURSOR param_type;
+ static void Write(Message* m, const param_type& p) {
+ m->WriteIntPtr(reinterpret_cast<intptr_t>(p));
+ }
+ static bool Read(const Message* m, void** iter, param_type* r) {
+ DCHECK_EQ(sizeof(param_type), sizeof(intptr_t));
+ return m->ReadIntPtr(iter, reinterpret_cast<intptr_t*>(r));
+ }
+ static void Log(const param_type& p, std::wstring* l) {
+ l->append(StringPrintf(L"0x%X", p));
+ }
+};
+
+template <>
+struct ParamTraits<HWND> {
+ typedef HWND param_type;
+ static void Write(Message* m, const param_type& p) {
+ m->WriteIntPtr(reinterpret_cast<intptr_t>(p));
+ }
+ static bool Read(const Message* m, void** iter, param_type* r) {
+ DCHECK_EQ(sizeof(param_type), sizeof(intptr_t));
+ return m->ReadIntPtr(iter, reinterpret_cast<intptr_t*>(r));
+ }
+ static void Log(const param_type& p, std::wstring* l) {
+ l->append(StringPrintf(L"0x%X", p));
+ }
+};
+
+template <>
+struct ParamTraits<HRGN> {
+ typedef HRGN param_type;
+ static void Write(Message* m, const param_type& p) {
+ int data_size = GetRegionData(p, 0, NULL);
+ if (data_size) {
+ char* bytes = new char[data_size];
+ GetRegionData(p, data_size, reinterpret_cast<LPRGNDATA>(bytes));
+ m->WriteData(reinterpret_cast<const char*>(bytes), data_size);
+ delete [] bytes;
+ } else {
+ m->WriteData(NULL, 0);
+ }
+ }
+ static bool Read(const Message* m, void** iter, param_type* r) {
+ bool res = FALSE;
+ const char *data;
+ int data_size = 0;
+ res = m->ReadData(iter, &data, &data_size);
+ if (data_size) {
+ *r = ExtCreateRegion(NULL, data_size,
+ reinterpret_cast<CONST RGNDATA*>(data));
+ } else {
+ res = TRUE;
+ *r = CreateRectRgn(0, 0, 0, 0);
+ }
+ return res;
+ }
+ static void Log(const param_type& p, std::wstring* l) {
+ l->append(StringPrintf(L"0x%X", p));
+ }
+};
+
+template <>
+struct ParamTraits<HACCEL> {
+ typedef HACCEL param_type;
+ static void Write(Message* m, const param_type& p) {
+ m->WriteIntPtr(reinterpret_cast<intptr_t>(p));
+ }
+ static bool Read(const Message* m, void** iter, param_type* r) {
+ DCHECK_EQ(sizeof(param_type), sizeof(intptr_t));
+ return m->ReadIntPtr(iter, reinterpret_cast<intptr_t*>(r));
+ }
+};
+
+template <>
+struct ParamTraits<POINT> {
+ typedef POINT param_type;
+ static void Write(Message* m, const param_type& p) {
+ m->WriteInt(p.x);
+ m->WriteInt(p.y);
+ }
+ static bool Read(const Message* m, void** iter, param_type* r) {
+ int x, y;
+ if (!m->ReadInt(iter, &x) || !m->ReadInt(iter, &y))
+ return false;
+ r->x = x;
+ r->y = y;
+ return true;
+ }
+ static void Log(const param_type& p, std::wstring* l) {
+ l->append(StringPrintf(L"(%d, %d)", p.x, p.y));
+ }
+};
+#endif // defined(OS_WIN)
+
+template <>
+struct ParamTraits<FilePath> {
+ typedef FilePath param_type;
+ static void Write(Message* m, const param_type& p) {
+ ParamTraits<FilePath::StringType>::Write(m, p.value());
+ }
+ static bool Read(const Message* m, void** iter, param_type* r) {
+ FilePath::StringType value;
+ if (!ParamTraits<FilePath::StringType>::Read(m, iter, &value))
+ return false;
+ *r = FilePath(value);
+ return true;
+ }
+ static void Log(const param_type& p, std::wstring* l) {
+ ParamTraits<FilePath::StringType>::Log(p.value(), l);
+ }
+};
+
+template <>
+struct ParamTraits<gfx::Point> {
+ typedef gfx::Point param_type;
+ static void Write(Message* m, const param_type& p);
+ static bool Read(const Message* m, void** iter, param_type* r);
+ static void Log(const param_type& p, std::wstring* l);
+};
+
+template <>
+struct ParamTraits<gfx::Rect> {
+ typedef gfx::Rect param_type;
+ static void Write(Message* m, const param_type& p);
+ static bool Read(const Message* m, void** iter, param_type* r);
+ static void Log(const param_type& p, std::wstring* l);
+};
+
+template <>
+struct ParamTraits<gfx::Size> {
+ typedef gfx::Size param_type;
+ static void Write(Message* m, const param_type& p);
+ static bool Read(const Message* m, void** iter, param_type* r);
+ static void Log(const param_type& p, std::wstring* l);
+};
+
+template<>
+struct ParamTraits<ThumbnailScore> {
+ typedef ThumbnailScore param_type;
+ static void Write(Message* m, const param_type& p) {
+ IPC::ParamTraits<double>::Write(m, p.boring_score);
+ IPC::ParamTraits<bool>::Write(m, p.good_clipping);
+ IPC::ParamTraits<bool>::Write(m, p.at_top);
+ IPC::ParamTraits<base::Time>::Write(m, p.time_at_snapshot);
+ }
+ static bool Read(const Message* m, void** iter, param_type* r) {
+ double boring_score;
+ bool good_clipping, at_top;
+ base::Time time_at_snapshot;
+ if (!IPC::ParamTraits<double>::Read(m, iter, &boring_score) ||
+ !IPC::ParamTraits<bool>::Read(m, iter, &good_clipping) ||
+ !IPC::ParamTraits<bool>::Read(m, iter, &at_top) ||
+ !IPC::ParamTraits<base::Time>::Read(m, iter, &time_at_snapshot))
+ return false;
+
+ r->boring_score = boring_score;
+ r->good_clipping = good_clipping;
+ r->at_top = at_top;
+ r->time_at_snapshot = time_at_snapshot;
+ return true;
+ }
+ static void Log(const param_type& p, std::wstring* l) {
+ l->append(StringPrintf(L"(%f, %d, %d)",
+ p.boring_score, p.good_clipping, p.at_top));
+ }
+};
+
+template <>
+struct ParamTraits<WindowOpenDisposition> {
+ typedef WindowOpenDisposition param_type;
+ static void Write(Message* m, const param_type& p) {
+ m->WriteInt(p);
+ }
+ static bool Read(const Message* m, void** iter, param_type* r) {
+ int temp;
+ bool res = m->ReadInt(iter, &temp);
+ *r = static_cast<WindowOpenDisposition>(temp);
+ return res;
+ }
+ static void Log(const param_type& p, std::wstring* l) {
+ l->append(StringPrintf(L"%d", p));
+ }
+};
+
+template <>
+struct ParamTraits<ConsoleMessageLevel> {
+ typedef ConsoleMessageLevel param_type;
+ static void Write(Message* m, const param_type& p) {
+ m->WriteInt(p);
+ }
+ static bool Read(const Message* m, void** iter, param_type* r) {
+ int temp;
+ bool res = m->ReadInt(iter, &temp);
+ *r = static_cast<ConsoleMessageLevel>(temp);
+ return res;
+ }
+ static void Log(const param_type& p, std::wstring* l) {
+ l->append(StringPrintf(L"%d", p));
+ }
+};
+
+template <>
+struct ParamTraits<CacheManager::ResourceTypeStat> {
+ typedef CacheManager::ResourceTypeStat param_type;
+ static void Write(Message* m, const param_type& p) {
+ WriteParam(m, p.count);
+ WriteParam(m, p.size);
+ WriteParam(m, p.live_size);
+ WriteParam(m, p.decoded_size);
+ }
+ static bool Read(const Message* m, void** iter, param_type* r) {
+ bool result =
+ ReadParam(m, iter, &r->count) &&
+ ReadParam(m, iter, &r->size) &&
+ ReadParam(m, iter, &r->live_size) &&
+ ReadParam(m, iter, &r->decoded_size);
+ return result;
+ }
+ static void Log(const param_type& p, std::wstring* l) {
+ l->append(StringPrintf(L"%d %d %d %d", p.count, p.size, p.live_size,
+ p.decoded_size));
+ }
+};
+
+template <>
+struct ParamTraits<CacheManager::ResourceTypeStats> {
+ typedef CacheManager::ResourceTypeStats param_type;
+ static void Write(Message* m, const param_type& p) {
+ WriteParam(m, p.images);
+ WriteParam(m, p.css_stylesheets);
+ WriteParam(m, p.scripts);
+ WriteParam(m, p.xsl_stylesheets);
+ WriteParam(m, p.fonts);
+ }
+ static bool Read(const Message* m, void** iter, param_type* r) {
+ bool result =
+ ReadParam(m, iter, &r->images) &&
+ ReadParam(m, iter, &r->css_stylesheets) &&
+ ReadParam(m, iter, &r->scripts) &&
+ ReadParam(m, iter, &r->xsl_stylesheets) &&
+ ReadParam(m, iter, &r->fonts);
+ return result;
+ }
+ static void Log(const param_type& p, std::wstring* l) {
+ l->append(L"<WebCoreStats>");
+ LogParam(p.images, l);
+ LogParam(p.css_stylesheets, l);
+ LogParam(p.scripts, l);
+ LogParam(p.xsl_stylesheets, l);
+ LogParam(p.fonts, l);
+ l->append(L"</WebCoreStats>");
+ }
+};
+
+#if defined(OS_WIN)
+template <>
+struct ParamTraits<XFORM> {
+ typedef XFORM param_type;
+ static void Write(Message* m, const param_type& p) {
+ m->WriteData(reinterpret_cast<const char*>(&p), sizeof(XFORM));
+ }
+ static bool Read(const Message* m, void** iter, param_type* r) {
+ const char *data;
+ int data_size = 0;
+ bool result = m->ReadData(iter, &data, &data_size);
+ if (result && data_size == sizeof(XFORM)) {
+ memcpy(r, data, sizeof(XFORM));
+ } else {
+ result = false;
+ NOTREACHED();
+ }
+
+ return result;
+ }
+ static void Log(const param_type& p, std::wstring* l) {
+ l->append(L"<XFORM>");
+ }
+};
+#endif // defined(OS_WIN)
+
+template <>
+struct ParamTraits<WebCursor> {
+ typedef WebCursor param_type;
+ static void Write(Message* m, const param_type& p) {
+ p.Serialize(m);
+ }
+ static bool Read(const Message* m, void** iter, param_type* r) {
+ return r->Deserialize(m, iter);
+ }
+ static void Log(const param_type& p, std::wstring* l) {
+ l->append(L"<WebCursor>");
+ }
+};
+
+struct LogData {
+ std::wstring channel;
+ uint16 type;
+ std::wstring flags;
+ int64 sent; // Time that the message was sent (i.e. at Send()).
+ int64 receive; // Time before it was dispatched (i.e. before calling
+ // OnMessageReceived).
+ int64 dispatch; // Time after it was dispatched (i.e. after calling
+ // OnMessageReceived).
+ std::wstring params;
+};
+
+template <>
+struct ParamTraits<LogData> {
+ typedef LogData param_type;
+ static void Write(Message* m, const param_type& p) {
+ WriteParam(m, p.channel);
+ WriteParam(m, static_cast<int>(p.type));
+ WriteParam(m, p.flags);
+ WriteParam(m, p.sent);
+ WriteParam(m, p.receive);
+ WriteParam(m, p.dispatch);
+ WriteParam(m, p.params);
+ }
+ static bool Read(const Message* m, void** iter, param_type* r) {
+ int type;
+ bool result =
+ ReadParam(m, iter, &r->channel) &&
+ ReadParam(m, iter, &type) &&
+ ReadParam(m, iter, &r->flags) &&
+ ReadParam(m, iter, &r->sent) &&
+ ReadParam(m, iter, &r->receive) &&
+ ReadParam(m, iter, &r->dispatch) &&
+ ReadParam(m, iter, &r->params);
+ r->type = static_cast<uint16>(type);
+ return result;
+ }
+ static void Log(const param_type& p, std::wstring* l) {
+ // Doesn't make sense to implement this!
+ }
+};
+
+template <>
+struct ParamTraits<Tuple0> {
+ typedef Tuple0 param_type;
+ static void Write(Message* m, const param_type& p) {
+ }
+ static bool Read(const Message* m, void** iter, param_type* r) {
+ return true;
+ }
+ static void Log(const param_type& p, std::wstring* l) {
+ }
+};
+
+template <class A>
+struct ParamTraits< Tuple1<A> > {
+ typedef Tuple1<A> param_type;
+ static void Write(Message* m, const param_type& p) {
+ WriteParam(m, p.a);
+ }
+ static bool Read(const Message* m, void** iter, param_type* r) {
+ return ReadParam(m, iter, &r->a);
+ }
+ static void Log(const param_type& p, std::wstring* l) {
+ LogParam(p.a, l);
+ }
+};
+
+template <class A, class B>
+struct ParamTraits< Tuple2<A, B> > {
+ typedef Tuple2<A, B> param_type;
+ static void Write(Message* m, const param_type& p) {
+ WriteParam(m, p.a);
+ WriteParam(m, p.b);
+ }
+ static bool Read(const Message* m, void** iter, param_type* r) {
+ return (ReadParam(m, iter, &r->a) &&
+ ReadParam(m, iter, &r->b));
+ }
+ static void Log(const param_type& p, std::wstring* l) {
+ LogParam(p.a, l);
+ l->append(L", ");
+ LogParam(p.b, l);
+ }
+};
+
+template <class A, class B, class C>
+struct ParamTraits< Tuple3<A, B, C> > {
+ typedef Tuple3<A, B, C> param_type;
+ static void Write(Message* m, const param_type& p) {
+ WriteParam(m, p.a);
+ WriteParam(m, p.b);
+ WriteParam(m, p.c);
+ }
+ static bool Read(const Message* m, void** iter, param_type* r) {
+ return (ReadParam(m, iter, &r->a) &&
+ ReadParam(m, iter, &r->b) &&
+ ReadParam(m, iter, &r->c));
+ }
+ static void Log(const param_type& p, std::wstring* l) {
+ LogParam(p.a, l);
+ l->append(L", ");
+ LogParam(p.b, l);
+ l->append(L", ");
+ LogParam(p.c, l);
+ }
+};
+
+template <class A, class B, class C, class D>
+struct ParamTraits< Tuple4<A, B, C, D> > {
+ typedef Tuple4<A, B, C, D> param_type;
+ static void Write(Message* m, const param_type& p) {
+ WriteParam(m, p.a);
+ WriteParam(m, p.b);
+ WriteParam(m, p.c);
+ WriteParam(m, p.d);
+ }
+ static bool Read(const Message* m, void** iter, param_type* r) {
+ return (ReadParam(m, iter, &r->a) &&
+ ReadParam(m, iter, &r->b) &&
+ ReadParam(m, iter, &r->c) &&
+ ReadParam(m, iter, &r->d));
+ }
+ static void Log(const param_type& p, std::wstring* l) {
+ LogParam(p.a, l);
+ l->append(L", ");
+ LogParam(p.b, l);
+ l->append(L", ");
+ LogParam(p.c, l);
+ l->append(L", ");
+ LogParam(p.d, l);
+ }
+};
+
+template <class A, class B, class C, class D, class E>
+struct ParamTraits< Tuple5<A, B, C, D, E> > {
+ typedef Tuple5<A, B, C, D, E> param_type;
+ static void Write(Message* m, const param_type& p) {
+ WriteParam(m, p.a);
+ WriteParam(m, p.b);
+ WriteParam(m, p.c);
+ WriteParam(m, p.d);
+ WriteParam(m, p.e);
+ }
+ static bool Read(const Message* m, void** iter, param_type* r) {
+ return (ReadParam(m, iter, &r->a) &&
+ ReadParam(m, iter, &r->b) &&
+ ReadParam(m, iter, &r->c) &&
+ ReadParam(m, iter, &r->d) &&
+ ReadParam(m, iter, &r->e));
+ }
+ static void Log(const param_type& p, std::wstring* l) {
+ LogParam(p.a, l);
+ l->append(L", ");
+ LogParam(p.b, l);
+ l->append(L", ");
+ LogParam(p.c, l);
+ l->append(L", ");
+ LogParam(p.d, l);
+ l->append(L", ");
+ LogParam(p.e, l);
+ }
+};
+
+template <class A, class B, class C, class D, class E, class F>
+struct ParamTraits< Tuple6<A, B, C, D, E, F> > {
+ typedef Tuple6<A, B, C, D, E, F> param_type;
+ static void Write(Message* m, const param_type& p) {
+ WriteParam(m, p.a);
+ WriteParam(m, p.b);
+ WriteParam(m, p.c);
+ WriteParam(m, p.d);
+ WriteParam(m, p.e);
+ WriteParam(m, p.f);
+ }
+ static bool Read(const Message* m, void** iter, param_type* r) {
+ return (ReadParam(m, iter, &r->a) &&
+ ReadParam(m, iter, &r->b) &&
+ ReadParam(m, iter, &r->c) &&
+ ReadParam(m, iter, &r->d) &&
+ ReadParam(m, iter, &r->e) &&
+ ReadParam(m, iter, &r->f));
+ }
+ static void Log(const param_type& p, std::wstring* l) {
+ LogParam(p.a, l);
+ l->append(L", ");
+ LogParam(p.b, l);
+ l->append(L", ");
+ LogParam(p.c, l);
+ l->append(L", ");
+ LogParam(p.d, l);
+ l->append(L", ");
+ LogParam(p.e, l);
+ l->append(L", ");
+ LogParam(p.f, l);
+ }
+};
+
+template <>
+struct ParamTraits<webkit_glue::WebApplicationInfo> {
+ typedef webkit_glue::WebApplicationInfo param_type;
+ static void Write(Message* m, const param_type& p);
+ static bool Read(const Message* m, void** iter, param_type* r);
+ static void Log(const param_type& p, std::wstring* l);
+};
+
+
+//-----------------------------------------------------------------------------
// Generic message subclasses
// Used for asynchronous messages.
@@ -1068,7 +1025,7 @@
WriteParam(this, p);
}
- static bool Read(const IPC::Message* msg, Param* p) {
+ static bool Read(const Message* msg, Param* p) {
void* iter = NULL;
bool rv = ReadParam(msg, &iter, p);
DCHECK(rv) << "Error deserializing message " << msg->type();
@@ -1077,7 +1034,7 @@
// Generic dispatcher. Should cover most cases.
template<class T, class Method>
- static bool Dispatch(const IPC::Message* msg, T* obj, Method func) {
+ static bool Dispatch(const Message* msg, T* obj, Method func) {
Param p;
if (Read(msg, &p)) {
DispatchToMethod(obj, func, p);
@@ -1090,7 +1047,7 @@
// needs the message as well. They assume that "Param" is a type of Tuple
// (except the one arg case, as there is no Tuple1).
template<class T, typename TA>
- static bool Dispatch(const IPC::Message* msg, T* obj,
+ static bool Dispatch(const Message* msg, T* obj,
void (T::*func)(const Message&, TA)) {
Param p;
if (Read(msg, &p)) {
@@ -1101,7 +1058,7 @@
}
template<class T, typename TA, typename TB>
- static bool Dispatch(const IPC::Message* msg, T* obj,
+ static bool Dispatch(const Message* msg, T* obj,
void (T::*func)(const Message&, TA, TB)) {
Param p;
if (Read(msg, &p)) {
@@ -1112,7 +1069,7 @@
}
template<class T, typename TA, typename TB, typename TC>
- static bool Dispatch(const IPC::Message* msg, T* obj,
+ static bool Dispatch(const Message* msg, T* obj,
void (T::*func)(const Message&, TA, TB, TC)) {
Param p;
if (Read(msg, &p)) {
@@ -1123,7 +1080,7 @@
}
template<class T, typename TA, typename TB, typename TC, typename TD>
- static bool Dispatch(const IPC::Message* msg, T* obj,
+ static bool Dispatch(const Message* msg, T* obj,
void (T::*func)(const Message&, TA, TB, TC, TD)) {
Param p;
if (Read(msg, &p)) {
@@ -1135,7 +1092,7 @@
template<class T, typename TA, typename TB, typename TC, typename TD,
typename TE>
- static bool Dispatch(const IPC::Message* msg, T* obj,
+ static bool Dispatch(const Message* msg, T* obj,
void (T::*func)(const Message&, TA, TB, TC, TD, TE)) {
Param p;
if (Read(msg, &p)) {
@@ -1145,59 +1102,11 @@
return false;
}
- static void Log(const IPC::Message* msg, std::wstring* l) {
+ static void Log(const Message* msg, std::wstring* l) {
Param p;
if (Read(msg, &p))
LogParam(p, l);
}
-
- // Functions used to do manual unpacking. Only used by the automation code,
- // these should go away once that code uses SyncChannel.
- template<typename TA, typename TB>
- static bool Read(const IPC::Message* msg, TA* a, TB* b) {
- ParamType params;
- if (!Read(msg, ¶ms))
- return false;
- *a = params.a;
- *b = params.b;
- return true;
- }
-
- template<typename TA, typename TB, typename TC>
- static bool Read(const IPC::Message* msg, TA* a, TB* b, TC* c) {
- ParamType params;
- if (!Read(msg, ¶ms))
- return false;
- *a = params.a;
- *b = params.b;
- *c = params.c;
- return true;
- }
-
- template<typename TA, typename TB, typename TC, typename TD>
- static bool Read(const IPC::Message* msg, TA* a, TB* b, TC* c, TD* d) {
- ParamType params;
- if (!Read(msg, ¶ms))
- return false;
- *a = params.a;
- *b = params.b;
- *c = params.c;
- *d = params.d;
- return true;
- }
-
- template<typename TA, typename TB, typename TC, typename TD, typename TE>
- static bool Read(const IPC::Message* msg, TA* a, TB* b, TC* c, TD* d, TE* e) {
- ParamType params;
- if (!Read(msg, ¶ms))
- return false;
- *a = params.a;
- *b = params.b;
- *c = params.c;
- *d = params.d;
- *e = params.e;
- return true;
- }
};
// This class assumes that its template argument is a RefTuple (a Tuple with
@@ -1229,7 +1138,7 @@
WriteParam(this, send);
}
- static void Log(const IPC::Message* msg, std::wstring* l) {
+ static void Log(const Message* msg, std::wstring* l) {
if (msg->is_sync()) {
SendParam p;
void* iter = SyncMessage::GetDataIterator(msg);
@@ -1254,7 +1163,7 @@
}
template<class T, class Method>
- static bool Dispatch(const IPC::Message* msg, T* obj, Method func) {
+ static bool Dispatch(const Message* msg, T* obj, Method func) {
SendParam send_params;
void* iter = GetDataIterator(msg);
Message* reply = GenerateReply(msg);
@@ -1282,7 +1191,7 @@
}
template<class T, class Method>
- static bool DispatchDelayReply(const IPC::Message* msg, T* obj, Method func) {
+ static bool DispatchDelayReply(const Message* msg, T* obj, Method func) {
SendParam send_params;
void* iter = GetDataIterator(msg);
Message* reply = GenerateReply(msg);
@@ -1343,6 +1252,32 @@
}
};
+// Traits for ViewMsg_FindInPageMsg_Request structure to pack/unpack.
+template <>
+struct ParamTraits<FindInPageRequest> {
+ typedef FindInPageRequest param_type;
+ static void Write(Message* m, const param_type& p) {
+ WriteParam(m, p.request_id);
+ WriteParam(m, p.search_string);
+ WriteParam(m, p.forward);
+ WriteParam(m, p.match_case);
+ WriteParam(m, p.find_next);
+ }
+ static bool Read(const Message* m, void** iter, param_type* p) {
+ return
+ ReadParam(m, iter, &p->request_id) &&
+ ReadParam(m, iter, &p->search_string) &&
+ ReadParam(m, iter, &p->forward) &&
+ ReadParam(m, iter, &p->match_case) &&
+ ReadParam(m, iter, &p->find_next);
+ }
+ static void Log(const param_type& p, std::wstring* l) {
+ l->append(L"<FindInPageRequest>");
+ }
+};
+
+//-----------------------------------------------------------------------------
+
} // namespace IPC
#endif // CHROME_COMMON_IPC_MESSAGE_UTILS_H_