Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 1 | /* |
| 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 Sollenberger | d7ebf27 | 2009-06-18 11:19:41 -0400 | [diff] [blame] | 31 | #include "AnimationPlugin.h" |
Derek Sollenberger | f42e2f4 | 2009-06-26 11:42:46 -0400 | [diff] [blame^] | 32 | #include "AudioPlugin.h" |
Derek Sollenberger | d7ebf27 | 2009-06-18 11:19:41 -0400 | [diff] [blame] | 33 | #include "BackgroundPlugin.h" |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 34 | #include "android_npapi.h" |
| 35 | |
| 36 | NPNetscapeFuncs* browser; |
| 37 | #define EXPORT __attribute__((visibility("default"))) |
| 38 | |
Derek Sollenberger | 9119e7d | 2009-06-08 10:53:09 -0400 | [diff] [blame] | 39 | NPError NPP_New(NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc, |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 40 | char* argn[], char* argv[], NPSavedData* saved); |
| 41 | NPError NPP_Destroy(NPP instance, NPSavedData** save); |
| 42 | NPError NPP_SetWindow(NPP instance, NPWindow* window); |
Derek Sollenberger | 9119e7d | 2009-06-08 10:53:09 -0400 | [diff] [blame] | 43 | NPError NPP_NewStream(NPP instance, NPMIMEType type, NPStream* stream, |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 44 | NPBool seekable, uint16* stype); |
| 45 | NPError NPP_DestroyStream(NPP instance, NPStream* stream, NPReason reason); |
| 46 | int32 NPP_WriteReady(NPP instance, NPStream* stream); |
Derek Sollenberger | 9119e7d | 2009-06-08 10:53:09 -0400 | [diff] [blame] | 47 | int32 NPP_Write(NPP instance, NPStream* stream, int32 offset, int32 len, |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 48 | void* buffer); |
| 49 | void NPP_StreamAsFile(NPP instance, NPStream* stream, const char* fname); |
| 50 | void NPP_Print(NPP instance, NPPrint* platformPrint); |
| 51 | int16 NPP_HandleEvent(NPP instance, void* event); |
Derek Sollenberger | 9119e7d | 2009-06-08 10:53:09 -0400 | [diff] [blame] | 52 | void NPP_URLNotify(NPP instance, const char* URL, NPReason reason, |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 53 | void* notifyData); |
| 54 | NPError NPP_GetValue(NPP instance, NPPVariable variable, void *value); |
| 55 | NPError NPP_SetValue(NPP instance, NPNVariable variable, void *value); |
| 56 | |
| 57 | extern "C" { |
| 58 | EXPORT NPError NP_Initialize(NPNetscapeFuncs* browserFuncs, NPPluginFuncs* pluginFuncs, void *java_env, void *application_context); |
| 59 | EXPORT NPError NP_GetValue(NPP instance, NPPVariable variable, void *value); |
| 60 | EXPORT const char* NP_GetMIMEDescription(void); |
Derek Sollenberger | 9119e7d | 2009-06-08 10:53:09 -0400 | [diff] [blame] | 61 | EXPORT void NP_Shutdown(void); |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 62 | }; |
| 63 | |
| 64 | ANPAudioTrackInterfaceV0 gSoundI; |
Mike Reed | 224adad | 2009-06-10 10:24:01 -0400 | [diff] [blame] | 65 | ANPBitmapInterfaceV0 gBitmapI; |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 66 | ANPCanvasInterfaceV0 gCanvasI; |
| 67 | ANPLogInterfaceV0 gLogI; |
| 68 | ANPPaintInterfaceV0 gPaintI; |
| 69 | ANPPathInterfaceV0 gPathI; |
| 70 | ANPTypefaceInterfaceV0 gTypefaceI; |
Derek Sollenberger | 5b011e3 | 2009-06-22 11:39:40 -0400 | [diff] [blame] | 71 | ANPWindowInterfaceV0 gWindowI; |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 72 | |
| 73 | #define ARRAY_COUNT(array) (sizeof(array) / sizeof(array[0])) |
Derek Sollenberger | 5b011e3 | 2009-06-22 11:39:40 -0400 | [diff] [blame] | 74 | #define DEBUG_PLUGIN_EVENTS 0 |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 75 | |
| 76 | NPError NP_Initialize(NPNetscapeFuncs* browserFuncs, NPPluginFuncs* pluginFuncs, void *java_env, void *application_context) |
| 77 | { |
| 78 | // Make sure we have a function table equal or larger than we are built against. |
| 79 | if (browserFuncs->size < sizeof(NPNetscapeFuncs)) { |
| 80 | return NPERR_GENERIC_ERROR; |
| 81 | } |
Derek Sollenberger | 9119e7d | 2009-06-08 10:53:09 -0400 | [diff] [blame] | 82 | |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 83 | // Copy the function table (structure) |
| 84 | browser = (NPNetscapeFuncs*) malloc(sizeof(NPNetscapeFuncs)); |
| 85 | memcpy(browser, browserFuncs, sizeof(NPNetscapeFuncs)); |
Derek Sollenberger | 9119e7d | 2009-06-08 10:53:09 -0400 | [diff] [blame] | 86 | |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 87 | // Build the plugin function table |
| 88 | pluginFuncs->version = 11; |
| 89 | pluginFuncs->size = sizeof(pluginFuncs); |
| 90 | pluginFuncs->newp = NPP_New; |
| 91 | pluginFuncs->destroy = NPP_Destroy; |
| 92 | pluginFuncs->setwindow = NPP_SetWindow; |
| 93 | pluginFuncs->newstream = NPP_NewStream; |
| 94 | pluginFuncs->destroystream = NPP_DestroyStream; |
| 95 | pluginFuncs->asfile = NPP_StreamAsFile; |
| 96 | pluginFuncs->writeready = NPP_WriteReady; |
| 97 | pluginFuncs->write = (NPP_WriteProcPtr)NPP_Write; |
| 98 | pluginFuncs->print = NPP_Print; |
| 99 | pluginFuncs->event = NPP_HandleEvent; |
| 100 | pluginFuncs->urlnotify = NPP_URLNotify; |
| 101 | pluginFuncs->getvalue = NPP_GetValue; |
| 102 | pluginFuncs->setvalue = NPP_SetValue; |
| 103 | |
| 104 | static const struct { |
| 105 | NPNVariable v; |
| 106 | uint32_t size; |
| 107 | ANPInterface* i; |
| 108 | } gPairs[] = { |
Mike Reed | 224adad | 2009-06-10 10:24:01 -0400 | [diff] [blame] | 109 | { kBitmapInterfaceV0_ANPGetValue, sizeof(gBitmapI), &gBitmapI }, |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 110 | { kCanvasInterfaceV0_ANPGetValue, sizeof(gCanvasI), &gCanvasI }, |
Mike Reed | 224adad | 2009-06-10 10:24:01 -0400 | [diff] [blame] | 111 | { kLogInterfaceV0_ANPGetValue, sizeof(gLogI), &gLogI }, |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 112 | { kPaintInterfaceV0_ANPGetValue, sizeof(gPaintI), &gPaintI }, |
| 113 | { kPathInterfaceV0_ANPGetValue, sizeof(gPathI), &gPathI }, |
| 114 | { kTypefaceInterfaceV0_ANPGetValue, sizeof(gPaintI), &gTypefaceI }, |
| 115 | { kAudioTrackInterfaceV0_ANPGetValue, sizeof(gSoundI), &gSoundI }, |
Derek Sollenberger | 5b011e3 | 2009-06-22 11:39:40 -0400 | [diff] [blame] | 116 | { kWindowInterfaceV0_ANPGetValue, sizeof(gWindowI), &gWindowI }, |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 117 | }; |
| 118 | for (size_t i = 0; i < ARRAY_COUNT(gPairs); i++) { |
| 119 | gPairs[i].i->inSize = gPairs[i].size; |
| 120 | NPError err = browser->getvalue(NULL, gPairs[i].v, gPairs[i].i); |
| 121 | if (err) { |
| 122 | return err; |
| 123 | } |
| 124 | } |
Derek Sollenberger | 9119e7d | 2009-06-08 10:53:09 -0400 | [diff] [blame] | 125 | |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 126 | return NPERR_NO_ERROR; |
| 127 | } |
| 128 | |
| 129 | void NP_Shutdown(void) |
| 130 | { |
| 131 | |
| 132 | } |
| 133 | |
Derek Sollenberger | 9119e7d | 2009-06-08 10:53:09 -0400 | [diff] [blame] | 134 | const char *NP_GetMIMEDescription(void) |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 135 | { |
Derek Sollenberger | d7ebf27 | 2009-06-18 11:19:41 -0400 | [diff] [blame] | 136 | return "application/x-testbrowserplugin:tst:Test plugin mimetype is application/x-testbrowserplugin"; |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | NPError NPP_New(NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc, |
| 140 | char* argn[], char* argv[], NPSavedData* saved) |
| 141 | { |
Derek Sollenberger | d7ebf27 | 2009-06-18 11:19:41 -0400 | [diff] [blame] | 142 | |
| 143 | /* BEGIN: STANDARD PLUGIN FRAMEWORK */ |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 144 | PluginObject *obj = NULL; |
| 145 | |
| 146 | // Scripting functions appeared in NPAPI version 14 |
| 147 | if (browser->version >= 14) { |
Derek Sollenberger | d7ebf27 | 2009-06-18 11:19:41 -0400 | [diff] [blame] | 148 | instance->pdata = browser->createobject (instance, getPluginClass()); |
| 149 | obj = static_cast<PluginObject*>(instance->pdata); |
| 150 | bzero(obj, sizeof(*obj)); |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 151 | } |
Derek Sollenberger | d7ebf27 | 2009-06-18 11:19:41 -0400 | [diff] [blame] | 152 | /* END: STANDARD PLUGIN FRAMEWORK */ |
Derek Sollenberger | 9119e7d | 2009-06-08 10:53:09 -0400 | [diff] [blame] | 153 | |
Derek Sollenberger | d7ebf27 | 2009-06-18 11:19:41 -0400 | [diff] [blame] | 154 | // select the drawing model based on user input |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 155 | ANPDrawingModel model = kBitmap_ANPDrawingModel; |
| 156 | |
Derek Sollenberger | d7ebf27 | 2009-06-18 11:19:41 -0400 | [diff] [blame] | 157 | for (int i = 0; i < argc; i++) { |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 158 | if (!strcmp(argn[i], "DrawingModel")) { |
| 159 | if (!strcmp(argv[i], "Bitmap")) { |
| 160 | model = kBitmap_ANPDrawingModel; |
| 161 | } |
| 162 | if (!strcmp(argv[i], "Canvas")) { |
Derek Sollenberger | d7ebf27 | 2009-06-18 11:19:41 -0400 | [diff] [blame] | 163 | //TODO support drawing on canvas instead of bitmap |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 164 | } |
| 165 | gLogI.log(instance, kDebug_ANPLogType, "------ %p DrawingModel is %d", instance, model); |
| 166 | break; |
| 167 | } |
| 168 | } |
| 169 | |
Derek Sollenberger | d7ebf27 | 2009-06-18 11:19:41 -0400 | [diff] [blame] | 170 | // comment this out to use the default model (bitmaps) |
| 171 | NPError err = browser->setvalue(instance, kRequestDrawingModel_ANPSetValue, |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 172 | reinterpret_cast<void*>(model)); |
| 173 | if (err) { |
| 174 | gLogI.log(instance, kError_ANPLogType, "request model %d err %d", model, err); |
Derek Sollenberger | d7ebf27 | 2009-06-18 11:19:41 -0400 | [diff] [blame] | 175 | return err; |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 176 | } |
Derek Sollenberger | d7ebf27 | 2009-06-18 11:19:41 -0400 | [diff] [blame] | 177 | |
| 178 | // select the pluginType |
| 179 | for (int i = 0; i < argc; i++) { |
| 180 | if (!strcmp(argn[i], "PluginType")) { |
| 181 | if (!strcmp(argv[i], "Animation")) { |
| 182 | obj->pluginType = kAnimation_PluginType; |
| 183 | obj->activePlugin = new BallAnimation(instance); |
| 184 | } |
| 185 | else if (!strcmp(argv[i], "Audio")) { |
| 186 | obj->pluginType = kAudio_PluginType; |
Derek Sollenberger | f42e2f4 | 2009-06-26 11:42:46 -0400 | [diff] [blame^] | 187 | obj->activePlugin = new AudioPlugin(instance); |
Derek Sollenberger | d7ebf27 | 2009-06-18 11:19:41 -0400 | [diff] [blame] | 188 | } |
| 189 | else if (!strcmp(argv[i], "Background")) { |
| 190 | obj->pluginType = kBackground_PluginType; |
| 191 | obj->activePlugin = new BackgroundPlugin(instance); |
| 192 | } |
| 193 | gLogI.log(instance, kDebug_ANPLogType, "------ %p PluginType is %d", instance, obj->pluginType); |
| 194 | break; |
| 195 | } |
| 196 | } |
| 197 | |
| 198 | // if no pluginType is specified then default to Animation |
| 199 | if (!obj->pluginType) { |
| 200 | obj->pluginType = kAnimation_PluginType; |
| 201 | obj->activePlugin = new BallAnimation(instance); |
| 202 | } |
| 203 | |
| 204 | return NPERR_NO_ERROR; |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 205 | } |
| 206 | |
| 207 | NPError NPP_Destroy(NPP instance, NPSavedData** save) |
| 208 | { |
| 209 | PluginObject *obj = (PluginObject*) instance->pdata; |
Derek Sollenberger | d7ebf27 | 2009-06-18 11:19:41 -0400 | [diff] [blame] | 210 | delete obj->activePlugin; |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 211 | |
| 212 | return NPERR_NO_ERROR; |
| 213 | } |
| 214 | |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 215 | NPError NPP_SetWindow(NPP instance, NPWindow* window) |
| 216 | { |
| 217 | PluginObject *obj = (PluginObject*) instance->pdata; |
Derek Sollenberger | 9119e7d | 2009-06-08 10:53:09 -0400 | [diff] [blame] | 218 | |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 219 | // Do nothing if browser didn't support NPN_CreateObject which would have created the PluginObject. |
| 220 | if (obj != NULL) { |
| 221 | obj->window = window; |
| 222 | } |
Derek Sollenberger | 9119e7d | 2009-06-08 10:53:09 -0400 | [diff] [blame] | 223 | |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 224 | browser->invalidaterect(instance, NULL); |
| 225 | |
| 226 | return NPERR_NO_ERROR; |
| 227 | } |
Derek Sollenberger | 9119e7d | 2009-06-08 10:53:09 -0400 | [diff] [blame] | 228 | |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 229 | NPError NPP_NewStream(NPP instance, NPMIMEType type, NPStream* stream, NPBool seekable, uint16* stype) |
| 230 | { |
| 231 | *stype = NP_ASFILEONLY; |
| 232 | return NPERR_NO_ERROR; |
| 233 | } |
| 234 | |
| 235 | NPError NPP_DestroyStream(NPP instance, NPStream* stream, NPReason reason) |
| 236 | { |
| 237 | return NPERR_NO_ERROR; |
| 238 | } |
| 239 | |
| 240 | int32 NPP_WriteReady(NPP instance, NPStream* stream) |
| 241 | { |
| 242 | return 0; |
| 243 | } |
| 244 | |
| 245 | int32 NPP_Write(NPP instance, NPStream* stream, int32 offset, int32 len, void* buffer) |
| 246 | { |
| 247 | return 0; |
| 248 | } |
| 249 | |
| 250 | void NPP_StreamAsFile(NPP instance, NPStream* stream, const char* fname) |
| 251 | { |
| 252 | } |
| 253 | |
| 254 | void NPP_Print(NPP instance, NPPrint* platformPrint) |
| 255 | { |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 256 | } |
| 257 | |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 258 | int16 NPP_HandleEvent(NPP instance, void* event) |
| 259 | { |
| 260 | PluginObject *obj = reinterpret_cast<PluginObject*>(instance->pdata); |
| 261 | const ANPEvent* evt = reinterpret_cast<const ANPEvent*>(event); |
| 262 | |
Derek Sollenberger | 5b011e3 | 2009-06-22 11:39:40 -0400 | [diff] [blame] | 263 | #if DEBUG_PLUGIN_EVENTS |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 264 | switch (evt->eventType) { |
| 265 | case kDraw_ANPEventType: |
Derek Sollenberger | d7ebf27 | 2009-06-18 11:19:41 -0400 | [diff] [blame] | 266 | |
| 267 | if (evt->data.draw.model == kBitmap_ANPDrawingModel) { |
| 268 | |
| 269 | static ANPBitmapFormat currentFormat = -1; |
| 270 | if (evt->data.draw.data.bitmap.format != currentFormat) { |
| 271 | currentFormat = evt->data.draw.data.bitmap.format; |
| 272 | gLogI.log(instance, kDebug_ANPLogType, "---- %p Draw (bitmap)" |
| 273 | " clip=%d,%d,%d,%d format=%d", instance, |
| 274 | evt->data.draw.clip.left, |
| 275 | evt->data.draw.clip.top, |
| 276 | evt->data.draw.clip.right, |
| 277 | evt->data.draw.clip.bottom, |
| 278 | evt->data.draw.data.bitmap.format); |
| 279 | } |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 280 | } |
Derek Sollenberger | d7ebf27 | 2009-06-18 11:19:41 -0400 | [diff] [blame] | 281 | break; |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 282 | |
| 283 | case kKey_ANPEventType: |
| 284 | gLogI.log(instance, kDebug_ANPLogType, "---- %p Key action=%d" |
| 285 | " code=%d vcode=%d unichar=%d repeat=%d mods=%x", instance, |
| 286 | evt->data.key.action, |
| 287 | evt->data.key.nativeCode, |
| 288 | evt->data.key.virtualCode, |
| 289 | evt->data.key.unichar, |
| 290 | evt->data.key.repeatCount, |
| 291 | evt->data.key.modifiers); |
Derek Sollenberger | d7ebf27 | 2009-06-18 11:19:41 -0400 | [diff] [blame] | 292 | break; |
Derek Sollenberger | 9119e7d | 2009-06-08 10:53:09 -0400 | [diff] [blame] | 293 | |
| 294 | case kLifecycle_ANPEventType: |
| 295 | gLogI.log(instance, kDebug_ANPLogType, "---- %p Lifecycle action=%d", |
Derek Sollenberger | d7ebf27 | 2009-06-18 11:19:41 -0400 | [diff] [blame] | 296 | instance, evt->data.lifecycle.action); |
Mike Reed | 1e7c331 | 2009-05-26 16:37:45 -0400 | [diff] [blame] | 297 | break; |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 298 | |
Derek Sollenberger | d7ebf27 | 2009-06-18 11:19:41 -0400 | [diff] [blame] | 299 | case kTouch_ANPEventType: |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 300 | gLogI.log(instance, kDebug_ANPLogType, "---- %p Touch action=%d [%d %d]", |
| 301 | instance, evt->data.touch.action, evt->data.touch.x, |
| 302 | evt->data.touch.y); |
Derek Sollenberger | 5b011e3 | 2009-06-22 11:39:40 -0400 | [diff] [blame] | 303 | break; |
| 304 | |
| 305 | case kVisibleRect_ANPEventType: |
| 306 | gLogI.log(instance, kDebug_ANPLogType, "---- %p VisibleRect [%d %d %d %d]", |
Derek Sollenberger | f42e2f4 | 2009-06-26 11:42:46 -0400 | [diff] [blame^] | 307 | instance, evt->data.visibleRect.rect.left, evt->data.visibleRect.rect.top, |
| 308 | evt->data.visibleRect.rect.right, evt->data.visibleRect.rect.bottom); |
Derek Sollenberger | 5b011e3 | 2009-06-22 11:39:40 -0400 | [diff] [blame] | 309 | break; |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 310 | |
| 311 | default: |
Derek Sollenberger | 5b011e3 | 2009-06-22 11:39:40 -0400 | [diff] [blame] | 312 | gLogI.log(instance, kError_ANPLogType, "---- %p Unknown Event [%d]", |
| 313 | instance, evt->eventType); |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 314 | break; |
| 315 | } |
Derek Sollenberger | 5b011e3 | 2009-06-22 11:39:40 -0400 | [diff] [blame] | 316 | #endif |
Derek Sollenberger | d7ebf27 | 2009-06-18 11:19:41 -0400 | [diff] [blame] | 317 | |
| 318 | if(!obj->activePlugin) { |
| 319 | gLogI.log(instance, kError_ANPLogType, "the active plugin is null."); |
| 320 | return 0; // unknown or unhandled event |
| 321 | } |
| 322 | else { |
| 323 | return obj->activePlugin->handleEvent(evt); |
| 324 | } |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 325 | } |
| 326 | |
| 327 | void NPP_URLNotify(NPP instance, const char* url, NPReason reason, void* notifyData) |
| 328 | { |
| 329 | |
| 330 | } |
| 331 | |
| 332 | EXPORT NPError NP_GetValue(NPP instance, NPPVariable variable, void *value) { |
| 333 | |
| 334 | if (variable == NPPVpluginNameString) { |
| 335 | const char **str = (const char **)value; |
| 336 | *str = "Test Plugin"; |
| 337 | return NPERR_NO_ERROR; |
| 338 | } |
Derek Sollenberger | 9119e7d | 2009-06-08 10:53:09 -0400 | [diff] [blame] | 339 | |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 340 | if (variable == NPPVpluginDescriptionString) { |
| 341 | const char **str = (const char **)value; |
| 342 | *str = "Description of Test Plugin"; |
| 343 | return NPERR_NO_ERROR; |
| 344 | } |
Derek Sollenberger | 9119e7d | 2009-06-08 10:53:09 -0400 | [diff] [blame] | 345 | |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 346 | return NPERR_GENERIC_ERROR; |
| 347 | } |
| 348 | |
| 349 | NPError NPP_GetValue(NPP instance, NPPVariable variable, void *value) |
| 350 | { |
| 351 | if (variable == NPPVpluginScriptableNPObject) { |
| 352 | void **v = (void **)value; |
| 353 | PluginObject *obj = (PluginObject*) instance->pdata; |
Derek Sollenberger | 9119e7d | 2009-06-08 10:53:09 -0400 | [diff] [blame] | 354 | |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 355 | if (obj) |
| 356 | browser->retainobject((NPObject*)obj); |
Derek Sollenberger | 9119e7d | 2009-06-08 10:53:09 -0400 | [diff] [blame] | 357 | |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 358 | *v = obj; |
| 359 | return NPERR_NO_ERROR; |
| 360 | } |
Derek Sollenberger | 9119e7d | 2009-06-08 10:53:09 -0400 | [diff] [blame] | 361 | |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 362 | return NPERR_GENERIC_ERROR; |
| 363 | } |
| 364 | |
| 365 | NPError NPP_SetValue(NPP instance, NPNVariable variable, void *value) |
| 366 | { |
| 367 | return NPERR_GENERIC_ERROR; |
| 368 | } |
| 369 | |