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