Simplify PDF initialization code.
chrome_pdf::InitializeSDK() always returns true. So remove code that assume otherwise. Change-Id: I2585e006e87b906795b0b1f201be78106871d9d4 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1801249 Reviewed-by: Robert Sesek <rsesek@chromium.org> Commit-Queue: Lei Zhang <thestig@chromium.org> Cr-Commit-Position: refs/heads/master@{#696151}
This commit is contained in:
50
pdf/pdf.cc
50
pdf/pdf.cc
@ -19,28 +19,16 @@ namespace {
|
||||
|
||||
class ScopedSdkInitializer {
|
||||
public:
|
||||
ScopedSdkInitializer() {}
|
||||
explicit ScopedSdkInitializer(bool enable_v8) {
|
||||
if (!IsSDKInitializedViaPepper())
|
||||
InitializeSDK(enable_v8);
|
||||
}
|
||||
~ScopedSdkInitializer() {
|
||||
#if DCHECK_IS_ON()
|
||||
DCHECK(initialized_);
|
||||
#endif
|
||||
if (!IsSDKInitializedViaPepper())
|
||||
ShutdownSDK();
|
||||
}
|
||||
|
||||
// Must be called.
|
||||
bool Init(bool enable_v8) {
|
||||
#if DCHECK_IS_ON()
|
||||
initialized_ = true;
|
||||
#endif
|
||||
return IsSDKInitializedViaPepper() || InitializeSDK(enable_v8);
|
||||
}
|
||||
|
||||
private:
|
||||
#if DCHECK_IS_ON()
|
||||
bool initialized_ = false;
|
||||
#endif
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(ScopedSdkInitializer);
|
||||
};
|
||||
|
||||
@ -62,10 +50,7 @@ bool RenderPDFPageToDC(base::span<const uint8_t> pdf_buffer,
|
||||
bool center_in_bounds,
|
||||
bool autorotate,
|
||||
bool use_color) {
|
||||
ScopedSdkInitializer scoped_sdk_initializer;
|
||||
if (!scoped_sdk_initializer.Init(/*enable_v8=*/true))
|
||||
return false;
|
||||
|
||||
ScopedSdkInitializer scoped_sdk_initializer(/*enable_v8=*/true);
|
||||
PDFEngineExports* engine_exports = PDFEngineExports::Get();
|
||||
PDFEngineExports::RenderingSettings settings(
|
||||
dpi_x, dpi_y,
|
||||
@ -93,10 +78,7 @@ void SetPDFUsePrintMode(int mode) {
|
||||
bool GetPDFDocInfo(base::span<const uint8_t> pdf_buffer,
|
||||
int* page_count,
|
||||
double* max_page_width) {
|
||||
ScopedSdkInitializer scoped_sdk_initializer;
|
||||
if (!scoped_sdk_initializer.Init(/*enable_v8=*/true))
|
||||
return false;
|
||||
|
||||
ScopedSdkInitializer scoped_sdk_initializer(/*enable_v8=*/true);
|
||||
PDFEngineExports* engine_exports = PDFEngineExports::Get();
|
||||
return engine_exports->GetPDFDocInfo(pdf_buffer, page_count, max_page_width);
|
||||
}
|
||||
@ -105,10 +87,7 @@ bool GetPDFPageSizeByIndex(base::span<const uint8_t> pdf_buffer,
|
||||
int page_number,
|
||||
double* width,
|
||||
double* height) {
|
||||
ScopedSdkInitializer scoped_sdk_initializer;
|
||||
if (!scoped_sdk_initializer.Init(/*enable_v8=*/true))
|
||||
return false;
|
||||
|
||||
ScopedSdkInitializer scoped_sdk_initializer(/*enable_v8=*/true);
|
||||
chrome_pdf::PDFEngineExports* engine_exports =
|
||||
chrome_pdf::PDFEngineExports::Get();
|
||||
return engine_exports->GetPDFPageSizeByIndex(pdf_buffer, page_number, width,
|
||||
@ -124,10 +103,7 @@ bool RenderPDFPageToBitmap(base::span<const uint8_t> pdf_buffer,
|
||||
int dpi_y,
|
||||
bool autorotate,
|
||||
bool use_color) {
|
||||
ScopedSdkInitializer scoped_sdk_initializer;
|
||||
if (!scoped_sdk_initializer.Init(/*enable_v8=*/true))
|
||||
return false;
|
||||
|
||||
ScopedSdkInitializer scoped_sdk_initializer(/*enable_v8=*/true);
|
||||
PDFEngineExports* engine_exports = PDFEngineExports::Get();
|
||||
PDFEngineExports::RenderingSettings settings(
|
||||
dpi_x, dpi_y, pp::Rect(bitmap_width, bitmap_height), true, false, true,
|
||||
@ -141,10 +117,7 @@ std::vector<uint8_t> ConvertPdfPagesToNupPdf(
|
||||
size_t pages_per_sheet,
|
||||
const gfx::Size& page_size,
|
||||
const gfx::Rect& printable_area) {
|
||||
ScopedSdkInitializer scoped_sdk_initializer;
|
||||
if (!scoped_sdk_initializer.Init(/*enable_v8=*/false))
|
||||
return std::vector<uint8_t>();
|
||||
|
||||
ScopedSdkInitializer scoped_sdk_initializer(/*enable_v8=*/false);
|
||||
PDFEngineExports* engine_exports = PDFEngineExports::Get();
|
||||
return engine_exports->ConvertPdfPagesToNupPdf(
|
||||
std::move(input_buffers), pages_per_sheet, page_size, printable_area);
|
||||
@ -155,10 +128,7 @@ std::vector<uint8_t> ConvertPdfDocumentToNupPdf(
|
||||
size_t pages_per_sheet,
|
||||
const gfx::Size& page_size,
|
||||
const gfx::Rect& printable_area) {
|
||||
ScopedSdkInitializer scoped_sdk_initializer;
|
||||
if (!scoped_sdk_initializer.Init(/*enable_v8=*/false))
|
||||
return std::vector<uint8_t>();
|
||||
|
||||
ScopedSdkInitializer scoped_sdk_initializer(/*enable_v8=*/false);
|
||||
PDFEngineExports* engine_exports = PDFEngineExports::Get();
|
||||
return engine_exports->ConvertPdfDocumentToNupPdf(
|
||||
input_buffer, pages_per_sheet, page_size, printable_area);
|
||||
|
@ -58,7 +58,7 @@ namespace chrome_pdf {
|
||||
// Do one time initialization of the SDK.
|
||||
// If |enable_v8| is false, then the PDFEngine will not be able to run
|
||||
// JavaScript.
|
||||
bool InitializeSDK(bool enable_v8);
|
||||
void InitializeSDK(bool enable_v8);
|
||||
// Tells the SDK that we're shutting down.
|
||||
void ShutdownSDK();
|
||||
|
||||
|
@ -52,8 +52,7 @@ pp::Instance* PDFModule::CreateInstance(PP_Instance instance) {
|
||||
v8::V8::SetNativesDataBlob(&natives);
|
||||
v8::V8::SetSnapshotDataBlob(&snapshot);
|
||||
}
|
||||
if (!InitializeSDK(/*enable_v8=*/true))
|
||||
return nullptr;
|
||||
InitializeSDK(/*enable_v8=*/true);
|
||||
g_sdk_initialized_via_pepper = true;
|
||||
}
|
||||
|
||||
|
@ -363,7 +363,7 @@ wchar_t SimplifyForSearch(wchar_t c) {
|
||||
|
||||
} // namespace
|
||||
|
||||
bool InitializeSDK(bool enable_v8) {
|
||||
void InitializeSDK(bool enable_v8) {
|
||||
FPDF_LIBRARY_CONFIG config;
|
||||
config.version = 2;
|
||||
config.m_pUserFontPaths = nullptr;
|
||||
@ -382,8 +382,6 @@ bool InitializeSDK(bool enable_v8) {
|
||||
#endif
|
||||
|
||||
InitializeUnsupportedFeaturesHandler();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void ShutdownSDK() {
|
||||
|
Reference in New Issue
Block a user