Kaydet (Commit) 3a68b21c authored tarafından Jan Holesovsky's avatar Jan Holesovsky Kaydeden (comit) Michael Meeks

lok: Allow whitelisting languages that should be used by LibreOfficeKit.

LOK may get way too many languages if there are dictionaries for them
installed which blows the pre-init to >2G easily; let's allow limiting that.

Also make the preloading of languages work with the internal spell checking
dictionaries and thesauri.

Change-Id: I77119970030a7386a5cccbe4fdc89b15eab56ef1
Reviewed-on: https://gerrit.libreoffice.org/48720Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarMichael Meeks <michael.meeks@collabora.com>
üst 079775c0
......@@ -9,6 +9,8 @@
#include <comphelper/lok.hxx>
#include <iostream>
namespace comphelper
{
......@@ -112,6 +114,52 @@ const LanguageTag& getLanguageTag()
return g_aLanguageTag;
}
bool isWhitelistedLanguage(const OUString& lang)
{
if (!isActive())
return true;
static bool bInitialized = false;
static std::vector<OUString> aWhitelist;
if (!bInitialized)
{
const char* pWhitelist = getenv("LOK_WHITELIST_LANGUAGES");
if (pWhitelist)
{
std::stringstream stream(pWhitelist);
std::string s;
std::cerr << "Whitelisted languages: ";
while (getline(stream, s, ' ')) {
if (s.length() == 0)
continue;
std::cerr << s << " ";
aWhitelist.emplace_back(OStringToOUString(s.c_str(), RTL_TEXTENCODING_UTF8));
}
std::cerr << std::endl;
}
if (aWhitelist.empty())
std::cerr << "No language whitelisted, turning off the language support." << std::endl;
bInitialized = true;
}
if (aWhitelist.empty())
return false;
for (auto& entry : aWhitelist)
{
if (lang.startsWith(entry))
return true;
if (lang.startsWith(entry.replace('_', '-')))
return true;
}
return false;
}
static void (*pStatusIndicatorCallback)(void *data, statusIndicatorCallbackType type, int percent)(nullptr);
static void *pStatusIndicatorCallbackData(nullptr);
......
......@@ -3720,7 +3720,7 @@ static int lo_initialize(LibreOfficeKit* pThis, const char* pAppPath, const char
if (eStage != PRE_INIT)
comphelper::LibreOfficeKit::setStatusIndicatorCallback(lo_status_indicator_callback, pLib);
if (pUserProfileUrl)
if (pUserProfileUrl && eStage != PRE_INIT)
{
OUString url(
pUserProfileUrl, strlen(pUserProfileUrl), RTL_TEXTENCODING_UTF8);
......
......@@ -71,6 +71,8 @@ COMPHELPER_DLLPUBLIC bool isRangeHeaders();
COMPHELPER_DLLPUBLIC void setLanguageTag(const LanguageTag& languageTag);
/// Get the current LOK's language.
COMPHELPER_DLLPUBLIC const LanguageTag& getLanguageTag();
/// If the language name should be used for this LOK instance.
COMPHELPER_DLLPUBLIC bool isWhitelistedLanguage(const OUString& lang);
// Status indicator handling. Even if in theory there could be several status indicators active at
// the same time, in practice there is only one at a time, so we don't handle any identification of
......
......@@ -20,6 +20,7 @@
#include <com/sun/star/uno/Reference.h>
#include <com/sun/star/linguistic2/SpellFailure.hpp>
#include <comphelper/lok.hxx>
#include <comphelper/processfactory.hxx>
#include <cppuhelper/factory.hxx>
#include <cppuhelper/supportsservice.hxx>
......@@ -156,6 +157,9 @@ Sequence< Locale > SAL_CALL SpellChecker::getLocales()
{
for (auto const& locale : aLocaleNames)
{
if (!comphelper::LibreOfficeKit::isWhitelistedLanguage(locale))
continue;
aLocaleNamesSet.insert(locale);
}
}
......
......@@ -26,6 +26,7 @@
#include <com/sun/star/linguistic2/XSpellChecker1.hpp>
#include <i18nlangtag/languagetag.hxx>
#include <tools/debug.hxx>
#include <comphelper/lok.hxx>
#include <comphelper/processfactory.hxx>
#include <osl/mutex.hxx>
#include <unotools/pathoptions.hxx>
......@@ -174,6 +175,9 @@ Sequence< Locale > SAL_CALL Thesaurus::getLocales()
sal_Int32 nLen2 = aLocaleNames.getLength();
for (k = 0; k < nLen2; ++k)
{
if (!comphelper::LibreOfficeKit::isWhitelistedLanguage(aLocaleNames[k]))
continue;
aLocaleNamesSet.insert( aLocaleNames[k] );
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment