LCOV - code coverage report
Current view: top level - libreoffice/extensions/source/plugin/base - manager.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 87 0.0 %
Date: 2012-12-27 Functions: 0 17 0.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10