sw/inc/IDocumentFieldsAccess.hxx | 2 +- sw/inc/viewsh.hxx | 2 +- sw/qa/extras/tiledrendering/data/signed-doc.odt |binary sw/qa/extras/tiledrendering/tiledrendering.cxx | 20 ++++++++++++++++++++ sw/source/core/doc/DocumentFieldsManager.cxx | 9 ++++++--- sw/source/core/inc/DocumentFieldsManager.hxx | 2 +- sw/source/core/view/viewsh.cxx | 4 ++-- sw/source/uibase/uno/unotxdoc.cxx | 3 +-- 8 files changed, 32 insertions(+), 10 deletions(-)
New commits: commit bc71b10fc3656677385d6397ee75fc9527adf9d7 Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Tue Sep 17 08:42:01 2024 +0200 Commit: Caolán McNamara <caolan.mcnam...@collabora.com> CommitDate: Wed Sep 18 09:59:17 2024 +0200 cool#9992 lok doc sign: fix signature status after load Load a document, see the 'signaturestatus: 4' callback (SignatureState::NOTVALIDATED, "signature is OK, but certificate could not be validated"), wait till the view is initialized, notice the strange later arriving 'statechanged: .uno:Signature=3' callback, which hints that the document was modified, but we're right after load, so that should not happen. I already tried to prevent doc modified status in commit 654f972a97c374fa90eb3984a44c7f54ddba9c61 (sw lok: make sure author name change doesn't mark the doc as modified, 2023-01-16), but this is not enough for the doc sign case, where SfxObjectShell::SetModified() ends up refreshing the doc title, which calls SfxObjectShell::GetDocumentSignatureState() and then caches the wrong SignatureState::INVALID state. Fix the problem by adding a flag to not mark the document as modified during "init view" in the first place: that keeps the document unchanged after updating fields, but doesn't break the doc sign status. Now LOK clients get a first 'signaturestatus: 4' on load, and a 'statechanged: .uno:Signature=4' on initializing the view, which is a bit redundant, but at least is consistent. (cherry picked from commit a95b90bc0cf0f8a58fc20684acc23bb89b827cd1) Conflicts: sw/inc/viewsh.hxx sw/qa/extras/tiledrendering/data/signed-doc.odt sw/qa/extras/tiledrendering2/tiledrendering2.cxx Change-Id: I42d50525ba96900eeeb927a50f1484c882347b13 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/173584 Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com> Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Tested-by: Caolán McNamara <caolan.mcnam...@collabora.com> diff --git a/sw/inc/IDocumentFieldsAccess.hxx b/sw/inc/IDocumentFieldsAccess.hxx index 4ffe7779833f..1ef5f3d1400a 100644 --- a/sw/inc/IDocumentFieldsAccess.hxx +++ b/sw/inc/IDocumentFieldsAccess.hxx @@ -61,7 +61,7 @@ namespace com::sun::star::uno { class Any; } virtual void RemoveFieldType(size_t nField) = 0; - virtual void UpdateFields(bool bCloseDB) = 0; + virtual void UpdateFields(bool bCloseDB, bool bSetModified = true) = 0; virtual void InsDeletedFieldType(SwFieldType &) = 0; diff --git a/sw/inc/viewsh.hxx b/sw/inc/viewsh.hxx index ed3cbfee3b4d..50abcda03782 100644 --- a/sw/inc/viewsh.hxx +++ b/sw/inc/viewsh.hxx @@ -397,7 +397,7 @@ public: void CalcPagesForPrint( sal_uInt16 nMax ); // All about fields. - void UpdateFields(bool bCloseDB = false); + void UpdateFields(bool bCloseDB = false, bool bSetModified = true); bool IsAnyFieldInDoc() const; /// Update the previews of all OLE objects. diff --git a/sw/qa/extras/tiledrendering/data/signed-doc.odt b/sw/qa/extras/tiledrendering/data/signed-doc.odt new file mode 100644 index 000000000000..cd8d1d469cd3 Binary files /dev/null and b/sw/qa/extras/tiledrendering/data/signed-doc.odt differ diff --git a/sw/qa/extras/tiledrendering/tiledrendering.cxx b/sw/qa/extras/tiledrendering/tiledrendering.cxx index 33c0365d4489..a6e07bd7220d 100644 --- a/sw/qa/extras/tiledrendering/tiledrendering.cxx +++ b/sw/qa/extras/tiledrendering/tiledrendering.cxx @@ -4640,6 +4640,26 @@ CPPUNIT_TEST_FIXTURE(SwTiledRenderingTest, testAnyInput) Scheduler::ProcessEventsToIdle(); } +CPPUNIT_TEST_FIXTURE(SwTiledRenderingTest, testSignatureState) +{ + // Given a document with a signature where the digest matches: + SwXTextDocument* pXTextDocument = createDoc("signed-doc.odt"); + CPPUNIT_ASSERT(pXTextDocument); + + // When initializing tiled rendering with an author name: + uno::Sequence<beans::PropertyValue> aPropertyValues + = { comphelper::makePropertyValue(".uno:Author", uno::Any(u"A"_ustr)) }; + pXTextDocument->initializeForTiledRendering(aPropertyValues); + SignatureState eState = getSwDocShell()->GetDocumentSignatureState(); + + // Then make sure the signature state is unchanged: + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 4 (NOTVALIDATED) + // - Actual : 3 (INVALID) + // i.e. the doc was modified by the time the signature state was calculated. + CPPUNIT_ASSERT_EQUAL(SignatureState::NOTVALIDATED, eState); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/core/doc/DocumentFieldsManager.cxx b/sw/source/core/doc/DocumentFieldsManager.cxx index 66f65438c095..72f890fbc8f5 100644 --- a/sw/source/core/doc/DocumentFieldsManager.cxx +++ b/sw/source/core/doc/DocumentFieldsManager.cxx @@ -389,7 +389,7 @@ void DocumentFieldsManager::RemoveFieldType(size_t nField) } // All have to be re-evaluated. -void DocumentFieldsManager::UpdateFields(bool bCloseDB) +void DocumentFieldsManager::UpdateFields(bool bCloseDB, bool bSetModified) { // Tell all types to update their fields for(auto const& pFieldType: *mpFieldTypes) @@ -409,8 +409,11 @@ void DocumentFieldsManager::UpdateFields(bool bCloseDB) m_rDoc.GetDBManager()->CloseAll(); #endif } - // Only evaluate on full update - m_rDoc.getIDocumentState().SetModified(); + if (bSetModified) + { + // Only evaluate on full update + m_rDoc.getIDocumentState().SetModified(); + } } void DocumentFieldsManager::InsDeletedFieldType( SwFieldType& rFieldTyp ) diff --git a/sw/source/core/inc/DocumentFieldsManager.hxx b/sw/source/core/inc/DocumentFieldsManager.hxx index accf7a53e83c..559c528c82ad 100644 --- a/sw/source/core/inc/DocumentFieldsManager.hxx +++ b/sw/source/core/inc/DocumentFieldsManager.hxx @@ -40,7 +40,7 @@ public: virtual SwFieldType *GetSysFieldType( const SwFieldIds eWhich ) const override; virtual SwFieldType* GetFieldType(SwFieldIds nResId, const OUString& rName, bool bDbFieldMatching) const override; virtual void RemoveFieldType(size_t nField) override; - virtual void UpdateFields(bool bCloseDB) override; + virtual void UpdateFields(bool bCloseDB, bool bSetModified = true) override; virtual void InsDeletedFieldType(SwFieldType &) override; virtual void PutValueToField(const SwPosition & rPos, const css::uno::Any& rVal, sal_uInt16 nWhich) override; virtual bool UpdateField(SwTextField* rDstFormatField, SwField& rSrcField, bool bUpdateTableFields) override; diff --git a/sw/source/core/view/viewsh.cxx b/sw/source/core/view/viewsh.cxx index b485482987c7..95feb1a18708 100644 --- a/sw/source/core/view/viewsh.cxx +++ b/sw/source/core/view/viewsh.cxx @@ -719,7 +719,7 @@ bool SwViewShell::IsDummyPage( sal_uInt16 nPageNum ) const * type is sent (???). * @param[in] bCloseDB Passed in to GetDoc()->UpdateFields. [TODO] Purpose??? */ -void SwViewShell::UpdateFields(bool bCloseDB) +void SwViewShell::UpdateFields(bool bCloseDB, bool bSetModified) { CurrShell aCurr( this ); @@ -729,7 +729,7 @@ void SwViewShell::UpdateFields(bool bCloseDB) else StartAction(); - GetDoc()->getIDocumentFieldsAccess().UpdateFields(bCloseDB); + GetDoc()->getIDocumentFieldsAccess().UpdateFields(bCloseDB, bSetModified); if ( pCursorShell ) pCursorShell->EndAction(); diff --git a/sw/source/uibase/uno/unotxdoc.cxx b/sw/source/uibase/uno/unotxdoc.cxx index 4125910105a2..0571fc2947eb 100644 --- a/sw/source/uibase/uno/unotxdoc.cxx +++ b/sw/source/uibase/uno/unotxdoc.cxx @@ -3692,8 +3692,7 @@ void SwXTextDocument::initializeForTiledRendering(const css::uno::Sequence<css:: { if (SwEditShell* pShell = &pFirstView->GetWrtShell()) { - pShell->SwViewShell::UpdateFields(true); - pShell->ResetModified(); + pShell->SwViewShell::UpdateFields(true, /*bSetModified=*/false); } } }