Home | History | Annotate | Download | only in common
      1 // Copyright (c) 2011 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 "base/values.h"
      9 #include "base/shared_memory.h"
     10 #include "ipc/ipc_message_macros.h"
     11 #include "ui/gfx/native_widget_types.h"
     12 #include "ui/gfx/rect.h"
     13 
     14 #define IPC_MESSAGE_START PrintMsgStart
     15 
     16 // Parameters for a render request.
     17 IPC_STRUCT_BEGIN(PrintMsg_Print_Params)
     18   // Physical size of the page, including non-printable margins,
     19   // in pixels according to dpi.
     20   IPC_STRUCT_MEMBER(gfx::Size, page_size)
     21 
     22   // In pixels according to dpi_x and dpi_y.
     23   IPC_STRUCT_MEMBER(gfx::Size, printable_size)
     24 
     25   // The y-offset of the printable area, in pixels according to dpi.
     26   IPC_STRUCT_MEMBER(int, margin_top)
     27 
     28   // The x-offset of the printable area, in pixels according to dpi.
     29   IPC_STRUCT_MEMBER(int, margin_left)
     30 
     31   // Specifies dots per inch.
     32   IPC_STRUCT_MEMBER(double, dpi)
     33 
     34   // Minimum shrink factor. See PrintSettings::min_shrink for more information.
     35   IPC_STRUCT_MEMBER(double, min_shrink)
     36 
     37   // Maximum shrink factor. See PrintSettings::max_shrink for more information.
     38   IPC_STRUCT_MEMBER(double, max_shrink)
     39 
     40   // Desired apparent dpi on paper.
     41   IPC_STRUCT_MEMBER(int, desired_dpi)
     42 
     43   // Cookie for the document to ensure correctness.
     44   IPC_STRUCT_MEMBER(int, document_cookie)
     45 
     46   // Should only print currently selected text.
     47   IPC_STRUCT_MEMBER(bool, selection_only)
     48 
     49   // Does the printer support alpha blending?
     50   IPC_STRUCT_MEMBER(bool, supports_alpha_blend)
     51 IPC_STRUCT_END()
     52 
     53 IPC_STRUCT_BEGIN(PrintMsg_PrintPage_Params)
     54   // Parameters to render the page as a printed page. It must always be the same
     55   // value for all the document.
     56   IPC_STRUCT_MEMBER(PrintMsg_Print_Params, params)
     57 
     58   // The page number is the indicator of the square that should be rendered
     59   // according to the layout specified in PrintMsg_Print_Params.
     60   IPC_STRUCT_MEMBER(int, page_number)
     61 IPC_STRUCT_END()
     62 
     63 IPC_STRUCT_BEGIN(PrintMsg_PrintPages_Params)
     64   // Parameters to render the page as a printed page. It must always be the same
     65   // value for all the document.
     66   IPC_STRUCT_MEMBER(PrintMsg_Print_Params, params)
     67 
     68   // If empty, this means a request to render all the printed pages.
     69   IPC_STRUCT_MEMBER(std::vector<int>, pages)
     70 IPC_STRUCT_END()
     71 
     72 // Parameters to describe a rendered document.
     73 IPC_STRUCT_BEGIN(PrintHostMsg_DidPreviewDocument_Params)
     74   // A shared memory handle to metafile data.
     75   IPC_STRUCT_MEMBER(base::SharedMemoryHandle, metafile_data_handle)
     76 
     77   // Size of metafile data.
     78   IPC_STRUCT_MEMBER(uint32, data_size)
     79 
     80   // Cookie for the document to ensure correctness.
     81   IPC_STRUCT_MEMBER(int, document_cookie)
     82 
     83   // Store the expected pages count.
     84   IPC_STRUCT_MEMBER(int, expected_pages_count)
     85 IPC_STRUCT_END()
     86 
     87 // Parameters to describe a rendered page.
     88 IPC_STRUCT_BEGIN(PrintHostMsg_DidPrintPage_Params)
     89   // A shared memory handle to the EMF data. This data can be quite large so a
     90   // memory map needs to be used.
     91   IPC_STRUCT_MEMBER(base::SharedMemoryHandle, metafile_data_handle)
     92 
     93   // Size of the metafile data.
     94   IPC_STRUCT_MEMBER(uint32, data_size)
     95 
     96   // Cookie for the document to ensure correctness.
     97   IPC_STRUCT_MEMBER(int, document_cookie)
     98 
     99   // Page number.
    100   IPC_STRUCT_MEMBER(int, page_number)
    101 
    102   // Shrink factor used to render this page.
    103   IPC_STRUCT_MEMBER(double, actual_shrink)
    104 
    105   // The size of the page the page author specified.
    106   IPC_STRUCT_MEMBER(gfx::Size, page_size)
    107 
    108   // The printable area the page author specified.
    109   IPC_STRUCT_MEMBER(gfx::Rect, content_area)
    110 
    111   // True if the page has visible overlays.
    112   IPC_STRUCT_MEMBER(bool, has_visible_overlays)
    113 IPC_STRUCT_END()
    114 
    115 // Parameters for the IPC message ViewHostMsg_ScriptedPrint
    116 IPC_STRUCT_BEGIN(PrintHostMsg_ScriptedPrint_Params)
    117   IPC_STRUCT_MEMBER(int, routing_id)
    118   IPC_STRUCT_MEMBER(gfx::NativeViewId, host_window_id)
    119   IPC_STRUCT_MEMBER(int, cookie)
    120   IPC_STRUCT_MEMBER(int, expected_pages_count)
    121   IPC_STRUCT_MEMBER(bool, has_selection)
    122   IPC_STRUCT_MEMBER(bool, use_overlays)
    123 IPC_STRUCT_END()
    124 
    125 
    126 // Messages sent from the browser to the renderer.
    127 
    128 IPC_MESSAGE_ROUTED0(PrintMsg_PrintNodeUnderContextMenu)
    129 
    130 // Tells the renderer to print the print preview tab's PDF plugin without
    131 // showing the print dialog.
    132 IPC_MESSAGE_ROUTED1(PrintMsg_PrintForPrintPreview,
    133                     DictionaryValue /* settings*/)
    134 
    135 // Tells the render view to switch the CSS to print media type, renders every
    136 // requested pages and switch back the CSS to display media type.
    137 IPC_MESSAGE_ROUTED0(PrintMsg_PrintPages)
    138 
    139 // Tells the render view that printing is done so it can clean up.
    140 IPC_MESSAGE_ROUTED2(PrintMsg_PrintingDone,
    141                     int /* document_cookie */,
    142                     bool /* success */)
    143 
    144 // Tells the render view to switch the CSS to print media type, renders every
    145 // requested pages for print preview using the given |settngs|.
    146 IPC_MESSAGE_ROUTED1(PrintMsg_PrintPreview,
    147                     DictionaryValue /* settings */)
    148 
    149 // Tells a renderer to stop blocking script initiated printing.
    150 IPC_MESSAGE_ROUTED0(PrintMsg_ResetScriptedPrintCount)
    151 
    152 
    153 // Messages sent from the renderer to the browser.
    154 
    155 #if defined(OS_WIN)
    156 // Duplicates a shared memory handle from the renderer to the browser. Then
    157 // the renderer can flush the handle.
    158 IPC_SYNC_MESSAGE_ROUTED1_1(PrintHostMsg_DuplicateSection,
    159                            base::SharedMemoryHandle /* renderer handle */,
    160                            base::SharedMemoryHandle /* browser handle */)
    161 #endif
    162 
    163 // Tells the browser that the renderer is done calculating the number of
    164 // rendered pages according to the specified settings.
    165 IPC_MESSAGE_ROUTED2(PrintHostMsg_DidGetPrintedPagesCount,
    166                     int /* rendered document cookie */,
    167                     int /* number of rendered pages */)
    168 
    169 // Sends back to the browser the rendered "printed page" that was requested by
    170 // a ViewMsg_PrintPage message or from scripted printing. The memory handle in
    171 // this message is already valid in the browser process.
    172 IPC_MESSAGE_ROUTED1(PrintHostMsg_DidPrintPage,
    173                     PrintHostMsg_DidPrintPage_Params /* page content */)
    174 
    175 // The renderer wants to know the default print settings.
    176 IPC_SYNC_MESSAGE_ROUTED0_1(PrintHostMsg_GetDefaultPrintSettings,
    177                            PrintMsg_Print_Params /* default_settings */)
    178 
    179 // The renderer wants to update the current print settings with new
    180 // |job_settings|.
    181 IPC_SYNC_MESSAGE_ROUTED2_1(PrintHostMsg_UpdatePrintSettings,
    182                            int /* document_cookie */,
    183                            DictionaryValue /* job_settings */,
    184                            PrintMsg_PrintPages_Params /* current_settings */)
    185 
    186 // It's the renderer that controls the printing process when it is generated
    187 // by javascript. This step is about showing UI to the user to select the
    188 // final print settings. The output parameter is the same as
    189 // ViewMsg_PrintPages which is executed implicitly.
    190 IPC_SYNC_MESSAGE_ROUTED1_1(PrintHostMsg_ScriptedPrint,
    191                            PrintHostMsg_ScriptedPrint_Params,
    192                            PrintMsg_PrintPages_Params
    193                                /* settings chosen by the user*/)
    194 
    195 #if defined(USE_X11)
    196 // Asks the browser to create a temporary file for the renderer to fill
    197 // in resulting NativeMetafile in printing.
    198 IPC_SYNC_MESSAGE_CONTROL0_2(PrintHostMsg_AllocateTempFileForPrinting,
    199                             base::FileDescriptor /* temp file fd */,
    200                             int /* fd in browser*/)
    201 IPC_MESSAGE_CONTROL1(PrintHostMsg_TempFileForPrintingWritten,
    202                      int /* fd in browser */)
    203 #endif
    204 
    205 // Asks the browser to do print preview for the node under the context menu.
    206 IPC_MESSAGE_ROUTED0(PrintHostMsg_PrintPreviewNodeUnderContextMenu)
    207 
    208 // Asks the browser to do print preview for window.print().
    209 IPC_MESSAGE_ROUTED0(PrintHostMsg_ScriptInitiatedPrintPreview)
    210 
    211 // Sends back to the browser the rendered "printed document" for preview that
    212 // was requested by a PrintMsg_PrintPreview message. The memory handle in this
    213 // message is already valid in the browser process.
    214 IPC_MESSAGE_ROUTED1(PrintHostMsg_PagesReadyForPreview,
    215                     PrintHostMsg_DidPreviewDocument_Params /* params */)
    216