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