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