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 | 1bc5ab6 | 2010-01-14 11:44:37 -0500 | [diff] [blame] | 35 | #include "NavigationPlugin.h" |
Derek Sollenberger | 4fb83e6 | 2009-07-27 16:40:13 -0400 | [diff] [blame] | 36 | #include "PaintPlugin.h" |
Derek Sollenberger | b8947ee | 2009-10-05 14:40:18 -0400 | [diff] [blame] | 37 | #include "VideoPlugin.h" |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 38 | |
| 39 | NPNetscapeFuncs* browser; |
Derek Sollenberger | b8947ee | 2009-10-05 14:40:18 -0400 | [diff] [blame] | 40 | JavaVM* gVM; |
| 41 | |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 42 | #define EXPORT __attribute__((visibility("default"))) |
| 43 | |
Ben Murdoch | 3b6f45d | 2010-05-12 14:09:26 +0100 | [diff] [blame] | 44 | NPError NPP_New(NPMIMEType pluginType, NPP instance, uint16_t mode, int16_t argc, |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 45 | char* argn[], char* argv[], NPSavedData* saved); |
| 46 | NPError NPP_Destroy(NPP instance, NPSavedData** save); |
| 47 | NPError NPP_SetWindow(NPP instance, NPWindow* window); |
Derek Sollenberger | 9119e7d | 2009-06-08 10:53:09 -0400 | [diff] [blame] | 48 | NPError NPP_NewStream(NPP instance, NPMIMEType type, NPStream* stream, |
Ben Murdoch | 3b6f45d | 2010-05-12 14:09:26 +0100 | [diff] [blame] | 49 | NPBool seekable, uint16_t* stype); |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 50 | NPError NPP_DestroyStream(NPP instance, NPStream* stream, NPReason reason); |
Ben Murdoch | 3b6f45d | 2010-05-12 14:09:26 +0100 | [diff] [blame] | 51 | int32_t NPP_WriteReady(NPP instance, NPStream* stream); |
| 52 | int32_t NPP_Write(NPP instance, NPStream* stream, int32_t offset, int32_t len, |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 53 | void* buffer); |
| 54 | void NPP_StreamAsFile(NPP instance, NPStream* stream, const char* fname); |
| 55 | void NPP_Print(NPP instance, NPPrint* platformPrint); |
Ben Murdoch | 3b6f45d | 2010-05-12 14:09:26 +0100 | [diff] [blame] | 56 | int16_t NPP_HandleEvent(NPP instance, void* event); |
Derek Sollenberger | 9119e7d | 2009-06-08 10:53:09 -0400 | [diff] [blame] | 57 | void NPP_URLNotify(NPP instance, const char* URL, NPReason reason, |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 58 | void* notifyData); |
| 59 | NPError NPP_GetValue(NPP instance, NPPVariable variable, void *value); |
| 60 | NPError NPP_SetValue(NPP instance, NPNVariable variable, void *value); |
| 61 | |
| 62 | extern "C" { |
Derek Sollenberger | 4fe6d38 | 2010-01-21 15:04:58 -0500 | [diff] [blame] | 63 | EXPORT NPError NP_Initialize(NPNetscapeFuncs* browserFuncs, NPPluginFuncs* pluginFuncs, void *java_env); |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 64 | EXPORT NPError NP_GetValue(NPP instance, NPPVariable variable, void *value); |
| 65 | EXPORT const char* NP_GetMIMEDescription(void); |
Derek Sollenberger | 9119e7d | 2009-06-08 10:53:09 -0400 | [diff] [blame] | 66 | EXPORT void NP_Shutdown(void); |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 67 | }; |
| 68 | |
| 69 | ANPAudioTrackInterfaceV0 gSoundI; |
Mike Reed | 224adad | 2009-06-10 10:24:01 -0400 | [diff] [blame] | 70 | ANPBitmapInterfaceV0 gBitmapI; |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 71 | ANPCanvasInterfaceV0 gCanvasI; |
Derek Sollenberger | d53b56d | 2010-01-11 12:31:49 -0500 | [diff] [blame] | 72 | ANPEventInterfaceV0 gEventI; |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 73 | ANPLogInterfaceV0 gLogI; |
| 74 | ANPPaintInterfaceV0 gPaintI; |
| 75 | ANPPathInterfaceV0 gPathI; |
Derek Sollenberger | c0f2657 | 2009-07-16 11:38:02 -0400 | [diff] [blame] | 76 | ANPSurfaceInterfaceV0 gSurfaceI; |
Grace Kloba | 9ffe5ac | 2009-08-04 17:51:06 -0700 | [diff] [blame] | 77 | ANPSystemInterfaceV0 gSystemI; |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 78 | ANPTypefaceInterfaceV0 gTypefaceI; |
Derek Sollenberger | 1e64f02 | 2011-01-07 14:11:29 -0500 | [diff] [blame] | 79 | ANPWindowInterfaceV1 gWindowI; |
Derek Sollenberger | 349bc37 | 2011-01-04 16:14:34 -0500 | [diff] [blame] | 80 | ANPOpenGLInterfaceV0 gOpenGLI; |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 81 | |
| 82 | #define ARRAY_COUNT(array) (sizeof(array) / sizeof(array[0])) |
Derek Sollenberger | 5b011e3 | 2009-06-22 11:39:40 -0400 | [diff] [blame] | 83 | #define DEBUG_PLUGIN_EVENTS 0 |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 84 | |
Derek Sollenberger | 4fe6d38 | 2010-01-21 15:04:58 -0500 | [diff] [blame] | 85 | NPError NP_Initialize(NPNetscapeFuncs* browserFuncs, NPPluginFuncs* pluginFuncs, void *java_env) |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 86 | { |
| 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 Sollenberger | 9119e7d | 2009-06-08 10:53:09 -0400 | [diff] [blame] | 91 | |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 92 | // Copy the function table (structure) |
| 93 | browser = (NPNetscapeFuncs*) malloc(sizeof(NPNetscapeFuncs)); |
| 94 | memcpy(browser, browserFuncs, sizeof(NPNetscapeFuncs)); |
Derek Sollenberger | 9119e7d | 2009-06-08 10:53:09 -0400 | [diff] [blame] | 95 | |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 96 | // 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[] = { |
Derek Sollenberger | c0f2657 | 2009-07-16 11:38:02 -0400 | [diff] [blame] | 118 | { kAudioTrackInterfaceV0_ANPGetValue, sizeof(gSoundI), &gSoundI }, |
Mike Reed | 224adad | 2009-06-10 10:24:01 -0400 | [diff] [blame] | 119 | { kBitmapInterfaceV0_ANPGetValue, sizeof(gBitmapI), &gBitmapI }, |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 120 | { kCanvasInterfaceV0_ANPGetValue, sizeof(gCanvasI), &gCanvasI }, |
Derek Sollenberger | d53b56d | 2010-01-11 12:31:49 -0500 | [diff] [blame] | 121 | { kEventInterfaceV0_ANPGetValue, sizeof(gEventI), &gEventI }, |
Mike Reed | 224adad | 2009-06-10 10:24:01 -0400 | [diff] [blame] | 122 | { kLogInterfaceV0_ANPGetValue, sizeof(gLogI), &gLogI }, |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 123 | { kPaintInterfaceV0_ANPGetValue, sizeof(gPaintI), &gPaintI }, |
| 124 | { kPathInterfaceV0_ANPGetValue, sizeof(gPathI), &gPathI }, |
Derek Sollenberger | c0f2657 | 2009-07-16 11:38:02 -0400 | [diff] [blame] | 125 | { kSurfaceInterfaceV0_ANPGetValue, sizeof(gSurfaceI), &gSurfaceI }, |
Grace Kloba | 9ffe5ac | 2009-08-04 17:51:06 -0700 | [diff] [blame] | 126 | { kSystemInterfaceV0_ANPGetValue, sizeof(gSystemI), &gSystemI }, |
| 127 | { kTypefaceInterfaceV0_ANPGetValue, sizeof(gTypefaceI), &gTypefaceI }, |
Derek Sollenberger | 1e64f02 | 2011-01-07 14:11:29 -0500 | [diff] [blame] | 128 | { kWindowInterfaceV1_ANPGetValue, sizeof(gWindowI), &gWindowI }, |
Derek Sollenberger | 349bc37 | 2011-01-04 16:14:34 -0500 | [diff] [blame] | 129 | { kOpenGLInterfaceV0_ANPGetValue, sizeof(gOpenGLI), &gOpenGLI }, |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 130 | }; |
| 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 Sollenberger | 9119e7d | 2009-06-08 10:53:09 -0400 | [diff] [blame] | 138 | |
Derek Sollenberger | b8947ee | 2009-10-05 14:40:18 -0400 | [diff] [blame] | 139 | // store the JavaVM for the plugin |
| 140 | JNIEnv* env = (JNIEnv*)java_env; |
| 141 | env->GetJavaVM(&gVM); |
| 142 | |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 143 | return NPERR_NO_ERROR; |
| 144 | } |
| 145 | |
| 146 | void NP_Shutdown(void) |
| 147 | { |
| 148 | |
| 149 | } |
| 150 | |
Derek Sollenberger | 9119e7d | 2009-06-08 10:53:09 -0400 | [diff] [blame] | 151 | const char *NP_GetMIMEDescription(void) |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 152 | { |
Derek Sollenberger | d7ebf27 | 2009-06-18 11:19:41 -0400 | [diff] [blame] | 153 | return "application/x-testbrowserplugin:tst:Test plugin mimetype is application/x-testbrowserplugin"; |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 154 | } |
| 155 | |
Ben Murdoch | 3b6f45d | 2010-05-12 14:09:26 +0100 | [diff] [blame] | 156 | NPError NPP_New(NPMIMEType pluginType, NPP instance, uint16_t mode, int16_t argc, |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 157 | char* argn[], char* argv[], NPSavedData* saved) |
| 158 | { |
Derek Sollenberger | d7ebf27 | 2009-06-18 11:19:41 -0400 | [diff] [blame] | 159 | |
| 160 | /* BEGIN: STANDARD PLUGIN FRAMEWORK */ |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 161 | PluginObject *obj = NULL; |
| 162 | |
| 163 | // Scripting functions appeared in NPAPI version 14 |
| 164 | if (browser->version >= 14) { |
Derek Sollenberger | b4a2391 | 2009-11-09 15:38:58 -0500 | [diff] [blame] | 165 | instance->pdata = browser->createobject (instance, getPluginClass()); |
| 166 | obj = static_cast<PluginObject*>(instance->pdata); |
Derek Sollenberger | 349bc37 | 2011-01-04 16:14:34 -0500 | [diff] [blame] | 167 | obj->pluginType = 0; |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 168 | } |
Derek Sollenberger | d7ebf27 | 2009-06-18 11:19:41 -0400 | [diff] [blame] | 169 | /* END: STANDARD PLUGIN FRAMEWORK */ |
Derek Sollenberger | 9119e7d | 2009-06-08 10:53:09 -0400 | [diff] [blame] | 170 | |
Derek Sollenberger | 4fb83e6 | 2009-07-27 16:40:13 -0400 | [diff] [blame] | 171 | // 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 Sollenberger | 349bc37 | 2011-01-04 16:14:34 -0500 | [diff] [blame] | 182 | else if (!strcmp(argv[i], "OpenGL")) { |
| 183 | model = kOpenGL_ANPDrawingModel; |
| 184 | } |
Derek Sollenberger | e62ce17 | 2009-11-30 11:52:06 -0500 | [diff] [blame] | 185 | gLogI.log(kDebug_ANPLogType, "------ %p DrawingModel is %d", instance, model); |
Derek Sollenberger | 4fb83e6 | 2009-07-27 16:40:13 -0400 | [diff] [blame] | 186 | 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 Sollenberger | e62ce17 | 2009-11-30 11:52:06 -0500 | [diff] [blame] | 195 | gLogI.log(kError_ANPLogType, "request model %d err %d", model, err); |
Derek Sollenberger | 4fb83e6 | 2009-07-27 16:40:13 -0400 | [diff] [blame] | 196 | return err; |
| 197 | } |
| 198 | |
Grace Kloba | 9ffe5ac | 2009-08-04 17:51:06 -0700 | [diff] [blame] | 199 | const char* path = gSystemI.getApplicationDataDirectory(); |
| 200 | if (path) { |
Derek Sollenberger | e62ce17 | 2009-11-30 11:52:06 -0500 | [diff] [blame] | 201 | gLogI.log(kDebug_ANPLogType, "Application data dir is %s", path); |
Grace Kloba | 9ffe5ac | 2009-08-04 17:51:06 -0700 | [diff] [blame] | 202 | } else { |
Derek Sollenberger | e62ce17 | 2009-11-30 11:52:06 -0500 | [diff] [blame] | 203 | gLogI.log(kError_ANPLogType, "Can't find Application data dir"); |
Grace Kloba | 9ffe5ac | 2009-08-04 17:51:06 -0700 | [diff] [blame] | 204 | } |
| 205 | |
Derek Sollenberger | d7ebf27 | 2009-06-18 11:19:41 -0400 | [diff] [blame] | 206 | // 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 Sollenberger | f42e2f4 | 2009-06-26 11:42:46 -0400 | [diff] [blame] | 215 | obj->activePlugin = new AudioPlugin(instance); |
Derek Sollenberger | d7ebf27 | 2009-06-18 11:19:41 -0400 | [diff] [blame] | 216 | } |
| 217 | else if (!strcmp(argv[i], "Background")) { |
| 218 | obj->pluginType = kBackground_PluginType; |
| 219 | obj->activePlugin = new BackgroundPlugin(instance); |
| 220 | } |
Derek Sollenberger | db398a7 | 2009-06-29 13:53:04 -0400 | [diff] [blame] | 221 | else if (!strcmp(argv[i], "Form")) { |
| 222 | obj->pluginType = kForm_PluginType; |
| 223 | obj->activePlugin = new FormPlugin(instance); |
| 224 | } |
Derek Sollenberger | 1bc5ab6 | 2010-01-14 11:44:37 -0500 | [diff] [blame] | 225 | else if (!strcmp(argv[i], "Navigation")) { |
| 226 | obj->pluginType = kNavigation_PluginType; |
| 227 | obj->activePlugin = new NavigationPlugin(instance); |
| 228 | } |
Derek Sollenberger | 4fb83e6 | 2009-07-27 16:40:13 -0400 | [diff] [blame] | 229 | else if (!strcmp(argv[i], "Paint")) { |
| 230 | obj->pluginType = kPaint_PluginType; |
| 231 | obj->activePlugin = new PaintPlugin(instance); |
| 232 | } |
Derek Sollenberger | b8947ee | 2009-10-05 14:40:18 -0400 | [diff] [blame] | 233 | else if (!strcmp(argv[i], "Video")) { |
| 234 | obj->pluginType = kVideo_PluginType; |
| 235 | obj->activePlugin = new VideoPlugin(instance); |
| 236 | } |
Derek Sollenberger | d7ebf27 | 2009-06-18 11:19:41 -0400 | [diff] [blame] | 237 | break; |
| 238 | } |
| 239 | } |
| 240 | |
| 241 | // if no pluginType is specified then default to Animation |
| 242 | if (!obj->pluginType) { |
Derek Sollenberger | e62ce17 | 2009-11-30 11:52:06 -0500 | [diff] [blame] | 243 | gLogI.log(kError_ANPLogType, "------ %p No PluginType attribute was found", instance); |
Derek Sollenberger | d7ebf27 | 2009-06-18 11:19:41 -0400 | [diff] [blame] | 244 | obj->pluginType = kAnimation_PluginType; |
| 245 | obj->activePlugin = new BallAnimation(instance); |
| 246 | } |
| 247 | |
Derek Sollenberger | 349bc37 | 2011-01-04 16:14:34 -0500 | [diff] [blame] | 248 | gLogI.log(kDebug_ANPLogType, "------ %p PluginType is %d", instance, obj->pluginType); |
| 249 | |
Derek Sollenberger | 21f3991 | 2009-07-09 09:19:39 -0400 | [diff] [blame] | 250 | // check to ensure the pluginType supports the model |
| 251 | if (!obj->activePlugin->supportsDrawingModel(model)) { |
Derek Sollenberger | e62ce17 | 2009-11-30 11:52:06 -0500 | [diff] [blame] | 252 | gLogI.log(kError_ANPLogType, "------ %p Unsupported DrawingModel (%d)", instance, model); |
Derek Sollenberger | 21f3991 | 2009-07-09 09:19:39 -0400 | [diff] [blame] | 253 | return NPERR_GENERIC_ERROR; |
| 254 | } |
| 255 | |
Derek Sollenberger | d53b56d | 2010-01-11 12:31:49 -0500 | [diff] [blame] | 256 | // if the plugin uses the surface drawing model then set the java context |
Derek Sollenberger | 349bc37 | 2011-01-04 16:14:34 -0500 | [diff] [blame] | 257 | if (model == kSurface_ANPDrawingModel || model == kOpenGL_ANPDrawingModel) { |
Derek Sollenberger | d53b56d | 2010-01-11 12:31:49 -0500 | [diff] [blame] | 258 | SurfaceSubPlugin* surfacePlugin = static_cast<SurfaceSubPlugin*>(obj->activePlugin); |
| 259 | |
| 260 | jobject context; |
| 261 | NPError err = browser->getvalue(instance, kJavaContext_ANPGetValue, |
| 262 | static_cast<void*>(&context)); |
| 263 | if (err) { |
| 264 | gLogI.log(kError_ANPLogType, "request context err: %d", err); |
| 265 | return err; |
| 266 | } |
| 267 | |
| 268 | surfacePlugin->setContext(context); |
| 269 | } |
| 270 | |
| 271 | |
Derek Sollenberger | d7ebf27 | 2009-06-18 11:19:41 -0400 | [diff] [blame] | 272 | return NPERR_NO_ERROR; |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 273 | } |
| 274 | |
| 275 | NPError NPP_Destroy(NPP instance, NPSavedData** save) |
| 276 | { |
| 277 | PluginObject *obj = (PluginObject*) instance->pdata; |
Grace Kloba | a0e762c | 2009-12-27 13:21:41 -0800 | [diff] [blame] | 278 | if (obj) { |
| 279 | delete obj->activePlugin; |
| 280 | browser->releaseobject(&obj->header); |
| 281 | } |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 282 | |
| 283 | return NPERR_NO_ERROR; |
| 284 | } |
| 285 | |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 286 | NPError NPP_SetWindow(NPP instance, NPWindow* window) |
| 287 | { |
| 288 | PluginObject *obj = (PluginObject*) instance->pdata; |
Derek Sollenberger | 9119e7d | 2009-06-08 10:53:09 -0400 | [diff] [blame] | 289 | |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 290 | // Do nothing if browser didn't support NPN_CreateObject which would have created the PluginObject. |
| 291 | if (obj != NULL) { |
| 292 | obj->window = window; |
| 293 | } |
Derek Sollenberger | 9119e7d | 2009-06-08 10:53:09 -0400 | [diff] [blame] | 294 | |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 295 | browser->invalidaterect(instance, NULL); |
| 296 | |
| 297 | return NPERR_NO_ERROR; |
| 298 | } |
Derek Sollenberger | 9119e7d | 2009-06-08 10:53:09 -0400 | [diff] [blame] | 299 | |
Ben Murdoch | 3b6f45d | 2010-05-12 14:09:26 +0100 | [diff] [blame] | 300 | NPError NPP_NewStream(NPP instance, NPMIMEType type, NPStream* stream, NPBool seekable, uint16_t* stype) |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 301 | { |
| 302 | *stype = NP_ASFILEONLY; |
| 303 | return NPERR_NO_ERROR; |
| 304 | } |
| 305 | |
| 306 | NPError NPP_DestroyStream(NPP instance, NPStream* stream, NPReason reason) |
| 307 | { |
| 308 | return NPERR_NO_ERROR; |
| 309 | } |
| 310 | |
Ben Murdoch | 3b6f45d | 2010-05-12 14:09:26 +0100 | [diff] [blame] | 311 | int32_t NPP_WriteReady(NPP instance, NPStream* stream) |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 312 | { |
| 313 | return 0; |
| 314 | } |
| 315 | |
Ben Murdoch | 3b6f45d | 2010-05-12 14:09:26 +0100 | [diff] [blame] | 316 | int32_t NPP_Write(NPP instance, NPStream* stream, int32_t offset, int32_t len, void* buffer) |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 317 | { |
| 318 | return 0; |
| 319 | } |
| 320 | |
| 321 | void NPP_StreamAsFile(NPP instance, NPStream* stream, const char* fname) |
| 322 | { |
| 323 | } |
| 324 | |
| 325 | void NPP_Print(NPP instance, NPPrint* platformPrint) |
| 326 | { |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 327 | } |
| 328 | |
Ben Murdoch | 3b6f45d | 2010-05-12 14:09:26 +0100 | [diff] [blame] | 329 | int16_t NPP_HandleEvent(NPP instance, void* event) |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 330 | { |
| 331 | PluginObject *obj = reinterpret_cast<PluginObject*>(instance->pdata); |
| 332 | const ANPEvent* evt = reinterpret_cast<const ANPEvent*>(event); |
| 333 | |
Derek Sollenberger | 5b011e3 | 2009-06-22 11:39:40 -0400 | [diff] [blame] | 334 | #if DEBUG_PLUGIN_EVENTS |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 335 | switch (evt->eventType) { |
| 336 | case kDraw_ANPEventType: |
Derek Sollenberger | d7ebf27 | 2009-06-18 11:19:41 -0400 | [diff] [blame] | 337 | |
| 338 | if (evt->data.draw.model == kBitmap_ANPDrawingModel) { |
| 339 | |
| 340 | static ANPBitmapFormat currentFormat = -1; |
| 341 | if (evt->data.draw.data.bitmap.format != currentFormat) { |
| 342 | currentFormat = evt->data.draw.data.bitmap.format; |
Derek Sollenberger | e62ce17 | 2009-11-30 11:52:06 -0500 | [diff] [blame] | 343 | gLogI.log(kDebug_ANPLogType, "---- %p Draw (bitmap)" |
Derek Sollenberger | d7ebf27 | 2009-06-18 11:19:41 -0400 | [diff] [blame] | 344 | " clip=%d,%d,%d,%d format=%d", instance, |
| 345 | evt->data.draw.clip.left, |
| 346 | evt->data.draw.clip.top, |
| 347 | evt->data.draw.clip.right, |
| 348 | evt->data.draw.clip.bottom, |
| 349 | evt->data.draw.data.bitmap.format); |
| 350 | } |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 351 | } |
Derek Sollenberger | d7ebf27 | 2009-06-18 11:19:41 -0400 | [diff] [blame] | 352 | break; |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 353 | |
| 354 | case kKey_ANPEventType: |
Derek Sollenberger | e62ce17 | 2009-11-30 11:52:06 -0500 | [diff] [blame] | 355 | gLogI.log(kDebug_ANPLogType, "---- %p Key action=%d" |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 356 | " code=%d vcode=%d unichar=%d repeat=%d mods=%x", instance, |
| 357 | evt->data.key.action, |
| 358 | evt->data.key.nativeCode, |
| 359 | evt->data.key.virtualCode, |
| 360 | evt->data.key.unichar, |
| 361 | evt->data.key.repeatCount, |
| 362 | evt->data.key.modifiers); |
Derek Sollenberger | d7ebf27 | 2009-06-18 11:19:41 -0400 | [diff] [blame] | 363 | break; |
Derek Sollenberger | 9119e7d | 2009-06-08 10:53:09 -0400 | [diff] [blame] | 364 | |
| 365 | case kLifecycle_ANPEventType: |
Derek Sollenberger | e62ce17 | 2009-11-30 11:52:06 -0500 | [diff] [blame] | 366 | gLogI.log(kDebug_ANPLogType, "---- %p Lifecycle action=%d", |
Derek Sollenberger | d7ebf27 | 2009-06-18 11:19:41 -0400 | [diff] [blame] | 367 | instance, evt->data.lifecycle.action); |
Mike Reed | 1e7c331 | 2009-05-26 16:37:45 -0400 | [diff] [blame] | 368 | break; |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 369 | |
Derek Sollenberger | d7ebf27 | 2009-06-18 11:19:41 -0400 | [diff] [blame] | 370 | case kTouch_ANPEventType: |
Derek Sollenberger | e62ce17 | 2009-11-30 11:52:06 -0500 | [diff] [blame] | 371 | gLogI.log(kDebug_ANPLogType, "---- %p Touch action=%d [%d %d]", |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 372 | instance, evt->data.touch.action, evt->data.touch.x, |
| 373 | evt->data.touch.y); |
Derek Sollenberger | 5b011e3 | 2009-06-22 11:39:40 -0400 | [diff] [blame] | 374 | break; |
| 375 | |
Derek Sollenberger | db398a7 | 2009-06-29 13:53:04 -0400 | [diff] [blame] | 376 | case kMouse_ANPEventType: |
Derek Sollenberger | e62ce17 | 2009-11-30 11:52:06 -0500 | [diff] [blame] | 377 | gLogI.log(kDebug_ANPLogType, "---- %p Mouse action=%d [%d %d]", |
Derek Sollenberger | db398a7 | 2009-06-29 13:53:04 -0400 | [diff] [blame] | 378 | instance, evt->data.mouse.action, evt->data.mouse.x, |
| 379 | evt->data.mouse.y); |
| 380 | break; |
| 381 | |
Derek Sollenberger | 5b011e3 | 2009-06-22 11:39:40 -0400 | [diff] [blame] | 382 | case kVisibleRect_ANPEventType: |
Derek Sollenberger | e62ce17 | 2009-11-30 11:52:06 -0500 | [diff] [blame] | 383 | gLogI.log(kDebug_ANPLogType, "---- %p VisibleRect [%d %d %d %d]", |
Derek Sollenberger | f42e2f4 | 2009-06-26 11:42:46 -0400 | [diff] [blame] | 384 | instance, evt->data.visibleRect.rect.left, evt->data.visibleRect.rect.top, |
| 385 | evt->data.visibleRect.rect.right, evt->data.visibleRect.rect.bottom); |
Derek Sollenberger | 5b011e3 | 2009-06-22 11:39:40 -0400 | [diff] [blame] | 386 | break; |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 387 | |
| 388 | default: |
Derek Sollenberger | e62ce17 | 2009-11-30 11:52:06 -0500 | [diff] [blame] | 389 | gLogI.log(kError_ANPLogType, "---- %p Unknown Event [%d]", |
Derek Sollenberger | 5b011e3 | 2009-06-22 11:39:40 -0400 | [diff] [blame] | 390 | instance, evt->eventType); |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 391 | break; |
| 392 | } |
Derek Sollenberger | 5b011e3 | 2009-06-22 11:39:40 -0400 | [diff] [blame] | 393 | #endif |
Derek Sollenberger | d7ebf27 | 2009-06-18 11:19:41 -0400 | [diff] [blame] | 394 | |
| 395 | if(!obj->activePlugin) { |
Derek Sollenberger | e62ce17 | 2009-11-30 11:52:06 -0500 | [diff] [blame] | 396 | gLogI.log(kError_ANPLogType, "the active plugin is null."); |
Derek Sollenberger | d7ebf27 | 2009-06-18 11:19:41 -0400 | [diff] [blame] | 397 | return 0; // unknown or unhandled event |
| 398 | } |
| 399 | else { |
| 400 | return obj->activePlugin->handleEvent(evt); |
| 401 | } |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 402 | } |
| 403 | |
| 404 | void NPP_URLNotify(NPP instance, const char* url, NPReason reason, void* notifyData) |
| 405 | { |
| 406 | |
| 407 | } |
| 408 | |
| 409 | EXPORT NPError NP_GetValue(NPP instance, NPPVariable variable, void *value) { |
| 410 | |
| 411 | if (variable == NPPVpluginNameString) { |
| 412 | const char **str = (const char **)value; |
| 413 | *str = "Test Plugin"; |
| 414 | return NPERR_NO_ERROR; |
| 415 | } |
Derek Sollenberger | 9119e7d | 2009-06-08 10:53:09 -0400 | [diff] [blame] | 416 | |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 417 | if (variable == NPPVpluginDescriptionString) { |
| 418 | const char **str = (const char **)value; |
| 419 | *str = "Description of Test Plugin"; |
| 420 | return NPERR_NO_ERROR; |
| 421 | } |
Derek Sollenberger | 9119e7d | 2009-06-08 10:53:09 -0400 | [diff] [blame] | 422 | |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 423 | return NPERR_GENERIC_ERROR; |
| 424 | } |
| 425 | |
Derek Sollenberger | d53b56d | 2010-01-11 12:31:49 -0500 | [diff] [blame] | 426 | NPError NPP_GetValue(NPP instance, NPPVariable variable, void* value) |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 427 | { |
| 428 | if (variable == NPPVpluginScriptableNPObject) { |
| 429 | void **v = (void **)value; |
| 430 | PluginObject *obj = (PluginObject*) instance->pdata; |
Derek Sollenberger | 9119e7d | 2009-06-08 10:53:09 -0400 | [diff] [blame] | 431 | |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 432 | if (obj) |
Derek Sollenberger | b4a2391 | 2009-11-09 15:38:58 -0500 | [diff] [blame] | 433 | browser->retainobject(&obj->header); |
Derek Sollenberger | 9119e7d | 2009-06-08 10:53:09 -0400 | [diff] [blame] | 434 | |
Derek Sollenberger | b4a2391 | 2009-11-09 15:38:58 -0500 | [diff] [blame] | 435 | *v = &(obj->header); |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 436 | return NPERR_NO_ERROR; |
| 437 | } |
Derek Sollenberger | 9119e7d | 2009-06-08 10:53:09 -0400 | [diff] [blame] | 438 | |
Derek Sollenberger | d53b56d | 2010-01-11 12:31:49 -0500 | [diff] [blame] | 439 | if (variable == kJavaSurface_ANPGetValue) { |
| 440 | //get the surface sub-plugin |
| 441 | PluginObject* obj = static_cast<PluginObject*>(instance->pdata); |
| 442 | if (obj && obj->activePlugin) { |
| 443 | |
Derek Sollenberger | 349bc37 | 2011-01-04 16:14:34 -0500 | [diff] [blame] | 444 | if(obj->activePlugin->supportsDrawingModel(kSurface_ANPDrawingModel) |
| 445 | || obj->activePlugin->supportsDrawingModel(kOpenGL_ANPDrawingModel)) { |
Derek Sollenberger | d53b56d | 2010-01-11 12:31:49 -0500 | [diff] [blame] | 446 | SurfaceSubPlugin* plugin = static_cast<SurfaceSubPlugin*>(obj->activePlugin); |
| 447 | jobject* surface = static_cast<jobject*>(value); |
| 448 | *surface = plugin->getSurface(); |
| 449 | return NPERR_NO_ERROR; |
| 450 | } else { |
| 451 | gLogI.log(kError_ANPLogType, |
| 452 | "-- %p Tried to retrieve surface for non-surface plugin", |
| 453 | instance); |
| 454 | } |
| 455 | } |
| 456 | } |
| 457 | |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 458 | return NPERR_GENERIC_ERROR; |
| 459 | } |
| 460 | |
| 461 | NPError NPP_SetValue(NPP instance, NPNVariable variable, void *value) |
| 462 | { |
| 463 | return NPERR_GENERIC_ERROR; |
| 464 | } |
| 465 | |