summaryrefslogtreecommitdiff
path: root/samples
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2018-03-21 18:08:26 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-03-21 18:08:26 +0000
commit0421202e8d95b7a652964452634f20f8e9870899 (patch)
treef9e82f0d41097376affbd94d7f4b9f99d4494981 /samples
parentcb009c8652e4f3654d666a64d962d48d4ddc2f65 (diff)
downloadpdfium-0421202e8d95b7a652964452634f20f8e9870899.tar.xz
Move declarations in pdfium_test closer to usage
This CL moves some definitions in pdfium_test closer to their usage. Change-Id: I30835b1749976cc027466df37e12ddd74581ce22 Reviewed-on: https://pdfium-review.googlesource.com/28972 Reviewed-by: Henrique Nakashima <hnakashima@chromium.org> Commit-Queue: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'samples')
-rw-r--r--samples/pdfium_test.cc46
1 files changed, 24 insertions, 22 deletions
diff --git a/samples/pdfium_test.cc b/samples/pdfium_test.cc
index ebc7412055..c02629732b 100644
--- a/samples/pdfium_test.cc
+++ b/samples/pdfium_test.cc
@@ -1354,27 +1354,8 @@ void RenderPdf(const std::string& name,
size_t len,
const Options& options,
const std::string& events) {
- IPDF_JSPLATFORM platform_callbacks = {};
- platform_callbacks.version = 3;
- platform_callbacks.app_alert = ExampleAppAlert;
- platform_callbacks.app_response = ExampleAppResponse;
- platform_callbacks.Doc_gotoPage = ExampleDocGotoPage;
- platform_callbacks.Doc_mail = ExampleDocMail;
-
- // The pdf_avail must outlive doc.
- std::unique_ptr<void, FPDFAvailDeleter> pdf_avail;
- // The document must outlive |form_callbacks.loaded_pages|.
- std::unique_ptr<void, FPDFDocumentDeleter> doc;
- FPDF_FORMFILLINFO_PDFiumTest form_callbacks = {};
-#ifdef PDF_ENABLE_XFA
- form_callbacks.version = 2;
-#else // PDF_ENABLE_XFA
- form_callbacks.version = 1;
-#endif // PDF_ENABLE_XFA
- form_callbacks.FFI_GetPage = GetPageForIndex;
- form_callbacks.m_pJsPlatform = &platform_callbacks;
-
TestLoader loader(pBuf, len);
+
FPDF_FILEACCESS file_access = {};
file_access.m_FileLen = static_cast<unsigned long>(len);
file_access.m_GetBlock = TestLoader::GetBlock;
@@ -1388,10 +1369,15 @@ void RenderPdf(const std::string& name,
hints.version = 1;
hints.AddSegment = Add_Segment;
+ // The pdf_avail must outlive doc.
+ std::unique_ptr<void, FPDFAvailDeleter> pdf_avail(
+ FPDFAvail_Create(&file_avail, &file_access));
+
+ // The document must outlive |form_callbacks.loaded_pages|.
+ std::unique_ptr<void, FPDFDocumentDeleter> doc;
+
int nRet = PDF_DATA_NOTAVAIL;
bool bIsLinearized = false;
- pdf_avail.reset(FPDFAvail_Create(&file_avail, &file_access));
-
if (FPDFAvail_IsLinearized(pdf_avail.get()) == PDF_LINEARIZED) {
doc.reset(FPDFAvail_GetDocument(pdf_avail.get(), nullptr));
if (doc) {
@@ -1428,6 +1414,22 @@ void RenderPdf(const std::string& name,
if (options.save_attachments)
SaveAttachments(doc.get(), name);
+ IPDF_JSPLATFORM platform_callbacks = {};
+ platform_callbacks.version = 3;
+ platform_callbacks.app_alert = ExampleAppAlert;
+ platform_callbacks.app_response = ExampleAppResponse;
+ platform_callbacks.Doc_gotoPage = ExampleDocGotoPage;
+ platform_callbacks.Doc_mail = ExampleDocMail;
+
+ FPDF_FORMFILLINFO_PDFiumTest form_callbacks = {};
+#ifdef PDF_ENABLE_XFA
+ form_callbacks.version = 2;
+#else // PDF_ENABLE_XFA
+ form_callbacks.version = 1;
+#endif // PDF_ENABLE_XFA
+ form_callbacks.FFI_GetPage = GetPageForIndex;
+ form_callbacks.m_pJsPlatform = &platform_callbacks;
+
std::unique_ptr<void, FPDFFormHandleDeleter> form(
FPDFDOC_InitFormFillEnvironment(doc.get(), &form_callbacks));
form_callbacks.form_handle = form.get();