blob: f6e340029aaf09469a8bf2d69da1c5c6320ed298 [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 Sollenberger1bc5ab62010-01-14 11:44:37 -050035#include "NavigationPlugin.h"
Derek Sollenberger4fb83e62009-07-27 16:40:13 -040036#include "PaintPlugin.h"
Derek Sollenbergerb8947ee2009-10-05 14:40:18 -040037#include "VideoPlugin.h"
Grace Klobafbe47c02009-05-14 17:31:45 -070038
39NPNetscapeFuncs* browser;
Derek Sollenbergerb8947ee2009-10-05 14:40:18 -040040JavaVM* gVM;
41
Grace Klobafbe47c02009-05-14 17:31:45 -070042#define EXPORT __attribute__((visibility("default")))
43
Ben Murdoch3b6f45d2010-05-12 14:09:26 +010044NPError NPP_New(NPMIMEType pluginType, NPP instance, uint16_t mode, int16_t argc,
Grace Klobafbe47c02009-05-14 17:31:45 -070045 char* argn[], char* argv[], NPSavedData* saved);
46NPError NPP_Destroy(NPP instance, NPSavedData** save);
47NPError NPP_SetWindow(NPP instance, NPWindow* window);
Derek Sollenberger9119e7d2009-06-08 10:53:09 -040048NPError NPP_NewStream(NPP instance, NPMIMEType type, NPStream* stream,
Ben Murdoch3b6f45d2010-05-12 14:09:26 +010049 NPBool seekable, uint16_t* stype);
Grace Klobafbe47c02009-05-14 17:31:45 -070050NPError NPP_DestroyStream(NPP instance, NPStream* stream, NPReason reason);
Ben Murdoch3b6f45d2010-05-12 14:09:26 +010051int32_t NPP_WriteReady(NPP instance, NPStream* stream);
52int32_t NPP_Write(NPP instance, NPStream* stream, int32_t offset, int32_t len,
Grace Klobafbe47c02009-05-14 17:31:45 -070053 void* buffer);
54void NPP_StreamAsFile(NPP instance, NPStream* stream, const char* fname);
55void NPP_Print(NPP instance, NPPrint* platformPrint);
Ben Murdoch3b6f45d2010-05-12 14:09:26 +010056int16_t NPP_HandleEvent(NPP instance, void* event);
Derek Sollenberger9119e7d2009-06-08 10:53:09 -040057void NPP_URLNotify(NPP instance, const char* URL, NPReason reason,
Grace Klobafbe47c02009-05-14 17:31:45 -070058 void* notifyData);
59NPError NPP_GetValue(NPP instance, NPPVariable variable, void *value);
60NPError NPP_SetValue(NPP instance, NPNVariable variable, void *value);
61
62extern "C" {
Derek Sollenberger4fe6d382010-01-21 15:04:58 -050063EXPORT NPError NP_Initialize(NPNetscapeFuncs* browserFuncs, NPPluginFuncs* pluginFuncs, void *java_env);
Grace Klobafbe47c02009-05-14 17:31:45 -070064EXPORT NPError NP_GetValue(NPP instance, NPPVariable variable, void *value);
65EXPORT const char* NP_GetMIMEDescription(void);
Derek Sollenberger9119e7d2009-06-08 10:53:09 -040066EXPORT void NP_Shutdown(void);
Grace Klobafbe47c02009-05-14 17:31:45 -070067};
68
69ANPAudioTrackInterfaceV0 gSoundI;
Mike Reed224adad2009-06-10 10:24:01 -040070ANPBitmapInterfaceV0 gBitmapI;
Grace Klobafbe47c02009-05-14 17:31:45 -070071ANPCanvasInterfaceV0 gCanvasI;
Derek Sollenbergerd53b56d2010-01-11 12:31:49 -050072ANPEventInterfaceV0 gEventI;
Grace Klobafbe47c02009-05-14 17:31:45 -070073ANPLogInterfaceV0 gLogI;
74ANPPaintInterfaceV0 gPaintI;
75ANPPathInterfaceV0 gPathI;
Derek Sollenbergerc0f26572009-07-16 11:38:02 -040076ANPSurfaceInterfaceV0 gSurfaceI;
Grace Kloba9ffe5ac2009-08-04 17:51:06 -070077ANPSystemInterfaceV0 gSystemI;
Grace Klobafbe47c02009-05-14 17:31:45 -070078ANPTypefaceInterfaceV0 gTypefaceI;
Derek Sollenberger1e64f022011-01-07 14:11:29 -050079ANPWindowInterfaceV1 gWindowI;
Chris Craikaceb2e32011-08-04 17:41:20 -070080ANPNativeWindowInterfaceV0 gNativeWindowI;
Grace Klobafbe47c02009-05-14 17:31:45 -070081
82#define ARRAY_COUNT(array) (sizeof(array) / sizeof(array[0]))
Derek Sollenberger5b011e32009-06-22 11:39:40 -040083#define DEBUG_PLUGIN_EVENTS 0
Grace Klobafbe47c02009-05-14 17:31:45 -070084
Derek Sollenberger4fe6d382010-01-21 15:04:58 -050085NPError NP_Initialize(NPNetscapeFuncs* browserFuncs, NPPluginFuncs* pluginFuncs, void *java_env)
Grace Klobafbe47c02009-05-14 17:31:45 -070086{
87 // Make sure we have a function table equal or larger than we are built against.
88 if (browserFuncs->size < sizeof(NPNetscapeFuncs)) {
89 return NPERR_GENERIC_ERROR;
90 }
Derek Sollenberger9119e7d2009-06-08 10:53:09 -040091
Grace Klobafbe47c02009-05-14 17:31:45 -070092 // Copy the function table (structure)
93 browser = (NPNetscapeFuncs*) malloc(sizeof(NPNetscapeFuncs));
94 memcpy(browser, browserFuncs, sizeof(NPNetscapeFuncs));
Derek Sollenberger9119e7d2009-06-08 10:53:09 -040095
Grace Klobafbe47c02009-05-14 17:31:45 -070096 // Build the plugin function table
97 pluginFuncs->version = 11;
98 pluginFuncs->size = sizeof(pluginFuncs);
99 pluginFuncs->newp = NPP_New;
100 pluginFuncs->destroy = NPP_Destroy;
101 pluginFuncs->setwindow = NPP_SetWindow;
102 pluginFuncs->newstream = NPP_NewStream;
103 pluginFuncs->destroystream = NPP_DestroyStream;
104 pluginFuncs->asfile = NPP_StreamAsFile;
105 pluginFuncs->writeready = NPP_WriteReady;
106 pluginFuncs->write = (NPP_WriteProcPtr)NPP_Write;
107 pluginFuncs->print = NPP_Print;
108 pluginFuncs->event = NPP_HandleEvent;
109 pluginFuncs->urlnotify = NPP_URLNotify;
110 pluginFuncs->getvalue = NPP_GetValue;
111 pluginFuncs->setvalue = NPP_SetValue;
112
113 static const struct {
114 NPNVariable v;
115 uint32_t size;
116 ANPInterface* i;
117 } gPairs[] = {
Chris Craikaceb2e32011-08-04 17:41:20 -0700118 { kAudioTrackInterfaceV0_ANPGetValue, sizeof(gSoundI), &gSoundI },
119 { kBitmapInterfaceV0_ANPGetValue, sizeof(gBitmapI), &gBitmapI },
120 { kCanvasInterfaceV0_ANPGetValue, sizeof(gCanvasI), &gCanvasI },
121 { kEventInterfaceV0_ANPGetValue, sizeof(gEventI), &gEventI },
122 { kLogInterfaceV0_ANPGetValue, sizeof(gLogI), &gLogI },
123 { kPaintInterfaceV0_ANPGetValue, sizeof(gPaintI), &gPaintI },
124 { kPathInterfaceV0_ANPGetValue, sizeof(gPathI), &gPathI },
125 { kSurfaceInterfaceV0_ANPGetValue, sizeof(gSurfaceI), &gSurfaceI },
126 { kSystemInterfaceV0_ANPGetValue, sizeof(gSystemI), &gSystemI },
127 { kTypefaceInterfaceV0_ANPGetValue, sizeof(gTypefaceI), &gTypefaceI },
128 { kWindowInterfaceV1_ANPGetValue, sizeof(gWindowI), &gWindowI },
129 { kNativeWindowInterfaceV0_ANPGetValue, sizeof(gNativeWindowI), &gNativeWindowI },
Grace Klobafbe47c02009-05-14 17:31:45 -0700130 };
131 for (size_t i = 0; i < ARRAY_COUNT(gPairs); i++) {
132 gPairs[i].i->inSize = gPairs[i].size;
133 NPError err = browser->getvalue(NULL, gPairs[i].v, gPairs[i].i);
134 if (err) {
135 return err;
136 }
137 }
Derek Sollenberger9119e7d2009-06-08 10:53:09 -0400138
Derek Sollenbergerb8947ee2009-10-05 14:40:18 -0400139 // store the JavaVM for the plugin
140 JNIEnv* env = (JNIEnv*)java_env;
141 env->GetJavaVM(&gVM);
142
Grace Klobafbe47c02009-05-14 17:31:45 -0700143 return NPERR_NO_ERROR;
144}
145
146void NP_Shutdown(void)
147{
148
149}
150
Derek Sollenberger9119e7d2009-06-08 10:53:09 -0400151const char *NP_GetMIMEDescription(void)
Grace Klobafbe47c02009-05-14 17:31:45 -0700152{
Derek Sollenbergerd7ebf272009-06-18 11:19:41 -0400153 return "application/x-testbrowserplugin:tst:Test plugin mimetype is application/x-testbrowserplugin";
Grace Klobafbe47c02009-05-14 17:31:45 -0700154}
155
Ben Murdoch3b6f45d2010-05-12 14:09:26 +0100156NPError NPP_New(NPMIMEType pluginType, NPP instance, uint16_t mode, int16_t argc,
Grace Klobafbe47c02009-05-14 17:31:45 -0700157 char* argn[], char* argv[], NPSavedData* saved)
158{
Derek Sollenbergerd7ebf272009-06-18 11:19:41 -0400159
160 /* BEGIN: STANDARD PLUGIN FRAMEWORK */
Grace Klobafbe47c02009-05-14 17:31:45 -0700161 PluginObject *obj = NULL;
162
163 // Scripting functions appeared in NPAPI version 14
164 if (browser->version >= 14) {
Derek Sollenbergerb4a23912009-11-09 15:38:58 -0500165 instance->pdata = browser->createobject (instance, getPluginClass());
166 obj = static_cast<PluginObject*>(instance->pdata);
Derek Sollenberger349bc372011-01-04 16:14:34 -0500167 obj->pluginType = 0;
Grace Klobafbe47c02009-05-14 17:31:45 -0700168 }
Derek Sollenbergerd7ebf272009-06-18 11:19:41 -0400169 /* END: STANDARD PLUGIN FRAMEWORK */
Derek Sollenberger9119e7d2009-06-08 10:53:09 -0400170
Derek Sollenberger4fb83e62009-07-27 16:40:13 -0400171 // select the drawing model based on user input
172 ANPDrawingModel model = kBitmap_ANPDrawingModel;
173
174 for (int i = 0; i < argc; i++) {
175 if (!strcmp(argn[i], "DrawingModel")) {
176 if (!strcmp(argv[i], "Bitmap")) {
177 model = kBitmap_ANPDrawingModel;
178 }
179 else if (!strcmp(argv[i], "Surface")) {
180 model = kSurface_ANPDrawingModel;
181 }
Derek Sollenberger349bc372011-01-04 16:14:34 -0500182 else if (!strcmp(argv[i], "OpenGL")) {
183 model = kOpenGL_ANPDrawingModel;
184 }
Derek Sollenbergere62ce172009-11-30 11:52:06 -0500185 gLogI.log(kDebug_ANPLogType, "------ %p DrawingModel is %d", instance, model);
Derek Sollenberger4fb83e62009-07-27 16:40:13 -0400186 break;
187 }
188 }
189
190 // notify the plugin API of the drawing model we wish to use. This must be
191 // done prior to creating certain subPlugin objects (e.g. surfaceViews)
192 NPError err = browser->setvalue(instance, kRequestDrawingModel_ANPSetValue,
193 reinterpret_cast<void*>(model));
194 if (err) {
Derek Sollenbergere62ce172009-11-30 11:52:06 -0500195 gLogI.log(kError_ANPLogType, "request model %d err %d", model, err);
Derek Sollenberger4fb83e62009-07-27 16:40:13 -0400196 return err;
197 }
198
Grace Kloba9ffe5ac2009-08-04 17:51:06 -0700199 const char* path = gSystemI.getApplicationDataDirectory();
200 if (path) {
Derek Sollenbergere62ce172009-11-30 11:52:06 -0500201 gLogI.log(kDebug_ANPLogType, "Application data dir is %s", path);
Grace Kloba9ffe5ac2009-08-04 17:51:06 -0700202 } else {
Derek Sollenbergere62ce172009-11-30 11:52:06 -0500203 gLogI.log(kError_ANPLogType, "Can't find Application data dir");
Grace Kloba9ffe5ac2009-08-04 17:51:06 -0700204 }
205
Derek Sollenbergerd7ebf272009-06-18 11:19:41 -0400206 // select the pluginType
207 for (int i = 0; i < argc; i++) {
208 if (!strcmp(argn[i], "PluginType")) {
209 if (!strcmp(argv[i], "Animation")) {
210 obj->pluginType = kAnimation_PluginType;
211 obj->activePlugin = new BallAnimation(instance);
212 }
213 else if (!strcmp(argv[i], "Audio")) {
214 obj->pluginType = kAudio_PluginType;
Derek Sollenbergerf42e2f42009-06-26 11:42:46 -0400215 obj->activePlugin = new AudioPlugin(instance);
Derek Sollenbergerd7ebf272009-06-18 11:19:41 -0400216 }
217 else if (!strcmp(argv[i], "Background")) {
218 obj->pluginType = kBackground_PluginType;
219 obj->activePlugin = new BackgroundPlugin(instance);
220 }
Derek Sollenbergerdb398a72009-06-29 13:53:04 -0400221 else if (!strcmp(argv[i], "Form")) {
222 obj->pluginType = kForm_PluginType;
223 obj->activePlugin = new FormPlugin(instance);
224 }
Derek Sollenberger1bc5ab62010-01-14 11:44:37 -0500225 else if (!strcmp(argv[i], "Navigation")) {
226 obj->pluginType = kNavigation_PluginType;
227 obj->activePlugin = new NavigationPlugin(instance);
228 }
Derek Sollenberger4fb83e62009-07-27 16:40:13 -0400229 else if (!strcmp(argv[i], "Paint")) {
230 obj->pluginType = kPaint_PluginType;
231 obj->activePlugin = new PaintPlugin(instance);
232 }
Derek Sollenbergerb8947ee2009-10-05 14:40:18 -0400233 else if (!strcmp(argv[i], "Video")) {
234 obj->pluginType = kVideo_PluginType;
235 obj->activePlugin = new VideoPlugin(instance);
236 }
Chris Craikaceb2e32011-08-04 17:41:20 -0700237 else {
238 gLogI.log(kError_ANPLogType, "PluginType %s unknown!", argv[i]);
239 }
Derek Sollenbergerd7ebf272009-06-18 11:19:41 -0400240 break;
241 }
242 }
243
244 // if no pluginType is specified then default to Animation
245 if (!obj->pluginType) {
Derek Sollenbergere62ce172009-11-30 11:52:06 -0500246 gLogI.log(kError_ANPLogType, "------ %p No PluginType attribute was found", instance);
Derek Sollenbergerd7ebf272009-06-18 11:19:41 -0400247 obj->pluginType = kAnimation_PluginType;
248 obj->activePlugin = new BallAnimation(instance);
249 }
250
Derek Sollenberger349bc372011-01-04 16:14:34 -0500251 gLogI.log(kDebug_ANPLogType, "------ %p PluginType is %d", instance, obj->pluginType);
252
Derek Sollenberger21f39912009-07-09 09:19:39 -0400253 // check to ensure the pluginType supports the model
254 if (!obj->activePlugin->supportsDrawingModel(model)) {
Derek Sollenbergere62ce172009-11-30 11:52:06 -0500255 gLogI.log(kError_ANPLogType, "------ %p Unsupported DrawingModel (%d)", instance, model);
Derek Sollenberger21f39912009-07-09 09:19:39 -0400256 return NPERR_GENERIC_ERROR;
257 }
258
Derek Sollenbergerd53b56d2010-01-11 12:31:49 -0500259 // if the plugin uses the surface drawing model then set the java context
Derek Sollenberger349bc372011-01-04 16:14:34 -0500260 if (model == kSurface_ANPDrawingModel || model == kOpenGL_ANPDrawingModel) {
Derek Sollenbergerd53b56d2010-01-11 12:31:49 -0500261 SurfaceSubPlugin* surfacePlugin = static_cast<SurfaceSubPlugin*>(obj->activePlugin);
262
263 jobject context;
264 NPError err = browser->getvalue(instance, kJavaContext_ANPGetValue,
265 static_cast<void*>(&context));
266 if (err) {
267 gLogI.log(kError_ANPLogType, "request context err: %d", err);
268 return err;
269 }
270
271 surfacePlugin->setContext(context);
272 }
273
274
Derek Sollenbergerd7ebf272009-06-18 11:19:41 -0400275 return NPERR_NO_ERROR;
Grace Klobafbe47c02009-05-14 17:31:45 -0700276}
277
278NPError NPP_Destroy(NPP instance, NPSavedData** save)
279{
280 PluginObject *obj = (PluginObject*) instance->pdata;
Grace Klobaa0e762c2009-12-27 13:21:41 -0800281 if (obj) {
282 delete obj->activePlugin;
283 browser->releaseobject(&obj->header);
284 }
Grace Klobafbe47c02009-05-14 17:31:45 -0700285
286 return NPERR_NO_ERROR;
287}
288
Grace Klobafbe47c02009-05-14 17:31:45 -0700289NPError NPP_SetWindow(NPP instance, NPWindow* window)
290{
291 PluginObject *obj = (PluginObject*) instance->pdata;
Derek Sollenberger9119e7d2009-06-08 10:53:09 -0400292
Grace Klobafbe47c02009-05-14 17:31:45 -0700293 // Do nothing if browser didn't support NPN_CreateObject which would have created the PluginObject.
294 if (obj != NULL) {
295 obj->window = window;
296 }
Derek Sollenberger9119e7d2009-06-08 10:53:09 -0400297
Grace Klobafbe47c02009-05-14 17:31:45 -0700298 browser->invalidaterect(instance, NULL);
299
300 return NPERR_NO_ERROR;
301}
Derek Sollenberger9119e7d2009-06-08 10:53:09 -0400302
Ben Murdoch3b6f45d2010-05-12 14:09:26 +0100303NPError NPP_NewStream(NPP instance, NPMIMEType type, NPStream* stream, NPBool seekable, uint16_t* stype)
Grace Klobafbe47c02009-05-14 17:31:45 -0700304{
305 *stype = NP_ASFILEONLY;
306 return NPERR_NO_ERROR;
307}
308
309NPError NPP_DestroyStream(NPP instance, NPStream* stream, NPReason reason)
310{
311 return NPERR_NO_ERROR;
312}
313
Ben Murdoch3b6f45d2010-05-12 14:09:26 +0100314int32_t NPP_WriteReady(NPP instance, NPStream* stream)
Grace Klobafbe47c02009-05-14 17:31:45 -0700315{
316 return 0;
317}
318
Ben Murdoch3b6f45d2010-05-12 14:09:26 +0100319int32_t NPP_Write(NPP instance, NPStream* stream, int32_t offset, int32_t len, void* buffer)
Grace Klobafbe47c02009-05-14 17:31:45 -0700320{
321 return 0;
322}
323
324void NPP_StreamAsFile(NPP instance, NPStream* stream, const char* fname)
325{
326}
327
328void NPP_Print(NPP instance, NPPrint* platformPrint)
329{
Grace Klobafbe47c02009-05-14 17:31:45 -0700330}
331
Ben Murdoch3b6f45d2010-05-12 14:09:26 +0100332int16_t NPP_HandleEvent(NPP instance, void* event)
Grace Klobafbe47c02009-05-14 17:31:45 -0700333{
334 PluginObject *obj = reinterpret_cast<PluginObject*>(instance->pdata);
335 const ANPEvent* evt = reinterpret_cast<const ANPEvent*>(event);
336
Derek Sollenberger5b011e32009-06-22 11:39:40 -0400337#if DEBUG_PLUGIN_EVENTS
Grace Klobafbe47c02009-05-14 17:31:45 -0700338 switch (evt->eventType) {
339 case kDraw_ANPEventType:
Derek Sollenbergerd7ebf272009-06-18 11:19:41 -0400340
341 if (evt->data.draw.model == kBitmap_ANPDrawingModel) {
342
343 static ANPBitmapFormat currentFormat = -1;
344 if (evt->data.draw.data.bitmap.format != currentFormat) {
345 currentFormat = evt->data.draw.data.bitmap.format;
Derek Sollenbergere62ce172009-11-30 11:52:06 -0500346 gLogI.log(kDebug_ANPLogType, "---- %p Draw (bitmap)"
Derek Sollenbergerd7ebf272009-06-18 11:19:41 -0400347 " clip=%d,%d,%d,%d format=%d", instance,
348 evt->data.draw.clip.left,
349 evt->data.draw.clip.top,
350 evt->data.draw.clip.right,
351 evt->data.draw.clip.bottom,
352 evt->data.draw.data.bitmap.format);
353 }
Grace Klobafbe47c02009-05-14 17:31:45 -0700354 }
Derek Sollenbergerd7ebf272009-06-18 11:19:41 -0400355 break;
Grace Klobafbe47c02009-05-14 17:31:45 -0700356
357 case kKey_ANPEventType:
Derek Sollenbergere62ce172009-11-30 11:52:06 -0500358 gLogI.log(kDebug_ANPLogType, "---- %p Key action=%d"
Grace Klobafbe47c02009-05-14 17:31:45 -0700359 " code=%d vcode=%d unichar=%d repeat=%d mods=%x", instance,
360 evt->data.key.action,
361 evt->data.key.nativeCode,
362 evt->data.key.virtualCode,
363 evt->data.key.unichar,
364 evt->data.key.repeatCount,
365 evt->data.key.modifiers);
Derek Sollenbergerd7ebf272009-06-18 11:19:41 -0400366 break;
Derek Sollenberger9119e7d2009-06-08 10:53:09 -0400367
368 case kLifecycle_ANPEventType:
Derek Sollenbergere62ce172009-11-30 11:52:06 -0500369 gLogI.log(kDebug_ANPLogType, "---- %p Lifecycle action=%d",
Derek Sollenbergerd7ebf272009-06-18 11:19:41 -0400370 instance, evt->data.lifecycle.action);
Mike Reed1e7c3312009-05-26 16:37:45 -0400371 break;
Grace Klobafbe47c02009-05-14 17:31:45 -0700372
Derek Sollenbergerd7ebf272009-06-18 11:19:41 -0400373 case kTouch_ANPEventType:
Derek Sollenbergere62ce172009-11-30 11:52:06 -0500374 gLogI.log(kDebug_ANPLogType, "---- %p Touch action=%d [%d %d]",
Grace Klobafbe47c02009-05-14 17:31:45 -0700375 instance, evt->data.touch.action, evt->data.touch.x,
376 evt->data.touch.y);
Derek Sollenberger5b011e32009-06-22 11:39:40 -0400377 break;
378
Derek Sollenbergerdb398a72009-06-29 13:53:04 -0400379 case kMouse_ANPEventType:
Derek Sollenbergere62ce172009-11-30 11:52:06 -0500380 gLogI.log(kDebug_ANPLogType, "---- %p Mouse action=%d [%d %d]",
Derek Sollenbergerdb398a72009-06-29 13:53:04 -0400381 instance, evt->data.mouse.action, evt->data.mouse.x,
382 evt->data.mouse.y);
383 break;
384
Derek Sollenberger5b011e32009-06-22 11:39:40 -0400385 case kVisibleRect_ANPEventType:
Derek Sollenbergere62ce172009-11-30 11:52:06 -0500386 gLogI.log(kDebug_ANPLogType, "---- %p VisibleRect [%d %d %d %d]",
Derek Sollenbergerf42e2f42009-06-26 11:42:46 -0400387 instance, evt->data.visibleRect.rect.left, evt->data.visibleRect.rect.top,
388 evt->data.visibleRect.rect.right, evt->data.visibleRect.rect.bottom);
Derek Sollenberger5b011e32009-06-22 11:39:40 -0400389 break;
Grace Klobafbe47c02009-05-14 17:31:45 -0700390
391 default:
Derek Sollenbergere62ce172009-11-30 11:52:06 -0500392 gLogI.log(kError_ANPLogType, "---- %p Unknown Event [%d]",
Derek Sollenberger5b011e32009-06-22 11:39:40 -0400393 instance, evt->eventType);
Grace Klobafbe47c02009-05-14 17:31:45 -0700394 break;
395 }
Derek Sollenberger5b011e32009-06-22 11:39:40 -0400396#endif
Derek Sollenbergerd7ebf272009-06-18 11:19:41 -0400397
398 if(!obj->activePlugin) {
Derek Sollenbergere62ce172009-11-30 11:52:06 -0500399 gLogI.log(kError_ANPLogType, "the active plugin is null.");
Derek Sollenbergerd7ebf272009-06-18 11:19:41 -0400400 return 0; // unknown or unhandled event
401 }
402 else {
403 return obj->activePlugin->handleEvent(evt);
404 }
Grace Klobafbe47c02009-05-14 17:31:45 -0700405}
406
407void NPP_URLNotify(NPP instance, const char* url, NPReason reason, void* notifyData)
408{
409
410}
411
412EXPORT NPError NP_GetValue(NPP instance, NPPVariable variable, void *value) {
413
414 if (variable == NPPVpluginNameString) {
415 const char **str = (const char **)value;
416 *str = "Test Plugin";
417 return NPERR_NO_ERROR;
418 }
Derek Sollenberger9119e7d2009-06-08 10:53:09 -0400419
Grace Klobafbe47c02009-05-14 17:31:45 -0700420 if (variable == NPPVpluginDescriptionString) {
421 const char **str = (const char **)value;
422 *str = "Description of Test Plugin";
423 return NPERR_NO_ERROR;
424 }
Derek Sollenberger9119e7d2009-06-08 10:53:09 -0400425
Grace Klobafbe47c02009-05-14 17:31:45 -0700426 return NPERR_GENERIC_ERROR;
427}
428
Derek Sollenbergerd53b56d2010-01-11 12:31:49 -0500429NPError NPP_GetValue(NPP instance, NPPVariable variable, void* value)
Grace Klobafbe47c02009-05-14 17:31:45 -0700430{
431 if (variable == NPPVpluginScriptableNPObject) {
432 void **v = (void **)value;
433 PluginObject *obj = (PluginObject*) instance->pdata;
Derek Sollenberger9119e7d2009-06-08 10:53:09 -0400434
Grace Klobafbe47c02009-05-14 17:31:45 -0700435 if (obj)
Derek Sollenbergerb4a23912009-11-09 15:38:58 -0500436 browser->retainobject(&obj->header);
Derek Sollenberger9119e7d2009-06-08 10:53:09 -0400437
Derek Sollenbergerb4a23912009-11-09 15:38:58 -0500438 *v = &(obj->header);
Grace Klobafbe47c02009-05-14 17:31:45 -0700439 return NPERR_NO_ERROR;
440 }
Derek Sollenberger9119e7d2009-06-08 10:53:09 -0400441
Derek Sollenbergerd53b56d2010-01-11 12:31:49 -0500442 if (variable == kJavaSurface_ANPGetValue) {
443 //get the surface sub-plugin
444 PluginObject* obj = static_cast<PluginObject*>(instance->pdata);
445 if (obj && obj->activePlugin) {
446
Derek Sollenberger349bc372011-01-04 16:14:34 -0500447 if(obj->activePlugin->supportsDrawingModel(kSurface_ANPDrawingModel)
448 || obj->activePlugin->supportsDrawingModel(kOpenGL_ANPDrawingModel)) {
Derek Sollenbergerd53b56d2010-01-11 12:31:49 -0500449 SurfaceSubPlugin* plugin = static_cast<SurfaceSubPlugin*>(obj->activePlugin);
450 jobject* surface = static_cast<jobject*>(value);
451 *surface = plugin->getSurface();
452 return NPERR_NO_ERROR;
453 } else {
454 gLogI.log(kError_ANPLogType,
455 "-- %p Tried to retrieve surface for non-surface plugin",
456 instance);
457 }
458 }
459 }
460
Grace Klobafbe47c02009-05-14 17:31:45 -0700461 return NPERR_GENERIC_ERROR;
462}
463
464NPError NPP_SetValue(NPP instance, NPNVariable variable, void *value)
465{
466 return NPERR_GENERIC_ERROR;
467}
468