LCOV - code coverage report
Current view: top level - connectivity/source/drivers/mozab/bootstrap - MMozillaBootstrap.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 50 78 64.1 %
Date: 2015-06-13 12:38:46 Functions: 13 28 46.4 %
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             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      21             : #include <cppuhelper/supportsservice.hxx>
      22             : #include "MMozillaBootstrap.hxx"
      23             : 
      24             : using namespace com::sun::star::uno;
      25             : using namespace com::sun::star::lang;
      26             : using namespace com::sun::star::mozilla;
      27             : using namespace connectivity::mozab;
      28             : #include "MNSFolders.hxx"
      29             : #include "MNSProfileDiscover.hxx"
      30             : #ifndef MINIMAL_PROFILEDISCOVER
      31             : #  include "MNSProfileManager.hxx"
      32             : #  include "MNSRunnable.hxx"
      33             : #endif
      34             : #include "MNSInit.hxx"
      35             : 
      36             : static MozillaBootstrap *pMozillaBootstrap=NULL;
      37           1 : static Reference<XMozillaBootstrap> xMozillaBootstrap;
      38           1 : extern "C" SAL_DLLPUBLIC_EXPORT void*  SAL_CALL OMozillaBootstrap_CreateInstance(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxFactory)
      39             : {
      40           1 :     if (!pMozillaBootstrap)
      41             :     {
      42           1 :         pMozillaBootstrap=new connectivity::mozab::MozillaBootstrap( _rxFactory );
      43           1 :         pMozillaBootstrap->Init();
      44           1 :         xMozillaBootstrap = pMozillaBootstrap;
      45             :     }
      46           1 :     return  pMozillaBootstrap;
      47             : }
      48             : 
      49           1 : MozillaBootstrap::MozillaBootstrap(
      50             :     const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxFactory)
      51             :     : OMozillaBootstrap_BASE(m_aMutex), m_xMSFactory( _rxFactory ),
      52           1 :       m_ProfileAccess(NULL), m_ProfileManager(NULL)
      53             : {
      54           1 : }
      55             : 
      56           0 : MozillaBootstrap::~MozillaBootstrap()
      57             : {
      58           0 : }
      59             : 
      60           1 : void MozillaBootstrap::Init()
      61             : {
      62           1 :     bool aProfileExists=false;
      63             : 
      64             : #ifndef MINIMAL_PROFILEDISCOVER
      65             :     //This must be call before any mozilla code
      66             :     MNS_Init(aProfileExists);
      67             : 
      68             :     m_ProfileManager = new ProfileManager();
      69             : #else
      70             :     (void)aProfileExists; /* avoid warning about unused parameter */
      71             : #endif
      72           1 :     m_ProfileAccess = new ProfileAccess();
      73           1 :     bootupProfile(::com::sun::star::mozilla::MozillaProductType_Mozilla,OUString());
      74           1 : }
      75             : 
      76             : 
      77           1 : void MozillaBootstrap::disposing()
      78             : {
      79           1 :     ::osl::MutexGuard aGuard(m_aMutex);
      80           1 :     OMozillaBootstrap_BASE::disposing();
      81           1 : }
      82             : 
      83             : // static ServiceInfo
      84             : 
      85           1 : OUString MozillaBootstrap::getImplementationName_Static(  ) throw(RuntimeException)
      86             : {
      87           1 :     return OUString(MOZAB_MozillaBootstrap_IMPL_NAME);
      88             : }
      89             : 
      90           1 : Sequence< OUString > MozillaBootstrap::getSupportedServiceNames_Static(  ) throw (RuntimeException)
      91             : {
      92             :     // which service is supported
      93             :     // for more information @see com.sun.star.mozilla.MozillaBootstrap
      94           1 :     Sequence< OUString > aSNS( 1 );
      95           1 :     aSNS[0] = "com.sun.star.mozilla.MozillaBootstrap";
      96           1 :     return aSNS;
      97             : }
      98             : 
      99             : 
     100           1 : OUString SAL_CALL MozillaBootstrap::getImplementationName(  ) throw(RuntimeException, std::exception)
     101             : {
     102           1 :     return getImplementationName_Static();
     103             : }
     104             : 
     105           0 : sal_Bool SAL_CALL MozillaBootstrap::supportsService( const OUString& _rServiceName ) throw(RuntimeException, std::exception)
     106             : {
     107           0 :     return cppu::supportsService(this, _rServiceName);
     108             : }
     109             : 
     110             : 
     111           1 : Sequence< OUString > SAL_CALL MozillaBootstrap::getSupportedServiceNames(  ) throw(RuntimeException, std::exception)
     112             : {
     113           1 :     return getSupportedServiceNames_Static();
     114             : }
     115             : 
     116             : 
     117             : // XProfileDiscover
     118           0 : ::sal_Int32 SAL_CALL MozillaBootstrap::getProfileCount( ::com::sun::star::mozilla::MozillaProductType product) throw (::com::sun::star::uno::RuntimeException, std::exception)
     119             : {
     120           0 :     return m_ProfileAccess->getProfileCount(product);
     121             : }
     122           0 : ::sal_Int32 SAL_CALL MozillaBootstrap::getProfileList( ::com::sun::star::mozilla::MozillaProductType product, ::com::sun::star::uno::Sequence< OUString >& list ) throw (::com::sun::star::uno::RuntimeException, std::exception)
     123             : {
     124           0 :     return m_ProfileAccess->getProfileList(product,list);
     125             : }
     126           0 : OUString SAL_CALL MozillaBootstrap::getDefaultProfile( ::com::sun::star::mozilla::MozillaProductType product ) throw (::com::sun::star::uno::RuntimeException, std::exception)
     127             : {
     128           0 :     return m_ProfileAccess->getDefaultProfile(product);
     129             : }
     130           0 : OUString SAL_CALL MozillaBootstrap::getProfilePath( ::com::sun::star::mozilla::MozillaProductType product, const OUString& profileName ) throw (::com::sun::star::uno::RuntimeException, std::exception)
     131             : {
     132           0 :     return m_ProfileAccess->getProfilePath(product,profileName);
     133             : }
     134           0 : sal_Bool SAL_CALL MozillaBootstrap::isProfileLocked( ::com::sun::star::mozilla::MozillaProductType product, const OUString& profileName ) throw (::com::sun::star::uno::RuntimeException, std::exception)
     135             : {
     136           0 :     return m_ProfileAccess->isProfileLocked(product,profileName);
     137             : }
     138           0 : sal_Bool SAL_CALL MozillaBootstrap::getProfileExists( ::com::sun::star::mozilla::MozillaProductType product, const OUString& profileName ) throw (::com::sun::star::uno::RuntimeException, std::exception)
     139             : {
     140           0 :     return m_ProfileAccess->getProfileExists(product,profileName);
     141             : }
     142             : 
     143             : // XProfileManager
     144           1 : ::sal_Int32 SAL_CALL MozillaBootstrap::bootupProfile( ::com::sun::star::mozilla::MozillaProductType product, const OUString& profileName ) throw (::com::sun::star::uno::RuntimeException, std::exception)
     145             : {
     146             : #ifndef MINIMAL_PROFILEDISCOVER
     147             :     return m_ProfileManager->bootupProfile(product,profileName);
     148             : #else
     149             :     (void)product; /* avoid warning about unused parameter */
     150             :     (void)profileName; /* avoid warning about unused parameter */
     151           1 :         return -1;
     152             : #endif
     153             : }
     154           0 : ::sal_Int32 SAL_CALL MozillaBootstrap::shutdownProfile(  ) throw (::com::sun::star::uno::RuntimeException, std::exception)
     155             : {
     156             : #ifndef MINIMAL_PROFILEDISCOVER
     157             :     return m_ProfileManager->shutdownProfile();
     158             : #else
     159           0 :     return -1;
     160             : #endif
     161             : }
     162           0 : ::com::sun::star::mozilla::MozillaProductType SAL_CALL MozillaBootstrap::getCurrentProduct(  ) throw (::com::sun::star::uno::RuntimeException, std::exception)
     163             : {
     164             : #ifndef MINIMAL_PROFILEDISCOVER
     165             :     return m_ProfileManager->getCurrentProduct();
     166             : #else
     167           0 :     return ::com::sun::star::mozilla::MozillaProductType_Default;
     168             : #endif
     169             : }
     170           0 : OUString SAL_CALL MozillaBootstrap::getCurrentProfile(  ) throw (::com::sun::star::uno::RuntimeException, std::exception)
     171             : {
     172             : #ifndef MINIMAL_PROFILEDISCOVER
     173             :     return m_ProfileManager->getCurrentProfile();
     174             : #else
     175           0 :     return OUString();
     176             : #endif
     177             : }
     178           0 : sal_Bool SAL_CALL MozillaBootstrap::isCurrentProfileLocked(  ) throw (::com::sun::star::uno::RuntimeException, std::exception)
     179             : {
     180             : #ifndef MINIMAL_PROFILEDISCOVER
     181             :     return isProfileLocked(getCurrentProduct(),m_ProfileManager->getCurrentProfile());
     182             : #else
     183           0 :     return true;
     184             : #endif
     185             : }
     186           0 : OUString SAL_CALL MozillaBootstrap::setCurrentProfile( ::com::sun::star::mozilla::MozillaProductType product, const OUString& profileName ) throw (::com::sun::star::uno::RuntimeException, std::exception)
     187             : {
     188             : #ifndef MINIMAL_PROFILEDISCOVER
     189             :     return m_ProfileManager->setCurrentProfile(product,profileName);
     190             : #else
     191             :     (void)product; /* avoid warning about unused parameter */
     192             :     (void)profileName; /* avoid warning about unused parameter */
     193           0 :     return OUString();
     194             : #endif
     195             : }
     196             : 
     197             : // XProxyRunner
     198           0 : ::sal_Int32 SAL_CALL MozillaBootstrap::Run( const ::com::sun::star::uno::Reference< ::com::sun::star::mozilla::XCodeProxy >& aCode ) throw (::com::sun::star::uno::RuntimeException, std::exception)
     199             : {
     200             : #ifndef MINIMAL_PROFILEDISCOVER
     201             :     OUString profileName = aCode->getProfileName();
     202             :     OUString currProfileName = getCurrentProfile();
     203             :     ::com::sun::star::mozilla::MozillaProductType currProduct = getCurrentProduct();
     204             : 
     205             :      //if client provides a profileName, we will use it
     206             :     if (!profileName.isEmpty()
     207             :              && ( aCode->getProductType() != currProduct  || !profileName.equals(currProfileName)) )
     208             :         setCurrentProfile(aCode->getProductType(),profileName);
     209             :        MNSRunnable xRunnable;
     210             : 
     211             :     return xRunnable.StartProxy(aCode);
     212             : #else
     213             :     (void)aCode; /* avoid warning about unused parameter */
     214           0 :     return -1;
     215             : #endif
     216             : }
     217             : 
     218             : #ifdef MINIMAL_PROFILEDISCOVER
     219             : #include <cppuhelper/factory.hxx>
     220             : using ::com::sun::star::uno::Reference;
     221             : using ::com::sun::star::uno::Sequence;
     222             : using ::com::sun::star::lang::XSingleServiceFactory;
     223             : using ::com::sun::star::lang::XMultiServiceFactory;
     224             : 
     225           1 : static Reference< XInterface > SAL_CALL createInstance( const Reference< XMultiServiceFactory >& rServiceManager )
     226             : {
     227           1 :         MozillaBootstrap * pBootstrap = static_cast<MozillaBootstrap*>(OMozillaBootstrap_CreateInstance(rServiceManager));
     228           1 :         return *pBootstrap;
     229             : }
     230             : 
     231           1 : extern "C" SAL_DLLPUBLIC_EXPORT void* SAL_CALL mozbootstrap_component_getFactory(
     232             :                                         const sal_Char* pImplementationName,
     233             :                                         void* pServiceManager,
     234             :                                         void* /*pRegistryKey*/)
     235             : {
     236           1 :         void* pRet = 0;
     237             : 
     238           1 :         if (pServiceManager)
     239             :         {
     240           1 :                 OUString aImplName( OUString::createFromAscii( pImplementationName ) );
     241           2 :                 Reference< XSingleServiceFactory > xFactory;
     242           1 :                 if ( aImplName == "com.sun.star.comp.mozilla.MozillaBootstrap" )
     243             :                 {
     244           1 :                     Sequence< OUString > aSNS( 1 );
     245           1 :                     aSNS[0] = "com.sun.star.mozilla.MozillaBootstrap";
     246             : 
     247           2 :                     xFactory = ::cppu::createSingleFactory(
     248             :                         static_cast< XMultiServiceFactory* > ( pServiceManager),
     249           2 :                         aImplName, createInstance, aSNS );
     250             :                 }
     251           1 :                 if ( xFactory.is() )
     252             :                 {
     253           1 :                     xFactory->acquire();
     254           1 :                     pRet = xFactory.get();
     255           1 :                 }
     256             :         }
     257             : 
     258           1 :         return pRet;
     259           3 : };
     260             : 
     261             : #endif
     262             : 
     263             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11