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