Hi All,

I have been trying to understand the WebKit2 source and hopefully
start contributing small missing functionality to start with. Towards
this goal, I have implemented a small browser that can open multiple
tabs based on WebKit2 C API. I am currently using the GTK+ port from
the master branch of WebKit's git repo for this.

As I understand, as of now plugins are not working in WebKit2/GTK+. To
understand the same and start contributing (if possible), I plan to
use a basic windowless plugin for understanding/debugging. However, my
problem is that when I open a test HTML page that has this plugin, it
opens fine in Firefox, and somewhat okay in Chrome (the position is
shifted), but when I open the same using GtkLauncher or midori, both
fail to show the plugin area - although I could see that the plugin's
NPP functions are receiving the calls and the plugin's event handler
is also fired with event type GraphicsExpose - but nothing is drawn in
plugin area. (The plugin should draw two empty squares with green
boundary on a black background.). It will be pointless to use this for
testing/understanding WebKit2 unless this works fine on WebKit.

I have tried running this both on a recent commit on the master branch
as well as on WebKit/GTK+ version 1.4.0. The plugin code is as
attached below.

Could someone please have a look and let me know if there is something
in the plugin that is wrong, or is there an issue in WebKit/GTK+ port
with respect to window-less plugins ? I tried looking at bugzilla but
could not find any relevant bugs...

Thanks in advance for any helpful suggestion and pointers..

regards,
Aneesh Bhasin
/*
 * Copyright (C) 2006, 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.
 */

#include <npfunctions.h>

extern NPNetscapeFuncs* browser;

