Commit 4376cbe6 authored by Vladislav Kuzkokov's avatar Vladislav Kuzkokov Committed by Commit Bot

Default printing color mode and duplex mode policies

Bug: 891174
Change-Id: I6962a3a9f07249dfe8e40f30d331606b61bc27d8
Reviewed-on: https://chromium-review.googlesource.com/c/1273144Reviewed-by: default avatarRebekah Potter <rbpotter@chromium.org>
Commit-Queue: Vladislav Kuzkokov <vkuzkokov@chromium.org>
Cr-Commit-Position: refs/heads/master@{#604224}
parent 35ade2a6
......@@ -181,6 +181,8 @@ print_preview.DuplexModeRestriction = {
* @typedef {{
* allowedColorModes: ?print_preview.ColorMode,
* allowedDuplexModes: ?print_preview.DuplexModeRestriction,
* defaultColorMode: ?print_preview.ColorMode,
* defaultDuplexMode: ?print_preview.DuplexModeRestriction,
* }}
*/
print_preview.Policies;
......@@ -796,23 +798,21 @@ cr.define('print_preview', function() {
/**
* @return {?print_preview.ColorMode} Color mode set by policy.
* @private
*/
colorPolicy_() {
get colorPolicy() {
return this.policies && this.policies.allowedColorModes ?
this.policies.allowedColorModes :
null;
}
/**
* @return {print_preview.DuplexModeRestriction} Duplex modes allowed by
* @return {?print_preview.DuplexModeRestriction} Duplex modes allowed by
* policy.
* @private
*/
duplexPolicy_() {
get duplexPolicy() {
return this.policies && this.policies.allowedDuplexModes ?
this.policies.allowedDuplexModes :
print_preview.DuplexModeRestriction.NONE;
null;
}
/**
......@@ -834,33 +834,20 @@ cr.define('print_preview', function() {
return hasColor && hasMonochrome;
}
/** @return {boolean} Whether the printer color mode is set by policy. */
get isColorManaged() {
return !!this.colorPolicy_();
}
/** @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 {?print_preview.ColorMode} Value of default color setting given
* by policy.
*/
get defaultColorPolicy() {
return this.policies && this.policies.defaultColorMode;
}
/** @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;
}
/**
* @return {?print_preview.DuplexModeRestriction} Value of default duplex
* setting given by policy.
*/
get defaultDuplexPolicy() {
return this.policies && this.policies.defaultDuplexMode;
}
/**
......
......@@ -411,6 +411,9 @@ Polymer({
if (!this.$.model.initialized())
this.$.model.applyStickySettings();
if (this.destination_)
this.$.model.applyDestinationSpecificPolicies();
if (this.state == print_preview_new.State.NOT_READY ||
this.state == print_preview_new.State.INVALID_PRINTER) {
this.$.state.transitTo(print_preview_new.State.READY);
......
......@@ -375,17 +375,6 @@ Polymer({
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 &&
......@@ -719,6 +708,33 @@ Polymer({
this.stickySettingsChanged_();
},
/**
* Restricts settings and applies defaults as defined by policy applicable to
* current destination.
*/
applyDestinationSpecificPolicies: function() {
const colorPolicy = this.destination.colorPolicy;
const colorValue =
colorPolicy ? colorPolicy : this.destination.defaultColorPolicy;
if (colorValue) {
// |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', colorValue == print_preview.ColorMode.COLOR);
}
this.set('settings.color.setByPolicy', !!colorPolicy);
const duplexPolicy = this.destination.duplexPolicy;
const duplexValue =
duplexPolicy ? duplexPolicy : this.destination.defaultDuplexPolicy;
if (duplexValue) {
this.set(
'settings.duplex.value',
duplexValue != print_preview.DuplexModeRestriction.SIMPLEX);
}
this.set('settings.duplex.setByPolicy', !!duplexPolicy);
},
/** @return {boolean} Whether the model has been initialized. */
initialized: function() {
return this.initialized_;
......
......@@ -190,6 +190,12 @@ void LocalPrinterHandlerChromeos::HandlePrinterSetup(
policies.SetInteger(
printing::kAllowedDuplexModes,
profile_->GetPrefs()->GetInteger(prefs::kPrintingAllowedDuplexModes));
policies.SetInteger(
printing::kDefaultColorMode,
profile_->GetPrefs()->GetInteger(prefs::kPrintingColorDefault));
policies.SetInteger(
printing::kDefaultDuplexMode,
profile_->GetPrefs()->GetInteger(prefs::kPrintingDuplexDefault));
// fetch settings on the blocking pool and invoke callback.
FetchCapabilities(std::move(printer), std::move(policies), std::move(cb));
return;
......
......@@ -1157,6 +1157,7 @@ cr.define('settings_sections_tests', function() {
// observers only check for |capabilities|, so the order is important.
page.set('destination_.policies', policies);
page.set('destination_.capabilities', capabilities);
page.$$('print-preview-model').applyDestinationSpecificPolicies();
assertEquals(
subtestParams.expectedValue, page.getSettingValue('color'));
assertEquals(subtestParams.expectedHidden, colorElement.hidden);
......
......@@ -8,6 +8,8 @@ namespace printing {
const char kAllowedColorModes[] = "allowedColorModes";
const char kAllowedDuplexModes[] = "allowedDuplexModes";
const char kDefaultColorMode[] = "defaultColorMode";
const char kDefaultDuplexMode[] = "defaultDuplexMode";
const char kPageWidthUm[] = "WidthUm";
const char kPageHeightUm[] = "HeightUm";
......
......@@ -50,6 +50,8 @@ struct PRINTING_EXPORT PrintingRestrictions {
// chrome/browser/resources/print_preview/native_layer.js
PRINTING_EXPORT extern const char kAllowedColorModes[];
PRINTING_EXPORT extern const char kAllowedDuplexModes[];
PRINTING_EXPORT extern const char kDefaultColorMode[];
PRINTING_EXPORT extern const char kDefaultDuplexMode[];
// 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