Update to Chromium revision 47fb4821 (#318735).

- Remove the in-process PDF plugin implementation. A new implementation is now required (issue #1565).

git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@2043 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
Marshall Greenblatt
2015-03-04 01:00:13 +00:00
parent a9191b26d2
commit ac4f451c94
42 changed files with 361 additions and 617 deletions

View File

@@ -30,225 +30,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)
// 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
// used by the Chrome PDF plugin that will fail in the sandbox.
static base::win::IATPatchFunction g_iat_patch_createdca;
HDC WINAPI UtilityProcess_CreateDCAPatch(LPCSTR driver_name,
LPCSTR device_name,
LPCSTR output,
const DEVMODEA* init_data) {
if (driver_name && (std::string("DISPLAY") == driver_name)) {
// CreateDC fails behind the sandbox, but not CreateCompatibleDC.
return CreateCompatibleDC(NULL);
}
NOTREACHED();
return CreateDCA(driver_name, device_name, output, init_data);
}
static base::win::IATPatchFunction g_iat_patch_get_font_data;
DWORD WINAPI UtilityProcess_GetFontDataPatch(
HDC hdc, DWORD table, DWORD offset, LPVOID buffer, DWORD length) {
int rv = GetFontData(hdc, table, offset, buffer, length);
if (rv == GDI_ERROR && hdc) {
HFONT font = static_cast<HFONT>(GetCurrentObject(hdc, OBJ_FONT));
LOGFONT logfont;
if (GetObject(font, sizeof(LOGFONT), &logfont)) {
content::UtilityThread::Get()->PreCacheFont(logfont);
rv = GetFontData(hdc, table, offset, buffer, length);
content::UtilityThread::Get()->ReleaseCachedFonts();
}
}
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() {}
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)
@@ -292,9 +79,6 @@ void PrintingHandler::OnRenderPDFPagesToMetafileStop() {
}
int PrintingHandler::LoadPDF(base::File pdf_file) {
if (!g_pdf_lib.Get().IsValid())
return 0;
int64 length = pdf_file.GetLength();
if (length < 0)
return 0;
@@ -304,7 +88,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;
}
@@ -333,13 +117,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(),