OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 The Native Client 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 // Implements the untrusted side of the PPB_GetInterface method. |
| 6 |
| 7 #include "native_client/src/shared/ppapi_proxy/plugin_globals.h" |
| 8 #include <stdlib.h> |
| 9 #include <string.h> |
| 10 #include "native_client/src/shared/ppapi_proxy/plugin_ppb_audio.h" |
| 11 #include "native_client/src/shared/ppapi_proxy/plugin_ppb_audio_config.h" |
| 12 #include "native_client/src/shared/ppapi_proxy/plugin_ppb_buffer.h" |
| 13 #include "native_client/src/shared/ppapi_proxy/plugin_ppb_core.h" |
| 14 #include "native_client/src/shared/ppapi_proxy/plugin_ppb_cursor_control.h" |
| 15 #include "native_client/src/shared/ppapi_proxy/plugin_ppb_file_io.h" |
| 16 #include "native_client/src/shared/ppapi_proxy/plugin_ppb_file_ref.h" |
| 17 #include "native_client/src/shared/ppapi_proxy/plugin_ppb_file_system.h" |
| 18 #include "native_client/src/shared/ppapi_proxy/plugin_ppb_find.h" |
| 19 #include "native_client/src/shared/ppapi_proxy/plugin_ppb_font.h" |
| 20 #include "native_client/src/shared/ppapi_proxy/plugin_ppb_graphics_2d.h" |
| 21 #include "native_client/src/shared/ppapi_proxy/plugin_ppb_graphics_3d.h" |
| 22 #include "native_client/src/shared/ppapi_proxy/plugin_ppb_image_data.h" |
| 23 #include "native_client/src/shared/ppapi_proxy/plugin_ppb_input_event.h" |
| 24 #include "native_client/src/shared/ppapi_proxy/plugin_ppb_instance.h" |
| 25 #include "native_client/src/shared/ppapi_proxy/plugin_ppb_memory.h" |
| 26 #include "native_client/src/shared/ppapi_proxy/plugin_ppb_messaging.h" |
| 27 #include "native_client/src/shared/ppapi_proxy/plugin_ppb_pdf.h" |
| 28 #include "native_client/src/shared/ppapi_proxy/plugin_ppb_scrollbar.h" |
| 29 #include "native_client/src/shared/ppapi_proxy/plugin_ppb_testing.h" |
| 30 #include "native_client/src/shared/ppapi_proxy/plugin_ppb_url_loader.h" |
| 31 #include "native_client/src/shared/ppapi_proxy/plugin_ppb_url_request_info.h" |
| 32 #include "native_client/src/shared/ppapi_proxy/plugin_ppb_url_response_info.h" |
| 33 #include "native_client/src/shared/ppapi_proxy/plugin_ppb_var.h" |
| 34 #include "native_client/src/shared/ppapi_proxy/plugin_ppb_widget.h" |
| 35 #include "native_client/src/shared/ppapi_proxy/plugin_ppb_zoom.h" |
| 36 #include "native_client/src/shared/ppapi_proxy/untrusted/srpcgen/ppb_rpc.h" |
| 37 #include "native_client/src/shared/ppapi_proxy/utility.h" |
| 38 |
| 39 namespace ppapi_proxy { |
| 40 |
| 41 namespace { |
| 42 |
| 43 struct InterfaceMapElement { |
| 44 const char* name; |
| 45 const void* ppb_interface; |
| 46 bool needs_browser_check; |
| 47 }; |
| 48 |
| 49 // List of interfaces that have at least partial proxy support. |
| 50 InterfaceMapElement interface_map[] = { |
| 51 { PPB_AUDIO_INTERFACE, PluginAudio::GetInterface(), true }, |
| 52 { PPB_AUDIO_CONFIG_INTERFACE, PluginAudioConfig::GetInterface(), true }, |
| 53 { PPB_CORE_INTERFACE, PluginCore::GetInterface(), true }, |
| 54 { PPB_CURSOR_CONTROL_DEV_INTERFACE, PluginCursorControl::GetInterface(), |
| 55 true }, |
| 56 { PPB_FILEIO_INTERFACE, PluginFileIO::GetInterface(), true }, |
| 57 { PPB_FILEREF_INTERFACE, PluginFileRef::GetInterface(), true }, |
| 58 { PPB_FILESYSTEM_INTERFACE, PluginFileSystem::GetInterface(), true }, |
| 59 { PPB_FIND_DEV_INTERFACE, PluginFind::GetInterface(), true }, |
| 60 { PPB_FONT_DEV_INTERFACE, PluginFont::GetInterface(), true }, |
| 61 { PPB_GRAPHICS_2D_INTERFACE, PluginGraphics2D::GetInterface(), true }, |
| 62 { PPB_GRAPHICS_3D_DEV_INTERFACE, PluginGraphics3D::GetInterface(), true }, |
| 63 { PPB_IMAGEDATA_INTERFACE, PluginImageData::GetInterface(), true }, |
| 64 { PPB_INPUT_EVENT_INTERFACE, PluginInputEvent::GetInterface(), true }, |
| 65 { PPB_INSTANCE_INTERFACE, PluginInstance::GetInterface(), true }, |
| 66 { PPB_KEYBOARD_INPUT_EVENT_INTERFACE, |
| 67 PluginInputEvent::GetKeyboardInterface(), true }, |
| 68 { PPB_MEMORY_DEV_INTERFACE, PluginMemory::GetInterface(), true }, |
| 69 { PPB_MESSAGING_INTERFACE, PluginMessaging::GetInterface(), true }, |
| 70 { PPB_MOUSE_INPUT_EVENT_INTERFACE, PluginInputEvent::GetMouseInterface(), |
| 71 true }, |
| 72 { PPB_OPENGLES2_DEV_INTERFACE, PluginGraphics3D::GetOpenGLESInterface(), |
| 73 true }, |
| 74 { PPB_PDF_INTERFACE, PluginPDF::GetInterface(), true }, |
| 75 { PPB_SCROLLBAR_DEV_INTERFACE, PluginScrollbar::GetInterface(), true }, |
| 76 { PPB_TESTING_DEV_INTERFACE, PluginTesting::GetInterface(), true }, |
| 77 { PPB_URLLOADER_INTERFACE, PluginURLLoader::GetInterface(), true }, |
| 78 { PPB_URLREQUESTINFO_INTERFACE, PluginURLRequestInfo::GetInterface(), true }, |
| 79 { PPB_URLRESPONSEINFO_INTERFACE, PluginURLResponseInfo::GetInterface(), |
| 80 true }, |
| 81 { PPB_VAR_INTERFACE, PluginVar::GetInterface(), true }, |
| 82 { PPB_WHEEL_INPUT_EVENT_INTERFACE, PluginInputEvent::GetWheelInterface(), |
| 83 true }, |
| 84 { PPB_WIDGET_DEV_INTERFACE, PluginWidget::GetInterface(), true }, |
| 85 { PPB_ZOOM_DEV_INTERFACE, PluginZoom::GetInterface(), true }, |
| 86 }; |
| 87 |
| 88 } // namespace |
| 89 |
| 90 // Returns the pointer to the interface proxy or NULL if not yet supported. |
| 91 // On the first invocation for a given interface that has proxy support, |
| 92 // also confirms over RPC that the browser indeed exports this interface. |
| 93 // Returns NULL otherwise. |
| 94 const void* GetBrowserInterface(const char* interface_name) { |
| 95 DebugPrintf("PPB_GetInterface('%s')\n", interface_name); |
| 96 const void* ppb_interface = NULL; |
| 97 int index = -1; |
| 98 // The interface map is so small that anything but a linear search would be an |
| 99 // overkill, especially since the keys are macros and might not sort in any |
| 100 // obvious order relative to the name. |
| 101 for (size_t i = 0; i < NACL_ARRAY_SIZE(interface_map); ++i) { |
| 102 if (strcmp(interface_name, interface_map[i].name) == 0) { |
| 103 ppb_interface = interface_map[i].ppb_interface; |
| 104 index = i; |
| 105 break; |
| 106 } |
| 107 } |
| 108 DebugPrintf("PPB_GetInterface('%s'): %p\n", interface_name, ppb_interface); |
| 109 if (index == -1 || ppb_interface == NULL) |
| 110 return NULL; |
| 111 if (!interface_map[index].needs_browser_check) |
| 112 return ppb_interface; |
| 113 |
| 114 int32_t browser_exports_interface; |
| 115 NaClSrpcError srpc_result = |
| 116 PpbRpcClient::PPB_GetInterface(GetMainSrpcChannel(), |
| 117 const_cast<char*>(interface_name), |
| 118 &browser_exports_interface); |
| 119 DebugPrintf("PPB_GetInterface('%s'): %s\n", |
| 120 interface_name, NaClSrpcErrorString(srpc_result)); |
| 121 if (srpc_result != NACL_SRPC_RESULT_OK || !browser_exports_interface) { |
| 122 interface_map[index].ppb_interface = NULL; |
| 123 ppb_interface = NULL; |
| 124 } |
| 125 interface_map[index].needs_browser_check = false; |
| 126 return ppb_interface; |
| 127 } |
| 128 |
| 129 } // namespace ppapi_proxy |
OLD | NEW |