Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(86)

Side by Side Diff: ppapi/proxy/truetype_font_resource.cc

Issue 337203003: Move PPB_TrueTypeFont_Dev host from renderer to browser. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add scopers, fix builds. Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ppapi/proxy/truetype_font_resource.h" 5 #include "ppapi/proxy/truetype_font_resource.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "ipc/ipc_message.h" 8 #include "ipc/ipc_message.h"
9 #include "ppapi/c/pp_errors.h" 9 #include "ppapi/c/pp_errors.h"
10 #include "ppapi/proxy/ppapi_messages.h" 10 #include "ppapi/proxy/ppapi_messages.h"
11 #include "ppapi/shared_impl/array_writer.h" 11 #include "ppapi/shared_impl/array_writer.h"
12 #include "ppapi/shared_impl/ppapi_globals.h" 12 #include "ppapi/shared_impl/ppapi_globals.h"
13 #include "ppapi/shared_impl/resource_tracker.h" 13 #include "ppapi/shared_impl/resource_tracker.h"
14 #include "ppapi/shared_impl/var.h" 14 #include "ppapi/shared_impl/var.h"
15 #include "ppapi/thunk/enter.h" 15 #include "ppapi/thunk/enter.h"
16 16
17 using ppapi::thunk::EnterResourceNoLock; 17 using ppapi::thunk::EnterResourceNoLock;
18 using ppapi::thunk::PPB_TrueTypeFont_API; 18 using ppapi::thunk::PPB_TrueTypeFont_API;
19 19
20 namespace { 20 namespace {
21 21
22 } // namespace 22 } // namespace
23 23
24 namespace ppapi { 24 namespace ppapi {
25 namespace proxy { 25 namespace proxy {
26 26
27 TrueTypeFontResource::TrueTypeFontResource( 27 TrueTypeFontResource::FontOp::FontOp(PP_TrueTypeFontDesc_Dev* desc,
28 Connection connection, 28 scoped_refptr<TrackedCallback> callback)
29 PP_Instance instance, 29 : type(DESCRIBE), callback(callback), desc(desc) {
30 const PP_TrueTypeFontDesc_Dev& desc) 30 }
31 : PluginResource(connection, instance) { 31
32 TrueTypeFontResource::FontOp::FontOp(const PP_ArrayOutput& output,
33 scoped_refptr<TrackedCallback> callback)
34 : type(GET_TABLE_TAGS), callback(callback), output(output) {
35 }
36
37 TrueTypeFontResource::FontOp::FontOp(uint32_t table,
38 int32_t offset,
39 int32_t max_data_length,
40 const PP_ArrayOutput& output,
41 scoped_refptr<TrackedCallback> callback)
42 : type(GET_TABLE),
43 callback(callback),
44 output(output),
45 table(table),
46 offset(offset),
47 max_data_length(max_data_length) {
48 }
49
50 TrueTypeFontResource::FontOp::~FontOp() {
51 }
52
53 TrueTypeFontResource::TrueTypeFontResource(Connection connection,
54 PP_Instance instance,
55 const PP_TrueTypeFontDesc_Dev& desc)
56 : PluginResource(connection, instance),
57 create_result_(PP_OK_COMPLETIONPENDING) {
32 SerializedTrueTypeFontDesc serialized_desc; 58 SerializedTrueTypeFontDesc serialized_desc;
33 serialized_desc.SetFromPPTrueTypeFontDesc(desc); 59 serialized_desc.SetFromPPTrueTypeFontDesc(desc);
34 SendCreate(RENDERER, PpapiHostMsg_TrueTypeFont_Create(serialized_desc)); 60 SendCreate(BROWSER, PpapiHostMsg_TrueTypeFont_Create(serialized_desc));
35 } 61 }
36 62
37 TrueTypeFontResource::~TrueTypeFontResource() { 63 TrueTypeFontResource::~TrueTypeFontResource() {
38 } 64 }
39 65
40 PPB_TrueTypeFont_API* TrueTypeFontResource::AsPPB_TrueTypeFont_API() { 66 PPB_TrueTypeFont_API* TrueTypeFontResource::AsPPB_TrueTypeFont_API() {
41 return this; 67 return this;
42 } 68 }
43 69
44 int32_t TrueTypeFontResource::Describe( 70 int32_t TrueTypeFontResource::Describe(
45 PP_TrueTypeFontDesc_Dev* desc, 71 PP_TrueTypeFontDesc_Dev* desc,
46 scoped_refptr<TrackedCallback> callback) { 72 scoped_refptr<TrackedCallback> callback) {
47 Call<PpapiPluginMsg_TrueTypeFont_DescribeReply>(RENDERER, 73 if (create_result_ == PP_OK) {
48 PpapiHostMsg_TrueTypeFont_Describe(), 74 desc_.CopyToPPTrueTypeFontDesc(desc);
49 base::Bind(&TrueTypeFontResource::OnPluginMsgDescribeComplete, this, 75 return PP_OK;
50 callback, desc)); 76 }
51 return PP_OK_COMPLETIONPENDING; 77 if (create_result_ == PP_OK_COMPLETIONPENDING) {
78 pending_font_ops_.push(FontOp(desc, callback));
79 return PP_OK_COMPLETIONPENDING;
80 }
81
82 return PP_ERROR_FAILED;
52 } 83 }
53 84
54 int32_t TrueTypeFontResource::GetTableTags( 85 int32_t TrueTypeFontResource::GetTableTags(
55 const PP_ArrayOutput& output, 86 const PP_ArrayOutput& output,
56 scoped_refptr<TrackedCallback> callback) { 87 scoped_refptr<TrackedCallback> callback) {
57 Call<PpapiPluginMsg_TrueTypeFont_GetTableTagsReply>(RENDERER, 88 FontOp op(output, callback);
58 PpapiHostMsg_TrueTypeFont_GetTableTags(), 89 if (create_result_ == PP_OK) {
59 base::Bind(&TrueTypeFontResource::OnPluginMsgGetTableTagsComplete, this, 90 RunFontOp(op);
60 callback, output)); 91 return PP_OK_COMPLETIONPENDING;
61 return PP_OK_COMPLETIONPENDING; 92 }
93 if (create_result_ == PP_OK_COMPLETIONPENDING) {
94 pending_font_ops_.push(op);
95 return PP_OK_COMPLETIONPENDING;
96 }
97
98 return PP_ERROR_FAILED;
62 } 99 }
63 100
64 int32_t TrueTypeFontResource::GetTable( 101 int32_t TrueTypeFontResource::GetTable(
65 uint32_t table, 102 uint32_t table,
66 int32_t offset, 103 int32_t offset,
67 int32_t max_data_length, 104 int32_t max_data_length,
68 const PP_ArrayOutput& output, 105 const PP_ArrayOutput& output,
69 scoped_refptr<TrackedCallback> callback) { 106 scoped_refptr<TrackedCallback> callback) {
70 Call<PpapiPluginMsg_TrueTypeFont_GetTableReply>(RENDERER, 107 FontOp op(table, offset, max_data_length, output, callback);
71 PpapiHostMsg_TrueTypeFont_GetTable(table, offset, max_data_length), 108 if (create_result_ == PP_OK) {
72 base::Bind(&TrueTypeFontResource::OnPluginMsgGetTableComplete, this, 109 RunFontOp(op);
73 callback, output)); 110 return PP_OK_COMPLETIONPENDING;
74 return PP_OK_COMPLETIONPENDING; 111 }
112 if (create_result_ == PP_OK_COMPLETIONPENDING) {
113 pending_font_ops_.push(op);
114 return PP_OK_COMPLETIONPENDING;
115 }
116
117 return PP_ERROR_FAILED;
75 } 118 }
76 119
77 void TrueTypeFontResource::OnPluginMsgDescribeComplete( 120 void TrueTypeFontResource::OnReplyReceived(
78 scoped_refptr<TrackedCallback> callback,
79 PP_TrueTypeFontDesc_Dev* pp_desc,
80 const ResourceMessageReplyParams& params, 121 const ResourceMessageReplyParams& params,
81 const ppapi::proxy::SerializedTrueTypeFontDesc& desc) { 122 const IPC::Message& msg) {
82 int32_t result = params.result(); 123 PPAPI_BEGIN_MESSAGE_MAP(TrueTypeFontResource, msg)
83 if (result == PP_OK) 124 PPAPI_DISPATCH_PLUGIN_RESOURCE_CALL(PpapiPluginMsg_TrueTypeFont_CreateReply,
84 desc.CopyToPPTrueTypeFontDesc(pp_desc); 125 OnPluginMsgCreateComplete)
126 PPAPI_DISPATCH_PLUGIN_RESOURCE_CALL_UNHANDLED(
127 PluginResource::OnReplyReceived(params, msg))
128 PPAPI_END_MESSAGE_MAP()
129 }
85 130
86 callback->Run(result); 131 void TrueTypeFontResource::OnPluginMsgCreateComplete(
132 const ResourceMessageReplyParams& params,
133 const ppapi::proxy::SerializedTrueTypeFontDesc& desc,
134 int32_t result) {
135 DCHECK(result != PP_OK_COMPLETIONPENDING);
136 DCHECK(create_result_ == PP_OK_COMPLETIONPENDING);
137 create_result_ = result;
138 if (create_result_ == PP_OK)
139 desc_ = desc;
140
141 // Now run any pending font operations.
142 while (!pending_font_ops_.empty()) {
143 RunFontOp(pending_font_ops_.front());
144 pending_font_ops_.pop();
145 }
87 } 146 }
88 147
89 void TrueTypeFontResource::OnPluginMsgGetTableTagsComplete( 148 void TrueTypeFontResource::OnPluginMsgGetTableTagsComplete(
90 scoped_refptr<TrackedCallback> callback, 149 scoped_refptr<TrackedCallback> callback,
91 PP_ArrayOutput array_output, 150 PP_ArrayOutput array_output,
92 const ResourceMessageReplyParams& params, 151 const ResourceMessageReplyParams& params,
93 const std::vector<uint32_t>& tag_array) { 152 const std::vector<uint32_t>& tag_array) {
94 // The result code should contain the data size if it's positive. 153 // The result code should contain the data size if it's positive.
95 int32_t result = params.result(); 154 int32_t result = params.result();
96 DCHECK((result < 0 && tag_array.size() == 0) || 155 DCHECK((result < 0 && tag_array.size() == 0) ||
(...skipping 22 matching lines...) Expand all
119 ArrayWriter output; 178 ArrayWriter output;
120 output.set_pp_array_output(array_output); 179 output.set_pp_array_output(array_output);
121 if (output.is_valid()) 180 if (output.is_valid())
122 output.StoreArray(data.data(), std::max(0, result)); 181 output.StoreArray(data.data(), std::max(0, result));
123 else 182 else
124 result = PP_ERROR_FAILED; 183 result = PP_ERROR_FAILED;
125 184
126 callback->Run(result); 185 callback->Run(result);
127 } 186 }
128 187
188 void TrueTypeFontResource::RunFontOp(const FontOp& op) {
189 switch (op.type) {
190 case FontOp::DESCRIBE:
191 if (create_result_ == PP_OK && TrackedCallback::IsPending(op.callback)) {
192 desc_.CopyToPPTrueTypeFontDesc(op.desc);
193 op.callback->Run(create_result_);
194 }
195 break;
196 case FontOp::GET_TABLE_TAGS:
197 Call<PpapiPluginMsg_TrueTypeFont_GetTableTagsReply>(
198 BROWSER,
199 PpapiHostMsg_TrueTypeFont_GetTableTags(),
200 base::Bind(&TrueTypeFontResource::OnPluginMsgGetTableTagsComplete,
201 this,
202 op.callback,
203 op.output));
204 break;
205 case FontOp::GET_TABLE:
206 Call<PpapiPluginMsg_TrueTypeFont_GetTableReply>(
207 BROWSER,
208 PpapiHostMsg_TrueTypeFont_GetTable(
209 op.table, op.offset, op.max_data_length),
210 base::Bind(&TrueTypeFontResource::OnPluginMsgGetTableComplete,
211 this,
212 op.callback,
213 op.output));
214 break;
215 // No default case, to catch unhandled op types.
216 }
217 }
218
129 } // namespace proxy 219 } // namespace proxy
130 } // namespace ppapi 220 } // namespace ppapi
OLDNEW
« content/browser/renderer_host/sandbox_ipc_linux.cc ('K') | « ppapi/proxy/truetype_font_resource.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698