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

Unified Diff: chrome/utility/printing_handler.cc

Issue 799643004: Combine PDF plugin into the Chromium binary. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 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 | « chrome/utility/printing_handler.h ('k') | pdf/BUILD.gn » ('j') | pdf/pdf.gyp » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/utility/printing_handler.cc
diff --git a/chrome/utility/printing_handler.cc b/chrome/utility/printing_handler.cc
index 3dd8e923b6c6e4fa76d70e70666c375d1cf1eef4..9e282adb467725a4549b0e24ca1d5c11502f8432 100644
--- a/chrome/utility/printing_handler.cc
+++ b/chrome/utility/printing_handler.cc
@@ -13,6 +13,7 @@
#include "chrome/utility/cloud_print/bitmap_image.h"
#include "chrome/utility/cloud_print/pwg_encoder.h"
#include "content/public/utility/utility_thread.h"
+#include "pdf/pdf.h"
#include "printing/page_range.h"
#include "printing/pdf_render_settings.h"
@@ -36,180 +37,12 @@ void ReleaseProcessIfNeeded() {
content::UtilityThread::Get()->ReleaseProcessIfNeeded();
}
-class PdfFunctionsBase {
- public:
- PdfFunctionsBase() : render_pdf_to_bitmap_func_(NULL),
- get_pdf_doc_info_func_(NULL) {}
-
- bool Init() {
- base::FilePath pdf_module_path;
- if (!PathService::Get(chrome::FILE_PDF_PLUGIN, &pdf_module_path) ||
- !base::PathExists(pdf_module_path)) {
- return false;
- }
-
- pdf_lib_.Reset(base::LoadNativeLibrary(pdf_module_path, NULL));
- if (!pdf_lib_.is_valid()) {
- LOG(WARNING) << "Couldn't load PDF plugin";
- return false;
- }
-
- render_pdf_to_bitmap_func_ =
- reinterpret_cast<RenderPDFPageToBitmapProc>(
- pdf_lib_.GetFunctionPointer("RenderPDFPageToBitmap"));
- LOG_IF(WARNING, !render_pdf_to_bitmap_func_) <<
- "Missing RenderPDFPageToBitmap";
-
- get_pdf_doc_info_func_ =
- reinterpret_cast<GetPDFDocInfoProc>(
- pdf_lib_.GetFunctionPointer("GetPDFDocInfo"));
- LOG_IF(WARNING, !get_pdf_doc_info_func_) << "Missing GetPDFDocInfo";
-
- if (!render_pdf_to_bitmap_func_ || !get_pdf_doc_info_func_ ||
- !PlatformInit(pdf_module_path, pdf_lib_)) {
- Reset();
- }
-
- return IsValid();
- }
-
- bool IsValid() const {
- return pdf_lib_.is_valid();
- }
-
- void Reset() {
- pdf_lib_.Reset(NULL);
- }
-
- bool RenderPDFPageToBitmap(const void* pdf_buffer,
- int pdf_buffer_size,
- int page_number,
- void* bitmap_buffer,
- int bitmap_width,
- int bitmap_height,
- int dpi_x,
- int dpi_y,
- bool autorotate) {
- if (!render_pdf_to_bitmap_func_)
- return false;
- return render_pdf_to_bitmap_func_(pdf_buffer, pdf_buffer_size, page_number,
- bitmap_buffer, bitmap_width,
- bitmap_height, dpi_x, dpi_y, autorotate);
- }
-
- bool GetPDFDocInfo(const void* pdf_buffer,
- int buffer_size,
- int* page_count,
- double* max_page_width) {
- if (!get_pdf_doc_info_func_)
- return false;
- return get_pdf_doc_info_func_(pdf_buffer, buffer_size, page_count,
- max_page_width);
- }
-
- protected:
- virtual bool PlatformInit(
- const base::FilePath& pdf_module_path,
- const base::ScopedNativeLibrary& pdf_lib) {
- return true;
- }
-
- private:
- // Exported by PDF plugin.
- typedef bool (*RenderPDFPageToBitmapProc)(const void* pdf_buffer,
- int pdf_buffer_size,
- int page_number,
- void* bitmap_buffer,
- int bitmap_width,
- int bitmap_height,
- int dpi_x,
- int dpi_y,
- bool autorotate);
- typedef bool (*GetPDFDocInfoProc)(const void* pdf_buffer,
- int buffer_size, int* page_count,
- double* max_page_width);
-
- RenderPDFPageToBitmapProc render_pdf_to_bitmap_func_;
- GetPDFDocInfoProc get_pdf_doc_info_func_;
-
- base::ScopedNativeLibrary pdf_lib_;
- DISALLOW_COPY_AND_ASSIGN(PdfFunctionsBase);
-};
-
-#if defined(OS_WIN)
-
-class PdfFunctionsWin : public PdfFunctionsBase {
- public:
- PdfFunctionsWin() : render_pdf_to_dc_func_(NULL) {
- }
-
- bool PlatformInit(
- const base::FilePath& pdf_module_path,
- const base::ScopedNativeLibrary& pdf_lib) override {
- render_pdf_to_dc_func_ =
- reinterpret_cast<RenderPDFPageToDCProc>(
- pdf_lib.GetFunctionPointer("RenderPDFPageToDC"));
- LOG_IF(WARNING, !render_pdf_to_dc_func_) << "Missing RenderPDFPageToDC";
-
- return render_pdf_to_dc_func_ != NULL;
- }
-
- bool RenderPDFPageToDC(const void* pdf_buffer,
- int buffer_size,
- int page_number,
- HDC dc,
- int dpi_x,
- int dpi_y,
- int bounds_origin_x,
- int bounds_origin_y,
- int bounds_width,
- int bounds_height,
- bool fit_to_bounds,
- bool stretch_to_bounds,
- bool keep_aspect_ratio,
- bool center_in_bounds,
- bool autorotate) {
- if (!render_pdf_to_dc_func_)
- return false;
- return render_pdf_to_dc_func_(pdf_buffer, buffer_size, page_number,
- dc, dpi_x, dpi_y, bounds_origin_x,
- bounds_origin_y, bounds_width, bounds_height,
- fit_to_bounds, stretch_to_bounds,
- keep_aspect_ratio, center_in_bounds,
- autorotate);
- }
-
- private:
- // Exported by PDF plugin.
- typedef bool (*RenderPDFPageToDCProc)(
- const void* pdf_buffer, int buffer_size, int page_number, HDC dc,
- int dpi_x, int dpi_y, int bounds_origin_x, int bounds_origin_y,
- int bounds_width, int bounds_height, bool fit_to_bounds,
- bool stretch_to_bounds, bool keep_aspect_ratio, bool center_in_bounds,
- bool autorotate);
- RenderPDFPageToDCProc render_pdf_to_dc_func_;
-
- DISALLOW_COPY_AND_ASSIGN(PdfFunctionsWin);
-};
-
-typedef PdfFunctionsWin PdfFunctions;
-#else // OS_WIN
-typedef PdfFunctionsBase PdfFunctions;
-#endif // OS_WIN
-
-base::LazyInstance<PdfFunctions> g_pdf_lib = LAZY_INSTANCE_INITIALIZER;
-
} // namespace
PrintingHandler::PrintingHandler() {}
PrintingHandler::~PrintingHandler() {}
-// static
-void PrintingHandler::PreSandboxStartup() {
- g_pdf_lib.Get().Init();
-}
-
bool PrintingHandler::OnMessageReceived(const IPC::Message& message) {
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(PrintingHandler, message)
@@ -282,9 +115,6 @@ void PrintingHandler::OnRenderPDFPagesToPWGRaster(
#if defined(OS_WIN)
int PrintingHandler::LoadPDF(base::File pdf_file) {
- if (!g_pdf_lib.Get().IsValid())
- return 0;
-
int64 length64 = pdf_file.GetLength();
if (length64 <= 0 || length64 > std::numeric_limits<int>::max())
return 0;
@@ -295,7 +125,7 @@ int PrintingHandler::LoadPDF(base::File pdf_file) {
return 0;
int total_page_count = 0;
- if (!g_pdf_lib.Get().GetPDFDocInfo(
+ if (!chrome_pdf::GetPDFDocInfo(
&pdf_data_.front(), pdf_data_.size(), &total_page_count, NULL)) {
return 0;
}
@@ -324,13 +154,12 @@ bool PrintingHandler::RenderPdfPageToMetafile(int page_number,
// The underlying metafile is of type Emf and ignores the arguments passed
// to StartPage.
metafile.StartPage(gfx::Size(), gfx::Rect(), 1);
- if (!g_pdf_lib.Get().RenderPDFPageToDC(
+ if (!chrome_pdf::RenderPDFPageToDC(
&pdf_data_.front(),
pdf_data_.size(),
page_number,
metafile.context(),
pdf_rendering_settings_.dpi(),
- pdf_rendering_settings_.dpi(),
pdf_rendering_settings_.area().x(),
pdf_rendering_settings_.area().y(),
pdf_rendering_settings_.area().width(),
@@ -356,9 +185,6 @@ bool PrintingHandler::RenderPDFPagesToPWGRaster(
const printing::PwgRasterSettings& bitmap_settings,
base::File bitmap_file) {
bool autoupdate = true;
- if (!g_pdf_lib.Get().IsValid())
- return false;
-
base::File::Info info;
if (!pdf_file.GetInfo(&info) || info.size <= 0 ||
info.size > std::numeric_limits<int>::max())
@@ -370,8 +196,8 @@ bool PrintingHandler::RenderPDFPagesToPWGRaster(
return false;
int total_page_count = 0;
- if (!g_pdf_lib.Get().GetPDFDocInfo(data.data(), data_size,
- &total_page_count, NULL)) {
+ if (!chrome_pdf::GetPDFDocInfo(data.data(), data_size,
+ &total_page_count, NULL)) {
return false;
}
@@ -392,15 +218,14 @@ bool PrintingHandler::RenderPDFPagesToPWGRaster(
page_number = total_page_count - 1 - page_number;
}
- if (!g_pdf_lib.Get().RenderPDFPageToBitmap(data.data(),
- data_size,
- page_number,
- image.pixel_data(),
- image.size().width(),
- image.size().height(),
- settings.dpi(),
- settings.dpi(),
- autoupdate)) {
+ if (!chrome_pdf::RenderPDFPageToBitmap(data.data(),
+ data_size,
+ page_number,
+ image.pixel_data(),
+ image.size().width(),
+ image.size().height(),
+ settings.dpi(),
+ autoupdate)) {
return false;
}
« no previous file with comments | « chrome/utility/printing_handler.h ('k') | pdf/BUILD.gn » ('j') | pdf/pdf.gyp » ('J')

Powered by Google App Engine
This is Rietveld 408576698