blob: 35dd5d65a54d58dfe5c699e9b67ebe70811249cd [file] [log] [blame]
Grace Klobafbe47c02009-05-14 17:31:45 -07001/*
2 * Copyright 2008, The Android Open Source Project
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#include <stdlib.h>
27#include <string.h>
28#include <stdio.h>
29#include "main.h"
30#include "PluginObject.h"
Derek Sollenbergerd7ebf272009-06-18 11:19:41 -040031#include "AnimationPlugin.h"
Derek Sollenbergerf42e2f42009-06-26 11:42:46 -040032#include "AudioPlugin.h"
Derek Sollenbergerd7ebf272009-06-18 11:19:41 -040033#include "BackgroundPlugin.h"
Derek Sollenbergerdb398a72009-06-29 13:53:04 -040034#include "FormPlugin.h"
Derek Sollenberger4fb83e62009-07-27 16:40:13 -040035#include "PaintPlugin.h"
Derek Sollenbergerb8947ee2009-10-05 14:40:18 -040036#include "VideoPlugin.h"
Grace Klobafbe47c02009-05-14 17:31:45 -070037
38NPNetscapeFuncs* browser;
Derek Sollenbergerb8947ee2009-10-05 14:40:18 -040039JavaVM* gVM;
40
Grace Klobafbe47c02009-05-14 17:31:45 -070041#define EXPORT __attribute__((visibility("default")))
42
Derek Sollenberger9119e7d2009-06-08 10:53:09 -040043NPError NPP_New(NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc,
Grace Klobafbe47c02009-05-14 17:31:45 -070044 char* argn[], char* argv[], NPSavedData* saved);
45NPError NPP_Destroy(NPP instance, NPSavedData** save);
46NPError NPP_SetWindow(NPP instance, NPWindow* window);
Derek Sollenberger9119e7d2009-06-08 10:53:09 -040047NPError NPP_NewStream(NPP instance, NPMIMEType type, NPStream* stream,
Grace Klobafbe47c02009-05-14 17:31:45 -070048 NPBool seekable, uint16* stype);
49NPError NPP_DestroyStream(NPP instance, NPStream* stream, NPReason reason);
50int32 NPP_WriteReady(NPP instance, NPStream* stream);
Derek Sollenberger9119e7d2009-06-08 10:53:09 -040051int32 NPP_Write(NPP instance, NPStream* stream, int32 offset, int32 len,
Grace Klobafbe47c02009-05-14 17:31:45 -070052 void* buffer);
53void NPP_StreamAsFile(NPP instance, NPStream* stream, const char* fname);
54void NPP_Print(NPP instance, NPPrint* platformPrint);
55int16 NPP_HandleEvent(NPP instance, void* event);
Derek Sollenberger9119e7d2009-06-08 10:53:09 -040056void NPP_URLNotify(NPP instance, const char* URL, NPReason reason,
Grace Klobafbe47c02009-05-14 17:31:45 -070057 void* notifyData);
58NPError NPP_GetValue(NPP instance, NPPVariable variable, void *value);
59NPError NPP_SetValue(NPP instance, NPNVariable variable, void *value);
60
61extern "C" {
62EXPORT NPError NP_Initialize(NPNetscapeFuncs* browserFuncs, NPPluginFuncs* pluginFuncs, void *java_env, void *application_context);
63EXPORT NPError NP_GetValue(NPP instance, NPPVariable variable, void *value);
64EXPORT const char* NP_GetMIMEDescription(void);
Derek Sollenberger9119e7d2009-06-08 10:53:09 -040065EXPORT void NP_Shutdown(void);
Grace Klobafbe47c02009-05-14 17:31:45 -070066};
67
68ANPAudioTrackInterfaceV0 gSoundI;
Mike Reed224adad2009-06-10 10:24:01 -040069ANPBitmapInterfaceV0 gBitmapI;
Grace Klobafbe47c02009-05-14 17:31:45 -070070ANPCanvasInterfaceV0 gCanvasI;
Derek Sollenbergerd53b56d2010-01-11 12:31:49 -050071ANPEventInterfaceV0 gEventI;
Grace Klobafbe47c02009-05-14 17:31:45 -070072ANPLogInterfaceV0 gLogI;
73ANPPaintInterfaceV0 gPaintI;
74ANPPathInterfaceV0 gPathI;
Derek Sollenbergerc0f26572009-07-16 11:38:02 -040075ANPSurfaceInterfaceV0 gSurfaceI;
Grace Kloba9ffe5ac2009-08-04 17:51:06 -070076ANPSystemInterfaceV0 gSystemI;
Grace Klobafbe47c02009-05-14 17:31:45 -070077ANPTypefaceInterfaceV0 gTypefaceI;
Derek Sollenberger5b011e32009-06-22 11:39:40 -040078ANPWindowInterfaceV0 gWindowI;
Grace Klobafbe47c02009-05-14 17:31:45 -070079
80#define ARRAY_COUNT(array) (sizeof(array) / sizeof(array[0]))
Derek Sollenberger5b011e32009-06-22 11:39:40 -040081#define DEBUG_PLUGIN_EVENTS 0
Grace Klobafbe47c02009-05-14 17:31:45 -070082
83NPError NP_Initialize(NPNetscapeFuncs* browserFuncs, NPPluginFuncs* pluginFuncs, void *java_env, void *application_context)
84{
85 // Make sure we have a function table equal or larger than we are built against.
86 if (browserFuncs->size < sizeof(NPNetscapeFuncs)) {
87 return NPERR_GENERIC_ERROR;
88 }
Derek Sollenberger9119e7d2009-06-08 10:53:09 -040089
Grace Klobafbe47c02009-05-14 17:31:45 -070090 // Copy the function table (structure)
91 browser = (NPNetscapeFuncs*) malloc(sizeof(NPNetscapeFuncs));
92 memcpy(browser, browserFuncs, sizeof(NPNetscapeFuncs));
Derek Sollenberger9119e7d2009-06-08 10:53:09 -040093
Grace Klobafbe47c02009-05-14 17:31:45 -070094 // Build the plugin function table
95 pluginFuncs->version = 11;
96 pluginFuncs->size = sizeof(pluginFuncs);
97 pluginFuncs->newp = NPP_New;
98 pluginFuncs->destroy = NPP_Destroy;
99 pluginFuncs->setwindow = NPP_SetWindow;
100 pluginFuncs->newstream = NPP_NewStream;
101 pluginFuncs->destroystream = NPP_DestroyStream;
102 pluginFuncs->asfile = NPP_StreamAsFile;
103 pluginFuncs->writeready = NPP_WriteReady;
104 pluginFuncs->write = (NPP_WriteProcPtr)NPP_Write;
105 pluginFuncs->print = NPP_Print;
106 pluginFuncs->event = NPP_HandleEvent;
107 pluginFuncs->urlnotify = NPP_URLNotify;
108 pluginFuncs->getvalue = NPP_GetValue;
109 pluginFuncs->setvalue = NPP_SetValue;
110
111 static const struct {
112 NPNVariable v;
113 uint32_t size;
114 ANPInterface* i;
115 } gPairs[] = {
Derek Sollenbergerc0f26572009-07-16 11:38:02 -0400116 { kAudioTrackInterfaceV0_ANPGetValue, sizeof(gSoundI), &gSoundI },
Mike Reed224adad2009-06-10 10:24:01 -0400117 { kBitmapInterfaceV0_ANPGetValue, sizeof(gBitmapI), &gBitmapI },
Grace Klobafbe47c02009-05-14 17:31:45 -0700118 { kCanvasInterfaceV0_ANPGetValue, sizeof(gCanvasI), &gCanvasI },
Derek Sollenbergerd53b56d2010-01-11 12:31:49 -0500119 { kEventInterfaceV0_ANPGetValue, sizeof(gEventI), &gEventI },
Mike Reed224adad2009-06-10 10:24:01 -0400120 { kLogInterfaceV0_ANPGetValue, sizeof(gLogI), &gLogI },
Grace Klobafbe47c02009-05-14 17:31:45 -0700121 { kPaintInterfaceV0_ANPGetValue, sizeof(gPaintI), &gPaintI },
122 { kPathInterfaceV0_ANPGetValue, sizeof(gPathI), &gPathI },
Derek Sollenbergerc0f26572009-07-16 11:38:02 -0400123 { kSurfaceInterfaceV0_ANPGetValue, sizeof(gSurfaceI), &gSurfaceI },
Grace Kloba9ffe5ac2009-08-04 17:51:06 -0700124 { kSystemInterfaceV0_ANPGetValue, sizeof(gSystemI), &gSystemI },
125 { kTypefaceInterfaceV0_ANPGetValue, sizeof(gTypefaceI), &gTypefaceI },
Derek Sollenbergerc0f26572009-07-16 11:38:02 -0400126 { kWindowInterfaceV0_ANPGetValue, sizeof(gWindowI), &gWindowI },
Grace Klobafbe47c02009-05-14 17:31:45 -0700127 };
128 for (size_t i = 0; i < ARRAY_COUNT(gPairs); i++) {
129 gPairs[i].i->inSize = gPairs[i].size;
130 NPError err = browser->getvalue(NULL, gPairs[i].v, gPairs[i].i);
131 if (err) {
132 return err;
133 }
134 }
Derek Sollenberger9119e7d2009-06-08 10:53:09 -0400135
Derek Sollenbergerb8947ee2009-10-05 14:40:18 -0400136 // store the JavaVM for the plugin
137 JNIEnv* env = (JNIEnv*)java_env;
138 env->GetJavaVM(&gVM);
139
Grace Klobafbe47c02009-05-14 17:31:45 -0700140 return NPERR_NO_ERROR;
141}
142
143void NP_Shutdown(void)
144{
145
146}
147
Derek Sollenberger9119e7d2009-06-08 10:53:09 -0400148const char *NP_GetMIMEDescription(void)
Grace Klobafbe47c02009-05-14 17:31:45 -0700149{
Derek Sollenbergerd7ebf272009-06-18 11:19:41 -0400150 return "application/x-testbrowserplugin:tst:Test plugin mimetype is application/x-testbrowserplugin";
Grace Klobafbe47c02009-05-14 17:31:45 -0700151}
152
153NPError NPP_New(NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc,
154 char* argn[], char* argv[], NPSavedData* saved)
155{
Derek Sollenbergerd7ebf272009-06-18 11:19:41 -0400156
157 /* BEGIN: STANDARD PLUGIN FRAMEWORK */
Grace Klobafbe47c02009-05-14 17:31:45 -0700158 PluginObject *obj = NULL;
159
160 // Scripting functions appeared in NPAPI version 14
161 if (browser->version >= 14) {
Derek Sollenbergerb4a23912009-11-09 15:38:58 -0500162 instance->pdata = browser->createobject (instance, getPluginClass());
163 obj = static_cast<PluginObject*>(instance->pdata);
Grace Klobafbe47c02009-05-14 17:31:45 -0700164 }
Derek Sollenbergerd7ebf272009-06-18 11:19:41 -0400165 /* END: STANDARD PLUGIN FRAMEWORK */
Derek Sollenberger9119e7d2009-06-08 10:53:09 -0400166
Derek Sollenberger4fb83e62009-07-27 16:40:13 -0400167 // select the drawing model based on user input
168 ANPDrawingModel model = kBitmap_ANPDrawingModel;
169
170 for (int i = 0; i < argc; i++) {
171 if (!strcmp(argn[i], "DrawingModel")) {
172 if (!strcmp(argv[i], "Bitmap")) {
173 model = kBitmap_ANPDrawingModel;
174 }
175 else if (!strcmp(argv[i], "Surface")) {
176 model = kSurface_ANPDrawingModel;
177 }
Derek Sollenbergere62ce172009-11-30 11:52:06 -0500178 gLogI.log(kDebug_ANPLogType, "------ %p DrawingModel is %d", instance, model);
Derek Sollenberger4fb83e62009-07-27 16:40:13 -0400179 break;
180 }
181 }
182
183 // notify the plugin API of the drawing model we wish to use. This must be
184 // done prior to creating certain subPlugin objects (e.g. surfaceViews)
185 NPError err = browser->setvalue(instance, kRequestDrawingModel_ANPSetValue,
186 reinterpret_cast<void*>(model));
187 if (err) {
Derek Sollenbergere62ce172009-11-30 11:52:06 -0500188 gLogI.log(kError_ANPLogType, "request model %d err %d", model, err);
Derek Sollenberger4fb83e62009-07-27 16:40:13 -0400189 return err;
190 }
191
Grace Kloba9ffe5ac2009-08-04 17:51:06 -0700192 const char* path = gSystemI.getApplicationDataDirectory();
193 if (path) {
Derek Sollenbergere62ce172009-11-30 11:52:06 -0500194 gLogI.log(kDebug_ANPLogType, "Application data dir is %s", path);
Grace Kloba9ffe5ac2009-08-04 17:51:06 -0700195 } else {
Derek Sollenbergere62ce172009-11-30 11:52:06 -0500196 gLogI.log(kError_ANPLogType, "Can't find Application data dir");
Grace Kloba9ffe5ac2009-08-04 17:51:06 -0700197 }
198
Derek Sollenbergerd7ebf272009-06-18 11:19:41 -0400199 // select the pluginType
200 for (int i = 0; i < argc; i++) {
201 if (!strcmp(argn[i], "PluginType")) {
202 if (!strcmp(argv[i], "Animation")) {
203 obj->pluginType = kAnimation_PluginType;
204 obj->activePlugin = new BallAnimation(instance);
205 }
206 else if (!strcmp(argv[i], "Audio")) {
207 obj->pluginType = kAudio_PluginType;
Derek Sollenbergerf42e2f42009-06-26 11:42:46 -0400208 obj->activePlugin = new AudioPlugin(instance);
Derek Sollenbergerd7ebf272009-06-18 11:19:41 -0400209 }
210 else if (!strcmp(argv[i], "Background")) {
211 obj->pluginType = kBackground_PluginType;
212 obj->activePlugin = new BackgroundPlugin(instance);
213 }
Derek Sollenbergerdb398a72009-06-29 13:53:04 -0400214 else if (!strcmp(argv[i], "Form")) {
215 obj->pluginType = kForm_PluginType;
216 obj->activePlugin = new FormPlugin(instance);
217 }
Derek Sollenberger4fb83e62009-07-27 16:40:13 -0400218 else if (!strcmp(argv[i], "Paint")) {
219 obj->pluginType = kPaint_PluginType;
220 obj->activePlugin = new PaintPlugin(instance);
221 }
Derek Sollenbergerb8947ee2009-10-05 14:40:18 -0400222 else if (!strcmp(argv[i], "Video")) {
223 obj->pluginType = kVideo_PluginType;
224 obj->activePlugin = new VideoPlugin(instance);
225 }
Derek Sollenbergere62ce172009-11-30 11:52:06 -0500226 gLogI.log(kDebug_ANPLogType, "------ %p PluginType is %d", instance, obj->pluginType);
Derek Sollenbergerd7ebf272009-06-18 11:19:41 -0400227 break;
228 }
229 }
230
231 // if no pluginType is specified then default to Animation
232 if (!obj->pluginType) {
Derek Sollenbergere62ce172009-11-30 11:52:06 -0500233 gLogI.log(kError_ANPLogType, "------ %p No PluginType attribute was found", instance);
Derek Sollenbergerd7ebf272009-06-18 11:19:41 -0400234 obj->pluginType = kAnimation_PluginType;
235 obj->activePlugin = new BallAnimation(instance);
236 }
237
Derek Sollenberger21f39912009-07-09 09:19:39 -0400238 // check to ensure the pluginType supports the model
239 if (!obj->activePlugin->supportsDrawingModel(model)) {
Derek Sollenbergere62ce172009-11-30 11:52:06 -0500240 gLogI.log(kError_ANPLogType, "------ %p Unsupported DrawingModel (%d)", instance, model);
Derek Sollenberger21f39912009-07-09 09:19:39 -0400241 return NPERR_GENERIC_ERROR;
242 }
243
Derek Sollenbergerd53b56d2010-01-11 12:31:49 -0500244 // if the plugin uses the surface drawing model then set the java context
245 if (model == kSurface_ANPDrawingModel) {
246 SurfaceSubPlugin* surfacePlugin = static_cast<SurfaceSubPlugin*>(obj->activePlugin);
247
248 jobject context;
249 NPError err = browser->getvalue(instance, kJavaContext_ANPGetValue,
250 static_cast<void*>(&context));
251 if (err) {
252 gLogI.log(kError_ANPLogType, "request context err: %d", err);
253 return err;
254 }
255
256 surfacePlugin->setContext(context);
257 }
258
259
Derek Sollenbergerd7ebf272009-06-18 11:19:41 -0400260 return NPERR_NO_ERROR;
Grace Klobafbe47c02009-05-14 17:31:45 -0700261}
262
263NPError NPP_Destroy(NPP instance, NPSavedData** save)
264{
265 PluginObject *obj = (PluginObject*) instance->pdata;
Grace Klobaa0e762c2009-12-27 13:21:41 -0800266 if (obj) {
267 delete obj->activePlugin;
268 browser->releaseobject(&obj->header);
269 }
Grace Klobafbe47c02009-05-14 17:31:45 -0700270
271 return NPERR_NO_ERROR;
272}
273
Grace Klobafbe47c02009-05-14 17:31:45 -0700274NPError NPP_SetWindow(NPP instance, NPWindow* window)
275{
276 PluginObject *obj = (PluginObject*) instance->pdata;
Derek Sollenberger9119e7d2009-06-08 10:53:09 -0400277
Grace Klobafbe47c02009-05-14 17:31:45 -0700278 // Do nothing if browser didn't support NPN_CreateObject which would have created the PluginObject.
279 if (obj != NULL) {
280 obj->window = window;
281 }
Derek Sollenberger9119e7d2009-06-08 10:53:09 -0400282
Grace Klobafbe47c02009-05-14 17:31:45 -0700283 browser->invalidaterect(instance, NULL);
284
285 return NPERR_NO_ERROR;
286}
Derek Sollenberger9119e7d2009-06-08 10:53:09 -0400287
Grace Klobafbe47c02009-05-14 17:31:45 -0700288NPError NPP_NewStream(NPP instance, NPMIMEType type, NPStream* stream, NPBool seekable, uint16* stype)
289{
290 *stype = NP_ASFILEONLY;
291 return NPERR_NO_ERROR;
292}
293
294NPError NPP_DestroyStream(NPP instance, NPStream* stream, NPReason reason)
295{
296 return NPERR_NO_ERROR;
297}
298
299int32 NPP_WriteReady(NPP instance, NPStream* stream)
300{
301 return 0;
302}
303
304int32 NPP_Write(NPP instance, NPStream* stream, int32 offset, int32 len, void* buffer)
305{
306 return 0;
307}
308
309void NPP_StreamAsFile(NPP instance, NPStream* stream, const char* fname)
310{
311}
312
313void NPP_Print(NPP instance, NPPrint* platformPrint)
314{
Grace Klobafbe47c02009-05-14 17:31:45 -0700315}
316
Grace Klobafbe47c02009-05-14 17:31:45 -0700317int16 NPP_HandleEvent(NPP instance, void* event)
318{
319 PluginObject *obj = reinterpret_cast<PluginObject*>(instance->pdata);
320 const ANPEvent* evt = reinterpret_cast<const ANPEvent*>(event);
321
Derek Sollenberger5b011e32009-06-22 11:39:40 -0400322#if DEBUG_PLUGIN_EVENTS
Grace Klobafbe47c02009-05-14 17:31:45 -0700323 switch (evt->eventType) {
324 case kDraw_ANPEventType:
Derek Sollenbergerd7ebf272009-06-18 11:19:41 -0400325
326 if (evt->data.draw.model == kBitmap_ANPDrawingModel) {
327
328 static ANPBitmapFormat currentFormat = -1;
329 if (evt->data.draw.data.bitmap.format != currentFormat) {
330 currentFormat = evt->data.draw.data.bitmap.format;
Derek Sollenbergere62ce172009-11-30 11:52:06 -0500331 gLogI.log(kDebug_ANPLogType, "---- %p Draw (bitmap)"
Derek Sollenbergerd7ebf272009-06-18 11:19:41 -0400332 " clip=%d,%d,%d,%d format=%d", instance,
333 evt->data.draw.clip.left,
334 evt->data.draw.clip.top,
335 evt->data.draw.clip.right,
336 evt->data.draw.clip.bottom,
337 evt->data.draw.data.bitmap.format);
338 }
Grace Klobafbe47c02009-05-14 17:31:45 -0700339 }
Derek Sollenbergerd7ebf272009-06-18 11:19:41 -0400340 break;
Grace Klobafbe47c02009-05-14 17:31:45 -0700341
342 case kKey_ANPEventType:
Derek Sollenbergere62ce172009-11-30 11:52:06 -0500343 gLogI.log(kDebug_ANPLogType, "---- %p Key action=%d"
Grace Klobafbe47c02009-05-14 17:31:45 -0700344 " code=%d vcode=%d unichar=%d repeat=%d mods=%x", instance,
345 evt->data.key.action,
346 evt->data.key.nativeCode,
347 evt->data.key.virtualCode,
348 evt->data.key.unichar,
349 evt->data.key.repeatCount,
350 evt->data.key.modifiers);
Derek Sollenbergerd7ebf272009-06-18 11:19:41 -0400351 break;
Derek Sollenberger9119e7d2009-06-08 10:53:09 -0400352
353 case kLifecycle_ANPEventType:
Derek Sollenbergere62ce172009-11-30 11:52:06 -0500354 gLogI.log(kDebug_ANPLogType, "---- %p Lifecycle action=%d",
Derek Sollenbergerd7ebf272009-06-18 11:19:41 -0400355 instance, evt->data.lifecycle.action);
Mike Reed1e7c3312009-05-26 16:37:45 -0400356 break;
Grace Klobafbe47c02009-05-14 17:31:45 -0700357
Derek Sollenbergerd7ebf272009-06-18 11:19:41 -0400358 case kTouch_ANPEventType:
Derek Sollenbergere62ce172009-11-30 11:52:06 -0500359 gLogI.log(kDebug_ANPLogType, "---- %p Touch action=%d [%d %d]",
Grace Klobafbe47c02009-05-14 17:31:45 -0700360 instance, evt->data.touch.action, evt->data.touch.x,
361 evt->data.touch.y);
Derek Sollenberger5b011e32009-06-22 11:39:40 -0400362 break;
363
Derek Sollenbergerdb398a72009-06-29 13:53:04 -0400364 case kMouse_ANPEventType:
Derek Sollenbergere62ce172009-11-30 11:52:06 -0500365 gLogI.log(kDebug_ANPLogType, "---- %p Mouse action=%d [%d %d]",
Derek Sollenbergerdb398a72009-06-29 13:53:04 -0400366 instance, evt->data.mouse.action, evt->data.mouse.x,
367 evt->data.mouse.y);
368 break;
369
Derek Sollenberger5b011e32009-06-22 11:39:40 -0400370 case kVisibleRect_ANPEventType:
Derek Sollenbergere62ce172009-11-30 11:52:06 -0500371 gLogI.log(kDebug_ANPLogType, "---- %p VisibleRect [%d %d %d %d]",
Derek Sollenbergerf42e2f42009-06-26 11:42:46 -0400372 instance, evt->data.visibleRect.rect.left, evt->data.visibleRect.rect.top,
373 evt->data.visibleRect.rect.right, evt->data.visibleRect.rect.bottom);
Derek Sollenberger5b011e32009-06-22 11:39:40 -0400374 break;
Grace Klobafbe47c02009-05-14 17:31:45 -0700375
376 default:
Derek Sollenbergere62ce172009-11-30 11:52:06 -0500377 gLogI.log(kError_ANPLogType, "---- %p Unknown Event [%d]",
Derek Sollenberger5b011e32009-06-22 11:39:40 -0400378 instance, evt->eventType);
Grace Klobafbe47c02009-05-14 17:31:45 -0700379 break;
380 }
Derek Sollenberger5b011e32009-06-22 11:39:40 -0400381#endif
Derek Sollenbergerd7ebf272009-06-18 11:19:41 -0400382
383 if(!obj->activePlugin) {
Derek Sollenbergere62ce172009-11-30 11:52:06 -0500384 gLogI.log(kError_ANPLogType, "the active plugin is null.");
Derek Sollenbergerd7ebf272009-06-18 11:19:41 -0400385 return 0; // unknown or unhandled event
386 }
387 else {
388 return obj->activePlugin->handleEvent(evt);
389 }
Grace Klobafbe47c02009-05-14 17:31:45 -0700390}
391
392void NPP_URLNotify(NPP instance, const char* url, NPReason reason, void* notifyData)
393{
394
395}
396
397EXPORT NPError NP_GetValue(NPP instance, NPPVariable variable, void *value) {
398
399 if (variable == NPPVpluginNameString) {
400 const char **str = (const char **)value;
401 *str = "Test Plugin";
402 return NPERR_NO_ERROR;
403 }
Derek Sollenberger9119e7d2009-06-08 10:53:09 -0400404
Grace Klobafbe47c02009-05-14 17:31:45 -0700405 if (variable == NPPVpluginDescriptionString) {
406 const char **str = (const char **)value;
407 *str = "Description of Test Plugin";
408 return NPERR_NO_ERROR;
409 }
Derek Sollenberger9119e7d2009-06-08 10:53:09 -0400410
Grace Klobafbe47c02009-05-14 17:31:45 -0700411 return NPERR_GENERIC_ERROR;
412}
413
Derek Sollenbergerd53b56d2010-01-11 12:31:49 -0500414NPError NPP_GetValue(NPP instance, NPPVariable variable, void* value)
Grace Klobafbe47c02009-05-14 17:31:45 -0700415{
416 if (variable == NPPVpluginScriptableNPObject) {
417 void **v = (void **)value;
418 PluginObject *obj = (PluginObject*) instance->pdata;
Derek Sollenberger9119e7d2009-06-08 10:53:09 -0400419
Grace Klobafbe47c02009-05-14 17:31:45 -0700420 if (obj)
Derek Sollenbergerb4a23912009-11-09 15:38:58 -0500421 browser->retainobject(&obj->header);
Derek Sollenberger9119e7d2009-06-08 10:53:09 -0400422
Derek Sollenbergerb4a23912009-11-09 15:38:58 -0500423 *v = &(obj->header);
Grace Klobafbe47c02009-05-14 17:31:45 -0700424 return NPERR_NO_ERROR;
425 }
Derek Sollenberger9119e7d2009-06-08 10:53:09 -0400426
Derek Sollenbergerd53b56d2010-01-11 12:31:49 -0500427 if (variable == kJavaSurface_ANPGetValue) {
428 //get the surface sub-plugin
429 PluginObject* obj = static_cast<PluginObject*>(instance->pdata);
430 if (obj && obj->activePlugin) {
431
432 if(obj->activePlugin->supportsDrawingModel(kSurface_ANPDrawingModel)) {
433 SurfaceSubPlugin* plugin = static_cast<SurfaceSubPlugin*>(obj->activePlugin);
434 jobject* surface = static_cast<jobject*>(value);
435 *surface = plugin->getSurface();
436 return NPERR_NO_ERROR;
437 } else {
438 gLogI.log(kError_ANPLogType,
439 "-- %p Tried to retrieve surface for non-surface plugin",
440 instance);
441 }
442 }
443 }
444
Grace Klobafbe47c02009-05-14 17:31:45 -0700445 return NPERR_GENERIC_ERROR;
446}
447
448NPError NPP_SetValue(NPP instance, NPNVariable variable, void *value)
449{
450 return NPERR_GENERIC_ERROR;
451}
452