typedef struct
{
	NPObject	header;
} DefaultObject;
/*
 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved.
 * Copyright (C) 2009 Holger Hans Peter Freyther
 *
 * 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.
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "defaultObject.h"

#include <npapi.h>
#include <npruntime.h>

#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xos.h>
#include <X11/Xatom.h>
#include <X11/keysym.h>


extern "C"
{
	char* NP_GetMIMEDescription(void);
	NPError NP_Initialize (NPNetscapeFuncs*, NPPluginFuncs*);
	NPError NP_Shutdown(void);
	NPError NP_GetValue(void*, NPPVariable, void*);
}

NPNetscapeFuncs* browser;

static NPObject* default_Allocate(NPP npp, NPClass* theClass)
{
    printf("\n\noDEFPLUGIN: in %s\n\n",__func__);
	DefaultObject* newInstance = (DefaultObject*) malloc(sizeof(DefaultObject));
	if(!newInstance)
	{
		return NULL;
	}
	memset(newInstance, 0, sizeof(DefaultObject));

	return (NPObject*) newInstance;
}

static void default_Deallocate(NPObject* obj)
{
    printf("\n\nDEFPLUGIN: in %s\n\n",__func__);
	DefaultObject* plugin = reinterpret_cast<DefaultObject*>(obj);
	free(plugin);
}

NPClass* getDefaultClass(void)
{
    printf("\n\nDEFPLUGIN: in %s\n\n",__func__);
	static NPClass defaultClass =
	{
		NP_CLASS_STRUCT_VERSION,
		default_Allocate,
		default_Deallocate,
		NULL,
		NULL,
		NULL,
		NULL,
		NULL,
		NULL,
		NULL,
		NULL,
		NULL,
		NULL
	};
	return &defaultClass;
}

static NPError createInstance(NPMIMEType mimetype, NPP instance, uint16_t mode,
			int16_t argc, char* argn[], char* argv[], NPSavedData* savedData)
{
    printf("\n\nDEFPLUGIN: in %s\n\n",__func__);
	if(browser->version >= 14)
	{
		DefaultObject* obj = (DefaultObject*) browser->createobject(instance, getDefaultClass());
		if(!obj)
		{
			return NPERR_OUT_OF_MEMORY_ERROR;
		}

		instance->pdata = obj;
		browser->setvalue(instance, NPPVpluginWindowBool, (void*) FALSE);
	}

	return NPERR_NO_ERROR;
}

static NPError destroyInstance(NPP instance, NPSavedData** save)
{
    printf("\n\nDEFPLUGIN: in %s\n\n",__func__);
	DefaultObject* obj = static_cast<DefaultObject*>(instance->pdata);
	if(!obj)
	{
		return NPERR_NO_DATA;
	}

	browser->releaseobject(&obj->header);
    return NPERR_NO_ERROR;
}

static NPError setWindow(NPP instance, NPWindow* window)
{
    printf("\n\nDEFPLUGIN: in %s\n\n",__func__);
	DefaultObject* obj = static_cast<DefaultObject*>(instance->pdata);
	if(!obj || !window)
	{
		return NPERR_NO_DATA;
	}

	return NPERR_NO_ERROR;
}


static int16_t handleEvent(NPP instance, void* event)
{
    printf("\n\nDEFPLUGIN: in %s\n\n",__func__);
	DefaultObject* obj = static_cast<DefaultObject*>(instance->pdata);
	if(!obj)
	{
		return 0;
	}

	XEvent* xevent = (XEvent*) event;
	if(xevent->type == GraphicsExpose)
	{
        printf("\n\nDEFPLUGIN: in %s, got GraphicsExpose!!\n\n",__func__);
		XGraphicsExposeEvent* expose = &xevent->xgraphicsexpose;

		GC green_gc;
		XColor green_col;
		Colormap colormap;
		char green[] = "#00FF00";
		colormap = DefaultColormap(expose->display, 0);
		green_gc = XCreateGC(expose->display, expose->drawable, 0, 0);
		XParseColor(expose->display, colormap, green, &green_col);
		XAllocColor(expose->display, colormap, &green_col);
		
		XSetForeground(expose->display, green_gc, green_col.pixel);

		XDrawRectangle(expose->display, expose->drawable, green_gc, 1, 1, 100, 100);
		XDrawRectangle(expose->display, expose->drawable, green_gc, 50, 50, 100, 100);
		XFlush(expose->display);	
	}
    else
    {
        printf("\n\nDEFPLUGIN: in %s, NOT GraphicsExpose\n\n",__func__);
    }

	return 1;
}

static NPError getValue(NPP instance, NPPVariable variable, void* value)
{
    printf("\n\nDEFPLUGIN: in %s\n\n",__func__);
	NPError err = NPERR_NO_ERROR;

	switch(variable)
	{
	case NPPVpluginNameString:
	case NPPVpluginDescriptionString:
		*((const char**)value) = "default plug-in";
		break;
	case NPPVpluginNeedsXEmbed:
		*((NPBool*)value) = TRUE;
		break;
	case NPPVpluginScriptableIID:
	case NPPVpluginScriptableInstance:
		err = NPERR_GENERIC_ERROR;
		break;
	case NPPVpluginScriptableNPObject:
		{
			NPObject* obj = static_cast<NPObject*>(instance->pdata);
			browser->retainobject(obj);
			*((void**)value) = obj;
			err = NPERR_NO_ERROR;
		}
		break;
	default:
		err = NPERR_GENERIC_ERROR;
		break;
	}

	return err;
}

static NPError setValue(NPP instance, NPNVariable variable, void* value)
{
    printf("\n\nDEFPLUGIN: in %s\n\n",__func__);
	return NPERR_NO_ERROR;
}

char* NP_GetMIMEDescription(void)
{
    printf("\n\nDEFPLUGIN: in %s\n\n",__func__);
	return (char*) "application/defplugin::";
}

NPError NP_Initialize(NPNetscapeFuncs* aMozillaVTable, NPPluginFuncs* aPluginVTable)
{
    printf("\n\nDEFPLUGIN: in %s\n\n",__func__);
	if(aMozillaVTable == NULL || aPluginVTable == NULL)
	{
		return NPERR_INVALID_FUNCTABLE_ERROR;
	}

	if((aMozillaVTable->version >> 8) > NP_VERSION_MAJOR)
	{
		return NPERR_INCOMPATIBLE_VERSION_ERROR;
	}

	if(aMozillaVTable->size < sizeof(NPNetscapeFuncs))
	{
		return NPERR_INVALID_FUNCTABLE_ERROR;
	}
	if(aPluginVTable->size < sizeof(NPPluginFuncs))
	{
		return NPERR_INVALID_FUNCTABLE_ERROR;
	}

	browser = aMozillaVTable;

	aPluginVTable->size           = sizeof(NPPluginFuncs);
	aPluginVTable->version        = (NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR;
	aPluginVTable->newp           = createInstance;
	aPluginVTable->destroy        = destroyInstance;
	aPluginVTable->setwindow      = setWindow;
	aPluginVTable->newstream      = NULL;
	aPluginVTable->destroystream  = NULL;
	aPluginVTable->asfile         = NULL;
	aPluginVTable->writeready     = NULL;
	aPluginVTable->write          = NULL;
	aPluginVTable->print          = NULL;
	aPluginVTable->event          = handleEvent;
	aPluginVTable->urlnotify      = NULL; 
	aPluginVTable->javaClass      = NULL;
	aPluginVTable->getvalue       = getValue;
	aPluginVTable->setvalue       = setValue;

	return NPERR_NO_ERROR;
}

NPError NP_Shutdown(void)
{
    printf("\n\nDEFPLUGIN: in %s\n\n",__func__);
	return NPERR_NO_ERROR;
}

NPError NP_GetValue(void* future, NPPVariable variable, void* value)
{
    printf("\n\nDEFPLUGIN: in %s\n\n",__func__);
	return getValue(NULL, variable, value);
}
_______________________________________________
webkit-dev mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-dev

Reply via email to