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