]> git.sesse.net Git - vlc/blob - projects/mozilla/support/npwin.cpp
mozilla: Resolve files with conflicting licensing terms
[vlc] / projects / mozilla / support / npwin.cpp
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4  *
5  * The contents of this file are subject to the Mozilla Public License Version
6  * 1.1 (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  * http://www.mozilla.org/MPL/
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 MPL, 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 MPL, 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 #include "nsDefaultPlugin.h"
46
47 //\\// DEFINE
48 #define NP_EXPORT
49
50 //\\// GLOBAL DATA
51 NPNetscapeFuncs* g_pNavigatorFuncs = 0;
52 #ifdef OJI
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 #endif /* OJI */
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 NPError WINAPI NP_EXPORT
95 NP_GetEntryPoints(NPPluginFuncs* pFuncs)
96 {
97     // trap a NULL ptr 
98     if(pFuncs == NULL)
99         return NPERR_INVALID_FUNCTABLE_ERROR;
100
101     // if the plugin's function table is smaller than the plugin expects,
102     // then they are incompatible, and should return an error 
103
104     pFuncs->version       = (NP_VERSION_MAJOR << 8) | NP_VERSION_MINOR;
105     pFuncs->newp          = NPP_New;
106     pFuncs->destroy       = NPP_Destroy;
107     pFuncs->setwindow     = NPP_SetWindow;
108     pFuncs->newstream     = NPP_NewStream;
109     pFuncs->destroystream = NPP_DestroyStream;
110     pFuncs->asfile        = NPP_StreamAsFile;
111     pFuncs->writeready    = NPP_WriteReady;
112     pFuncs->write         = NPP_Write;
113     pFuncs->print         = NPP_Print;
114     pFuncs->event         = 0;       /// reserved 
115
116         g_pluginFuncs             = pFuncs;
117
118     return NPERR_NO_ERROR;
119 }
120
121 //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\.
122 ////\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//.
123 // NP_Initialize
124 //
125 //      called immediately after the plugin DLL is loaded
126 //
127 NPError WINAPI NP_EXPORT 
128 NP_Initialize(NPNetscapeFuncs* pFuncs)
129 {
130     // trap a NULL ptr 
131     if(pFuncs == NULL)
132         return NPERR_INVALID_FUNCTABLE_ERROR;
133
134     g_pNavigatorFuncs = pFuncs; // save it for future reference 
135
136     // if the plugin's major ver level is lower than the Navigator's,
137     // then they are incompatible, and should return an error 
138     if(HIBYTE(pFuncs->version) > NP_VERSION_MAJOR)
139         return NPERR_INCOMPATIBLE_VERSION_ERROR;
140
141         // We have to defer these assignments until g_pNavigatorFuncs is set
142     int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
143
144         if( navMinorVers >= NPVERS_HAS_NOTIFICATION ) {
145                 g_pluginFuncs->urlnotify = NPP_URLNotify;
146         }
147 #ifdef OJI      
148         if( navMinorVers >= NPVERS_HAS_LIVECONNECT ) {
149                 g_pluginFuncs->javaClass = Private_GetJavaClass();
150         }
151 #endif
152         // NPP_Initialize is a standard (cross-platform) initialize function.
153     return NPP_Initialize();
154 }
155
156 //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\.
157 ////\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//.
158 // NP_Shutdown
159 //
160 //      called immediately before the plugin DLL is unloaded.
161 //      This function should check for some ref count on the dll to see if it is
162 //      unloadable or it needs to stay in memory. 
163 //
164 NPError WINAPI NP_EXPORT 
165 NP_Shutdown()
166 {
167     NPP_Shutdown();
168     g_pNavigatorFuncs = NULL;
169     return NPERR_NO_ERROR;
170 }
171
172 char * NP_GetMIMEDescription()
173 {
174   static char mimetype[] = NS_PLUGIN_DEFAULT_MIME_DESCRIPTION;
175   return mimetype;
176 }
177
178 //                                              END - PLUGIN DLL entry points   
179 ////\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//.
180 //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\.
181
182 /*    NAVIGATOR Entry points    */
183
184 /* These entry points expect to be called from within the plugin.  The
185    noteworthy assumption is that DS has already been set to point to the
186    plugin's DLL data segment.  Don't call these functions from outside
187    the plugin without ensuring DS is set to the DLLs data segment first,
188    typically using the NP_LOADDS macro
189 */
190
191 /* returns the major/minor version numbers of the Plugin API for the plugin
192    and the Navigator
193 */
194 void NPN_Version(int* plugin_major, int* plugin_minor, int* netscape_major, int* netscape_minor)
195 {
196     *plugin_major   = NP_VERSION_MAJOR;
197     *plugin_minor   = NP_VERSION_MINOR;
198     *netscape_major = HIBYTE(g_pNavigatorFuncs->version);
199     *netscape_minor = LOBYTE(g_pNavigatorFuncs->version);
200 }
201
202 NPError NPN_GetValue(NPP instance, NPNVariable variable, void *result)
203 {
204     return g_pNavigatorFuncs->getvalue(instance, variable, result);
205 }
206
207
208 /* causes the specified URL to be fetched and streamed in
209 */
210 NPError NPN_GetURLNotify(NPP instance, const char *url, const char *target, void* notifyData)
211
212 {
213         int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
214         NPError err;
215         if( navMinorVers >= NPVERS_HAS_NOTIFICATION ) {
216                 err = g_pNavigatorFuncs->geturlnotify(instance, url, target, notifyData);
217         }
218         else {
219                 err = NPERR_INCOMPATIBLE_VERSION_ERROR;
220         }
221         return err;
222 }
223
224
225 NPError NPN_GetURL(NPP instance, const char *url, const char *target)
226 {
227     return g_pNavigatorFuncs->geturl(instance, url, target);
228 }
229
230 NPError NPN_PostURLNotify(NPP instance, const char* url, const char* window, uint32 len, const char* buf, NPBool file, void* notifyData)
231 {
232         int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
233         NPError err;
234         if( navMinorVers >= NPVERS_HAS_NOTIFICATION ) {
235                 err = g_pNavigatorFuncs->posturlnotify(instance, url, window, len, buf, file, notifyData);
236         }
237         else {
238                 err = NPERR_INCOMPATIBLE_VERSION_ERROR;
239         }
240         return err;
241 }
242
243
244 NPError NPN_PostURL(NPP instance, const char* url, const char* window, uint32 len, const char* buf, NPBool file)
245 {
246     return g_pNavigatorFuncs->posturl(instance, url, window, len, buf, file);
247 }
248
249 /* Requests that a number of bytes be provided on a stream.  Typically
250    this would be used if a stream was in "pull" mode.  An optional
251    position can be provided for streams which are seekable.
252 */
253 NPError NPN_RequestRead(NPStream* stream, NPByteRange* rangeList)
254 {
255     return g_pNavigatorFuncs->requestread(stream, rangeList);
256 }
257
258 /* Creates a new stream of data from the plug-in to be interpreted
259    by Netscape in the current window.
260 */
261 NPError NPN_NewStream(NPP instance, NPMIMEType type, 
262                                                                 const char* target, NPStream** stream)
263 {
264         int navMinorVersion = g_pNavigatorFuncs->version & 0xFF;
265         NPError err;
266
267         if( navMinorVersion >= NPVERS_HAS_STREAMOUTPUT ) {
268                 err = g_pNavigatorFuncs->newstream(instance, type, target, stream);
269         }
270         else {
271                 err = NPERR_INCOMPATIBLE_VERSION_ERROR;
272         }
273         return err;
274 }
275
276 /* Provides len bytes of data.
277 */
278 int32 NPN_Write(NPP instance, NPStream *stream,
279                 int32 len, void *buffer)
280 {
281         int navMinorVersion = g_pNavigatorFuncs->version & 0xFF;
282         int32 result;
283
284         if( navMinorVersion >= NPVERS_HAS_STREAMOUTPUT ) {
285                 result = g_pNavigatorFuncs->write(instance, stream, len, buffer);
286         }
287         else {
288                 result = -1;
289         }
290         return result;
291 }
292
293 /* Closes a stream object.  
294 reason indicates why the stream was closed.
295 */
296 NPError NPN_DestroyStream(NPP instance, NPStream* stream, NPError reason)
297 {
298         int navMinorVersion = g_pNavigatorFuncs->version & 0xFF;
299         NPError err;
300
301         if( navMinorVersion >= NPVERS_HAS_STREAMOUTPUT ) {
302                 err = g_pNavigatorFuncs->destroystream(instance, stream, reason);
303         }
304         else {
305                 err = NPERR_INCOMPATIBLE_VERSION_ERROR;
306         }
307         return err;
308 }
309
310 /* Provides a text status message in the Netscape client user interface
311 */
312 void NPN_Status(NPP instance, const char *message)
313 {
314     g_pNavigatorFuncs->status(instance, message);
315 }
316
317 /* returns the user agent string of Navigator, which contains version info
318 */
319 const char* NPN_UserAgent(NPP instance)
320 {
321     return g_pNavigatorFuncs->uagent(instance);
322 }
323
324 /* allocates memory from the Navigator's memory space.  Necessary so that
325    saved instance data may be freed by Navigator when exiting.
326 */
327
328
329 void* NPN_MemAlloc(uint32 size)
330 {
331     return g_pNavigatorFuncs->memalloc(size);
332 }
333
334 /* reciprocal of MemAlloc() above
335 */
336 void NPN_MemFree(void* ptr)
337 {
338     g_pNavigatorFuncs->memfree(ptr);
339 }
340 #ifdef OJI
341 /* private function to Netscape.  do not use!
342 */
343 void NPN_ReloadPlugins(NPBool reloadPages)
344 {
345     g_pNavigatorFuncs->reloadplugins(reloadPages);
346 }
347
348 JRIEnv* NPN_GetJavaEnv(void)
349 {
350         return g_pNavigatorFuncs->getJavaEnv();
351 }
352
353 jref NPN_GetJavaPeer(NPP instance)
354 {
355         return g_pNavigatorFuncs->getJavaPeer(instance);
356 }
357 #endif
358