From e04b66cc759c2cf0ceafae47340fdf9588ca2e23 Mon Sep 17 00:00:00 2001 From: dan sinclair Date: Fri, 13 Apr 2018 16:43:05 +0000 Subject: Move SharedForm check to CPDF_Metadata class This CL moves code related to shared form detection into the CPDF_Metadata class. This allows us to hide the usage of CXML inside CPDF_Metadata. Change-Id: I547471a2bcc119221565c415a58211c1500cbb3c Reviewed-on: https://pdfium-review.googlesource.com/30370 Reviewed-by: Henrique Nakashima Commit-Queue: dsinclair --- core/fpdfdoc/cpdf_metadata.cpp | 77 ++++++++++++++++++++++++++++++++++-------- core/fpdfdoc/cpdf_metadata.h | 33 ++++++++++++++---- 2 files changed, 90 insertions(+), 20 deletions(-) (limited to 'core') diff --git a/core/fpdfdoc/cpdf_metadata.cpp b/core/fpdfdoc/cpdf_metadata.cpp index efe3c29dbf..11fde82036 100644 --- a/core/fpdfdoc/cpdf_metadata.cpp +++ b/core/fpdfdoc/cpdf_metadata.cpp @@ -6,27 +6,76 @@ #include "core/fpdfdoc/cpdf_metadata.h" -#include "core/fpdfapi/parser/cpdf_document.h" #include "core/fpdfapi/parser/cpdf_stream.h" #include "core/fpdfapi/parser/cpdf_stream_acc.h" +#include "core/fxcrt/xml/cxml_content.h" #include "core/fxcrt/xml/cxml_element.h" -CPDF_Metadata::CPDF_Metadata(const CPDF_Document* pDoc) { - const CPDF_Dictionary* pRoot = pDoc->GetRoot(); - if (!pRoot) - return; +namespace { - CPDF_Stream* pStream = pRoot->GetStreamFor("Metadata"); - if (!pStream) - return; +void CheckForSharedFormInternal(CXML_Element* element, + std::vector* unsupported) { + size_t count = element->CountAttrs(); + for (size_t i = 0; i < count; ++i) { + ByteString space; + ByteString name; + WideString value; + element->GetAttrByIndex(i, &space, &name, &value); + if (space != "xmlns" || name != "adhocwf" || + value != L"http://ns.adobe.com/AcrobatAdhocWorkflow/1.0/") { + continue; + } - auto pAcc = pdfium::MakeRetain(pStream); - pAcc->LoadAllDataFiltered(); - m_pXmlElement = CXML_Element::Parse(pAcc->GetData(), pAcc->GetSize()); + CXML_Element* pVersion = element->GetElement("adhocwf", "workflowType", 0); + if (!pVersion) + continue; + + CXML_Content* pContent = ToContent(pVersion->GetChild(0)); + if (!pContent) + continue; + + switch (pContent->m_Content.GetInteger()) { + case 0: + unsupported->push_back(UnsupportedFeature::kDocumentSharedFormEmail); + break; + case 1: + unsupported->push_back(UnsupportedFeature::kDocumentSharedFormAcrobat); + break; + case 2: + unsupported->push_back( + UnsupportedFeature::kDocumentSharedFormFilesystem); + break; + } + } + + count = element->CountChildren(); + for (size_t i = 0; i < count; ++i) { + CXML_Element* child = ToElement(element->GetChild(i)); + if (!child) + continue; + + CheckForSharedFormInternal(child, unsupported); + } } -CPDF_Metadata::~CPDF_Metadata() {} +} // namespace + +CPDF_Metadata::CPDF_Metadata(const CPDF_Stream* pStream) : stream_(pStream) { + ASSERT(pStream); +} + +CPDF_Metadata::~CPDF_Metadata() = default; + +std::vector CPDF_Metadata::CheckForSharedForm() const { + auto pAcc = pdfium::MakeRetain(stream_.Get()); + pAcc->LoadAllDataFiltered(); + + std::unique_ptr xml_root = + CXML_Element::Parse(pAcc->GetData(), pAcc->GetSize()); + if (!xml_root) + return {}; -const CXML_Element* CPDF_Metadata::GetRoot() const { - return m_pXmlElement.get(); + std::vector unsupported; + CheckForSharedFormInternal(xml_root.get(), &unsupported); + return unsupported; } diff --git a/core/fpdfdoc/cpdf_metadata.h b/core/fpdfdoc/cpdf_metadata.h index fa958153fc..edf1938c4e 100644 --- a/core/fpdfdoc/cpdf_metadata.h +++ b/core/fpdfdoc/cpdf_metadata.h @@ -8,19 +8,40 @@ #define CORE_FPDFDOC_CPDF_METADATA_H_ #include - -class CPDF_Document; -class CXML_Element; +#include + +#include "core/fxcrt/unowned_ptr.h" + +class CPDF_Stream; + +enum class UnsupportedFeature : uint8_t { + kDocumentXFAForm = 1, + kDocumentPortableCollection = 2, + kDocumentAttachment = 3, + kDocumentSecurity = 4, + kDocumentSharedReview = 5, + kDocumentSharedFormAcrobat = 6, + kDocumentSharedFormFilesystem = 7, + kDocumentSharedFormEmail = 8, + + kAnnotation3d = 11, + kAnnotationMovie = 12, + kAnnotationSound = 13, + kAnnotationScreenMedia = 14, + kAnnotationScreenRichMedia = 15, + kAnnotationAttachment = 16, + kAnnotationSignature = 17 +}; class CPDF_Metadata { public: - explicit CPDF_Metadata(const CPDF_Document* pDoc); + explicit CPDF_Metadata(const CPDF_Stream* pStream); ~CPDF_Metadata(); - const CXML_Element* GetRoot() const; + std::vector CheckForSharedForm() const; private: - std::unique_ptr m_pXmlElement; + UnownedPtr stream_; }; #endif // CORE_FPDFDOC_CPDF_METADATA_H_ -- cgit v1.2.3