summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordan sinclair <dsinclair@chromium.org>2018-04-13 16:43:05 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-04-13 16:43:05 +0000
commite04b66cc759c2cf0ceafae47340fdf9588ca2e23 (patch)
tree5b7e8da1e61d1b6dc9550fb599722681e65572fc
parent996c93068bfc8b443c77b735bc6400285bc8a407 (diff)
downloadpdfium-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>
-rw-r--r--core/fpdfdoc/cpdf_metadata.cpp77
-rw-r--r--core/fpdfdoc/cpdf_metadata.h33
-rw-r--r--fpdfsdk/cpdfsdk_helpers.cpp54
-rw-r--r--fpdfsdk/fpdf_ext.cpp51
-rw-r--r--xfa/fgas/crt/cfgas_formatstring.cpp1
-rw-r--r--xfa/fxfa/parser/cxfa_nodelocale.cpp1
6 files changed, 150 insertions, 67 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;
}
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 <memory>
-
-class CPDF_Document;
-class CXML_Element;
+#include <vector>
+
+#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<UnsupportedFeature> CheckForSharedForm() const;
private:
- std::unique_ptr<CXML_Element> m_pXmlElement;
+ UnownedPtr<const CPDF_Stream> stream_;
};
#endif // CORE_FPDFDOC_CPDF_METADATA_H_
diff --git a/fpdfsdk/cpdfsdk_helpers.cpp b/fpdfsdk/cpdfsdk_helpers.cpp
index 19252f7c5b..16e7efc873 100644
--- a/fpdfsdk/cpdfsdk_helpers.cpp
+++ b/fpdfsdk/cpdfsdk_helpers.cpp
@@ -13,8 +13,6 @@
#include "core/fpdfdoc/cpdf_annot.h"
#include "core/fpdfdoc/cpdf_interform.h"
#include "core/fpdfdoc/cpdf_metadata.h"
-#include "core/fxcrt/xml/cxml_content.h"
-#include "core/fxcrt/xml/cxml_element.h"
#include "public/fpdf_ext.h"
namespace {
@@ -37,45 +35,6 @@ bool RaiseUnSupportError(int nError) {
return true;
}
-bool CheckSharedForm(const CXML_Element* pElement, ByteString cbName) {
- size_t count = pElement->CountAttrs();
- for (size_t i = 0; i < count; ++i) {
- ByteString space;
- ByteString name;
- WideString value;
- pElement->GetAttrByIndex(i, &space, &name, &value);
- if (space == "xmlns" && name == "adhocwf" &&
- value == L"http://ns.adobe.com/AcrobatAdhocWorkflow/1.0/") {
- CXML_Element* pVersion =
- pElement->GetElement("adhocwf", cbName.AsStringView(), 0);
- if (!pVersion)
- continue;
- CXML_Content* pContent = ToContent(pVersion->GetChild(0));
- if (!pContent)
- continue;
- switch (pContent->m_Content.GetInteger()) {
- case 1:
- RaiseUnSupportError(FPDF_UNSP_DOC_SHAREDFORM_ACROBAT);
- break;
- case 2:
- RaiseUnSupportError(FPDF_UNSP_DOC_SHAREDFORM_FILESYSTEM);
- break;
- case 0:
- RaiseUnSupportError(FPDF_UNSP_DOC_SHAREDFORM_EMAIL);
- break;
- }
- }
- }
-
- size_t nCount = pElement->CountChildren();
- for (size_t i = 0; i < nCount; ++i) {
- CXML_Element* pChild = ToElement(pElement->GetChild(i));
- if (pChild && CheckSharedForm(pChild, cbName))
- return true;
- }
- return false;
-}
-
#ifdef PDF_ENABLE_XFA
class FPDF_FileHandlerContext : public IFX_SeekableStream {
public:
@@ -300,10 +259,15 @@ void CheckUnSupportError(CPDF_Document* pDoc, uint32_t err_code) {
}
// SharedForm
- CPDF_Metadata metaData(pDoc);
- const CXML_Element* pElement = metaData.GetRoot();
- if (pElement)
- CheckSharedForm(pElement, "workflowType");
+ const CPDF_Dictionary* pRoot = pDoc->GetRoot();
+ if (pRoot) {
+ CPDF_Stream* pStream = pRoot->GetStreamFor("Metadata");
+ if (pStream) {
+ CPDF_Metadata metaData(pStream);
+ for (const auto& err : metaData.CheckForSharedForm())
+ RaiseUnSupportError(static_cast<int>(err));
+ }
+ }
#ifndef PDF_ENABLE_XFA
// XFA Forms
diff --git a/fpdfsdk/fpdf_ext.cpp b/fpdfsdk/fpdf_ext.cpp
index 2f05fc5cdc..509cfe818b 100644
--- a/fpdfsdk/fpdf_ext.cpp
+++ b/fpdfsdk/fpdf_ext.cpp
@@ -9,12 +9,63 @@
#include "core/fpdfapi/cpdf_modulemgr.h"
#include "core/fpdfapi/parser/cpdf_document.h"
#include "core/fpdfdoc/cpdf_interform.h"
+#include "core/fpdfdoc/cpdf_metadata.h"
#include "fpdfsdk/cpdfsdk_helpers.h"
#ifdef PDF_ENABLE_XFA
#include "fpdfsdk/fpdfxfa/cpdfxfa_context.h"
#endif // PDF_ENABLE_XFA
+static_assert(static_cast<int>(UnsupportedFeature::kDocumentXFAForm) ==
+ FPDF_UNSP_DOC_XFAFORM,
+ "UnsupportedFeature::kDocumentXFAForm value mismatch");
+static_assert(
+ static_cast<int>(UnsupportedFeature::kDocumentPortableCollection) ==
+ FPDF_UNSP_DOC_PORTABLECOLLECTION,
+ "UnsupportedFeature::kDocumentPortableCollection value mismatch");
+static_assert(static_cast<int>(UnsupportedFeature::kDocumentAttachment) ==
+ FPDF_UNSP_DOC_ATTACHMENT,
+ "UnsupportedFeature::kDocumentAttachment value mismatch");
+static_assert(static_cast<int>(UnsupportedFeature::kDocumentSecurity) ==
+ FPDF_UNSP_DOC_SECURITY,
+ "UnsupportedFeature::kDocumentSecurity value mismatch");
+static_assert(static_cast<int>(UnsupportedFeature::kDocumentSharedReview) ==
+ FPDF_UNSP_DOC_SHAREDREVIEW,
+ "UnsupportedFeature::kDocumentSharedReview value mismatch");
+static_assert(
+ static_cast<int>(UnsupportedFeature::kDocumentSharedFormAcrobat) ==
+ FPDF_UNSP_DOC_SHAREDFORM_ACROBAT,
+ "UnsupportedFeature::kDocumentSharedFormAcrobat value mismatch");
+static_assert(
+ static_cast<int>(UnsupportedFeature::kDocumentSharedFormFilesystem) ==
+ FPDF_UNSP_DOC_SHAREDFORM_FILESYSTEM,
+ "UnsupportedFeature::kDocumentSharedFormFilesystem value mismatch");
+static_assert(static_cast<int>(UnsupportedFeature::kDocumentSharedFormEmail) ==
+ FPDF_UNSP_DOC_SHAREDFORM_EMAIL,
+ "UnsupportedFeature::kDocumentSharedFormEmail value mismatch");
+static_assert(static_cast<int>(UnsupportedFeature::kAnnotation3d) ==
+ FPDF_UNSP_ANNOT_3DANNOT,
+ "UnsupportedFeature::kAnnotation3d value mismatch");
+static_assert(static_cast<int>(UnsupportedFeature::kAnnotationMovie) ==
+ FPDF_UNSP_ANNOT_MOVIE,
+ "UnsupportedFeature::kAnnotationMovie value mismatch");
+static_assert(static_cast<int>(UnsupportedFeature::kAnnotationSound) ==
+ FPDF_UNSP_ANNOT_SOUND,
+ "UnsupportedFeature::kAnnotationSound value mismatch");
+static_assert(static_cast<int>(UnsupportedFeature::kAnnotationScreenMedia) ==
+ FPDF_UNSP_ANNOT_SCREEN_MEDIA,
+ "UnsupportedFeature::kAnnotationScreenMedia value mismatch");
+static_assert(
+ static_cast<int>(UnsupportedFeature::kAnnotationScreenRichMedia) ==
+ FPDF_UNSP_ANNOT_SCREEN_RICHMEDIA,
+ "UnsupportedFeature::kAnnotationScreenRichMedia value mismatch");
+static_assert(static_cast<int>(UnsupportedFeature::kAnnotationAttachment) ==
+ FPDF_UNSP_ANNOT_ATTACHMENT,
+ "UnsupportedFeature::kAnnotationAttachment value mismatch");
+static_assert(static_cast<int>(UnsupportedFeature::kAnnotationSignature) ==
+ FPDF_UNSP_ANNOT_SIG,
+ "UnsupportedFeature::kAnnotationSignature value mismatch");
+
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV
FSDK_SetUnSpObjProcessHandler(UNSUPPORT_INFO* unsp_info) {
if (!unsp_info || unsp_info->version != 1)
diff --git a/xfa/fgas/crt/cfgas_formatstring.cpp b/xfa/fgas/crt/cfgas_formatstring.cpp
index d7273d0e4a..1edcf1e51d 100644
--- a/xfa/fgas/crt/cfgas_formatstring.cpp
+++ b/xfa/fgas/crt/cfgas_formatstring.cpp
@@ -11,7 +11,6 @@
#include "core/fxcrt/cfx_decimal.h"
#include "core/fxcrt/fx_extension.h"
-#include "core/fxcrt/xml/cxml_element.h"
#define FX_LOCALECATEGORY_DateHash 0xbde9abde
#define FX_LOCALECATEGORY_TimeHash 0x2d71b00f
diff --git a/xfa/fxfa/parser/cxfa_nodelocale.cpp b/xfa/fxfa/parser/cxfa_nodelocale.cpp
index a93452cc51..71f4049b6b 100644
--- a/xfa/fxfa/parser/cxfa_nodelocale.cpp
+++ b/xfa/fxfa/parser/cxfa_nodelocale.cpp
@@ -8,7 +8,6 @@
#include <utility>
-#include "core/fxcrt/xml/cxml_element.h"
#include "fxjs/xfa/cjx_object.h"
#include "xfa/fxfa/parser/cxfa_calendarsymbols.h"
#include "xfa/fxfa/parser/cxfa_datetimesymbols.h"