Main Page | Modules | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

npwin.cpp

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

Generated on Tue Dec 20 10:14:59 2005 for vlc-0.8.4a by  doxygen 1.4.2