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