summaryrefslogtreecommitdiffstats
path: root/chrome/common/common_message_utils.cc
diff options
context:
space:
mode:
authoragl@chromium.org <agl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-03 02:19:49 +0000
committeragl@chromium.org <agl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-03 02:19:49 +0000
commit8cf3f1dae79db8cfbf9dc6b75c140eabad918a6e (patch)
tree89e93505cc275c0a22b5ca7d95c5f03cfacff6a1 /chrome/common/common_message_utils.cc
parent343b7211ff31670cded0f85fa8a056fa6cf7a9f3 (diff)
downloadchromium_src-8cf3f1dae79db8cfbf9dc6b75c140eabad918a6e.zip
chromium_src-8cf3f1dae79db8cfbf9dc6b75c140eabad918a6e.tar.gz
chromium_src-8cf3f1dae79db8cfbf9dc6b75c140eabad918a6e.tar.bz2
Move IPC code to ipc/
(No review URL: Rietvelt couldn't cope) git-svn-id: svn://svn.chromium.org/chrome/trunk/src@13062 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common/common_message_utils.cc')
-rw-r--r--chrome/common/common_message_utils.cc145
1 files changed, 145 insertions, 0 deletions
diff --git a/chrome/common/common_message_utils.cc b/chrome/common/common_message_utils.cc
new file mode 100644
index 0000000..e12edae
--- /dev/null
+++ b/chrome/common/common_message_utils.cc
@@ -0,0 +1,145 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/common/common_message_utils.h"
+
+#include "googleurl/src/gurl.h"
+#include "SkBitmap.h"
+#include "webkit/glue/dom_operations.h"
+
+namespace IPC {
+
+namespace {
+
+struct SkBitmap_Data {
+ // The configuration for the bitmap (bits per pixel, etc).
+ SkBitmap::Config fConfig;
+
+ // The width of the bitmap in pixels.
+ uint32 fWidth;
+
+ // The height of the bitmap in pixels.
+ uint32 fHeight;
+
+ // The number of bytes between subsequent rows of the bitmap.
+ uint32 fRowBytes;
+
+ void InitSkBitmapDataForTransfer(const SkBitmap& bitmap) {
+ fConfig = bitmap.config();
+ fWidth = bitmap.width();
+ fHeight = bitmap.height();
+ fRowBytes = bitmap.rowBytes();
+ }
+
+ void InitSkBitmapFromData(SkBitmap* bitmap, const char* pixels,
+ size_t total_pixels) const {
+ if (total_pixels) {
+ bitmap->setConfig(fConfig, fWidth, fHeight, fRowBytes);
+ bitmap->allocPixels();
+ memcpy(bitmap->getPixels(), pixels, total_pixels);
+ }
+ }
+};
+
+} // namespace
+
+void ParamTraits<SkBitmap>::Write(Message* m, const SkBitmap& p) {
+ size_t fixed_size = sizeof(SkBitmap_Data);
+ SkBitmap_Data bmp_data;
+ bmp_data.InitSkBitmapDataForTransfer(p);
+ m->WriteData(reinterpret_cast<const char*>(&bmp_data),
+ static_cast<int>(fixed_size));
+ size_t pixel_size = p.getSize();
+ SkAutoLockPixels p_lock(p);
+ m->WriteData(reinterpret_cast<const char*>(p.getPixels()),
+ static_cast<int>(pixel_size));
+}
+
+bool ParamTraits<SkBitmap>::Read(const Message* m, void** iter, SkBitmap* r) {
+ const char* fixed_data;
+ int fixed_data_size = 0;
+ if (!m->ReadData(iter, &fixed_data, &fixed_data_size) ||
+ (fixed_data_size <= 0)) {
+ NOTREACHED();
+ return false;
+ }
+ if (fixed_data_size != sizeof(SkBitmap_Data))
+ return false; // Message is malformed.
+
+ const char* variable_data;
+ int variable_data_size = 0;
+ if (!m->ReadData(iter, &variable_data, &variable_data_size) ||
+ (variable_data_size < 0)) {
+ NOTREACHED();
+ return false;
+ }
+ const SkBitmap_Data* bmp_data =
+ reinterpret_cast<const SkBitmap_Data*>(fixed_data);
+ bmp_data->InitSkBitmapFromData(r, variable_data, variable_data_size);
+ return true;
+}
+
+void ParamTraits<SkBitmap>::Log(const SkBitmap& p, std::wstring* l) {
+ l->append(StringPrintf(L"<SkBitmap>"));
+}
+
+void ParamTraits<GURL>::Write(Message* m, const GURL& p) {
+ m->WriteString(p.possibly_invalid_spec());
+ // TODO(brettw) bug 684583: Add encoding for query params.
+}
+
+bool ParamTraits<GURL>::Read(const Message* m, void** iter, GURL* p) {
+ std::string s;
+ if (!m->ReadString(iter, &s)) {
+ *p = GURL();
+ return false;
+ }
+ *p = GURL(s);
+ return true;
+}
+
+void ParamTraits<GURL>::Log(const GURL& p, std::wstring* l) {
+ l->append(UTF8ToWide(p.spec()));
+}
+
+void ParamTraits<webkit_glue::WebApplicationInfo>::Write(
+ Message* m, const webkit_glue::WebApplicationInfo& 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);
+ }
+}
+
+bool ParamTraits<webkit_glue::WebApplicationInfo>::Read(
+ const Message* m, void** iter, webkit_glue::WebApplicationInfo* 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;
+}
+
+void ParamTraits<webkit_glue::WebApplicationInfo>::Log(
+ const webkit_glue::WebApplicationInfo& p, std::wstring* l) {
+ l->append(L"<WebApplicationInfo>");
+}
+
+} // namespace IPC