Back to index

lightning-sunbird  0.9+nobinonly
npos2.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is Mozilla Communicator client code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 #include <os2.h>
00039 
00040 #ifndef _NPAPI_H_
00041 #include "npapi.h"
00042 #endif
00043 #ifndef _NPUPP_H_
00044 #include "npupp.h"
00045 #endif
00046 
00047 #include "nsDefaultPlugin.h"
00048 
00049 //\\// DEFINE
00050 #define NP_EXPORT
00051 
00052 //\\// GLOBAL DATA
00053 NPNetscapeFuncs* g_pNavigatorFuncs = 0;
00054 #ifdef OJI
00055 JRIGlobalRef Private_GetJavaClass(void);
00056 
00057 //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\.
00059 // Private_GetJavaClass (global function)
00060 //
00061 //     Given a Java class reference (thru NPP_GetJavaClass) inform JRT
00062 //     of this class existence
00063 //
00064 JRIGlobalRef
00065 Private_GetJavaClass(void)
00066 {
00067     jref clazz = NPP_GetJavaClass();
00068     if (clazz) {
00069               JRIEnv* env = NPN_GetJavaEnv();
00070               return JRI_NewGlobalRef(env, clazz);
00071     }
00072     return NULL;
00073 }
00074 #endif /* OJI */
00075 //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\.
00077 //                                        PLUGIN DLL entry points   
00078 //
00079 // These are the Windows specific DLL entry points. They must be exoprted
00080 //
00081 
00082 // we need these to be global since we have to fill one of its field
00083 // with a data (class) which requires knowlwdge of the navigator
00084 // jump-table. This jump table is known at Initialize time (NP_Initialize)
00085 // which is called after NP_GetEntryPoint
00086 static NPPluginFuncs* g_pluginFuncs;
00087 
00088 //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\.
00090 // NP_GetEntryPoints
00091 //
00092 //     fills in the func table used by Navigator to call entry points in
00093 //  plugin DLL.  Note that these entry points ensure that DS is loaded
00094 //  by using the NP_LOADDS macro, when compiling for Win16
00095 //
00096 NPError OSCALL NP_EXPORT
00097 NP_GetEntryPoints(NPPluginFuncs* pFuncs)
00098 {
00099     // trap a NULL ptr 
00100     if(pFuncs == NULL)
00101         return NPERR_INVALID_FUNCTABLE_ERROR;
00102 
00103     // if the plugin's function table is smaller than the plugin expects,
00104     // then they are incompatible, and should return an error 
00105 
00106     pFuncs->version       = (NP_VERSION_MAJOR << 8) | NP_VERSION_MINOR;
00107     pFuncs->newp          = NPP_New;
00108     pFuncs->destroy       = NPP_Destroy;
00109     pFuncs->setwindow     = NPP_SetWindow;
00110     pFuncs->newstream     = NPP_NewStream;
00111     pFuncs->destroystream = NPP_DestroyStream;
00112     pFuncs->asfile        = NPP_StreamAsFile;
00113     pFuncs->writeready    = NPP_WriteReady;
00114     pFuncs->write         = NPP_Write;
00115     pFuncs->print         = NPP_Print;
00116     pFuncs->event         = 0;       
00117 
00118        g_pluginFuncs          = pFuncs;
00119 
00120     return NPERR_NO_ERROR;
00121 }
00122 
00123 //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\.
00125 // NP_Initialize
00126 //
00127 //     called immediately after the plugin DLL is loaded
00128 //
00129 NPError OSCALL NP_EXPORT 
00130 NP_Initialize(NPNetscapeFuncs* pFuncs)
00131 {
00132     // trap a NULL ptr 
00133     if(pFuncs == NULL)
00134         return NPERR_INVALID_FUNCTABLE_ERROR;
00135 
00136     g_pNavigatorFuncs = pFuncs; // save it for future reference 
00137 
00138     // if the plugin's major ver level is lower than the Navigator's,
00139     // then they are incompatible, and should return an error 
00140     if(HIBYTE(pFuncs->version) > NP_VERSION_MAJOR)
00141         return NPERR_INCOMPATIBLE_VERSION_ERROR;
00142 
00143        // We have to defer these assignments until g_pNavigatorFuncs is set
00144     int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
00145 
00146        if( navMinorVers >= NPVERS_HAS_NOTIFICATION ) {
00147               g_pluginFuncs->urlnotify = NPP_URLNotify;
00148        }
00149 #ifdef OJI    
00150        if( navMinorVers >= NPVERS_HAS_LIVECONNECT ) {
00151               g_pluginFuncs->javaClass = Private_GetJavaClass();
00152        }
00153 #endif
00154        // NPP_Initialize is a standard (cross-platform) initialize function.
00155     return NPP_Initialize();
00156 }
00157 
00158 //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\.
00160 // NP_Shutdown
00161 //
00162 //     called immediately before the plugin DLL is unloaded.
00163 //     This functio shuold check for some ref count on the dll to see if it is
00164 //     unloadable or it needs to stay in memory. 
00165 //
00166 NPError OSCALL NP_EXPORT 
00167 NP_Shutdown()
00168 {
00169     NPP_Shutdown();
00170     g_pNavigatorFuncs = NULL;
00171     return NPERR_NO_ERROR;
00172 }
00173 
00174 char * NP_GetMIMEDescription()
00175 {
00176     static char mimetype[] = NS_PLUGIN_DEFAULT_MIME_DESCRIPTION;
00177     return mimetype;
00178 }
00179 
00180 //                                        END - PLUGIN DLL entry points   
00182 //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\.
00183 
00184 /*    NAVIGATOR Entry points    */
00185 
00186 /* These entry points expect to be called from within the plugin.  The
00187    noteworthy assumption is that DS has already been set to point to the
00188    plugin's DLL data segment.  Don't call these functions from outside
00189    the plugin without ensuring DS is set to the DLLs data segment first,
00190    typically using the NP_LOADDS macro
00191 */
00192 
00193 /* returns the major/minor version numbers of the Plugin API for the plugin
00194    and the Navigator
00195 */
00196 void NPN_Version(int* plugin_major, int* plugin_minor, int* netscape_major, int* netscape_minor)
00197 {
00198     *plugin_major   = NP_VERSION_MAJOR;
00199     *plugin_minor   = NP_VERSION_MINOR;
00200     *netscape_major = HIBYTE(g_pNavigatorFuncs->version);
00201     *netscape_minor = LOBYTE(g_pNavigatorFuncs->version);
00202 }
00203 
00204 NPError NPN_GetValue(NPP instance, NPNVariable variable, void *result)
00205 {
00206     return g_pNavigatorFuncs->getvalue(instance, variable, result);
00207 }
00208 
00209 
00210 /* causes the specified URL to be fetched and streamed in
00211 */
00212 NPError NPN_GetURLNotify(NPP instance, const char *url, const char *target, void* notifyData)
00213 
00214 {
00215        int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
00216        NPError err;
00217        if( navMinorVers >= NPVERS_HAS_NOTIFICATION ) {
00218               err = g_pNavigatorFuncs->geturlnotify(instance, url, target, notifyData);
00219        }
00220        else {
00221               err = NPERR_INCOMPATIBLE_VERSION_ERROR;
00222        }
00223        return err;
00224 }
00225 
00226 
00227 NPError NPN_GetURL(NPP instance, const char *url, const char *target)
00228 {
00229     return g_pNavigatorFuncs->geturl(instance, url, target);
00230 }
00231 
00232 NPError NPN_PostURLNotify(NPP instance, const char* url, const char* window, uint32 len, const char* buf, NPBool file, void* notifyData)
00233 {
00234        int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
00235        NPError err;
00236        if( navMinorVers >= NPVERS_HAS_NOTIFICATION ) {
00237               err = g_pNavigatorFuncs->posturlnotify(instance, url, window, len, buf, file, notifyData);
00238        }
00239        else {
00240               err = NPERR_INCOMPATIBLE_VERSION_ERROR;
00241        }
00242        return err;
00243 }
00244 
00245 
00246 NPError NPN_PostURL(NPP instance, const char* url, const char* window, uint32 len, const char* buf, NPBool file)
00247 {
00248     return g_pNavigatorFuncs->posturl(instance, url, window, len, buf, file);
00249 }
00250 
00251 /* Requests that a number of bytes be provided on a stream.  Typically
00252    this would be used if a stream was in "pull" mode.  An optional
00253    position can be provided for streams which are seekable.
00254 */
00255 NPError NPN_RequestRead(NPStream* stream, NPByteRange* rangeList)
00256 {
00257     return g_pNavigatorFuncs->requestread(stream, rangeList);
00258 }
00259 
00260 /* Creates a new stream of data from the plug-in to be interpreted
00261    by Netscape in the current window.
00262 */
00263 NPError NPN_NewStream(NPP instance, NPMIMEType type, 
00264                                                         const char* target, NPStream** stream)
00265 {
00266        int navMinorVersion = g_pNavigatorFuncs->version & 0xFF;
00267        NPError err;
00268 
00269        if( navMinorVersion >= NPVERS_HAS_STREAMOUTPUT ) {
00270               err = g_pNavigatorFuncs->newstream(instance, type, target, stream);
00271        }
00272        else {
00273               err = NPERR_INCOMPATIBLE_VERSION_ERROR;
00274        }
00275        return err;
00276 }
00277 
00278 /* Provides len bytes of data.
00279 */
00280 int32 NPN_Write(NPP instance, NPStream *stream,
00281                 int32 len, void *buffer)
00282 {
00283        int navMinorVersion = g_pNavigatorFuncs->version & 0xFF;
00284        int32 result;
00285 
00286        if( navMinorVersion >= NPVERS_HAS_STREAMOUTPUT ) {
00287               result = g_pNavigatorFuncs->write(instance, stream, len, buffer);
00288        }
00289        else {
00290               result = -1;
00291        }
00292        return result;
00293 }
00294 
00295 /* Closes a stream object.  
00296 reason indicates why the stream was closed.
00297 */
00298 NPError NPN_DestroyStream(NPP instance, NPStream* stream, NPError reason)
00299 {
00300        int navMinorVersion = g_pNavigatorFuncs->version & 0xFF;
00301        NPError err;
00302 
00303        if( navMinorVersion >= NPVERS_HAS_STREAMOUTPUT ) {
00304               err = g_pNavigatorFuncs->destroystream(instance, stream, reason);
00305        }
00306        else {
00307               err = NPERR_INCOMPATIBLE_VERSION_ERROR;
00308        }
00309        return err;
00310 }
00311 
00312 /* Provides a text status message in the Netscape client user interface
00313 */
00314 void NPN_Status(NPP instance, const char *message)
00315 {
00316     g_pNavigatorFuncs->status(instance, message);
00317 }
00318 
00319 /* returns the user agent string of Navigator, which contains version info
00320 */
00321 const char* NPN_UserAgent(NPP instance)
00322 {
00323     return g_pNavigatorFuncs->uagent(instance);
00324 }
00325 
00326 /* allocates memory from the Navigator's memory space.  Necessary so that
00327    saved instance data may be freed by Navigator when exiting.
00328 */
00329 
00330 
00331 void* NPN_MemAlloc(uint32 size)
00332 {
00333     return g_pNavigatorFuncs->memalloc(size);
00334 }
00335 
00336 /* reciprocal of MemAlloc() above
00337 */
00338 void NPN_MemFree(void* ptr)
00339 {
00340     g_pNavigatorFuncs->memfree(ptr);
00341 }
00342 #ifdef OJI
00343 /* private function to Netscape.  do not use!
00344 */
00345 void NPN_ReloadPlugins(NPBool reloadPages)
00346 {
00347     g_pNavigatorFuncs->reloadplugins(reloadPages);
00348 }
00349 
00350 JRIEnv* NPN_GetJavaEnv(void)
00351 {
00352        return g_pNavigatorFuncs->getJavaEnv();
00353 }
00354 
00355 jref NPN_GetJavaPeer(NPP instance)
00356 {
00357        return g_pNavigatorFuncs->getJavaPeer(instance);
00358 }
00359 #endif
00360