1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: NPL 1.1/GPL 2.0/LGPL 2.1
4 *
5 * The contents of this file are subject to the Netscape Public License
6 * Version 1.1 (the "License"); you may not use this file except in
7 * compliance with the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/NPL/
9 *
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
14 *
15 * The Original Code is mozilla.org code.
16 *
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
21 *
22 * Contributor(s):
23 *
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the NPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the NPL, the GPL or the LGPL.
35 *
36 * ***** END LICENSE BLOCK ***** */
37
38 ////////////////////////////////////////////////////////////
39 //
40 // Implementation of Netscape entry points (NPN_*)
41 //
42 #include <npapi.h>
43 //#include "npupp.h"
44 #include <npfunctions.h>
45
46 #ifndef HIBYTE
47 #define HIBYTE(x) ((((uint32_t)(x)) & 0xff00) >> 8)
48 #endif
49
50 #ifndef LOBYTE
51 #define LOBYTE(W) ((W) & 0xFF)
52 #endif
53
54 extern NPNetscapeFuncs NPNFuncs;
55
NPN_Version(int * plugin_major,int * plugin_minor,int * netscape_major,int * netscape_minor)56 void NPN_Version(int *plugin_major, int *plugin_minor, int *netscape_major, int *netscape_minor)
57 {
58 *plugin_major = NP_VERSION_MAJOR;
59 *plugin_minor = NP_VERSION_MINOR;
60 *netscape_major = HIBYTE(NPNFuncs.version);
61 *netscape_minor = LOBYTE(NPNFuncs.version);
62 }
63
NPN_GetURLNotify(NPP instance,const char * url,const char * target,void * notifyData)64 NPError NPN_GetURLNotify(NPP instance, const char *url, const char *target, void *notifyData)
65 {
66 int navMinorVers = NPNFuncs.version & 0xFF;
67 NPError rv = NPERR_NO_ERROR;
68
69 if (navMinorVers >= NPVERS_HAS_NOTIFICATION)
70 rv = NPNFuncs.geturlnotify(instance, url, target, notifyData);
71 else
72 rv = NPERR_INCOMPATIBLE_VERSION_ERROR;
73 return rv;
74 }
75
NPN_GetURL(NPP instance,const char * url,const char * target)76 NPError NPN_GetURL(NPP instance, const char *url, const char *target)
77 {
78 NPError rv = NPNFuncs.geturl(instance, url, target);
79 return rv;
80 }
81
NPN_PostURLNotify(NPP instance,const char * url,const char * window,uint32_t len,const char * buf,NPBool file,void * notifyData)82 NPError NPN_PostURLNotify(NPP instance, const char *url, const char *window, uint32_t len,
83 const char *buf, NPBool file, 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 return rv;
94 }
95
NPN_PostURL(NPP instance,const char * url,const char * window,uint32_t len,const char * buf,NPBool file)96 NPError NPN_PostURL(NPP instance, const char *url, const char *window, uint32_t len,
97 const char *buf, NPBool file)
98 {
99 NPError rv = NPNFuncs.posturl(instance, url, window, len, buf, file);
100 return rv;
101 }
102
NPN_RequestRead(NPStream * stream,NPByteRange * rangeList)103 NPError NPN_RequestRead(NPStream * stream, NPByteRange * rangeList)
104 {
105 NPError rv = NPNFuncs.requestread(stream, rangeList);
106 return rv;
107 }
108
NPN_NewStream(NPP instance,NPMIMEType type,const char * target,NPStream ** stream)109 NPError NPN_NewStream(NPP instance, NPMIMEType type, const char *target, NPStream ** stream)
110 {
111 int navMinorVersion = NPNFuncs.version & 0xFF;
112
113 NPError rv = NPERR_NO_ERROR;
114
115 if (navMinorVersion >= NPVERS_HAS_STREAMOUTPUT)
116 rv = NPNFuncs.newstream(instance, type, target, stream);
117 else
118 rv = NPERR_INCOMPATIBLE_VERSION_ERROR;
119
120 return rv;
121 }
122
NPN_Write(NPP instance,NPStream * stream,int32_t len,void * buffer)123 int32_t NPN_Write(NPP instance, NPStream * stream, int32_t len, void *buffer)
124 {
125 int navMinorVersion = NPNFuncs.version & 0xFF;
126 int32_t rv = 0;
127
128 if (navMinorVersion >= NPVERS_HAS_STREAMOUTPUT)
129 rv = NPNFuncs.write(instance, stream, len, buffer);
130 else
131 rv = -1;
132
133 return rv;
134 }
135
NPN_DestroyStream(NPP instance,NPStream * stream,NPError reason)136 NPError NPN_DestroyStream(NPP instance, NPStream * stream, NPError reason)
137 {
138 int navMinorVersion = NPNFuncs.version & 0xFF;
139 NPError rv = NPERR_NO_ERROR;
140
141 if (navMinorVersion >= NPVERS_HAS_STREAMOUTPUT)
142 rv = NPNFuncs.destroystream(instance, stream, reason);
143 else
144 rv = NPERR_INCOMPATIBLE_VERSION_ERROR;
145
146 return rv;
147 }
148
NPN_Status(NPP instance,const char * message)149 void NPN_Status(NPP instance, const char *message)
150 {
151 NPNFuncs.status(instance, message);
152 }
153
NPN_UserAgent(NPP instance)154 const char *NPN_UserAgent(NPP instance)
155 {
156 const char *rv = NULL;
157 rv = NPNFuncs.uagent(instance);
158 return rv;
159 }
160
NPN_MemAlloc(uint32_t size)161 void *NPN_MemAlloc(uint32_t size)
162 {
163 void *rv = NULL;
164 rv = NPNFuncs.memalloc(size);
165 return rv;
166 }
167
NPN_MemFree(void * ptr)168 void NPN_MemFree(void *ptr)
169 {
170 NPNFuncs.memfree(ptr);
171 }
172
NPN_MemFlush(uint32_t size)173 uint32_t NPN_MemFlush(uint32_t size)
174 {
175 uint32_t rv = NPNFuncs.memflush(size);
176 return rv;
177 }
178
NPN_ReloadPlugins(NPBool reloadPages)179 void NPN_ReloadPlugins(NPBool reloadPages)
180 {
181 NPNFuncs.reloadplugins(reloadPages);
182 }
183
184 /*
185 JRIEnv *NPN_GetJavaEnv(void)
186 {
187 JRIEnv *rv = NULL;
188 rv = NPNFuncs.getJavaEnv();
189 return rv;
190 }
191
192 jref NPN_GetJavaPeer(NPP instance)
193 {
194 jref rv;
195 rv = NPNFuncs.getJavaPeer(instance);
196 return rv;
197 }
198 */
199
NPN_GetValue(NPP instance,NPNVariable variable,void * value)200 NPError NPN_GetValue(NPP instance, NPNVariable variable, void *value)
201 {
202 NPError rv = NPNFuncs.getvalue(instance, variable, value);
203 return rv;
204 }
205
NPN_SetValue(NPP instance,NPPVariable variable,void * value)206 NPError NPN_SetValue(NPP instance, NPPVariable variable, void *value)
207 {
208 NPError rv = NPNFuncs.setvalue(instance, variable, value);
209 return rv;
210 }
211
NPN_InvalidateRect(NPP instance,NPRect * invalidRect)212 void NPN_InvalidateRect(NPP instance, NPRect * invalidRect)
213 {
214 NPNFuncs.invalidaterect(instance, invalidRect);
215 }
216
NPN_InvalidateRegion(NPP instance,NPRegion invalidRegion)217 void NPN_InvalidateRegion(NPP instance, NPRegion invalidRegion)
218 {
219 NPNFuncs.invalidateregion(instance, invalidRegion);
220 }
221
NPN_ForceRedraw(NPP instance)222 void NPN_ForceRedraw(NPP instance)
223 {
224 NPNFuncs.forceredraw(instance);
225 }
226
NPN_GetStringIdentifier(const NPUTF8 * name)227 NPIdentifier NPN_GetStringIdentifier(const NPUTF8 * name)
228 {
229 if (!NPNFuncs.getstringidentifier)
230 return 0;
231
232 return NPNFuncs.getstringidentifier(name);
233 }
234
NPN_GetStringIdentifiers(const NPUTF8 ** names,uint32_t nameCount,NPIdentifier * identifiers)235 void NPN_GetStringIdentifiers(const NPUTF8 ** names, uint32_t nameCount, NPIdentifier * identifiers)
236 {
237 return NPNFuncs.getstringidentifiers(names, nameCount, identifiers);
238 }
239
NPN_GetStringIdentifier(int32_t intid)240 NPIdentifier NPN_GetStringIdentifier(int32_t intid)
241 {
242 return NPNFuncs.getintidentifier(intid);
243 }
244
NPN_IdentifierIsString(NPIdentifier identifier)245 bool NPN_IdentifierIsString(NPIdentifier identifier)
246 {
247 return NPNFuncs.identifierisstring(identifier);
248 }
249
NPN_UTF8FromIdentifier(NPIdentifier identifier)250 NPUTF8 *NPN_UTF8FromIdentifier(NPIdentifier identifier)
251 {
252 return NPNFuncs.utf8fromidentifier(identifier);
253 }
254
NPN_IntFromIdentifier(NPIdentifier identifier)255 int32_t NPN_IntFromIdentifier(NPIdentifier identifier)
256 {
257 return NPNFuncs.intfromidentifier(identifier);
258 }
259
NPN_CreateObject(NPP npp,NPClass * aClass)260 NPObject *NPN_CreateObject(NPP npp, NPClass * aClass)
261 {
262 return NPNFuncs.createobject(npp, aClass);
263 }
264
NPN_RetainObject(NPObject * obj)265 NPObject *NPN_RetainObject(NPObject * obj)
266 {
267 return NPNFuncs.retainobject(obj);
268 }
269
NPN_ReleaseObject(NPObject * obj)270 void NPN_ReleaseObject(NPObject * obj)
271 {
272 return NPNFuncs.releaseobject(obj);
273 }
274
NPN_Invoke(NPP npp,NPObject * obj,NPIdentifier methodName,const NPVariant * args,uint32_t argCount,NPVariant * result)275 bool NPN_Invoke(NPP npp, NPObject * obj, NPIdentifier methodName,
276 const NPVariant * args, uint32_t argCount, NPVariant * result)
277 {
278 return NPNFuncs.invoke(npp, obj, methodName, args, argCount, result);
279 }
280
NPN_InvokeDefault(NPP npp,NPObject * obj,const NPVariant * args,uint32_t argCount,NPVariant * result)281 bool NPN_InvokeDefault(NPP npp, NPObject * obj, const NPVariant * args,
282 uint32_t argCount, NPVariant * result)
283 {
284 return NPNFuncs.invokeDefault(npp, obj, args, argCount, result);
285 }
286
NPN_Evaluate(NPP npp,NPObject * obj,NPString * script,NPVariant * result)287 bool NPN_Evaluate(NPP npp, NPObject * obj, NPString * script, NPVariant * result)
288 {
289 return NPNFuncs.evaluate(npp, obj, script, result);
290 }
291
NPN_GetProperty(NPP npp,NPObject * obj,NPIdentifier propertyName,NPVariant * result)292 bool NPN_GetProperty(NPP npp, NPObject * obj, NPIdentifier propertyName, NPVariant * result)
293 {
294 return NPNFuncs.getproperty(npp, obj, propertyName, result);
295 }
296
NPN_SetProperty(NPP npp,NPObject * obj,NPIdentifier propertyName,const NPVariant * value)297 bool NPN_SetProperty(NPP npp, NPObject * obj, NPIdentifier propertyName, const NPVariant * value)
298 {
299 return NPNFuncs.setproperty(npp, obj, propertyName, value);
300 }
301
NPN_RemoveProperty(NPP npp,NPObject * obj,NPIdentifier propertyName)302 bool NPN_RemoveProperty(NPP npp, NPObject * obj, NPIdentifier propertyName)
303 {
304 return NPNFuncs.removeproperty(npp, obj, propertyName);
305 }
306
NPN_HasProperty(NPP npp,NPObject * obj,NPIdentifier propertyName)307 bool NPN_HasProperty(NPP npp, NPObject * obj, NPIdentifier propertyName)
308 {
309 return NPNFuncs.hasproperty(npp, obj, propertyName);
310 }
311
NPN_HasMethod(NPP npp,NPObject * obj,NPIdentifier methodName)312 bool NPN_HasMethod(NPP npp, NPObject * obj, NPIdentifier methodName)
313 {
314 return NPNFuncs.hasmethod(npp, obj, methodName);
315 }
316
NPN_ReleaseVariantValue(NPVariant * variant)317 void NPN_ReleaseVariantValue(NPVariant * variant)
318 {
319 NPNFuncs.releasevariantvalue(variant);
320 }
321
NPN_SetException(NPObject * obj,const NPUTF8 * message)322 void NPN_SetException(NPObject * obj, const NPUTF8 * message)
323 {
324 NPNFuncs.setexception(obj, message);
325 }
326