Commit 1afb0f62 authored by Vladislav Kuzkokov's avatar Vladislav Kuzkokov Committed by Commit Bot

Printing duplex mode restriction policy

This adds new policy that allows admin to restrict duplex mode
to either one-sided only or two-sided only.

Bug: 853877, 885265
Change-Id: I3698ca4d248415693590b895d0f3c28ad95755c2
Reviewed-on: https://chromium-review.googlesource.com/1224310
Commit-Queue: Vladislav Kuzkokov <vkuzkokov@chromium.org>
Reviewed-by: default avatarRebekah Potter <rbpotter@chromium.org>
Cr-Commit-Position: refs/heads/master@{#595073}
parent a20c193c
......@@ -162,10 +162,25 @@ print_preview.ColorMode = {
COLOR: 2
};
/**
* Enumeration of duplex modes used by Chromium.
* This has to coincide with |printing::DuplexModeRestriction| as defined in
* printing/backend/printing_restrictions.h
* @enum {number}
*/
print_preview.DuplexModeRestriction = {
NONE: 0x0,
SIMPLEX: 0x1,
LONG_EDGE: 0x2,
SHORT_EDGE: 0x4,
DUPLEX: 0x6
};
/**
* Policies affecting a destination.
* @typedef {{
* allowedColorModes: ?number,
* allowedColorModes: ?print_preview.ColorMode,
* allowedDuplexModes: ?print_preview.DuplexModeRestriction,
* }}
*/
print_preview.Policies;
......@@ -780,8 +795,7 @@ cr.define('print_preview', function() {
}
/**
* @return {?number} Color mode set by policy. Valid values are |null|,
|print_preview.ColorMode.COLOR| and |print_preview.ColorMode.GRAY|.
* @return {?print_preview.ColorMode} Color mode set by policy.
* @private
*/
colorPolicy_() {
......@@ -790,6 +804,17 @@ cr.define('print_preview', function() {
null;
}
/**
* @return {print_preview.DuplexModeRestriction} Duplex modes allowed by
* policy.
* @private
*/
duplexPolicy_() {
return this.policies && this.policies.allowedDuplexModes ?
this.policies.allowedDuplexModes :
print_preview.DuplexModeRestriction.NONE;
}
/**
* @return {boolean} Whether the printer supports both black and white and
* color printing.
......@@ -809,22 +834,35 @@ cr.define('print_preview', function() {
return hasColor && hasMonochrome;
}
/**
* @return {boolean} Whether the printer color mode is set by policy.
*/
/** @return {boolean} Whether the printer color mode is set by policy. */
get isColorManaged() {
return !!this.colorPolicy_();
}
/**
* @return {?boolean} Value for color setting set by policy.
*/
/** @return {?boolean} Value of color setting given by policy. */
get colorPolicyValue() {
return this.colorPolicy_() ?
this.colorPolicy_() == print_preview.ColorMode.COLOR :
null;
}
/** @return {boolean} Whether the printer duplex mode is set by policy. */
get isDuplexManaged() {
return !!this.duplexPolicy_();
}
/** @return {?boolean} Value for duplex setting given by policy. */
get duplexPolicyValue() {
switch (this.duplexPolicy_()) {
case print_preview.DuplexModeRestriction.NONE:
return null;
case print_preview.DuplexModeRestriction.SIMPLEX:
return false;
default:
return true;
}
}
/**
* @param {boolean} isColor Whether to use a color printing mode.
* @return {Object} Selected color option.
......
......@@ -364,14 +364,18 @@ Polymer({
this.set('settings.collate.available', !!caps && !!(caps.collate));
this.set('settings.layout.available', this.isLayoutAvailable_(caps));
this.set('settings.color.available', this.destination.hasColorCapability);
if (this.destination.isColorManaged) {
// |this.setSetting| does nothing if policy is present.
// We want to set the value nevertheless so we call |this.set| directly.
this.set('settings.color.value', this.destination.colorPolicyValue);
}
this.set('settings.color.setByPolicy', this.destination.isColorManaged);
if (this.destination.isDuplexManaged)
this.set('settings.duplex.value', this.destination.duplexPolicyValue);
this.set('settings.duplex.setByPolicy', this.destination.isDuplexManaged);
this.set(
'settings.dpi.available',
!!caps && !!caps.dpi && !!caps.dpi.option &&
......
......@@ -187,6 +187,9 @@ void LocalPrinterHandlerChromeos::HandlePrinterSetup(
policies.SetInteger(
printing::kAllowedColorModes,
profile_->GetPrefs()->GetInteger(prefs::kPrintingAllowedColorModes));
policies.SetInteger(
printing::kAllowedDuplexModes,
profile_->GetPrefs()->GetInteger(prefs::kPrintingAllowedDuplexModes));
// fetch settings on the blocking pool and invoke callback.
FetchCapabilities(std::move(printer), std::move(policies), std::move(cb));
return;
......
......@@ -7,6 +7,7 @@
namespace printing {
const char kAllowedColorModes[] = "allowedColorModes";
const char kAllowedDuplexModes[] = "allowedDuplexModes";
const char kPageWidthUm[] = "WidthUm";
const char kPageHeightUm[] = "HeightUm";
......@@ -52,6 +53,9 @@ base::Optional<DuplexModeRestriction> GetAllowedDuplexModesForName(
if (mode_name == "any")
return DuplexModeRestriction::kNone;
if (mode_name == "simplex")
return DuplexModeRestriction::kSimplex;
if (mode_name == "duplex")
return DuplexModeRestriction::kDuplex;
......
......@@ -49,6 +49,7 @@ struct PRINTING_EXPORT PrintingRestrictions {
// Must coincide with the name of field in |print_preview.Policies| in
// chrome/browser/resources/print_preview/native_layer.js
PRINTING_EXPORT extern const char kAllowedColorModes[];
PRINTING_EXPORT extern const char kAllowedDuplexModes[];
// Dictionary keys to be used with |kPrintingAllowedPageSizes| and
// |kPrintingSizeDefault| policies.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment