diff options
Diffstat (limited to 'core/fpdfdoc/cpdf_metadata.cpp')
-rw-r--r-- | core/fpdfdoc/cpdf_metadata.cpp | 77 |
1 files changed, 63 insertions, 14 deletions
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<UnsupportedFeature>* 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<CPDF_StreamAcc>(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<UnsupportedFeature> CPDF_Metadata::CheckForSharedForm() const { + auto pAcc = pdfium::MakeRetain<CPDF_StreamAcc>(stream_.Get()); + pAcc->LoadAllDataFiltered(); + + std::unique_ptr<CXML_Element> 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<UnsupportedFeature> unsupported; + CheckForSharedFormInternal(xml_root.get(), &unsupported); + return unsupported; } |