Kaydet (Commit) d99e4864 authored tarafından Stephan Bergmann's avatar Stephan Bergmann Kaydeden (comit) Michael Stahl

Support "Preview in Web Browser" in Flatpak mode

...by storing the temporary HTML document in a location that can be accessed by
the browser running outside the Flatpak sandbox.  This reuses and extends the
mechanism already in place for the new HTML-based help in Flatpak mode (see
72b936d7 "Enable --help=html for flatpak").

This fixes <https://github.com/flathub/org.libreoffice.LibreOffice/issues/85>
"“Preview in Web Browser” does not work in Flatpak version".

Change-Id: I5f73fd89139ffe6b8ab0dc501154b4f054a0ae5c
Reviewed-on: https://gerrit.libreoffice.org/71570
Tested-by: Jenkins
Reviewed-by: 's avatarStephan Bergmann <sbergman@redhat.com>
(cherry picked from commit c61e7b99)
Reviewed-on: https://gerrit.libreoffice.org/71717Reviewed-by: 's avatarMichael Stahl <Michael.Stahl@cib.de>
üst 6d4bcc64
...@@ -108,7 +108,7 @@ ...@@ -108,7 +108,7 @@
#include <vcl/help.hxx> #include <vcl/help.hxx>
#include <vcl/weld.hxx> #include <vcl/weld.hxx>
#include <vcl/settings.hxx> #include <vcl/settings.hxx>
#include <sfx2/sfxhelp.hxx> #include <sfx2/flatpak.hxx>
#include <sfx2/sfxsids.hrc> #include <sfx2/sfxsids.hrc>
#include <sfx2/app.hxx> #include <sfx2/app.hxx>
#include <sfx2/safemode.hxx> #include <sfx2/safemode.hxx>
...@@ -1712,7 +1712,7 @@ int Desktop::doShutdown() ...@@ -1712,7 +1712,7 @@ int Desktop::doShutdown()
// remove temp directory // remove temp directory
RemoveTemporaryDirectory(); RemoveTemporaryDirectory();
SfxHelp::removeFlatpakHelpTemporaryDirectory(); flatpak::removeTemporaryHtmlDirectory();
// flush evtl. configuration changes so that all config files in user // flush evtl. configuration changes so that all config files in user
// dir are written // dir are written
......
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
/*
* 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/.
*/
#ifndef INCLUDED_INCLUDE_SFX2_FLATPAK_HXX
#define INCLUDED_INCLUDE_SFX2_FLATPAK_HXX
#include <sal/config.h>
#include <rtl/ustring.hxx>
#include <sfx2/dllapi.h>
// Functionality related to the Flatpak version of LibreOffice.
namespace flatpak {
bool isFlatpak();
// Must only be called with SolarMutex locked:
bool createTemporaryHtmlDirectory(OUString ** url);
// Must only be called with SolarMutex locked:
SFX2_DLLPUBLIC void removeTemporaryHtmlDirectory();
}
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
...@@ -53,8 +53,6 @@ public: ...@@ -53,8 +53,6 @@ public:
static OUString GetCurrentModuleIdentifier(); static OUString GetCurrentModuleIdentifier();
// Check for built-in help // Check for built-in help
static bool IsHelpInstalled(); static bool IsHelpInstalled();
static void removeFlatpakHelpTemporaryDirectory();
}; };
#endif // INCLUDED_SFX2_SFXHELP_HXX #endif // INCLUDED_SFX2_SFXHELP_HXX
......
...@@ -94,6 +94,7 @@ $(eval $(call gb_Library_add_exception_objects,sfx,\ ...@@ -94,6 +94,7 @@ $(eval $(call gb_Library_add_exception_objects,sfx,\
sfx2/source/appl/childwin \ sfx2/source/appl/childwin \
sfx2/source/appl/childwinimpl \ sfx2/source/appl/childwinimpl \
sfx2/source/appl/fileobj \ sfx2/source/appl/fileobj \
sfx2/source/appl/flatpak \
sfx2/source/appl/fwkhelper \ sfx2/source/appl/fwkhelper \
sfx2/source/appl/helpdispatch \ sfx2/source/appl/helpdispatch \
sfx2/source/appl/helpinterceptor \ sfx2/source/appl/helpinterceptor \
......
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
/*
* 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/.
*/
#include <sal/config.h>
#include <cassert>
#include <cstdlib>
#include <cstring>
#include <osl/file.hxx>
#include <osl/thread.h>
#include <rtl/textcvt.h>
#include <rtl/ustring.h>
#include <rtl/ustring.hxx>
#include <sal/log.hxx>
#include <sfx2/flatpak.hxx>
#include <tools/debug.hxx>
#include <unotools/tempfile.hxx>
#include <unotools/ucbhelper.hxx>
bool flatpak::isFlatpak() {
static auto const flatpak = [] { return std::getenv("LIBO_FLATPAK") != nullptr; }();
return flatpak;
}
namespace {
// Must only be accessed with SolarMutex locked:
struct {
bool created = false;
OUString url;
} temporaryHtmlDirectoryStatus;
}
bool flatpak::createTemporaryHtmlDirectory(OUString ** url) {
assert(url != nullptr);
DBG_TESTSOLARMUTEX();
if (!temporaryHtmlDirectoryStatus.created) {
auto const env = std::getenv("XDG_CACHE_HOME");
if (env == nullptr) {
SAL_WARN("sfx.appl", "LIBO_FLATPAK mode but unset XDG_CACHE_HOME");
return false;
}
OUString path;
if (!rtl_convertStringToUString(
&path.pData, env, std::strlen(env), osl_getThreadTextEncoding(),
(RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR | RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR
| RTL_TEXTTOUNICODE_FLAGS_INVALID_ERROR)))
{
SAL_WARN(
"sfx.appl",
"LIBO_FLATPAK mode failure converting XDG_CACHE_HOME \"" << env << "\" encoding");
return false;
}
OUString parent;
auto const err = osl::FileBase::getFileURLFromSystemPath(path, parent);
if (err != osl::FileBase::E_None) {
SAL_WARN(
"sfx.appl",
"LIBO_FLATPAK mode failure converting XDG_CACHE_HOME \"" << path << "\" to URL: "
<< err);
return false;
}
if (!parent.endsWith("/")) {
parent += "/";
}
auto const tmp = utl::TempFile(&parent, true);
if (!tmp.IsValid()) {
SAL_WARN(
"sfx.appl", "LIBO_FLATPAK mode failure creating temp dir at <" << parent << ">");
return false;
}
temporaryHtmlDirectoryStatus.url = tmp.GetURL();
temporaryHtmlDirectoryStatus.created = true;
}
*url = &temporaryHtmlDirectoryStatus.url;
return true;
}
void flatpak::removeTemporaryHtmlDirectory() {
DBG_TESTSOLARMUTEX();
if (temporaryHtmlDirectoryStatus.created) {
if (!utl::UCBContentHelper::Kill(temporaryHtmlDirectoryStatus.url)) {
SAL_INFO(
"sfx.appl",
"LIBO_FLATPAK mode failure removing directory <"
<< temporaryHtmlDirectoryStatus.url << ">");
}
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
...@@ -56,7 +56,6 @@ ...@@ -56,7 +56,6 @@
#include <osl/file.hxx> #include <osl/file.hxx>
#include <unotools/bootstrap.hxx> #include <unotools/bootstrap.hxx>
#include <unotools/tempfile.hxx> #include <unotools/tempfile.hxx>
#include <unotools/ucbhelper.hxx>
#include <rtl/uri.hxx> #include <rtl/uri.hxx>
#include <vcl/commandinfoprovider.hxx> #include <vcl/commandinfoprovider.hxx>
#include <vcl/layout.hxx> #include <vcl/layout.hxx>
...@@ -73,6 +72,7 @@ ...@@ -73,6 +72,7 @@
#include "newhelp.hxx" #include "newhelp.hxx"
#include <sfx2/objsh.hxx> #include <sfx2/objsh.hxx>
#include <sfx2/docfac.hxx> #include <sfx2/docfac.hxx>
#include <sfx2/flatpak.hxx>
#include <sfx2/sfxresid.hxx> #include <sfx2/sfxresid.hxx>
#include <helper.hxx> #include <helper.hxx>
#include <sfx2/strings.hrc> #include <sfx2/strings.hrc>
...@@ -734,11 +734,6 @@ static bool impl_showOnlineHelp( const OUString& rURL ) ...@@ -734,11 +734,6 @@ static bool impl_showOnlineHelp( const OUString& rURL )
namespace { namespace {
bool isFlatpak() {
static auto const flatpak = [] { return std::getenv("LIBO_FLATPAK") != nullptr; }();
return flatpak;
}
bool rewriteFlatpakHelpRootUrl(OUString * helpRootUrl) { bool rewriteFlatpakHelpRootUrl(OUString * helpRootUrl) {
assert(helpRootUrl != nullptr); assert(helpRootUrl != nullptr);
//TODO: This function for now assumes that the passed-in *helpRootUrl references //TODO: This function for now assumes that the passed-in *helpRootUrl references
...@@ -905,57 +900,6 @@ bool rewriteFlatpakHelpRootUrl(OUString * helpRootUrl) { ...@@ -905,57 +900,6 @@ bool rewriteFlatpakHelpRootUrl(OUString * helpRootUrl) {
} }
} }
// Must only be accessed with SolarMutex locked:
static struct {
bool created = false;
OUString url;
} flatpakHelpTemporaryDirectoryStatus;
bool createFlatpakHelpTemporaryDirectory(OUString ** url) {
assert(url != nullptr);
DBG_TESTSOLARMUTEX();
if (!flatpakHelpTemporaryDirectoryStatus.created) {
auto const env = std::getenv("XDG_CACHE_HOME");
if (env == nullptr) {
SAL_WARN("sfx.appl", "LIBO_FLATPAK mode but unset XDG_CACHE_HOME");
return false;
}
OUString path;
if (!rtl_convertStringToUString(
&path.pData, env, std::strlen(env), osl_getThreadTextEncoding(),
(RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR | RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR
| RTL_TEXTTOUNICODE_FLAGS_INVALID_ERROR)))
{
SAL_WARN(
"sfx.appl",
"LIBO_FLATPAK mode failure converting XDG_CACHE_HOME \"" << env << "\" encoding");
return false;
}
OUString parent;
auto const err = osl::FileBase::getFileURLFromSystemPath(path, parent);
if (err != osl::FileBase::E_None) {
SAL_WARN(
"sfx.appl",
"LIBO_FLATPAK mode failure converting XDG_CACHE_HOME \"" << path << "\" to URL: "
<< err);
return false;
}
if (!parent.endsWith("/")) {
parent += "/";
}
auto const tmp = utl::TempFile(&parent, true);
if (!tmp.IsValid()) {
SAL_WARN(
"sfx.appl", "LIBO_FLATPAK mode failure creating temp dir at <" << parent << ">");
return false;
}
flatpakHelpTemporaryDirectoryStatus.url = tmp.GetURL();
flatpakHelpTemporaryDirectoryStatus.created = true;
}
*url = &flatpakHelpTemporaryDirectoryStatus.url;
return true;
}
} }
#define SHTML1 "<!DOCTYPE HTML><html lang=\"en-US\"><head><meta charset=\"UTF-8\">" #define SHTML1 "<!DOCTYPE HTML><html lang=\"en-US\"><head><meta charset=\"UTF-8\">"
...@@ -968,7 +912,7 @@ static bool impl_showOfflineHelp( const OUString& rURL ) ...@@ -968,7 +912,7 @@ static bool impl_showOfflineHelp( const OUString& rURL )
OUString aBaseInstallPath = getHelpRootURL(); OUString aBaseInstallPath = getHelpRootURL();
// For the flatpak case, find the pathname outside the flatpak sandbox that corresponds to // For the flatpak case, find the pathname outside the flatpak sandbox that corresponds to
// aBaseInstallPath, because that is what needs to be stored in aTempFile below: // aBaseInstallPath, because that is what needs to be stored in aTempFile below:
if (isFlatpak() && !rewriteFlatpakHelpRootUrl(&aBaseInstallPath)) { if (flatpak::isFlatpak() && !rewriteFlatpakHelpRootUrl(&aBaseInstallPath)) {
return false; return false;
} }
...@@ -981,7 +925,7 @@ static bool impl_showOfflineHelp( const OUString& rURL ) ...@@ -981,7 +925,7 @@ static bool impl_showOfflineHelp( const OUString& rURL )
// technical reasons, so that it can be accessed by the browser running outside the sandbox): // technical reasons, so that it can be accessed by the browser running outside the sandbox):
OUString const aExtension(".html"); OUString const aExtension(".html");
OUString * parent = nullptr; OUString * parent = nullptr;
if (isFlatpak() && !createFlatpakHelpTemporaryDirectory(&parent)) { if (flatpak::isFlatpak() && !flatpak::createTemporaryHtmlDirectory(&parent)) {
return false; return false;
} }
::utl::TempFile aTempFile("NewHelp", true, &aExtension, parent, false ); ::utl::TempFile aTempFile("NewHelp", true, &aExtension, parent, false );
...@@ -1375,16 +1319,4 @@ bool SfxHelp::IsHelpInstalled() ...@@ -1375,16 +1319,4 @@ bool SfxHelp::IsHelpInstalled()
return impl_hasHelpInstalled(); return impl_hasHelpInstalled();
} }
void SfxHelp::removeFlatpakHelpTemporaryDirectory() {
DBG_TESTSOLARMUTEX();
if (flatpakHelpTemporaryDirectoryStatus.created) {
if (!utl::UCBContentHelper::Kill(flatpakHelpTemporaryDirectoryStatus.url)) {
SAL_INFO(
"sfx.appl",
"LIBO_FLATPAK mode failure removing directory <"
<< flatpakHelpTemporaryDirectoryStatus.url << ">");
}
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -61,6 +61,7 @@ ...@@ -61,6 +61,7 @@
#include <officecfg/Setup.hxx> #include <officecfg/Setup.hxx>
#include <sfx2/app.hxx> #include <sfx2/app.hxx>
#include <sfx2/flatpak.hxx>
#include <sfx2/viewsh.hxx> #include <sfx2/viewsh.hxx>
#include "viewimp.hxx" #include "viewimp.hxx"
#include <sfx2/sfxresid.hxx> #include <sfx2/sfxresid.hxx>
...@@ -618,8 +619,15 @@ void SfxViewShell::ExecMisc_Impl( SfxRequest &rReq ) ...@@ -618,8 +619,15 @@ void SfxViewShell::ExecMisc_Impl( SfxRequest &rReq )
OSL_ASSERT( !aFilterName.isEmpty() ); OSL_ASSERT( !aFilterName.isEmpty() );
OSL_ASSERT( !aFileName.isEmpty() ); OSL_ASSERT( !aFileName.isEmpty() );
// Creates a temporary directory to store our predefined file into it. // Creates a temporary directory to store our predefined file into it (for the
::utl::TempFile aTempDir( nullptr, true ); // flatpak case, create it in XDG_CACHE_HOME instead of /tmp for technical reasons,
// so that it can be accessed by the browser running outside the sandbox):
OUString * parent = nullptr;
if (flatpak::isFlatpak() && !flatpak::createTemporaryHtmlDirectory(&parent))
{
SAL_WARN("sfx.view", "cannot create Flatpak html temp dir");
}
::utl::TempFile aTempDir( parent, true );
INetURLObject aFilePathObj( aTempDir.GetURL() ); INetURLObject aFilePathObj( aTempDir.GetURL() );
aFilePathObj.insertName( aFileName ); aFilePathObj.insertName( aFileName );
......
...@@ -6799,6 +6799,7 @@ include/sfx2/event.hxx ...@@ -6799,6 +6799,7 @@ include/sfx2/event.hxx
include/sfx2/evntconf.hxx include/sfx2/evntconf.hxx
include/sfx2/fcontnr.hxx include/sfx2/fcontnr.hxx
include/sfx2/filedlghelper.hxx include/sfx2/filedlghelper.hxx
include/sfx2/flatpak.hxx
include/sfx2/frame.hxx include/sfx2/frame.hxx
include/sfx2/frmdescr.hxx include/sfx2/frmdescr.hxx
include/sfx2/frmhtml.hxx include/sfx2/frmhtml.hxx
...@@ -12802,6 +12803,7 @@ sfx2/source/appl/childwin.cxx ...@@ -12802,6 +12803,7 @@ sfx2/source/appl/childwin.cxx
sfx2/source/appl/childwinimpl.cxx sfx2/source/appl/childwinimpl.cxx
sfx2/source/appl/fileobj.cxx sfx2/source/appl/fileobj.cxx
sfx2/source/appl/fileobj.hxx sfx2/source/appl/fileobj.hxx
sfx2/source/appl/flatpak.cxx
sfx2/source/appl/fwkhelper.cxx sfx2/source/appl/fwkhelper.cxx
sfx2/source/appl/helpdispatch.cxx sfx2/source/appl/helpdispatch.cxx
sfx2/source/appl/helpdispatch.hxx sfx2/source/appl/helpdispatch.hxx
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment