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