Linux: Pass CefBrowser to CefPrintHandler callbacks (issue #2196)

This commit is contained in:
Marshall Greenblatt 2017-06-15 08:27:56 -07:00
parent 56ba4400a2
commit 141ab16dcd
10 changed files with 503 additions and 285 deletions

View File

@ -33,7 +33,7 @@
// by hand. See the translator.README.txt file in the tools directory for // by hand. See the translator.README.txt file in the tools directory for
// more information. // more information.
// //
// $hash=e8f6bdc822cf4f5c32b22ba8b5cacb25823d8971$ // $hash=ed78ca41d62dfc0cdb52828dcf795617c4e231a7$
// //
#ifndef CEF_INCLUDE_CAPI_CEF_PRINT_HANDLER_CAPI_H_ #ifndef CEF_INCLUDE_CAPI_CEF_PRINT_HANDLER_CAPI_H_
@ -85,8 +85,9 @@ typedef struct _cef_print_job_callback_t {
} cef_print_job_callback_t; } cef_print_job_callback_t;
/// ///
// Implement this structure to handle printing on Linux. The functions of this // Implement this structure to handle printing on Linux. Each browser will have
// structure will be called on the browser process UI thread. // only one print job in progress at a time. The functions of this structure
// will be called on the browser process UI thread.
/// ///
typedef struct _cef_print_handler_t { typedef struct _cef_print_handler_t {
/// ///
@ -109,6 +110,7 @@ typedef struct _cef_print_handler_t {
// reference to |settings| outside of this callback. // reference to |settings| outside of this callback.
/// ///
void(CEF_CALLBACK* on_print_settings)(struct _cef_print_handler_t* self, void(CEF_CALLBACK* on_print_settings)(struct _cef_print_handler_t* self,
struct _cef_browser_t* browser,
struct _cef_print_settings_t* settings, struct _cef_print_settings_t* settings,
int get_defaults); int get_defaults);
@ -119,6 +121,7 @@ typedef struct _cef_print_handler_t {
/// ///
int(CEF_CALLBACK* on_print_dialog)( int(CEF_CALLBACK* on_print_dialog)(
struct _cef_print_handler_t* self, struct _cef_print_handler_t* self,
struct _cef_browser_t* browser,
int has_selection, int has_selection,
struct _cef_print_dialog_callback_t* callback); struct _cef_print_dialog_callback_t* callback);
@ -128,6 +131,7 @@ typedef struct _cef_print_handler_t {
// the job immediately. // the job immediately.
/// ///
int(CEF_CALLBACK* on_print_job)(struct _cef_print_handler_t* self, int(CEF_CALLBACK* on_print_job)(struct _cef_print_handler_t* self,
struct _cef_browser_t* browser,
const cef_string_t* document_name, const cef_string_t* document_name,
const cef_string_t* pdf_file_path, const cef_string_t* pdf_file_path,
struct _cef_print_job_callback_t* callback); struct _cef_print_job_callback_t* callback);
@ -135,7 +139,8 @@ typedef struct _cef_print_handler_t {
/// ///
// Reset client state related to printing. // Reset client state related to printing.
/// ///
void(CEF_CALLBACK* on_print_reset)(struct _cef_print_handler_t* self); void(CEF_CALLBACK* on_print_reset)(struct _cef_print_handler_t* self,
struct _cef_browser_t* browser);
/// ///
// Return the PDF paper size in device units. Used in combination with // Return the PDF paper size in device units. Used in combination with
@ -143,6 +148,7 @@ typedef struct _cef_print_handler_t {
/// ///
cef_size_t(CEF_CALLBACK* get_pdf_paper_size)( cef_size_t(CEF_CALLBACK* get_pdf_paper_size)(
struct _cef_print_handler_t* self, struct _cef_print_handler_t* self,
struct _cef_browser_t* browser,
int device_units_per_inch); int device_units_per_inch);
} cef_print_handler_t; } cef_print_handler_t;

View File

@ -75,8 +75,9 @@ class CefPrintJobCallback : public virtual CefBaseRefCounted {
}; };
/// ///
// Implement this interface to handle printing on Linux. The methods of this // Implement this interface to handle printing on Linux. Each browser will have
// class will be called on the browser process UI thread. // only one print job in progress at a time. The methods of this class will be
// called on the browser process UI thread.
/// ///
/*--cef(source=client)--*/ /*--cef(source=client)--*/
class CefPrintHandler : public virtual CefBaseRefCounted { class CefPrintHandler : public virtual CefBaseRefCounted {
@ -96,7 +97,8 @@ class CefPrintHandler : public virtual CefBaseRefCounted {
// reference to |settings| outside of this callback. // reference to |settings| outside of this callback.
/// ///
/*--cef()--*/ /*--cef()--*/
virtual void OnPrintSettings(CefRefPtr<CefPrintSettings> settings, virtual void OnPrintSettings(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefPrintSettings> settings,
bool get_defaults) = 0; bool get_defaults) = 0;
/// ///
@ -105,7 +107,8 @@ class CefPrintHandler : public virtual CefBaseRefCounted {
// printing immediately. // printing immediately.
/// ///
/*--cef()--*/ /*--cef()--*/
virtual bool OnPrintDialog(bool has_selection, virtual bool OnPrintDialog(CefRefPtr<CefBrowser> browser,
bool has_selection,
CefRefPtr<CefPrintDialogCallback> callback) = 0; CefRefPtr<CefPrintDialogCallback> callback) = 0;
/// ///
@ -114,7 +117,8 @@ class CefPrintHandler : public virtual CefBaseRefCounted {
// immediately. // immediately.
/// ///
/*--cef()--*/ /*--cef()--*/
virtual bool OnPrintJob(const CefString& document_name, virtual bool OnPrintJob(CefRefPtr<CefBrowser> browser,
const CefString& document_name,
const CefString& pdf_file_path, const CefString& pdf_file_path,
CefRefPtr<CefPrintJobCallback> callback) = 0; CefRefPtr<CefPrintJobCallback> callback) = 0;
@ -122,14 +126,15 @@ class CefPrintHandler : public virtual CefBaseRefCounted {
// Reset client state related to printing. // Reset client state related to printing.
/// ///
/*--cef()--*/ /*--cef()--*/
virtual void OnPrintReset() = 0; virtual void OnPrintReset(CefRefPtr<CefBrowser> browser) = 0;
/// ///
// Return the PDF paper size in device units. Used in combination with // Return the PDF paper size in device units. Used in combination with
// CefBrowserHost::PrintToPDF(). // CefBrowserHost::PrintToPDF().
/// ///
/*--cef()--*/ /*--cef()--*/
virtual CefSize GetPdfPaperSize(int device_units_per_inch) { virtual CefSize GetPdfPaperSize(CefRefPtr<CefBrowser> browser,
int device_units_per_inch) {
return CefSize(); return CefSize();
} }
}; };

View File

@ -113,9 +113,12 @@ gfx::Size CefPrintDialogLinux::GetPdfPaperSize(
if (browser_handler.get()) { if (browser_handler.get()) {
CefRefPtr<CefPrintHandler> handler = browser_handler->GetPrintHandler(); CefRefPtr<CefPrintHandler> handler = browser_handler->GetPrintHandler();
if (handler.get()) { if (handler.get()) {
CefRefPtr<CefBrowserHostImpl> browser =
extensions::GetOwnerBrowserForFrame(
context->render_process_id(), context->render_frame_id(), NULL);
const printing::PrintSettings& settings = context->settings(); const printing::PrintSettings& settings = context->settings();
CefSize cef_size = CefSize cef_size = handler->GetPdfPaperSize(
handler->GetPdfPaperSize(settings.device_units_per_inch()); browser.get(), settings.device_units_per_inch());
size.SetSize(cef_size.width, cef_size.height); size.SetSize(cef_size.width, cef_size.height);
} }
} }
@ -187,10 +190,14 @@ void CefPrintDialogLinux::ShowDialog(
callback_ = callback; callback_ = callback;
CefRefPtr<CefBrowserHostImpl> browser = extensions::GetOwnerBrowserForFrame(
context_->render_process_id(), context_->render_frame_id(), NULL);
CefRefPtr<CefPrintDialogCallbackImpl> callback_impl( CefRefPtr<CefPrintDialogCallbackImpl> callback_impl(
new CefPrintDialogCallbackImpl(this)); new CefPrintDialogCallbackImpl(this));
if (!handler_->OnPrintDialog(has_selection, callback_impl.get())) { if (!handler_->OnPrintDialog(browser.get(), has_selection,
callback_impl.get())) {
callback_impl->Disconnect(); callback_impl->Disconnect();
OnPrintCancel(); OnPrintCancel();
} }
@ -253,7 +260,10 @@ void CefPrintDialogLinux::SetHandler() {
void CefPrintDialogLinux::ReleaseHandler() { void CefPrintDialogLinux::ReleaseHandler() {
if (handler_.get()) { if (handler_.get()) {
handler_->OnPrintReset(); CefRefPtr<CefBrowserHostImpl> browser = extensions::GetOwnerBrowserForFrame(
context_->render_process_id(), context_->render_frame_id(), NULL);
handler_->OnPrintReset(browser.get());
handler_ = NULL; handler_ = NULL;
} }
} }
@ -266,9 +276,12 @@ bool CefPrintDialogLinux::UpdateSettings(printing::PrintSettings* settings,
if (!handler_.get()) if (!handler_.get())
return false; return false;
CefRefPtr<CefBrowserHostImpl> browser = extensions::GetOwnerBrowserForFrame(
context_->render_process_id(), context_->render_frame_id(), NULL);
CefRefPtr<CefPrintSettingsImpl> settings_impl( CefRefPtr<CefPrintSettingsImpl> settings_impl(
new CefPrintSettingsImpl(settings, false, false)); new CefPrintSettingsImpl(settings, false, false));
handler_->OnPrintSettings(settings_impl.get(), get_defaults); handler_->OnPrintSettings(browser.get(), settings_impl.get(), get_defaults);
settings_impl->Detach(NULL); settings_impl->Detach(NULL);
context_->InitWithSettings(*settings); context_->InitWithSettings(*settings);
@ -284,10 +297,13 @@ void CefPrintDialogLinux::SendDocumentToPrinter(
return; return;
} }
CefRefPtr<CefBrowserHostImpl> browser = extensions::GetOwnerBrowserForFrame(
context_->render_process_id(), context_->render_frame_id(), NULL);
CefRefPtr<CefPrintJobCallbackImpl> callback_impl( CefRefPtr<CefPrintJobCallbackImpl> callback_impl(
new CefPrintJobCallbackImpl(this)); new CefPrintJobCallbackImpl(this));
if (!handler_->OnPrintJob(document_name, path_to_pdf_.value(), if (!handler_->OnPrintJob(browser.get(), document_name, path_to_pdf_.value(),
callback_impl.get())) { callback_impl.get())) {
callback_impl->Disconnect(); callback_impl->Disconnect();
OnJobCompleted(); OnJobCompleted();

View File

@ -9,7 +9,7 @@
// implementations. See the translator.README.txt file in the tools directory // implementations. See the translator.README.txt file in the tools directory
// for more information. // for more information.
// //
// $hash=e2a9910119dcf81b74624588d222c7781e3fdc9a$ // $hash=80fc869800987a74f4c6e4eb202f0f5201126a76$
// //
#include "libcef_dll/cpptoc/print_handler_cpptoc.h" #include "libcef_dll/cpptoc/print_handler_cpptoc.h"
@ -42,6 +42,7 @@ print_handler_on_print_start(struct _cef_print_handler_t* self,
void CEF_CALLBACK void CEF_CALLBACK
print_handler_on_print_settings(struct _cef_print_handler_t* self, print_handler_on_print_settings(struct _cef_print_handler_t* self,
cef_browser_t* browser,
struct _cef_print_settings_t* settings, struct _cef_print_settings_t* settings,
int get_defaults) { int get_defaults) {
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
@ -49,6 +50,10 @@ print_handler_on_print_settings(struct _cef_print_handler_t* self,
DCHECK(self); DCHECK(self);
if (!self) if (!self)
return; return;
// Verify param: browser; type: refptr_diff
DCHECK(browser);
if (!browser)
return;
// Verify param: settings; type: refptr_diff // Verify param: settings; type: refptr_diff
DCHECK(settings); DCHECK(settings);
if (!settings) if (!settings)
@ -56,11 +61,13 @@ print_handler_on_print_settings(struct _cef_print_handler_t* self,
// Execute // Execute
CefPrintHandlerCppToC::Get(self)->OnPrintSettings( CefPrintHandlerCppToC::Get(self)->OnPrintSettings(
CefPrintSettingsCToCpp::Wrap(settings), get_defaults ? true : false); CefBrowserCToCpp::Wrap(browser), CefPrintSettingsCToCpp::Wrap(settings),
get_defaults ? true : false);
} }
int CEF_CALLBACK int CEF_CALLBACK
print_handler_on_print_dialog(struct _cef_print_handler_t* self, print_handler_on_print_dialog(struct _cef_print_handler_t* self,
cef_browser_t* browser,
int has_selection, int has_selection,
cef_print_dialog_callback_t* callback) { cef_print_dialog_callback_t* callback) {
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
@ -68,6 +75,10 @@ print_handler_on_print_dialog(struct _cef_print_handler_t* self,
DCHECK(self); DCHECK(self);
if (!self) if (!self)
return 0; return 0;
// Verify param: browser; type: refptr_diff
DCHECK(browser);
if (!browser)
return 0;
// Verify param: callback; type: refptr_diff // Verify param: callback; type: refptr_diff
DCHECK(callback); DCHECK(callback);
if (!callback) if (!callback)
@ -75,7 +86,7 @@ print_handler_on_print_dialog(struct _cef_print_handler_t* self,
// Execute // Execute
bool _retval = CefPrintHandlerCppToC::Get(self)->OnPrintDialog( bool _retval = CefPrintHandlerCppToC::Get(self)->OnPrintDialog(
has_selection ? true : false, CefBrowserCToCpp::Wrap(browser), has_selection ? true : false,
CefPrintDialogCallbackCToCpp::Wrap(callback)); CefPrintDialogCallbackCToCpp::Wrap(callback));
// Return type: bool // Return type: bool
@ -84,6 +95,7 @@ print_handler_on_print_dialog(struct _cef_print_handler_t* self,
int CEF_CALLBACK int CEF_CALLBACK
print_handler_on_print_job(struct _cef_print_handler_t* self, print_handler_on_print_job(struct _cef_print_handler_t* self,
cef_browser_t* browser,
const cef_string_t* document_name, const cef_string_t* document_name,
const cef_string_t* pdf_file_path, const cef_string_t* pdf_file_path,
cef_print_job_callback_t* callback) { cef_print_job_callback_t* callback) {
@ -92,6 +104,10 @@ print_handler_on_print_job(struct _cef_print_handler_t* self,
DCHECK(self); DCHECK(self);
if (!self) if (!self)
return 0; return 0;
// Verify param: browser; type: refptr_diff
DCHECK(browser);
if (!browser)
return 0;
// Verify param: document_name; type: string_byref_const // Verify param: document_name; type: string_byref_const
DCHECK(document_name); DCHECK(document_name);
if (!document_name) if (!document_name)
@ -107,37 +123,48 @@ print_handler_on_print_job(struct _cef_print_handler_t* self,
// Execute // Execute
bool _retval = CefPrintHandlerCppToC::Get(self)->OnPrintJob( bool _retval = CefPrintHandlerCppToC::Get(self)->OnPrintJob(
CefString(document_name), CefString(pdf_file_path), CefBrowserCToCpp::Wrap(browser), CefString(document_name),
CefPrintJobCallbackCToCpp::Wrap(callback)); CefString(pdf_file_path), CefPrintJobCallbackCToCpp::Wrap(callback));
// Return type: bool // Return type: bool
return _retval; return _retval;
} }
void CEF_CALLBACK void CEF_CALLBACK
print_handler_on_print_reset(struct _cef_print_handler_t* self) { print_handler_on_print_reset(struct _cef_print_handler_t* self,
cef_browser_t* browser) {
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
DCHECK(self); DCHECK(self);
if (!self) if (!self)
return; return;
// Verify param: browser; type: refptr_diff
DCHECK(browser);
if (!browser)
return;
// Execute // Execute
CefPrintHandlerCppToC::Get(self)->OnPrintReset(); CefPrintHandlerCppToC::Get(self)->OnPrintReset(
CefBrowserCToCpp::Wrap(browser));
} }
cef_size_t CEF_CALLBACK cef_size_t CEF_CALLBACK
print_handler_get_pdf_paper_size(struct _cef_print_handler_t* self, print_handler_get_pdf_paper_size(struct _cef_print_handler_t* self,
cef_browser_t* browser,
int device_units_per_inch) { int device_units_per_inch) {
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
DCHECK(self); DCHECK(self);
if (!self) if (!self)
return CefSize(); return CefSize();
// Verify param: browser; type: refptr_diff
DCHECK(browser);
if (!browser)
return CefSize();
// Execute // Execute
cef_size_t _retval = cef_size_t _retval = CefPrintHandlerCppToC::Get(self)->GetPdfPaperSize(
CefPrintHandlerCppToC::Get(self)->GetPdfPaperSize(device_units_per_inch); CefBrowserCToCpp::Wrap(browser), device_units_per_inch);
// Return type: simple // Return type: simple
return _retval; return _retval;

View File

@ -9,7 +9,7 @@
// implementations. See the translator.README.txt file in the tools directory // implementations. See the translator.README.txt file in the tools directory
// for more information. // for more information.
// //
// $hash=0749b78aaf8f69cd706962477d4d0241c93cf333$ // $hash=80679bfc067e7564eadb691876081c4176b04c4f$
// //
#include "libcef_dll/ctocpp/print_handler_ctocpp.h" #include "libcef_dll/ctocpp/print_handler_ctocpp.h"
@ -37,6 +37,7 @@ void CefPrintHandlerCToCpp::OnPrintStart(CefRefPtr<CefBrowser> browser) {
} }
void CefPrintHandlerCToCpp::OnPrintSettings( void CefPrintHandlerCToCpp::OnPrintSettings(
CefRefPtr<CefBrowser> browser,
CefRefPtr<CefPrintSettings> settings, CefRefPtr<CefPrintSettings> settings,
bool get_defaults) { bool get_defaults) {
cef_print_handler_t* _struct = GetStruct(); cef_print_handler_t* _struct = GetStruct();
@ -45,17 +46,23 @@ void CefPrintHandlerCToCpp::OnPrintSettings(
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Verify param: browser; type: refptr_diff
DCHECK(browser.get());
if (!browser.get())
return;
// Verify param: settings; type: refptr_diff // Verify param: settings; type: refptr_diff
DCHECK(settings.get()); DCHECK(settings.get());
if (!settings.get()) if (!settings.get())
return; return;
// Execute // Execute
_struct->on_print_settings(_struct, CefPrintSettingsCppToC::Wrap(settings), _struct->on_print_settings(_struct, CefBrowserCppToC::Wrap(browser),
CefPrintSettingsCppToC::Wrap(settings),
get_defaults); get_defaults);
} }
bool CefPrintHandlerCToCpp::OnPrintDialog( bool CefPrintHandlerCToCpp::OnPrintDialog(
CefRefPtr<CefBrowser> browser,
bool has_selection, bool has_selection,
CefRefPtr<CefPrintDialogCallback> callback) { CefRefPtr<CefPrintDialogCallback> callback) {
cef_print_handler_t* _struct = GetStruct(); cef_print_handler_t* _struct = GetStruct();
@ -64,6 +71,10 @@ bool CefPrintHandlerCToCpp::OnPrintDialog(
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Verify param: browser; type: refptr_diff
DCHECK(browser.get());
if (!browser.get())
return false;
// Verify param: callback; type: refptr_diff // Verify param: callback; type: refptr_diff
DCHECK(callback.get()); DCHECK(callback.get());
if (!callback.get()) if (!callback.get())
@ -71,13 +82,15 @@ bool CefPrintHandlerCToCpp::OnPrintDialog(
// Execute // Execute
int _retval = _struct->on_print_dialog( int _retval = _struct->on_print_dialog(
_struct, has_selection, CefPrintDialogCallbackCppToC::Wrap(callback)); _struct, CefBrowserCppToC::Wrap(browser), has_selection,
CefPrintDialogCallbackCppToC::Wrap(callback));
// Return type: bool // Return type: bool
return _retval ? true : false; return _retval ? true : false;
} }
bool CefPrintHandlerCToCpp::OnPrintJob( bool CefPrintHandlerCToCpp::OnPrintJob(
CefRefPtr<CefBrowser> browser,
const CefString& document_name, const CefString& document_name,
const CefString& pdf_file_path, const CefString& pdf_file_path,
CefRefPtr<CefPrintJobCallback> callback) { CefRefPtr<CefPrintJobCallback> callback) {
@ -87,6 +100,10 @@ bool CefPrintHandlerCToCpp::OnPrintJob(
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Verify param: browser; type: refptr_diff
DCHECK(browser.get());
if (!browser.get())
return false;
// Verify param: document_name; type: string_byref_const // Verify param: document_name; type: string_byref_const
DCHECK(!document_name.empty()); DCHECK(!document_name.empty());
if (document_name.empty()) if (document_name.empty())
@ -102,34 +119,45 @@ bool CefPrintHandlerCToCpp::OnPrintJob(
// Execute // Execute
int _retval = _struct->on_print_job( int _retval = _struct->on_print_job(
_struct, document_name.GetStruct(), pdf_file_path.GetStruct(), _struct, CefBrowserCppToC::Wrap(browser), document_name.GetStruct(),
CefPrintJobCallbackCppToC::Wrap(callback)); pdf_file_path.GetStruct(), CefPrintJobCallbackCppToC::Wrap(callback));
// Return type: bool // Return type: bool
return _retval ? true : false; return _retval ? true : false;
} }
void CefPrintHandlerCToCpp::OnPrintReset() { void CefPrintHandlerCToCpp::OnPrintReset(CefRefPtr<CefBrowser> browser) {
cef_print_handler_t* _struct = GetStruct(); cef_print_handler_t* _struct = GetStruct();
if (CEF_MEMBER_MISSING(_struct, on_print_reset)) if (CEF_MEMBER_MISSING(_struct, on_print_reset))
return; return;
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Verify param: browser; type: refptr_diff
DCHECK(browser.get());
if (!browser.get())
return;
// Execute // Execute
_struct->on_print_reset(_struct); _struct->on_print_reset(_struct, CefBrowserCppToC::Wrap(browser));
} }
CefSize CefPrintHandlerCToCpp::GetPdfPaperSize(int device_units_per_inch) { CefSize CefPrintHandlerCToCpp::GetPdfPaperSize(CefRefPtr<CefBrowser> browser,
int device_units_per_inch) {
cef_print_handler_t* _struct = GetStruct(); cef_print_handler_t* _struct = GetStruct();
if (CEF_MEMBER_MISSING(_struct, get_pdf_paper_size)) if (CEF_MEMBER_MISSING(_struct, get_pdf_paper_size))
return CefSize(); return CefSize();
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Verify param: browser; type: refptr_diff
DCHECK(browser.get());
if (!browser.get())
return CefSize();
// Execute // Execute
cef_size_t _retval = cef_size_t _retval = _struct->get_pdf_paper_size(
_struct->get_pdf_paper_size(_struct, device_units_per_inch); _struct, CefBrowserCppToC::Wrap(browser), device_units_per_inch);
// Return type: simple // Return type: simple
return _retval; return _retval;

View File

@ -9,7 +9,7 @@
// implementations. See the translator.README.txt file in the tools directory // implementations. See the translator.README.txt file in the tools directory
// for more information. // for more information.
// //
// $hash=104e754c5019270e7bd700c6b979891f1275f9a7$ // $hash=1a2adb6e9cbbe96253cc997312e60ca330dc4de6$
// //
#ifndef CEF_LIBCEF_DLL_CTOCPP_PRINT_HANDLER_CTOCPP_H_ #ifndef CEF_LIBCEF_DLL_CTOCPP_PRINT_HANDLER_CTOCPP_H_
@ -34,15 +34,19 @@ class CefPrintHandlerCToCpp : public CefCToCppRefCounted<CefPrintHandlerCToCpp,
// CefPrintHandler methods. // CefPrintHandler methods.
void OnPrintStart(CefRefPtr<CefBrowser> browser) override; void OnPrintStart(CefRefPtr<CefBrowser> browser) override;
void OnPrintSettings(CefRefPtr<CefPrintSettings> settings, void OnPrintSettings(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefPrintSettings> settings,
bool get_defaults) override; bool get_defaults) override;
bool OnPrintDialog(bool has_selection, bool OnPrintDialog(CefRefPtr<CefBrowser> browser,
bool has_selection,
CefRefPtr<CefPrintDialogCallback> callback) override; CefRefPtr<CefPrintDialogCallback> callback) override;
bool OnPrintJob(const CefString& document_name, bool OnPrintJob(CefRefPtr<CefBrowser> browser,
const CefString& document_name,
const CefString& pdf_file_path, const CefString& pdf_file_path,
CefRefPtr<CefPrintJobCallback> callback) override; CefRefPtr<CefPrintJobCallback> callback) override;
void OnPrintReset() override; void OnPrintReset(CefRefPtr<CefBrowser> browser) override;
CefSize GetPdfPaperSize(int device_units_per_inch) override; CefSize GetPdfPaperSize(CefRefPtr<CefBrowser> browser,
int device_units_per_inch) override;
}; };
#endif // CEF_LIBCEF_DLL_CTOCPP_PRINT_HANDLER_CTOCPP_H_ #endif // CEF_LIBCEF_DLL_CTOCPP_PRINT_HANDLER_CTOCPP_H_

View File

@ -298,4 +298,9 @@ patches = [
# https://bitbucket.org/chromiumembedded/cef/issues/2015 # https://bitbucket.org/chromiumembedded/cef/issues/2015
'name': 'webkit_plugin_info_2015', 'name': 'webkit_plugin_info_2015',
}, },
{
# Linux: Attach routing IDs to PrintingContext.
# https://bitbucket.org/chromiumembedded/cef/issues/2196
'name': 'printing_context_2196',
},
] ]

View File

@ -0,0 +1,41 @@
diff --git chrome/browser/printing/print_job_worker.cc chrome/browser/printing/print_job_worker.cc
index d06b61a..f41f848 100644
--- chrome/browser/printing/print_job_worker.cc
+++ chrome/browser/printing/print_job_worker.cc
@@ -121,6 +121,7 @@ PrintJobWorker::PrintJobWorker(int render_process_id,
printing_context_delegate_ = base::MakeUnique<PrintingContextDelegate>(
render_process_id, render_frame_id);
printing_context_ = PrintingContext::Create(printing_context_delegate_.get());
+ printing_context_->set_render_ids(render_process_id, render_frame_id);
}
PrintJobWorker::~PrintJobWorker() {
diff --git printing/printing_context.h printing/printing_context.h
index 7054654..ed5b664 100644
--- printing/printing_context.h
+++ printing/printing_context.h
@@ -127,6 +127,13 @@ class PRINTING_EXPORT PrintingContext {
int job_id() const { return job_id_; }
+ void set_render_ids(int render_process_id, int render_frame_id) {
+ render_process_id_ = render_process_id;
+ render_frame_id_ = render_frame_id;
+ }
+ int render_process_id() const { return render_process_id_; }
+ int render_frame_id() const { return render_frame_id_; }
+
protected:
explicit PrintingContext(Delegate* delegate);
@@ -151,6 +158,10 @@ class PRINTING_EXPORT PrintingContext {
// The job id for the current job. The value is 0 if no jobs are active.
int job_id_;
+ // Routing IDs for the frame that owns this object.
+ int render_process_id_ = 0;
+ int render_frame_id_ = 0;
+
private:
DISALLOW_COPY_AND_ASSIGN(PrintingContext);
};

View File

@ -7,10 +7,15 @@
#include <vector> #include <vector>
#include <gtk/gtk.h>
#include <gtk/gtkunixprint.h>
#include "include/base/cef_logging.h" #include "include/base/cef_logging.h"
#include "include/base/cef_macros.h" #include "include/base/cef_macros.h"
#include "include/wrapper/cef_helpers.h" #include "include/wrapper/cef_helpers.h"
#include "tests/cefclient/browser/root_window.h"
namespace client { namespace client {
namespace { namespace {
@ -267,20 +272,42 @@ void InitPrintSettings(GtkPrintSettings* settings,
} // namespace } // namespace
ClientPrintHandlerGtk::ClientPrintHandlerGtk() struct ClientPrintHandlerGtk::PrintHandler {
: dialog_(NULL), gtk_settings_(NULL), page_setup_(NULL), printer_(NULL) {} PrintHandler(CefRefPtr<CefBrowser> browser)
: browser_(browser),
dialog_(NULL),
gtk_settings_(NULL),
page_setup_(NULL),
printer_(NULL) {}
void ClientPrintHandlerGtk::OnPrintStart(CefRefPtr<CefBrowser> browser) {} ~PrintHandler() {
if (dialog_) {
gtk_widget_destroy(dialog_);
dialog_ = NULL;
}
if (gtk_settings_) {
g_object_unref(gtk_settings_);
gtk_settings_ = NULL;
}
if (page_setup_) {
g_object_unref(page_setup_);
page_setup_ = NULL;
}
if (printer_) {
g_object_unref(printer_);
printer_ = NULL;
}
}
void ClientPrintHandlerGtk::OnPrintSettings( void OnPrintSettings(CefRefPtr<CefPrintSettings> settings,
CefRefPtr<CefPrintSettings> settings,
bool get_defaults) { bool get_defaults) {
if (get_defaults) { if (get_defaults) {
DCHECK(!page_setup_); DCHECK(!page_setup_);
DCHECK(!printer_); DCHECK(!printer_);
// |gtk_settings_| is a new copy. // |gtk_settings_| is a new copy.
gtk_settings_ = gtk_print_settings_copy(GetLastUsedSettings()->settings()); gtk_settings_ =
gtk_print_settings_copy(GetLastUsedSettings()->settings());
page_setup_ = gtk_page_setup_new(); page_setup_ = gtk_page_setup_new();
} else { } else {
if (!gtk_settings_) { if (!gtk_settings_) {
@ -331,8 +358,9 @@ void ClientPrintHandlerGtk::OnPrintSettings(
if (!page_setup_) if (!page_setup_)
page_setup_ = gtk_page_setup_new(); page_setup_ = gtk_page_setup_new();
gtk_print_settings_set_orientation( gtk_print_settings_set_orientation(gtk_settings_,
gtk_settings_, settings->IsLandscape() ? GTK_PAGE_ORIENTATION_LANDSCAPE settings->IsLandscape()
? GTK_PAGE_ORIENTATION_LANDSCAPE
: GTK_PAGE_ORIENTATION_PORTRAIT); : GTK_PAGE_ORIENTATION_PORTRAIT);
delete printer_list; delete printer_list;
@ -341,13 +369,11 @@ void ClientPrintHandlerGtk::OnPrintSettings(
InitPrintSettings(gtk_settings_, page_setup_, settings); InitPrintSettings(gtk_settings_, page_setup_, settings);
} }
bool ClientPrintHandlerGtk::OnPrintDialog( bool OnPrintDialog(bool has_selection,
bool has_selection,
CefRefPtr<CefPrintDialogCallback> callback) { CefRefPtr<CefPrintDialogCallback> callback) {
dialog_callback_ = callback; dialog_callback_ = callback;
// TODO(cef): Identify the correct parent window. GtkWindow* parent = GetWindow();
GtkWindow* parent = NULL;
// TODO(estade): We need a window title here. // TODO(estade): We need a window title here.
dialog_ = gtk_print_unix_dialog_new(NULL, parent); dialog_ = gtk_print_unix_dialog_new(NULL, parent);
g_signal_connect(dialog_, "delete-event", g_signal_connect(dialog_, "delete-event",
@ -362,8 +388,8 @@ bool ClientPrintHandlerGtk::OnPrintDialog(
GTK_PRINT_CAPABILITY_GENERATE_PDF | GTK_PRINT_CAPABILITY_PAGE_SET | GTK_PRINT_CAPABILITY_GENERATE_PDF | GTK_PRINT_CAPABILITY_PAGE_SET |
GTK_PRINT_CAPABILITY_COPIES | GTK_PRINT_CAPABILITY_COLLATE | GTK_PRINT_CAPABILITY_COPIES | GTK_PRINT_CAPABILITY_COLLATE |
GTK_PRINT_CAPABILITY_REVERSE); GTK_PRINT_CAPABILITY_REVERSE);
gtk_print_unix_dialog_set_manual_capabilities(GTK_PRINT_UNIX_DIALOG(dialog_), gtk_print_unix_dialog_set_manual_capabilities(
cap); GTK_PRINT_UNIX_DIALOG(dialog_), cap);
gtk_print_unix_dialog_set_embed_page_setup(GTK_PRINT_UNIX_DIALOG(dialog_), gtk_print_unix_dialog_set_embed_page_setup(GTK_PRINT_UNIX_DIALOG(dialog_),
TRUE); TRUE);
gtk_print_unix_dialog_set_support_selection(GTK_PRINT_UNIX_DIALOG(dialog_), gtk_print_unix_dialog_set_support_selection(GTK_PRINT_UNIX_DIALOG(dialog_),
@ -379,8 +405,7 @@ bool ClientPrintHandlerGtk::OnPrintDialog(
return true; return true;
} }
bool ClientPrintHandlerGtk::OnPrintJob( bool OnPrintJob(const CefString& document_name,
const CefString& document_name,
const CefString& pdf_file_path, const CefString& pdf_file_path,
CefRefPtr<CefPrintJobCallback> callback) { CefRefPtr<CefPrintJobCallback> callback) {
// If |printer_| is NULL then somehow the GTK printer list changed out under // If |printer_| is NULL then somehow the GTK printer list changed out under
@ -402,38 +427,18 @@ bool ClientPrintHandlerGtk::OnPrintJob(
return true; return true;
} }
void ClientPrintHandlerGtk::OnPrintReset() { private:
if (dialog_) { // Returns the GtkWindow* for the browser. Will return NULL when using the
gtk_widget_destroy(dialog_); // Views framework.
dialog_ = NULL; GtkWindow* GetWindow() {
} scoped_refptr<RootWindow> root_window =
if (gtk_settings_) { RootWindow::GetForBrowser(browser_->GetIdentifier());
g_object_unref(gtk_settings_); if (root_window)
gtk_settings_ = NULL; return GTK_WINDOW(root_window->GetWindowHandle());
} return NULL;
if (page_setup_) {
g_object_unref(page_setup_);
page_setup_ = NULL;
}
if (printer_) {
g_object_unref(printer_);
printer_ = NULL;
}
} }
CefSize ClientPrintHandlerGtk::GetPdfPaperSize(int device_units_per_inch) { void OnDialogResponse(GtkDialog* dialog, gint response_id) {
GtkPageSetup* page_setup = gtk_page_setup_new();
float width = gtk_page_setup_get_paper_width(page_setup, GTK_UNIT_INCH);
float height = gtk_page_setup_get_paper_height(page_setup, GTK_UNIT_INCH);
g_object_unref(page_setup);
return CefSize(width * device_units_per_inch, height * device_units_per_inch);
}
void ClientPrintHandlerGtk::OnDialogResponse(GtkDialog* dialog,
gint response_id) {
int num_matched_handlers = g_signal_handlers_disconnect_by_func( int num_matched_handlers = g_signal_handlers_disconnect_by_func(
dialog_, reinterpret_cast<gpointer>(&OnDialogResponseThunk), this); dialog_, reinterpret_cast<gpointer>(&OnDialogResponseThunk), this);
DCHECK_EQ(1, num_matched_handlers); DCHECK_EQ(1, num_matched_handlers);
@ -455,8 +460,8 @@ void ClientPrintHandlerGtk::OnDialogResponse(GtkDialog* dialog,
if (page_setup_) if (page_setup_)
g_object_unref(page_setup_); g_object_unref(page_setup_);
page_setup_ = page_setup_ = gtk_print_unix_dialog_get_page_setup(
gtk_print_unix_dialog_get_page_setup(GTK_PRINT_UNIX_DIALOG(dialog_)); GTK_PRINT_UNIX_DIALOG(dialog_));
g_object_ref(page_setup_); g_object_ref(page_setup_);
// Handle page ranges. // Handle page ranges.
@ -507,10 +512,104 @@ void ClientPrintHandlerGtk::OnDialogResponse(GtkDialog* dialog,
} }
} }
void ClientPrintHandlerGtk::OnJobCompleted(GtkPrintJob* print_job, void OnJobCompleted(GtkPrintJob* print_job, GError* error) {
GError* error) {
job_callback_->Continue(); job_callback_->Continue();
job_callback_ = NULL; job_callback_ = NULL;
} }
static void OnDialogResponseThunk(GtkDialog* dialog,
gint response_id,
PrintHandler* handler) {
handler->OnDialogResponse(dialog, response_id);
}
static void OnJobCompletedThunk(GtkPrintJob* print_job,
void* handler,
GError* error) {
static_cast<PrintHandler*>(handler)->OnJobCompleted(print_job, error);
}
CefRefPtr<CefBrowser> browser_;
GtkWidget* dialog_; // Owned.
GtkPrintSettings* gtk_settings_; // Referenced.
GtkPageSetup* page_setup_; // Referenced.
GtkPrinter* printer_; // Referenced.
CefRefPtr<CefPrintDialogCallback> dialog_callback_;
CefRefPtr<CefPrintJobCallback> job_callback_;
};
ClientPrintHandlerGtk::ClientPrintHandlerGtk() {}
ClientPrintHandlerGtk::~ClientPrintHandlerGtk() {
DCHECK(print_handler_map_.empty());
}
void ClientPrintHandlerGtk::OnPrintStart(CefRefPtr<CefBrowser> browser) {
const int browser_id = browser->GetIdentifier();
#ifndef _NDEBUG
// Print handler should not already exist for the browser.
PrintHandlerMap::const_iterator it = print_handler_map_.find(browser_id);
DCHECK(it == print_handler_map_.end());
#endif
// Create a new print handler.
PrintHandler* ph = new PrintHandler(browser);
print_handler_map_.insert(std::make_pair(browser_id, ph));
}
void ClientPrintHandlerGtk::OnPrintSettings(
CefRefPtr<CefBrowser> browser,
CefRefPtr<CefPrintSettings> settings,
bool get_defaults) {
GetPrintHandler(browser)->OnPrintSettings(settings, get_defaults);
}
bool ClientPrintHandlerGtk::OnPrintDialog(
CefRefPtr<CefBrowser> browser,
bool has_selection,
CefRefPtr<CefPrintDialogCallback> callback) {
return GetPrintHandler(browser)->OnPrintDialog(has_selection, callback);
}
bool ClientPrintHandlerGtk::OnPrintJob(
CefRefPtr<CefBrowser> browser,
const CefString& document_name,
const CefString& pdf_file_path,
CefRefPtr<CefPrintJobCallback> callback) {
return GetPrintHandler(browser)->OnPrintJob(document_name, pdf_file_path,
callback);
}
void ClientPrintHandlerGtk::OnPrintReset(CefRefPtr<CefBrowser> browser) {
// Delete the print handler.
PrintHandlerMap::iterator it =
print_handler_map_.find(browser->GetIdentifier());
DCHECK(it != print_handler_map_.end());
delete it->second;
print_handler_map_.erase(it);
}
CefSize ClientPrintHandlerGtk::GetPdfPaperSize(CefRefPtr<CefBrowser> browser,
int device_units_per_inch) {
GtkPageSetup* page_setup = gtk_page_setup_new();
float width = gtk_page_setup_get_paper_width(page_setup, GTK_UNIT_INCH);
float height = gtk_page_setup_get_paper_height(page_setup, GTK_UNIT_INCH);
g_object_unref(page_setup);
return CefSize(width * device_units_per_inch, height * device_units_per_inch);
}
ClientPrintHandlerGtk::PrintHandler* ClientPrintHandlerGtk::GetPrintHandler(
CefRefPtr<CefBrowser> browser) {
PrintHandlerMap::const_iterator it =
print_handler_map_.find(browser->GetIdentifier());
DCHECK(it != print_handler_map_.end());
return it->second;
}
} // namespace client } // namespace client

View File

@ -7,8 +7,7 @@
#define CEF_TESTS_CEFCLIENT_BROWSER_PRINT_HANDLER_GTK_H_ #define CEF_TESTS_CEFCLIENT_BROWSER_PRINT_HANDLER_GTK_H_
#pragma once #pragma once
#include <gtk/gtk.h> #include <map>
#include <gtk/gtkunixprint.h>
#include "include/cef_print_handler.h" #include "include/cef_print_handler.h"
@ -17,44 +16,32 @@ namespace client {
class ClientPrintHandlerGtk : public CefPrintHandler { class ClientPrintHandlerGtk : public CefPrintHandler {
public: public:
ClientPrintHandlerGtk(); ClientPrintHandlerGtk();
virtual ~ClientPrintHandlerGtk();
// CefPrintHandler methods. // CefPrintHandler methods.
void OnPrintStart(CefRefPtr<CefBrowser> browser) OVERRIDE; void OnPrintStart(CefRefPtr<CefBrowser> browser) OVERRIDE;
void OnPrintSettings(CefRefPtr<CefPrintSettings> settings, void OnPrintSettings(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefPrintSettings> settings,
bool get_defaults) OVERRIDE; bool get_defaults) OVERRIDE;
bool OnPrintDialog(bool has_selection, bool OnPrintDialog(CefRefPtr<CefBrowser> browser,
bool has_selection,
CefRefPtr<CefPrintDialogCallback> callback) OVERRIDE; CefRefPtr<CefPrintDialogCallback> callback) OVERRIDE;
bool OnPrintJob(const CefString& document_name, bool OnPrintJob(CefRefPtr<CefBrowser> browser,
const CefString& document_name,
const CefString& pdf_file_path, const CefString& pdf_file_path,
CefRefPtr<CefPrintJobCallback> callback) OVERRIDE; CefRefPtr<CefPrintJobCallback> callback) OVERRIDE;
void OnPrintReset() OVERRIDE; void OnPrintReset(CefRefPtr<CefBrowser> browser) OVERRIDE;
CefSize GetPdfPaperSize(int device_units_per_inch) OVERRIDE; CefSize GetPdfPaperSize(CefRefPtr<CefBrowser> browser,
int device_units_per_inch) OVERRIDE;
private: private:
void OnDialogResponse(GtkDialog* dialog, gint response_id); // Print handler.
void OnJobCompleted(GtkPrintJob* print_job, GError* error); struct PrintHandler;
PrintHandler* GetPrintHandler(CefRefPtr<CefBrowser> browser);
static void OnDialogResponseThunk(GtkDialog* dialog, // Map of browser ID to print handler.
gint response_id, typedef std::map<int, PrintHandler*> PrintHandlerMap;
ClientPrintHandlerGtk* handler) { PrintHandlerMap print_handler_map_;
handler->OnDialogResponse(dialog, response_id);
}
static void OnJobCompletedThunk(GtkPrintJob* print_job,
void* handler,
GError* error) {
static_cast<ClientPrintHandlerGtk*>(handler)->OnJobCompleted(print_job,
error);
}
// Print dialog settings. ClientPrintHandlerGtk owns |dialog_| and holds
// references to the other objects.
GtkWidget* dialog_;
GtkPrintSettings* gtk_settings_;
GtkPageSetup* page_setup_;
GtkPrinter* printer_;
CefRefPtr<CefPrintDialogCallback> dialog_callback_;
CefRefPtr<CefPrintJobCallback> job_callback_;
IMPLEMENT_REFCOUNTING(ClientPrintHandlerGtk); IMPLEMENT_REFCOUNTING(ClientPrintHandlerGtk);
DISALLOW_COPY_AND_ASSIGN(ClientPrintHandlerGtk); DISALLOW_COPY_AND_ASSIGN(ClientPrintHandlerGtk);