code_junkie

How can I associate a scriptable Mozilla plugin instance with its NObject?

Nov 11th, 2011
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. static NPClass refObject = {
  2. NP_CLASS_STRUCT_VERSION,
  3. My_Allocate,
  4. My_Deallocate,
  5. NULL,
  6. My_HasMethod,
  7. My_Invoke,
  8. My_InvokeDefault,
  9. My_HasProperty,
  10. My_GetProperty,
  11. NULL,
  12. NULL,
  13. };
  14.  
  15. class MyImplClass {
  16. // Implementation goes here
  17. };
  18.  
  19. struct MyNPObject : public NPObject {
  20. MyImplClass *my_impl_instance;
  21. };
  22.  
  23. // This is just a bit of memory management - Mozilla wants us to allocate our own memory:
  24. NPObject *My_Allocate(NPP inst, NPClass *)
  25. {
  26. // We initialize the structure in NPP_New() below
  27. return (NPObject *)malloc(sizeof(MyNPObject));
  28. }
  29.  
  30. NPError NPP_New( NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc,
  31. char* argn[], char* argv[], NPSavedData* saved )
  32. {
  33. NPObject *scriptable_object = npnfuncs->createobject(instance, &refObject);
  34. npnfuncs->retainobject(scriptable_object);
  35. MyImplClass *new_player = new MyImplClass();
  36.  
  37. instance->pdata = scriptable_object;
  38. ((MyNPObject*)instance->pdata)->my_impl_instance = new_player;
  39. return NPERR_NO_ERROR;
Add Comment
Please, Sign In to add comment