1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 // IPC messages for printing.
6 // Multiply-included message file, hence no include guard.
11 #include "base/memory/shared_memory.h"
12 #include "base/values.h"
13 #include "components/printing/common/printing_param_traits_macros.h"
14 #include "ipc/ipc_message_macros.h"
15 #include "printing/page_range.h"
16 #include "printing/page_size_margins.h"
17 #include "printing/print_job_constants.h"
18 #include "third_party/WebKit/public/web/WebPrintScalingOption.h"
19 #include "ui/gfx/geometry/rect.h"
20 #include "ui/gfx/ipc/gfx_param_traits.h"
21 #include "ui/gfx/native_widget_types.h"
23 // Force multiple inclusion of the param traits file to generate all methods.
24 #undef COMPONENTS_PRINTING_COMMON_PRINTING_PARAM_TRAITS_MACROS_H_
26 #ifndef COMPONENTS_PRINTING_COMMON_PRINT_MESSAGES_H_
27 #define COMPONENTS_PRINTING_COMMON_PRINT_MESSAGES_H_
29 struct PrintMsg_Print_Params
{
30 PrintMsg_Print_Params();
31 ~PrintMsg_Print_Params();
33 // Resets the members of the struct to 0.
37 gfx::Size content_size
;
38 gfx::Rect printable_area
;
47 bool supports_alpha_blend
;
49 int preview_request_id
;
50 bool is_first_request
;
51 blink::WebPrintScalingOption print_scaling_option
;
53 bool display_header_footer
;
56 bool should_print_backgrounds
;
59 struct PrintMsg_PrintPages_Params
{
60 PrintMsg_PrintPages_Params();
61 ~PrintMsg_PrintPages_Params();
63 // Resets the members of the struct to 0.
66 PrintMsg_Print_Params params
;
67 std::vector
<int> pages
;
70 struct PrintHostMsg_RequestPrintPreview_Params
{
71 PrintHostMsg_RequestPrintPreview_Params();
72 ~PrintHostMsg_RequestPrintPreview_Params();
79 struct PrintHostMsg_SetOptionsFromDocument_Params
{
80 PrintHostMsg_SetOptionsFromDocument_Params();
81 ~PrintHostMsg_SetOptionsFromDocument_Params();
83 bool is_scaling_disabled
;
85 printing::DuplexMode duplex
;
86 printing::PageRanges page_ranges
;
89 #endif // COMPONENTS_PRINTING_COMMON_PRINT_MESSAGES_H_
91 #define IPC_MESSAGE_START PrintMsgStart
93 IPC_ENUM_TRAITS_MAX_VALUE(blink::WebPrintScalingOption
,
94 blink::WebPrintScalingOptionLast
)
96 // Parameters for a render request.
97 IPC_STRUCT_TRAITS_BEGIN(PrintMsg_Print_Params
)
98 // Physical size of the page, including non-printable margins,
99 // in pixels according to dpi.
100 IPC_STRUCT_TRAITS_MEMBER(page_size
)
102 // In pixels according to dpi_x and dpi_y.
103 IPC_STRUCT_TRAITS_MEMBER(content_size
)
105 // Physical printable area of the page in pixels according to dpi.
106 IPC_STRUCT_TRAITS_MEMBER(printable_area
)
108 // The y-offset of the printable area, in pixels according to dpi.
109 IPC_STRUCT_TRAITS_MEMBER(margin_top
)
111 // The x-offset of the printable area, in pixels according to dpi.
112 IPC_STRUCT_TRAITS_MEMBER(margin_left
)
114 // Specifies dots per inch.
115 IPC_STRUCT_TRAITS_MEMBER(dpi
)
117 // Minimum shrink factor. See PrintSettings::min_shrink for more information.
118 IPC_STRUCT_TRAITS_MEMBER(min_shrink
)
120 // Maximum shrink factor. See PrintSettings::max_shrink for more information.
121 IPC_STRUCT_TRAITS_MEMBER(max_shrink
)
123 // Desired apparent dpi on paper.
124 IPC_STRUCT_TRAITS_MEMBER(desired_dpi
)
126 // Cookie for the document to ensure correctness.
127 IPC_STRUCT_TRAITS_MEMBER(document_cookie
)
129 // Should only print currently selected text.
130 IPC_STRUCT_TRAITS_MEMBER(selection_only
)
132 // Does the printer support alpha blending?
133 IPC_STRUCT_TRAITS_MEMBER(supports_alpha_blend
)
135 // *** Parameters below are used only for print preview. ***
137 // The print preview ui associated with this request.
138 IPC_STRUCT_TRAITS_MEMBER(preview_ui_id
)
140 // The id of the preview request.
141 IPC_STRUCT_TRAITS_MEMBER(preview_request_id
)
143 // True if this is the first preview request.
144 IPC_STRUCT_TRAITS_MEMBER(is_first_request
)
146 // Specifies the page scaling option for preview printing.
147 IPC_STRUCT_TRAITS_MEMBER(print_scaling_option
)
149 // True if print to pdf is requested.
150 IPC_STRUCT_TRAITS_MEMBER(print_to_pdf
)
152 // Specifies if the header and footer should be rendered.
153 IPC_STRUCT_TRAITS_MEMBER(display_header_footer
)
155 // Title string to be printed as header if requested by the user.
156 IPC_STRUCT_TRAITS_MEMBER(title
)
158 // URL string to be printed as footer if requested by the user.
159 IPC_STRUCT_TRAITS_MEMBER(url
)
161 // True if print backgrounds is requested by the user.
162 IPC_STRUCT_TRAITS_MEMBER(should_print_backgrounds
)
163 IPC_STRUCT_TRAITS_END()
165 IPC_STRUCT_BEGIN(PrintMsg_PrintPage_Params
)
166 // Parameters to render the page as a printed page. It must always be the same
167 // value for all the document.
168 IPC_STRUCT_MEMBER(PrintMsg_Print_Params
, params
)
170 // The page number is the indicator of the square that should be rendered
171 // according to the layout specified in PrintMsg_Print_Params.
172 IPC_STRUCT_MEMBER(int, page_number
)
175 IPC_STRUCT_TRAITS_BEGIN(PrintHostMsg_RequestPrintPreview_Params
)
176 IPC_STRUCT_TRAITS_MEMBER(is_modifiable
)
177 IPC_STRUCT_TRAITS_MEMBER(webnode_only
)
178 IPC_STRUCT_TRAITS_MEMBER(has_selection
)
179 IPC_STRUCT_TRAITS_MEMBER(selection_only
)
180 IPC_STRUCT_TRAITS_END()
182 IPC_STRUCT_TRAITS_BEGIN(printing::PageRange
)
183 IPC_STRUCT_TRAITS_MEMBER(from
)
184 IPC_STRUCT_TRAITS_MEMBER(to
)
185 IPC_STRUCT_TRAITS_END()
187 IPC_STRUCT_TRAITS_BEGIN(PrintHostMsg_SetOptionsFromDocument_Params
)
188 // Specifies whether print scaling is enabled or not.
189 IPC_STRUCT_TRAITS_MEMBER(is_scaling_disabled
)
191 // Specifies number of copies to be printed.
192 IPC_STRUCT_TRAITS_MEMBER(copies
)
194 // Specifies paper handling option.
195 IPC_STRUCT_TRAITS_MEMBER(duplex
)
197 // Specifies page range to be printed.
198 IPC_STRUCT_TRAITS_MEMBER(page_ranges
)
199 IPC_STRUCT_TRAITS_END()
201 IPC_STRUCT_TRAITS_BEGIN(printing::PageSizeMargins
)
202 IPC_STRUCT_TRAITS_MEMBER(content_width
)
203 IPC_STRUCT_TRAITS_MEMBER(content_height
)
204 IPC_STRUCT_TRAITS_MEMBER(margin_left
)
205 IPC_STRUCT_TRAITS_MEMBER(margin_right
)
206 IPC_STRUCT_TRAITS_MEMBER(margin_top
)
207 IPC_STRUCT_TRAITS_MEMBER(margin_bottom
)
208 IPC_STRUCT_TRAITS_END()
210 IPC_STRUCT_TRAITS_BEGIN(PrintMsg_PrintPages_Params
)
211 // Parameters to render the page as a printed page. It must always be the same
212 // value for all the document.
213 IPC_STRUCT_TRAITS_MEMBER(params
)
215 // If empty, this means a request to render all the printed pages.
216 IPC_STRUCT_TRAITS_MEMBER(pages
)
217 IPC_STRUCT_TRAITS_END()
219 // Parameters to describe a rendered document.
220 IPC_STRUCT_BEGIN(PrintHostMsg_DidPreviewDocument_Params
)
221 // A shared memory handle to metafile data.
222 IPC_STRUCT_MEMBER(base::SharedMemoryHandle
, metafile_data_handle
)
224 // Size of metafile data.
225 IPC_STRUCT_MEMBER(uint32
, data_size
)
227 // Cookie for the document to ensure correctness.
228 IPC_STRUCT_MEMBER(int, document_cookie
)
230 // Store the expected pages count.
231 IPC_STRUCT_MEMBER(int, expected_pages_count
)
233 // Whether the preview can be modified.
234 IPC_STRUCT_MEMBER(bool, modifiable
)
236 // The id of the preview request.
237 IPC_STRUCT_MEMBER(int, preview_request_id
)
240 // Parameters to describe a rendered preview page.
241 IPC_STRUCT_BEGIN(PrintHostMsg_DidPreviewPage_Params
)
242 // A shared memory handle to metafile data for a draft document of the page.
243 IPC_STRUCT_MEMBER(base::SharedMemoryHandle
, metafile_data_handle
)
245 // Size of metafile data.
246 IPC_STRUCT_MEMBER(uint32
, data_size
)
248 // |page_number| is zero-based and can be |printing::INVALID_PAGE_INDEX| if it
250 IPC_STRUCT_MEMBER(int, page_number
)
252 // The id of the preview request.
253 IPC_STRUCT_MEMBER(int, preview_request_id
)
256 // Parameters sent along with the page count.
257 IPC_STRUCT_BEGIN(PrintHostMsg_DidGetPreviewPageCount_Params
)
258 // Cookie for the document to ensure correctness.
259 IPC_STRUCT_MEMBER(int, document_cookie
)
262 IPC_STRUCT_MEMBER(int, page_count
)
264 // Indicates whether the previewed document is modifiable.
265 IPC_STRUCT_MEMBER(bool, is_modifiable
)
267 // The id of the preview request.
268 IPC_STRUCT_MEMBER(int, preview_request_id
)
270 // Indicates whether the existing preview data needs to be cleared or not.
271 IPC_STRUCT_MEMBER(bool, clear_preview_data
)
274 // Parameters to describe a rendered page.
275 IPC_STRUCT_BEGIN(PrintHostMsg_DidPrintPage_Params
)
276 // A shared memory handle to the EMF data. This data can be quite large so a
277 // memory map needs to be used.
278 IPC_STRUCT_MEMBER(base::SharedMemoryHandle
, metafile_data_handle
)
280 // Size of the metafile data.
281 IPC_STRUCT_MEMBER(uint32
, data_size
)
283 // Cookie for the document to ensure correctness.
284 IPC_STRUCT_MEMBER(int, document_cookie
)
287 IPC_STRUCT_MEMBER(int, page_number
)
289 // The size of the page the page author specified.
290 IPC_STRUCT_MEMBER(gfx::Size
, page_size
)
292 // The printable area the page author specified.
293 IPC_STRUCT_MEMBER(gfx::Rect
, content_area
)
296 // TODO(dgn) Rename *ScriptedPrint messages because they are not called only
298 // Parameters for the IPC message ViewHostMsg_ScriptedPrint
299 IPC_STRUCT_BEGIN(PrintHostMsg_ScriptedPrint_Params
)
300 IPC_STRUCT_MEMBER(int, cookie
)
301 IPC_STRUCT_MEMBER(int, expected_pages_count
)
302 IPC_STRUCT_MEMBER(bool, has_selection
)
303 IPC_STRUCT_MEMBER(bool, is_scripted
)
304 IPC_STRUCT_MEMBER(printing::MarginType
, margin_type
)
308 // Messages sent from the browser to the renderer.
310 // Tells the render view to initiate print preview for the entire document.
311 IPC_MESSAGE_ROUTED1(PrintMsg_InitiatePrintPreview
, bool /* selection_only */)
313 // Tells the render frame to initiate printing or print preview for a particular
314 // node, depending on which mode the render frame is in.
315 IPC_MESSAGE_ROUTED0(PrintMsg_PrintNodeUnderContextMenu
)
317 // Tells the renderer to print the print preview tab's PDF plugin without
318 // showing the print dialog. (This is the final step in the print preview
320 IPC_MESSAGE_ROUTED1(PrintMsg_PrintForPrintPreview
,
321 base::DictionaryValue
/* settings */)
323 #if defined(ENABLE_BASIC_PRINTING)
324 // Tells the render view to switch the CSS to print media type, renders every
325 // requested pages and switch back the CSS to display media type.
326 IPC_MESSAGE_ROUTED0(PrintMsg_PrintPages
)
328 // Like PrintMsg_PrintPages, but using the print preview document's frame/node.
329 IPC_MESSAGE_ROUTED0(PrintMsg_PrintForSystemDialog
)
330 #endif // ENABLE_BASIC_PRINTING
332 // Tells the render view that printing is done so it can clean up.
333 IPC_MESSAGE_ROUTED1(PrintMsg_PrintingDone
,
336 // Tells the render view whether scripted printing is blocked or not.
337 IPC_MESSAGE_ROUTED1(PrintMsg_SetScriptedPrintingBlocked
,
340 // Tells the render view to switch the CSS to print media type, renders every
341 // requested pages for print preview using the given |settings|. This gets
342 // called multiple times as the user updates settings.
343 IPC_MESSAGE_ROUTED1(PrintMsg_PrintPreview
,
344 base::DictionaryValue
/* settings */)
346 // Messages sent from the renderer to the browser.
349 // Duplicates a shared memory handle from the renderer to the browser. Then
350 // the renderer can flush the handle.
351 IPC_SYNC_MESSAGE_ROUTED1_1(PrintHostMsg_DuplicateSection
,
352 base::SharedMemoryHandle
/* renderer handle */,
353 base::SharedMemoryHandle
/* browser handle */)
356 // Check if printing is enabled.
357 IPC_SYNC_MESSAGE_ROUTED0_1(PrintHostMsg_IsPrintingEnabled
,
358 bool /* is_enabled */)
360 // Tells the browser that the renderer is done calculating the number of
361 // rendered pages according to the specified settings.
362 IPC_MESSAGE_ROUTED2(PrintHostMsg_DidGetPrintedPagesCount
,
363 int /* rendered document cookie */,
364 int /* number of rendered pages */)
366 // Sends the document cookie of the current printer query to the browser.
367 IPC_MESSAGE_ROUTED1(PrintHostMsg_DidGetDocumentCookie
,
368 int /* rendered document cookie */)
370 // Tells the browser that the print dialog has been shown.
371 IPC_MESSAGE_ROUTED0(PrintHostMsg_DidShowPrintDialog
)
373 // Sends back to the browser the rendered "printed page" that was requested by
374 // a ViewMsg_PrintPage message or from scripted printing. The memory handle in
375 // this message is already valid in the browser process.
376 IPC_MESSAGE_ROUTED1(PrintHostMsg_DidPrintPage
,
377 PrintHostMsg_DidPrintPage_Params
/* page content */)
379 // The renderer wants to know the default print settings.
380 IPC_SYNC_MESSAGE_ROUTED0_1(PrintHostMsg_GetDefaultPrintSettings
,
381 PrintMsg_Print_Params
/* default_settings */)
383 // The renderer wants to update the current print settings with new
385 IPC_SYNC_MESSAGE_ROUTED2_2(PrintHostMsg_UpdatePrintSettings
,
386 int /* document_cookie */,
387 base::DictionaryValue
/* job_settings */,
388 PrintMsg_PrintPages_Params
/* current_settings */,
391 // It's the renderer that controls the printing process when it is generated
392 // by javascript. This step is about showing UI to the user to select the
393 // final print settings. The output parameter is the same as
394 // ViewMsg_PrintPages which is executed implicitly.
395 IPC_SYNC_MESSAGE_ROUTED1_1(PrintHostMsg_ScriptedPrint
,
396 PrintHostMsg_ScriptedPrint_Params
,
397 PrintMsg_PrintPages_Params
398 /* settings chosen by the user*/)
400 #if defined(OS_CHROMEOS) || defined(OS_ANDROID)
401 // Asks the browser to create a temporary file for the renderer to fill
402 // in resulting PdfMetafileSkia in printing.
403 IPC_SYNC_MESSAGE_CONTROL1_2(PrintHostMsg_AllocateTempFileForPrinting
,
404 int /* render_view_id */,
405 base::FileDescriptor
/* temp file fd */,
406 int /* fd in browser*/) // Used only by Chrome OS.
407 IPC_MESSAGE_CONTROL2(PrintHostMsg_TempFileForPrintingWritten
,
408 int /* render_view_id */,
409 int /* fd in browser */) // Used only by Chrome OS.
412 // Asks the browser to do print preview.
413 IPC_MESSAGE_ROUTED1(PrintHostMsg_RequestPrintPreview
,
414 PrintHostMsg_RequestPrintPreview_Params
/* params */)
416 // Notify the browser the number of pages in the print preview document.
417 IPC_MESSAGE_ROUTED1(PrintHostMsg_DidGetPreviewPageCount
,
418 PrintHostMsg_DidGetPreviewPageCount_Params
/* params */)
420 // Notify the browser of the default page layout according to the currently
421 // selected printer and page size.
422 // |printable_area_in_points| Specifies the printable area in points.
423 // |has_custom_page_size_style| is true when the printing frame has a custom
424 // page size css otherwise false.
425 IPC_MESSAGE_ROUTED3(PrintHostMsg_DidGetDefaultPageLayout
,
426 printing::PageSizeMargins
/* page layout in points */,
427 gfx::Rect
/* printable area in points */,
428 bool /* has custom page size style */)
430 // Notify the browser a print preview page has been rendered.
431 IPC_MESSAGE_ROUTED1(PrintHostMsg_DidPreviewPage
,
432 PrintHostMsg_DidPreviewPage_Params
/* params */)
434 // Asks the browser whether the print preview has been cancelled.
435 IPC_SYNC_MESSAGE_ROUTED2_1(PrintHostMsg_CheckForCancel
,
436 int32
/* PrintPreviewUI ID */,
437 int /* request id */,
438 bool /* print preview cancelled */)
440 // This is sent when there are invalid printer settings.
441 IPC_MESSAGE_ROUTED0(PrintHostMsg_ShowInvalidPrinterSettingsError
)
443 // Sends back to the browser the complete rendered document (non-draft mode,
444 // used for printing) that was requested by a PrintMsg_PrintPreview message.
445 // The memory handle in this message is already valid in the browser process.
446 IPC_MESSAGE_ROUTED1(PrintHostMsg_MetafileReadyForPrinting
,
447 PrintHostMsg_DidPreviewDocument_Params
/* params */)
449 // Tell the browser printing failed.
450 IPC_MESSAGE_ROUTED1(PrintHostMsg_PrintingFailed
,
451 int /* document cookie */)
453 // Tell the browser print preview failed.
454 IPC_MESSAGE_ROUTED1(PrintHostMsg_PrintPreviewFailed
,
455 int /* document cookie */)
457 // Tell the browser print preview was cancelled.
458 IPC_MESSAGE_ROUTED1(PrintHostMsg_PrintPreviewCancelled
,
459 int /* document cookie */)
461 // Tell the browser print preview found the selected printer has invalid
462 // settings (which typically caused by disconnected network printer or printer
464 IPC_MESSAGE_ROUTED1(PrintHostMsg_PrintPreviewInvalidPrinterSettings
,
465 int /* document cookie */)
467 // Run a nested message loop in the renderer until print preview for
468 // window.print() finishes.
469 IPC_SYNC_MESSAGE_ROUTED0_0(PrintHostMsg_SetupScriptedPrintPreview
)
471 // Tell the browser to show the print preview, when the document is sufficiently
472 // loaded such that the renderer can determine whether it is modifiable or not.
473 IPC_MESSAGE_ROUTED1(PrintHostMsg_ShowScriptedPrintPreview
,
474 bool /* is_modifiable */)
476 // Notify the browser to set print presets based on source PDF document.
477 IPC_MESSAGE_ROUTED1(PrintHostMsg_SetOptionsFromDocument
,
478 PrintHostMsg_SetOptionsFromDocument_Params
/* params */)