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