chromium/components/cloud_devices/common/printer_description.cc

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

#include "components/cloud_devices/common/printer_description.h"

#include <stddef.h>

#include <algorithm>
#include <memory>
#include <ostream>
#include <string>
#include <utility>

#include "base/check.h"
#include "base/json/json_reader.h"
#include "base/json/json_writer.h"
#include "base/notreached.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/values.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "components/cloud_devices/common/cloud_device_description_consts.h"
#include "components/cloud_devices/common/description_items_inl.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/size.h"

namespace cloud_devices {

namespace printer {

namespace {

constexpr int32_t kMaxPageNumber =;

constexpr char kSectionPrint[] =;
constexpr char kSectionPrinter[] =;

constexpr char kKeyCustomDisplayName[] =;
constexpr char kKeyContentType[] =;
constexpr char kKeyDisplayName[] =;
constexpr char kKeyId[] =;
constexpr char kKeyName[] =;
constexpr char kKeyType[] =;
constexpr char kKeyValue[] =;
constexpr char kKeyValueType[] =;
constexpr char kKeyVendorId[] =;

// extern is required to be used in templates.
extern constexpr char kOptionCollate[] =;
extern constexpr char kOptionColor[] =;
extern constexpr char kOptionContentType[] =;
extern constexpr char kOptionCopies[] =;
extern constexpr char kOptionDpi[] =;
extern constexpr char kOptionDuplex[] =;
extern constexpr char kOptionFitToPage[] =;
extern constexpr char kOptionMargins[] =;
extern constexpr char kOptionMediaSize[] =;
extern constexpr char kOptionMediaType[] =;
extern constexpr char kOptionPageOrientation[] =;
extern constexpr char kOptionPageRange[] =;
extern constexpr char kOptionReverse[] =;
extern constexpr char kOptionPwgRasterConfig[] =;
extern constexpr char kOptionRangeCapability[] =;
extern constexpr char kOptionSelectCapability[] =;
extern constexpr char kOptionTypedValueCapability[] =;
extern constexpr char kOptionVendorCapability[] =;
extern constexpr char kOptionVendorItem[] =;
#if BUILDFLAG(IS_CHROMEOS)
extern constexpr char kOptionPin[] = "pin";
#endif  // BUILDFLAG(IS_CHROMEOS)

constexpr char kMarginBottom[] =;
constexpr char kMarginLeft[] =;
constexpr char kMarginRight[] =;
constexpr char kMarginTop[] =;

constexpr char kDpiHorizontal[] =;
constexpr char kDpiVertical[] =;

constexpr char kMediaWidth[] =;
constexpr char kMediaHeight[] =;
constexpr char kMediaIsContinuous[] =;
constexpr char kMediaImageableAreaLeft[] =;
constexpr char kMediaImageableAreaBottom[] =;
constexpr char kMediaImageableAreaRight[] =;
constexpr char kMediaImageableAreaTop[] =;
constexpr char kMediaMinHeight[] =;
constexpr char kMediaMaxHeight[] =;
constexpr char kMediaHasBorderlessVariant[] =;

constexpr char kPageRangeInterval[] =;
constexpr char kPageRangeEnd[] =;
constexpr char kPageRangeStart[] =;

constexpr char kPwgRasterDocumentTypeSupported[] =;
constexpr char kPwgRasterDocumentSheetBack[] =;
constexpr char kPwgRasterReverseOrderStreaming[] =;
constexpr char kPwgRasterRotateAllPages[] =;

constexpr char kMinValue[] =;
constexpr char kMaxValue[] =;
constexpr char kDefaultValue[] =;

#if BUILDFLAG(IS_CHROMEOS)
constexpr char kPinSupported[] = "supported";
#endif  // BUILDFLAG(IS_CHROMEOS)

constexpr char kTypeRangeVendorCapabilityFloat[] =;
constexpr char kTypeRangeVendorCapabilityInteger[] =;

constexpr char kTypeTypedValueVendorCapabilityBoolean[] =;
constexpr char kTypeTypedValueVendorCapabilityFloat[] =;
constexpr char kTypeTypedValueVendorCapabilityInteger[] =;
constexpr char kTypeTypedValueVendorCapabilityString[] =;

constexpr char kTypeVendorCapabilityRange[] =;
constexpr char kTypeVendorCapabilitySelect[] =;
constexpr char kTypeVendorCapabilityTypedValue[] =;

constexpr char kTypeColorColor[] =;
constexpr char kTypeColorMonochrome[] =;
constexpr char kTypeColorCustomColor[] =;
constexpr char kTypeColorCustomMonochrome[] =;
constexpr char kTypeColorAuto[] =;

constexpr char kTypeDuplexLongEdge[] =;
constexpr char kTypeDuplexNoDuplex[] =;
constexpr char kTypeDuplexShortEdge[] =;

constexpr char kTypeFitToPageFillPage[] =;
constexpr char kTypeFitToPageFitToPage[] =;
constexpr char kTypeFitToPageGrowToPage[] =;
constexpr char kTypeFitToPageNoFitting[] =;
constexpr char kTypeFitToPageShrinkToPage[] =;

constexpr char kTypeMarginsBorderless[] =;
constexpr char kTypeMarginsCustom[] =;
constexpr char kTypeMarginsStandard[] =;
constexpr char kTypeOrientationAuto[] =;

constexpr char kTypeOrientationLandscape[] =;
constexpr char kTypeOrientationPortrait[] =;

constexpr char kTypeDocumentSupportedTypeSRGB8[] =;
constexpr char kTypeDocumentSupportedTypeSGRAY8[] =;

constexpr char kTypeDocumentSheetBackNormal[] =;
constexpr char kTypeDocumentSheetBackRotated[] =;
constexpr char kTypeDocumentSheetBackManualTumble[] =;
constexpr char kTypeDocumentSheetBackFlipped[] =;

constexpr struct RangeVendorCapabilityTypeNames {} kRangeVendorCapabilityTypeNames[] =;

constexpr struct TypedValueVendorCapabilityTypeNames {} kTypedValueVendorCapabilityTypeNames[] =;

constexpr struct VendorCapabilityTypeNames {} kVendorCapabilityTypeNames[] =;

constexpr struct ColorNames {} kColorNames[] =;

constexpr struct DuplexNames {} kDuplexNames[] =;

constexpr struct OrientationNames {} kOrientationNames[] =;

constexpr struct MarginsNames {} kMarginsNames[] =;

constexpr struct FitToPageNames {} kFitToPageNames[] =;

constexpr struct DocumentSheetBackNames {} kDocumentSheetBackNames[] =;

constexpr int32_t kInchToUm =;
constexpr int32_t kMmToUm =;
constexpr int32_t kSizeThresholdUm =;

constexpr size_t kEnumClassPrefixLen =;

// Json name of media type is constructed by removing "MediaSize::" enum class
// prefix from it.
#define MAP_CLOUD_PRINT_MEDIA_SIZE

constexpr struct MediaDefinition {} kMediaDefinitions[] =;
#undef MAP_CLOUD_PRINT_MEDIA_SIZE

const gfx::Size& FindMediaSizeByType(MediaSize size_name) {}

const MediaDefinition* FindMediaBySize(const gfx::Size& size_um) {}

template <class T, class IdType>
std::string TypeToString(const T& names, IdType id) {}

template <class T, class IdType>
bool TypeFromString(const T& names, const std::string& type, IdType* id) {}

}  // namespace

PwgRasterConfig::PwgRasterConfig()
    :{}

PwgRasterConfig::~PwgRasterConfig() {}

RangeVendorCapability::RangeVendorCapability() = default;

RangeVendorCapability::RangeVendorCapability(ValueType value_type,
                                             const std::string& min_value,
                                             const std::string& max_value)
    :{}

RangeVendorCapability::RangeVendorCapability(ValueType value_type,
                                             const std::string& min_value,
                                             const std::string& max_value,
                                             const std::string& default_value)
    :{}

RangeVendorCapability::RangeVendorCapability(RangeVendorCapability&& other) =
    default;

RangeVendorCapability::~RangeVendorCapability() = default;

RangeVendorCapability& RangeVendorCapability::operator=(
    RangeVendorCapability&& other) = default;

bool RangeVendorCapability::operator==(
    const RangeVendorCapability& other) const {}

bool RangeVendorCapability::IsValid() const {}

bool RangeVendorCapability::LoadFrom(const base::Value::Dict& dict) {}

void RangeVendorCapability::SaveTo(base::Value::Dict* dict) const {}

SelectVendorCapabilityOption::SelectVendorCapabilityOption() = default;

SelectVendorCapabilityOption::SelectVendorCapabilityOption(
    const std::string& value,
    const std::string& display_name)
    :{}

SelectVendorCapabilityOption::~SelectVendorCapabilityOption() = default;

bool SelectVendorCapabilityOption::operator==(
    const SelectVendorCapabilityOption& other) const {}

bool SelectVendorCapabilityOption::IsValid() const {}

TypedValueVendorCapability::TypedValueVendorCapability() = default;

TypedValueVendorCapability::TypedValueVendorCapability(ValueType value_type)
    :{}

TypedValueVendorCapability::TypedValueVendorCapability(
    ValueType value_type,
    const std::string& default_value)
    :{}

TypedValueVendorCapability::TypedValueVendorCapability(
    TypedValueVendorCapability&& other) = default;

TypedValueVendorCapability::~TypedValueVendorCapability() = default;

TypedValueVendorCapability& TypedValueVendorCapability::operator=(
    TypedValueVendorCapability&& other) = default;

bool TypedValueVendorCapability::operator==(
    const TypedValueVendorCapability& other) const {}

bool TypedValueVendorCapability::IsValid() const {}

bool TypedValueVendorCapability::LoadFrom(const base::Value::Dict& dict) {}

void TypedValueVendorCapability::SaveTo(base::Value::Dict* dict) const {}

VendorCapability::VendorCapability() :{}

VendorCapability::VendorCapability(const std::string& id,
                                   const std::string& display_name,
                                   RangeVendorCapability range_capability)
    :{}

VendorCapability::VendorCapability(const std::string& id,
                                   const std::string& display_name,
                                   SelectVendorCapability select_capability)
    :{}

VendorCapability::VendorCapability(
    const std::string& id,
    const std::string& display_name,
    TypedValueVendorCapability typed_value_capability)
    :{}

VendorCapability::VendorCapability(VendorCapability&& other)
    :{}

VendorCapability::~VendorCapability() {}

void VendorCapability::InternalCleanup() {}

bool VendorCapability::operator==(const VendorCapability& other) const {}

bool VendorCapability::IsValid() const {}

bool VendorCapability::LoadFrom(const base::Value::Dict& dict) {}

void VendorCapability::SaveTo(base::Value::Dict* dict) const {}

Color::Color() :{}

Color::Color(ColorType type) :{}

bool Color::operator==(const Color& other) const {}

bool Color::IsValid() const {}

VendorItem::VendorItem() = default;

VendorItem::VendorItem(const std::string& id, const std::string& value)
    :{}

bool VendorItem::IsValid() const {}

bool VendorItem::operator==(const VendorItem& other) const {}

Margins::Margins()
    :{}

Margins::Margins(MarginsType type,
                 int32_t top_um,
                 int32_t right_um,
                 int32_t bottom_um,
                 int32_t left_um)
    :{}

bool Margins::operator==(const Margins& other) const {}

Dpi::Dpi() :{}

Dpi::Dpi(int32_t horizontal, int32_t vertical)
    :{}

bool Dpi::IsValid() const {}

bool Dpi::operator==(const Dpi& other) const {}

Media::Media()
    :{}

Media::Media(const Media& other) = default;

Media& Media::operator=(const Media& other) = default;

bool Media::IsValid() const {}

bool Media::operator==(const Media& other) const {}

MediaBuilder::MediaBuilder() = default;

MediaBuilder& MediaBuilder::WithStandardName(MediaSize size_name) {}

MediaBuilder& MediaBuilder::WithCustomName(
    const std::string& custom_display_name,
    const std::string& vendor_id) {}

MediaBuilder& MediaBuilder::WithSizeAndDefaultPrintableArea(
    const gfx::Size& size_um) {}

MediaBuilder& MediaBuilder::WithSizeAndPrintableArea(
    const gfx::Size& size_um,
    const gfx::Rect& printable_area_um) {}

MediaBuilder& MediaBuilder::WithNameMaybeBasedOnSize(
    const std::string& custom_display_name,
    const std::string& vendor_id) {}

MediaBuilder& MediaBuilder::WithSizeAndPrintableAreaBasedOnStandardName() {}

MediaBuilder& MediaBuilder::WithMaxHeight(int max_height_um) {}

MediaBuilder& MediaBuilder::WithBorderlessVariant(bool has_borderless_variant) {}

Media MediaBuilder::Build() const {}

bool MediaBuilder::IsContinuousFeed() const {}

Interval::Interval() :{}

Interval::Interval(int32_t start, int32_t end) :{}

Interval::Interval(int32_t start) :{}

bool Interval::operator==(const Interval& other) const {}

MediaType::MediaType() = default;

MediaType::MediaType(const std::string& vendor_id,
                     const std::string& custom_display_name)
    :{}

bool MediaType::operator==(const MediaType& other) const = default;

bool MediaType::IsValid() const {}

template <const char* kName>
class ItemsTraits {};

class NoValueValidation {};

class ContentTypeTraits : public NoValueValidation,
                          public ItemsTraits<kOptionContentType> {};

class PwgRasterConfigTraits : public NoValueValidation,
                              public ItemsTraits<kOptionPwgRasterConfig> {};

class VendorCapabilityTraits : public ItemsTraits<kOptionVendorCapability> {};

class SelectVendorCapabilityTraits
    : public ItemsTraits<kOptionSelectCapability> {};

class ColorTraits : public ItemsTraits<kOptionColor> {};

class DuplexTraits : public NoValueValidation,
                     public ItemsTraits<kOptionDuplex> {};

class OrientationTraits : public NoValueValidation,
                          public ItemsTraits<kOptionPageOrientation> {};

class CopiesTicketItemTraits : public NoValueValidation,
                               public ItemsTraits<kOptionCopies> {};

class CopiesCapabilityTraits : public NoValueValidation,
                               public ItemsTraits<kOptionCopies> {};

class MarginsTraits : public NoValueValidation,
                      public ItemsTraits<kOptionMargins> {};

class DpiTraits : public ItemsTraits<kOptionDpi> {};

class FitToPageTraits : public NoValueValidation,
                        public ItemsTraits<kOptionFitToPage> {};

class PageRangeTraits : public ItemsTraits<kOptionPageRange> {};

class MediaTraits : public ItemsTraits<kOptionMediaSize> {};

class MediaTypeTraits : public ItemsTraits<kOptionMediaType> {};

class CollateTraits : public NoValueValidation,
                      public ItemsTraits<kOptionCollate> {};

class ReverseTraits : public NoValueValidation,
                      public ItemsTraits<kOptionReverse> {};

class VendorItemTraits : public ItemsTraits<kOptionVendorItem> {};

#if BUILDFLAG(IS_CHROMEOS)
class PinTraits : public NoValueValidation, public ItemsTraits<kOptionPin> {
 public:
  static bool Load(const base::Value::Dict& dict, bool* option) {
    std::optional<bool> supported = dict.FindBool(kPinSupported);
    if (!supported)
      return false;
    *option = supported.value();
    return true;
  }

