summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.co.uk>2016-03-09 10:58:25 +0100
committerMiklos Vajna <vmiklos@collabora.co.uk>2016-03-09 14:18:28 +0100
commit76e2cede5a415df8d3e7a874f56be7a0b5953e12 (patch)
treee7eafef3b01fad3fd36f1dc97484d9f414102941
parent644ace4143fe2576bfd71c8ab3da9d666d6523bb (diff)
Move copy/paste classification check from sw to sfx2
So that it's easy to unit test it and other apps can use it as well in the future. Change-Id: I38d601924b7fbb17615ff6e9c031a71b40777c4c
-rw-r--r--include/sfx2/classificationhelper.hxx10
-rw-r--r--sfx2/source/view/classificationhelper.cxx29
-rw-r--r--sw/source/uibase/dochdl/swdtflvr.cxx29
3 files changed, 50 insertions, 18 deletions
diff --git a/include/sfx2/classificationhelper.hxx b/include/sfx2/classificationhelper.hxx
index 5c49db700e13..5a58fccd6afa 100644
--- a/include/sfx2/classificationhelper.hxx
+++ b/include/sfx2/classificationhelper.hxx
@@ -23,6 +23,14 @@ namespace basegfx
class BColor;
}
+/// Return code of SfxClassificationHelper::CheckPaste().
+enum class SfxClassificationCheckPasteResult
+{
+ None = 1,
+ TargetDocNotClassified = 2,
+ DocClassificationTooLow = 3
+};
+
/// Shared code to handle Business Authorization Identification and Labeling Scheme (BAILS) properties.
class SFX2_DLLPUBLIC SfxClassificationHelper
{
@@ -32,6 +40,8 @@ class SFX2_DLLPUBLIC SfxClassificationHelper
public:
/// Does the document have any BAILS properties?
static bool IsClassified(SfxObjectShell& rObjectShell);
+ /// Checks if pasting from rSource to rDestination would leak information.
+ static SfxClassificationCheckPasteResult CheckPaste(SfxObjectShell& rSource, SfxObjectShell& rDestination);
SfxClassificationHelper(SfxObjectShell& rObjectShell);
~SfxClassificationHelper();
diff --git a/sfx2/source/view/classificationhelper.cxx b/sfx2/source/view/classificationhelper.cxx
index ab913b537d3f..6950048fae82 100644
--- a/sfx2/source/view/classificationhelper.cxx
+++ b/sfx2/source/view/classificationhelper.cxx
@@ -426,6 +426,35 @@ bool SfxClassificationHelper::IsClassified(SfxObjectShell& rObjectShell)
return false;
}
+SfxClassificationCheckPasteResult SfxClassificationHelper::CheckPaste(SfxObjectShell& rSource, SfxObjectShell& rDestination)
+{
+ bool bSourceClassified = SfxClassificationHelper::IsClassified(rSource);
+ if (!bSourceClassified)
+ // No classification on the source side. Return early, regardless the
+ // state of the destination side.
+ return SfxClassificationCheckPasteResult::None;
+
+ bool bDestinationClassified = SfxClassificationHelper::IsClassified(rDestination);
+ if (bSourceClassified && !bDestinationClassified)
+ {
+ // Paste from a classified document to a non-classified one -> deny.
+ return SfxClassificationCheckPasteResult::TargetDocNotClassified;
+ }
+
+ // Remaining case: paste between two classified documents.
+ SfxClassificationHelper aSource(rSource);
+ SfxClassificationHelper aDestination(rDestination);
+ if (aSource.GetImpactScale() != aDestination.GetImpactScale())
+ // It's possible to compare them if they have the same scale.
+ return SfxClassificationCheckPasteResult::None;
+
+ if (aSource.GetImpactLevel() > aDestination.GetImpactLevel())
+ // Paste from a doc that has higher classification -> deny.
+ return SfxClassificationCheckPasteResult::DocClassificationTooLow;
+
+ return SfxClassificationCheckPasteResult::None;
+}
+
SfxClassificationHelper::SfxClassificationHelper(SfxObjectShell& rObjectShell)
: m_pImpl(o3tl::make_unique<Impl>(rObjectShell))
{
diff --git a/sw/source/uibase/dochdl/swdtflvr.cxx b/sw/source/uibase/dochdl/swdtflvr.cxx
index 04c3ae1e25b8..fb46de918bfe 100644
--- a/sw/source/uibase/dochdl/swdtflvr.cxx
+++ b/sw/source/uibase/dochdl/swdtflvr.cxx
@@ -3222,33 +3222,26 @@ bool lcl_checkClassification(SwDoc* pSourceDoc, SwDoc* pDestinationDoc)
if (!pSourceShell || !pDestinationShell)
return true;
- bool bSourceClassified = SfxClassificationHelper::IsClassified(*pSourceShell);
- if (!bSourceClassified)
- // No classification on the source side. Return early, regardless the
- // state of the destination side.
+ switch (SfxClassificationHelper::CheckPaste(*pSourceShell, *pDestinationShell))
+ {
+ case SfxClassificationCheckPasteResult::None:
+ {
return true;
-
- bool bDestinationClassified = SfxClassificationHelper::IsClassified(*pDestinationShell);
- if (bSourceClassified && !bDestinationClassified)
+ }
+ break;
+ case SfxClassificationCheckPasteResult::TargetDocNotClassified:
{
- // Paste from a classified document to a non-classified one -> deny.
ScopedVclPtrInstance<MessageDialog>::Create(nullptr, SW_RES(STR_TARGET_DOC_NOT_CLASSIFIED), VCL_MESSAGE_INFO)->Execute();
return false;
}
-
- // Remaining case: paste between two classified documents.
- SfxClassificationHelper aSource(*pSourceShell);
- SfxClassificationHelper aDestination(*pDestinationShell);
- if (aSource.GetImpactScale() != aDestination.GetImpactScale())
- // It's possible to compare them if they have the same scale.
- return true;
-
- if (aSource.GetImpactLevel() > aDestination.GetImpactLevel())
+ break;
+ case SfxClassificationCheckPasteResult::DocClassificationTooLow:
{
- // Paste from a doc that has higher classification -> deny.
ScopedVclPtrInstance<MessageDialog>::Create(nullptr, SW_RES(STR_DOC_CLASSIFICATION_TOO_LOW), VCL_MESSAGE_INFO)->Execute();
return false;
}
+ break;
+ }
return true;
}