Related: tdf#104718 Use package repair request and behavior

Same as in other places handling that:
* SfxBaseModel::load (sfx2/source/doc/sfxbasemodel.cxx);
* StorageFilterDetect::detect (filter/source/storagefilterdetect/filterdetect.cxx);
* TypeDetection::impl_detectTypeFlatAndDeep (filter/source/config/cache/typedetection.cxx)

In these cases, the same handler is used (RequestPackageReparation);
when the user approves an attempt to repair the package, the media
descriptor gets "RepairPackage" property set to true (this produces
a "(repaired document)" appended to the document title); also, the
document is opened in template mode (so saving it doesn't simply
overwrite the original broken document, but asks for a new name).

Re-using this logic, and checking if the "RepairPackage" is already
set, allows to unify the behavior, and to avoid duplicate warnings
when the user already approved repair of a broken package.

The request won't contain the details of the XML problem; but it
will be shown if rejected anyway, so OK for the diagnostics.

Change-Id: Ic997f89272212227479d14236f5e7788298a904a
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/160001
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
This commit is contained in:
Mike Kaganski
2023-11-29 06:23:33 +01:00
parent 01a02ee7f1
commit 92e7f28f9a
4 changed files with 47 additions and 18 deletions
+1 -1
View File
@@ -475,7 +475,7 @@ public:
void AvoidRecentDocs(bool bAvoid) { mbAvoidRecentDocs = bAvoid; }
/// On first error ask user if import should continue; return saved answer.
bool IsContinueImportOnFilterExceptions(std::u16string_view aErrMessage);
bool IsContinueImportOnFilterExceptions();
// Transfer IFace
bool IsAbortingImport() const;
-3
View File
@@ -70,9 +70,6 @@
#define STR_QMSG_SEL_FOLDER_DELETE NC_("STR_QMSG_SEL_FOLDER_DELETE", "Do you want to delete the selected category?")
#define STR_QMSG_TEMPLATE_OVERWRITE NC_("STR_QMSG_TEMPLATE_OVERWRITE", "A template named $1 already exists in $2. Do you want to overwrite it?")
#define STR_QMSG_SEL_TEMPLATE_DELETE NC_("STR_QMSG_SEL_TEMPLATE_DELETE", "Do you want to delete the selected templates?")
#define STR_QMSG_ERROR_OPENING_FILE NC_("STR_QMSG_ERROR_OPENING_FILE", "An error occurred during opening the file. This may be caused by incorrect file contents.\n")
#define STR_QMSG_ERROR_OPENING_FILE_DETAILS NC_("STR_QMSG_ERROR_OPENING_FILE_DETAILS", "The error details are:\n")
#define STR_QMSG_ERROR_OPENING_FILE_CONTINUE NC_("STR_QMSG_ERROR_OPENING_FILE_CONTINUE", "\nProceeding with import may cause data loss or corruption, and application may become unstable or crash.\n\nDo you want to ignore the error and attempt to continue loading the file?")
#define STR_HELP_WINDOW_TITLE NC_("STR_HELP_WINDOW_TITLE", "%PRODUCTNAME Help")
#define STR_HELP_BUTTON_INDEX_ON NC_("STR_HELP_BUTTON_INDEX_ON", "Show Navigation Pane")
+44 -10
View File
@@ -50,6 +50,7 @@
#include <com/sun/star/uno/Any.h>
#include <com/sun/star/task/ErrorCodeRequest2.hpp>
#include <comphelper/lok.hxx>
#include <comphelper/processfactory.hxx>
#include <comphelper/string.hxx>
@@ -66,6 +67,7 @@
#include <basic/sbx.hxx>
#include <svtools/sfxecode.hxx>
#include <unotools/mediadescriptor.hxx>
#include <unotools/ucbhelper.hxx>
#include <tools/urlobj.hxx>
#include <svl/sharecontrolfile.hxx>
@@ -80,6 +82,7 @@
#include <ucbhelper/simpleinteractionrequest.hxx>
#include <officecfg/Office/Common.hxx>
#include <sfx2/brokenpackageint.hxx>
#include <sfx2/signaturestate.hxx>
#include <sfx2/app.hxx>
#include <appdata.hxx>
@@ -1937,20 +1940,51 @@ bool SfxObjectShell_Impl::hasTrustedScriptingSignature(
return bResult;
}
bool SfxObjectShell::IsContinueImportOnFilterExceptions(std::u16string_view aErrMessage)
bool SfxObjectShell::IsContinueImportOnFilterExceptions()
{
if (mbContinueImportOnFilterExceptions == undefined)
{
if (Application::GetDialogCancelMode() == DialogCancelMode::Off)
if (!pMedium)
{
// Ask the user to try to continue or abort loading
OUString aMessage = SfxResId(STR_QMSG_ERROR_OPENING_FILE);
if (!aErrMessage.empty())
aMessage += SfxResId(STR_QMSG_ERROR_OPENING_FILE_DETAILS) + aErrMessage;
aMessage += SfxResId(STR_QMSG_ERROR_OPENING_FILE_CONTINUE);
std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(nullptr,
VclMessageType::Question, VclButtonsType::YesNo, aMessage));
mbContinueImportOnFilterExceptions = (xBox->run() == RET_YES) ? yes : no;
mbContinueImportOnFilterExceptions = no;
return false;
}
if (utl::MediaDescriptor desc(pMedium->GetArgs());
!desc.getUnpackedValueOrDefault("RepairAllowed", true))
{
mbContinueImportOnFilterExceptions = no;
return false;
}
if (const SfxBoolItem* pRepairItem
= pMedium->GetItemSet().GetItem(SID_REPAIRPACKAGE, false);
pRepairItem && pRepairItem->GetValue())
{
mbContinueImportOnFilterExceptions = yes;
return true;
}
auto xInteractionHandler = pMedium->GetInteractionHandler();
if (!xInteractionHandler)
{
mbContinueImportOnFilterExceptions = no;
return false;
}
const OUString aDocName(pMedium->GetURLObject().getName(
INetURLObject::LAST_SEGMENT, true, INetURLObject::DecodeMechanism::WithCharset));
RequestPackageReparation aRequest(aDocName);
xInteractionHandler->handle(aRequest.GetRequest());
if (aRequest.isApproved())
{
mbContinueImportOnFilterExceptions = yes;
// lok: we want to overwrite file in jail, so don't use template flag
bool bIsLOK = comphelper::LibreOfficeKit::isActive();
// allow repair
pMedium->GetItemSet().Put(SfxBoolItem(SID_REPAIRPACKAGE, true));
pMedium->GetItemSet().Put(SfxBoolItem(SID_TEMPLATE, !bIsLOK));
pMedium->GetItemSet().Put(SfxStringItem(SID_DOCINFO_TITLE, aDocName));
}
else
mbContinueImportOnFilterExceptions = no;
@@ -514,15 +514,13 @@ void OOXMLDocumentImpl::resolve(Stream & rStream)
{
xParser->parseStream(aParserInput);
}
catch (xml::sax::SAXException const& rErr)
catch (xml::sax::SAXException const&)
{
// don't silently swallow these - handlers may not have been executed,
// and the domain mapper is likely in an inconsistent state
// In case user chooses to try to continue loading, don't ask again for this file
SfxObjectShell* rShell = SfxObjectShell::GetShellFromComponent(mxModel);
if (!rShell
|| !rShell->IsContinueImportOnFilterExceptions(
Concat2View("SAXException: " + rErr.Message)))
if (!rShell || !rShell->IsContinueImportOnFilterExceptions())
throw;
}
catch (uno::RuntimeException const&)