[webkit-dev] Plugins again :-)

R Bassett rachel.bassett at yahoo.co.uk
Fri Apr 18 09:19:03 PDT 2008


Many thanks for both your feedback and help - I will give it a go.

Rachel

--- Sriram Neelakandan <sriram.neelakandan at gmail.com> wrote:

> Rachel,
> 
> First of all, you will have to apply this patch  for Plugins to work
> https://bugs.webkit.org/show_bug.cgi?id=14750
> 
> And this patch currently supports only GTK/X11. no GTK/DFB !
> 
> I have got a basic gtk-plugin .. No Drawing .. just printfs .. started to
> work just a few hours ago ..
> I have attached the file here (main.c) .. It has been adopted from the Mac
> Version
> 
> 
> 1. Create a Directory "TestNetscapePlugin" under
> /WebKitTools/DumpRenderTree/gtk/
> 2. Copy attached main.c to this new directory
> WebKitTools/DumpRenderTree/gtk/TestNetscapePlugin/
> 3. Attached "plugin_build.sh" I use this to build the plugin .. to work
> around Makefile.in issues
> 
> As i told you this plugin is very very basic
> 
> Once my sample plugin is up to some shape .. i plan to submit a patch with a
> complete GTK plugin sample .. may take a week or so
> 
> Also .. you will require this HTML snippet to test your plugin
> 
> <object url="/home/sriram/my_patch.txt" width="100" height="100"
> type="application/basic-test-plugin">
>   <p>Sample plugin installed and running ? </p>
> </object>
> 
> Happy pluging
> Sriram
> 
> 
> On 4/17/08, Darin Adler <darin at apple.com> wrote:
> >
> > On Apr 17, 2008, at 8:40 AM, R Bassett wrote:
> >
> >  I've got a directfb / gtk / webkit software stack cross-compiled and
> > > running nicely on my platform. I'd like to add a plugin however I'm
> failing
> > > to find a simple example that I can start with. I got hold of the
> "simple"
> > > NetscapeMoviePlugIn from the Mac from a friend but that still seems to
> want
> > > to include all sorts of other Mac OS headers I don't have. So then I
> thought
> > > I'd look at Mozillas plugin examples, but even the "basic" plugin relies
> on
> > > X. Does anyone have a simple template that just prints hello world or
> > > something like that into a webkit window, that doesn't try and pull in
> > > dependancies from all over the place?
> > >
> > > If I've missed the plot - please let me know!
> > >
> >
> > The Netscape plug-in API doesn't provide a graphics library. So you have
> > to use one from the platform you're working on. Thus any plug-in that does
> > any drawing at all will have to pull in some platform dependency. You are
> > presumably looking for one with GTK or something in its family as the
> > graphics dependency, and you probably won't find a plug-in example that's
> > already like that.
> >
> >    -- Darin
> >
> > _______________________________________________
> > webkit-dev mailing list
> > webkit-dev at lists.webkit.org
> > http://lists.webkit.org/mailman/listinfo/webkit-dev
> >
> 
> 
> 
> -- 
> Sriram Neelakandan
> Author - Embedded Linux System Design And Development (
> http://tinyurl.com/2doosu)
> > /*
>  * Copyright (C) 2007 Apple Inc. All rights reserved.
>  *
>  * Redistribution and use in source and binary forms, with or without
>  * modification, are permitted provided that the following conditions
>  * are met:
>  * 1. Redistributions of source code must retain the above copyright
>  *    notice, this list of conditions and the following disclaimer.
>  * 2. Redistributions in binary form must reproduce the above copyright
>  *    notice, this list of conditions and the following disclaimer in the
>  *    documentation and/or other materials provided with the distribution.
>  *
>  * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
>  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
>  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
>  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
>  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
>  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
>  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
>  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
>  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
>  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
>  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
>  *
>  *
>  * Modified from MacOS sample for GTK by Sriram Neelakandan
>  */
> 
> //#include "PluginObject.h"
> 
> #include <stdio.h>
> #include <stdlib.h>
> #include <string.h>
> 
> #define __stdcall 
> 
> #define MIME_TYPES_HANDLED  "application/basic-test-plugin"
> #define PLUGIN_NAME         "Basic Example Plug-in for Webkit"
> #define MIME_TYPES_DESCRIPTION  MIME_TYPES_HANDLED":bsc:"PLUGIN_NAME
> #define PLUGIN_DESCRIPTION  PLUGIN_NAME " (Plug-ins SDK sample)"
> 
> NPNetscapeFuncs* browser;
> extern "C"
> NPError __stdcall NP_Initialize(NPNetscapeFuncs* browserFuncs, NPPluginFuncs
> *pluginFuncs)
> {
>     browser = browserFuncs;
>     pluginFuncs->version = 11;
>     pluginFuncs->size = sizeof(pluginFuncs);
>     pluginFuncs->newp = NPP_New;
>     pluginFuncs->destroy = NPP_Destroy;
>     pluginFuncs->setwindow = NPP_SetWindow;
>     pluginFuncs->newstream = NPP_NewStream;
>     pluginFuncs->destroystream = NPP_DestroyStream;
>     pluginFuncs->asfile = NPP_StreamAsFile;
>     pluginFuncs->writeready = NPP_WriteReady;
>     pluginFuncs->write = (NPP_WriteProcPtr)NPP_Write;
>     pluginFuncs->print = NPP_Print;
>     pluginFuncs->event = NPP_HandleEvent;
>     pluginFuncs->urlnotify = NPP_URLNotify;
>     pluginFuncs->getvalue = NPP_GetValue;
>     pluginFuncs->setvalue = NPP_SetValue;
>     
>     return NPERR_NO_ERROR;
> }
> 
> 
> extern "C"
> NPError __stdcall NP_Shutdown()
> {
>     return NPERR_NO_ERROR;
> }
> extern "C"
> char* NP_GetMIMEDescription(void)
> {
>   return (char*)(MIME_TYPES_DESCRIPTION);
> }
> 
> // get values per plugin
> NPError NS_PluginGetValue(NPPVariable aVariable, void *aValue)
> {
>   NPError err = NPERR_NO_ERROR;
>   switch (aVariable) {
>     case NPPVpluginNameString:
>       *((char **)aValue) = (char*)PLUGIN_NAME;
>       break;
>     case NPPVpluginDescriptionString:
>       *((char **)aValue) = (char*)PLUGIN_DESCRIPTION;
>       break;
>     default:
>       err = NPERR_INVALID_PARAM;
>       break;
>   }
>   return err;
> }
> 
> extern "C"
> NPError NP_GetValue(void *instance, 
>                     NPPVariable variable, 
>                     void *value)
> {
> 
>   NPError err = NPERR_NO_ERROR;
>   switch (variable) {
>     case NPPVpluginNameString:
>     case NPPVpluginDescriptionString:
>       return NS_PluginGetValue(variable, value) ;
>       break;
>     default:
>       err = NPERR_INVALID_PARAM;
>       break;
>   }
>   return err;
> }
> 
> 
> 
> 
> 
> 
> NPError NPP_New(NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc,
> char *argn[], char *argv[], NPSavedData *saved)
> {
> 
>   switch(mode)
>   {
>     case NP_EMBED:
> 	printf("called from embed tag\n");
> 	break;
>     case NP_FULL:
> 	printf("File\n");
> 	break;
>   }
> 	char cmd[1024];
> 	cmd[0]='\0';
>         for (int16 i = 0; i < argc; i++) {
>             if (strcasecmp(argn[i], "url") == 0) {
>                 printf("Got URL as :%s\n",(argv[i]));
> 		sprintf(cmd,"cat '%s'",argv[i]);
> 		system(cmd);
> 		}
>         }
> 
> 
> #if 0
>     if (browser->version >= 14) {
>         PluginObject* obj = (PluginObject*)browser->createobject(instance,
> getPluginClass());
>     
>         obj->onStreamLoad = NULL;
>         
>         for (int16 i = 0; i < argc; i++) {
>             if (strcasecmp(argn[i], "onstreamload") == 0 &&
> !obj->onStreamLoad)
>                 obj->onStreamLoad = strdup(argv[i]);
>         }
>         
>         instance->pdata = obj;
>     }
> #endif
>     printf("NPP_New called\n");
>     
>     return NPERR_NO_ERROR;
> }
> 
> NPError NPP_Destroy(NPP instance, NPSavedData **save)
> {
>     PluginObject *obj = (PluginObject*)instance->pdata;
>     if (obj) {
>         if (obj->onStreamLoad)
>             free(obj->onStreamLoad);
>         
>         if (obj->logDestroy)
>             printf("PLUGIN: NPP_Destroy\n");
> 
>         browser->releaseobject(&obj->header);
>     }
>     return NPERR_NO_ERROR;
> }
> 
> NPError NPP_SetWindow(NPP instance, NPWindow *window)
> {
>     return NPERR_NO_ERROR;
> }
> 
> NPError NPP_NewStream(NPP instance, NPMIMEType type, NPStream *stream, NPBool
> seekable, uint16 *stype)
> {
>     PluginObject* obj = (PluginObject*)instance->pdata;
>     obj->stream = stream;
>     *stype = NP_ASFILEONLY;
> 
>     if (obj->onStreamLoad) {
>         NPObject *windowScriptObject;
>         browser->getvalue(obj->npp, NPNVWindowNPObject, &windowScriptObject);
>                 
>         NPString script;
>         script.UTF8Characters = obj->onStreamLoad;
>         script.UTF8Length = strlen(obj->onStreamLoad);
>         
>         NPVariant browserResult;
>         browser->evaluate(obj->npp, windowScriptObject, &script,
> &browserResult);
>         browser->releasevariantvalue(&browserResult);
>     }
>     
>     return NPERR_NO_ERROR;
> }
> 
> NPError NPP_DestroyStream(NPP instance, NPStream *stream, NPReason reason)
> {
>     return NPERR_NO_ERROR;
> }
> 
> int32 NPP_WriteReady(NPP instance, NPStream *stream)
> {
>     return 0;
> }
> 
> int32 NPP_Write(NPP instance, NPStream *stream, int32 offset, int32 len, void
> *buffer)
> {
>     return 0;
> }
> 
> void NPP_StreamAsFile(NPP instance, NPStream *stream, const char *fname)
> {
> }
> 
> void NPP_Print(NPP instance, NPPrint *platformPrint)
> {
> }
> 
> int16 NPP_HandleEvent(NPP instance, void *event)
> {
>     PluginObject *obj = (PluginObject*)instance->pdata;
>     if (!obj->eventLogging)
>         return 0;
>     
>     // FIXME: Implement this
>     return 0;
> }
> 
> void NPP_URLNotify(NPP instance, const char *url, NPReason reason, void
> *notifyData)
> {
>     PluginObject *obj = (PluginObject*)instance->pdata;
> #if 0    
>     handleCallback(obj, url, reason, notifyData);
> #else
>     printf("Got URL= %s\n",url);
> #endif 
> }
> 
> NPError NPP_GetValue(NPP instance, NPPVariable variable, void *value)
> {
>     if (variable == NPPVpluginScriptableNPObject) {
>         void **v = (void **)value;
>         PluginObject *obj = (PluginObject*)instance->pdata;
>         // Return value is expected to be retained
>         browser->retainobject((NPObject *)obj);
>         *v = obj;
>         return NPERR_NO_ERROR;
>     }
>     return NPERR_GENERIC_ERROR;
> }
> 
> NPError NPP_SetValue(NPP instance, NPNVariable variable, void *value)
> {
>     return NPERR_GENERIC_ERROR;
> }
> 
> 
> 
> 
> 
> 



      __________________________________________________________
Sent from Yahoo! Mail.
A Smarter Email http://uk.docs.yahoo.com/nowyoucan.html


More information about the webkit-dev mailing list