1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
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/
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
15 * The Original Code is mozilla.org code.
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.
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.
36 * ***** END LICENSE BLOCK ***** */
40 #include "npfunctions.h"
46 extern NPNetscapeFuncs NPNFuncs
;
47 NPNetscapeFuncs wrapperNPNFuncs
;
48 NPPluginFuncs pluginNPPFuncs
;
50 typedef NPError (__stdcall
* NP_GETENTRYPOINTS
)(NPPluginFuncs
*);
51 typedef NPError (__stdcall
* NP_INITIALIZE
)(NPNetscapeFuncs
*);
52 typedef NPError (__stdcall
* NP_SHUTDOWN
)(void);
54 NP_SHUTDOWN plugin_NP_Shutdown
= NULL
;
55 HINSTANCE pluginLibrary
= NULL
;
57 nsPluginThread::nsPluginThread(DWORD aP1
) : CThread(),
66 dbgOut1("nsPluginThread::nsPluginThread");
71 nsPluginThread::~nsPluginThread()
73 dbgOut1("nsPluginThread::~nsPluginThread");
78 BOOL
nsPluginThread::init()
80 dbgOut1("nsPluginThread::init");
82 // scan plugins dir for available plugins to see if we have anything
83 // for the given mimetype
84 pluginLibrary
= LoadRealPlugin((NPMIMEType
)mP1
);
88 NP_GETENTRYPOINTS plugin_NP_GetEntryPoints
= (NP_GETENTRYPOINTS
)GetProcAddress(pluginLibrary
, "NP_GetEntryPoints");
89 if(!plugin_NP_GetEntryPoints
)
92 NP_INITIALIZE plugin_NP_Initialize
= (NP_INITIALIZE
)GetProcAddress(pluginLibrary
, "NP_Initialize");
93 if(!plugin_NP_Initialize
)
96 plugin_NP_Shutdown
= (NP_SHUTDOWN
)GetProcAddress(pluginLibrary
, "NP_Shutdown");
97 if(!plugin_NP_Shutdown
)
100 // fill callbacks structs
101 memset(&pluginNPPFuncs
, 0, sizeof(NPPluginFuncs
));
102 pluginNPPFuncs
.size
= sizeof(NPPluginFuncs
);
104 plugin_NP_GetEntryPoints(&pluginNPPFuncs
);
106 // inform the plugin about our entry point it should call
107 memset((void *)&wrapperNPNFuncs
, 0, sizeof(wrapperNPNFuncs
));
108 wrapperNPNFuncs
.size
= sizeof(wrapperNPNFuncs
);
109 wrapperNPNFuncs
.version
= NPNFuncs
.version
;
110 wrapperNPNFuncs
.geturlnotify
= NPN_GetURLNotify
;
111 wrapperNPNFuncs
.geturl
= NPN_GetURL
;
112 wrapperNPNFuncs
.posturlnotify
= NPN_PostURLNotify
;
113 wrapperNPNFuncs
.posturl
= NPN_PostURL
;
114 wrapperNPNFuncs
.requestread
= NPN_RequestRead
;
115 wrapperNPNFuncs
.newstream
= NPN_NewStream
;
116 wrapperNPNFuncs
.write
= NPN_Write
;
117 wrapperNPNFuncs
.destroystream
= NPN_DestroyStream
;
118 wrapperNPNFuncs
.status
= NPN_Status
;
119 wrapperNPNFuncs
.uagent
= NPN_UserAgent
;
120 wrapperNPNFuncs
.memalloc
= NPN_MemAlloc
;
121 wrapperNPNFuncs
.memfree
= NPN_MemFree
;
122 wrapperNPNFuncs
.memflush
= NPN_MemFlush
;
123 wrapperNPNFuncs
.reloadplugins
= NPN_ReloadPlugins
;
124 wrapperNPNFuncs
.getJavaEnv
= NULL
;
125 wrapperNPNFuncs
.getJavaPeer
= NULL
;
126 wrapperNPNFuncs
.getvalue
= NPN_GetValue
;
127 wrapperNPNFuncs
.setvalue
= NPN_SetValue
;
128 wrapperNPNFuncs
.invalidaterect
= NPN_InvalidateRect
;
129 wrapperNPNFuncs
.invalidateregion
= NPN_InvalidateRegion
;
130 wrapperNPNFuncs
.forceredraw
= NPN_ForceRedraw
;
132 plugin_NP_Initialize(&wrapperNPNFuncs
);
137 void nsPluginThread::shut()
139 dbgOut1("nsPluginThread::shut");
141 if (!plugin_NP_Shutdown
)
142 plugin_NP_Shutdown();
145 UnloadRealPlugin(pluginLibrary
);
148 // NPP_ call translator
149 DWORD
nsPluginThread::callNPP(npapiAction aAction
, DWORD aP1
, DWORD aP2
,
150 DWORD aP3
, DWORD aP4
, DWORD aP5
,
151 DWORD aP6
, DWORD aP7
)
153 // don't enter untill thread is ready
168 // don't return untill thread is ready
173 return NPERR_NO_ERROR
;
175 void nsPluginThread::dispatch()
177 dbgOut2("nsPluginThread::dispatch: %s", FormatAction(mAction
));
181 pluginNPPFuncs
.newp((NPMIMEType
)mP1
, (NPP
)mP2
, (uint16
)mP3
, (int16
)mP4
, (char**)mP5
, (char**)mP6
, (NPSavedData
*)mP7
);
183 case action_npp_destroy
:
184 pluginNPPFuncs
.destroy((NPP
)mP1
, (NPSavedData
**)mP2
);
186 case action_npp_set_window
:
187 pluginNPPFuncs
.setwindow((NPP
)mP1
, (NPWindow
*)mP2
);
189 case action_npp_new_stream
:
190 pluginNPPFuncs
.newstream((NPP
)mP1
, (NPMIMEType
)mP2
, (NPStream
*)mP3
, (NPBool
)mP4
, (uint16
*)mP5
);
192 case action_npp_destroy_stream
:
194 NPStream
* stream
= (NPStream
*)mP2
;
195 pluginNPPFuncs
.destroystream((NPP
)mP1
, stream
, (NPError
)mP3
);
198 case action_npp_stream_as_file
:
200 NPStream
* stream
= (NPStream
*)mP2
;
201 pluginNPPFuncs
.asfile((NPP
)mP1
, stream
, (char*)mP3
);
204 case action_npp_write_ready
:
205 pluginNPPFuncs
.writeready((NPP
)mP1
, (NPStream
*)mP2
);
207 case action_npp_write
:
208 pluginNPPFuncs
.write((NPP
)mP1
, (NPStream
*)mP2
, (int32
)mP3
, (int32
)mP4
, (void *)mP5
);
210 case action_npp_print
:
211 pluginNPPFuncs
.print((NPP
)mP1
, (NPPrint
*)mP2
);
213 case action_npp_handle_event
:
214 pluginNPPFuncs
.event((NPP
)mP1
, (void *)mP2
);
216 case action_npp_url_notify
:
217 pluginNPPFuncs
.urlnotify((NPP
)mP1
, (const char*)mP2
, (NPReason
)mP3
, (void*)mP4
);
219 case action_npp_get_java_class
:
222 case action_npp_get_value
:
223 pluginNPPFuncs
.getvalue((NPP
)mP1
, (NPPVariable
)mP2
, (void *)mP3
);
225 case action_npp_set_value
:
226 pluginNPPFuncs
.setvalue((NPP
)mP1
, (NPNVariable
)mP2
, (void *)mP3
);
229 dbgOut1("Unexpected action!");