OLD | NEW |
| (Empty) |
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/geometry/rect.h" | |
19 #include "ui/gfx/ipc/gfx_param_traits.h" | |
20 #include "ui/gfx/native_widget_types.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 // The size of the page the page author specified. | |
291 IPC_STRUCT_MEMBER(gfx::Size, page_size) | |
292 | |
293 // The printable area the page author specified. | |
294 IPC_STRUCT_MEMBER(gfx::Rect, content_area) | |
295 IPC_STRUCT_END() | |
296 | |
297 // TODO(dgn) Rename *ScriptedPrint messages because they are not called only | |
298 // from scripts. | |
299 // Parameters for the IPC message ViewHostMsg_ScriptedPrint | |
300 IPC_STRUCT_BEGIN(PrintHostMsg_ScriptedPrint_Params) | |
301 IPC_STRUCT_MEMBER(int, cookie) | |
302 IPC_STRUCT_MEMBER(int, expected_pages_count) | |
303 IPC_STRUCT_MEMBER(bool, has_selection) | |
304 IPC_STRUCT_MEMBER(bool, is_scripted) | |
305 IPC_STRUCT_MEMBER(printing::MarginType, margin_type) | |
306 IPC_STRUCT_END() | |
307 | |
308 | |
309 // Messages sent from the browser to the renderer. | |
310 | |
311 // Tells the render view to initiate print preview for the entire document. | |
312 IPC_MESSAGE_ROUTED1(PrintMsg_InitiatePrintPreview, bool /* selection_only */) | |
313 | |
314 // Tells the render frame to initiate printing or print preview for a particular | |
315 // node, depending on which mode the render frame is in. | |
316 IPC_MESSAGE_ROUTED0(PrintMsg_PrintNodeUnderContextMenu) | |
317 | |
318 // Tells the renderer to print the print preview tab's PDF plugin without | |
319 // showing the print dialog. (This is the final step in the print preview | |
320 // workflow.) | |
321 IPC_MESSAGE_ROUTED1(PrintMsg_PrintForPrintPreview, | |
322 base::DictionaryValue /* settings */) | |
323 | |
324 #if defined(ENABLE_BASIC_PRINTING) | |
325 // Tells the render view to switch the CSS to print media type, renders every | |
326 // requested pages and switch back the CSS to display media type. | |
327 IPC_MESSAGE_ROUTED0(PrintMsg_PrintPages) | |
328 | |
329 // Like PrintMsg_PrintPages, but using the print preview document's frame/node. | |
330 IPC_MESSAGE_ROUTED0(PrintMsg_PrintForSystemDialog) | |
331 #endif // ENABLE_BASIC_PRINTING | |
332 | |
333 // Tells the render view that printing is done so it can clean up. | |
334 IPC_MESSAGE_ROUTED1(PrintMsg_PrintingDone, | |
335 bool /* success */) | |
336 | |
337 // Tells the render view whether scripted printing is blocked or not. | |
338 IPC_MESSAGE_ROUTED1(PrintMsg_SetScriptedPrintingBlocked, | |
339 bool /* blocked */) | |
340 | |
341 // Tells the render view to switch the CSS to print media type, renders every | |
342 // requested pages for print preview using the given |settings|. This gets | |
343 // called multiple times as the user updates settings. | |
344 IPC_MESSAGE_ROUTED1(PrintMsg_PrintPreview, | |
345 base::DictionaryValue /* settings */) | |
346 | |
347 // Messages sent from the renderer to the browser. | |
348 | |
349 #if defined(OS_WIN) | |
350 // Duplicates a shared memory handle from the renderer to the browser. Then | |
351 // the renderer can flush the handle. | |
352 IPC_SYNC_MESSAGE_ROUTED1_1(PrintHostMsg_DuplicateSection, | |
353 base::SharedMemoryHandle /* renderer handle */, | |
354 base::SharedMemoryHandle /* browser handle */) | |
355 #endif | |
356 | |
357 // Check if printing is enabled. | |
358 IPC_SYNC_MESSAGE_ROUTED0_1(PrintHostMsg_IsPrintingEnabled, | |
359 bool /* is_enabled */) | |
360 | |
361 // Tells the browser that the renderer is done calculating the number of | |
362 // rendered pages according to the specified settings. | |
363 IPC_MESSAGE_ROUTED2(PrintHostMsg_DidGetPrintedPagesCount, | |
364 int /* rendered document cookie */, | |
365 int /* number of rendered pages */) | |
366 | |
367 // Sends the document cookie of the current printer query to the browser. | |
368 IPC_MESSAGE_ROUTED1(PrintHostMsg_DidGetDocumentCookie, | |
369 int /* rendered document cookie */) | |
370 | |
371 // Tells the browser that the print dialog has been shown. | |
372 IPC_MESSAGE_ROUTED0(PrintHostMsg_DidShowPrintDialog) | |
373 | |
374 // Sends back to the browser the rendered "printed page" that was requested by | |
375 // a ViewMsg_PrintPage message or from scripted printing. The memory handle in | |
376 // this message is already valid in the browser process. | |
377 IPC_MESSAGE_ROUTED1(PrintHostMsg_DidPrintPage, | |
378 PrintHostMsg_DidPrintPage_Params /* page content */) | |
379 | |
380 // The renderer wants to know the default print settings. | |
381 IPC_SYNC_MESSAGE_ROUTED0_1(PrintHostMsg_GetDefaultPrintSettings, | |
382 PrintMsg_Print_Params /* default_settings */) | |
383 | |
384 // The renderer wants to update the current print settings with new | |
385 // |job_settings|. | |
386 IPC_SYNC_MESSAGE_ROUTED2_2(PrintHostMsg_UpdatePrintSettings, | |
387 int /* document_cookie */, | |
388 base::DictionaryValue /* job_settings */, | |
389 PrintMsg_PrintPages_Params /* current_settings */, | |
390 bool /* canceled */) | |
391 | |
392 // It's the renderer that controls the printing process when it is generated | |
393 // by javascript. This step is about showing UI to the user to select the | |
394 // final print settings. The output parameter is the same as | |
395 // ViewMsg_PrintPages which is executed implicitly. | |
396 IPC_SYNC_MESSAGE_ROUTED1_1(PrintHostMsg_ScriptedPrint, | |
397 PrintHostMsg_ScriptedPrint_Params, | |
398 PrintMsg_PrintPages_Params | |
399 /* settings chosen by the user*/) | |
400 | |
401 #if defined(OS_CHROMEOS) || defined(OS_ANDROID) | |
402 // Asks the browser to create a temporary file for the renderer to fill | |
403 // in resulting PdfMetafileSkia in printing. | |
404 IPC_SYNC_MESSAGE_CONTROL1_2(PrintHostMsg_AllocateTempFileForPrinting, | |
405 int /* render_view_id */, | |
406 base::FileDescriptor /* temp file fd */, | |
407 int /* fd in browser*/) // Used only by Chrome OS. | |
408 IPC_MESSAGE_CONTROL2(PrintHostMsg_TempFileForPrintingWritten, | |
409 int /* render_view_id */, | |
410 int /* fd in browser */) // Used only by Chrome OS. | |
411 #endif | |
412 | |
413 // Asks the browser to do print preview. | |
414 IPC_MESSAGE_ROUTED1(PrintHostMsg_RequestPrintPreview, | |
415 PrintHostMsg_RequestPrintPreview_Params /* params */) | |
416 | |
417 // Notify the browser the number of pages in the print preview document. | |
418 IPC_MESSAGE_ROUTED1(PrintHostMsg_DidGetPreviewPageCount, | |
419 PrintHostMsg_DidGetPreviewPageCount_Params /* params */) | |
420 | |
421 // Notify the browser of the default page layout according to the currently | |
422 // selected printer and page size. | |
423 // |printable_area_in_points| Specifies the printable area in points. | |
424 // |has_custom_page_size_style| is true when the printing frame has a custom | |
425 // page size css otherwise false. | |
426 IPC_MESSAGE_ROUTED3(PrintHostMsg_DidGetDefaultPageLayout, | |
427 printing::PageSizeMargins /* page layout in points */, | |
428 gfx::Rect /* printable area in points */, | |
429 bool /* has custom page size style */) | |
430 | |
431 // Notify the browser a print preview page has been rendered. | |
432 IPC_MESSAGE_ROUTED1(PrintHostMsg_DidPreviewPage, | |
433 PrintHostMsg_DidPreviewPage_Params /* params */) | |
434 | |
435 // Asks the browser whether the print preview has been cancelled. | |
436 IPC_SYNC_MESSAGE_ROUTED2_1(PrintHostMsg_CheckForCancel, | |
437 int32 /* PrintPreviewUI ID */, | |
438 int /* request id */, | |
439 bool /* print preview cancelled */) | |
440 | |
441 // This is sent when there are invalid printer settings. | |
442 IPC_MESSAGE_ROUTED0(PrintHostMsg_ShowInvalidPrinterSettingsError) | |
443 | |
444 // Sends back to the browser the complete rendered document (non-draft mode, | |
445 // used for printing) that was requested by a PrintMsg_PrintPreview message. | |
446 // The memory handle in this message is already valid in the browser process. | |
447 IPC_MESSAGE_ROUTED1(PrintHostMsg_MetafileReadyForPrinting, | |
448 PrintHostMsg_DidPreviewDocument_Params /* params */) | |
449 | |
450 // Tell the browser printing failed. | |
451 IPC_MESSAGE_ROUTED1(PrintHostMsg_PrintingFailed, | |
452 int /* document cookie */) | |
453 | |
454 // Tell the browser print preview failed. | |
455 IPC_MESSAGE_ROUTED1(PrintHostMsg_PrintPreviewFailed, | |
456 int /* document cookie */) | |
457 | |
458 // Tell the browser print preview was cancelled. | |
459 IPC_MESSAGE_ROUTED1(PrintHostMsg_PrintPreviewCancelled, | |
460 int /* document cookie */) | |
461 | |
462 // Tell the browser print preview found the selected printer has invalid | |
463 // settings (which typically caused by disconnected network printer or printer | |
464 // driver is bogus). | |
465 IPC_MESSAGE_ROUTED1(PrintHostMsg_PrintPreviewInvalidPrinterSettings, | |
466 int /* document cookie */) | |
467 | |
468 // Run a nested message loop in the renderer until print preview for | |
469 // window.print() finishes. | |
470 IPC_SYNC_MESSAGE_ROUTED0_0(PrintHostMsg_SetupScriptedPrintPreview) | |
471 | |
472 // Tell the browser to show the print preview, when the document is sufficiently | |
473 // loaded such that the renderer can determine whether it is modifiable or not. | |
474 IPC_MESSAGE_ROUTED1(PrintHostMsg_ShowScriptedPrintPreview, | |
475 bool /* is_modifiable */) | |
476 | |
477 // Notify the browser to set print presets based on source PDF document. | |
478 IPC_MESSAGE_ROUTED1(PrintHostMsg_SetOptionsFromDocument, | |
479 PrintHostMsg_SetOptionsFromDocument_Params /* params */) | |
OLD | NEW |