mirror of
https://pdfium.googlesource.com/pdfium
synced 2026-07-30 10:21:46 +08:00
This CL updates FPDF_LIBRARY_CONFIG to version 6, introducing an experimental m_BrotliEnabled flag. This allows applications to dynamically enable or disable /BrotliDecode at library initialization time when PDFium is compiled with Brotli support. Other codepaths check if Brotli is enabled before decoding brotli-encoded streams. Bug: 475855993 Change-Id: I4ef555dfc58581bae0289c293d2f77a387749637 Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/149610 Reviewed-by: Andy Phan <andyphan@chromium.org> Commit-Queue: Aryan Krishnan <aryankrishnan4b@gmail.com> Reviewed-by: Lei Zhang <thestig@chromium.org>
113 lines
2.8 KiB
C++
113 lines
2.8 KiB
C++
// Copyright 2020 The PDFium Authors
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
#include "testing/embedder_test_environment.h"
|
|
|
|
#include <ostream>
|
|
|
|
#include "core/fxcrt/check.h"
|
|
#include "core/fxcrt/compiler_specific.h"
|
|
#include "core/fxcrt/fx_system.h"
|
|
#include "public/fpdfview.h"
|
|
#include "testing/command_line_helpers.h"
|
|
|
|
#ifdef PDF_ENABLE_V8
|
|
#include "testing/v8_test_environment.h"
|
|
#endif // PDF_ENABLE_V8
|
|
|
|
namespace {
|
|
|
|
EmbedderTestEnvironment* g_environment = nullptr;
|
|
|
|
} // namespace
|
|
|
|
EmbedderTestEnvironment::EmbedderTestEnvironment()
|
|
: renderer_type_(GetDefaultRendererType()) {
|
|
DCHECK(!g_environment);
|
|
g_environment = this;
|
|
}
|
|
|
|
EmbedderTestEnvironment::~EmbedderTestEnvironment() {
|
|
DCHECK(g_environment);
|
|
g_environment = nullptr;
|
|
}
|
|
|
|
// static
|
|
EmbedderTestEnvironment* EmbedderTestEnvironment::GetInstance() {
|
|
return g_environment;
|
|
}
|
|
|
|
void EmbedderTestEnvironment::SetUp() {
|
|
FPDF_LIBRARY_CONFIG config = {
|
|
.version = version_,
|
|
.m_pUserFontPaths = test_fonts_.font_paths(),
|
|
|
|
#ifdef PDF_ENABLE_V8
|
|
.m_pIsolate = V8TestEnvironment::GetInstance()->isolate(),
|
|
.m_v8EmbedderSlot = 0,
|
|
.m_pPlatform = V8TestEnvironment::GetInstance()->platform(),
|
|
#else // PDF_ENABLE_V8
|
|
.m_pIsolate = nullptr,
|
|
.m_v8EmbedderSlot = 0,
|
|
.m_pPlatform = nullptr,
|
|
#endif // PDF_ENABLE_V8
|
|
|
|
.m_RendererType = renderer_type_,
|
|
.m_FontLibraryType = fontations_ ? FPDF_FONTBACKENDTYPE_FONTATIONS
|
|
: FPDF_FONTBACKENDTYPE_FREETYPE,
|
|
.m_BrotliEnabled = brotli_enabled_,
|
|
};
|
|
|
|
FPDF_InitLibraryWithConfig(&config);
|
|
|
|
test_fonts_.InstallFontMapper();
|
|
}
|
|
|
|
void EmbedderTestEnvironment::TearDown() {
|
|
FPDF_DestroyLibrary();
|
|
}
|
|
|
|
void EmbedderTestEnvironment::AddFlags(int argc, char** argv) {
|
|
for (int i = 1; i < argc; ++i) {
|
|
AddFlag(UNSAFE_TODO(argv[i]));
|
|
}
|
|
CHECK(CheckFlags());
|
|
}
|
|
|
|
void EmbedderTestEnvironment::AddFlag(const std::string& flag) {
|
|
if (flag == "--write-pngs") {
|
|
write_pngs_ = true;
|
|
return;
|
|
}
|
|
|
|
#if defined(PDF_USE_SKIA)
|
|
std::string value;
|
|
if (ParseSwitchKeyValue(flag, "--use-renderer=", &value)) {
|
|
if (value == "agg") {
|
|
renderer_type_ = FPDF_RENDERERTYPE_AGG;
|
|
} else if (value == "skia") {
|
|
renderer_type_ = FPDF_RENDERERTYPE_SKIA;
|
|
} else {
|
|
std::cerr << "Invalid --use-renderer argument, value must be one of agg "
|
|
"or skia\n";
|
|
}
|
|
return;
|
|
}
|
|
if (flag == "--fontations") {
|
|
fontations_ = true;
|
|
return;
|
|
}
|
|
#endif // defined(PDF_USE_SKIA)
|
|
|
|
std::cerr << "Unknown flag: " << flag << "\n";
|
|
}
|
|
|
|
bool EmbedderTestEnvironment::CheckFlags() {
|
|
if (fontations_ && renderer_type_ != FPDF_RENDERERTYPE_SKIA) {
|
|
std::cerr << "--fontations requires --use-renderer=skia as well.\n";
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|