[M120 Migration][VD] Remove accessing oom_score_adj in zygote process
[platform/framework/web/chromium-efl.git] / printing / print_settings.h
1 // Copyright 2012 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef PRINTING_PRINT_SETTINGS_H_
6 #define PRINTING_PRINT_SETTINGS_H_
7
8 #include <algorithm>
9 #include <string>
10 #include <utility>
11 #include <vector>
12
13 #include "base/component_export.h"
14 #include "build/build_config.h"
15 #include "printing/buildflags/buildflags.h"
16 #include "printing/mojom/print.mojom.h"
17 #include "printing/page_range.h"
18 #include "printing/page_setup.h"
19 #include "printing/print_job_constants.h"
20 #include "third_party/abseil-cpp/absl/types/optional.h"
21 #include "ui/gfx/geometry/rect.h"
22 #include "ui/gfx/geometry/size.h"
23
24 #if BUILDFLAG(ENABLE_OOP_PRINTING_NO_OOP_BASIC_PRINT_DIALOG)
25 #include "base/values.h"
26 #endif
27
28 #if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
29 #include <map>
30
31 #include "base/values.h"
32 #endif  // BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
33
34 #if BUILDFLAG(IS_CHROMEOS)
35 #include "chromeos/crosapi/mojom/local_printer.mojom.h"
36 #endif  // BUILDFLAG(IS_CHROMEOS)
37
38 namespace printing {
39
40 #if BUILDFLAG(ENABLE_OOP_PRINTING_NO_OOP_BASIC_PRINT_DIALOG)
41
42 #if BUILDFLAG(IS_MAC)
43 inline constexpr char kMacSystemPrintDialogDataDestinationType[] =
44     "destination_type";
45 inline constexpr char kMacSystemPrintDialogDataDestinationFormat[] =
46     "destination_format";
47 inline constexpr char kMacSystemPrintDialogDataDestinationLocation[] =
48     "destination_location";
49 inline constexpr char kMacSystemPrintDialogDataPageFormat[] = "page_format";
50 inline constexpr char kMacSystemPrintDialogDataPrintSettings[] =
51     "print_settings";
52 #endif  // BUILDFLAG(IS_MAC)
53
54 #if BUILDFLAG(IS_LINUX)
55 inline constexpr char kLinuxSystemPrintDialogDataPrinter[] = "printer_name";
56 inline constexpr char kLinuxSystemPrintDialogDataPrintSettings[] =
57     "print_settings";
58 inline constexpr char kLinuxSystemPrintDialogDataPageSetup[] = "page_setup";
59 #endif  // BUILDFLAG(IS_LINUX)
60
61 #endif  // BUILDFLAG(ENABLE_OOP_PRINTING_NO_OOP_BASIC_PRINT_DIALOG)
62
63 // Convert from `color_mode` into a `color_model`.  An invalid `color_mode`
64 // will give a result of `mojom::ColorModel::kUnknownColorModel`.
65 COMPONENT_EXPORT(PRINTING)
66 mojom::ColorModel ColorModeToColorModel(int color_mode);
67
68 // Returns true if `color_model` is color and false if it is B&W.  Callers
69 // are not supposed to pass in `mojom::ColorModel::kUnknownColorModel`, but
70 // if they do then the result will be absl::nullopt.
71 COMPONENT_EXPORT(PRINTING)
72 absl::optional<bool> IsColorModelSelected(mojom::ColorModel color_model);
73
74 #if BUILDFLAG(USE_CUPS)
75 // Get the color model setting name and value for the `color_model`.
76 COMPONENT_EXPORT(PRINTING)
77 void GetColorModelForModel(mojom::ColorModel color_model,
78                            std::string* color_setting_name,
79                            std::string* color_value);
80 #endif  // BUILDFLAG(USE_CUPS)
81
82 #if BUILDFLAG(USE_CUPS_IPP)
83 // Convert from `color_model` to a print-color-mode value from PWG 5100.13.
84 COMPONENT_EXPORT(PRINTING)
85 std::string GetIppColorModelForModel(mojom::ColorModel color_model);
86 #endif  // BUILDFLAG(USE_CUPS_IPP)
87
88 class COMPONENT_EXPORT(PRINTING) PrintSettings {
89  public:
90   // Media properties requested by the user. Default instance represents
91   // default media selection.
92   struct RequestedMedia {
93     bool operator==(const RequestedMedia& other) const;
94     bool IsDefault() const {
95       return size_microns.IsEmpty() && vendor_id.empty();
96     }
97
98     // Size of the media, in microns.
99     gfx::Size size_microns;
100     // Platform specific id to map it back to the particular media.
101     std::string vendor_id;
102   };
103
104 #if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
105   using AdvancedSettings = std::map<std::string, base::Value>;
106 #endif  // BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
107
108   PrintSettings();
109   PrintSettings(const PrintSettings&);
110   PrintSettings& operator=(const PrintSettings&);
111   ~PrintSettings();
112
113   bool operator==(const PrintSettings& other) const;
114
115   // Reinitialize the settings to the default values.
116   void Clear();
117
118   void SetCustomMargins(const PageMargins& requested_margins_in_points);
119   const PageMargins& requested_custom_margins_in_points() const {
120     return requested_custom_margins_in_points_;
121   }
122   void set_margin_type(mojom::MarginType margin_type) {
123     margin_type_ = margin_type;
124   }
125   mojom::MarginType margin_type() const { return margin_type_; }
126
127   // Updates the orientation and flip the page if needed.
128   void SetOrientation(bool landscape);
129   bool landscape() const { return landscape_; }
130
131   // Updates user requested media.
132   void set_requested_media(const RequestedMedia& media) {
133     requested_media_ = media;
134   }
135   // Media properties requested by the user. Translated into device media by the
136   // platform specific layers.
137   const RequestedMedia& requested_media() const { return requested_media_; }
138
139   // Set printer printable area in in device units.
140   // Some platforms already provide flipped area. Set `landscape_needs_flip`
141   // to false on those platforms to avoid double flipping.
142   // This method assumes correct DPI is already set.
143   void SetPrinterPrintableArea(const gfx::Size& physical_size_device_units,
144                                const gfx::Rect& printable_area_device_units,
145                                bool landscape_needs_flip);
146 #if BUILDFLAG(IS_WIN)
147   // Update the printer printable area for the current media using the
148   // provided area in microns.
149   void UpdatePrinterPrintableArea(const gfx::Rect& printable_area_um);
150 #endif
151   const PageSetup& page_setup_device_units() const {
152     return page_setup_device_units_;
153   }
154   // `set_page_setup_device_units()` intended to be used only for mojom
155   // validation.
156   void set_page_setup_device_units(const PageSetup& page_setup_device_units) {
157     page_setup_device_units_ = page_setup_device_units;
158   }
159
160   void set_device_name(const std::u16string& device_name) {
161     device_name_ = device_name;
162   }
163   const std::u16string& device_name() const { return device_name_; }
164
165   void set_borderless(bool borderless) { borderless_ = borderless; }
166   bool borderless() const { return borderless_; }
167
168   void set_media_type(const std::string& media_type) {
169     media_type_ = media_type;
170   }
171   const std::string& media_type() const { return media_type_; }
172
173   void set_dpi(int dpi) { dpi_ = gfx::Size(dpi, dpi); }
174   void set_dpi_xy(int dpi_horizontal, int dpi_vertical) {
175     dpi_ = gfx::Size(dpi_horizontal, dpi_vertical);
176   }
177
178   int dpi() const { return std::max(dpi_.width(), dpi_.height()); }
179   int dpi_horizontal() const { return dpi_.width(); }
180   int dpi_vertical() const { return dpi_.height(); }
181   const gfx::Size& dpi_size() const { return dpi_; }
182
183   void set_scale_factor(double scale_factor) { scale_factor_ = scale_factor; }
184   double scale_factor() const { return scale_factor_; }
185
186   void set_rasterize_pdf(bool rasterize_pdf) { rasterize_pdf_ = rasterize_pdf; }
187   bool rasterize_pdf() const { return rasterize_pdf_; }
188
189   void set_rasterize_pdf_dpi(int32_t dpi) { rasterize_pdf_dpi_ = dpi; }
190   int32_t rasterize_pdf_dpi() const { return rasterize_pdf_dpi_; }
191
192   int device_units_per_inch() const {
193 #if BUILDFLAG(IS_MAC)
194     return kMacDeviceUnitsPerInch;
195 #else   // BUILDFLAG(IS_MAC)
196     return dpi();
197 #endif  // BUILDFLAG(IS_MAC)
198   }
199
200   const gfx::Size& device_units_per_inch_size() const {
201 #if BUILDFLAG(IS_MAC)
202     static constexpr gfx::Size kSize{kMacDeviceUnitsPerInch,
203                                      kMacDeviceUnitsPerInch};
204     return kSize;
205 #else   // BUILDFLAG(IS_MAC)
206     return dpi_size();
207 #endif  // BUILDFLAG(IS_MAC)
208   }
209
210   void set_ranges(const PageRanges& ranges) { ranges_ = ranges; }
211   const PageRanges& ranges() const { return ranges_; }
212
213   void set_selection_only(bool selection_only) {
214     selection_only_ = selection_only;
215   }
216   bool selection_only() const { return selection_only_; }
217
218   void set_should_print_backgrounds(bool should_print_backgrounds) {
219     should_print_backgrounds_ = should_print_backgrounds;
220   }
221   bool should_print_backgrounds() const { return should_print_backgrounds_; }
222
223   void set_display_header_footer(bool display_header_footer) {
224     display_header_footer_ = display_header_footer;
225   }
226   bool display_header_footer() const { return display_header_footer_; }
227
228   void set_title(const std::u16string& title) { title_ = title; }
229   const std::u16string& title() const { return title_; }
230
231   void set_url(const std::u16string& url) { url_ = url; }
232   const std::u16string& url() const { return url_; }
233
234   void set_collate(bool collate) { collate_ = collate; }
235   bool collate() const { return collate_; }
236
237   void set_color(mojom::ColorModel color) { color_ = color; }
238   mojom::ColorModel color() const { return color_; }
239
240   void set_copies(int copies) { copies_ = copies; }
241   int copies() const { return copies_; }
242
243   void set_duplex_mode(mojom::DuplexMode duplex_mode) {
244     duplex_mode_ = duplex_mode;
245   }
246   mojom::DuplexMode duplex_mode() const { return duplex_mode_; }
247
248 #if BUILDFLAG(IS_WIN)
249   void set_printer_language_type(mojom::PrinterLanguageType type) {
250     printer_language_type_ = type;
251   }
252   mojom::PrinterLanguageType printer_language_type() const {
253     return printer_language_type_;
254   }
255   bool printer_language_is_textonly() const {
256     return printer_language_type_ == mojom::PrinterLanguageType::kTextOnly;
257   }
258   bool printer_language_is_xps() const {
259     return printer_language_type_ == mojom::PrinterLanguageType::kXps;
260   }
261   bool printer_language_is_ps2() const {
262     return printer_language_type_ ==
263            mojom::PrinterLanguageType::kPostscriptLevel2;
264   }
265   bool printer_language_is_ps3() const {
266     return printer_language_type_ ==
267            mojom::PrinterLanguageType::kPostscriptLevel3;
268   }
269 #endif
270
271   void set_is_modifiable(bool is_modifiable) { is_modifiable_ = is_modifiable; }
272   bool is_modifiable() const { return is_modifiable_; }
273
274   int pages_per_sheet() const { return pages_per_sheet_; }
275   void set_pages_per_sheet(int pages_per_sheet) {
276     pages_per_sheet_ = pages_per_sheet;
277   }
278
279 #if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
280   AdvancedSettings& advanced_settings() { return advanced_settings_; }
281   const AdvancedSettings& advanced_settings() const {
282     return advanced_settings_;
283   }
284 #endif  // BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
285
286 #if BUILDFLAG(IS_CHROMEOS)
287   void set_send_user_info(bool send_user_info) {
288     send_user_info_ = send_user_info;
289   }
290   bool send_user_info() const { return send_user_info_; }
291
292   void set_username(const std::string& username) { username_ = username; }
293   const std::string& username() const { return username_; }
294
295   void set_oauth_token(const std::string& oauth_token) {
296     oauth_token_ = oauth_token;
297   }
298   const std::string& oauth_token() const { return oauth_token_; }
299
300   void set_pin_value(const std::string& pin_value) { pin_value_ = pin_value; }
301   const std::string& pin_value() const { return pin_value_; }
302
303   void set_client_infos(std::vector<mojom::IppClientInfo> client_infos) {
304     client_infos_ = std::move(client_infos);
305   }
306   const std::vector<mojom::IppClientInfo>& client_infos() const {
307     return client_infos_;
308   }
309
310   void set_printer_manually_selected(bool printer_manually_selected) {
311     printer_manually_selected_ = printer_manually_selected;
312   }
313   bool printer_manually_selected() const { return printer_manually_selected_; }
314
315   void set_printer_status_reason(
316       crosapi::mojom::StatusReason::Reason printer_status_reason) {
317     printer_status_reason_ = printer_status_reason;
318   }
319   absl::optional<crosapi::mojom::StatusReason::Reason> printer_status_reason()
320       const {
321     return printer_status_reason_;
322   }
323 #endif  // BUILDFLAG(IS_CHROMEOS)
324
325 #if BUILDFLAG(ENABLE_OOP_PRINTING_NO_OOP_BASIC_PRINT_DIALOG)
326   void set_system_print_dialog_data(base::Value::Dict data) {
327     system_print_dialog_data_ = std::move(data);
328   }
329   const base::Value::Dict& system_print_dialog_data() const {
330     return system_print_dialog_data_;
331   }
332 #endif
333   // Cookie generator. It is used to initialize `PrintedDocument` with its
334   // associated `PrintSettings`, to be sure that each generated `PrintedPage`
335   // is correctly associated with its corresponding `PrintedDocument`.
336   static int NewCookie();
337
338   // Creates an invalid cookie for use in situations where the cookie needs to
339   // be marked as invalid.
340   static int NewInvalidCookie();
341
342  private:
343 #if BUILDFLAG(IS_MAC)
344   static constexpr int kMacDeviceUnitsPerInch = 72;
345 #endif
346
347   // Multi-page printing. Each `PageRange` describes a from-to page combination.
348   // This permits printing selected pages only.
349   PageRanges ranges_;
350
351   // Indicates if the user only wants to print the current selection.
352   bool selection_only_;
353
354   // Indicates what kind of margins should be applied to the printable area.
355   mojom::MarginType margin_type_;
356
357   // Strings to be printed as headers and footers if requested by the user.
358   std::u16string title_;
359   std::u16string url_;
360
361   // True if the user wants headers and footers to be displayed.
362   bool display_header_footer_;
363
364   // True if the user wants to print CSS backgrounds.
365   bool should_print_backgrounds_;
366
367   // True if the user wants to print with collate.
368   bool collate_;
369
370   // Color model type for the printer to use.
371   mojom::ColorModel color_;
372
373   // Number of copies user wants to print.
374   int copies_;
375
376   // Duplex type user wants to use.
377   mojom::DuplexMode duplex_mode_;
378
379   // Printer device name as opened by the OS.
380   std::u16string device_name_;
381
382 #if BUILDFLAG(ENABLE_OOP_PRINTING_NO_OOP_BASIC_PRINT_DIALOG)
383   // Platform-specific print settings captured from a system print dialog.
384   // The settings are captured in the browser process for transmission to
385   // the Print Backend service for OOP printing.
386   base::Value::Dict system_print_dialog_data_;
387 #endif
388
389   // Media requested by the user.
390   RequestedMedia requested_media_;
391
392   // Page setup in device units.
393   PageSetup page_setup_device_units_;
394
395   // Whether the user has requested borderless (zero margin) printing.
396   bool borderless_;
397
398   // Media type requested by the user.
399   std::string media_type_;
400
401   // Printer's device effective dots per inch in both axes. The two values will
402   // generally be identical. However, on Windows, there are a few rare printers
403   // that support resolutions with different DPI in different dimensions.
404   gfx::Size dpi_;
405
406   // Scale factor
407   double scale_factor_;
408
409   // True if PDF should be printed as a raster PDF
410   bool rasterize_pdf_;
411
412   // The DPI which overrides the calculated value normally used when
413   // rasterizing a PDF.  A non-positive value would be an invalid choice of a
414   // DPI and indicates no override.
415   int32_t rasterize_pdf_dpi_;
416
417   // Is the orientation landscape or portrait.
418   bool landscape_;
419
420 #if BUILDFLAG(IS_WIN)
421   mojom::PrinterLanguageType printer_language_type_;
422 #endif
423
424   bool is_modifiable_;
425
426   // If margin type is custom, this is what was requested.
427   PageMargins requested_custom_margins_in_points_;
428
429   // Number of pages per sheet.
430   int pages_per_sheet_;
431
432 #if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
433   // Advanced settings.
434   AdvancedSettings advanced_settings_;
435 #endif  // BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
436
437 #if BUILDFLAG(IS_CHROMEOS)
438   // Whether to send user info.
439   bool send_user_info_;
440
441   // Username if it's required by the printer.
442   std::string username_;
443
444   // OAuth access token if it's required by the printer.
445   std::string oauth_token_;
446
447   // PIN code entered by the user.
448   std::string pin_value_;
449
450   // Value of the 'client-info' that will be sent to the printer.
451   // Should only be set for printers that support 'client-info'.
452   std::vector<mojom::IppClientInfo> client_infos_;
453
454   // True if the user selects to print to a different printer than the original
455   // destination shown when Print Preview opens.
456   bool printer_manually_selected_;
457
458   // The printer status reason shown for the selected printer at the time print
459   // is requested. Only local CrOS printers set printer statuses.
460   absl::optional<crosapi::mojom::StatusReason::Reason> printer_status_reason_;
461 #endif  // BUILDFLAG(IS_CHROMEOS)
462 };
463
464 }  // namespace printing
465
466 #endif  // PRINTING_PRINT_SETTINGS_H_