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/factory.hxx>
22 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
23 #include <cppuhelper/supportsservice.hxx>
24 #include "MMozillaBootstrap.hxx"
25 #include "MNSFolders.hxx"
26 #include "MNSProfileDiscover.hxx"
27
28 using namespace com::sun::star::uno;
29 using namespace com::sun::star::lang;
30 using namespace com::sun::star::mozilla;
31 using namespace connectivity::mozab;
32
33 using ::com::sun::star::uno::Reference;
34 using ::com::sun::star::uno::Sequence;
35 using ::com::sun::star::lang::XSingleServiceFactory;
36 using ::com::sun::star::lang::XMultiServiceFactory;
37
38 static MozillaBootstrap *pMozillaBootstrap=nullptr;
39 static Reference<XMozillaBootstrap> xMozillaBootstrap;
OMozillaBootstrap_CreateInstance(const css::uno::Reference<css::lang::XMultiServiceFactory> &)40 extern "C" SAL_DLLPUBLIC_EXPORT void* OMozillaBootstrap_CreateInstance(const css::uno::Reference< css::lang::XMultiServiceFactory >& )
41 {
42 if (!pMozillaBootstrap)
43 {
44 pMozillaBootstrap=new connectivity::mozab::MozillaBootstrap;
45 pMozillaBootstrap->Init();
46 xMozillaBootstrap = pMozillaBootstrap;
47 }
48 return pMozillaBootstrap;
49 }
50
MozillaBootstrap()51 MozillaBootstrap::MozillaBootstrap()
52 : OMozillaBootstrap_BASE(m_aMutex)
53 {
54 }
55
~MozillaBootstrap()56 MozillaBootstrap::~MozillaBootstrap()
57 {
58 }
59
Init()60 void MozillaBootstrap::Init()
61 {
62 m_ProfileAccess.reset(new ProfileAccess);
63 bootupProfile(css::mozilla::MozillaProductType_Mozilla,OUString());
64 }
65
disposing()66 void MozillaBootstrap::disposing()
67 {
68 ::osl::MutexGuard aGuard(m_aMutex);
69 OMozillaBootstrap_BASE::disposing();
70 }
71
getImplementationName()72 OUString SAL_CALL MozillaBootstrap::getImplementationName( )
73 {
74 return MOZAB_MozillaBootstrap_IMPL_NAME;
75 }
76
supportsService(const OUString & _rServiceName)77 sal_Bool SAL_CALL MozillaBootstrap::supportsService( const OUString& _rServiceName )
78 {
79 return cppu::supportsService(this, _rServiceName);
80 }
81
getSupportedServiceNames()82 Sequence< OUString > SAL_CALL MozillaBootstrap::getSupportedServiceNames( )
83 {
84 // which service is supported
85 // for more information @see com.sun.star.mozilla.MozillaBootstrap
86 return { "com.sun.star.mozilla.MozillaBootstrap" };
87 }
88
89
90 // XProfileDiscover
getProfileCount(css::mozilla::MozillaProductType product)91 ::sal_Int32 SAL_CALL MozillaBootstrap::getProfileCount( css::mozilla::MozillaProductType product)
92 {
93 return m_ProfileAccess->getProfileCount(product);
94 }
getProfileList(css::mozilla::MozillaProductType product,css::uno::Sequence<OUString> & list)95 ::sal_Int32 SAL_CALL MozillaBootstrap::getProfileList( css::mozilla::MozillaProductType product, css::uno::Sequence< OUString >& list )
96 {
97 return m_ProfileAccess->getProfileList(product,list);
98 }
getDefaultProfile(css::mozilla::MozillaProductType product)99 OUString SAL_CALL MozillaBootstrap::getDefaultProfile( css::mozilla::MozillaProductType product )
100 {
101 return m_ProfileAccess->getDefaultProfile(product);
102 }
getProfilePath(css::mozilla::MozillaProductType product,const OUString & profileName)103 OUString SAL_CALL MozillaBootstrap::getProfilePath( css::mozilla::MozillaProductType product, const OUString& profileName )
104 {
105 return m_ProfileAccess->getProfilePath(product,profileName);
106 }
isProfileLocked(css::mozilla::MozillaProductType,const OUString &)107 sal_Bool SAL_CALL MozillaBootstrap::isProfileLocked( css::mozilla::MozillaProductType /*product*/, const OUString& /*profileName*/ )
108 {
109 return true;
110 }
getProfileExists(css::mozilla::MozillaProductType product,const OUString & profileName)111 sal_Bool SAL_CALL MozillaBootstrap::getProfileExists( css::mozilla::MozillaProductType product, const OUString& profileName )
112 {
113 return m_ProfileAccess->getProfileExists(product,profileName);
114 }
115
116 // XProfileManager
bootupProfile(css::mozilla::MozillaProductType,const OUString &)117 ::sal_Int32 SAL_CALL MozillaBootstrap::bootupProfile( css::mozilla::MozillaProductType, const OUString& )
118 {
119 return -1;
120 }
shutdownProfile()121 ::sal_Int32 SAL_CALL MozillaBootstrap::shutdownProfile( )
122 {
123 return -1;
124 }
getCurrentProduct()125 css::mozilla::MozillaProductType SAL_CALL MozillaBootstrap::getCurrentProduct( )
126 {
127 return css::mozilla::MozillaProductType_Default;
128 }
getCurrentProfile()129 OUString SAL_CALL MozillaBootstrap::getCurrentProfile( )
130 {
131 return OUString();
132 }
isCurrentProfileLocked()133 sal_Bool SAL_CALL MozillaBootstrap::isCurrentProfileLocked( )
134 {
135 return true;
136 }
setCurrentProfile(css::mozilla::MozillaProductType,const OUString &)137 OUString SAL_CALL MozillaBootstrap::setCurrentProfile( css::mozilla::MozillaProductType, const OUString& )
138 {
139 return OUString();
140 }
141
142 // XProxyRunner
Run(const css::uno::Reference<css::mozilla::XCodeProxy> &)143 ::sal_Int32 SAL_CALL MozillaBootstrap::Run( const css::uno::Reference< css::mozilla::XCodeProxy >& )
144 {
145 return -1;
146 }
147
createInstance(const Reference<XMultiServiceFactory> & rServiceManager)148 static Reference< XInterface > createInstance( const Reference< XMultiServiceFactory >& rServiceManager )
149 {
150 MozillaBootstrap * pBootstrap = static_cast<MozillaBootstrap*>(OMozillaBootstrap_CreateInstance(rServiceManager));
151 return *pBootstrap;
152 }
153
mozbootstrap_component_getFactory(const sal_Char * pImplementationName,void * pServiceManager,void *)154 extern "C" SAL_DLLPUBLIC_EXPORT void* mozbootstrap_component_getFactory(
155 const sal_Char* pImplementationName,
156 void* pServiceManager,
157 void* /*pRegistryKey*/)
158 {
159 void* pRet = nullptr;
160
161 if (pServiceManager)
162 {
163 OUString aImplName( OUString::createFromAscii( pImplementationName ) );
164 Reference< XSingleServiceFactory > xFactory;
165 if ( aImplName == "com.sun.star.comp.mozilla.MozillaBootstrap" )
166 {
167 Sequence<OUString> aSNS { "com.sun.star.mozilla.MozillaBootstrap" };
168
169 xFactory = ::cppu::createSingleFactory(
170 static_cast< XMultiServiceFactory* > ( pServiceManager),
171 aImplName, createInstance, aSNS );
172 }
173 if ( xFactory.is() )
174 {
175 xFactory->acquire();
176 pRet = xFactory.get();
177 }
178 }
179
180 return pRet;
181 };
182
183
184 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
185