diff options
author | dan sinclair <dsinclair@chromium.org> | 2018-04-13 16:43:05 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-04-13 16:43:05 +0000 |
commit | e04b66cc759c2cf0ceafae47340fdf9588ca2e23 (patch) | |
tree | 5b7e8da1e61d1b6dc9550fb599722681e65572fc /core/fpdfdoc/cpdf_metadata.cpp | |
parent | 996c93068bfc8b443c77b735bc6400285bc8a407 (diff) | |
download | pdfium-e04b66cc759c2cf0ceafae47340fdf9588ca2e23.tar.xz |
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 <hnakashima@chromium.org>
Commit-Queue: dsinclair <dsinclair@chromium.org>
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; } |