Print enhancement: add webContents.printerList And a print option to select printer
This commit is contained in:
parent
093b844859
commit
023a3fd547
15 changed files with 290 additions and 27 deletions
|
@ -661,13 +661,14 @@ void PrintWebViewHelper::OnDestruct() {
|
|||
}
|
||||
|
||||
#if !defined(DISABLE_BASIC_PRINTING)
|
||||
void PrintWebViewHelper::OnPrintPages(bool silent, bool print_background) {
|
||||
void PrintWebViewHelper::OnPrintPages(bool silent, bool print_background,
|
||||
const base::string16& device_name) {
|
||||
if (ipc_nesting_level_> 1)
|
||||
return;
|
||||
|
||||
blink::WebLocalFrame* frame =
|
||||
render_view()->GetMainRenderFrame()->GetWebFrame();
|
||||
Print(frame, blink::WebNode(), silent, print_background);
|
||||
Print(frame, blink::WebNode(), silent, print_background, device_name);
|
||||
}
|
||||
#endif // !DISABLE_BASIC_PRINTING
|
||||
|
||||
|
@ -851,7 +852,8 @@ void PrintWebViewHelper::PrintNode(const blink::WebNode& node) {
|
|||
void PrintWebViewHelper::Print(blink::WebLocalFrame* frame,
|
||||
const blink::WebNode& node,
|
||||
bool silent,
|
||||
bool print_background) {
|
||||
bool print_background,
|
||||
const base::string16& device_name) {
|
||||
// If still not finished with earlier print request simply ignore.
|
||||
if (prep_frame_view_)
|
||||
return;
|
||||
|
@ -859,7 +861,7 @@ void PrintWebViewHelper::Print(blink::WebLocalFrame* frame,
|
|||
FrameReference frame_ref(frame);
|
||||
|
||||
int expected_page_count = 0;
|
||||
if (!CalculateNumberOfPages(frame, node, &expected_page_count)) {
|
||||
if (!CalculateNumberOfPages(frame, node, &expected_page_count, device_name)) {
|
||||
DidFinishPrinting(FAIL_PRINT_INIT);
|
||||
return; // Failed to init print page settings.
|
||||
}
|
||||
|
@ -995,10 +997,16 @@ void PrintWebViewHelper::ComputePageLayoutInPointsForCss(
|
|||
CalculatePageLayoutFromPrintParams(params, page_layout_in_points);
|
||||
}
|
||||
|
||||
bool PrintWebViewHelper::InitPrintSettings(bool fit_to_paper_size) {
|
||||
bool PrintWebViewHelper::InitPrintSettings(bool fit_to_paper_size,
|
||||
const base::string16& device_name) {
|
||||
PrintMsg_PrintPages_Params settings;
|
||||
Send(new PrintHostMsg_GetDefaultPrintSettings(routing_id(),
|
||||
&settings.params));
|
||||
if (device_name.empty()) {
|
||||
Send(new PrintHostMsg_GetDefaultPrintSettings(routing_id(),
|
||||
&settings.params));
|
||||
} else {
|
||||
Send(new PrintHostMsg_InitSettingWithDeviceName(routing_id(), device_name,
|
||||
&settings.params));
|
||||
}
|
||||
// Check if the printer returned any settings, if the settings is empty, we
|
||||
// can safely assume there are no printer drivers configured. So we safely
|
||||
// terminate.
|
||||
|
@ -1023,10 +1031,11 @@ bool PrintWebViewHelper::InitPrintSettings(bool fit_to_paper_size) {
|
|||
|
||||
bool PrintWebViewHelper::CalculateNumberOfPages(blink::WebLocalFrame* frame,
|
||||
const blink::WebNode& node,
|
||||
int* number_of_pages) {
|
||||
int* number_of_pages,
|
||||
const base::string16& device_name) {
|
||||
DCHECK(frame);
|
||||
bool fit_to_paper_size = !(PrintingNodeOrPdfFrame(frame, node));
|
||||
if (!InitPrintSettings(fit_to_paper_size)) {
|
||||
if (!InitPrintSettings(fit_to_paper_size, device_name)) {
|
||||
notify_browser_of_print_failure_ = false;
|
||||
Send(new PrintHostMsg_ShowInvalidPrinterSettingsError(routing_id()));
|
||||
return false;
|
||||
|
|
|
@ -98,7 +98,7 @@ class PrintWebViewHelper
|
|||
|
||||
// Message handlers ---------------------------------------------------------
|
||||
#if !defined(DISABLE_BASIC_PRINTING)
|
||||
void OnPrintPages(bool silent, bool print_background);
|
||||
void OnPrintPages(bool silent, bool print_background, const base::string16&);
|
||||
void OnPrintingDone(bool success);
|
||||
#endif // !DISABLE_BASIC_PRINTING
|
||||
void OnPrintPreview(const base::DictionaryValue& settings);
|
||||
|
@ -137,7 +137,8 @@ class PrintWebViewHelper
|
|||
void Print(blink::WebLocalFrame* frame,
|
||||
const blink::WebNode& node,
|
||||
bool silent = false,
|
||||
bool print_background = false);
|
||||
bool print_background = false,
|
||||
const base::string16& device_name = base::string16());
|
||||
|
||||
// Notification when printing is done - signal tear-down/free resources.
|
||||
void DidFinishPrinting(PrintingResult result);
|
||||
|
@ -146,12 +147,14 @@ class PrintWebViewHelper
|
|||
|
||||
// Initialize print page settings with default settings.
|
||||
// Used only for native printing workflow.
|
||||
bool InitPrintSettings(bool fit_to_paper_size);
|
||||
bool InitPrintSettings(bool fit_to_paper_size,
|
||||
const base::string16& device_name = base::string16());
|
||||
|
||||
// Calculate number of pages in source document.
|
||||
bool CalculateNumberOfPages(blink::WebLocalFrame* frame,
|
||||
const blink::WebNode& node,
|
||||
int* number_of_pages);
|
||||
int* number_of_pages,
|
||||
const base::string16& device_name = base::string16());
|
||||
|
||||
// Update the current print settings with new |passed_job_settings|.
|
||||
// |passed_job_settings| dictionary contains print job details such as printer
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue