• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #include "ppapi/proxy/truetype_font_resource.h"
6 
7 #include "base/bind.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"
16 
17 using ppapi::thunk::EnterResourceNoLock;
18 using ppapi::thunk::PPB_TrueTypeFont_API;
19 
20 namespace {
21 
22 }  // namespace
23 
24 namespace ppapi {
25 namespace proxy {
26 
TrueTypeFontResource(Connection connection,PP_Instance instance,const PP_TrueTypeFontDesc_Dev & desc)27 TrueTypeFontResource::TrueTypeFontResource(
28     Connection connection,
29     PP_Instance instance,
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));
35 }
36 
~TrueTypeFontResource()37 TrueTypeFontResource::~TrueTypeFontResource() {
38 }
39 
AsPPB_TrueTypeFont_API()40 PPB_TrueTypeFont_API* TrueTypeFontResource::AsPPB_TrueTypeFont_API() {
41   return this;
42 }
43 
Describe(PP_TrueTypeFontDesc_Dev * desc,scoped_refptr<TrackedCallback> callback)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,
50                  callback, desc));
51   return PP_OK_COMPLETIONPENDING;
52 }
53 
GetTableTags(const PP_ArrayOutput & output,scoped_refptr<TrackedCallback> callback)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,
60                  callback, output));
61   return PP_OK_COMPLETIONPENDING;
62 }
63 
GetTable(uint32_t table,int32_t offset,int32_t max_data_length,const PP_ArrayOutput & output,scoped_refptr<TrackedCallback> callback)64 int32_t TrueTypeFontResource::GetTable(
65     uint32_t table,
66     int32_t offset,
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,
73                  callback, output));
74   return PP_OK_COMPLETIONPENDING;
75 }
76 
OnPluginMsgDescribeComplete(scoped_refptr<TrackedCallback> callback,PP_TrueTypeFontDesc_Dev * pp_desc,const ResourceMessageReplyParams & params,const ppapi::proxy::SerializedTrueTypeFontDesc & desc)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();
83   if (result == PP_OK)
84     desc.CopyToPPTrueTypeFontDesc(pp_desc);
85 
86   callback->Run(result);
87 }
88 
OnPluginMsgGetTableTagsComplete(scoped_refptr<TrackedCallback> callback,PP_ArrayOutput array_output,const ResourceMessageReplyParams & params,const std::vector<uint32_t> & tag_array)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()));
98 
99   ArrayWriter output;
100   output.set_pp_array_output(array_output);
101   if (output.is_valid())
102     output.StoreArray(&tag_array[0], std::max(0, result));
103   else
104     result = PP_ERROR_FAILED;
105 
106   callback->Run(result);
107 }
108 
OnPluginMsgGetTableComplete(scoped_refptr<TrackedCallback> callback,PP_ArrayOutput array_output,const ResourceMessageReplyParams & params,const std::string & data)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()));
118 
119   ArrayWriter output;
120   output.set_pp_array_output(array_output);
121   if (output.is_valid())
122     output.StoreArray(data.data(), std::max(0, result));
123   else
124     result = PP_ERROR_FAILED;
125 
126   callback->Run(result);
127 }
128 
129 }  // namespace proxy
130 }  // namespace ppapi
131