summaryrefslogtreecommitdiff
path: root/shell
diff options
context:
space:
mode:
authorJan-Marek Glogowski <glogow@fbihome.de>2021-11-30 19:15:13 +0100
committerJan-Marek Glogowski <glogow@fbihome.de>2022-01-20 10:26:04 +0100
commit972aa39fb976e30ce73065b1eba69f4c78c17855 (patch)
tree144c1a2c7ef462c6391bb6cd647a05960ee2aa96 /shell
parente9443070888628f7643741c1abcaaef28de6a53f (diff)
WASM open links in new browser tabs
I quickly gave up trying to understand what exactly clashes between the Emscripten macros and OUString templates / initializers. Not sure it can actually be "fixed". Also disables the makeshared clang compilerplugin; currently there is no way to get rid of all the false positive hits when assigning the std::shared_ptr from a function instead of a constructor call. Change-Id: I8b13f179629ea63ff221584030556d2bedadc01b Reviewed-on: https://gerrit.libreoffice.org/c/core/+/128604 Tested-by: Jenkins Reviewed-by: Jan-Marek Glogowski <glogow@fbihome.de>
Diffstat (limited to 'shell')
-rw-r--r--shell/Library_syssh.mk6
-rw-r--r--shell/source/unix/exec/shellexec.cxx24
-rw-r--r--shell/source/unix/exec/shellexec_em.cxx28
3 files changed, 58 insertions, 0 deletions
diff --git a/shell/Library_syssh.mk b/shell/Library_syssh.mk
index e83a85262dcf..d059d6c5b671 100644
--- a/shell/Library_syssh.mk
+++ b/shell/Library_syssh.mk
@@ -43,6 +43,12 @@ $(eval $(call gb_Library_add_exception_objects,syssh,\
shell/source/unix/exec/shellexec \
))
+ifeq ($(OS),EMSCRIPTEN)
+$(eval $(call gb_Library_add_exception_objects,syssh,\
+ shell/source/unix/exec/shellexec_em \
+))
+endif
+
endif # OS
# vim: set shiftwidth=4 tabstop=4 noexpandtab:
diff --git a/shell/source/unix/exec/shellexec.cxx b/shell/source/unix/exec/shellexec.cxx
index 5248c934ab16..2e2b2040af1b 100644
--- a/shell/source/unix/exec/shellexec.cxx
+++ b/shell/source/unix/exec/shellexec.cxx
@@ -39,6 +39,11 @@
#include <sys/stat.h>
#endif
+#ifdef EMSCRIPTEN
+#include <rtl/uri.hxx>
+extern void execute_browser(const char* sUrl);
+#endif
+
using com::sun::star::system::XSystemShellExecute;
using com::sun::star::system::SystemShellExecuteException;
@@ -47,6 +52,7 @@ using namespace ::com::sun::star::lang;
using namespace ::com::sun::star::system::SystemShellExecuteFlags;
using namespace cppu;
+#ifndef EMSCRIPTEN
namespace
{
void escapeForShell( OStringBuffer & rBuffer, const OString & rURL)
@@ -63,6 +69,7 @@ namespace
}
}
}
+#endif
ShellExec::ShellExec( const Reference< XComponentContext >& xContext ) :
m_xContext(xContext)
@@ -71,6 +78,7 @@ ShellExec::ShellExec( const Reference< XComponentContext >& xContext ) :
void SAL_CALL ShellExec::execute( const OUString& aCommand, const OUString& aParameter, sal_Int32 nFlags )
{
+#ifndef EMSCRIPTEN
OStringBuffer aBuffer, aLaunchBuffer;
if (comphelper::LibreOfficeKit::isActive())
@@ -228,6 +236,22 @@ void SAL_CALL ShellExec::execute( const OUString& aCommand, const OUString& aPar
int nerr = errno;
throw SystemShellExecuteException(OUString::createFromAscii( strerror( nerr ) ),
static_cast < XSystemShellExecute * > (this), nerr );
+#else // EMSCRIPTEN
+ (void)nFlags;
+
+ css::uno::Reference< css::uri::XUriReference > uri(
+ css::uri::UriReferenceFactory::create(m_xContext)->parse(aCommand));
+ if (!uri.is() || !uri->isAbsolute())
+ throw SystemShellExecuteException("Emscripten can just open absolute URIs.",
+ static_cast<XSystemShellExecute*>(this), 42);
+ if (!aParameter.isEmpty())
+ throw SystemShellExecuteException("Emscripten can't process parameters; encode in URI.",
+ static_cast<XSystemShellExecute*>(this), 42);
+
+ OUString sEscapedURI(rtl::Uri::encode(aCommand, rtl_UriCharClassUric,
+ rtl_UriEncodeIgnoreEscapes, RTL_TEXTENCODING_UTF8));
+ execute_browser(sEscapedURI.toUtf8().getStr());
+#endif
}
// XServiceInfo
diff --git a/shell/source/unix/exec/shellexec_em.cxx b/shell/source/unix/exec/shellexec_em.cxx
new file mode 100644
index 000000000000..219eac969416
--- /dev/null
+++ b/shell/source/unix/exec/shellexec_em.cxx
@@ -0,0 +1,28 @@
+/* -*- 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/.
+ */
+
+/**
+ * Some of our templating stuff clashes with EM_ASM / MAIN_THREAD_EM_ASM:
+ *
+ * shellexec.cxx:250:5: error: called object type 'const char *' is not a function or function pointer
+ * MAIN_THREAD_EM_ASM(
+ * ^
+ * git_emsdk/upstream/emscripten/cache/sysroot/include/emscripten/em_asm.h:208:39: note: expanded from macro 'MAIN_THREAD_EM_ASM'
+ * #define MAIN_THREAD_EM_ASM(code, ...) ((void)emscripten_asm_const_int_sync_on_main_thread(CODE_EXPR(#code) _EM_ASM_PREP_ARGS(__VA_ARGS__)))
+ * ^
+ * 1 error generated.
+ *
+ * so as a workaround the EM_ASM call is now in an extra file.
+ */
+
+#include <emscripten.h>
+
+void execute_browser(const char* sUrl) { EM_ASM("window.open(UTF8ToString($0));", sUrl); }
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */