[Libreoffice-commits] core.git: comphelper/source desktop/source include/comphelper lingucomponent/source

Jan Holesovsky kendy at collabora.com
Sat Jan 27 10:04:54 UTC 2018


 comphelper/source/misc/lok.cxx                       |   48 +++++++++++++++++++
 desktop/source/lib/init.cxx                          |    2 
 include/comphelper/lok.hxx                           |    2 
 lingucomponent/source/spellcheck/spell/sspellimp.cxx |    4 +
 lingucomponent/source/thesaurus/libnth/nthesimp.cxx  |    4 +
 5 files changed, 59 insertions(+), 1 deletion(-)

New commits:
commit 3a68b21c212c1c2fc7f1d8f4d1abc8990bcd91c0
Author: Jan Holesovsky <kendy at collabora.com>
Date:   Fri Jan 26 20:28:46 2018 +0100

    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/48720
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Michael Meeks <michael.meeks at collabora.com>

diff --git a/comphelper/source/misc/lok.cxx b/comphelper/source/misc/lok.cxx
index 2e8624d1e8d0..589f57b61bce 100644
--- a/comphelper/source/misc/lok.cxx
+++ b/comphelper/source/misc/lok.cxx
@@ -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);
 
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index deba56c3eafc..54f81663517b 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -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);
diff --git a/include/comphelper/lok.hxx b/include/comphelper/lok.hxx
index e9634e77d6f9..9759bb524541 100644
--- a/include/comphelper/lok.hxx
+++ b/include/comphelper/lok.hxx
@@ -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
diff --git a/lingucomponent/source/spellcheck/spell/sspellimp.cxx b/lingucomponent/source/spellcheck/spell/sspellimp.cxx
index 694bc1aa27e4..12b9e240fa24 100644
--- a/lingucomponent/source/spellcheck/spell/sspellimp.cxx
+++ b/lingucomponent/source/spellcheck/spell/sspellimp.cxx
@@ -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);
                         }
                     }
diff --git a/lingucomponent/source/thesaurus/libnth/nthesimp.cxx b/lingucomponent/source/thesaurus/libnth/nthesimp.cxx
index 88a6550ddf5e..ce1d4a07f492 100644
--- a/lingucomponent/source/thesaurus/libnth/nthesimp.cxx
+++ b/lingucomponent/source/thesaurus/libnth/nthesimp.cxx
@@ -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] );
                 }
             }


More information about the Libreoffice-commits mailing list