Add PDF printing support (issue #1478).

This commit is contained in:
Alexei Bykov
2015-03-24 18:40:08 +03:00
committed by Marshall Greenblatt
parent b6e5310bce
commit 85f83680d7
42 changed files with 1039 additions and 24 deletions

View File

@@ -16,6 +16,7 @@
#include "libcef_dll/cpptoc/request_context_cpptoc.h"
#include "libcef_dll/ctocpp/client_ctocpp.h"
#include "libcef_dll/ctocpp/navigation_entry_visitor_ctocpp.h"
#include "libcef_dll/ctocpp/pdf_print_callback_ctocpp.h"
#include "libcef_dll/ctocpp/run_file_dialog_callback_ctocpp.h"
#include "libcef_dll/transfer_util.h"
@@ -307,6 +308,36 @@ void CEF_CALLBACK browser_host_print(struct _cef_browser_host_t* self) {
CefBrowserHostCppToC::Get(self)->Print();
}
void CEF_CALLBACK browser_host_print_to_pdf(struct _cef_browser_host_t* self,
const cef_string_t* path, const struct _cef_pdf_print_settings_t* settings,
cef_pdf_print_callback_t* callback) {
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
DCHECK(self);
if (!self)
return;
// Verify param: path; type: string_byref_const
DCHECK(path);
if (!path)
return;
// Verify param: settings; type: struct_byref_const
DCHECK(settings);
if (!settings)
return;
// Unverified params: callback
// Translate param: settings; type: struct_byref_const
CefPdfPrintSettings settingsObj;
if (settings)
settingsObj.Set(*settings, false);
// Execute
CefBrowserHostCppToC::Get(self)->PrintToPDF(
CefString(path),
settingsObj,
CefPdfPrintCallbackCToCpp::Wrap(callback));
}
void CEF_CALLBACK browser_host_find(struct _cef_browser_host_t* self,
int identifier, const cef_string_t* searchText, int forward, int matchCase,
int findNext) {
@@ -881,6 +912,7 @@ CefBrowserHostCppToC::CefBrowserHostCppToC() {
GetStruct()->run_file_dialog = browser_host_run_file_dialog;
GetStruct()->start_download = browser_host_start_download;
GetStruct()->print = browser_host_print;
GetStruct()->print_to_pdf = browser_host_print_to_pdf;
GetStruct()->find = browser_host_find;
GetStruct()->stop_finding = browser_host_stop_finding;
GetStruct()->show_dev_tools = browser_host_show_dev_tools;

View File

@@ -0,0 +1,61 @@
// Copyright (c) 2015 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
//
// ---------------------------------------------------------------------------
//
// This file was generated by the CEF translator tool. If making changes by
// hand only do so within the body of existing method and function
// implementations. See the translator.README.txt file in the tools directory
// for more information.
//
#include "libcef_dll/cpptoc/pdf_print_callback_cpptoc.h"
namespace {
// MEMBER FUNCTIONS - Body may be edited by hand.
void CEF_CALLBACK pdf_print_callback_on_pdf_print_finished(
struct _cef_pdf_print_callback_t* self, const cef_string_t* path, int ok) {
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
DCHECK(self);
if (!self)
return;
// Verify param: path; type: string_byref_const
DCHECK(path);
if (!path)
return;
// Execute
CefPdfPrintCallbackCppToC::Get(self)->OnPdfPrintFinished(
CefString(path),
ok?true:false);
}
} // namespace
// CONSTRUCTOR - Do not edit by hand.
CefPdfPrintCallbackCppToC::CefPdfPrintCallbackCppToC() {
GetStruct()->on_pdf_print_finished = pdf_print_callback_on_pdf_print_finished;
}
template<> CefRefPtr<CefPdfPrintCallback> CefCppToC<CefPdfPrintCallbackCppToC,
CefPdfPrintCallback, cef_pdf_print_callback_t>::UnwrapDerived(
CefWrapperType type, cef_pdf_print_callback_t* s) {
NOTREACHED() << "Unexpected class type: " << type;
return NULL;
}
#ifndef NDEBUG
template<> base::AtomicRefCount CefCppToC<CefPdfPrintCallbackCppToC,
CefPdfPrintCallback, cef_pdf_print_callback_t>::DebugObjCt = 0;
#endif
template<> CefWrapperType CefCppToC<CefPdfPrintCallbackCppToC,
CefPdfPrintCallback, cef_pdf_print_callback_t>::kWrapperType =
WT_PDF_PRINT_CALLBACK;

View File

@@ -0,0 +1,37 @@
// Copyright (c) 2015 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
//
// ---------------------------------------------------------------------------
//
// This file was generated by the CEF translator tool. If making changes by
// hand only do so within the body of existing method and function
// implementations. See the translator.README.txt file in the tools directory
// for more information.
//
#ifndef CEF_LIBCEF_DLL_CPPTOC_PDF_PRINT_CALLBACK_CPPTOC_H_
#define CEF_LIBCEF_DLL_CPPTOC_PDF_PRINT_CALLBACK_CPPTOC_H_
#pragma once
#ifndef USING_CEF_SHARED
#pragma message("Warning: "__FILE__" may be accessed wrapper-side only")
#else // USING_CEF_SHARED
#include "include/cef_browser.h"
#include "include/capi/cef_browser_capi.h"
#include "include/cef_client.h"
#include "include/capi/cef_client_capi.h"
#include "libcef_dll/cpptoc/cpptoc.h"
// Wrap a C++ class with a C structure.
// This class may be instantiated and accessed wrapper-side only.
class CefPdfPrintCallbackCppToC
: public CefCppToC<CefPdfPrintCallbackCppToC, CefPdfPrintCallback,
cef_pdf_print_callback_t> {
public:
CefPdfPrintCallbackCppToC();
};
#endif // USING_CEF_SHARED
#endif // CEF_LIBCEF_DLL_CPPTOC_PDF_PRINT_CALLBACK_CPPTOC_H_

View File

@@ -104,6 +104,22 @@ void CEF_CALLBACK print_handler_on_print_reset(
CefPrintHandlerCppToC::Get(self)->OnPrintReset();
}
cef_size_t CEF_CALLBACK print_handler_get_pdf_paper_size(
struct _cef_print_handler_t* self, int device_units_per_inch) {
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
DCHECK(self);
if (!self)
return CefSize();
// Execute
cef_size_t _retval = CefPrintHandlerCppToC::Get(self)->GetPdfPaperSize(
device_units_per_inch);
// Return type: simple
return _retval;
}
} // namespace
@@ -114,6 +130,7 @@ CefPrintHandlerCppToC::CefPrintHandlerCppToC() {
GetStruct()->on_print_dialog = print_handler_on_print_dialog;
GetStruct()->on_print_job = print_handler_on_print_job;
GetStruct()->on_print_reset = print_handler_on_print_reset;
GetStruct()->get_pdf_paper_size = print_handler_get_pdf_paper_size;
}
template<> CefRefPtr<CefPrintHandler> CefCppToC<CefPrintHandlerCppToC,

View File

@@ -12,6 +12,7 @@
#include "libcef_dll/cpptoc/client_cpptoc.h"
#include "libcef_dll/cpptoc/navigation_entry_visitor_cpptoc.h"
#include "libcef_dll/cpptoc/pdf_print_callback_cpptoc.h"
#include "libcef_dll/cpptoc/run_file_dialog_callback_cpptoc.h"
#include "libcef_dll/ctocpp/browser_ctocpp.h"
#include "libcef_dll/ctocpp/browser_host_ctocpp.h"
@@ -265,6 +266,28 @@ void CefBrowserHostCToCpp::Print() {
_struct->print(_struct);
}
void CefBrowserHostCToCpp::PrintToPDF(const CefString& path,
const CefPdfPrintSettings& settings,
CefRefPtr<CefPdfPrintCallback> callback) {
cef_browser_host_t* _struct = GetStruct();
if (CEF_MEMBER_MISSING(_struct, print_to_pdf))
return;
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Verify param: path; type: string_byref_const
DCHECK(!path.empty());
if (path.empty())
return;
// Unverified params: callback
// Execute
_struct->print_to_pdf(_struct,
path.GetStruct(),
&settings,
CefPdfPrintCallbackCppToC::Wrap(callback));
}
void CefBrowserHostCToCpp::Find(int identifier, const CefString& searchText,
bool forward, bool matchCase, bool findNext) {
cef_browser_host_t* _struct = GetStruct();

View File

@@ -50,6 +50,8 @@ class CefBrowserHostCToCpp
CefRefPtr<CefRunFileDialogCallback> callback) OVERRIDE;
void StartDownload(const CefString& url) OVERRIDE;
void Print() OVERRIDE;
void PrintToPDF(const CefString& path, const CefPdfPrintSettings& settings,
CefRefPtr<CefPdfPrintCallback> callback) OVERRIDE;
void Find(int identifier, const CefString& searchText, bool forward,
bool matchCase, bool findNext) OVERRIDE;
void StopFinding(bool clearSelection) OVERRIDE;

View File

@@ -0,0 +1,57 @@
// Copyright (c) 2015 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
//
// ---------------------------------------------------------------------------
//
// This file was generated by the CEF translator tool. If making changes by
// hand only do so within the body of existing method and function
// implementations. See the translator.README.txt file in the tools directory
// for more information.
//
#include "libcef_dll/ctocpp/pdf_print_callback_ctocpp.h"
// VIRTUAL METHODS - Body may be edited by hand.
void CefPdfPrintCallbackCToCpp::OnPdfPrintFinished(const CefString& path,
bool ok) {
cef_pdf_print_callback_t* _struct = GetStruct();
if (CEF_MEMBER_MISSING(_struct, on_pdf_print_finished))
return;
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Verify param: path; type: string_byref_const
DCHECK(!path.empty());
if (path.empty())
return;
// Execute
_struct->on_pdf_print_finished(_struct,
path.GetStruct(),
ok);
}
// CONSTRUCTOR - Do not edit by hand.
CefPdfPrintCallbackCToCpp::CefPdfPrintCallbackCToCpp() {
}
template<> cef_pdf_print_callback_t* CefCToCpp<CefPdfPrintCallbackCToCpp,
CefPdfPrintCallback, cef_pdf_print_callback_t>::UnwrapDerived(
CefWrapperType type, CefPdfPrintCallback* c) {
NOTREACHED() << "Unexpected class type: " << type;
return NULL;
}
#ifndef NDEBUG
template<> base::AtomicRefCount CefCToCpp<CefPdfPrintCallbackCToCpp,
CefPdfPrintCallback, cef_pdf_print_callback_t>::DebugObjCt = 0;
#endif
template<> CefWrapperType CefCToCpp<CefPdfPrintCallbackCToCpp,
CefPdfPrintCallback, cef_pdf_print_callback_t>::kWrapperType =
WT_PDF_PRINT_CALLBACK;

View File

@@ -0,0 +1,40 @@
// Copyright (c) 2015 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
//
// ---------------------------------------------------------------------------
//
// This file was generated by the CEF translator tool. If making changes by
// hand only do so within the body of existing method and function
// implementations. See the translator.README.txt file in the tools directory
// for more information.
//
#ifndef CEF_LIBCEF_DLL_CTOCPP_PDF_PRINT_CALLBACK_CTOCPP_H_
#define CEF_LIBCEF_DLL_CTOCPP_PDF_PRINT_CALLBACK_CTOCPP_H_
#pragma once
#ifndef BUILDING_CEF_SHARED
#pragma message("Warning: "__FILE__" may be accessed DLL-side only")
#else // BUILDING_CEF_SHARED
#include "include/cef_browser.h"
#include "include/capi/cef_browser_capi.h"
#include "include/cef_client.h"
#include "include/capi/cef_client_capi.h"
#include "libcef_dll/ctocpp/ctocpp.h"
// Wrap a C structure with a C++ class.
// This class may be instantiated and accessed DLL-side only.
class CefPdfPrintCallbackCToCpp
: public CefCToCpp<CefPdfPrintCallbackCToCpp, CefPdfPrintCallback,
cef_pdf_print_callback_t> {
public:
CefPdfPrintCallbackCToCpp();
// CefPdfPrintCallback methods.
void OnPdfPrintFinished(const CefString& path, bool ok) override;
};
#endif // BUILDING_CEF_SHARED
#endif // CEF_LIBCEF_DLL_CTOCPP_PDF_PRINT_CALLBACK_CTOCPP_H_

View File

@@ -101,6 +101,21 @@ void CefPrintHandlerCToCpp::OnPrintReset() {
_struct->on_print_reset(_struct);
}
CefSize CefPrintHandlerCToCpp::GetPdfPaperSize(int device_units_per_inch) {
cef_print_handler_t* _struct = GetStruct();
if (CEF_MEMBER_MISSING(_struct, get_pdf_paper_size))
return CefSize();
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Execute
cef_size_t _retval = _struct->get_pdf_paper_size(_struct,
device_units_per_inch);
// Return type: simple
return _retval;
}
// CONSTRUCTOR - Do not edit by hand.

View File

@@ -39,6 +39,7 @@ class CefPrintHandlerCToCpp
const CefString& pdf_file_path,
CefRefPtr<CefPrintJobCallback> callback) override;
void OnPrintReset() override;
CefSize GetPdfPaperSize(int device_units_per_inch) override;
};
#endif // BUILDING_CEF_SHARED

View File

@@ -95,6 +95,7 @@
#include "libcef_dll/ctocpp/life_span_handler_ctocpp.h"
#include "libcef_dll/ctocpp/load_handler_ctocpp.h"
#include "libcef_dll/ctocpp/navigation_entry_visitor_ctocpp.h"
#include "libcef_dll/ctocpp/pdf_print_callback_ctocpp.h"
#include "libcef_dll/ctocpp/print_handler_ctocpp.h"
#include "libcef_dll/ctocpp/read_handler_ctocpp.h"
#include "libcef_dll/ctocpp/render_handler_ctocpp.h"
@@ -232,6 +233,7 @@ CEF_EXPORT void cef_shutdown() {
DCHECK(base::AtomicRefCountIsZero(&CefNavigationEntryCppToC::DebugObjCt));
DCHECK(base::AtomicRefCountIsZero(
&CefNavigationEntryVisitorCToCpp::DebugObjCt));
DCHECK(base::AtomicRefCountIsZero(&CefPdfPrintCallbackCToCpp::DebugObjCt));
DCHECK(base::AtomicRefCountIsZero(&CefPrintDialogCallbackCppToC::DebugObjCt));
DCHECK(base::AtomicRefCountIsZero(&CefPrintHandlerCToCpp::DebugObjCt));
DCHECK(base::AtomicRefCountIsZero(&CefPrintJobCallbackCppToC::DebugObjCt));

View File

@@ -54,6 +54,7 @@
#include "libcef_dll/cpptoc/life_span_handler_cpptoc.h"
#include "libcef_dll/cpptoc/load_handler_cpptoc.h"
#include "libcef_dll/cpptoc/navigation_entry_visitor_cpptoc.h"
#include "libcef_dll/cpptoc/pdf_print_callback_cpptoc.h"
#include "libcef_dll/cpptoc/print_handler_cpptoc.h"
#include "libcef_dll/cpptoc/read_handler_cpptoc.h"
#include "libcef_dll/cpptoc/render_handler_cpptoc.h"
@@ -224,6 +225,7 @@ CEF_GLOBAL void CefShutdown() {
DCHECK(base::AtomicRefCountIsZero(&CefNavigationEntryCToCpp::DebugObjCt));
DCHECK(base::AtomicRefCountIsZero(
&CefNavigationEntryVisitorCppToC::DebugObjCt));
DCHECK(base::AtomicRefCountIsZero(&CefPdfPrintCallbackCppToC::DebugObjCt));
DCHECK(base::AtomicRefCountIsZero(&CefPrintDialogCallbackCToCpp::DebugObjCt));
DCHECK(base::AtomicRefCountIsZero(&CefPrintHandlerCppToC::DebugObjCt));
DCHECK(base::AtomicRefCountIsZero(&CefPrintJobCallbackCToCpp::DebugObjCt));

View File

@@ -60,6 +60,7 @@ enum CefWrapperType {
WT_MENU_MODEL,
WT_NAVIGATION_ENTRY,
WT_NAVIGATION_ENTRY_VISITOR,
WT_PDF_PRINT_CALLBACK,
WT_POST_DATA,
WT_POST_DATA_ELEMENT,
WT_PRINT_DIALOG_CALLBACK,