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 "ipc/ipc_message_macros.h"
14 #include "printing/page_size_margins.h"
15 #include "printing/print_job_constants.h"
16 #include "third_party/WebKit/public/web/WebPrintScalingOption.h"
17 #include "ui/gfx/native_widget_types.h"
18 #include "ui/gfx/rect.h"
20 #ifndef CHROME_COMMON_PRINT_MESSAGES_H_
21 #define CHROME_COMMON_PRINT_MESSAGES_H_
23 struct PrintMsg_Print_Params
{
24 PrintMsg_Print_Params();
25 ~PrintMsg_Print_Params();
27 // Resets the members of the struct to 0.
31 gfx::Size content_size
;
32 gfx::Rect printable_area
;
41 bool supports_alpha_blend
;
43 int preview_request_id
;
44 bool is_first_request
;
45 blink::WebPrintScalingOption print_scaling_option
;
47 bool display_header_footer
;
50 bool should_print_backgrounds
;
53 struct PrintMsg_PrintPages_Params
{
54 PrintMsg_PrintPages_Params();
55 ~PrintMsg_PrintPages_Params();
57 // Resets the members of the struct to 0.
60 PrintMsg_Print_Params params
;
61 std::vector
<int> pages
;
64 struct PrintHostMsg_RequestPrintPreview_Params
{
65 PrintHostMsg_RequestPrintPreview_Params();
66 ~PrintHostMsg_RequestPrintPreview_Params();
73 #endif // CHROME_COMMON_PRINT_MESSAGES_H_
75 #define IPC_MESSAGE_START PrintMsgStart
77 IPC_ENUM_TRAITS(printing::MarginType
)
78 IPC_ENUM_TRAITS(blink::WebPrintScalingOption
)
80 // Parameters for a render request.
81 IPC_STRUCT_TRAITS_BEGIN(PrintMsg_Print_Params
)
82 // Physical size of the page, including non-printable margins,
83 // in pixels according to dpi.
84 IPC_STRUCT_TRAITS_MEMBER(page_size
)
86 // In pixels according to dpi_x and dpi_y.
87 IPC_STRUCT_TRAITS_MEMBER(content_size
)
89 // Physical printable area of the page in pixels according to dpi.
90 IPC_STRUCT_TRAITS_MEMBER(printable_area
)
92 // The y-offset of the printable area, in pixels according to dpi.
93 IPC_STRUCT_TRAITS_MEMBER(margin_top
)
95 // The x-offset of the printable area, in pixels according to dpi.
96 IPC_STRUCT_TRAITS_MEMBER(margin_left
)
98 // Specifies dots per inch.
99 IPC_STRUCT_TRAITS_MEMBER(dpi
)
101 // Minimum shrink factor. See PrintSettings::min_shrink for more information.
102 IPC_STRUCT_TRAITS_MEMBER(min_shrink
)
104 // Maximum shrink factor. See PrintSettings::max_shrink for more information.
105 IPC_STRUCT_TRAITS_MEMBER(max_shrink
)
107 // Desired apparent dpi on paper.
108 IPC_STRUCT_TRAITS_MEMBER(desired_dpi
)
110 // Cookie for the document to ensure correctness.
111 IPC_STRUCT_TRAITS_MEMBER(document_cookie
)
113 // Should only print currently selected text.
114 IPC_STRUCT_TRAITS_MEMBER(selection_only
)
116 // Does the printer support alpha blending?
117 IPC_STRUCT_TRAITS_MEMBER(supports_alpha_blend
)
119 // *** Parameters below are used only for print preview. ***
121 // The print preview ui associated with this request.
122 IPC_STRUCT_TRAITS_MEMBER(preview_ui_id
)
124 // The id of the preview request.
125 IPC_STRUCT_TRAITS_MEMBER(preview_request_id
)
127 // True if this is the first preview request.
128 IPC_STRUCT_TRAITS_MEMBER(is_first_request
)
130 // Specifies the page scaling option for preview printing.
131 IPC_STRUCT_TRAITS_MEMBER(print_scaling_option
)
133 // True if print to pdf is requested.
134 IPC_STRUCT_TRAITS_MEMBER(print_to_pdf
)
136 // Specifies if the header and footer should be rendered.
137 IPC_STRUCT_TRAITS_MEMBER(display_header_footer
)
139 // Title string to be printed as header if requested by the user.
140 IPC_STRUCT_TRAITS_MEMBER(title
)
142 // URL string to be printed as footer if requested by the user.
143 IPC_STRUCT_TRAITS_MEMBER(url
)
145 // True if print backgrounds is requested by the user.
146 IPC_STRUCT_TRAITS_MEMBER(should_print_backgrounds
)
147 IPC_STRUCT_TRAITS_END()
149 IPC_STRUCT_BEGIN(PrintMsg_PrintPage_Params
)
150 // Parameters to render the page as a printed page. It must always be the same
151 // value for all the document.
152 IPC_STRUCT_MEMBER(PrintMsg_Print_Params
, params
)
154 // The page number is the indicator of the square that should be rendered
155 // according to the layout specified in PrintMsg_Print_Params.
156 IPC_STRUCT_MEMBER(int, page_number
)
159 IPC_STRUCT_TRAITS_BEGIN(PrintHostMsg_RequestPrintPreview_Params
)
160 IPC_STRUCT_TRAITS_MEMBER(is_modifiable
)
161 IPC_STRUCT_TRAITS_MEMBER(webnode_only
)
162 IPC_STRUCT_TRAITS_MEMBER(has_selection
)
163 IPC_STRUCT_TRAITS_MEMBER(selection_only
)
164 IPC_STRUCT_TRAITS_END()
166 IPC_STRUCT_TRAITS_BEGIN(printing::PageSizeMargins
)
167 IPC_STRUCT_TRAITS_MEMBER(content_width
)
168 IPC_STRUCT_TRAITS_MEMBER(content_height
)
169 IPC_STRUCT_TRAITS_MEMBER(margin_left
)
170 IPC_STRUCT_TRAITS_MEMBER(margin_right
)
171 IPC_STRUCT_TRAITS_MEMBER(margin_top
)
172 IPC_STRUCT_TRAITS_MEMBER(margin_bottom
)
173 IPC_STRUCT_TRAITS_END()
175 IPC_STRUCT_TRAITS_BEGIN(PrintMsg_PrintPages_Params
)
176 // Parameters to render the page as a printed page. It must always be the same
177 // value for all the document.
178 IPC_STRUCT_TRAITS_MEMBER(params
)
180 // If empty, this means a request to render all the printed pages.
181 IPC_STRUCT_TRAITS_MEMBER(pages
)
182 IPC_STRUCT_TRAITS_END()
184 // Parameters to describe a rendered document.
185 IPC_STRUCT_BEGIN(PrintHostMsg_DidPreviewDocument_Params
)
186 // A shared memory handle to metafile data.
187 IPC_STRUCT_MEMBER(base::SharedMemoryHandle
, metafile_data_handle
)
189 // Size of metafile data.
190 IPC_STRUCT_MEMBER(uint32
, data_size
)
192 // Cookie for the document to ensure correctness.
193 IPC_STRUCT_MEMBER(int, document_cookie
)
195 // Store the expected pages count.
196 IPC_STRUCT_MEMBER(int, expected_pages_count
)
198 // Whether the preview can be modified.
199 IPC_STRUCT_MEMBER(bool, modifiable
)
201 // The id of the preview request.
202 IPC_STRUCT_MEMBER(int, preview_request_id
)
205 // Parameters to describe a rendered preview page.
206 IPC_STRUCT_BEGIN(PrintHostMsg_DidPreviewPage_Params
)
207 // A shared memory handle to metafile data for a draft document of the page.
208 IPC_STRUCT_MEMBER(base::SharedMemoryHandle
, metafile_data_handle
)
210 // Size of metafile data.
211 IPC_STRUCT_MEMBER(uint32
, data_size
)
213 // |page_number| is zero-based and can be |printing::INVALID_PAGE_INDEX| if it
215 IPC_STRUCT_MEMBER(int, page_number
)
217 // The id of the preview request.
218 IPC_STRUCT_MEMBER(int, preview_request_id
)
221 // Parameters sent along with the page count.
222 IPC_STRUCT_BEGIN(PrintHostMsg_DidGetPreviewPageCount_Params
)
223 // Cookie for the document to ensure correctness.
224 IPC_STRUCT_MEMBER(int, document_cookie
)
227 IPC_STRUCT_MEMBER(int, page_count
)
229 // Indicates whether the previewed document is modifiable.
230 IPC_STRUCT_MEMBER(bool, is_modifiable
)
232 // The id of the preview request.
233 IPC_STRUCT_MEMBER(int, preview_request_id
)
235 // Indicates whether the existing preview data needs to be cleared or not.
236 IPC_STRUCT_MEMBER(bool, clear_preview_data
)
239 // Parameters to describe a rendered page.
240 IPC_STRUCT_BEGIN(PrintHostMsg_DidPrintPage_Params
)
241 // A shared memory handle to the EMF data. This data can be quite large so a
242 // memory map needs to be used.
243 IPC_STRUCT_MEMBER(base::SharedMemoryHandle
, metafile_data_handle
)
245 // Size of the metafile data.
246 IPC_STRUCT_MEMBER(uint32
, data_size
)
248 // Cookie for the document to ensure correctness.
249 IPC_STRUCT_MEMBER(int, document_cookie
)
252 IPC_STRUCT_MEMBER(int, page_number
)
254 // Shrink factor used to render this page.
255 IPC_STRUCT_MEMBER(double, actual_shrink
)
257 // The size of the page the page author specified.
258 IPC_STRUCT_MEMBER(gfx::Size
, page_size
)
260 // The printable area the page author specified.
261 IPC_STRUCT_MEMBER(gfx::Rect
, content_area
)
264 // Parameters for the IPC message ViewHostMsg_ScriptedPrint
265 IPC_STRUCT_BEGIN(PrintHostMsg_ScriptedPrint_Params
)
266 IPC_STRUCT_MEMBER(int, cookie
)
267 IPC_STRUCT_MEMBER(int, expected_pages_count
)
268 IPC_STRUCT_MEMBER(bool, has_selection
)
269 IPC_STRUCT_MEMBER(printing::MarginType
, margin_type
)
273 // Messages sent from the browser to the renderer.
275 // Tells the render view to initiate print preview for the entire document.
276 IPC_MESSAGE_ROUTED1(PrintMsg_InitiatePrintPreview
, bool /* selection_only */)
278 // Tells the render view to initiate printing or print preview for a particular
279 // node, depending on which mode the render view is in.
280 IPC_MESSAGE_ROUTED0(PrintMsg_PrintNodeUnderContextMenu
)
282 // Tells the renderer to print the print preview tab's PDF plugin without
283 // showing the print dialog. (This is the final step in the print preview
285 IPC_MESSAGE_ROUTED1(PrintMsg_PrintForPrintPreview
,
286 base::DictionaryValue
/* settings */)
288 // Tells the render view to switch the CSS to print media type, renders every
289 // requested pages and switch back the CSS to display media type.
290 IPC_MESSAGE_ROUTED0(PrintMsg_PrintPages
)
292 // Tells the render view that printing is done so it can clean up.
293 IPC_MESSAGE_ROUTED1(PrintMsg_PrintingDone
,
296 // Tells the render view whether scripted printing is blocked or not.
297 IPC_MESSAGE_ROUTED1(PrintMsg_SetScriptedPrintingBlocked
,
300 // Tells the render view to switch the CSS to print media type, renders every
301 // requested pages for print preview using the given |settings|. This gets
302 // called multiple times as the user updates settings.
303 IPC_MESSAGE_ROUTED1(PrintMsg_PrintPreview
,
304 base::DictionaryValue
/* settings */)
306 // Like PrintMsg_PrintPages, but using the print preview document's frame/node.
307 IPC_MESSAGE_ROUTED0(PrintMsg_PrintForSystemDialog
)
309 // Tells a renderer to stop blocking script initiated printing.
310 IPC_MESSAGE_ROUTED0(PrintMsg_ResetScriptedPrintCount
)
312 // Messages sent from the renderer to the browser.
315 // Duplicates a shared memory handle from the renderer to the browser. Then
316 // the renderer can flush the handle.
317 IPC_SYNC_MESSAGE_ROUTED1_1(PrintHostMsg_DuplicateSection
,
318 base::SharedMemoryHandle
/* renderer handle */,
319 base::SharedMemoryHandle
/* browser handle */)
322 // Check if printing is enabled.
323 IPC_SYNC_MESSAGE_ROUTED0_1(PrintHostMsg_IsPrintingEnabled
,
324 bool /* is_enabled */)
326 // Tells the browser that the renderer is done calculating the number of
327 // rendered pages according to the specified settings.
328 IPC_MESSAGE_ROUTED2(PrintHostMsg_DidGetPrintedPagesCount
,
329 int /* rendered document cookie */,
330 int /* number of rendered pages */)
332 // Sends the document cookie of the current printer query to the browser.
333 IPC_MESSAGE_ROUTED1(PrintHostMsg_DidGetDocumentCookie
,
334 int /* rendered document cookie */)
336 // Tells the browser that the print dialog has been shown.
337 IPC_MESSAGE_ROUTED0(PrintHostMsg_DidShowPrintDialog
)
339 // Sends back to the browser the rendered "printed page" that was requested by
340 // a ViewMsg_PrintPage message or from scripted printing. The memory handle in
341 // this message is already valid in the browser process.
342 IPC_MESSAGE_ROUTED1(PrintHostMsg_DidPrintPage
,
343 PrintHostMsg_DidPrintPage_Params
/* page content */)
345 // The renderer wants to know the default print settings.
346 IPC_SYNC_MESSAGE_ROUTED0_1(PrintHostMsg_GetDefaultPrintSettings
,
347 PrintMsg_Print_Params
/* default_settings */)
349 // The renderer wants to update the current print settings with new
351 IPC_SYNC_MESSAGE_ROUTED2_1(PrintHostMsg_UpdatePrintSettings
,
352 int /* document_cookie */,
353 base::DictionaryValue
/* job_settings */,
354 PrintMsg_PrintPages_Params
/* current_settings */)
356 // It's the renderer that controls the printing process when it is generated
357 // by javascript. This step is about showing UI to the user to select the
358 // final print settings. The output parameter is the same as
359 // ViewMsg_PrintPages which is executed implicitly.
360 IPC_SYNC_MESSAGE_ROUTED1_1(PrintHostMsg_ScriptedPrint
,
361 PrintHostMsg_ScriptedPrint_Params
,
362 PrintMsg_PrintPages_Params
363 /* settings chosen by the user*/)
365 #if defined(OS_CHROMEOS) || defined(OS_ANDROID)
366 // Asks the browser to create a temporary file for the renderer to fill
367 // in resulting NativeMetafile in printing.
368 IPC_SYNC_MESSAGE_CONTROL1_2(PrintHostMsg_AllocateTempFileForPrinting
,
369 int /* render_view_id */,
370 base::FileDescriptor
/* temp file fd */,
371 int /* fd in browser*/) // Used only by Chrome OS.
372 IPC_MESSAGE_CONTROL2(PrintHostMsg_TempFileForPrintingWritten
,
373 int /* render_view_id */,
374 int /* fd in browser */) // Used only by Chrome OS.
377 // Asks the browser to do print preview.
378 IPC_MESSAGE_ROUTED1(PrintHostMsg_RequestPrintPreview
,
379 PrintHostMsg_RequestPrintPreview_Params
/* params */)
381 // Notify the browser the number of pages in the print preview document.
382 IPC_MESSAGE_ROUTED1(PrintHostMsg_DidGetPreviewPageCount
,
383 PrintHostMsg_DidGetPreviewPageCount_Params
/* params */)
385 // Notify the browser of the default page layout according to the currently
386 // selected printer and page size.
387 // |printable_area_in_points| Specifies the printable area in points.
388 // |has_custom_page_size_style| is true when the printing frame has a custom
389 // page size css otherwise false.
390 IPC_MESSAGE_ROUTED3(PrintHostMsg_DidGetDefaultPageLayout
,
391 printing::PageSizeMargins
/* page layout in points */,
392 gfx::Rect
/* printable area in points */,
393 bool /* has custom page size style */)
395 // Notify the browser a print preview page has been rendered.
396 IPC_MESSAGE_ROUTED1(PrintHostMsg_DidPreviewPage
,
397 PrintHostMsg_DidPreviewPage_Params
/* params */)
399 // Asks the browser whether the print preview has been cancelled.
400 IPC_SYNC_MESSAGE_ROUTED2_1(PrintHostMsg_CheckForCancel
,
401 int32
/* PrintPreviewUI ID */,
402 int /* request id */,
403 bool /* print preview cancelled */)
405 // Sends back to the browser the complete rendered document (non-draft mode,
406 // used for printing) that was requested by a PrintMsg_PrintPreview message.
407 // The memory handle in this message is already valid in the browser process.
408 IPC_MESSAGE_ROUTED1(PrintHostMsg_MetafileReadyForPrinting
,
409 PrintHostMsg_DidPreviewDocument_Params
/* params */)
411 // Tell the browser printing failed.
412 IPC_MESSAGE_ROUTED1(PrintHostMsg_PrintingFailed
,
413 int /* document cookie */)
415 // Tell the browser print preview failed.
416 IPC_MESSAGE_ROUTED1(PrintHostMsg_PrintPreviewFailed
,
417 int /* document cookie */)
419 // Tell the browser print preview was cancelled.
420 IPC_MESSAGE_ROUTED1(PrintHostMsg_PrintPreviewCancelled
,
421 int /* document cookie */)
423 // Tell the browser print preview found the selected printer has invalid
424 // settings (which typically caused by disconnected network printer or printer
426 IPC_MESSAGE_ROUTED1(PrintHostMsg_PrintPreviewInvalidPrinterSettings
,
427 int /* document cookie */)
429 // Run a nested message loop in the renderer until print preview for
430 // window.print() finishes.
431 IPC_SYNC_MESSAGE_ROUTED0_0(PrintHostMsg_SetupScriptedPrintPreview
)
433 // Tell the browser to show the print preview, when the document is sufficiently
434 // loaded such that the renderer can determine whether it is modifiable or not.
435 IPC_MESSAGE_ROUTED1(PrintHostMsg_ShowScriptedPrintPreview
,
436 bool /* is_modifiable */)
438 // Notify the browser that the PDF in the initiator renderer has disabled print
440 IPC_MESSAGE_ROUTED0(PrintHostMsg_PrintPreviewScalingDisabled
)