LCOV - code coverage report
Current view: top level - extensions/source/plugin/base - manager.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 28 82 34.1 %
Date: 2015-06-13 12:38:46 Functions: 10 17 58.8 %
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             : #endif
      40             : 
      41             : #include <cstdarg>
      42             : 
      43             : #include <comphelper/string.hxx>
      44             : #include <comphelper/processfactory.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             : #include <cppuhelper/supportsservice.hxx>
      60             : 
      61             : PluginManager* PluginManager::pManager = NULL;
      62             : 
      63           1 : PluginManager& PluginManager::get()
      64             : {
      65           1 :     if( ! pManager )
      66           1 :         pManager = new PluginManager();
      67           1 :     return *pManager;
      68             : }
      69             : 
      70           1 : void PluginManager::setServiceFactory( const Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory )
      71             : {
      72           1 :     PluginManager& rManager = get();
      73           1 :     if( ! rManager.m_xSMgr.is() )
      74           1 :         rManager.m_xSMgr = xFactory;
      75           1 : }
      76             : 
      77           1 : PluginManager::PluginManager()
      78             : {
      79           1 : }
      80             : 
      81           0 : const Sequence< OUString >& PluginManager::getAdditionalSearchPaths()
      82             : {
      83           0 :     static Sequence< OUString > aPaths;
      84             : 
      85           0 :     if( ! aPaths.getLength() )
      86             :     {
      87           0 :         SvtPathOptions aOptions;
      88           0 :         OUString aPluginPath( aOptions.GetPluginPath() );
      89           0 :         if( !aPluginPath.isEmpty() )
      90             :         {
      91           0 :             sal_Int32 nPaths = comphelper::string::getTokenCount(aPluginPath, ';');
      92           0 :             aPaths.realloc( nPaths );
      93           0 :             for( sal_Int32 i = 0; i < nPaths; i++ )
      94           0 :                 aPaths.getArray()[i] = aPluginPath.getToken(i, ';');
      95           0 :         }
      96             :     }
      97             : 
      98           0 :     return aPaths;
      99             : }
     100             : 
     101             : 
     102           1 : Reference< XInterface > SAL_CALL PluginManager_CreateInstance( const Reference< ::com::sun::star::lang::XMultiServiceFactory >  & rSMgr ) throw( Exception )
     103             : {
     104           1 :     Reference< XInterface >  xService = *new XPluginManager_Impl( comphelper::getComponentContext(rSMgr) );
     105           1 :     return xService;
     106             : }
     107             : 
     108             : // ::com::sun::star::lang::XServiceInfo
     109           1 : OUString XPluginManager_Impl::getImplementationName() throw(  )
     110             : 
     111             : {
     112           1 :     return getImplementationName_Static();
     113             : 
     114             : }
     115             : 
     116             : // ::com::sun::star::lang::XServiceInfo
     117           0 : sal_Bool XPluginManager_Impl::supportsService(const OUString& ServiceName) throw(  )
     118             : {
     119           0 :     return cppu::supportsService(this, ServiceName);
     120             : }
     121             : 
     122             : // ::com::sun::star::lang::XServiceInfo
     123           1 : Sequence< OUString > XPluginManager_Impl::getSupportedServiceNames() throw(  )
     124             : {
     125           1 :     return getSupportedServiceNames_Static();
     126             : }
     127             : 
     128             : // XPluginManager_Impl
     129           2 : Sequence< OUString > XPluginManager_Impl::getSupportedServiceNames_Static() throw(  )
     130             : {
     131           2 :     Sequence< OUString > aSNS( 1 );
     132           2 :     aSNS[0] = "com.sun.star.plugin.PluginManager";
     133           2 :     return aSNS;
     134             : }
     135             : 
     136           1 : XPluginManager_Impl::XPluginManager_Impl( const Reference< ::com::sun::star::uno::XComponentContext >  & rxContext )
     137           1 : : m_xContext( rxContext )
     138             : {
     139           1 :     PluginManager::setServiceFactory( Reference< ::com::sun::star::lang::XMultiServiceFactory>(rxContext->getServiceManager(), UNO_QUERY_THROW) );
     140           1 : }
     141             : 
     142           2 : XPluginManager_Impl::~XPluginManager_Impl()
     143             : {
     144           2 : }
     145             : 
     146           0 : XPlugin_Impl* XPluginManager_Impl::getXPluginFromNPP( NPP instance )
     147             : {
     148           0 :     ::std::list<XPlugin_Impl*>::iterator iter;
     149           0 :     for( iter = PluginManager::get().getPlugins().begin();
     150           0 :          iter != PluginManager::get().getPlugins().end(); ++iter )
     151             :     {
     152           0 :         if( &(*iter)->getNPPInstance() == instance )
     153           0 :             return *iter;
     154             :     }
     155             : 
     156           0 :     return NULL;
     157             : }
     158             : 
     159           0 : XPlugin_Impl* XPluginManager_Impl::getPluginImplementation( const Reference< ::com::sun::star::plugin::XPlugin >& plugin )
     160             : {
     161           0 :     ::std::list<XPlugin_Impl*>::iterator iter;
     162           0 :     for( iter = PluginManager::get().getPlugins().begin();
     163           0 :          iter != PluginManager::get().getPlugins().end(); ++iter )
     164             :     {
     165           0 :         if( plugin == Reference< ::com::sun::star::plugin::XPlugin >((*iter)) )
     166           0 :             return *iter;
     167             :     }
     168             : 
     169           0 :     return NULL;
     170             : }
     171             : 
     172           0 : Sequence<com::sun::star::plugin::PluginDescription> XPluginManager_Impl::getPluginDescriptions()
     173             :     throw (RuntimeException, 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 (RuntimeException, 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: */

Generated by: LCOV version 1.11