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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
|
// Copyright (c) 2009 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.
#include "webkit/glue/plugins/npapi_extension_thunk.h"
#include "base/logging.h"
#include "third_party/npapi/bindings/npapi_extensions.h"
#include "webkit/glue/plugins/plugin_instance.h"
#include "webkit/glue/webplugin.h"
#include "webkit/glue/webplugin_delegate.h"
//#include "third_party/npapi/bindings/npruntime.h"
#if defined(ENABLE_PEPPER)
// FindInstance()
// Finds a PluginInstance from an NPP.
// The caller must take a reference if needed.
static NPAPI::PluginInstance* FindInstance(NPP id) {
if (id == NULL) {
NOTREACHED();
return NULL;
}
return static_cast<NPAPI::PluginInstance*>(id->ndata);
}
// 2D device API ---------------------------------------------------------------
static NPError Device2DQueryCapability(NPP id, int32 capability, int32* value) {
scoped_refptr<NPAPI::PluginInstance> plugin = FindInstance(id);
if (plugin) {
plugin->webplugin()->delegate()->Device2DQueryCapability(capability, value);
return NPERR_NO_ERROR;
} else {
return NPERR_GENERIC_ERROR;
}
}
static NPError Device2DQueryConfig(NPP id,
const NPDeviceConfig* request,
NPDeviceConfig* obtain) {
scoped_refptr<NPAPI::PluginInstance> plugin = FindInstance(id);
if (plugin) {
return plugin->webplugin()->delegate()->Device2DQueryConfig(
static_cast<const NPDeviceContext2DConfig*>(request),
static_cast<NPDeviceContext2DConfig*>(obtain));
}
return NPERR_GENERIC_ERROR;
}
static NPError Device2DInitializeContext(NPP id,
const NPDeviceConfig* config,
NPDeviceContext* context) {
scoped_refptr<NPAPI::PluginInstance> plugin = FindInstance(id);
if (plugin) {
return plugin->webplugin()->delegate()->Device2DInitializeContext(
static_cast<const NPDeviceContext2DConfig*>(config),
static_cast<NPDeviceContext2D*>(context));
}
return NPERR_GENERIC_ERROR;
}
static NPError Device2DSetStateContext(NPP id,
NPDeviceContext* context,
int32 state,
int32 value) {
scoped_refptr<NPAPI::PluginInstance> plugin = FindInstance(id);
if (plugin) {
return plugin->webplugin()->delegate()->Device2DSetStateContext(
static_cast<NPDeviceContext2D*>(context), state, value);
}
return NPERR_GENERIC_ERROR;
}
static NPError Device2DGetStateContext(NPP id,
NPDeviceContext* context,
int32 state,
int32* value) {
scoped_refptr<NPAPI::PluginInstance> plugin = FindInstance(id);
if (plugin) {
return plugin->webplugin()->delegate()->Device2DGetStateContext(
static_cast<NPDeviceContext2D*>(context), state, value);
}
return NPERR_GENERIC_ERROR;
}
static NPError Device2DFlushContext(NPP id,
NPDeviceContext* context,
NPDeviceFlushContextCallbackPtr callback,
void* user_data) {
scoped_refptr<NPAPI::PluginInstance> plugin = FindInstance(id);
if (plugin) {
NPError err = plugin->webplugin()->delegate()->Device2DFlushContext(
id, static_cast<NPDeviceContext2D*>(context), callback, user_data);
// Invoke the callback to inform the caller the work was done.
// TODO(brettw) this is probably not how we want this to work, this should
// happen when the frame is painted so the plugin knows when it can draw
// the next frame.
if (callback != NULL)
(*callback)(id, context, err, user_data);
// Return any errors.
return err;
}
return NPERR_GENERIC_ERROR;
}
static NPError Device2DDestroyContext(NPP id,
NPDeviceContext* context) {
scoped_refptr<NPAPI::PluginInstance> plugin = FindInstance(id);
if (plugin) {
return plugin->webplugin()->delegate()->Device2DDestroyContext(
static_cast<NPDeviceContext2D*>(context));
}
return NPERR_GENERIC_ERROR;
}
// 3D device API ---------------------------------------------------------------
static NPError Device3DQueryCapability(NPP id, int32 capability, int32* value) {
scoped_refptr<NPAPI::PluginInstance> plugin = FindInstance(id);
if (plugin) {
plugin->webplugin()->delegate()->Device3DQueryCapability(capability, value);
return NPERR_NO_ERROR;
} else {
return NPERR_GENERIC_ERROR;
}
}
static NPError Device3DQueryConfig(NPP id,
const NPDeviceConfig* request,
NPDeviceConfig* obtain) {
scoped_refptr<NPAPI::PluginInstance> plugin = FindInstance(id);
if (plugin) {
return plugin->webplugin()->delegate()->Device3DQueryConfig(
static_cast<const NPDeviceContext3DConfig*>(request),
static_cast<NPDeviceContext3DConfig*>(obtain));
}
return NPERR_GENERIC_ERROR;
}
static NPError Device3DInitializeContext(NPP id,
const NPDeviceConfig* config,
NPDeviceContext* context) {
scoped_refptr<NPAPI::PluginInstance> plugin = FindInstance(id);
if (plugin) {
return plugin->webplugin()->delegate()->Device3DInitializeContext(
static_cast<const NPDeviceContext3DConfig*>(config),
static_cast<NPDeviceContext3D*>(context));
}
return NPERR_GENERIC_ERROR;
}
static NPError Device3DSetStateContext(NPP id,
NPDeviceContext* context,
int32 state,
int32 value) {
scoped_refptr<NPAPI::PluginInstance> plugin = FindInstance(id);
if (plugin) {
return plugin->webplugin()->delegate()->Device3DSetStateContext(
static_cast<NPDeviceContext3D*>(context), state, value);
}
return NPERR_GENERIC_ERROR;
}
static NPError Device3DGetStateContext(NPP id,
NPDeviceContext* context,
int32 state,
int32* value) {
scoped_refptr<NPAPI::PluginInstance> plugin = FindInstance(id);
if (plugin) {
return plugin->webplugin()->delegate()->Device3DGetStateContext(
static_cast<NPDeviceContext3D*>(context), state, value);
}
return NPERR_GENERIC_ERROR;
}
static NPError Device3DFlushContext(NPP id,
NPDeviceContext* context,
NPDeviceFlushContextCallbackPtr callback,
void* user_data) {
scoped_refptr<NPAPI::PluginInstance> plugin = FindInstance(id);
if (plugin) {
return plugin->webplugin()->delegate()->Device3DFlushContext(
id, static_cast<NPDeviceContext3D*>(context), callback, user_data);
}
return NPERR_GENERIC_ERROR;
}
static NPError Device3DDestroyContext(NPP id,
NPDeviceContext* context) {
scoped_refptr<NPAPI::PluginInstance> plugin = FindInstance(id);
if (plugin) {
return plugin->webplugin()->delegate()->Device3DDestroyContext(
static_cast<NPDeviceContext3D*>(context));
}
return NPERR_GENERIC_ERROR;
}
// -----------------------------------------------------------------------------
static NPDevice* AcquireDevice(NPP id, NPDeviceID device_id) {
static NPDevice device_2d = {
Device2DQueryCapability,
Device2DQueryConfig,
Device2DInitializeContext,
Device2DSetStateContext,
Device2DGetStateContext,
Device2DFlushContext,
Device2DDestroyContext,
};
static NPDevice device_3d = {
Device3DQueryCapability,
Device3DQueryConfig,
Device3DInitializeContext,
Device3DSetStateContext,
Device3DGetStateContext,
Device3DFlushContext,
Device3DDestroyContext,
};
switch (device_id) {
case NPPepper2DDevice:
return const_cast<NPDevice*>(&device_2d);
case NPPepper3DDevice:
return const_cast<NPDevice*>(&device_3d);
default:
return NULL;
}
}
namespace NPAPI {
NPError GetPepperExtensionsFunctions(void* value) {
static const NPExtensions kExtensions = {
&AcquireDevice,
};
// Return a pointer to the canonical function table.
NPExtensions* extensions = const_cast<NPExtensions*>(&kExtensions);
NPExtensions** exts = reinterpret_cast<NPExtensions**>(value);
*exts = extensions;
return NPERR_NO_ERROR;
}
} // namespace NPAPI
#else // Not compiling with pepper support
namespace NPAPI {
// This NOP function implements the getter for the extensions when the
// extensions aren't available.
NPError GetPepperExtensionsFunctions(void* value) {
return NPERR_GENERIC_ERROR;
}
} // namespace NPAPI
#endif // defined(ENABLE_PEPPER)
|