| Index: chrome/utility/printing_handler.cc
|
| diff --git a/chrome/utility/printing_handler.cc b/chrome/utility/printing_handler.cc
|
| index b69d6ea4932d427a8b39385f0f2ae4e8a2494894..d037949703b375a8acf750a9e77f38c24030b378 100644
|
| --- a/chrome/utility/printing_handler.cc
|
| +++ b/chrome/utility/printing_handler.cc
|
| @@ -10,9 +10,11 @@
|
| #include "base/scoped_native_library.h"
|
| #include "chrome/common/chrome_paths.h"
|
| #include "chrome/common/chrome_utility_printing_messages.h"
|
| +#include "chrome/installer/util/util_constants.h"
|
| #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"
|
|
|
| @@ -37,106 +39,6 @@ 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)
|
| // The 2 below IAT patch functions are almost identical to the code in
|
| // render_process_impl.cc. This is needed to work around specific Windows APIs
|
| @@ -171,80 +73,8 @@ DWORD WINAPI UtilityProcess_GetFontDataPatch(
|
| }
|
| return rv;
|
| }
|
| -
|
| -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 {
|
| - // Patch the IAT for handling specific APIs known to fail in the sandbox.
|
| - if (!g_iat_patch_createdca.is_patched()) {
|
| - g_iat_patch_createdca.Patch(pdf_module_path.value().c_str(),
|
| - "gdi32.dll", "CreateDCA",
|
| - UtilityProcess_CreateDCAPatch);
|
| - }
|
| -
|
| - if (!g_iat_patch_get_font_data.is_patched()) {
|
| - g_iat_patch_get_font_data.Patch(pdf_module_path.value().c_str(),
|
| - "gdi32.dll", "GetFontData",
|
| - UtilityProcess_GetFontDataPatch);
|
| - }
|
| - 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() {}
|
| @@ -253,7 +83,26 @@ PrintingHandler::~PrintingHandler() {}
|
|
|
| // static
|
| void PrintingHandler::PreSandboxStartup() {
|
| - g_pdf_lib.Get().Init();
|
| +#if defined(OS_WIN)
|
| + // Patch the IAT for handling specific APIs known to fail in the sandbox.
|
| + const wchar_t* chrome_dll_name =
|
| +#if defined(CHROME_MULTIPLE_DLL_CHILD)
|
| + installer::kChromeChildDll;
|
| +#else
|
| + installer::kChromeDll;
|
| +#endif
|
| + if (!g_iat_patch_createdca.is_patched()) {
|
| + g_iat_patch_createdca.Patch(chrome_dll_name,
|
| + "gdi32.dll", "CreateDCA",
|
| + UtilityProcess_CreateDCAPatch);
|
| + }
|
| +
|
| + if (!g_iat_patch_get_font_data.is_patched()) {
|
| + g_iat_patch_get_font_data.Patch(chrome_dll_name,
|
| + "gdi32.dll", "GetFontData",
|
| + UtilityProcess_GetFontDataPatch);
|
| + }
|
| +#endif
|
| }
|
|
|
| bool PrintingHandler::OnMessageReceived(const IPC::Message& message) {
|
| @@ -328,9 +177,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;
|
| @@ -341,7 +187,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;
|
| }
|
| @@ -370,13 +216,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(),
|
| @@ -402,9 +247,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())
|
| @@ -416,8 +258,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;
|
| }
|
|
|
| @@ -438,15 +280,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;
|
| }
|
|
|
|
|