Skip to content

Commit

Permalink
[CrOS Printing] Add advanced printing options.
Browse files Browse the repository at this point in the history
This uses UI that already exists for Cloud Print to surface
additional CUPS options.

Bug: 964919

Change-Id: I82a0793318da6f904477318dc0aac75a8d6433c4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1578602
Reviewed-by: Rebekah Potter <rbpotter@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
Reviewed-by: Sean Kau <skau@chromium.org>
Commit-Queue: Vladislav Kuzkokov <vkuzkokov@chromium.org>
Cr-Commit-Position: refs/heads/master@{#696348}
  • Loading branch information
Vladislav Kuzkokov authored and Commit Bot committed Sep 13, 2019
1 parent 8613044 commit d4e4ff3
Show file tree
Hide file tree
Showing 23 changed files with 856 additions and 33 deletions.
3 changes: 3 additions & 0 deletions chrome/browser/resources/print_preview/data/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -1252,6 +1252,9 @@ Polymer({
if (this.getSettingValue('pin')) {
ticket.pinValue = this.getSettingValue('pinValue');
}
if (destination.origin == print_preview.DestinationOrigin.CROS) {
ticket.advancedSettings = this.getSettingValue('vendorItems');
}
// </if>

return JSON.stringify(ticket);
Expand Down
15 changes: 13 additions & 2 deletions chrome/test/data/webui/print_preview/model_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,10 @@ cr.define('model_test', function() {
* print ticket.
*/
test(assert(TestNames.GetPrintTicket), function() {
const origin = cr.isChromeOS ? print_preview.DestinationOrigin.CROS :
print_preview.DestinationOrigin.LOCAL;
const testDestination = new print_preview.Destination(
'FooDevice', print_preview.DestinationType.LOCAL,
print_preview.DestinationOrigin.LOCAL, 'FooName',
'FooDevice', print_preview.DestinationType.LOCAL, origin, 'FooName',
print_preview.DestinationConnectionStatus.ONLINE);
testDestination.capabilities =
print_preview_test_utils.getCddTemplateWithAdvancedSettings(2)
Expand Down Expand Up @@ -301,6 +302,12 @@ cr.define('model_test', function() {
pageHeight: 792,
showSystemDialog: false,
};
if (cr.isChromeOS) {
expectedDefaultTicketObject.advancedSettings = {
printArea: 4,
paperType: 0,
};
}
expectEquals(JSON.stringify(expectedDefaultTicketObject), defaultTicket);

// Toggle all the values and create a new print ticket.
Expand Down Expand Up @@ -344,6 +351,10 @@ cr.define('model_test', function() {
};
if (cr.isChromeOS) {
expectedNewTicketObject.pinValue = '0000';
expectedNewTicketObject.advancedSettings = {
printArea: 6,
paperType: 1,
};
}

expectEquals(JSON.stringify(expectedNewTicketObject), newTicket);
Expand Down
7 changes: 7 additions & 0 deletions components/printing/browser/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ static_library("browser") {
]
}

if (is_chromeos) {
sources += [
"ipp_l10n.cc",
"ipp_l10n.h",
]
}

if (enable_print_media_l10n) {
sources += [
"print_media_l10n.cc",
Expand Down
86 changes: 86 additions & 0 deletions components/printing/browser/ipp_l10n.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "components/printing/browser/ipp_l10n.h"

#include "base/no_destructor.h"
#include "components/strings/grit/components_strings.h"

// TODO(crbug.com/964919) generate from csv.
const std::map<base::StringPiece, int>& CapabilityLocalizationMap() {
static const base::NoDestructor<std::map<base::StringPiece, int>> l10n_map(
{{"finishings/4", IDS_PRINT_FINISHINGS_STAPLE},
{"finishings/5", IDS_PRINT_FINISHINGS_PUNCH},
{"finishings/6", IDS_PRINT_FINISHINGS_COVER},
{"finishings/7", IDS_PRINT_FINISHINGS_BIND},
{"finishings/8", IDS_PRINT_FINISHINGS_SADDLE_STITCH},
{"finishings/9", IDS_PRINT_FINISHINGS_EDGE_STITCH},
{"finishings/10", IDS_PRINT_FINISHINGS_FOLD},
{"finishings/11", IDS_PRINT_FINISHINGS_TRIM},
{"finishings/12", IDS_PRINT_FINISHINGS_BALE},
{"finishings/13", IDS_PRINT_FINISHINGS_BOOKLET_MAKER},
{"finishings/14", IDS_PRINT_FINISHINGS_JOG_OFFSET},
{"finishings/15", IDS_PRINT_FINISHINGS_COAT},
{"finishings/16", IDS_PRINT_FINISHINGS_LAMINATE},
{"finishings/20", IDS_PRINT_FINISHINGS_STAPLE_TOP_LEFT},
{"finishings/21", IDS_PRINT_FINISHINGS_STAPLE_BOTTOM_LEFT},
{"finishings/22", IDS_PRINT_FINISHINGS_STAPLE_TOP_RIGHT},
{"finishings/23", IDS_PRINT_FINISHINGS_STAPLE_BOTTOM_RIGHT},
{"finishings/24", IDS_PRINT_FINISHINGS_EDGE_STITCH_LEFT},
{"finishings/25", IDS_PRINT_FINISHINGS_EDGE_STITCH_TOP},
{"finishings/26", IDS_PRINT_FINISHINGS_EDGE_STITCH_RIGHT},
{"finishings/27", IDS_PRINT_FINISHINGS_EDGE_STITCH_BOTTOM},
{"finishings/28", IDS_PRINT_FINISHINGS_STAPLE_DUAL_LEFT},
{"finishings/29", IDS_PRINT_FINISHINGS_STAPLE_DUAL_TOP},
{"finishings/30", IDS_PRINT_FINISHINGS_STAPLE_DUAL_RIGHT},
{"finishings/31", IDS_PRINT_FINISHINGS_STAPLE_DUAL_BOTTOM},
{"finishings/32", IDS_PRINT_FINISHINGS_STAPLE_TRIPLE_LEFT},
{"finishings/33", IDS_PRINT_FINISHINGS_STAPLE_TRIPLE_TOP},
{"finishings/34", IDS_PRINT_FINISHINGS_STAPLE_TRIPLE_RIGHT},
{"finishings/35", IDS_PRINT_FINISHINGS_STAPLE_TRIPLE_BOTTOM},
{"finishings/50", IDS_PRINT_FINISHINGS_BIND_LEFT},
{"finishings/51", IDS_PRINT_FINISHINGS_BIND_TOP},
{"finishings/52", IDS_PRINT_FINISHINGS_BIND_RIGHT},
{"finishings/53", IDS_PRINT_FINISHINGS_BIND_BOTTOM},
{"finishings/60", IDS_PRINT_FINISHINGS_TRIM_AFTER_PAGES},
{"finishings/61", IDS_PRINT_FINISHINGS_TRIM_AFTER_DOCUMENTS},
{"finishings/62", IDS_PRINT_FINISHINGS_TRIM_AFTER_COPIES},
{"finishings/63", IDS_PRINT_FINISHINGS_TRIM_AFTER_JOB},
{"finishings/70", IDS_PRINT_FINISHINGS_PUNCH_TOP_LEFT},
{"finishings/71", IDS_PRINT_FINISHINGS_PUNCH_BOTTOM_LEFT},
{"finishings/72", IDS_PRINT_FINISHINGS_PUNCH_TOP_RIGHT},
{"finishings/73", IDS_PRINT_FINISHINGS_PUNCH_BOTTOM_RIGHT},
{"finishings/74", IDS_PRINT_FINISHINGS_PUNCH_DUAL_LEFT},
{"finishings/75", IDS_PRINT_FINISHINGS_PUNCH_DUAL_TOP},
{"finishings/76", IDS_PRINT_FINISHINGS_PUNCH_DUAL_RIGHT},
{"finishings/77", IDS_PRINT_FINISHINGS_PUNCH_DUAL_BOTTOM},
{"finishings/78", IDS_PRINT_FINISHINGS_PUNCH_TRIPLE_LEFT},
{"finishings/79", IDS_PRINT_FINISHINGS_PUNCH_TRIPLE_TOP},
{"finishings/80", IDS_PRINT_FINISHINGS_PUNCH_TRIPLE_RIGHT},
{"finishings/81", IDS_PRINT_FINISHINGS_PUNCH_TRIPLE_BOTTOM},
{"finishings/82", IDS_PRINT_FINISHINGS_PUNCH_QUAD_LEFT},
{"finishings/83", IDS_PRINT_FINISHINGS_PUNCH_QUAD_TOP},
{"finishings/84", IDS_PRINT_FINISHINGS_PUNCH_QUAD_RIGHT},
{"finishings/85", IDS_PRINT_FINISHINGS_PUNCH_QUAD_BOTTOM},
{"finishings/86", IDS_PRINT_FINISHINGS_PUNCH_MULTIPLE_LEFT},
{"finishings/87", IDS_PRINT_FINISHINGS_PUNCH_MULTIPLE_TOP},
{"finishings/88", IDS_PRINT_FINISHINGS_PUNCH_MULTIPLE_RIGHT},
{"finishings/89", IDS_PRINT_FINISHINGS_PUNCH_MULTIPLE_BOTTOM},
{"finishings/90", IDS_PRINT_FINISHINGS_FOLD_ACCORDION},
{"finishings/91", IDS_PRINT_FINISHINGS_FOLD_DOUBLE_GATE},
{"finishings/92", IDS_PRINT_FINISHINGS_FOLD_GATE},
{"finishings/93", IDS_PRINT_FINISHINGS_FOLD_HALF},
{"finishings/94", IDS_PRINT_FINISHINGS_FOLD_HALF_Z},
{"finishings/95", IDS_PRINT_FINISHINGS_FOLD_LEFT_GATE},
{"finishings/96", IDS_PRINT_FINISHINGS_FOLD_LETTER},
{"finishings/97", IDS_PRINT_FINISHINGS_FOLD_PARALLEL},
{"finishings/98", IDS_PRINT_FINISHINGS_FOLD_POSTER},
{"finishings/99", IDS_PRINT_FINISHINGS_FOLD_RIGHT_GATE},
{"finishings/100", IDS_PRINT_FINISHINGS_FOLD_Z},
{"finishings/101", IDS_PRINT_FINISHINGS_FOLD_ENGINEERING_Z},
{"print-quality/3", IDS_PRINT_PRINT_QUALITY_DRAFT},
{"print-quality/4", IDS_PRINT_PRINT_QUALITY_NORMAL},
{"print-quality/5", IDS_PRINT_PRINT_QUALITY_HIGH}});
return *l10n_map;
}
14 changes: 14 additions & 0 deletions components/printing/browser/ipp_l10n.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef COMPONENTS_PRINTING_BROWSER_IPP_L10N_H_
#define COMPONENTS_PRINTING_BROWSER_IPP_L10N_H_

#include <map>

#include "base/strings/string_piece.h"

const std::map<base::StringPiece, int>& CapabilityLocalizationMap();

#endif // COMPONENTS_PRINTING_BROWSER_IPP_L10N_H_
29 changes: 29 additions & 0 deletions components/printing/browser/printer_capabilities.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@
#include "ui/base/l10n/l10n_util.h"
#endif

#if defined(OS_CHROMEOS)
#include "base/feature_list.h"
#include "components/printing/browser/ipp_l10n.h"
#include "components/strings/grit/components_strings.h"
#include "printing/printing_features_chromeos.h"
#include "ui/base/l10n/l10n_util.h"
#endif // defined(OS_CHROMEOS)

#if BUILDFLAG(PRINT_MEDIA_L10N_ENABLED)
#include "components/printing/browser/print_media_l10n.h"
#endif
Expand All @@ -53,6 +61,24 @@ void PopulateAllPaperDisplayNames(PrinterSemanticCapsAndDefaults* info) {
}
#endif // BUILDFLAG(PRINT_MEDIA_L10N_ENABLED)

#if defined(OS_CHROMEOS)
void PopulateAdvancedCapsLocalization(
std::vector<AdvancedCapability>* advanced_capabilities) {
auto& l10n_map = CapabilityLocalizationMap();
for (AdvancedCapability& capability : *advanced_capabilities) {
auto it = l10n_map.find(capability.name);
if (it != l10n_map.end())
capability.display_name = l10n_util::GetStringUTF8(it->second);

for (AdvancedCapabilityValue& value : capability.values) {
auto it = l10n_map.find(capability.name + "/" + value.name);
if (it != l10n_map.end())
value.display_name = l10n_util::GetStringUTF8(it->second);
}
}
}
#endif // defined(OS_CHROMEOS)

// Returns a dictionary representing printer capabilities as CDD. Returns
// an empty dictionary if a dictionary could not be generated.
base::Value GetPrinterCapabilitiesOnBlockingPoolThread(
Expand Down Expand Up @@ -85,6 +111,9 @@ base::Value GetPrinterCapabilitiesOnBlockingPoolThread(
#if defined(OS_CHROMEOS)
if (!has_secure_protocol)
info.pin_supported = false;

if (base::FeatureList::IsEnabled(printing::kAdvancedPpdAttributes))
PopulateAdvancedCapsLocalization(&info.advanced_capabilities);
#endif // defined(OS_CHROMEOS)

return cloud_print::PrinterSemanticCapsAndDefaultsToCdd(info);
Expand Down
56 changes: 56 additions & 0 deletions components/printing/common/cloud_print_cdd_conversion.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
#include "components/cloud_devices/common/printer_description.h"
#include "printing/backend/print_backend.h"

#if defined(OS_CHROMEOS)
#include "base/feature_list.h"
#include "printing/printing_features_chromeos.h"
#endif // defined(OS_CHROMEOS)

namespace cloud_print {

namespace {
Expand All @@ -32,6 +37,29 @@ cloud_devices::printer::DuplexType ToCloudDuplexType(
return cloud_devices::printer::DuplexType::NO_DUPLEX;
}

#if defined(OS_CHROMEOS)
cloud_devices::printer::TypedValueVendorCapability::ValueType ToCloudValueType(
base::Value::Type type) {
switch (type) {
case base::Value::Type::BOOLEAN:
return cloud_devices::printer::TypedValueVendorCapability::ValueType::
BOOLEAN;
case base::Value::Type::DOUBLE:
return cloud_devices::printer::TypedValueVendorCapability::ValueType::
FLOAT;
case base::Value::Type::INTEGER:
return cloud_devices::printer::TypedValueVendorCapability::ValueType::
INTEGER;
case base::Value::Type::STRING:
return cloud_devices::printer::TypedValueVendorCapability::ValueType::
STRING;
default:
NOTREACHED();
}
return cloud_devices::printer::TypedValueVendorCapability::ValueType::STRING;
}
#endif // defined(OS_CHROMEOS)

} // namespace

base::Value PrinterSemanticCapsAndDefaultsToCdd(
Expand Down Expand Up @@ -145,6 +173,34 @@ base::Value PrinterSemanticCapsAndDefaultsToCdd(
PinCapability pin;
pin.set_value(semantic_info.pin_supported);
pin.SaveTo(&description);

if (base::FeatureList::IsEnabled(printing::kAdvancedPpdAttributes) &&
!semantic_info.advanced_capabilities.empty()) {
VendorCapabilities vendor_capabilities;
for (const auto& capability : semantic_info.advanced_capabilities) {
std::string capability_name = capability.display_name.empty()
? capability.name
: capability.display_name;
if (!capability.values.empty()) {
SelectVendorCapability select_capability;
for (const auto& value : capability.values) {
std::string localized_value =
value.display_name.empty() ? value.name : value.display_name;
select_capability.AddDefaultOption(
SelectVendorCapabilityOption(value.name, localized_value),
value.is_default);
}
vendor_capabilities.AddOption(VendorCapability(
capability.name, capability_name, std::move(select_capability)));
} else {
vendor_capabilities.AddOption(
VendorCapability(capability.name, capability_name,
TypedValueVendorCapability(
ToCloudValueType(base::Value::Type::STRING))));
}
}
vendor_capabilities.SaveTo(&description);
}
#endif // defined(OS_CHROMEOS)

return std::move(description).ToValue();
Expand Down
Loading

0 comments on commit d4e4ff3

Please sign in to comment.