summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJUN FANG <jun_fang@foxitsoftware.com>2015-03-05 13:39:21 -0800
committerJUN FANG <jun_fang@foxitsoftware.com>2015-03-05 13:39:21 -0800
commit827a1722f70e7092270b5e0fdfba1e9c0b1ac50f (patch)
tree4f54a77d5b14d0ee3cce0e210fd8c450f7a92042
parent2785fb46249df5229e057917e54fe161bb0e3517 (diff)
downloadpdfium-827a1722f70e7092270b5e0fdfba1e9c0b1ac50f.tar.xz
Check whether a pdf has XFA fields before loading XFA fields
BUG=452793 R=tsepez@chromium.org Review URL: https://codereview.chromium.org/973673002
-rw-r--r--fpdfsdk/src/fpdfview.cpp63
-rw-r--r--samples/pdfium_test.cc13
-rw-r--r--testing/embedder_test.cpp7
3 files changed, 47 insertions, 36 deletions
diff --git a/fpdfsdk/src/fpdfview.cpp b/fpdfsdk/src/fpdfview.cpp
index 6a8f890115..db191245f3 100644
--- a/fpdfsdk/src/fpdfview.cpp
+++ b/fpdfsdk/src/fpdfview.cpp
@@ -303,43 +303,40 @@ DLLEXPORT FPDF_DOCUMENT STDCALL FPDF_LoadDocument(FPDF_STRING file_path, FPDF_BY
return pDocument;
}
-DLLEXPORT FX_BOOL STDCALL FPDF_HasXFAField(FPDF_DOCUMENT document, int& docType)
-{
- if (!document)
- return FALSE;
-
- CPDF_Dictionary* pRoot = ((CPDF_Document*)document)->GetRoot();
- if (!pRoot)
- return FALSE;
-
- CPDF_Dictionary* pAcroForm = pRoot->GetDict("AcroForm");
- if (!pAcroForm)
- return FALSE;
-
- CPDF_Object* pXFA = pAcroForm->GetElement("XFA");
- if (!pXFA)
- return FALSE;
-
- FX_BOOL bDynamicXFA = pRoot->GetBoolean("NeedsRendering", FALSE);
-
- if (bDynamicXFA)
- docType = DOCTYPE_DYNIMIC_XFA;
- else
- docType = DOCTYPE_STATIC_XFA;
-
- return TRUE;
-}
-
-DLLEXPORT FPDF_BOOL STDCALL FPDF_LoadXFA(FPDF_DOCUMENT document)
+DLLEXPORT FX_BOOL STDCALL FPDF_HasXFAField(FPDF_DOCUMENT document, int& docType)
{
- if (!document)
+ if (!document)
+ return FALSE;
+
+ CPDF_Document *pdfDoc = (static_cast<CPDFXFA_Document *>(document))->GetPDFDoc();
+ if (!pdfDoc)
+ return FALSE;
+
+ CPDF_Dictionary* pRoot = pdfDoc->GetRoot();
+ if (!pRoot)
+ return FALSE;
+
+ CPDF_Dictionary* pAcroForm = pRoot->GetDict("AcroForm");
+ if (!pAcroForm)
return FALSE;
- int iDocType = DOCTYPE_PDF;
- FX_BOOL hasXFAField = FPDF_HasXFAField(document, iDocType);
- if (!hasXFAField)
+ CPDF_Object* pXFA = pAcroForm->GetElement("XFA");
+ if (!pXFA)
return FALSE;
- return ((CPDFXFA_Document*)document)->LoadXFADoc();
+
+ FX_BOOL bDynamicXFA = pRoot->GetBoolean("NeedsRendering", FALSE);
+
+ if (bDynamicXFA)
+ docType = DOCTYPE_DYNIMIC_XFA;
+ else
+ docType = DOCTYPE_STATIC_XFA;
+
+ return TRUE;
+}
+
+DLLEXPORT FPDF_BOOL STDCALL FPDF_LoadXFA(FPDF_DOCUMENT document)
+{
+ return document && (static_cast<CPDFXFA_Document *>(document))->LoadXFADoc();
}
diff --git a/samples/pdfium_test.cc b/samples/pdfium_test.cc
index d861f2f5c9..e4a55f27ff 100644
--- a/samples/pdfium_test.cc
+++ b/samples/pdfium_test.cc
@@ -468,12 +468,21 @@ void RenderPdf(const std::string& name, const char* pBuf, size_t len,
doc = FPDFAvail_GetDocument(pdf_avail, NULL);
}
+ if (!doc)
+ {
+ fprintf(stderr, "Load pdf docs unsuccessful.\n");
+ return;
+ }
+
(void) FPDF_GetDocPermissions(doc);
(void) FPDFAvail_IsFormAvail(pdf_avail, &hints);
FPDF_FORMHANDLE form = FPDFDOC_InitFormFillEnvironment(doc, &form_callbacks);
- if (!FPDF_LoadXFA(doc)) {
- fprintf(stderr, "LoadXFA unsuccessful, continuing anyway.\n");
+ int docType = DOCTYPE_PDF;
+ if (FPDF_HasXFAField(doc, docType))
+ {
+ if (docType != DOCTYPE_PDF && !FPDF_LoadXFA(doc))
+ fprintf(stderr, "LoadXFA unsuccessful, continuing anyway.\n");
}
FPDF_SetFormFieldHighlightColor(form, 0, 0xFFE4DD);
FPDF_SetFormFieldHighlightAlpha(form, 100);
diff --git a/testing/embedder_test.cpp b/testing/embedder_test.cpp
index cf0bdf892c..563dec8bec 100644
--- a/testing/embedder_test.cpp
+++ b/testing/embedder_test.cpp
@@ -261,7 +261,12 @@ bool EmbedderTest::OpenDocument(const std::string& filename) {
if (!document_) {
return false;
}
- (void) FPDF_LoadXFA(document_);
+ int docType = DOCTYPE_PDF;
+ if (FPDF_HasXFAField(document_, docType))
+ {
+ if (docType != DOCTYPE_PDF)
+ (void) FPDF_LoadXFA(document_);
+ }
(void) FPDF_GetDocPermissions(document_);
(void) FPDFAvail_IsFormAvail(avail_, &hints_);