summaryrefslogtreecommitdiffstats
path: root/ppapi/proxy
diff options
context:
space:
mode:
authorbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-11 20:43:50 +0000
committerbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-11 20:43:50 +0000
commit9ca952dbc18f7128ac0f29ba00c142d6379fd62c (patch)
treeef5c3c86f733f703e01bd8949e40891a5de1e2e3 /ppapi/proxy
parent3393b52d8f93a21398fcfa9b67cc1e89d4af603a (diff)
downloadchromium_src-9ca952dbc18f7128ac0f29ba00c142d6379fd62c.zip
chromium_src-9ca952dbc18f7128ac0f29ba00c142d6379fd62c.tar.gz
chromium_src-9ca952dbc18f7128ac0f29ba00c142d6379fd62c.tar.bz2
Add support for proxying the font and char set interfaces.
TEST=none BUG=none Review URL: http://codereview.chromium.org/4653006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@65847 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi/proxy')
-rw-r--r--ppapi/proxy/dispatcher.cc13
-rw-r--r--ppapi/proxy/ppapi_param_traits.cc2
-rw-r--r--ppapi/proxy/ppb_char_set_proxy.cc157
-rw-r--r--ppapi/proxy/ppb_char_set_proxy.h62
-rw-r--r--ppapi/proxy/ppb_font_proxy.cc334
-rw-r--r--ppapi/proxy/ppb_font_proxy.h70
6 files changed, 634 insertions, 4 deletions
diff --git a/ppapi/proxy/dispatcher.cc b/ppapi/proxy/dispatcher.cc
index eecc9a0..61365d6 100644
--- a/ppapi/proxy/dispatcher.cc
+++ b/ppapi/proxy/dispatcher.cc
@@ -12,8 +12,8 @@
#include "base/logging.h"
#include "ipc/ipc_message.h"
#include "ipc/ipc_sync_channel.h"
-#include "ppapi/proxy/interface_proxy.h"
-#include "ppapi/proxy/ppapi_messages.h"
+#include "ppapi/c/dev/ppb_char_set_dev.h"
+#include "ppapi/c/dev/ppb_font_dev.h"
#include "ppapi/c/dev/ppb_testing_dev.h"
#include "ppapi/c/dev/ppb_var_deprecated.h"
#include "ppapi/c/pp_errors.h"
@@ -21,11 +21,14 @@
#include "ppapi/c/ppb_graphics_2d.h"
#include "ppapi/c/ppb_image_data.h"
#include "ppapi/c/ppb_instance.h"
-#include "ppapi/c/ppp_instance.h"
#include "ppapi/c/ppb_url_loader.h"
#include "ppapi/c/ppb_url_request_info.h"
#include "ppapi/c/ppb_url_response_info.h"
+#include "ppapi/c/ppp_instance.h"
+#include "ppapi/proxy/ppapi_messages.h"
+#include "ppapi/proxy/ppb_char_set_proxy.h"
#include "ppapi/proxy/ppb_core_proxy.h"
+#include "ppapi/proxy/ppb_font_proxy.h"
#include "ppapi/proxy/ppb_graphics_2d_proxy.h"
#include "ppapi/proxy/ppb_image_data_proxy.h"
#include "ppapi/proxy/ppb_instance_proxy.h"
@@ -203,8 +206,12 @@ void Dispatcher::OnMsgDeclareInterfaces(
InterfaceProxy* Dispatcher::CreateProxyForInterface(
const std::string& interface_name,
const void* interface_functions) {
+ if (interface_name == PPB_CHAR_SET_DEV_INTERFACE)
+ return new PPB_CharSet_Proxy(this, interface_functions);
if (interface_name == PPB_CORE_INTERFACE)
return new PPB_Core_Proxy(this, interface_functions);
+ if (interface_name == PPB_FONT_DEV_INTERFACE)
+ return new PPB_Font_Proxy(this, interface_functions);
if (interface_name == PPB_GRAPHICS_2D_INTERFACE)
return new PPB_Graphics2D_Proxy(this, interface_functions);
if (interface_name == PPB_IMAGEDATA_INTERFACE)
diff --git a/ppapi/proxy/ppapi_param_traits.cc b/ppapi/proxy/ppapi_param_traits.cc
index 04c014b..5e2dfd7 100644
--- a/ppapi/proxy/ppapi_param_traits.cc
+++ b/ppapi/proxy/ppapi_param_traits.cc
@@ -89,7 +89,7 @@ void ParamTraits<PP_Point>::Write(Message* m, const param_type& p) {
// static
bool ParamTraits<PP_Point>::Read(const Message* m, void** iter, param_type* r) {
- return m->ReadInt(iter, &r->x) && !m->ReadInt(iter, &r->y);
+ return m->ReadInt(iter, &r->x) && m->ReadInt(iter, &r->y);
}
// static
diff --git a/ppapi/proxy/ppb_char_set_proxy.cc b/ppapi/proxy/ppb_char_set_proxy.cc
new file mode 100644
index 0000000..d5be4c5
--- /dev/null
+++ b/ppapi/proxy/ppb_char_set_proxy.cc
@@ -0,0 +1,157 @@
+// Copyright (c) 2010 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 "ppapi/proxy/ppb_char_set_proxy.h"
+
+#include "ppapi/c/dev/ppb_char_set_dev.h"
+#include "ppapi/c/ppb_core.h"
+#include "ppapi/proxy/plugin_dispatcher.h"
+#include "ppapi/proxy/ppapi_messages.h"
+#include "ppapi/proxy/serialized_var.h"
+
+namespace pp {
+namespace proxy {
+
+namespace {
+
+char* UTF16ToCharSet(const uint16_t* utf16, uint32_t utf16_len,
+ const char* output_char_set,
+ PP_CharSet_ConversionError on_error,
+ uint32_t* output_length) {
+ bool output_is_success = false;
+ std::string result;
+ PluginDispatcher::Get()->Send(new PpapiHostMsg_PPBCharSet_UTF16ToCharSet(
+ INTERFACE_ID_PPB_CHAR_SET,
+ string16(reinterpret_cast<const char16*>(utf16), utf16_len),
+ std::string(output_char_set), static_cast<int32_t>(on_error),
+ &result, &output_is_success));
+ if (!output_is_success)
+ return NULL;
+
+ *output_length = static_cast<uint32_t>(result.size());
+ char* ret_val = static_cast<char*>(malloc(result.size() + 1));
+ memcpy(ret_val, result.c_str(), result.size() + 1);
+ return ret_val;
+}
+
+uint16_t* CharSetToUTF16(const char* input, uint32_t input_len,
+ const char* input_char_set,
+ PP_CharSet_ConversionError on_error,
+ uint32_t* output_length) {
+ bool output_is_success = false;
+ string16 result;
+ PluginDispatcher::Get()->Send(new PpapiHostMsg_PPBCharSet_CharSetToUTF16(
+ INTERFACE_ID_PPB_CHAR_SET,
+ std::string(input, input_len),
+ std::string(input_char_set), static_cast<int32_t>(on_error),
+ &result, &output_is_success));
+ if (!output_is_success)
+ return NULL;
+
+ *output_length = static_cast<uint32_t>(result.size());
+ uint16_t* ret_val = static_cast<uint16_t*>(
+ malloc((result.size() + 1) * sizeof(uint16_t)));
+ memcpy(ret_val, result.c_str(), (result.size() + 1) * sizeof(uint16_t));
+ return ret_val;
+}
+
+PP_Var GetDefaultCharSet(PP_Module pp_module) {
+ ReceiveSerializedVarReturnValue result;
+ PluginDispatcher::Get()->Send(new PpapiHostMsg_PPBCharSet_GetDefaultCharSet(
+ INTERFACE_ID_PPB_CHAR_SET, pp_module, &result));
+ return result.Return(PluginDispatcher::Get());
+}
+
+const PPB_CharSet_Dev ppb_charset_interface = {
+ &UTF16ToCharSet,
+ &CharSetToUTF16,
+ &GetDefaultCharSet
+};
+
+} // namespace
+
+PPB_CharSet_Proxy::PPB_CharSet_Proxy(Dispatcher* dispatcher,
+ const void* target_interface)
+ : InterfaceProxy(dispatcher, target_interface),
+ core_interface_(NULL) {
+}
+
+PPB_CharSet_Proxy::~PPB_CharSet_Proxy() {
+}
+
+const void* PPB_CharSet_Proxy::GetSourceInterface() const {
+ return &ppb_charset_interface;
+}
+
+InterfaceID PPB_CharSet_Proxy::GetInterfaceId() const {
+ return INTERFACE_ID_PPB_CHAR_SET;
+}
+
+void PPB_CharSet_Proxy::OnMessageReceived(const IPC::Message& msg) {
+ IPC_BEGIN_MESSAGE_MAP(PPB_CharSet_Proxy, msg)
+ IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBCharSet_UTF16ToCharSet,
+ OnMsgUTF16ToCharSet)
+ IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBCharSet_CharSetToUTF16,
+ OnMsgCharSetToUTF16)
+ IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBCharSet_GetDefaultCharSet,
+ OnMsgGetDefaultCharSet)
+ IPC_END_MESSAGE_MAP()
+}
+
+void PPB_CharSet_Proxy::OnMsgUTF16ToCharSet(const string16& utf16,
+ const std::string& char_set,
+ int32_t on_error,
+ std::string* output,
+ bool* output_is_success) {
+ uint32_t output_len = 0;
+ char* result = ppb_char_set_target()->UTF16ToCharSet(
+ reinterpret_cast<const uint16_t*>(utf16.c_str()),
+ static_cast<uint32_t>(utf16.size()),
+ char_set.c_str(), static_cast<PP_CharSet_ConversionError>(on_error),
+ &output_len);
+ if (result) {
+ output->assign(result, output_len);
+ GetCoreInterface()->MemFree(result);
+ *output_is_success = true;
+ } else {
+ *output_is_success = false;
+ }
+}
+
+void PPB_CharSet_Proxy::OnMsgCharSetToUTF16(const std::string& input,
+ const std::string& char_set,
+ int32_t on_error,
+ string16* output,
+ bool* output_is_success) {
+ uint32_t output_len = 0;
+ uint16_t* result = ppb_char_set_target()->CharSetToUTF16(
+ input.c_str(), static_cast<uint32_t>(input.size()),
+ char_set.c_str(), static_cast<PP_CharSet_ConversionError>(on_error),
+ &output_len);
+ if (result) {
+ output->assign(reinterpret_cast<const char16*>(result), output_len);
+ GetCoreInterface()->MemFree(result);
+ *output_is_success = true;
+ } else {
+ *output_is_success = false;
+ }
+}
+
+void PPB_CharSet_Proxy::OnMsgGetDefaultCharSet(
+ PP_Module module,
+ SerializedVarReturnValue result) {
+ result.Return(dispatcher(),
+ ppb_char_set_target()->GetDefaultCharSet(module));
+}
+
+const PPB_Core* PPB_CharSet_Proxy::GetCoreInterface() {
+ if (!core_interface_) {
+ core_interface_ = static_cast<const PPB_Core*>(
+ dispatcher()->GetLocalInterface(PPB_CORE_INTERFACE));
+ }
+ return core_interface_;
+}
+
+} // namespace proxy
+} // namespace pp
diff --git a/ppapi/proxy/ppb_char_set_proxy.h b/ppapi/proxy/ppb_char_set_proxy.h
new file mode 100644
index 0000000..17dddd5
--- /dev/null
+++ b/ppapi/proxy/ppb_char_set_proxy.h
@@ -0,0 +1,62 @@
+// Copyright (c) 2010 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.
+
+#ifndef PPAPI_PROXY_PPB_CHAR_SET_PROXY_H_
+#define PPAPI_PROXY_PPB_CHAR_SET_PROXY_H_
+
+#include "base/basictypes.h"
+#include "ppapi/c/pp_module.h"
+#include "ppapi/c/pp_resource.h"
+#include "ppapi/proxy/interface_proxy.h"
+
+struct PPB_CharSet_Dev;
+struct PPB_Core;
+
+namespace pp {
+namespace proxy {
+
+class SerializedVarReturnValue;
+
+class PPB_CharSet_Proxy : public InterfaceProxy {
+ public:
+ PPB_CharSet_Proxy(Dispatcher* dispatcher, const void* target_interface);
+ virtual ~PPB_CharSet_Proxy();
+
+ const PPB_CharSet_Dev* ppb_char_set_target() const {
+ return static_cast<const PPB_CharSet_Dev*>(target_interface());
+ }
+
+ // InterfaceProxy implementation.
+ virtual const void* GetSourceInterface() const;
+ virtual InterfaceID GetInterfaceId() const;
+ virtual void OnMessageReceived(const IPC::Message& msg);
+
+ private:
+ // Message handlers.
+ void OnMsgUTF16ToCharSet(const string16& utf16,
+ const std::string& char_set,
+ int32_t on_error,
+ std::string* output,
+ bool* output_is_success);
+ void OnMsgCharSetToUTF16(const std::string& input,
+ const std::string& char_set,
+ int32_t on_error,
+ string16* output,
+ bool* output_is_success);
+ void OnMsgGetDefaultCharSet(PP_Module module,
+ SerializedVarReturnValue result);
+
+ // Returns the local PPB_Core interface for freeing strings.
+ const PPB_Core* GetCoreInterface();
+
+ // Possibly NULL, lazily initialized by GetCoreInterface.
+ const PPB_Core* core_interface_;
+
+ DISALLOW_COPY_AND_ASSIGN(PPB_CharSet_Proxy);
+};
+
+} // namespace proxy
+} // namespace pp
+
+#endif // PPAPI_PROXY_PPB_CHAR_SET_PROXY_H_
diff --git a/ppapi/proxy/ppb_font_proxy.cc b/ppapi/proxy/ppb_font_proxy.cc
new file mode 100644
index 0000000..2313c34
--- /dev/null
+++ b/ppapi/proxy/ppb_font_proxy.cc
@@ -0,0 +1,334 @@
+// Copyright (c) 2010 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 "ppapi/proxy/ppb_font_proxy.h"
+
+#include "ppapi/c/dev/ppb_font_dev.h"
+#include "ppapi/proxy/plugin_dispatcher.h"
+#include "ppapi/proxy/plugin_resource.h"
+#include "ppapi/proxy/ppapi_messages.h"
+
+namespace pp {
+namespace proxy {
+
+class Font : public PluginResource {
+ public:
+ Font();
+ virtual ~Font();
+
+ // PluginResource overrides.
+ virtual Font* AsFont() { return this; }
+
+ PP_FontDescription_Dev& desc() { return desc_; }
+ PP_FontMetrics_Dev& metrics() { return metrics_; }
+
+ private:
+ PP_FontDescription_Dev desc_;
+ PP_FontMetrics_Dev metrics_;
+
+ DISALLOW_COPY_AND_ASSIGN(Font);
+};
+
+Font::Font() {
+ memset(&desc_, 0, sizeof(PP_FontDescription_Dev));
+ desc_.face.type = PP_VARTYPE_UNDEFINED;
+ memset(&metrics_, 0, sizeof(PP_FontMetrics_Dev));
+}
+
+Font::~Font() {
+ PluginDispatcher::Get()->plugin_var_tracker()->Release(desc_.face);
+}
+
+namespace {
+
+PP_Resource Create(PP_Module module_id,
+ const PP_FontDescription_Dev* description) {
+ PluginDispatcher* dispatcher = PluginDispatcher::Get();
+
+ // Convert the input font description to a SerializedFontDescription.
+ SerializedFontDescription in_description;
+ in_description.face = SerializedVarSendInput(dispatcher, description->face);
+ in_description.family = description->family;
+ in_description.size = description->size;
+ in_description.weight = description->weight;
+ in_description.italic = description->italic;
+ in_description.small_caps = description->small_caps;
+ in_description.letter_spacing = description->letter_spacing;
+ in_description.word_spacing = description->word_spacing;
+
+ PP_Resource result;
+ SerializedFontDescription out_description;
+ std::string out_metrics;
+ PluginDispatcher::Get()->Send(new PpapiHostMsg_PPBFont_Create(
+ INTERFACE_ID_PPB_FONT,
+ module_id, in_description, &result, &out_description, &out_metrics));
+
+ if (!result)
+ return 0; // Failure creating font.
+
+ linked_ptr<Font> object(new Font);
+
+ // Jump through some hoops to get a PP_Var with a single ref to it in our
+ // resource object.
+ ReceiveSerializedVarReturnValue face_return_value;
+ *static_cast<SerializedVar*>(&face_return_value) = out_description.face;
+ object->desc().face = face_return_value.Return(dispatcher);
+
+ // Convert the rest of the font description.
+ object->desc().family =
+ static_cast<PP_FontFamily_Dev>(out_description.family);
+ object->desc().size = out_description.size;
+ object->desc().weight =
+ static_cast<PP_FontWeight_Dev>(out_description.weight);
+ object->desc().italic = out_description.italic;
+ object->desc().small_caps = out_description.small_caps;
+ object->desc().letter_spacing = out_description.letter_spacing;
+ object->desc().word_spacing = out_description.word_spacing;
+
+ // Convert the metrics, this is just serialized as a string of bytes.
+ if (out_metrics.size() != sizeof(PP_FontMetrics_Dev))
+ return 0;
+ memcpy(&object->metrics(), out_metrics.data(), sizeof(PP_FontMetrics_Dev));
+
+ PluginDispatcher::Get()->plugin_resource_tracker()->AddResource(
+ result, object);
+ return result;
+}
+
+PP_Bool IsFont(PP_Resource resource) {
+ Font* object = PluginResource::GetAs<Font>(resource);
+ return BoolToPPBool(!!object);
+}
+
+PP_Bool Describe(PP_Resource font_id,
+ PP_FontDescription_Dev* description,
+ PP_FontMetrics_Dev* metrics) {
+ Font* object = PluginResource::GetAs<Font>(font_id);
+ if (!object)
+ return PP_FALSE;
+
+ // Copy the description, the caller expects its face PP_Var to have a ref
+ // added to it on its behalf.
+ memcpy(description, &object->desc(), sizeof(PP_FontDescription_Dev));
+ PluginDispatcher::Get()->plugin_var_tracker()->AddRef(description->face);
+
+ memcpy(metrics, &object->metrics(), sizeof(PP_FontMetrics_Dev));
+ return PP_TRUE;
+}
+
+PP_Bool DrawTextAt(PP_Resource font_id,
+ PP_Resource image_data,
+ const PP_TextRun_Dev* text,
+ const PP_Point* position,
+ uint32_t color,
+ const PP_Rect* clip,
+ PP_Bool image_data_is_opaque) {
+ PPBFont_DrawTextAt_Params params;
+ params.font = font_id;
+ params.image_data = image_data;
+ params.text_is_rtl = text->rtl;
+ params.override_direction = text->override_direction;
+ params.position = *position;
+ params.color = color;
+ if (clip) {
+ params.clip = *clip;
+ params.clip_is_null = false;
+ } else {
+ params.clip = PP_MakeRectFromXYWH(0, 0, 0, 0);
+ params.clip_is_null = true;
+ }
+ params.image_data_is_opaque = image_data_is_opaque;
+
+ Dispatcher* dispatcher = PluginDispatcher::Get();
+ PP_Bool result = PP_FALSE;
+ dispatcher->Send(new PpapiHostMsg_PPBFont_DrawTextAt(
+ INTERFACE_ID_PPB_FONT,
+ SerializedVarSendInput(dispatcher, text->text),
+ params, &result));
+ return result;
+}
+
+int32_t MeasureText(PP_Resource font_id, const PP_TextRun_Dev* text) {
+ Dispatcher* dispatcher = PluginDispatcher::Get();
+ int32_t result = 0;
+ dispatcher->Send(new PpapiHostMsg_PPBFont_MeasureText(
+ INTERFACE_ID_PPB_FONT, font_id,
+ SerializedVarSendInput(dispatcher, text->text),
+ text->rtl, text->override_direction, &result));
+ return result;
+}
+
+uint32_t CharacterOffsetForPixel(PP_Resource font_id,
+ const PP_TextRun_Dev* text,
+ int32_t pixel_position) {
+ Dispatcher* dispatcher = PluginDispatcher::Get();
+ uint32_t result = 0;
+ dispatcher->Send(new PpapiHostMsg_PPBFont_CharacterOffsetForPixel(
+ INTERFACE_ID_PPB_FONT, font_id,
+ SerializedVarSendInput(dispatcher, text->text),
+ text->rtl, text->override_direction, pixel_position, &result));
+ return result;
+}
+
+int32_t PixelOffsetForCharacter(PP_Resource font_id,
+ const PP_TextRun_Dev* text,
+ uint32_t char_offset) {
+ Dispatcher* dispatcher = PluginDispatcher::Get();
+ int32_t result = 0;
+ dispatcher->Send(new PpapiHostMsg_PPBFont_PixelOffsetForCharacter(
+ INTERFACE_ID_PPB_FONT, font_id,
+ SerializedVarSendInput(dispatcher, text->text),
+ text->rtl, text->override_direction, char_offset, &result));
+ return result;
+}
+
+const PPB_Font_Dev ppb_font_interface = {
+ &Create,
+ &IsFont,
+ &Describe,
+ &DrawTextAt,
+ &MeasureText,
+ &CharacterOffsetForPixel,
+ &PixelOffsetForCharacter
+};
+
+} // namespace
+
+PPB_Font_Proxy::PPB_Font_Proxy(Dispatcher* dispatcher,
+ const void* target_interface)
+ : InterfaceProxy(dispatcher, target_interface) {
+}
+
+PPB_Font_Proxy::~PPB_Font_Proxy() {
+}
+
+const void* PPB_Font_Proxy::GetSourceInterface() const {
+ return &ppb_font_interface;
+}
+
+InterfaceID PPB_Font_Proxy::GetInterfaceId() const {
+ return INTERFACE_ID_PPB_FONT;
+}
+
+void PPB_Font_Proxy::OnMessageReceived(const IPC::Message& msg) {
+ IPC_BEGIN_MESSAGE_MAP(PPB_Font_Proxy, msg)
+ IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFont_Create,
+ OnMsgCreate)
+ IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFont_DrawTextAt,
+ OnMsgDrawTextAt)
+ IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFont_MeasureText,
+ OnMsgMeasureText)
+ IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFont_CharacterOffsetForPixel,
+ OnMsgCharacterOffsetForPixel)
+ IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFont_PixelOffsetForCharacter,
+ OnMsgPixelOffsetForCharacter)
+ IPC_END_MESSAGE_MAP()
+}
+
+void PPB_Font_Proxy::OnMsgCreate(
+ PP_Module pp_module,
+ const SerializedFontDescription& in_description,
+ PP_Resource* result,
+ SerializedFontDescription* out_description,
+ std::string* out_metrics) {
+ // Convert the face name in the input description.
+ PP_FontDescription_Dev in_desc;
+ SerializedVarReceiveInput in_face_name(in_description.face);
+ in_desc.face = in_face_name.Get(dispatcher());
+
+ // The rest of the font description is easy.
+ in_desc.family = static_cast<PP_FontFamily_Dev>(in_description.family);
+ in_desc.size = in_description.size;
+ in_desc.weight = static_cast<PP_FontWeight_Dev>(in_description.weight);
+ in_desc.italic = in_description.italic;
+ in_desc.small_caps = in_description.small_caps;
+ in_desc.letter_spacing = in_description.letter_spacing;
+ in_desc.word_spacing = in_description.word_spacing;
+
+ *result = ppb_font_target()->Create(pp_module, &in_desc);
+ if (!*result)
+ return;
+
+ // Get the metrics and resulting description to return to the browser.
+ PP_FontDescription_Dev out_desc;
+ PP_FontMetrics_Dev metrics;
+ ppb_font_target()->Describe(*result, &out_desc, &metrics);
+
+ // Convert the PP_Var in the resulting description to an out param. This
+ // should clean up the ref |Describe| assigned to our font name.
+ SerializedVarOutParam out_face_name(&out_description->face);
+ *out_face_name.OutParam(dispatcher()) = out_desc.face;
+
+ // The rest of the font description is easy.
+ out_description->family = out_desc.family;
+ out_description->size = out_desc.size;
+ out_description->weight = out_desc.weight;
+ out_description->italic = out_desc.italic;
+ out_description->small_caps = out_desc.small_caps;
+ out_description->letter_spacing = out_desc.letter_spacing;
+ out_description->word_spacing = out_desc.word_spacing;
+
+ // Metrics are just serialized as a string.
+ out_metrics->assign(reinterpret_cast<const char*>(&metrics),
+ sizeof(PP_FontMetrics_Dev));
+}
+
+void PPB_Font_Proxy::OnMsgDrawTextAt(SerializedVarReceiveInput text,
+ const PPBFont_DrawTextAt_Params& params,
+ PP_Bool* result) {
+ PP_TextRun_Dev run;
+ run.text = text.Get(dispatcher());
+ run.rtl = params.text_is_rtl;
+ run.override_direction = params.override_direction;
+
+ *result = ppb_font_target()->DrawTextAt(params.font, params.image_data,
+ &run, &params.position, params.color,
+ params.clip_is_null ? NULL : &params.clip, params.image_data_is_opaque);
+}
+
+void PPB_Font_Proxy::OnMsgMeasureText(PP_Resource font,
+ SerializedVarReceiveInput text,
+ PP_Bool text_is_rtl,
+ PP_Bool override_direction,
+ int32_t* result) {
+ PP_TextRun_Dev run;
+ run.text = text.Get(dispatcher());
+ run.rtl = text_is_rtl;
+ run.override_direction = override_direction;
+
+ *result = ppb_font_target()->MeasureText(font, &run);
+}
+
+void PPB_Font_Proxy::OnMsgCharacterOffsetForPixel(
+ PP_Resource font,
+ SerializedVarReceiveInput text,
+ PP_Bool text_is_rtl,
+ PP_Bool override_direction,
+ int32_t pixel_pos,
+ uint32_t* result) {
+ PP_TextRun_Dev run;
+ run.text = text.Get(dispatcher());
+ run.rtl = text_is_rtl;
+ run.override_direction = override_direction;
+
+ *result = ppb_font_target()->CharacterOffsetForPixel(font, &run, pixel_pos);
+}
+
+void PPB_Font_Proxy::OnMsgPixelOffsetForCharacter(
+ PP_Resource font,
+ SerializedVarReceiveInput text,
+ PP_Bool text_is_rtl,
+ PP_Bool override_direction,
+ uint32_t char_offset,
+ int32_t* result) {
+ PP_TextRun_Dev run;
+ run.text = text.Get(dispatcher());
+ run.rtl = text_is_rtl;
+ run.override_direction = override_direction;
+
+ *result = ppb_font_target()->PixelOffsetForCharacter(font, &run, char_offset);
+}
+
+} // namespace proxy
+} // namespace pp
diff --git a/ppapi/proxy/ppb_font_proxy.h b/ppapi/proxy/ppb_font_proxy.h
new file mode 100644
index 0000000..25e14ed
--- /dev/null
+++ b/ppapi/proxy/ppb_font_proxy.h
@@ -0,0 +1,70 @@
+// Copyright (c) 2010 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.
+
+#ifndef PPAPI_PROXY_PPB_FONT_PROXY_H_
+#define PPAPI_PROXY_PPB_FONT_PROXY_H_
+
+#include "base/basictypes.h"
+#include "ppapi/c/pp_module.h"
+#include "ppapi/c/pp_resource.h"
+#include "ppapi/proxy/interface_proxy.h"
+
+struct PPB_Font_Dev;
+
+namespace pp {
+namespace proxy {
+
+struct PPBFont_DrawTextAt_Params;
+struct SerializedFontDescription;
+class SerializedVarReceiveInput;
+
+class PPB_Font_Proxy : public InterfaceProxy {
+ public:
+ PPB_Font_Proxy(Dispatcher* dispatcher, const void* target_interface);
+ virtual ~PPB_Font_Proxy();
+
+ const PPB_Font_Dev* ppb_font_target() const {
+ return static_cast<const PPB_Font_Dev*>(target_interface());
+ }
+
+ // InterfaceProxy implementation.
+ virtual const void* GetSourceInterface() const;
+ virtual InterfaceID GetInterfaceId() const;
+ virtual void OnMessageReceived(const IPC::Message& msg);
+
+ private:
+ // Message handlers.
+ void OnMsgCreate(PP_Module pp_module,
+ const SerializedFontDescription& in_description,
+ PP_Resource* result,
+ SerializedFontDescription* out_description,
+ std::string* out_metrics);
+ void OnMsgDrawTextAt(SerializedVarReceiveInput text,
+ const PPBFont_DrawTextAt_Params& params,
+ PP_Bool* result);
+ void OnMsgMeasureText(PP_Resource font,
+ SerializedVarReceiveInput text,
+ PP_Bool text_is_rtl,
+ PP_Bool override_direction,
+ int32_t* result);
+ void OnMsgCharacterOffsetForPixel(PP_Resource font,
+ SerializedVarReceiveInput text,
+ PP_Bool text_is_rtl,
+ PP_Bool override_direction,
+ int32_t pixel_pos,
+ uint32_t* result);
+ void OnMsgPixelOffsetForCharacter(PP_Resource font,
+ SerializedVarReceiveInput text,
+ PP_Bool text_is_rtl,
+ PP_Bool override_direction,
+ uint32_t char_offset,
+ int32_t* result);
+
+ DISALLOW_COPY_AND_ASSIGN(PPB_Font_Proxy);
+};
+
+} // namespace proxy
+} // namespace pp
+
+#endif // PPAPI_PROXY_PPB_FONT_PROXY_H_