print_messages.h revision 5d1f7b1de12d16ceb2c938c56701a3e8bfa558f7
1// Copyright 2013 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.
4
5// IPC messages for printing.
6// Multiply-included message file, hence no include guard.
7
8// TODO(sgurun) copied from chrome/common. Remove after crbug.com/322276
9
10#include <string>
11#include <vector>
12
13#include "base/memory/shared_memory.h"
14#include "base/values.h"
15#include "ipc/ipc_message_macros.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/native_widget_types.h"
20#include "ui/gfx/rect.h"
21
22#ifndef AW_COMMON_PRINT_MESSAGES_H_
23#define AW_COMMON_PRINT_MESSAGES_H_
24
25struct PrintMsg_Print_Params {
26  PrintMsg_Print_Params();
27  ~PrintMsg_Print_Params();
28
29  // Resets the members of the struct to 0.
30  void Reset();
31
32  gfx::Size page_size;
33  gfx::Size content_size;
34  gfx::Rect printable_area;
35  int margin_top;
36  int margin_left;
37  double dpi;
38  double min_shrink;
39  double max_shrink;
40  int desired_dpi;
41  int document_cookie;
42  bool selection_only;
43  bool supports_alpha_blend;
44  int32 preview_ui_id;
45  int preview_request_id;
46  bool is_first_request;
47  blink::WebPrintScalingOption print_scaling_option;
48  bool print_to_pdf;
49  bool display_header_footer;
50  base::string16 title;
51  base::string16 url;
52  bool should_print_backgrounds;
53};
54
55struct PrintMsg_PrintPages_Params {
56  PrintMsg_PrintPages_Params();
57  ~PrintMsg_PrintPages_Params();
58
59  // Resets the members of the struct to 0.
60  void Reset();
61
62  PrintMsg_Print_Params params;
63  std::vector<int> pages;
64};
65
66struct PrintHostMsg_RequestPrintPreview_Params {
67  PrintHostMsg_RequestPrintPreview_Params();
68  ~PrintHostMsg_RequestPrintPreview_Params();
69  bool is_modifiable;
70  bool webnode_only;
71  bool has_selection;
72  bool selection_only;
73};
74
75#endif  // AW_COMMON_PRINT_MESSAGES_H_
76
77#define IPC_MESSAGE_START PrintMsgStart
78
79IPC_ENUM_TRAITS(printing::MarginType)
80IPC_ENUM_TRAITS(blink::WebPrintScalingOption)
81
82// Parameters for a render request.
83IPC_STRUCT_TRAITS_BEGIN(PrintMsg_Print_Params)
84  // Physical size of the page, including non-printable margins,
85  // in pixels according to dpi.
86  IPC_STRUCT_TRAITS_MEMBER(page_size)
87
88  // In pixels according to dpi_x and dpi_y.
89  IPC_STRUCT_TRAITS_MEMBER(content_size)
90
91  // Physical printable area of the page in pixels according to dpi.
92  IPC_STRUCT_TRAITS_MEMBER(printable_area)
93
94  // The y-offset of the printable area, in pixels according to dpi.
95  IPC_STRUCT_TRAITS_MEMBER(margin_top)
96
97  // The x-offset of the printable area, in pixels according to dpi.
98  IPC_STRUCT_TRAITS_MEMBER(margin_left)
99
100  // Specifies dots per inch.
101  IPC_STRUCT_TRAITS_MEMBER(dpi)
102
103  // Minimum shrink factor. See PrintSettings::min_shrink for more information.
104  IPC_STRUCT_TRAITS_MEMBER(min_shrink)
105
106  // Maximum shrink factor. See PrintSettings::max_shrink for more information.
107  IPC_STRUCT_TRAITS_MEMBER(max_shrink)
108
109  // Desired apparent dpi on paper.
110  IPC_STRUCT_TRAITS_MEMBER(desired_dpi)
111
112  // Cookie for the document to ensure correctness.
113  IPC_STRUCT_TRAITS_MEMBER(document_cookie)
114
115  // Should only print currently selected text.
116  IPC_STRUCT_TRAITS_MEMBER(selection_only)
117
118  // Does the printer support alpha blending?
119  IPC_STRUCT_TRAITS_MEMBER(supports_alpha_blend)
120
121  // *** Parameters below are used only for print preview. ***
122
123  // The print preview ui associated with this request.
124  IPC_STRUCT_TRAITS_MEMBER(preview_ui_id)
125
126  // The id of the preview request.
127  IPC_STRUCT_TRAITS_MEMBER(preview_request_id)
128
129  // True if this is the first preview request.
130  IPC_STRUCT_TRAITS_MEMBER(is_first_request)
131
132  // Specifies the page scaling option for preview printing.
133  IPC_STRUCT_TRAITS_MEMBER(print_scaling_option)
134
135  // True if print to pdf is requested.
136  IPC_STRUCT_TRAITS_MEMBER(print_to_pdf)
137
138  // Specifies if the header and footer should be rendered.
139  IPC_STRUCT_TRAITS_MEMBER(display_header_footer)
140
141  // Title string to be printed as header if requested by the user.
142  IPC_STRUCT_TRAITS_MEMBER(title)
143
144  // URL string to be printed as footer if requested by the user.
145  IPC_STRUCT_TRAITS_MEMBER(url)
146
147  // True if print backgrounds is requested by the user.
148  IPC_STRUCT_TRAITS_MEMBER(should_print_backgrounds)
149IPC_STRUCT_TRAITS_END()
150
151IPC_STRUCT_BEGIN(PrintMsg_PrintPage_Params)
152  // Parameters to render the page as a printed page. It must always be the same
153  // value for all the document.
154  IPC_STRUCT_MEMBER(PrintMsg_Print_Params, params)
155
156  // The page number is the indicator of the square that should be rendered
157  // according to the layout specified in PrintMsg_Print_Params.
158  IPC_STRUCT_MEMBER(int, page_number)
159IPC_STRUCT_END()
160
161IPC_STRUCT_TRAITS_BEGIN(PrintHostMsg_RequestPrintPreview_Params)
162  IPC_STRUCT_TRAITS_MEMBER(is_modifiable)
163  IPC_STRUCT_TRAITS_MEMBER(webnode_only)
164  IPC_STRUCT_TRAITS_MEMBER(has_selection)
165  IPC_STRUCT_TRAITS_MEMBER(selection_only)
166IPC_STRUCT_TRAITS_END()
167
168IPC_STRUCT_TRAITS_BEGIN(printing::PageSizeMargins)
169  IPC_STRUCT_TRAITS_MEMBER(content_width)
170  IPC_STRUCT_TRAITS_MEMBER(content_height)
171  IPC_STRUCT_TRAITS_MEMBER(margin_left)
172  IPC_STRUCT_TRAITS_MEMBER(margin_right)
173  IPC_STRUCT_TRAITS_MEMBER(margin_top)
174  IPC_STRUCT_TRAITS_MEMBER(margin_bottom)
175IPC_STRUCT_TRAITS_END()
176
177IPC_STRUCT_TRAITS_BEGIN(PrintMsg_PrintPages_Params)
178  // Parameters to render the page as a printed page. It must always be the same
179  // value for all the document.
180  IPC_STRUCT_TRAITS_MEMBER(params)
181
182  // If empty, this means a request to render all the printed pages.
183  IPC_STRUCT_TRAITS_MEMBER(pages)
184IPC_STRUCT_TRAITS_END()
185
186// Parameters to describe a rendered document.
187IPC_STRUCT_BEGIN(PrintHostMsg_DidPreviewDocument_Params)
188  // True when we can reuse existing preview data. |metafile_data_handle| and
189  // |data_size| should not be used when this is true.
190  IPC_STRUCT_MEMBER(bool, reuse_existing_data)
191
192  // A shared memory handle to metafile data.
193  IPC_STRUCT_MEMBER(base::SharedMemoryHandle, metafile_data_handle)
194
195  // Size of metafile data.
196  IPC_STRUCT_MEMBER(uint32, data_size)
197
198  // Cookie for the document to ensure correctness.
199  IPC_STRUCT_MEMBER(int, document_cookie)
200
201  // Store the expected pages count.
202  IPC_STRUCT_MEMBER(int, expected_pages_count)
203
204  // Whether the preview can be modified.
205  IPC_STRUCT_MEMBER(bool, modifiable)
206
207  // The id of the preview request.
208  IPC_STRUCT_MEMBER(int, preview_request_id)
209IPC_STRUCT_END()
210
211// Parameters to describe a rendered preview page.
212IPC_STRUCT_BEGIN(PrintHostMsg_DidPreviewPage_Params)
213  // A shared memory handle to metafile data for a draft document of the page.
214  IPC_STRUCT_MEMBER(base::SharedMemoryHandle, metafile_data_handle)
215
216  // Size of metafile data.
217  IPC_STRUCT_MEMBER(uint32, data_size)
218
219  // |page_number| is zero-based and can be |printing::INVALID_PAGE_INDEX| if it
220  // is just a check.
221  IPC_STRUCT_MEMBER(int, page_number)
222
223  // The id of the preview request.
224  IPC_STRUCT_MEMBER(int, preview_request_id)
225IPC_STRUCT_END()
226
227// Parameters sent along with the page count.
228IPC_STRUCT_BEGIN(PrintHostMsg_DidGetPreviewPageCount_Params)
229  // Cookie for the document to ensure correctness.
230  IPC_STRUCT_MEMBER(int, document_cookie)
231
232  // Total page count.
233  IPC_STRUCT_MEMBER(int, page_count)
234
235  // Indicates whether the previewed document is modifiable.
236  IPC_STRUCT_MEMBER(bool, is_modifiable)
237
238  // The id of the preview request.
239  IPC_STRUCT_MEMBER(int, preview_request_id)
240
241  // Indicates whether the existing preview data needs to be cleared or not.
242  IPC_STRUCT_MEMBER(bool, clear_preview_data)
243IPC_STRUCT_END()
244
245// Parameters to describe a rendered page.
246IPC_STRUCT_BEGIN(PrintHostMsg_DidPrintPage_Params)
247  // A shared memory handle to the EMF data. This data can be quite large so a
248  // memory map needs to be used.
249  IPC_STRUCT_MEMBER(base::SharedMemoryHandle, metafile_data_handle)
250
251  // Size of the metafile data.
252  IPC_STRUCT_MEMBER(uint32, data_size)
253
254  // Cookie for the document to ensure correctness.
255  IPC_STRUCT_MEMBER(int, document_cookie)
256
257  // Page number.
258  IPC_STRUCT_MEMBER(int, page_number)
259
260  // Shrink factor used to render this page.
261  IPC_STRUCT_MEMBER(double, actual_shrink)
262
263  // The size of the page the page author specified.
264  IPC_STRUCT_MEMBER(gfx::Size, page_size)
265
266  // The printable area the page author specified.
267  IPC_STRUCT_MEMBER(gfx::Rect, content_area)
268IPC_STRUCT_END()
269
270// Parameters for the IPC message ViewHostMsg_ScriptedPrint
271IPC_STRUCT_BEGIN(PrintHostMsg_ScriptedPrint_Params)
272  IPC_STRUCT_MEMBER(int, cookie)
273  IPC_STRUCT_MEMBER(int, expected_pages_count)
274  IPC_STRUCT_MEMBER(bool, has_selection)
275  IPC_STRUCT_MEMBER(printing::MarginType, margin_type)
276IPC_STRUCT_END()
277
278
279// Messages sent from the browser to the renderer.
280
281// Tells the render view to initiate print preview for the entire document.
282IPC_MESSAGE_ROUTED1(PrintMsg_InitiatePrintPreview, bool /* selection_only */)
283
284// Tells the render view to initiate printing or print preview for a particular
285// node, depending on which mode the render view is in.
286IPC_MESSAGE_ROUTED0(PrintMsg_PrintNodeUnderContextMenu)
287
288// Tells the renderer to print the print preview tab's PDF plugin without
289// showing the print dialog. (This is the final step in the print preview
290// workflow.)
291IPC_MESSAGE_ROUTED1(PrintMsg_PrintForPrintPreview,
292                    base::DictionaryValue /* settings */)
293
294// Tells the render view to switch the CSS to print media type, renders every
295// requested pages and switch back the CSS to display media type.
296IPC_MESSAGE_ROUTED0(PrintMsg_PrintPages)
297
298// Tells the render view that printing is done so it can clean up.
299IPC_MESSAGE_ROUTED1(PrintMsg_PrintingDone,
300                    bool /* success */)
301
302// Tells the render view whether scripted printing is blocked or not.
303IPC_MESSAGE_ROUTED1(PrintMsg_SetScriptedPrintingBlocked,
304                    bool /* blocked */)
305
306// Tells the render view to switch the CSS to print media type, renders every
307// requested pages for print preview using the given |settings|. This gets
308// called multiple times as the user updates settings.
309IPC_MESSAGE_ROUTED1(PrintMsg_PrintPreview,
310                    base::DictionaryValue /* settings */)
311
312// Like PrintMsg_PrintPages, but using the print preview document's frame/node.
313IPC_MESSAGE_ROUTED0(PrintMsg_PrintForSystemDialog)
314
315// Tells a renderer to stop blocking script initiated printing.
316IPC_MESSAGE_ROUTED0(PrintMsg_ResetScriptedPrintCount)
317
318// Messages sent from the renderer to the browser.
319
320#if defined(OS_WIN)
321// Duplicates a shared memory handle from the renderer to the browser. Then
322// the renderer can flush the handle.
323IPC_SYNC_MESSAGE_ROUTED1_1(PrintHostMsg_DuplicateSection,
324                           base::SharedMemoryHandle /* renderer handle */,
325                           base::SharedMemoryHandle /* browser handle */)
326#endif
327
328// Check if printing is enabled.
329IPC_SYNC_MESSAGE_ROUTED0_1(PrintHostMsg_IsPrintingEnabled,
330                           bool /* is_enabled */)
331
332// Tells the browser that the renderer is done calculating the number of
333// rendered pages according to the specified settings.
334IPC_MESSAGE_ROUTED2(PrintHostMsg_DidGetPrintedPagesCount,
335                    int /* rendered document cookie */,
336                    int /* number of rendered pages */)
337
338// Sends the document cookie of the current printer query to the browser.
339IPC_MESSAGE_ROUTED1(PrintHostMsg_DidGetDocumentCookie,
340                    int /* rendered document cookie */)
341
342// Tells the browser that the print dialog has been shown.
343IPC_MESSAGE_ROUTED0(PrintHostMsg_DidShowPrintDialog)
344
345// Sends back to the browser the rendered "printed page" that was requested by
346// a ViewMsg_PrintPage message or from scripted printing. The memory handle in
347// this message is already valid in the browser process.
348IPC_MESSAGE_ROUTED1(PrintHostMsg_DidPrintPage,
349                    PrintHostMsg_DidPrintPage_Params /* page content */)
350
351// The renderer wants to know the default print settings.
352IPC_SYNC_MESSAGE_ROUTED0_1(PrintHostMsg_GetDefaultPrintSettings,
353                           PrintMsg_Print_Params /* default_settings */)
354
355// The renderer wants to update the current print settings with new
356// |job_settings|.
357IPC_SYNC_MESSAGE_ROUTED2_1(PrintHostMsg_UpdatePrintSettings,
358                           int /* document_cookie */,
359                           base::DictionaryValue /* job_settings */,
360                           PrintMsg_PrintPages_Params /* current_settings */)
361
362// It's the renderer that controls the printing process when it is generated
363// by javascript. This step is about showing UI to the user to select the
364// final print settings. The output parameter is the same as
365// ViewMsg_PrintPages which is executed implicitly.
366IPC_SYNC_MESSAGE_ROUTED1_1(PrintHostMsg_ScriptedPrint,
367                           PrintHostMsg_ScriptedPrint_Params,
368                           PrintMsg_PrintPages_Params
369                               /* settings chosen by the user*/)
370
371#if defined(OS_ANDROID)
372// Asks the browser to create a temporary file for the renderer to fill
373// in resulting NativeMetafile in printing.
374IPC_SYNC_MESSAGE_ROUTED0_2(PrintHostMsg_AllocateTempFileForPrinting,
375                           base::FileDescriptor /* temp file fd */,
376                           int /* fd in browser*/)
377IPC_MESSAGE_ROUTED1(PrintHostMsg_TempFileForPrintingWritten,
378                    int /* fd in browser */)
379#endif
380// Asks the browser to do print preview.
381IPC_MESSAGE_ROUTED1(PrintHostMsg_RequestPrintPreview,
382                    PrintHostMsg_RequestPrintPreview_Params /* params */)
383
384// Notify the browser the number of pages in the print preview document.
385IPC_MESSAGE_ROUTED1(PrintHostMsg_DidGetPreviewPageCount,
386                    PrintHostMsg_DidGetPreviewPageCount_Params /* params */)
387
388// Notify the browser of the default page layout according to the currently
389// selected printer and page size.
390// |printable_area_in_points| Specifies the printable area in points.
391// |has_custom_page_size_style| is true when the printing frame has a custom
392// page size css otherwise false.
393IPC_MESSAGE_ROUTED3(PrintHostMsg_DidGetDefaultPageLayout,
394                    printing::PageSizeMargins /* page layout in points */,
395                    gfx::Rect /* printable area in points */,
396                    bool /* has custom page size style */)
397
398// Notify the browser a print preview page has been rendered.
399IPC_MESSAGE_ROUTED1(PrintHostMsg_DidPreviewPage,
400                    PrintHostMsg_DidPreviewPage_Params /* params */)
401
402// Asks the browser whether the print preview has been cancelled.
403IPC_SYNC_MESSAGE_ROUTED2_1(PrintHostMsg_CheckForCancel,
404                           int32 /* PrintPreviewUI ID */,
405                           int /* request id */,
406                           bool /* print preview cancelled */)
407
408// Sends back to the browser the complete rendered document (non-draft mode,
409// used for printing) that was requested by a PrintMsg_PrintPreview message.
410// The memory handle in this message is already valid in the browser process.
411IPC_MESSAGE_ROUTED1(PrintHostMsg_MetafileReadyForPrinting,
412                    PrintHostMsg_DidPreviewDocument_Params /* params */)
413
414// Tell the browser printing failed.
415IPC_MESSAGE_ROUTED1(PrintHostMsg_PrintingFailed,
416                    int /* document cookie */)
417
418// Tell the browser print preview failed.
419IPC_MESSAGE_ROUTED1(PrintHostMsg_PrintPreviewFailed,
420                    int /* document cookie */)
421
422// Tell the browser print preview was cancelled.
423IPC_MESSAGE_ROUTED1(PrintHostMsg_PrintPreviewCancelled,
424                    int /* document cookie */)
425
426// Tell the browser print preview found the selected printer has invalid
427// settings (which typically caused by disconnected network printer or printer
428// driver is bogus).
429IPC_MESSAGE_ROUTED1(PrintHostMsg_PrintPreviewInvalidPrinterSettings,
430                    int /* document cookie */)
431
432// Run a nested message loop in the renderer until print preview for
433// window.print() finishes.
434IPC_SYNC_MESSAGE_ROUTED0_0(PrintHostMsg_SetupScriptedPrintPreview)
435
436// Tell the browser to show the print preview, when the document is sufficiently
437// loaded such that the renderer can determine whether it is modifiable or not.
438IPC_MESSAGE_ROUTED1(PrintHostMsg_ShowScriptedPrintPreview,
439                    bool /* is_modifiable */)
440
441// Notify the browser that the PDF in the initiator renderer has disabled print
442// scaling option.
443IPC_MESSAGE_ROUTED0(PrintHostMsg_PrintPreviewScalingDisabled)
444