diff options
author | maruel@google.com <maruel@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-08-05 21:20:41 +0000 |
---|---|---|
committer | maruel@google.com <maruel@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-08-05 21:20:41 +0000 |
commit | 3178f4e296e24781be5fbcc4ba91815e08c78897 (patch) | |
tree | 5e08c0ac8e8bf73f6bd13c221fad934a1534ceca /chrome/common/ipc_message_utils.h | |
parent | 72c93c7075cc4b68c3e013be1aeeb3d0c9671873 (diff) | |
download | chromium_src-3178f4e296e24781be5fbcc4ba91815e08c78897.zip chromium_src-3178f4e296e24781be5fbcc4ba91815e08c78897.tar.gz chromium_src-3178f4e296e24781be5fbcc4ba91815e08c78897.tar.bz2 |
Reapply 379 since it wasn't the issue with the build breakage.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@393 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common/ipc_message_utils.h')
-rw-r--r-- | chrome/common/ipc_message_utils.h | 216 |
1 files changed, 34 insertions, 182 deletions
diff --git a/chrome/common/ipc_message_utils.h b/chrome/common/ipc_message_utils.h index 7599b4fb..263a877 100644 --- a/chrome/common/ipc_message_utils.h +++ b/chrome/common/ipc_message_utils.h @@ -34,23 +34,28 @@ #include <vector> #include <map> -#include "base/basictypes.h" -#include "base/gfx/rect.h" -#include "base/gfx/size.h" -#include "base/logging.h" #include "base/string_util.h" -#include "base/time.h" #include "base/tuple.h" -#include "chrome/common/ipc_message.h" #include "chrome/common/ipc_sync_message.h" #include "chrome/common/thumbnail_score.h" -#include "googleurl/src/gurl.h" #include "skia/include/SkBitmap.h" #include "webkit/glue/cache_manager.h" #include "webkit/glue/console_message_level.h" -#include "webkit/glue/dom_operations.h" #include "webkit/glue/window_open_disposition.h" -#include "webkit/glue/webcursor.h" + +// Forward declarations. +class GURL; +class WebCursor; + +namespace gfx { +class Point; +class Rect; +class Size; +} // namespace gfx + +namespace webkit_glue { +struct WebApplicationInfo; +} // namespace webkit_glue namespace IPC { @@ -556,22 +561,9 @@ struct ParamTraits<std::wstring> { template <> struct ParamTraits<GURL> { typedef GURL param_type; - static void Write(Message* m, const param_type& p) { - m->WriteString(p.possibly_invalid_spec()); - // TODO(brettw) bug 684583: Add encoding for query params. - } - static bool Read(const Message* m, void** iter, param_type* p) { - std::string s; - if (!m->ReadString(iter, &s)) { - *p = GURL(); - return false; - } - *p = GURL(s); - return true; - } - static void Log(const param_type& p, std::wstring* l) { - l->append(UTF8ToWide(p.spec())); - } + 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... @@ -688,70 +680,25 @@ struct ParamTraits<POINT> { template <> struct ParamTraits<gfx::Point> { typedef gfx::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->set_x(x); - r->set_y(y); - return true; - } - static void Log(const param_type& p, std::wstring* l) { - l->append(StringPrintf(L"(%d, %d)", p.x(), p.y())); - } + 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) { - m->WriteInt(p.x()); - m->WriteInt(p.y()); - m->WriteInt(p.width()); - m->WriteInt(p.height()); - } - static bool Read(const Message* m, void** iter, param_type* r) { - int x, y, w, h; - if (!m->ReadInt(iter, &x) || - !m->ReadInt(iter, &y) || - !m->ReadInt(iter, &w) || - !m->ReadInt(iter, &h)) - return false; - r->set_x(x); - r->set_y(y); - r->set_width(w); - r->set_height(h); - return true; - } - static void Log(const param_type& p, std::wstring* l) { - l->append(StringPrintf(L"(%d, %d, %d, %d)", p.x(), p.y(), p.width(), p.height())); - } + 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) { - m->WriteInt(p.width()); - m->WriteInt(p.height()); - } - static bool Read(const Message* m, void** iter, param_type* r) { - int w, h; - if (!m->ReadInt(iter, &w) || - !m->ReadInt(iter, &h)) - return false; - r->set_width(w); - r->set_height(h); - return true; - } - static void Log(const param_type& p, std::wstring* l) { - l->append(StringPrintf(L"(%d, %d)", p.width(), p.height())); - } + 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<> @@ -896,78 +843,12 @@ struct ParamTraits<XFORM> { } }; -struct WebCursor_Data { - WebCursor::Type cursor_type; - int hotspot_x; - int hotspot_y; - SkBitmap_Data bitmap_info; -}; - template <> struct ParamTraits<WebCursor> { typedef WebCursor param_type; - static void Write(Message* m, const param_type& p) { - const SkBitmap& src_bitmap = p.bitmap(); - WebCursor_Data web_cursor_info; - web_cursor_info.cursor_type = p.type(); - web_cursor_info.hotspot_x = p.hotspot_x(); - web_cursor_info.hotspot_y = p.hotspot_y(); - web_cursor_info.bitmap_info.InitSkBitmapDataForTransfer(src_bitmap); - - size_t fixed_data = sizeof(web_cursor_info); - m->WriteData(reinterpret_cast<const char*>(&web_cursor_info), - static_cast<int>(fixed_data)); - size_t pixel_size = src_bitmap.getSize(); - m->WriteBool(pixel_size != 0); - if (pixel_size) { - SkAutoLockPixels src_bitmap_lock(src_bitmap); - m->WriteData(reinterpret_cast<const char*>(src_bitmap.getPixels()), - static_cast<int>(pixel_size)); - } - } - static bool Read(const Message* m, void** iter, param_type* r) { - const char* fixed_data = NULL; - int fixed_data_size = 0; - if (!m->ReadData(iter, &fixed_data, &fixed_data_size) || - (fixed_data_size <= 0)) { - NOTREACHED(); - return false; - } - DCHECK(fixed_data_size == sizeof(WebCursor_Data)); - - const WebCursor_Data* web_cursor_info = - reinterpret_cast<const WebCursor_Data*>(fixed_data); - - bool variable_data_avail; - if (!m->ReadBool(iter, &variable_data_avail)) { - NOTREACHED(); - return false; - } - - // No variable data indicates that this is not a custom cursor. - if (variable_data_avail) { - const char* variable_data = NULL; - int variable_data_size = 0; - if (!m->ReadData(iter, &variable_data, &variable_data_size) || - variable_data_size <= 0) { - NOTREACHED(); - return false; - } - - SkBitmap dest_bitmap; - web_cursor_info->bitmap_info.InitSkBitmapFromData(&dest_bitmap, - variable_data, - variable_data_size); - r->set_bitmap(dest_bitmap); - r->set_hotspot(web_cursor_info->hotspot_x, web_cursor_info->hotspot_y); - } - - r->set_type(web_cursor_info->cursor_type); - return true; - } - static void Log(const param_type& p, std::wstring* l) { - l->append(L"<WebCursor>"); - } + 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); }; struct LogData { @@ -1135,39 +1016,9 @@ struct ParamTraits< Tuple5<A, B, C, D, E> > { template <> struct ParamTraits<webkit_glue::WebApplicationInfo> { typedef webkit_glue::WebApplicationInfo param_type; - static void Write(Message* m, const param_type& p) { - WriteParam(m, p.title); - WriteParam(m, p.description); - WriteParam(m, p.app_url); - WriteParam(m, p.icons.size()); - for (size_t i = 0; i < p.icons.size(); ++i) { - WriteParam(m, p.icons[i].url); - WriteParam(m, p.icons[i].width); - WriteParam(m, p.icons[i].height); - } - } - static bool Read(const Message* m, void** iter, param_type* r) { - size_t icon_count; - bool result = - ReadParam(m, iter, &r->title) && - ReadParam(m, iter, &r->description) && - ReadParam(m, iter, &r->app_url) && - ReadParam(m, iter, &icon_count); - if (!result) - return false; - for (size_t i = 0; i < icon_count && result; ++i) { - param_type::IconInfo icon_info; - result = - ReadParam(m, iter, &icon_info.url) && - ReadParam(m, iter, &icon_info.width) && - ReadParam(m, iter, &icon_info.height); - r->icons.push_back(icon_info); - } - return result; - } - static void Log(const param_type& p, std::wstring* l) { - l->append(L"<WebApplicationInfo>"); - } + 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); }; @@ -1409,6 +1260,7 @@ class MessageWithReply : public SyncMessage { }; //----------------------------------------------------------------------------- -} + +} // namespace IPC #endif // CHROME_COMMON_IPC_MESSAGE_UTILS_H__ |