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