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
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/
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
15 * The Original Code is mozilla.org code.
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.
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.
36 * ***** END LICENSE BLOCK ***** */
38 ////////////////////////////////////////////////////////////
40 // Implementation of Netscape entry points (NPN_*)
43 #include "npfunctions.h"
46 #define HIBYTE(x) ((((uint32_t)(x)) & 0xff00) >> 8)
50 #define LOBYTE(W) ((W) & 0xFF)
53 extern NPNetscapeFuncs NPNFuncs
;
55 void NPN_Version(int* plugin_major
, int* plugin_minor
, int* netscape_major
, int* netscape_minor
)
57 *plugin_major
= NP_VERSION_MAJOR
;
58 *plugin_minor
= NP_VERSION_MINOR
;
59 *netscape_major
= HIBYTE(NPNFuncs
.version
);
60 *netscape_minor
= LOBYTE(NPNFuncs
.version
);
63 NPError
NPN_GetURLNotify(NPP instance
, const char *url
, const char *target
, void* notifyData
)
65 int navMinorVers
= NPNFuncs
.version
& 0xFF;
66 NPError rv
= NPERR_NO_ERROR
;
68 if( navMinorVers
>= NPVERS_HAS_NOTIFICATION
)
69 rv
= NPNFuncs
.geturlnotify(instance
, url
, target
, notifyData
);
71 rv
= NPERR_INCOMPATIBLE_VERSION_ERROR
;
76 NPError
NPN_GetURL(NPP instance
, const char *url
, const char *target
)
78 NPError rv
= NPNFuncs
.geturl(instance
, url
, target
);
82 NPError
NPN_PostURLNotify(NPP instance
, const char* url
, const char* window
, uint32_t len
, const char* buf
, NPBool file
, void* notifyData
)
84 int navMinorVers
= NPNFuncs
.version
& 0xFF;
85 NPError rv
= NPERR_NO_ERROR
;
87 if( navMinorVers
>= NPVERS_HAS_NOTIFICATION
)
88 rv
= NPNFuncs
.posturlnotify(instance
, url
, window
, len
, buf
, file
, notifyData
);
90 rv
= NPERR_INCOMPATIBLE_VERSION_ERROR
;
95 NPError
NPN_PostURL(NPP instance
, const char* url
, const char* window
, uint32_t len
, const char* buf
, NPBool file
)
97 NPError rv
= NPNFuncs
.posturl(instance
, url
, window
, len
, buf
, file
);
101 NPError
NPN_RequestRead(NPStream
* stream
, NPByteRange
* rangeList
)
103 NPError rv
= NPNFuncs
.requestread(stream
, rangeList
);
107 NPError
NPN_NewStream(NPP instance
, NPMIMEType type
, const char* target
, NPStream
** stream
)
109 int navMinorVersion
= NPNFuncs
.version
& 0xFF;
111 NPError rv
= NPERR_NO_ERROR
;
113 if( navMinorVersion
>= NPVERS_HAS_STREAMOUTPUT
)
114 rv
= NPNFuncs
.newstream(instance
, type
, target
, stream
);
116 rv
= NPERR_INCOMPATIBLE_VERSION_ERROR
;
121 int32_t NPN_Write(NPP instance
, NPStream
*stream
, int32_t len
, void *buffer
)
123 int navMinorVersion
= NPNFuncs
.version
& 0xFF;
126 if( navMinorVersion
>= NPVERS_HAS_STREAMOUTPUT
)
127 rv
= NPNFuncs
.write(instance
, stream
, len
, buffer
);
134 NPError
NPN_DestroyStream(NPP instance
, NPStream
* stream
, NPError reason
)
136 int navMinorVersion
= NPNFuncs
.version
& 0xFF;
137 NPError rv
= NPERR_NO_ERROR
;
139 if( navMinorVersion
>= NPVERS_HAS_STREAMOUTPUT
)
140 rv
= NPNFuncs
.destroystream(instance
, stream
, reason
);
142 rv
= NPERR_INCOMPATIBLE_VERSION_ERROR
;
147 void NPN_Status(NPP instance
, const char *message
)
149 NPNFuncs
.status(instance
, message
);
152 const char* NPN_UserAgent(NPP instance
)
154 const char * rv
= NULL
;
155 rv
= NPNFuncs
.uagent(instance
);
159 void* NPN_MemAlloc(uint32_t size
)
162 rv
= NPNFuncs
.memalloc(size
);
166 void NPN_MemFree(void* ptr
)
168 NPNFuncs
.memfree(ptr
);
171 uint32_t NPN_MemFlush(uint32_t size
)
173 uint32_t rv
= NPNFuncs
.memflush(size
);
177 void NPN_ReloadPlugins(NPBool reloadPages
)
179 NPNFuncs
.reloadplugins(reloadPages
);
182 NPError
NPN_GetValue(NPP instance
, NPNVariable variable
, void *value
)
184 NPError rv
= NPNFuncs
.getvalue(instance
, variable
, value
);
188 NPError
NPN_SetValue(NPP instance
, NPPVariable variable
, void *value
)
190 NPError rv
= NPNFuncs
.setvalue(instance
, variable
, value
);
194 void NPN_InvalidateRect(NPP instance
, NPRect
*invalidRect
)
196 NPNFuncs
.invalidaterect(instance
, invalidRect
);
199 void NPN_InvalidateRegion(NPP instance
, NPRegion invalidRegion
)
201 NPNFuncs
.invalidateregion(instance
, invalidRegion
);
204 void NPN_ForceRedraw(NPP instance
)
206 NPNFuncs
.forceredraw(instance
);
209 NPIdentifier
NPN_GetStringIdentifier(const NPUTF8
*name
)
211 return NPNFuncs
.getstringidentifier(name
);
214 void NPN_GetStringIdentifiers(const NPUTF8
**names
, uint32_t nameCount
,
215 NPIdentifier
*identifiers
)
217 return NPNFuncs
.getstringidentifiers(names
, nameCount
, identifiers
);
220 NPIdentifier
NPN_GetStringIdentifier(int32_t intid
)
222 return NPNFuncs
.getintidentifier(intid
);
225 bool NPN_IdentifierIsString(NPIdentifier identifier
)
227 return NPNFuncs
.identifierisstring(identifier
);
230 NPUTF8
*NPN_UTF8FromIdentifier(NPIdentifier identifier
)
232 return NPNFuncs
.utf8fromidentifier(identifier
);
235 int32_t NPN_IntFromIdentifier(NPIdentifier identifier
)
237 return NPNFuncs
.intfromidentifier(identifier
);
240 NPObject
*NPN_CreateObject(NPP npp
, NPClass
*aClass
)
242 return NPNFuncs
.createobject(npp
, aClass
);
245 NPObject
*NPN_RetainObject(NPObject
*obj
)
247 return NPNFuncs
.retainobject(obj
);
250 void NPN_ReleaseObject(NPObject
*obj
)
252 return NPNFuncs
.releaseobject(obj
);
255 bool NPN_Invoke(NPP npp
, NPObject
* obj
, NPIdentifier methodName
,
256 const NPVariant
*args
, uint32_t argCount
, NPVariant
*result
)
258 return NPNFuncs
.invoke(npp
, obj
, methodName
, args
, argCount
, result
);
261 bool NPN_InvokeDefault(NPP npp
, NPObject
* obj
, const NPVariant
*args
,
262 uint32_t argCount
, NPVariant
*result
)
264 return NPNFuncs
.invokeDefault(npp
, obj
, args
, argCount
, result
);
267 bool NPN_Evaluate(NPP npp
, NPObject
* obj
, NPString
*script
,
270 return NPNFuncs
.evaluate(npp
, obj
, script
, result
);
273 bool NPN_GetProperty(NPP npp
, NPObject
* obj
, NPIdentifier propertyName
,
276 return NPNFuncs
.getproperty(npp
, obj
, propertyName
, result
);
279 bool NPN_SetProperty(NPP npp
, NPObject
* obj
, NPIdentifier propertyName
,
280 const NPVariant
*value
)
282 return NPNFuncs
.setproperty(npp
, obj
, propertyName
, value
);
285 bool NPN_RemoveProperty(NPP npp
, NPObject
* obj
, NPIdentifier propertyName
)
287 return NPNFuncs
.removeproperty(npp
, obj
, propertyName
);
290 bool NPN_Enumerate(NPP npp
, NPObject
*obj
, NPIdentifier
**identifier
,
293 return NPNFuncs
.enumerate(npp
, obj
, identifier
, count
);
296 bool NPN_Construct(NPP npp
, NPObject
*obj
, const NPVariant
*args
,
297 uint32_t argCount
, NPVariant
*result
)
299 return NPNFuncs
.construct(npp
, obj
, args
, argCount
, result
);
302 bool NPN_HasProperty(NPP npp
, NPObject
* obj
, NPIdentifier propertyName
)
304 return NPNFuncs
.hasproperty(npp
, obj
, propertyName
);
307 bool NPN_HasMethod(NPP npp
, NPObject
* obj
, NPIdentifier methodName
)
309 return NPNFuncs
.hasmethod(npp
, obj
, methodName
);
312 void NPN_ReleaseVariantValue(NPVariant
*variant
)
314 NPNFuncs
.releasevariantvalue(variant
);
317 void NPN_SetException(NPObject
* obj
, const NPUTF8
*message
)
319 NPNFuncs
.setexception(obj
, message
);