12a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Copyright (c) 2013 The Chromium Authors. All rights reserved. 22a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 32a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// found in the LICENSE file. 42a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 52a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ppapi/proxy/truetype_font_resource.h" 62a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 72a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/bind.h" 82a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ipc/ipc_message.h" 92a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ppapi/c/pp_errors.h" 102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ppapi/proxy/ppapi_messages.h" 112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ppapi/shared_impl/array_writer.h" 122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ppapi/shared_impl/ppapi_globals.h" 132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ppapi/shared_impl/resource_tracker.h" 142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ppapi/shared_impl/var.h" 152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ppapi/thunk/enter.h" 162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)using ppapi::thunk::EnterResourceNoLock; 182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)using ppapi::thunk::PPB_TrueTypeFont_API; 192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace { 212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} // namespace 232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace ppapi { 252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace proxy { 262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TrueTypeFontResource::TrueTypeFontResource( 282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Connection connection, 292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) PP_Instance instance, 302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const PP_TrueTypeFontDesc_Dev& desc) 312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) : PluginResource(connection, instance) { 322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) SerializedTrueTypeFontDesc serialized_desc; 332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) serialized_desc.SetFromPPTrueTypeFontDesc(desc); 342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) SendCreate(RENDERER, PpapiHostMsg_TrueTypeFont_Create(serialized_desc)); 352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TrueTypeFontResource::~TrueTypeFontResource() { 382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)PPB_TrueTypeFont_API* TrueTypeFontResource::AsPPB_TrueTypeFont_API() { 412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return this; 422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)int32_t TrueTypeFontResource::Describe( 452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) PP_TrueTypeFontDesc_Dev* desc, 462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) scoped_refptr<TrackedCallback> callback) { 472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Call<PpapiPluginMsg_TrueTypeFont_DescribeReply>(RENDERER, 482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) PpapiHostMsg_TrueTypeFont_Describe(), 492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::Bind(&TrueTypeFontResource::OnPluginMsgDescribeComplete, this, 502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) callback, desc)); 512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return PP_OK_COMPLETIONPENDING; 522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)int32_t TrueTypeFontResource::GetTableTags( 552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const PP_ArrayOutput& output, 562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) scoped_refptr<TrackedCallback> callback) { 572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Call<PpapiPluginMsg_TrueTypeFont_GetTableTagsReply>(RENDERER, 582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) PpapiHostMsg_TrueTypeFont_GetTableTags(), 592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::Bind(&TrueTypeFontResource::OnPluginMsgGetTableTagsComplete, this, 602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) callback, output)); 612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return PP_OK_COMPLETIONPENDING; 622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)int32_t TrueTypeFontResource::GetTable( 652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) uint32_t table, 662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) int32_t offset, 672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) int32_t max_data_length, 682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const PP_ArrayOutput& output, 692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) scoped_refptr<TrackedCallback> callback) { 702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Call<PpapiPluginMsg_TrueTypeFont_GetTableReply>(RENDERER, 712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) PpapiHostMsg_TrueTypeFont_GetTable(table, offset, max_data_length), 722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::Bind(&TrueTypeFontResource::OnPluginMsgGetTableComplete, this, 732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) callback, output)); 742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return PP_OK_COMPLETIONPENDING; 752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void TrueTypeFontResource::OnPluginMsgDescribeComplete( 782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) scoped_refptr<TrackedCallback> callback, 792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) PP_TrueTypeFontDesc_Dev* pp_desc, 802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const ResourceMessageReplyParams& params, 812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const ppapi::proxy::SerializedTrueTypeFontDesc& desc) { 822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) int32_t result = params.result(); 832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (result == PP_OK) 842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) desc.CopyToPPTrueTypeFontDesc(pp_desc); 85c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) callback->Run(result); 872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void TrueTypeFontResource::OnPluginMsgGetTableTagsComplete( 902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) scoped_refptr<TrackedCallback> callback, 912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) PP_ArrayOutput array_output, 922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const ResourceMessageReplyParams& params, 932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const std::vector<uint32_t>& tag_array) { 942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // The result code should contain the data size if it's positive. 952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) int32_t result = params.result(); 962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DCHECK((result < 0 && tag_array.size() == 0) || 972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) result == static_cast<int32_t>(tag_array.size())); 982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ArrayWriter output; 1002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) output.set_pp_array_output(array_output); 1012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (output.is_valid()) 1022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) output.StoreArray(&tag_array[0], std::max(0, result)); 1032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) else 1042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) result = PP_ERROR_FAILED; 1052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) callback->Run(result); 1072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 1082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void TrueTypeFontResource::OnPluginMsgGetTableComplete( 1102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) scoped_refptr<TrackedCallback> callback, 1112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) PP_ArrayOutput array_output, 1122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const ResourceMessageReplyParams& params, 1132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const std::string& data) { 1142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // The result code should contain the data size if it's positive. 1152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) int32_t result = params.result(); 1162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DCHECK((result < 0 && data.size() == 0) || 1172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) result == static_cast<int32_t>(data.size())); 1182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ArrayWriter output; 1202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) output.set_pp_array_output(array_output); 1212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (output.is_valid()) 1222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) output.StoreArray(data.data(), std::max(0, result)); 1232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) else 1242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) result = PP_ERROR_FAILED; 1252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) callback->Run(result); 1272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 1282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} // namespace proxy 1302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} // namespace ppapi 131