  static void Save(bool option, base::Value::Dict* dict) {
    dict->Set(kPinSupported, option);
  }
};
#endif  // BUILDFLAG(IS_CHROMEOS)

}  // namespace printer

template class ListCapability<printer::ContentType, printer::ContentTypeTraits>;
template class ValueCapability<printer::PwgRasterConfig,
                               printer::PwgRasterConfigTraits>;
template class ListCapability<printer::VendorCapability,
                              printer::VendorCapabilityTraits>;
template class SelectionCapability<printer::SelectVendorCapabilityOption,
                                   printer::SelectVendorCapabilityTraits>;
template class SelectionCapability<printer::Color, printer::ColorTraits>;
template class SelectionCapability<printer::DuplexType, printer::DuplexTraits>;
template class SelectionCapability<printer::OrientationType,
                                   printer::OrientationTraits>;
template class SelectionCapability<printer::Margins, printer::MarginsTraits>;
template class SelectionCapability<printer::Dpi, printer::DpiTraits>;
template class SelectionCapability<printer::FitToPageType,
                                   printer::FitToPageTraits>;
template class SelectionCapability<printer::Media, printer::MediaTraits>;
template class SelectionCapability<printer::MediaType,
                                   printer::MediaTypeTraits>;
template class ValueCapability<printer::Copies,
                               printer::CopiesCapabilityTraits>;
template class EmptyCapability<printer::PageRangeTraits>;
template class BooleanCapability<printer::CollateTraits>;
template class BooleanCapability<printer::ReverseTraits>;
#if BUILDFLAG(IS_CHROMEOS)
template class ValueCapability<bool, printer::PinTraits>;
#endif  // BUILDFLAG(IS_CHROMEOS)

template class TicketItem<printer::PwgRasterConfig,
                          printer::PwgRasterConfigTraits>;
template class TicketItem<printer::Color, printer::ColorTraits>;
template class TicketItem<printer::DuplexType, printer::DuplexTraits>;
template class TicketItem<printer::OrientationType, printer::OrientationTraits>;
template class TicketItem<printer::Margins, printer::MarginsTraits>;
template class TicketItem<printer::Dpi, printer::DpiTraits>;
template class TicketItem<printer::FitToPageType, printer::FitToPageTraits>;
template class TicketItem<printer::Media, printer::MediaTraits>;
template class TicketItem<int32_t, printer::CopiesTicketItemTraits>;
template class TicketItem<printer::PageRange, printer::PageRangeTraits>;
template class TicketItem<bool, printer::CollateTraits>;
template class TicketItem<bool, printer::ReverseTraits>;
template class ListCapability<printer::VendorItem, printer::VendorItemTraits>;
template class ListTicketItem<printer::VendorItem, printer::VendorItemTraits>;

}  // namespace cloud_devices