From: Braden M. <br...@us...> - 2006-10-09 03:09:06
|
Update of /cvsroot/openvrml/openvrml/mozilla-plugin/src In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv22198/mozilla-plugin/src Modified Files: Tag: OpenVRML-0_16-BRANCH Makefile.am openvrml.cpp Removed Files: Tag: OpenVRML-0_16-BRANCH openvrml.idl Log Message: Use the npruntime extensions to NPAPI to make the plug-in scriptable instead of XPCOM. --- openvrml.idl DELETED --- Index: openvrml.cpp =================================================================== RCS file: /cvsroot/openvrml/openvrml/mozilla-plugin/src/openvrml.cpp,v retrieving revision 1.37.2.2 retrieving revision 1.37.2.3 diff -C2 -d -r1.37.2.2 -r1.37.2.3 *** openvrml.cpp 1 Oct 2006 05:48:29 -0000 1.37.2.2 --- openvrml.cpp 9 Oct 2006 03:09:02 -0000 1.37.2.3 *************** *** 19,24 **** // ! # include <cerrno> ! # include <list> # include <memory> # include <sstream> --- 19,23 ---- // ! # include <map> # include <memory> # include <sstream> *************** *** 29,39 **** # include <boost/lexical_cast.hpp> # include <boost/noncopyable.hpp> # include <mozilla-config.h> # include <npupp.h> - # include <nsCOMPtr.h> - # include <nsIServiceManagerUtils.h> - # include <nsMemory.h> - # include <nsString.h> - # include <nsIConsoleService.h> # if defined MOZ_X11 # include <fcntl.h> --- 28,34 ---- # include <boost/lexical_cast.hpp> # include <boost/noncopyable.hpp> + # include <boost/scoped_ptr.hpp> # include <mozilla-config.h> # include <npupp.h> # if defined MOZ_X11 # include <fcntl.h> *************** *** 42,46 **** # error Unsupported toolkit. # endif - # include "openvrml.h" namespace { --- 37,40 ---- *************** *** 48,59 **** void printerr(const char * str); - class ScriptablePeer; - extern "C" gboolean request_data_available(GIOChannel * source, GIOCondition condition, gpointer data); ! class PluginInstance : boost::noncopyable { ! friend class ScriptablePeer; friend gboolean request_data_available(GIOChannel * source, GIOCondition condition, --- 42,71 ---- void printerr(const char * str); extern "C" gboolean request_data_available(GIOChannel * source, GIOCondition condition, gpointer data); + class plugin_instance; ! typedef bool (plugin_instance::*script_callback_t)(const NPVariant *, ! uint32_t, ! NPVariant *); ! ! // ! // Mozilla doesn't like us to use NPN_GetStringIdentifier during static ! // initialization; so this is a singleton. ! // ! class script_callback_map : public std::map<NPIdentifier, ! script_callback_t>, ! boost::noncopyable { ! static boost::scoped_ptr<const script_callback_map> instance_; ! ! script_callback_map(); ! ! public: ! static const script_callback_map & instance(); ! }; ! ! ! class plugin_instance : boost::noncopyable { friend gboolean request_data_available(GIOChannel * source, GIOCondition condition, *************** *** 68,93 **** guint request_channel_watch_id; std::stringstream request_line; - nsCOMPtr<VrmlBrowser> scriptablePeer; public: ! explicit PluginInstance(NPP npp) throw (std::bad_alloc); ! ~PluginInstance() throw (); ! ! nsISupports * GetScriptablePeer() throw (); ! void SetWindow(NPWindow & window) throw (std::bad_alloc); ! void HandleEvent(void * event) throw (); ! ssize_t WriteCommand(const std::string & command); ! }; ! class ScriptablePeer : public nsIClassInfo, public VrmlBrowser { ! PluginInstance & pluginInstance; ! public: ! explicit ScriptablePeer(PluginInstance & pluginInstance); ! ~ScriptablePeer(); ! NS_DECL_ISUPPORTS ! NS_DECL_NSICLASSINFO ! NS_DECL_VRMLBROWSER }; } // namespace --- 80,101 ---- guint request_channel_watch_id; std::stringstream request_line; public: ! NPObject * const npobj; ! explicit plugin_instance(NPP npp) throw (std::bad_alloc); ! ~plugin_instance() throw (); ! void set_window(NPWindow & window) throw (std::bad_alloc); ! void HandleEvent(void * event) throw (); ! ssize_t write_command(const std::string & command); ! // ! // Scripting API method implementations. ! // ! bool get_name(const NPVariant * args, uint32_t argCount, ! NPVariant * result); ! bool get_version(const NPVariant * args, uint32_t argCount, ! NPVariant * result); }; } // namespace *************** *** 100,104 **** namespace { NPNetscapeFuncs mozillaFuncs; - nsCOMPtr<nsIConsoleService> console_service; } --- 108,111 ---- *************** *** 151,172 **** // table could be bigger than what we expect. // ! mozillaFuncs.version = mozTable->version; ! mozillaFuncs.size = mozTable->size; ! mozillaFuncs.posturl = mozTable->posturl; ! mozillaFuncs.geturl = mozTable->geturl; ! mozillaFuncs.geturlnotify = mozTable->geturlnotify; ! mozillaFuncs.requestread = mozTable->requestread; ! mozillaFuncs.newstream = mozTable->newstream; ! mozillaFuncs.write = mozTable->write; ! mozillaFuncs.destroystream = mozTable->destroystream; ! mozillaFuncs.status = mozTable->status; ! mozillaFuncs.uagent = mozTable->uagent; ! mozillaFuncs.memalloc = mozTable->memalloc; ! mozillaFuncs.memfree = mozTable->memfree; ! mozillaFuncs.memflush = mozTable->memflush; ! mozillaFuncs.reloadplugins = mozTable->reloadplugins; ! mozillaFuncs.getJavaEnv = mozTable->getJavaEnv; ! mozillaFuncs.getJavaPeer = mozTable->getJavaPeer; ! mozillaFuncs.getvalue = mozTable->getvalue; // --- 158,198 ---- // table could be bigger than what we expect. // ! mozillaFuncs.version = mozTable->version; ! mozillaFuncs.size = mozTable->size; ! mozillaFuncs.posturl = mozTable->posturl; ! mozillaFuncs.geturl = mozTable->geturl; ! mozillaFuncs.geturlnotify = mozTable->geturlnotify; ! mozillaFuncs.requestread = mozTable->requestread; ! mozillaFuncs.newstream = mozTable->newstream; ! mozillaFuncs.write = mozTable->write; ! mozillaFuncs.destroystream = mozTable->destroystream; ! mozillaFuncs.status = mozTable->status; ! mozillaFuncs.uagent = mozTable->uagent; ! mozillaFuncs.memalloc = mozTable->memalloc; ! mozillaFuncs.memfree = mozTable->memfree; ! mozillaFuncs.memflush = mozTable->memflush; ! mozillaFuncs.reloadplugins = mozTable->reloadplugins; ! mozillaFuncs.getJavaEnv = mozTable->getJavaEnv; ! mozillaFuncs.getJavaPeer = mozTable->getJavaPeer; ! mozillaFuncs.getvalue = mozTable->getvalue; ! mozillaFuncs.getstringidentifier = mozTable->getstringidentifier; ! mozillaFuncs.getstringidentifiers = mozTable->getstringidentifiers; ! mozillaFuncs.getintidentifier = mozTable->getintidentifier; ! mozillaFuncs.identifierisstring = mozTable->identifierisstring; ! mozillaFuncs.utf8fromidentifier = mozTable->utf8fromidentifier; ! mozillaFuncs.intfromidentifier = mozTable->intfromidentifier; ! mozillaFuncs.createobject = mozTable->createobject; ! mozillaFuncs.retainobject = mozTable->retainobject; ! mozillaFuncs.releaseobject = mozTable->releaseobject; ! mozillaFuncs.invoke = mozTable->invoke; ! mozillaFuncs.invokeDefault = mozTable->invokeDefault; ! mozillaFuncs.evaluate = mozTable->evaluate; ! mozillaFuncs.getproperty = mozTable->getproperty; ! mozillaFuncs.setproperty = mozTable->setproperty; ! mozillaFuncs.removeproperty = mozTable->removeproperty; ! mozillaFuncs.hasproperty = mozTable->hasproperty; ! mozillaFuncs.hasmethod = mozTable->hasmethod; ! mozillaFuncs.releasevariantvalue = mozTable->releasevariantvalue; ! mozillaFuncs.setexception = mozTable->setexception; // *************** *** 222,229 **** # endif // defined MOZ_X11 - nsresult rv; - console_service = do_GetService(NS_CONSOLESERVICE_CONTRACTID, &rv); - if (NS_FAILED(rv)) { return NPERR_GENERIC_ERROR; } - return NPP_Initialize(); } --- 248,251 ---- *************** *** 320,324 **** try { ! instance->pdata = new PluginInstance(instance); } catch (std::bad_alloc &) { return NPERR_OUT_OF_MEMORY_ERROR; --- 342,346 ---- try { ! instance->pdata = new plugin_instance(instance); } catch (std::bad_alloc &) { return NPERR_OUT_OF_MEMORY_ERROR; *************** *** 376,380 **** */ ! delete static_cast<PluginInstance *>(instance->pdata); instance->pdata = 0; --- 398,402 ---- */ ! delete static_cast<plugin_instance *>(instance->pdata); instance->pdata = 0; *************** *** 387,392 **** try { assert(window); ! static_cast<PluginInstance *>(instance->pdata) ! ->SetWindow(*window); } catch (std::bad_alloc &) { return NPERR_OUT_OF_MEMORY_ERROR; --- 409,414 ---- try { assert(window); ! static_cast<plugin_instance *>(instance->pdata) ! ->set_window(*window); } catch (std::bad_alloc &) { return NPERR_OUT_OF_MEMORY_ERROR; *************** *** 405,415 **** assert(instance->pdata); ! PluginInstance & pluginInstance = ! *static_cast<PluginInstance *>(instance->pdata); std::ostringstream command; command << "new-stream " << ptrdiff_t(stream) << ' ' << type << ' ' << stream->url << '\n'; ! const ssize_t bytes_written = pluginInstance.WriteCommand(command.str()); return (bytes_written < 0) ? NPERR_GENERIC_ERROR --- 427,437 ---- assert(instance->pdata); ! plugin_instance & pluginInstance = ! *static_cast<plugin_instance *>(instance->pdata); std::ostringstream command; command << "new-stream " << ptrdiff_t(stream) << ' ' << type << ' ' << stream->url << '\n'; ! const ssize_t bytes_written = pluginInstance.write_command(command.str()); return (bytes_written < 0) ? NPERR_GENERIC_ERROR *************** *** 423,432 **** if (!instance || !instance->pdata) { return NPERR_INVALID_INSTANCE_ERROR; } ! PluginInstance & pluginInstance = ! *static_cast<PluginInstance *>(instance->pdata); std::ostringstream command; command << "destroy-stream " << ptrdiff_t(stream) << '\n'; ! const ssize_t bytes_written = pluginInstance.WriteCommand(command.str()); return (bytes_written < 0) ? NPERR_GENERIC_ERROR --- 445,454 ---- if (!instance || !instance->pdata) { return NPERR_INVALID_INSTANCE_ERROR; } ! plugin_instance & pluginInstance = ! *static_cast<plugin_instance *>(instance->pdata); std::ostringstream command; command << "destroy-stream " << ptrdiff_t(stream) << '\n'; ! const ssize_t bytes_written = pluginInstance.write_command(command.str()); return (bytes_written < 0) ? NPERR_GENERIC_ERROR *************** *** 466,471 **** if (!instance || !instance->pdata) { return 0; } ! PluginInstance & pluginInstance = ! *static_cast<PluginInstance *>(instance->pdata); std::ostringstream command; --- 488,493 ---- if (!instance || !instance->pdata) { return 0; } ! plugin_instance & pluginInstance = ! *static_cast<plugin_instance *>(instance->pdata); std::ostringstream command; *************** *** 475,479 **** command.put(static_cast<char *>(buffer)[i]); } ! const ssize_t bytes_written = pluginInstance.WriteCommand(command.str()); return bytes_written; // The number of bytes accepted. --- 497,501 ---- command.put(static_cast<char *>(buffer)[i]); } ! const ssize_t bytes_written = pluginInstance.write_command(command.str()); return bytes_written; // The number of bytes accepted. *************** *** 551,593 **** } ! NPError NPP_GetValue(const NPP instance, const NPPVariable variable, void * const value) { ! if (!instance) { return NPERR_INVALID_INSTANCE_ERROR; } NPError err = NPERR_NO_ERROR; ! static const nsIID scriptableIID = VRMLBROWSER_IID; ! nsISupports * scriptablePeer = 0; ! nsIID * scriptableIID_ptr = 0; ! PluginInstance * pluginInstance = 0; switch (variable) { - case NPPVpluginScriptableInstance: - assert(instance->pdata); - pluginInstance = - static_cast<PluginInstance *>(instance->pdata); - scriptablePeer = pluginInstance->GetScriptablePeer(); - assert(scriptablePeer); - // - // Add reference for the caller requesting the object. - // - NS_ADDREF(scriptablePeer); - *static_cast<nsISupports **>(value) = scriptablePeer; - break; - case NPPVpluginScriptableIID: - try { - scriptableIID_ptr = - static_cast<nsIID *>(NPN_MemAlloc(sizeof (nsIID))); - if (!scriptableIID_ptr) { throw std::bad_alloc(); } - *scriptableIID_ptr = scriptableIID; - *static_cast<nsIID **>(value) = scriptableIID_ptr; - } catch (std::bad_alloc &) { - err = NPERR_OUT_OF_MEMORY_ERROR; - } - break; case NPPVpluginNeedsXEmbed: *static_cast<PRBool *>(value) = PR_TRUE; break; default: err = NP_GetValue(instance, variable, value); --- 573,595 ---- } ! NPError NPP_GetValue(const NPP npp, const NPPVariable variable, void * const value) { ! if (!npp) { return NPERR_INVALID_INSTANCE_ERROR; } NPError err = NPERR_NO_ERROR; ! plugin_instance * instance = 0; switch (variable) { case NPPVpluginNeedsXEmbed: *static_cast<PRBool *>(value) = PR_TRUE; break; + case NPPVpluginScriptableNPObject: + assert(npp->pdata); + instance = static_cast<plugin_instance *>(npp->pdata); + NPN_RetainObject(instance->npobj); + *static_cast<NPObject **>(value) = instance->npobj; + break; default: err = NP_GetValue(instance, variable, value); *************** *** 785,992 **** } ! namespace { ! ! void printerr(const char * str) ! { ! console_service->LogStringMessage(NS_ConvertUTF8toUTF16(str).get()); ! } ! ! ScriptablePeer::ScriptablePeer(PluginInstance & pluginInstance): ! pluginInstance(pluginInstance) ! { ! NS_INIT_ISUPPORTS(); ! } ! ScriptablePeer::~ScriptablePeer() ! {} ! NS_IMPL_ISUPPORTS2(ScriptablePeer, nsIClassInfo, VrmlBrowser) ! /////////////////////////////////////////////////////////////////////////// ! // ! // nsIClassInfo implementation ! // ! NS_IMETHODIMP ScriptablePeer::GetFlags(PRUint32 * aFlags) ! { ! *aFlags = nsIClassInfo::PLUGIN_OBJECT | nsIClassInfo::DOM_OBJECT; ! return NS_OK; ! } ! NS_IMETHODIMP ! ScriptablePeer:: ! GetImplementationLanguage(PRUint32 * aImplementationLanguage) ! { ! *aImplementationLanguage = nsIProgrammingLanguage::CPLUSPLUS; ! return NS_OK; ! } ! NS_IMETHODIMP ScriptablePeer::GetInterfaces(PRUint32 * /* count */, ! nsIID *** /* array */) ! { ! return NS_ERROR_NOT_IMPLEMENTED; ! } ! NS_IMETHODIMP ScriptablePeer::GetHelperForLanguage(PRUint32 /* language */, ! nsISupports ** /* _retval */) ! { ! return NS_ERROR_NOT_IMPLEMENTED; ! } ! NS_IMETHODIMP ScriptablePeer::GetContractID(char ** /* aContractID */) ! { ! return NS_ERROR_NOT_IMPLEMENTED; ! } ! NS_IMETHODIMP ! ScriptablePeer::GetClassDescription(char ** /* aClassDescription */) ! { ! return NS_ERROR_NOT_IMPLEMENTED; ! } ! NS_IMETHODIMP ScriptablePeer::GetClassID(nsCID ** /* aClassID */) ! { ! return NS_ERROR_NOT_IMPLEMENTED; ! } ! NS_IMETHODIMP ScriptablePeer::GetClassIDNoAlloc(nsCID * /* aClassIDNoAlloc */) ! { ! return NS_ERROR_NOT_IMPLEMENTED; ! } ! /////////////////////////////////////////////////////////////////////////// ! // ! // VrmlBrowser implementation ! // ! NS_IMETHODIMP ScriptablePeer::GetName(char ** _retval) ! { ! if (!_retval) { return NS_ERROR_NULL_POINTER; } ! const std::string name; ! const size_t bufferSize = sizeof (char) * (name.length() + 1); ! *_retval = static_cast<char *>(nsMemory::Clone(name.c_str(), ! bufferSize)); ! if (!*_retval) { return NS_ERROR_OUT_OF_MEMORY; } ! return NS_OK; ! } ! NS_IMETHODIMP ScriptablePeer::GetVersion(char ** _retval) ! { ! if (!_retval) { return NS_ERROR_NULL_POINTER; } ! const std::string version; ! const size_t bufferSize = sizeof (char) * (version.length() + 1); ! *_retval = static_cast<char *>(nsMemory::Clone(version.c_str(), ! bufferSize)); ! if (!*_retval) { return NS_ERROR_OUT_OF_MEMORY; } ! return NS_OK; ! } ! NS_IMETHODIMP ScriptablePeer::GetCurrentSpeed(float * /* _retval */) { ! return NS_ERROR_NOT_IMPLEMENTED; } ! NS_IMETHODIMP ScriptablePeer::GetCurrentFrameRate(float * /* _retval */) { ! return NS_ERROR_NOT_IMPLEMENTED; } ! NS_IMETHODIMP ScriptablePeer::GetWorldURL(char ** /* _retval */) { ! return NS_ERROR_NOT_IMPLEMENTED; } - NS_IMETHODIMP ScriptablePeer::ReplaceWorld(PRUint32 /* nodeArraySize */, - VrmlNode ** /* nodeArray */) - { - return NS_ERROR_NOT_IMPLEMENTED; - } ! NS_IMETHODIMP ScriptablePeer::LoadURL(PRUint32 /* urlArraySize */, ! const char ** /* url */, ! PRUint32 /* paramArraySize */, ! const char ** /* parameter */) ! { ! return NS_ERROR_NOT_IMPLEMENTED; ! } ! NS_IMETHODIMP ScriptablePeer::SetDescription(const char * /* description */) { ! return NS_ERROR_NOT_IMPLEMENTED; ! } ! NS_IMETHODIMP ! ScriptablePeer::CreateVrmlFromString(const char * /* vrmlSyntax */, ! PRUint32 * /* nodeArraySize */, ! VrmlNode *** /* nodeArray */) ! { ! return NS_ERROR_NOT_IMPLEMENTED; ! } ! NS_IMETHODIMP ScriptablePeer::CreateVrmlFromURL(PRUint32 /* urlArraySize */, ! const char ** /* url */, ! VrmlNode * /* node */, ! const char * /* event */) ! { ! return NS_ERROR_NOT_IMPLEMENTED; } ! NS_IMETHODIMP ScriptablePeer::GetNode(const char * /* name */, ! VrmlNode ** /* _retval */) { ! return NS_ERROR_NOT_IMPLEMENTED; } ! NS_IMETHODIMP ScriptablePeer::AddRoute(VrmlNode * /* fromNode */, ! const char * /* fromEventOut */, ! VrmlNode * /* toNode */, ! const char * /* toEventIn */) { ! return NS_ERROR_NOT_IMPLEMENTED; } ! NS_IMETHODIMP ScriptablePeer::DeleteRoute(VrmlNode * /* fromNode */, ! const char * /* fromEventOut */, ! VrmlNode * /* toNode */, ! const char * /* toEvent */) { ! return NS_ERROR_NOT_IMPLEMENTED; } ! NS_IMETHODIMP ScriptablePeer::BeginUpdate() { ! return NS_ERROR_NOT_IMPLEMENTED; } ! NS_IMETHODIMP ScriptablePeer::EndUpdate() { ! return NS_ERROR_NOT_IMPLEMENTED; } ! NS_IMETHODIMP ScriptablePeer::Dispose() { ! return NS_ERROR_NOT_IMPLEMENTED; } ! NS_IMETHODIMP ! ScriptablePeer::AddBrowserListener(VrmlBrowserListener * /* listener */) { ! return NS_ERROR_NOT_IMPLEMENTED; } ! NS_IMETHODIMP ! ScriptablePeer::RemoveBrowserListener(VrmlBrowserListener * /* listener */) { ! return NS_ERROR_NOT_IMPLEMENTED; } ! PluginInstance::PluginInstance(const NPP npp) throw (std::bad_alloc): npp(npp), window(0), --- 787,1033 ---- } ! void NPN_ReleaseVariantValue(NPVariant * variant) ! { ! CallNPN_ReleaseVariantValueProc(mozillaFuncs.releasevariantvalue, variant); ! } ! NPIdentifier NPN_GetStringIdentifier(const NPUTF8 * name) ! { ! return CallNPN_GetStringIdentifierProc(mozillaFuncs.getstringidentifier, ! name); ! } ! void NPN_GetStringIdentifiers(const NPUTF8 ** names, ! int32_t nameCount, ! NPIdentifier * identifiers) ! { ! CallNPN_GetStringIdentifiersProc(mozillaFuncs.getstringidentifiers, ! names, ! nameCount, ! identifiers); ! } ! NPIdentifier NPN_GetIntIdentifier(int32_t intid) ! { ! return CallNPN_GetIntIdentifierProc(mozillaFuncs.getintidentifier, intid); ! } ! bool NPN_IdentifierIsString(NPIdentifier * identifier) ! { ! return CallNPN_IdentifierIsStringProc(mozillaFuncs.identifierisstring, ! identifier); ! } ! NPUTF8 * NPN_UTF8FromIdentifier(NPIdentifier identifier) ! { ! return CallNPN_UTF8FromIdentifierProc(mozillaFuncs.utf8fromidentifier, ! identifier); ! } ! int32_t NPN_IntFromIdentifier(NPIdentifier identifier) ! { ! return CallNPN_IntFromIdentifierProc(mozillaFuncs.intfromidentifier, ! identifier); ! } ! NPObject * NPN_CreateObject(NPP npp, NPClass * aClass) ! { ! return CallNPN_CreateObjectProc(mozillaFuncs.createobject, npp, aClass); ! } ! NPObject * NPN_RetainObject(NPObject * npobj) ! { ! return CallNPN_RetainObjectProc(mozillaFuncs.retainobject, npobj); ! } ! void NPN_ReleaseObject(NPObject * npobj) ! { ! CallNPN_ReleaseObjectProc(mozillaFuncs.releaseobject, npobj); ! } ! bool NPN_Invoke(NPP npp, NPObject * npobj, NPIdentifier methodName, ! const NPVariant * args, uint32_t argCount, NPVariant * result) ! { ! return CallNPN_InvokeProc(mozillaFuncs.invoke, ! npp, npobj, methodName, args, argCount, result); ! } ! bool NPN_InvokeDefault(NPP npp, NPObject * npobj, const NPVariant * args, ! uint32_t argCount, NPVariant * result) ! { ! return CallNPN_InvokeDefaultProc(mozillaFuncs.invokeDefault, ! npp, npobj, args, argCount, result); ! } ! bool NPN_Evaluate(NPP npp, NPObject * npobj, NPString * script, ! NPVariant * result) ! { ! return CallNPN_EvaluateProc(mozillaFuncs.evaluate, npp, npobj, script, ! result); ! } ! bool NPN_GetProperty(NPP npp, NPObject * npobj, NPIdentifier propertyName, ! NPVariant * result) ! { ! return CallNPN_GetPropertyProc(mozillaFuncs.getproperty, ! npp, npobj, propertyName, result); ! } ! bool NPN_SetProperty(NPP npp, NPObject * npobj, NPIdentifier propertyName, ! const NPVariant * result) ! { ! return CallNPN_SetPropertyProc(mozillaFuncs.setproperty, ! npp, npobj, propertyName, result); ! } ! bool NPN_RemoveProperty(NPP npp, NPObject * npobj, NPIdentifier propertyName) ! { ! return CallNPN_RemovePropertyProc(mozillaFuncs.removeproperty, ! npp, npobj, propertyName); ! } ! bool NPN_HasProperty(NPP npp, NPObject * npobj, NPIdentifier propertyName) ! { ! return CallNPN_HasPropertyProc(mozillaFuncs.hasproperty, ! npp, npobj, propertyName); ! } ! bool NPN_HasMethod(NPP npp, NPObject * npobj, NPIdentifier methodName) ! { ! return CallNPN_HasMethodProc(mozillaFuncs.hasmethod, ! npp, npobj, methodName); ! } ! void NPN_SetException(NPObject * npobj, const NPUTF8 * message) ! { ! return CallNPN_SetExceptionProc(mozillaFuncs.setexception, npobj, message); ! } ! namespace { ! boost::scoped_ptr<const script_callback_map> script_callback_map::instance_; ! script_callback_map::script_callback_map() { ! using std::make_pair; ! this->insert(make_pair(NPN_GetStringIdentifier("getName"), ! &plugin_instance::get_name)); ! this->insert(make_pair(NPN_GetStringIdentifier("getVersion"), ! &plugin_instance::get_version)); } ! const script_callback_map & script_callback_map::instance() { ! if (!script_callback_map::instance_) { ! script_callback_map::instance_.reset(new script_callback_map); ! } ! return *script_callback_map::instance_; } ! void printerr(const char * str) { ! fprintf(stderr, "%s\n", str); } ! struct OpenVRMLNPObject { ! NPObject npobj; ! NPP npp; ! }; ! NPObject * openvrmlnpobject_allocate(NPP npp, NPClass *) { ! OpenVRMLNPObject * const npobj = ! static_cast<OpenVRMLNPObject *>( ! NPN_MemAlloc(sizeof (OpenVRMLNPObject))); ! npobj->npp = npp; ! return static_cast<NPObject *>(static_cast<void *>(npobj)); } ! void openvrmlnpobject_deallocate(NPObject * const npobj) { ! NPN_MemFree(npobj); } ! void openvrmlnpobject_invalidate(NPObject * /* npobj */) ! {} ! ! bool openvrmlnpobject_hasMethod(NPObject *, const NPIdentifier name) { ! const script_callback_map::const_iterator pos = ! script_callback_map::instance().find(name); ! return pos != script_callback_map::instance().end(); } ! bool openvrmlnpobject_invoke(NPObject * const npobj, ! const NPIdentifier name, ! const NPVariant * const args, ! const uint32_t argCount, ! NPVariant * const result) { ! const script_callback_map::const_iterator pos = ! script_callback_map::instance().find(name); ! assert(pos != script_callback_map::instance().end()); ! ! OpenVRMLNPObject * const openvrml_npobj = ! static_cast<OpenVRMLNPObject *>(static_cast<void *>(npobj)); ! ! plugin_instance * const instance = ! static_cast<plugin_instance *>(openvrml_npobj->npp->pdata); ! ! return (instance->*(pos->second))(args, argCount, result); } ! bool openvrmlnpobject_invokeDefault(NPObject * /* npobj */, ! const NPVariant * /* args */, ! uint32_t /* argCount */, ! NPVariant * /* result */) { ! return false; } ! bool openvrmlnpobject_hasProperty(NPObject * /* npobj */, ! NPIdentifier /* name */) { ! return false; } ! bool openvrmlnpobject_getProperty(NPObject * /* npobj */, ! NPIdentifier /* name */, ! NPVariant * /* result */) { ! return false; } ! bool openvrmlnpobject_setProperty(NPObject * /* npobj */, ! NPIdentifier /* name */, ! const NPVariant * /* value */) { ! return false; } ! bool openvrmlnpobject_removeProperty(NPObject * /* npobj */, ! NPIdentifier /* name */) { ! return false; } + NPClass npclass = { + NP_CLASS_STRUCT_VERSION, + openvrmlnpobject_allocate, + openvrmlnpobject_deallocate, + openvrmlnpobject_invalidate, + openvrmlnpobject_hasMethod, + openvrmlnpobject_invoke, + openvrmlnpobject_invokeDefault, + openvrmlnpobject_hasProperty, + openvrmlnpobject_getProperty, + openvrmlnpobject_setProperty, + openvrmlnpobject_removeProperty + }; ! plugin_instance::plugin_instance(const NPP npp) throw (std::bad_alloc): npp(npp), window(0), *************** *** 998,1005 **** request_channel(0), request_channel_watch_id(0), ! scriptablePeer(new ScriptablePeer(*this)) ! {} ! PluginInstance::~PluginInstance() throw () { if (this->request_channel_watch_id) { --- 1039,1048 ---- request_channel(0), request_channel_watch_id(0), ! npobj(NPN_CreateObject(this->npp, &npclass)) ! { ! if (!this->npobj) { throw std::bad_alloc(); } ! } ! plugin_instance::~plugin_instance() throw () { if (this->request_channel_watch_id) { *************** *** 1040,1051 **** g_io_channel_unref(this->command_channel); } - } ! nsISupports * PluginInstance::GetScriptablePeer() throw () ! { ! return this->scriptablePeer; } ! void PluginInstance::SetWindow(NPWindow & window) throw (std::bad_alloc) { --- 1083,1091 ---- g_io_channel_unref(this->command_channel); } ! NPN_ReleaseObject(this->npobj); } ! void plugin_instance::set_window(NPWindow & window) throw (std::bad_alloc) { *************** *** 1176,1183 **** } ! void PluginInstance::HandleEvent(void *) throw () {} ! ssize_t PluginInstance::WriteCommand(const std::string & command) { if (!this->command_channel) { return 0; } --- 1216,1223 ---- } ! void plugin_instance::HandleEvent(void *) throw () {} ! ssize_t plugin_instance::write_command(const std::string & command) { if (!this->command_channel) { return 0; } *************** *** 1213,1216 **** --- 1253,1280 ---- } + bool plugin_instance::get_name(const NPVariant * const args, + const uint32_t argCount, + NPVariant * const result) + { + static const std::string name = PACKAGE_NAME; + NPUTF8 * const name_str = + static_cast<NPUTF8 *>(NPN_MemAlloc(sizeof (NPUTF8) * name.length())); + std::copy(name.begin(), name.end(), name_str); + STRINGN_TO_NPVARIANT(name_str, name.length(), *result); + return true; + } + + bool plugin_instance::get_version(const NPVariant * const args, + const uint32_t argCount, + NPVariant * const result) + { + static const std::string ver = PACKAGE_VERSION; + NPUTF8 * const ver_str = + static_cast<NPUTF8 *>(NPN_MemAlloc(sizeof (NPUTF8) * ver.length())); + std::copy(ver.begin(), ver.end(), ver_str); + STRINGN_TO_NPVARIANT(ver_str, ver.length(), *result); + return true; + } + gboolean request_data_available(GIOChannel * const source, GIOCondition, *************** *** 1219,1223 **** using std::string; ! PluginInstance & pluginInstance = *static_cast<PluginInstance *>(data); gchar c; --- 1283,1287 ---- using std::string; ! plugin_instance & pluginInstance = *static_cast<plugin_instance *>(data); gchar c; *************** *** 1257,1262 **** command << "get-url-result " << url << ' ' << result << '\n'; const ssize_t bytes_written = ! pluginInstance.WriteCommand(command.str()); ! if (bytes_written != command.str().length()) { // XXX // XXX Do what here? Console message? --- 1321,1326 ---- command << "get-url-result " << url << ' ' << result << '\n'; const ssize_t bytes_written = ! pluginInstance.write_command(command.str()); ! if (bytes_written != ssize_t(command.str().length())) { // XXX // XXX Do what here? Console message? Index: Makefile.am =================================================================== RCS file: /cvsroot/openvrml/openvrml/mozilla-plugin/src/Makefile.am,v retrieving revision 1.13.2.1 retrieving revision 1.13.2.2 diff -C2 -d -r1.13.2.1 -r1.13.2.2 *** Makefile.am 1 Oct 2006 05:48:29 -0000 1.13.2.1 --- Makefile.am 9 Oct 2006 03:09:02 -0000 1.13.2.2 *************** *** 5,17 **** AM_CXXFLAGS = @MOZILLA_PLUGIN_CFLAGS@ @GTK_CFLAGS@ - idldir = $(datadir)/idl/openvrml-@PACKAGE_VERSION@ - mozpluginsdir = $(libdir)/mozilla/plugins if ENABLE_MOZILLA_PLUGIN mozplugins_LTLIBRARIES = openvrml.la - mozplugins_DATA = openvrml.xpt endif - dist_idl_DATA = openvrml.idl openvrml_la_SOURCES = openvrml.cpp --- 5,13 ---- *************** *** 22,33 **** EXTRA_DIST = $(openvrml_la_SOURCES) - - BUILT_SOURCES = openvrml.h - - CLEANFILES = openvrml.h openvrml.xpt - - .idl.h: - $(XPIDL) $(XPIDLFLAGS) @MOZILLA_XPIDLFLAGS@ -m header $< - - .idl.xpt: - $(XPIDL) $(XPIDLFLAGS) @MOZILLA_XPIDLFLAGS@ -m typelib $< --- 18,19 ---- |