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