Revert "Move the code of getting printing settings to another class."
This reverts commit 57d06c5241
.
Conflicts:
atom/browser/printing/printing_config_service.cc
This commit is contained in:
parent
e43b3309af
commit
d20ec6952a
6 changed files with 134 additions and 225 deletions
6
atom.gyp
6
atom.gyp
|
@ -123,10 +123,6 @@
|
||||||
'atom/browser/net/url_request_string_job.h',
|
'atom/browser/net/url_request_string_job.h',
|
||||||
'atom/browser/node_debugger.cc',
|
'atom/browser/node_debugger.cc',
|
||||||
'atom/browser/node_debugger.h',
|
'atom/browser/node_debugger.h',
|
||||||
'atom/browser/printing/printing_config_service.cc',
|
|
||||||
'atom/browser/printing/printing_config_service.h',
|
|
||||||
'atom/browser/printing/printing_message_filter.cc',
|
|
||||||
'atom/browser/printing/printing_message_filter.h',
|
|
||||||
'atom/browser/ui/accelerator_util.cc',
|
'atom/browser/ui/accelerator_util.cc',
|
||||||
'atom/browser/ui/accelerator_util.h',
|
'atom/browser/ui/accelerator_util.h',
|
||||||
'atom/browser/ui/accelerator_util_mac.mm',
|
'atom/browser/ui/accelerator_util_mac.mm',
|
||||||
|
@ -263,6 +259,8 @@
|
||||||
'chromium_src/chrome/browser/printing/print_view_manager_observer.h',
|
'chromium_src/chrome/browser/printing/print_view_manager_observer.h',
|
||||||
'chromium_src/chrome/browser/printing/printer_query.cc',
|
'chromium_src/chrome/browser/printing/printer_query.cc',
|
||||||
'chromium_src/chrome/browser/printing/printer_query.h',
|
'chromium_src/chrome/browser/printing/printer_query.h',
|
||||||
|
'chromium_src/chrome/browser/printing/printing_message_filter.cc',
|
||||||
|
'chromium_src/chrome/browser/printing/printing_message_filter.h',
|
||||||
'chromium_src/chrome/browser/printing/printing_ui_web_contents_observer.cc',
|
'chromium_src/chrome/browser/printing/printing_ui_web_contents_observer.cc',
|
||||||
'chromium_src/chrome/browser/printing/printing_ui_web_contents_observer.h',
|
'chromium_src/chrome/browser/printing/printing_ui_web_contents_observer.h',
|
||||||
'chromium_src/chrome/browser/ui/libgtk2ui/app_indicator_icon_menu.cc',
|
'chromium_src/chrome/browser/ui/libgtk2ui/app_indicator_icon_menu.cc',
|
||||||
|
|
|
@ -9,8 +9,8 @@
|
||||||
#include "atom/browser/atom_browser_main_parts.h"
|
#include "atom/browser/atom_browser_main_parts.h"
|
||||||
#include "atom/browser/atom_resource_dispatcher_host_delegate.h"
|
#include "atom/browser/atom_resource_dispatcher_host_delegate.h"
|
||||||
#include "atom/browser/native_window.h"
|
#include "atom/browser/native_window.h"
|
||||||
#include "atom/browser/printing/printing_message_filter.h"
|
|
||||||
#include "atom/browser/window_list.h"
|
#include "atom/browser/window_list.h"
|
||||||
|
#include "chrome/browser/printing/printing_message_filter.h"
|
||||||
#include "content/public/browser/render_process_host.h"
|
#include "content/public/browser/render_process_host.h"
|
||||||
#include "content/public/browser/render_view_host.h"
|
#include "content/public/browser/render_view_host.h"
|
||||||
#include "content/public/browser/resource_dispatcher_host.h"
|
#include "content/public/browser/resource_dispatcher_host.h"
|
||||||
|
|
|
@ -1,119 +0,0 @@
|
||||||
// Copyright (c) 2014 GitHub, Inc. All rights reserved.
|
|
||||||
// Use of this source code is governed by the MIT license that can be
|
|
||||||
// found in the LICENSE file.
|
|
||||||
|
|
||||||
#include "atom/browser/printing/printing_config_service.h"
|
|
||||||
|
|
||||||
#include "base/memory/singleton.h"
|
|
||||||
#include "chrome/browser/printing/printer_query.h"
|
|
||||||
#include "chrome/browser/printing/printing_ui_web_contents_observer.h"
|
|
||||||
#include "chrome/common/print_messages.h"
|
|
||||||
#include "content/public/browser/browser_thread.h"
|
|
||||||
#include "content/public/browser/web_contents.h"
|
|
||||||
|
|
||||||
using content::BrowserThread;
|
|
||||||
|
|
||||||
namespace atom {
|
|
||||||
|
|
||||||
namespace {
|
|
||||||
|
|
||||||
void RenderParamsFromPrintSettings(const printing::PrintSettings& settings,
|
|
||||||
PrintMsg_Print_Params* params) {
|
|
||||||
params->page_size = settings.page_setup_device_units().physical_size();
|
|
||||||
params->content_size.SetSize(
|
|
||||||
settings.page_setup_device_units().content_area().width(),
|
|
||||||
settings.page_setup_device_units().content_area().height());
|
|
||||||
params->printable_area.SetRect(
|
|
||||||
settings.page_setup_device_units().printable_area().x(),
|
|
||||||
settings.page_setup_device_units().printable_area().y(),
|
|
||||||
settings.page_setup_device_units().printable_area().width(),
|
|
||||||
settings.page_setup_device_units().printable_area().height());
|
|
||||||
params->margin_top = settings.page_setup_device_units().content_area().y();
|
|
||||||
params->margin_left = settings.page_setup_device_units().content_area().x();
|
|
||||||
params->dpi = settings.dpi();
|
|
||||||
// Currently hardcoded at 1.25. See PrintSettings' constructor.
|
|
||||||
params->min_shrink = settings.min_shrink();
|
|
||||||
// Currently hardcoded at 2.0. See PrintSettings' constructor.
|
|
||||||
params->max_shrink = settings.max_shrink();
|
|
||||||
// Currently hardcoded at 72dpi. See PrintSettings' constructor.
|
|
||||||
params->desired_dpi = settings.desired_dpi();
|
|
||||||
// Always use an invalid cookie.
|
|
||||||
params->document_cookie = 0;
|
|
||||||
params->selection_only = settings.selection_only();
|
|
||||||
params->supports_alpha_blend = settings.supports_alpha_blend();
|
|
||||||
params->should_print_backgrounds = settings.should_print_backgrounds();
|
|
||||||
params->title = settings.title();
|
|
||||||
params->url = settings.url();
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace
|
|
||||||
|
|
||||||
// static
|
|
||||||
PrintingConfigService* PrintingConfigService::GetInstance() {
|
|
||||||
return Singleton<PrintingConfigService>::get();
|
|
||||||
}
|
|
||||||
|
|
||||||
PrintingConfigService::PrintingConfigService()
|
|
||||||
: weak_factory_(this) {
|
|
||||||
}
|
|
||||||
|
|
||||||
PrintingConfigService::~PrintingConfigService() {
|
|
||||||
}
|
|
||||||
|
|
||||||
void PrintingConfigService::GetPrintSettings(
|
|
||||||
content::WebContents* wc,
|
|
||||||
scoped_refptr<printing::PrinterQuery> printer_query,
|
|
||||||
bool ask_user_for_settings,
|
|
||||||
const PrintHostMsg_ScriptedPrint_Params& params,
|
|
||||||
PrintSettingsCallback callback) {
|
|
||||||
DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
|
||||||
if (wc) {
|
|
||||||
scoped_ptr<PrintingUIWebContentsObserver> wc_observer(
|
|
||||||
new PrintingUIWebContentsObserver(wc));
|
|
||||||
printing::PrinterQuery::GetSettingsAskParam ask_param =
|
|
||||||
ask_user_for_settings ? printing::PrinterQuery::ASK_USER :
|
|
||||||
printing::PrinterQuery::DEFAULTS;
|
|
||||||
BrowserThread::PostTask(
|
|
||||||
BrowserThread::IO, FROM_HERE,
|
|
||||||
base::Bind(&printing::PrinterQuery::GetSettings, printer_query,
|
|
||||||
ask_param, base::Passed(&wc_observer),
|
|
||||||
params.expected_pages_count, params.has_selection,
|
|
||||||
params.margin_type,
|
|
||||||
base::Bind(&PrintingConfigService::OnGetSettings,
|
|
||||||
weak_factory_.GetWeakPtr(), printer_query,
|
|
||||||
callback)));
|
|
||||||
} else {
|
|
||||||
BrowserThread::PostTask(
|
|
||||||
BrowserThread::IO, FROM_HERE,
|
|
||||||
base::Bind(&PrintingConfigService::OnGetSettingsFailed,
|
|
||||||
weak_factory_.GetWeakPtr(), printer_query, callback));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void PrintingConfigService::OnGetSettings(
|
|
||||||
scoped_refptr<printing::PrinterQuery> printer_query,
|
|
||||||
PrintSettingsCallback callback) {
|
|
||||||
DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
|
||||||
PrintMsg_PrintPages_Params params;
|
|
||||||
if (printer_query->last_status() != printing::PrintingContext::OK ||
|
|
||||||
!printer_query->settings().dpi()) {
|
|
||||||
params.Reset();
|
|
||||||
} else {
|
|
||||||
RenderParamsFromPrintSettings(printer_query->settings(), ¶ms.params);
|
|
||||||
params.params.document_cookie = printer_query->cookie();
|
|
||||||
params.pages =
|
|
||||||
printing::PageRange::GetPages(printer_query->settings().ranges());
|
|
||||||
}
|
|
||||||
callback.Run(params);
|
|
||||||
}
|
|
||||||
|
|
||||||
void PrintingConfigService::OnGetSettingsFailed(
|
|
||||||
scoped_refptr<printing::PrinterQuery> printer_query,
|
|
||||||
PrintSettingsCallback callback) {
|
|
||||||
DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
|
||||||
printer_query->GetSettingsDone(printing::PrintSettings(),
|
|
||||||
printing::PrintingContext::FAILED);
|
|
||||||
callback.Run(PrintMsg_PrintPages_Params());
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace atom
|
|
|
@ -1,60 +0,0 @@
|
||||||
// Copyright (c) 2014 GitHub, Inc. All rights reserved.
|
|
||||||
// Use of this source code is governed by the MIT license that can be
|
|
||||||
// found in the LICENSE file.
|
|
||||||
|
|
||||||
#ifndef ATOM_BROWSER_PRINTING_PRINTING_CONFIG_SERVICE_H_
|
|
||||||
#define ATOM_BROWSER_PRINTING_PRINTING_CONFIG_SERVICE_H_
|
|
||||||
|
|
||||||
#include "base/memory/weak_ptr.h"
|
|
||||||
|
|
||||||
template <typename T> struct DefaultSingletonTraits;
|
|
||||||
struct PrintHostMsg_ScriptedPrint_Params;
|
|
||||||
struct PrintMsg_PrintPages_Params;
|
|
||||||
|
|
||||||
namespace content {
|
|
||||||
class WebContents;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace printing {
|
|
||||||
class PrinterQuery;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace atom {
|
|
||||||
|
|
||||||
// This interface manages the config of printing.
|
|
||||||
class PrintingConfigService {
|
|
||||||
public:
|
|
||||||
static PrintingConfigService* GetInstance();
|
|
||||||
|
|
||||||
typedef base::Callback<void(const PrintMsg_PrintPages_Params&)>
|
|
||||||
PrintSettingsCallback;
|
|
||||||
|
|
||||||
// Gets printing settings for query on UI thread, and then call the |callback|
|
|
||||||
// on the IO thread with the result.
|
|
||||||
void GetPrintSettings(content::WebContents* wc,
|
|
||||||
scoped_refptr<printing::PrinterQuery> printer_query,
|
|
||||||
bool ask_user_for_settings,
|
|
||||||
const PrintHostMsg_ScriptedPrint_Params& params,
|
|
||||||
PrintSettingsCallback callback);
|
|
||||||
|
|
||||||
private:
|
|
||||||
PrintingConfigService();
|
|
||||||
virtual ~PrintingConfigService();
|
|
||||||
|
|
||||||
// Called by content::PrinterQuery::GetSettings in GetPrintSettings.
|
|
||||||
void OnGetSettings(scoped_refptr<printing::PrinterQuery> printer_query,
|
|
||||||
PrintSettingsCallback callback);
|
|
||||||
void OnGetSettingsFailed(scoped_refptr<printing::PrinterQuery> printer_query,
|
|
||||||
PrintSettingsCallback callback);
|
|
||||||
|
|
||||||
private:
|
|
||||||
friend struct DefaultSingletonTraits<PrintingConfigService>;
|
|
||||||
|
|
||||||
base::WeakPtrFactory<PrintingConfigService> weak_factory_;
|
|
||||||
|
|
||||||
DISALLOW_COPY_AND_ASSIGN(PrintingConfigService);
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace atom
|
|
||||||
|
|
||||||
#endif // ATOM_BROWSER_PRINTING_PRINTING_CONFIG_SERVICE_H_
|
|
|
@ -2,13 +2,17 @@
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
#include "atom/browser/printing/printing_message_filter.h"
|
#include "chrome/browser/printing/printing_message_filter.h"
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include "atom/browser/printing/printing_config_service.h"
|
|
||||||
#include "base/bind.h"
|
#include "base/bind.h"
|
||||||
#include "chrome/browser/browser_process.h"
|
#include "chrome/browser/browser_process.h"
|
||||||
#include "chrome/browser/printing/print_job_manager.h"
|
|
||||||
#include "chrome/browser/printing/printer_query.h"
|
#include "chrome/browser/printing/printer_query.h"
|
||||||
|
#include "chrome/browser/printing/print_job_manager.h"
|
||||||
|
#include "chrome/browser/printing/printing_ui_web_contents_observer.h"
|
||||||
|
#include "chrome/browser/profiles/profile.h"
|
||||||
|
#include "chrome/browser/profiles/profile_io_data.h"
|
||||||
#include "chrome/common/print_messages.h"
|
#include "chrome/common/print_messages.h"
|
||||||
#include "content/public/browser/browser_thread.h"
|
#include "content/public/browser/browser_thread.h"
|
||||||
#include "content/public/browser/render_view_host.h"
|
#include "content/public/browser/render_view_host.h"
|
||||||
|
@ -16,7 +20,38 @@
|
||||||
|
|
||||||
using content::BrowserThread;
|
using content::BrowserThread;
|
||||||
|
|
||||||
namespace atom {
|
namespace {
|
||||||
|
|
||||||
|
void RenderParamsFromPrintSettings(const printing::PrintSettings& settings,
|
||||||
|
PrintMsg_Print_Params* params) {
|
||||||
|
params->page_size = settings.page_setup_device_units().physical_size();
|
||||||
|
params->content_size.SetSize(
|
||||||
|
settings.page_setup_device_units().content_area().width(),
|
||||||
|
settings.page_setup_device_units().content_area().height());
|
||||||
|
params->printable_area.SetRect(
|
||||||
|
settings.page_setup_device_units().printable_area().x(),
|
||||||
|
settings.page_setup_device_units().printable_area().y(),
|
||||||
|
settings.page_setup_device_units().printable_area().width(),
|
||||||
|
settings.page_setup_device_units().printable_area().height());
|
||||||
|
params->margin_top = settings.page_setup_device_units().content_area().y();
|
||||||
|
params->margin_left = settings.page_setup_device_units().content_area().x();
|
||||||
|
params->dpi = settings.dpi();
|
||||||
|
// Currently hardcoded at 1.25. See PrintSettings' constructor.
|
||||||
|
params->min_shrink = settings.min_shrink();
|
||||||
|
// Currently hardcoded at 2.0. See PrintSettings' constructor.
|
||||||
|
params->max_shrink = settings.max_shrink();
|
||||||
|
// Currently hardcoded at 72dpi. See PrintSettings' constructor.
|
||||||
|
params->desired_dpi = settings.desired_dpi();
|
||||||
|
// Always use an invalid cookie.
|
||||||
|
params->document_cookie = 0;
|
||||||
|
params->selection_only = settings.selection_only();
|
||||||
|
params->supports_alpha_blend = settings.supports_alpha_blend();
|
||||||
|
params->should_print_backgrounds = settings.should_print_backgrounds();
|
||||||
|
params->title = settings.title();
|
||||||
|
params->url = settings.url();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
PrintingMessageFilter::PrintingMessageFilter(int render_process_id)
|
PrintingMessageFilter::PrintingMessageFilter(int render_process_id)
|
||||||
: BrowserMessageFilter(PrintMsgStart),
|
: BrowserMessageFilter(PrintMsgStart),
|
||||||
|
@ -62,16 +97,44 @@ content::WebContents* PrintingMessageFilter::GetWebContentsForRenderView(
|
||||||
return view ? content::WebContents::FromRenderViewHost(view) : NULL;
|
return view ? content::WebContents::FromRenderViewHost(view) : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct PrintingMessageFilter::GetPrintSettingsForRenderViewParams {
|
||||||
|
printing::PrinterQuery::GetSettingsAskParam ask_user_for_settings;
|
||||||
|
int expected_page_count;
|
||||||
|
bool has_selection;
|
||||||
|
printing::MarginType margin_type;
|
||||||
|
};
|
||||||
|
|
||||||
void PrintingMessageFilter::GetPrintSettingsForRenderView(
|
void PrintingMessageFilter::GetPrintSettingsForRenderView(
|
||||||
int render_view_id,
|
int render_view_id,
|
||||||
bool ask_user_for_settings,
|
GetPrintSettingsForRenderViewParams params,
|
||||||
PrintHostMsg_ScriptedPrint_Params params,
|
const base::Closure& callback,
|
||||||
const base::Callback<void(const PrintMsg_PrintPages_Params&)>callback,
|
|
||||||
scoped_refptr<printing::PrinterQuery> printer_query) {
|
scoped_refptr<printing::PrinterQuery> printer_query) {
|
||||||
DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
||||||
content::WebContents* wc = GetWebContentsForRenderView(render_view_id);
|
content::WebContents* wc = GetWebContentsForRenderView(render_view_id);
|
||||||
PrintingConfigService::GetInstance()->GetPrintSettings(
|
if (wc) {
|
||||||
wc, printer_query, ask_user_for_settings, params, callback);
|
scoped_ptr<PrintingUIWebContentsObserver> wc_observer(
|
||||||
|
new PrintingUIWebContentsObserver(wc));
|
||||||
|
BrowserThread::PostTask(
|
||||||
|
BrowserThread::IO, FROM_HERE,
|
||||||
|
base::Bind(&printing::PrinterQuery::GetSettings, printer_query,
|
||||||
|
params.ask_user_for_settings, base::Passed(&wc_observer),
|
||||||
|
params.expected_page_count, params.has_selection,
|
||||||
|
params.margin_type, callback));
|
||||||
|
} else {
|
||||||
|
BrowserThread::PostTask(
|
||||||
|
BrowserThread::IO, FROM_HERE,
|
||||||
|
base::Bind(&PrintingMessageFilter::OnGetPrintSettingsFailed, this,
|
||||||
|
callback, printer_query));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void PrintingMessageFilter::OnGetPrintSettingsFailed(
|
||||||
|
const base::Closure& callback,
|
||||||
|
scoped_refptr<printing::PrinterQuery> printer_query) {
|
||||||
|
DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
||||||
|
printer_query->GetSettingsDone(printing::PrintSettings(),
|
||||||
|
printing::PrintingContext::FAILED);
|
||||||
|
callback.Run();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PrintingMessageFilter::OnGetDefaultPrintSettings(IPC::Message* reply_msg) {
|
void PrintingMessageFilter::OnGetDefaultPrintSettings(IPC::Message* reply_msg) {
|
||||||
|
@ -79,8 +142,7 @@ void PrintingMessageFilter::OnGetDefaultPrintSettings(IPC::Message* reply_msg) {
|
||||||
scoped_refptr<printing::PrinterQuery> printer_query;
|
scoped_refptr<printing::PrinterQuery> printer_query;
|
||||||
if (false) {
|
if (false) {
|
||||||
// Reply with NULL query.
|
// Reply with NULL query.
|
||||||
OnGetDefaultPrintSettingsReply(printer_query, reply_msg,
|
OnGetDefaultPrintSettingsReply(printer_query, reply_msg);
|
||||||
PrintMsg_PrintPages_Params());
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
printer_query = queue_->PopPrinterQuery(0);
|
printer_query = queue_->PopPrinterQuery(0);
|
||||||
|
@ -89,27 +151,33 @@ void PrintingMessageFilter::OnGetDefaultPrintSettings(IPC::Message* reply_msg) {
|
||||||
|
|
||||||
// Loads default settings. This is asynchronous, only the IPC message sender
|
// Loads default settings. This is asynchronous, only the IPC message sender
|
||||||
// will hang until the settings are retrieved.
|
// will hang until the settings are retrieved.
|
||||||
PrintHostMsg_ScriptedPrint_Params params;
|
GetPrintSettingsForRenderViewParams params;
|
||||||
params.expected_pages_count = 0;
|
params.ask_user_for_settings = printing::PrinterQuery::DEFAULTS;
|
||||||
|
params.expected_page_count = 0;
|
||||||
params.has_selection = false;
|
params.has_selection = false;
|
||||||
params.margin_type = printing::DEFAULT_MARGINS;
|
params.margin_type = printing::DEFAULT_MARGINS;
|
||||||
BrowserThread::PostTask(
|
BrowserThread::PostTask(
|
||||||
BrowserThread::UI, FROM_HERE,
|
BrowserThread::UI, FROM_HERE,
|
||||||
base::Bind(&PrintingMessageFilter::GetPrintSettingsForRenderView, this,
|
base::Bind(&PrintingMessageFilter::GetPrintSettingsForRenderView, this,
|
||||||
reply_msg->routing_id(), false, params,
|
reply_msg->routing_id(), params,
|
||||||
base::Bind(&PrintingMessageFilter::OnGetDefaultPrintSettingsReply,
|
base::Bind(&PrintingMessageFilter::OnGetDefaultPrintSettingsReply,
|
||||||
this, printer_query, reply_msg),
|
this, printer_query, reply_msg),
|
||||||
printer_query));
|
printer_query));
|
||||||
}
|
}
|
||||||
|
|
||||||
void PrintingMessageFilter::OnGetDefaultPrintSettingsReply(
|
void PrintingMessageFilter::OnGetDefaultPrintSettingsReply(
|
||||||
scoped_refptr<printing::PrinterQuery> printer_query,
|
scoped_refptr<printing::PrinterQuery> printer_query,
|
||||||
IPC::Message* reply_msg,
|
IPC::Message* reply_msg) {
|
||||||
const PrintMsg_PrintPages_Params& params) {
|
PrintMsg_Print_Params params;
|
||||||
PrintHostMsg_GetDefaultPrintSettings::WriteReplyParams(
|
if (!printer_query.get() ||
|
||||||
reply_msg, params.params);
|
printer_query->last_status() != printing::PrintingContext::OK) {
|
||||||
|
params.Reset();
|
||||||
|
} else {
|
||||||
|
RenderParamsFromPrintSettings(printer_query->settings(), ¶ms);
|
||||||
|
params.document_cookie = printer_query->cookie();
|
||||||
|
}
|
||||||
|
PrintHostMsg_GetDefaultPrintSettings::WriteReplyParams(reply_msg, params);
|
||||||
Send(reply_msg);
|
Send(reply_msg);
|
||||||
|
|
||||||
// If printing was enabled.
|
// If printing was enabled.
|
||||||
if (printer_query.get()) {
|
if (printer_query.get()) {
|
||||||
// If user hasn't cancelled.
|
// If user hasn't cancelled.
|
||||||
|
@ -128,10 +196,16 @@ void PrintingMessageFilter::OnScriptedPrint(
|
||||||
queue_->PopPrinterQuery(params.cookie);
|
queue_->PopPrinterQuery(params.cookie);
|
||||||
if (!printer_query)
|
if (!printer_query)
|
||||||
printer_query = queue_->CreatePrinterQuery();
|
printer_query = queue_->CreatePrinterQuery();
|
||||||
|
GetPrintSettingsForRenderViewParams settings_params;
|
||||||
|
settings_params.ask_user_for_settings = printing::PrinterQuery::ASK_USER;
|
||||||
|
settings_params.expected_page_count = params.expected_pages_count;
|
||||||
|
settings_params.has_selection = params.has_selection;
|
||||||
|
settings_params.margin_type = params.margin_type;
|
||||||
|
|
||||||
BrowserThread::PostTask(
|
BrowserThread::PostTask(
|
||||||
BrowserThread::UI, FROM_HERE,
|
BrowserThread::UI, FROM_HERE,
|
||||||
base::Bind(&PrintingMessageFilter::GetPrintSettingsForRenderView, this,
|
base::Bind(&PrintingMessageFilter::GetPrintSettingsForRenderView, this,
|
||||||
reply_msg->routing_id(), true, params,
|
reply_msg->routing_id(), settings_params,
|
||||||
base::Bind(&PrintingMessageFilter::OnScriptedPrintReply, this,
|
base::Bind(&PrintingMessageFilter::OnScriptedPrintReply, this,
|
||||||
printer_query, reply_msg),
|
printer_query, reply_msg),
|
||||||
printer_query));
|
printer_query));
|
||||||
|
@ -139,16 +213,22 @@ void PrintingMessageFilter::OnScriptedPrint(
|
||||||
|
|
||||||
void PrintingMessageFilter::OnScriptedPrintReply(
|
void PrintingMessageFilter::OnScriptedPrintReply(
|
||||||
scoped_refptr<printing::PrinterQuery> printer_query,
|
scoped_refptr<printing::PrinterQuery> printer_query,
|
||||||
IPC::Message* reply_msg,
|
IPC::Message* reply_msg) {
|
||||||
const PrintMsg_PrintPages_Params& params) {
|
PrintMsg_PrintPages_Params params;
|
||||||
|
if (printer_query->last_status() != printing::PrintingContext::OK ||
|
||||||
|
!printer_query->settings().dpi()) {
|
||||||
|
params.Reset();
|
||||||
|
} else {
|
||||||
|
RenderParamsFromPrintSettings(printer_query->settings(), ¶ms.params);
|
||||||
|
params.params.document_cookie = printer_query->cookie();
|
||||||
|
params.pages =
|
||||||
|
printing::PageRange::GetPages(printer_query->settings().ranges());
|
||||||
|
}
|
||||||
PrintHostMsg_ScriptedPrint::WriteReplyParams(reply_msg, params);
|
PrintHostMsg_ScriptedPrint::WriteReplyParams(reply_msg, params);
|
||||||
Send(reply_msg);
|
Send(reply_msg);
|
||||||
|
|
||||||
if (params.params.dpi && params.params.document_cookie) {
|
if (params.params.dpi && params.params.document_cookie) {
|
||||||
queue_->QueuePrinterQuery(printer_query.get());
|
queue_->QueuePrinterQuery(printer_query.get());
|
||||||
} else {
|
} else {
|
||||||
printer_query->StopWorker();
|
printer_query->StopWorker();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace atom
|
|
|
@ -2,8 +2,10 @@
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
#ifndef ATOM_BROWSER_PRINTING_PRINTING_MESSAGE_FILTER_H_
|
#ifndef CHROME_BROWSER_PRINTING_PRINTING_MESSAGE_FILTER_H_
|
||||||
#define ATOM_BROWSER_PRINTING_PRINTING_MESSAGE_FILTER_H_
|
#define CHROME_BROWSER_PRINTING_PRINTING_MESSAGE_FILTER_H_
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include "base/compiler_specific.h"
|
#include "base/compiler_specific.h"
|
||||||
#include "content/public/browser/browser_message_filter.h"
|
#include "content/public/browser/browser_message_filter.h"
|
||||||
|
@ -12,20 +14,23 @@
|
||||||
#include "base/memory/shared_memory.h"
|
#include "base/memory/shared_memory.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct PrintMsg_PrintPages_Params;
|
|
||||||
struct PrintHostMsg_ScriptedPrint_Params;
|
struct PrintHostMsg_ScriptedPrint_Params;
|
||||||
|
|
||||||
|
namespace base {
|
||||||
|
class DictionaryValue;
|
||||||
|
class FilePath;
|
||||||
|
}
|
||||||
|
|
||||||
namespace content {
|
namespace content {
|
||||||
class WebContents;
|
class WebContents;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace printing {
|
namespace printing {
|
||||||
class PrinterQuery;
|
class PrinterQuery;
|
||||||
|
class PrintJobManager;
|
||||||
class PrintQueriesQueue;
|
class PrintQueriesQueue;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace atom {
|
|
||||||
|
|
||||||
// This class filters out incoming printing related IPC messages for the
|
// This class filters out incoming printing related IPC messages for the
|
||||||
// renderer process on the IPC thread.
|
// renderer process on the IPC thread.
|
||||||
class PrintingMessageFilter : public content::BrowserMessageFilter {
|
class PrintingMessageFilter : public content::BrowserMessageFilter {
|
||||||
|
@ -49,21 +54,29 @@ class PrintingMessageFilter : public content::BrowserMessageFilter {
|
||||||
// Must be called on the UI thread.
|
// Must be called on the UI thread.
|
||||||
content::WebContents* GetWebContentsForRenderView(int render_view_id);
|
content::WebContents* GetWebContentsForRenderView(int render_view_id);
|
||||||
|
|
||||||
|
// GetPrintSettingsForRenderView must be called via PostTask and
|
||||||
|
// base::Bind. Collapse the settings-specific params into a
|
||||||
|
// struct to avoid running into issues with too many params
|
||||||
|
// to base::Bind.
|
||||||
|
struct GetPrintSettingsForRenderViewParams;
|
||||||
|
|
||||||
// Retrieve print settings. Uses |render_view_id| to get a parent
|
// Retrieve print settings. Uses |render_view_id| to get a parent
|
||||||
// for any UI created if needed.
|
// for any UI created if needed.
|
||||||
void GetPrintSettingsForRenderView(
|
void GetPrintSettingsForRenderView(
|
||||||
int render_view_id,
|
int render_view_id,
|
||||||
bool ask_user_for_settings,
|
GetPrintSettingsForRenderViewParams params,
|
||||||
PrintHostMsg_ScriptedPrint_Params params,
|
const base::Closure& callback,
|
||||||
const base::Callback<void(const PrintMsg_PrintPages_Params&)>callback,
|
scoped_refptr<printing::PrinterQuery> printer_query);
|
||||||
|
|
||||||
|
void OnGetPrintSettingsFailed(
|
||||||
|
const base::Closure& callback,
|
||||||
scoped_refptr<printing::PrinterQuery> printer_query);
|
scoped_refptr<printing::PrinterQuery> printer_query);
|
||||||
|
|
||||||
// Get the default print setting.
|
// Get the default print setting.
|
||||||
void OnGetDefaultPrintSettings(IPC::Message* reply_msg);
|
void OnGetDefaultPrintSettings(IPC::Message* reply_msg);
|
||||||
void OnGetDefaultPrintSettingsReply(
|
void OnGetDefaultPrintSettingsReply(
|
||||||
scoped_refptr<printing::PrinterQuery> printer_query,
|
scoped_refptr<printing::PrinterQuery> printer_query,
|
||||||
IPC::Message* reply_msg,
|
IPC::Message* reply_msg);
|
||||||
const PrintMsg_PrintPages_Params& params);
|
|
||||||
|
|
||||||
// The renderer host have to show to the user the print dialog and returns
|
// The renderer host have to show to the user the print dialog and returns
|
||||||
// the selected print settings. The task is handled by the print worker
|
// the selected print settings. The task is handled by the print worker
|
||||||
|
@ -72,8 +85,7 @@ class PrintingMessageFilter : public content::BrowserMessageFilter {
|
||||||
IPC::Message* reply_msg);
|
IPC::Message* reply_msg);
|
||||||
void OnScriptedPrintReply(
|
void OnScriptedPrintReply(
|
||||||
scoped_refptr<printing::PrinterQuery> printer_query,
|
scoped_refptr<printing::PrinterQuery> printer_query,
|
||||||
IPC::Message* reply_msg,
|
IPC::Message* reply_msg);
|
||||||
const PrintMsg_PrintPages_Params& params);
|
|
||||||
|
|
||||||
const int render_process_id_;
|
const int render_process_id_;
|
||||||
|
|
||||||
|
@ -82,6 +94,4 @@ class PrintingMessageFilter : public content::BrowserMessageFilter {
|
||||||
DISALLOW_COPY_AND_ASSIGN(PrintingMessageFilter);
|
DISALLOW_COPY_AND_ASSIGN(PrintingMessageFilter);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace atom
|
#endif // CHROME_BROWSER_PRINTING_PRINTING_MESSAGE_FILTER_H_
|
||||||
|
|
||||||
#endif // ATOM_BROWSER_PRINTING_PRINTING_MESSAGE_FILTER_H_
|
|
Loading…
Reference in a new issue