1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
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.
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).
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.
27 ************************************************************************/
31 #define _LINUX_SOURCE_COMPAT
32 #include <sys/timer.h>
33 #undef _LINUX_SOURCE_COMPAT
43 #include <comphelper/string.hxx>
44 #include <comphelper/processfactory.hxx>
46 #include "plugin/impl.hxx"
48 #include "osl/mutex.hxx"
49 #include "unotools/pathoptions.hxx"
50 #include "vcl/configsettings.hxx"
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"
59 #include <cppuhelper/supportsservice.hxx>
61 PluginManager
* PluginManager::pManager
= NULL
;
63 PluginManager
& PluginManager::get()
66 pManager
= new PluginManager();
70 void PluginManager::setServiceFactory( const Reference
< ::com::sun::star::lang::XMultiServiceFactory
>& xFactory
)
72 PluginManager
& rManager
= get();
73 if( ! rManager
.m_xSMgr
.is() )
74 rManager
.m_xSMgr
= xFactory
;
77 PluginManager::PluginManager()
81 const Sequence
< OUString
>& PluginManager::getAdditionalSearchPaths()
83 static Sequence
< OUString
> aPaths
;
85 if( ! aPaths
.getLength() )
87 SvtPathOptions aOptions
;
88 OUString
aPluginPath( aOptions
.GetPluginPath() );
89 if( !aPluginPath
.isEmpty() )
91 sal_Int32 nPaths
= comphelper::string::getTokenCount(aPluginPath
, ';');
92 aPaths
.realloc( nPaths
);
93 for( sal_uInt16 i
= 0; i
< nPaths
; i
++ )
94 aPaths
.getArray()[i
] = aPluginPath
.getToken(i
, ';');
102 Reference
< XInterface
> SAL_CALL
PluginManager_CreateInstance( const Reference
< ::com::sun::star::lang::XMultiServiceFactory
> & rSMgr
) throw( Exception
)
104 Reference
< XInterface
> xService
= *new XPluginManager_Impl( comphelper::getComponentContext(rSMgr
) );
108 // ::com::sun::star::lang::XServiceInfo
109 OUString
XPluginManager_Impl::getImplementationName() throw( )
112 return getImplementationName_Static();
116 // ::com::sun::star::lang::XServiceInfo
117 sal_Bool
XPluginManager_Impl::supportsService(const OUString
& ServiceName
) throw( )
119 return cppu::supportsService(this, ServiceName
);
122 // ::com::sun::star::lang::XServiceInfo
123 Sequence
< OUString
> XPluginManager_Impl::getSupportedServiceNames() throw( )
125 return getSupportedServiceNames_Static();
128 // XPluginManager_Impl
129 Sequence
< OUString
> XPluginManager_Impl::getSupportedServiceNames_Static() throw( )
131 Sequence
< OUString
> aSNS( 1 );
132 aSNS
[0] = "com.sun.star.plugin.PluginManager";
136 XPluginManager_Impl::XPluginManager_Impl( const Reference
< ::com::sun::star::uno::XComponentContext
> & rxContext
)
137 : m_xContext( rxContext
)
139 PluginManager::setServiceFactory( Reference
< ::com::sun::star::lang::XMultiServiceFactory
>(rxContext
->getServiceManager(), UNO_QUERY_THROW
) );
142 XPluginManager_Impl::~XPluginManager_Impl()
146 XPlugin_Impl
* XPluginManager_Impl::getXPluginFromNPP( NPP instance
)
148 ::std::list
<XPlugin_Impl
*>::iterator iter
;
149 for( iter
= PluginManager::get().getPlugins().begin();
150 iter
!= PluginManager::get().getPlugins().end(); ++iter
)
152 if( &(*iter
)->getNPPInstance() == instance
)
159 XPlugin_Impl
* XPluginManager_Impl::getPluginImplementation( const Reference
< ::com::sun::star::plugin::XPlugin
>& plugin
)
161 ::std::list
<XPlugin_Impl
*>::iterator iter
;
162 for( iter
= PluginManager::get().getPlugins().begin();
163 iter
!= PluginManager::get().getPlugins().end(); ++iter
)
165 if( plugin
== Reference
< ::com::sun::star::plugin::XPlugin
>((*iter
)) )
172 Sequence
<com::sun::star::plugin::PluginDescription
> XPluginManager_Impl::getPluginDescriptions()
173 throw (RuntimeException
, std::exception
)
175 Sequence
<com::sun::star::plugin::PluginDescription
> aRet
;
177 vcl::SettingsConfigItem
* pCfg
= vcl::SettingsConfigItem::get();
178 OUString
aVal( pCfg
->getValue( OUString( "BrowserPlugins" ),
179 OUString( "Disabled" ) ) );
180 if( ! aVal
.toBoolean() )
182 aRet
= impl_getPluginDescriptions();
187 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
)
190 XPlugin_Impl
* pImpl
= new XPlugin_Impl( Reference
< ::com::sun::star::lang::XMultiServiceFactory
>(m_xContext
->getServiceManager(), UNO_QUERY_THROW
) );
191 pImpl
->setPluginContext( acontext
);
193 PluginManager::get().getPlugins().push_back( pImpl
);
195 pImpl
->initInstance( plugintype
,
203 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 (RuntimeException
, std::exception
)
205 XPlugin_Impl
* pImpl
= new XPlugin_Impl( Reference
< ::com::sun::star::lang::XMultiServiceFactory
>(m_xContext
->getServiceManager(), UNO_QUERY_THROW
) );
206 Reference
< ::com::sun::star::plugin::XPlugin
> xRef
= pImpl
;
208 pImpl
->setPluginContext( acontext
);
210 PluginManager::get().getPlugins().push_back( pImpl
);
213 pImpl
->initInstance( url
,
218 pImpl
->createPeer( toolkit
, parent
);
220 pImpl
->provideNewStream( pImpl
->getDescription().Mimetype
,
221 Reference
< com::sun::star::io::XActiveDataSource
>(),
223 0, 0, url
.startsWith("file:") );
225 if( ! pImpl
->getPluginComm() )
234 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */