blob: 323de4ffcf1fa49c390a61d6986e6d94a38eb132 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
// Copyright 2016 PDFium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
#include "core/fpdfdoc/cpdf_metadata.h"
#include "core/fpdfapi/parser/cpdf_stream.h"
#include "core/fpdfapi/parser/cpdf_stream_acc.h"
#include "core/fxcrt/cfx_memorystream.h"
#include "core/fxcrt/fx_codepage.h"
#include "core/fxcrt/xml/cfx_xmldocument.h"
#include "core/fxcrt/xml/cfx_xmlelement.h"
#include "core/fxcrt/xml/cfx_xmlparser.h"
namespace {
void CheckForSharedFormInternal(CFX_XMLElement* element,
std::vector<UnsupportedFeature>* unsupported) {
WideString attr = element->GetAttribute(L"xmlns:adhocwf");
if (attr == L"http://ns.adobe.com/AcrobatAdhocWorkflow/1.0/") {
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;
}
}
for (auto* child = element->GetFirstChild(); child;
child = child->GetNextSibling()) {
if (child->GetType() != FX_XMLNODE_Element)
continue;
CheckForSharedFormInternal(static_cast<CFX_XMLElement*>(child),
unsupported);
}
}
} // 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();
auto stream = pdfium::MakeRetain<CFX_MemoryStream>(pAcc->GetData(),
pAcc->GetSize(), false);
CFX_XMLParser parser(stream);
std::unique_ptr<CFX_XMLDocument> doc = parser.Parse();
if (!doc)
return {};
std::vector<UnsupportedFeature> unsupported;
CheckForSharedFormInternal(doc->GetRoot(), &unsupported);
return unsupported;
}
|