1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Implements the untrusted side of the PPB_GetInterface method.
#include "native_client/src/shared/ppapi_proxy/plugin_globals.h"
#include <stdlib.h>
#include <string.h>
#include "native_client/src/shared/ppapi_proxy/plugin_ppb_audio.h"
#include "native_client/src/shared/ppapi_proxy/plugin_ppb_audio_config.h"
#include "native_client/src/shared/ppapi_proxy/plugin_ppb_buffer.h"
#include "native_client/src/shared/ppapi_proxy/plugin_ppb_core.h"
#include "native_client/src/shared/ppapi_proxy/plugin_ppb_cursor_control.h"
#include "native_client/src/shared/ppapi_proxy/plugin_ppb_file_io.h"
#include "native_client/src/shared/ppapi_proxy/plugin_ppb_file_ref.h"
#include "native_client/src/shared/ppapi_proxy/plugin_ppb_file_system.h"
#include "native_client/src/shared/ppapi_proxy/plugin_ppb_find.h"
#include "native_client/src/shared/ppapi_proxy/plugin_ppb_font.h"
#include "native_client/src/shared/ppapi_proxy/plugin_ppb_fullscreen.h"
#include "native_client/src/shared/ppapi_proxy/plugin_ppb_gamepad.h"
#include "native_client/src/shared/ppapi_proxy/plugin_ppb_graphics_2d.h"
#include "native_client/src/shared/ppapi_proxy/plugin_ppb_graphics_3d.h"
#include "native_client/src/shared/ppapi_proxy/plugin_ppb_image_data.h"
#include "native_client/src/shared/ppapi_proxy/plugin_ppb_input_event.h"
#include "native_client/src/shared/ppapi_proxy/plugin_ppb_instance.h"
#include "native_client/src/shared/ppapi_proxy/plugin_ppb_memory.h"
#include "native_client/src/shared/ppapi_proxy/plugin_ppb_messaging.h"
#include "native_client/src/shared/ppapi_proxy/plugin_ppb_mouse_lock.h"
#include "native_client/src/shared/ppapi_proxy/plugin_ppb_net_address_private.h"
#include "native_client/src/shared/ppapi_proxy/plugin_ppb_pdf.h"
#include "native_client/src/shared/ppapi_proxy/plugin_ppb_scrollbar.h"
#include "native_client/src/shared/ppapi_proxy/plugin_ppb_tcp_socket_private.h"
#include "native_client/src/shared/ppapi_proxy/plugin_ppb_testing.h"
#include "native_client/src/shared/ppapi_proxy/plugin_ppb_udp_socket_private.h"
#include "native_client/src/shared/ppapi_proxy/plugin_ppb_url_loader.h"
#include "native_client/src/shared/ppapi_proxy/plugin_ppb_url_request_info.h"
#include "native_client/src/shared/ppapi_proxy/plugin_ppb_url_response_info.h"
#include "native_client/src/shared/ppapi_proxy/plugin_ppb_var.h"
#include "native_client/src/shared/ppapi_proxy/plugin_ppb_view.h"
#include "native_client/src/shared/ppapi_proxy/plugin_ppb_websocket.h"
#include "native_client/src/shared/ppapi_proxy/plugin_ppb_widget.h"
#include "native_client/src/shared/ppapi_proxy/plugin_ppb_zoom.h"
#include "native_client/src/shared/ppapi_proxy/untrusted/srpcgen/ppb_rpc.h"
#include "native_client/src/shared/ppapi_proxy/utility.h"
namespace ppapi_proxy {
namespace {
struct InterfaceMapElement {
const char* name;
const void* ppb_interface;
bool needs_browser_check;
};
// List of interfaces that have at least partial proxy support.
InterfaceMapElement interface_map[] = {
{ PPB_AUDIO_INTERFACE, PluginAudio::GetInterface(), true },
{ PPB_AUDIO_CONFIG_INTERFACE, PluginAudioConfig::GetInterface(), true },
{ PPB_CORE_INTERFACE, PluginCore::GetInterface(), true },
{ PPB_CURSOR_CONTROL_DEV_INTERFACE, PluginCursorControl::GetInterface(),
true },
{ PPB_FILEIO_INTERFACE, PluginFileIO::GetInterface(), true },
{ PPB_FILEREF_INTERFACE, PluginFileRef::GetInterface(), true },
{ PPB_FILESYSTEM_INTERFACE, PluginFileSystem::GetInterface(), true },
{ PPB_FIND_DEV_INTERFACE, PluginFind::GetInterface(), true },
{ PPB_FONT_DEV_INTERFACE, PluginFont::GetInterface(), true },
{ PPB_FULLSCREEN_INTERFACE, PluginFullscreen::GetInterface(), true },
{ PPB_GAMEPAD_DEV_INTERFACE, PluginGamepad::GetInterface(), true },
{ PPB_GRAPHICS_2D_INTERFACE, PluginGraphics2D::GetInterface(), true },
{ PPB_GRAPHICS_3D_INTERFACE, PluginGraphics3D::GetInterface(), true },
{ PPB_IMAGEDATA_INTERFACE, PluginImageData::GetInterface(), true },
{ PPB_INPUT_EVENT_INTERFACE, PluginInputEvent::GetInterface(), true },
{ PPB_INSTANCE_INTERFACE, PluginInstance::GetInterface(), true },
{ PPB_KEYBOARD_INPUT_EVENT_INTERFACE,
PluginInputEvent::GetKeyboardInterface(), true },
{ PPB_MEMORY_DEV_INTERFACE, PluginMemory::GetInterface(), true },
{ PPB_MESSAGING_INTERFACE, PluginMessaging::GetInterface(), true },
{ PPB_MOUSE_INPUT_EVENT_INTERFACE_1_0,
PluginInputEvent::GetMouseInterface1_0(), true },
{ PPB_MOUSE_INPUT_EVENT_INTERFACE_1_1,
PluginInputEvent::GetMouseInterface1_1(), true },
{ PPB_MOUSELOCK_INTERFACE, PluginMouseLock::GetInterface(), true },
{ PPB_NETADDRESS_PRIVATE_INTERFACE, PluginNetAddressPrivate::GetInterface(),
true },
{ PPB_OPENGLES2_INTERFACE, PluginGraphics3D::GetOpenGLESInterface(),
true },
{ PPB_PDF_INTERFACE, PluginPDF::GetInterface(), true },
{ PPB_SCROLLBAR_DEV_INTERFACE, PluginScrollbar::GetInterface(), true },
{ PPB_TCPSOCKET_PRIVATE_INTERFACE, PluginTCPSocketPrivate::GetInterface(),
true },
{ PPB_TESTING_DEV_INTERFACE_0_9, PluginTesting::GetInterface(), true },
{ PPB_TESTING_DEV_INTERFACE, PluginTesting::GetInterface(), true },
{ PPB_UDPSOCKET_PRIVATE_INTERFACE, PluginUDPSocketPrivate::GetInterface(),
true },
{ PPB_URLLOADER_INTERFACE, PluginURLLoader::GetInterface(), true },
{ PPB_URLREQUESTINFO_INTERFACE, PluginURLRequestInfo::GetInterface(), true },
{ PPB_URLRESPONSEINFO_INTERFACE, PluginURLResponseInfo::GetInterface(),
true },
{ PPB_VAR_ARRAY_BUFFER_INTERFACE, PluginVar::GetArrayBufferInterface(),
true },
{ PPB_VAR_INTERFACE, PluginVar::GetInterface(), true },
{ PPB_VAR_INTERFACE_1_0, PluginVar::GetInterface1_0(), true },
{ PPB_VIEW_INTERFACE, PluginView::GetInterface(), true },
{ PPB_WEBSOCKET_INTERFACE, PluginWebSocket::GetInterface(),
true },
{ PPB_WHEEL_INPUT_EVENT_INTERFACE, PluginInputEvent::GetWheelInterface(),
true },
{ PPB_WIDGET_DEV_INTERFACE, PluginWidget::GetInterface(), true },
{ PPB_ZOOM_DEV_INTERFACE, PluginZoom::GetInterface(), true },
};
} // namespace
// Returns the pointer to the interface proxy or NULL if not yet supported.
// On the first invocation for a given interface that has proxy support,
// also confirms over RPC that the browser indeed exports this interface.
// Returns NULL otherwise.
const void* GetBrowserInterface(const char* interface_name) {
DebugPrintf("PPB_GetInterface('%s')\n", interface_name);
const void* ppb_interface = NULL;
int index = -1;
// The interface map is so small that anything but a linear search would be an
// overkill, especially since the keys are macros and might not sort in any
// obvious order relative to the name.
for (size_t i = 0; i < NACL_ARRAY_SIZE(interface_map); ++i) {
if (strcmp(interface_name, interface_map[i].name) == 0) {
ppb_interface = interface_map[i].ppb_interface;
index = i;
break;
}
}
DebugPrintf("PPB_GetInterface('%s'): %p\n", interface_name, ppb_interface);
if (index == -1 || ppb_interface == NULL)
return NULL;
if (!interface_map[index].needs_browser_check)
return ppb_interface;
int32_t browser_exports_interface;
NaClSrpcError srpc_result =
PpbRpcClient::PPB_GetInterface(GetMainSrpcChannel(),
const_cast<char*>(interface_name),
&browser_exports_interface);
DebugPrintf("PPB_GetInterface('%s'): %s\n",
interface_name, NaClSrpcErrorString(srpc_result));
if (srpc_result != NACL_SRPC_RESULT_OK || !browser_exports_interface) {
interface_map[index].ppb_interface = NULL;
ppb_interface = NULL;
}
interface_map[index].needs_browser_check = false;
return ppb_interface;
}
} // namespace ppapi_proxy
|