1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3  * License, v. 2.0. If a copy of the MPL was not distributed with this
4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 
6 #ifndef npfunctions_h_
7 #define npfunctions_h_
8 
9 #include "npapi.h"
10 #include "npruntime.h"
11 
12 typedef NPError (*NPP_NewProcPtr)(NPMIMEType pluginType, NPP instance,
13                                   uint16_t mode, int16_t argc, char* argn[],
14                                   char* argv[], NPSavedData* saved);
15 typedef NPError (*NPP_DestroyProcPtr)(NPP instance, NPSavedData** save);
16 typedef NPError (*NPP_SetWindowProcPtr)(NPP instance, NPWindow* window);
17 typedef NPError (*NPP_NewStreamProcPtr)(NPP instance, NPMIMEType type,
18                                         NPStream* stream, NPBool seekable,
19                                         uint16_t* stype);
20 typedef NPError (*NPP_DestroyStreamProcPtr)(NPP instance, NPStream* stream,
21                                             NPReason reason);
22 typedef int32_t (*NPP_WriteReadyProcPtr)(NPP instance, NPStream* stream);
23 typedef int32_t (*NPP_WriteProcPtr)(NPP instance, NPStream* stream,
24                                     int32_t offset, int32_t len, void* buffer);
25 typedef void (*NPP_StreamAsFileProcPtr)(NPP instance, NPStream* stream,
26                                         const char* fname);
27 typedef void (*NPP_PrintProcPtr)(NPP instance, NPPrint* platformPrint);
28 typedef int16_t (*NPP_HandleEventProcPtr)(NPP instance, void* event);
29 typedef void (*NPP_URLNotifyProcPtr)(NPP instance, const char* url,
30                                      NPReason reason, void* notifyData);
31 /* Any NPObjects returned to the browser via NPP_GetValue should be retained
32    by the plugin on the way out. The browser is responsible for releasing. */
33 typedef NPError (*NPP_GetValueProcPtr)(NPP instance, NPPVariable variable,
34                                        void* ret_value);
35 typedef NPError (*NPP_SetValueProcPtr)(NPP instance, NPNVariable variable,
36                                        void* value);
37 typedef NPBool (*NPP_GotFocusPtr)(NPP instance, NPFocusDirection direction);
38 typedef void (*NPP_LostFocusPtr)(NPP instance);
39 typedef void (*NPP_URLRedirectNotifyPtr)(NPP instance, const char* url,
40                                          int32_t status, void* notifyData);
41 typedef NPError (*NPP_ClearSiteDataPtr)(const char* site, uint64_t flags,
42                                         uint64_t maxAge);
43 typedef char** (*NPP_GetSitesWithDataPtr)(void);
44 typedef void (*NPP_DidCompositePtr)(NPP instance);
45 
46 typedef NPError (*NPN_GetValueProcPtr)(NPP instance, NPNVariable variable,
47                                        void* ret_value);
48 typedef NPError (*NPN_SetValueProcPtr)(NPP instance, NPPVariable variable,
49                                        void* value);
50 typedef NPError (*NPN_GetURLNotifyProcPtr)(NPP instance, const char* url,
51                                            const char* window,
52                                            void* notifyData);
53 typedef NPError (*NPN_PostURLNotifyProcPtr)(NPP instance, const char* url,
54                                             const char* window, uint32_t len,
55                                             const char* buf, NPBool file,
56                                             void* notifyData);
57 typedef NPError (*NPN_GetURLProcPtr)(NPP instance, const char* url,
58                                      const char* window);
59 typedef NPError (*NPN_PostURLProcPtr)(NPP instance, const char* url,
60                                       const char* window, uint32_t len,
61                                       const char* buf, NPBool file);
62 typedef NPError (*NPN_RequestReadProcPtr)(NPStream* stream,
63                                           NPByteRange* rangeList);
64 typedef NPError (*NPN_NewStreamProcPtr)(NPP instance, NPMIMEType type,
65                                         const char* window, NPStream** stream);
66 typedef int32_t (*NPN_WriteProcPtr)(NPP instance, NPStream* stream, int32_t len,
67                                     void* buffer);
68 typedef NPError (*NPN_DestroyStreamProcPtr)(NPP instance, NPStream* stream,
69                                             NPReason reason);
70 typedef void (*NPN_StatusProcPtr)(NPP instance, const char* message);
71 /* Browser manages the lifetime of the buffer returned by NPN_UserAgent, don't
72    depend on it sticking around and don't free it. */
73 typedef const char* (*NPN_UserAgentProcPtr)(NPP instance);
74 typedef void* (*NPN_MemAllocProcPtr)(uint32_t size);
75 typedef void (*NPN_MemFreeProcPtr)(void* ptr);
76 typedef uint32_t (*NPN_MemFlushProcPtr)(uint32_t size);
77 typedef void (*NPN_ReloadPluginsProcPtr)(NPBool reloadPages);
78 typedef void* (*NPN_GetJavaEnvProcPtr)(void);
79 typedef void* (*NPN_GetJavaPeerProcPtr)(NPP instance);
80 typedef void (*NPN_InvalidateRectProcPtr)(NPP instance, NPRect* rect);
81 typedef void (*NPN_InvalidateRegionProcPtr)(NPP instance, NPRegion region);
82 typedef void (*NPN_ForceRedrawProcPtr)(NPP instance);
83 typedef NPIdentifier (*NPN_GetStringIdentifierProcPtr)(const NPUTF8* name);
84 typedef void (*NPN_GetStringIdentifiersProcPtr)(const NPUTF8** names,
85                                                 int32_t nameCount,
86                                                 NPIdentifier* identifiers);
87 typedef NPIdentifier (*NPN_GetIntIdentifierProcPtr)(int32_t intid);
88 typedef bool (*NPN_IdentifierIsStringProcPtr)(NPIdentifier identifier);
89 typedef NPUTF8* (*NPN_UTF8FromIdentifierProcPtr)(NPIdentifier identifier);
90 typedef int32_t (*NPN_IntFromIdentifierProcPtr)(NPIdentifier identifier);
91 typedef NPObject* (*NPN_CreateObjectProcPtr)(NPP npp, NPClass* aClass);
92 typedef NPObject* (*NPN_RetainObjectProcPtr)(NPObject* obj);
93 typedef void (*NPN_ReleaseObjectProcPtr)(NPObject* obj);
94 typedef bool (*NPN_InvokeProcPtr)(NPP npp, NPObject* obj,
95                                   NPIdentifier methodName,
96                                   const NPVariant* args, uint32_t argCount,
97                                   NPVariant* result);
98 typedef bool (*NPN_InvokeDefaultProcPtr)(NPP npp, NPObject* obj,
99                                          const NPVariant* args,
100                                          uint32_t argCount, NPVariant* result);
101 typedef bool (*NPN_EvaluateProcPtr)(NPP npp, NPObject* obj, NPString* script,
102                                     NPVariant* result);
103 typedef bool (*NPN_GetPropertyProcPtr)(NPP npp, NPObject* obj,
104                                        NPIdentifier propertyName,
105                                        NPVariant* result);
106 typedef bool (*NPN_SetPropertyProcPtr)(NPP npp, NPObject* obj,
107                                        NPIdentifier propertyName,
108                                        const NPVariant* value);
109 typedef bool (*NPN_RemovePropertyProcPtr)(NPP npp, NPObject* obj,
110                                           NPIdentifier propertyName);
111 typedef bool (*NPN_HasPropertyProcPtr)(NPP npp, NPObject* obj,
112                                        NPIdentifier propertyName);
113 typedef bool (*NPN_HasMethodProcPtr)(NPP npp, NPObject* obj,
114                                      NPIdentifier propertyName);
115 typedef void (*NPN_ReleaseVariantValueProcPtr)(NPVariant* variant);
116 typedef void (*NPN_SetExceptionProcPtr)(NPObject* obj, const NPUTF8* message);
117 typedef void (*NPN_PushPopupsEnabledStateProcPtr)(NPP npp, NPBool enabled);
118 typedef void (*NPN_PopPopupsEnabledStateProcPtr)(NPP npp);
119 typedef bool (*NPN_EnumerateProcPtr)(NPP npp, NPObject* obj,
120                                      NPIdentifier** identifier,
121                                      uint32_t* count);
122 typedef void (*NPN_PluginThreadAsyncCallProcPtr)(NPP instance,
123                                                  void (*func)(void*),
124                                                  void* userData);
125 typedef bool (*NPN_ConstructProcPtr)(NPP npp, NPObject* obj,
126                                      const NPVariant* args, uint32_t argCount,
127                                      NPVariant* result);
128 typedef NPError (*NPN_GetValueForURLPtr)(NPP npp, NPNURLVariable variable,
129                                          const char* url, char** value,
130                                          uint32_t* len);
131 typedef NPError (*NPN_SetValueForURLPtr)(NPP npp, NPNURLVariable variable,
132                                          const char* url, const char* value,
133                                          uint32_t len);
134 typedef NPError (*NPN_GetAuthenticationInfoPtr)(
135     NPP npp, const char* protocol, const char* host, int32_t port,
136     const char* scheme, const char* realm, char** username, uint32_t* ulen,
137     char** password, uint32_t* plen);
138 typedef uint32_t (*NPN_ScheduleTimerPtr)(NPP instance, uint32_t interval,
139                                          NPBool repeat,
140                                          void (*timerFunc)(NPP npp,
141                                                            uint32_t timerID));
142 typedef void (*NPN_UnscheduleTimerPtr)(NPP instance, uint32_t timerID);
143 typedef NPError (*NPN_PopUpContextMenuPtr)(NPP instance, NPMenu* menu);
144 typedef NPBool (*NPN_ConvertPointPtr)(NPP instance, double sourceX,
145                                       double sourceY,
146                                       NPCoordinateSpace sourceSpace,
147                                       double* destX, double* destY,
148                                       NPCoordinateSpace destSpace);
149 typedef NPBool (*NPN_HandleEventPtr)(NPP instance, void* event, NPBool handled);
150 typedef NPBool (*NPN_UnfocusInstancePtr)(NPP instance,
151                                          NPFocusDirection direction);
152 typedef void (*NPN_URLRedirectResponsePtr)(NPP instance, void* notifyData,
153                                            NPBool allow);
154 typedef NPError (*NPN_InitAsyncSurfacePtr)(NPP instance, NPSize* size,
155                                            NPImageFormat format, void* initData,
156                                            NPAsyncSurface* surface);
157 typedef NPError (*NPN_FinalizeAsyncSurfacePtr)(NPP instance,
158                                                NPAsyncSurface* surface);
159 typedef void (*NPN_SetCurrentAsyncSurfacePtr)(NPP instance,
160                                               NPAsyncSurface* surface,
161                                               NPRect* changed);
162 
163 typedef void (*NPN_DummyPtr)(void);
164 
165 typedef struct _NPPluginFuncs {
166   uint16_t size;
167   uint16_t version;
168   NPP_NewProcPtr newp;
169   NPP_DestroyProcPtr destroy;
170   NPP_SetWindowProcPtr setwindow;
171   NPP_NewStreamProcPtr newstream;
172   NPP_DestroyStreamProcPtr destroystream;
173   NPP_StreamAsFileProcPtr asfile;
174   NPP_WriteReadyProcPtr writeready;
175   NPP_WriteProcPtr write;
176   NPP_PrintProcPtr print;
177   NPP_HandleEventProcPtr event;
178   NPP_URLNotifyProcPtr urlnotify;
179   void* javaClass;
180   NPP_GetValueProcPtr getvalue;
181   NPP_SetValueProcPtr setvalue;
182   NPP_GotFocusPtr gotfocus;
183   NPP_LostFocusPtr lostfocus;
184   NPP_URLRedirectNotifyPtr urlredirectnotify;
185   NPP_ClearSiteDataPtr clearsitedata;
186   NPP_GetSitesWithDataPtr getsiteswithdata;
187   NPP_DidCompositePtr didComposite;
188 } NPPluginFuncs;
189 
190 typedef struct _NPNetscapeFuncs {
191   uint16_t size;
192   uint16_t version;
193   NPN_GetURLProcPtr geturl;
194   NPN_PostURLProcPtr posturl;
195   NPN_RequestReadProcPtr requestread;
196   NPN_NewStreamProcPtr newstream;
197   NPN_WriteProcPtr write;
198   NPN_DestroyStreamProcPtr destroystream;
199   NPN_StatusProcPtr status;
200   NPN_UserAgentProcPtr uagent;
201   NPN_MemAllocProcPtr memalloc;
202   NPN_MemFreeProcPtr memfree;
203   NPN_MemFlushProcPtr memflush;
204   NPN_ReloadPluginsProcPtr reloadplugins;
205   NPN_GetJavaEnvProcPtr getJavaEnv;
206   NPN_GetJavaPeerProcPtr getJavaPeer;
207   NPN_GetURLNotifyProcPtr geturlnotify;
208   NPN_PostURLNotifyProcPtr posturlnotify;
209   NPN_GetValueProcPtr getvalue;
210   NPN_SetValueProcPtr setvalue;
211   NPN_InvalidateRectProcPtr invalidaterect;
212   NPN_InvalidateRegionProcPtr invalidateregion;
213   NPN_ForceRedrawProcPtr forceredraw;
214   NPN_GetStringIdentifierProcPtr getstringidentifier;
215   NPN_GetStringIdentifiersProcPtr getstringidentifiers;
216   NPN_GetIntIdentifierProcPtr getintidentifier;
217   NPN_IdentifierIsStringProcPtr identifierisstring;
218   NPN_UTF8FromIdentifierProcPtr utf8fromidentifier;
219   NPN_IntFromIdentifierProcPtr intfromidentifier;
220   NPN_CreateObjectProcPtr createobject;
221   NPN_RetainObjectProcPtr retainobject;
222   NPN_ReleaseObjectProcPtr releaseobject;
223   NPN_InvokeProcPtr invoke;
224   NPN_InvokeDefaultProcPtr invokeDefault;
225   NPN_EvaluateProcPtr evaluate;
226   NPN_GetPropertyProcPtr getproperty;
227   NPN_SetPropertyProcPtr setproperty;
228   NPN_RemovePropertyProcPtr removeproperty;
229   NPN_HasPropertyProcPtr hasproperty;
230   NPN_HasMethodProcPtr hasmethod;
231   NPN_ReleaseVariantValueProcPtr releasevariantvalue;
232   NPN_SetExceptionProcPtr setexception;
233   NPN_PushPopupsEnabledStateProcPtr pushpopupsenabledstate;
234   NPN_PopPopupsEnabledStateProcPtr poppopupsenabledstate;
235   NPN_EnumerateProcPtr enumerate;
236   NPN_PluginThreadAsyncCallProcPtr pluginthreadasynccall;
237   NPN_ConstructProcPtr construct;
238   NPN_GetValueForURLPtr getvalueforurl;
239   NPN_SetValueForURLPtr setvalueforurl;
240   NPN_GetAuthenticationInfoPtr getauthenticationinfo;
241   NPN_ScheduleTimerPtr scheduletimer;
242   NPN_UnscheduleTimerPtr unscheduletimer;
243   NPN_PopUpContextMenuPtr popupcontextmenu;
244   NPN_ConvertPointPtr convertpoint;
245   NPN_HandleEventPtr handleevent;
246   NPN_UnfocusInstancePtr unfocusinstance;
247   NPN_URLRedirectResponsePtr urlredirectresponse;
248   NPN_InitAsyncSurfacePtr initasyncsurface;
249   NPN_FinalizeAsyncSurfacePtr finalizeasyncsurface;
250   NPN_SetCurrentAsyncSurfacePtr setcurrentasyncsurface;
251 } NPNetscapeFuncs;
252 
253 #ifdef XP_MACOSX
254 /*
255  * Mac OS X version(s) of NP_GetMIMEDescription(const char *)
256  * These can be called to retreive MIME information from the plugin dynamically
257  *
258  * Note: For compatibility with Quicktime, BPSupportedMIMEtypes is another way
259  *       to get mime info from the plugin only on OSX and may not be supported
260  *       in furture version -- use NP_GetMIMEDescription instead
261  */
262 enum { kBPSupportedMIMETypesStructVers_1 = 1 };
263 typedef struct _BPSupportedMIMETypes {
264   SInt32 structVersion; /* struct version */
265   Handle typeStrings;   /* STR# formated handle, allocated by plug-in */
266   Handle infoStrings;   /* STR# formated handle, allocated by plug-in */
267 } BPSupportedMIMETypes;
268 OSErr BP_GetSupportedMIMETypes(BPSupportedMIMETypes* mimeInfo, UInt32 flags);
269 #  define NP_GETMIMEDESCRIPTION_NAME "NP_GetMIMEDescription"
270 typedef const char* (*NP_GetMIMEDescriptionProcPtr)(void);
271 typedef OSErr (*BP_GetSupportedMIMETypesProcPtr)(BPSupportedMIMETypes*, UInt32);
272 #endif
273 
274 #if defined(_WIN32)
275 #  define OSCALL WINAPI
276 #else
277 #  define OSCALL
278 #endif
279 
280 #if defined(XP_UNIX)
281 /* GCC 3.3 and later support the visibility attribute. */
282 #  if defined(__GNUC__) && \
283       ((__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3))
284 #    define NP_VISIBILITY_DEFAULT __attribute__((visibility("default")))
285 #  elif defined(__SUNPRO_C) || defined(__SUNPRO_CC)
286 #    define NP_VISIBILITY_DEFAULT __global
287 #  else
288 #    define NP_VISIBILITY_DEFAULT
289 #  endif
290 #  define NP_EXPORT(__type) NP_VISIBILITY_DEFAULT __type
291 #endif
292 
293 #if defined(_WIN32)
294 #  ifdef __cplusplus
295 extern "C" {
296 #  endif
297 /* plugin meta member functions */
298 typedef NPError(OSCALL* NP_GetEntryPointsFunc)(NPPluginFuncs*);
299 NPError OSCALL NP_GetEntryPoints(NPPluginFuncs* pFuncs);
300 typedef NPError(OSCALL* NP_InitializeFunc)(NPNetscapeFuncs*);
301 NPError OSCALL NP_Initialize(NPNetscapeFuncs* bFuncs);
302 typedef NPError(OSCALL* NP_ShutdownFunc)(void);
303 NPError OSCALL NP_Shutdown(void);
304 typedef const char* (*NP_GetMIMEDescriptionFunc)(void);
305 const char* NP_GetMIMEDescription(void);
306 #  ifdef __cplusplus
307 }
308 #  endif
309 #endif
310 
311 #ifdef XP_UNIX
312 #  ifdef __cplusplus
313 extern "C" {
314 #  endif
315 typedef char* (*NP_GetPluginVersionFunc)(void);
316 NP_EXPORT(char*) NP_GetPluginVersion(void);
317 typedef const char* (*NP_GetMIMEDescriptionFunc)(void);
318 NP_EXPORT(const char*) NP_GetMIMEDescription(void);
319 #  ifdef XP_MACOSX
320 typedef NPError (*NP_InitializeFunc)(NPNetscapeFuncs*);
321 NP_EXPORT(NPError) NP_Initialize(NPNetscapeFuncs* bFuncs);
322 typedef NPError (*NP_GetEntryPointsFunc)(NPPluginFuncs*);
323 NP_EXPORT(NPError) NP_GetEntryPoints(NPPluginFuncs* pFuncs);
324 #  else
325 typedef NPError (*NP_InitializeFunc)(NPNetscapeFuncs*, NPPluginFuncs*);
326 NP_EXPORT(NPError)
327 NP_Initialize(NPNetscapeFuncs* bFuncs, NPPluginFuncs* pFuncs);
328 #  endif
329 typedef NPError (*NP_ShutdownFunc)(void);
330 NP_EXPORT(NPError) NP_Shutdown(void);
331 typedef NPError (*NP_GetValueFunc)(void*, NPPVariable, void*);
332 NP_EXPORT(NPError)
333 NP_GetValue(void* future, NPPVariable aVariable, void* aValue);
334 #  ifdef __cplusplus
335 }
336 #  endif
337 #endif
338 
339 // clang-format off
340 // See bug 1431030
341 #if defined(XP_WIN)
342 #define NS_NPAPIPLUGIN_CALLBACK(_type, _name) _type (__stdcall * _name)
343 #else
344 #define NS_NPAPIPLUGIN_CALLBACK(_type, _name) _type (* _name)
345 #endif
346 // clang-format on
347 
348 typedef NS_NPAPIPLUGIN_CALLBACK(NPError,
349                                 NP_GETENTRYPOINTS)(NPPluginFuncs* pCallbacks);
350 typedef NS_NPAPIPLUGIN_CALLBACK(NPError, NP_PLUGININIT)(
351     const NPNetscapeFuncs* pCallbacks);
352 typedef NS_NPAPIPLUGIN_CALLBACK(NPError, NP_PLUGINUNIXINIT)(
353     const NPNetscapeFuncs* pCallbacks, NPPluginFuncs* fCallbacks);
354 typedef NS_NPAPIPLUGIN_CALLBACK(NPError, NP_PLUGINSHUTDOWN)(void);
355 
356 #endif /* npfunctions_h_ */
357