summaryrefslogtreecommitdiff
path: root/samples
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2018-04-23 18:02:57 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-04-23 18:02:57 +0000
commit0784c7317e3aaa2c65d098cf2593b6b49986307d (patch)
treea264d06dcd9fd0d914324d5bd0a96430cc543b87 /samples
parent9f71afb882a9d1294f8a4392b8553e2c285f51c7 (diff)
downloadpdfium-0784c7317e3aaa2c65d098cf2593b6b49986307d.tar.xz
Disable JavaScript entirely if no JSPlatform passed by embedder.
Allows run-time selection of whether to permit JS inside PDF. Previously, this was a link-time decision only. This requires a little more caution before we decide that we have the CJS_Runtime, and not the CJS_RuntimeStub in a few casts. Adds a kDisableJavaScript option to the form fill embeddertests. Adds a --disable-javascript flag to the pdfium_test executable. Also adds a --disable-xfa flag while we're at it. Change-Id: I8d8ac95f6474459cadba9a60572fbb342e984646 Reviewed-on: https://pdfium-review.googlesource.com/31090 Reviewed-by: dsinclair <dsinclair@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'samples')
-rw-r--r--samples/pdfium_test.cc78
1 files changed, 45 insertions, 33 deletions
diff --git a/samples/pdfium_test.cc b/samples/pdfium_test.cc
index 3dcd8311c6..292673f1de 100644
--- a/samples/pdfium_test.cc
+++ b/samples/pdfium_test.cc
@@ -88,40 +88,32 @@ enum OutputFormat {
namespace {
struct Options {
- Options()
- : show_config(false),
- show_metadata(false),
- send_events(false),
- render_oneshot(false),
- save_attachments(false),
- save_images(false),
-#ifdef ENABLE_CALLGRIND
- callgrind_delimiters(false),
-#endif // ENABLE_CALLGRIND
- pages(false),
- md5(false),
- output_format(OUTPUT_NONE) {
- }
-
- bool show_config;
- bool show_metadata;
- bool send_events;
- bool render_oneshot;
- bool save_attachments;
- bool save_images;
+ Options() = default;
+
+ bool show_config = false;
+ bool show_metadata = false;
+ bool send_events = false;
+ bool render_oneshot = false;
+ bool save_attachments = false;
+ bool save_images = false;
+#ifdef PDF_ENABLE_V8
+ bool disable_javascript = false;
+#ifdef PDF_ENABLE_XFA
+ bool disable_xfa = false;
+#endif // PDF_ENABLE_XFA
+#endif // PDF_ENABLE_V8
+ bool pages = false;
+ bool md5 = false;
#ifdef ENABLE_CALLGRIND
- bool callgrind_delimiters;
+ bool callgrind_delimiters = false;
#endif // ENABLE_CALLGRIND
- bool pages;
- bool md5;
- OutputFormat output_format;
+ OutputFormat output_format = OUTPUT_NONE;
std::string scale_factor_as_string;
std::string exe_path;
std::string bin_directory;
std::string font_directory;
- // 0-based page numbers to be rendered.
- int first_page;
- int last_page;
+ int first_page = 0; // First 0-based page number to renderer.
+ int last_page = 0; // Last 0-based page number to renderer.
};
Optional<std::string> ExpandDirectoryPath(const std::string& path) {
@@ -286,6 +278,14 @@ bool ParseCommandLine(const std::vector<std::string>& args,
options->save_attachments = true;
} else if (cur_arg == "--save-images") {
options->save_images = true;
+#if PDF_ENABLE_V8
+ } else if (cur_arg == "--disable-javascript") {
+ options->disable_javascript = true;
+#ifdef PDF_ENABLE_XFA
+ } else if (cur_arg == "--disable-xfa") {
+ options->disable_xfa = true;
+#endif // PDF_ENABLE_XFA
+#endif // PDF_ENABLE_V8
#ifdef ENABLE_CALLGRIND
} else if (cur_arg == "--callgrind-delim") {
options->callgrind_delimiters = true;
@@ -695,17 +695,23 @@ void RenderPdf(const std::string& name,
form_callbacks.version = 1;
#endif // PDF_ENABLE_XFA
form_callbacks.FFI_GetPage = GetPageForIndex;
- form_callbacks.m_pJsPlatform = &platform_callbacks;
+
+#ifdef PDF_ENABLE_V8
+ if (!options.disable_javascript)
+ form_callbacks.m_pJsPlatform = &platform_callbacks;
+#endif // PDF_ENABLE_V8
std::unique_ptr<void, FPDFFormHandleDeleter> form(
FPDFDOC_InitFormFillEnvironment(doc.get(), &form_callbacks));
form_callbacks.form_handle = form.get();
#ifdef PDF_ENABLE_XFA
- int doc_type = FPDF_GetFormType(doc.get());
- if (doc_type == FORMTYPE_XFA_FULL || doc_type == FORMTYPE_XFA_FOREGROUND) {
- if (!FPDF_LoadXFA(doc.get()))
- fprintf(stderr, "LoadXFA unsuccessful, continuing anyway.\n");
+ if (!options.disable_xfa && !options.disable_javascript) {
+ int doc_type = FPDF_GetFormType(doc.get());
+ if (doc_type == FORMTYPE_XFA_FULL || doc_type == FORMTYPE_XFA_FOREGROUND) {
+ if (!FPDF_LoadXFA(doc.get()))
+ fprintf(stderr, "LoadXFA unsuccessful, continuing anyway.\n");
+ }
}
#endif // PDF_ENABLE_XFA
@@ -789,6 +795,12 @@ constexpr char kUsageString[] =
"<pdf-name>.attachment.<attachment-name>\n"
" --save-images - write embedded images "
"<pdf-name>.<page-number>.<object-number>.png\n"
+#ifdef PDF_ENABLE_V8
+ " --disable-javascript- do not execute JS in PDF files"
+#ifdef PDF_ENABLE_XFA
+ " --disable-xfa - do not process XFA forms"
+#endif // PDF_ENABLE_XFA
+#endif // PDF_ENABLE_V8
#ifdef ENABLE_CALLGRIND
" --callgrind-delim - delimit interesting section when using callgrind\n"
#endif // ENABLE_CALLGRIND