#include "npfrmwkbase.h"
//
// npapi plugin functions
//
NPNetscapeFuncs* nsPluginInstanceBase::NPNFuncs = NULL;
#ifdef XP_UNIX
NP_EXPORT(char*) NP_GetPluginVersion()
{
return nsPluginInstanceBase::GetPluginVersion();
}
#endif
#if defined(XP_UNIX)
NP_EXPORT(const char*) NP_GetMIMEDescription()
#elif defined(XP_WIN) || defined(XP_OS2)
const char* NP_GetMIMEDescription()
#endif
{
return nsPluginInstanceBase::GetMIMEDescription();
}
#ifdef XP_UNIX
NP_EXPORT(NPError) NP_GetValue(void* future, NPPVariable aVariable, void* aValue) {
return nsPluginInstanceBase::GetValue(aVariable,aValue);
}
#endif
static NPError fillPluginFunctionTable(NPPluginFuncs* aNPPFuncs)
{
if (!aNPPFuncs)
return NPERR_INVALID_FUNCTABLE_ERROR;
// Set up the plugin function table that Netscape will use to call us.
aNPPFuncs->version = (NP_VERSION_MAJOR << 8) | NP_VERSION_MINOR;
aNPPFuncs->newp = NPP_New;
aNPPFuncs->destroy = NPP_Destroy;
aNPPFuncs->setwindow = NPP_SetWindow;
aNPPFuncs->newstream = NPP_NewStream;
aNPPFuncs->destroystream = NPP_DestroyStream;
aNPPFuncs->asfile = NPP_StreamAsFile;
aNPPFuncs->writeready = NPP_WriteReady;
aNPPFuncs->write = NPP_Write;
aNPPFuncs->print = NPP_Print;
aNPPFuncs->event = NPP_HandleEvent;
aNPPFuncs->urlnotify = NPP_URLNotify;
aNPPFuncs->getvalue = NPP_GetValue;
aNPPFuncs->setvalue = NPP_SetValue;
return NPERR_NO_ERROR;
}
#if defined(XP_MACOSX)
NP_EXPORT(NPError) NP_Initialize(NPNetscapeFuncs* aNPNFuncs)
#elif defined(XP_WIN) || defined(XP_OS2)
NPError OSCALL NP_Initialize(NPNetscapeFuncs* aNPNFuncs)
#elif defined(XP_UNIX)
NP_EXPORT(NPError) NP_Initialize(NPNetscapeFuncs* aNPNFuncs, NPPluginFuncs* pFuncs)
#endif
{
nsPluginInstanceBase::NPNFuncs = aNPNFuncs;
#if defined(XP_UNIX) && !defined(XP_MACOSX)
if (!fillPluginFunctionTable(pFuncs)) {
return NPERR_INVALID_FUNCTABLE_ERROR;
}
#endif
return nsPluginInstanceBase::PluginInitialize();
}
#if defined(XP_MACOSX)
NP_EXPORT(NPError) NP_GetEntryPoints(NPPluginFuncs* pFuncs)
#elif defined(XP_WIN) || defined(XP_OS2)
NPError OSCALL NP_GetEntryPoints(NPPluginFuncs* pFuncs)
#endif
#if defined(XP_MACOSX) || defined(XP_WIN) || defined(XP_OS2)
{
return fillPluginFunctionTable(pFuncs);
}
#endif
#if defined(XP_UNIX)
NP_EXPORT(NPError) NP_Shutdown()
#elif defined(XP_WIN) || defined(XP_OS2)
NPError OSCALL NP_Shutdown()
#endif
{
nsPluginInstanceBase::PluginShutdown();
return NPERR_NO_ERROR;
}
//npp_functions
#ifdef XP_UNIX
char* NPP_GetMIMEDescription(void)
{
return NS_GetMIMEDescription();
}
#endif
NPError NPP_New(NPMIMEType pluginType, NPP instance, uint16_t mode, int16_t argc, char* argn[], char* argv[], NPSavedData* saved)
{
if (!instance)
return NPERR_INVALID_INSTANCE_ERROR;
// create a new plugin instance object
// initialization will be done when the associated window is ready
nsPluginCreateData ds;
ds.instance = instance;
ds.type = pluginType;
ds.mode = mode;
ds.argc = argc;
ds.argn = argn;
ds.argv = argv;
ds.saved = saved;
nsPluginInstanceBase * plugin = nsPluginInstanceBase::NewPluginInstance(&ds);
if (!plugin)
return NPERR_OUT_OF_MEMORY_ERROR;
// associate the plugin instance object with NPP instance
instance->pdata = (void *)plugin;
return NPERR_NO_ERROR;
}
NPError NPP_Destroy (NPP instance, NPSavedData** save)
{
if (!instance)
return NPERR_INVALID_INSTANCE_ERROR;
nsPluginInstanceBase * plugin = (nsPluginInstanceBase *)instance->pdata;
if (plugin) {
plugin->shut();
nsPluginInstanceBase::DestroyPluginInstance(plugin);
}
return NPERR_NO_ERROR;
}
NPError NPP_SetWindow (NPP instance, NPWindow* pNPWindow)
{
if (!instance)
return NPERR_INVALID_INSTANCE_ERROR;
if (!pNPWindow)
return NPERR_GENERIC_ERROR;
nsPluginInstanceBase * plugin = (nsPluginInstanceBase *)instance->pdata;
if (!plugin)
return NPERR_GENERIC_ERROR;
// window just created
if (!plugin->isInitialized() && pNPWindow->window) {
if (!plugin->init(pNPWindow)) {
nsPluginInstanceBase::DestroyPluginInstance(plugin);
return NPERR_MODULE_LOAD_FAILED_ERROR;
}
}
// window goes away
if (!pNPWindow->window && plugin->isInitialized())
return plugin->SetWindow(pNPWindow);
// window resized?
if (plugin->isInitialized() && pNPWindow->window)
return plugin->SetWindow(pNPWindow);
// this should not happen, nothing to do
if (!pNPWindow->window && !plugin->isInitialized())
return plugin->SetWindow(pNPWindow);
return NPERR_NO_ERROR;
}
NPError NPP_NewStream(NPP instance, NPMIMEType type, NPStream* stream, NPBool seekable, uint16_t* stype)
{
if (!instance)
return NPERR_INVALID_INSTANCE_ERROR;
nsPluginInstanceBase * plugin = (nsPluginInstanceBase *)instance->pdata;
if (!plugin)
return NPERR_GENERIC_ERROR;
return plugin->NewStream(type, stream, seekable, stype);
}
int32_t NPP_WriteReady (NPP instance, NPStream *stream)
{
if (!instance)
return 0x0fffffff;
nsPluginInstanceBase * plugin = (nsPluginInstanceBase *)instance->pdata;
if (!plugin)
return 0x0fffffff;
return plugin->WriteReady(stream);
}
int32_t NPP_Write (NPP instance, NPStream *stream, int32_t offset, int32_t len, void *buffer)
{
if (!instance)
return len;
nsPluginInstanceBase * plugin = (nsPluginInstanceBase *)instance->pdata;
if (!plugin)
return len;
return plugin->Write(stream, offset, len, buffer);
}
NPError NPP_DestroyStream (NPP instance, NPStream *stream, NPError reason)
{
if (!instance)
return NPERR_INVALID_INSTANCE_ERROR;
nsPluginInstanceBase * plugin = (nsPluginInstanceBase *)instance->pdata;
if (!plugin)
return NPERR_GENERIC_ERROR;
return plugin->DestroyStream(stream, reason);
}
void NPP_StreamAsFile (NPP instance, NPStream* stream, const char* fname)
{
if (!instance)
return;
nsPluginInstanceBase * plugin = (nsPluginInstanceBase *)instance->pdata;
if (!plugin)
return;
plugin->StreamAsFile(stream, fname);
}
void NPP_Print (NPP instance, NPPrint* printInfo)
{
if (!instance)
return;
nsPluginInstanceBase * plugin = (nsPluginInstanceBase *)instance->pdata;
if (!plugin)
return;
plugin->Print(printInfo);
}
void NPP_URLNotify(NPP instance, const char* url, NPReason reason, void* notifyData)
{
if (!instance)
return;
nsPluginInstanceBase * plugin = (nsPluginInstanceBase *)instance->pdata;
if (!plugin)
return;
plugin->URLNotify(url, reason, notifyData);
}
NPError NPP_SetValue(NPP instance, NPNVariable variable, void *value)
{
if (!instance)
return NPERR_INVALID_INSTANCE_ERROR;
nsPluginInstanceBase * plugin = (nsPluginInstanceBase *)instance->pdata;
if (!plugin)
return NPERR_GENERIC_ERROR;
return plugin->SetValue(variable, value);
}
int16_t NPP_HandleEvent(NPP instance, void* event)
{
if (!instance)
return 0;
nsPluginInstanceBase * plugin = (nsPluginInstanceBase *)instance->pdata;
if (!plugin)
return 0;
return plugin->HandleEvent(event);
}
NPError NPP_GetValue(NPP instance, NPPVariable variable, void *value)
{
if(instance == NULL)
return NPERR_INVALID_INSTANCE_ERROR;
NPError rv = NPERR_NO_ERROR;
nsPluginInstanceBase* plugin = (nsPluginInstanceBase*)instance->pdata;
if(plugin == NULL)
return NPERR_GENERIC_ERROR;
if (variable==NPPVpluginScriptableNPObject)
{
*(NPObject **)value = plugin->GetScriptableObject();
}
else rv=plugin->GetValue(variable,value);
return rv;
}
//npn_functions
bool NPN_SetProperty(NPP instance, NPObject* obj, NPIdentifier propertyName, const NPVariant* value)
{
return nsPluginInstanceBase::NPNFuncs->setproperty(instance, obj, propertyName, value);
}
NPIdentifier NPN_GetIntIdentifier(int32_t intid)
{
return nsPluginInstanceBase::NPNFuncs->getintidentifier(intid);
}
NPIdentifier NPN_GetStringIdentifier(const NPUTF8* name)
{
return nsPluginInstanceBase::NPNFuncs->getstringidentifier(name);
}
void NPN_GetStringIdentifiers(const NPUTF8 **names, int32_t nameCount, NPIdentifier *identifiers)
{
return nsPluginIn
- 1
- 2
- 3
前往页