chromium/printing/backend/print_backend.h

// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef PRINTING_BACKEND_PRINT_BACKEND_H_
#define PRINTING_BACKEND_PRINT_BACKEND_H_

#include <stdint.h>

#include <map>
#include <optional>
#include <string>
#include <vector>

#include "base/component_export.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_refptr.h"
#include "build/build_config.h"
#include "printing/mojom/print.mojom.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/size.h"

#if BUILDFLAG(IS_WIN)
#include "base/types/expected.h"
#endif  // BUILDFLAG(IS_WIN)

// This is the interface for platform-specific code for a print backend
namespace printing {

PrinterBasicInfoOptions;

struct COMPONENT_EXPORT(PRINT_BACKEND) PrinterBasicInfo {};

PrinterList;

#if BUILDFLAG(IS_CHROMEOS)

struct COMPONENT_EXPORT(PRINT_BACKEND) AdvancedCapabilityValue {
  AdvancedCapabilityValue();
  AdvancedCapabilityValue(const std::string& name,
                          const std::string& display_name);
  AdvancedCapabilityValue(const AdvancedCapabilityValue& other);
  ~AdvancedCapabilityValue();

  bool operator==(const AdvancedCapabilityValue& other) const;

  // IPP identifier of the value.
  std::string name;

  // Localized name for the value.
  std::string display_name;
};

struct COMPONENT_EXPORT(PRINT_BACKEND) AdvancedCapability {
  enum class Type : uint8_t { kBoolean, kFloat, kInteger, kString };

  AdvancedCapability();
  AdvancedCapability(const std::string& name, AdvancedCapability::Type type);
  AdvancedCapability(const std::string& name,
                     const std::string& display_name,
                     AdvancedCapability::Type type,
                     const std::string& default_value,
                     const std::vector<AdvancedCapabilityValue>& values);
  AdvancedCapability(const AdvancedCapability& other);
  ~AdvancedCapability();

  bool operator==(const AdvancedCapability& other) const;

  // IPP identifier of the attribute.
  std::string name;

  // Localized name for the attribute.
  std::string display_name;

  // Attribute type.
  AdvancedCapability::Type type;

  // Default value.
  std::string default_value;

  // Values for enumerated attributes.
  std::vector<AdvancedCapabilityValue> values;
};

using AdvancedCapabilities = std::vector<AdvancedCapability>;

#endif  // BUILDFLAG(IS_CHROMEOS)

#if BUILDFLAG(IS_WIN)

struct COMPONENT_EXPORT(PRINT_BACKEND) PageOutputQualityAttribute {
  PageOutputQualityAttribute();
  PageOutputQualityAttribute(const std::string& display_name,
                             const std::string& name);
  ~PageOutputQualityAttribute();

  bool operator==(const PageOutputQualityAttribute& other) const;

  bool operator<(const PageOutputQualityAttribute& other) const;

  // Localized name of the page output quality attribute.
  std::string display_name;

  // Internal ID of the page output quality attribute.
  std::string name;
};
using PageOutputQualityAttributes = std::vector<PageOutputQualityAttribute>;

struct COMPONENT_EXPORT(PRINT_BACKEND) PageOutputQuality {
  PageOutputQuality();
  PageOutputQuality(PageOutputQualityAttributes qualities,
                    std::optional<std::string> default_quality);
  PageOutputQuality(const PageOutputQuality& other);
  ~PageOutputQuality();

  // All options of page output quality.
  PageOutputQualityAttributes qualities;

  // Default option of page output quality.
  // TODO(crbug.com/40212677): Need populate this option in the next CLs.
  std::optional<std::string> default_quality;
};

#if defined(UNIT_TEST)

COMPONENT_EXPORT(PRINT_BACKEND)
bool operator==(const PageOutputQuality& quality1,
                const PageOutputQuality& quality2);

#endif  // defined(UNIT_TEST)

struct COMPONENT_EXPORT(PRINT_BACKEND) XpsCapabilities {
  XpsCapabilities();
  XpsCapabilities(const XpsCapabilities&) = delete;
  XpsCapabilities& operator=(const XpsCapabilities&) = delete;
  XpsCapabilities(XpsCapabilities&& other) noexcept;
  XpsCapabilities& operator=(XpsCapabilities&& other) noexcept;
  ~XpsCapabilities();

  std::optional<PageOutputQuality> page_output_quality;
};

#endif  // BUILDFLAG(IS_WIN)

struct COMPONENT_EXPORT(PRINT_BACKEND) PrinterSemanticCapsAndDefaults {};

#if defined(UNIT_TEST)

COMPONENT_EXPORT(PRINT_BACKEND)
bool operator==(const PrinterSemanticCapsAndDefaults& caps1,
                const PrinterSemanticCapsAndDefaults& caps2);

#endif  // defined(UNIT_TEST)

struct COMPONENT_EXPORT(PRINT_BACKEND) PrinterCapsAndDefaults {};

// PrintBackend class will provide interface for different print backends
// (Windows, CUPS) to implement. User will call CreateInstance() to
// obtain available print backend.
// Please note, that PrintBackend is not platform specific, but rather
// print system specific. For example, CUPS is available on both Linux and Mac,
// but not available on ChromeOS, etc. This design allows us to add more
// functionality on some platforms, while reusing core (CUPS) functions.
class COMPONENT_EXPORT(PRINT_BACKEND) PrintBackend
    : public base::RefCountedThreadSafe<PrintBackend> {};

}  // namespace printing

#endif  // PRINTING_BACKEND_PRINT_BACKEND_H_