Add header file to iteration over browser and plugin functions

Saves a bit of effort, and simplifies capability passing. We lose the
npruntime logic, but we may as well unconditionally initialize the
bridge. It's cheap and every browser should have it by now.
This commit is contained in:
David Benjamin 2011-04-27 10:06:42 -04:00
parent eab4684a2f
commit a8017830ef
4 changed files with 136 additions and 131 deletions

75
src/browser-funcs.h Normal file
View File

@ -0,0 +1,75 @@
/*
* browser-funcs.h - Browser functions
*
* nspluginwrapper (C) 2011 David Benjamin
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
BROWSER_FUNC(NPN_GetURL, geturl)
BROWSER_FUNC(NPN_PostURL, posturl)
BROWSER_FUNC(NPN_RequestRead, requestread)
BROWSER_FUNC(NPN_NewStream, newstream)
BROWSER_FUNC(NPN_Write, write)
BROWSER_FUNC(NPN_DestroyStream, destroystream)
BROWSER_FUNC(NPN_Status, status)
BROWSER_FUNC(NPN_UserAgent, uagent)
BROWSER_FUNC(NPN_MemAlloc, memalloc)
BROWSER_FUNC(NPN_MemFree, memfree)
BROWSER_FUNC(NPN_MemFlush, memflush)
BROWSER_FUNC(NPN_ReloadPlugins, reloadplugins)
BROWSER_FUNC(NPN_GetJavaEnv, getJavaEnv)
BROWSER_FUNC(NPN_GetJavaPeer, getJavaPeer)
BROWSER_FUNC(NPN_GetURLNotify, geturlnotify)
BROWSER_FUNC(NPN_PostURLNotify, posturlnotify)
BROWSER_FUNC(NPN_GetValue, getvalue)
BROWSER_FUNC(NPN_SetValue, setvalue)
BROWSER_FUNC(NPN_InvalidateRect, invalidaterect)
BROWSER_FUNC(NPN_InvalidateRegion, invalidateregion)
BROWSER_FUNC(NPN_ForceRedraw, forceredraw)
BROWSER_FUNC(NPN_GetStringIdentifier, getstringidentifier)
BROWSER_FUNC(NPN_GetStringIdentifiers, getstringidentifiers)
BROWSER_FUNC(NPN_GetIntIdentifier, getintidentifier)
BROWSER_FUNC(NPN_IdentifierIsString, identifierisstring)
BROWSER_FUNC(NPN_UTF8FromIdentifier, utf8fromidentifier)
BROWSER_FUNC(NPN_IntFromIdentifier, intfromidentifier)
BROWSER_FUNC(NPN_CreateObject, createobject)
BROWSER_FUNC(NPN_RetainObject, retainobject)
BROWSER_FUNC(NPN_ReleaseObject, releaseobject)
BROWSER_FUNC(NPN_Invoke, invoke)
BROWSER_FUNC(NPN_InvokeDefault, invokeDefault)
BROWSER_FUNC(NPN_Evaluate, evaluate)
BROWSER_FUNC(NPN_GetProperty, getproperty)
BROWSER_FUNC(NPN_SetProperty, setproperty)
BROWSER_FUNC(NPN_RemoveProperty, removeproperty)
BROWSER_FUNC(NPN_HasProperty, hasproperty)
BROWSER_FUNC(NPN_HasMethod, hasmethod)
BROWSER_FUNC(NPN_ReleaseVariantValue, releasevariantvalue)
BROWSER_FUNC(NPN_SetException, setexception)
BROWSER_FUNC(NPN_PushPopupsEnabledState, pushpopupsenabledstate)
BROWSER_FUNC(NPN_PopPopupsEnabledState, poppopupsenabledstate)
BROWSER_FUNC(NPN_Enumerate, enumerate)
BROWSER_FUNC(NPN_PluginThreadAsyncCall, pluginthreadasynccall)
BROWSER_FUNC(NPN_Construct, construct)
BROWSER_FUNC(NPN_GetValueForURL, getvalueforurl)
BROWSER_FUNC(NPN_SetValueForURL, setvalueforurl)
BROWSER_FUNC(NPN_GetAuthenticationInfo, getauthenticationinfo)
BROWSER_FUNC(NPN_ScheduleTimer, scheduletimer)
BROWSER_FUNC(NPN_UnscheduleTimer, unscheduletimer)
// BROWSER_FUNC(NPN_PopUpContextMenu, popupcontextmenu)
// BROWSER_FUNC(NPN_ConvertPoint, convertpoint)
// BROWSER_FUNC(NPN_HandleEvent, handleevent)
// BROWSER_FUNC(NPN_UnfocusInstance, unfocusinstance)
// BROWSER_FUNC(NPN_URLRedirectResponse, urlredirectresponse)

View File

@ -3560,62 +3560,17 @@ g_NP_Initialize(uint32_t version, uint32_t *plugin_version)
memset(&mozilla_funcs, 0, sizeof(mozilla_funcs));
mozilla_funcs.size = sizeof(mozilla_funcs);
mozilla_funcs.version = version;
mozilla_funcs.geturl = g_NPN_GetURL;
mozilla_funcs.posturl = g_NPN_PostURL;
mozilla_funcs.requestread = g_NPN_RequestRead;
mozilla_funcs.newstream = g_NPN_NewStream;
mozilla_funcs.write = g_NPN_Write;
mozilla_funcs.destroystream = g_NPN_DestroyStream;
mozilla_funcs.status = g_NPN_Status;
mozilla_funcs.uagent = g_NPN_UserAgent;
mozilla_funcs.memalloc = g_NPN_MemAlloc;
mozilla_funcs.memfree = g_NPN_MemFree;
mozilla_funcs.memflush = g_NPN_MemFlush;
mozilla_funcs.reloadplugins = g_NPN_ReloadPlugins;
mozilla_funcs.getJavaEnv = g_NPN_GetJavaEnv;
mozilla_funcs.getJavaPeer = g_NPN_GetJavaPeer;
mozilla_funcs.geturlnotify = g_NPN_GetURLNotify;
mozilla_funcs.posturlnotify = g_NPN_PostURLNotify;
mozilla_funcs.getvalue = g_NPN_GetValue;
mozilla_funcs.setvalue = g_NPN_SetValue;
mozilla_funcs.invalidaterect = g_NPN_InvalidateRect;
mozilla_funcs.invalidateregion = g_NPN_InvalidateRegion;
mozilla_funcs.forceredraw = g_NPN_ForceRedraw;
mozilla_funcs.pushpopupsenabledstate = g_NPN_PushPopupsEnabledState;
mozilla_funcs.poppopupsenabledstate = g_NPN_PopPopupsEnabledState;
mozilla_funcs.pluginthreadasynccall = g_NPN_PluginThreadAsyncCall;
mozilla_funcs.getvalueforurl = g_NPN_GetValueForURL;
mozilla_funcs.setvalueforurl = g_NPN_SetValueForURL;
mozilla_funcs.getauthenticationinfo = g_NPN_GetAuthenticationInfo;
mozilla_funcs.scheduletimer = g_NPN_ScheduleTimer;
mozilla_funcs.unscheduletimer = g_NPN_UnscheduleTimer;
// TODO: query for support.
#define BROWSER_FUNC(func, member) \
mozilla_funcs.member = g_ ## func;
#include "browser-funcs.h"
#undef BROWSER_FUNC
if (!npobject_bridge_new())
return NPERR_OUT_OF_MEMORY_ERROR;
if (NPN_HAS_FEATURE(NPRUNTIME_SCRIPTING)) {
D(bug(" browser supports scripting through npruntime\n"));
mozilla_funcs.getstringidentifier = g_NPN_GetStringIdentifier;
mozilla_funcs.getstringidentifiers = g_NPN_GetStringIdentifiers;
mozilla_funcs.getintidentifier = g_NPN_GetIntIdentifier;
mozilla_funcs.identifierisstring = g_NPN_IdentifierIsString;
mozilla_funcs.utf8fromidentifier = g_NPN_UTF8FromIdentifier;
mozilla_funcs.intfromidentifier = g_NPN_IntFromIdentifier;
mozilla_funcs.createobject = g_NPN_CreateObject;
mozilla_funcs.retainobject = g_NPN_RetainObject;
mozilla_funcs.releaseobject = g_NPN_ReleaseObject;
mozilla_funcs.invoke = g_NPN_Invoke;
mozilla_funcs.invokeDefault = g_NPN_InvokeDefault;
mozilla_funcs.evaluate = g_NPN_Evaluate;
mozilla_funcs.getproperty = g_NPN_GetProperty;
mozilla_funcs.setproperty = g_NPN_SetProperty;
mozilla_funcs.removeproperty = g_NPN_RemoveProperty;
mozilla_funcs.hasproperty = g_NPN_HasProperty;
mozilla_funcs.hasmethod = g_NPN_HasMethod;
mozilla_funcs.releasevariantvalue = g_NPN_ReleaseVariantValue;
mozilla_funcs.setexception = g_NPN_SetException;
mozilla_funcs.enumerate = g_NPN_Enumerate;
mozilla_funcs.construct = g_NPN_Construct;
if (!npobject_bridge_new())
return NPERR_OUT_OF_MEMORY_ERROR;
}
// Initialize function tables
@ -3662,8 +3617,7 @@ g_NP_Shutdown(void)
NPError ret = g_plugin_NP_Shutdown();
D(bugiD("NP_Shutdown done\n"));
if (NPN_HAS_FEATURE(NPRUNTIME_SCRIPTING))
npobject_bridge_destroy();
npobject_bridge_destroy();
g_is_running = false;

View File

@ -3428,69 +3428,16 @@ static NPError
invoke_NP_Initialize(uint32_t npapi_version, uint32_t *plugin_version)
{
if (PLUGIN_DIRECT_EXEC) {
NPNetscapeFuncs mozilla_funcs;
memset(&mozilla_funcs, 0, sizeof(mozilla_funcs));
mozilla_funcs.size = sizeof(mozilla_funcs);
mozilla_funcs.version = npapi_version;
mozilla_funcs.geturl = g_NPN_GetURL;
mozilla_funcs.posturl = g_NPN_PostURL;
mozilla_funcs.requestread = g_NPN_RequestRead;
mozilla_funcs.newstream = g_NPN_NewStream;
mozilla_funcs.write = g_NPN_Write;
mozilla_funcs.destroystream = g_NPN_DestroyStream;
mozilla_funcs.status = g_NPN_Status;
mozilla_funcs.uagent = g_NPN_UserAgent;
mozilla_funcs.memalloc = g_NPN_MemAlloc;
mozilla_funcs.memfree = g_NPN_MemFree;
mozilla_funcs.memflush = g_NPN_MemFlush;
mozilla_funcs.reloadplugins = g_NPN_ReloadPlugins;
mozilla_funcs.getJavaEnv = g_NPN_GetJavaEnv;
mozilla_funcs.getJavaPeer = g_NPN_GetJavaPeer;
mozilla_funcs.geturlnotify = g_NPN_GetURLNotify;
mozilla_funcs.posturlnotify = g_NPN_PostURLNotify;
mozilla_funcs.getvalue = g_NPN_GetValue;
mozilla_funcs.setvalue = g_NPN_SetValue;
mozilla_funcs.invalidaterect = g_NPN_InvalidateRect;
mozilla_funcs.invalidateregion = g_NPN_InvalidateRegion;
mozilla_funcs.forceredraw = g_NPN_ForceRedraw;
mozilla_funcs.pushpopupsenabledstate = g_NPN_PushPopupsEnabledState;
mozilla_funcs.poppopupsenabledstate = g_NPN_PopPopupsEnabledState;
mozilla_funcs.getvalueforurl = g_NPN_GetValueForURL;
mozilla_funcs.setvalueforurl = g_NPN_SetValueForURL;
mozilla_funcs.getauthenticationinfo = g_NPN_GetAuthenticationInfo;
if ((npapi_version & 0xff) >= NPVERS_HAS_NPRUNTIME_SCRIPTING) {
mozilla_funcs.getstringidentifier = g_NPN_GetStringIdentifier;
mozilla_funcs.getstringidentifiers = g_NPN_GetStringIdentifiers;
mozilla_funcs.getintidentifier = g_NPN_GetIntIdentifier;
mozilla_funcs.identifierisstring = g_NPN_IdentifierIsString;
mozilla_funcs.utf8fromidentifier = g_NPN_UTF8FromIdentifier;
mozilla_funcs.intfromidentifier = g_NPN_IntFromIdentifier;
mozilla_funcs.createobject = g_NPN_CreateObject;
mozilla_funcs.retainobject = g_NPN_RetainObject;
mozilla_funcs.releaseobject = g_NPN_ReleaseObject;
mozilla_funcs.invoke = g_NPN_Invoke;
mozilla_funcs.invokeDefault = g_NPN_InvokeDefault;
mozilla_funcs.evaluate = g_NPN_Evaluate;
mozilla_funcs.getproperty = g_NPN_GetProperty;
mozilla_funcs.setproperty = g_NPN_SetProperty;
mozilla_funcs.removeproperty = g_NPN_RemoveProperty;
mozilla_funcs.hasproperty = g_NPN_HasProperty;
mozilla_funcs.hasmethod = g_NPN_HasMethod;
mozilla_funcs.releasevariantvalue = g_NPN_ReleaseVariantValue;
mozilla_funcs.setexception = g_NPN_SetException;
mozilla_funcs.enumerate = g_NPN_Enumerate;
mozilla_funcs.construct = g_NPN_Construct;
}
if ((npapi_version & 0xff) >= NPVERS_HAS_PLUGIN_THREAD_ASYNC_CALL) {
// Avoid pretending we have support for this if we really don't.
mozilla_funcs.pluginthreadasynccall = g_NPN_PluginThreadAsyncCall;
}
if ((npapi_version & 0xff) >= NPVERS_MACOSX_HAS_COCOA_EVENTS) {
// Avoid pretending we have support for this if we really don't.
mozilla_funcs.scheduletimer = g_NPN_ScheduleTimer;
mozilla_funcs.unscheduletimer = g_NPN_UnscheduleTimer;
}
NPError error = g_plugin_NP_Initialize(&mozilla_funcs, &plugin_funcs);
NPNetscapeFuncs wrapped_mozilla_funcs;
memset(&wrapped_mozilla_funcs, 0, sizeof(wrapped_mozilla_funcs));
wrapped_mozilla_funcs.size = sizeof(wrapped_mozilla_funcs);
wrapped_mozilla_funcs.version = npapi_version;
#define BROWSER_FUNC(func, member) \
if (mozilla_funcs.member != NULL) \
wrapped_mozilla_funcs.member = g_ ## func;
#include "browser-funcs.h"
#undef BROWSER_FUNC
NPError error = g_plugin_NP_Initialize(&wrapped_mozilla_funcs, &plugin_funcs);
*plugin_version = plugin_funcs.version;
return error;
}
@ -3555,20 +3502,11 @@ NP_Initialize(NPNetscapeFuncs *moz_funcs, NPPluginFuncs *plugin_funcs)
memset(&full_plugin_funcs, 0, sizeof(full_plugin_funcs));
full_plugin_funcs.size = sizeof(NPPluginFuncs);
full_plugin_funcs.version = NPW_NPAPI_VERSION;
full_plugin_funcs.newp = g_NPP_New;
full_plugin_funcs.destroy = g_NPP_Destroy;
full_plugin_funcs.setwindow = g_NPP_SetWindow;
full_plugin_funcs.newstream = g_NPP_NewStream;
full_plugin_funcs.destroystream = g_NPP_DestroyStream;
full_plugin_funcs.asfile = g_NPP_StreamAsFile;
full_plugin_funcs.writeready = g_NPP_WriteReady;
full_plugin_funcs.write = g_NPP_Write;
full_plugin_funcs.print = g_NPP_Print;
full_plugin_funcs.event = g_NPP_HandleEvent;
full_plugin_funcs.urlnotify = g_NPP_URLNotify;
#define PLUGIN_FUNC(func, member) \
full_plugin_funcs.member = g_ ## func;
#include "plugin-funcs.h"
#undef PLUGIN_FUNC
full_plugin_funcs.javaClass = NULL;
full_plugin_funcs.getvalue = g_NPP_GetValue;
full_plugin_funcs.setvalue = g_NPP_SetValue;
// override function table with an additional thunking layer for
// possibly broken 64-bit Konqueror versions (NPAPI 0.11)

38
src/plugin-funcs.h Normal file
View File

@ -0,0 +1,38 @@
/*
* plugin-funcs.h - Plugin functions
*
* nspluginwrapper (C) 2011 David Benjamin
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
PLUGIN_FUNC(NPP_New, newp)
PLUGIN_FUNC(NPP_Destroy, destroy)
PLUGIN_FUNC(NPP_SetWindow, setwindow)
PLUGIN_FUNC(NPP_NewStream, newstream)
PLUGIN_FUNC(NPP_DestroyStream, destroystream)
PLUGIN_FUNC(NPP_StreamAsFile, asfile)
PLUGIN_FUNC(NPP_WriteReady, writeready)
PLUGIN_FUNC(NPP_Write, write)
PLUGIN_FUNC(NPP_Print, print)
PLUGIN_FUNC(NPP_HandleEvent, event)
PLUGIN_FUNC(NPP_URLNotify, urlnotify)
PLUGIN_FUNC(NPP_GetValue, getvalue)
PLUGIN_FUNC(NPP_SetValue, setvalue)
// PLUGIN_FUNC(NPP_GotFocus, gotfocus)
// PLUGIN_FUNC(NPP_LostFocus, lostfocus)
// PLUGIN_FUNC(NPP_URLRedirectNotify, urlredirectnotify)
// PLUGIN_FUNC(NPP_ClearSiteData, clearsitedata)
// PLUGIN_FUNC(NPP_GetSitesWithData, getsiteswithdata)