diff options
author | Jan-Marek Glogowski <glogow@fbihome.de> | 2021-11-30 19:15:13 +0100 |
---|---|---|
committer | Jan-Marek Glogowski <glogow@fbihome.de> | 2022-01-20 10:26:04 +0100 |
commit | 972aa39fb976e30ce73065b1eba69f4c78c17855 (patch) | |
tree | 144c1a2c7ef462c6391bb6cd647a05960ee2aa96 | |
parent | e9443070888628f7643741c1abcaaef28de6a53f (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>
-rw-r--r-- | compilerplugins/clang/makeshared.cxx | 2 | ||||
-rw-r--r-- | postprocess/Module_postprocess.mk | 2 | ||||
-rw-r--r-- | shell/Library_syssh.mk | 6 | ||||
-rw-r--r-- | shell/source/unix/exec/shellexec.cxx | 24 | ||||
-rw-r--r-- | shell/source/unix/exec/shellexec_em.cxx | 28 | ||||
-rw-r--r-- | vcl/source/control/fixedhyper.cxx | 5 |
6 files changed, 63 insertions, 4 deletions
diff --git a/compilerplugins/clang/makeshared.cxx b/compilerplugins/clang/makeshared.cxx index 816d1269fac3..bac0ea0a5653 100644 --- a/compilerplugins/clang/makeshared.cxx +++ b/compilerplugins/clang/makeshared.cxx @@ -242,7 +242,7 @@ bool MakeShared::VisitVarDecl(VarDecl const* varDecl) return true; } -loplugin::Plugin::Registration<MakeShared> makeshared("makeshared"); +loplugin::Plugin::Registration<MakeShared> makeshared("makeshared", false); } // namespace diff --git a/postprocess/Module_postprocess.mk b/postprocess/Module_postprocess.mk index 8a8ec0891540..0fbede6a9f2b 100644 --- a/postprocess/Module_postprocess.mk +++ b/postprocess/Module_postprocess.mk @@ -40,7 +40,7 @@ endif # contain content from at least one of external/more_fonts/fc_local.snippet # (conditional on MORE_FONTS in BUILD_TYPE) and # extras/source/truetype/symbol/fc_local.snippet (unconditional): -ifneq ($(USING_X11)$(DISABLE_GUI)$(filter ANDROID,$(OS)),) +ifneq ($(USING_X11)$(DISABLE_GUI)$(filter ANDROID EMSCRIPTEN,$(OS)),) $(eval $(call gb_Module_add_targets,postprocess, \ CustomTarget_fontconfig \ Package_fontconfig \ 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: */ diff --git a/vcl/source/control/fixedhyper.cxx b/vcl/source/control/fixedhyper.cxx index f5d49057228d..8a451d2fab47 100644 --- a/vcl/source/control/fixedhyper.cxx +++ b/vcl/source/control/fixedhyper.cxx @@ -176,9 +176,10 @@ IMPL_LINK(FixedHyperlink, HandleClick, FixedHyperlink&, rHyperlink, void) uno::Any exc(cppu::getCaughtException()); OUString msg(comphelper::anyToString(exc)); SolarMutexGuard g; - std::unique_ptr<weld::MessageDialog> xErrorBox(Application::CreateMessageDialog(GetFrameWeld(), VclMessageType::Error, VclButtonsType::Ok, msg)); + std::shared_ptr<weld::MessageDialog> xErrorBox( + Application::CreateMessageDialog(GetFrameWeld(), VclMessageType::Error, VclButtonsType::Ok, msg)); xErrorBox->set_title(rHyperlink.GetText()); - xErrorBox->run(); + xErrorBox->runAsync(xErrorBox, [](sal_Int32){}); } } |