1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/renderer/pepper/pepper_truetype_font_host.h"
8 #include "content/public/renderer/renderer_ppapi_host.h"
9 #include "content/renderer/pepper/pepper_truetype_font.h"
10 #include "ppapi/c/pp_errors.h"
11 #include "ppapi/host/dispatch_host_message.h"
12 #include "ppapi/host/host_message_context.h"
13 #include "ppapi/host/ppapi_host.h"
14 #include "ppapi/proxy/ppapi_messages.h"
16 using ppapi::host::HostMessageContext;
17 using ppapi::host::ReplyMessageContext;
21 PepperTrueTypeFontHost::PepperTrueTypeFontHost(
22 RendererPpapiHost* host,
25 const ppapi::proxy::SerializedTrueTypeFontDesc& desc)
26 : ResourceHost(host->GetPpapiHost(), instance, resource),
27 renderer_ppapi_host_(host),
28 font_(PepperTrueTypeFont::Create(desc)),
29 weak_factory_(this) {}
31 PepperTrueTypeFontHost::~PepperTrueTypeFontHost() {}
33 int32_t PepperTrueTypeFontHost::OnResourceMessageReceived(
34 const IPC::Message& msg,
35 HostMessageContext* context) {
36 if (!host()->permissions().HasPermission(ppapi::PERMISSION_DEV))
37 return PP_ERROR_FAILED;
39 PPAPI_BEGIN_MESSAGE_MAP(PepperTrueTypeFontHost, msg)
40 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_TrueTypeFont_Describe,
42 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_TrueTypeFont_GetTableTags,
43 OnHostMsgGetTableTags)
44 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_TrueTypeFont_GetTable,
46 PPAPI_END_MESSAGE_MAP()
47 return PP_ERROR_FAILED;
50 int32_t PepperTrueTypeFontHost::OnHostMsgDescribe(HostMessageContext* context) {
51 if (!font_->IsValid())
52 return PP_ERROR_FAILED;
54 ppapi::proxy::SerializedTrueTypeFontDesc desc;
55 ReplyMessageContext reply_context = context->MakeReplyMessageContext();
56 reply_context.params.set_result(font_->Describe(&desc));
57 host()->SendReply(reply_context,
58 PpapiPluginMsg_TrueTypeFont_DescribeReply(desc));
59 return PP_OK_COMPLETIONPENDING;
62 int32_t PepperTrueTypeFontHost::OnHostMsgGetTableTags(
63 HostMessageContext* context) {
64 if (!font_->IsValid())
65 return PP_ERROR_FAILED;
67 std::vector<uint32_t> tags;
68 ReplyMessageContext reply_context = context->MakeReplyMessageContext();
69 reply_context.params.set_result(font_->GetTableTags(&tags));
70 host()->SendReply(reply_context,
71 PpapiPluginMsg_TrueTypeFont_GetTableTagsReply(tags));
72 return PP_OK_COMPLETIONPENDING;
75 int32_t PepperTrueTypeFontHost::OnHostMsgGetTable(HostMessageContext* context,
78 int32_t max_data_length) {
79 if (!font_->IsValid())
80 return PP_ERROR_FAILED;
81 if (offset < 0 || max_data_length < 0)
82 return PP_ERROR_BADARGUMENT;
85 ReplyMessageContext reply_context = context->MakeReplyMessageContext();
86 reply_context.params.set_result(
87 font_->GetTable(table, offset, max_data_length, &data));
88 host()->SendReply(reply_context,
89 PpapiPluginMsg_TrueTypeFont_GetTableReply(data));
90 return PP_OK_COMPLETIONPENDING;
93 } // namespace content