Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(281)

Unified Diff: samples/pdfium_test.cc

Issue 2277063003: Extend pdfium_test capability so that more Javascript can be executed (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | testing/resources/pixel/bug_492.pdf » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: samples/pdfium_test.cc
diff --git a/samples/pdfium_test.cc b/samples/pdfium_test.cc
index da2d1f6977fa45e71fdf72ea756e96a9426a68e3..421df39bf3cdfe30d56326dad52a585e444ea490 100644
--- a/samples/pdfium_test.cc
+++ b/samples/pdfium_test.cc
@@ -7,6 +7,7 @@
#include <stdlib.h>
#include <string.h>
+#include <map>
#include <sstream>
#include <string>
#include <utility>
@@ -53,6 +54,14 @@ enum OutputFormat {
#endif
};
+// Hold a map of the currently loaded pages in order to avoid them
+// to get loaded twice.
+std::map<int, FPDF_PAGE> g_loadedPages;
dsinclair 2016/08/25 19:36:49 It may actually be closer to what Chromium is doin
tonikitoo 2016/08/25 19:48:58 Chromium keeps track of the pages in src/pdf/pdfiu
Lei Zhang 2016/08/27 01:03:23 I believe this actually adds a static initializer,
Lei Zhang 2016/08/27 01:03:23 Form_GetPage() does reload the page as shown. The
+
+// Hold a global pointer of FPDF_FORMHANDLE so that PDFium
+// app hooks can made use of it.
+FPDF_FORMHANDLE g_formHandle;
Lei Zhang 2016/08/27 01:03:23 It would have been nice to use GetPageForIndex()'s
+
struct Options {
Options()
: show_config(false), send_events(false), output_format(OUTPUT_NONE) {}
@@ -520,19 +529,35 @@ void SendPageEvents(const FPDF_FORMHANDLE& form,
}
}
+FPDF_PAGE GetPageForIndex(FPDF_FORMFILLINFO* param,
+ FPDF_DOCUMENT doc,
+ int index) {
+ auto iter = g_loadedPages.find(index);
+ if (iter != g_loadedPages.end())
+ return iter->second;
+
+ FPDF_PAGE page = FPDF_LoadPage(doc, index);
+ if (!page)
+ return nullptr;
+
+ FORM_OnAfterLoadPage(page, g_formHandle);
+ FORM_DoPageAAction(page, g_formHandle, FPDFPAGE_AACTION_OPEN);
+
+ g_loadedPages[index] = page;
+ return page;
+}
+
bool RenderPage(const std::string& name,
- const FPDF_DOCUMENT& doc,
- const FPDF_FORMHANDLE& form,
+ FPDF_DOCUMENT doc,
+ FPDF_FORMHANDLE& form,
const int page_index,
const Options& options,
const std::string& events) {
- FPDF_PAGE page = FPDF_LoadPage(doc, page_index);
+ FPDF_PAGE page = GetPageForIndex(nullptr, doc, page_index);
if (!page)
return false;
FPDF_TEXTPAGE text_page = FPDFText_LoadPage(page);
- FORM_OnAfterLoadPage(page, form);
- FORM_DoPageAAction(page, form, FPDFPAGE_AACTION_OPEN);
if (options.send_events)
SendPageEvents(form, page, events);
@@ -593,6 +618,8 @@ bool RenderPage(const std::string& name,
} else {
fprintf(stderr, "Page was too large to be rendered.\n");
}
+
+ g_loadedPages.erase(page_index);
FORM_DoPageAAction(page, form, FPDFPAGE_AACTION_CLOSE);
FORM_OnBeforeClosePage(page, form);
FPDFText_ClosePage(text_page);
@@ -620,6 +647,7 @@ void RenderPdf(const std::string& name,
#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);
@@ -703,7 +731,8 @@ void RenderPdf(const std::string& name,
(void)FPDF_GetDocPermissions(doc);
- FPDF_FORMHANDLE form = FPDFDOC_InitFormFillEnvironment(doc, &form_callbacks);
+ FPDF_FORMHANDLE form = g_formHandle =
+ FPDFDOC_InitFormFillEnvironment(doc, &form_callbacks);
#ifdef PDF_ENABLE_XFA
int docType = DOCTYPE_PDF;
if (FPDF_HasXFAField(doc, &docType) && docType != DOCTYPE_PDF &&
« no previous file with comments | « no previous file | testing/resources/pixel/bug_492.pdf » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698