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

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

Issue 11510008: Refactor 4 PPB_Flash functions to the new PPAPI resource model. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years 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
« no previous file with comments | « ppapi/proxy/ppb_flash_proxy.h ('k') | ppapi/proxy/serialized_structs.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/ppb_flash_proxy.h" 5 #include "ppapi/proxy/ppb_flash_proxy.h"
6 6
7 #include <limits> 7 #include <limits>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 const PPB_Flash_Print_1_0* PPB_Flash_Proxy::GetFlashPrintInterface() { 70 const PPB_Flash_Print_1_0* PPB_Flash_Proxy::GetFlashPrintInterface() {
71 return &g_flash_print_interface; 71 return &g_flash_print_interface;
72 } 72 }
73 73
74 bool PPB_Flash_Proxy::OnMessageReceived(const IPC::Message& msg) { 74 bool PPB_Flash_Proxy::OnMessageReceived(const IPC::Message& msg) {
75 if (!dispatcher()->permissions().HasPermission(PERMISSION_FLASH)) 75 if (!dispatcher()->permissions().HasPermission(PERMISSION_FLASH))
76 return false; 76 return false;
77 77
78 bool handled = true; 78 bool handled = true;
79 IPC_BEGIN_MESSAGE_MAP(PPB_Flash_Proxy, msg) 79 IPC_BEGIN_MESSAGE_MAP(PPB_Flash_Proxy, msg)
80 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_SetInstanceAlwaysOnTop,
81 OnHostMsgSetInstanceAlwaysOnTop)
82 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_DrawGlyphs,
83 OnHostMsgDrawGlyphs)
84 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_Navigate, OnHostMsgNavigate)
85 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_IsRectTopmost,
86 OnHostMsgIsRectTopmost)
87 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_InvokePrinting, 80 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_InvokePrinting,
88 OnHostMsgInvokePrinting) 81 OnHostMsgInvokePrinting)
89 IPC_MESSAGE_UNHANDLED(handled = false) 82 IPC_MESSAGE_UNHANDLED(handled = false)
90 IPC_END_MESSAGE_MAP() 83 IPC_END_MESSAGE_MAP()
91 // TODO(brettw) handle bad messages! 84 // TODO(brettw) handle bad messages!
92 return handled; 85 return handled;
93 } 86 }
94 87
95 void PPB_Flash_Proxy::SetInstanceAlwaysOnTop(PP_Instance instance,
96 PP_Bool on_top) {
97 dispatcher()->Send(new PpapiHostMsg_PPBFlash_SetInstanceAlwaysOnTop(
98 API_ID_PPB_FLASH, instance, on_top));
99 }
100
101 PP_Bool PPB_Flash_Proxy::DrawGlyphs(
102 PP_Instance instance,
103 PP_Resource pp_image_data,
104 const PP_BrowserFont_Trusted_Description* font_desc,
105 uint32_t color,
106 const PP_Point* position,
107 const PP_Rect* clip,
108 const float transformation[3][3],
109 PP_Bool allow_subpixel_aa,
110 uint32_t glyph_count,
111 const uint16_t glyph_indices[],
112 const PP_Point glyph_advances[]) {
113 Resource* image_data =
114 PpapiGlobals::Get()->GetResourceTracker()->GetResource(pp_image_data);
115 if (!image_data)
116 return PP_FALSE;
117 // The instance parameter isn't strictly necessary but we check that it
118 // matches anyway.
119 if (image_data->pp_instance() != instance)
120 return PP_FALSE;
121
122 PPBFlash_DrawGlyphs_Params params;
123 params.image_data = image_data->host_resource();
124 params.font_desc.SetFromPPBrowserFontDescription(*font_desc);
125 params.color = color;
126 params.position = *position;
127 params.clip = *clip;
128 for (int i = 0; i < 3; i++) {
129 for (int j = 0; j < 3; j++)
130 params.transformation[i][j] = transformation[i][j];
131 }
132 params.allow_subpixel_aa = allow_subpixel_aa;
133
134 params.glyph_indices.insert(params.glyph_indices.begin(),
135 &glyph_indices[0],
136 &glyph_indices[glyph_count]);
137 params.glyph_advances.insert(params.glyph_advances.begin(),
138 &glyph_advances[0],
139 &glyph_advances[glyph_count]);
140
141 PP_Bool result = PP_FALSE;
142 dispatcher()->Send(new PpapiHostMsg_PPBFlash_DrawGlyphs(
143 API_ID_PPB_FLASH, instance, params, &result));
144 return result;
145 }
146
147 int32_t PPB_Flash_Proxy::Navigate(PP_Instance instance,
148 PP_Resource request_info,
149 const char* target,
150 PP_Bool from_user_action) {
151 thunk::EnterResourceNoLock<thunk::PPB_URLRequestInfo_API> enter(
152 request_info, true);
153 if (enter.failed())
154 return PP_ERROR_BADRESOURCE;
155 return Navigate(instance, enter.object()->GetData(), target,
156 from_user_action);
157 }
158
159 int32_t PPB_Flash_Proxy::Navigate(PP_Instance instance,
160 const URLRequestInfoData& data,
161 const char* target,
162 PP_Bool from_user_action) {
163 int32_t result = PP_ERROR_FAILED;
164 dispatcher()->Send(new PpapiHostMsg_PPBFlash_Navigate(
165 API_ID_PPB_FLASH, instance, data, target, from_user_action, &result));
166 return result;
167 }
168
169 PP_Bool PPB_Flash_Proxy::IsRectTopmost(PP_Instance instance,
170 const PP_Rect* rect) {
171 PP_Bool result = PP_FALSE;
172 dispatcher()->Send(new PpapiHostMsg_PPBFlash_IsRectTopmost(
173 API_ID_PPB_FLASH, instance, *rect, &result));
174 return result;
175 }
176
177 void PPB_Flash_Proxy::OnHostMsgSetInstanceAlwaysOnTop(PP_Instance instance,
178 PP_Bool on_top) {
179 EnterInstanceNoLock enter(instance);
180 if (enter.succeeded())
181 enter.functions()->GetFlashAPI()->SetInstanceAlwaysOnTop(instance, on_top);
182 }
183
184 void PPB_Flash_Proxy::OnHostMsgDrawGlyphs(
185 PP_Instance instance,
186 const PPBFlash_DrawGlyphs_Params& params,
187 PP_Bool* result) {
188 *result = PP_FALSE;
189 EnterInstanceNoLock enter(instance);
190 if (enter.failed())
191 return;
192
193 if (params.glyph_indices.size() != params.glyph_advances.size() ||
194 params.glyph_indices.empty())
195 return;
196
197 PP_BrowserFont_Trusted_Description font_desc;
198 params.font_desc.SetToPPBrowserFontDescription(&font_desc);
199
200 *result = enter.functions()->GetFlashAPI()->DrawGlyphs(
201 0, // Unused instance param.
202 params.image_data.host_resource(), &font_desc,
203 params.color, &params.position, &params.clip,
204 const_cast<float(*)[3]>(params.transformation),
205 params.allow_subpixel_aa,
206 static_cast<uint32_t>(params.glyph_indices.size()),
207 const_cast<uint16_t*>(&params.glyph_indices[0]),
208 const_cast<PP_Point*>(&params.glyph_advances[0]));
209
210 // SetToPPFontDescription() creates a var which is owned by the caller.
211 PpapiGlobals::Get()->GetVarTracker()->ReleaseVar(font_desc.face);
212 }
213
214 void PPB_Flash_Proxy::OnHostMsgNavigate(PP_Instance instance,
215 const URLRequestInfoData& data,
216 const std::string& target,
217 PP_Bool from_user_action,
218 int32_t* result) {
219 EnterInstanceNoLock enter_instance(instance);
220 if (enter_instance.failed()) {
221 *result = PP_ERROR_BADARGUMENT;
222 return;
223 }
224 DCHECK(!dispatcher()->IsPlugin());
225
226 // Validate the PP_Instance since we'll be constructing resources on its
227 // behalf.
228 HostDispatcher* host_dispatcher = static_cast<HostDispatcher*>(dispatcher());
229 if (HostDispatcher::GetForInstance(instance) != host_dispatcher) {
230 NOTREACHED();
231 *result = PP_ERROR_BADARGUMENT;
232 return;
233 }
234
235 // We need to allow re-entrancy here, because this may call into Javascript
236 // (e.g. with a "javascript:" URL), or do things like navigate away from the
237 // page, either one of which will need to re-enter into the plugin.
238 // It is safe, because it is essentially equivalent to NPN_GetURL, where Flash
239 // would expect re-entrancy. When running in-process, it does re-enter here.
240 host_dispatcher->set_allow_plugin_reentrancy();
241 *result = enter_instance.functions()->GetFlashAPI()->Navigate(
242 instance, data, target.c_str(), from_user_action);
243 }
244
245 void PPB_Flash_Proxy::OnHostMsgIsRectTopmost(PP_Instance instance,
246 PP_Rect rect,
247 PP_Bool* result) {
248 EnterInstanceNoLock enter(instance);
249 if (enter.succeeded())
250 *result = enter.functions()->GetFlashAPI()->IsRectTopmost(instance, &rect);
251 else
252 *result = PP_FALSE;
253 }
254
255 void PPB_Flash_Proxy::OnHostMsgInvokePrinting(PP_Instance instance) { 88 void PPB_Flash_Proxy::OnHostMsgInvokePrinting(PP_Instance instance) {
256 // This function is actually implemented in the PPB_Flash_Print interface. 89 // This function is actually implemented in the PPB_Flash_Print interface.
257 // It's rarely used enough that we just request this interface when needed. 90 // It's rarely used enough that we just request this interface when needed.
258 const PPB_Flash_Print_1_0* print_interface = 91 const PPB_Flash_Print_1_0* print_interface =
259 static_cast<const PPB_Flash_Print_1_0*>( 92 static_cast<const PPB_Flash_Print_1_0*>(
260 dispatcher()->local_get_interface()(PPB_FLASH_PRINT_INTERFACE_1_0)); 93 dispatcher()->local_get_interface()(PPB_FLASH_PRINT_INTERFACE_1_0));
261 if (print_interface) 94 if (print_interface)
262 print_interface->InvokePrinting(instance); 95 print_interface->InvokePrinting(instance);
263 } 96 }
264 97
265 } // namespace proxy 98 } // namespace proxy
266 } // namespace ppapi 99 } // namespace ppapi
OLDNEW
« no previous file with comments | « ppapi/proxy/ppb_flash_proxy.h ('k') | ppapi/proxy/serialized_structs.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698