1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
3 //
4 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
5 // Free Software Foundation, Inc
6 //
7 // This program is free software; you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by
9 // the Free Software Foundation; either version 3 of the License, or
10 // (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 //
21
22 ////////////////////////////////////////////////////////////
23 //
24 // Implementation of Netscape entry points (NPN_*)
25 //
26 #include "plugin.h"
27
28 #if NPAPI_VERSION == 190
29 #include "npupp.h"
30 #else
31 #include "npapi.h"
32 #include "npfunctions.h"
33 #endif
34
35 #include "GnashNPVariant.h"
36
37 #ifndef HIBYTE
38 #define HIBYTE(x) ((((uint32_t)(x)) & 0xff00) >> 8)
39 #endif
40
41 #ifndef LOBYTE
42 #define LOBYTE(W) ((W) & 0xFF)
43 #endif
44
45 extern NPNetscapeFuncs NPNFuncs;
46
47 void
NPN_Version(int * plugin_major,int * plugin_minor,int * netscape_major,int * netscape_minor)48 NPN_Version(int* plugin_major, int* plugin_minor,
49 int* netscape_major, int* netscape_minor)
50 {
51 *plugin_major = NP_VERSION_MAJOR;
52 *plugin_minor = NP_VERSION_MINOR;
53 *netscape_major = HIBYTE(NPNFuncs.version);
54 *netscape_minor = LOBYTE(NPNFuncs.version);
55 }
56
57 NPError
NPN_GetURLNotify(NPP instance,const char * url,const char * target,void * notifyData)58 NPN_GetURLNotify(NPP instance, const char *url, const char *target,
59 void* notifyData)
60 {
61 int navMinorVers = NPNFuncs.version & 0xFF;
62 NPError rv = NPERR_NO_ERROR;
63
64 if(navMinorVers >= NPVERS_HAS_NOTIFICATION) {
65 rv = NPNFuncs.geturlnotify(instance, url, target, notifyData);
66 } else {
67 rv = NPERR_INCOMPATIBLE_VERSION_ERROR;
68 }
69
70 return rv;
71 }
72
73 NPError
NPN_GetURL(NPP instance,const char * url,const char * target)74 NPN_GetURL(NPP instance, const char *url, const char *target)
75 {
76 NPError rv = NPNFuncs.geturl(instance, url, target);
77 return rv;
78 }
79
80 NPError
NPN_PostURLNotify(NPP instance,const char * url,const char * window,uint32_t len,const char * buf,NPBool file,void * notifyData)81 NPN_PostURLNotify(NPP instance, const char* url, const char* window,
82 uint32_t len, const char* buf, NPBool file,
83 void* notifyData)
84 {
85 int navMinorVers = NPNFuncs.version & 0xFF;
86 NPError rv = NPERR_NO_ERROR;
87
88 if(navMinorVers >= NPVERS_HAS_NOTIFICATION) {
89 rv = NPNFuncs.posturlnotify(instance, url, window, len, buf, file, notifyData);
90 } else {
91 rv = NPERR_INCOMPATIBLE_VERSION_ERROR;
92 }
93
94 return rv;
95 }
96
97 NPError
NPN_PostURL(NPP instance,const char * url,const char * window,uint32_t len,const char * buf,NPBool file)98 NPN_PostURL(NPP instance, const char* url, const char* window,
99 uint32_t len, const char* buf, NPBool file)
100 {
101 NPError rv = NPNFuncs.posturl(instance, url, window, len, buf, file);
102 return rv;
103 }
104
105 NPError
NPN_RequestRead(NPStream * stream,NPByteRange * rangeList)106 NPN_RequestRead(NPStream* stream, NPByteRange* rangeList)
107 {
108 NPError rv = NPNFuncs.requestread(stream, rangeList);
109 return rv;
110 }
111
112 NPError
NPN_NewStream(NPP instance,NPMIMEType type,const char * target,NPStream ** stream)113 NPN_NewStream(NPP instance, NPMIMEType type, const char* target,
114 NPStream** stream)
115 {
116 int navMinorVersion = NPNFuncs.version & 0xFF;
117
118 NPError rv = NPERR_NO_ERROR;
119
120 if(navMinorVersion >= NPVERS_HAS_STREAMOUTPUT) {
121 rv = NPNFuncs.newstream(instance, type, target, stream);
122 } else {
123 rv = NPERR_INCOMPATIBLE_VERSION_ERROR;
124 }
125
126 return rv;
127 }
128
129 int32_t
NPN_Write(NPP instance,NPStream * stream,int32_t len,void * buffer)130 NPN_Write(NPP instance, NPStream *stream, int32_t len, void *buffer)
131 {
132 int navMinorVersion = NPNFuncs.version & 0xFF;
133 int32_t rv = 0;
134
135 if(navMinorVersion >= NPVERS_HAS_STREAMOUTPUT) {
136 rv = NPNFuncs.write(instance, stream, len, buffer);
137 } else {
138 rv = -1;
139 }
140
141 return rv;
142 }
143
144 NPError
NPN_DestroyStream(NPP instance,NPStream * stream,NPError reason)145 NPN_DestroyStream(NPP instance, NPStream* stream, NPError reason)
146 {
147 int navMinorVersion = NPNFuncs.version & 0xFF;
148 NPError rv = NPERR_NO_ERROR;
149
150 if(navMinorVersion >= NPVERS_HAS_STREAMOUTPUT) {
151 rv = NPNFuncs.destroystream(instance, stream, reason);
152 } else {
153 rv = NPERR_INCOMPATIBLE_VERSION_ERROR;
154 }
155
156 return rv;
157 }
158
159 void
NPN_Status(NPP instance,const char * message)160 NPN_Status(NPP instance, const char *message)
161 {
162 NPNFuncs.status(instance, message);
163 }
164
165 const char *
NPN_UserAgent(NPP instance)166 NPN_UserAgent(NPP instance)
167 {
168 const char * rv = nullptr;
169 rv = NPNFuncs.uagent(instance);
170 return rv;
171 }
172
173 void *
NPN_MemAlloc(uint32_t size)174 NPN_MemAlloc(uint32_t size)
175 {
176 void * rv = nullptr;
177 rv = NPNFuncs.memalloc(size);
178 return rv;
179 }
180
181 void
NPN_MemFree(void * ptr)182 NPN_MemFree(void* ptr)
183 {
184 NPNFuncs.memfree(ptr);
185 }
186
187 uint32_t
NPN_MemFlush(uint32_t size)188 NPN_MemFlush(uint32_t size)
189 {
190 uint32_t rv = NPNFuncs.memflush(size);
191 return rv;
192 }
193
194 void
NPN_ReloadPlugins(NPBool reloadPages)195 NPN_ReloadPlugins(NPBool reloadPages)
196 {
197 NPNFuncs.reloadplugins(reloadPages);
198 }
199
200 NPError
NPN_GetValue(NPP instance,NPNVariable variable,void * value)201 NPN_GetValue(NPP instance, NPNVariable variable, void *value)
202 {
203 NPError rv = NPERR_GENERIC_ERROR;
204 if (NPNFuncs.getvalue) {
205 rv = NPNFuncs.getvalue(instance, variable, value);
206 }
207 return rv;
208 }
209
210 NPError
NPN_SetValue(NPP instance,NPPVariable variable,void * value)211 NPN_SetValue(NPP instance, NPPVariable variable, void *value)
212 {
213 NPError rv = NPERR_GENERIC_ERROR;
214 if (NPNFuncs.setvalue) {
215 rv = NPNFuncs.setvalue(instance, variable, value);
216 }
217 return rv;
218 }
219
220 void
NPN_InvalidateRect(NPP instance,NPRect * invalidRect)221 NPN_InvalidateRect(NPP instance, NPRect *invalidRect)
222 {
223 NPNFuncs.invalidaterect(instance, invalidRect);
224 }
225
226 void
NPN_InvalidateRegion(NPP instance,NPRegion invalidRegion)227 NPN_InvalidateRegion(NPP instance, NPRegion invalidRegion)
228 {
229 NPNFuncs.invalidateregion(instance, invalidRegion);
230 }
231
232 void
NPN_ForceRedraw(NPP instance)233 NPN_ForceRedraw(NPP instance)
234 {
235 NPNFuncs.forceredraw(instance);
236 }
237
238 NPIdentifier
NPN_GetStringIdentifier(const NPUTF8 * name)239 NPN_GetStringIdentifier(const NPUTF8 *name)
240 {
241 return NPNFuncs.getstringidentifier(name);
242 }
243
244 void
NPN_GetStringIdentifiers(const NPUTF8 ** names,uint32_t nameCount,NPIdentifier * identifiers)245 NPN_GetStringIdentifiers(const NPUTF8 **names, uint32_t nameCount,
246 NPIdentifier *identifiers)
247 {
248 return NPNFuncs.getstringidentifiers(names, nameCount, identifiers);
249 }
250
251 NPIdentifier
NPN_GetStringIdentifier(int32_t intid)252 NPN_GetStringIdentifier(int32_t intid)
253 {
254 return NPNFuncs.getintidentifier(intid);
255 }
256
257 bool
NPN_IdentifierIsString(NPIdentifier identifier)258 NPN_IdentifierIsString(NPIdentifier identifier)
259 {
260 return NPNFuncs.identifierisstring(identifier);
261 }
262
263 NPUTF8 *
NPN_UTF8FromIdentifier(NPIdentifier identifier)264 NPN_UTF8FromIdentifier(NPIdentifier identifier)
265 {
266 return NPNFuncs.utf8fromidentifier(identifier);
267 }
268
269 int32_t
NPN_IntFromIdentifier(NPIdentifier identifier)270 NPN_IntFromIdentifier(NPIdentifier identifier)
271 {
272 return NPNFuncs.intfromidentifier(identifier);
273 }
274
275 NPObject *
NPN_CreateObject(NPP npp,NPClass * aClass)276 NPN_CreateObject(NPP npp, NPClass *aClass)
277 {
278 return NPNFuncs.createobject(npp, aClass);
279 }
280
281 NPObject *
NPN_RetainObject(NPObject * obj)282 NPN_RetainObject(NPObject *obj)
283 {
284 return NPNFuncs.retainobject(obj);
285 }
286
287 void
NPN_ReleaseObject(NPObject * obj)288 NPN_ReleaseObject(NPObject *obj)
289 {
290 return NPNFuncs.releaseobject(obj);
291 }
292
293 bool
NPN_Invoke(NPP npp,NPObject * obj,NPIdentifier methodName,const NPVariant * args,uint32_t argCount,NPVariant * result)294 NPN_Invoke(NPP npp, NPObject* obj, NPIdentifier methodName,
295 const NPVariant *args, uint32_t argCount, NPVariant *result)
296 {
297 return NPNFuncs.invoke(npp, obj, methodName, args, argCount, result);
298 }
299
300 bool
NPN_InvokeDefault(NPP npp,NPObject * obj,const NPVariant * args,uint32_t argCount,NPVariant * result)301 NPN_InvokeDefault(NPP npp, NPObject* obj, const NPVariant *args,
302 uint32_t argCount, NPVariant *result)
303 {
304 return NPNFuncs.invokeDefault(npp, obj, args, argCount, result);
305 }
306
307 bool
NPN_Evaluate(NPP npp,NPObject * obj,NPString * script,NPVariant * result)308 NPN_Evaluate(NPP npp, NPObject* obj, NPString *script,
309 NPVariant *result)
310 {
311 return NPNFuncs.evaluate(npp, obj, script, result);
312 }
313
314 bool
NPN_GetProperty(NPP npp,NPObject * obj,NPIdentifier propertyName,NPVariant * result)315 NPN_GetProperty(NPP npp, NPObject* obj, NPIdentifier propertyName,
316 NPVariant *result)
317 {
318 return NPNFuncs.getproperty(npp, obj, propertyName, result);
319 }
320
321 bool
NPN_SetProperty(NPP npp,NPObject * obj,NPIdentifier propertyName,const NPVariant * value)322 NPN_SetProperty(NPP npp, NPObject* obj, NPIdentifier propertyName,
323 const NPVariant *value)
324 {
325 return NPNFuncs.setproperty(npp, obj, propertyName, value);
326 }
327
328 bool
NPN_RemoveProperty(NPP npp,NPObject * obj,NPIdentifier propertyName)329 NPN_RemoveProperty(NPP npp, NPObject* obj, NPIdentifier propertyName)
330 {
331 return NPNFuncs.removeproperty(npp, obj, propertyName);
332 }
333
334 bool
NPN_Enumerate(NPP npp,NPObject * obj,NPIdentifier ** identifier,uint32_t * count)335 NPN_Enumerate(NPP npp, NPObject *obj, NPIdentifier **identifier,
336 uint32_t *count)
337 {
338 return NPNFuncs.enumerate(npp, obj, identifier, count);
339 }
340
341 bool
NPN_Construct(NPP npp,NPObject * obj,const NPVariant * args,uint32_t argCount,NPVariant * result)342 NPN_Construct(NPP npp, NPObject *obj, const NPVariant *args,
343 uint32_t argCount, NPVariant *result)
344 {
345 return NPNFuncs.construct(npp, obj, args, argCount, result);
346 }
347
348 bool
NPN_HasProperty(NPP npp,NPObject * obj,NPIdentifier propertyName)349 NPN_HasProperty(NPP npp, NPObject* obj, NPIdentifier propertyName)
350 {
351 return NPNFuncs.hasproperty(npp, obj, propertyName);
352 }
353
354 bool
NPN_HasMethod(NPP npp,NPObject * obj,NPIdentifier methodName)355 NPN_HasMethod(NPP npp, NPObject* obj, NPIdentifier methodName)
356 {
357 return NPNFuncs.hasmethod(npp, obj, methodName);
358 }
359
360 void
NPN_ReleaseVariantValue(NPVariant * variant)361 NPN_ReleaseVariantValue(NPVariant *variant)
362 {
363 if (NPNFuncs.releasevariantvalue) {
364 NPNFuncs.releasevariantvalue(variant);
365 } else {
366 if (variant->type == NPVariantType_String) {
367 NPString& strVar = NPVARIANT_TO_STRING(*variant);
368 NPUTF8* buffer = const_cast<NPUTF8*>(gnash::GetNPStringChars(strVar));
369 NPN_MemFree(buffer);
370 } else if (variant->type == NPVariantType_Object) {
371 NPN_ReleaseObject(NPVARIANT_TO_OBJECT(*variant));
372 }
373 VOID_TO_NPVARIANT(*variant);
374 }
375 }
376
377 void
NPN_SetException(NPObject * obj,const NPUTF8 * message)378 NPN_SetException(NPObject* obj, const NPUTF8 *message)
379 {
380 NPNFuncs.setexception(obj, message);
381 }
382 #if NPAPI_VERSION != 190
383 NPError
NPN_GetValueForURL(NPP instance,NPNURLVariable variable,const char * url,char ** value,uint32_t * len)384 NPN_GetValueForURL(NPP instance, NPNURLVariable variable,
385 const char *url, char **value, uint32_t *len)
386 {
387 return NPNFuncs.getvalueforurl(instance, variable, url, value, len);
388 }
389
390 NPError
NPN_SetValueForURL(NPP instance,NPNURLVariable variable,const char * url,const char * value,uint32_t len)391 NPN_SetValueForURL(NPP instance, NPNURLVariable variable,
392 const char *url, const char *value, uint32_t len)
393 {
394 return NPNFuncs.setvalueforurl(instance, variable, url, value, len);
395 }
396
NPN_GetAuthenticationInfo(NPP instance,const char * protocol,const char * host,int32_t port,const char * scheme,const char * realm,char ** username,uint32_t * ulen,char ** password,uint32_t * plen)397 NPError NPN_GetAuthenticationInfo(NPP instance, const char *protocol,
398 const char *host, int32_t port,
399 const char *scheme, const char *realm,
400 char **username, uint32_t *ulen,
401 char **password, uint32_t *plen)
402 {
403 return NPNFuncs.getauthenticationinfo(instance, protocol, host, port,
404 scheme, realm, username, ulen,
405 password, plen);
406 }
407 #endif
408 void
NPN_PluginThreadAsyncCall(NPP plugin,void (* func)(void *),void * userData)409 NPN_PluginThreadAsyncCall(NPP plugin, void (*func)(void *), void *userData)
410 {
411 NPNFuncs.pluginthreadasynccall(plugin, func, userData);
412 }
413
414 // local Variables:
415 // mode: C++
416 // indent-tabs-mode: nil
417 // End:
418