FireBreath  1.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Pages
NpapiPluginModule.h
1 /**********************************************************\
2 Original Authors: Richard Bateman (taxilian)
3 Don Jordan (kc7zax)
4 
5 Created: Oct 15, 2009
6 License: Dual license model; choose one of two:
7  New BSD License
8  http://www.opensource.org/licenses/bsd-license.php
9  - or -
10  GNU Lesser General Public License, version 2.1
11  http://www.gnu.org/licenses/lgpl-2.1.html
12 
13 Copyright 2009 Richard Bateman, Firebreath development team
14 \**********************************************************/
15 
16 #pragma once
17 #ifndef H_NPAPIPLUGINMODULE
18 #define H_NPAPIPLUGINMODULE
19 
20 #include "APITypes.h"
21 #include "NpapiTypes.h"
22 #include "FactoryBase.h"
23 #include <boost/thread.hpp>
24 #include <boost/noncopyable.hpp>
25 
26 namespace FB {
27  namespace Npapi {
28  FB_FORWARD_PTR(NpapiPlugin);
29  // Get instance of NpapiPlugin from an NPP instance
30  NpapiPluginPtr getPlugin(NPP instance);
31 
32  class NpapiPluginModule : boost::noncopyable
33  {
34  public:
35  NpapiPluginModule();
36  virtual ~NpapiPluginModule();
37 
38  typedef std::map<const void*,NpapiPluginModule*> Modules;
39  static NpapiPluginModule* GetModule(const void* key);
40  static void ReleaseModule(const void*);
41 
42 
43  void setNetscapeFuncs(NPNetscapeFuncs *npnFuncs);
44  void getPluginFuncs(NPPluginFuncs* pFuncs);
45 
46  NPNetscapeFuncs NPNFuncs;
47 
48  protected:
49  boost::thread::id m_threadId;
50  static volatile uint32_t PluginModuleInitialized;
51  static Modules m_modules;
52 
53 
54  public:
55  void assertMainThread();
56 
57  public:
58  // These are the NPN_ functions that don't require a NPP
59  void Version(int* plugin_major, int* plugin_minor, int* netscape_major,
60  int* netscape_minor);
61  void* MemAlloc(uint32_t size);
62  void MemFree(void* ptr);
63  uint32_t MemFlush(uint32_t size);
64  void ReloadPlugins(NPBool reloadPages);
65  void ReleaseVariantValue(NPVariant *variant);
66  NPIdentifier GetStringIdentifier(const NPUTF8 *name);
67  void GetStringIdentifiers(const NPUTF8 **names, int32_t nameCount,
68  NPIdentifier *identifiers);
69  NPIdentifier GetIntIdentifier(int32_t intid);
70  bool IdentifierIsString(NPIdentifier identifier);
71  NPUTF8 *UTF8FromIdentifier(NPIdentifier identifier);
72  std::string StringFromIdentifier(NPIdentifier identifier);
73  int32_t IntFromIdentifier(NPIdentifier identifier);
74  NPObject *RetainObject(NPObject *npobj);
75  void ReleaseObject(NPObject *npobj);
76 
77 #ifdef FB_MACOSX
78  // This is used on Mac OS X when we don't have pluginthreadasynccall
79  static void scheduleAsyncCallback(NPP npp, void (*func)(void *), void *userData);
80 #endif
81  public:
82  // These are the static NPP_ functions; NPP_New and NPP_Destroy create and destroy the
83  // plugin, the rest are wrappers that dereference NPP->pdata to get at the plugin object
84  // and proxy the call to there.
85  static NPError NPP_New(NPMIMEType pluginType, NPP instance, uint16_t mode, int16_t argc,
86  char* argn[], char* argv[], NPSavedData* saved);
87  static NPError NPP_Destroy(NPP instance, NPSavedData** save);
88  static NPError NPP_SetWindow(NPP instance, NPWindow* window);
89  static NPError NPP_NewStream(NPP instance, NPMIMEType type, NPStream* stream,
90  NPBool seekable, uint16_t* stype);
91  static NPError NPP_DestroyStream(NPP instance, NPStream* stream, NPReason reason);
92  static int32_t NPP_WriteReady(NPP instance, NPStream* stream);
93  static int32_t NPP_Write(NPP instance, NPStream* stream, int32_t offset, int32_t len,
94  void* buffer);
95  static void NPP_StreamAsFile(NPP instance, NPStream* stream, const char* fname);
96  static void NPP_Print(NPP instance, NPPrint* platformPrint);
97  static int16_t NPP_HandleEvent(NPP instance, void* event);
98  static void NPP_URLNotify(NPP instance, const char* url, NPReason reason,
99  void* notifyData);
100  static NPError NPP_GetValue(NPP instance, NPPVariable variable, void *ret_alue);
101  static NPError NPP_SetValue(NPP instance, NPNVariable variable, void *ret_alue);
102  };
103  };
104 };
105 
106 #endif
107