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 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.
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 ***** */
40 #ifdef HAVE_MOZILLA_CONFIG_H
41 # include <mozilla-config.h>
52 NPNetscapeFuncs* g_pNavigatorFuncs = 0;
53 JRIGlobalRef Private_GetJavaClass(void);
55 //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\.
56 ////\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//.
57 // Private_GetJavaClass (global function)
59 // Given a Java class reference (thru NPP_GetJavaClass) inform JRT
60 // of this class existence
63 Private_GetJavaClass(void)
65 jref clazz = NPP_GetJavaClass();
67 JRIEnv* env = NPN_GetJavaEnv();
68 return JRI_NewGlobalRef(env, clazz);
73 //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\.
74 ////\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//.
75 // PLUGIN DLL entry points
77 // These are the Windows specific DLL entry points. They must be exoprted
80 // we need these to be global since we have to fill one of its field
81 // with a data (class) which requires knowlwdge of the navigator
82 // jump-table. This jump table is known at Initialize time (NP_Initialize)
83 // which is called after NP_GetEntryPoint
84 static NPPluginFuncs* g_pluginFuncs;
86 //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\.
87 ////\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//.
90 // fills in the func table used by Navigator to call entry points in
91 // plugin DLL. Note that these entry points ensure that DS is loaded
92 // by using the NP_LOADDS macro, when compiling for Win16
95 extern "C" __declspec(dllexport) NPError WINAPI
97 NPError WINAPI NP_EXPORT
99 NP_GetEntryPoints(NPPluginFuncs* pFuncs)
103 return NPERR_INVALID_FUNCTABLE_ERROR;
105 // if the plugin's function table is smaller than the plugin expects,
106 // then they are incompatible, and should return an error
108 pFuncs->version = (NP_VERSION_MAJOR << 8) | NP_VERSION_MINOR;
109 pFuncs->newp = NPP_New;
110 pFuncs->destroy = NPP_Destroy;
111 pFuncs->setwindow = NPP_SetWindow;
112 pFuncs->newstream = NPP_NewStream;
113 pFuncs->destroystream = NPP_DestroyStream;
114 pFuncs->asfile = NPP_StreamAsFile;
115 pFuncs->writeready = NPP_WriteReady;
116 pFuncs->write = NPP_Write;
117 pFuncs->print = NPP_Print;
118 pFuncs->getvalue = NPP_GetValue;
119 pFuncs->event = 0; /// reserved
121 g_pluginFuncs = pFuncs;
123 return NPERR_NO_ERROR;
126 //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\.
127 ////\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//.
130 // called immediately after the plugin DLL is loaded
133 extern "C" __declspec(dllexport) NPError WINAPI
135 NPError WINAPI NP_EXPORT
137 NP_Initialize(NPNetscapeFuncs* pFuncs)
141 return NPERR_INVALID_FUNCTABLE_ERROR;
143 g_pNavigatorFuncs = pFuncs; // save it for future reference
145 // if the plugin's major ver level is lower than the Navigator's,
146 // then they are incompatible, and should return an error
147 if(HIBYTE(pFuncs->version) > NP_VERSION_MAJOR)
148 return NPERR_INCOMPATIBLE_VERSION_ERROR;
150 // We have to defer these assignments until g_pNavigatorFuncs is set
151 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
153 if( navMinorVers >= NPVERS_HAS_NOTIFICATION ) {
154 g_pluginFuncs->urlnotify = NPP_URLNotify;
157 if( navMinorVers >= NPVERS_HAS_LIVECONNECT ) {
158 g_pluginFuncs->javaClass = Private_GetJavaClass();
161 // NPP_Initialize is a standard (cross-platform) initialize function.
162 return NPP_Initialize();
165 //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\.
166 ////\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//.
169 // called immediately before the plugin DLL is unloaded.
170 // This functio shuold check for some ref count on the dll to see if it is
171 // unloadable or it needs to stay in memory.
174 extern "C" __declspec(dllexport) NPError WINAPI
176 NPError WINAPI NP_EXPORT
181 g_pNavigatorFuncs = NULL;
182 return NPERR_NO_ERROR;
185 // END - PLUGIN DLL entry points
186 ////\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//.
187 //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\.
189 /* NAVIGATOR Entry points */
191 /* These entry points expect to be called from within the plugin. The
192 noteworthy assumption is that DS has already been set to point to the
193 plugin's DLL data segment. Don't call these functions from outside
194 the plugin without ensuring DS is set to the DLLs data segment first,
195 typically using the NP_LOADDS macro
198 /* returns the major/minor version numbers of the Plugin API for the plugin
201 void NPN_Version(int* plugin_major, int* plugin_minor, int* netscape_major, int* netscape_minor)
203 *plugin_major = NP_VERSION_MAJOR;
204 *plugin_minor = NP_VERSION_MINOR;
205 *netscape_major = HIBYTE(g_pNavigatorFuncs->version);
206 *netscape_minor = LOBYTE(g_pNavigatorFuncs->version);
209 NPError NPN_GetValue(NPP instance, NPNVariable variable, void *result)
211 return g_pNavigatorFuncs->getvalue(instance, variable, result);
215 /* causes the specified URL to be fetched and streamed in
217 NPError NPN_GetURLNotify(NPP instance, const char *url, const char *target, void* notifyData)
220 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
222 if( navMinorVers >= NPVERS_HAS_NOTIFICATION ) {
223 err = g_pNavigatorFuncs->geturlnotify(instance, url, target, notifyData);
226 err = NPERR_INCOMPATIBLE_VERSION_ERROR;
232 NPError NPN_GetURL(NPP instance, const char *url, const char *target)
234 return g_pNavigatorFuncs->geturl(instance, url, target);
237 NPError NPN_PostURLNotify(NPP instance, const char* url, const char* window, uint32 len, const char* buf, NPBool file, void* notifyData)
239 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
241 if( navMinorVers >= NPVERS_HAS_NOTIFICATION ) {
242 err = g_pNavigatorFuncs->posturlnotify(instance, url, window, len, buf, file, notifyData);
245 err = NPERR_INCOMPATIBLE_VERSION_ERROR;
251 NPError NPN_PostURL(NPP instance, const char* url, const char* window, uint32 len, const char* buf, NPBool file)
253 return g_pNavigatorFuncs->posturl(instance, url, window, len, buf, file);
256 /* Requests that a number of bytes be provided on a stream. Typically
257 this would be used if a stream was in "pull" mode. An optional
258 position can be provided for streams which are seekable.
260 NPError NPN_RequestRead(NPStream* stream, NPByteRange* rangeList)
262 return g_pNavigatorFuncs->requestread(stream, rangeList);
265 /* Creates a new stream of data from the plug-in to be interpreted
266 by Netscape in the current window.
268 NPError NPN_NewStream(NPP instance, NPMIMEType type,
269 const char* target, NPStream** stream)
271 int navMinorVersion = g_pNavigatorFuncs->version & 0xFF;
274 if( navMinorVersion >= NPVERS_HAS_STREAMOUTPUT ) {
275 err = g_pNavigatorFuncs->newstream(instance, type, target, stream);
278 err = NPERR_INCOMPATIBLE_VERSION_ERROR;
283 /* Provides len bytes of data.
285 int32 NPN_Write(NPP instance, NPStream *stream,
286 int32 len, void *buffer)
288 int navMinorVersion = g_pNavigatorFuncs->version & 0xFF;
291 if( navMinorVersion >= NPVERS_HAS_STREAMOUTPUT ) {
292 result = g_pNavigatorFuncs->write(instance, stream, len, buffer);
300 /* Closes a stream object.
301 reason indicates why the stream was closed.
303 NPError NPN_DestroyStream(NPP instance, NPStream* stream, NPError reason)
305 int navMinorVersion = g_pNavigatorFuncs->version & 0xFF;
308 if( navMinorVersion >= NPVERS_HAS_STREAMOUTPUT ) {
309 err = g_pNavigatorFuncs->destroystream(instance, stream, reason);
312 err = NPERR_INCOMPATIBLE_VERSION_ERROR;
317 /* Provides a text status message in the Netscape client user interface
319 void NPN_Status(NPP instance, const char *message)
321 g_pNavigatorFuncs->status(instance, message);
324 /* returns the user agent string of Navigator, which contains version info
326 const char* NPN_UserAgent(NPP instance)
328 return g_pNavigatorFuncs->uagent(instance);
331 /* allocates memory from the Navigator's memory space. Necessary so that
332 saved instance data may be freed by Navigator when exiting.
336 void* NPN_MemAlloc(uint32 size)
338 return g_pNavigatorFuncs->memalloc(size);
341 /* reciprocal of MemAlloc() above
343 void NPN_MemFree(void* ptr)
345 g_pNavigatorFuncs->memfree(ptr);
348 /* private function to Netscape. do not use!
350 void NPN_ReloadPlugins(NPBool reloadPages)
352 g_pNavigatorFuncs->reloadplugins(reloadPages);
355 JRIEnv* NPN_GetJavaEnv(void)
357 return g_pNavigatorFuncs->getJavaEnv();
360 jref NPN_GetJavaPeer(NPP instance)
362 return g_pNavigatorFuncs->getJavaPeer(instance);