bump product version to 4.1.6.2
[LibreOffice.git] / extensions / source / plugin / win / sysplug.cxx
blobf50bc30ed508086ae3a1ba0e6b86bc2696230e37
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 ************************************************************************/
30 #include <prewin.h>
31 #include <postwin.h>
32 #undef OPTIONAL
34 #include <plugin/impl.hxx>
36 #if defined _MSC_VER
37 #pragma warning (push,1)
38 #pragma warning (disable:4005)
39 #endif
41 #include <string.h>
42 #include <tchar.h>
43 #include <objbase.h>
45 #if defined _MSC_VER
46 #pragma warning (pop)
47 #endif
49 #include <list>
50 #include <map>
51 #include <algorithm>
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 );
62 #else
63 #define TRACE(x)
64 #define TRACEN(x,n)
65 #endif
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 ) );
78 #ifdef UNICODE
79 _plDLL = ::LoadLibrary( rName.getStr() );
80 #else
81 OString aStr( OUStringToOString( rName, RTL_TEXTENCODING_MS_1252 ) );
82 _plDLL = ::LoadLibrary( aStr.getStr() );
83 #endif
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 );
93 SAL_WARN_IF(
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;
100 execute();
103 //--------------------------------------------------------------------------------------------------
104 PluginComm_Impl::~PluginComm_Impl()
106 if (_plDLL)
108 // NPP_Shutdown();
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!" );
119 _plDLL = NULL;
123 //--------------------------------------------------------------------------------------------------
124 BOOL PluginComm_Impl::retrieveFunction( TCHAR const * pName, void** ppFunc ) const
126 if( ! _plDLL )
127 return FALSE;
129 *ppFunc = (void*)::GetProcAddress( _plDLL, pName );
131 return (*ppFunc != NULL);
134 //--------------------------------------------------------------------------------------------------
136 long PluginComm_Impl::doIt()
138 long nRet = 0;
139 switch( m_eCall )
141 case eNP_Initialize:
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 );
151 else
153 nRet = NPERR_GENERIC_ERROR;
155 DBG_ASSERT( nRet == NPERR_NO_ERROR, "### NP_Initialize() failed!" );
157 break;
158 case eNPP_Destroy:
159 TRACE( "eNPP_Destroy" );
160 nRet = (_NPPfuncs.destroy
161 ? (*_NPPfuncs.destroy)(
162 (NPP)m_aArgs[0],
163 (NPSavedData**)m_aArgs[1] )
164 : NPERR_GENERIC_ERROR);
165 break;
166 case eNPP_DestroyStream:
167 TRACE( "eNPP_DestroyStream" );
168 nRet = (_NPPfuncs.destroystream
169 ? (*_NPPfuncs.destroystream)(
170 (NPP)m_aArgs[0],
171 (NPStream*)m_aArgs[1],
172 (NPError)(sal_IntPtr)m_aArgs[2] )
173 : NPERR_GENERIC_ERROR);
174 break;
175 case eNPP_New:
176 TRACE( "eNPP_New" );
177 nRet = (_NPPfuncs.newp
178 ? (*_NPPfuncs.newp)(
179 (NPMIMEType)m_aArgs[0],
180 (NPP)m_aArgs[1],
181 (uint16_t)(sal_IntPtr)m_aArgs[2],
182 (int16_t)(sal_IntPtr)m_aArgs[3],
183 (char**)m_aArgs[4],
184 (char**)m_aArgs[5],
185 (NPSavedData*)m_aArgs[6] )
186 : NPERR_GENERIC_ERROR);
187 break;
188 case eNPP_NewStream:
189 TRACE( "eNPP_NewStream" );
190 nRet = (_NPPfuncs.newstream
191 ? (*_NPPfuncs.newstream)(
192 (NPP)m_aArgs[0],
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);
198 break;
199 case eNPP_Print:
200 TRACE( "eNPP_Print" );
201 if (_NPPfuncs.print)
202 (*_NPPfuncs.print)(
203 (NPP)m_aArgs[0],
204 (NPPrint*)m_aArgs[1] );
205 break;
206 case eNPP_SetWindow:
208 TRACE( "eNPP_SetWindow" );
209 nRet = (_NPPfuncs.setwindow
210 ? (*_NPPfuncs.setwindow)(
211 (NPP)m_aArgs[0],
212 (NPWindow*)m_aArgs[1] )
213 : NPERR_GENERIC_ERROR);
214 break;
216 case eNPP_StreamAsFile:
217 TRACE( "eNPP_StreamAsFile" );
218 if (_NPPfuncs.asfile)
219 (*_NPPfuncs.asfile)(
220 (NPP)m_aArgs[0],
221 (NPStream*)m_aArgs[1],
222 (char*)m_aArgs[2] );
223 break;
224 case eNPP_URLNotify:
225 TRACE( "eNPP_URLNotify" );
226 if (_NPPfuncs.urlnotify)
227 (*_NPPfuncs.urlnotify)(
228 (NPP)m_aArgs[0],
229 (char*)m_aArgs[1],
230 (NPReason)(sal_IntPtr)m_aArgs[2],
231 m_aArgs[3] );
232 break;
233 case eNPP_Write:
234 TRACEN( "eNPP_Write n=", (int32_t)m_aArgs[3] );
235 nRet = (_NPPfuncs.write
236 ? (*_NPPfuncs.write)(
237 (NPP)m_aArgs[0],
238 (NPStream*)m_aArgs[1],
239 (int32_t)m_aArgs[2],
240 (int32_t)m_aArgs[3],
241 m_aArgs[4] )
242 : 0);
243 break;
244 case eNPP_WriteReady:
245 TRACE( "eNPP_WriteReady" );
246 nRet = (_NPPfuncs.writeready
247 ? (*_NPPfuncs.writeready)(
248 (NPP)m_aArgs[0],
249 (NPStream*)m_aArgs[1] )
250 : 0);
251 break;
252 case eNPP_GetValue:
253 TRACE( "eNPP_GetValue" );
254 nRet = (_NPPfuncs.getvalue
255 ? (*_NPPfuncs.getvalue)(
256 (NPP)m_aArgs[0],
257 (NPPVariable)(int)m_aArgs[1],
258 m_aArgs[2] )
259 : NPERR_GENERIC_ERROR);
260 break;
261 case eNPP_SetValue:
262 TRACE( "eNPP_SetValue" );
263 nRet = (_NPPfuncs.setvalue
264 ? (*_NPPfuncs.setvalue)(
265 (NPP)m_aArgs[0],
266 (NPNVariable)(int)m_aArgs[1],
267 m_aArgs[2] )
268 : NPERR_GENERIC_ERROR);
269 break;
270 case eNPP_Shutdown:
272 TRACE( "eNPP_Shutdown" );
273 NPP_ShutdownUPP pFunc;
274 if (retrieveFunction( _T("NPP_Shutdown"), (void**)&pFunc ))
275 (*pFunc)();
277 break;
278 case eNPP_Initialize:
279 TRACE( "eNPP_Initialize" );
280 OSL_FAIL( "NPP_Initialize: not implemented!" );
281 break;
282 case eNPP_GetJavaClass:
283 TRACE( "eNPP_GetJavaClass" );
284 OSL_FAIL( "NPP_GetJavaClass: not implemented!" );
285 break;
287 return nRet;
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!" );
316 m_eCall = eNPP_New;
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;
349 execute();
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;
370 execute();
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;
382 execute();
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;
394 m_aArgs[4] = buffer;
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;
405 return execute();
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!" );
434 return 0;
437 //--------------------------------------------------------------------------------------------------
438 NPError PluginComm_Impl::NPP_Initialize()
440 return NPERR_NO_ERROR;
443 //--------------------------------------------------------------------------------------------------
444 void PluginComm_Impl::NPP_Shutdown()
446 m_eCall = eNPP_Shutdown;
447 execute();
450 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */