Commit 87d1a392 authored by n.bansal@samsung.com's avatar n.bansal@samsung.com

Add support to send print preset options in one message

This patch introduces structure that should be filled with all
print preset options that we need to get from PDF and set in print
preview.

Before this patch one message was being sent to browser to set PrintScaling
property but going forward, more properties will be supported and so
it is better to send only one message with all properties set in one structure.

BUG=169120

Review URL: https://codereview.chromium.org/388783003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@285159 0039d316-1c4b-4281-b951-d872f2087c98
parent 785e6a45
......@@ -194,11 +194,12 @@ void PrintPreviewMessageHandler::OnInvalidPrinterSettings(int document_cookie) {
print_preview_ui->OnInvalidPrinterSettings();
}
void PrintPreviewMessageHandler::OnPrintPreviewScalingDisabled() {
void PrintPreviewMessageHandler::OnSetOptionsFromDocument(
const PrintHostMsg_SetOptionsFromDocument_Params& params) {
PrintPreviewUI* print_preview_ui = GetPrintPreviewUI();
if (!print_preview_ui)
return;
print_preview_ui->OnPrintPreviewScalingDisabled();
print_preview_ui->OnSetOptionsFromDocument(params);
}
bool PrintPreviewMessageHandler::OnMessageReceived(
......@@ -221,8 +222,8 @@ bool PrintPreviewMessageHandler::OnMessageReceived(
OnPrintPreviewCancelled)
IPC_MESSAGE_HANDLER(PrintHostMsg_PrintPreviewInvalidPrinterSettings,
OnInvalidPrinterSettings)
IPC_MESSAGE_HANDLER(PrintHostMsg_PrintPreviewScalingDisabled,
OnPrintPreviewScalingDisabled)
IPC_MESSAGE_HANDLER(PrintHostMsg_SetOptionsFromDocument,
OnSetOptionsFromDocument)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
return handled;
......
......@@ -14,6 +14,7 @@ struct PrintHostMsg_DidGetPreviewPageCount_Params;
struct PrintHostMsg_DidPreviewDocument_Params;
struct PrintHostMsg_DidPreviewPage_Params;
struct PrintHostMsg_RequestPrintPreview_Params;
struct PrintHostMsg_SetOptionsFromDocument_Params;
namespace content {
class WebContents;
......@@ -63,7 +64,8 @@ class PrintPreviewMessageHandler
void OnPrintPreviewFailed(int document_cookie);
void OnPrintPreviewCancelled(int document_cookie);
void OnInvalidPrinterSettings(int document_cookie);
void OnPrintPreviewScalingDisabled();
void OnSetOptionsFromDocument(
const PrintHostMsg_SetOptionsFromDocument_Params& params);
DISALLOW_COPY_AND_ASSIGN(PrintPreviewMessageHandler);
};
......
......@@ -609,8 +609,11 @@ void PrintPreviewUI::OnReloadPrintersList() {
web_ui()->CallJavascriptFunction("reloadPrintersList");
}
void PrintPreviewUI::OnPrintPreviewScalingDisabled() {
web_ui()->CallJavascriptFunction("printScalingDisabledForSourcePDF");
void PrintPreviewUI::OnSetOptionsFromDocument(
const PrintHostMsg_SetOptionsFromDocument_Params& params) {
// Notify WebUI that print scaling is disabled
if (params.is_scaling_disabled)
web_ui()->CallJavascriptFunction("printScalingDisabledForSourcePDF");
}
// static
......
......@@ -17,6 +17,7 @@ class PrintPreviewDataService;
class PrintPreviewHandler;
struct PrintHostMsg_DidGetPreviewPageCount_Params;
struct PrintHostMsg_RequestPrintPreview_Params;
struct PrintHostMsg_SetOptionsFromDocument_Params;
namespace base {
class FilePath;
......@@ -141,9 +142,9 @@ class PrintPreviewUI : public ConstrainedWebDialogUI {
// Reload the printers list.
void OnReloadPrintersList();
// Notifies the WebUI that the pdf print scaling option is disabled by
// default.
void OnPrintPreviewScalingDisabled();
// Notifies the WebUI to set print preset options from source PDF.
void OnSetOptionsFromDocument(
const PrintHostMsg_SetOptionsFromDocument_Params& params);
// Allows tests to wait until the print preview dialog is loaded. Optionally
// also instructs the dialog to auto-cancel, which is used for testing only.
......
......@@ -20,11 +20,6 @@
#define IPC_MESSAGE_START ChromeUtilityPrintingMsgStart
IPC_STRUCT_TRAITS_BEGIN(printing::PageRange)
IPC_STRUCT_TRAITS_MEMBER(from)
IPC_STRUCT_TRAITS_MEMBER(to)
IPC_STRUCT_TRAITS_END()
IPC_STRUCT_TRAITS_BEGIN(printing::PrinterCapsAndDefaults)
IPC_STRUCT_TRAITS_MEMBER(printer_capabilities)
IPC_STRUCT_TRAITS_MEMBER(caps_mime_type)
......@@ -33,9 +28,6 @@ IPC_STRUCT_TRAITS_BEGIN(printing::PrinterCapsAndDefaults)
IPC_STRUCT_TRAITS_END()
IPC_ENUM_TRAITS_MAX_VALUE(printing::ColorModel, printing::PROCESSCOLORMODEL_RGB)
IPC_ENUM_TRAITS_MIN_MAX_VALUE(printing::DuplexMode,
printing::UNKNOWN_DUPLEX_MODE,
printing::SHORT_EDGE)
IPC_STRUCT_TRAITS_BEGIN(printing::PrinterSemanticCapsAndDefaults::Paper)
IPC_STRUCT_TRAITS_MEMBER(display_name)
......
......@@ -79,3 +79,14 @@ PrintHostMsg_RequestPrintPreview_Params::
PrintHostMsg_RequestPrintPreview_Params::
~PrintHostMsg_RequestPrintPreview_Params() {}
PrintHostMsg_SetOptionsFromDocument_Params::
PrintHostMsg_SetOptionsFromDocument_Params()
: is_scaling_disabled(false),
copies(0),
duplex(printing::UNKNOWN_DUPLEX_MODE) {
}
PrintHostMsg_SetOptionsFromDocument_Params::
~PrintHostMsg_SetOptionsFromDocument_Params() {
}
......@@ -11,6 +11,7 @@
#include "base/memory/shared_memory.h"
#include "base/values.h"
#include "ipc/ipc_message_macros.h"
#include "printing/page_range.h"
#include "printing/page_size_margins.h"
#include "printing/print_job_constants.h"
#include "third_party/WebKit/public/web/WebPrintScalingOption.h"
......@@ -71,6 +72,16 @@ struct PrintHostMsg_RequestPrintPreview_Params {
bool selection_only;
};
struct PrintHostMsg_SetOptionsFromDocument_Params {
PrintHostMsg_SetOptionsFromDocument_Params();
~PrintHostMsg_SetOptionsFromDocument_Params();
bool is_scaling_disabled;
int copies;
printing::DuplexMode duplex;
printing::PageRanges page_ranges;
};
#endif // CHROME_COMMON_PRINT_MESSAGES_H_
#define IPC_MESSAGE_START PrintMsgStart
......@@ -79,6 +90,9 @@ IPC_ENUM_TRAITS_MAX_VALUE(printing::MarginType,
printing::MARGIN_TYPE_LAST)
IPC_ENUM_TRAITS_MAX_VALUE(blink::WebPrintScalingOption,
blink::WebPrintScalingOptionLast)
IPC_ENUM_TRAITS_MIN_MAX_VALUE(printing::DuplexMode,
printing::UNKNOWN_DUPLEX_MODE,
printing::SHORT_EDGE)
// Parameters for a render request.
IPC_STRUCT_TRAITS_BEGIN(PrintMsg_Print_Params)
......@@ -166,6 +180,25 @@ IPC_STRUCT_TRAITS_BEGIN(PrintHostMsg_RequestPrintPreview_Params)
IPC_STRUCT_TRAITS_MEMBER(selection_only)
IPC_STRUCT_TRAITS_END()
IPC_STRUCT_TRAITS_BEGIN(printing::PageRange)
IPC_STRUCT_TRAITS_MEMBER(from)
IPC_STRUCT_TRAITS_MEMBER(to)
IPC_STRUCT_TRAITS_END()
IPC_STRUCT_TRAITS_BEGIN(PrintHostMsg_SetOptionsFromDocument_Params)
// Specifies whether print scaling is enabled or not.
IPC_STRUCT_TRAITS_MEMBER(is_scaling_disabled)
// Specifies number of copies to be printed.
IPC_STRUCT_TRAITS_MEMBER(copies)
// Specifies paper handling option.
IPC_STRUCT_TRAITS_MEMBER(duplex)
// Specifies page range to be printed.
IPC_STRUCT_TRAITS_MEMBER(page_ranges)
IPC_STRUCT_TRAITS_END()
IPC_STRUCT_TRAITS_BEGIN(printing::PageSizeMargins)
IPC_STRUCT_TRAITS_MEMBER(content_width)
IPC_STRUCT_TRAITS_MEMBER(content_height)
......@@ -443,6 +476,6 @@ IPC_SYNC_MESSAGE_ROUTED0_0(PrintHostMsg_SetupScriptedPrintPreview)
IPC_MESSAGE_ROUTED1(PrintHostMsg_ShowScriptedPrintPreview,
bool /* is_modifiable */)
// Notify the browser that the PDF in the initiator renderer has disabled print
// scaling option.
IPC_MESSAGE_ROUTED0(PrintHostMsg_PrintPreviewScalingDisabled)
// Notify the browser to set print presets based on source PDF document.
IPC_MESSAGE_ROUTED1(PrintHostMsg_SetOptionsFromDocument,
PrintHostMsg_SetOptionsFromDocument_Params /* params */)
......@@ -1025,13 +1025,13 @@ void PrintWebViewHelper::OnPrintPreview(const base::DictionaryValue& settings) {
return;
}
// If we are previewing a pdf and the print scaling is disabled, send a
// Set the options from document if we are previewing a pdf and send a
// message to browser.
if (print_pages_params_->params.is_first_request &&
!print_preview_context_.IsModifiable() &&
print_preview_context_.source_frame()->isPrintScalingDisabledForPlugin(
print_preview_context_.source_node())) {
Send(new PrintHostMsg_PrintPreviewScalingDisabled(routing_id()));
!print_preview_context_.IsModifiable()) {
PrintHostMsg_SetOptionsFromDocument_Params params;
SetOptionsFromDocument(params);
Send(new PrintHostMsg_SetOptionsFromDocument(routing_id(), params));
}
is_print_ready_metafile_sent_ = false;
......@@ -1466,6 +1466,15 @@ bool PrintWebViewHelper::CalculateNumberOfPages(blink::WebLocalFrame* frame,
return true;
}
void PrintWebViewHelper::SetOptionsFromDocument(
PrintHostMsg_SetOptionsFromDocument_Params& params) {
blink::WebLocalFrame* source_frame = print_preview_context_.source_frame();
const blink::WebNode& source_node = print_preview_context_.source_node();
params.is_scaling_disabled =
source_frame->isPrintScalingDisabledForPlugin(source_node);
}
bool PrintWebViewHelper::UpdatePrintSettings(
blink::WebLocalFrame* frame,
const blink::WebNode& node,
......
......@@ -23,6 +23,7 @@
struct PrintMsg_Print_Params;
struct PrintMsg_PrintPage_Params;
struct PrintMsg_PrintPages_Params;
struct PrintHostMsg_SetOptionsFromDocument_Params;
namespace base {
class DictionaryValue;
......@@ -178,6 +179,10 @@ class PrintWebViewHelper
const blink::WebNode& node,
int* number_of_pages);
// Set options for print preset from source PDF document.
void SetOptionsFromDocument(
PrintHostMsg_SetOptionsFromDocument_Params& params);
// Update the current print settings with new |passed_job_settings|.
// |passed_job_settings| dictionary contains print job details such as printer
// name, number of copies, page range, etc.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment