summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2024-02-17 00:19:41 +0900
committerTomaž Vajngerl <quikee@gmail.com>2024-02-17 12:07:28 +0100
commit923b1ad7b7bc249838aa619361974f0e3134ab6a (patch)
treecae5f8c374fefb9712b94c805dee3675ee054831
parent347890c05e689cecc9361b4c2ebd25cb3b87f8e7 (diff)
sc: Show warning for a XLS document with unknown encrypted part
If a document contains a "DRMContent" section that we don't know how to decrypt, show a warning before showing the un-encrypted content. Change-Id: Id7f48b68e1d65ce46434906b2fb3c7912dcc5f49 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/163513 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
-rw-r--r--sc/inc/scerrors.hrc2
-rw-r--r--sc/inc/scerrors.hxx1
-rw-r--r--sc/inc/strings.hrc3
-rw-r--r--sc/source/filter/excel/excel.cxx9
-rw-r--r--sc/source/ui/docshell/docsh.cxx26
-rw-r--r--sc/source/ui/docshell/docshimp.hxx3
6 files changed, 40 insertions, 4 deletions
diff --git a/sc/inc/scerrors.hrc b/sc/inc/scerrors.hrc
index 88b099f69107..b3fc7bd01ec1 100644
--- a/sc/inc/scerrors.hrc
+++ b/sc/inc/scerrors.hrc
@@ -101,7 +101,7 @@ const ErrMsgCode RID_ERRHDLSC[] =
SCWARN_EXPORT_NONCONVERTIBLE_CHARS },
{ NC_("RID_ERRHDLSC", "Format error discovered in the file in sub-document $(ARG1) at $(ARG2)(row,col)."),
SCWARN_IMPORT_FILE_ROWCOL },
- { NC_("RID_ERRHDLSC", "Not all attributes could be read.") ,
+ { NC_("RID_ERRHDLSC", "Not all attributes could be read."),
SCWARN_IMPORT_FEATURES_LOST },
{ {}, ERRCODE_NONE }
};
diff --git a/sc/inc/scerrors.hxx b/sc/inc/scerrors.hxx
index dcb734502eae..c425e2fe8862 100644
--- a/sc/inc/scerrors.hxx
+++ b/sc/inc/scerrors.hxx
@@ -47,6 +47,7 @@
#define SCERR_IMPORT_FILE_ROWCOL ErrCode( ErrCodeArea::Sc, ErrCodeClass::Read, 16 )
#define SCERR_IMPORT_FORMAT_ROWCOL ErrCode( ErrCodeArea::Sc, ErrCodeClass::Read, 17 )
#define SCWARN_IMPORT_FILE_ROWCOL ErrCode( WarningFlag::Yes, ErrCodeArea::Sc, ErrCodeClass::Read, 18 )
+#define SCWARN_IMPORT_UNKNOWN_ENCRYPTION ErrCode(WarningFlag::Yes, ErrCodeArea::Sc, ErrCodeClass::Read, 19)
// ErrCodeClass::Write - file related, displays "Write-Error" in MsgBox
#define SCERR_EXPORT_CONNECT ErrCode( ErrCodeArea::Sc, ErrCodeClass::Write, 1 )
diff --git a/sc/inc/strings.hrc b/sc/inc/strings.hrc
index 266cb4cc6c5b..070f117a001e 100644
--- a/sc/inc/strings.hrc
+++ b/sc/inc/strings.hrc
@@ -412,4 +412,7 @@
#define STR_CONDITION_CONTAINS_TEXT NC_("STR_CONDITION_CONTAINS_TEXT", "containing text")
#define STR_CONDITION_NOT_CONTAINS_TEXT NC_("STR_CONDITION_NOT_CONTAINS_TEXT", "not containing text")
+#define STR_CONTENT_WITH_UNKNOWN_ENCRYPTION NC_("STR_CONTENT_WITH_UNKNOWN_ENCRYPTION", "Document contains DRM content that is encrypted with an unknown encryption method. Only the un-encrypted content will be shown.")
+
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/filter/excel/excel.cxx b/sc/source/filter/excel/excel.cxx
index 3542208eb174..862e85d08545 100644
--- a/sc/source/filter/excel/excel.cxx
+++ b/sc/source/filter/excel/excel.cxx
@@ -165,6 +165,8 @@ ErrCode ScFormatFilterPluginImpl::ScImportExcel( SfxMedium& rMedium, ScDocument*
SvStream* pBookStrm = nullptr; // The "Book"/"Workbook" stream containing main data.
XclBiff eBiff = EXC_BIFF_UNKNOWN; // The BIFF version of the main stream.
+ bool bUnableToDecryptContent = false;
+
// try to open an OLE storage
tools::SvRef<SotStorage> xRootStrg;
tools::SvRef<SotStorageStream> xStrgStrm;
@@ -186,6 +188,10 @@ ErrCode ScFormatFilterPluginImpl::ScImportExcel( SfxMedium& rMedium, ScDocument*
auto pDecryptedStorage = lcl_DRMDecrypt(rMedium, xRootStrg, aNewStorageStrm);
if (pDecryptedStorage)
xRootStrg = pDecryptedStorage;
+ else
+ {
+ bUnableToDecryptContent = true;
+ }
}
// try to open the "Book" stream
@@ -250,6 +256,9 @@ ErrCode ScFormatFilterPluginImpl::ScImportExcel( SfxMedium& rMedium, ScDocument*
eRet = xFilter ? xFilter->Read() : SCERR_IMPORT_INTERNAL;
}
+ if (bUnableToDecryptContent && eRet == ERRCODE_NONE)
+ eRet = SCWARN_IMPORT_UNKNOWN_ENCRYPTION;
+
return eRet;
}
diff --git a/sc/source/ui/docshell/docsh.cxx b/sc/source/ui/docshell/docsh.cxx
index 1cfd3778d6be..5f0cf927cd1d 100644
--- a/sc/source/ui/docshell/docsh.cxx
+++ b/sc/source/ui/docshell/docsh.cxx
@@ -48,6 +48,7 @@
#include <sfx2/lokhelper.hxx>
#include <sfx2/objface.hxx>
#include <sfx2/viewfrm.hxx>
+#include <sfx2/infobar.hxx>
#include <svl/documentlockfile.hxx>
#include <svl/fstathelper.hxx>
#include <svl/sharecontrolfile.hxx>
@@ -775,6 +776,11 @@ void ScDocShell::Notify( SfxBroadcaster&, const SfxHint& rHint )
}
}
#endif
+
+ ScViewData* pViewData = GetViewData();
+ SfxViewShell* pViewShell = pViewData ? pViewData->GetViewShell() : nullptr;
+ SfxViewFrame* pViewFrame = pViewShell ? &pViewShell->GetViewFrame() : nullptr;
+
try
{
uno::Reference< uno::XComponentContext > xContext(
@@ -795,9 +801,6 @@ void ScDocShell::Notify( SfxBroadcaster&, const SfxHint& rHint )
if ( xFactory.is() )
{
uno::Reference< task::XJob > xJob( xFactory->createInstanceWithContext( xContext ), uno::UNO_QUERY_THROW );
- ScViewData* pViewData = GetViewData();
- SfxViewShell* pViewShell = ( pViewData ? pViewData->GetViewShell() : nullptr );
- SfxViewFrame* pViewFrame = ( pViewShell ? &pViewShell->GetViewFrame() : nullptr );
SfxFrame* pFrame = ( pViewFrame ? &pViewFrame->GetFrame() : nullptr );
uno::Reference< frame::XController > xController = ( pFrame ? pFrame->GetController() : nullptr );
uno::Reference< sheet::XSpreadsheetView > xSpreadsheetView( xController, uno::UNO_QUERY_THROW );
@@ -810,6 +813,16 @@ void ScDocShell::Notify( SfxBroadcaster&, const SfxHint& rHint )
catch ( uno::Exception & )
{
}
+
+ // Show delayed infobar entries
+ if (pViewFrame)
+ {
+ for (auto const& r : m_pImpl->mpDelayedInfobarEntry)
+ {
+ pViewFrame->AppendInfoBar(r.msId, r.msPrimaryMessage, r.msSecondaryMessage, r.maInfobarType, r.mbShowCloseButton);
+ }
+ m_pImpl->mpDelayedInfobarEntry.clear();
+ }
}
break;
case SfxEventHintId::SaveDoc:
@@ -1259,6 +1272,13 @@ bool ScDocShell::ConvertFrom( SfxMedium& rMedium )
// all graphics objects must have names
m_pDocument->EnsureGraphicNames();
+ if (eError == SCWARN_IMPORT_UNKNOWN_ENCRYPTION)
+ {
+
+ m_pImpl->mpDelayedInfobarEntry.push_back({ "UnknownEncryption", ScResId(STR_CONTENT_WITH_UNKNOWN_ENCRYPTION), "", InfobarType::INFO, true });
+ eError = ERRCODE_NONE;
+ }
+
if (eError != ERRCODE_NONE)
{
if (!GetErrorIgnoreWarning())
diff --git a/sc/source/ui/docshell/docshimp.hxx b/sc/source/ui/docshell/docshimp.hxx
index 58cfb23ac70f..b6942d549db8 100644
--- a/sc/source/ui/docshell/docshimp.hxx
+++ b/sc/source/ui/docshell/docshimp.hxx
@@ -21,6 +21,7 @@
#include <svtools/ctrltool.hxx>
#include <sfx2/docinsert.hxx>
#include <sfx2/request.hxx>
+#include <sfx2/infobar.hxx>
struct DocShell_Impl
{
@@ -29,6 +30,8 @@ struct DocShell_Impl
std::unique_ptr<sfx2::DocumentInserter> pDocInserter;
std::unique_ptr<SfxRequest> pRequest;
+ std::vector<InfobarData> mpDelayedInfobarEntry;
+
DocShell_Impl() :
bIgnoreLostRedliningWarning( false )
{}