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