merge the formfield patch from ooo-build
[ooovba.git] / connectivity / source / drivers / mozab / bootstrap / MMozillaBootstrap.cxx
blobd504f75224b08fe2f56430f07d3f3187b74c659e
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: MMozillaBootstrap.cxx,v $
10 * $Revision: 1.8 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_connectivity.hxx"
34 #include "MMozillaBootstrap.hxx"
36 using namespace com::sun::star::uno;
37 using namespace com::sun::star::lang;
38 using namespace com::sun::star::mozilla;
39 using namespace connectivity::mozab;
40 #include <MNSFolders.hxx>
41 #include "MNSProfileDiscover.hxx"
42 #ifndef MINIMAL_PROFILEDISCOVER
43 # include "MNSProfileManager.hxx"
44 # include "MNSRunnable.hxx"
45 #endif
46 #include <MNSInit.hxx>
48 static MozillaBootstrap *pMozillaBootstrap=NULL;
49 static Reference<XMozillaBootstrap> xMozillaBootstrap;
50 extern "C" SAL_DLLPUBLIC_EXPORT void* SAL_CALL OMozillaBootstrap_CreateInstance(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxFactory)
52 if (!pMozillaBootstrap)
54 pMozillaBootstrap=new connectivity::mozab::MozillaBootstrap( _rxFactory );
55 pMozillaBootstrap->Init();
56 xMozillaBootstrap = pMozillaBootstrap;
58 return pMozillaBootstrap;
61 // --------------------------------------------------------------------------------
64 // --------------------------------------------------------------------------------
65 MozillaBootstrap::MozillaBootstrap(
66 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxFactory)
67 : OMozillaBootstrap_BASE(m_aMutex), m_xMSFactory( _rxFactory )
70 // -----------------------------------------------------------------------------
71 MozillaBootstrap::~MozillaBootstrap()
74 // -----------------------------------------------------------------------------
75 void MozillaBootstrap::Init()
77 sal_Bool aProfileExists=sal_False;
79 #ifndef MINIMAL_PROFILEDISCOVER
80 //This must be call before any mozilla code
81 MNS_Init(aProfileExists);
83 m_ProfileManager = new ProfileManager();
84 #else
85 (void)aProfileExists; /* avoid warning about unused parameter */
86 #endif
87 m_ProfileAccess = new ProfileAccess();
88 bootupProfile(::com::sun::star::mozilla::MozillaProductType_Mozilla,rtl::OUString());
91 // --------------------------------------------------------------------------------
92 void MozillaBootstrap::disposing()
94 ::osl::MutexGuard aGuard(m_aMutex);
95 OMozillaBootstrap_BASE::disposing();
98 // static ServiceInfo
99 //------------------------------------------------------------------------------
100 rtl::OUString MozillaBootstrap::getImplementationName_Static( ) throw(RuntimeException)
102 return rtl::OUString::createFromAscii(MOZAB_MozillaBootstrap_IMPL_NAME);
104 //------------------------------------------------------------------------------
105 Sequence< ::rtl::OUString > MozillaBootstrap::getSupportedServiceNames_Static( ) throw (RuntimeException)
107 // which service is supported
108 // for more information @see com.sun.star.mozilla.MozillaBootstrap
109 Sequence< ::rtl::OUString > aSNS( 1 );
110 aSNS[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.mozilla.MozillaBootstrap"));
111 return aSNS;
114 //------------------------------------------------------------------
115 ::rtl::OUString SAL_CALL MozillaBootstrap::getImplementationName( ) throw(RuntimeException)
117 return getImplementationName_Static();
120 //------------------------------------------------------------------
121 sal_Bool SAL_CALL MozillaBootstrap::supportsService( const ::rtl::OUString& _rServiceName ) throw(RuntimeException)
123 Sequence< ::rtl::OUString > aSupported(getSupportedServiceNames());
124 const ::rtl::OUString* pSupported = aSupported.getConstArray();
125 const ::rtl::OUString* pEnd = pSupported + aSupported.getLength();
126 for (;pSupported != pEnd && !pSupported->equals(_rServiceName); ++pSupported)
129 return pSupported != pEnd;
132 //------------------------------------------------------------------
133 Sequence< ::rtl::OUString > SAL_CALL MozillaBootstrap::getSupportedServiceNames( ) throw(RuntimeException)
135 return getSupportedServiceNames_Static();
139 // XProfileDiscover
140 ::sal_Int32 SAL_CALL MozillaBootstrap::getProfileCount( ::com::sun::star::mozilla::MozillaProductType product) throw (::com::sun::star::uno::RuntimeException)
142 return m_ProfileAccess->getProfileCount(product);
144 ::sal_Int32 SAL_CALL MozillaBootstrap::getProfileList( ::com::sun::star::mozilla::MozillaProductType product, ::com::sun::star::uno::Sequence< ::rtl::OUString >& list ) throw (::com::sun::star::uno::RuntimeException)
146 return m_ProfileAccess->getProfileList(product,list);
148 ::rtl::OUString SAL_CALL MozillaBootstrap::getDefaultProfile( ::com::sun::star::mozilla::MozillaProductType product ) throw (::com::sun::star::uno::RuntimeException)
150 return m_ProfileAccess->getDefaultProfile(product);
152 ::rtl::OUString SAL_CALL MozillaBootstrap::getProfilePath( ::com::sun::star::mozilla::MozillaProductType product, const ::rtl::OUString& profileName ) throw (::com::sun::star::uno::RuntimeException)
154 return m_ProfileAccess->getProfilePath(product,profileName);
156 ::sal_Bool SAL_CALL MozillaBootstrap::isProfileLocked( ::com::sun::star::mozilla::MozillaProductType product, const ::rtl::OUString& profileName ) throw (::com::sun::star::uno::RuntimeException)
158 return m_ProfileAccess->isProfileLocked(product,profileName);
160 ::sal_Bool SAL_CALL MozillaBootstrap::getProfileExists( ::com::sun::star::mozilla::MozillaProductType product, const ::rtl::OUString& profileName ) throw (::com::sun::star::uno::RuntimeException)
162 return m_ProfileAccess->getProfileExists(product,profileName);
165 // XProfileManager
166 ::sal_Int32 SAL_CALL MozillaBootstrap::bootupProfile( ::com::sun::star::mozilla::MozillaProductType product, const ::rtl::OUString& profileName ) throw (::com::sun::star::uno::RuntimeException)
168 #ifndef MINIMAL_PROFILEDISCOVER
169 return m_ProfileManager->bootupProfile(product,profileName);
170 #else
171 (void)product; /* avoid warning about unused parameter */
172 (void)profileName; /* avoid warning about unused parameter */
173 return -1;
174 #endif
176 ::sal_Int32 SAL_CALL MozillaBootstrap::shutdownProfile( ) throw (::com::sun::star::uno::RuntimeException)
178 #ifndef MINIMAL_PROFILEDISCOVER
179 return m_ProfileManager->shutdownProfile();
180 #else
181 return -1;
182 #endif
184 ::com::sun::star::mozilla::MozillaProductType SAL_CALL MozillaBootstrap::getCurrentProduct( ) throw (::com::sun::star::uno::RuntimeException)
186 #ifndef MINIMAL_PROFILEDISCOVER
187 return m_ProfileManager->getCurrentProduct();
188 #else
189 return ::com::sun::star::mozilla::MozillaProductType_Default;
190 #endif
192 ::rtl::OUString SAL_CALL MozillaBootstrap::getCurrentProfile( ) throw (::com::sun::star::uno::RuntimeException)
194 #ifndef MINIMAL_PROFILEDISCOVER
195 return m_ProfileManager->getCurrentProfile();
196 #else
197 return ::rtl::OUString();
198 #endif
200 ::sal_Bool SAL_CALL MozillaBootstrap::isCurrentProfileLocked( ) throw (::com::sun::star::uno::RuntimeException)
202 #ifndef MINIMAL_PROFILEDISCOVER
203 return isProfileLocked(getCurrentProduct(),m_ProfileManager->getCurrentProfile());
204 #else
205 return true;
206 #endif
208 ::rtl::OUString SAL_CALL MozillaBootstrap::setCurrentProfile( ::com::sun::star::mozilla::MozillaProductType product, const ::rtl::OUString& profileName ) throw (::com::sun::star::uno::RuntimeException)
210 #ifndef MINIMAL_PROFILEDISCOVER
211 return m_ProfileManager->setCurrentProfile(product,profileName);
212 #else
213 (void)product; /* avoid warning about unused parameter */
214 (void)profileName; /* avoid warning about unused parameter */
215 return ::rtl::OUString();
216 #endif
219 // XProxyRunner
220 ::sal_Int32 SAL_CALL MozillaBootstrap::Run( const ::com::sun::star::uno::Reference< ::com::sun::star::mozilla::XCodeProxy >& aCode ) throw (::com::sun::star::uno::RuntimeException)
222 #ifndef MINIMAL_PROFILEDISCOVER
223 ::rtl::OUString profileName = aCode->getProfileName();
224 ::rtl::OUString currProfileName = getCurrentProfile();
225 ::com::sun::star::mozilla::MozillaProductType currProduct = getCurrentProduct();
227 //if client provides a profileName, we will use it
228 if (profileName.getLength()
229 && ( aCode->getProductType() != currProduct || !profileName.equals(currProfileName)) )
230 setCurrentProfile(aCode->getProductType(),profileName);
231 MNSRunnable xRunnable;
233 return xRunnable.StartProxy(aCode);;
234 #else
235 (void)aCode; /* avoid warning about unused parameter */
236 return -1;
237 #endif
240 #ifdef MINIMAL_PROFILEDISCOVER
241 #include <cppuhelper/factory.hxx>
242 using ::com::sun::star::uno::Reference;
243 using ::com::sun::star::uno::Sequence;
244 using ::com::sun::star::registry::XRegistryKey;
245 using ::com::sun::star::lang::XSingleServiceFactory;
246 using ::com::sun::star::lang::XMultiServiceFactory;
248 extern "C" SAL_DLLPUBLIC_EXPORT void SAL_CALL
249 component_getImplementationEnvironment(
250 const sal_Char **ppEnvTypeName,
251 uno_Environment ** /*ppEnv*/
254 *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
257 //---------------------------------------------------------------------------------------
258 void REGISTER_PROVIDER(
259 const ::rtl::OUString& aServiceImplName,
260 const Sequence< ::rtl::OUString>& Services,
261 const Reference< ::com::sun::star::registry::XRegistryKey > & xKey)
263 ::rtl::OUString aMainKeyName;
264 aMainKeyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("/"));
265 aMainKeyName += aServiceImplName;
266 aMainKeyName += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("/UNO/SERVICES"));
268 Reference< ::com::sun::star::registry::XRegistryKey > xNewKey( xKey->createKey(aMainKeyName) );
269 OSL_ENSURE(xNewKey.is(), "MOZAB::component_writeInfo : could not create a registry key !");
271 for (sal_Int32 i=0; i<Services.getLength(); ++i)
272 xNewKey->createKey(Services[i]);
275 extern "C" SAL_DLLPUBLIC_EXPORT sal_Bool SAL_CALL component_writeInfo(
276 void* /*pServiceManager*/,
277 void* pRegistryKey
280 if (pRegistryKey)
283 Reference< ::com::sun::star::registry::XRegistryKey > xKey(reinterpret_cast< ::com::sun::star::registry::XRegistryKey*>(pRegistryKey));
285 Sequence< ::rtl::OUString > aSNS( 1 );
286 aSNS[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.mozilla.MozillaBootstrap"));
287 REGISTER_PROVIDER(
288 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.mozilla.MozillaBootstrap")),
289 aSNS, xKey);
291 return sal_True;
293 catch (::com::sun::star::registry::InvalidRegistryException& )
295 OSL_ENSURE(sal_False, "Mozab::component_writeInfo : could not create a registry key ! ## InvalidRegistryException !");
298 return sal_False;
301 static Reference< XInterface > SAL_CALL createInstance( const Reference< XMultiServiceFactory >& rServiceManager )
303 MozillaBootstrap * pBootstrap = reinterpret_cast<MozillaBootstrap*>(OMozillaBootstrap_CreateInstance(rServiceManager));
304 return *pBootstrap;
307 extern "C" SAL_DLLPUBLIC_EXPORT void* SAL_CALL component_getFactory(
308 const sal_Char* pImplementationName,
309 void* pServiceManager,
310 void* /*pRegistryKey*/)
312 void* pRet = 0;
314 if (pServiceManager)
316 ::rtl::OUString aImplName( ::rtl::OUString::createFromAscii( pImplementationName ) );
317 Reference< XSingleServiceFactory > xFactory;
318 if (aImplName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.mozilla.MozillaBootstrap")) ))
320 Sequence< ::rtl::OUString > aSNS( 1 );
321 aSNS[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.mozilla.MozillaBootstrap"));
323 xFactory = ::cppu::createSingleFactory(
324 reinterpret_cast< XMultiServiceFactory* > ( pServiceManager),
325 aImplName, createInstance, aSNS );
327 if ( xFactory.is() )
329 xFactory->acquire();
330 pRet = xFactory.get();
334 return pRet;
337 #endif