merged tag ooo/OOO330_m14
[LibreOffice.git] / extensions / source / plugin / win / sysplug.cxx
blob1d117f6927d5c1cec97008e35e43c98e8a7cfb89
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_extensions.hxx"
31 #include <plugin/impl.hxx>
33 #pragma warning (push,1)
34 #pragma warning (disable:4005)
36 #include <tools/prewin.h>
38 #include <windows.h>
39 #include <string.h>
40 #include <tchar.h>
41 #include <winreg.h>
42 #include <winbase.h>
43 #include <objbase.h>
45 #include <tools/postwin.h>
47 #pragma warning (pop)
49 #include <list>
50 #include <map>
51 #include <algorithm>
54 extern NPNetscapeFuncs aNPNFuncs;
56 #include <tools/debug.hxx>
58 using namespace rtl;
60 #if OSL_DEBUG_LEVEL > 1
61 void TRACE( char const * s );
62 void TRACEN( char const * s, long n );
63 #else
64 #define TRACE(x)
65 #define TRACEN(x,n)
66 #endif
69 //--------------------------------------------------------------------------------------------------
70 PluginComm_Impl::PluginComm_Impl( const OUString& /*rMIME*/, const OUString& rName, HWND /*hWnd*/ )
71 : PluginComm( OUStringToOString( rName, RTL_TEXTENCODING_MS_1252 ) )
73 // initialize plugin function table
74 memset( &_NPPfuncs, 0, sizeof( _NPPfuncs ) );
75 #ifdef UNICODE
76 _plDLL = ::LoadLibrary( rName.getStr() );
77 #else
78 OString aStr( OUStringToOString( rName, RTL_TEXTENCODING_MS_1252 ) );
79 _plDLL = ::LoadLibrary( aStr.getStr() );
80 #endif
81 DBG_ASSERT( _plDLL, "### loading plugin dll failed!" );
83 NPError nErr = NPERR_NO_ERROR;
84 NPError (WINAPI * pEntry)( NPPluginFuncs* );
85 retrieveFunction( _T("NP_GetEntryPoints"), (void**)&pEntry );
87 _NPPfuncs.size = sizeof( _NPPfuncs );
88 _NPPfuncs.version = 0;
89 nErr = (*pEntry)( &_NPPfuncs );
91 DBG_ASSERT( nErr == NPERR_NO_ERROR, "### NP_GetEntryPoints() failed!" );
92 DBG_ASSERT( (_NPPfuncs.version >> 8) >= NP_VERSION_MAJOR,
93 "### version failure!" );
95 m_eCall = eNP_Initialize;
96 execute();
99 //--------------------------------------------------------------------------------------------------
100 PluginComm_Impl::~PluginComm_Impl()
102 if (_plDLL)
104 // NPP_Shutdown();
106 NPError (WINAPI * pShutdown)();
107 if (retrieveFunction( _T("NP_Shutdown"), (void**)&pShutdown ))
109 NPError nErr = (*pShutdown)(); (void)nErr;
110 DBG_ASSERT( nErr == NPERR_NO_ERROR, "### NP_Shutdown() failed!" );
113 BOOL bRet = (BOOL)::FreeLibrary( _plDLL ); (void)bRet;
114 DBG_ASSERT( bRet, "### unloading plugin dll failed!" );
115 _plDLL = NULL;
119 //--------------------------------------------------------------------------------------------------
120 BOOL PluginComm_Impl::retrieveFunction( TCHAR* pName, void** ppFunc ) const
122 if( ! _plDLL )
123 return FALSE;
125 *ppFunc = (void*)::GetProcAddress( _plDLL, pName );
127 return (*ppFunc != NULL);
130 //--------------------------------------------------------------------------------------------------
132 long PluginComm_Impl::doIt()
134 long nRet = 0;
135 switch( m_eCall )
137 case eNP_Initialize:
139 TRACE( "eNP_Initialize" );
140 NPError (WINAPI * pInit)( NPNetscapeFuncs* );
141 if ((_NPPfuncs.version >> 8) >= NP_VERSION_MAJOR &&
142 (retrieveFunction( _T("NP_Initialize"), (void**)&pInit ) ||
143 retrieveFunction( _T("NP_PluginInit"), (void**)&pInit )))
145 nRet = (*pInit)( &aNPNFuncs );
147 else
149 nRet = NPERR_GENERIC_ERROR;
151 DBG_ASSERT( nRet == NPERR_NO_ERROR, "### NP_Initialize() failed!" );
153 break;
154 case eNPP_Destroy:
155 TRACE( "eNPP_Destroy" );
156 nRet = (_NPPfuncs.destroy
157 ? (*_NPPfuncs.destroy)(
158 (NPP)m_aArgs[0],
159 (NPSavedData**)m_aArgs[1] )
160 : NPERR_GENERIC_ERROR);
161 break;
162 case eNPP_DestroyStream:
163 TRACE( "eNPP_DestroyStream" );
164 nRet = (_NPPfuncs.destroystream
165 ? (*_NPPfuncs.destroystream)(
166 (NPP)m_aArgs[0],
167 (NPStream*)m_aArgs[1],
168 (NPError)(sal_IntPtr)m_aArgs[2] )
169 : NPERR_GENERIC_ERROR);
170 break;
171 case eNPP_New:
172 TRACE( "eNPP_New" );
173 nRet = (_NPPfuncs.newp
174 ? (*_NPPfuncs.newp)(
175 (NPMIMEType)m_aArgs[0],
176 (NPP)m_aArgs[1],
177 (uint16)(sal_IntPtr)m_aArgs[2],
178 (int16)(sal_IntPtr)m_aArgs[3],
179 (char**)m_aArgs[4],
180 (char**)m_aArgs[5],
181 (NPSavedData*)m_aArgs[6] )
182 : NPERR_GENERIC_ERROR);
183 break;
184 case eNPP_NewStream:
185 TRACE( "eNPP_NewStream" );
186 nRet = (_NPPfuncs.newstream
187 ? (*_NPPfuncs.newstream)(
188 (NPP)m_aArgs[0],
189 (NPMIMEType)m_aArgs[1],
190 (NPStream*)m_aArgs[2],
191 (NPBool)(sal_IntPtr)m_aArgs[3],
192 (uint16*)m_aArgs[4] )
193 : NPERR_GENERIC_ERROR);
194 break;
195 case eNPP_Print:
196 TRACE( "eNPP_Print" );
197 if (_NPPfuncs.print)
198 (*_NPPfuncs.print)(
199 (NPP)m_aArgs[0],
200 (NPPrint*)m_aArgs[1] );
201 break;
202 case eNPP_SetWindow:
204 TRACE( "eNPP_SetWindow" );
205 nRet = (_NPPfuncs.setwindow
206 ? (*_NPPfuncs.setwindow)(
207 (NPP)m_aArgs[0],
208 (NPWindow*)m_aArgs[1] )
209 : NPERR_GENERIC_ERROR);
210 break;
212 case eNPP_StreamAsFile:
213 TRACE( "eNPP_StreamAsFile" );
214 if (_NPPfuncs.asfile)
215 (*_NPPfuncs.asfile)(
216 (NPP)m_aArgs[0],
217 (NPStream*)m_aArgs[1],
218 (char*)m_aArgs[2] );
219 break;
220 case eNPP_URLNotify:
221 TRACE( "eNPP_URLNotify" );
222 if (_NPPfuncs.urlnotify)
223 (*_NPPfuncs.urlnotify)(
224 (NPP)m_aArgs[0],
225 (char*)m_aArgs[1],
226 (NPReason)(sal_IntPtr)m_aArgs[2],
227 m_aArgs[3] );
228 break;
229 case eNPP_Write:
230 TRACEN( "eNPP_Write n=", (int32)m_aArgs[3] );
231 nRet = (_NPPfuncs.write
232 ? (*_NPPfuncs.write)(
233 (NPP)m_aArgs[0],
234 (NPStream*)m_aArgs[1],
235 (int32)m_aArgs[2],
236 (int32)m_aArgs[3],
237 m_aArgs[4] )
238 : 0);
239 break;
240 case eNPP_WriteReady:
241 TRACE( "eNPP_WriteReady" );
242 nRet = (_NPPfuncs.writeready
243 ? (*_NPPfuncs.writeready)(
244 (NPP)m_aArgs[0],
245 (NPStream*)m_aArgs[1] )
246 : 0);
247 break;
248 case eNPP_GetValue:
249 TRACE( "eNPP_GetValue" );
250 nRet = (_NPPfuncs.getvalue
251 ? (*_NPPfuncs.getvalue)(
252 (NPP)m_aArgs[0],
253 (NPPVariable)(int)m_aArgs[1],
254 m_aArgs[2] )
255 : NPERR_GENERIC_ERROR);
256 break;
257 case eNPP_SetValue:
258 TRACE( "eNPP_SetValue" );
259 nRet = (_NPPfuncs.setvalue
260 ? (*_NPPfuncs.setvalue)(
261 (NPP)m_aArgs[0],
262 (NPNVariable)(int)m_aArgs[1],
263 m_aArgs[2] )
264 : NPERR_GENERIC_ERROR);
265 break;
266 case eNPP_Shutdown:
268 TRACE( "eNPP_Shutdown" );
269 NPP_ShutdownUPP pFunc;
270 if (retrieveFunction( _T("NPP_Shutdown"), (void**)&pFunc ))
271 (*pFunc)();
273 break;
274 case eNPP_Initialize:
275 TRACE( "eNPP_Initialize" );
276 OSL_ENSURE( false, "NPP_Initialize: not implemented!" );
277 break;
278 case eNPP_GetJavaClass:
279 TRACE( "eNPP_GetJavaClass" );
280 OSL_ENSURE( false, "NPP_GetJavaClass: not implemented!" );
281 break;
283 return nRet;
286 //--------------------------------------------------------------------------------------------------
287 NPError PluginComm_Impl::NPP_Destroy( NPP instance, NPSavedData** save )
289 DBG_ASSERT( _NPPfuncs.destroy, "### NPP_Destroy(): null pointer in NPP functions table!" );
290 m_eCall = eNPP_Destroy;
291 m_aArgs[0] = (void*)instance;
292 m_aArgs[1] = (void*)save;
293 return (NPError)execute();
296 //--------------------------------------------------------------------------------------------------
297 NPError PluginComm_Impl::NPP_DestroyStream( NPP instance, NPStream* stream, NPError reason )
299 DBG_ASSERT( _NPPfuncs.destroystream, "### NPP_DestroyStream(): null pointer in NPP functions table!" );
300 m_eCall = eNPP_DestroyStream;
301 m_aArgs[0] = (void*)instance;
302 m_aArgs[1] = (void*)stream;
303 m_aArgs[2] = (void*)reason;
304 return (NPError)execute();
307 //--------------------------------------------------------------------------------------------------
308 NPError PluginComm_Impl::NPP_New( NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc,
309 char* argn[], char* argv[], NPSavedData *saved )
311 DBG_ASSERT( _NPPfuncs.newp, "### NPP_New(): null pointer in NPP functions table!" );
312 m_eCall = eNPP_New;
313 m_aArgs[0] = (void*)pluginType;
314 m_aArgs[1] = (void*)instance;
315 m_aArgs[2] = (void*)mode;
316 m_aArgs[3] = (void*)argc;
317 m_aArgs[4] = (void*)argn;
318 m_aArgs[5] = (void*)argv;
319 m_aArgs[6] = (void*)saved;
320 return (NPError)execute();
323 //--------------------------------------------------------------------------------------------------
324 NPError PluginComm_Impl::NPP_NewStream( NPP instance, NPMIMEType type, NPStream* stream,
325 NPBool seekable, uint16* stype )
327 DBG_ASSERT( _NPPfuncs.newstream, "### NPP_NewStream(): null pointer in NPP functions table!" );
328 m_eCall = eNPP_NewStream;
329 m_aArgs[0] = (void*)instance;
330 m_aArgs[1] = (void*)type;
331 m_aArgs[2] = (void*)stream;
332 m_aArgs[3] = (void*)seekable;
333 m_aArgs[4] = (void*)stype;
334 return (NPError)execute();
337 //--------------------------------------------------------------------------------------------------
338 void PluginComm_Impl::NPP_Print( NPP instance, NPPrint* platformPrint )
340 DBG_ASSERT( _NPPfuncs.print, "### NPP_Print(): null pointer in NPP functions table!" );
341 m_eCall = eNPP_Print;
342 m_aArgs[0] = (void*)instance;
343 m_aArgs[1] = (void*)platformPrint;
344 execute();
347 //--------------------------------------------------------------------------------------------------
348 NPError PluginComm_Impl::NPP_SetWindow( NPP instance, NPWindow* window )
350 DBG_ASSERT( _NPPfuncs.setwindow, "### NPP_SetWindow(): null pointer in NPP functions table!" );
351 m_eCall = eNPP_SetWindow;
352 m_aArgs[0] = (void*)instance;
353 m_aArgs[1] = (void*)window;
354 return (NPError)execute();
357 //--------------------------------------------------------------------------------------------------
358 void PluginComm_Impl::NPP_StreamAsFile( NPP instance, NPStream* stream, const char* fname )
360 DBG_ASSERT( _NPPfuncs.asfile, "### NPP_StreamAsFile(): null pointer in NPP functions table!" );
361 m_eCall = eNPP_StreamAsFile;
362 m_aArgs[0] = (void*)instance;
363 m_aArgs[1] = (void*)stream;
364 m_aArgs[2] = (void*)fname;
365 execute();
368 //--------------------------------------------------------------------------------------------------
369 void PluginComm_Impl::NPP_URLNotify( NPP instance, const char* url, NPReason reason, void* notifyData )
371 DBG_ASSERT( _NPPfuncs.urlnotify, "### NPP_URLNotify(): null pointer in NPP functions table!" );
372 m_eCall = eNPP_URLNotify;
373 m_aArgs[0] = (void*)instance;
374 m_aArgs[1] = (void*)url;
375 m_aArgs[2] = (void*)reason;
376 m_aArgs[3] = notifyData;
377 execute();
380 //--------------------------------------------------------------------------------------------------
381 int32 PluginComm_Impl::NPP_Write( NPP instance, NPStream* stream, int32 offset, int32 len, void* buffer )
383 DBG_ASSERT( _NPPfuncs.write, "### NPP_Write(): null pointer in NPP functions table!" );
384 m_eCall = eNPP_Write;
385 m_aArgs[0] = (void*)instance;
386 m_aArgs[1] = (void*)stream;
387 m_aArgs[2] = (void*)offset;
388 m_aArgs[3] = (void*)len;
389 m_aArgs[4] = buffer;
390 return (NPError)execute();
393 //--------------------------------------------------------------------------------------------------
394 int32 PluginComm_Impl::NPP_WriteReady( NPP instance, NPStream* stream )
396 DBG_ASSERT( _NPPfuncs.writeready, "### NPP_WriteReady(): null pointer in NPP functions table!" );
397 m_eCall = eNPP_WriteReady;
398 m_aArgs[0] = (void*)instance;
399 m_aArgs[1] = (void*)stream;
400 return execute();
403 //--------------------------------------------------------------------------------------------------
404 NPError PluginComm_Impl::NPP_GetValue( NPP instance, NPPVariable variable, void *ret_value )
406 DBG_ASSERT( _NPPfuncs.getvalue, "### NPP_GetValue(): null pointer in NPP functions table!" );
407 m_eCall = eNPP_GetValue;
408 m_aArgs[0] = (void*)instance;
409 m_aArgs[1] = (void*)variable;
410 m_aArgs[2] = ret_value;
411 return (NPError)execute();
414 //--------------------------------------------------------------------------------------------------
415 NPError PluginComm_Impl::NPP_SetValue( NPP instance, NPNVariable variable, void *set_value )
417 DBG_ASSERT( _NPPfuncs.setvalue, "### NPP_SetValue(): null pointer in NPP functions table!" );
418 m_eCall = eNPP_SetValue;
419 m_aArgs[0] = (void*)instance;
420 m_aArgs[1] = (void*)variable;
421 m_aArgs[2] = set_value;
422 return (NPError)execute();
425 //--------------------------------------------------------------------------------------------------
426 void * PluginComm_Impl::NPP_GetJavaClass()
428 DBG_ERROR( "no java class available!" );
429 return 0;
432 //--------------------------------------------------------------------------------------------------
433 NPError PluginComm_Impl::NPP_Initialize()
435 return NPERR_NO_ERROR;
438 //--------------------------------------------------------------------------------------------------
439 void PluginComm_Impl::NPP_Shutdown()
441 m_eCall = eNPP_Shutdown;
442 execute();