diff options
Diffstat (limited to 'ppapi/proxy')
-rw-r--r-- | ppapi/proxy/interface_list.cc | 1 | ||||
-rw-r--r-- | ppapi/proxy/ppapi_messages.h | 26 | ||||
-rw-r--r-- | ppapi/proxy/ppapi_param_traits.cc | 37 | ||||
-rw-r--r-- | ppapi/proxy/ppapi_param_traits.h | 10 | ||||
-rw-r--r-- | ppapi/proxy/ppb_instance_proxy.cc | 4 | ||||
-rw-r--r-- | ppapi/proxy/resource_creation_proxy.cc | 9 | ||||
-rw-r--r-- | ppapi/proxy/resource_creation_proxy.h | 3 | ||||
-rw-r--r-- | ppapi/proxy/serialized_structs.cc | 34 | ||||
-rw-r--r-- | ppapi/proxy/serialized_structs.h | 25 | ||||
-rw-r--r-- | ppapi/proxy/truetype_font_resource.cc | 130 | ||||
-rw-r--r-- | ppapi/proxy/truetype_font_resource.h | 73 | ||||
-rw-r--r-- | ppapi/proxy/truetype_font_singleton_resource.cc | 68 | ||||
-rw-r--r-- | ppapi/proxy/truetype_font_singleton_resource.h | 55 |
13 files changed, 475 insertions, 0 deletions
diff --git a/ppapi/proxy/interface_list.cc b/ppapi/proxy/interface_list.cc index 71444ce..4beeaab 100644 --- a/ppapi/proxy/interface_list.cc +++ b/ppapi/proxy/interface_list.cc @@ -25,6 +25,7 @@ #include "ppapi/c/dev/ppb_testing_dev.h" #include "ppapi/c/dev/ppb_text_input_dev.h" #include "ppapi/c/dev/ppb_trace_event_dev.h" +#include "ppapi/c/dev/ppb_truetype_font_dev.h" #include "ppapi/c/dev/ppb_url_util_dev.h" #include "ppapi/c/dev/ppb_var_deprecated.h" #include "ppapi/c/dev/ppb_video_capture_dev.h" diff --git a/ppapi/proxy/ppapi_messages.h b/ppapi/proxy/ppapi_messages.h index 4e9c0e2..9ccd930 100644 --- a/ppapi/proxy/ppapi_messages.h +++ b/ppapi/proxy/ppapi_messages.h @@ -22,6 +22,7 @@ #include "ppapi/c/dev/pp_video_dev.h" #include "ppapi/c/dev/ppb_directory_reader_dev.h" #include "ppapi/c/dev/ppb_text_input_dev.h" +#include "ppapi/c/dev/ppb_truetype_font_dev.h" #include "ppapi/c/dev/ppb_url_util_dev.h" #include "ppapi/c/dev/ppp_printing_dev.h" #include "ppapi/c/pp_bool.h" @@ -84,6 +85,11 @@ IPC_ENUM_TRAITS(PP_PrintOutputFormat_Dev) IPC_ENUM_TRAITS(PP_PrintScalingOption_Dev) IPC_ENUM_TRAITS(PP_PrivateFontCharset) IPC_ENUM_TRAITS(PP_TextInput_Type) +IPC_ENUM_TRAITS(PP_TrueTypeFontFamily_Dev) +IPC_ENUM_TRAITS(PP_TrueTypeFontStyle_Dev) +IPC_ENUM_TRAITS(PP_TrueTypeFontWeight_Dev) +IPC_ENUM_TRAITS(PP_TrueTypeFontWidth_Dev) +IPC_ENUM_TRAITS(PP_TrueTypeFontCharset_Dev) IPC_ENUM_TRAITS(PP_VideoDecodeError_Dev) IPC_ENUM_TRAITS(PP_VideoDecoder_Profile) @@ -1414,6 +1420,26 @@ IPC_MESSAGE_CONTROL2(PpapiHostMsg_Graphics2D_ReadImageData, PP_Point /* top_left */) IPC_MESSAGE_CONTROL0(PpapiPluginMsg_Graphics2D_ReadImageDataAck) +// TrueTypeFont. +IPC_MESSAGE_CONTROL0(PpapiHostMsg_TrueTypeFontSingleton_Create) +IPC_MESSAGE_CONTROL0(PpapiHostMsg_TrueTypeFontSingleton_GetFontFamilies) +IPC_MESSAGE_CONTROL1(PpapiPluginMsg_TrueTypeFontSingleton_GetFontFamiliesReply, + std::vector<std::string> /* font_families */) +IPC_MESSAGE_CONTROL1(PpapiHostMsg_TrueTypeFont_Create, + ppapi::proxy::SerializedTrueTypeFontDesc /* desc */) +IPC_MESSAGE_CONTROL0(PpapiHostMsg_TrueTypeFont_Describe) +IPC_MESSAGE_CONTROL1(PpapiPluginMsg_TrueTypeFont_DescribeReply, + ppapi::proxy::SerializedTrueTypeFontDesc /* desc */) +IPC_MESSAGE_CONTROL0(PpapiHostMsg_TrueTypeFont_GetTableTags) +IPC_MESSAGE_CONTROL1(PpapiPluginMsg_TrueTypeFont_GetTableTagsReply, + std::vector<uint32_t> /* tags */) +IPC_MESSAGE_CONTROL3(PpapiHostMsg_TrueTypeFont_GetTable, + uint32_t /* table */, + int32_t /* offset */, + int32_t /* max_data_length */) +IPC_MESSAGE_CONTROL1(PpapiPluginMsg_TrueTypeFont_GetTableReply, + std::string /* data */) + // HostResolverPrivate, plugin -> host -> plugin IPC_MESSAGE_CONTROL0(PpapiHostMsg_HostResolverPrivate_Create) IPC_MESSAGE_CONTROL2(PpapiHostMsg_HostResolverPrivate_Resolve, diff --git a/ppapi/proxy/ppapi_param_traits.cc b/ppapi/proxy/ppapi_param_traits.cc index e457503..b654b22 100644 --- a/ppapi/proxy/ppapi_param_traits.cc +++ b/ppapi/proxy/ppapi_param_traits.cc @@ -560,7 +560,44 @@ void ParamTraits<ppapi::proxy::SerializedFontDescription>::Log( const param_type& p, std::string* l) { } +#endif // !defined(OS_NACL) && !defined(NACL_WIN64) + +// ppapi::proxy::SerializedTrueTypeFontDesc ------------------------------------ + +// static +void ParamTraits<ppapi::proxy::SerializedTrueTypeFontDesc>::Write( + Message* m, + const param_type& p) { + ParamTraits<std::string>::Write(m, p.family); + ParamTraits<PP_TrueTypeFontFamily_Dev>::Write(m, p.generic_family); + ParamTraits<PP_TrueTypeFontStyle_Dev>::Write(m, p.style); + ParamTraits<PP_TrueTypeFontWeight_Dev>::Write(m, p.weight); + ParamTraits<PP_TrueTypeFontWidth_Dev>::Write(m, p.width); + ParamTraits<PP_TrueTypeFontCharset_Dev>::Write(m, p.charset); +} + +// static +bool ParamTraits<ppapi::proxy::SerializedTrueTypeFontDesc>::Read( + const Message* m, + PickleIterator* iter, + param_type* r) { + return + ParamTraits<std::string>::Read(m, iter, &r->family) && + ParamTraits<PP_TrueTypeFontFamily_Dev>::Read(m, iter, + &r->generic_family) && + ParamTraits<PP_TrueTypeFontStyle_Dev>::Read(m, iter, &r->style) && + ParamTraits<PP_TrueTypeFontWeight_Dev>::Read(m, iter, &r->weight) && + ParamTraits<PP_TrueTypeFontWidth_Dev>::Read(m, iter, &r->width) && + ParamTraits<PP_TrueTypeFontCharset_Dev>::Read(m, iter, &r->charset); +} + +// static +void ParamTraits<ppapi::proxy::SerializedTrueTypeFontDesc>::Log( + const param_type& p, + std::string* l) { +} +#if !defined(OS_NACL) && !defined(NACL_WIN64) // ppapi::PepperFilePath ------------------------------------------------------- // static diff --git a/ppapi/proxy/ppapi_param_traits.h b/ppapi/proxy/ppapi_param_traits.h index 7556e35..38ec6f3 100644 --- a/ppapi/proxy/ppapi_param_traits.h +++ b/ppapi/proxy/ppapi_param_traits.h @@ -33,6 +33,7 @@ struct PPBFlash_DrawGlyphs_Params; struct PPBURLLoader_UpdateProgress_Params; struct SerializedDirEntry; struct SerializedFontDescription; +struct SerializedTrueTypeFontDesc; class SerializedFlashMenu; class SerializedHandle; class SerializedVar; @@ -117,6 +118,15 @@ struct PPAPI_PROXY_EXPORT ParamTraits<ppapi::proxy::SerializedFontDescription> { }; template<> +struct PPAPI_PROXY_EXPORT + ParamTraits<ppapi::proxy::SerializedTrueTypeFontDesc> { + typedef ppapi::proxy::SerializedTrueTypeFontDesc param_type; + static void Write(Message* m, const param_type& p); + static bool Read(const Message* m, PickleIterator* iter, param_type* r); + static void Log(const param_type& p, std::string* l); +}; + +template<> struct PPAPI_PROXY_EXPORT ParamTraits<ppapi::proxy::SerializedHandle> { typedef ppapi::proxy::SerializedHandle param_type; static void Write(Message* m, const param_type& p); diff --git a/ppapi/proxy/ppb_instance_proxy.cc b/ppapi/proxy/ppb_instance_proxy.cc index df83edc..58b1593 100644 --- a/ppapi/proxy/ppb_instance_proxy.cc +++ b/ppapi/proxy/ppb_instance_proxy.cc @@ -27,6 +27,7 @@ #include "ppapi/proxy/plugin_dispatcher.h" #include "ppapi/proxy/ppapi_messages.h" #include "ppapi/proxy/serialized_var.h" +#include "ppapi/proxy/truetype_font_singleton_resource.h" #include "ppapi/shared_impl/ppapi_globals.h" #include "ppapi/shared_impl/ppb_url_util_shared.h" #include "ppapi/shared_impl/ppb_view_shared.h" @@ -357,6 +358,9 @@ Resource* PPB_Instance_Proxy::GetSingletonResource(PP_Instance instance, case GAMEPAD_SINGLETON_ID: new_singleton = new GamepadResource(connection, instance); break; + case TRUETYPE_FONT_SINGLETON_ID: + new_singleton = new TrueTypeFontSingletonResource(connection, instance); + break; // Flash/trusted resources aren't needed for NaCl. #if !defined(OS_NACL) && !defined(NACL_WIN64) case BROWSER_FONT_SINGLETON_ID: diff --git a/ppapi/proxy/resource_creation_proxy.cc b/ppapi/proxy/resource_creation_proxy.cc index a821a15..4aec036 100644 --- a/ppapi/proxy/resource_creation_proxy.cc +++ b/ppapi/proxy/resource_creation_proxy.cc @@ -38,6 +38,7 @@ #include "ppapi/proxy/ppb_x509_certificate_private_proxy.h" #include "ppapi/proxy/printing_resource.h" #include "ppapi/proxy/talk_resource.h" +#include "ppapi/proxy/truetype_font_resource.h" #include "ppapi/proxy/udp_socket_private_resource.h" #include "ppapi/proxy/url_request_info_resource.h" #include "ppapi/proxy/url_response_info_resource.h" @@ -143,6 +144,14 @@ PP_Resource ResourceCreationProxy::CreateResourceArray( return object->GetReference(); } +PP_Resource ResourceCreationProxy::CreateTrueTypeFont( + PP_Instance instance, + const PP_TrueTypeFontDesc_Dev& desc) { + return (new TrueTypeFontResource(GetConnection(), + instance, desc))->GetReference(); + +} + PP_Resource ResourceCreationProxy::CreateURLLoader(PP_Instance instance) { return PPB_URLLoader_Proxy::CreateProxyResource(instance); } diff --git a/ppapi/proxy/resource_creation_proxy.h b/ppapi/proxy/resource_creation_proxy.h index 940b254..2a95c12 100644 --- a/ppapi/proxy/resource_creation_proxy.h +++ b/ppapi/proxy/resource_creation_proxy.h @@ -75,6 +75,9 @@ class ResourceCreationProxy : public InterfaceProxy, virtual PP_Resource CreateResourceArray(PP_Instance instance, const PP_Resource elements[], uint32_t size) OVERRIDE; + virtual PP_Resource CreateTrueTypeFont( + PP_Instance instance, + const PP_TrueTypeFontDesc_Dev& desc) OVERRIDE; virtual PP_Resource CreateURLLoader(PP_Instance instance) OVERRIDE; virtual PP_Resource CreateURLRequestInfo( PP_Instance instance, diff --git a/ppapi/proxy/serialized_structs.cc b/ppapi/proxy/serialized_structs.cc index ebd7ed0..8c984d5 100644 --- a/ppapi/proxy/serialized_structs.cc +++ b/ppapi/proxy/serialized_structs.cc @@ -80,6 +80,40 @@ void SerializedFontDescription::SetToPPBrowserFontDescription( desc->word_spacing = word_spacing; } +SerializedTrueTypeFontDesc::SerializedTrueTypeFontDesc() + : family(), + generic_family(), + style(), + weight(), + width(), + charset() { +} + +SerializedTrueTypeFontDesc::~SerializedTrueTypeFontDesc() {} + +void SerializedTrueTypeFontDesc::SetFromPPTrueTypeFontDesc( + const PP_TrueTypeFontDesc_Dev& desc) { + StringVar* string_var = StringVar::FromPPVar(desc.family); + family = string_var ? string_var->value() : std::string(); + + generic_family = desc.generic_family; + style = desc.style; + weight = desc.weight; + width = desc.width; + charset = desc.charset; +} + +void SerializedTrueTypeFontDesc::CopyToPPTrueTypeFontDesc( + PP_TrueTypeFontDesc_Dev* desc) const { + desc->family = StringVar::StringToPPVar(family); + + desc->generic_family = generic_family; + desc->style = style; + desc->weight = weight; + desc->width = width; + desc->charset = charset; +} + PPBFlash_DrawGlyphs_Params::PPBFlash_DrawGlyphs_Params() : instance(0), font_desc(), diff --git a/ppapi/proxy/serialized_structs.h b/ppapi/proxy/serialized_structs.h index dcb99817..4844d6b 100644 --- a/ppapi/proxy/serialized_structs.h +++ b/ppapi/proxy/serialized_structs.h @@ -11,6 +11,7 @@ #include "base/logging.h" #include "base/shared_memory.h" #include "build/build_config.h" +#include "ppapi/c/dev/ppb_truetype_font_dev.h" #include "ppapi/c/pp_bool.h" #include "ppapi/c/pp_instance.h" #include "ppapi/c/pp_point.h" @@ -56,6 +57,30 @@ struct PPAPI_PROXY_EXPORT SerializedFontDescription { int32_t word_spacing; }; +struct PPAPI_PROXY_EXPORT SerializedTrueTypeFontDesc { + SerializedTrueTypeFontDesc(); + ~SerializedTrueTypeFontDesc(); + + // Sets this to correspond to the contents of a PP_TrueTypeFontDesc_Dev. + // + // The reference count of the desc.family PP_Var will be unchanged and the + // caller is responsible for releasing it. + void SetFromPPTrueTypeFontDesc(const PP_TrueTypeFontDesc_Dev& desc); + + // Converts this to a PP_FontDescription_Dev. + // + // The desc.family PP_Var will have one reference assigned to it. The caller + // is responsible for releasing it. + void CopyToPPTrueTypeFontDesc(PP_TrueTypeFontDesc_Dev* desc) const; + + std::string family; + PP_TrueTypeFontFamily_Dev generic_family; + PP_TrueTypeFontStyle_Dev style; + PP_TrueTypeFontWeight_Dev weight; + PP_TrueTypeFontWidth_Dev width; + PP_TrueTypeFontCharset_Dev charset; +}; + struct SerializedDirEntry { std::string name; bool is_dir; diff --git a/ppapi/proxy/truetype_font_resource.cc b/ppapi/proxy/truetype_font_resource.cc new file mode 100644 index 0000000..0b07195 --- /dev/null +++ b/ppapi/proxy/truetype_font_resource.cc @@ -0,0 +1,130 @@ +// Copyright (c) 2013 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/truetype_font_resource.h" + +#include "base/bind.h" +#include "ipc/ipc_message.h" +#include "ppapi/c/pp_errors.h" +#include "ppapi/proxy/ppapi_messages.h" +#include "ppapi/shared_impl/array_writer.h" +#include "ppapi/shared_impl/ppapi_globals.h" +#include "ppapi/shared_impl/resource_tracker.h" +#include "ppapi/shared_impl/var.h" +#include "ppapi/thunk/enter.h" + +using ppapi::thunk::EnterResourceNoLock; +using ppapi::thunk::PPB_TrueTypeFont_API; + +namespace { + +} // namespace + +namespace ppapi { +namespace proxy { + +TrueTypeFontResource::TrueTypeFontResource( + Connection connection, + PP_Instance instance, + const PP_TrueTypeFontDesc_Dev& desc) + : PluginResource(connection, instance) { + SerializedTrueTypeFontDesc serialized_desc; + serialized_desc.SetFromPPTrueTypeFontDesc(desc); + SendCreate(RENDERER, PpapiHostMsg_TrueTypeFont_Create(serialized_desc)); +} + +TrueTypeFontResource::~TrueTypeFontResource() { +} + +PPB_TrueTypeFont_API* TrueTypeFontResource::AsPPB_TrueTypeFont_API() { + return this; +} + +int32_t TrueTypeFontResource::Describe( + PP_TrueTypeFontDesc_Dev* desc, + scoped_refptr<TrackedCallback> callback) { + + Call<PpapiPluginMsg_TrueTypeFont_DescribeReply>(RENDERER, + PpapiHostMsg_TrueTypeFont_Describe(), + base::Bind(&TrueTypeFontResource::OnPluginMsgDescribeComplete, this, + callback, desc)); + return PP_OK_COMPLETIONPENDING; +} + +int32_t TrueTypeFontResource::GetTableTags( + const PP_ArrayOutput& output, + scoped_refptr<TrackedCallback> callback) { + Call<PpapiPluginMsg_TrueTypeFont_GetTableTagsReply>(RENDERER, + PpapiHostMsg_TrueTypeFont_GetTableTags(), + base::Bind(&TrueTypeFontResource::OnPluginMsgGetTableTagsComplete, this, + callback, output)); + return PP_OK_COMPLETIONPENDING; +} + +int32_t TrueTypeFontResource::GetTable( + uint32_t table, + int32_t offset, + int32_t max_data_length, + const PP_ArrayOutput& output, + scoped_refptr<TrackedCallback> callback) { + Call<PpapiPluginMsg_TrueTypeFont_GetTableReply>(RENDERER, + PpapiHostMsg_TrueTypeFont_GetTable(table, offset, max_data_length), + base::Bind(&TrueTypeFontResource::OnPluginMsgGetTableComplete, this, + callback, output)); + return PP_OK_COMPLETIONPENDING; +} + +void TrueTypeFontResource::OnPluginMsgDescribeComplete( + scoped_refptr<TrackedCallback> callback, + PP_TrueTypeFontDesc_Dev* pp_desc, + const ResourceMessageReplyParams& params, + const ppapi::proxy::SerializedTrueTypeFontDesc& desc) { + int32_t result = params.result(); + if (result == PP_OK) + desc.CopyToPPTrueTypeFontDesc(pp_desc); + callback->Run(result); +} + +void TrueTypeFontResource::OnPluginMsgGetTableTagsComplete( + scoped_refptr<TrackedCallback> callback, + PP_ArrayOutput array_output, + const ResourceMessageReplyParams& params, + const std::vector<uint32_t>& tag_array) { + // The result code should contain the data size if it's positive. + int32_t result = params.result(); + DCHECK((result < 0 && tag_array.size() == 0) || + result == static_cast<int32_t>(tag_array.size())); + + ArrayWriter output; + output.set_pp_array_output(array_output); + if (output.is_valid()) + output.StoreArray(&tag_array[0], std::max(0, result)); + else + result = PP_ERROR_FAILED; + + callback->Run(result); +} + +void TrueTypeFontResource::OnPluginMsgGetTableComplete( + scoped_refptr<TrackedCallback> callback, + PP_ArrayOutput array_output, + const ResourceMessageReplyParams& params, + const std::string& data) { + // The result code should contain the data size if it's positive. + int32_t result = params.result(); + DCHECK((result < 0 && data.size() == 0) || + result == static_cast<int32_t>(data.size())); + + ArrayWriter output; + output.set_pp_array_output(array_output); + if (output.is_valid()) + output.StoreArray(data.data(), std::max(0, result)); + else + result = PP_ERROR_FAILED; + + callback->Run(result); +} + +} // namespace proxy +} // namespace ppapi diff --git a/ppapi/proxy/truetype_font_resource.h b/ppapi/proxy/truetype_font_resource.h new file mode 100644 index 0000000..6aac2d5 --- /dev/null +++ b/ppapi/proxy/truetype_font_resource.h @@ -0,0 +1,73 @@ +// Copyright (c) 2013 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_TRUETYPE_FONT_RESOURCE_H_ +#define PPAPI_PROXY_TRUETYPE_FONT_RESOURCE_H_ + +#include <string> + +#include "ppapi/proxy/connection.h" +#include "ppapi/proxy/plugin_resource.h" +#include "ppapi/proxy/ppapi_proxy_export.h" +#include "ppapi/shared_impl/var.h" +#include "ppapi/thunk/ppb_truetype_font_api.h" + +namespace ppapi { + +class TrackedCallback; + +namespace proxy { + +struct SerializedTrueTypeFontDesc; + +class PPAPI_PROXY_EXPORT TrueTypeFontResource + : public PluginResource, + public thunk::PPB_TrueTypeFont_API { + public: + TrueTypeFontResource(Connection connection, + PP_Instance instance, + const PP_TrueTypeFontDesc_Dev& desc); + virtual ~TrueTypeFontResource(); + + // Resource overrides. + virtual thunk::PPB_TrueTypeFont_API* AsPPB_TrueTypeFont_API() OVERRIDE; + + // PPB_TrueTypeFont_API implementation. + virtual int32_t Describe( + PP_TrueTypeFontDesc_Dev* desc, + scoped_refptr<TrackedCallback> callback) OVERRIDE; + virtual int32_t GetTableTags( + const PP_ArrayOutput& output, + scoped_refptr<TrackedCallback> callback) OVERRIDE; + virtual int32_t GetTable( + uint32_t table, + int32_t offset, + int32_t max_data_length, + const PP_ArrayOutput& output, + scoped_refptr<TrackedCallback> callback) OVERRIDE; + + private: + void OnPluginMsgDescribeComplete( + scoped_refptr<TrackedCallback> callback, + PP_TrueTypeFontDesc_Dev* pp_desc, + const ResourceMessageReplyParams& params, + const ppapi::proxy::SerializedTrueTypeFontDesc& desc); + void OnPluginMsgGetTableTagsComplete( + scoped_refptr<TrackedCallback> callback, + PP_ArrayOutput array_output, + const ResourceMessageReplyParams& params, + const std::vector<uint32_t>& data); + void OnPluginMsgGetTableComplete( + scoped_refptr<TrackedCallback> callback, + PP_ArrayOutput array_output, + const ResourceMessageReplyParams& params, + const std::string& data); + + DISALLOW_COPY_AND_ASSIGN(TrueTypeFontResource); +}; + +} // namespace proxy +} // namespace ppapi + +#endif // PPAPI_PROXY_TRUETYPE_FONT_RESOURCE_H_ diff --git a/ppapi/proxy/truetype_font_singleton_resource.cc b/ppapi/proxy/truetype_font_singleton_resource.cc new file mode 100644 index 0000000..b812bf1 --- /dev/null +++ b/ppapi/proxy/truetype_font_singleton_resource.cc @@ -0,0 +1,68 @@ +// Copyright (c) 2013 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/truetype_font_singleton_resource.h" + +#include "ppapi/proxy/ppapi_messages.h" +#include "ppapi/shared_impl/array_writer.h" +#include "ppapi/shared_impl/tracked_callback.h" +#include "ppapi/shared_impl/var.h" + +namespace ppapi { +namespace proxy { + +TrueTypeFontSingletonResource::TrueTypeFontSingletonResource( + Connection connection, + PP_Instance instance) + : PluginResource(connection, instance) { + SendCreate(BROWSER, PpapiHostMsg_TrueTypeFontSingleton_Create()); +} + +TrueTypeFontSingletonResource::~TrueTypeFontSingletonResource() { +} + +thunk::PPB_TrueTypeFont_Singleton_API* +TrueTypeFontSingletonResource::AsPPB_TrueTypeFont_Singleton_API() { + return this; +} + +int32_t TrueTypeFontSingletonResource::GetFontFamilies( + PP_Instance instance, + const PP_ArrayOutput& output, + const scoped_refptr<TrackedCallback>& callback) { + Call<PpapiPluginMsg_TrueTypeFontSingleton_GetFontFamiliesReply>(BROWSER, + PpapiHostMsg_TrueTypeFontSingleton_GetFontFamilies(), + base::Bind( + &TrueTypeFontSingletonResource::OnPluginMsgGetFontFamiliesComplete, + this, callback, output)); + return PP_OK_COMPLETIONPENDING; +} + +void TrueTypeFontSingletonResource::OnPluginMsgGetFontFamiliesComplete( + scoped_refptr<TrackedCallback> callback, + PP_ArrayOutput array_output, + const ResourceMessageReplyParams& params, + const std::vector<std::string>& font_families) { + // The result code should contain the data size if it's positive. + int32_t result = params.result(); + DCHECK((result < 0 && font_families.size() == 0) || + result == static_cast<int32_t>(font_families.size())); + + ArrayWriter output; + output.set_pp_array_output(array_output); + if (output.is_valid()) { + std::vector< scoped_refptr<Var> > font_family_vars; + for (size_t i = 0; i < font_families.size(); i++) + font_family_vars.push_back( + scoped_refptr<Var>(new StringVar(font_families[i]))); + output.StoreVarVector(font_family_vars); + } else { + result = PP_ERROR_FAILED; + } + + callback->Run(result); +} + +} // namespace proxy +} // namespace ppapi diff --git a/ppapi/proxy/truetype_font_singleton_resource.h b/ppapi/proxy/truetype_font_singleton_resource.h new file mode 100644 index 0000000..03c9c7d --- /dev/null +++ b/ppapi/proxy/truetype_font_singleton_resource.h @@ -0,0 +1,55 @@ +// Copyright (c) 2013 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_TRUETYPE_FONT_SINGLETON_RESOURCE_H_ +#define PPAPI_PROXY_TRUETYPE_FONT_SINGLETON_RESOURCE_H_ + +#include <string> +#include <vector> + +#include "ppapi/proxy/connection.h" +#include "ppapi/proxy/plugin_resource.h" +#include "ppapi/thunk/ppb_truetype_font_singleton_api.h" + +namespace ppapi { + +class TrackedCallback; + +namespace proxy { + +struct SerializedTrueTypeFontDescription; + +// This handles the singleton calls (that don't take a PP_Resource parameter) +// on the TrueType font interface. +class TrueTypeFontSingletonResource + : public PluginResource, + public thunk::PPB_TrueTypeFont_Singleton_API { + public: + TrueTypeFontSingletonResource(Connection connection, PP_Instance instance); + virtual ~TrueTypeFontSingletonResource(); + + // Resource override. + virtual thunk::PPB_TrueTypeFont_Singleton_API* + AsPPB_TrueTypeFont_Singleton_API() OVERRIDE; + + // thunk::PPB_TrueTypeFont_Singleton_API implementation. + virtual int32_t GetFontFamilies( + PP_Instance instance, + const PP_ArrayOutput& output, + const scoped_refptr<TrackedCallback>& callback) OVERRIDE; + + private: + void OnPluginMsgGetFontFamiliesComplete( + scoped_refptr<TrackedCallback> callback, + PP_ArrayOutput array_output, + const ResourceMessageReplyParams& params, + const std::vector<std::string>& data); + + DISALLOW_COPY_AND_ASSIGN(TrueTypeFontSingletonResource); +}; + +} // namespace proxy +} // namespace ppapi + +#endif // PPAPI_PROXY_TRUETYPE_FONT_SINGLETON_RESOURCE_H_ |