1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 // MARKER(update_precomp.py): autogen include statement, do not remove
23 #include "precompiled_extensions.hxx"
24 
25 #include "MMozillaBootstrap.hxx"
26 
27 using namespace com::sun::star::uno;
28 using namespace com::sun::star::lang;
29 using namespace com::sun::star::mozilla;
30 using namespace connectivity::mozab;
31 #include <MNSFolders.hxx>
32 #include "MNSProfileDiscover.hxx"
33 
34 static MozillaBootstrap *pMozillaBootstrap=NULL;
35 static Reference<XMozillaBootstrap> xMozillaBootstrap;
OMozillaBootstrap_CreateInstance(const::com::sun::star::uno::Reference<::com::sun::star::lang::XMultiServiceFactory> & _rxFactory)36 extern "C" SAL_DLLPUBLIC_EXPORT void*  SAL_CALL OMozillaBootstrap_CreateInstance(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxFactory)
37 {
38     if (!pMozillaBootstrap)
39     {
40         pMozillaBootstrap=new connectivity::mozab::MozillaBootstrap( _rxFactory );
41         pMozillaBootstrap->Init();
42         xMozillaBootstrap = pMozillaBootstrap;
43     }
44     return  pMozillaBootstrap;
45 }
46 
47 // --------------------------------------------------------------------------------
48 
49 
50 // --------------------------------------------------------------------------------
MozillaBootstrap(const::com::sun::star::uno::Reference<::com::sun::star::lang::XMultiServiceFactory> & _rxFactory)51 MozillaBootstrap::MozillaBootstrap(
52     const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxFactory)
53     : OMozillaBootstrap_BASE(m_aMutex), m_xMSFactory( _rxFactory )
54 {
55 }
56 // -----------------------------------------------------------------------------
~MozillaBootstrap()57 MozillaBootstrap::~MozillaBootstrap()
58 {
59 }
60 // -----------------------------------------------------------------------------
Init()61 void MozillaBootstrap::Init()
62 {
63     sal_Bool aProfileExists=sal_False;
64 
65     (void)aProfileExists; /* avoid warning about unused parameter */
66 
67     m_ProfileAccess = new ProfileAccess();
68     bootupProfile(::com::sun::star::mozilla::MozillaProductType_Mozilla,rtl::OUString());
69 }
70 
71 // --------------------------------------------------------------------------------
disposing()72 void MozillaBootstrap::disposing()
73 {
74     ::osl::MutexGuard aGuard(m_aMutex);
75     OMozillaBootstrap_BASE::disposing();
76 }
77 
78 // static ServiceInfo
79 //------------------------------------------------------------------------------
getImplementationName_Static()80 rtl::OUString MozillaBootstrap::getImplementationName_Static(  ) throw(RuntimeException)
81 {
82     return rtl::OUString::createFromAscii(MOZAB_MozillaBootstrap_IMPL_NAME);
83 }
84 //------------------------------------------------------------------------------
getSupportedServiceNames_Static()85 Sequence< ::rtl::OUString > MozillaBootstrap::getSupportedServiceNames_Static(  ) throw (RuntimeException)
86 {
87     // which service is supported
88     // for more information @see com.sun.star.mozilla.MozillaBootstrap
89     Sequence< ::rtl::OUString > aSNS( 1 );
90     aSNS[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.mozilla.MozillaBootstrap"));
91     return aSNS;
92 }
93 
94 //------------------------------------------------------------------
getImplementationName()95 ::rtl::OUString SAL_CALL MozillaBootstrap::getImplementationName(  ) throw(RuntimeException)
96 {
97     return getImplementationName_Static();
98 }
99 
100 //------------------------------------------------------------------
supportsService(const::rtl::OUString & _rServiceName)101 sal_Bool SAL_CALL MozillaBootstrap::supportsService( const ::rtl::OUString& _rServiceName ) throw(RuntimeException)
102 {
103     Sequence< ::rtl::OUString > aSupported(getSupportedServiceNames());
104     const ::rtl::OUString* pSupported = aSupported.getConstArray();
105     const ::rtl::OUString* pEnd = pSupported + aSupported.getLength();
106     for (;pSupported != pEnd && !pSupported->equals(_rServiceName); ++pSupported)
107         ;
108 
109     return pSupported != pEnd;
110 }
111 
112 //------------------------------------------------------------------
getSupportedServiceNames()113 Sequence< ::rtl::OUString > SAL_CALL MozillaBootstrap::getSupportedServiceNames(  ) throw(RuntimeException)
114 {
115     return getSupportedServiceNames_Static();
116 }
117 
118 
119 // XProfileDiscover
getProfileCount(::com::sun::star::mozilla::MozillaProductType product)120 ::sal_Int32 SAL_CALL MozillaBootstrap::getProfileCount( ::com::sun::star::mozilla::MozillaProductType product) throw (::com::sun::star::uno::RuntimeException)
121 {
122     return m_ProfileAccess->getProfileCount(product);
123 }
getProfileList(::com::sun::star::mozilla::MozillaProductType product,::com::sun::star::uno::Sequence<::rtl::OUString> & list)124 ::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)
125 {
126     return m_ProfileAccess->getProfileList(product,list);
127 }
getDefaultProfile(::com::sun::star::mozilla::MozillaProductType product)128 ::rtl::OUString SAL_CALL MozillaBootstrap::getDefaultProfile( ::com::sun::star::mozilla::MozillaProductType product ) throw (::com::sun::star::uno::RuntimeException)
129 {
130     return m_ProfileAccess->getDefaultProfile(product);
131 }
getProfilePath(::com::sun::star::mozilla::MozillaProductType product,const::rtl::OUString & profileName)132 ::rtl::OUString SAL_CALL MozillaBootstrap::getProfilePath( ::com::sun::star::mozilla::MozillaProductType product, const ::rtl::OUString& profileName ) throw (::com::sun::star::uno::RuntimeException)
133 {
134     return m_ProfileAccess->getProfilePath(product,profileName);
135 }
isProfileLocked(::com::sun::star::mozilla::MozillaProductType product,const::rtl::OUString & profileName)136 ::sal_Bool SAL_CALL MozillaBootstrap::isProfileLocked( ::com::sun::star::mozilla::MozillaProductType product, const ::rtl::OUString& profileName ) throw (::com::sun::star::uno::RuntimeException)
137 {
138     return m_ProfileAccess->isProfileLocked(product,profileName);
139 }
getProfileExists(::com::sun::star::mozilla::MozillaProductType product,const::rtl::OUString & profileName)140 ::sal_Bool SAL_CALL MozillaBootstrap::getProfileExists( ::com::sun::star::mozilla::MozillaProductType product, const ::rtl::OUString& profileName ) throw (::com::sun::star::uno::RuntimeException)
141 {
142     return m_ProfileAccess->getProfileExists(product,profileName);
143 }
144 
145 // XProfileManager
bootupProfile(::com::sun::star::mozilla::MozillaProductType product,const::rtl::OUString & profileName)146 ::sal_Int32 SAL_CALL MozillaBootstrap::bootupProfile( ::com::sun::star::mozilla::MozillaProductType product, const ::rtl::OUString& profileName ) throw (::com::sun::star::uno::RuntimeException)
147 {
148     (void)product; /* avoid warning about unused parameter */
149     (void)profileName; /* avoid warning about unused parameter */
150         return -1;
151 }
shutdownProfile()152 ::sal_Int32 SAL_CALL MozillaBootstrap::shutdownProfile(  ) throw (::com::sun::star::uno::RuntimeException)
153 {
154     return -1;
155 }
getCurrentProduct()156 ::com::sun::star::mozilla::MozillaProductType SAL_CALL MozillaBootstrap::getCurrentProduct(  ) throw (::com::sun::star::uno::RuntimeException)
157 {
158     return ::com::sun::star::mozilla::MozillaProductType_Default;
159 }
getCurrentProfile()160 ::rtl::OUString SAL_CALL MozillaBootstrap::getCurrentProfile(  ) throw (::com::sun::star::uno::RuntimeException)
161 {
162     return ::rtl::OUString();
163 }
isCurrentProfileLocked()164 ::sal_Bool SAL_CALL MozillaBootstrap::isCurrentProfileLocked(  ) throw (::com::sun::star::uno::RuntimeException)
165 {
166     return true;
167 }
setCurrentProfile(::com::sun::star::mozilla::MozillaProductType product,const::rtl::OUString & profileName)168 ::rtl::OUString SAL_CALL MozillaBootstrap::setCurrentProfile( ::com::sun::star::mozilla::MozillaProductType product, const ::rtl::OUString& profileName ) throw (::com::sun::star::uno::RuntimeException)
169 {
170     (void)product; /* avoid warning about unused parameter */
171     (void)profileName; /* avoid warning about unused parameter */
172     return ::rtl::OUString();
173 }
174 
175 // XProxyRunner
Run(const::com::sun::star::uno::Reference<::com::sun::star::mozilla::XCodeProxy> & aCode)176 ::sal_Int32 SAL_CALL MozillaBootstrap::Run( const ::com::sun::star::uno::Reference< ::com::sun::star::mozilla::XCodeProxy >& aCode ) throw (::com::sun::star::uno::RuntimeException)
177 {
178     (void)aCode; /* avoid warning about unused parameter */
179     return -1;
180 }
181 
182 
183 #include <cppuhelper/factory.hxx>
184 using ::com::sun::star::uno::Reference;
185 using ::com::sun::star::uno::Sequence;
186 using ::com::sun::star::lang::XSingleServiceFactory;
187 using ::com::sun::star::lang::XMultiServiceFactory;
188 
189 extern "C" SAL_DLLPUBLIC_EXPORT void SAL_CALL
component_getImplementationEnvironment(const sal_Char ** ppEnvTypeName,uno_Environment **)190 component_getImplementationEnvironment(
191                 const sal_Char  **ppEnvTypeName,
192                 uno_Environment ** /*ppEnv*/
193             )
194 {
195     *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
196 }
197 
createInstance(const Reference<XMultiServiceFactory> & rServiceManager)198 static Reference< XInterface > SAL_CALL createInstance( const Reference< XMultiServiceFactory >& rServiceManager )
199 {
200         MozillaBootstrap * pBootstrap = reinterpret_cast<MozillaBootstrap*>(OMozillaBootstrap_CreateInstance(rServiceManager));
201         return *pBootstrap;
202 }
203 
component_getFactory(const sal_Char * pImplementationName,void * pServiceManager,void *)204 extern "C" SAL_DLLPUBLIC_EXPORT void* SAL_CALL component_getFactory(
205                                         const sal_Char* pImplementationName,
206                                         void* pServiceManager,
207                                         void* /*pRegistryKey*/)
208 {
209         void* pRet = 0;
210 
211         if (pServiceManager)
212         {
213                 ::rtl::OUString aImplName( ::rtl::OUString::createFromAscii( pImplementationName ) );
214                 Reference< XSingleServiceFactory > xFactory;
215                 if (aImplName.equals(  ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.mozilla.MozillaBootstrap"))  ))
216                 {
217                     Sequence< ::rtl::OUString > aSNS( 1 );
218                     aSNS[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.mozilla.MozillaBootstrap"));
219 
220                     xFactory = ::cppu::createSingleFactory(
221                         reinterpret_cast< XMultiServiceFactory* > ( pServiceManager),
222                         aImplName, createInstance, aSNS );
223                 }
224                 if ( xFactory.is() )
225                 {
226                     xFactory->acquire();
227                     pRet = xFactory.get();
228                 }
229         }
230 
231         return pRet;
232 };
233 
234