update dev300-m58
[ooovba.git] / np_sdk / mozsrc / npwin.cpp
blob3c893b284ca8876e4815a832554542a55774ce33
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 #ifndef _NPAPI_H_
39 #include "npapi.h"
40 #endif
41 #ifndef _NPUPP_H_
42 #include "npupp.h"
43 #endif
45 //\\// DEFINE
46 #define NP_EXPORT
48 //\\// GLOBAL DATA
49 NPNetscapeFuncs* g_pNavigatorFuncs = 0;
51 extern "C"
53 #ifdef OJI
54 JRIGlobalRef Private_GetJavaClass(void);
56 //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\.
57 ////\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//.
58 // Private_GetJavaClass (global function)
60 // Given a Java class reference (thru NPP_GetJavaClass) inform JRT
61 // of this class existence
63 JRIGlobalRef
64 Private_GetJavaClass(void)
66 jref clazz = NPP_GetJavaClass();
67 if (clazz) {
68 JRIEnv* env = NPN_GetJavaEnv();
69 return JRI_NewGlobalRef(env, clazz);
71 return NULL;
73 #endif /* OJI */
75 //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\.
76 ////\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//.
77 // PLUGIN DLL entry points
79 // These are the Windows specific DLL entry points. They must be exoprted
82 // we need these to be global since we have to fill one of its field
83 // with a data (class) which requires knowlwdge of the navigator
84 // jump-table. This jump table is known at Initialize time (NP_Initialize)
85 // which is called after NP_GetEntryPoint
86 static NPPluginFuncs* g_pluginFuncs;
88 //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\.
89 ////\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//.
90 // NP_GetEntryPoints
92 // fills in the func table used by Navigator to call entry points in
93 // plugin DLL. Note that these entry points ensure that DS is loaded
94 // by using the NP_LOADDS macro, when compiling for Win16
96 NPError WINAPI NP_EXPORT
97 NP_GetEntryPoints(NPPluginFuncs* pFuncs)
99 // trap a NULL ptr
100 if(pFuncs == NULL)
101 return NPERR_INVALID_FUNCTABLE_ERROR;
103 // if the plugin's function table is smaller than the plugin expects,
104 // then they are incompatible, and should return an error
106 pFuncs->version = (NP_VERSION_MAJOR << 8) | NP_VERSION_MINOR;
107 pFuncs->newp = NPP_New;
108 pFuncs->destroy = NPP_Destroy;
109 pFuncs->setwindow = NPP_SetWindow;
110 pFuncs->newstream = NPP_NewStream;
111 pFuncs->destroystream = NPP_DestroyStream;
112 pFuncs->asfile = NPP_StreamAsFile;
113 pFuncs->writeready = NPP_WriteReady;
114 pFuncs->write = NPP_Write;
115 pFuncs->print = NPP_Print;
116 pFuncs->event = 0; /// reserved
118 g_pluginFuncs = pFuncs;
120 return NPERR_NO_ERROR;
123 //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\.
124 ////\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//.
125 // NP_Initialize
127 // called immediately after the plugin DLL is loaded
129 NPError WINAPI NP_EXPORT
130 NP_Initialize(NPNetscapeFuncs* pFuncs)
132 // trap a NULL ptr
133 if(pFuncs == NULL)
134 return NPERR_INVALID_FUNCTABLE_ERROR;
136 g_pNavigatorFuncs = pFuncs; // save it for future reference
138 // if the plugin's major ver level is lower than the Navigator's,
139 // then they are incompatible, and should return an error
140 if(HIBYTE(pFuncs->version) > NP_VERSION_MAJOR)
141 return NPERR_INCOMPATIBLE_VERSION_ERROR;
143 // We have to defer these assignments until g_pNavigatorFuncs is set
144 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
146 if( navMinorVers >= NPVERS_HAS_NOTIFICATION ) {
147 g_pluginFuncs->urlnotify = NPP_URLNotify;
150 #ifdef OJI
151 if( navMinorVers >= NPVERS_HAS_LIVECONNECT ) {
152 g_pluginFuncs->javaClass = Private_GetJavaClass();
154 #endif
156 // NPP_Initialize is a standard (cross-platform) initialize function.
157 return NPP_Initialize();
160 //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\.
161 ////\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//.
162 // NP_Shutdown
164 // called immediately before the plugin DLL is unloaded.
165 // This functio shuold check for some ref count on the dll to see if it is
166 // unloadable or it needs to stay in memory.
168 NPError WINAPI NP_EXPORT
169 NP_Shutdown()
171 NPP_Shutdown();
172 g_pNavigatorFuncs = NULL;
173 return NPERR_NO_ERROR;
176 char * NP_GetMIMEDescription()
178 return NPP_GetMIMEDescription();
181 // END - PLUGIN DLL entry points
182 ////\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//.
183 //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\.
185 /* NAVIGATOR Entry points */
187 /* These entry points expect to be called from within the plugin. The
188 noteworthy assumption is that DS has already been set to point to the
189 plugin's DLL data segment. Don't call these functions from outside
190 the plugin without ensuring DS is set to the DLLs data segment first,
191 typically using the NP_LOADDS macro
194 /* returns the major/minor version numbers of the Plugin API for the plugin
195 and the Navigator
197 void NPN_Version(int* plugin_major, int* plugin_minor, int* netscape_major, int* netscape_minor)
199 *plugin_major = NP_VERSION_MAJOR;
200 *plugin_minor = NP_VERSION_MINOR;
201 *netscape_major = HIBYTE(g_pNavigatorFuncs->version);
202 *netscape_minor = LOBYTE(g_pNavigatorFuncs->version);
205 NPError NPN_GetValue(NPP instance, NPNVariable variable, void *result)
207 return g_pNavigatorFuncs->getvalue(instance, variable, result);
211 /* causes the specified URL to be fetched and streamed in
213 NPError NPN_GetURLNotify(NPP instance, const char *url, const char *target, void* notifyData)
216 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
217 NPError err;
218 if( navMinorVers >= NPVERS_HAS_NOTIFICATION ) {
219 err = g_pNavigatorFuncs->geturlnotify(instance, url, target, notifyData);
221 else {
222 err = NPERR_INCOMPATIBLE_VERSION_ERROR;
224 return err;
228 NPError NPN_GetURL(NPP instance, const char *url, const char *target)
230 return g_pNavigatorFuncs->geturl(instance, url, target);
233 NPError NPN_PostURLNotify(NPP instance, const char* url, const char* window, uint32 len, const char* buf, NPBool file, void* notifyData)
235 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
236 NPError err;
237 if( navMinorVers >= NPVERS_HAS_NOTIFICATION ) {
238 err = g_pNavigatorFuncs->posturlnotify(instance, url, window, len, buf, file, notifyData);
240 else {
241 err = NPERR_INCOMPATIBLE_VERSION_ERROR;
243 return err;
247 NPError NPN_PostURL(NPP instance, const char* url, const char* window, uint32 len, const char* buf, NPBool file)
249 return g_pNavigatorFuncs->posturl(instance, url, window, len, buf, file);
252 /* Requests that a number of bytes be provided on a stream. Typically
253 this would be used if a stream was in "pull" mode. An optional
254 position can be provided for streams which are seekable.
256 NPError NPN_RequestRead(NPStream* stream, NPByteRange* rangeList)
258 return g_pNavigatorFuncs->requestread(stream, rangeList);
261 /* Creates a new stream of data from the plug-in to be interpreted
262 by Netscape in the current window.
264 NPError NPN_NewStream(NPP instance, NPMIMEType type,
265 const char* target, NPStream** stream)
267 int navMinorVersion = g_pNavigatorFuncs->version & 0xFF;
268 NPError err;
270 if( navMinorVersion >= NPVERS_HAS_STREAMOUTPUT ) {
271 err = g_pNavigatorFuncs->newstream(instance, type, target, stream);
273 else {
274 err = NPERR_INCOMPATIBLE_VERSION_ERROR;
276 return err;
279 /* Provides len bytes of data.
281 int32 NPN_Write(NPP instance, NPStream *stream,
282 int32 len, void *buffer)
284 int navMinorVersion = g_pNavigatorFuncs->version & 0xFF;
285 int32 result;
287 if( navMinorVersion >= NPVERS_HAS_STREAMOUTPUT ) {
288 result = g_pNavigatorFuncs->write(instance, stream, len, buffer);
290 else {
291 result = -1;
293 return result;
296 /* Closes a stream object.
297 reason indicates why the stream was closed.
299 NPError NPN_DestroyStream(NPP instance, NPStream* stream, NPError reason)
301 int navMinorVersion = g_pNavigatorFuncs->version & 0xFF;
302 NPError err;
304 if( navMinorVersion >= NPVERS_HAS_STREAMOUTPUT ) {
305 err = g_pNavigatorFuncs->destroystream(instance, stream, reason);
307 else {
308 err = NPERR_INCOMPATIBLE_VERSION_ERROR;
310 return err;
313 /* Provides a text status message in the Netscape client user interface
315 void NPN_Status(NPP instance, const char *message)
317 g_pNavigatorFuncs->status(instance, message);
320 /* returns the user agent string of Navigator, which contains version info
322 const char* NPN_UserAgent(NPP instance)
324 return g_pNavigatorFuncs->uagent(instance);
327 /* allocates memory from the Navigator's memory space. Necessary so that
328 saved instance data may be freed by Navigator when exiting.
332 void* NPN_MemAlloc(uint32 size)
334 return g_pNavigatorFuncs->memalloc(size);
337 /* reciprocal of MemAlloc() above
339 void NPN_MemFree(void* ptr)
341 g_pNavigatorFuncs->memfree(ptr);
344 #ifdef OJI
345 /* private function to Netscape. do not use!
347 void NPN_ReloadPlugins(NPBool reloadPages)
349 g_pNavigatorFuncs->reloadplugins(reloadPages);
352 JRIEnv* NPN_GetJavaEnv(void)
354 return g_pNavigatorFuncs->getJavaEnv();
357 jref NPN_GetJavaPeer(NPP instance)
359 return g_pNavigatorFuncs->getJavaPeer(instance);
361 #endif
362 } //end of extern "C"