From ed5640d8b587fbcfed7dd7967f3de04b37a76f26 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 11:06:44 +0200 Subject: Adding upstream version 4:7.4.7. Signed-off-by: Daniel Baumann --- .../drivers/mozab/bootstrap/MMozillaBootstrap.cxx | 138 ++++++++++++++ .../drivers/mozab/bootstrap/MMozillaBootstrap.hxx | 78 ++++++++ .../source/drivers/mozab/bootstrap/MNSFolders.cxx | 159 ++++++++++++++++ .../source/drivers/mozab/bootstrap/MNSFolders.hxx | 28 +++ .../drivers/mozab/bootstrap/MNSINIParser.cxx | 94 +++++++++ .../drivers/mozab/bootstrap/MNSINIParser.hxx | 54 ++++++ .../drivers/mozab/bootstrap/MNSProfileDiscover.cxx | 210 +++++++++++++++++++++ .../drivers/mozab/bootstrap/MNSProfileDiscover.hxx | 80 ++++++++ connectivity/source/drivers/mozab/bootstrap/README | 3 + .../drivers/mozab/bootstrap/mozbootstrap.component | 26 +++ 10 files changed, 870 insertions(+) create mode 100644 connectivity/source/drivers/mozab/bootstrap/MMozillaBootstrap.cxx create mode 100644 connectivity/source/drivers/mozab/bootstrap/MMozillaBootstrap.hxx create mode 100644 connectivity/source/drivers/mozab/bootstrap/MNSFolders.cxx create mode 100644 connectivity/source/drivers/mozab/bootstrap/MNSFolders.hxx create mode 100644 connectivity/source/drivers/mozab/bootstrap/MNSINIParser.cxx create mode 100644 connectivity/source/drivers/mozab/bootstrap/MNSINIParser.hxx create mode 100644 connectivity/source/drivers/mozab/bootstrap/MNSProfileDiscover.cxx create mode 100644 connectivity/source/drivers/mozab/bootstrap/MNSProfileDiscover.hxx create mode 100644 connectivity/source/drivers/mozab/bootstrap/README create mode 100644 connectivity/source/drivers/mozab/bootstrap/mozbootstrap.component (limited to 'connectivity/source/drivers/mozab/bootstrap') diff --git a/connectivity/source/drivers/mozab/bootstrap/MMozillaBootstrap.cxx b/connectivity/source/drivers/mozab/bootstrap/MMozillaBootstrap.cxx new file mode 100644 index 000000000..faa2063b2 --- /dev/null +++ b/connectivity/source/drivers/mozab/bootstrap/MMozillaBootstrap.cxx @@ -0,0 +1,138 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include +#include +#include +#include +#include +#include "MMozillaBootstrap.hxx" +#include "MNSProfileDiscover.hxx" + +using namespace com::sun::star::uno; +using namespace com::sun::star::lang; +using namespace com::sun::star::mozilla; +using namespace connectivity::mozab; + +using ::com::sun::star::uno::Reference; +using ::com::sun::star::uno::Sequence; +using ::com::sun::star::lang::XSingleServiceFactory; +using ::com::sun::star::lang::XMultiServiceFactory; + +MozillaBootstrap::MozillaBootstrap() + : OMozillaBootstrap_BASE(m_aMutex) +{ + m_ProfileAccess.reset(new ProfileAccess); + bootupProfile(css::mozilla::MozillaProductType_Mozilla,OUString()); +} + +MozillaBootstrap::~MozillaBootstrap() +{ +} + +void MozillaBootstrap::disposing() +{ + ::osl::MutexGuard aGuard(m_aMutex); + OMozillaBootstrap_BASE::disposing(); +} + +OUString SAL_CALL MozillaBootstrap::getImplementationName( ) +{ + return "com.sun.star.comp.mozilla.MozillaBootstrap"; +} + +sal_Bool SAL_CALL MozillaBootstrap::supportsService( const OUString& _rServiceName ) +{ + return cppu::supportsService(this, _rServiceName); +} + +Sequence< OUString > SAL_CALL MozillaBootstrap::getSupportedServiceNames( ) +{ + // which service is supported + // for more information @see com.sun.star.mozilla.MozillaBootstrap + return { "com.sun.star.mozilla.MozillaBootstrap" }; +} + + +// XProfileDiscover +::sal_Int32 SAL_CALL MozillaBootstrap::getProfileCount( css::mozilla::MozillaProductType product) +{ + return m_ProfileAccess->getProfileCount(product); +} +::sal_Int32 SAL_CALL MozillaBootstrap::getProfileList( css::mozilla::MozillaProductType product, css::uno::Sequence< OUString >& list ) +{ + return m_ProfileAccess->getProfileList(product,list); +} +OUString SAL_CALL MozillaBootstrap::getDefaultProfile( css::mozilla::MozillaProductType product ) +{ + return m_ProfileAccess->getDefaultProfile(product); +} +OUString SAL_CALL MozillaBootstrap::getProfilePath( css::mozilla::MozillaProductType product, const OUString& profileName ) +{ + return m_ProfileAccess->getProfilePath(product,profileName); +} +sal_Bool SAL_CALL MozillaBootstrap::isProfileLocked( css::mozilla::MozillaProductType /*product*/, const OUString& /*profileName*/ ) +{ + return true; +} +sal_Bool SAL_CALL MozillaBootstrap::getProfileExists( css::mozilla::MozillaProductType product, const OUString& profileName ) +{ + return m_ProfileAccess->getProfileExists(product,profileName); +} + +// XProfileManager +::sal_Int32 SAL_CALL MozillaBootstrap::bootupProfile( css::mozilla::MozillaProductType, const OUString& ) +{ + return -1; +} +::sal_Int32 SAL_CALL MozillaBootstrap::shutdownProfile( ) +{ + return -1; +} +css::mozilla::MozillaProductType SAL_CALL MozillaBootstrap::getCurrentProduct( ) +{ + return css::mozilla::MozillaProductType_Default; +} +OUString SAL_CALL MozillaBootstrap::getCurrentProfile( ) +{ + return OUString(); +} +sal_Bool SAL_CALL MozillaBootstrap::isCurrentProfileLocked( ) +{ + return true; +} +OUString SAL_CALL MozillaBootstrap::setCurrentProfile( css::mozilla::MozillaProductType, const OUString& ) +{ + return OUString(); +} + +// XProxyRunner +::sal_Int32 SAL_CALL MozillaBootstrap::Run( const css::uno::Reference< css::mozilla::XCodeProxy >& ) +{ + return -1; +} + +extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface* +connectivity_moz_MozillaBootstrap_get_implementation( + css::uno::XComponentContext* , css::uno::Sequence const&) +{ + return cppu::acquire(new connectivity::mozab::MozillaBootstrap()); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/mozab/bootstrap/MMozillaBootstrap.hxx b/connectivity/source/drivers/mozab/bootstrap/MMozillaBootstrap.hxx new file mode 100644 index 000000000..e01a2bb96 --- /dev/null +++ b/connectivity/source/drivers/mozab/bootstrap/MMozillaBootstrap.hxx @@ -0,0 +1,78 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#pragma once + +#include + +#include + +#include +#include +#include + + +namespace connectivity::mozab +{ + typedef ::cppu::WeakComponentImplHelper< css::mozilla::XMozillaBootstrap, + css::lang::XServiceInfo > OMozillaBootstrap_BASE; + class ProfileAccess; + class ProfileManager; + class MozillaBootstrap : public OMozillaBootstrap_BASE + { + private: + ::osl::Mutex m_aMutex; // mutex is need to control member access + virtual ~MozillaBootstrap() override; + std::unique_ptr m_ProfileAccess; + public: + + MozillaBootstrap(); + + // OComponentHelper + virtual void SAL_CALL disposing() override; + + // XServiceInfo + virtual OUString SAL_CALL getImplementationName( ) override; + virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override; + virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override; + + // XMozillaBootstrap + + // XProfileDiscover + virtual ::sal_Int32 SAL_CALL getProfileCount( css::mozilla::MozillaProductType product) override; + virtual ::sal_Int32 SAL_CALL getProfileList( css::mozilla::MozillaProductType product, css::uno::Sequence< OUString >& list ) override; + virtual OUString SAL_CALL getDefaultProfile( css::mozilla::MozillaProductType product ) override; + virtual OUString SAL_CALL getProfilePath( css::mozilla::MozillaProductType product, const OUString& profileName ) override; + virtual sal_Bool SAL_CALL isProfileLocked( css::mozilla::MozillaProductType product, const OUString& profileName ) override; + virtual sal_Bool SAL_CALL getProfileExists( css::mozilla::MozillaProductType product, const OUString& profileName ) override; + + // XProfileManager + virtual ::sal_Int32 SAL_CALL bootupProfile( css::mozilla::MozillaProductType product, const OUString& profileName ) override; + virtual ::sal_Int32 SAL_CALL shutdownProfile( ) override; + virtual css::mozilla::MozillaProductType SAL_CALL getCurrentProduct( ) override; + virtual OUString SAL_CALL getCurrentProfile( ) override; + virtual sal_Bool SAL_CALL isCurrentProfileLocked( ) override; + virtual OUString SAL_CALL setCurrentProfile( css::mozilla::MozillaProductType product, const OUString& profileName ) override; + + // XProxyRunner + virtual ::sal_Int32 SAL_CALL Run( const css::uno::Reference< css::mozilla::XCodeProxy >& aCode ) override; + }; + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/mozab/bootstrap/MNSFolders.cxx b/connectivity/source/drivers/mozab/bootstrap/MNSFolders.cxx new file mode 100644 index 000000000..71c70c641 --- /dev/null +++ b/connectivity/source/drivers/mozab/bootstrap/MNSFolders.cxx @@ -0,0 +1,159 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include "MNSFolders.hxx" + +#ifdef UNIX +#include +#endif // End UNIX + +#ifdef _WIN32 +#if !defined WIN32_LEAN_AND_MEAN +# define WIN32_LEAN_AND_MEAN +#endif +#include +#include +#include +#include +#endif // End _WIN32 +#include +#include +#include + +using namespace ::com::sun::star::mozilla; + +namespace +{ + + OUString lcl_getUserDataDirectory() + { + ::osl::Security aSecurity; + OUString aConfigPath; + + #if defined(_WIN32) || defined(MACOSX) + aSecurity.getConfigDir( aConfigPath ); + #else + //This is to find the dir under which .mozilla/.thunderbird is created. + //mozilla doesn't honour XDG_CONFIG_HOME, so raw home dir required here + //not xdg-config dir + aSecurity.getHomeDir( aConfigPath ); + #endif + + return aConfigPath + "/"; + } + + + const size_t NB_PRODUCTS = 3; + const size_t NB_CANDIDATES = 4; + + // The order (index) of entries in DefaultProductDir and + // ProductRootEnvironmentVariable *must* match the constants + // (minus 1) in offapi/com/sun/star/mozilla/MozillaProductType.idl + // DO NOT CHANGE THE ORDER; ADD ONLY TO THE END + const char* DefaultProductDir[NB_PRODUCTS][NB_CANDIDATES] = + { + #if defined(_WIN32) + { "Mozilla/SeaMonkey/", nullptr, nullptr, nullptr }, + { "Mozilla/Firefox/", nullptr, nullptr, nullptr }, + { "Thunderbird/", "Mozilla/Thunderbird/", nullptr, nullptr } + #elif defined(MACOSX) + { "../Mozilla/SeaMonkey/", nullptr, nullptr, nullptr }, + { "Firefox/", nullptr, nullptr, nullptr }, + { "../Thunderbird/", nullptr, nullptr, nullptr } + #else + { ".mozilla/seamonkey/", nullptr, nullptr, nullptr }, + { ".mozilla/firefox/", nullptr, nullptr, nullptr }, + { ".thunderbird/", ".mozilla-thunderbird/", ".mozilla/thunderbird/", ".icedove/" } + #endif + }; + + const char* ProductRootEnvironmentVariable[NB_PRODUCTS] = + { + "MOZILLA_PROFILE_ROOT", + "MOZILLA_FIREFOX_PROFILE_ROOT", + "MOZILLA_THUNDERBIRD_PROFILE_ROOT", + }; + + + OUString const & lcl_guessProfileRoot( MozillaProductType _product ) + { + size_t productIndex = static_cast(_product) - 1; + + static OUString s_productDirectories[NB_PRODUCTS]; + + if ( s_productDirectories[ productIndex ].isEmpty() ) + { + OUString sProductPath; + + // check whether we have an environment variable which help us + const char* pProfileByEnv = getenv( ProductRootEnvironmentVariable[ productIndex ] ); + if ( pProfileByEnv ) + { + sProductPath = OUString( pProfileByEnv, rtl_str_getLength( pProfileByEnv ), osl_getThreadTextEncoding() ); + // assume that this is fine, no further checks + } + else + { + OUString sProductDirCandidate; + const char pProfileRegistry[] = "profiles.ini"; + + // check all possible candidates + for ( size_t i=0; i + +#include + +OUString getRegistryDir(css::mozilla::MozillaProductType product); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/mozab/bootstrap/MNSINIParser.cxx b/connectivity/source/drivers/mozab/bootstrap/MNSINIParser.cxx new file mode 100644 index 000000000..a146d0c09 --- /dev/null +++ b/connectivity/source/drivers/mozab/bootstrap/MNSINIParser.cxx @@ -0,0 +1,94 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include "MNSINIParser.hxx" +#include +#include +#include +#include +#include + +IniParser::IniParser(OUString const & rIniName) +{ + OUString iniUrl; + if (osl_File_E_None != osl_getFileURLFromSystemPath(rIniName.pData, &iniUrl.pData)) + return; + + + oslFileHandle handle=nullptr; + oslFileError fileError = osl_File_E_INVAL; + try{ + if (!iniUrl.isEmpty()) + fileError = osl_openFile(iniUrl.pData, &handle, osl_File_OpenFlag_Read); + } + catch(const css::io::IOException&) + { + SAL_WARN("connectivity.mozab", "couldn't open file: " << iniUrl ); + } + + if (osl_File_E_None == fileError) + { + rtl::ByteSequence seq; + sal_uInt64 nSize = 0; + + osl_getFileSize(handle, &nSize); + OUString sectionName( "no name section" ); + while (true) + { + sal_uInt64 nPos; + if (osl_File_E_None != osl_getFilePos(handle, &nPos) || nPos >= nSize) + break; + if (osl_File_E_None != osl_readLine(handle, reinterpret_cast(&seq))) + break; + OString line(reinterpret_cast(seq.getConstArray()), seq.getLength() ); + sal_Int32 nIndex = line.indexOf('='); + if (nIndex >= 1) + { + ini_Section *aSection = &mAllSection[sectionName]; + struct ini_NameValue nameValue; + nameValue.sName = OStringToOUString( + o3tl::trim(line.subView(0,nIndex)), RTL_TEXTENCODING_ASCII_US ); + nameValue.sValue = OStringToOUString( + o3tl::trim(line.subView(nIndex+1)), RTL_TEXTENCODING_UTF8 ); + + aSection->vVector.push_back(nameValue); + + } + else + { + sal_Int32 nIndexStart = line.indexOf('['); + sal_Int32 nIndexEnd = line.indexOf(']'); + if ( nIndexEnd > nIndexStart && nIndexStart >=0) + { + sectionName = OStringToOUString( + o3tl::trim(line.subView(nIndexStart + 1,nIndexEnd - nIndexStart -1)), RTL_TEXTENCODING_ASCII_US ); + if (sectionName.isEmpty()) + sectionName = "no name section"; + } + } + } + osl_closeFile(handle); + } + else + { + SAL_INFO("connectivity.mozab", "couldn't open file: " << iniUrl ); + } +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/mozab/bootstrap/MNSINIParser.hxx b/connectivity/source/drivers/mozab/bootstrap/MNSINIParser.hxx new file mode 100644 index 000000000..27746364a --- /dev/null +++ b/connectivity/source/drivers/mozab/bootstrap/MNSINIParser.hxx @@ -0,0 +1,54 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#pragma once + +#include + +#include +#include + +struct ini_NameValue +{ + OUString sName; + OUString sValue; +}; + +typedef std::vector< + ini_NameValue +> NameValueVector; + +struct ini_Section +{ + NameValueVector vVector; +}; +typedef std::mapIniSectionMap; + + +class IniParser +{ + IniSectionMap mAllSection; +public: + IniSectionMap& getAllSection() { return mAllSection; } + /// @throws css::io::IOException + explicit IniParser(OUString const & rIniName); +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/mozab/bootstrap/MNSProfileDiscover.cxx b/connectivity/source/drivers/mozab/bootstrap/MNSProfileDiscover.cxx new file mode 100644 index 000000000..18d95cdbd --- /dev/null +++ b/connectivity/source/drivers/mozab/bootstrap/MNSProfileDiscover.cxx @@ -0,0 +1,210 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + + +#include "MNSProfileDiscover.hxx" +#include "MNSFolders.hxx" +#include "MNSINIParser.hxx" + +namespace connectivity::mozab +{ + ProfileStruct::ProfileStruct() + { + } + + ProfileStruct::ProfileStruct(const OUString& aProfileName, + const OUString& aProfilePath) + : profileName(aProfileName) + , profilePath(aProfilePath) + { + } + + const OUString& ProfileStruct::getProfilePath() const + { + return profilePath; + } + + ProfileAccess::~ProfileAccess() + { + } + + ProfileAccess::ProfileAccess() + { + LoadProductsInfo(); + } + + void ProfileAccess::LoadProductsInfo() + { + //tdf#39279: LO should search Thunderbird first then Seamonkey and finally Firefox + //load thunderbird profiles to m_ProductProfileList + LoadXPToolkitProfiles(MozillaProductType_Thunderbird); + + //load SeaMonkey 2 profiles to m_ProductProfileList + LoadXPToolkitProfiles(MozillaProductType_Mozilla); + + //load firefox profiles to m_ProductProfileList + //firefox profile does not contain address book, but maybe others need them + LoadXPToolkitProfiles(MozillaProductType_Firefox); + } + //Thunderbird and firefox profiles are saved in profiles.ini + void ProfileAccess::LoadXPToolkitProfiles(MozillaProductType product) + { + sal_Int32 index=static_cast(product); + ProductStruct &rProduct = m_ProductProfileList[index]; + + OUString regDir = getRegistryDir(product); + OUString profilesIni = regDir + "profiles.ini"; + IniParser parser( profilesIni ); + IniSectionMap &rAllSection = parser.getAllSection(); + + for(auto& rSection : rAllSection) + { + ini_Section *aSection = &rSection.second; + OUString profileName; + OUString profilePath; + OUString sIsRelative; + OUString sIsDefault; + + for(auto& rValue : aSection->vVector) + { + struct ini_NameValue * aValue = &rValue; + if ( aValue->sName == "Name" ) + { + profileName = aValue->sValue; + } + else if ( aValue->sName == "IsRelative" ) + { + sIsRelative = aValue->sValue; + } + else if ( aValue->sName == "Path" ) + { + profilePath = aValue->sValue; + } + else if ( aValue->sName == "Default" ) + { + sIsDefault = aValue->sValue; + } + } + if (!(profileName.isEmpty() && profilePath.isEmpty())) + { + sal_Int32 isRelative = 0; + if (!sIsRelative.isEmpty()) + { + isRelative = sIsRelative.toInt32(); + } + + OUString fullProfilePath; + if(isRelative) + { + fullProfilePath = regDir + profilePath; + } + else + { + fullProfilePath = profilePath; + } + + rProduct.mProfileList[profileName] = ProfileStruct(profileName,fullProfilePath); + + sal_Int32 isDefault = 0; + if (!sIsDefault.isEmpty()) + { + isDefault = sIsDefault.toInt32(); + } + if (isDefault) + rProduct.mCurrentProfileName = profileName; + + } + + // Depending on TB versions, some generate "default" profile + // others "default-release" profile + // See https://support.mozilla.org/gl/questions/1264072 + // for some background info (the link quotes Firefox but it seems + // the same for TB). + if (profileName == "default-release") + { + rProduct.mCurrentProfileName = profileName; + break; + } + } + } + + OUString ProfileAccess::getProfilePath( css::mozilla::MozillaProductType product, const OUString& profileName ) + { + sal_Int32 index=static_cast(product); + ProductStruct &rProduct = m_ProductProfileList[index]; + if (rProduct.mProfileList.empty() || rProduct.mProfileList.find(profileName) == rProduct.mProfileList.end()) + { + //Profile not found + return OUString(); + } + else + return rProduct.mProfileList[profileName].getProfilePath(); + } + + ::sal_Int32 ProfileAccess::getProfileCount( css::mozilla::MozillaProductType product) + { + sal_Int32 index=static_cast(product); + ProductStruct &rProduct = m_ProductProfileList[index]; + return static_cast< ::sal_Int32 >(rProduct.mProfileList.size()); + } + ::sal_Int32 ProfileAccess::getProfileList( css::mozilla::MozillaProductType product, css::uno::Sequence< OUString >& list ) + { + sal_Int32 index=static_cast(product); + ProductStruct &rProduct = m_ProductProfileList[index]; + list.realloc(static_cast(rProduct.mProfileList.size())); + auto listRange = list.getArray(); + sal_Int32 i=0; + for(const auto& rEntry : rProduct.mProfileList) + { + const ProfileStruct& rProfile = rEntry.second; + listRange[i] = rProfile.getProfileName(); + i++; + } + + return static_cast< ::sal_Int32 >(rProduct.mProfileList.size()); + } + + OUString ProfileAccess::getDefaultProfile( css::mozilla::MozillaProductType product ) + { + sal_Int32 index=static_cast(product); + ProductStruct &rProduct = m_ProductProfileList[index]; + if (!rProduct.mCurrentProfileName.isEmpty()) + { + //default profile set in mozilla registry + return rProduct.mCurrentProfileName; + } + if (rProduct.mProfileList.empty()) + { + //there are not any profiles + return OUString(); + } + const ProfileStruct& rProfile = (*rProduct.mProfileList.begin()).second; + return rProfile.getProfileName(); + } + + bool ProfileAccess::getProfileExists( css::mozilla::MozillaProductType product, const OUString& profileName ) + { + sal_Int32 index=static_cast(product); + ProductStruct &rProduct = m_ProductProfileList[index]; + return rProduct.mProfileList.find(profileName) != rProduct.mProfileList.end(); + } +} + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/mozab/bootstrap/MNSProfileDiscover.hxx b/connectivity/source/drivers/mozab/bootstrap/MNSProfileDiscover.hxx new file mode 100644 index 000000000..a5f271183 --- /dev/null +++ b/connectivity/source/drivers/mozab/bootstrap/MNSProfileDiscover.hxx @@ -0,0 +1,80 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include +#include +#include +#include + +#include +#include + +using namespace com::sun::star::mozilla; +namespace connectivity::mozab { class ProfileStruct; } + +typedef std::map ProfileList; +namespace connectivity::mozab + { + class ProfileStruct + { + public: + ProfileStruct(); + ProfileStruct(const OUString& aProfileName, const OUString &aProfilePath); + const OUString& getProfileName() const { return profileName;} + const OUString& getProfilePath() const; + private: + OUString profileName; + OUString profilePath; + }; + + class ProductStruct + { + public: + OUString mCurrentProfileName; + ProfileList mProfileList; + }; + + //Used to query profiles information + class ProfileAccess final + { + public: + ~ProfileAccess(); + ProfileAccess(); + /// @throws css::uno::RuntimeException + OUString getProfilePath( css::mozilla::MozillaProductType product, const OUString& profileName ); + /// @throws css::uno::RuntimeException + ::sal_Int32 getProfileCount( css::mozilla::MozillaProductType product ); + /// @throws css::uno::RuntimeException + ::sal_Int32 getProfileList( css::mozilla::MozillaProductType product, css::uno::Sequence< OUString >& list ); + /// @throws css::uno::RuntimeException + OUString getDefaultProfile( css::mozilla::MozillaProductType product ); + /// @throws css::uno::RuntimeException + bool getProfileExists( css::mozilla::MozillaProductType product, const OUString& profileName ); + private: + ProductStruct m_ProductProfileList[4]; + void LoadProductsInfo(); + void LoadXPToolkitProfiles(MozillaProductType product); + }; + +} + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/mozab/bootstrap/README b/connectivity/source/drivers/mozab/bootstrap/README new file mode 100644 index 000000000..cea68d86c --- /dev/null +++ b/connectivity/source/drivers/mozab/bootstrap/README @@ -0,0 +1,3 @@ +this provides com.sun.star.mozilla.MozillaBootstrap which is used by at least +xmlsecurity/source/xmlsec/nss/nssinitializer.cxx to find a user's +firefox/thunderbird profile to use its certs diff --git a/connectivity/source/drivers/mozab/bootstrap/mozbootstrap.component b/connectivity/source/drivers/mozab/bootstrap/mozbootstrap.component new file mode 100644 index 000000000..bfc0afe38 --- /dev/null +++ b/connectivity/source/drivers/mozab/bootstrap/mozbootstrap.component @@ -0,0 +1,26 @@ + + + + + + + + -- cgit v1.2.3