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>
This commit is contained in:
Jan-Marek Glogowski 2021-11-30 19:15:13 +01:00
parent e944307088
commit 972aa39fb9
6 changed files with 63 additions and 4 deletions

View file

@ -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

View file

@ -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 \

View file

@ -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:

View file

@ -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

View file

@ -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: */

View file

@ -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){});
}
}