mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-06-05 21:39:12 +02:00
Add CefPrintHandler::OnPrintStart callback (issue #1736)
This commit is contained in:
@ -95,6 +95,15 @@ typedef struct _cef_print_handler_t {
|
||||
///
|
||||
cef_base_t base;
|
||||
|
||||
///
|
||||
// Called when printing has started for the specified |browser|. This function
|
||||
// will be called before the other OnPrint*() functions and irrespective of
|
||||
// how printing was initiated (e.g. cef_browser_host_t::print(), JavaScript
|
||||
// window.print() or PDF extension print button).
|
||||
///
|
||||
void (CEF_CALLBACK *on_print_start)(struct _cef_print_handler_t* self,
|
||||
struct _cef_browser_t* browser);
|
||||
|
||||
///
|
||||
// Synchronize |settings| with client state. If |get_defaults| is true (1)
|
||||
// then populate |settings| with the default print settings. Do not keep a
|
||||
|
@ -82,6 +82,15 @@ class CefPrintJobCallback : public virtual CefBase {
|
||||
/*--cef(source=client)--*/
|
||||
class CefPrintHandler : public virtual CefBase {
|
||||
public:
|
||||
///
|
||||
// Called when printing has started for the specified |browser|. This method
|
||||
// will be called before the other OnPrint*() methods and irrespective of how
|
||||
// printing was initiated (e.g. CefBrowserHost::Print(), JavaScript
|
||||
// window.print() or PDF extension print button).
|
||||
///
|
||||
/*--cef()--*/
|
||||
virtual void OnPrintStart(CefRefPtr<CefBrowser> browser) =0;
|
||||
|
||||
///
|
||||
// Synchronize |settings| with client state. If |get_defaults| is true then
|
||||
// populate |settings| with the default print settings. Do not keep a
|
||||
|
@ -985,15 +985,7 @@ void CefContentBrowserClient::OverrideWebkitPrefs(
|
||||
base::CommandLine::ForCurrentProcess();
|
||||
|
||||
CefRefPtr<CefBrowserHostImpl> browser =
|
||||
CefBrowserHostImpl::GetBrowserForHost(rvh);
|
||||
if (!browser.get() && extensions::ExtensionsEnabled()) {
|
||||
// Retrieve the owner browser, if any.
|
||||
content::WebContents* owner = extensions::GetOwnerForGuestContents(
|
||||
content::WebContents::FromRenderViewHost(rvh));
|
||||
if (owner)
|
||||
browser = CefBrowserHostImpl::GetBrowserForContents(owner);
|
||||
}
|
||||
|
||||
extensions::GetOwnerBrowserForHost(rvh);
|
||||
if (browser.get()) {
|
||||
// Populate WebPreferences based on CefBrowserSettings.
|
||||
BrowserToWebSettings(browser->settings(), *prefs);
|
||||
|
@ -4,6 +4,8 @@
|
||||
|
||||
#include "libcef/browser/extensions/browser_extensions_util.h"
|
||||
|
||||
#include "libcef/common/extensions/extensions_util.h"
|
||||
|
||||
#include "content/browser/browser_plugin/browser_plugin_embedder.h"
|
||||
#include "content/browser/browser_plugin/browser_plugin_guest.h"
|
||||
#include "content/browser/web_contents/web_contents_impl.h"
|
||||
@ -55,4 +57,27 @@ content::WebContents* GetOwnerForGuestContents(content::WebContents* guest) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
CefRefPtr<CefBrowserHostImpl> GetOwnerBrowserForView(int render_process_id,
|
||||
int render_routing_id) {
|
||||
content::RenderViewHost* host =
|
||||
content::RenderViewHost::FromID(render_process_id, render_routing_id);
|
||||
if (host)
|
||||
return GetOwnerBrowserForHost(host);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
CefRefPtr<CefBrowserHostImpl> GetOwnerBrowserForHost(
|
||||
content::RenderViewHost* host) {
|
||||
CefRefPtr<CefBrowserHostImpl> browser =
|
||||
CefBrowserHostImpl::GetBrowserForHost(host);
|
||||
if (!browser.get() && ExtensionsEnabled()) {
|
||||
// Retrieve the owner browser, if any.
|
||||
content::WebContents* owner = GetOwnerForGuestContents(
|
||||
content::WebContents::FromRenderViewHost(host));
|
||||
if (owner)
|
||||
browser = CefBrowserHostImpl::GetBrowserForContents(owner);
|
||||
}
|
||||
return browser;
|
||||
}
|
||||
|
||||
} // namespace extensions
|
||||
|
@ -7,7 +7,10 @@
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "libcef/browser/browser_host_impl.h"
|
||||
|
||||
namespace content {
|
||||
class RenderViewHost;
|
||||
class WebContents;
|
||||
}
|
||||
|
||||
@ -24,6 +27,15 @@ void GetAllGuestsForOwnerContents(content::WebContents* owner,
|
||||
// Returns the WebContents that owns the specified |guest|, if any.
|
||||
content::WebContents* GetOwnerForGuestContents(content::WebContents* guest);
|
||||
|
||||
// Returns the CefBrowserHostImpl that owns the host identified by the specified
|
||||
// view routing IDs, if any.
|
||||
CefRefPtr<CefBrowserHostImpl> GetOwnerBrowserForView(int render_process_id,
|
||||
int render_routing_id);
|
||||
|
||||
// Returns the CefBrowserHostImpl that owns the specified |host|, if any.
|
||||
CefRefPtr<CefBrowserHostImpl> GetOwnerBrowserForHost(
|
||||
content::RenderViewHost* host);
|
||||
|
||||
} // namespace extensions
|
||||
|
||||
#endif // CEF_LIBCEF_BROWSER_EXTENSIONS_BROWSER_EXTENSIONS_UTIL_H_
|
||||
|
@ -8,6 +8,8 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "libcef/browser/browser_host_impl.h"
|
||||
#include "libcef/browser/extensions/browser_extensions_util.h"
|
||||
#include "libcef/browser/print_settings_impl.h"
|
||||
#include "libcef/browser/thread_util.h"
|
||||
#include "libcef/common/content_client.h"
|
||||
@ -134,6 +136,35 @@ gfx::Size CefPrintDialogLinux::GetPdfPaperSize(
|
||||
return size;
|
||||
}
|
||||
|
||||
// static
|
||||
void CefPrintDialogLinux::OnPrintStart(int render_process_id,
|
||||
int render_routing_id) {
|
||||
if (!CEF_CURRENTLY_ON(CEF_UIT)) {
|
||||
CEF_POST_TASK(CEF_UIT,
|
||||
base::Bind(&CefPrintDialogLinux::OnPrintStart,
|
||||
render_process_id, render_routing_id));
|
||||
return;
|
||||
}
|
||||
|
||||
CefRefPtr<CefApp> app = CefContentClient::Get()->application();
|
||||
if (!app.get())
|
||||
return;
|
||||
|
||||
CefRefPtr<CefBrowserProcessHandler> browser_handler =
|
||||
app->GetBrowserProcessHandler();
|
||||
if (!browser_handler.get())
|
||||
return;
|
||||
|
||||
CefRefPtr<CefPrintHandler> handler = browser_handler->GetPrintHandler();
|
||||
if (!handler.get())
|
||||
return;
|
||||
|
||||
CefRefPtr<CefBrowserHostImpl> browser =
|
||||
extensions::GetOwnerBrowserForView(render_process_id, render_routing_id);
|
||||
if (browser.get())
|
||||
handler->OnPrintStart(browser.get());
|
||||
}
|
||||
|
||||
CefPrintDialogLinux::CefPrintDialogLinux(PrintingContextLinux* context)
|
||||
: context_(context) {
|
||||
}
|
||||
|
@ -37,6 +37,10 @@ class CefPrintDialogLinux
|
||||
static gfx::Size GetPdfPaperSize(
|
||||
printing::PrintingContextLinux* context);
|
||||
|
||||
// Notify the client when printing has started.
|
||||
static void OnPrintStart(int render_process_id,
|
||||
int render_routing_id);
|
||||
|
||||
// printing::CefPrintDialogLinuxInterface implementation.
|
||||
void UseDefaultSettings() override;
|
||||
bool UpdateSettings(printing::PrintSettings* settings) override;
|
||||
|
@ -17,6 +17,10 @@
|
||||
#include "content/public/browser/web_contents.h"
|
||||
#include "content/public/common/child_process_host.h"
|
||||
|
||||
#if defined(OS_LINUX)
|
||||
#include "libcef/browser/printing/print_dialog_linux.h"
|
||||
#endif
|
||||
|
||||
using content::BrowserThread;
|
||||
|
||||
namespace printing {
|
||||
@ -72,6 +76,12 @@ void PrintingMessageFilter::OnIsPrintingEnabled(bool* is_enabled) {
|
||||
|
||||
void PrintingMessageFilter::OnGetDefaultPrintSettings(IPC::Message* reply_msg) {
|
||||
DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
||||
#if defined(OS_LINUX)
|
||||
// Send notification to the client.
|
||||
CefPrintDialogLinux::OnPrintStart(render_process_id_,
|
||||
reply_msg->routing_id());
|
||||
#endif
|
||||
|
||||
scoped_refptr<PrinterQuery> printer_query;
|
||||
printer_query = queue_->PopPrinterQuery(0);
|
||||
if (!printer_query.get()) {
|
||||
|
@ -11,6 +11,7 @@
|
||||
//
|
||||
|
||||
#include "libcef_dll/cpptoc/print_handler_cpptoc.h"
|
||||
#include "libcef_dll/ctocpp/browser_ctocpp.h"
|
||||
#include "libcef_dll/ctocpp/print_dialog_callback_ctocpp.h"
|
||||
#include "libcef_dll/ctocpp/print_job_callback_ctocpp.h"
|
||||
#include "libcef_dll/ctocpp/print_settings_ctocpp.h"
|
||||
@ -20,6 +21,23 @@ namespace {
|
||||
|
||||
// MEMBER FUNCTIONS - Body may be edited by hand.
|
||||
|
||||
void CEF_CALLBACK print_handler_on_print_start(
|
||||
struct _cef_print_handler_t* self, cef_browser_t* browser) {
|
||||
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
|
||||
|
||||
DCHECK(self);
|
||||
if (!self)
|
||||
return;
|
||||
// Verify param: browser; type: refptr_diff
|
||||
DCHECK(browser);
|
||||
if (!browser)
|
||||
return;
|
||||
|
||||
// Execute
|
||||
CefPrintHandlerCppToC::Get(self)->OnPrintStart(
|
||||
CefBrowserCToCpp::Wrap(browser));
|
||||
}
|
||||
|
||||
void CEF_CALLBACK print_handler_on_print_settings(
|
||||
struct _cef_print_handler_t* self, struct _cef_print_settings_t* settings,
|
||||
int get_defaults) {
|
||||
@ -126,6 +144,7 @@ cef_size_t CEF_CALLBACK print_handler_get_pdf_paper_size(
|
||||
// CONSTRUCTOR - Do not edit by hand.
|
||||
|
||||
CefPrintHandlerCppToC::CefPrintHandlerCppToC() {
|
||||
GetStruct()->on_print_start = print_handler_on_print_start;
|
||||
GetStruct()->on_print_settings = print_handler_on_print_settings;
|
||||
GetStruct()->on_print_dialog = print_handler_on_print_dialog;
|
||||
GetStruct()->on_print_job = print_handler_on_print_job;
|
||||
|
@ -10,6 +10,7 @@
|
||||
// for more information.
|
||||
//
|
||||
|
||||
#include "libcef_dll/cpptoc/browser_cpptoc.h"
|
||||
#include "libcef_dll/cpptoc/print_dialog_callback_cpptoc.h"
|
||||
#include "libcef_dll/cpptoc/print_job_callback_cpptoc.h"
|
||||
#include "libcef_dll/cpptoc/print_settings_cpptoc.h"
|
||||
@ -18,6 +19,23 @@
|
||||
|
||||
// VIRTUAL METHODS - Body may be edited by hand.
|
||||
|
||||
void CefPrintHandlerCToCpp::OnPrintStart(CefRefPtr<CefBrowser> browser) {
|
||||
cef_print_handler_t* _struct = GetStruct();
|
||||
if (CEF_MEMBER_MISSING(_struct, on_print_start))
|
||||
return;
|
||||
|
||||
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
|
||||
|
||||
// Verify param: browser; type: refptr_diff
|
||||
DCHECK(browser.get());
|
||||
if (!browser.get())
|
||||
return;
|
||||
|
||||
// Execute
|
||||
_struct->on_print_start(_struct,
|
||||
CefBrowserCppToC::Wrap(browser));
|
||||
}
|
||||
|
||||
void CefPrintHandlerCToCpp::OnPrintSettings(
|
||||
CefRefPtr<CefPrintSettings> settings, bool get_defaults) {
|
||||
cef_print_handler_t* _struct = GetStruct();
|
||||
|
@ -31,6 +31,7 @@ class CefPrintHandlerCToCpp
|
||||
CefPrintHandlerCToCpp();
|
||||
|
||||
// CefPrintHandler methods.
|
||||
void OnPrintStart(CefRefPtr<CefBrowser> browser) override;
|
||||
void OnPrintSettings(CefRefPtr<CefPrintSettings> settings,
|
||||
bool get_defaults) override;
|
||||
bool OnPrintDialog(bool has_selection,
|
||||
|
@ -282,6 +282,9 @@ ClientPrintHandlerGtk::ClientPrintHandlerGtk()
|
||||
printer_(NULL) {
|
||||
}
|
||||
|
||||
void ClientPrintHandlerGtk::OnPrintStart(CefRefPtr<CefBrowser> browser) {
|
||||
}
|
||||
|
||||
void ClientPrintHandlerGtk::OnPrintSettings(
|
||||
CefRefPtr<CefPrintSettings> settings,
|
||||
bool get_defaults) {
|
||||
|
@ -19,6 +19,7 @@ class ClientPrintHandlerGtk : public CefPrintHandler {
|
||||
ClientPrintHandlerGtk();
|
||||
|
||||
// CefPrintHandler methods.
|
||||
void OnPrintStart(CefRefPtr<CefBrowser> browser) OVERRIDE;
|
||||
void OnPrintSettings(CefRefPtr<CefPrintSettings> settings,
|
||||
bool get_defaults) OVERRIDE;
|
||||
bool OnPrintDialog(
|
||||
|
Reference in New Issue
Block a user