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:
@@ -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()) {
|
||||
|
Reference in New Issue
Block a user