From 7d37241dcb7aa20adfa7510323cfd7984ff5e911 Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Fri, 23 Aug 2024 14:09:41 +0200 Subject: Emscripten: Module.uno_scripts are relative to document.baseURI ...so explicitly make them absolute, in case the WorkerGlboalScope used in runUnoScriptUrl would make them absolute relative to a different base URL. (See "WorkerGlobalScope.importScripts URLs relative to what base URL?" for my confusion of what base URL should actually be used there. But at least with an emsdk that uses recent Emscripten trunk towards 3.1.65, and where meanwhile worker threads no longer load an soffice.worker.js but instead use some blob: URL, a > Module.uno_scripts = ['example.js']; now failed with > Error: Failed to execute 'importScripts' on 'WorkerGlobalScope': The URL 'example.js' is invalid. on Chrome 127.) Change-Id: I9f9b43d501a7b5d933c8506debdebe67ff1b5795 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/172325 Reviewed-by: Stephan Bergmann Tested-by: Jenkins --- desktop/source/app/appinit.cxx | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'desktop/source/app/appinit.cxx') diff --git a/desktop/source/app/appinit.cxx b/desktop/source/app/appinit.cxx index 6253b7afe20b..1dc962e7a008 100644 --- a/desktop/source/app/appinit.cxx +++ b/desktop/source/app/appinit.cxx @@ -36,6 +36,7 @@ #include #include #include +#include #include #include @@ -63,13 +64,14 @@ using namespace ::com::sun::star::ucb; namespace { -extern "C" void getUnoScriptUrls(std::vector * urls) { +extern "C" void getUnoScriptUrls(std::vector * urls) { assert(urls != nullptr); + OUString const base(emscripten::val::global("document")["baseURI"].as()); auto const val = emscripten::val::module_property("uno_scripts"); if (!val.isUndefined()) { auto const len = val["length"].as(); for (std::uint32_t i = 0; i != len; ++i) { - urls->push_back(val[i].as()); + urls->push_back(rtl::Uri::convertRelToAbs(base, OUString(val[i].as()))); } } } @@ -108,13 +110,13 @@ extern "C" void resolveUnoMain() { void initUno() { init_unoembind_uno(); - std::vector urls; + std::vector urls; emscripten_sync_run_in_main_runtime_thread(EM_FUNC_SIG_VI, getUnoScriptUrls, &urls); for (auto const & url: urls) { - if (url.find('\0') != std::u16string::npos) { + if (url.indexOf('\0') != -1) { throw std::invalid_argument("Module.uno_scripts element contains embedded NUL"); } - runUnoScriptUrl(url.c_str()); + runUnoScriptUrl(url.getStr()); } setupMainChannel(); EM_ASM(Module.uno_init$resolve();); -- cgit