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