Back to index

lightning-sunbird  0.9+nobinonly
npp_gate.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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.org 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 "windows.h"
00039 
00040 #include "npupp.h"
00041 #include "npapi.h"
00042 #include "plugin.h"
00043 #include "dbg.h"
00044 
00045 nsPluginThread * thePluginThread = NULL;
00046 
00047 jref NPP_GetJavaClass ()
00048 {
00049   dbgOut1("wrapper: NPP_GetJavaClass");
00050   jref rv = (jref)thePluginThread->callNPP(action_npp_get_java_class);
00051   return NULL;
00052 }
00053 
00054 NPError NPP_New(NPMIMEType aType,
00055                 NPP aInstance,
00056                 uint16 aMode,
00057                 int16 aArgc,
00058                 char* aArgn[],
00059                 char* aArgv[],
00060                 NPSavedData* aSaved)
00061 {   
00062   dbgOut1("wrapper: NPP_New");
00063 
00064   NPError rv = NPERR_NO_ERROR;
00065 
00066   // lamely assuming there is only one embed tag on the page!
00067   
00068   // if it is first time in, we don't have it yet
00069   // initiate a thread with plugin running in it
00070   thePluginThread = new nsPluginThread((DWORD)aType);
00071 
00072   if (!thePluginThread)
00073     return NPERR_GENERIC_ERROR;
00074 
00075   rv = (NPError)thePluginThread->callNPP(action_npp_new, 
00076                                          (DWORD)aType, 
00077                                          (DWORD)aInstance, 
00078                                          (DWORD)aMode, 
00079                                          (DWORD)aArgc, 
00080                                          (DWORD)aArgn, 
00081                                          (DWORD)aArgv, 
00082                                          (DWORD)aSaved);
00083 
00084   return rv;
00085 }
00086 
00087 NPError NPP_Destroy (NPP aInstance, NPSavedData** aSave)
00088 {
00089   dbgOut1("wrapper: NPP_Destroy");
00090 
00091   if (!thePluginThread)
00092     return NPERR_GENERIC_ERROR;
00093 
00094   NPError ret = (NPError)thePluginThread->callNPP(action_npp_destroy, (DWORD)aInstance, (DWORD)aSave);
00095 
00096   delete thePluginThread;
00097   thePluginThread = NULL;
00098 
00099   return ret;
00100 }
00101 
00102 NPError NPP_SetWindow (NPP aInstance, NPWindow* aNPWindow)
00103 {    
00104   dbgOut1("wrapper: NPP_SetWindow");
00105 
00106   NPError rv = (NPError)thePluginThread->callNPP(action_npp_set_window, (DWORD)aInstance, (DWORD)aNPWindow);
00107   return rv;
00108 }
00109 
00110 NPError NPP_NewStream(NPP aInstance,
00111                       NPMIMEType aType,
00112                       NPStream* aStream, 
00113                       NPBool aSeekable,
00114                       uint16* aStype)
00115 {
00116   dbgOut1("wrapper: NPP_NewStream");
00117 
00118   NPError rv = (NPError)thePluginThread->callNPP(action_npp_new_stream, (DWORD)aInstance, (DWORD)aType, (DWORD)aStream, (DWORD)aSeekable, (DWORD)aStype);
00119   return rv;
00120 }
00121 
00122 int32 NPP_WriteReady (NPP aInstance, NPStream *aStream)
00123 {
00124   dbgOut1("wrapper: NPP_WriteReady");
00125 
00126   int32 rv = (int32)thePluginThread->callNPP(action_npp_write_ready, (DWORD)aInstance, (DWORD)aStream);
00127   return rv;
00128 }
00129 
00130 int32 NPP_Write (NPP aInstance, NPStream *aStream, int32 aOffset, int32 len, void *aBuffer)
00131 {   
00132   dbgOut1("wrapper: NPP_Write");
00133 
00134   int32 rv = (int32)thePluginThread->callNPP(action_npp_write, (DWORD)aInstance, (DWORD)aStream, (DWORD)aOffset, (DWORD)len, (DWORD)aBuffer);
00135   return rv;
00136 }
00137 
00138 NPError NPP_DestroyStream (NPP aInstance, NPStream *aStream, NPError aReason)
00139 {
00140   dbgOut1("wrapper: NPP_DestroyStream");
00141 
00142   NPError rv = (NPError)thePluginThread->callNPP(action_npp_destroy_stream, (DWORD)aInstance, (DWORD)aStream, (DWORD)aReason);
00143   return rv;
00144 }
00145 
00146 void NPP_StreamAsFile (NPP aInstance, NPStream* aStream, const char* aName)
00147 {
00148   dbgOut1("wrapper: NPP_StreamAsFile");
00149 
00150   thePluginThread->callNPP(action_npp_stream_as_file, (DWORD)aInstance, (DWORD)aStream, (DWORD)aName);
00151 }
00152 
00153 void NPP_Print (NPP aInstance, NPPrint* aPrintInfo)
00154 {
00155   dbgOut1("wrapper: NPP_Print");
00156 
00157   thePluginThread->callNPP(action_npp_print, (DWORD)aInstance, (DWORD)aPrintInfo);
00158 }
00159 
00160 void NPP_URLNotify(NPP aInstance, const char* aUrl, NPReason aReason, void* aNotifyData)
00161 {
00162   dbgOut1("wrapper: NPP_URLNotify");
00163 
00164   thePluginThread->callNPP(action_npp_url_notify, (DWORD)aInstance, (DWORD)aUrl, (DWORD)aReason, (DWORD)aNotifyData);
00165 }
00166 
00167 NPError       NPP_GetValue(NPP aInstance, NPPVariable aVariable, void *aValue)
00168 {
00169   dbgOut1("wrapper: NPP_GetValue");
00170 
00171   NPError rv = (NPError)thePluginThread->callNPP(action_npp_get_value, (DWORD)aInstance, (DWORD)aVariable, (DWORD)aValue);
00172   return rv;
00173 }
00174 
00175 NPError NPP_SetValue(NPP aInstance, NPNVariable aVariable, void *aValue)
00176 {
00177   dbgOut1("wrapper: NPP_SetValue");
00178 
00179   NPError rv = (NPError)thePluginThread->callNPP(action_npp_set_value, (DWORD)aInstance, (DWORD)aVariable, (DWORD)aValue);
00180   return rv;
00181 }
00182 
00183 int16  NPP_HandleEvent(NPP aInstance, void* aEvent)
00184 {
00185   dbgOut1("wrapper: NPP_HandleEvent");
00186 
00187   int16 rv = (int16)thePluginThread->callNPP(action_npp_handle_event, (DWORD)aInstance, (DWORD)aEvent);
00188   return rv;
00189 }