bump product version to 4.1.6.2
[LibreOffice.git] / np_sdk / npsdk / npwin.cxx
blob9021c635993c6dc2ec43f35c8ca7bb35c51cdac2
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
13 * License.
15 * The Original Code is Mozilla Communicator client 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.
22 * Contributor(s):
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 #include "npapi.h"
39 #include "npupp.h"
40 #include "plugin.h"
42 //\\// DEFINE
43 #define NP_EXPORT
45 //\\// GLOBAL DATA
46 NPNetscapeFuncs* g_pNavigatorFuncs = 0;
48 extern "C"
50 #ifdef OJI
51 JRIGlobalRef Private_GetJavaClass(void);
53 //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\.
54 ////\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//.
55 // Private_GetJavaClass (global function)
57 // Given a Java class reference (thru NPP_GetJavaClass) inform JRT
58 // of this class existence
60 JRIGlobalRef
61 Private_GetJavaClass(void)
63 jref clazz = NPP_GetJavaClass();
64 if (clazz) {
65 JRIEnv* env = NPN_GetJavaEnv();
66 return JRI_NewGlobalRef(env, clazz);
68 return NULL;
70 #endif /* OJI */
72 //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\.
73 ////\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//.
74 // PLUGIN DLL entry points
76 // These are the Windows specific DLL entry points. They must be exoprted
79 // we need these to be global since we have to fill one of its field
80 // with a data (class) which requires knowlwdge of the navigator
81 // jump-table. This jump table is known at Initialize time (NP_Initialize)
82 // which is called after NP_GetEntryPoint
83 static NPPluginFuncs* g_pluginFuncs;
85 //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\.
86 ////\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//.
87 // NP_GetEntryPoints
89 // fills in the func table used by Navigator to call entry points in
90 // plugin DLL. Note that these entry points ensure that DS is loaded
91 // by using the NP_LOADDS macro, when compiling for Win16
93 NPError WINAPI NP_EXPORT
94 NP_GetEntryPoints(NPPluginFuncs* pFuncs)
96 // trap a NULL ptr
97 if(pFuncs == NULL)
98 return NPERR_INVALID_FUNCTABLE_ERROR;
100 // if the plugin's function table is smaller than the plugin expects,
101 // then they are incompatible, and should return an error
103 pFuncs->version = (NP_VERSION_MAJOR << 8) | NP_VERSION_MINOR;
104 pFuncs->newp = NPP_New;
105 pFuncs->destroy = NPP_Destroy;
106 pFuncs->setwindow = NPP_SetWindow;
107 pFuncs->newstream = NPP_NewStream;
108 pFuncs->destroystream = NPP_DestroyStream;
109 pFuncs->asfile = NPP_StreamAsFile;
110 pFuncs->writeready = NPP_WriteReady;
111 pFuncs->write = NPP_Write;
112 pFuncs->print = NPP_Print;
113 pFuncs->event = 0; /// reserved
115 g_pluginFuncs = pFuncs;
117 return NPERR_NO_ERROR;
120 //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\.
121 ////\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//.
122 // NP_Initialize
124 // called immediately after the plugin DLL is loaded
126 NPError WINAPI NP_EXPORT
127 NP_Initialize(NPNetscapeFuncs* pFuncs)
129 // trap a NULL ptr
130 if(pFuncs == NULL)
131 return NPERR_INVALID_FUNCTABLE_ERROR;
133 g_pNavigatorFuncs = pFuncs; // save it for future reference
135 // if the plugin's major ver level is lower than the Navigator's,
136 // then they are incompatible, and should return an error
137 if(HIBYTE(pFuncs->version) > NP_VERSION_MAJOR)
138 return NPERR_INCOMPATIBLE_VERSION_ERROR;
140 // We have to defer these assignments until g_pNavigatorFuncs is set
141 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
143 if( navMinorVers >= NPVERS_HAS_NOTIFICATION ) {
144 g_pluginFuncs->urlnotify = NPP_URLNotify;
147 #ifdef OJI
148 if( navMinorVers >= NPVERS_HAS_LIVECONNECT ) {
149 g_pluginFuncs->javaClass = Private_GetJavaClass();
151 #endif
153 return NPP_Initialize();
156 //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\.
157 ////\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//.
158 // NP_Shutdown
160 // called immediately before the plugin DLL is unloaded.
161 // This functio shuold check for some ref count on the dll to see if it is
162 // unloadable or it needs to stay in memory.
164 void WINAPI NP_EXPORT
165 NP_Shutdown()
167 NPP_Shutdown();
168 g_pNavigatorFuncs = NULL;
171 char * NP_GetMIMEDescription()
173 return (char *)NPP_GetMIMEDescription();
176 // END - PLUGIN DLL entry points
177 ////\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//.
178 //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\.
180 /* NAVIGATOR Entry points */
182 /* These entry points expect to be called from within the plugin. The
183 noteworthy assumption is that DS has already been set to point to the
184 plugin's DLL data segment. Don't call these functions from outside
185 the plugin without ensuring DS is set to the DLLs data segment first,
186 typically using the NP_LOADDS macro
189 /* returns the major/minor version numbers of the Plugin API for the plugin
190 and the Navigator
192 void NPN_Version(int* plugin_major, int* plugin_minor, int* netscape_major, int* netscape_minor)
194 *plugin_major = NP_VERSION_MAJOR;
195 *plugin_minor = NP_VERSION_MINOR;
196 *netscape_major = HIBYTE(g_pNavigatorFuncs->version);
197 *netscape_minor = LOBYTE(g_pNavigatorFuncs->version);
200 NPError NPN_GetValue(NPP instance, NPNVariable variable, void *result)
202 return g_pNavigatorFuncs->getvalue(instance, variable, result);
206 /* causes the specified URL to be fetched and streamed in
208 NPError NPN_GetURLNotify(NPP instance, const char *url, const char *target, void* notifyData)
211 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
212 NPError err;
213 if( navMinorVers >= NPVERS_HAS_NOTIFICATION ) {
214 err = g_pNavigatorFuncs->geturlnotify(instance, url, target, notifyData);
216 else {
217 err = NPERR_INCOMPATIBLE_VERSION_ERROR;
219 return err;
223 NPError NPN_GetURL(NPP instance, const char *url, const char *target)
225 return g_pNavigatorFuncs->geturl(instance, url, target);
228 NPError NPN_PostURLNotify(NPP instance, const char* url, const char* window, uint32_t len, const char* buf, NPBool file, void* notifyData)
230 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
231 NPError err;
232 if( navMinorVers >= NPVERS_HAS_NOTIFICATION ) {
233 err = g_pNavigatorFuncs->posturlnotify(instance, url, window, len, buf, file, notifyData);
235 else {
236 err = NPERR_INCOMPATIBLE_VERSION_ERROR;
238 return err;
242 NPError NPN_PostURL(NPP instance, const char* url, const char* window, uint32_t len, const char* buf, NPBool file)
244 return g_pNavigatorFuncs->posturl(instance, url, window, len, buf, file);
247 /* Requests that a number of bytes be provided on a stream. Typically
248 this would be used if a stream was in "pull" mode. An optional
249 position can be provided for streams which are seekable.
251 NPError NPN_RequestRead(NPStream* stream, NPByteRange* rangeList)
253 return g_pNavigatorFuncs->requestread(stream, rangeList);
256 /* Creates a new stream of data from the plug-in to be interpreted
257 by Netscape in the current window.
259 NPError NPN_NewStream(NPP instance, NPMIMEType type,
260 const char* target, NPStream** stream)
262 int navMinorVersion = g_pNavigatorFuncs->version & 0xFF;
263 NPError err;
265 if( navMinorVersion >= NPVERS_HAS_STREAMOUTPUT ) {
266 err = g_pNavigatorFuncs->newstream(instance, type, target, stream);
268 else {
269 err = NPERR_INCOMPATIBLE_VERSION_ERROR;
271 return err;
274 /* Provides len bytes of data.
276 int32_t NPN_Write(NPP instance, NPStream *stream,
277 int32_t len, void *buffer)
279 int navMinorVersion = g_pNavigatorFuncs->version & 0xFF;
280 int32_t result;
282 if( navMinorVersion >= NPVERS_HAS_STREAMOUTPUT ) {
283 result = g_pNavigatorFuncs->write(instance, stream, len, buffer);
285 else {
286 result = -1;
288 return result;
291 /* Closes a stream object.
292 reason indicates why the stream was closed.
294 NPError NPN_DestroyStream(NPP instance, NPStream* stream, NPError reason)
296 int navMinorVersion = g_pNavigatorFuncs->version & 0xFF;
297 NPError err;
299 if( navMinorVersion >= NPVERS_HAS_STREAMOUTPUT ) {
300 err = g_pNavigatorFuncs->destroystream(instance, stream, reason);
302 else {
303 err = NPERR_INCOMPATIBLE_VERSION_ERROR;
305 return err;
308 /* Provides a text status message in the Netscape client user interface
310 void NPN_Status(NPP instance, const char *message)
312 g_pNavigatorFuncs->status(instance, message);
315 /* returns the user agent string of Navigator, which contains version info
317 const char* NPN_UserAgent(NPP instance)
319 return g_pNavigatorFuncs->uagent(instance);
322 /* allocates memory from the Navigator's memory space. Necessary so that
323 saved instance data may be freed by Navigator when exiting.
327 void* NPN_MemAlloc(uint32_t size)
329 return g_pNavigatorFuncs->memalloc(size);
332 /* reciprocal of MemAlloc() above
334 void NPN_MemFree(void* ptr)
336 g_pNavigatorFuncs->memfree(ptr);
339 #ifdef OJI
340 /* private function to Netscape. do not use!
342 void NPN_ReloadPlugins(NPBool reloadPages)
344 g_pNavigatorFuncs->reloadplugins(reloadPages);
347 JRIEnv* NPN_GetJavaEnv(void)
349 return g_pNavigatorFuncs->getJavaEnv();
352 jref NPN_GetJavaPeer(NPP instance)
354 return g_pNavigatorFuncs->getJavaPeer(instance);
356 #endif
357 } //end of extern "C"