1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
34 #include <plugin/impl.hxx>
37 #pragma warning (push,1)
38 #pragma warning (disable:4005)
54 extern NPNetscapeFuncs aNPNFuncs
;
56 #include <tools/debug.hxx>
59 #if OSL_DEBUG_LEVEL > 1
60 void TRACE( char const * s
);
61 void TRACEN( char const * s
, long n
);
67 ::boost::shared_ptr
<SysPlugData
> CreateSysPlugData()
69 return ::boost::shared_ptr
<SysPlugData
>();
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 (WINAPI
* pEntry
)( NPPluginFuncs
* );
87 retrieveFunction( _T("NP_GetEntryPoints"), (void**)&pEntry
);
89 _NPPfuncs
.size
= sizeof( _NPPfuncs
);
90 _NPPfuncs
.version
= 0;
91 NPError nErr
= (*pEntry
)( &_NPPfuncs
);
94 nErr
!= NPERR_NO_ERROR
, "extensions.plugin",
95 "NP_GetEntryPoints() failed");
96 DBG_ASSERT( (_NPPfuncs
.version
>> 8) >= NP_VERSION_MAJOR
,
97 "### version failure!" );
99 m_eCall
= eNP_Initialize
;
103 //--------------------------------------------------------------------------------------------------
104 PluginComm_Impl::~PluginComm_Impl()
110 NPError (WINAPI
* pShutdown
)();
111 if (retrieveFunction( _T("NP_Shutdown"), (void**)&pShutdown
))
113 NPError nErr
= (*pShutdown
)(); (void)nErr
;
114 DBG_ASSERT( nErr
== NPERR_NO_ERROR
, "### NP_Shutdown() failed!" );
117 BOOL bRet
= (BOOL
)::FreeLibrary( _plDLL
); (void)bRet
;
118 DBG_ASSERT( bRet
, "### unloading plugin dll failed!" );
123 //--------------------------------------------------------------------------------------------------
124 BOOL
PluginComm_Impl::retrieveFunction( TCHAR
const * pName
, void** ppFunc
) const
129 *ppFunc
= (void*)::GetProcAddress( _plDLL
, pName
);
131 return (*ppFunc
!= NULL
);
134 //--------------------------------------------------------------------------------------------------
136 long PluginComm_Impl::doIt()
143 TRACE( "eNP_Initialize" );
144 NPError (WINAPI
* pInit
)( NPNetscapeFuncs
* );
145 if ((_NPPfuncs
.version
>> 8) >= NP_VERSION_MAJOR
&&
146 (retrieveFunction( _T("NP_Initialize"), (void**)&pInit
) ||
147 retrieveFunction( _T("NP_PluginInit"), (void**)&pInit
)))
149 nRet
= (*pInit
)( &aNPNFuncs
);
153 nRet
= NPERR_GENERIC_ERROR
;
155 DBG_ASSERT( nRet
== NPERR_NO_ERROR
, "### NP_Initialize() failed!" );
159 TRACE( "eNPP_Destroy" );
160 nRet
= (_NPPfuncs
.destroy
161 ? (*_NPPfuncs
.destroy
)(
163 (NPSavedData
**)m_aArgs
[1] )
164 : NPERR_GENERIC_ERROR
);
166 case eNPP_DestroyStream
:
167 TRACE( "eNPP_DestroyStream" );
168 nRet
= (_NPPfuncs
.destroystream
169 ? (*_NPPfuncs
.destroystream
)(
171 (NPStream
*)m_aArgs
[1],
172 (NPError
)(sal_IntPtr
)m_aArgs
[2] )
173 : NPERR_GENERIC_ERROR
);
177 nRet
= (_NPPfuncs
.newp
179 (NPMIMEType
)m_aArgs
[0],
181 (uint16_t)(sal_IntPtr
)m_aArgs
[2],
182 (int16_t)(sal_IntPtr
)m_aArgs
[3],
185 (NPSavedData
*)m_aArgs
[6] )
186 : NPERR_GENERIC_ERROR
);
189 TRACE( "eNPP_NewStream" );
190 nRet
= (_NPPfuncs
.newstream
191 ? (*_NPPfuncs
.newstream
)(
193 (NPMIMEType
)m_aArgs
[1],
194 (NPStream
*)m_aArgs
[2],
195 (NPBool
)(sal_IntPtr
)m_aArgs
[3],
196 (uint16_t*)m_aArgs
[4] )
197 : NPERR_GENERIC_ERROR
);
200 TRACE( "eNPP_Print" );
204 (NPPrint
*)m_aArgs
[1] );
208 TRACE( "eNPP_SetWindow" );
209 nRet
= (_NPPfuncs
.setwindow
210 ? (*_NPPfuncs
.setwindow
)(
212 (NPWindow
*)m_aArgs
[1] )
213 : NPERR_GENERIC_ERROR
);
216 case eNPP_StreamAsFile
:
217 TRACE( "eNPP_StreamAsFile" );
218 if (_NPPfuncs
.asfile
)
221 (NPStream
*)m_aArgs
[1],
225 TRACE( "eNPP_URLNotify" );
226 if (_NPPfuncs
.urlnotify
)
227 (*_NPPfuncs
.urlnotify
)(
230 (NPReason
)(sal_IntPtr
)m_aArgs
[2],
234 TRACEN( "eNPP_Write n=", (int32_t)m_aArgs
[3] );
235 nRet
= (_NPPfuncs
.write
236 ? (*_NPPfuncs
.write
)(
238 (NPStream
*)m_aArgs
[1],
244 case eNPP_WriteReady
:
245 TRACE( "eNPP_WriteReady" );
246 nRet
= (_NPPfuncs
.writeready
247 ? (*_NPPfuncs
.writeready
)(
249 (NPStream
*)m_aArgs
[1] )
253 TRACE( "eNPP_GetValue" );
254 nRet
= (_NPPfuncs
.getvalue
255 ? (*_NPPfuncs
.getvalue
)(
257 (NPPVariable
)(int)m_aArgs
[1],
259 : NPERR_GENERIC_ERROR
);
262 TRACE( "eNPP_SetValue" );
263 nRet
= (_NPPfuncs
.setvalue
264 ? (*_NPPfuncs
.setvalue
)(
266 (NPNVariable
)(int)m_aArgs
[1],
268 : NPERR_GENERIC_ERROR
);
272 TRACE( "eNPP_Shutdown" );
273 NPP_ShutdownUPP pFunc
;
274 if (retrieveFunction( _T("NPP_Shutdown"), (void**)&pFunc
))
278 case eNPP_Initialize
:
279 TRACE( "eNPP_Initialize" );
280 OSL_FAIL( "NPP_Initialize: not implemented!" );
282 case eNPP_GetJavaClass
:
283 TRACE( "eNPP_GetJavaClass" );
284 OSL_FAIL( "NPP_GetJavaClass: not implemented!" );
290 //--------------------------------------------------------------------------------------------------
291 NPError
PluginComm_Impl::NPP_Destroy( NPP instance
, NPSavedData
** save
)
293 DBG_ASSERT( _NPPfuncs
.destroy
, "### NPP_Destroy(): null pointer in NPP functions table!" );
294 m_eCall
= eNPP_Destroy
;
295 m_aArgs
[0] = (void*)instance
;
296 m_aArgs
[1] = (void*)save
;
297 return (NPError
)execute();
300 //--------------------------------------------------------------------------------------------------
301 NPError
PluginComm_Impl::NPP_DestroyStream( NPP instance
, NPStream
* stream
, NPError reason
)
303 DBG_ASSERT( _NPPfuncs
.destroystream
, "### NPP_DestroyStream(): null pointer in NPP functions table!" );
304 m_eCall
= eNPP_DestroyStream
;
305 m_aArgs
[0] = (void*)instance
;
306 m_aArgs
[1] = (void*)stream
;
307 m_aArgs
[2] = reinterpret_cast< void * >(static_cast< sal_IntPtr
>(reason
));
308 return (NPError
)execute();
311 //--------------------------------------------------------------------------------------------------
312 NPError
PluginComm_Impl::NPP_New( NPMIMEType pluginType
, NPP instance
, uint16_t mode
, int16_t argc
,
313 char* argn
[], char* argv
[], NPSavedData
*saved
)
315 DBG_ASSERT( _NPPfuncs
.newp
, "### NPP_New(): null pointer in NPP functions table!" );
317 m_aArgs
[0] = (void*)pluginType
;
318 m_aArgs
[1] = (void*)instance
;
319 m_aArgs
[2] = reinterpret_cast< void * >(static_cast< sal_uIntPtr
>(mode
));
320 m_aArgs
[3] = reinterpret_cast< void * >(static_cast< sal_IntPtr
>(argc
));
321 m_aArgs
[4] = (void*)argn
;
322 m_aArgs
[5] = (void*)argv
;
323 m_aArgs
[6] = (void*)saved
;
324 return (NPError
)execute();
327 //--------------------------------------------------------------------------------------------------
328 NPError
PluginComm_Impl::NPP_NewStream( NPP instance
, NPMIMEType type
, NPStream
* stream
,
329 NPBool seekable
, uint16_t* stype
)
331 DBG_ASSERT( _NPPfuncs
.newstream
, "### NPP_NewStream(): null pointer in NPP functions table!" );
332 m_eCall
= eNPP_NewStream
;
333 m_aArgs
[0] = (void*)instance
;
334 m_aArgs
[1] = (void*)type
;
335 m_aArgs
[2] = (void*)stream
;
336 m_aArgs
[3] = reinterpret_cast< void * >(
337 static_cast< sal_uIntPtr
>(seekable
));
338 m_aArgs
[4] = (void*)stype
;
339 return (NPError
)execute();
342 //--------------------------------------------------------------------------------------------------
343 void PluginComm_Impl::NPP_Print( NPP instance
, NPPrint
* platformPrint
)
345 DBG_ASSERT( _NPPfuncs
.print
, "### NPP_Print(): null pointer in NPP functions table!" );
346 m_eCall
= eNPP_Print
;
347 m_aArgs
[0] = (void*)instance
;
348 m_aArgs
[1] = (void*)platformPrint
;
352 //--------------------------------------------------------------------------------------------------
353 NPError
PluginComm_Impl::NPP_SetWindow( NPP instance
, NPWindow
* window
)
355 DBG_ASSERT( _NPPfuncs
.setwindow
, "### NPP_SetWindow(): null pointer in NPP functions table!" );
356 m_eCall
= eNPP_SetWindow
;
357 m_aArgs
[0] = (void*)instance
;
358 m_aArgs
[1] = (void*)window
;
359 return (NPError
)execute();
362 //--------------------------------------------------------------------------------------------------
363 void PluginComm_Impl::NPP_StreamAsFile( NPP instance
, NPStream
* stream
, const char* fname
)
365 DBG_ASSERT( _NPPfuncs
.asfile
, "### NPP_StreamAsFile(): null pointer in NPP functions table!" );
366 m_eCall
= eNPP_StreamAsFile
;
367 m_aArgs
[0] = (void*)instance
;
368 m_aArgs
[1] = (void*)stream
;
369 m_aArgs
[2] = (void*)fname
;
373 //--------------------------------------------------------------------------------------------------
374 void PluginComm_Impl::NPP_URLNotify( NPP instance
, const char* url
, NPReason reason
, void* notifyData
)
376 DBG_ASSERT( _NPPfuncs
.urlnotify
, "### NPP_URLNotify(): null pointer in NPP functions table!" );
377 m_eCall
= eNPP_URLNotify
;
378 m_aArgs
[0] = (void*)instance
;
379 m_aArgs
[1] = (void*)url
;
380 m_aArgs
[2] = reinterpret_cast< void * >(static_cast< sal_IntPtr
>(reason
));
381 m_aArgs
[3] = notifyData
;
385 //--------------------------------------------------------------------------------------------------
386 int32_t PluginComm_Impl::NPP_Write( NPP instance
, NPStream
* stream
, int32_t offset
, int32_t len
, void* buffer
)
388 DBG_ASSERT( _NPPfuncs
.write
, "### NPP_Write(): null pointer in NPP functions table!" );
389 m_eCall
= eNPP_Write
;
390 m_aArgs
[0] = (void*)instance
;
391 m_aArgs
[1] = (void*)stream
;
392 m_aArgs
[2] = (void*)offset
;
393 m_aArgs
[3] = (void*)len
;
395 return (NPError
)execute();
398 //--------------------------------------------------------------------------------------------------
399 int32_t PluginComm_Impl::NPP_WriteReady( NPP instance
, NPStream
* stream
)
401 DBG_ASSERT( _NPPfuncs
.writeready
, "### NPP_WriteReady(): null pointer in NPP functions table!" );
402 m_eCall
= eNPP_WriteReady
;
403 m_aArgs
[0] = (void*)instance
;
404 m_aArgs
[1] = (void*)stream
;
408 //--------------------------------------------------------------------------------------------------
409 NPError
PluginComm_Impl::NPP_GetValue( NPP instance
, NPPVariable variable
, void *ret_value
)
411 DBG_ASSERT( _NPPfuncs
.getvalue
, "### NPP_GetValue(): null pointer in NPP functions table!" );
412 m_eCall
= eNPP_GetValue
;
413 m_aArgs
[0] = (void*)instance
;
414 m_aArgs
[1] = (void*)variable
;
415 m_aArgs
[2] = ret_value
;
416 return (NPError
)execute();
419 //--------------------------------------------------------------------------------------------------
420 NPError
PluginComm_Impl::NPP_SetValue( NPP instance
, NPNVariable variable
, void *set_value
)
422 DBG_ASSERT( _NPPfuncs
.setvalue
, "### NPP_SetValue(): null pointer in NPP functions table!" );
423 m_eCall
= eNPP_SetValue
;
424 m_aArgs
[0] = (void*)instance
;
425 m_aArgs
[1] = (void*)variable
;
426 m_aArgs
[2] = set_value
;
427 return (NPError
)execute();
430 //--------------------------------------------------------------------------------------------------
431 void * PluginComm_Impl::NPP_GetJavaClass()
433 OSL_FAIL( "no java class available!" );
437 //--------------------------------------------------------------------------------------------------
438 NPError
PluginComm_Impl::NPP_Initialize()
440 return NPERR_NO_ERROR
;
443 //--------------------------------------------------------------------------------------------------
444 void PluginComm_Impl::NPP_Shutdown()
446 m_eCall
= eNPP_Shutdown
;
450 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */