Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*************************************************************************
3 : *
4 : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : *
6 : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : *
8 : * OpenOffice.org - a multi-platform office productivity suite
9 : *
10 : * This file is part of OpenOffice.org.
11 : *
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.
15 : *
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).
21 : *
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.
26 : *
27 : ************************************************************************/
28 : #ifndef PLUGIN_SOURCE_MGR_IMPL_HXX
29 : #define PLUGIN_SOURCE_MGR_IMPL_HXX
30 :
31 : #include <config_lgpl.h>
32 :
33 : #ifdef SOLARIS
34 : #include <limits>
35 : #endif
36 :
37 : #include <boost/shared_ptr.hpp>
38 :
39 : #include "cppuhelper/weak.hxx"
40 :
41 : #include "com/sun/star/awt/Key.hpp"
42 : #include "com/sun/star/awt/KeyFunction.hpp"
43 : #include "com/sun/star/beans/PropertyAttribute.hpp"
44 : #include "com/sun/star/plugin/PluginMode.hpp"
45 : #include "com/sun/star/plugin/PluginDescription.hpp"
46 : #include "com/sun/star/plugin/PluginException.hpp"
47 : #include "com/sun/star/plugin/PluginVariable.hpp"
48 : #include "com/sun/star/plugin/XPlugin.hpp"
49 : #include "com/sun/star/plugin/XPluginManager.hpp"
50 : #include "com/sun/star/plugin/XPluginContext.hpp"
51 : #include "com/sun/star/io/XConnectable.hpp"
52 : #include "com/sun/star/io/XOutputStream.hpp"
53 : #include "com/sun/star/io/XDataOutputStream.hpp"
54 : #include "com/sun/star/io/XActiveDataControl.hpp"
55 : #include "com/sun/star/io/XDataInputStream.hpp"
56 : #include "com/sun/star/io/XMarkableStream.hpp"
57 : #include "com/sun/star/io/XInputStream.hpp"
58 : #include "com/sun/star/io/XStreamListener.hpp"
59 : #include "com/sun/star/io/XActiveDataSink.hpp"
60 : #include "com/sun/star/io/XActiveDataSource.hpp"
61 : #include "com/sun/star/lang/XServiceName.hpp"
62 : #include "com/sun/star/lang/XServiceInfo.hpp"
63 : #include "com/sun/star/lang/XMultiServiceFactory.hpp"
64 : #include "com/sun/star/lang/XSingleServiceFactory.hpp"
65 : #include "com/sun/star/awt/GradientStyle.hpp"
66 : #include "com/sun/star/awt/RasterOperation.hpp"
67 : #include "com/sun/star/awt/Gradient.hpp"
68 : #include "com/sun/star/awt/XGraphics.hpp"
69 :
70 : #include "cppuhelper/implbase3.hxx"
71 : #include "cppuhelper/implbase2.hxx"
72 : #include "cppuhelper/implbase1.hxx"
73 :
74 : #include <list>
75 :
76 : #ifdef WNT
77 : #include <plugin/win/sysplug.hxx>
78 : #elif defined(MACOSX)
79 : #include "plugin/aqua/sysplug.hxx"
80 : #elif defined(UNX)
81 : #include "plugin/unx/sysplug.hxx"
82 : #endif
83 :
84 : struct SysPlugData;
85 :
86 : ::boost::shared_ptr<SysPlugData> CreateSysPlugData();
87 :
88 : extern "C" {
89 :
90 : void /*SAL_CALL NP_LOADDS*/ NPN_ForceRedraw_Impl(NPP instance);
91 : NPError /*SAL_CALL NP_LOADDS*/ NPN_SetValue_Impl( NPP instance,
92 : NPPVariable variable,
93 : void* value );
94 : } // extern "C"
95 :
96 : #include "plugin/plctrl.hxx"
97 : #include "plugin/model.hxx"
98 :
99 : #include "vcl/sysdata.hxx"
100 : #include "vcl/syschild.hxx"
101 :
102 : #include "tools/link.hxx"
103 : #include "tools/stream.hxx"
104 :
105 :
106 : using namespace com::sun::star::uno;
107 :
108 : #define PROVIDING_NONE 0
109 : #define PROVIDING_NOW 1
110 : #define PROVIDING_MODEL_UPDATE 2
111 :
112 : // forwards
113 : namespace ucbhelper { class Content; }
114 : class PluginStream;
115 : class PluginInputStream;
116 : class PluginOutputStream;
117 : class XPlugin_Impl;
118 : class PluginDisposer;
119 : class PluginEventListener;
120 :
121 : class XPlugin_Impl : public com::sun::star::plugin::XPlugin,
122 : public PluginControl_Impl,
123 : public com::sun::star::beans::XPropertyChangeListener
124 : {
125 : private:
126 : ::osl::Mutex m_aMutex;
127 : Reference< com::sun::star::lang::XMultiServiceFactory > m_xSMgr;
128 : Reference< com::sun::star::plugin::XPluginContext > m_rBrowserContext;
129 :
130 : PluginComm* m_pPluginComm;
131 : NPP_t m_aInstance;
132 : NPWindow m_aNPWindow;
133 : ::boost::shared_ptr<SysPlugData> m_pSysPlugData;
134 : rtl_TextEncoding m_aEncoding;
135 :
136 : const char** m_pArgv;
137 : const char** m_pArgn;
138 : int m_nArgs;
139 : OString m_aLastGetUrl;
140 :
141 : Reference< com::sun::star::awt::XControlModel > m_xModel;
142 :
143 : ::com::sun::star::plugin::PluginDescription m_aDescription;
144 : sal_Int16 m_aPluginMode;
145 :
146 : int m_nProvidingState;
147 : int m_nCalledFromPlugin;
148 : PluginDisposer* m_pDisposer;
149 :
150 : ::std::list<PluginInputStream*> m_aInputStreams;
151 : ::std::list<PluginOutputStream*> m_aOutputStreams;
152 : ::std::list<PluginEventListener*> m_aPEventListeners;
153 : OUString m_aURL;
154 :
155 : sal_Bool m_bIsDisposed;
156 :
157 : #ifdef MACOSX
158 : void SetSysPlugDataParentView(SystemEnvData const& rEnvData);
159 : #endif
160 :
161 : void prependArg( const char* pName, const char* pValue ); // arguments will be strdup'ed
162 : void initArgs( const Sequence< OUString >& argn,
163 : const Sequence< OUString >& argv,
164 : sal_Int16 mode );
165 : void freeArgs();
166 : void handleSpecialArgs();
167 :
168 : void loadPlugin();
169 : void destroyInstance();
170 : void modelChanged();
171 :
172 : public:
173 : XPlugin_Impl( const Reference< com::sun::star::lang::XMultiServiceFactory > & rSMgr );
174 : virtual ~XPlugin_Impl();
175 :
176 0 : ::osl::Mutex& getMutex() { return m_aMutex; }
177 :
178 : void destroyStreams();
179 :
180 0 : void setLastGetUrl( const OString& rUrl ) { m_aLastGetUrl = rUrl; }
181 :
182 : com::sun::star::plugin::PluginDescription fitDescription( const OUString& rURL );
183 :
184 0 : ::std::list<PluginInputStream*>& getInputStreams() { return m_aInputStreams; }
185 0 : ::std::list<PluginOutputStream*>& getOutputStreams() { return m_aOutputStreams; }
186 0 : PluginComm* getPluginComm() { return m_pPluginComm; }
187 0 : void setPluginComm( PluginComm* comm )
188 : {
189 0 : if( ! m_pPluginComm )
190 : {
191 0 : m_pPluginComm = comm;
192 0 : m_pPluginComm->addRef();
193 : }
194 0 : }
195 0 : Reference< com::sun::star::lang::XMultiServiceFactory > getServiceManager() { return m_xSMgr; }
196 0 : const com::sun::star::plugin::PluginDescription& getDescription() const { return m_aDescription; }
197 0 : rtl_TextEncoding getTextEncoding() { return m_aEncoding; }
198 0 : NPP getNPPInstance() { return &m_aInstance; }
199 0 : NPWindow* getNPWindow() { return &m_aNPWindow; }
200 : SysPlugData& getSysPlugData() { return *m_pSysPlugData; }
201 :
202 0 : void enterPluginCallback() { m_nCalledFromPlugin++; }
203 0 : void leavePluginCallback() { m_nCalledFromPlugin--; }
204 0 : sal_Bool isDisposable() { return m_nCalledFromPlugin < 1 ? sal_True : sal_False; }
205 : DECL_LINK( secondLevelDispose, XPlugin_Impl* );
206 :
207 0 : void addPluginEventListener( PluginEventListener* pListener )
208 0 : { m_aPEventListeners.push_back( pListener ); }
209 : void checkListeners( const char* normalizedURL );
210 :
211 : void initInstance(
212 : const com::sun::star::plugin::PluginDescription& rDescription,
213 : const Sequence< OUString >& argn,
214 : const Sequence< OUString >& argv,
215 : sal_Int16 mode );
216 : void initInstance(
217 : const OUString& rURL,
218 : const Sequence< OUString >& argn,
219 : const Sequence< OUString >& argv,
220 : sal_Int16 mode );
221 :
222 0 : const OUString& getRefererURL() { return m_aURL; }
223 : OUString getCreationURL();
224 :
225 : PluginStream* getStreamFromNPStream( NPStream* );
226 :
227 0 : const SystemEnvData* getSysChildSysData()
228 0 : { return _pSysChild->GetSystemData(); }
229 :
230 0 : const Reference< com::sun::star::plugin::XPluginContext > & getPluginContext() const
231 0 : { return m_rBrowserContext; }
232 : void setPluginContext( const Reference< com::sun::star::plugin::XPluginContext > & );
233 :
234 : void secondLevelDispose();
235 :
236 : // static const Reference< com::sun::star::reflection::XIdlClass > & staticGetIdlClass();
237 :
238 : // XInterface
239 : virtual Any SAL_CALL queryInterface( const Type& ) throw( com::sun::star::uno::RuntimeException );
240 0 : virtual void SAL_CALL acquire() throw()
241 0 : { OWeakAggObject::acquire(); }
242 0 : virtual void SAL_CALL release() throw()
243 0 : { OWeakAggObject::release(); }
244 :
245 : // OWeakAggObject
246 : virtual Any SAL_CALL queryAggregation( const Type& )
247 : throw( com::sun::star::uno::RuntimeException );
248 :
249 : // PluginContol_Impl
250 : virtual void SAL_CALL dispose() throw();
251 : virtual void SAL_CALL createPeer( const Reference< com::sun::star::awt::XToolkit > & xToolkit, const Reference< com::sun::star::awt::XWindowPeer > & Parent) throw( RuntimeException );
252 :
253 : virtual sal_Bool SAL_CALL setModel( const Reference< com::sun::star::awt::XControlModel > & Model ) throw( RuntimeException );
254 0 : virtual Reference< com::sun::star::awt::XControlModel > SAL_CALL getModel()throw( RuntimeException )
255 0 : { return m_xModel; }
256 :
257 : virtual void SAL_CALL setPosSize( sal_Int32 nX_, sal_Int32 nY_, sal_Int32 nWidth_, sal_Int32 nHeight_, sal_Int16 nFlags ) throw( RuntimeException );
258 :
259 : // com::sun::star::plugin::XPlugin
260 : virtual sal_Bool SAL_CALL provideNewStream(const OUString& mimetype, const Reference< com::sun::star::io::XActiveDataSource > & stream, const OUString& url, sal_Int32 length, sal_Int32 lastmodified, sal_Bool isfile) throw();
261 :
262 : // com::sun::star::beans::XPropertyChangeListener
263 : virtual void SAL_CALL disposing( const com::sun::star::lang::EventObject& rSource ) throw();
264 : virtual void SAL_CALL propertyChange( const com::sun::star::beans::PropertyChangeEvent& rEvent ) throw();
265 : };
266 :
267 : class PluginManager
268 : {
269 : private:
270 : Reference< com::sun::star::lang::XMultiServiceFactory > m_xSMgr;
271 : ::std::list<PluginComm*> m_aPluginComms;
272 : ::std::list<XPlugin_Impl*> m_aAllPlugins;
273 : ::osl::Mutex m_aPluginMutex;
274 :
275 : static PluginManager* pManager;
276 :
277 : PluginManager();
278 : public:
279 :
280 : static PluginManager& get();
281 : static void setServiceFactory( const Reference< com::sun::star::lang::XMultiServiceFactory >& xFactory );
282 : static const Sequence< OUString >& getAdditionalSearchPaths();
283 :
284 0 : ::std::list<PluginComm*>& getPluginComms() { return m_aPluginComms; }
285 0 : ::std::list<XPlugin_Impl*>& getPlugins() { return m_aAllPlugins; }
286 0 : ::osl::Mutex& getPluginMutex() { return m_aPluginMutex; }
287 : };
288 :
289 : class XPluginManager_Impl :
290 : public cppu::WeakAggImplHelper1< com::sun::star::plugin::XPluginManager >
291 : {
292 : Reference< com::sun::star::uno::XComponentContext > m_xContext;
293 : public:
294 : XPluginManager_Impl( const Reference< com::sun::star::uno::XComponentContext > & );
295 : virtual ~XPluginManager_Impl();
296 :
297 : static XPlugin_Impl* getXPluginFromNPP( NPP );
298 : static XPlugin_Impl* getPluginImplementation( const Reference< com::sun::star::plugin::XPlugin >& plugin );
299 :
300 : virtual Reference< com::sun::star::plugin::XPluginContext > SAL_CALL createPluginContext() throw();
301 :
302 : // has to be implemented per system
303 : virtual Sequence< com::sun::star::plugin::PluginDescription > SAL_CALL impl_getPluginDescriptions(void) throw();
304 : // calls system specific impl_getPluginDescriptions
305 : // checks whether plugins are disabled
306 : virtual Sequence< com::sun::star::plugin::PluginDescription > SAL_CALL getPluginDescriptions(void) throw();
307 :
308 : virtual Reference< com::sun::star::plugin::XPlugin > SAL_CALL createPlugin( const Reference< com::sun::star::plugin::XPluginContext > & acontext, sal_Int16 mode, const Sequence< OUString >& argn, const Sequence< OUString >& argv, const com::sun::star::plugin::PluginDescription& plugintype) throw( RuntimeException,::com::sun::star::plugin::PluginException );
309 :
310 : virtual Reference< com::sun::star::plugin::XPlugin > SAL_CALL createPluginFromURL( const Reference< com::sun::star::plugin::XPluginContext > & acontext, sal_Int16 mode, const Sequence< OUString >& argn, const Sequence< OUString >& argv, const Reference< com::sun::star::awt::XToolkit > & toolkit, const Reference< com::sun::star::awt::XWindowPeer > & parent, const OUString& url ) throw();
311 :
312 : virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) throw();
313 : virtual OUString SAL_CALL getImplementationName() throw();
314 :
315 : Sequence< OUString > SAL_CALL getSupportedServiceNames(void) throw( );
316 : static Sequence< OUString > getSupportedServiceNames_Static(void) throw( );
317 0 : static OUString getImplementationName_Static() throw( )
318 : {
319 : /** the soplayer uses this name in its source! maybe not after 5.2 */
320 0 : return OUString( "com.sun.star.extensions.PluginManager" );
321 : }
322 : };
323 : Reference< XInterface > SAL_CALL PluginManager_CreateInstance( const Reference< com::sun::star::lang::XMultiServiceFactory > & ) throw( Exception );
324 :
325 : enum PluginStreamType { InputStream, OutputStream };
326 :
327 : class PluginStream
328 : {
329 : protected:
330 : XPlugin_Impl* m_pPlugin;
331 : NPStream m_aNPStream;
332 : public:
333 : PluginStream( XPlugin_Impl* pPlugin,
334 : const char* url, sal_uInt32 len, sal_uInt32 lastmod );
335 : virtual ~PluginStream();
336 :
337 0 : NPStream* getStream() { return &m_aNPStream; }
338 : XPlugin_Impl* getPlugin() { return m_pPlugin; }
339 :
340 : virtual PluginStreamType getStreamType() = 0;
341 : };
342 :
343 : class PluginInputStream :
344 : public PluginStream,
345 : public cppu::WeakAggImplHelper2<
346 : ::com::sun::star::io::XOutputStream,
347 : ::com::sun::star::io::XConnectable
348 : >
349 : {
350 : private:
351 : ::ucbhelper::Content* m_pContent;
352 : sal_Int32 m_nMode;
353 : sal_uInt32 m_nWritePos;
354 :
355 : Reference< com::sun::star::io::XActiveDataSource > m_xSource;
356 : // hold a reference on input until closeOutput is called
357 :
358 : Reference< com::sun::star::io::XConnectable > m_xPredecessor;
359 : Reference< com::sun::star::io::XConnectable > m_xSuccessor;
360 :
361 : // needed to hold a reference to self in NP_SEEK mode
362 : Reference< com::sun::star::io::XOutputStream > m_xSelf;
363 :
364 : SvFileStream m_aFileStream;
365 : public:
366 : PluginInputStream( XPlugin_Impl* pPlugin,
367 : const char* url, sal_uInt32 len, sal_uInt32 lastmod );
368 :
369 : PluginInputStream() : PluginStream( NULL, NULL, 0, 0 ) {}
370 :
371 : virtual ~PluginInputStream();
372 :
373 : virtual PluginStreamType getStreamType();
374 :
375 : void setMode( sal_Int32 nMode );
376 : sal_uInt32 read( sal_uInt32 offset, sal_Int8* buffer, sal_uInt32 size );
377 0 : void setSource( const Reference< com::sun::star::io::XActiveDataSource >& xSource ) { m_xSource = xSource; }
378 : // get contents ot url via ucbhelper::Content
379 : void load();
380 :
381 : // clear reference
382 0 : bool releaseSelf()
383 0 : { bool bRet = m_xSelf.is(); m_xSelf.clear(); return bRet; }
384 :
385 : // XOutputStream
386 : virtual void SAL_CALL writeBytes( const Sequence<sal_Int8>& ) throw();
387 : virtual void SAL_CALL flush() throw();
388 : virtual void SAL_CALL closeOutput() throw();
389 :
390 : // XConnectable
391 0 : virtual void SAL_CALL setPredecessor( const Reference< com::sun::star::io::XConnectable >& xPredecessor ) throw()
392 0 : { m_xPredecessor = xPredecessor; }
393 0 : virtual Reference< com::sun::star::io::XConnectable > SAL_CALL getPredecessor() throw()
394 0 : { return m_xPredecessor; }
395 :
396 0 : virtual void SAL_CALL setSuccessor( const Reference< com::sun::star::io::XConnectable >& xSuccessor ) throw()
397 0 : { m_xSuccessor = xSuccessor; }
398 0 : virtual Reference< com::sun::star::io::XConnectable > SAL_CALL getSuccessor() throw()
399 0 : { return m_xSuccessor; }
400 : };
401 :
402 : class PluginOutputStream : public PluginStream
403 : {
404 : private:
405 : Reference< com::sun::star::io::XOutputStream > m_xStream;
406 : public:
407 : PluginOutputStream( XPlugin_Impl* pPlugin, const char* url,
408 : sal_uInt32 len, sal_uInt32 lastmod );
409 : virtual ~PluginOutputStream();
410 :
411 : virtual PluginStreamType getStreamType();
412 :
413 0 : Reference< com::sun::star::io::XOutputStream > & getOutputStream() { return m_xStream; }
414 : };
415 :
416 : class PluginEventListener :
417 : public cppu::WeakAggImplHelper1< com::sun::star::lang::XEventListener >
418 : {
419 : private:
420 : XPlugin_Impl* m_pPlugin;
421 : Reference< com::sun::star::plugin::XPlugin > m_xPlugin; // just to hold the plugin
422 : char* m_pUrl;
423 : char* m_pNormalizedUrl;
424 : void* m_pNotifyData;
425 : public:
426 : PluginEventListener( XPlugin_Impl*,
427 : const char* url,
428 : const char* normurl,
429 : void* notifyData );
430 : virtual ~PluginEventListener();
431 :
432 0 : const char* getURL() { return m_pUrl; }
433 0 : const char* getNormalizedURL() { return m_pNormalizedUrl; }
434 0 : void* getNotifyData() { return m_pNotifyData; }
435 :
436 : // com::sun::star::lang::XEventListener
437 : virtual void SAL_CALL disposing( const com::sun::star::lang::EventObject& Source ) throw();
438 : };
439 :
440 : #endif
441 :
442 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|