diff options
Diffstat (limited to 'chrome/common/ipc_message_utils.h')
-rw-r--r-- | chrome/common/ipc_message_utils.h | 447 |
1 files changed, 191 insertions, 256 deletions
diff --git a/chrome/common/ipc_message_utils.h b/chrome/common/ipc_message_utils.h index 35146ee..39bb231 100644 --- a/chrome/common/ipc_message_utils.h +++ b/chrome/common/ipc_message_utils.h @@ -34,30 +34,57 @@ namespace webkit_glue { 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 -}; +namespace IPC { + +// 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); + + +//----------------------------------------------------------------------------- +// An iterator class for reading the fields contained within a Message. -COMPILE_ASSERT(LastMsgIndex <= 16, need_to_update_IPC_MESSAGE_MACRO); +class MessageIterator { + public: + explicit MessageIterator(const Message& m) : msg_(m), iter_(NULL) { + } + int NextInt() const { + int val; + if (!msg_.ReadInt(&iter_, &val)) + NOTREACHED(); + return val; + } + intptr_t NextIntPtr() const { + intptr_t val; + if (!msg_.ReadIntPtr(&iter_, &val)) + NOTREACHED(); + return val; + } + const std::string NextString() const { + std::string val; + if (!msg_.ReadString(&iter_, &val)) + NOTREACHED(); + return val; + } + const std::wstring NextWString() const { + std::wstring val; + if (!msg_.ReadWString(&iter_, &val)) + NOTREACHED(); + return val; + } + const void NextData(const char** data, int* length) const { + if (!msg_.ReadData(&iter_, data, length)) { + NOTREACHED(); + } + } + private: + const Message& msg_; + mutable void* iter_; +}; //----------------------------------------------------------------------------- // ParamTraits specializations, etc. @@ -65,12 +92,12 @@ COMPILE_ASSERT(LastMsgIndex <= 16, need_to_update_IPC_MESSAGE_MACRO); template <class P> struct ParamTraits {}; template <class P> -static inline void WriteParam(IPC::Message* m, const P& p) { +static inline void WriteParam(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) { +static inline bool ReadParam(const Message* m, void** iter, P* p) { return ParamTraits<P>::Read(m, iter, p); } @@ -82,10 +109,10 @@ static inline void LogParam(const P& p, std::wstring* l) { template <> struct ParamTraits<bool> { typedef bool param_type; - static void Write(IPC::Message* m, const param_type& p) { + static void Write(Message* m, const param_type& p) { m->WriteBool(p); } - static bool Read(const IPC::Message* m, void** iter, param_type* r) { + 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) { @@ -96,10 +123,10 @@ struct ParamTraits<bool> { template <> struct ParamTraits<int> { typedef int param_type; - static void Write(IPC::Message* m, const param_type& p) { + static void Write(Message* m, const param_type& p) { m->WriteInt(p); } - static bool Read(const IPC::Message* m, void** iter, param_type* r) { + 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) { @@ -110,10 +137,10 @@ struct ParamTraits<int> { template <> struct ParamTraits<long> { typedef long param_type; - static void Write(IPC::Message* m, const param_type& p) { + static void Write(Message* m, const param_type& p) { m->WriteLong(p); } - static bool Read(const IPC::Message* m, void** iter, param_type* r) { + 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) { @@ -124,10 +151,10 @@ struct ParamTraits<long> { template <> struct ParamTraits<size_t> { typedef size_t param_type; - static void Write(IPC::Message* m, const param_type& p) { + static void Write(Message* m, const param_type& p) { m->WriteSize(p); } - static bool Read(const IPC::Message* m, void** iter, param_type* r) { + 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) { @@ -141,10 +168,10 @@ struct ParamTraits<size_t> { template <> struct ParamTraits<uint32> { typedef uint32 param_type; - static void Write(IPC::Message* m, const param_type& p) { + static void Write(Message* m, const param_type& p) { m->WriteUInt32(p); } - static bool Read(const IPC::Message* m, void** iter, param_type* r) { + 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) { @@ -156,10 +183,10 @@ struct ParamTraits<uint32> { template <> struct ParamTraits<int64> { typedef int64 param_type; - static void Write(IPC::Message* m, const param_type& p) { + static void Write(Message* m, const param_type& p) { m->WriteInt64(p); } - static bool Read(const IPC::Message* m, void** iter, param_type* r) { + 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) { @@ -170,10 +197,10 @@ struct ParamTraits<int64> { template <> struct ParamTraits<uint64> { typedef uint64 param_type; - static void Write(IPC::Message* m, const param_type& p) { + static void Write(Message* m, const param_type& p) { m->WriteInt64(static_cast<int64>(p)); } - static bool Read(const IPC::Message* m, void** iter, param_type* r) { + 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) { @@ -184,10 +211,10 @@ struct ParamTraits<uint64> { template <> struct ParamTraits<double> { typedef double param_type; - static void Write(IPC::Message* m, const param_type& p) { + static void Write(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) { + 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); @@ -208,10 +235,10 @@ struct ParamTraits<double> { template <> struct ParamTraits<wchar_t> { typedef wchar_t param_type; - static void Write(IPC::Message* m, const param_type& p) { + static void Write(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) { + 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); @@ -232,10 +259,10 @@ struct ParamTraits<wchar_t> { template <> struct ParamTraits<base::Time> { typedef base::Time param_type; - static void Write(IPC::Message* m, const param_type& p) { + static void Write(Message* m, const param_type& p) { ParamTraits<int64>::Write(m, p.ToInternalValue()); } - static bool Read(const IPC::Message* m, void** iter, param_type* r) { + static bool Read(const Message* m, void** iter, param_type* r) { int64 value; if (!ParamTraits<int64>::Read(m, iter, &value)) return false; @@ -251,10 +278,10 @@ struct ParamTraits<base::Time> { template <> struct ParamTraits<LOGFONT> { typedef LOGFONT param_type; - static void Write(IPC::Message* m, const param_type& p) { + static void Write(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) { + 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); @@ -275,10 +302,10 @@ struct ParamTraits<LOGFONT> { template <> struct ParamTraits<MSG> { typedef MSG param_type; - static void Write(IPC::Message* m, const param_type& p) { + static void Write(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) { + 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); @@ -297,11 +324,11 @@ struct ParamTraits<MSG> { template <> struct ParamTraits<SkBitmap> { typedef SkBitmap param_type; - static void Write(IPC::Message* m, const param_type& p); + 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 IPC::Message* m, void** iter, param_type* r); + static bool Read(const Message* m, void** iter, param_type* r); static void Log(const param_type& p, std::wstring* l); }; @@ -309,10 +336,10 @@ struct ParamTraits<SkBitmap> { template <> struct ParamTraits<std::string> { typedef std::string param_type; - static void Write(IPC::Message* m, const param_type& p) { + static void Write(Message* m, const param_type& p) { m->WriteString(p); } - static bool Read(const IPC::Message* m, void** iter, param_type* r) { + 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) { @@ -323,7 +350,7 @@ struct ParamTraits<std::string> { template <> struct ParamTraits<std::vector<unsigned char> > { typedef std::vector<unsigned char> param_type; - static void Write(IPC::Message* m, const param_type& p) { + static void Write(Message* m, const param_type& p) { if (p.size() == 0) { m->WriteData(NULL, 0); } else { @@ -331,7 +358,7 @@ struct ParamTraits<std::vector<unsigned char> > { static_cast<int>(p.size())); } } - static bool Read(const IPC::Message* m, void** iter, param_type* r) { + 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) @@ -350,14 +377,14 @@ struct ParamTraits<std::vector<unsigned char> > { template <> struct ParamTraits<std::vector<char> > { typedef std::vector<char> param_type; - static void Write(IPC::Message* m, const param_type& p) { + 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 IPC::Message* m, void** iter, param_type* r) { + 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) @@ -376,12 +403,12 @@ struct ParamTraits<std::vector<char> > { template <class P> struct ParamTraits<std::vector<P> > { typedef std::vector<P> param_type; - static void Write(IPC::Message* m, const param_type& p) { + 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 IPC::Message* m, void** iter, param_type* r) { + static bool Read(const Message* m, void** iter, param_type* r) { int size; if (!m->ReadLength(iter, &size)) return false; @@ -415,7 +442,7 @@ struct ParamTraits<std::vector<P> > { 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) { + 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) { @@ -423,7 +450,7 @@ struct ParamTraits<std::map<K, V> > { WriteParam(m, iter->second); } } - static bool Read(const IPC::Message* m, void** iter, param_type* r) { + static bool Read(const Message* m, void** iter, param_type* r) { int size; if (!ReadParam(m, iter, &size) || size < 0) return false; @@ -445,10 +472,10 @@ struct ParamTraits<std::map<K, V> > { template <> struct ParamTraits<std::wstring> { typedef std::wstring param_type; - static void Write(IPC::Message* m, const param_type& p) { + static void Write(Message* m, const param_type& p) { m->WriteWString(p); } - static bool Read(const IPC::Message* m, void** iter, param_type* r) { + 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) { @@ -459,8 +486,8 @@ struct ParamTraits<std::wstring> { 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 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); }; @@ -469,10 +496,10 @@ struct ParamTraits<GURL> { template <> struct ParamTraits<HANDLE> { typedef HANDLE param_type; - static void Write(IPC::Message* m, const param_type& p) { + static void Write(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) { + 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)); } @@ -484,10 +511,10 @@ struct ParamTraits<HANDLE> { template <> struct ParamTraits<HCURSOR> { typedef HCURSOR param_type; - static void Write(IPC::Message* m, const param_type& p) { + static void Write(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) { + 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)); } @@ -499,10 +526,10 @@ struct ParamTraits<HCURSOR> { template <> struct ParamTraits<HWND> { typedef HWND param_type; - static void Write(IPC::Message* m, const param_type& p) { + static void Write(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) { + 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)); } @@ -514,7 +541,7 @@ struct ParamTraits<HWND> { template <> struct ParamTraits<HRGN> { typedef HRGN param_type; - static void Write(IPC::Message* m, const param_type& p) { + 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]; @@ -525,7 +552,7 @@ struct ParamTraits<HRGN> { m->WriteData(NULL, 0); } } - static bool Read(const IPC::Message* m, void** iter, param_type* r) { + static bool Read(const Message* m, void** iter, param_type* r) { bool res = FALSE; const char *data; int data_size = 0; @@ -547,10 +574,10 @@ struct ParamTraits<HRGN> { template <> struct ParamTraits<HACCEL> { typedef HACCEL param_type; - static void Write(IPC::Message* m, const param_type& p) { + static void Write(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) { + 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)); } @@ -559,11 +586,11 @@ struct ParamTraits<HACCEL> { template <> struct ParamTraits<POINT> { typedef POINT param_type; - static void Write(IPC::Message* m, const param_type& p) { + static void Write(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) { + 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; @@ -580,10 +607,10 @@ struct ParamTraits<POINT> { template <> struct ParamTraits<FilePath> { typedef FilePath param_type; - static void Write(IPC::Message* m, const param_type& p) { + static void Write(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) { + static bool Read(const Message* m, void** iter, param_type* r) { FilePath::StringType value; if (!ParamTraits<FilePath::StringType>::Read(m, iter, &value)) return false; @@ -598,44 +625,44 @@ struct ParamTraits<FilePath> { 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 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(IPC::Message* m, const param_type& p); - static bool Read(const IPC::Message* m, void** iter, param_type* r); + 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(IPC::Message* m, const param_type& p); - static bool Read(const IPC::Message* m, void** iter, param_type* r); + 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(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 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 IPC::Message* m, void** iter, param_type* r) { + 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 (!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)) + 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; @@ -653,10 +680,10 @@ struct ParamTraits<ThumbnailScore> { template <> struct ParamTraits<WindowOpenDisposition> { typedef WindowOpenDisposition param_type; - static void Write(IPC::Message* m, const param_type& p) { + static void Write(Message* m, const param_type& p) { m->WriteInt(p); } - static bool Read(const IPC::Message* m, void** iter, param_type* r) { + static bool Read(const Message* m, void** iter, param_type* r) { int temp; bool res = m->ReadInt(iter, &temp); *r = static_cast<WindowOpenDisposition>(temp); @@ -670,10 +697,10 @@ struct ParamTraits<WindowOpenDisposition> { template <> struct ParamTraits<ConsoleMessageLevel> { typedef ConsoleMessageLevel param_type; - static void Write(IPC::Message* m, const param_type& p) { + static void Write(Message* m, const param_type& p) { m->WriteInt(p); } - static bool Read(const IPC::Message* m, void** iter, param_type* r) { + static bool Read(const Message* m, void** iter, param_type* r) { int temp; bool res = m->ReadInt(iter, &temp); *r = static_cast<ConsoleMessageLevel>(temp); @@ -687,13 +714,13 @@ struct ParamTraits<ConsoleMessageLevel> { template <> struct ParamTraits<CacheManager::ResourceTypeStat> { typedef CacheManager::ResourceTypeStat param_type; - static void Write(IPC::Message* m, const param_type& p) { + 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 IPC::Message* m, void** iter, param_type* r) { + static bool Read(const Message* m, void** iter, param_type* r) { bool result = ReadParam(m, iter, &r->count) && ReadParam(m, iter, &r->size) && @@ -710,14 +737,14 @@ struct ParamTraits<CacheManager::ResourceTypeStat> { template <> struct ParamTraits<CacheManager::ResourceTypeStats> { typedef CacheManager::ResourceTypeStats param_type; - static void Write(IPC::Message* m, const param_type& p) { + 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 IPC::Message* m, void** iter, param_type* r) { + static bool Read(const Message* m, void** iter, param_type* r) { bool result = ReadParam(m, iter, &r->images) && ReadParam(m, iter, &r->css_stylesheets) && @@ -741,10 +768,10 @@ struct ParamTraits<CacheManager::ResourceTypeStats> { template <> struct ParamTraits<XFORM> { typedef XFORM param_type; - static void Write(IPC::Message* m, const param_type& p) { + static void Write(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) { + 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); @@ -766,10 +793,10 @@ struct ParamTraits<XFORM> { template <> struct ParamTraits<WebCursor> { typedef WebCursor param_type; - static void Write(IPC::Message* m, const param_type& p) { + static void Write(Message* m, const param_type& p) { p.Serialize(m); } - static bool Read(const IPC::Message* m, void** iter, param_type* r) { + 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) { @@ -777,8 +804,6 @@ struct ParamTraits<WebCursor> { } }; -namespace IPC { - struct LogData { std::wstring channel; uint16 type; @@ -791,12 +816,10 @@ struct LogData { std::wstring params; }; -} - template <> -struct ParamTraits<IPC::LogData> { - typedef IPC::LogData param_type; - static void Write(IPC::Message* m, const param_type& p) { +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); @@ -805,7 +828,7 @@ struct ParamTraits<IPC::LogData> { WriteParam(m, p.dispatch); WriteParam(m, p.params); } - static bool Read(const IPC::Message* m, void** iter, param_type* r) { + static bool Read(const Message* m, void** iter, param_type* r) { int type; bool result = ReadParam(m, iter, &r->channel) && @@ -826,9 +849,9 @@ struct ParamTraits<IPC::LogData> { template <> struct ParamTraits<Tuple0> { typedef Tuple0 param_type; - static void Write(IPC::Message* m, const param_type& p) { + static void Write(Message* m, const param_type& p) { } - static bool Read(const IPC::Message* m, void** iter, param_type* r) { + static bool Read(const Message* m, void** iter, param_type* r) { return true; } static void Log(const param_type& p, std::wstring* l) { @@ -838,10 +861,10 @@ struct ParamTraits<Tuple0> { template <class A> struct ParamTraits< Tuple1<A> > { typedef Tuple1<A> param_type; - static void Write(IPC::Message* m, const param_type& p) { + static void Write(Message* m, const param_type& p) { WriteParam(m, p.a); } - static bool Read(const IPC::Message* m, void** iter, param_type* r) { + 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) { @@ -852,11 +875,11 @@ struct ParamTraits< Tuple1<A> > { 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) { + static void Write(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) { + static bool Read(const Message* m, void** iter, param_type* r) { return (ReadParam(m, iter, &r->a) && ReadParam(m, iter, &r->b)); } @@ -870,12 +893,12 @@ struct ParamTraits< Tuple2<A, B> > { 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) { + 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 IPC::Message* m, void** iter, param_type* r) { + 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)); @@ -892,13 +915,13 @@ struct ParamTraits< Tuple3<A, B, C> > { 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) { + 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 IPC::Message* m, void** iter, param_type* r) { + 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) && @@ -918,14 +941,14 @@ struct ParamTraits< Tuple4<A, B, C, D> > { 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) { + 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 IPC::Message* m, void** iter, param_type* r) { + 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) && @@ -948,7 +971,7 @@ struct ParamTraits< Tuple5<A, B, C, D, E> > { 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) { + static void Write(Message* m, const param_type& p) { WriteParam(m, p.a); WriteParam(m, p.b); WriteParam(m, p.c); @@ -956,7 +979,7 @@ struct ParamTraits< Tuple6<A, B, C, D, E, F> > { WriteParam(m, p.e); WriteParam(m, p.f); } - static bool Read(const IPC::Message* m, void** iter, param_type* r) { + 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) && @@ -982,77 +1005,11 @@ struct ParamTraits< Tuple6<A, B, C, D, E, F> > { 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 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); }; -// 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. - -class MessageIterator { - public: - explicit MessageIterator(const Message& m) : msg_(m), iter_(NULL) { - } - int NextInt() const { - int val; - if (!msg_.ReadInt(&iter_, &val)) - NOTREACHED(); - return val; - } - intptr_t NextIntPtr() const { - intptr_t val; - if (!msg_.ReadIntPtr(&iter_, &val)) - NOTREACHED(); - return val; - } - const std::string NextString() const { - std::string val; - if (!msg_.ReadString(&iter_, &val)) - NOTREACHED(); - return val; - } - const std::wstring NextWString() const { - std::wstring val; - if (!msg_.ReadWString(&iter_, &val)) - NOTREACHED(); - return val; - } - const void NextData(const char** data, int* length) const { - if (!msg_.ReadData(&iter_, data, length)) { - NOTREACHED(); - } - } - private: - const Message& msg_; - mutable void* iter_; -}; //----------------------------------------------------------------------------- // Generic message subclasses @@ -1068,7 +1025,7 @@ class MessageWithTuple : public Message { 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 @@ class MessageWithTuple : public Message { // 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 @@ class MessageWithTuple : public Message { // 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 @@ class MessageWithTuple : public Message { } 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 @@ class MessageWithTuple : public Message { } 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 @@ class MessageWithTuple : public Message { } 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 @@ class MessageWithTuple : public Message { 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 @@ class MessageWithTuple : public Message { 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 @@ class MessageWithReply : public SyncMessage { 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 @@ class MessageWithReply : public SyncMessage { } 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 @@ class MessageWithReply : public SyncMessage { } 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 @@ class MessageWithReply : public SyncMessage { } }; +// 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_ |