OLD | NEW |
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_instance_proxy.h" | 5 #include "ppapi/proxy/ppb_instance_proxy.h" |
6 | 6 |
| 7 #include "base/memory/ref_counted.h" |
7 #include "build/build_config.h" | 8 #include "build/build_config.h" |
8 #include "ppapi/c/pp_errors.h" | 9 #include "ppapi/c/pp_errors.h" |
9 #include "ppapi/c/pp_time.h" | 10 #include "ppapi/c/pp_time.h" |
10 #include "ppapi/c/pp_var.h" | 11 #include "ppapi/c/pp_var.h" |
11 #include "ppapi/c/ppb_audio_config.h" | 12 #include "ppapi/c/ppb_audio_config.h" |
12 #include "ppapi/c/ppb_instance.h" | 13 #include "ppapi/c/ppb_instance.h" |
13 #include "ppapi/c/ppb_messaging.h" | 14 #include "ppapi/c/ppb_messaging.h" |
14 #include "ppapi/c/ppb_mouse_lock.h" | 15 #include "ppapi/c/ppb_mouse_lock.h" |
15 #include "ppapi/c/private/pp_content_decryptor.h" | 16 #include "ppapi/c/private/pp_content_decryptor.h" |
16 #include "ppapi/proxy/content_decryptor_private_serializer.h" | 17 #include "ppapi/proxy/content_decryptor_private_serializer.h" |
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 dispatcher()->Send(new PpapiHostMsg_PPBInstance_GetScreenSize( | 324 dispatcher()->Send(new PpapiHostMsg_PPBInstance_GetScreenSize( |
324 API_ID_PPB_INSTANCE, instance, &result, size)); | 325 API_ID_PPB_INSTANCE, instance, &result, size)); |
325 return result; | 326 return result; |
326 } | 327 } |
327 | 328 |
328 thunk::PPB_Flash_API* PPB_Instance_Proxy::GetFlashAPI() { | 329 thunk::PPB_Flash_API* PPB_Instance_Proxy::GetFlashAPI() { |
329 InterfaceProxy* ip = dispatcher()->GetInterfaceProxy(API_ID_PPB_FLASH); | 330 InterfaceProxy* ip = dispatcher()->GetInterfaceProxy(API_ID_PPB_FLASH); |
330 return static_cast<PPB_Flash_Proxy*>(ip); | 331 return static_cast<PPB_Flash_Proxy*>(ip); |
331 } | 332 } |
332 | 333 |
333 // TODO(raymes): We can most likely cut down this boilerplate for grabbing | 334 Resource* PPB_Instance_Proxy::GetSingletonResource(PP_Instance instance, |
334 // singleton resource APIs. | 335 SingletonResourceID id) { |
335 thunk::PPB_Flash_Functions_API* PPB_Instance_Proxy::GetFlashFunctionsAPI( | |
336 PP_Instance instance) { | |
337 #if !defined(OS_NACL) && !defined(NACL_WIN64) | |
338 InstanceData* data = static_cast<PluginDispatcher*>(dispatcher())-> | 336 InstanceData* data = static_cast<PluginDispatcher*>(dispatcher())-> |
339 GetInstanceData(instance); | 337 GetInstanceData(instance); |
340 if (!data) | 338 |
| 339 InstanceData::SingletonResourceMap::iterator it = |
| 340 data->singleton_resources.find(id); |
| 341 if (it != data->singleton_resources.end()) |
| 342 return it->second.get(); |
| 343 |
| 344 scoped_refptr<Resource> new_singleton; |
| 345 Connection connection(PluginGlobals::Get()->GetBrowserSender(), dispatcher()); |
| 346 |
| 347 switch (id) { |
| 348 case GAMEPAD_SINGLETON_ID: |
| 349 new_singleton = new GamepadResource(connection, instance); |
| 350 break; |
| 351 // Flash resources aren't needed for NaCl. |
| 352 #if !defined(OS_NACL) && !defined(NACL_WIN64) |
| 353 case FLASH_SINGLETON_ID: |
| 354 new_singleton = new FlashResource(connection, instance); |
| 355 break; |
| 356 case FLASH_CLIPBOARD_SINGLETON_ID: |
| 357 new_singleton = new FlashClipboardResource(connection, instance); |
| 358 break; |
| 359 #else |
| 360 case FLASH_SINGLETON_ID: |
| 361 case FLASH_CLIPBOARD_SINGLETON_ID: |
| 362 NOTREACHED(); |
| 363 break; |
| 364 #endif // !defined(OS_NACL) && !defined(NACL_WIN64) |
| 365 } |
| 366 |
| 367 if (!new_singleton) { |
| 368 // Getting here implies that a constructor is missing in the above switch. |
| 369 NOTREACHED(); |
341 return NULL; | 370 return NULL; |
| 371 } |
342 | 372 |
343 if (!data->flash_resource.get()) { | 373 data->singleton_resources[id] = new_singleton; |
344 Connection connection(PluginGlobals::Get()->GetBrowserSender(), | 374 return new_singleton.get(); |
345 dispatcher()); | |
346 data->flash_resource = new FlashResource(connection, instance); | |
347 } | |
348 return data->flash_resource.get(); | |
349 #else | |
350 // Flash functions aren't implemented for nacl. | |
351 NOTIMPLEMENTED(); | |
352 return NULL; | |
353 #endif // !defined(OS_NACL) && !defined(NACL_WIN64) | |
354 } | |
355 | |
356 thunk::PPB_Flash_Clipboard_API* PPB_Instance_Proxy::GetFlashClipboardAPI( | |
357 PP_Instance instance) { | |
358 #if !defined(OS_NACL) && !defined(NACL_WIN64) | |
359 InstanceData* data = static_cast<PluginDispatcher*>(dispatcher())-> | |
360 GetInstanceData(instance); | |
361 if (!data) | |
362 return NULL; | |
363 | |
364 if (!data->flash_clipboard_resource.get()) { | |
365 Connection connection(PluginGlobals::Get()->GetBrowserSender(), | |
366 dispatcher()); | |
367 data->flash_clipboard_resource = | |
368 new FlashClipboardResource(connection, instance); | |
369 } | |
370 return data->flash_clipboard_resource.get(); | |
371 #else | |
372 // Flash functions aren't implemented for nacl. | |
373 NOTIMPLEMENTED(); | |
374 return NULL; | |
375 #endif // !defined(OS_NACL) && !defined(NACL_WIN64) | |
376 } | |
377 | |
378 thunk::PPB_Gamepad_API* PPB_Instance_Proxy::GetGamepadAPI( | |
379 PP_Instance instance) { | |
380 InstanceData* data = static_cast<PluginDispatcher*>(dispatcher())-> | |
381 GetInstanceData(instance); | |
382 if (!data) | |
383 return NULL; | |
384 | |
385 if (!data->gamepad_resource.get()) { | |
386 Connection connection(PluginGlobals::Get()->GetBrowserSender(), | |
387 dispatcher()); | |
388 data->gamepad_resource = new GamepadResource(connection, instance); | |
389 } | |
390 return data->gamepad_resource.get(); | |
391 } | 375 } |
392 | 376 |
393 int32_t PPB_Instance_Proxy::RequestInputEvents(PP_Instance instance, | 377 int32_t PPB_Instance_Proxy::RequestInputEvents(PP_Instance instance, |
394 uint32_t event_classes) { | 378 uint32_t event_classes) { |
395 dispatcher()->Send(new PpapiHostMsg_PPBInstance_RequestInputEvents( | 379 dispatcher()->Send(new PpapiHostMsg_PPBInstance_RequestInputEvents( |
396 API_ID_PPB_INSTANCE, instance, false, event_classes)); | 380 API_ID_PPB_INSTANCE, instance, false, event_classes)); |
397 | 381 |
398 // We always register for the classes we can handle, this function validates | 382 // We always register for the classes we can handle, this function validates |
399 // the flags so we can notify it if anything was invalid, without requiring | 383 // the flags so we can notify it if anything was invalid, without requiring |
400 // a sync reply. | 384 // a sync reply. |
(...skipping 787 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1188 PP_Instance instance) { | 1172 PP_Instance instance) { |
1189 InstanceData* data = static_cast<PluginDispatcher*>(dispatcher())-> | 1173 InstanceData* data = static_cast<PluginDispatcher*>(dispatcher())-> |
1190 GetInstanceData(instance); | 1174 GetInstanceData(instance); |
1191 if (!data) | 1175 if (!data) |
1192 return; // Instance was probably deleted. | 1176 return; // Instance was probably deleted. |
1193 data->should_do_request_surrounding_text = false; | 1177 data->should_do_request_surrounding_text = false; |
1194 } | 1178 } |
1195 | 1179 |
1196 } // namespace proxy | 1180 } // namespace proxy |
1197 } // namespace ppapi | 1181 } // namespace ppapi |
OLD | NEW |