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>
45 #include <tools/postwin.h>
54 extern NPNetscapeFuncs aNPNFuncs
;
56 #include <tools/debug.hxx>
60 #if OSL_DEBUG_LEVEL > 1
61 void TRACE( char const * s
);
62 void TRACEN( char const * s
, long n
);
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
) );
76 _plDLL
= ::LoadLibrary( rName
.getStr() );
78 OString
aStr( OUStringToOString( rName
, RTL_TEXTENCODING_MS_1252
) );
79 _plDLL
= ::LoadLibrary( aStr
.getStr() );
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
;
99 //--------------------------------------------------------------------------------------------------
100 PluginComm_Impl::~PluginComm_Impl()
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!" );
119 //--------------------------------------------------------------------------------------------------
120 BOOL
PluginComm_Impl::retrieveFunction( TCHAR
* pName
, void** ppFunc
) const
125 *ppFunc
= (void*)::GetProcAddress( _plDLL
, pName
);
127 return (*ppFunc
!= NULL
);
130 //--------------------------------------------------------------------------------------------------
132 long PluginComm_Impl::doIt()
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
);
149 nRet
= NPERR_GENERIC_ERROR
;
151 DBG_ASSERT( nRet
== NPERR_NO_ERROR
, "### NP_Initialize() failed!" );
155 TRACE( "eNPP_Destroy" );
156 nRet
= (_NPPfuncs
.destroy
157 ? (*_NPPfuncs
.destroy
)(
159 (NPSavedData
**)m_aArgs
[1] )
160 : NPERR_GENERIC_ERROR
);
162 case eNPP_DestroyStream
:
163 TRACE( "eNPP_DestroyStream" );
164 nRet
= (_NPPfuncs
.destroystream
165 ? (*_NPPfuncs
.destroystream
)(
167 (NPStream
*)m_aArgs
[1],
168 (NPError
)(sal_IntPtr
)m_aArgs
[2] )
169 : NPERR_GENERIC_ERROR
);
173 nRet
= (_NPPfuncs
.newp
175 (NPMIMEType
)m_aArgs
[0],
177 (uint16
)(sal_IntPtr
)m_aArgs
[2],
178 (int16
)(sal_IntPtr
)m_aArgs
[3],
181 (NPSavedData
*)m_aArgs
[6] )
182 : NPERR_GENERIC_ERROR
);
185 TRACE( "eNPP_NewStream" );
186 nRet
= (_NPPfuncs
.newstream
187 ? (*_NPPfuncs
.newstream
)(
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
);
196 TRACE( "eNPP_Print" );
200 (NPPrint
*)m_aArgs
[1] );
204 TRACE( "eNPP_SetWindow" );
205 nRet
= (_NPPfuncs
.setwindow
206 ? (*_NPPfuncs
.setwindow
)(
208 (NPWindow
*)m_aArgs
[1] )
209 : NPERR_GENERIC_ERROR
);
212 case eNPP_StreamAsFile
:
213 TRACE( "eNPP_StreamAsFile" );
214 if (_NPPfuncs
.asfile
)
217 (NPStream
*)m_aArgs
[1],
221 TRACE( "eNPP_URLNotify" );
222 if (_NPPfuncs
.urlnotify
)
223 (*_NPPfuncs
.urlnotify
)(
226 (NPReason
)(sal_IntPtr
)m_aArgs
[2],
230 TRACEN( "eNPP_Write n=", (int32
)m_aArgs
[3] );
231 nRet
= (_NPPfuncs
.write
232 ? (*_NPPfuncs
.write
)(
234 (NPStream
*)m_aArgs
[1],
240 case eNPP_WriteReady
:
241 TRACE( "eNPP_WriteReady" );
242 nRet
= (_NPPfuncs
.writeready
243 ? (*_NPPfuncs
.writeready
)(
245 (NPStream
*)m_aArgs
[1] )
249 TRACE( "eNPP_GetValue" );
250 nRet
= (_NPPfuncs
.getvalue
251 ? (*_NPPfuncs
.getvalue
)(
253 (NPPVariable
)(int)m_aArgs
[1],
255 : NPERR_GENERIC_ERROR
);
258 TRACE( "eNPP_SetValue" );
259 nRet
= (_NPPfuncs
.setvalue
260 ? (*_NPPfuncs
.setvalue
)(
262 (NPNVariable
)(int)m_aArgs
[1],
264 : NPERR_GENERIC_ERROR
);
268 TRACE( "eNPP_Shutdown" );
269 NPP_ShutdownUPP pFunc
;
270 if (retrieveFunction( _T("NPP_Shutdown"), (void**)&pFunc
))
274 case eNPP_Initialize
:
275 TRACE( "eNPP_Initialize" );
276 OSL_ENSURE( false, "NPP_Initialize: not implemented!" );
278 case eNPP_GetJavaClass
:
279 TRACE( "eNPP_GetJavaClass" );
280 OSL_ENSURE( false, "NPP_GetJavaClass: not implemented!" );
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!" );
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
;
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
;
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
;
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
;
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
;
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!" );
432 //--------------------------------------------------------------------------------------------------
433 NPError
PluginComm_Impl::NPP_Initialize()
435 return NPERR_NO_ERROR
;
438 //--------------------------------------------------------------------------------------------------
439 void PluginComm_Impl::NPP_Shutdown()
441 m_eCall
= eNPP_Shutdown
;