npnimpl.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /****************************************************************************
  2. **
  3. ** Copyright (C) 2009 Girish Ramakrishnan (girish@forwardbias.in)
  4. ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
  5. **
  6. ** Use, modification and distribution is allowed without limitation,
  7. ** warranty, liability or support of any kind.
  8. **
  9. ****************************************************************************/
  10. #ifndef NPNIMPL_H
  11. #define NPNIMPL_H
  12. #include <npapi.h>
  13. #include "npfunctions.h"
  14. #include <stdint.h>
  15. class Instance;
  16. class Plugin
  17. {
  18. public:
  19. Plugin(const QString &name);
  20. bool load();
  21. bool unload();
  22. bool initialize();
  23. NPPluginFuncs *funcs() { return &m_funcs; }
  24. Instance *newInstance(const char *url, const char *mimeType, const char *keys[], const char *values[], int count);
  25. bool destroyInstance(Instance *instance);
  26. typedef NPError (*_NP_InitializePtr)(NPNetscapeFuncs* nsTable, NPPluginFuncs* pluginFuncs);
  27. typedef NPError (*_NP_ShutdownPtr)();
  28. typedef char *(*_NP_GetMIMEDescriptionPtr)(void);
  29. typedef NPError (*_NP_GetValuePtr)(void* future, NPPVariable variable, void *value);
  30. _NP_InitializePtr NP_InitializePtr;
  31. _NP_ShutdownPtr NP_ShutdownPtr;
  32. _NP_GetMIMEDescriptionPtr NP_GetMIMEDescriptionPtr;
  33. _NP_GetValuePtr NP_GetValuePtr;
  34. private:
  35. static NPError NPN_GetValueImpl(NPP instance, NPNVariable variable, void *r_value);
  36. static NPError NPN_SetValueImpl(NPP instance, NPPVariable variable, void *value);
  37. static void *NPN_MemAllocImpl(uint32_t size);
  38. static void NPN_MemFreeImpl(void* ptr);
  39. static void NPN_InvalidateRectImpl(NPP instance, NPRect *invalidRect);
  40. static void NPN_InvalidateRegionImpl(NPP instance, NPRegion invalidRegion);
  41. static void NPN_ForceRedrawImpl(NPP instance);
  42. static NPError NPN_GetURLImpl(NPP instance, const char* url, const char* target);
  43. static NPError NPN_GetURLNotifyImpl(NPP instance, const char* url, const char* target, void *notifyData);
  44. static NPError NPN_PostURLImpl(NPP instance, const char *url, const char *target, uint32_t len, const char *buf, NPBool file);
  45. static NPError NPN_NewStreamImpl(NPP instance, NPMIMEType type, const char* target, NPStream** stream);
  46. static int32_t NPN_WriteImpl(NPP instance, NPStream* stream, int32_t len, void *buf);
  47. static NPError NPN_RequestReadImpl(NPStream *stream, NPByteRange* rangeList);
  48. static NPError NPN_DestroyStreamImpl(NPP instance, NPStream* stream, NPError reason);
  49. static void NPN_StatusImpl(NPP instance, const char* message);
  50. static const char* NPN_UserAgentImpl(NPP instance);
  51. NPPluginFuncs m_funcs;
  52. QString m_name;
  53. };
  54. class QWidget;
  55. class Instance
  56. {
  57. friend class Plugin;
  58. public:
  59. NPP npInstance();
  60. void printInfo();
  61. QWidget *container();
  62. void setWindow(QWidget *window);
  63. QWidget *window() const { return m_window; }
  64. char *mimeType() const { return m_mimeType; }
  65. char *url() const { return m_url; }
  66. bool isWindowless() const { return m_windowless; }
  67. bool isTransparent() const { return m_transparent; }
  68. bool isLocalRendering() const { return m_localRendering; }
  69. Plugin *plugin() const { return m_plugin; }
  70. private:
  71. Instance(Plugin *plugin, const char *url, const char *mimeType);
  72. ~Instance();
  73. bool m_windowless;
  74. bool m_transparent;
  75. QWidget *m_container;
  76. QWidget *m_window;
  77. char *m_url;
  78. char *m_mimeType;
  79. NPP_t m_npInstance;
  80. Plugin *m_plugin;
  81. bool m_localRendering;
  82. };
  83. #endif // NPNIMPL_H