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