diff options
author | dan sinclair <dsinclair@chromium.org> | 2018-04-16 16:54:27 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-04-16 16:54:27 +0000 |
commit | 19ae9bf554fc1c01e352a846646c8005a4fe6b2b (patch) | |
tree | f17f74da5b0a95e93d6275d422f441f07169062a /core/fpdfdoc/cpdf_metadata.cpp | |
parent | d5624a47bcaad45f6fcb30ad03b6e474f5cee17e (diff) | |
download | pdfium-19ae9bf554fc1c01e352a846646c8005a4fe6b2b.tar.xz |
Use CFX_XML instead of CXML in CPDF_Metadata
This CL converts CPDF_Metadata to use the CFX_XML classes instead of
CXML classes. This also moves the CFX_XML classes from being XFA only to
being used everywhere.
Change-Id: Idb784f8aaa0bc843d8a3415ba5262ccf4949308a
Reviewed-on: https://pdfium-review.googlesource.com/30650
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 | 83 |
1 files changed, 44 insertions, 39 deletions
diff --git a/core/fpdfdoc/cpdf_metadata.cpp b/core/fpdfdoc/cpdf_metadata.cpp index 11fde82036..972569a25d 100644 --- a/core/fpdfdoc/cpdf_metadata.cpp +++ b/core/fpdfdoc/cpdf_metadata.cpp @@ -8,53 +8,54 @@ #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" +#include "core/fxcrt/fx_codepage.h" +#include "core/fxcrt/xml/cfx_xmlelement.h" +#include "core/fxcrt/xml/cfx_xmlparser.h" namespace { -void CheckForSharedFormInternal(CXML_Element* element, +void CheckForSharedFormInternal(CFX_XMLElement* 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/") { + for (const auto& pair : element->GetAttributes()) { + if (pair.first != L"xmlns:adhocwf" || + pair.second != L"http://ns.adobe.com/AcrobatAdhocWorkflow/1.0/") { continue; } - 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; + for (const auto* child = element->GetFirstChild(); child; + child = child->GetNextSibling()) { + if (child->GetType() != FX_XMLNODE_Element) + continue; + + const auto* child_elem = static_cast<const CFX_XMLElement*>(child); + if (child_elem->GetName() != L"adhocwf:workflowType") + continue; + + switch (child_elem->GetTextData().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; + } + // We only care about the first one we find. + break; } } - count = element->CountChildren(); - for (size_t i = 0; i < count; ++i) { - CXML_Element* child = ToElement(element->GetChild(i)); - if (!child) + for (auto* child = element->GetFirstChild(); child; + child = child->GetNextSibling()) { + if (child->GetType() != FX_XMLNODE_Element) continue; - CheckForSharedFormInternal(child, unsupported); + CheckForSharedFormInternal(static_cast<CFX_XMLElement*>(child), + unsupported); } } @@ -70,12 +71,16 @@ 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) + auto root = pdfium::MakeUnique<CFX_XMLElement>(L"root"); + auto proxy = pdfium::MakeRetain<CFX_SeekableStreamProxy>(pAcc->GetData(), + pAcc->GetSize()); + proxy->SetCodePage(FX_CODEPAGE_UTF8); + + CFX_XMLParser parser(root.get(), proxy); + if (!parser.Parse()) return {}; std::vector<UnsupportedFeature> unsupported; - CheckForSharedFormInternal(xml_root.get(), &unsupported); + CheckForSharedFormInternal(root.get(), &unsupported); return unsupported; } |