From 349b02b7f21ffda1e3e9c92939fc4d77029d0086 Mon Sep 17 00:00:00 2001 From: Christian Lohmaier Date: Wed, 29 May 2019 15:16:23 +0200 Subject: tdf#125578 force webhelp as workaround for Safari sandboxing w/ macOS 10.14 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sandboxing prevents access to files in user profile as well as to contents of the LibreOffice.app unless it is manually triggered by the user. Even a clicking a link pointing to the files on an automatically opened file is not enough, the user would have to copy'n'paste the target. As a workaround force online help when default browser is Safari and running on 10.14 or later. (other browsers don't seem to enforce sandboxing yet and continue to work) also fix error in the meta tag for the intermediate page (delay and URL are both part of the content attribute and not separate) Change-Id: I6cc50ec1b1928c2416fdfef4cf50e2196a8594ae Reviewed-on: https://gerrit.libreoffice.org/73163 Tested-by: Xisco FaulĂ­ Tested-by: Jenkins Reviewed-by: Olivier Hallot Reviewed-by: Christian Lohmaier (cherry picked from commit 44893662d510c4173e55ba27af02d0258a697a5d) Reviewed-on: https://gerrit.libreoffice.org/73245 Reviewed-by: Adolfo Jayme Barrientos --- sfx2/Library_sfx.mk | 3 +++ sfx2/source/appl/sfxhelp.cxx | 47 +++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 47 insertions(+), 3 deletions(-) (limited to 'sfx2') diff --git a/sfx2/Library_sfx.mk b/sfx2/Library_sfx.mk index 750f3b354c73..8557d763a31a 100644 --- a/sfx2/Library_sfx.mk +++ b/sfx2/Library_sfx.mk @@ -324,6 +324,9 @@ $(eval $(call gb_Library_add_defs,sfx,\ endif ifeq ($(OS),MACOSX) +$(eval $(call gb_Library_add_cxxflags,sfx,\ + $(gb_OBJCXXFLAGS) \ +)) $(eval $(call gb_Library_add_objcxxobjects,sfx,\ sfx2/source/appl/shutdowniconaqua \ )) diff --git a/sfx2/source/appl/sfxhelp.cxx b/sfx2/source/appl/sfxhelp.cxx index ce59b412d8ce..2d36e9ac5198 100644 --- a/sfx2/source/appl/sfxhelp.cxx +++ b/sfx2/source/appl/sfxhelp.cxx @@ -23,6 +23,13 @@ #include #include #include +#ifdef MACOSX +#include +#include +#include +#include +#include +#endif #include #include @@ -723,7 +730,16 @@ static bool impl_showOnlineHelp( const OUString& rURL ) try { +#ifdef MACOSX + LSOpenCFURLRef(CFURLCreateWithString(kCFAllocatorDefault, + CFStringCreateWithCString(kCFAllocatorDefault, + aHelpLink.toUtf8().getStr(), + kCFStringEncodingUTF8), + NULL), + NULL); +#else sfx2::openUriExternally(aHelpLink, false); +#endif return true; } catch (const Exception&) @@ -903,10 +919,11 @@ bool rewriteFlatpakHelpRootUrl(OUString * helpRootUrl) { } #define SHTML1 "" -#define SHTML2 "Help Page Redirection" +// use a tempfile since e.g. xdg-open doesn't support URL-parameters with file:// URLs static bool impl_showOfflineHelp( const OUString& rURL ) { OUString aBaseInstallPath = getHelpRootURL(); @@ -940,10 +957,18 @@ static bool impl_showOfflineHelp( const OUString& rURL ) pStream->WriteUnicodeOrByteText(aTempStr); aTempFile.CloseStream(); - try { +#ifdef MACOSX + LSOpenCFURLRef(CFURLCreateWithString(kCFAllocatorDefault, + CFStringCreateWithCString(kCFAllocatorDefault, + aTempFile.GetURL().toUtf8().getStr(), + kCFStringEncodingUTF8), + NULL), + NULL); +#else sfx2::openUriExternally(aTempFile.GetURL(), false); +#endif return true; } catch (const Exception&) @@ -1055,6 +1080,22 @@ bool SfxHelp::Start_Impl(const OUString& rURL, const vcl::Window* pWindow, const impl_showOnlineHelp( aHelpURL ); return true; } +#ifdef MACOSX + if (@available(macOS 10.14, *)) { + // Workaround: Safari sandboxing prevents it from accessing files in the LibreOffice.app folder + // force online-help instead if Safari is default browser. + CFURLRef pBrowser = LSCopyDefaultApplicationURLForURL( + CFURLCreateWithString( + kCFAllocatorDefault, + (CFStringRef)@"https://www.libreoffice.org", + NULL), + kLSRolesAll, NULL); + if([(NSString*)CFURLGetString(pBrowser) isEqualToString:@"file:///Applications/Safari.app/"]) { + impl_showOnlineHelp( aHelpURL ); + return true; + } + } +#endif // If the HTML or no help is installed, but aHelpURL nevertheless references valid help content, // that implies that this help content belongs to an extension (and thus would not be available -- cgit