summaryrefslogtreecommitdiff
path: root/sfx2
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2019-04-30 10:38:38 +0200
committerMichael Stahl <Michael.Stahl@cib.de>2019-05-03 12:45:42 +0200
commitd99e4864ef838093d47aa8f3c43403a082e26be2 (patch)
treec2f04d32e752311ea8b0b9c1041b6d6bd76a17c6 /sfx2
parent6d4bcc64184e47c37080bc2b3d780980aff2d98a (diff)
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 72b936d70b7eaa6d9f5f911b27e3c955382de967 "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: Stephan Bergmann <sbergman@redhat.com> (cherry picked from commit c61e7b9940cb30800d6f1000727f9cfd5de9fa5e) Reviewed-on: https://gerrit.libreoffice.org/71717 Reviewed-by: Michael Stahl <Michael.Stahl@cib.de>
Diffstat (limited to 'sfx2')
-rw-r--r--sfx2/Library_sfx.mk1
-rw-r--r--sfx2/source/appl/flatpak.cxx99
-rw-r--r--sfx2/source/appl/sfxhelp.cxx74
-rw-r--r--sfx2/source/view/viewsh.cxx12
4 files changed, 113 insertions, 73 deletions
diff --git a/sfx2/Library_sfx.mk b/sfx2/Library_sfx.mk
index 97f6f9706e76..750f3b354c73 100644
--- a/sfx2/Library_sfx.mk
+++ b/sfx2/Library_sfx.mk
@@ -94,6 +94,7 @@ $(eval $(call gb_Library_add_exception_objects,sfx,\
sfx2/source/appl/childwin \
sfx2/source/appl/childwinimpl \
sfx2/source/appl/fileobj \
+ sfx2/source/appl/flatpak \
sfx2/source/appl/fwkhelper \
sfx2/source/appl/helpdispatch \
sfx2/source/appl/helpinterceptor \
diff --git a/sfx2/source/appl/flatpak.cxx b/sfx2/source/appl/flatpak.cxx
new file mode 100644
index 000000000000..14411dafc5d0
--- /dev/null
+++ b/sfx2/source/appl/flatpak.cxx
@@ -0,0 +1,99 @@
+/* -*- 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: */
diff --git a/sfx2/source/appl/sfxhelp.cxx b/sfx2/source/appl/sfxhelp.cxx
index 03de650df70e..ce59b412d8ce 100644
--- a/sfx2/source/appl/sfxhelp.cxx
+++ b/sfx2/source/appl/sfxhelp.cxx
@@ -56,7 +56,6 @@
#include <osl/file.hxx>
#include <unotools/bootstrap.hxx>
#include <unotools/tempfile.hxx>
-#include <unotools/ucbhelper.hxx>
#include <rtl/uri.hxx>
#include <vcl/commandinfoprovider.hxx>
#include <vcl/layout.hxx>
@@ -73,6 +72,7 @@
#include "newhelp.hxx"
#include <sfx2/objsh.hxx>
#include <sfx2/docfac.hxx>
+#include <sfx2/flatpak.hxx>
#include <sfx2/sfxresid.hxx>
#include <helper.hxx>
#include <sfx2/strings.hrc>
@@ -734,11 +734,6 @@ static bool impl_showOnlineHelp( const OUString& rURL )
namespace {
-bool isFlatpak() {
- static auto const flatpak = [] { return std::getenv("LIBO_FLATPAK") != nullptr; }();
- return flatpak;
-}
-
bool rewriteFlatpakHelpRootUrl(OUString * helpRootUrl) {
assert(helpRootUrl != nullptr);
//TODO: This function for now assumes that the passed-in *helpRootUrl references
@@ -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\">"
@@ -968,7 +912,7 @@ static bool impl_showOfflineHelp( const OUString& rURL )
OUString aBaseInstallPath = getHelpRootURL();
// 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:
- if (isFlatpak() && !rewriteFlatpakHelpRootUrl(&aBaseInstallPath)) {
+ if (flatpak::isFlatpak() && !rewriteFlatpakHelpRootUrl(&aBaseInstallPath)) {
return false;
}
@@ -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):
OUString const aExtension(".html");
OUString * parent = nullptr;
- if (isFlatpak() && !createFlatpakHelpTemporaryDirectory(&parent)) {
+ if (flatpak::isFlatpak() && !flatpak::createTemporaryHtmlDirectory(&parent)) {
return false;
}
::utl::TempFile aTempFile("NewHelp", true, &aExtension, parent, false );
@@ -1375,16 +1319,4 @@ bool SfxHelp::IsHelpInstalled()
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: */
diff --git a/sfx2/source/view/viewsh.cxx b/sfx2/source/view/viewsh.cxx
index 04733ec20cfb..f7b3d2166b8b 100644
--- a/sfx2/source/view/viewsh.cxx
+++ b/sfx2/source/view/viewsh.cxx
@@ -61,6 +61,7 @@
#include <officecfg/Setup.hxx>
#include <sfx2/app.hxx>
+#include <sfx2/flatpak.hxx>
#include <sfx2/viewsh.hxx>
#include "viewimp.hxx"
#include <sfx2/sfxresid.hxx>
@@ -618,8 +619,15 @@ void SfxViewShell::ExecMisc_Impl( SfxRequest &rReq )
OSL_ASSERT( !aFilterName.isEmpty() );
OSL_ASSERT( !aFileName.isEmpty() );
- // Creates a temporary directory to store our predefined file into it.
- ::utl::TempFile aTempDir( nullptr, true );
+ // Creates a temporary directory to store our predefined file into it (for the
+ // 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() );
aFilePathObj.insertName( aFileName );