1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: sysplug.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_extensions.hxx"
34 #include <plugin/impl.hxx>
36 #pragma warning (push,1)
37 #pragma warning (disable:4005)
39 #include <tools/prewin.h>
48 #include <tools/postwin.h>
57 extern NPNetscapeFuncs aNPNFuncs
;
59 #include <tools/debug.hxx>
63 #if OSL_DEBUG_LEVEL > 1
64 void TRACE( char const * s
);
65 void TRACEN( char const * s
, long n
);
72 //--------------------------------------------------------------------------------------------------
73 PluginComm_Impl::PluginComm_Impl( const OUString
& /*rMIME*/, const OUString
& rName
, HWND
/*hWnd*/ )
74 : PluginComm( OUStringToOString( rName
, RTL_TEXTENCODING_MS_1252
) )
76 // initialize plugin function table
77 memset( &_NPPfuncs
, 0, sizeof( _NPPfuncs
) );
79 _plDLL
= ::LoadLibrary( rName
.getStr() );
81 OString
aStr( OUStringToOString( rName
, RTL_TEXTENCODING_MS_1252
) );
82 _plDLL
= ::LoadLibrary( aStr
.getStr() );
84 DBG_ASSERT( _plDLL
, "### loading plugin dll failed!" );
86 NPError nErr
= NPERR_NO_ERROR
;
87 NPError (WINAPI
* pEntry
)( NPPluginFuncs
* );
88 retrieveFunction( _T("NP_GetEntryPoints"), (void**)&pEntry
);
90 _NPPfuncs
.size
= sizeof( _NPPfuncs
);
91 _NPPfuncs
.version
= 0;
92 nErr
= (*pEntry
)( &_NPPfuncs
);
94 DBG_ASSERT( nErr
== NPERR_NO_ERROR
, "### NP_GetEntryPoints() failed!" );
95 DBG_ASSERT( (_NPPfuncs
.version
>> 8) >= NP_VERSION_MAJOR
,
96 "### version failure!" );
98 m_eCall
= eNP_Initialize
;
102 //--------------------------------------------------------------------------------------------------
103 PluginComm_Impl::~PluginComm_Impl()
109 NPError (WINAPI
* pShutdown
)();
110 if (retrieveFunction( _T("NP_Shutdown"), (void**)&pShutdown
))
112 NPError nErr
= (*pShutdown
)(); (void)nErr
;
113 DBG_ASSERT( nErr
== NPERR_NO_ERROR
, "### NP_Shutdown() failed!" );
116 BOOL bRet
= (BOOL
)::FreeLibrary( _plDLL
); (void)bRet
;
117 DBG_ASSERT( bRet
, "### unloading plugin dll failed!" );
122 //--------------------------------------------------------------------------------------------------
123 BOOL
PluginComm_Impl::retrieveFunction( TCHAR
* pName
, void** ppFunc
) const
128 *ppFunc
= (void*)::GetProcAddress( _plDLL
, pName
);
130 return (*ppFunc
!= NULL
);
133 //--------------------------------------------------------------------------------------------------
135 long PluginComm_Impl::doIt()
142 TRACE( "eNP_Initialize" );
143 NPError (WINAPI
* pInit
)( NPNetscapeFuncs
* );
144 if ((_NPPfuncs
.version
>> 8) >= NP_VERSION_MAJOR
&&
145 (retrieveFunction( _T("NP_Initialize"), (void**)&pInit
) ||
146 retrieveFunction( _T("NP_PluginInit"), (void**)&pInit
)))
148 nRet
= (*pInit
)( &aNPNFuncs
);
152 nRet
= NPERR_GENERIC_ERROR
;
154 DBG_ASSERT( nRet
== NPERR_NO_ERROR
, "### NP_Initialize() failed!" );
158 TRACE( "eNPP_Destroy" );
159 nRet
= (_NPPfuncs
.destroy
160 ? (*_NPPfuncs
.destroy
)(
162 (NPSavedData
**)m_aArgs
[1] )
163 : NPERR_GENERIC_ERROR
);
165 case eNPP_DestroyStream
:
166 TRACE( "eNPP_DestroyStream" );
167 nRet
= (_NPPfuncs
.destroystream
168 ? (*_NPPfuncs
.destroystream
)(
170 (NPStream
*)m_aArgs
[1],
171 (NPError
)(sal_IntPtr
)m_aArgs
[2] )
172 : NPERR_GENERIC_ERROR
);
176 nRet
= (_NPPfuncs
.newp
178 (NPMIMEType
)m_aArgs
[0],
180 (uint16
)(sal_IntPtr
)m_aArgs
[2],
181 (int16
)(sal_IntPtr
)m_aArgs
[3],
184 (NPSavedData
*)m_aArgs
[6] )
185 : NPERR_GENERIC_ERROR
);
188 TRACE( "eNPP_NewStream" );
189 nRet
= (_NPPfuncs
.newstream
190 ? (*_NPPfuncs
.newstream
)(
192 (NPMIMEType
)m_aArgs
[1],
193 (NPStream
*)m_aArgs
[2],
194 (NPBool
)(sal_IntPtr
)m_aArgs
[3],
195 (uint16
*)m_aArgs
[4] )
196 : NPERR_GENERIC_ERROR
);
199 TRACE( "eNPP_Print" );
203 (NPPrint
*)m_aArgs
[1] );
207 TRACE( "eNPP_SetWindow" );
208 nRet
= (_NPPfuncs
.setwindow
209 ? (*_NPPfuncs
.setwindow
)(
211 (NPWindow
*)m_aArgs
[1] )
212 : NPERR_GENERIC_ERROR
);
215 case eNPP_StreamAsFile
:
216 TRACE( "eNPP_StreamAsFile" );
217 if (_NPPfuncs
.asfile
)
220 (NPStream
*)m_aArgs
[1],
224 TRACE( "eNPP_URLNotify" );
225 if (_NPPfuncs
.urlnotify
)
226 (*_NPPfuncs
.urlnotify
)(
229 (NPReason
)(sal_IntPtr
)m_aArgs
[2],
233 TRACEN( "eNPP_Write n=", (int32
)m_aArgs
[3] );
234 nRet
= (_NPPfuncs
.write
235 ? (*_NPPfuncs
.write
)(
237 (NPStream
*)m_aArgs
[1],
243 case eNPP_WriteReady
:
244 TRACE( "eNPP_WriteReady" );
245 nRet
= (_NPPfuncs
.writeready
246 ? (*_NPPfuncs
.writeready
)(
248 (NPStream
*)m_aArgs
[1] )
252 TRACE( "eNPP_GetValue" );
253 nRet
= (_NPPfuncs
.getvalue
254 ? (*_NPPfuncs
.getvalue
)(
256 (NPPVariable
)(int)m_aArgs
[1],
258 : NPERR_GENERIC_ERROR
);
261 TRACE( "eNPP_SetValue" );
262 nRet
= (_NPPfuncs
.setvalue
263 ? (*_NPPfuncs
.setvalue
)(
265 (NPNVariable
)(int)m_aArgs
[1],
267 : NPERR_GENERIC_ERROR
);
271 TRACE( "eNPP_Shutdown" );
272 NPP_ShutdownUPP pFunc
;
273 if (retrieveFunction( _T("NPP_Shutdown"), (void**)&pFunc
))
277 case eNPP_Initialize
:
278 TRACE( "eNPP_Initialize" );
279 OSL_ENSURE( false, "NPP_Initialize: not implemented!" );
281 case eNPP_GetJavaClass
:
282 TRACE( "eNPP_GetJavaClass" );
283 OSL_ENSURE( false, "NPP_GetJavaClass: not implemented!" );
289 //--------------------------------------------------------------------------------------------------
290 NPError
PluginComm_Impl::NPP_Destroy( NPP instance
, NPSavedData
** save
)
292 DBG_ASSERT( _NPPfuncs
.destroy
, "### NPP_Destroy(): null pointer in NPP functions table!" );
293 m_eCall
= eNPP_Destroy
;
294 m_aArgs
[0] = (void*)instance
;
295 m_aArgs
[1] = (void*)save
;
296 return (NPError
)execute();
299 //--------------------------------------------------------------------------------------------------
300 NPError
PluginComm_Impl::NPP_DestroyStream( NPP instance
, NPStream
* stream
, NPError reason
)
302 DBG_ASSERT( _NPPfuncs
.destroystream
, "### NPP_DestroyStream(): null pointer in NPP functions table!" );
303 m_eCall
= eNPP_DestroyStream
;
304 m_aArgs
[0] = (void*)instance
;
305 m_aArgs
[1] = (void*)stream
;
306 m_aArgs
[2] = (void*)reason
;
307 return (NPError
)execute();
310 //--------------------------------------------------------------------------------------------------
311 NPError
PluginComm_Impl::NPP_New( NPMIMEType pluginType
, NPP instance
, uint16 mode
, int16 argc
,
312 char* argn
[], char* argv
[], NPSavedData
*saved
)
314 DBG_ASSERT( _NPPfuncs
.newp
, "### NPP_New(): null pointer in NPP functions table!" );
316 m_aArgs
[0] = (void*)pluginType
;
317 m_aArgs
[1] = (void*)instance
;
318 m_aArgs
[2] = (void*)mode
;
319 m_aArgs
[3] = (void*)argc
;
320 m_aArgs
[4] = (void*)argn
;
321 m_aArgs
[5] = (void*)argv
;
322 m_aArgs
[6] = (void*)saved
;
323 return (NPError
)execute();
326 //--------------------------------------------------------------------------------------------------
327 NPError
PluginComm_Impl::NPP_NewStream( NPP instance
, NPMIMEType type
, NPStream
* stream
,
328 NPBool seekable
, uint16
* stype
)
330 DBG_ASSERT( _NPPfuncs
.newstream
, "### NPP_NewStream(): null pointer in NPP functions table!" );
331 m_eCall
= eNPP_NewStream
;
332 m_aArgs
[0] = (void*)instance
;
333 m_aArgs
[1] = (void*)type
;
334 m_aArgs
[2] = (void*)stream
;
335 m_aArgs
[3] = (void*)seekable
;
336 m_aArgs
[4] = (void*)stype
;
337 return (NPError
)execute();
340 //--------------------------------------------------------------------------------------------------
341 void PluginComm_Impl::NPP_Print( NPP instance
, NPPrint
* platformPrint
)
343 DBG_ASSERT( _NPPfuncs
.print
, "### NPP_Print(): null pointer in NPP functions table!" );
344 m_eCall
= eNPP_Print
;
345 m_aArgs
[0] = (void*)instance
;
346 m_aArgs
[1] = (void*)platformPrint
;
350 //--------------------------------------------------------------------------------------------------
351 NPError
PluginComm_Impl::NPP_SetWindow( NPP instance
, NPWindow
* window
)
353 DBG_ASSERT( _NPPfuncs
.setwindow
, "### NPP_SetWindow(): null pointer in NPP functions table!" );
354 m_eCall
= eNPP_SetWindow
;
355 m_aArgs
[0] = (void*)instance
;
356 m_aArgs
[1] = (void*)window
;
357 return (NPError
)execute();
360 //--------------------------------------------------------------------------------------------------
361 void PluginComm_Impl::NPP_StreamAsFile( NPP instance
, NPStream
* stream
, const char* fname
)
363 DBG_ASSERT( _NPPfuncs
.asfile
, "### NPP_StreamAsFile(): null pointer in NPP functions table!" );
364 m_eCall
= eNPP_StreamAsFile
;
365 m_aArgs
[0] = (void*)instance
;
366 m_aArgs
[1] = (void*)stream
;
367 m_aArgs
[2] = (void*)fname
;
371 //--------------------------------------------------------------------------------------------------
372 void PluginComm_Impl::NPP_URLNotify( NPP instance
, const char* url
, NPReason reason
, void* notifyData
)
374 DBG_ASSERT( _NPPfuncs
.urlnotify
, "### NPP_URLNotify(): null pointer in NPP functions table!" );
375 m_eCall
= eNPP_URLNotify
;
376 m_aArgs
[0] = (void*)instance
;
377 m_aArgs
[1] = (void*)url
;
378 m_aArgs
[2] = (void*)reason
;
379 m_aArgs
[3] = notifyData
;
383 //--------------------------------------------------------------------------------------------------
384 int32
PluginComm_Impl::NPP_Write( NPP instance
, NPStream
* stream
, int32 offset
, int32 len
, void* buffer
)
386 DBG_ASSERT( _NPPfuncs
.write
, "### NPP_Write(): null pointer in NPP functions table!" );
387 m_eCall
= eNPP_Write
;
388 m_aArgs
[0] = (void*)instance
;
389 m_aArgs
[1] = (void*)stream
;
390 m_aArgs
[2] = (void*)offset
;
391 m_aArgs
[3] = (void*)len
;
393 return (NPError
)execute();
396 //--------------------------------------------------------------------------------------------------
397 int32
PluginComm_Impl::NPP_WriteReady( NPP instance
, NPStream
* stream
)
399 DBG_ASSERT( _NPPfuncs
.writeready
, "### NPP_WriteReady(): null pointer in NPP functions table!" );
400 m_eCall
= eNPP_WriteReady
;
401 m_aArgs
[0] = (void*)instance
;
402 m_aArgs
[1] = (void*)stream
;
406 //--------------------------------------------------------------------------------------------------
407 NPError
PluginComm_Impl::NPP_GetValue( NPP instance
, NPPVariable variable
, void *ret_value
)
409 DBG_ASSERT( _NPPfuncs
.getvalue
, "### NPP_GetValue(): null pointer in NPP functions table!" );
410 m_eCall
= eNPP_GetValue
;
411 m_aArgs
[0] = (void*)instance
;
412 m_aArgs
[1] = (void*)variable
;
413 m_aArgs
[2] = ret_value
;
414 return (NPError
)execute();
417 //--------------------------------------------------------------------------------------------------
418 NPError
PluginComm_Impl::NPP_SetValue( NPP instance
, NPNVariable variable
, void *set_value
)
420 DBG_ASSERT( _NPPfuncs
.setvalue
, "### NPP_SetValue(): null pointer in NPP functions table!" );
421 m_eCall
= eNPP_SetValue
;
422 m_aArgs
[0] = (void*)instance
;
423 m_aArgs
[1] = (void*)variable
;
424 m_aArgs
[2] = set_value
;
425 return (NPError
)execute();
428 //--------------------------------------------------------------------------------------------------
429 void * PluginComm_Impl::NPP_GetJavaClass()
431 DBG_ERROR( "no java class available!" );
435 //--------------------------------------------------------------------------------------------------
436 NPError
PluginComm_Impl::NPP_Initialize()
438 return NPERR_NO_ERROR
;
441 //--------------------------------------------------------------------------------------------------
442 void PluginComm_Impl::NPP_Shutdown()
444 m_eCall
= eNPP_Shutdown
;