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 :
29 :
30 : #ifdef AIX
31 : #define _LINUX_SOURCE_COMPAT
32 : #include <sys/timer.h>
33 : #undef _LINUX_SOURCE_COMPAT
34 : #endif
35 :
36 : #ifdef WNT
37 : #include <prewin.h>
38 : #include <postwin.h>
39 : #undef OPTIONAL
40 : #endif
41 :
42 : #include <cstdarg>
43 :
44 : #include <comphelper/string.hxx>
45 : #include <comphelper/processfactory.hxx>
46 :
47 : #include "plugin/impl.hxx"
48 :
49 : #include "osl/mutex.hxx"
50 : #include "unotools/pathoptions.hxx"
51 : #include "vcl/configsettings.hxx"
52 :
53 : #include "com/sun/star/container/XEnumerationAccess.hpp"
54 : #include "com/sun/star/container/XNameAccess.hpp"
55 : #include "com/sun/star/container/XEnumeration.hpp"
56 : #include "com/sun/star/container/XElementAccess.hpp"
57 : #include "com/sun/star/container/XIndexAccess.hpp"
58 : #include "com/sun/star/loader/XImplementationLoader.hpp"
59 :
60 : #include <cppuhelper/supportsservice.hxx>
61 :
62 : PluginManager* PluginManager::pManager = NULL;
63 :
64 0 : PluginManager& PluginManager::get()
65 : {
66 0 : if( ! pManager )
67 0 : pManager = new PluginManager();
68 0 : return *pManager;
69 : }
70 :
71 0 : void PluginManager::setServiceFactory( const Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory )
72 : {
73 0 : PluginManager& rManager = get();
74 0 : if( ! rManager.m_xSMgr.is() )
75 0 : rManager.m_xSMgr = xFactory;
76 0 : }
77 :
78 0 : PluginManager::PluginManager()
79 : {
80 0 : }
81 :
82 0 : const Sequence< OUString >& PluginManager::getAdditionalSearchPaths()
83 : {
84 0 : static Sequence< OUString > aPaths;
85 :
86 0 : if( ! aPaths.getLength() )
87 : {
88 0 : SvtPathOptions aOptions;
89 0 : OUString aPluginPath( aOptions.GetPluginPath() );
90 0 : if( !aPluginPath.isEmpty() )
91 : {
92 0 : sal_Int32 nPaths = comphelper::string::getTokenCount(aPluginPath, ';');
93 0 : aPaths.realloc( nPaths );
94 0 : for( sal_uInt16 i = 0; i < nPaths; i++ )
95 0 : aPaths.getArray()[i] = comphelper::string::getToken(aPluginPath, i, ';');
96 0 : }
97 : }
98 :
99 0 : return aPaths;
100 : }
101 :
102 :
103 0 : Reference< XInterface > SAL_CALL PluginManager_CreateInstance( const Reference< ::com::sun::star::lang::XMultiServiceFactory > & rSMgr ) throw( Exception )
104 : {
105 0 : Reference< XInterface > xService = *new XPluginManager_Impl( comphelper::getComponentContext(rSMgr) );
106 0 : return xService;
107 : }
108 :
109 : // ::com::sun::star::lang::XServiceInfo
110 0 : OUString XPluginManager_Impl::getImplementationName() throw( )
111 :
112 : {
113 0 : return getImplementationName_Static();
114 :
115 : }
116 :
117 : // ::com::sun::star::lang::XServiceInfo
118 0 : sal_Bool XPluginManager_Impl::supportsService(const OUString& ServiceName) throw( )
119 : {
120 0 : return cppu::supportsService(this, ServiceName);
121 : }
122 :
123 : // ::com::sun::star::lang::XServiceInfo
124 0 : Sequence< OUString > XPluginManager_Impl::getSupportedServiceNames(void) throw( )
125 : {
126 0 : return getSupportedServiceNames_Static();
127 : }
128 :
129 : // XPluginManager_Impl
130 0 : Sequence< OUString > XPluginManager_Impl::getSupportedServiceNames_Static(void) throw( )
131 : {
132 0 : Sequence< OUString > aSNS( 1 );
133 0 : aSNS[0] = "com.sun.star.plugin.PluginManager";
134 0 : return aSNS;
135 : }
136 :
137 0 : XPluginManager_Impl::XPluginManager_Impl( const Reference< ::com::sun::star::uno::XComponentContext > & rxContext )
138 0 : : m_xContext( rxContext )
139 : {
140 0 : PluginManager::setServiceFactory( Reference< ::com::sun::star::lang::XMultiServiceFactory>(rxContext->getServiceManager(), UNO_QUERY_THROW) );
141 0 : }
142 :
143 0 : XPluginManager_Impl::~XPluginManager_Impl()
144 : {
145 0 : }
146 :
147 0 : XPlugin_Impl* XPluginManager_Impl::getXPluginFromNPP( NPP instance )
148 : {
149 0 : ::std::list<XPlugin_Impl*>::iterator iter;
150 0 : for( iter = PluginManager::get().getPlugins().begin();
151 0 : iter != PluginManager::get().getPlugins().end(); ++iter )
152 : {
153 0 : if( (*iter)->getNPPInstance() == instance )
154 0 : return *iter;
155 : }
156 :
157 0 : return NULL;
158 : }
159 :
160 0 : XPlugin_Impl* XPluginManager_Impl::getPluginImplementation( const Reference< ::com::sun::star::plugin::XPlugin >& plugin )
161 : {
162 0 : ::std::list<XPlugin_Impl*>::iterator iter;
163 0 : for( iter = PluginManager::get().getPlugins().begin();
164 0 : iter != PluginManager::get().getPlugins().end(); ++iter )
165 : {
166 0 : if( plugin == Reference< ::com::sun::star::plugin::XPlugin >((*iter)) )
167 0 : return *iter;
168 : }
169 :
170 0 : return NULL;
171 : }
172 :
173 0 : Sequence<com::sun::star::plugin::PluginDescription> XPluginManager_Impl::getPluginDescriptions() throw(std::exception)
174 : {
175 0 : Sequence<com::sun::star::plugin::PluginDescription> aRet;
176 :
177 0 : vcl::SettingsConfigItem* pCfg = vcl::SettingsConfigItem::get();
178 : OUString aVal( pCfg->getValue( OUString( "BrowserPlugins" ),
179 0 : OUString( "Disabled" ) ) );
180 0 : if( ! aVal.toBoolean() )
181 : {
182 0 : aRet = impl_getPluginDescriptions();
183 : }
184 0 : return aRet;
185 : }
186 :
187 0 : Reference< ::com::sun::star::plugin::XPlugin > XPluginManager_Impl::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)
188 : throw( RuntimeException,::com::sun::star::plugin::PluginException, std::exception )
189 : {
190 0 : XPlugin_Impl* pImpl = new XPlugin_Impl( Reference< ::com::sun::star::lang::XMultiServiceFactory>(m_xContext->getServiceManager(), UNO_QUERY_THROW) );
191 0 : pImpl->setPluginContext( acontext );
192 :
193 0 : PluginManager::get().getPlugins().push_back( pImpl );
194 :
195 : pImpl->initInstance( plugintype,
196 : argn,
197 : argv,
198 0 : mode );
199 :
200 0 : return pImpl;
201 : }
202 :
203 0 : Reference< ::com::sun::star::plugin::XPlugin > XPluginManager_Impl::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)
204 : {
205 0 : XPlugin_Impl* pImpl = new XPlugin_Impl( Reference< ::com::sun::star::lang::XMultiServiceFactory>(m_xContext->getServiceManager(), UNO_QUERY_THROW) );
206 0 : Reference< ::com::sun::star::plugin::XPlugin > xRef = pImpl;
207 :
208 0 : pImpl->setPluginContext( acontext );
209 :
210 0 : PluginManager::get().getPlugins().push_back( pImpl );
211 :
212 :
213 : pImpl->initInstance( url,
214 : argn,
215 : argv,
216 0 : mode );
217 :
218 0 : pImpl->createPeer( toolkit, parent );
219 :
220 0 : pImpl->provideNewStream( pImpl->getDescription().Mimetype,
221 : Reference< com::sun::star::io::XActiveDataSource >(),
222 : url,
223 0 : 0, 0, url.startsWith("file:") );
224 :
225 0 : if( ! pImpl->getPluginComm() )
226 : {
227 0 : pImpl->dispose();
228 0 : xRef = NULL;
229 : }
230 :
231 0 : return xRef;
232 : }
233 :
234 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|