diff options
author | bbudge@chromium.org <bbudge@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-19 03:50:35 +0000 |
---|---|---|
committer | bbudge@chromium.org <bbudge@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-19 03:50:35 +0000 |
commit | 720e1e622e14c79677bbe27604e6638bf294ec4d (patch) | |
tree | b120d55625d4836bd5b21d190d519b497bb12471 /ppapi/proxy | |
parent | 76de6d1c423858d6e3bae517fcff0c8cddf1a090 (diff) | |
download | chromium_src-720e1e622e14c79677bbe27604e6638bf294ec4d.zip chromium_src-720e1e622e14c79677bbe27604e6638bf294ec4d.tar.gz chromium_src-720e1e622e14c79677bbe27604e6638bf294ec4d.tar.bz2 |
Add Pepper TrueType font API call to enumerate fonts in a given family.
Adds a new function, GetFontsInFamily, to the PPB_TrueTypeFont_Dev interface.
This method returns an array of descriptors for every font in the given family
on the host platform.
Tests are currently disabled for Windows and Mac, since I got failures on XP and OSX 10.6 when landing them originally. I will re-enable them in follow on patches, which will be easier to land / revert if necessary. The tests pass locally for me on all platforms.
BUG=79375,230130
TEST=browser_tests, gtest_filter="PPAPIOutOfProcessTest.TrueTypeFont"
Review URL: https://chromiumcodereview.appspot.com/13913006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@195082 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi/proxy')
-rw-r--r-- | ppapi/proxy/ppapi_messages.h | 5 | ||||
-rw-r--r-- | ppapi/proxy/truetype_font_resource.cc | 2 | ||||
-rw-r--r-- | ppapi/proxy/truetype_font_singleton_resource.cc | 53 | ||||
-rw-r--r-- | ppapi/proxy/truetype_font_singleton_resource.h | 12 |
4 files changed, 70 insertions, 2 deletions
diff --git a/ppapi/proxy/ppapi_messages.h b/ppapi/proxy/ppapi_messages.h index 78f9eda..42ef363 100644 --- a/ppapi/proxy/ppapi_messages.h +++ b/ppapi/proxy/ppapi_messages.h @@ -1445,6 +1445,11 @@ 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_TrueTypeFontSingleton_GetFontsInFamily, + std::string /* family */) +IPC_MESSAGE_CONTROL1(PpapiPluginMsg_TrueTypeFontSingleton_GetFontsInFamilyReply, + std::vector<ppapi::proxy::SerializedTrueTypeFontDesc> + /* fonts */) IPC_MESSAGE_CONTROL1(PpapiHostMsg_TrueTypeFont_Create, ppapi::proxy::SerializedTrueTypeFontDesc /* desc */) IPC_MESSAGE_CONTROL0(PpapiHostMsg_TrueTypeFont_Describe) diff --git a/ppapi/proxy/truetype_font_resource.cc b/ppapi/proxy/truetype_font_resource.cc index 0b07195..1de32abb 100644 --- a/ppapi/proxy/truetype_font_resource.cc +++ b/ppapi/proxy/truetype_font_resource.cc @@ -44,7 +44,6 @@ PPB_TrueTypeFont_API* TrueTypeFontResource::AsPPB_TrueTypeFont_API() { 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, @@ -83,6 +82,7 @@ void TrueTypeFontResource::OnPluginMsgDescribeComplete( int32_t result = params.result(); if (result == PP_OK) desc.CopyToPPTrueTypeFontDesc(pp_desc); + callback->Run(result); } diff --git a/ppapi/proxy/truetype_font_singleton_resource.cc b/ppapi/proxy/truetype_font_singleton_resource.cc index b812bf1..1fee97b 100644 --- a/ppapi/proxy/truetype_font_singleton_resource.cc +++ b/ppapi/proxy/truetype_font_singleton_resource.cc @@ -5,9 +5,12 @@ #include "ppapi/proxy/truetype_font_singleton_resource.h" #include "ppapi/proxy/ppapi_messages.h" +#include "ppapi/proxy/serialized_structs.h" #include "ppapi/shared_impl/array_writer.h" +#include "ppapi/shared_impl/ppapi_globals.h" #include "ppapi/shared_impl/tracked_callback.h" #include "ppapi/shared_impl/var.h" +#include "ppapi/shared_impl/var_tracker.h" namespace ppapi { namespace proxy { @@ -39,11 +42,30 @@ int32_t TrueTypeFontSingletonResource::GetFontFamilies( return PP_OK_COMPLETIONPENDING; } +int32_t TrueTypeFontSingletonResource::GetFontsInFamily( + PP_Instance instance, + PP_Var family, + const PP_ArrayOutput& output, + const scoped_refptr<TrackedCallback>& callback) { + scoped_refptr<StringVar> family_var = StringVar::FromPPVar(family); + const uint32_t kMaxFamilySizeInBytes = 1024; + if (!family_var || family_var->value().size() > kMaxFamilySizeInBytes) + return PP_ERROR_BADARGUMENT; + Call<PpapiPluginMsg_TrueTypeFontSingleton_GetFontsInFamilyReply>(BROWSER, + PpapiHostMsg_TrueTypeFontSingleton_GetFontsInFamily(family_var->value()), + base::Bind( + &TrueTypeFontSingletonResource::OnPluginMsgGetFontsInFamilyComplete, + 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) { + if (!TrackedCallback::IsPending(callback)) + return; // The result code should contain the data size if it's positive. int32_t result = params.result(); DCHECK((result < 0 && font_families.size() == 0) || @@ -64,5 +86,36 @@ void TrueTypeFontSingletonResource::OnPluginMsgGetFontFamiliesComplete( callback->Run(result); } +void TrueTypeFontSingletonResource::OnPluginMsgGetFontsInFamilyComplete( + scoped_refptr<TrackedCallback> callback, + PP_ArrayOutput array_output, + const ResourceMessageReplyParams& params, + const std::vector<SerializedTrueTypeFontDesc>& fonts) { + if (!TrackedCallback::IsPending(callback)) + return; + // The result code should contain the data size if it's positive. + int32_t result = params.result(); + DCHECK((result < 0 && fonts.size() == 0) || + result == static_cast<int32_t>(fonts.size())); + ArrayWriter output; + output.set_pp_array_output(array_output); + if (output.is_valid()) { + // Convert the message data to an array of PP_TrueTypeFontDesc_Dev structs. + // Each desc has an embedded PP_Var containing the family name. + std::vector<PP_TrueTypeFontDesc_Dev> pp_fonts(fonts.size()); + for (size_t i = 0; i < fonts.size(); i++) + fonts[i].CopyToPPTrueTypeFontDesc(&pp_fonts[i]); + + if (!output.StoreVector(pp_fonts)) { + for (size_t i = 0; i < pp_fonts.size(); i++) + PpapiGlobals::Get()->GetVarTracker()->ReleaseVar(pp_fonts[i].family); + } + } 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 index 03c9c7d..dee5863 100644 --- a/ppapi/proxy/truetype_font_singleton_resource.h +++ b/ppapi/proxy/truetype_font_singleton_resource.h @@ -18,7 +18,7 @@ class TrackedCallback; namespace proxy { -struct SerializedTrueTypeFontDescription; +struct SerializedTrueTypeFontDesc; // This handles the singleton calls (that don't take a PP_Resource parameter) // on the TrueType font interface. @@ -38,6 +38,11 @@ class TrueTypeFontSingletonResource PP_Instance instance, const PP_ArrayOutput& output, const scoped_refptr<TrackedCallback>& callback) OVERRIDE; + virtual int32_t GetFontsInFamily( + PP_Instance instance, + PP_Var family, + const PP_ArrayOutput& output, + const scoped_refptr<TrackedCallback>& callback) OVERRIDE; private: void OnPluginMsgGetFontFamiliesComplete( @@ -45,6 +50,11 @@ class TrueTypeFontSingletonResource PP_ArrayOutput array_output, const ResourceMessageReplyParams& params, const std::vector<std::string>& data); + void OnPluginMsgGetFontsInFamilyComplete( + scoped_refptr<TrackedCallback> callback, + PP_ArrayOutput array_output, + const ResourceMessageReplyParams& params, + const std::vector<SerializedTrueTypeFontDesc>& fonts); DISALLOW_COPY_AND_ASSIGN(TrueTypeFontSingletonResource); }; |