/* Compile with: GECKO=firefox # or xulrunner gcc -c `pkg-config --cflags $GECKO-plugin` -o dumbplugin.o dumbplugin.c gcc -shared -fPIC -o libdumbplugin.so dumbplugin.o `pkg-config --libs $GECKO-plugin` cp libdumbplugin.so /usr/lib/mozilla/plugins */ /* Totem Mozilla plugin * * Copyright (C) <2004> Bastien Nocera * Copyright (C) <2002> David A. Schleef * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ #include "mozilla-config.h" #include #include #include #include #include "npapi.h" #include "npupp.h" static NPNetscapeFuncs mozilla_functions; static NPError dumb_plugin_new_instance (NPMIMEType mime_type, NPP instance, uint16_t mode, int16_t argc, char *argn[], char *argv[], NPSavedData *saved) { int i; printf ("NewInstance instance %p mime_type %s mode %d\n", instance, mime_type, mode); for (i=0; igetvalue, NULL, NPNVSupportsXEmbedBool, (void *)&supportsXEmbed); if (err != NPERR_NO_ERROR || supportsXEmbed != PR_TRUE) return NPERR_INCOMPATIBLE_VERSION_ERROR; /* Are we using a GTK+ 2.x Moz? */ err = CallNPN_GetValueProc (moz_funcs->getvalue, NULL, NPNVToolkit, (void *)&toolkit); if (err != NPERR_NO_ERROR || toolkit != NPNVGtk2) return NPERR_INCOMPATIBLE_VERSION_ERROR; if(moz_funcs == NULL || plugin_funcs == NULL) return NPERR_INVALID_FUNCTABLE_ERROR; if ((moz_funcs->version >> 8) > NP_VERSION_MAJOR) return NPERR_INCOMPATIBLE_VERSION_ERROR; if (moz_funcs->size < sizeof (NPNetscapeFuncs)) return NPERR_INVALID_FUNCTABLE_ERROR; if (plugin_funcs->size < sizeof (NPPluginFuncs)) return NPERR_INVALID_FUNCTABLE_ERROR; /* * Copy all of the fields of the Mozilla function table into our * copy so we can call back into Mozilla later. Note that we need * to copy the fields one by one, rather than assigning the whole * structure, because the Mozilla function table could actually be * bigger than what we expect. */ mozilla_functions.size = moz_funcs->size; mozilla_functions.version = moz_funcs->version; mozilla_functions.geturl = moz_funcs->geturl; mozilla_functions.posturl = moz_funcs->posturl; mozilla_functions.requestread = moz_funcs->requestread; mozilla_functions.newstream = moz_funcs->newstream; mozilla_functions.write = moz_funcs->write; mozilla_functions.destroystream = moz_funcs->destroystream; mozilla_functions.status = moz_funcs->status; mozilla_functions.uagent = moz_funcs->uagent; mozilla_functions.memalloc = moz_funcs->memalloc; mozilla_functions.memfree = moz_funcs->memfree; mozilla_functions.memflush = moz_funcs->memflush; mozilla_functions.reloadplugins = moz_funcs->reloadplugins; mozilla_functions.getJavaEnv = moz_funcs->getJavaEnv; mozilla_functions.getJavaPeer = moz_funcs->getJavaPeer; mozilla_functions.geturlnotify = moz_funcs->geturlnotify; mozilla_functions.posturlnotify = moz_funcs->posturlnotify; mozilla_functions.getvalue = moz_funcs->getvalue; mozilla_functions.setvalue = moz_funcs->setvalue; mozilla_functions.invalidaterect = moz_funcs->invalidaterect; mozilla_functions.invalidateregion = moz_funcs->invalidateregion; mozilla_functions.forceredraw = moz_funcs->forceredraw; /* * Set up a plugin function table that Mozilla will use to call * into us. Mozilla needs to know about our version and size and * have a UniversalProcPointer for every function we implement. */ plugin_funcs->size = sizeof(NPPluginFuncs); plugin_funcs->version = (NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR; plugin_funcs->newp = NewNPP_NewProc(dumb_plugin_new_instance); plugin_funcs->destroy = NewNPP_DestroyProc(dumb_plugin_destroy_instance); plugin_funcs->setwindow = NewNPP_SetWindowProc(dumb_plugin_set_window); plugin_funcs->newstream = NewNPP_NewStreamProc(dumb_plugin_new_stream); plugin_funcs->destroystream = NewNPP_DestroyStreamProc(dumb_plugin_destroy_stream); plugin_funcs->asfile = NewNPP_StreamAsFileProc(dumb_plugin_stream_as_file); plugin_funcs->writeready = NewNPP_WriteReadyProc(dumb_plugin_write_ready); plugin_funcs->write = NewNPP_WriteProc(dumb_plugin_write); /* Printing ? */ plugin_funcs->print = NewNPP_PrintProc(NULL); /* What's that for ? */ plugin_funcs->event = NewNPP_HandleEventProc(NULL); plugin_funcs->urlnotify = NewNPP_URLNotifyProc(dumb_plugin_url_notify); plugin_funcs->javaClass = NULL; plugin_funcs->getvalue = NewNPP_GetValueProc(dumb_plugin_get_value); plugin_funcs->setvalue = NewNPP_SetValueProc(dumb_plugin_set_value); printf ("NP_Initialize success\n"); return NPERR_NO_ERROR; } NPError NP_Shutdown(void) { printf ("NP_Shutdown\n"); return NPERR_NO_ERROR; }