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 "ppapi/proxy/truetype_font_resource.h"
8 #include "ipc/ipc_message.h"
9 #include "ppapi/c/pp_errors.h"
10 #include "ppapi/proxy/ppapi_messages.h"
11 #include "ppapi/shared_impl/array_writer.h"
12 #include "ppapi/shared_impl/ppapi_globals.h"
13 #include "ppapi/shared_impl/resource_tracker.h"
14 #include "ppapi/shared_impl/var.h"
15 #include "ppapi/thunk/enter.h"
17 using ppapi::thunk::EnterResourceNoLock
;
18 using ppapi::thunk::PPB_TrueTypeFont_API
;
27 TrueTypeFontResource::TrueTypeFontResource(
28 Connection connection
,
30 const PP_TrueTypeFontDesc_Dev
& desc
)
31 : PluginResource(connection
, instance
) {
32 SerializedTrueTypeFontDesc serialized_desc
;
33 serialized_desc
.SetFromPPTrueTypeFontDesc(desc
);
34 SendCreate(RENDERER
, PpapiHostMsg_TrueTypeFont_Create(serialized_desc
));
37 TrueTypeFontResource::~TrueTypeFontResource() {
40 PPB_TrueTypeFont_API
* TrueTypeFontResource::AsPPB_TrueTypeFont_API() {
44 int32_t TrueTypeFontResource::Describe(
45 PP_TrueTypeFontDesc_Dev
* desc
,
46 scoped_refptr
<TrackedCallback
> callback
) {
47 Call
<PpapiPluginMsg_TrueTypeFont_DescribeReply
>(RENDERER
,
48 PpapiHostMsg_TrueTypeFont_Describe(),
49 base::Bind(&TrueTypeFontResource::OnPluginMsgDescribeComplete
, this,
51 return PP_OK_COMPLETIONPENDING
;
54 int32_t TrueTypeFontResource::GetTableTags(
55 const PP_ArrayOutput
& output
,
56 scoped_refptr
<TrackedCallback
> callback
) {
57 Call
<PpapiPluginMsg_TrueTypeFont_GetTableTagsReply
>(RENDERER
,
58 PpapiHostMsg_TrueTypeFont_GetTableTags(),
59 base::Bind(&TrueTypeFontResource::OnPluginMsgGetTableTagsComplete
, this,
61 return PP_OK_COMPLETIONPENDING
;
64 int32_t TrueTypeFontResource::GetTable(
67 int32_t max_data_length
,
68 const PP_ArrayOutput
& output
,
69 scoped_refptr
<TrackedCallback
> callback
) {
70 Call
<PpapiPluginMsg_TrueTypeFont_GetTableReply
>(RENDERER
,
71 PpapiHostMsg_TrueTypeFont_GetTable(table
, offset
, max_data_length
),
72 base::Bind(&TrueTypeFontResource::OnPluginMsgGetTableComplete
, this,
74 return PP_OK_COMPLETIONPENDING
;
77 void TrueTypeFontResource::OnPluginMsgDescribeComplete(
78 scoped_refptr
<TrackedCallback
> callback
,
79 PP_TrueTypeFontDesc_Dev
* pp_desc
,
80 const ResourceMessageReplyParams
& params
,
81 const ppapi::proxy::SerializedTrueTypeFontDesc
& desc
) {
82 int32_t result
= params
.result();
84 desc
.CopyToPPTrueTypeFontDesc(pp_desc
);
86 callback
->Run(result
);
89 void TrueTypeFontResource::OnPluginMsgGetTableTagsComplete(
90 scoped_refptr
<TrackedCallback
> callback
,
91 PP_ArrayOutput array_output
,
92 const ResourceMessageReplyParams
& params
,
93 const std::vector
<uint32_t>& tag_array
) {
94 // The result code should contain the data size if it's positive.
95 int32_t result
= params
.result();
96 DCHECK((result
< 0 && tag_array
.size() == 0) ||
97 result
== static_cast<int32_t>(tag_array
.size()));
100 output
.set_pp_array_output(array_output
);
101 if (output
.is_valid())
102 output
.StoreArray(&tag_array
[0], std::max(0, result
));
104 result
= PP_ERROR_FAILED
;
106 callback
->Run(result
);
109 void TrueTypeFontResource::OnPluginMsgGetTableComplete(
110 scoped_refptr
<TrackedCallback
> callback
,
111 PP_ArrayOutput array_output
,
112 const ResourceMessageReplyParams
& params
,
113 const std::string
& data
) {
114 // The result code should contain the data size if it's positive.
115 int32_t result
= params
.result();
116 DCHECK((result
< 0 && data
.size() == 0) ||
117 result
== static_cast<int32_t>(data
.size()));
120 output
.set_pp_array_output(array_output
);
121 if (output
.is_valid())
122 output
.StoreArray(data
.data(), std::max(0, result
));
124 result
= PP_ERROR_FAILED
;
126 callback
->Run(result
);