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 ************************************************************************/
29 // MARKER(update_precomp.py): autogen include statement, do not remove
30 #include "precompiled_extensions.hxx"
32 #include <plugin/impl.hxx>
34 #pragma warning (push,1)
35 #pragma warning (disable:4005)
37 #include <tools/prewin.h>
46 #include <tools/postwin.h>
55 extern NPNetscapeFuncs aNPNFuncs
;
57 #include <tools/debug.hxx>
61 #if OSL_DEBUG_LEVEL > 1
62 void TRACE( char const * s
);
63 void TRACEN( char const * s
, long n
);
70 //--------------------------------------------------------------------------------------------------
71 PluginComm_Impl::PluginComm_Impl( const OUString
& /*rMIME*/, const OUString
& rName
, HWND
/*hWnd*/ )
72 : PluginComm( OUStringToOString( rName
, RTL_TEXTENCODING_MS_1252
) )
74 // initialize plugin function table
75 memset( &_NPPfuncs
, 0, sizeof( _NPPfuncs
) );
77 _plDLL
= ::LoadLibrary( rName
.getStr() );
79 OString
aStr( OUStringToOString( rName
, RTL_TEXTENCODING_MS_1252
) );
80 _plDLL
= ::LoadLibrary( aStr
.getStr() );
82 DBG_ASSERT( _plDLL
, "### loading plugin dll failed!" );
84 NPError nErr
= NPERR_NO_ERROR
;
85 NPError (WINAPI
* pEntry
)( NPPluginFuncs
* );
86 retrieveFunction( _T("NP_GetEntryPoints"), (void**)&pEntry
);
88 _NPPfuncs
.size
= sizeof( _NPPfuncs
);
89 _NPPfuncs
.version
= 0;
90 nErr
= (*pEntry
)( &_NPPfuncs
);
92 DBG_ASSERT( nErr
== NPERR_NO_ERROR
, "### NP_GetEntryPoints() failed!" );
93 DBG_ASSERT( (_NPPfuncs
.version
>> 8) >= NP_VERSION_MAJOR
,
94 "### version failure!" );
96 m_eCall
= eNP_Initialize
;
100 //--------------------------------------------------------------------------------------------------
101 PluginComm_Impl::~PluginComm_Impl()
107 NPError (WINAPI
* pShutdown
)();
108 if (retrieveFunction( _T("NP_Shutdown"), (void**)&pShutdown
))
110 NPError nErr
= (*pShutdown
)(); (void)nErr
;
111 DBG_ASSERT( nErr
== NPERR_NO_ERROR
, "### NP_Shutdown() failed!" );
114 BOOL bRet
= (BOOL
)::FreeLibrary( _plDLL
); (void)bRet
;
115 DBG_ASSERT( bRet
, "### unloading plugin dll failed!" );
120 //--------------------------------------------------------------------------------------------------
121 BOOL
PluginComm_Impl::retrieveFunction( TCHAR
* pName
, void** ppFunc
) const
126 *ppFunc
= (void*)::GetProcAddress( _plDLL
, pName
);
128 return (*ppFunc
!= NULL
);
131 //--------------------------------------------------------------------------------------------------
133 long PluginComm_Impl::doIt()
140 TRACE( "eNP_Initialize" );
141 NPError (WINAPI
* pInit
)( NPNetscapeFuncs
* );
142 if ((_NPPfuncs
.version
>> 8) >= NP_VERSION_MAJOR
&&
143 (retrieveFunction( _T("NP_Initialize"), (void**)&pInit
) ||
144 retrieveFunction( _T("NP_PluginInit"), (void**)&pInit
)))
146 nRet
= (*pInit
)( &aNPNFuncs
);
150 nRet
= NPERR_GENERIC_ERROR
;
152 DBG_ASSERT( nRet
== NPERR_NO_ERROR
, "### NP_Initialize() failed!" );
156 TRACE( "eNPP_Destroy" );
157 nRet
= (_NPPfuncs
.destroy
158 ? (*_NPPfuncs
.destroy
)(
160 (NPSavedData
**)m_aArgs
[1] )
161 : NPERR_GENERIC_ERROR
);
163 case eNPP_DestroyStream
:
164 TRACE( "eNPP_DestroyStream" );
165 nRet
= (_NPPfuncs
.destroystream
166 ? (*_NPPfuncs
.destroystream
)(
168 (NPStream
*)m_aArgs
[1],
169 (NPError
)(sal_IntPtr
)m_aArgs
[2] )
170 : NPERR_GENERIC_ERROR
);
174 nRet
= (_NPPfuncs
.newp
176 (NPMIMEType
)m_aArgs
[0],
178 (uint16
)(sal_IntPtr
)m_aArgs
[2],
179 (int16
)(sal_IntPtr
)m_aArgs
[3],
182 (NPSavedData
*)m_aArgs
[6] )
183 : NPERR_GENERIC_ERROR
);
186 TRACE( "eNPP_NewStream" );
187 nRet
= (_NPPfuncs
.newstream
188 ? (*_NPPfuncs
.newstream
)(
190 (NPMIMEType
)m_aArgs
[1],
191 (NPStream
*)m_aArgs
[2],
192 (NPBool
)(sal_IntPtr
)m_aArgs
[3],
193 (uint16
*)m_aArgs
[4] )
194 : NPERR_GENERIC_ERROR
);
197 TRACE( "eNPP_Print" );
201 (NPPrint
*)m_aArgs
[1] );
205 TRACE( "eNPP_SetWindow" );
206 nRet
= (_NPPfuncs
.setwindow
207 ? (*_NPPfuncs
.setwindow
)(
209 (NPWindow
*)m_aArgs
[1] )
210 : NPERR_GENERIC_ERROR
);
213 case eNPP_StreamAsFile
:
214 TRACE( "eNPP_StreamAsFile" );
215 if (_NPPfuncs
.asfile
)
218 (NPStream
*)m_aArgs
[1],
222 TRACE( "eNPP_URLNotify" );
223 if (_NPPfuncs
.urlnotify
)
224 (*_NPPfuncs
.urlnotify
)(
227 (NPReason
)(sal_IntPtr
)m_aArgs
[2],
231 TRACEN( "eNPP_Write n=", (int32
)m_aArgs
[3] );
232 nRet
= (_NPPfuncs
.write
233 ? (*_NPPfuncs
.write
)(
235 (NPStream
*)m_aArgs
[1],
241 case eNPP_WriteReady
:
242 TRACE( "eNPP_WriteReady" );
243 nRet
= (_NPPfuncs
.writeready
244 ? (*_NPPfuncs
.writeready
)(
246 (NPStream
*)m_aArgs
[1] )
250 TRACE( "eNPP_GetValue" );
251 nRet
= (_NPPfuncs
.getvalue
252 ? (*_NPPfuncs
.getvalue
)(
254 (NPPVariable
)(int)m_aArgs
[1],
256 : NPERR_GENERIC_ERROR
);
259 TRACE( "eNPP_SetValue" );
260 nRet
= (_NPPfuncs
.setvalue
261 ? (*_NPPfuncs
.setvalue
)(
263 (NPNVariable
)(int)m_aArgs
[1],
265 : NPERR_GENERIC_ERROR
);
269 TRACE( "eNPP_Shutdown" );
270 NPP_ShutdownUPP pFunc
;
271 if (retrieveFunction( _T("NPP_Shutdown"), (void**)&pFunc
))
275 case eNPP_Initialize
:
276 TRACE( "eNPP_Initialize" );
277 OSL_ENSURE( false, "NPP_Initialize: not implemented!" );
279 case eNPP_GetJavaClass
:
280 TRACE( "eNPP_GetJavaClass" );
281 OSL_ENSURE( false, "NPP_GetJavaClass: not implemented!" );
287 //--------------------------------------------------------------------------------------------------
288 NPError
PluginComm_Impl::NPP_Destroy( NPP instance
, NPSavedData
** save
)
290 DBG_ASSERT( _NPPfuncs
.destroy
, "### NPP_Destroy(): null pointer in NPP functions table!" );
291 m_eCall
= eNPP_Destroy
;
292 m_aArgs
[0] = (void*)instance
;
293 m_aArgs
[1] = (void*)save
;
294 return (NPError
)execute();
297 //--------------------------------------------------------------------------------------------------
298 NPError
PluginComm_Impl::NPP_DestroyStream( NPP instance
, NPStream
* stream
, NPError reason
)
300 DBG_ASSERT( _NPPfuncs
.destroystream
, "### NPP_DestroyStream(): null pointer in NPP functions table!" );
301 m_eCall
= eNPP_DestroyStream
;
302 m_aArgs
[0] = (void*)instance
;
303 m_aArgs
[1] = (void*)stream
;
304 m_aArgs
[2] = (void*)reason
;
305 return (NPError
)execute();
308 //--------------------------------------------------------------------------------------------------
309 NPError
PluginComm_Impl::NPP_New( NPMIMEType pluginType
, NPP instance
, uint16 mode
, int16 argc
,
310 char* argn
[], char* argv
[], NPSavedData
*saved
)
312 DBG_ASSERT( _NPPfuncs
.newp
, "### NPP_New(): null pointer in NPP functions table!" );
314 m_aArgs
[0] = (void*)pluginType
;
315 m_aArgs
[1] = (void*)instance
;
316 m_aArgs
[2] = (void*)mode
;
317 m_aArgs
[3] = (void*)argc
;
318 m_aArgs
[4] = (void*)argn
;
319 m_aArgs
[5] = (void*)argv
;
320 m_aArgs
[6] = (void*)saved
;
321 return (NPError
)execute();
324 //--------------------------------------------------------------------------------------------------
325 NPError
PluginComm_Impl::NPP_NewStream( NPP instance
, NPMIMEType type
, NPStream
* stream
,
326 NPBool seekable
, uint16
* stype
)
328 DBG_ASSERT( _NPPfuncs
.newstream
, "### NPP_NewStream(): null pointer in NPP functions table!" );
329 m_eCall
= eNPP_NewStream
;
330 m_aArgs
[0] = (void*)instance
;
331 m_aArgs
[1] = (void*)type
;
332 m_aArgs
[2] = (void*)stream
;
333 m_aArgs
[3] = (void*)seekable
;
334 m_aArgs
[4] = (void*)stype
;
335 return (NPError
)execute();
338 //--------------------------------------------------------------------------------------------------
339 void PluginComm_Impl::NPP_Print( NPP instance
, NPPrint
* platformPrint
)
341 DBG_ASSERT( _NPPfuncs
.print
, "### NPP_Print(): null pointer in NPP functions table!" );
342 m_eCall
= eNPP_Print
;
343 m_aArgs
[0] = (void*)instance
;
344 m_aArgs
[1] = (void*)platformPrint
;
348 //--------------------------------------------------------------------------------------------------
349 NPError
PluginComm_Impl::NPP_SetWindow( NPP instance
, NPWindow
* window
)
351 DBG_ASSERT( _NPPfuncs
.setwindow
, "### NPP_SetWindow(): null pointer in NPP functions table!" );
352 m_eCall
= eNPP_SetWindow
;
353 m_aArgs
[0] = (void*)instance
;
354 m_aArgs
[1] = (void*)window
;
355 return (NPError
)execute();
358 //--------------------------------------------------------------------------------------------------
359 void PluginComm_Impl::NPP_StreamAsFile( NPP instance
, NPStream
* stream
, const char* fname
)
361 DBG_ASSERT( _NPPfuncs
.asfile
, "### NPP_StreamAsFile(): null pointer in NPP functions table!" );
362 m_eCall
= eNPP_StreamAsFile
;
363 m_aArgs
[0] = (void*)instance
;
364 m_aArgs
[1] = (void*)stream
;
365 m_aArgs
[2] = (void*)fname
;
369 //--------------------------------------------------------------------------------------------------
370 void PluginComm_Impl::NPP_URLNotify( NPP instance
, const char* url
, NPReason reason
, void* notifyData
)
372 DBG_ASSERT( _NPPfuncs
.urlnotify
, "### NPP_URLNotify(): null pointer in NPP functions table!" );
373 m_eCall
= eNPP_URLNotify
;
374 m_aArgs
[0] = (void*)instance
;
375 m_aArgs
[1] = (void*)url
;
376 m_aArgs
[2] = (void*)reason
;
377 m_aArgs
[3] = notifyData
;
381 //--------------------------------------------------------------------------------------------------
382 int32
PluginComm_Impl::NPP_Write( NPP instance
, NPStream
* stream
, int32 offset
, int32 len
, void* buffer
)
384 DBG_ASSERT( _NPPfuncs
.write
, "### NPP_Write(): null pointer in NPP functions table!" );
385 m_eCall
= eNPP_Write
;
386 m_aArgs
[0] = (void*)instance
;
387 m_aArgs
[1] = (void*)stream
;
388 m_aArgs
[2] = (void*)offset
;
389 m_aArgs
[3] = (void*)len
;
391 return (NPError
)execute();
394 //--------------------------------------------------------------------------------------------------
395 int32
PluginComm_Impl::NPP_WriteReady( NPP instance
, NPStream
* stream
)
397 DBG_ASSERT( _NPPfuncs
.writeready
, "### NPP_WriteReady(): null pointer in NPP functions table!" );
398 m_eCall
= eNPP_WriteReady
;
399 m_aArgs
[0] = (void*)instance
;
400 m_aArgs
[1] = (void*)stream
;
404 //--------------------------------------------------------------------------------------------------
405 NPError
PluginComm_Impl::NPP_GetValue( NPP instance
, NPPVariable variable
, void *ret_value
)
407 DBG_ASSERT( _NPPfuncs
.getvalue
, "### NPP_GetValue(): null pointer in NPP functions table!" );
408 m_eCall
= eNPP_GetValue
;
409 m_aArgs
[0] = (void*)instance
;
410 m_aArgs
[1] = (void*)variable
;
411 m_aArgs
[2] = ret_value
;
412 return (NPError
)execute();
415 //--------------------------------------------------------------------------------------------------
416 NPError
PluginComm_Impl::NPP_SetValue( NPP instance
, NPNVariable variable
, void *set_value
)
418 DBG_ASSERT( _NPPfuncs
.setvalue
, "### NPP_SetValue(): null pointer in NPP functions table!" );
419 m_eCall
= eNPP_SetValue
;
420 m_aArgs
[0] = (void*)instance
;
421 m_aArgs
[1] = (void*)variable
;
422 m_aArgs
[2] = set_value
;
423 return (NPError
)execute();
426 //--------------------------------------------------------------------------------------------------
427 void * PluginComm_Impl::NPP_GetJavaClass()
429 DBG_ERROR( "no java class available!" );
433 //--------------------------------------------------------------------------------------------------
434 NPError
PluginComm_Impl::NPP_Initialize()
436 return NPERR_NO_ERROR
;
439 //--------------------------------------------------------------------------------------------------
440 void PluginComm_Impl::NPP_Shutdown()
442 m_eCall
= eNPP_Shutdown
;
446 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */