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 ************************************************************************/
33 #include <sal/log.hxx>
35 #include <plugin/impl.hxx>
38 #pragma warning (push,1)
39 #pragma warning (disable:4005)
55 extern NPNetscapeFuncs aNPNFuncs
;
57 #include <tools/debug.hxx>
60 #if OSL_DEBUG_LEVEL > 1
61 void TRACE( char const * s
);
62 void TRACEN( char const * s
, long n
);
68 ::boost::shared_ptr
<SysPlugData
> CreateSysPlugData()
70 return ::boost::shared_ptr
<SysPlugData
>();
74 PluginComm_Impl::PluginComm_Impl( const OUString
& /*rMIME*/, const OUString
& rName
, HWND
/*hWnd*/ )
75 : PluginComm( OUStringToOString( rName
, RTL_TEXTENCODING_MS_1252
) )
77 // initialize plugin function table
78 memset( &_NPPfuncs
, 0, sizeof( _NPPfuncs
) );
80 _plDLL
= ::LoadLibrary( rName
.getStr() );
82 OString
aStr( OUStringToOString( rName
, RTL_TEXTENCODING_MS_1252
) );
83 _plDLL
= ::LoadLibrary( aStr
.getStr() );
85 DBG_ASSERT( _plDLL
, "### loading plugin dll failed!" );
87 NPError (WINAPI
* pEntry
)( NPPluginFuncs
* );
88 retrieveFunction( _T("NP_GetEntryPoints"), (void**)&pEntry
);
90 _NPPfuncs
.size
= sizeof( _NPPfuncs
);
91 _NPPfuncs
.version
= 0;
92 NPError nErr
= (*pEntry
)( &_NPPfuncs
);
95 nErr
!= NPERR_NO_ERROR
, "extensions.plugin",
96 "NP_GetEntryPoints() failed");
97 DBG_ASSERT( (_NPPfuncs
.version
>> 8) >= NP_VERSION_MAJOR
,
98 "### version failure!" );
100 m_eCall
= eNP_Initialize
;
105 PluginComm_Impl::~PluginComm_Impl()
111 NPError (WINAPI
* pShutdown
)();
112 if (retrieveFunction( _T("NP_Shutdown"), (void**)&pShutdown
))
114 NPError nErr
= (*pShutdown
)(); (void)nErr
;
115 DBG_ASSERT( nErr
== NPERR_NO_ERROR
, "### NP_Shutdown() failed!" );
118 BOOL bRet
= (BOOL
)::FreeLibrary( _plDLL
); (void)bRet
;
119 DBG_ASSERT( bRet
, "### unloading plugin dll failed!" );
125 BOOL
PluginComm_Impl::retrieveFunction( TCHAR
const * pName
, void** ppFunc
) const
130 *ppFunc
= (void*)::GetProcAddress( _plDLL
, pName
);
132 return (*ppFunc
!= NULL
);
137 long PluginComm_Impl::doIt()
144 TRACE( "eNP_Initialize" );
145 NPError (WINAPI
* pInit
)( NPNetscapeFuncs
* );
146 if ((_NPPfuncs
.version
>> 8) >= NP_VERSION_MAJOR
&&
147 (retrieveFunction( _T("NP_Initialize"), (void**)&pInit
) ||
148 retrieveFunction( _T("NP_PluginInit"), (void**)&pInit
)))
150 nRet
= (*pInit
)( &aNPNFuncs
);
154 nRet
= NPERR_GENERIC_ERROR
;
156 DBG_ASSERT( nRet
== NPERR_NO_ERROR
, "### NP_Initialize() failed!" );
160 TRACE( "eNPP_Destroy" );
161 nRet
= (_NPPfuncs
.destroy
162 ? (*_NPPfuncs
.destroy
)(
164 (NPSavedData
**)m_aArgs
[1] )
165 : NPERR_GENERIC_ERROR
);
167 case eNPP_DestroyStream
:
168 TRACE( "eNPP_DestroyStream" );
169 nRet
= (_NPPfuncs
.destroystream
170 ? (*_NPPfuncs
.destroystream
)(
172 (NPStream
*)m_aArgs
[1],
173 (NPError
)(sal_IntPtr
)m_aArgs
[2] )
174 : NPERR_GENERIC_ERROR
);
178 nRet
= (_NPPfuncs
.newp
180 (NPMIMEType
)m_aArgs
[0],
182 (uint16_t)(sal_IntPtr
)m_aArgs
[2],
183 (int16_t)(sal_IntPtr
)m_aArgs
[3],
186 (NPSavedData
*)m_aArgs
[6] )
187 : NPERR_GENERIC_ERROR
);
190 TRACE( "eNPP_NewStream" );
191 nRet
= (_NPPfuncs
.newstream
192 ? (*_NPPfuncs
.newstream
)(
194 (NPMIMEType
)m_aArgs
[1],
195 (NPStream
*)m_aArgs
[2],
196 (NPBool
)(sal_IntPtr
)m_aArgs
[3],
197 (uint16_t*)m_aArgs
[4] )
198 : NPERR_GENERIC_ERROR
);
201 TRACE( "eNPP_Print" );
205 (NPPrint
*)m_aArgs
[1] );
209 TRACE( "eNPP_SetWindow" );
210 nRet
= (_NPPfuncs
.setwindow
211 ? (*_NPPfuncs
.setwindow
)(
213 (NPWindow
*)m_aArgs
[1] )
214 : NPERR_GENERIC_ERROR
);
217 case eNPP_StreamAsFile
:
218 TRACE( "eNPP_StreamAsFile" );
219 if (_NPPfuncs
.asfile
)
222 (NPStream
*)m_aArgs
[1],
226 TRACE( "eNPP_URLNotify" );
227 if (_NPPfuncs
.urlnotify
)
228 (*_NPPfuncs
.urlnotify
)(
231 (NPReason
)(sal_IntPtr
)m_aArgs
[2],
235 TRACEN( "eNPP_Write n=", (int32_t)m_aArgs
[3] );
236 nRet
= (_NPPfuncs
.write
237 ? (*_NPPfuncs
.write
)(
239 (NPStream
*)m_aArgs
[1],
240 (sal_IntPtr
)m_aArgs
[2],
241 (sal_IntPtr
)m_aArgs
[3],
245 case eNPP_WriteReady
:
246 TRACE( "eNPP_WriteReady" );
247 nRet
= (_NPPfuncs
.writeready
248 ? (*_NPPfuncs
.writeready
)(
250 (NPStream
*)m_aArgs
[1] )
254 TRACE( "eNPP_GetValue" );
255 nRet
= (_NPPfuncs
.getvalue
256 ? (*_NPPfuncs
.getvalue
)(
258 (NPPVariable
)(sal_IntPtr
)m_aArgs
[1],
260 : NPERR_GENERIC_ERROR
);
263 TRACE( "eNPP_SetValue" );
264 nRet
= (_NPPfuncs
.setvalue
265 ? (*_NPPfuncs
.setvalue
)(
267 (NPNVariable
)(sal_IntPtr
)m_aArgs
[1],
269 : NPERR_GENERIC_ERROR
);
273 TRACE( "eNPP_Shutdown" );
274 NPP_ShutdownUPP pFunc
;
275 if (retrieveFunction( _T("NPP_Shutdown"), (void**)&pFunc
))
279 case eNPP_Initialize
:
280 TRACE( "eNPP_Initialize" );
281 OSL_FAIL( "NPP_Initialize: not implemented!" );
283 case eNPP_GetJavaClass
:
284 TRACE( "eNPP_GetJavaClass" );
285 OSL_FAIL( "NPP_GetJavaClass: not implemented!" );
292 NPError
PluginComm_Impl::NPP_Destroy( NPP instance
, NPSavedData
** save
)
294 DBG_ASSERT( _NPPfuncs
.destroy
, "### NPP_Destroy(): null pointer in NPP functions table!" );
295 m_eCall
= eNPP_Destroy
;
296 m_aArgs
[0] = (void*)instance
;
297 m_aArgs
[1] = (void*)save
;
298 return (NPError
)execute();
302 NPError
PluginComm_Impl::NPP_DestroyStream( NPP instance
, NPStream
* stream
, NPError reason
)
304 DBG_ASSERT( _NPPfuncs
.destroystream
, "### NPP_DestroyStream(): null pointer in NPP functions table!" );
305 m_eCall
= eNPP_DestroyStream
;
306 m_aArgs
[0] = (void*)instance
;
307 m_aArgs
[1] = (void*)stream
;
308 m_aArgs
[2] = reinterpret_cast< void * >(static_cast< sal_IntPtr
>(reason
));
309 return (NPError
)execute();
313 NPError
PluginComm_Impl::NPP_New( NPMIMEType pluginType
, NPP instance
, uint16_t mode
, int16_t argc
,
314 char* argn
[], char* argv
[], NPSavedData
*saved
)
316 DBG_ASSERT( _NPPfuncs
.newp
, "### NPP_New(): null pointer in NPP functions table!" );
318 m_aArgs
[0] = (void*)pluginType
;
319 m_aArgs
[1] = (void*)instance
;
320 m_aArgs
[2] = reinterpret_cast< void * >(static_cast< sal_uIntPtr
>(mode
));
321 m_aArgs
[3] = reinterpret_cast< void * >(static_cast< sal_IntPtr
>(argc
));
322 m_aArgs
[4] = (void*)argn
;
323 m_aArgs
[5] = (void*)argv
;
324 m_aArgs
[6] = (void*)saved
;
325 return (NPError
)execute();
329 NPError
PluginComm_Impl::NPP_NewStream( NPP instance
, NPMIMEType type
, NPStream
* stream
,
330 NPBool seekable
, uint16_t* stype
)
332 DBG_ASSERT( _NPPfuncs
.newstream
, "### NPP_NewStream(): null pointer in NPP functions table!" );
333 m_eCall
= eNPP_NewStream
;
334 m_aArgs
[0] = (void*)instance
;
335 m_aArgs
[1] = (void*)type
;
336 m_aArgs
[2] = (void*)stream
;
337 m_aArgs
[3] = reinterpret_cast< void * >(
338 static_cast< sal_uIntPtr
>(seekable
));
339 m_aArgs
[4] = (void*)stype
;
340 return (NPError
)execute();
344 void PluginComm_Impl::NPP_Print( NPP instance
, NPPrint
* platformPrint
)
346 DBG_ASSERT( _NPPfuncs
.print
, "### NPP_Print(): null pointer in NPP functions table!" );
347 m_eCall
= eNPP_Print
;
348 m_aArgs
[0] = (void*)instance
;
349 m_aArgs
[1] = (void*)platformPrint
;
354 NPError
PluginComm_Impl::NPP_SetWindow( NPP instance
, NPWindow
* window
)
356 DBG_ASSERT( _NPPfuncs
.setwindow
, "### NPP_SetWindow(): null pointer in NPP functions table!" );
357 m_eCall
= eNPP_SetWindow
;
358 m_aArgs
[0] = (void*)instance
;
359 m_aArgs
[1] = (void*)window
;
360 return (NPError
)execute();
364 void PluginComm_Impl::NPP_StreamAsFile( NPP instance
, NPStream
* stream
, const char* fname
)
366 DBG_ASSERT( _NPPfuncs
.asfile
, "### NPP_StreamAsFile(): null pointer in NPP functions table!" );
367 m_eCall
= eNPP_StreamAsFile
;
368 m_aArgs
[0] = (void*)instance
;
369 m_aArgs
[1] = (void*)stream
;
370 m_aArgs
[2] = (void*)fname
;
375 void PluginComm_Impl::NPP_URLNotify( NPP instance
, const char* url
, NPReason reason
, void* notifyData
)
377 DBG_ASSERT( _NPPfuncs
.urlnotify
, "### NPP_URLNotify(): null pointer in NPP functions table!" );
378 m_eCall
= eNPP_URLNotify
;
379 m_aArgs
[0] = (void*)instance
;
380 m_aArgs
[1] = (void*)url
;
381 m_aArgs
[2] = reinterpret_cast< void * >(static_cast< sal_IntPtr
>(reason
));
382 m_aArgs
[3] = notifyData
;
387 int32_t PluginComm_Impl::NPP_Write( NPP instance
, NPStream
* stream
, int32_t offset
, int32_t len
, void* buffer
)
389 DBG_ASSERT( _NPPfuncs
.write
, "### NPP_Write(): null pointer in NPP functions table!" );
390 m_eCall
= eNPP_Write
;
391 m_aArgs
[0] = (void*)instance
;
392 m_aArgs
[1] = (void*)stream
;
393 m_aArgs
[2] = (void*)(sal_IntPtr
)offset
;
394 m_aArgs
[3] = (void*)(sal_IntPtr
)len
;
396 return (NPError
)execute();
400 int32_t PluginComm_Impl::NPP_WriteReady( NPP instance
, NPStream
* stream
)
402 DBG_ASSERT( _NPPfuncs
.writeready
, "### NPP_WriteReady(): null pointer in NPP functions table!" );
403 m_eCall
= eNPP_WriteReady
;
404 m_aArgs
[0] = (void*)instance
;
405 m_aArgs
[1] = (void*)stream
;
410 NPError
PluginComm_Impl::NPP_GetValue( NPP instance
, NPPVariable variable
, void *ret_value
)
412 DBG_ASSERT( _NPPfuncs
.getvalue
, "### NPP_GetValue(): null pointer in NPP functions table!" );
413 m_eCall
= eNPP_GetValue
;
414 m_aArgs
[0] = (void*)instance
;
415 m_aArgs
[1] = (void*)variable
;
416 m_aArgs
[2] = ret_value
;
417 return (NPError
)execute();
421 NPError
PluginComm_Impl::NPP_SetValue( NPP instance
, NPNVariable variable
, void *set_value
)
423 DBG_ASSERT( _NPPfuncs
.setvalue
, "### NPP_SetValue(): null pointer in NPP functions table!" );
424 m_eCall
= eNPP_SetValue
;
425 m_aArgs
[0] = (void*)instance
;
426 m_aArgs
[1] = (void*)variable
;
427 m_aArgs
[2] = set_value
;
428 return (NPError
)execute();
432 void * PluginComm_Impl::NPP_GetJavaClass()
434 OSL_FAIL( "no java class available!" );
439 NPError
PluginComm_Impl::NPP_Initialize()
441 return NPERR_NO_ERROR
;
445 void PluginComm_Impl::NPP_Shutdown()
447 m_eCall
= eNPP_Shutdown
;
451 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */