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 WebKit::WebPrintScalingOption print_scaling_option
;
47 bool display_header_footer
;
51 bool should_print_backgrounds
;
54 struct PrintMsg_PrintPages_Params
{
55 PrintMsg_PrintPages_Params();
56 ~PrintMsg_PrintPages_Params();
58 // Resets the members of the struct to 0.
61 PrintMsg_Print_Params params
;
62 std::vector
<int> pages
;
65 struct PrintHostMsg_RequestPrintPreview_Params
{
66 PrintHostMsg_RequestPrintPreview_Params();
67 ~PrintHostMsg_RequestPrintPreview_Params();
74 #endif // CHROME_COMMON_PRINT_MESSAGES_H_
76 #define IPC_MESSAGE_START PrintMsgStart
78 IPC_ENUM_TRAITS(printing::MarginType
)
79 IPC_ENUM_TRAITS(WebKit::WebPrintScalingOption
)
81 // Parameters for a render request.
82 IPC_STRUCT_TRAITS_BEGIN(PrintMsg_Print_Params
)
83 // Physical size of the page, including non-printable margins,
84 // in pixels according to dpi.
85 IPC_STRUCT_TRAITS_MEMBER(page_size
)
87 // In pixels according to dpi_x and dpi_y.
88 IPC_STRUCT_TRAITS_MEMBER(content_size
)
90 // Physical printable area of the page in pixels according to dpi.
91 IPC_STRUCT_TRAITS_MEMBER(printable_area
)
93 // The y-offset of the printable area, in pixels according to dpi.
94 IPC_STRUCT_TRAITS_MEMBER(margin_top
)
96 // The x-offset of the printable area, in pixels according to dpi.
97 IPC_STRUCT_TRAITS_MEMBER(margin_left
)
99 // Specifies dots per inch.
100 IPC_STRUCT_TRAITS_MEMBER(dpi
)
102 // Minimum shrink factor. See PrintSettings::min_shrink for more information.
103 IPC_STRUCT_TRAITS_MEMBER(min_shrink
)
105 // Maximum shrink factor. See PrintSettings::max_shrink for more information.
106 IPC_STRUCT_TRAITS_MEMBER(max_shrink
)
108 // Desired apparent dpi on paper.
109 IPC_STRUCT_TRAITS_MEMBER(desired_dpi
)
111 // Cookie for the document to ensure correctness.
112 IPC_STRUCT_TRAITS_MEMBER(document_cookie
)
114 // Should only print currently selected text.
115 IPC_STRUCT_TRAITS_MEMBER(selection_only
)
117 // Does the printer support alpha blending?
118 IPC_STRUCT_TRAITS_MEMBER(supports_alpha_blend
)
120 // *** Parameters below are used only for print preview. ***
122 // The print preview ui associated with this request.
123 IPC_STRUCT_TRAITS_MEMBER(preview_ui_id
)
125 // The id of the preview request.
126 IPC_STRUCT_TRAITS_MEMBER(preview_request_id
)
128 // True if this is the first preview request.
129 IPC_STRUCT_TRAITS_MEMBER(is_first_request
)
131 // Specifies the page scaling option for preview printing.
132 IPC_STRUCT_TRAITS_MEMBER(print_scaling_option
)
134 // True if print to pdf is requested.
135 IPC_STRUCT_TRAITS_MEMBER(print_to_pdf
)
137 // Specifies if the header and footer should be rendered.
138 IPC_STRUCT_TRAITS_MEMBER(display_header_footer
)
140 // Date string to be printed as header if requested by the user.
141 IPC_STRUCT_TRAITS_MEMBER(date
)
143 // Title string to be printed as header if requested by the user.
144 IPC_STRUCT_TRAITS_MEMBER(title
)
146 // URL string to be printed as footer if requested by the user.
147 IPC_STRUCT_TRAITS_MEMBER(url
)
149 // True if print backgrounds is requested by the user.
150 IPC_STRUCT_TRAITS_MEMBER(should_print_backgrounds
)
151 IPC_STRUCT_TRAITS_END()
153 IPC_STRUCT_BEGIN(PrintMsg_PrintPage_Params
)
154 // Parameters to render the page as a printed page. It must always be the same
155 // value for all the document.
156 IPC_STRUCT_MEMBER(PrintMsg_Print_Params
, params
)
158 // The page number is the indicator of the square that should be rendered
159 // according to the layout specified in PrintMsg_Print_Params.
160 IPC_STRUCT_MEMBER(int, page_number
)
163 IPC_STRUCT_TRAITS_BEGIN(PrintHostMsg_RequestPrintPreview_Params
)
164 IPC_STRUCT_TRAITS_MEMBER(is_modifiable
)
165 IPC_STRUCT_TRAITS_MEMBER(webnode_only
)
166 IPC_STRUCT_TRAITS_MEMBER(has_selection
)
167 IPC_STRUCT_TRAITS_MEMBER(selection_only
)
168 IPC_STRUCT_TRAITS_END()
170 IPC_STRUCT_TRAITS_BEGIN(printing::PageSizeMargins
)
171 IPC_STRUCT_TRAITS_MEMBER(content_width
)
172 IPC_STRUCT_TRAITS_MEMBER(content_height
)
173 IPC_STRUCT_TRAITS_MEMBER(margin_left
)
174 IPC_STRUCT_TRAITS_MEMBER(margin_right
)
175 IPC_STRUCT_TRAITS_MEMBER(margin_top
)
176 IPC_STRUCT_TRAITS_MEMBER(margin_bottom
)
177 IPC_STRUCT_TRAITS_END()
179 IPC_STRUCT_TRAITS_BEGIN(PrintMsg_PrintPages_Params
)
180 // Parameters to render the page as a printed page. It must always be the same
181 // value for all the document.
182 IPC_STRUCT_TRAITS_MEMBER(params
)
184 // If empty, this means a request to render all the printed pages.
185 IPC_STRUCT_TRAITS_MEMBER(pages
)
186 IPC_STRUCT_TRAITS_END()
188 // Parameters to describe a rendered document.
189 IPC_STRUCT_BEGIN(PrintHostMsg_DidPreviewDocument_Params
)
190 // True when we can reuse existing preview data. |metafile_data_handle| and
191 // |data_size| should not be used when this is true.
192 IPC_STRUCT_MEMBER(bool, reuse_existing_data
)
194 // A shared memory handle to metafile data.
195 IPC_STRUCT_MEMBER(base::SharedMemoryHandle
, metafile_data_handle
)
197 // Size of metafile data.
198 IPC_STRUCT_MEMBER(uint32
, data_size
)
200 // Cookie for the document to ensure correctness.
201 IPC_STRUCT_MEMBER(int, document_cookie
)
203 // Store the expected pages count.
204 IPC_STRUCT_MEMBER(int, expected_pages_count
)
206 // Whether the preview can be modified.
207 IPC_STRUCT_MEMBER(bool, modifiable
)
209 // The id of the preview request.
210 IPC_STRUCT_MEMBER(int, preview_request_id
)
213 // Parameters to describe a rendered preview page.
214 IPC_STRUCT_BEGIN(PrintHostMsg_DidPreviewPage_Params
)
215 // A shared memory handle to metafile data for a draft document of the page.
216 IPC_STRUCT_MEMBER(base::SharedMemoryHandle
, metafile_data_handle
)
218 // Size of metafile data.
219 IPC_STRUCT_MEMBER(uint32
, data_size
)
221 // |page_number| is zero-based and can be |printing::INVALID_PAGE_INDEX| if it
223 IPC_STRUCT_MEMBER(int, page_number
)
225 // The id of the preview request.
226 IPC_STRUCT_MEMBER(int, preview_request_id
)
229 // Parameters sent along with the page count.
230 IPC_STRUCT_BEGIN(PrintHostMsg_DidGetPreviewPageCount_Params
)
231 // Cookie for the document to ensure correctness.
232 IPC_STRUCT_MEMBER(int, document_cookie
)
235 IPC_STRUCT_MEMBER(int, page_count
)
237 // Indicates whether the previewed document is modifiable.
238 IPC_STRUCT_MEMBER(bool, is_modifiable
)
240 // The id of the preview request.
241 IPC_STRUCT_MEMBER(int, preview_request_id
)
243 // Indicates whether the existing preview data needs to be cleared or not.
244 IPC_STRUCT_MEMBER(bool, clear_preview_data
)
247 // Parameters to describe a rendered page.
248 IPC_STRUCT_BEGIN(PrintHostMsg_DidPrintPage_Params
)
249 // A shared memory handle to the EMF data. This data can be quite large so a
250 // memory map needs to be used.
251 IPC_STRUCT_MEMBER(base::SharedMemoryHandle
, metafile_data_handle
)
253 // Size of the metafile data.
254 IPC_STRUCT_MEMBER(uint32
, data_size
)
256 // Cookie for the document to ensure correctness.
257 IPC_STRUCT_MEMBER(int, document_cookie
)
260 IPC_STRUCT_MEMBER(int, page_number
)
262 // Shrink factor used to render this page.
263 IPC_STRUCT_MEMBER(double, actual_shrink
)
265 // The size of the page the page author specified.
266 IPC_STRUCT_MEMBER(gfx::Size
, page_size
)
268 // The printable area the page author specified.
269 IPC_STRUCT_MEMBER(gfx::Rect
, content_area
)
272 // Parameters for the IPC message ViewHostMsg_ScriptedPrint
273 IPC_STRUCT_BEGIN(PrintHostMsg_ScriptedPrint_Params
)
274 IPC_STRUCT_MEMBER(int, cookie
)
275 IPC_STRUCT_MEMBER(int, expected_pages_count
)
276 IPC_STRUCT_MEMBER(bool, has_selection
)
277 IPC_STRUCT_MEMBER(printing::MarginType
, margin_type
)
281 // Messages sent from the browser to the renderer.
283 // Tells the render view to initiate print preview for the entire document.
284 IPC_MESSAGE_ROUTED1(PrintMsg_InitiatePrintPreview
, bool /* selection_only */)
286 // Tells the render view to initiate printing or print preview for a particular
287 // node, depending on which mode the render view is in.
288 IPC_MESSAGE_ROUTED0(PrintMsg_PrintNodeUnderContextMenu
)
290 // Tells the renderer to print the print preview tab's PDF plugin without
291 // showing the print dialog. (This is the final step in the print preview
293 IPC_MESSAGE_ROUTED1(PrintMsg_PrintForPrintPreview
,
294 base::DictionaryValue
/* settings */)
296 // Tells the render view to switch the CSS to print media type, renders every
297 // requested pages and switch back the CSS to display media type.
298 IPC_MESSAGE_ROUTED0(PrintMsg_PrintPages
)
300 // Tells the render view that printing is done so it can clean up.
301 IPC_MESSAGE_ROUTED1(PrintMsg_PrintingDone
,
304 // Tells the render view whether scripted printing is blocked or not.
305 IPC_MESSAGE_ROUTED1(PrintMsg_SetScriptedPrintingBlocked
,
308 // Tells the render view to switch the CSS to print media type, renders every
309 // requested pages for print preview using the given |settings|. This gets
310 // called multiple times as the user updates settings.
311 IPC_MESSAGE_ROUTED1(PrintMsg_PrintPreview
,
312 base::DictionaryValue
/* settings */)
314 // Like PrintMsg_PrintPages, but using the print preview document's frame/node.
315 IPC_MESSAGE_ROUTED0(PrintMsg_PrintForSystemDialog
)
317 // Tells a renderer to stop blocking script initiated printing.
318 IPC_MESSAGE_ROUTED0(PrintMsg_ResetScriptedPrintCount
)
320 // Messages sent from the renderer to the browser.
323 // Duplicates a shared memory handle from the renderer to the browser. Then
324 // the renderer can flush the handle.
325 IPC_SYNC_MESSAGE_ROUTED1_1(PrintHostMsg_DuplicateSection
,
326 base::SharedMemoryHandle
/* renderer handle */,
327 base::SharedMemoryHandle
/* browser handle */)
330 // Check if printing is enabled.
331 IPC_SYNC_MESSAGE_ROUTED0_1(PrintHostMsg_IsPrintingEnabled
,
332 bool /* is_enabled */)
334 // Tells the browser that the renderer is done calculating the number of
335 // rendered pages according to the specified settings.
336 IPC_MESSAGE_ROUTED2(PrintHostMsg_DidGetPrintedPagesCount
,
337 int /* rendered document cookie */,
338 int /* number of rendered pages */)
340 // Sends the document cookie of the current printer query to the browser.
341 IPC_MESSAGE_ROUTED1(PrintHostMsg_DidGetDocumentCookie
,
342 int /* rendered document cookie */)
344 // Tells the browser that the print dialog has been shown.
345 IPC_MESSAGE_ROUTED0(PrintHostMsg_DidShowPrintDialog
)
347 // Sends back to the browser the rendered "printed page" that was requested by
348 // a ViewMsg_PrintPage message or from scripted printing. The memory handle in
349 // this message is already valid in the browser process.
350 IPC_MESSAGE_ROUTED1(PrintHostMsg_DidPrintPage
,
351 PrintHostMsg_DidPrintPage_Params
/* page content */)
353 // The renderer wants to know the default print settings.
354 IPC_SYNC_MESSAGE_ROUTED0_1(PrintHostMsg_GetDefaultPrintSettings
,
355 PrintMsg_Print_Params
/* default_settings */)
357 // The renderer wants to update the current print settings with new
359 IPC_SYNC_MESSAGE_ROUTED2_1(PrintHostMsg_UpdatePrintSettings
,
360 int /* document_cookie */,
361 base::DictionaryValue
/* job_settings */,
362 PrintMsg_PrintPages_Params
/* current_settings */)
364 // It's the renderer that controls the printing process when it is generated
365 // by javascript. This step is about showing UI to the user to select the
366 // final print settings. The output parameter is the same as
367 // ViewMsg_PrintPages which is executed implicitly.
368 IPC_SYNC_MESSAGE_ROUTED1_1(PrintHostMsg_ScriptedPrint
,
369 PrintHostMsg_ScriptedPrint_Params
,
370 PrintMsg_PrintPages_Params
371 /* settings chosen by the user*/)
374 // Asks the browser to create a temporary file for the renderer to fill
375 // in resulting NativeMetafile in printing.
376 IPC_SYNC_MESSAGE_CONTROL0_2(PrintHostMsg_AllocateTempFileForPrinting
,
377 base::FileDescriptor
/* temp file fd */,
378 int /* fd in browser*/)
379 IPC_MESSAGE_CONTROL2(PrintHostMsg_TempFileForPrintingWritten
,
380 int /* render_view_id */,
381 int /* fd in browser */)
384 // Asks the browser to do print preview.
385 IPC_MESSAGE_ROUTED1(PrintHostMsg_RequestPrintPreview
,
386 PrintHostMsg_RequestPrintPreview_Params
/* params */)
388 // Notify the browser the number of pages in the print preview document.
389 IPC_MESSAGE_ROUTED1(PrintHostMsg_DidGetPreviewPageCount
,
390 PrintHostMsg_DidGetPreviewPageCount_Params
/* params */)
392 // Notify the browser of the default page layout according to the currently
393 // selected printer and page size.
394 // |printable_area_in_points| Specifies the printable area in points.
395 // |has_custom_page_size_style| is true when the printing frame has a custom
396 // page size css otherwise false.
397 IPC_MESSAGE_ROUTED3(PrintHostMsg_DidGetDefaultPageLayout
,
398 printing::PageSizeMargins
/* page layout in points */,
399 gfx::Rect
/* printable area in points */,
400 bool /* has custom page size style */)
402 // Notify the browser a print preview page has been rendered.
403 IPC_MESSAGE_ROUTED1(PrintHostMsg_DidPreviewPage
,
404 PrintHostMsg_DidPreviewPage_Params
/* params */)
406 // Asks the browser whether the print preview has been cancelled.
407 IPC_SYNC_MESSAGE_ROUTED2_1(PrintHostMsg_CheckForCancel
,
408 int32
/* PrintPreviewUI ID */,
409 int /* request id */,
410 bool /* print preview cancelled */)
412 // Sends back to the browser the complete rendered document (non-draft mode,
413 // used for printing) that was requested by a PrintMsg_PrintPreview message.
414 // The memory handle in this message is already valid in the browser process.
415 IPC_MESSAGE_ROUTED1(PrintHostMsg_MetafileReadyForPrinting
,
416 PrintHostMsg_DidPreviewDocument_Params
/* params */)
418 // Tell the browser printing failed.
419 IPC_MESSAGE_ROUTED1(PrintHostMsg_PrintingFailed
,
420 int /* document cookie */)
422 // Tell the browser print preview failed.
423 IPC_MESSAGE_ROUTED1(PrintHostMsg_PrintPreviewFailed
,
424 int /* document cookie */)
426 // Tell the browser print preview was cancelled.
427 IPC_MESSAGE_ROUTED1(PrintHostMsg_PrintPreviewCancelled
,
428 int /* document cookie */)
430 // Tell the browser print preview found the selected printer has invalid
431 // settings (which typically caused by disconnected network printer or printer
433 IPC_MESSAGE_ROUTED1(PrintHostMsg_PrintPreviewInvalidPrinterSettings
,
434 int /* document cookie */)
436 // Run a nested message loop in the renderer until print preview for
437 // window.print() finishes.
438 IPC_SYNC_MESSAGE_ROUTED1_0(PrintHostMsg_ScriptedPrintPreview
,
439 bool /* is_modifiable */)
441 // Notify the browser that the PDF in the initiator renderer has disabled print
443 IPC_MESSAGE_ROUTED0(PrintHostMsg_PrintPreviewScalingDisabled
)