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

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
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 <math.h> 7 #include <math.h>
8 8
9 #include <limits> 9 #include <limits>
10 10
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 const PPB_Flash_Print_1_0* PPB_Flash_Proxy::GetFlashPrintInterface() { 93 const PPB_Flash_Print_1_0* PPB_Flash_Proxy::GetFlashPrintInterface() {
94 return &g_flash_print_interface; 94 return &g_flash_print_interface;
95 } 95 }
96 96
97 bool PPB_Flash_Proxy::OnMessageReceived(const IPC::Message& msg) { 97 bool PPB_Flash_Proxy::OnMessageReceived(const IPC::Message& msg) {
98 if (!dispatcher()->permissions().HasPermission(PERMISSION_FLASH)) 98 if (!dispatcher()->permissions().HasPermission(PERMISSION_FLASH))
99 return false; 99 return false;
100 100
101 bool handled = true; 101 bool handled = true;
102 IPC_BEGIN_MESSAGE_MAP(PPB_Flash_Proxy, msg) 102 IPC_BEGIN_MESSAGE_MAP(PPB_Flash_Proxy, msg)
103 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_SetInstanceAlwaysOnTop,
104 OnHostMsgSetInstanceAlwaysOnTop)
105 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_DrawGlyphs,
106 OnHostMsgDrawGlyphs)
107 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_Navigate, OnHostMsgNavigate)
108 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_GetLocalTimeZoneOffset, 103 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_GetLocalTimeZoneOffset,
109 OnHostMsgGetLocalTimeZoneOffset) 104 OnHostMsgGetLocalTimeZoneOffset)
110 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_IsRectTopmost,
111 OnHostMsgIsRectTopmost)
112 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_InvokePrinting, 105 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_InvokePrinting,
113 OnHostMsgInvokePrinting) 106 OnHostMsgInvokePrinting)
114 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_GetSetting, 107 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_GetSetting,
115 OnHostMsgGetSetting) 108 OnHostMsgGetSetting)
116 IPC_MESSAGE_UNHANDLED(handled = false) 109 IPC_MESSAGE_UNHANDLED(handled = false)
117 IPC_END_MESSAGE_MAP() 110 IPC_END_MESSAGE_MAP()
118 // TODO(brettw) handle bad messages! 111 // TODO(brettw) handle bad messages!
119 return handled; 112 return handled;
120 } 113 }
121 114
122 void PPB_Flash_Proxy::SetInstanceAlwaysOnTop(PP_Instance instance,
123 PP_Bool on_top) {
124 dispatcher()->Send(new PpapiHostMsg_PPBFlash_SetInstanceAlwaysOnTop(
125 API_ID_PPB_FLASH, instance, on_top));
126 }
127
128 PP_Bool PPB_Flash_Proxy::DrawGlyphs(
129 PP_Instance instance,
130 PP_Resource pp_image_data,
131 const PP_BrowserFont_Trusted_Description* font_desc,
132 uint32_t color,
133 const PP_Point* position,
134 const PP_Rect* clip,
135 const float transformation[3][3],
136 PP_Bool allow_subpixel_aa,
137 uint32_t glyph_count,
138 const uint16_t glyph_indices[],
139 const PP_Point glyph_advances[]) {
140 Resource* image_data =
141 PpapiGlobals::Get()->GetResourceTracker()->GetResource(pp_image_data);
142 if (!image_data)
143 return PP_FALSE;
144 // The instance parameter isn't strictly necessary but we check that it
145 // matches anyway.
146 if (image_data->pp_instance() != instance)
147 return PP_FALSE;
148
149 PPBFlash_DrawGlyphs_Params params;
150 params.image_data = image_data->host_resource();
151 params.font_desc.SetFromPPBrowserFontDescription(*font_desc);
152 params.color = color;
153 params.position = *position;
154 params.clip = *clip;
155 for (int i = 0; i < 3; i++) {
156 for (int j = 0; j < 3; j++)
157 params.transformation[i][j] = transformation[i][j];
158 }
159 params.allow_subpixel_aa = allow_subpixel_aa;
160
161 params.glyph_indices.insert(params.glyph_indices.begin(),
162 &glyph_indices[0],
163 &glyph_indices[glyph_count]);
164 params.glyph_advances.insert(params.glyph_advances.begin(),
165 &glyph_advances[0],
166 &glyph_advances[glyph_count]);
167
168 PP_Bool result = PP_FALSE;
169 dispatcher()->Send(new PpapiHostMsg_PPBFlash_DrawGlyphs(
170 API_ID_PPB_FLASH, instance, params, &result));
171 return result;
172 }
173
174 int32_t PPB_Flash_Proxy::Navigate(PP_Instance instance,
175 PP_Resource request_info,
176 const char* target,
177 PP_Bool from_user_action) {
178 thunk::EnterResourceNoLock<thunk::PPB_URLRequestInfo_API> enter(
179 request_info, true);
180 if (enter.failed())
181 return PP_ERROR_BADRESOURCE;
182 return Navigate(instance, enter.object()->GetData(), target,
183 from_user_action);
184 }
185
186 int32_t PPB_Flash_Proxy::Navigate(PP_Instance instance,
187 const URLRequestInfoData& data,
188 const char* target,
189 PP_Bool from_user_action) {
190 int32_t result = PP_ERROR_FAILED;
191 dispatcher()->Send(new PpapiHostMsg_PPBFlash_Navigate(
192 API_ID_PPB_FLASH, instance, data, target, from_user_action, &result));
193 return result;
194 }
195
196 double PPB_Flash_Proxy::GetLocalTimeZoneOffset(PP_Instance instance, 115 double PPB_Flash_Proxy::GetLocalTimeZoneOffset(PP_Instance instance,
197 PP_Time t) { 116 PP_Time t) {
198 LocalTimeZoneOffsetCache& cache = g_local_time_zone_offset_cache.Get(); 117 LocalTimeZoneOffsetCache& cache = g_local_time_zone_offset_cache.Get();
199 118
200 // Get the minimum PP_Time value that shares the same minute as |t|. 119 // Get the minimum PP_Time value that shares the same minute as |t|.
201 // Use cached offset if cache hasn't expired and |t| is in the same minute as 120 // Use cached offset if cache hasn't expired and |t| is in the same minute as
202 // the time for the cached offset (assume offsets change on minute 121 // the time for the cached offset (assume offsets change on minute
203 // boundaries). 122 // boundaries).
204 PP_Time t_minute_base = floor(t / 60.0) * 60.0; 123 PP_Time t_minute_base = floor(t / 60.0) * 60.0;
205 LocalTimeZoneOffsetCache::iterator iter = cache.Get(t_minute_base); 124 LocalTimeZoneOffsetCache::iterator iter = cache.Get(t_minute_base);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 base::Time adj_time = base::Time::FromUTCExploded(exploded); 156 base::Time adj_time = base::Time::FromUTCExploded(exploded);
238 base::Time cur = base::Time::FromUTCExploded(utc_exploded); 157 base::Time cur = base::Time::FromUTCExploded(utc_exploded);
239 cache_entry.offset = (adj_time - cur).InSecondsF(); 158 cache_entry.offset = (adj_time - cur).InSecondsF();
240 } 159 }
241 #endif 160 #endif
242 161
243 cache.Put(t_minute_base, cache_entry); 162 cache.Put(t_minute_base, cache_entry);
244 return cache_entry.offset; 163 return cache_entry.offset;
245 } 164 }
246 165
247 PP_Bool PPB_Flash_Proxy::IsRectTopmost(PP_Instance instance,
248 const PP_Rect* rect) {
249 PP_Bool result = PP_FALSE;
250 dispatcher()->Send(new PpapiHostMsg_PPBFlash_IsRectTopmost(
251 API_ID_PPB_FLASH, instance, *rect, &result));
252 return result;
253 }
254
255 PP_Var PPB_Flash_Proxy::GetSetting(PP_Instance instance, 166 PP_Var PPB_Flash_Proxy::GetSetting(PP_Instance instance,
256 PP_FlashSetting setting) { 167 PP_FlashSetting setting) {
257 PluginDispatcher* plugin_dispatcher = 168 PluginDispatcher* plugin_dispatcher =
258 static_cast<PluginDispatcher*>(dispatcher()); 169 static_cast<PluginDispatcher*>(dispatcher());
259 switch (setting) { 170 switch (setting) {
260 case PP_FLASHSETTING_3DENABLED: 171 case PP_FLASHSETTING_3DENABLED:
261 return PP_MakeBool(PP_FromBool( 172 return PP_MakeBool(PP_FromBool(
262 plugin_dispatcher->preferences().is_3d_supported)); 173 plugin_dispatcher->preferences().is_3d_supported));
263 case PP_FLASHSETTING_INCOGNITO: 174 case PP_FLASHSETTING_INCOGNITO:
264 return PP_MakeBool(PP_FromBool(plugin_dispatcher->incognito())); 175 return PP_MakeBool(PP_FromBool(plugin_dispatcher->incognito()));
265 case PP_FLASHSETTING_STAGE3DENABLED: 176 case PP_FLASHSETTING_STAGE3DENABLED:
266 return PP_MakeBool(PP_FromBool( 177 return PP_MakeBool(PP_FromBool(
267 plugin_dispatcher->preferences().is_stage3d_supported)); 178 plugin_dispatcher->preferences().is_stage3d_supported));
268 case PP_FLASHSETTING_LANGUAGE: 179 case PP_FLASHSETTING_LANGUAGE:
269 return StringVar::StringToPPVar( 180 return StringVar::StringToPPVar(
270 PluginGlobals::Get()->GetUILanguage()); 181 PluginGlobals::Get()->GetUILanguage());
271 case PP_FLASHSETTING_NUMCORES: 182 case PP_FLASHSETTING_NUMCORES:
272 return PP_MakeInt32(plugin_dispatcher->preferences().number_of_cpu_cores); 183 return PP_MakeInt32(plugin_dispatcher->preferences().number_of_cpu_cores);
273 case PP_FLASHSETTING_LSORESTRICTIONS: { 184 case PP_FLASHSETTING_LSORESTRICTIONS: {
274 ReceiveSerializedVarReturnValue result; 185 ReceiveSerializedVarReturnValue result;
275 dispatcher()->Send(new PpapiHostMsg_PPBFlash_GetSetting( 186 dispatcher()->Send(new PpapiHostMsg_PPBFlash_GetSetting(
276 API_ID_PPB_FLASH, instance, setting, &result)); 187 API_ID_PPB_FLASH, instance, setting, &result));
277 return result.Return(dispatcher()); 188 return result.Return(dispatcher());
278 } 189 }
279 } 190 }
280 return PP_MakeUndefined(); 191 return PP_MakeUndefined();
281 } 192 }
282 193
283 void PPB_Flash_Proxy::OnHostMsgSetInstanceAlwaysOnTop(PP_Instance instance,
284 PP_Bool on_top) {
285 EnterInstanceNoLock enter(instance);
286 if (enter.succeeded())
287 enter.functions()->GetFlashAPI()->SetInstanceAlwaysOnTop(instance, on_top);
288 }
289
290 void PPB_Flash_Proxy::OnHostMsgDrawGlyphs(
291 PP_Instance instance,
292 const PPBFlash_DrawGlyphs_Params& params,
293 PP_Bool* result) {
294 *result = PP_FALSE;
295 EnterInstanceNoLock enter(instance);
296 if (enter.failed())
297 return;
298
299 if (params.glyph_indices.size() != params.glyph_advances.size() ||
300 params.glyph_indices.empty())
301 return;
302
303 PP_BrowserFont_Trusted_Description font_desc;
304 params.font_desc.SetToPPBrowserFontDescription(&font_desc);
305
306 *result = enter.functions()->GetFlashAPI()->DrawGlyphs(
307 0, // Unused instance param.
308 params.image_data.host_resource(), &font_desc,
309 params.color, &params.position, &params.clip,
310 const_cast<float(*)[3]>(params.transformation),
311 params.allow_subpixel_aa,
312 static_cast<uint32_t>(params.glyph_indices.size()),
313 const_cast<uint16_t*>(&params.glyph_indices[0]),
314 const_cast<PP_Point*>(&params.glyph_advances[0]));
315
316 // SetToPPFontDescription() creates a var which is owned by the caller.
317 PpapiGlobals::Get()->GetVarTracker()->ReleaseVar(font_desc.face);
318 }
319
320 void PPB_Flash_Proxy::OnHostMsgNavigate(PP_Instance instance,
321 const URLRequestInfoData& data,
322 const std::string& target,
323 PP_Bool from_user_action,
324 int32_t* result) {
325 EnterInstanceNoLock enter_instance(instance);
326 if (enter_instance.failed()) {
327 *result = PP_ERROR_BADARGUMENT;
328 return;
329 }
330 DCHECK(!dispatcher()->IsPlugin());
331
332 // Validate the PP_Instance since we'll be constructing resources on its
333 // behalf.
334 HostDispatcher* host_dispatcher = static_cast<HostDispatcher*>(dispatcher());
335 if (HostDispatcher::GetForInstance(instance) != host_dispatcher) {
336 NOTREACHED();
337 *result = PP_ERROR_BADARGUMENT;
338 return;
339 }
340
341 // We need to allow re-entrancy here, because this may call into Javascript
342 // (e.g. with a "javascript:" URL), or do things like navigate away from the
343 // page, either one of which will need to re-enter into the plugin.
344 // It is safe, because it is essentially equivalent to NPN_GetURL, where Flash
345 // would expect re-entrancy. When running in-process, it does re-enter here.
346 host_dispatcher->set_allow_plugin_reentrancy();
347 *result = enter_instance.functions()->GetFlashAPI()->Navigate(
348 instance, data, target.c_str(), from_user_action);
349 }
350
351 void PPB_Flash_Proxy::OnHostMsgGetLocalTimeZoneOffset(PP_Instance instance, 194 void PPB_Flash_Proxy::OnHostMsgGetLocalTimeZoneOffset(PP_Instance instance,
352 PP_Time t, 195 PP_Time t,
353 double* result) { 196 double* result) {
354 EnterInstanceNoLock enter(instance); 197 EnterInstanceNoLock enter(instance);
355 if (enter.succeeded()) { 198 if (enter.succeeded()) {
356 *result = enter.functions()->GetFlashAPI()->GetLocalTimeZoneOffset( 199 *result = enter.functions()->GetFlashAPI()->GetLocalTimeZoneOffset(
357 instance, t); 200 instance, t);
358 } else { 201 } else {
359 *result = 0.0; 202 *result = 0.0;
360 } 203 }
361 } 204 }
362 205
363 void PPB_Flash_Proxy::OnHostMsgIsRectTopmost(PP_Instance instance,
364 PP_Rect rect,
365 PP_Bool* result) {
366 EnterInstanceNoLock enter(instance);
367 if (enter.succeeded())
368 *result = enter.functions()->GetFlashAPI()->IsRectTopmost(instance, &rect);
369 else
370 *result = PP_FALSE;
371 }
372
373 void PPB_Flash_Proxy::OnHostMsgGetSetting(PP_Instance instance, 206 void PPB_Flash_Proxy::OnHostMsgGetSetting(PP_Instance instance,
374 PP_FlashSetting setting, 207 PP_FlashSetting setting,
375 SerializedVarReturnValue id) { 208 SerializedVarReturnValue id) {
376 EnterInstanceNoLock enter(instance); 209 EnterInstanceNoLock enter(instance);
377 if (enter.succeeded()) { 210 if (enter.succeeded()) {
378 id.Return(dispatcher(), 211 id.Return(dispatcher(),
379 enter.functions()->GetFlashAPI()->GetSetting( 212 enter.functions()->GetFlashAPI()->GetSetting(
380 instance, setting)); 213 instance, setting));
381 } else { 214 } else {
382 id.Return(dispatcher(), PP_MakeUndefined()); 215 id.Return(dispatcher(), PP_MakeUndefined());
383 } 216 }
384 } 217 }
385 218
386 void PPB_Flash_Proxy::OnHostMsgInvokePrinting(PP_Instance instance) { 219 void PPB_Flash_Proxy::OnHostMsgInvokePrinting(PP_Instance instance) {
387 // This function is actually implemented in the PPB_Flash_Print interface. 220 // This function is actually implemented in the PPB_Flash_Print interface.
388 // It's rarely used enough that we just request this interface when needed. 221 // It's rarely used enough that we just request this interface when needed.
389 const PPB_Flash_Print_1_0* print_interface = 222 const PPB_Flash_Print_1_0* print_interface =
390 static_cast<const PPB_Flash_Print_1_0*>( 223 static_cast<const PPB_Flash_Print_1_0*>(
391 dispatcher()->local_get_interface()(PPB_FLASH_PRINT_INTERFACE_1_0)); 224 dispatcher()->local_get_interface()(PPB_FLASH_PRINT_INTERFACE_1_0));
392 if (print_interface) 225 if (print_interface)
393 print_interface->InvokePrinting(instance); 226 print_interface->InvokePrinting(instance);
394 } 227 }
395 228
396 } // namespace proxy 229 } // namespace proxy
397 } // namespace ppapi 230 } // namespace ppapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698