[webkit-dev] Pushing data to plugin

Eric Carlson eric.carlson at mac.com
Fri Mar 20 10:09:38 PDT 2009


Jack -

On Mar 20, 2009, at 9:24 AM, Jack Wootton wrote:

> Yes, but the problem is that program control is in the plugin instance
> object and not the Plugin itself.  Plugin instance objects are created
> after the plugin is created.
>
> 1. Plugin created (have reference to Browser via NPNetscapeFuncs.
> 2. Plugin object returned to Browser.
>
> /* Some time later */
>
> 3. Browser parses an instance of the <object> tag with a MIME type
> matching the plugin.
> 4. Browser creates a plugin instance object, but does not provide a
> reference to to NPNetscapeFuncs.
>

   There is only one browser, so stash the table of function pointers  
in a static variable:

enum
{
	kUserAgent_WebKit	= 'webk',
	kUserAgent_Opera	= 'opra',
	kUserAgent_Gecko	= 'geko',
	kUserAgent_Camino	= 'simn',
	kUserAgent_Firefox	= 'ffox',
	kUserAgent_MSIE	= 'msie',
};

static NPNetscapeFuncs *gBrowser  = NULL;
static uint32 gUserAgent = 0;

NPError OSCALL NP_Initialize(NPNetscapeFuncs* browserFuncs)
{
     gBrowser = browserFuncs;
     return NPERR_NO_ERROR;
}

NPError NPP_New(NPMIMEType pluginType, NPP instance, uint16 mode,  
int16 argc, char* argn[], char* argv[], NPSavedData* saved)
{
	const char *userAgent = gBrowser->uagent(instance);

	if ( userAgent )
	{
		if ( strstr(userAgent, "AppleWebKit") )
			gUserAgent = kUserAgent_WebKit;
		else if ( strstr(userAgent, "Opera") )
			gUserAgent = kUserAgent_Opera;
		else if ( strstr(userAgent, "Gecko") )
		{
			gUserAgent = kUserAgent_Gecko;
			if ( strstr(userAgent, "Camino") )
				gUserAgent = kUserAgent_Camino;
			else if ( strstr(userAgent, "Firefox") )
				gUserAgent = kUserAgent_Firefox;
		}
		else if ( strstr(userAgent, "MSIE") )
			gUserAgent = kUserAgent_MSIE;
	}

     return NPERR_NO_ERROR;
}

   Or have I misunderstood what you are trying to do?

eric


>
>
> On Fri, Mar 20, 2009 at 4:11 PM, Mugdha Jain  
> <MugdhaJain at smarttech.com> wrote:
>>
>> No that won't work. What you need to do is store the function  
>> pointer passed
>> by the browser and use that to call the required function. That  
>> would mean
>> you have to do the following:
>>
>> g_NPNFuncs.geturl
>>
>> Where g_NPNFuncs is: g_NPNFuncs = browser below.
>>
>> // Mach-o entry points
>> NPError NP_Initialize(NPNetscapeFuncs *browserFuncs)
>> {
>>     browser = browserFuncs;
>>     return NPERR_NO_ERROR;
>> }
>>
>> Browser would call this function on the plugin when it loads the  
>> plugin for
>> the first time.
>>
>> Hope that helps.
>> Mugdha
>>
>> -----Original Message-----
>> From: webkit-dev-bounces at lists.webkit.org on behalf of Jack Wootton
>> Sent: Fri 3/20/2009 9:35 AM
>> To: Alexey Proskuryakov
>> Cc: webkit-dev at lists.webkit.org
>> Subject: Re: [webkit-dev] Pushing data to plugin
>>
>> So I would have thought this would work inside the plugin instance
>> object method New (aInstance is of type NPP)
>>
>>
>> NPNetscapeFuncs* browser =  
>> static_cast<NPNetscapeFuncs*>(aInstance.ndata);
>>
>> But it doesn't :P
>>
>>
>> 2009/3/20 Alexey Proskuryakov <ap at webkit.org>:
>>>
>>> 20.03.2009, ? 18:15, Jack Wootton ???????(?):
>>>
>>>> I'm unsure about how I can access the Browser functions.
>>>
>>>
>>> You can see how this works in one of our example plug-ins. E.g.,  
>>> form
>>> TestNetscapePlugin:
>>>
>>> NPNetscapeFuncs *browser;
>>>
>>> // Mach-o entry points
>>> extern "C" {
>>>    NPError NP_Initialize(NPNetscapeFuncs *browserFuncs);
>>>    NPError NP_GetEntryPoints(NPPluginFuncs *pluginFuncs);
>>>    void NP_Shutdown(void);
>>> }
>>>
>>> // Mach-o entry points
>>> NPError NP_Initialize(NPNetscapeFuncs *browserFuncs)
>>> {
>>>    browser = browserFuncs;
>>>    return NPERR_NO_ERROR;
>>> }
>>>
>>> - WBR, Alexey Proskuryakov
>>>
>>>
>>>
>>
>>
>>
>> --
>> Regards
>> Jack
>> _______________________________________________
>> webkit-dev mailing list
>> webkit-dev at lists.webkit.org
>> http://lists.webkit.org/mailman/listinfo.cgi/webkit-dev
>>
>>
>
>
>
> -- 
> Regards
> Jack
> _______________________________________________
> webkit-dev mailing list
> webkit-dev at lists.webkit.org
> http://lists.webkit.org/mailman/listinfo.cgi/webkit-dev



More information about the webkit-dev mailing list