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 23 struct 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 53 struct 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 64 struct 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 77 IPC_ENUM_TRAITS_MAX_VALUE(printing::MarginType, 78 printing::MARGIN_TYPE_LAST) 79 IPC_ENUM_TRAITS_MAX_VALUE(blink::WebPrintScalingOption, 80 blink::WebPrintScalingOptionLast) 81 82 // Parameters for a render request. 83 IPC_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) 149 IPC_STRUCT_TRAITS_END() 150 151 IPC_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) 159 IPC_STRUCT_END() 160 161 IPC_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) 166 IPC_STRUCT_TRAITS_END() 167 168 IPC_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) 175 IPC_STRUCT_TRAITS_END() 176 177 IPC_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) 184 IPC_STRUCT_TRAITS_END() 185 186 // Parameters to describe a rendered document. 187 IPC_STRUCT_BEGIN(PrintHostMsg_DidPreviewDocument_Params) 188 // A shared memory handle to metafile data. 189 IPC_STRUCT_MEMBER(base::SharedMemoryHandle, metafile_data_handle) 190 191 // Size of metafile data. 192 IPC_STRUCT_MEMBER(uint32, data_size) 193 194 // Cookie for the document to ensure correctness. 195 IPC_STRUCT_MEMBER(int, document_cookie) 196 197 // Store the expected pages count. 198 IPC_STRUCT_MEMBER(int, expected_pages_count) 199 200 // Whether the preview can be modified. 201 IPC_STRUCT_MEMBER(bool, modifiable) 202 203 // The id of the preview request. 204 IPC_STRUCT_MEMBER(int, preview_request_id) 205 IPC_STRUCT_END() 206 207 // Parameters to describe a rendered preview page. 208 IPC_STRUCT_BEGIN(PrintHostMsg_DidPreviewPage_Params) 209 // A shared memory handle to metafile data for a draft document of the page. 210 IPC_STRUCT_MEMBER(base::SharedMemoryHandle, metafile_data_handle) 211 212 // Size of metafile data. 213 IPC_STRUCT_MEMBER(uint32, data_size) 214 215 // |page_number| is zero-based and can be |printing::INVALID_PAGE_INDEX| if it 216 // is just a check. 217 IPC_STRUCT_MEMBER(int, page_number) 218 219 // The id of the preview request. 220 IPC_STRUCT_MEMBER(int, preview_request_id) 221 IPC_STRUCT_END() 222 223 // Parameters sent along with the page count. 224 IPC_STRUCT_BEGIN(PrintHostMsg_DidGetPreviewPageCount_Params) 225 // Cookie for the document to ensure correctness. 226 IPC_STRUCT_MEMBER(int, document_cookie) 227 228 // Total page count. 229 IPC_STRUCT_MEMBER(int, page_count) 230 231 // Indicates whether the previewed document is modifiable. 232 IPC_STRUCT_MEMBER(bool, is_modifiable) 233 234 // The id of the preview request. 235 IPC_STRUCT_MEMBER(int, preview_request_id) 236 237 // Indicates whether the existing preview data needs to be cleared or not. 238 IPC_STRUCT_MEMBER(bool, clear_preview_data) 239 IPC_STRUCT_END() 240 241 // Parameters to describe a rendered page. 242 IPC_STRUCT_BEGIN(PrintHostMsg_DidPrintPage_Params) 243 // A shared memory handle to the EMF data. This data can be quite large so a 244 // memory map needs to be used. 245 IPC_STRUCT_MEMBER(base::SharedMemoryHandle, metafile_data_handle) 246 247 // Size of the metafile data. 248 IPC_STRUCT_MEMBER(uint32, data_size) 249 250 // Cookie for the document to ensure correctness. 251 IPC_STRUCT_MEMBER(int, document_cookie) 252 253 // Page number. 254 IPC_STRUCT_MEMBER(int, page_number) 255 256 #if defined(OS_WIN) && !defined(WIN_PDF_METAFILE_FOR_PRINTING) 257 // Shrink factor used to render this page. 258 IPC_STRUCT_MEMBER(double, actual_shrink) 259 #endif // OS_WIN && !WIN_PDF_METAFILE_FOR_PRINTING 260 261 // The size of the page the page author specified. 262 IPC_STRUCT_MEMBER(gfx::Size, page_size) 263 264 // The printable area the page author specified. 265 IPC_STRUCT_MEMBER(gfx::Rect, content_area) 266 IPC_STRUCT_END() 267 268 // Parameters for the IPC message ViewHostMsg_ScriptedPrint 269 IPC_STRUCT_BEGIN(PrintHostMsg_ScriptedPrint_Params) 270 IPC_STRUCT_MEMBER(int, cookie) 271 IPC_STRUCT_MEMBER(int, expected_pages_count) 272 IPC_STRUCT_MEMBER(bool, has_selection) 273 IPC_STRUCT_MEMBER(printing::MarginType, margin_type) 274 IPC_STRUCT_END() 275 276 277 // Messages sent from the browser to the renderer. 278 279 // Tells the render view to initiate print preview for the entire document. 280 IPC_MESSAGE_ROUTED1(PrintMsg_InitiatePrintPreview, bool /* selection_only */) 281 282 // Tells the render frame to initiate printing or print preview for a particular 283 // node, depending on which mode the render frame is in. 284 IPC_MESSAGE_ROUTED0(PrintMsg_PrintNodeUnderContextMenu) 285 286 // Tells the renderer to print the print preview tab's PDF plugin without 287 // showing the print dialog. (This is the final step in the print preview 288 // workflow.) 289 IPC_MESSAGE_ROUTED1(PrintMsg_PrintForPrintPreview, 290 base::DictionaryValue /* settings */) 291 292 // Tells the render view to switch the CSS to print media type, renders every 293 // requested pages and switch back the CSS to display media type. 294 IPC_MESSAGE_ROUTED0(PrintMsg_PrintPages) 295 296 // Tells the render view that printing is done so it can clean up. 297 IPC_MESSAGE_ROUTED1(PrintMsg_PrintingDone, 298 bool /* success */) 299 300 // Tells the render view whether scripted printing is blocked or not. 301 IPC_MESSAGE_ROUTED1(PrintMsg_SetScriptedPrintingBlocked, 302 bool /* blocked */) 303 304 // Tells the render view to switch the CSS to print media type, renders every 305 // requested pages for print preview using the given |settings|. This gets 306 // called multiple times as the user updates settings. 307 IPC_MESSAGE_ROUTED1(PrintMsg_PrintPreview, 308 base::DictionaryValue /* settings */) 309 310 // Like PrintMsg_PrintPages, but using the print preview document's frame/node. 311 IPC_MESSAGE_ROUTED0(PrintMsg_PrintForSystemDialog) 312 313 // Tells a renderer to stop blocking script initiated printing. 314 IPC_MESSAGE_ROUTED0(PrintMsg_ResetScriptedPrintCount) 315 316 // Messages sent from the renderer to the browser. 317 318 #if defined(OS_WIN) 319 // Duplicates a shared memory handle from the renderer to the browser. Then 320 // the renderer can flush the handle. 321 IPC_SYNC_MESSAGE_ROUTED1_1(PrintHostMsg_DuplicateSection, 322 base::SharedMemoryHandle /* renderer handle */, 323 base::SharedMemoryHandle /* browser handle */) 324 #endif 325 326 // Check if printing is enabled. 327 IPC_SYNC_MESSAGE_ROUTED0_1(PrintHostMsg_IsPrintingEnabled, 328 bool /* is_enabled */) 329 330 // Tells the browser that the renderer is done calculating the number of 331 // rendered pages according to the specified settings. 332 IPC_MESSAGE_ROUTED2(PrintHostMsg_DidGetPrintedPagesCount, 333 int /* rendered document cookie */, 334 int /* number of rendered pages */) 335 336 // Sends the document cookie of the current printer query to the browser. 337 IPC_MESSAGE_ROUTED1(PrintHostMsg_DidGetDocumentCookie, 338 int /* rendered document cookie */) 339 340 // Tells the browser that the print dialog has been shown. 341 IPC_MESSAGE_ROUTED0(PrintHostMsg_DidShowPrintDialog) 342 343 // Sends back to the browser the rendered "printed page" that was requested by 344 // a ViewMsg_PrintPage message or from scripted printing. The memory handle in 345 // this message is already valid in the browser process. 346 IPC_MESSAGE_ROUTED1(PrintHostMsg_DidPrintPage, 347 PrintHostMsg_DidPrintPage_Params /* page content */) 348 349 // The renderer wants to know the default print settings. 350 IPC_SYNC_MESSAGE_ROUTED0_1(PrintHostMsg_GetDefaultPrintSettings, 351 PrintMsg_Print_Params /* default_settings */) 352 353 // The renderer wants to update the current print settings with new 354 // |job_settings|. 355 IPC_SYNC_MESSAGE_ROUTED2_1(PrintHostMsg_UpdatePrintSettings, 356 int /* document_cookie */, 357 base::DictionaryValue /* job_settings */, 358 PrintMsg_PrintPages_Params /* current_settings */) 359 360 // It's the renderer that controls the printing process when it is generated 361 // by javascript. This step is about showing UI to the user to select the 362 // final print settings. The output parameter is the same as 363 // ViewMsg_PrintPages which is executed implicitly. 364 IPC_SYNC_MESSAGE_ROUTED1_1(PrintHostMsg_ScriptedPrint, 365 PrintHostMsg_ScriptedPrint_Params, 366 PrintMsg_PrintPages_Params 367 /* settings chosen by the user*/) 368 369 #if defined(OS_CHROMEOS) || defined(OS_ANDROID) 370 // Asks the browser to create a temporary file for the renderer to fill 371 // in resulting NativeMetafile in printing. 372 IPC_SYNC_MESSAGE_CONTROL1_2(PrintHostMsg_AllocateTempFileForPrinting, 373 int /* render_view_id */, 374 base::FileDescriptor /* temp file fd */, 375 int /* fd in browser*/) // Used only by Chrome OS. 376 IPC_MESSAGE_CONTROL2(PrintHostMsg_TempFileForPrintingWritten, 377 int /* render_view_id */, 378 int /* fd in browser */) // Used only by Chrome OS. 379 #endif 380 381 // Asks the browser to do print preview. 382 IPC_MESSAGE_ROUTED1(PrintHostMsg_RequestPrintPreview, 383 PrintHostMsg_RequestPrintPreview_Params /* params */) 384 385 // Notify the browser the number of pages in the print preview document. 386 IPC_MESSAGE_ROUTED1(PrintHostMsg_DidGetPreviewPageCount, 387 PrintHostMsg_DidGetPreviewPageCount_Params /* params */) 388 389 // Notify the browser of the default page layout according to the currently 390 // selected printer and page size. 391 // |printable_area_in_points| Specifies the printable area in points. 392 // |has_custom_page_size_style| is true when the printing frame has a custom 393 // page size css otherwise false. 394 IPC_MESSAGE_ROUTED3(PrintHostMsg_DidGetDefaultPageLayout, 395 printing::PageSizeMargins /* page layout in points */, 396 gfx::Rect /* printable area in points */, 397 bool /* has custom page size style */) 398 399 // Notify the browser a print preview page has been rendered. 400 IPC_MESSAGE_ROUTED1(PrintHostMsg_DidPreviewPage, 401 PrintHostMsg_DidPreviewPage_Params /* params */) 402 403 // Asks the browser whether the print preview has been cancelled. 404 IPC_SYNC_MESSAGE_ROUTED2_1(PrintHostMsg_CheckForCancel, 405 int32 /* PrintPreviewUI ID */, 406 int /* request id */, 407 bool /* print preview cancelled */) 408 409 // This is sent when there are invalid printer settings. 410 IPC_MESSAGE_ROUTED0(PrintHostMsg_ShowInvalidPrinterSettingsError) 411 412 // Sends back to the browser the complete rendered document (non-draft mode, 413 // used for printing) that was requested by a PrintMsg_PrintPreview message. 414 // The memory handle in this message is already valid in the browser process. 415 IPC_MESSAGE_ROUTED1(PrintHostMsg_MetafileReadyForPrinting, 416 PrintHostMsg_DidPreviewDocument_Params /* params */) 417 418 // Tell the browser printing failed. 419 IPC_MESSAGE_ROUTED1(PrintHostMsg_PrintingFailed, 420 int /* document cookie */) 421 422 // Tell the browser print preview failed. 423 IPC_MESSAGE_ROUTED1(PrintHostMsg_PrintPreviewFailed, 424 int /* document cookie */) 425 426 // Tell the browser print preview was cancelled. 427 IPC_MESSAGE_ROUTED1(PrintHostMsg_PrintPreviewCancelled, 428 int /* document cookie */) 429 430 // Tell the browser print preview found the selected printer has invalid 431 // settings (which typically caused by disconnected network printer or printer 432 // driver is bogus). 433 IPC_MESSAGE_ROUTED1(PrintHostMsg_PrintPreviewInvalidPrinterSettings, 434 int /* document cookie */) 435 436 // Run a nested message loop in the renderer until print preview for 437 // window.print() finishes. 438 IPC_SYNC_MESSAGE_ROUTED0_0(PrintHostMsg_SetupScriptedPrintPreview) 439 440 // Tell the browser to show the print preview, when the document is sufficiently 441 // loaded such that the renderer can determine whether it is modifiable or not. 442 IPC_MESSAGE_ROUTED1(PrintHostMsg_ShowScriptedPrintPreview, 443 bool /* is_modifiable */) 444 445 // Notify the browser that the PDF in the initiator renderer has disabled print 446 // scaling option. 447 IPC_MESSAGE_ROUTED0(PrintHostMsg_PrintPreviewScalingDisabled) 448