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 ***** */
49 NPNetscapeFuncs* g_pNavigatorFuncs = 0;
50 JRIGlobalRef Private_GetJavaClass(void);
52 //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\.
53 ////\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//.
54 // Private_GetJavaClass (global function)
56 // Given a Java class reference (thru NPP_GetJavaClass) inform JRT
57 // of this class existence
60 Private_GetJavaClass(void)
62 jref clazz = NPP_GetJavaClass();
64 JRIEnv* env = NPN_GetJavaEnv();
65 return JRI_NewGlobalRef(env, clazz);
70 //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\.
71 ////\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//.
72 // PLUGIN DLL entry points
74 // These are the Windows specific DLL entry points. They must be exoprted
77 // we need these to be global since we have to fill one of its field
78 // with a data (class) which requires knowlwdge of the navigator
79 // jump-table. This jump table is known at Initialize time (NP_Initialize)
80 // which is called after NP_GetEntryPoint
81 static NPPluginFuncs* g_pluginFuncs;
83 //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\.
84 ////\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//.
87 // fills in the func table used by Navigator to call entry points in
88 // plugin DLL. Note that these entry points ensure that DS is loaded
89 // by using the NP_LOADDS macro, when compiling for Win16
94 NPError WINAPI NP_EXPORT
96 NP_GetEntryPoints(NPPluginFuncs* pFuncs)
100 return NPERR_INVALID_FUNCTABLE_ERROR;
102 // if the plugin's function table is smaller than the plugin expects,
103 // then they are incompatible, and should return an error
105 pFuncs->version = (NP_VERSION_MAJOR << 8) | NP_VERSION_MINOR;
106 pFuncs->newp = NPP_New;
107 pFuncs->destroy = NPP_Destroy;
108 pFuncs->setwindow = NPP_SetWindow;
109 pFuncs->newstream = NPP_NewStream;
110 pFuncs->destroystream = NPP_DestroyStream;
111 pFuncs->asfile = NPP_StreamAsFile;
112 pFuncs->writeready = NPP_WriteReady;
113 pFuncs->write = NPP_Write;
114 pFuncs->print = NPP_Print;
115 pFuncs->getvalue = NPP_GetValue;
116 pFuncs->event = 0; /// reserved
118 g_pluginFuncs = pFuncs;
120 return NPERR_NO_ERROR;
123 //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\.
124 ////\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//.
127 // called immediately after the plugin DLL is loaded
132 NPError WINAPI NP_EXPORT
134 NP_Initialize(NPNetscapeFuncs* pFuncs)
138 return NPERR_INVALID_FUNCTABLE_ERROR;
140 g_pNavigatorFuncs = pFuncs; // save it for future reference
142 // if the plugin's major ver level is lower than the Navigator's,
143 // then they are incompatible, and should return an error
144 if(HIBYTE(pFuncs->version) > NP_VERSION_MAJOR)
145 return NPERR_INCOMPATIBLE_VERSION_ERROR;
147 // We have to defer these assignments until g_pNavigatorFuncs is set
148 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
150 if( navMinorVers >= NPVERS_HAS_NOTIFICATION ) {
151 g_pluginFuncs->urlnotify = NPP_URLNotify;
154 if( navMinorVers >= NPVERS_HAS_LIVECONNECT ) {
155 g_pluginFuncs->javaClass = Private_GetJavaClass();
158 // NPP_Initialize is a standard (cross-platform) initialize function.
159 return NPP_Initialize();
162 //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\.
163 ////\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//.
166 // called immediately before the plugin DLL is unloaded.
167 // This functio shuold check for some ref count on the dll to see if it is
168 // unloadable or it needs to stay in memory.
173 NPError WINAPI NP_EXPORT
178 g_pNavigatorFuncs = NULL;
179 return NPERR_NO_ERROR;
182 // END - PLUGIN DLL entry points
183 ////\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//.
184 //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\.
186 /* NAVIGATOR Entry points */
188 /* These entry points expect to be called from within the plugin. The
189 noteworthy assumption is that DS has already been set to point to the
190 plugin's DLL data segment. Don't call these functions from outside
191 the plugin without ensuring DS is set to the DLLs data segment first,
192 typically using the NP_LOADDS macro
195 /* returns the major/minor version numbers of the Plugin API for the plugin
198 void NPN_Version(int* plugin_major, int* plugin_minor, int* netscape_major, int* netscape_minor)
200 *plugin_major = NP_VERSION_MAJOR;
201 *plugin_minor = NP_VERSION_MINOR;
202 *netscape_major = HIBYTE(g_pNavigatorFuncs->version);
203 *netscape_minor = LOBYTE(g_pNavigatorFuncs->version);
206 NPError NPN_GetValue(NPP instance, NPNVariable variable, void *result)
208 return g_pNavigatorFuncs->getvalue(instance, variable, result);
212 /* causes the specified URL to be fetched and streamed in
214 NPError NPN_GetURLNotify(NPP instance, const char *url, const char *target, void* notifyData)
217 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
219 if( navMinorVers >= NPVERS_HAS_NOTIFICATION ) {
220 err = g_pNavigatorFuncs->geturlnotify(instance, url, target, notifyData);
223 err = NPERR_INCOMPATIBLE_VERSION_ERROR;
229 NPError NPN_GetURL(NPP instance, const char *url, const char *target)
231 return g_pNavigatorFuncs->geturl(instance, url, target);
234 NPError NPN_PostURLNotify(NPP instance, const char* url, const char* window, uint32 len, const char* buf, NPBool file, void* notifyData)
236 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
238 if( navMinorVers >= NPVERS_HAS_NOTIFICATION ) {
239 err = g_pNavigatorFuncs->posturlnotify(instance, url, window, len, buf, file, notifyData);
242 err = NPERR_INCOMPATIBLE_VERSION_ERROR;
248 NPError NPN_PostURL(NPP instance, const char* url, const char* window, uint32 len, const char* buf, NPBool file)
250 return g_pNavigatorFuncs->posturl(instance, url, window, len, buf, file);
253 /* Requests that a number of bytes be provided on a stream. Typically
254 this would be used if a stream was in "pull" mode. An optional
255 position can be provided for streams which are seekable.
257 NPError NPN_RequestRead(NPStream* stream, NPByteRange* rangeList)
259 return g_pNavigatorFuncs->requestread(stream, rangeList);
262 /* Creates a new stream of data from the plug-in to be interpreted
263 by Netscape in the current window.
265 NPError NPN_NewStream(NPP instance, NPMIMEType type,
266 const char* target, NPStream** stream)
268 int navMinorVersion = g_pNavigatorFuncs->version & 0xFF;
271 if( navMinorVersion >= NPVERS_HAS_STREAMOUTPUT ) {
272 err = g_pNavigatorFuncs->newstream(instance, type, target, stream);
275 err = NPERR_INCOMPATIBLE_VERSION_ERROR;
280 /* Provides len bytes of data.
282 int32 NPN_Write(NPP instance, NPStream *stream,
283 int32 len, void *buffer)
285 int navMinorVersion = g_pNavigatorFuncs->version & 0xFF;
288 if( navMinorVersion >= NPVERS_HAS_STREAMOUTPUT ) {
289 result = g_pNavigatorFuncs->write(instance, stream, len, buffer);
297 /* Closes a stream object.
298 reason indicates why the stream was closed.
300 NPError NPN_DestroyStream(NPP instance, NPStream* stream, NPError reason)
302 int navMinorVersion = g_pNavigatorFuncs->version & 0xFF;
305 if( navMinorVersion >= NPVERS_HAS_STREAMOUTPUT ) {
306 err = g_pNavigatorFuncs->destroystream(instance, stream, reason);
309 err = NPERR_INCOMPATIBLE_VERSION_ERROR;
314 /* Provides a text status message in the Netscape client user interface
316 void NPN_Status(NPP instance, const char *message)
318 g_pNavigatorFuncs->status(instance, message);
321 /* returns the user agent string of Navigator, which contains version info
323 const char* NPN_UserAgent(NPP instance)
325 return g_pNavigatorFuncs->uagent(instance);
328 /* allocates memory from the Navigator's memory space. Necessary so that
329 saved instance data may be freed by Navigator when exiting.
333 void* NPN_MemAlloc(uint32 size)
335 return g_pNavigatorFuncs->memalloc(size);
338 /* reciprocal of MemAlloc() above
340 void NPN_MemFree(void* ptr)
342 g_pNavigatorFuncs->memfree(ptr);
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);