| Index: ppapi/proxy/truetype_font_resource.cc
|
| diff --git a/ppapi/proxy/truetype_font_resource.cc b/ppapi/proxy/truetype_font_resource.cc
|
| index 1de32abb434a38752207fa5d3a31b6cf3ba77636..a7d99f7b2a3ab908bfca30b528361f0e329ada51 100644
|
| --- a/ppapi/proxy/truetype_font_resource.cc
|
| +++ b/ppapi/proxy/truetype_font_resource.cc
|
| @@ -24,14 +24,40 @@ namespace {
|
| namespace ppapi {
|
| namespace proxy {
|
|
|
| -TrueTypeFontResource::TrueTypeFontResource(
|
| - Connection connection,
|
| - PP_Instance instance,
|
| - const PP_TrueTypeFontDesc_Dev& desc)
|
| - : PluginResource(connection, instance) {
|
| +TrueTypeFontResource::FontOp::FontOp(PP_TrueTypeFontDesc_Dev* desc,
|
| + scoped_refptr<TrackedCallback> callback)
|
| + : type(DESCRIBE), callback(callback), desc(desc) {
|
| +}
|
| +
|
| +TrueTypeFontResource::FontOp::FontOp(const PP_ArrayOutput& output,
|
| + scoped_refptr<TrackedCallback> callback)
|
| + : type(GET_TABLE_TAGS), callback(callback), output(output) {
|
| +}
|
| +
|
| +TrueTypeFontResource::FontOp::FontOp(uint32_t table,
|
| + int32_t offset,
|
| + int32_t max_data_length,
|
| + const PP_ArrayOutput& output,
|
| + scoped_refptr<TrackedCallback> callback)
|
| + : type(GET_TABLE),
|
| + callback(callback),
|
| + output(output),
|
| + table(table),
|
| + offset(offset),
|
| + max_data_length(max_data_length) {
|
| +}
|
| +
|
| +TrueTypeFontResource::FontOp::~FontOp() {
|
| +}
|
| +
|
| +TrueTypeFontResource::TrueTypeFontResource(Connection connection,
|
| + PP_Instance instance,
|
| + const PP_TrueTypeFontDesc_Dev& desc)
|
| + : PluginResource(connection, instance),
|
| + create_result_(PP_OK_COMPLETIONPENDING) {
|
| SerializedTrueTypeFontDesc serialized_desc;
|
| serialized_desc.SetFromPPTrueTypeFontDesc(desc);
|
| - SendCreate(RENDERER, PpapiHostMsg_TrueTypeFont_Create(serialized_desc));
|
| + SendCreate(BROWSER, PpapiHostMsg_TrueTypeFont_Create(serialized_desc));
|
| }
|
|
|
| TrueTypeFontResource::~TrueTypeFontResource() {
|
| @@ -44,21 +70,32 @@ 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,
|
| - callback, desc));
|
| - return PP_OK_COMPLETIONPENDING;
|
| + if (create_result_ == PP_OK) {
|
| + desc_.CopyToPPTrueTypeFontDesc(desc);
|
| + return PP_OK;
|
| + }
|
| + if (create_result_ == PP_OK_COMPLETIONPENDING) {
|
| + pending_font_ops_.push(FontOp(desc, callback));
|
| + return PP_OK_COMPLETIONPENDING;
|
| + }
|
| +
|
| + return PP_ERROR_FAILED;
|
| }
|
|
|
| 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;
|
| + FontOp op(output, callback);
|
| + if (create_result_ == PP_OK) {
|
| + RunFontOp(op);
|
| + return PP_OK_COMPLETIONPENDING;
|
| + }
|
| + if (create_result_ == PP_OK_COMPLETIONPENDING) {
|
| + pending_font_ops_.push(op);
|
| + return PP_OK_COMPLETIONPENDING;
|
| + }
|
| +
|
| + return PP_ERROR_FAILED;
|
| }
|
|
|
| int32_t TrueTypeFontResource::GetTable(
|
| @@ -67,23 +104,45 @@ int32_t TrueTypeFontResource::GetTable(
|
| 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;
|
| + FontOp op(table, offset, max_data_length, output, callback);
|
| + if (create_result_ == PP_OK) {
|
| + RunFontOp(op);
|
| + return PP_OK_COMPLETIONPENDING;
|
| + }
|
| + if (create_result_ == PP_OK_COMPLETIONPENDING) {
|
| + pending_font_ops_.push(op);
|
| + return PP_OK_COMPLETIONPENDING;
|
| + }
|
| +
|
| + return PP_ERROR_FAILED;
|
| }
|
|
|
| -void TrueTypeFontResource::OnPluginMsgDescribeComplete(
|
| - scoped_refptr<TrackedCallback> callback,
|
| - PP_TrueTypeFontDesc_Dev* pp_desc,
|
| +void TrueTypeFontResource::OnReplyReceived(
|
| const ResourceMessageReplyParams& params,
|
| - const ppapi::proxy::SerializedTrueTypeFontDesc& desc) {
|
| - int32_t result = params.result();
|
| - if (result == PP_OK)
|
| - desc.CopyToPPTrueTypeFontDesc(pp_desc);
|
| + const IPC::Message& msg) {
|
| + PPAPI_BEGIN_MESSAGE_MAP(TrueTypeFontResource, msg)
|
| + PPAPI_DISPATCH_PLUGIN_RESOURCE_CALL(PpapiPluginMsg_TrueTypeFont_CreateReply,
|
| + OnPluginMsgCreateComplete)
|
| + PPAPI_DISPATCH_PLUGIN_RESOURCE_CALL_UNHANDLED(
|
| + PluginResource::OnReplyReceived(params, msg))
|
| + PPAPI_END_MESSAGE_MAP()
|
| +}
|
|
|
| - callback->Run(result);
|
| +void TrueTypeFontResource::OnPluginMsgCreateComplete(
|
| + const ResourceMessageReplyParams& params,
|
| + const ppapi::proxy::SerializedTrueTypeFontDesc& desc,
|
| + int32_t result) {
|
| + DCHECK(result != PP_OK_COMPLETIONPENDING);
|
| + DCHECK(create_result_ == PP_OK_COMPLETIONPENDING);
|
| + create_result_ = result;
|
| + if (create_result_ == PP_OK)
|
| + desc_ = desc;
|
| +
|
| + // Now run any pending font operations.
|
| + while (!pending_font_ops_.empty()) {
|
| + RunFontOp(pending_font_ops_.front());
|
| + pending_font_ops_.pop();
|
| + }
|
| }
|
|
|
| void TrueTypeFontResource::OnPluginMsgGetTableTagsComplete(
|
| @@ -126,5 +185,36 @@ void TrueTypeFontResource::OnPluginMsgGetTableComplete(
|
| callback->Run(result);
|
| }
|
|
|
| +void TrueTypeFontResource::RunFontOp(const FontOp& op) {
|
| + switch (op.type) {
|
| + case FontOp::DESCRIBE:
|
| + if (create_result_ == PP_OK && TrackedCallback::IsPending(op.callback)) {
|
| + desc_.CopyToPPTrueTypeFontDesc(op.desc);
|
| + op.callback->Run(create_result_);
|
| + }
|
| + break;
|
| + case FontOp::GET_TABLE_TAGS:
|
| + Call<PpapiPluginMsg_TrueTypeFont_GetTableTagsReply>(
|
| + BROWSER,
|
| + PpapiHostMsg_TrueTypeFont_GetTableTags(),
|
| + base::Bind(&TrueTypeFontResource::OnPluginMsgGetTableTagsComplete,
|
| + this,
|
| + op.callback,
|
| + op.output));
|
| + break;
|
| + case FontOp::GET_TABLE:
|
| + Call<PpapiPluginMsg_TrueTypeFont_GetTableReply>(
|
| + BROWSER,
|
| + PpapiHostMsg_TrueTypeFont_GetTable(
|
| + op.table, op.offset, op.max_data_length),
|
| + base::Bind(&TrueTypeFontResource::OnPluginMsgGetTableComplete,
|
| + this,
|
| + op.callback,
|
| + op.output));
|
| + break;
|
| + // No default case, to catch unhandled op types.
|
| + }
|
| +}
|
| +
|
| } // namespace proxy
|
| } // namespace ppapi
|
|
|