Emscripten: Call initJsUnoScripting also from LOKit
...so that functionality is available there, too. (And by breaking the code out into its own file, give the function a more self-explanatory name than the original "initUno".) Change-Id: Ic65fbd98447574d881c4e7827a2cfeb67d3ff1fa Reviewed-on: https://gerrit.libreoffice.org/c/core/+/188040 Reviewed-by: Stephan Bergmann <stephan.bergmann@collabora.com> Tested-by: Jenkins
This commit is contained in:
@@ -122,6 +122,7 @@ $(eval $(call gb_Library_add_exception_objects,sofficeapp,\
|
||||
desktop/source/app/cmdlinehelp \
|
||||
desktop/source/app/desktopcontext \
|
||||
desktop/source/app/dispatchwatcher \
|
||||
desktop/source/app/initjsunoscripting \
|
||||
desktop/source/app/langselect \
|
||||
desktop/source/app/lockfile2 \
|
||||
desktop/source/app/officeipcthread \
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
|
||||
/*
|
||||
* 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/.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <sal/config.h>
|
||||
|
||||
#if defined EMSCRIPTEN
|
||||
|
||||
void initJsUnoScripting();
|
||||
|
||||
#endif
|
||||
|
||||
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
|
||||
@@ -19,13 +19,11 @@
|
||||
|
||||
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <app.hxx>
|
||||
#include <dp_shared.hxx>
|
||||
#include <initjsunoscripting.hxx>
|
||||
#include "cmdlineargs.hxx"
|
||||
#include <strings.hrc>
|
||||
#include <com/sun/star/lang/XInitialization.hpp>
|
||||
@@ -36,7 +34,6 @@
|
||||
#include <officecfg/Setup.hxx>
|
||||
#include <osl/file.hxx>
|
||||
#include <rtl/bootstrap.hxx>
|
||||
#include <rtl/uri.hxx>
|
||||
#include <sal/log.hxx>
|
||||
#include <comphelper/diagnose_ex.hxx>
|
||||
|
||||
@@ -49,103 +46,10 @@
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
|
||||
#if defined EMSCRIPTEN
|
||||
#include <emscripten.h>
|
||||
#include <emscripten/threading.h>
|
||||
#include <emscripten/val.h>
|
||||
#include <bindings_uno.hxx>
|
||||
#include <config_emscripten.h>
|
||||
#endif
|
||||
|
||||
using namespace ::com::sun::star::uno;
|
||||
using namespace ::com::sun::star::lang;
|
||||
using namespace ::com::sun::star::ucb;
|
||||
|
||||
#if defined EMSCRIPTEN
|
||||
|
||||
namespace {
|
||||
|
||||
extern "C" void getUnoScriptUrls(std::vector<std::u16string> * urls) {
|
||||
assert(urls != nullptr);
|
||||
OUString const base(emscripten::val::global("document")["baseURI"].as<std::u16string>());
|
||||
auto const val = emscripten::val::module_property("uno_scripts");
|
||||
if (!val.isUndefined()) {
|
||||
auto const len = val["length"].as<std::uint32_t>();
|
||||
for (std::uint32_t i = 0; i != len; ++i) {
|
||||
urls->push_back(
|
||||
std::u16string(
|
||||
rtl::Uri::convertRelToAbs(base, OUString(val[i].as<std::u16string>()))));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if HAVE_EMSCRIPTEN_PROXY_TO_PTHREAD
|
||||
EM_JS(void, runUnoScriptUrls, (emscripten::EM_VAL handle), {
|
||||
importScripts.apply(self, Emval.toValue(handle));
|
||||
});
|
||||
#else
|
||||
EM_JS(void, runUnoScriptUrls, (emscripten::EM_VAL handle), {
|
||||
const urls = Emval.toValue(handle);
|
||||
function step() {
|
||||
if (urls.length !== 0) {
|
||||
const url = urls.shift();
|
||||
fetch(url).then(res => {
|
||||
if (!res.ok) {
|
||||
throw Error(
|
||||
"Loading <" + res.url + "> failed with " + res.status + " "
|
||||
+ res.statusText);
|
||||
}
|
||||
return res.blob();
|
||||
}).then(blob => blob.text()).then(text => { eval(text); step(); });
|
||||
}
|
||||
};
|
||||
step();
|
||||
});
|
||||
#endif
|
||||
|
||||
EM_JS(void, setupMainChannel, (), {
|
||||
const orig = self.onmessage;
|
||||
self.onmessage = function(e) {
|
||||
if (e.data.cmd === "LOWA-channel") {
|
||||
self.onmessage = orig;
|
||||
Module.uno_mainPort = e.ports[0];
|
||||
Module.uno_init$resolve();
|
||||
} else if (orig) {
|
||||
orig(e);
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
extern "C" void resolveUnoMain(pthread_t id) {
|
||||
#if HAVE_EMSCRIPTEN_PROXY_TO_PTHREAD
|
||||
EM_ASM({
|
||||
const sofficeMain = PThread.pthreads[$0];
|
||||
const channel = new MessageChannel();
|
||||
sofficeMain.postMessage({cmd:"LOWA-channel"}, [channel.port2]);
|
||||
Module.uno_main$resolve(channel.port1);
|
||||
}, id);
|
||||
#else
|
||||
EM_ASM({
|
||||
const channel = new MessageChannel();
|
||||
postMessage({cmd:"LOWA-channel"}, [channel.port2]);
|
||||
Module.uno_main$resolve(channel.port1);
|
||||
}, id);
|
||||
#endif
|
||||
}
|
||||
|
||||
void initUno() {
|
||||
init_unoembind_uno();
|
||||
std::vector<std::u16string> urls;
|
||||
emscripten_sync_run_in_main_runtime_thread(EM_FUNC_SIG_VI, getUnoScriptUrls, &urls);
|
||||
runUnoScriptUrls(emscripten::val::array(urls).as_handle());
|
||||
setupMainChannel();
|
||||
emscripten_async_run_in_main_runtime_thread(EM_FUNC_SIG_VI, resolveUnoMain, pthread_self());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
namespace desktop
|
||||
{
|
||||
|
||||
@@ -179,7 +83,7 @@ void Desktop::InitApplicationServiceManager()
|
||||
#endif
|
||||
comphelper::setProcessServiceFactory(sm);
|
||||
#if defined EMSCRIPTEN
|
||||
initUno();
|
||||
initJsUnoScripting();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,113 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
|
||||
/*
|
||||
* 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/.
|
||||
*/
|
||||
|
||||
#include <sal/config.h>
|
||||
|
||||
#if defined EMSCRIPTEN
|
||||
|
||||
#include <cassert>
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
#include <emscripten.h>
|
||||
#include <emscripten/threading.h>
|
||||
#include <emscripten/val.h>
|
||||
|
||||
#include <bindings_uno.hxx>
|
||||
#include <config_emscripten.h>
|
||||
#include <rtl/uri.hxx>
|
||||
#include <rtl/ustring.hxx>
|
||||
|
||||
namespace {
|
||||
|
||||
extern "C" void getUnoScriptUrls(std::vector<std::u16string> * urls) {
|
||||
assert(urls != nullptr);
|
||||
OUString const base(emscripten::val::global("document")["baseURI"].as<std::u16string>());
|
||||
auto const val = emscripten::val::module_property("uno_scripts");
|
||||
if (!val.isUndefined()) {
|
||||
auto const len = val["length"].as<std::uint32_t>();
|
||||
for (std::uint32_t i = 0; i != len; ++i) {
|
||||
urls->push_back(
|
||||
std::u16string(
|
||||
rtl::Uri::convertRelToAbs(base, OUString(val[i].as<std::u16string>()))));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if HAVE_EMSCRIPTEN_PROXY_TO_PTHREAD
|
||||
EM_JS(void, runUnoScriptUrls, (emscripten::EM_VAL handle), {
|
||||
importScripts.apply(self, Emval.toValue(handle));
|
||||
});
|
||||
#else
|
||||
EM_JS(void, runUnoScriptUrls, (emscripten::EM_VAL handle), {
|
||||
const urls = Emval.toValue(handle);
|
||||
function step() {
|
||||
if (urls.length !== 0) {
|
||||
const url = urls.shift();
|
||||
fetch(url).then(res => {
|
||||
if (!res.ok) {
|
||||
throw Error(
|
||||
"Loading <" + res.url + "> failed with " + res.status + " "
|
||||
+ res.statusText);
|
||||
}
|
||||
return res.blob();
|
||||
}).then(blob => blob.text()).then(text => { eval(text); step(); });
|
||||
}
|
||||
};
|
||||
step();
|
||||
});
|
||||
#endif
|
||||
|
||||
EM_JS(void, setupMainChannel, (), {
|
||||
const orig = self.onmessage;
|
||||
self.onmessage = function(e) {
|
||||
if (e.data.cmd === "LOWA-channel") {
|
||||
self.onmessage = orig;
|
||||
Module.uno_mainPort = e.ports[0];
|
||||
Module.uno_init$resolve();
|
||||
} else if (orig) {
|
||||
orig(e);
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
extern "C" void resolveUnoMain(pthread_t id) {
|
||||
#if HAVE_EMSCRIPTEN_PROXY_TO_PTHREAD
|
||||
EM_ASM({
|
||||
const sofficeMain = PThread.pthreads[$0];
|
||||
const channel = new MessageChannel();
|
||||
sofficeMain.postMessage({cmd:"LOWA-channel"}, [channel.port2]);
|
||||
Module.uno_main$resolve(channel.port1);
|
||||
}, id);
|
||||
#else
|
||||
EM_ASM({
|
||||
const channel = new MessageChannel();
|
||||
postMessage({cmd:"LOWA-channel"}, [channel.port2]);
|
||||
Module.uno_main$resolve(channel.port1);
|
||||
}, id);
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void initJsUnoScripting() {
|
||||
init_unoembind_uno();
|
||||
std::vector<std::u16string> urls;
|
||||
emscripten_sync_run_in_main_runtime_thread(EM_FUNC_SIG_VI, getUnoScriptUrls, &urls);
|
||||
runUnoScriptUrls(emscripten::val::array(urls).as_handle());
|
||||
setupMainChannel();
|
||||
emscripten_async_run_in_main_runtime_thread(EM_FUNC_SIG_VI, resolveUnoMain, pthread_self());
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
|
||||
@@ -212,6 +212,7 @@
|
||||
#include <svx/pageitem.hxx>
|
||||
|
||||
#include <app.hxx>
|
||||
#include <initjsunoscripting.hxx>
|
||||
|
||||
#include "../app/cmdlineargs.hxx"
|
||||
// We also need to hackily be able to start the main libreoffice thread:
|
||||
@@ -7768,6 +7769,10 @@ static bool initialize_uno(const OUString& aAppProgramURL)
|
||||
xSFactory.set(xFactory, uno::UNO_QUERY_THROW);
|
||||
comphelper::setProcessServiceFactory(xSFactory);
|
||||
|
||||
#if defined EMSCRIPTEN
|
||||
initJsUnoScripting();
|
||||
#endif
|
||||
|
||||
SAL_INFO("lok", "Uno initialized - " << xContext.is());
|
||||
|
||||
// set UserInstallation to user profile dir in test/user-template
|
||||
|
||||
@@ -2976,6 +2976,7 @@ desktop/source/app/crashreport.cxx
|
||||
desktop/source/app/desktopcontext.hxx
|
||||
desktop/source/app/dispatchwatcher.cxx
|
||||
desktop/source/app/dispatchwatcher.hxx
|
||||
desktop/source/app/initjsunoscripting.cxx
|
||||
desktop/source/app/langselect.cxx
|
||||
desktop/source/app/lockfile2.cxx
|
||||
desktop/source/app/officeipcthread.cxx
|
||||
|
||||
Reference in New Issue
Block a user