]> git.sesse.net Git - vlc/blob - mozilla/support/npwin.cpp
* ./mozilla/*: moved support files in a separate directory.
[vlc] / mozilla / support / npwin.cpp
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
4  *
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/
9  *
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.
14  *
15  * The Original Code is Mozilla Communicator client code.
16  *
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.
21  *
22  * Contributor(s):
23  *
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.
35  *
36  * ***** END LICENSE BLOCK ***** */
37
38 #ifndef _NPAPI_H_
39 #include "npapi.h"
40 #endif
41 #ifndef _NPUPP_H_
42 #include "npupp.h"
43 #endif
44
45 //\\// DEFINE
46 #define NP_EXPORT
47
48 //\\// GLOBAL DATA
49 NPNetscapeFuncs* g_pNavigatorFuncs = 0;
50 JRIGlobalRef Private_GetJavaClass(void);
51
52 //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\.
53 ////\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//.
54 // Private_GetJavaClass (global function)
55 //
56 //      Given a Java class reference (thru NPP_GetJavaClass) inform JRT
57 //      of this class existence
58 //
59 JRIGlobalRef
60 Private_GetJavaClass(void)
61 {
62     jref clazz = NPP_GetJavaClass();
63     if (clazz) {
64                 JRIEnv* env = NPN_GetJavaEnv();
65                 return JRI_NewGlobalRef(env, clazz);
66     }
67     return NULL;
68 }
69
70 //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\.
71 ////\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//.
72 //                                              PLUGIN DLL entry points   
73 //
74 // These are the Windows specific DLL entry points. They must be exoprted
75 //
76
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;
82
83 //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\.
84 ////\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//.
85 // NP_GetEntryPoints
86 //
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
90 //
91 #ifdef __MINGW32__
92 extern "C" NPError
93 #else
94 NPError WINAPI NP_EXPORT
95 #endif
96 NP_GetEntryPoints(NPPluginFuncs* pFuncs)
97 {
98     // trap a NULL ptr 
99     if(pFuncs == NULL)
100         return NPERR_INVALID_FUNCTABLE_ERROR;
101
102     // if the plugin's function table is smaller than the plugin expects,
103     // then they are incompatible, and should return an error 
104
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 
117
118         g_pluginFuncs             = pFuncs;
119
120     return NPERR_NO_ERROR;
121 }
122
123 //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\.
124 ////\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//.
125 // NP_Initialize
126 //
127 //      called immediately after the plugin DLL is loaded
128 //
129 #ifdef __MINGW32__
130 extern "C" NPError
131 #else
132 NPError WINAPI NP_EXPORT 
133 #endif
134 NP_Initialize(NPNetscapeFuncs* pFuncs)
135 {
136     // trap a NULL ptr 
137     if(pFuncs == NULL)
138         return NPERR_INVALID_FUNCTABLE_ERROR;
139
140     g_pNavigatorFuncs = pFuncs; // save it for future reference 
141
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;
146
147         // We have to defer these assignments until g_pNavigatorFuncs is set
148     int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
149
150         if( navMinorVers >= NPVERS_HAS_NOTIFICATION ) {
151                 g_pluginFuncs->urlnotify = NPP_URLNotify;
152         }
153         
154         if( navMinorVers >= NPVERS_HAS_LIVECONNECT ) {
155                 g_pluginFuncs->javaClass = Private_GetJavaClass();
156         }
157
158         // NPP_Initialize is a standard (cross-platform) initialize function.
159     return NPP_Initialize();
160 }
161
162 //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\.
163 ////\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//.
164 // NP_Shutdown
165 //
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. 
169 //
170 #ifdef __MINGW32__
171 extern "C" NPError
172 #else
173 NPError WINAPI NP_EXPORT 
174 #endif
175 NP_Shutdown()
176 {
177     NPP_Shutdown();
178     g_pNavigatorFuncs = NULL;
179     return NPERR_NO_ERROR;
180 }
181
182 //                                              END - PLUGIN DLL entry points   
183 ////\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//.
184 //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\.
185
186 /*    NAVIGATOR Entry points    */
187
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
193 */
194
195 /* returns the major/minor version numbers of the Plugin API for the plugin
196    and the Navigator
197 */
198 void NPN_Version(int* plugin_major, int* plugin_minor, int* netscape_major, int* netscape_minor)
199 {
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);
204 }
205
206 NPError NPN_GetValue(NPP instance, NPNVariable variable, void *result)
207 {
208     return g_pNavigatorFuncs->getvalue(instance, variable, result);
209 }
210
211
212 /* causes the specified URL to be fetched and streamed in
213 */
214 NPError NPN_GetURLNotify(NPP instance, const char *url, const char *target, void* notifyData)
215
216 {
217         int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
218         NPError err;
219         if( navMinorVers >= NPVERS_HAS_NOTIFICATION ) {
220                 err = g_pNavigatorFuncs->geturlnotify(instance, url, target, notifyData);
221         }
222         else {
223                 err = NPERR_INCOMPATIBLE_VERSION_ERROR;
224         }
225         return err;
226 }
227
228
229 NPError NPN_GetURL(NPP instance, const char *url, const char *target)
230 {
231     return g_pNavigatorFuncs->geturl(instance, url, target);
232 }
233
234 NPError NPN_PostURLNotify(NPP instance, const char* url, const char* window, uint32 len, const char* buf, NPBool file, void* notifyData)
235 {
236         int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
237         NPError err;
238         if( navMinorVers >= NPVERS_HAS_NOTIFICATION ) {
239                 err = g_pNavigatorFuncs->posturlnotify(instance, url, window, len, buf, file, notifyData);
240         }
241         else {
242                 err = NPERR_INCOMPATIBLE_VERSION_ERROR;
243         }
244         return err;
245 }
246
247
248 NPError NPN_PostURL(NPP instance, const char* url, const char* window, uint32 len, const char* buf, NPBool file)
249 {
250     return g_pNavigatorFuncs->posturl(instance, url, window, len, buf, file);
251 }
252
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.
256 */
257 NPError NPN_RequestRead(NPStream* stream, NPByteRange* rangeList)
258 {
259     return g_pNavigatorFuncs->requestread(stream, rangeList);
260 }
261
262 /* Creates a new stream of data from the plug-in to be interpreted
263    by Netscape in the current window.
264 */
265 NPError NPN_NewStream(NPP instance, NPMIMEType type, 
266                                                                 const char* target, NPStream** stream)
267 {
268         int navMinorVersion = g_pNavigatorFuncs->version & 0xFF;
269         NPError err;
270
271         if( navMinorVersion >= NPVERS_HAS_STREAMOUTPUT ) {
272                 err = g_pNavigatorFuncs->newstream(instance, type, target, stream);
273         }
274         else {
275                 err = NPERR_INCOMPATIBLE_VERSION_ERROR;
276         }
277         return err;
278 }
279
280 /* Provides len bytes of data.
281 */
282 int32 NPN_Write(NPP instance, NPStream *stream,
283                 int32 len, void *buffer)
284 {
285         int navMinorVersion = g_pNavigatorFuncs->version & 0xFF;
286         int32 result;
287
288         if( navMinorVersion >= NPVERS_HAS_STREAMOUTPUT ) {
289                 result = g_pNavigatorFuncs->write(instance, stream, len, buffer);
290         }
291         else {
292                 result = -1;
293         }
294         return result;
295 }
296
297 /* Closes a stream object.  
298 reason indicates why the stream was closed.
299 */
300 NPError NPN_DestroyStream(NPP instance, NPStream* stream, NPError reason)
301 {
302         int navMinorVersion = g_pNavigatorFuncs->version & 0xFF;
303         NPError err;
304
305         if( navMinorVersion >= NPVERS_HAS_STREAMOUTPUT ) {
306                 err = g_pNavigatorFuncs->destroystream(instance, stream, reason);
307         }
308         else {
309                 err = NPERR_INCOMPATIBLE_VERSION_ERROR;
310         }
311         return err;
312 }
313
314 /* Provides a text status message in the Netscape client user interface
315 */
316 void NPN_Status(NPP instance, const char *message)
317 {
318     g_pNavigatorFuncs->status(instance, message);
319 }
320
321 /* returns the user agent string of Navigator, which contains version info
322 */
323 const char* NPN_UserAgent(NPP instance)
324 {
325     return g_pNavigatorFuncs->uagent(instance);
326 }
327
328 /* allocates memory from the Navigator's memory space.  Necessary so that
329    saved instance data may be freed by Navigator when exiting.
330 */
331
332
333 void* NPN_MemAlloc(uint32 size)
334 {
335     return g_pNavigatorFuncs->memalloc(size);
336 }
337
338 /* reciprocal of MemAlloc() above
339 */
340 void NPN_MemFree(void* ptr)
341 {
342     g_pNavigatorFuncs->memfree(ptr);
343 }
344
345 /* private function to Netscape.  do not use!
346 */
347 void NPN_ReloadPlugins(NPBool reloadPages)
348 {
349     g_pNavigatorFuncs->reloadplugins(reloadPages);
350 }
351
352 JRIEnv* NPN_GetJavaEnv(void)
353 {
354         return g_pNavigatorFuncs->getJavaEnv();
355 }
356
357 jref NPN_GetJavaPeer(NPP instance)
358 {
359         return g_pNavigatorFuncs->getJavaPeer(instance);
360 }
361