summaryrefslogtreecommitdiff
path: root/chromium/chrome/browser/resources/print_preview
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/chrome/browser/resources/print_preview')
-rw-r--r--chromium/chrome/browser/resources/print_preview/data/app_state.js202
-rw-r--r--chromium/chrome/browser/resources/print_preview/data/capabilities_holder.js30
-rw-r--r--chromium/chrome/browser/resources/print_preview/data/coordinate2d.js55
-rw-r--r--chromium/chrome/browser/resources/print_preview/data/destination.js476
-rw-r--r--chromium/chrome/browser/resources/print_preview/data/destination_match.js85
-rw-r--r--chromium/chrome/browser/resources/print_preview/data/destination_store.js1400
-rw-r--r--chromium/chrome/browser/resources/print_preview/data/invitation.js91
-rw-r--r--chromium/chrome/browser/resources/print_preview/data/local_parsers.js50
-rw-r--r--chromium/chrome/browser/resources/print_preview/data/margins.js93
-rw-r--r--chromium/chrome/browser/resources/print_preview/data/measurement_system.js17
-rw-r--r--chromium/chrome/browser/resources/print_preview/data/measurement_system_unittest.gtestjs68
-rw-r--r--chromium/chrome/browser/resources/print_preview/data/page_number_set.js45
-rw-r--r--chromium/chrome/browser/resources/print_preview/data/print_ticket_store.js527
-rw-r--r--chromium/chrome/browser/resources/print_preview/data/printable_area.js49
-rw-r--r--chromium/chrome/browser/resources/print_preview/data/size.js45
-rw-r--r--chromium/chrome/browser/resources/print_preview/data/ticket_items/collate.js52
-rw-r--r--chromium/chrome/browser/resources/print_preview/data/ticket_items/color.js83
-rw-r--r--chromium/chrome/browser/resources/print_preview/data/ticket_items/copies.js51
-rw-r--r--chromium/chrome/browser/resources/print_preview/data/ticket_items/css_background.js48
-rw-r--r--chromium/chrome/browser/resources/print_preview/data/ticket_items/custom_margins.js117
-rw-r--r--chromium/chrome/browser/resources/print_preview/data/ticket_items/dpi.js49
-rw-r--r--chromium/chrome/browser/resources/print_preview/data/ticket_items/duplex.js52
-rw-r--r--chromium/chrome/browser/resources/print_preview/data/ticket_items/fit_to_page.js51
-rw-r--r--chromium/chrome/browser/resources/print_preview/data/ticket_items/header_footer.js129
-rw-r--r--chromium/chrome/browser/resources/print_preview/data/ticket_items/landscape.js96
-rw-r--r--chromium/chrome/browser/resources/print_preview/data/ticket_items/margins_type.js66
-rw-r--r--chromium/chrome/browser/resources/print_preview/data/ticket_items/media_size.js87
-rw-r--r--chromium/chrome/browser/resources/print_preview/data/ticket_items/page_range.js96
-rw-r--r--chromium/chrome/browser/resources/print_preview/data/ticket_items/rasterize.js44
-rw-r--r--chromium/chrome/browser/resources/print_preview/data/ticket_items/scaling.js63
-rw-r--r--chromium/chrome/browser/resources/print_preview/data/ticket_items/selection_only.js44
-rw-r--r--chromium/chrome/browser/resources/print_preview/data/ticket_items/ticket_item.js214
-rw-r--r--chromium/chrome/browser/resources/print_preview/data/ticket_items/vendor_items.js80
-rw-r--r--chromium/chrome/browser/resources/print_preview/images/1x/printer.png (renamed from chromium/chrome/browser/resources/print_preview/images/printer.png)bin363 -> 363 bytes
-rw-r--r--chromium/chrome/browser/resources/print_preview/images/1x/printer_shared.png (renamed from chromium/chrome/browser/resources/print_preview/images/printer_shared.png)bin685 -> 685 bytes
-rw-r--r--chromium/chrome/browser/resources/print_preview/images/2x/printer.pngbin0 -> 1935 bytes
-rw-r--r--chromium/chrome/browser/resources/print_preview/images/2x/printer_shared.pngbin0 -> 2603 bytes
-rw-r--r--chromium/chrome/browser/resources/print_preview/native_layer.js306
-rw-r--r--chromium/chrome/browser/resources/print_preview/previewarea/preview_area.js4
-rw-r--r--chromium/chrome/browser/resources/print_preview/print_header.js25
-rw-r--r--chromium/chrome/browser/resources/print_preview/print_preview.css19
-rw-r--r--chromium/chrome/browser/resources/print_preview/print_preview.html2
-rw-r--r--chromium/chrome/browser/resources/print_preview/print_preview.js65
-rw-r--r--chromium/chrome/browser/resources/print_preview/print_preview_utils.js2
-rw-r--r--chromium/chrome/browser/resources/print_preview/search/destination_list_item.js1
-rw-r--r--chromium/chrome/browser/resources/print_preview/settings/copies_settings.css12
-rw-r--r--chromium/chrome/browser/resources/print_preview/settings/destination_settings.js1
-rw-r--r--chromium/chrome/browser/resources/print_preview/settings/page_settings.js28
-rw-r--r--chromium/chrome/browser/resources/print_preview/settings/scaling_settings.css7
-rw-r--r--chromium/chrome/browser/resources/print_preview/settings/settings_box.css11
-rw-r--r--chromium/chrome/browser/resources/print_preview/settings/settings_section_select.js12
51 files changed, 2318 insertions, 2832 deletions
diff --git a/chromium/chrome/browser/resources/print_preview/data/app_state.js b/chromium/chrome/browser/resources/print_preview/data/app_state.js
index 06541447351..6e14236ee9c 100644
--- a/chromium/chrome/browser/resources/print_preview/data/app_state.js
+++ b/chromium/chrome/browser/resources/print_preview/data/app_state.js
@@ -26,149 +26,113 @@ print_preview.AppStateField = {
VENDOR_OPTIONS: 'vendorOptions'
};
+
/**
- * Object used to represent a recent destination in the app state.
- * @constructor
- * @struct
+ * @typedef {{id: string,
+ * origin: print_preview.DestinationOrigin,
+ * account: string,
+ * capabilities: ?print_preview.Cdd,
+ * displayName: string,
+ * extensionId: string,
+ * extensionName: string}}
*/
-function RecentDestination(destination) {
- /**
- * ID of the RecentDestination.
- * @type {string}
- */
- this.id = destination.id;
-
- /**
- * Origin of the RecentDestination.
- * @type {string}
- */
- this.origin = destination.origin;
-
- /**
- * Account the RecentDestination is registered for.
- * @type {string}
- */
- this.account = destination.account || '';
-
- /**
- * CDD of the RecentDestination.
- * @type {print_preview.Cdd}
- */
- this.capabilities = destination.capabilities;
-
- /**
- * Name of the RecentDestination.
- * @type {string}
- */
- this.name = destination.name || '';
-
- /**
- * Extension ID associated with the RecentDestination.
- * @type {string}
- */
- this.extensionId = destination.extension_id || '';
+print_preview.AppStateRecentDestination;
- /**
- * Extension name associated with the RecentDestination.
- * @type {string}
- */
- this.extensionName = destination.extension_name || '';
+/**
+ * Creates a |AppStateRecentDestination| to represent |destination| in the app
+ * state.
+ * @param {!print_preview.Destination} destination The destination to store.
+ * @return {!print_preview.AppStateRecentDestination}
+ */
+function makeRecentDestination(destination) {
+ return {
+ id: destination.id_,
+ origin: destination.origin_,
+ account: destination.account_ || '',
+ capabilities: destination.capabilities,
+ displayName: destination.displayName_ || '',
+ extensionId: destination.extensionId_ || '',
+ extensionName: destination.extensionName_ || '',
+ };
}
cr.define('print_preview', function() {
'use strict';
-
- /**
- * Object used to get and persist the print preview application state.
- * @constructor
- */
- function AppState() {
- /**
- * Internal representation of application state.
- * @private {Object}
- */
- this.state_ = {};
- this.state_[print_preview.AppStateField.VERSION] = AppState.VERSION_;
- this.state_[print_preview.AppStateField.RECENT_DESTINATIONS] = [];
-
+ class AppState {
/**
- * Whether the app state has been initialized. The app state will ignore all
- * writes until it has been initialized.
- * @private {boolean}
+ * Object used to get and persist the print preview application state.
*/
- this.isInitialized_ = false;
+ constructor() {
+ /**
+ * Internal representation of application state.
+ * @private {!Object}
+ */
+ this.state_ = {};
+ this.state_[print_preview.AppStateField.VERSION] = AppState.VERSION_;
+ this.state_[print_preview.AppStateField.RECENT_DESTINATIONS] = [];
- /**
- * Native Layer object to use for sending app state to C++ handler.
- * @private {!print_preview.NativeLayer}
- */
- this.nativeLayer_ = print_preview.NativeLayer.getInstance();
- }
-
- /**
- * Number of recent print destinations to store across browser sessions.
- * @const {number}
- */
- AppState.NUM_DESTINATIONS_ = 3;
+ /**
+ * Whether the app state has been initialized. The app state will ignore
+ * all writes until it has been initialized.
+ * @private {boolean}
+ */
+ this.isInitialized_ = false;
- /**
- * Current version of the app state. This value helps to understand how to
- * parse earlier versions of the app state.
- * @type {number}
- * @const
- * @private
- */
- AppState.VERSION_ = 2;
+ /**
+ * Native Layer object to use for sending app state to C++ handler.
+ * @private {!print_preview.NativeLayer}
+ */
+ this.nativeLayer_ = print_preview.NativeLayer.getInstance();
+ }
- AppState.prototype = {
/**
- * @return {?RecentDestination} The most recent destination,
- * which is currently the selected destination.
+ * @return {?print_preview.AppStateRecentDestination} The most recent
+ * destination, which is currently the selected destination.
*/
get selectedDestination() {
return (this.state_[print_preview.AppStateField.RECENT_DESTINATIONS]
.length > 0) ?
this.state_[print_preview.AppStateField.RECENT_DESTINATIONS][0] :
null;
- },
+ }
/**
* @return {boolean} Whether the selected destination is valid.
*/
- isSelectedDestinationValid: function() {
- return !!this.selectedDestination && !!this.selectedDestination.id &&
- !!this.selectedDestination.origin;
- },
+ isSelectedDestinationValid() {
+ var selected = this.selectedDestination;
+ return !!selected && !!selected.id && !!selected.origin;
+ }
/**
- * @return {?Array<!RecentDestination>} The
+ * @return {?Array<!print_preview.AppStateRecentDestination>} The
* AppState.NUM_DESTINATIONS_ most recent destinations.
*/
get recentDestinations() {
return this.state_[print_preview.AppStateField.RECENT_DESTINATIONS];
- },
+ }
/**
* @param {!print_preview.AppStateField} field App state field to check if
* set.
* @return {boolean} Whether a field has been set in the app state.
*/
- hasField: function(field) {
+ hasField(field) {
return this.state_.hasOwnProperty(field);
- },
+ }
/**
* @param {!print_preview.AppStateField} field App state field to get.
* @return {?} Value of the app state field.
*/
- getField: function(field) {
+ getField(field) {
if (field == print_preview.AppStateField.CUSTOM_MARGINS) {
return this.state_[field] ?
print_preview.Margins.parse(this.state_[field]) :
null;
}
return this.state_[field];
- },
+ }
/**
* Initializes the app state from a serialized string returned by the native
@@ -176,12 +140,13 @@ cr.define('print_preview', function() {
* @param {?string} serializedAppStateStr Serialized string representation
* of the app state.
*/
- init: function(serializedAppStateStr) {
+ init(serializedAppStateStr) {
if (serializedAppStateStr) {
try {
var state = JSON.parse(serializedAppStateStr);
- if (state[print_preview.AppStateField.VERSION] == AppState.VERSION_) {
- this.state_ = /** @type {Object} */ (state);
+ if (!!state &&
+ state[print_preview.AppStateField.VERSION] == AppState.VERSION_) {
+ this.state_ = /** @type {!Object} */ (state);
}
} catch (e) {
console.error('Unable to parse state: ' + e);
@@ -209,21 +174,21 @@ cr.define('print_preview', function() {
this.state_[print_preview.AppStateField.RECENT_DESTINATIONS].length =
AppState.NUM_DESTINATIONS_;
}
- },
+ }
/**
* Sets to initialized state. Now object will accept persist requests.
*/
- setInitialized: function() {
+ setInitialized() {
this.isInitialized_ = true;
- },
+ }
/**
* Persists the given value for the given field.
* @param {!print_preview.AppStateField} field Field to persist.
* @param {?} value Value of field to persist.
*/
- persistField: function(field, value) {
+ persistField(field, value) {
if (!this.isInitialized_)
return;
if (field == print_preview.AppStateField.CUSTOM_MARGINS) {
@@ -232,19 +197,19 @@ cr.define('print_preview', function() {
this.state_[field] = value;
}
this.persist_();
- },
+ }
/**
* Persists the selected destination.
* @param {!print_preview.Destination} dest Destination to persist.
*/
- persistSelectedDestination: function(dest) {
+ persistSelectedDestination(dest) {
if (!this.isInitialized_)
return;
// Determine if this destination is already in the recent destinations,
// and where in the array it is located.
- var newDestination = new RecentDestination(dest);
+ var newDestination = makeRecentDestination(dest);
var indexFound =
this.state_[print_preview.AppStateField.RECENT_DESTINATIONS]
.findIndex(function(recent) {
@@ -275,16 +240,33 @@ cr.define('print_preview', function() {
0, 0, newDestination);
this.persist_();
- },
+ }
/**
* Calls into the native layer to persist the application state.
* @private
*/
- persist_: function() {
+ persist_() {
this.nativeLayer_.saveAppState(JSON.stringify(this.state_));
}
- };
+ }
+
+ /**
+ * Number of recent print destinations to store across browser sessions.
+ * @const {number}
+ * @private
+ */
+ AppState.NUM_DESTINATIONS_ = 3;
- return {AppState: AppState};
+ /**
+ * Current version of the app state. This value helps to understand how to
+ * parse earlier versions of the app state.
+ * @const {number}
+ * @private
+ */
+ AppState.VERSION_ = 2;
+
+ return {
+ AppState: AppState,
+ };
});
diff --git a/chromium/chrome/browser/resources/print_preview/data/capabilities_holder.js b/chromium/chrome/browser/resources/print_preview/data/capabilities_holder.js
index 1201ae2d3ac..edb8094ca7e 100644
--- a/chromium/chrome/browser/resources/print_preview/data/capabilities_holder.js
+++ b/chromium/chrome/browser/resources/print_preview/data/capabilities_holder.js
@@ -5,33 +5,29 @@
cr.define('print_preview', function() {
'use strict';
- /**
- * Mutable reference to a CDD object.
- * @constructor
- */
- function CapabilitiesHolder() {
- /**
- * Reference to the capabilities object.
- * @type {?print_preview.Cdd}
- * @private
- */
- this.capabilities_ = null;
- }
+ /* Mutable reference to a CDD object. */
+ class CapabilitiesHolder {
+ constructor() {
+ /**
+ * Reference to the capabilities object.
+ * @private {?print_preview.Cdd}
+ */
+ this.capabilities_ = null;
+ }
- CapabilitiesHolder.prototype = {
/** @return {?print_preview.Cdd} The instance held by the holder. */
- get: function() {
+ get() {
return this.capabilities_;
- },
+ }
/**
* @param {!print_preview.Cdd} capabilities New instance to put into the
* holder.
*/
- set: function(capabilities) {
+ set(capabilities) {
this.capabilities_ = capabilities;
}
- };
+ }
// Export
return {CapabilitiesHolder: CapabilitiesHolder};
diff --git a/chromium/chrome/browser/resources/print_preview/data/coordinate2d.js b/chromium/chrome/browser/resources/print_preview/data/coordinate2d.js
index b336f743504..f4dff0458ad 100644
--- a/chromium/chrome/browser/resources/print_preview/data/coordinate2d.js
+++ b/chromium/chrome/browser/resources/print_preview/data/coordinate2d.js
@@ -5,39 +5,38 @@
cr.define('print_preview', function() {
'use strict';
- /**
- * Immutable two dimensional point in space. The units of the dimensions are
- * undefined.
- * @param {number} x X-dimension of the point.
- * @param {number} y Y-dimension of the point.
- * @constructor
- */
- function Coordinate2d(x, y) {
+ class Coordinate2d {
/**
- * X-dimension of the point.
- * @type {number}
- * @private
+ * Immutable two dimensional point in space. The units of the dimensions are
+ * undefined.
+ * @param {number} x X-dimension of the point.
+ * @param {number} y Y-dimension of the point.
*/
- this.x_ = x;
+ constructor(x, y) {
+ /**
+ * X-dimension of the point.
+ * @type {number}
+ * @private
+ */
+ this.x_ = x;
- /**
- * Y-dimension of the point.
- * @type {number}
- * @private
- */
- this.y_ = y;
- }
+ /**
+ * Y-dimension of the point.
+ * @type {number}
+ * @private
+ */
+ this.y_ = y;
+ }
- Coordinate2d.prototype = {
/** @return {number} X-dimension of the point. */
get x() {
return this.x_;
- },
+ }
/** @return {number} Y-dimension of the point. */
get y() {
return this.y_;
- },
+ }
/**
* @param {number} x Amount to translate in the X dimension.
@@ -45,27 +44,27 @@ cr.define('print_preview', function() {
* @return {!print_preview.Coordinate2d} A new two-dimensional point
* translated along the X and Y dimensions.
*/
- translate: function(x, y) {
+ translate(x, y) {
return new Coordinate2d(this.x_ + x, this.y_ + y);
- },
+ }
/**
* @param {number} factor Amount to scale the X and Y dimensions.
* @return {!print_preview.Coordinate2d} A new two-dimensional point scaled
* by the given factor.
*/
- scale: function(factor) {
+ scale(factor) {
return new Coordinate2d(this.x_ * factor, this.y_ * factor);
- },
+ }
/**
* @param {print_preview.Coordinate2d} other The point to compare against.
* @return {boolean} Whether another point is equal to this one.
*/
- equals: function(other) {
+ equals(other) {
return other != null && this.x_ == other.x_ && this.y_ == other.y_;
}
- };
+ }
// Export
return {Coordinate2d: Coordinate2d};
diff --git a/chromium/chrome/browser/resources/print_preview/data/destination.js b/chromium/chrome/browser/resources/print_preview/data/destination.js
index 24e93cb4e8a..e98026cea19 100644
--- a/chromium/chrome/browser/resources/print_preview/data/destination.js
+++ b/chromium/chrome/browser/resources/print_preview/data/destination.js
@@ -96,226 +96,192 @@ print_preview.Cdd;
cr.define('print_preview', function() {
'use strict';
- /**
- * Print destination data object that holds data for both local and cloud
- * destinations.
- * @param {string} id ID of the destination.
- * @param {!print_preview.DestinationType} type Type of the destination.
- * @param {!print_preview.DestinationOrigin} origin Origin of the
- * destination.
- * @param {string} displayName Display name of the destination.
- * @param {boolean} isRecent Whether the destination has been used recently.
- * @param {!print_preview.DestinationConnectionStatus} connectionStatus
- * Connection status of the print destination.
- * @param {{tags: (Array<string>|undefined),
- * isOwned: (boolean|undefined),
- * isEnterprisePrinter: (boolean|undefined),
- * account: (string|undefined),
- * lastAccessTime: (number|undefined),
- * cloudID: (string|undefined),
- * provisionalType:
- * (print_preview.DestinationProvisionalType|undefined),
- * extensionId: (string|undefined),
- * extensionName: (string|undefined),
- * description: (string|undefined)}=} opt_params Optional parameters
- * for the destination.
- * @constructor
- */
- function Destination(
- id, type, origin, displayName, isRecent, connectionStatus, opt_params) {
- /**
- * ID of the destination.
- * @private {string}
- */
- this.id_ = id;
-
- /**
- * Type of the destination.
- * @private {!print_preview.DestinationType}
- */
- this.type_ = type;
-
- /**
- * Origin of the destination.
- * @private {!print_preview.DestinationOrigin}
- */
- this.origin_ = origin;
-
- /**
- * Display name of the destination.
- * @private {string}
- */
- this.displayName_ = displayName || '';
-
- /**
- * Whether the destination has been used recently.
- * @private {boolean}
- */
- this.isRecent_ = isRecent;
-
- /**
- * Tags associated with the destination.
- * @private {!Array<string>}
- */
- this.tags_ = (opt_params && opt_params.tags) || [];
-
- /**
- * Print capabilities of the destination.
- * @private {?print_preview.Cdd}
- */
- this.capabilities_ = null;
-
- /**
- * Whether the destination is owned by the user.
- * @private {boolean}
- */
- this.isOwned_ = (opt_params && opt_params.isOwned) || false;
-
- /**
- * Whether the destination is an enterprise policy controlled printer.
- * @private {boolean}
- */
- this.isEnterprisePrinter_ =
- (opt_params && opt_params.isEnterprisePrinter) || false;
-
- /**
- * Account this destination is registered for, if known.
- * @private {string}
- */
- this.account_ = (opt_params && opt_params.account) || '';
-
- /**
- * Cache of destination location fetched from tags.
- * @private {?string}
- */
- this.location_ = null;
-
- /**
- * Printer description.
- * @private {string}
- */
- this.description_ = (opt_params && opt_params.description) || '';
-
- /**
- * Connection status of the destination.
- * @private {!print_preview.DestinationConnectionStatus}
- */
- this.connectionStatus_ = connectionStatus;
-
- /**
- * Number of milliseconds since the epoch when the printer was last
- * accessed.
- * @private {number}
- */
- this.lastAccessTime_ =
- (opt_params && opt_params.lastAccessTime) || Date.now();
-
- /**
- * Cloud ID for Privet printers.
- * @private {string}
- */
- this.cloudID_ = (opt_params && opt_params.cloudID) || '';
-
+ class Destination {
/**
- * Extension ID for extension managed printers.
- * @private {string}
- */
- this.extensionId_ = (opt_params && opt_params.extensionId) || '';
-
- /**
- * Extension name for extension managed printers.
- * @private {string}
- */
- this.extensionName_ = (opt_params && opt_params.extensionName) || '';
-
- /**
- * Different from {@code print_preview.DestinationProvisionalType.NONE} if
- * the destination is provisional. Provisional destinations cannot be
- * selected as they are, but have to be resolved first (i.e. extra steps
- * have to be taken to get actual destination properties, which should
- * replace the provisional ones). Provisional destination resolvment flow
- * will be started when the user attempts to select the destination in
- * search UI.
- * @private {print_preview.DestinationProvisionalType}
- */
- this.provisionalType_ = (opt_params && opt_params.provisionalType) ||
- print_preview.DestinationProvisionalType.NONE;
-
- assert(
- this.provisionalType_ !=
- print_preview.DestinationProvisionalType.NEEDS_USB_PERMISSION ||
- this.isExtension,
- 'Provisional USB destination only supprted with extension origin.');
- }
-
- /**
- * Prefix of the location destination tag.
- * @type {!Array<string>}
- * @const
- */
- Destination.LOCATION_TAG_PREFIXES =
- ['__cp__location=', '__cp__printer-location='];
+ * Print destination data object that holds data for both local and cloud
+ * destinations.
+ * @param {string} id ID of the destination.
+ * @param {!print_preview.DestinationType} type Type of the destination.
+ * @param {!print_preview.DestinationOrigin} origin Origin of the
+ * destination.
+ * @param {string} displayName Display name of the destination.
+ * @param {boolean} isRecent Whether the destination has been used recently.
+ * @param {!print_preview.DestinationConnectionStatus} connectionStatus
+ * Connection status of the print destination.
+ * @param {{tags: (Array<string>|undefined),
+ * isOwned: (boolean|undefined),
+ * isEnterprisePrinter: (boolean|undefined),
+ * account: (string|undefined),
+ * lastAccessTime: (number|undefined),
+ * cloudID: (string|undefined),
+ * provisionalType:
+ * (print_preview.DestinationProvisionalType|undefined),
+ * extensionId: (string|undefined),
+ * extensionName: (string|undefined),
+ * description: (string|undefined)}=} opt_params Optional
+ * parameters for the destination.
+ */
+ constructor(
+ id, type, origin, displayName, isRecent, connectionStatus, opt_params) {
+ /**
+ * ID of the destination.
+ * @private {string}
+ */
+ this.id_ = id;
+
+ /**
+ * Type of the destination.
+ * @private {!print_preview.DestinationType}
+ */
+ this.type_ = type;
+
+ /**
+ * Origin of the destination.
+ * @private {!print_preview.DestinationOrigin}
+ */
+ this.origin_ = origin;
+
+ /**
+ * Display name of the destination.
+ * @private {string}
+ */
+ this.displayName_ = displayName || '';
+
+ /**
+ * Whether the destination has been used recently.
+ * @private {boolean}
+ */
+ this.isRecent_ = isRecent;
- /**
- * Enumeration of Google-promoted destination IDs.
- * @enum {string}
- */
- Destination.GooglePromotedId = {
- DOCS: '__google__docs',
- SAVE_AS_PDF: 'Save as PDF'
- };
+ /**
+ * Tags associated with the destination.
+ * @private {!Array<string>}
+ */
+ this.tags_ = (opt_params && opt_params.tags) || [];
+
+ /**
+ * Print capabilities of the destination.
+ * @private {?print_preview.Cdd}
+ */
+ this.capabilities_ = null;
+
+ /**
+ * Whether the destination is owned by the user.
+ * @private {boolean}
+ */
+ this.isOwned_ = (opt_params && opt_params.isOwned) || false;
+
+ /**
+ * Whether the destination is an enterprise policy controlled printer.
+ * @private {boolean}
+ */
+ this.isEnterprisePrinter_ =
+ (opt_params && opt_params.isEnterprisePrinter) || false;
+
+ /**
+ * Account this destination is registered for, if known.
+ * @private {string}
+ */
+ this.account_ = (opt_params && opt_params.account) || '';
+
+ /**
+ * Cache of destination location fetched from tags.
+ * @private {?string}
+ */
+ this.location_ = null;
+
+ /**
+ * Printer description.
+ * @private {string}
+ */
+ this.description_ = (opt_params && opt_params.description) || '';
+
+ /**
+ * Connection status of the destination.
+ * @private {!print_preview.DestinationConnectionStatus}
+ */
+ this.connectionStatus_ = connectionStatus;
+
+ /**
+ * Number of milliseconds since the epoch when the printer was last
+ * accessed.
+ * @private {number}
+ */
+ this.lastAccessTime_ =
+ (opt_params && opt_params.lastAccessTime) || Date.now();
+
+ /**
+ * Cloud ID for Privet printers.
+ * @private {string}
+ */
+ this.cloudID_ = (opt_params && opt_params.cloudID) || '';
+
+ /**
+ * Extension ID for extension managed printers.
+ * @private {string}
+ */
+ this.extensionId_ = (opt_params && opt_params.extensionId) || '';
+
+ /**
+ * Extension name for extension managed printers.
+ * @private {string}
+ */
+ this.extensionName_ = (opt_params && opt_params.extensionName) || '';
+
+ /**
+ * Different from {@code print_preview.DestinationProvisionalType.NONE} if
+ * the destination is provisional. Provisional destinations cannot be
+ * selected as they are, but have to be resolved first (i.e. extra steps
+ * have to be taken to get actual destination properties, which should
+ * replace the provisional ones). Provisional destination resolvment flow
+ * will be started when the user attempts to select the destination in
+ * search UI.
+ * @private {print_preview.DestinationProvisionalType}
+ */
+ this.provisionalType_ = (opt_params && opt_params.provisionalType) ||
+ print_preview.DestinationProvisionalType.NONE;
- /**
- * Enumeration of relative icon URLs for various types of destinations.
- * @enum {string}
- * @private
- */
- Destination.IconUrl_ = {
- CLOUD: 'images/printer.png',
- CLOUD_SHARED: 'images/printer_shared.png',
- LOCAL: 'images/printer.png',
- MOBILE: 'images/mobile.png',
- MOBILE_SHARED: 'images/mobile_shared.png',
- THIRD_PARTY: 'images/third_party.png',
- PDF: 'images/pdf.png',
- DOCS: 'images/google_doc.png',
- ENTERPRISE: 'images/business.svg'
- };
+ assert(
+ this.provisionalType_ !=
+ print_preview.DestinationProvisionalType
+ .NEEDS_USB_PERMISSION ||
+ this.isExtension,
+ 'Provisional USB destination only supprted with extension origin.');
+ }
- Destination.prototype = {
/** @return {string} ID of the destination. */
get id() {
return this.id_;
- },
+ }
/** @return {!print_preview.DestinationType} Type of the destination. */
get type() {
return this.type_;
- },
+ }
/**
* @return {!print_preview.DestinationOrigin} Origin of the destination.
*/
get origin() {
return this.origin_;
- },
+ }
/** @return {string} Display name of the destination. */
get displayName() {
return this.displayName_;
- },
+ }
/** @return {boolean} Whether the destination has been used recently. */
get isRecent() {
return this.isRecent_;
- },
+ }
/**
* @param {boolean} isRecent Whether the destination has been used recently.
*/
set isRecent(isRecent) {
this.isRecent_ = isRecent;
- },
+ }
/**
* @return {boolean} Whether the user owns the destination. Only applies to
@@ -323,14 +289,14 @@ cr.define('print_preview', function() {
*/
get isOwned() {
return this.isOwned_;
- },
+ }
/**
* @return {string} Account this destination is registered for, if known.
*/
get account() {
return this.account_;
- },
+ }
/** @return {boolean} Whether the destination is local or cloud-based. */
get isLocal() {
@@ -340,12 +306,12 @@ cr.define('print_preview', function() {
(this.origin_ == print_preview.DestinationOrigin.PRIVET &&
this.connectionStatus_ !=
print_preview.DestinationConnectionStatus.UNREGISTERED);
- },
+ }
/** @return {boolean} Whether the destination is a Privet local printer */
get isPrivet() {
return this.origin_ == print_preview.DestinationOrigin.PRIVET;
- },
+ }
/**
* @return {boolean} Whether the destination is an extension managed
@@ -353,7 +319,7 @@ cr.define('print_preview', function() {
*/
get isExtension() {
return this.origin_ == print_preview.DestinationOrigin.EXTENSION;
- },
+ }
/**
* @return {string} The location of the destination, or an empty string if
@@ -362,17 +328,17 @@ cr.define('print_preview', function() {
get location() {
if (this.location_ == null) {
this.location_ = '';
- this.tags_.some(function(tag) {
- return Destination.LOCATION_TAG_PREFIXES.some(function(prefix) {
+ this.tags_.some(tag => {
+ return Destination.LOCATION_TAG_PREFIXES.some(prefix => {
if (tag.startsWith(prefix)) {
this.location_ = tag.substring(prefix.length) || '';
return true;
}
- }, this);
- }, this);
+ });
+ });
}
return this.location_;
- },
+ }
/**
* @return {string} The description of the destination, or an empty string,
@@ -380,7 +346,7 @@ cr.define('print_preview', function() {
*/
get description() {
return this.description_;
- },
+ }
/**
* @return {string} Most relevant string to help user to identify this
@@ -391,17 +357,17 @@ cr.define('print_preview', function() {
return this.account_;
}
return this.location || this.extensionName || this.description;
- },
+ }
/** @return {!Array<string>} Tags associated with the destination. */
get tags() {
return this.tags_.slice(0);
- },
+ }
/** @return {string} Cloud ID associated with the destination */
get cloudID() {
return this.cloudID_;
- },
+ }
/**
* @return {string} Extension ID associated with the destination. Non-empty
@@ -409,7 +375,7 @@ cr.define('print_preview', function() {
*/
get extensionId() {
return this.extensionId_;
- },
+ }
/**
* @return {string} Extension name associated with the destination.
@@ -417,20 +383,21 @@ cr.define('print_preview', function() {
*/
get extensionName() {
return this.extensionName_;
- },
+ }
/** @return {?print_preview.Cdd} Print capabilities of the destination. */
get capabilities() {
return this.capabilities_;
- },
+ }
/**
- * @param {!print_preview.Cdd} capabilities Print capabilities of the
+ * @param {?print_preview.Cdd} capabilities Print capabilities of the
* destination.
*/
set capabilities(capabilities) {
- this.capabilities_ = capabilities;
- },
+ if (capabilities)
+ this.capabilities_ = capabilities;
+ }
/**
* @return {!print_preview.DestinationConnectionStatus} Connection status
@@ -438,7 +405,7 @@ cr.define('print_preview', function() {
*/
get connectionStatus() {
return this.connectionStatus_;
- },
+ }
/**
* @param {!print_preview.DestinationConnectionStatus} status Connection
@@ -446,7 +413,7 @@ cr.define('print_preview', function() {
*/
set connectionStatus(status) {
this.connectionStatus_ = status;
- },
+ }
/** @return {boolean} Whether the destination is considered offline. */
get isOffline() {
@@ -456,7 +423,7 @@ cr.define('print_preview', function() {
print_preview.DestinationConnectionStatus.DORMANT
],
this.connectionStatus_);
- },
+ }
/** @return {string} Human readable status for offline destination. */
get offlineStatusText() {
@@ -475,7 +442,7 @@ cr.define('print_preview', function() {
offlineMessageId = 'offline';
}
return loadTimeData.getString(offlineMessageId);
- },
+ }
/**
* @return {number} Number of milliseconds since the epoch when the printer
@@ -483,7 +450,7 @@ cr.define('print_preview', function() {
*/
get lastAccessTime() {
return this.lastAccessTime_;
- },
+ }
/** @return {string} Relative URL of the destination's icon. */
get iconUrl() {
@@ -497,7 +464,7 @@ cr.define('print_preview', function() {
return Destination.IconUrl_.ENTERPRISE;
}
if (this.isLocal) {
- return Destination.IconUrl_.LOCAL;
+ return Destination.IconUrl_.LOCAL_1X;
}
if (this.type_ == print_preview.DestinationType.MOBILE && this.isOwned_) {
return Destination.IconUrl_.MOBILE;
@@ -506,10 +473,30 @@ cr.define('print_preview', function() {
return Destination.IconUrl_.MOBILE_SHARED;
}
if (this.isOwned_) {
- return Destination.IconUrl_.CLOUD;
+ return Destination.IconUrl_.CLOUD_1X;
+ }
+ return Destination.IconUrl_.CLOUD_SHARED_1X;
+ }
+
+ /**
+ * @return {string} The srcset="" attribute of a destination. Generally used
+ * for a 2x (e.g. HiDPI) icon. Can be empty or of the format '<url> 2x'.
+ */
+ get srcSet() {
+ let srcSetIcon = '';
+ let iconUrl = this.iconUrl;
+ if (iconUrl == Destination.IconUrl_.LOCAL_1X) {
+ srcSetIcon = Destination.IconUrl_.LOCAL_2X;
+ } else if (iconUrl == Destination.IconUrl_.CLOUD_1X) {
+ srcSetIcon = Destination.IconUrl_.CLOUD_2X;
+ } else if (iconUrl == Destination.IconUrl_.CLOUD_SHARED_1X) {
+ srcSetIcon = Destination.IconUrl_.CLOUD_SHARED_2X;
}
- return Destination.IconUrl_.CLOUD_SHARED;
- },
+ if (srcSetIcon) {
+ srcSetIcon += ' 2x';
+ }
+ return srcSetIcon;
+ }
/**
* @return {!Array<string>} Properties (besides display name) to match
@@ -517,7 +504,7 @@ cr.define('print_preview', function() {
*/
get extraPropertiesToMatch() {
return [this.location, this.description];
- },
+ }
/**
* Matches a query against the destination.
@@ -525,13 +512,11 @@ cr.define('print_preview', function() {
* @return {boolean} {@code true} if the query matches this destination,
* {@code false} otherwise.
*/
- matches: function(query) {
+ matches(query) {
return !!this.displayName_.match(query) ||
!!this.extensionName_.match(query) ||
- this.extraPropertiesToMatch.some(function(property) {
- return property.match(query);
- });
- },
+ this.extraPropertiesToMatch.some(p => p.match(query));
+ }
/**
* Gets the destination's provisional type.
@@ -539,7 +524,7 @@ cr.define('print_preview', function() {
*/
get provisionalType() {
return this.provisionalType_;
- },
+ }
/**
* Whether the destinaion is provisional.
@@ -548,7 +533,7 @@ cr.define('print_preview', function() {
get isProvisional() {
return this.provisionalType_ !=
print_preview.DestinationProvisionalType.NONE;
- },
+ }
/**
* Whether the printer is enterprise policy controlled printer.
@@ -556,7 +541,44 @@ cr.define('print_preview', function() {
*/
get isEnterprisePrinter() {
return this.isEnterprisePrinter_;
- },
+ }
+ }
+
+ /**
+ * Prefix of the location destination tag.
+ * @type {!Array<string>}
+ * @const
+ */
+ Destination.LOCATION_TAG_PREFIXES =
+ ['__cp__location=', '__cp__printer-location='];
+
+ /**
+ * Enumeration of Google-promoted destination IDs.
+ * @enum {string}
+ */
+ Destination.GooglePromotedId = {
+ DOCS: '__google__docs',
+ SAVE_AS_PDF: 'Save as PDF'
+ };
+
+ /**
+ * Enumeration of relative icon URLs for various types of destinations.
+ * @enum {string}
+ * @private
+ */
+ Destination.IconUrl_ = {
+ CLOUD_1X: 'images/1x/printer.png',
+ CLOUD_2X: 'images/2x/printer.png',
+ CLOUD_SHARED_1X: 'images/1x/printer_shared.png',
+ CLOUD_SHARED_2X: 'images/2x/printer_shared.png',
+ LOCAL_1X: 'images/1x/printer.png',
+ LOCAL_2X: 'images/2x/printer.png',
+ MOBILE: 'images/mobile.png',
+ MOBILE_SHARED: 'images/mobile_shared.png',
+ THIRD_PARTY: 'images/third_party.png',
+ PDF: 'images/pdf.png',
+ DOCS: 'images/google_doc.png',
+ ENTERPRISE: 'images/business.svg'
};
// Export
diff --git a/chromium/chrome/browser/resources/print_preview/data/destination_match.js b/chromium/chrome/browser/resources/print_preview/data/destination_match.js
index 3152abe2342..165aa22f013 100644
--- a/chromium/chrome/browser/resources/print_preview/data/destination_match.js
+++ b/chromium/chrome/browser/resources/print_preview/data/destination_match.js
@@ -4,59 +4,74 @@
cr.define('print_preview', function() {
'use strict';
-
/**
- * A set of key parameters describing a destination used to determine
- * if two destinations are the same.
- * @param {!Array<!print_preview.DestinationOrigin>} origins Match
- * destinations from these origins.
- * @param {RegExp} idRegExp Match destination's id.
- * @param {RegExp} displayNameRegExp Match destination's displayName.
- * @param {boolean} skipVirtualDestinations Whether to ignore virtual
- * destinations, for example, Save as PDF.
- * @constructor
+ * Converts DestinationOrigin to PrinterType.
+ * @param {!print_preview.DestinationOrigin} origin The printer's
+ * destination origin.
+ * return {?print_preview.PrinterType} The corresponding PrinterType.
+ * Returns null if no match is found.
*/
- function DestinationMatch(
- origins, idRegExp, displayNameRegExp, skipVirtualDestinations) {
- /** @private {!Array<!print_preview.DestinationOrigin>} */
- this.origins_ = origins;
+ var originToType = function(origin) {
+ if (origin === print_preview.DestinationOrigin.LOCAL ||
+ origin === print_preview.DestinationOrigin.CROS) {
+ return print_preview.PrinterType.LOCAL_PRINTER;
+ }
+ if (origin === print_preview.DestinationOrigin.PRIVET)
+ return print_preview.PrinterType.PRIVET_PRINTER;
+ if (origin === print_preview.DestinationOrigin.EXTENSION)
+ return print_preview.PrinterType.EXTENSION_PRINTER;
+ return null;
+ };
- /** @private {RegExp} */
- this.idRegExp_ = idRegExp;
+ class DestinationMatch {
+ /**
+ * A set of key parameters describing a destination used to determine
+ * if two destinations are the same.
+ * @param {!Array<!print_preview.DestinationOrigin>} origins Match
+ * destinations from these origins.
+ * @param {RegExp} idRegExp Match destination's id.
+ * @param {RegExp} displayNameRegExp Match destination's displayName.
+ * @param {boolean} skipVirtualDestinations Whether to ignore virtual
+ * destinations, for example, Save as PDF.
+ */
+ constructor(origins, idRegExp, displayNameRegExp, skipVirtualDestinations) {
+ /** @private {!Array<!print_preview.DestinationOrigin>} */
+ this.origins_ = origins;
- /** @private {RegExp} */
- this.displayNameRegExp_ = displayNameRegExp;
+ /** @private {RegExp} */
+ this.idRegExp_ = idRegExp;
- /** @private {boolean} */
- this.skipVirtualDestinations_ = skipVirtualDestinations;
- }
+ /** @private {RegExp} */
+ this.displayNameRegExp_ = displayNameRegExp;
- DestinationMatch.prototype = {
+ /** @private {boolean} */
+ this.skipVirtualDestinations_ = skipVirtualDestinations;
+ }
/**
* @param {string} origin Origin to match.
* @return {boolean} Whether the origin is one of the {@code origins_}.
*/
- matchOrigin: function(origin) {
+ matchOrigin(origin) {
return arrayContains(this.origins_, origin);
- },
+ }
/**
* @param {string} id Id of the destination.
* @param {string} origin Origin of the destination.
* @return {boolean} Whether destination is the same as initial.
*/
- matchIdAndOrigin: function(id, origin) {
+ matchIdAndOrigin(id, origin) {
return this.matchOrigin(origin) && !!this.idRegExp_ &&
this.idRegExp_.test(id);
- },
+ }
/**
* @param {!print_preview.Destination} destination Destination to match.
* @return {boolean} Whether {@code destination} matches the last user
* selected one.
*/
- match: function(destination) {
+ match(destination) {
if (!this.matchOrigin(destination.origin)) {
return false;
}
@@ -72,7 +87,7 @@ cr.define('print_preview', function() {
return false;
}
return true;
- },
+ }
/**
* @param {!print_preview.Destination} destination Destination to check.
@@ -80,7 +95,7 @@ cr.define('print_preview', function() {
* destination selection.
* @private
*/
- isVirtualDestination_: function(destination) {
+ isVirtualDestination_(destination) {
if (destination.origin == print_preview.DestinationOrigin.LOCAL) {
return arrayContains(
[print_preview.Destination.GooglePromotedId.SAVE_AS_PDF],
@@ -89,8 +104,16 @@ cr.define('print_preview', function() {
return arrayContains(
[print_preview.Destination.GooglePromotedId.DOCS], destination.id);
}
- };
+
+ /**
+ * @return {?print_preview.PrinterType} The printer type of this
+ * destination match. Will return null for Cloud destinations.
+ */
+ getType() {
+ return originToType(this.origins_[0]);
+ }
+ }
// Export
- return {DestinationMatch: DestinationMatch};
+ return {originToType: originToType, DestinationMatch: DestinationMatch};
});
diff --git a/chromium/chrome/browser/resources/print_preview/data/destination_store.js b/chromium/chrome/browser/resources/print_preview/data/destination_store.js
index 8ef5101ccb1..80072b56887 100644
--- a/chromium/chrome/browser/resources/print_preview/data/destination_store.js
+++ b/chromium/chrome/browser/resources/print_preview/data/destination_store.js
@@ -2,404 +2,27 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+cr.exportPath('print_preview');
+
+/**
+ * Printer search statuses used by the destination store.
+ * @enum {string}
+ */
+print_preview.DestinationStorePrinterSearchStatus = {
+ START: 'start',
+ SEARCHING: 'searching',
+ DONE: 'done'
+};
+
cr.define('print_preview', function() {
'use strict';
-
- /**
- * A data store that stores destinations and dispatches events when the data
- * store changes.
- * @param {!print_preview.UserInfo} userInfo User information repository.
- * @param {!print_preview.AppState} appState Application state.
- * @param {!WebUIListenerTracker} listenerTracker Tracker for WebUI listeners
- * added in DestinationStore constructor.
- * @constructor
- * @extends {cr.EventTarget}
- */
- function DestinationStore(userInfo, appState, listenerTracker) {
- cr.EventTarget.call(this);
-
- /**
- * Used to fetch local print destinations.
- * @private {!print_preview.NativeLayer}
- */
- this.nativeLayer_ = print_preview.NativeLayer.getInstance();
-
- /**
- * User information repository.
- * @private {!print_preview.UserInfo}
- */
- this.userInfo_ = userInfo;
-
- /**
- * Used to load and persist the selected destination.
- * @private {!print_preview.AppState}
- */
- this.appState_ = appState;
-
- /**
- * Used to track metrics.
- * @private {!print_preview.DestinationSearchMetricsContext}
- */
- this.metrics_ = new print_preview.DestinationSearchMetricsContext();
-
- /**
- * Internal backing store for the data store.
- * @private {!Array<!print_preview.Destination>}
- */
- this.destinations_ = [];
-
- /**
- * Cache used for constant lookup of destinations by origin and id.
- * @private {Object<!print_preview.Destination>}
- */
- this.destinationMap_ = {};
-
- /**
- * Currently selected destination.
- * @private {print_preview.Destination}
- */
- this.selectedDestination_ = null;
-
- /**
- * Whether the destination store will auto select the destination that
- * matches this set of parameters.
- * @private {print_preview.DestinationMatch}
- */
- this.autoSelectMatchingDestination_ = null;
-
- /**
- * Event tracker used to track event listeners of the destination store.
- * @private {!EventTracker}
- */
- this.tracker_ = new EventTracker();
-
- /**
- * Whether PDF printer is enabled. It's disabled, for example, in App Kiosk
- * mode.
- * @private {boolean}
- */
- this.pdfPrinterEnabled_ = false;
-
- /**
- * ID of the system default destination.
- * @private {?string}
- */
- this.systemDefaultDestinationId_ = null;
-
- /**
- * Used to fetch cloud-based print destinations.
- * @private {cloudprint.CloudPrintInterface}
- */
- this.cloudPrintInterface_ = null;
-
- /**
- * Maps user account to the list of origins for which destinations are
- * already loaded.
- * @private {!Object<Array<!print_preview.DestinationOrigin>>}
- */
- this.loadedCloudOrigins_ = {};
-
- /**
- * ID of a timeout after the initial destination ID is set. If no inserted
- * destination matches the initial destination ID after the specified
- * timeout, the first destination in the store will be automatically
- * selected.
- * @private {?number}
- */
- this.autoSelectTimeout_ = null;
-
- /**
- * Whether a search for local destinations is in progress.
- * @private {boolean}
- */
- this.isLocalDestinationSearchInProgress_ = false;
-
- /**
- * Whether the destination store has already loaded or is loading all local
- * destinations.
- * @private {boolean}
- */
- this.hasLoadedAllLocalDestinations_ = false;
-
- /**
- * Whether a search for privet destinations is in progress.
- * @private {boolean}
- */
- this.isPrivetDestinationSearchInProgress_ = false;
-
- /**
- * Whether the destination store has already loaded or is loading all privet
- * destinations.
- * @private {boolean}
- */
- this.hasLoadedAllPrivetDestinations_ = false;
-
- /**
- * Whether a search for extension destinations is in progress.
- * @private {boolean}
- */
- this.isExtensionDestinationSearchInProgress_ = false;
-
- /**
- * Whether the destination store has already loaded all extension
- * destinations.
- * @private {boolean}
- */
- this.hasLoadedAllExtensionDestinations_ = false;
-
- /**
- * ID of a timeout set at the start of an extension destination search. The
- * timeout ends the search.
- * @private {?number}
- */
- this.extensionSearchTimeout_ = null;
-
- /**
- * MDNS service name of destination that we are waiting to register.
- * @private {?string}
- */
- this.waitForRegisterDestination_ = null;
-
- /**
- * Local destinations are CROS destinations on ChromeOS because they require
- * extra setup.
- * @private {!print_preview.DestinationOrigin}
- */
- this.platformOrigin_ = cr.isChromeOS ?
- print_preview.DestinationOrigin.CROS :
- print_preview.DestinationOrigin.LOCAL;
-
- /**
- * Whether to default to the system default printer instead of the most
- * recent destination.
- * @private {boolean}
- */
- this.useSystemDefaultAsDefault_ =
- loadTimeData.getBoolean('useSystemDefaultPrinter');
-
- this.reset_();
-
- this.addWebUIEventListeners_(listenerTracker);
- }
-
- /**
- * Event types dispatched by the data store.
- * @enum {string}
- */
- DestinationStore.EventType = {
- DESTINATION_SEARCH_DONE:
- 'print_preview.DestinationStore.DESTINATION_SEARCH_DONE',
- DESTINATION_SEARCH_STARTED:
- 'print_preview.DestinationStore.DESTINATION_SEARCH_STARTED',
- DESTINATION_SELECT: 'print_preview.DestinationStore.DESTINATION_SELECT',
- DESTINATIONS_INSERTED:
- 'print_preview.DestinationStore.DESTINATIONS_INSERTED',
- PROVISIONAL_DESTINATION_RESOLVED:
- 'print_preview.DestinationStore.PROVISIONAL_DESTINATION_RESOLVED',
- CACHED_SELECTED_DESTINATION_INFO_READY:
- 'print_preview.DestinationStore.CACHED_SELECTED_DESTINATION_INFO_READY',
- SELECTED_DESTINATION_CAPABILITIES_READY: 'print_preview.DestinationStore' +
- '.SELECTED_DESTINATION_CAPABILITIES_READY',
- };
-
- /**
- * Delay in milliseconds before the destination store ignores the initial
- * destination ID and just selects any printer (since the initial destination
- * was not found).
- * @private {number}
- * @const
- */
- DestinationStore.AUTO_SELECT_TIMEOUT_ = 15000;
-
- /**
- * Maximum amount of time spent searching for extension destinations, in
- * milliseconds.
- * @private {number}
- * @const
- */
- DestinationStore.EXTENSION_SEARCH_DURATION_ = 5000;
-
- /**
- * Human readable names for media sizes in the cloud print CDD.
- * https://developers.google.com/cloud-print/docs/cdd
- * @private {Object<string>}
- * @const
- */
- DestinationStore.MEDIA_DISPLAY_NAMES_ = {
- 'ISO_2A0': '2A0',
- 'ISO_A0': 'A0',
- 'ISO_A0X3': 'A0x3',
- 'ISO_A1': 'A1',
- 'ISO_A10': 'A10',
- 'ISO_A1X3': 'A1x3',
- 'ISO_A1X4': 'A1x4',
- 'ISO_A2': 'A2',
- 'ISO_A2X3': 'A2x3',
- 'ISO_A2X4': 'A2x4',
- 'ISO_A2X5': 'A2x5',
- 'ISO_A3': 'A3',
- 'ISO_A3X3': 'A3x3',
- 'ISO_A3X4': 'A3x4',
- 'ISO_A3X5': 'A3x5',
- 'ISO_A3X6': 'A3x6',
- 'ISO_A3X7': 'A3x7',
- 'ISO_A3_EXTRA': 'A3 Extra',
- 'ISO_A4': 'A4',
- 'ISO_A4X3': 'A4x3',
- 'ISO_A4X4': 'A4x4',
- 'ISO_A4X5': 'A4x5',
- 'ISO_A4X6': 'A4x6',
- 'ISO_A4X7': 'A4x7',
- 'ISO_A4X8': 'A4x8',
- 'ISO_A4X9': 'A4x9',
- 'ISO_A4_EXTRA': 'A4 Extra',
- 'ISO_A4_TAB': 'A4 Tab',
- 'ISO_A5': 'A5',
- 'ISO_A5_EXTRA': 'A5 Extra',
- 'ISO_A6': 'A6',
- 'ISO_A7': 'A7',
- 'ISO_A8': 'A8',
- 'ISO_A9': 'A9',
- 'ISO_B0': 'B0',
- 'ISO_B1': 'B1',
- 'ISO_B10': 'B10',
- 'ISO_B2': 'B2',
- 'ISO_B3': 'B3',
- 'ISO_B4': 'B4',
- 'ISO_B5': 'B5',
- 'ISO_B5_EXTRA': 'B5 Extra',
- 'ISO_B6': 'B6',
- 'ISO_B6C4': 'B6C4',
- 'ISO_B7': 'B7',
- 'ISO_B8': 'B8',
- 'ISO_B9': 'B9',
- 'ISO_C0': 'C0',
- 'ISO_C1': 'C1',
- 'ISO_C10': 'C10',
- 'ISO_C2': 'C2',
- 'ISO_C3': 'C3',
- 'ISO_C4': 'C4',
- 'ISO_C5': 'C5',
- 'ISO_C6': 'C6',
- 'ISO_C6C5': 'C6C5',
- 'ISO_C7': 'C7',
- 'ISO_C7C6': 'C7C6',
- 'ISO_C8': 'C8',
- 'ISO_C9': 'C9',
- 'ISO_DL': 'Envelope DL',
- 'ISO_RA0': 'RA0',
- 'ISO_RA1': 'RA1',
- 'ISO_RA2': 'RA2',
- 'ISO_SRA0': 'SRA0',
- 'ISO_SRA1': 'SRA1',
- 'ISO_SRA2': 'SRA2',
- 'JIS_B0': 'B0 (JIS)',
- 'JIS_B1': 'B1 (JIS)',
- 'JIS_B10': 'B10 (JIS)',
- 'JIS_B2': 'B2 (JIS)',
- 'JIS_B3': 'B3 (JIS)',
- 'JIS_B4': 'B4 (JIS)',
- 'JIS_B5': 'B5 (JIS)',
- 'JIS_B6': 'B6 (JIS)',
- 'JIS_B7': 'B7 (JIS)',
- 'JIS_B8': 'B8 (JIS)',
- 'JIS_B9': 'B9 (JIS)',
- 'JIS_EXEC': 'Executive (JIS)',
- 'JPN_CHOU2': 'Choukei 2',
- 'JPN_CHOU3': 'Choukei 3',
- 'JPN_CHOU4': 'Choukei 4',
- 'JPN_HAGAKI': 'Hagaki',
- 'JPN_KAHU': 'Kahu Envelope',
- 'JPN_KAKU2': 'Kaku 2',
- 'JPN_OUFUKU': 'Oufuku Hagaki',
- 'JPN_YOU4': 'You 4',
- 'NA_10X11': '10x11',
- 'NA_10X13': '10x13',
- 'NA_10X14': '10x14',
- 'NA_10X15': '10x15',
- 'NA_11X12': '11x12',
- 'NA_11X15': '11x15',
- 'NA_12X19': '12x19',
- 'NA_5X7': '5x7',
- 'NA_6X9': '6x9',
- 'NA_7X9': '7x9',
- 'NA_9X11': '9x11',
- 'NA_A2': 'A2',
- 'NA_ARCH_A': 'Arch A',
- 'NA_ARCH_B': 'Arch B',
- 'NA_ARCH_C': 'Arch C',
- 'NA_ARCH_D': 'Arch D',
- 'NA_ARCH_E': 'Arch E',
- 'NA_ASME_F': 'ASME F',
- 'NA_B_PLUS': 'B-plus',
- 'NA_C': 'C',
- 'NA_C5': 'C5',
- 'NA_D': 'D',
- 'NA_E': 'E',
- 'NA_EDP': 'EDP',
- 'NA_EUR_EDP': 'European EDP',
- 'NA_EXECUTIVE': 'Executive',
- 'NA_F': 'F',
- 'NA_FANFOLD_EUR': 'FanFold European',
- 'NA_FANFOLD_US': 'FanFold US',
- 'NA_FOOLSCAP': 'FanFold German Legal',
- 'NA_GOVT_LEGAL': 'Government Legal',
- 'NA_GOVT_LETTER': 'Government Letter',
- 'NA_INDEX_3X5': 'Index 3x5',
- 'NA_INDEX_4X6': 'Index 4x6',
- 'NA_INDEX_4X6_EXT': 'Index 4x6 ext',
- 'NA_INDEX_5X8': '5x8',
- 'NA_INVOICE': 'Invoice',
- 'NA_LEDGER': 'Tabloid', // Ledger in portrait is called Tabloid.
- 'NA_LEGAL': 'Legal',
- 'NA_LEGAL_EXTRA': 'Legal extra',
- 'NA_LETTER': 'Letter',
- 'NA_LETTER_EXTRA': 'Letter extra',
- 'NA_LETTER_PLUS': 'Letter plus',
- 'NA_MONARCH': 'Monarch',
- 'NA_NUMBER_10': 'Envelope #10',
- 'NA_NUMBER_11': 'Envelope #11',
- 'NA_NUMBER_12': 'Envelope #12',
- 'NA_NUMBER_14': 'Envelope #14',
- 'NA_NUMBER_9': 'Envelope #9',
- 'NA_PERSONAL': 'Personal',
- 'NA_QUARTO': 'Quarto',
- 'NA_SUPER_A': 'Super A',
- 'NA_SUPER_B': 'Super B',
- 'NA_WIDE_FORMAT': 'Wide format',
- 'OM_DAI_PA_KAI': 'Dai-pa-kai',
- 'OM_FOLIO': 'Folio',
- 'OM_FOLIO_SP': 'Folio SP',
- 'OM_INVITE': 'Invite Envelope',
- 'OM_ITALIAN': 'Italian Envelope',
- 'OM_JUURO_KU_KAI': 'Juuro-ku-kai',
- 'OM_LARGE_PHOTO': 'Large photo',
- 'OM_OFICIO': 'Oficio',
- 'OM_PA_KAI': 'Pa-kai',
- 'OM_POSTFIX': 'Postfix Envelope',
- 'OM_SMALL_PHOTO': 'Small photo',
- 'PRC_1': 'prc1 Envelope',
- 'PRC_10': 'prc10 Envelope',
- 'PRC_16K': 'prc 16k',
- 'PRC_2': 'prc2 Envelope',
- 'PRC_3': 'prc3 Envelope',
- 'PRC_32K': 'prc 32k',
- 'PRC_4': 'prc4 Envelope',
- 'PRC_5': 'prc5 Envelope',
- 'PRC_6': 'prc6 Envelope',
- 'PRC_7': 'prc7 Envelope',
- 'PRC_8': 'prc8 Envelope',
- 'ROC_16K': 'ROC 16K',
- 'ROC_8K': 'ROC 8k',
- };
-
/**
* Localizes printer capabilities.
- * @param {!print_preview.Cdd} capabilities Printer capabilities to localize.
+ * @param {!print_preview.Cdd} capabilities Printer capabilities to
+ * localize.
* @return {!print_preview.Cdd} Localized capabilities.
- * @private
*/
- DestinationStore.localizeCapabilities_ = function(capabilities) {
+ var localizeCapabilities = function(capabilities) {
if (!capabilities.printer)
return capabilities;
@@ -422,9 +45,8 @@ cr.define('print_preview', function() {
* @param {!Object} a Media to compare.
* @param {!Object} b Media to compare.
* @return {number} 1 if a > b, -1 if a < b, or 0 if a == b.
- * @private
*/
- DestinationStore.compareMediaNames_ = function(a, b) {
+ var compareMediaNames = function(a, b) {
var nameA = a.custom_display_name_localized || a.custom_display_name;
var nameB = b.custom_display_name_localized || b.custom_display_name;
return nameA == nameB ? 0 : (nameA > nameB ? 1 : -1);
@@ -432,11 +54,12 @@ cr.define('print_preview', function() {
/**
* Sort printer media sizes.
- * @param {!print_preview.Cdd} capabilities Printer capabilities to localize.
+ * @param {!print_preview.Cdd} capabilities Printer capabilities to
+ * localize.
* @return {!print_preview.Cdd} Localized capabilities.
* @private
*/
- DestinationStore.sortMediaSizes_ = function(capabilities) {
+ var sortMediaSizes = function(capabilities) {
if (!capabilities.printer)
return capabilities;
@@ -482,12 +105,12 @@ cr.define('print_preview', function() {
}
// For each category, sort by name.
- categoryStandardNA.sort(DestinationStore.compareMediaNames_);
- categoryStandardCN.sort(DestinationStore.compareMediaNames_);
- categoryStandardISO.sort(DestinationStore.compareMediaNames_);
- categoryStandardJP.sort(DestinationStore.compareMediaNames_);
- categoryStandardMisc.sort(DestinationStore.compareMediaNames_);
- categoryCustom.sort(DestinationStore.compareMediaNames_);
+ categoryStandardNA.sort(compareMediaNames);
+ categoryStandardCN.sort(compareMediaNames);
+ categoryStandardISO.sort(compareMediaNames);
+ categoryStandardJP.sort(compareMediaNames);
+ categoryStandardMisc.sort(compareMediaNames);
+ categoryCustom.sort(compareMediaNames);
// Then put it all back together.
mediaSize.option = categoryStandardNA;
@@ -497,8 +120,157 @@ cr.define('print_preview', function() {
return capabilities;
};
- DestinationStore.prototype = {
- __proto__: cr.EventTarget.prototype,
+
+ class DestinationStore extends cr.EventTarget {
+ /**
+ * A data store that stores destinations and dispatches events when the
+ * data store changes.
+ * @param {!print_preview.UserInfo} userInfo User information repository.
+ * @param {!print_preview.AppState} appState Application state.
+ * @param {!WebUIListenerTracker} listenerTracker Tracker for WebUI
+ * listeners added in DestinationStore constructor.
+ */
+ constructor(userInfo, appState, listenerTracker) {
+ super();
+
+ /**
+ * Used to fetch local print destinations.
+ * @private {!print_preview.NativeLayer}
+ */
+ this.nativeLayer_ = print_preview.NativeLayer.getInstance();
+
+ /**
+ * User information repository.
+ * @private {!print_preview.UserInfo}
+ */
+ this.userInfo_ = userInfo;
+
+ /**
+ * Used to load and persist the selected destination.
+ * @private {!print_preview.AppState}
+ */
+ this.appState_ = appState;
+
+ /**
+ * Used to track metrics.
+ * @private {!print_preview.DestinationSearchMetricsContext}
+ */
+ this.metrics_ = new print_preview.DestinationSearchMetricsContext();
+
+ /**
+ * Internal backing store for the data store.
+ * @private {!Array<!print_preview.Destination>}
+ */
+ this.destinations_ = [];
+
+ /**
+ * Cache used for constant lookup of destinations by origin and id.
+ * @private {Object<!print_preview.Destination>}
+ */
+ this.destinationMap_ = {};
+
+ /**
+ * Currently selected destination.
+ * @private {print_preview.Destination}
+ */
+ this.selectedDestination_ = null;
+
+ /**
+ * Whether the destination store will auto select the destination that
+ * matches this set of parameters.
+ * @private {print_preview.DestinationMatch}
+ */
+ this.autoSelectMatchingDestination_ = null;
+
+ /**
+ * Event tracker used to track event listeners of the destination store.
+ * @private {!EventTracker}
+ */
+ this.tracker_ = new EventTracker();
+
+ /**
+ * Whether PDF printer is enabled. It's disabled, for example, in App
+ * Kiosk mode.
+ * @private {boolean}
+ */
+ this.pdfPrinterEnabled_ = false;
+
+ /**
+ * ID of the system default destination.
+ * @private {string}
+ */
+ this.systemDefaultDestinationId_ = '';
+
+ /**
+ * Used to fetch cloud-based print destinations.
+ * @private {cloudprint.CloudPrintInterface}
+ */
+ this.cloudPrintInterface_ = null;
+
+ /**
+ * Maps user account to the list of origins for which destinations are
+ * already loaded.
+ * @private {!Object<Array<!print_preview.DestinationOrigin>>}
+ */
+ this.loadedCloudOrigins_ = {};
+
+ /**
+ * ID of a timeout after the initial destination ID is set. If no inserted
+ * destination matches the initial destination ID after the specified
+ * timeout, the first destination in the store will be automatically
+ * selected.
+ * @private {?number}
+ */
+ this.autoSelectTimeout_ = null;
+
+ /**
+ * Whether a search for destinations is in progress for each type of
+ * printer.
+ * @private {!Map<!print_preview.PrinterType,
+ * !print_preview.DestinationStorePrinterSearchStatus>}
+ */
+ this.destinationSearchStatus_ = new Map([
+ [
+ print_preview.PrinterType.EXTENSION_PRINTER,
+ print_preview.DestinationStorePrinterSearchStatus.START
+ ],
+ [
+ print_preview.PrinterType.PRIVET_PRINTER,
+ print_preview.DestinationStorePrinterSearchStatus.START
+ ],
+ [
+ print_preview.PrinterType.LOCAL_PRINTER,
+ print_preview.DestinationStorePrinterSearchStatus.START
+ ]
+ ]);
+
+ /**
+ * MDNS service name of destination that we are waiting to register.
+ * @private {?string}
+ */
+ this.waitForRegisterDestination_ = null;
+
+ /**
+ * Local destinations are CROS destinations on ChromeOS because they
+ * require extra setup.
+ * @private {!print_preview.DestinationOrigin}
+ */
+ this.platformOrigin_ = cr.isChromeOS ?
+ print_preview.DestinationOrigin.CROS :
+ print_preview.DestinationOrigin.LOCAL;
+
+ /**
+ * Whether to default to the system default printer instead of the most
+ * recent destination.
+ * @private {boolean}
+ */
+ this.useSystemDefaultAsDefault_ =
+ loadTimeData.getBoolean('useSystemDefaultPrinter');
+
+ this.reset_();
+
+ this.addWebUIEventListeners_(listenerTracker);
+ }
/**
* @param {?string=} opt_account Account to filter destinations by. When
@@ -506,14 +278,14 @@ cr.define('print_preview', function() {
* @return {!Array<!print_preview.Destination>} List of destinations
* accessible by the {@code account}.
*/
- destinations: function(opt_account) {
+ destinations(opt_account) {
if (opt_account) {
return this.destinations_.filter(function(destination) {
return !destination.account || destination.account == opt_account;
});
}
return this.destinations_.slice(0);
- },
+ }
/**
* @return {print_preview.Destination} The currently selected destination or
@@ -521,22 +293,23 @@ cr.define('print_preview', function() {
*/
get selectedDestination() {
return this.selectedDestination_;
- },
+ }
/** @return {boolean} Whether destination selection is pending or not. */
get isAutoSelectDestinationInProgress() {
return this.selectedDestination_ == null &&
this.autoSelectTimeout_ != null;
- },
+ }
/**
* @return {boolean} Whether a search for local destinations is in progress.
*/
get isLocalDestinationSearchInProgress() {
- return this.isLocalDestinationSearchInProgress_ ||
- this.isPrivetDestinationSearchInProgress_ ||
- this.isExtensionDestinationSearchInProgress_;
- },
+ return Array.from(this.destinationSearchStatus_.values())
+ .some(
+ el => el ===
+ print_preview.DestinationStorePrinterSearchStatus.SEARCHING);
+ }
/**
* @return {boolean} Whether a search for cloud destinations is in progress.
@@ -544,7 +317,7 @@ cr.define('print_preview', function() {
get isCloudDestinationSearchInProgress() {
return !!this.cloudPrintInterface_ &&
this.cloudPrintInterface_.isCloudDestinationSearchInProgress;
- },
+ }
/**
* Starts listening for relevant WebUI events and adds the listeners to
@@ -553,15 +326,11 @@ cr.define('print_preview', function() {
* @param {!WebUIListenerTracker} listenerTracker
* @private
*/
- addWebUIEventListeners_: function(listenerTracker) {
- listenerTracker.add(
- 'privet-printer-added', this.onPrivetPrinterAdded_.bind(this));
- listenerTracker.add(
- 'extension-printers-added',
- this.onExtensionPrintersAdded_.bind(this));
+ addWebUIEventListeners_(listenerTracker) {
+ listenerTracker.add('printers-added', this.onPrintersAdded_.bind(this));
listenerTracker.add(
'reload-printer-list', this.onDestinationsReload.bind(this));
- },
+ }
/**
* Initializes the destination store. Sets the initially selected
@@ -570,12 +339,12 @@ cr.define('print_preview', function() {
* print_preview.AppState has been initialized.
* @param {boolean} isInAppKioskMode Whether the print preview is in App
* Kiosk mode.
- * @param {?string} systemDefaultDestinationId ID of the system default
+ * @param {string} systemDefaultDestinationId ID of the system default
* destination.
* @param {?string} serializedDefaultDestinationSelectionRulesStr Serialized
* default destination selection rules.
*/
- init: function(
+ init(
isInAppKioskMode, systemDefaultDestinationId,
serializedDefaultDestinationSelectionRulesStr) {
this.pdfPrinterEnabled_ = !isInAppKioskMode;
@@ -591,7 +360,7 @@ cr.define('print_preview', function() {
}
}
- if (!this.systemDefaultDestinationId_ &&
+ if (this.systemDefaultDestinationId_.length == 0 &&
!this.appState_.isSelectedDestinationValid()) {
this.selectPdfDestination_();
return;
@@ -615,7 +384,7 @@ cr.define('print_preview', function() {
origin = this.appState_.recentDestinations[i].origin;
id = this.appState_.recentDestinations[i].id;
account = this.appState_.recentDestinations[i].account || '';
- name = this.appState_.recentDestinations[i].name || '';
+ name = this.appState_.recentDestinations[i].displayName || '';
capabilities = this.appState_.recentDestinations[i].capabilities;
extensionId = this.appState_.recentDestinations[i].extensionId || '';
extensionName =
@@ -639,7 +408,7 @@ cr.define('print_preview', function() {
return;
// Try the system default
- id = this.systemDefaultDestinationId_ || '';
+ id = this.systemDefaultDestinationId_;
origin = id == print_preview.Destination.GooglePromotedId.SAVE_AS_PDF ?
print_preview.DestinationOrigin.LOCAL :
this.platformOrigin_;
@@ -658,12 +427,12 @@ cr.define('print_preview', function() {
}
this.selectPdfDestination_();
- },
+ }
/**
* Attempts to fetch capabilities of the destination identified by the
* provided origin, id and account.
- * @param {string | print_preview.DestinationOrigin} origin Destination
+ * @param {print_preview.DestinationOrigin} origin Destination
* origin.
* @param {string} id Destination id.
* @param {string} account User account destination is registered for.
@@ -676,67 +445,46 @@ cr.define('print_preview', function() {
* @return {boolean} Whether capabilities fetch was successfully started.
* @private
*/
- fetchPreselectedDestination_: function(
+ fetchPreselectedDestination_(
origin, id, account, name, capabilities, extensionId, extensionName) {
this.autoSelectMatchingDestination_ =
this.createExactDestinationMatch_(origin, id);
- if (origin == print_preview.DestinationOrigin.LOCAL ||
- origin == print_preview.DestinationOrigin.CROS) {
- this.nativeLayer_.getPrinterCapabilities(id).then(
- this.onLocalDestinationCapabilitiesSet_.bind(this),
- this.onGetCapabilitiesFail_.bind(
- this,
- /** @type {print_preview.DestinationOrigin} */ (origin), id));
+ var type = print_preview.originToType(origin);
+ if (type == print_preview.PrinterType.LOCAL_PRINTER) {
+ this.nativeLayer_.getPrinterCapabilities(id, type).then(
+ this.onCapabilitiesSet_.bind(this, origin, id),
+ this.onGetCapabilitiesFail_.bind(this, origin, id));
return true;
}
if (this.cloudPrintInterface_ &&
(origin == print_preview.DestinationOrigin.COOKIES ||
origin == print_preview.DestinationOrigin.DEVICE)) {
- this.cloudPrintInterface_.printer(
- id,
- /** @type {print_preview.DestinationOrigin} */ (origin), account);
+ this.cloudPrintInterface_.printer(id, origin, account);
return true;
}
- if (origin == print_preview.DestinationOrigin.PRIVET) {
+ if (origin == print_preview.DestinationOrigin.PRIVET ||
+ origin == print_preview.DestinationOrigin.EXTENSION) {
// TODO(noamsml): Resolve a specific printer instead of listing all
- // privet printers in this case.
- this.nativeLayer_.getPrivetPrinters().then(
- this.endPrivetPrinterSearch_.bind(this));
+ // privet or extension printers in this case.
+ this.startLoadDestinations(type);
// Create a fake selectedDestination_ that is not actually in the
// destination store. When the real destination is created, this
// destination will be overwritten.
- this.selectedDestination_ = new print_preview.Destination(
- id, print_preview.DestinationType.LOCAL,
- print_preview.DestinationOrigin.PRIVET, name, false /*isRecent*/,
- print_preview.DestinationConnectionStatus.ONLINE);
-
- if (capabilities) {
- this.selectedDestination_.capabilities = capabilities;
-
- cr.dispatchSimpleEvent(
- this,
- DestinationStore.EventType
- .CACHED_SELECTED_DESTINATION_INFO_READY);
- }
- return true;
- }
-
- if (origin == print_preview.DestinationOrigin.EXTENSION) {
- // TODO(tbarzic): Add support for requesting a single extension's
- // printer list.
- this.startLoadExtensionDestinations();
-
- this.selectedDestination_ =
- print_preview.ExtensionDestinationParser.parse({
+ var params =
+ (origin === print_preview.DestinationOrigin.PRIVET) ? {} : {
+ description: '',
extensionId: extensionId,
extensionName: extensionName,
- id: id,
- name: name
- });
+ provisionalType: print_preview.DestinationProvisionalType.NONE
+ };
+ this.selectedDestination_ = new print_preview.Destination(
+ id, print_preview.DestinationType.LOCAL, origin, name,
+ false /*isRecent*/,
+ print_preview.DestinationConnectionStatus.ONLINE, params);
if (capabilities) {
this.selectedDestination_.capabilities = capabilities;
@@ -748,37 +496,27 @@ cr.define('print_preview', function() {
}
return true;
}
-
return false;
- },
+ }
/**
* Attempts to find a destination matching the provided rules.
* @param {!print_preview.DestinationMatch} destinationMatch Rules to match.
* @private
*/
- fetchMatchingDestination_: function(destinationMatch) {
+ fetchMatchingDestination_(destinationMatch) {
this.autoSelectMatchingDestination_ = destinationMatch;
-
- if (destinationMatch.matchOrigin(print_preview.DestinationOrigin.LOCAL) ||
- destinationMatch.matchOrigin(print_preview.DestinationOrigin.CROS)) {
- this.startLoadLocalDestinations();
- }
- if (destinationMatch.matchOrigin(
- print_preview.DestinationOrigin.PRIVET)) {
- this.startLoadPrivetDestinations();
- }
- if (destinationMatch.matchOrigin(
- print_preview.DestinationOrigin.EXTENSION)) {
- this.startLoadExtensionDestinations();
- }
- if (destinationMatch.matchOrigin(
+ var type = destinationMatch.getType();
+ if (type != null) { // Local, Privet, or Extension.
+ this.startLoadDestinations(type);
+ } else if (
+ destinationMatch.matchOrigin(
print_preview.DestinationOrigin.COOKIES) ||
destinationMatch.matchOrigin(
print_preview.DestinationOrigin.DEVICE)) {
this.startLoadCloudDestinations();
}
- },
+ }
/**
* @param {?string} serializedDefaultDestinationSelectionRulesStr Serialized
@@ -787,8 +525,7 @@ cr.define('print_preview', function() {
* previously selected destination.
* @private
*/
- convertToDestinationMatch_: function(
- serializedDefaultDestinationSelectionRulesStr) {
+ convertToDestinationMatch_(serializedDefaultDestinationSelectionRulesStr) {
var matchRules = null;
try {
if (serializedDefaultDestinationSelectionRulesStr) {
@@ -841,25 +578,25 @@ cr.define('print_preview', function() {
return new print_preview.DestinationMatch(
origins, idRegExp, displayNameRegExp,
true /*skipVirtualDestinations*/);
- },
+ }
/**
* @return {print_preview.DestinationMatch} Creates rules matching
* previously selected destination.
* @private
*/
- convertPreselectedToDestinationMatch_: function() {
+ convertPreselectedToDestinationMatch_() {
if (this.appState_.isSelectedDestinationValid()) {
return this.createExactDestinationMatch_(
this.appState_.selectedDestination.origin,
this.appState_.selectedDestination.id);
}
- if (this.systemDefaultDestinationId_) {
+ if (this.systemDefaultDestinationId_.length > 0) {
return this.createExactDestinationMatch_(
this.platformOrigin_, this.systemDefaultDestinationId_);
}
return null;
- },
+ }
/**
* @param {string | print_preview.DestinationOrigin} origin Destination
@@ -869,19 +606,19 @@ cr.define('print_preview', function() {
* provided destination.
* @private
*/
- createExactDestinationMatch_: function(origin, id) {
+ createExactDestinationMatch_(origin, id) {
return new print_preview.DestinationMatch(
[origin],
new RegExp('^' + id.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') + '$'),
null /*displayNameRegExp*/, false /*skipVirtualDestinations*/);
- },
+ }
/**
* Sets the destination store's Google Cloud Print interface.
* @param {!cloudprint.CloudPrintInterface} cloudPrintInterface Interface
* to set.
*/
- setCloudPrintInterface: function(cloudPrintInterface) {
+ setCloudPrintInterface(cloudPrintInterface) {
assert(this.cloudPrintInterface_ == null);
this.cloudPrintInterface_ = cloudPrintInterface;
this.tracker_.add(
@@ -904,12 +641,12 @@ cr.define('print_preview', function() {
this.cloudPrintInterface_,
cloudprint.CloudPrintInterfaceEventType.PROCESS_INVITE_DONE,
this.onCloudPrintProcessInviteDone_.bind(this));
- },
+ }
/**
* @param {print_preview.Destination} destination Destination to select.
*/
- selectDestination: function(destination) {
+ selectDestination(destination) {
this.autoSelectMatchingDestination_ = null;
// When auto select expires, DESTINATION_SELECT event has to be dispatched
// anyway (see isAutoSelectDestinationInProgress() logic).
@@ -952,24 +689,14 @@ cr.define('print_preview', function() {
// Request destination capabilities from backend, since they are not
// known yet.
if (destination.capabilities == null) {
- if (destination.isPrivet) {
- this.nativeLayer_.getPrivetPrinterCapabilities(destination.id)
- .then(
- this.onPrivetCapabilitiesSet_.bind(this),
- this.onGetCapabilitiesFail_.bind(
- this, destination.origin, destination.id));
- } else if (destination.isExtension) {
- this.nativeLayer_.getExtensionPrinterCapabilities(destination.id)
+ var type = print_preview.originToType(destination.origin);
+ if (type !== null) {
+ this.nativeLayer_.getPrinterCapabilities(destination.id, type)
.then(
- this.onExtensionCapabilitiesSet_.bind(this, destination.id),
- this.onGetCapabilitiesFail_.bind(
- this, destination.origin, destination.id));
- } else if (destination.isLocal) {
- this.nativeLayer_.getPrinterCapabilities(destination.id)
- .then(
- this.onLocalDestinationCapabilitiesSet_.bind(this),
- this.onGetCapabilitiesFail_.bind(
- this, destination.origin, destination.id));
+ (caps) => this.onCapabilitiesSet_(
+ destination.origin, destination.id, caps),
+ () => this.onGetCapabilitiesFail_(
+ destination.origin, destination.origin));
} else {
assert(
this.cloudPrintInterface_ != null,
@@ -982,7 +709,7 @@ cr.define('print_preview', function() {
this,
DestinationStore.EventType.SELECTED_DESTINATION_CAPABILITIES_READY);
}
- },
+ }
/**
* Attempt to resolve the capabilities for a Chrome OS printer.
@@ -990,17 +717,17 @@ cr.define('print_preview', function() {
* requires resolution.
* @return {!Promise<!print_preview.PrinterSetupResponse>}
*/
- resolveCrosDestination: function(destination) {
+ resolveCrosDestination(destination) {
assert(destination.origin == print_preview.DestinationOrigin.CROS);
return this.nativeLayer_.setupPrinter(destination.id);
- },
+ }
/**
* Attempts to resolve a provisional destination.
* @param {!print_preview.Destination} destination Provisional destination
* that should be resolved.
*/
- resolveProvisionalDestination: function(destination) {
+ resolveProvisionalDestination(destination) {
assert(
destination.provisionalType ==
print_preview.DestinationProvisionalType.NEEDS_USB_PERMISSION,
@@ -1016,8 +743,7 @@ cr.define('print_preview', function() {
*/
this.removeProvisionalDestination_(destination.id);
var parsedDestination =
- print_preview.ExtensionDestinationParser.parse(
- destinationInfo);
+ print_preview.parseExtensionDestination(destinationInfo);
this.insertIntoStore_(parsedDestination);
this.dispatchProvisionalDestinationResolvedEvent_(
destination.id, parsedDestination);
@@ -1032,27 +758,27 @@ cr.define('print_preview', function() {
this.dispatchProvisionalDestinationResolvedEvent_(
destination.id, null);
});
- },
+ }
/**
* Selects 'Save to PDF' destination (since it always exists).
* @private
*/
- selectPdfDestination_: function() {
+ selectPdfDestination_() {
var saveToPdfKey = this.getDestinationKey_(
print_preview.DestinationOrigin.LOCAL,
print_preview.Destination.GooglePromotedId.SAVE_AS_PDF, '');
this.selectDestination(
this.destinationMap_[saveToPdfKey] || this.destinations_[0] || null);
- },
+ }
/**
* Attempts to select system default destination with a fallback to
* 'Save to PDF' destination.
* @private
*/
- selectDefaultDestination_: function() {
- if (this.systemDefaultDestinationId_) {
+ selectDefaultDestination_() {
+ if (this.systemDefaultDestinationId_.length > 0) {
if (this.autoSelectMatchingDestination_ &&
!this.autoSelectMatchingDestination_.matchIdAndOrigin(
this.systemDefaultDestinationId_, this.platformOrigin_)) {
@@ -1065,59 +791,37 @@ cr.define('print_preview', function() {
}
}
this.selectPdfDestination_();
- },
-
- /** Initiates loading of local print destinations. */
- startLoadLocalDestinations: function() {
- if (!this.hasLoadedAllLocalDestinations_) {
- this.hasLoadedAllLocalDestinations_ = true;
- this.nativeLayer_.getPrinters().then(
- this.onLocalDestinationsSet_.bind(this));
- this.isLocalDestinationSearchInProgress_ = true;
- cr.dispatchSimpleEvent(
- this, DestinationStore.EventType.DESTINATION_SEARCH_STARTED);
- }
- },
+ }
- /** Initiates loading of privet print destinations. */
- startLoadPrivetDestinations: function() {
- if (this.hasLoadedAllPrivetDestinations_)
+ /**
+ * Initiates loading of destinations.
+ * @param{print_preview.PrinterType} type The type of destinations to load.
+ */
+ startLoadDestinations(type) {
+ if (this.destinationSearchStatus_.get(type) ===
+ print_preview.DestinationStorePrinterSearchStatus.DONE) {
return;
- this.isPrivetDestinationSearchInProgress_ = true;
- this.nativeLayer_.getPrivetPrinters().then(
- this.endPrivetPrinterSearch_.bind(this), () => {
- // Rejected by C++, indicating privet printing is disabled.
- this.hasLoadedAllPrivetDestinations_ = true;
- this.isPrivetDestinationSearchInProgress_ = false;
+ }
+ this.destinationSearchStatus_.set(
+ type, print_preview.DestinationStorePrinterSearchStatus.SEARCHING);
+ this.nativeLayer_.getPrinters(type).then(
+ this.onDestinationSearchDone_.bind(this, type), () => {
+ // Will be rejected by C++ for privet printers if privet printing
+ // is disabled.
+ assert(type === print_preview.PrinterType.PRIVET_PRINTER);
+ this.destinationSearchStatus_.set(
+ type, print_preview.DestinationStorePrinterSearchStatus.DONE);
});
cr.dispatchSimpleEvent(
this, DestinationStore.EventType.DESTINATION_SEARCH_STARTED);
- },
-
- /** Initializes loading of extension managed print destinations. */
- startLoadExtensionDestinations: function() {
- if (this.hasLoadedAllExtensionDestinations_)
- return;
-
- if (this.isExtensionDestinationSearchInProgress_)
- clearTimeout(this.extensionSearchTimeout_);
-
- this.isExtensionDestinationSearchInProgress_ = true;
- this.nativeLayer_.getExtensionPrinters().then(
- this.onExtensionPrintersDone_.bind(this));
- cr.dispatchSimpleEvent(
- this, DestinationStore.EventType.DESTINATION_SEARCH_STARTED);
- this.extensionSearchTimeout_ = setTimeout(
- this.endExtensionPrinterSearch_.bind(this),
- DestinationStore.EXTENSION_SEARCH_DURATION_);
- },
+ }
/**
* Initiates loading of cloud destinations.
* @param {print_preview.DestinationOrigin=} opt_origin Search destinations
* for the specified origin only.
*/
- startLoadCloudDestinations: function(opt_origin) {
+ startLoadCloudDestinations(opt_origin) {
if (this.cloudPrintInterface_ != null) {
var origins = this.loadedCloudOrigins_[this.userInfo_.activeUser] || [];
if (origins.length == 0 ||
@@ -1128,10 +832,10 @@ cr.define('print_preview', function() {
this, DestinationStore.EventType.DESTINATION_SEARCH_STARTED);
}
}
- },
+ }
/** Requests load of COOKIE based cloud destinations. */
- reloadUserCookieBasedDestinations: function() {
+ reloadUserCookieBasedDestinations() {
var origins = this.loadedCloudOrigins_[this.userInfo_.activeUser] || [];
if (origins.indexOf(print_preview.DestinationOrigin.COOKIES) >= 0) {
cr.dispatchSimpleEvent(
@@ -1140,24 +844,26 @@ cr.define('print_preview', function() {
this.startLoadCloudDestinations(
print_preview.DestinationOrigin.COOKIES);
}
- },
+ }
/** Initiates loading of all known destination types. */
- startLoadAllDestinations: function() {
+ startLoadAllDestinations() {
this.startLoadCloudDestinations();
- this.startLoadLocalDestinations();
- this.startLoadPrivetDestinations();
- this.startLoadExtensionDestinations();
- },
+ for (var printerType of Object.values(print_preview.PrinterType)) {
+ if (printerType !== print_preview.PrinterType.PDF_PRINTER)
+ this.startLoadDestinations(printerType);
+ }
+ }
/**
* Wait for a privet device to be registered.
*/
- waitForRegister: function(id) {
- this.nativeLayer_.getPrivetPrinters().then(
- this.endPrivetPrinterSearch_.bind(this));
+ waitForRegister(id) {
+ var privetType = print_preview.PrinterType.PRIVET_PRINTER;
+ this.nativeLayer_.getPrinters(privetType)
+ .then(this.onDestinationSearchDone_.bind(this, privetType));
this.waitForRegisterDestination_ = id;
- },
+ }
/**
* Removes the provisional destination with ID |provisionalId| from
@@ -1165,7 +871,7 @@ cr.define('print_preview', function() {
* @param{string} provisionalId The provisional destination ID.
* @private
*/
- removeProvisionalDestination_: function(provisionalId) {
+ removeProvisionalDestination_(provisionalId) {
this.destinations_ = this.destinations_.filter(
function(el) {
if (el.id == provisionalId) {
@@ -1174,7 +880,7 @@ cr.define('print_preview', function() {
}
return true;
}, this);
- },
+ }
/**
* Dispatches the PROVISIONAL_DESTINATION_RESOLVED event for id
@@ -1184,14 +890,13 @@ cr.define('print_preview', function() {
* @param {?print_preview.Destination} destination Information about the
* destination if it was resolved successfully.
*/
- dispatchProvisionalDestinationResolvedEvent_: function(
- provisionalId, destination) {
+ dispatchProvisionalDestinationResolvedEvent_(provisionalId, destination) {
var event = new Event(
DestinationStore.EventType.PROVISIONAL_DESTINATION_RESOLVED);
event.provisionalId = provisionalId;
event.destination = destination;
this.dispatchEvent(event);
- },
+ }
/**
* Inserts {@code destination} to the data store and dispatches a
@@ -1200,28 +905,36 @@ cr.define('print_preview', function() {
* insert.
* @private
*/
- insertDestination_: function(destination) {
+ insertDestination_(destination) {
if (this.insertIntoStore_(destination)) {
this.destinationsInserted_(destination);
}
- },
+ }
/**
* Inserts multiple {@code destinations} to the data store and dispatches
* single DESTINATIONS_INSERTED event.
- * @param {!Array<print_preview.Destination>} destinations Print
+ * @param {!Array<!print_preview.Destination |
+ * !Array<print_preview.Destination>>} destinations Print
* destinations to insert.
* @private
*/
- insertDestinations_: function(destinations) {
+ insertDestinations_(destinations) {
var inserted = false;
- destinations.forEach(function(destination) {
- inserted = this.insertIntoStore_(destination) || inserted;
- }, this);
+ destinations.forEach(destination => {
+ if (Array.isArray(destination)) {
+ // privet printers return arrays of 1 or 2 printers
+ inserted = destination.reduce(function(soFar, d) {
+ return this.insertIntoStore_(d) || soFar;
+ }, inserted);
+ } else {
+ inserted = this.insertIntoStore_(destination) || inserted;
+ }
+ });
if (inserted) {
this.destinationsInserted_();
}
- },
+ }
/**
* Dispatches DESTINATIONS_INSERTED event. In auto select mode, tries to
@@ -1232,7 +945,7 @@ cr.define('print_preview', function() {
* changed. Used as a hint to limit destination search scope against
* {@code autoSelectMatchingDestination_}.
*/
- destinationsInserted_: function(opt_destination) {
+ destinationsInserted_(opt_destination) {
cr.dispatchSimpleEvent(
this, DestinationStore.EventType.DESTINATIONS_INSERTED);
if (this.autoSelectMatchingDestination_) {
@@ -1245,7 +958,7 @@ cr.define('print_preview', function() {
}
}, this);
}
- },
+ }
/**
* Updates an existing print destination with capabilities and display name
@@ -1253,12 +966,14 @@ cr.define('print_preview', function() {
* @param {!print_preview.Destination} destination Destination to update.
* @private
*/
- updateDestination_: function(destination) {
+ updateDestination_(destination) {
assert(destination.constructor !== Array, 'Single printer expected');
- destination.capabilities_ = DestinationStore.localizeCapabilities_(
- assert(destination.capabilities_));
destination.capabilities_ =
- DestinationStore.sortMediaSizes_(destination.capabilities_);
+ localizeCapabilities(assert(destination.capabilities_));
+ if (print_preview.originToType(destination.origin) !==
+ print_preview.PrinterType.LOCAL_PRINTER) {
+ destination.capabilities_ = sortMediaSizes(destination.capabilities_);
+ }
var existingDestination = this.destinationMap_[this.getKey_(destination)];
if (existingDestination != null) {
existingDestination.capabilities = destination.capabilities;
@@ -1274,28 +989,13 @@ cr.define('print_preview', function() {
this,
DestinationStore.EventType.SELECTED_DESTINATION_CAPABILITIES_READY);
}
- },
-
- /**
- * Called when the search for Privet printers is done.
- * @private
- */
- endPrivetPrinterSearch_: function() {
- this.isPrivetDestinationSearchInProgress_ = false;
- this.hasLoadedAllPrivetDestinations_ = true;
- cr.dispatchSimpleEvent(
- this, DestinationStore.EventType.DESTINATION_SEARCH_DONE);
- },
+ }
/**
* Called when loading of extension managed printers is done.
* @private
*/
- endExtensionPrinterSearch_: function() {
- this.isExtensionDestinationSearchInProgress_ = false;
- this.hasLoadedAllExtensionDestinations_ = true;
- cr.dispatchSimpleEvent(
- this, DestinationStore.EventType.DESTINATION_SEARCH_DONE);
+ endExtensionPrinterSearch_() {
// Clear initially selected (cached) extension destination if it hasn't
// been found among reported extension destinations.
if (this.autoSelectMatchingDestination_ &&
@@ -1304,15 +1004,17 @@ cr.define('print_preview', function() {
this.selectedDestination_ && this.selectedDestination_.isExtension) {
this.selectDefaultDestination_();
}
- },
+ }
/**
* Inserts a destination into the store without dispatching any events.
+ * @param {!print_preview.Destination} destination The destination to be
+ * inserted.
* @return {boolean} Whether the inserted destination was not already in the
* store.
* @private
*/
- insertIntoStore_: function(destination) {
+ insertIntoStore_(destination) {
var key = this.getKey_(destination);
var existingDestination = this.destinationMap_[key];
if (existingDestination == null) {
@@ -1334,13 +1036,13 @@ cr.define('print_preview', function() {
return true;
}
return false;
- },
+ }
/**
* Creates a local PDF print destination.
* @private
*/
- createLocalPdfPrintDestination_: function() {
+ createLocalPdfPrintDestination_() {
// TODO(alekseys): Create PDF printer in the native code and send its
// capabilities back with other local printers.
if (this.pdfPrinterEnabled_) {
@@ -1351,100 +1053,86 @@ cr.define('print_preview', function() {
loadTimeData.getString('printToPDF'), false /*isRecent*/,
print_preview.DestinationConnectionStatus.ONLINE));
}
- },
+ }
/**
* Resets the state of the destination store to its initial state.
* @private
*/
- reset_: function() {
+ reset_() {
this.destinations_ = [];
this.destinationMap_ = {};
this.selectDestination(null);
this.loadedCloudOrigins_ = {};
- this.hasLoadedAllLocalDestinations_ = false;
- this.hasLoadedAllPrivetDestinations_ = false;
- this.hasLoadedAllExtensionDestinations_ = false;
+ for (var printerType of Object.values(print_preview.PrinterType)) {
+ if (printerType !== print_preview.PrinterType.PDF_PRINTER) {
+ this.destinationSearchStatus_.set(
+ printerType,
+ print_preview.DestinationStorePrinterSearchStatus.START);
+ }
+ }
clearTimeout(this.autoSelectTimeout_);
this.autoSelectTimeout_ = setTimeout(
this.selectDefaultDestination_.bind(this),
DestinationStore.AUTO_SELECT_TIMEOUT_);
- },
+ }
+
/**
- * Called when the local destinations have been got from the native layer.
- * @param {!Array<!print_preview.LocalDestinationInfo>} destinationInfos A
- * list of the local destinations retrieved.
- * @private
+ * Called when destination search is complete for some type of printer.
+ * @param {!print_preview.PrinterType} type The type of printers that are
+ * done being retreived.
*/
- onLocalDestinationsSet_: function(destinationInfos) {
- var localDestinations = destinationInfos.map(function(destInfo) {
- return print_preview.LocalDestinationParser.parse(destInfo);
- });
- this.insertDestinations_(localDestinations);
- this.isLocalDestinationSearchInProgress_ = false;
+ onDestinationSearchDone_(type) {
+ this.destinationSearchStatus_.set(
+ type, print_preview.DestinationStorePrinterSearchStatus.DONE);
cr.dispatchSimpleEvent(
this, DestinationStore.EventType.DESTINATION_SEARCH_DONE);
- },
+ if (type === print_preview.PrinterType.EXTENSION_PRINTER)
+ this.endExtensionPrinterSearch_();
+ }
/**
* Called when the native layer retrieves the capabilities for the selected
* local destination. Updates the destination with new capabilities if the
* destination already exists, otherwise it creates a new destination and
* then updates its capabilities.
- * @param {print_preview.PrinterCapabilitiesResponse} settingsInfo Contains
- * information about and capabilities of the local print destination.
+ * @param {!print_preview.DestinationOrigin} origin The origin of the
+ * print destination.
+ * @param {string} id The id of the print destination.
+ * @param {!print_preview.CapabilitiesResponse} settingsInfo Contains
+ * the capabilities of the print destination, and information about
+ * the destination except in the case of extension printers.
* @private
*/
- onLocalDestinationCapabilitiesSet_: function(settingsInfo) {
- var destinationId = settingsInfo['printerId'];
- var printerName = settingsInfo['printerName'];
- var printerDescription = settingsInfo['printerDescription'];
- // PDF is special since we don't need to query the device for
- // capabilities.
- var origin = destinationId ==
- print_preview.Destination.GooglePromotedId.SAVE_AS_PDF ?
- print_preview.DestinationOrigin.LOCAL :
- this.platformOrigin_;
- var key = this.getDestinationKey_(origin, destinationId, '');
- var destination = this.destinationMap_[key];
- var capabilities =
- DestinationStore.localizeCapabilities_(settingsInfo.capabilities);
- // Special case for PDF printer (until local printers capabilities are
- // reported in CDD format too).
- if (destinationId ==
- print_preview.Destination.GooglePromotedId.SAVE_AS_PDF) {
- if (destination) {
- destination.capabilities = capabilities;
+ onCapabilitiesSet_(origin, id, settingsInfo) {
+ var dest = null;
+ if (origin !== print_preview.DestinationOrigin.PRIVET) {
+ var key = this.getDestinationKey_(origin, id, '');
+ dest = this.destinationMap_[key];
+ }
+ if (!dest) {
+ // Ignore unrecognized extension printers
+ if (!settingsInfo.printer) {
+ assert(origin === print_preview.DestinationOrigin.EXTENSION);
+ return;
}
- } else {
- if (destination) {
- // In case there were multiple capabilities request for this local
- // destination, just ignore the later ones.
- if (destination.capabilities != null) {
- return;
- }
- destination.capabilities = capabilities;
+ dest = print_preview.parseDestination(
+ print_preview.originToType(origin), assert(settingsInfo.printer));
+ }
+ if (dest) {
+ var updateDestination = destination => {
+ destination.capabilities = settingsInfo.capabilities;
+ this.updateDestination_(destination);
+ };
+ if (Array.isArray(dest)) {
+ dest.forEach(updateDestination);
} else {
- var isEnterprisePrinter = settingsInfo['cupsEnterprisePrinter'];
- destination = print_preview.LocalDestinationParser.parse({
- deviceName: destinationId,
- printerName: printerName,
- cupsEnterprisePrinter: isEnterprisePrinter,
- printerDescription: printerDescription
- });
- destination.capabilities = capabilities;
- this.insertDestination_(destination);
+ updateDestination(dest);
}
}
- if (this.selectedDestination_ &&
- this.selectedDestination_.id == destinationId) {
- cr.dispatchSimpleEvent(
- this,
- DestinationStore.EventType.SELECTED_DESTINATION_CAPABILITIES_READY);
- }
- },
+ }
/**
* Called when a request to get a local destination's print capabilities
@@ -1455,15 +1143,22 @@ cr.define('print_preview', function() {
* @param {string} destinationId The destination ID that failed.
* @private
*/
- onGetCapabilitiesFail_: function(origin, destinationId) {
+ onGetCapabilitiesFail_(origin, destinationId) {
console.warn(
'Failed to get print capabilities for printer ' + destinationId);
+ if (this.selectedDestination_ &&
+ this.selectedDestination_.id == destinationId) {
+ var event =
+ new Event(DestinationStore.EventType.SELECTED_DESTINATION_INVALID);
+ event.destinationId = destinationId;
+ this.dispatchEvent(event);
+ }
if (this.autoSelectMatchingDestination_ &&
this.autoSelectMatchingDestination_.matchIdAndOrigin(
destinationId, origin)) {
this.selectDefaultDestination_();
}
- },
+ }
/**
* Called when the /search call completes, either successfully or not.
@@ -1471,7 +1166,7 @@ cr.define('print_preview', function() {
* @param {Event} event Contains the request result.
* @private
*/
- onCloudPrintSearchDone_: function(event) {
+ onCloudPrintSearchDone_(event) {
if (event.printers) {
this.insertDestinations_(event.printers);
}
@@ -1483,7 +1178,7 @@ cr.define('print_preview', function() {
}
cr.dispatchSimpleEvent(
this, DestinationStore.EventType.DESTINATION_SEARCH_DONE);
- },
+ }
/**
* Called when /printer call completes. Updates the specified destination's
@@ -1492,9 +1187,9 @@ cr.define('print_preview', function() {
* destination.
* @private
*/
- onCloudPrintPrinterDone_: function(event) {
+ onCloudPrintPrinterDone_(event) {
this.updateDestination_(event.printer);
- },
+ }
/**
* Called when the Google Cloud Print interface fails to lookup a
@@ -1504,7 +1199,7 @@ cr.define('print_preview', function() {
* to be looked up.
* @private
*/
- onCloudPrintPrinterFailed_: function(event) {
+ onCloudPrintPrinterFailed_(event) {
if (this.autoSelectMatchingDestination_ &&
this.autoSelectMatchingDestination_.matchIdAndOrigin(
event.destinationId, event.destinationOrigin)) {
@@ -1512,7 +1207,7 @@ cr.define('print_preview', function() {
'Failed to fetch last used printer caps: ' + event.destinationId);
this.selectDefaultDestination_();
}
- },
+ }
/**
* Called when printer sharing invitation was processed successfully.
@@ -1520,105 +1215,49 @@ cr.define('print_preview', function() {
* newly accepted destination (if known).
* @private
*/
- onCloudPrintProcessInviteDone_: function(event) {
+ onCloudPrintProcessInviteDone_(event) {
if (event.accept && event.printer) {
// Hint the destination list to promote this new destination.
event.printer.isRecent = true;
this.insertDestination_(event.printer);
}
- },
-
- /**
- * Called when a Privet printer is added to the local network.
- * @param {!{serviceName: string,
- * name: string,
- * hasLocalPrinting: boolean,
- * isUnregistered: boolean,
- * cloudID: string}} printer Information about the added printer.
- * @private
- */
- onPrivetPrinterAdded_: function(printer) {
- if (printer.serviceName == this.waitForRegisterDestination_ &&
- !printer.isUnregistered) {
- this.waitForRegisterDestination_ = null;
- this.onDestinationsReload();
- } else {
- this.insertDestinations_(
- print_preview.PrivetDestinationParser.parse(printer));
- }
- },
-
- /**
- * Called when capabilities for a privet printer are set.
- * @param {!print_preview.PrivetPrinterCapabilitiesResponse} printerInfo
- * Contains the privet printer's description and capabilities.
- * @private
- */
- onPrivetCapabilitiesSet_: function(printerInfo) {
- var destinations =
- print_preview.PrivetDestinationParser.parse(printerInfo.printer);
- destinations.forEach(function(dest) {
- dest.capabilities = printerInfo.capabilities;
- this.updateDestination_(dest);
- }, this);
- },
-
- /**
- * Called when an extension responds to a getExtensionDestinations
- * request.
- * @param {!Array<!{extensionId: string,
- * extensionName: string,
- * id: string,
- * name: string,
- * description: (string|undefined),
- * provisional: (boolean|undefined)}>} printers The list
- * containing information about printers added by an extension.
- * @private
- */
- onExtensionPrintersAdded_: function(printers) {
- this.insertDestinations_(
- printers.map(print_preview.ExtensionDestinationParser.parse));
- },
+ }
/**
- * Called when all extensions are done adding printers.
- * @private
- */
- onExtensionPrintersDone_: function() {
- if (this.isExtensionDestinationSearchInProgress_) {
- clearTimeout(this.extensionSearchTimeout_);
- this.endExtensionPrinterSearch_();
+ * Called when a printer or printers are detected after sending getPrinters
+ * from the native layer.
+ * @param {print_preview.PrinterType} type The type of printer(s) added.
+ * @param {!Array<!print_preview.LocalDestinationInfo |
+ * !print_preview.PrivetPrinterDescription |
+ * !print_preview.ProvisionalDestinationInfo>} printers
+ * Information about the printers that have been retrieved.
+ */
+ onPrintersAdded_(type, printers) {
+ if (type == print_preview.PrinterType.PRIVET_PRINTER) {
+ var printer =
+ /** !print_preview.PrivetPrinterDescription */ (printers[0]);
+ if (printer.serviceName == this.waitForRegisterDestination_ &&
+ !printer.isUnregistered) {
+ this.waitForRegisterDestination_ = null;
+ this.onDestinationsReload();
+ return;
+ }
}
- },
-
- /**
- * Called when capabilities for an extension managed printer are set.
- * @param {string} printerId The printer Id.
- * @param {!print_preview.Cdd} capabilities The printer's capabilities.
- * @private
- */
- onExtensionCapabilitiesSet_: function(printerId, capabilities) {
- var destinationKey = this.getDestinationKey_(
- print_preview.DestinationOrigin.EXTENSION, printerId,
- '' /* account */);
- var destination = this.destinationMap_[destinationKey];
- if (!destination)
- return;
- destination.capabilities = capabilities;
- this.updateDestination_(destination);
- },
+ this.insertDestinations_(printers.map(
+ printer => print_preview.parseDestination(type, printer)));
+ }
/**
* Called from print preview after the user was requested to sign in, and
* did so successfully.
*/
- onDestinationsReload: function() {
+ onDestinationsReload() {
this.reset_();
this.autoSelectMatchingDestination_ =
this.convertPreselectedToDestinationMatch_();
this.createLocalPdfPrintDestination_();
this.startLoadAllDestinations();
- },
+ }
// TODO(vitalybuka): Remove three next functions replacing Destination.id
// and Destination.origin by complex ID.
@@ -1630,19 +1269,232 @@ cr.define('print_preview', function() {
* @param {string} account User account destination is registered for.
* @private
*/
- getDestinationKey_: function(origin, id, account) {
+ getDestinationKey_(origin, id, account) {
return origin + '/' + id + '/' + account;
- },
+ }
/**
* Returns key to be used with {@code destinationMap_}.
* @param {!print_preview.Destination} destination Destination.
* @private
*/
- getKey_: function(destination) {
+ getKey_(destination) {
return this.getDestinationKey_(
destination.origin, destination.id, destination.account);
}
+ }
+
+ /**
+ * Event types dispatched by the data store.
+ * @enum {string}
+ */
+ DestinationStore.EventType = {
+ DESTINATION_SEARCH_DONE:
+ 'print_preview.DestinationStore.DESTINATION_SEARCH_DONE',
+ DESTINATION_SEARCH_STARTED:
+ 'print_preview.DestinationStore.DESTINATION_SEARCH_STARTED',
+ DESTINATION_SELECT: 'print_preview.DestinationStore.DESTINATION_SELECT',
+ DESTINATIONS_INSERTED:
+ 'print_preview.DestinationStore.DESTINATIONS_INSERTED',
+ PROVISIONAL_DESTINATION_RESOLVED:
+ 'print_preview.DestinationStore.PROVISIONAL_DESTINATION_RESOLVED',
+ CACHED_SELECTED_DESTINATION_INFO_READY:
+ 'print_preview.DestinationStore.CACHED_SELECTED_DESTINATION_INFO_READY',
+ SELECTED_DESTINATION_CAPABILITIES_READY: 'print_preview.DestinationStore' +
+ '.SELECTED_DESTINATION_CAPABILITIES_READY',
+ SELECTED_DESTINATION_INVALID:
+ 'print_preview.DestinationStore.SELECTED_DESTINATION_INVALID',
+ };
+
+ /**
+ * Delay in milliseconds before the destination store ignores the initial
+ * destination ID and just selects any printer (since the initial destination
+ * was not found).
+ * @private {number}
+ * @const
+ */
+ DestinationStore.AUTO_SELECT_TIMEOUT_ = 15000;
+
+ /**
+ * Maximum amount of time spent searching for extension destinations, in
+ * milliseconds.
+ * @private {number}
+ * @const
+ */
+ DestinationStore.EXTENSION_SEARCH_DURATION_ = 5000;
+
+ /**
+ * Human readable names for media sizes in the cloud print CDD.
+ * https://developers.google.com/cloud-print/docs/cdd
+ * @private {Object<string>}
+ * @const
+ */
+ DestinationStore.MEDIA_DISPLAY_NAMES_ = {
+ 'ISO_2A0': '2A0',
+ 'ISO_A0': 'A0',
+ 'ISO_A0X3': 'A0x3',
+ 'ISO_A1': 'A1',
+ 'ISO_A10': 'A10',
+ 'ISO_A1X3': 'A1x3',
+ 'ISO_A1X4': 'A1x4',
+ 'ISO_A2': 'A2',
+ 'ISO_A2X3': 'A2x3',
+ 'ISO_A2X4': 'A2x4',
+ 'ISO_A2X5': 'A2x5',
+ 'ISO_A3': 'A3',
+ 'ISO_A3X3': 'A3x3',
+ 'ISO_A3X4': 'A3x4',
+ 'ISO_A3X5': 'A3x5',
+ 'ISO_A3X6': 'A3x6',
+ 'ISO_A3X7': 'A3x7',
+ 'ISO_A3_EXTRA': 'A3 Extra',
+ 'ISO_A4': 'A4',
+ 'ISO_A4X3': 'A4x3',
+ 'ISO_A4X4': 'A4x4',
+ 'ISO_A4X5': 'A4x5',
+ 'ISO_A4X6': 'A4x6',
+ 'ISO_A4X7': 'A4x7',
+ 'ISO_A4X8': 'A4x8',
+ 'ISO_A4X9': 'A4x9',
+ 'ISO_A4_EXTRA': 'A4 Extra',
+ 'ISO_A4_TAB': 'A4 Tab',
+ 'ISO_A5': 'A5',
+ 'ISO_A5_EXTRA': 'A5 Extra',
+ 'ISO_A6': 'A6',
+ 'ISO_A7': 'A7',
+ 'ISO_A8': 'A8',
+ 'ISO_A9': 'A9',
+ 'ISO_B0': 'B0',
+ 'ISO_B1': 'B1',
+ 'ISO_B10': 'B10',
+ 'ISO_B2': 'B2',
+ 'ISO_B3': 'B3',
+ 'ISO_B4': 'B4',
+ 'ISO_B5': 'B5',
+ 'ISO_B5_EXTRA': 'B5 Extra',
+ 'ISO_B6': 'B6',
+ 'ISO_B6C4': 'B6C4',
+ 'ISO_B7': 'B7',
+ 'ISO_B8': 'B8',
+ 'ISO_B9': 'B9',
+ 'ISO_C0': 'C0',
+ 'ISO_C1': 'C1',
+ 'ISO_C10': 'C10',
+ 'ISO_C2': 'C2',
+ 'ISO_C3': 'C3',
+ 'ISO_C4': 'C4',
+ 'ISO_C5': 'C5',
+ 'ISO_C6': 'C6',
+ 'ISO_C6C5': 'C6C5',
+ 'ISO_C7': 'C7',
+ 'ISO_C7C6': 'C7C6',
+ 'ISO_C8': 'C8',
+ 'ISO_C9': 'C9',
+ 'ISO_DL': 'Envelope DL',
+ 'ISO_RA0': 'RA0',
+ 'ISO_RA1': 'RA1',
+ 'ISO_RA2': 'RA2',
+ 'ISO_SRA0': 'SRA0',
+ 'ISO_SRA1': 'SRA1',
+ 'ISO_SRA2': 'SRA2',
+ 'JIS_B0': 'B0 (JIS)',
+ 'JIS_B1': 'B1 (JIS)',
+ 'JIS_B10': 'B10 (JIS)',
+ 'JIS_B2': 'B2 (JIS)',
+ 'JIS_B3': 'B3 (JIS)',
+ 'JIS_B4': 'B4 (JIS)',
+ 'JIS_B5': 'B5 (JIS)',
+ 'JIS_B6': 'B6 (JIS)',
+ 'JIS_B7': 'B7 (JIS)',
+ 'JIS_B8': 'B8 (JIS)',
+ 'JIS_B9': 'B9 (JIS)',
+ 'JIS_EXEC': 'Executive (JIS)',
+ 'JPN_CHOU2': 'Choukei 2',
+ 'JPN_CHOU3': 'Choukei 3',
+ 'JPN_CHOU4': 'Choukei 4',
+ 'JPN_HAGAKI': 'Hagaki',
+ 'JPN_KAHU': 'Kahu Envelope',
+ 'JPN_KAKU2': 'Kaku 2',
+ 'JPN_OUFUKU': 'Oufuku Hagaki',
+ 'JPN_YOU4': 'You 4',
+ 'NA_10X11': '10x11',
+ 'NA_10X13': '10x13',
+ 'NA_10X14': '10x14',
+ 'NA_10X15': '10x15',
+ 'NA_11X12': '11x12',
+ 'NA_11X15': '11x15',
+ 'NA_12X19': '12x19',
+ 'NA_5X7': '5x7',
+ 'NA_6X9': '6x9',
+ 'NA_7X9': '7x9',
+ 'NA_9X11': '9x11',
+ 'NA_A2': 'A2',
+ 'NA_ARCH_A': 'Arch A',
+ 'NA_ARCH_B': 'Arch B',
+ 'NA_ARCH_C': 'Arch C',
+ 'NA_ARCH_D': 'Arch D',
+ 'NA_ARCH_E': 'Arch E',
+ 'NA_ASME_F': 'ASME F',
+ 'NA_B_PLUS': 'B-plus',
+ 'NA_C': 'C',
+ 'NA_C5': 'C5',
+ 'NA_D': 'D',
+ 'NA_E': 'E',
+ 'NA_EDP': 'EDP',
+ 'NA_EUR_EDP': 'European EDP',
+ 'NA_EXECUTIVE': 'Executive',
+ 'NA_F': 'F',
+ 'NA_FANFOLD_EUR': 'FanFold European',
+ 'NA_FANFOLD_US': 'FanFold US',
+ 'NA_FOOLSCAP': 'FanFold German Legal',
+ 'NA_GOVT_LEGAL': 'Government Legal',
+ 'NA_GOVT_LETTER': 'Government Letter',
+ 'NA_INDEX_3X5': 'Index 3x5',
+ 'NA_INDEX_4X6': 'Index 4x6',
+ 'NA_INDEX_4X6_EXT': 'Index 4x6 ext',
+ 'NA_INDEX_5X8': '5x8',
+ 'NA_INVOICE': 'Invoice',
+ 'NA_LEDGER': 'Tabloid', // Ledger in portrait is called Tabloid.
+ 'NA_LEGAL': 'Legal',
+ 'NA_LEGAL_EXTRA': 'Legal extra',
+ 'NA_LETTER': 'Letter',
+ 'NA_LETTER_EXTRA': 'Letter extra',
+ 'NA_LETTER_PLUS': 'Letter plus',
+ 'NA_MONARCH': 'Monarch',
+ 'NA_NUMBER_10': 'Envelope #10',
+ 'NA_NUMBER_11': 'Envelope #11',
+ 'NA_NUMBER_12': 'Envelope #12',
+ 'NA_NUMBER_14': 'Envelope #14',
+ 'NA_NUMBER_9': 'Envelope #9',
+ 'NA_PERSONAL': 'Personal',
+ 'NA_QUARTO': 'Quarto',
+ 'NA_SUPER_A': 'Super A',
+ 'NA_SUPER_B': 'Super B',
+ 'NA_WIDE_FORMAT': 'Wide format',
+ 'OM_DAI_PA_KAI': 'Dai-pa-kai',
+ 'OM_FOLIO': 'Folio',
+ 'OM_FOLIO_SP': 'Folio SP',
+ 'OM_INVITE': 'Invite Envelope',
+ 'OM_ITALIAN': 'Italian Envelope',
+ 'OM_JUURO_KU_KAI': 'Juuro-ku-kai',
+ 'OM_LARGE_PHOTO': 'Large photo',
+ 'OM_OFICIO': 'Oficio',
+ 'OM_PA_KAI': 'Pa-kai',
+ 'OM_POSTFIX': 'Postfix Envelope',
+ 'OM_SMALL_PHOTO': 'Small photo',
+ 'PRC_1': 'prc1 Envelope',
+ 'PRC_10': 'prc10 Envelope',
+ 'PRC_16K': 'prc 16k',
+ 'PRC_2': 'prc2 Envelope',
+ 'PRC_3': 'prc3 Envelope',
+ 'PRC_32K': 'prc 32k',
+ 'PRC_4': 'prc4 Envelope',
+ 'PRC_5': 'prc5 Envelope',
+ 'PRC_6': 'prc6 Envelope',
+ 'PRC_7': 'prc7 Envelope',
+ 'PRC_8': 'prc8 Envelope',
+ 'ROC_16K': 'ROC 16K',
+ 'ROC_8K': 'ROC 8k',
};
// Export
diff --git a/chromium/chrome/browser/resources/print_preview/data/invitation.js b/chromium/chrome/browser/resources/print_preview/data/invitation.js
index 8aef4f3b23c..6f5d09de7ee 100644
--- a/chromium/chrome/browser/resources/print_preview/data/invitation.js
+++ b/chromium/chrome/browser/resources/print_preview/data/invitation.js
@@ -5,62 +5,61 @@
cr.define('print_preview', function() {
'use strict';
- /**
- * Printer sharing invitation data object.
- * @param {string} sender Text identifying invitation sender.
- * @param {string} receiver Text identifying invitation receiver. Empty in
- * case of a personal invitation. Identifies a group or domain in case
- * of an invitation received by a group manager.
- * @param {!print_preview.Destination} destination Shared destination.
- * @param {!Object} aclEntry JSON representation of the ACL entry this
- * invitation was sent to.
- * @param {string} account User account this invitation is sent for.
- * @constructor
- */
- function Invitation(sender, receiver, destination, aclEntry, account) {
+ class Invitation {
/**
- * Text identifying invitation sender.
- * @private {string}
+ * Printer sharing invitation data object.
+ * @param {string} sender Text identifying invitation sender.
+ * @param {string} receiver Text identifying invitation receiver. Empty in
+ * case of a personal invitation. Identifies a group or domain in case
+ * of an invitation received by a group manager.
+ * @param {!print_preview.Destination} destination Shared destination.
+ * @param {!Object} aclEntry JSON representation of the ACL entry this
+ * invitation was sent to.
+ * @param {string} account User account this invitation is sent for.
*/
- this.sender_ = sender;
+ constructor(sender, receiver, destination, aclEntry, account) {
+ /**
+ * Text identifying invitation sender.
+ * @private {string}
+ */
+ this.sender_ = sender;
- /**
- * Text identifying invitation receiver. Empty in case of a personal
- * invitation. Identifies a group or domain in case of an invitation
- * received by a group manager.
- * @private {string}
- */
- this.receiver_ = receiver;
+ /**
+ * Text identifying invitation receiver. Empty in case of a personal
+ * invitation. Identifies a group or domain in case of an invitation
+ * received by a group manager.
+ * @private {string}
+ */
+ this.receiver_ = receiver;
- /**
- * Shared destination.
- * @private {!print_preview.Destination}
- */
- this.destination_ = destination;
+ /**
+ * Shared destination.
+ * @private {!print_preview.Destination}
+ */
+ this.destination_ = destination;
- /**
- * JSON representation of the ACL entry this invitation was sent to.
- * @private {!Object}
- */
- this.aclEntry_ = aclEntry;
+ /**
+ * JSON representation of the ACL entry this invitation was sent to.
+ * @private {!Object}
+ */
+ this.aclEntry_ = aclEntry;
- /**
- * Account this invitation is sent for.
- * @private {string}
- */
- this.account_ = account;
- }
+ /**
+ * Account this invitation is sent for.
+ * @private {string}
+ */
+ this.account_ = account;
+ }
- Invitation.prototype = {
/** @return {string} Text identifying invitation sender. */
get sender() {
return this.sender_;
- },
+ }
/** @return {string} Text identifying invitation receiver. */
get receiver() {
return this.receiver_;
- },
+ }
/**
* @return {boolean} Whether this user acts as a manager for a group of
@@ -68,23 +67,23 @@ cr.define('print_preview', function() {
*/
get asGroupManager() {
return !!this.receiver_;
- },
+ }
/** @return {!print_preview.Destination} Shared destination. */
get destination() {
return this.destination_;
- },
+ }
/** @return {string} Scope (account) this invitation was sent to. */
get scopeId() {
return this.aclEntry_['scope'] || '';
- },
+ }
/** @return {string} Account this invitation is sent for. */
get account() {
return this.account_;
}
- };
+ }
// Export
return {Invitation: Invitation};
diff --git a/chromium/chrome/browser/resources/print_preview/data/local_parsers.js b/chromium/chrome/browser/resources/print_preview/data/local_parsers.js
index 8748f37b625..9b09d62e06f 100644
--- a/chromium/chrome/browser/resources/print_preview/data/local_parsers.js
+++ b/chromium/chrome/browser/resources/print_preview/data/local_parsers.js
@@ -5,8 +5,33 @@
cr.define('print_preview', function() {
'use strict';
- /** Namespace that contains a method to parse local print destinations. */
- function LocalDestinationParser() {}
+ /**
+ * @param{!print_preview.PrinterType} type The type of printer to parse.
+ * @param{!print_preview.LocalDestinationInfo |
+ * !print_preview.PrivetPrinterDescription |
+ * !print_preview.ProvisionalDestinationInfo} printer Information
+ * about the printer. Type expected depends on |type|:
+ * For LOCAL_PRINTER => print_preview.LocalDestinationInfo
+ * For PRIVET_PRINTER => print_preview.PrivetPrinterDescription
+ * For EXTENSION_PRINTER => print_preview.ProvisionalDestinationInfo
+ * @return {!Array<!print_preview.Destination> | !print_preview.Destination}
+ */
+ var parseDestination = function(type, printer) {
+ if (type === print_preview.PrinterType.LOCAL_PRINTER) {
+ return parseLocalDestination(
+ /** @type {!print_preview.LocalDestinationInfo} */ (printer));
+ }
+ if (type === print_preview.PrinterType.PRIVET_PRINTER) {
+ return parsePrivetDestination(
+ /** @type {!print_preview.PrivetPrinterDescription} */ (printer));
+ }
+ if (type === print_preview.PrinterType.EXTENSION_PRINTER) {
+ return parseExtensionDestination(
+ /** @type {!print_preview.ProvisionalDestinationInfo} */ (printer));
+ }
+ assertNotReached('Unknown printer type ' + type);
+ return [];
+ };
/**
* Parses a local print destination.
@@ -14,7 +39,7 @@ cr.define('print_preview', function() {
* describing a local print destination.
* @return {!print_preview.Destination} Parsed local print destination.
*/
- LocalDestinationParser.parse = function(destinationInfo) {
+ var parseLocalDestination = function(destinationInfo) {
var options = {
description: destinationInfo.printerDescription,
isEnterprisePrinter: destinationInfo.cupsEnterprisePrinter
@@ -34,15 +59,14 @@ cr.define('print_preview', function() {
print_preview.DestinationConnectionStatus.ONLINE, options);
};
- function PrivetDestinationParser() {}
-
/**
* Parses a privet destination as one or more local printers.
* @param {!print_preview.PrivetPrinterDescription} destinationInfo Object
* that describes a privet printer.
- * @return {!Array<!print_preview.Destination>} Parsed destination info.
+ * @return {!print_preview.Destination |
+ * !Array<!print_preview.Destination>} Parsed destination info.
*/
- PrivetDestinationParser.parse = function(destinationInfo) {
+ var parsePrivetDestination = function(destinationInfo) {
var returnedPrinters = [];
if (destinationInfo.hasLocalPrinting) {
@@ -61,11 +85,10 @@ cr.define('print_preview', function() {
print_preview.DestinationConnectionStatus.UNREGISTERED));
}
- return returnedPrinters;
+ return returnedPrinters.length === 1 ? returnedPrinters[0] :
+ returnedPrinters;
};
- function ExtensionDestinationParser() {}
-
/**
* Parses an extension destination from an extension supplied printer
* description.
@@ -73,7 +96,7 @@ cr.define('print_preview', function() {
* describing an extension printer.
* @return {!print_preview.Destination} Parsed destination.
*/
- ExtensionDestinationParser.parse = function(destinationInfo) {
+ var parseExtensionDestination = function(destinationInfo) {
var provisionalType = destinationInfo.provisional ?
print_preview.DestinationProvisionalType.NEEDS_USB_PERMISSION :
print_preview.DestinationProvisionalType.NONE;
@@ -92,8 +115,7 @@ cr.define('print_preview', function() {
// Export
return {
- LocalDestinationParser: LocalDestinationParser,
- PrivetDestinationParser: PrivetDestinationParser,
- ExtensionDestinationParser: ExtensionDestinationParser
+ parseDestination: parseDestination,
+ parseExtensionDestination: parseExtensionDestination
};
});
diff --git a/chromium/chrome/browser/resources/print_preview/data/margins.js b/chromium/chrome/browser/resources/print_preview/data/margins.js
index ba8239b9210..b7bef50c686 100644
--- a/chromium/chrome/browser/resources/print_preview/data/margins.js
+++ b/chromium/chrome/browser/resources/print_preview/data/margins.js
@@ -5,54 +5,55 @@
cr.define('print_preview', function() {
'use strict';
- /**
- * Creates a Margins object that holds four margin values in points.
- * @param {number} top The top margin in pts.
- * @param {number} right The right margin in pts.
- * @param {number} bottom The bottom margin in pts.
- * @param {number} left The left margin in pts.
- * @constructor
- */
- function Margins(top, right, bottom, left) {
+ class Margins {
/**
- * Backing store for the margin values in points.
- * @type {!Object<
- * !print_preview.ticket_items.CustomMarginsOrientation, number>}
- * @private
+ * Creates a Margins object that holds four margin values in points.
+ * @param {number} top The top margin in pts.
+ * @param {number} right The right margin in pts.
+ * @param {number} bottom The bottom margin in pts.
+ * @param {number} left The left margin in pts.
*/
- this.value_ = {};
- this.value_[print_preview.ticket_items.CustomMarginsOrientation.TOP] = top;
- this.value_[print_preview.ticket_items.CustomMarginsOrientation.RIGHT] =
- right;
- this.value_[print_preview.ticket_items.CustomMarginsOrientation.BOTTOM] =
- bottom;
- this.value_[print_preview.ticket_items.CustomMarginsOrientation.LEFT] =
- left;
- }
+ constructor(top, right, bottom, left) {
+ /**
+ * Backing store for the margin values in points.
+ * @type {!Object<
+ * !print_preview.ticket_items.CustomMarginsOrientation, number>}
+ * @private
+ */
+ this.value_ = {};
+ this.value_[print_preview.ticket_items.CustomMarginsOrientation.TOP] =
+ top;
+ this.value_[print_preview.ticket_items.CustomMarginsOrientation.RIGHT] =
+ right;
+ this.value_[print_preview.ticket_items.CustomMarginsOrientation.BOTTOM] =
+ bottom;
+ this.value_[print_preview.ticket_items.CustomMarginsOrientation.LEFT] =
+ left;
+ }
- /**
- * Parses a margins object from the given serialized state.
- * @param {Object} state Serialized representation of the margins created by
- * the {@code serialize} method.
- * @return {!print_preview.Margins} New margins instance.
- */
- Margins.parse = function(state) {
- return new print_preview.Margins(
- state[print_preview.ticket_items.CustomMarginsOrientation.TOP] || 0,
- state[print_preview.ticket_items.CustomMarginsOrientation.RIGHT] || 0,
- state[print_preview.ticket_items.CustomMarginsOrientation.BOTTOM] || 0,
- state[print_preview.ticket_items.CustomMarginsOrientation.LEFT] || 0);
- };
+ /**
+ * Parses a margins object from the given serialized state.
+ * @param {Object} state Serialized representation of the margins created by
+ * the {@code serialize} method.
+ * @return {!print_preview.Margins} New margins instance.
+ */
+ static parse(state) {
+ return new print_preview.Margins(
+ state[print_preview.ticket_items.CustomMarginsOrientation.TOP] || 0,
+ state[print_preview.ticket_items.CustomMarginsOrientation.RIGHT] || 0,
+ state[print_preview.ticket_items.CustomMarginsOrientation.BOTTOM] ||
+ 0,
+ state[print_preview.ticket_items.CustomMarginsOrientation.LEFT] || 0);
+ }
- Margins.prototype = {
/**
* @param {!print_preview.ticket_items.CustomMarginsOrientation}
* orientation Specifies the margin value to get.
* @return {number} Value of the margin of the given orientation.
*/
- get: function(orientation) {
+ get(orientation) {
return this.value_[orientation];
- },
+ }
/**
* @param {!print_preview.ticket_items.CustomMarginsOrientation}
@@ -61,7 +62,7 @@ cr.define('print_preview', function() {
* @return {!print_preview.Margins} A new copy of |this| with the
* modification made to the specified margin.
*/
- set: function(orientation, value) {
+ set(orientation, value) {
var newValue = this.clone_();
newValue[orientation] = value;
return new Margins(
@@ -69,14 +70,14 @@ cr.define('print_preview', function() {
newValue[print_preview.ticket_items.CustomMarginsOrientation.RIGHT],
newValue[print_preview.ticket_items.CustomMarginsOrientation.BOTTOM],
newValue[print_preview.ticket_items.CustomMarginsOrientation.LEFT]);
- },
+ }
/**
* @param {print_preview.Margins} other The other margins object to compare
* against.
* @return {boolean} Whether this margins object is equal to another.
*/
- equals: function(other) {
+ equals(other) {
if (other == null) {
return false;
}
@@ -86,25 +87,25 @@ cr.define('print_preview', function() {
}
}
return true;
- },
+ }
/** @return {Object} A serialized representation of the margins. */
- serialize: function() {
+ serialize() {
return this.clone_();
- },
+ }
/**
* @return {Object} Cloned state of the margins.
* @private
*/
- clone_: function() {
+ clone_() {
var clone = {};
for (var o in this.value_) {
clone[o] = this.value_[o];
}
return clone;
}
- };
+ }
// Export
return {Margins: Margins};
diff --git a/chromium/chrome/browser/resources/print_preview/data/measurement_system.js b/chromium/chrome/browser/resources/print_preview/data/measurement_system.js
index 01c6a55f4ee..1548de6b4e1 100644
--- a/chromium/chrome/browser/resources/print_preview/data/measurement_system.js
+++ b/chromium/chrome/browser/resources/print_preview/data/measurement_system.js
@@ -32,23 +32,6 @@ cr.define('print_preview', function() {
}
/**
- * Parses |numberFormat| and extracts the symbols used for the thousands point
- * and decimal point.
- * @param {string} numberFormat The formatted version of the number 12345678.
- * @return {!Array<string>} The extracted symbols in the order
- * [thousandsSymbol, decimalSymbol]. For example,
- * parseNumberFormat("123,456.78") returns [",", "."].
- */
- MeasurementSystem.parseNumberFormat = function(numberFormat) {
- if (!numberFormat) {
- return [',', '.'];
- }
- var regex = /^(\d+)(\W?)(\d+)(\W?)(\d+)$/;
- var matches = numberFormat.match(regex) || ['', '', ',', '', '.'];
- return [matches[2], matches[4]];
- };
-
- /**
* Maximum resolution of local unit values.
* @type {!Object<!print_preview.MeasurementSystemUnitType, number>}
* @private
diff --git a/chromium/chrome/browser/resources/print_preview/data/measurement_system_unittest.gtestjs b/chromium/chrome/browser/resources/print_preview/data/measurement_system_unittest.gtestjs
deleted file mode 100644
index f81960d5969..00000000000
--- a/chromium/chrome/browser/resources/print_preview/data/measurement_system_unittest.gtestjs
+++ /dev/null
@@ -1,68 +0,0 @@
-// Copyright (c) 2012 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.
-
-/**
- * Test fixture for the MeasurementSystem.
- * @constructor
- * @extends {testing.Test}
- */
-function MeasurementSystemUnitTest() {
- testing.Test.call(this);
-}
-
-MeasurementSystemUnitTest.prototype = {
- __proto__: testing.Test.prototype,
-
- extraLibraries: [
- '../../../../../ui/webui/resources/js/cr.js',
- '../print_preview_utils.js',
- 'measurement_system.js'
- ]
-};
-
-TEST_F('MeasurementSystemUnitTest', 'parseNumberFormat', function() {
- assertTrue(areArraysEqual(
- ['.', ','],
- print_preview.MeasurementSystem.parseNumberFormat('123.456,78')));
- assertTrue(areArraysEqual(
- ['.', '.'],
- print_preview.MeasurementSystem.parseNumberFormat('123.456.78')));
- assertTrue(areArraysEqual(
- [',', '.'],
- print_preview.MeasurementSystem.parseNumberFormat('123,456.78')));
- assertTrue(areArraysEqual(
- [',', ','],
- print_preview.MeasurementSystem.parseNumberFormat('123,456,78')));
- assertTrue(areArraysEqual(
- [' ', ','],
- print_preview.MeasurementSystem.parseNumberFormat('123 456,78')));
- assertTrue(areArraysEqual(
- [' ', '.'],
- print_preview.MeasurementSystem.parseNumberFormat('123 456.78')));
- assertTrue(areArraysEqual(
- [' ', ' '],
- print_preview.MeasurementSystem.parseNumberFormat('123 456 78')));
- assertTrue(areArraysEqual(
- ['', ''],
- print_preview.MeasurementSystem.parseNumberFormat('123')));
-
- assertTrue(areArraysEqual(
- [',', '.'],
- print_preview.MeasurementSystem.parseNumberFormat('abcdef')));
- assertTrue(areArraysEqual(
- [',', '.'],
- print_preview.MeasurementSystem.parseNumberFormat(null)));
- assertTrue(areArraysEqual(
- [',', '.'],
- print_preview.MeasurementSystem.parseNumberFormat(undefined)));
- assertTrue(areArraysEqual(
- [',', '.'],
- print_preview.MeasurementSystem.parseNumberFormat('')));
- assertTrue(areArraysEqual(
- [',', '.'],
- print_preview.MeasurementSystem.parseNumberFormat('1')));
- assertTrue(areArraysEqual(
- [',', '.'],
- print_preview.MeasurementSystem.parseNumberFormat('12')));
-});
diff --git a/chromium/chrome/browser/resources/print_preview/data/page_number_set.js b/chromium/chrome/browser/resources/print_preview/data/page_number_set.js
index 81fb7b66815..7eef255936e 100644
--- a/chromium/chrome/browser/resources/print_preview/data/page_number_set.js
+++ b/chromium/chrome/browser/resources/print_preview/data/page_number_set.js
@@ -5,57 +5,56 @@
cr.define('print_preview', function() {
'use strict';
- /**
- * An immutable ordered set of page numbers.
- * @param {!Array<number>} pageNumberList A list of page numbers to include
- * in the set.
- * @constructor
- */
- function PageNumberSet(pageNumberList) {
+ class PageNumberSet {
/**
- * Internal data store for the page number set.
- * @type {!Array<number>}
- * @private
+ * An immutable ordered set of page numbers.
+ * @param {!Array<number>} pageNumberList A list of page numbers to include
+ * in the set.
*/
- this.pageNumberSet_ = pageListToPageSet(pageNumberList);
- }
+ constructor(pageNumberList) {
+ /**
+ * Internal data store for the page number set.
+ * @type {!Array<number>}
+ * @private
+ */
+ this.pageNumberSet_ = pageListToPageSet(pageNumberList);
+ }
- PageNumberSet.prototype = {
/** @return {number} The number of page numbers in the set. */
get size() {
return this.pageNumberSet_.length;
- },
+ }
/**
* @param {number} index 0-based index of the page number to get.
* @return {number} Page number at the given index.
*/
- getPageNumberAt: function(index) {
+ getPageNumberAt(index) {
return this.pageNumberSet_[index];
- },
+ }
/**
* @param {number} pageNumber 1-based page number to check for.
* @return {boolean} Whether the given page number is in the page range.
*/
- hasPageNumber: function(pageNumber) {
+ hasPageNumber(pageNumber) {
return arrayContains(this.pageNumberSet_, pageNumber);
- },
+ }
/**
* @param {number} pageNumber 1-based number of the page to get index of.
* @return {number} 0-based index of the given page number with respect to
* all of the pages in the page range.
*/
- getPageNumberIndex: function(pageNumber) {
+ getPageNumberIndex(pageNumber) {
return this.pageNumberSet_.indexOf(pageNumber);
- },
+ }
/** @return {!Array<number>} Array representation of the set. */
- asArray: function() {
+ asArray() {
return this.pageNumberSet_.slice(0);
- },
- };
+ }
+ }
// Export
return {PageNumberSet: PageNumberSet};
diff --git a/chromium/chrome/browser/resources/print_preview/data/print_ticket_store.js b/chromium/chrome/browser/resources/print_preview/data/print_ticket_store.js
index 63a42bc086f..6675843b53e 100644
--- a/chromium/chrome/browser/resources/print_preview/data/print_ticket_store.js
+++ b/chromium/chrome/browser/resources/print_preview/data/print_ticket_store.js
@@ -10,310 +10,289 @@ cr.define('print_preview', function() {
// destination changes, the new destination might not support duplex anymore,
// so we should clear the ticket's isDuplexEnabled state.
- /**
- * Storage of the print ticket and document statistics. Dispatches events when
- * the contents of the print ticket or document statistics change. Also
- * handles validation of the print ticket against destination capabilities and
- * against the document.
- * @param {!print_preview.DestinationStore} destinationStore Used to
- * understand which printer is selected.
- * @param {!print_preview.AppState} appState Print preview application state.
- * @param {!print_preview.DocumentInfo} documentInfo Document data model.
- * @constructor
- * @extends {cr.EventTarget}
- */
- function PrintTicketStore(destinationStore, appState, documentInfo) {
- cr.EventTarget.call(this);
-
- /**
- * Destination store used to understand which printer is selected.
- * @type {!print_preview.DestinationStore}
- * @private
- */
- this.destinationStore_ = destinationStore;
-
- /**
- * App state used to persist and load ticket values.
- * @type {!print_preview.AppState}
- * @private
- */
- this.appState_ = appState;
-
- /**
- * Information about the document to print.
- * @type {!print_preview.DocumentInfo}
- * @private
- */
- this.documentInfo_ = documentInfo;
-
- /**
- * Printing capabilities of Chromium and the currently selected destination.
- * @type {!print_preview.CapabilitiesHolder}
- * @private
- */
- this.capabilitiesHolder_ = new print_preview.CapabilitiesHolder();
-
- /**
- * Current measurement system. Used to work with margin measurements.
- * @type {!print_preview.MeasurementSystem}
- * @private
- */
- this.measurementSystem_ = new print_preview.MeasurementSystem(
- ',', '.', print_preview.MeasurementSystemUnitType.IMPERIAL);
-
- /**
- * Collate ticket item.
- * @type {!print_preview.ticket_items.Collate}
- * @private
- */
- this.collate_ = new print_preview.ticket_items.Collate(
- this.appState_, this.destinationStore_);
-
- /**
- * Color ticket item.
- * @type {!print_preview.ticket_items.Color}
- * @private
- */
- this.color_ = new print_preview.ticket_items.Color(
- this.appState_, this.destinationStore_);
-
- /**
- * Copies ticket item.
- * @type {!print_preview.ticket_items.Copies}
- * @private
- */
- this.copies_ =
- new print_preview.ticket_items.Copies(this.destinationStore_);
-
- /**
- * DPI ticket item.
- * @type {!print_preview.ticket_items.Dpi}
- * @private
- */
- this.dpi_ = new print_preview.ticket_items.Dpi(
- this.appState_, this.destinationStore_);
-
- /**
- * Duplex ticket item.
- * @type {!print_preview.ticket_items.Duplex}
- * @private
- */
- this.duplex_ = new print_preview.ticket_items.Duplex(
- this.appState_, this.destinationStore_);
-
- /**
- * Page range ticket item.
- * @type {!print_preview.ticket_items.PageRange}
- * @private
- */
- this.pageRange_ =
- new print_preview.ticket_items.PageRange(this.documentInfo_);
-
- /**
- * Rasterize PDF ticket item.
- * @type {!print_preview.ticket_items.Rasterize}
- * @private
- */
- this.rasterize_ = new print_preview.ticket_items.Rasterize(
- this.destinationStore_, this.documentInfo_);
-
- /**
- * Scaling ticket item.
- * @type {!print_preview.ticket_items.Scaling}
- * @private
- */
- this.scaling_ = new print_preview.ticket_items.Scaling(
- this.appState_, this.destinationStore_, this.documentInfo_);
-
- /**
- * Custom margins ticket item.
- * @type {!print_preview.ticket_items.CustomMargins}
- * @private
- */
- this.customMargins_ = new print_preview.ticket_items.CustomMargins(
- this.appState_, this.documentInfo_);
-
- /**
- * Margins type ticket item.
- * @type {!print_preview.ticket_items.MarginsType}
- * @private
- */
- this.marginsType_ = new print_preview.ticket_items.MarginsType(
- this.appState_, this.documentInfo_, this.customMargins_);
-
- /**
- * Media size ticket item.
- * @type {!print_preview.ticket_items.MediaSize}
- * @private
- */
- this.mediaSize_ = new print_preview.ticket_items.MediaSize(
- this.appState_, this.destinationStore_, this.documentInfo_,
- this.marginsType_, this.customMargins_);
-
- /**
- * Landscape ticket item.
- * @type {!print_preview.ticket_items.Landscape}
- * @private
- */
- this.landscape_ = new print_preview.ticket_items.Landscape(
- this.appState_, this.destinationStore_, this.documentInfo_,
- this.marginsType_, this.customMargins_);
-
- /**
- * Header-footer ticket item.
- * @type {!print_preview.ticket_items.HeaderFooter}
- * @private
- */
- this.headerFooter_ = new print_preview.ticket_items.HeaderFooter(
- this.appState_, this.documentInfo_, this.marginsType_,
- this.customMargins_, this.mediaSize_, this.landscape_);
-
- /**
- * Fit-to-page ticket item.
- * @type {!print_preview.ticket_items.FitToPage}
- * @private
- */
- this.fitToPage_ = new print_preview.ticket_items.FitToPage(
- this.appState_, this.documentInfo_, this.destinationStore_);
-
- /**
- * Print CSS backgrounds ticket item.
- * @type {!print_preview.ticket_items.CssBackground}
- * @private
- */
- this.cssBackground_ = new print_preview.ticket_items.CssBackground(
- this.appState_, this.documentInfo_);
-
- /**
- * Print selection only ticket item.
- * @type {!print_preview.ticket_items.SelectionOnly}
- * @private
- */
- this.selectionOnly_ =
- new print_preview.ticket_items.SelectionOnly(this.documentInfo_);
+ class PrintTicketStore extends cr.EventTarget {
+ /**
+ * Storage of the print ticket and document statistics. Dispatches events
+ * when the contents of the print ticket or document statistics change. Also
+ * handles validation of the print ticket against destination capabilities
+ * and against the document.
+ * @param {!print_preview.DestinationStore} destinationStore Used to
+ * understand which printer is selected.
+ * @param {!print_preview.AppState} appState Print preview application
+ * state.
+ * @param {!print_preview.DocumentInfo} documentInfo Document data model.
+ */
+ constructor(destinationStore, appState, documentInfo) {
+ super();
+
+ /**
+ * Destination store used to understand which printer is selected.
+ * @type {!print_preview.DestinationStore}
+ * @private
+ */
+ this.destinationStore_ = destinationStore;
+
+ /**
+ * App state used to persist and load ticket values.
+ * @type {!print_preview.AppState}
+ * @private
+ */
+ this.appState_ = appState;
+
+ /**
+ * Information about the document to print.
+ * @type {!print_preview.DocumentInfo}
+ * @private
+ */
+ this.documentInfo_ = documentInfo;
+
+ /**
+ * Printing capabilities of Chromium and the currently selected
+ * destination.
+ * @type {!print_preview.CapabilitiesHolder}
+ * @private
+ */
+ this.capabilitiesHolder_ = new print_preview.CapabilitiesHolder();
+
+ /**
+ * Current measurement system. Used to work with margin measurements.
+ * @type {!print_preview.MeasurementSystem}
+ * @private
+ */
+ this.measurementSystem_ = new print_preview.MeasurementSystem(
+ ',', '.', print_preview.MeasurementSystemUnitType.IMPERIAL);
+
+ /**
+ * Collate ticket item.
+ * @type {!print_preview.ticket_items.Collate}
+ * @private
+ */
+ this.collate_ = new print_preview.ticket_items.Collate(
+ this.appState_, this.destinationStore_);
+
+ /**
+ * Color ticket item.
+ * @type {!print_preview.ticket_items.Color}
+ * @private
+ */
+ this.color_ = new print_preview.ticket_items.Color(
+ this.appState_, this.destinationStore_);
+
+ /**
+ * Copies ticket item.
+ * @type {!print_preview.ticket_items.Copies}
+ * @private
+ */
+ this.copies_ =
+ new print_preview.ticket_items.Copies(this.destinationStore_);
+
+ /**
+ * DPI ticket item.
+ * @type {!print_preview.ticket_items.Dpi}
+ * @private
+ */
+ this.dpi_ = new print_preview.ticket_items.Dpi(
+ this.appState_, this.destinationStore_);
+
+ /**
+ * Duplex ticket item.
+ * @type {!print_preview.ticket_items.Duplex}
+ * @private
+ */
+ this.duplex_ = new print_preview.ticket_items.Duplex(
+ this.appState_, this.destinationStore_);
+
+ /**
+ * Page range ticket item.
+ * @type {!print_preview.ticket_items.PageRange}
+ * @private
+ */
+ this.pageRange_ =
+ new print_preview.ticket_items.PageRange(this.documentInfo_);
+
+ /**
+ * Rasterize PDF ticket item.
+ * @type {!print_preview.ticket_items.Rasterize}
+ * @private
+ */
+ this.rasterize_ = new print_preview.ticket_items.Rasterize(
+ this.destinationStore_, this.documentInfo_);
+
+ /**
+ * Scaling ticket item.
+ * @type {!print_preview.ticket_items.Scaling}
+ * @private
+ */
+ this.scaling_ = new print_preview.ticket_items.Scaling(
+ this.appState_, this.destinationStore_, this.documentInfo_);
+
+ /**
+ * Custom margins ticket item.
+ * @type {!print_preview.ticket_items.CustomMargins}
+ * @private
+ */
+ this.customMargins_ = new print_preview.ticket_items.CustomMargins(
+ this.appState_, this.documentInfo_);
+
+ /**
+ * Margins type ticket item.
+ * @type {!print_preview.ticket_items.MarginsType}
+ * @private
+ */
+ this.marginsType_ = new print_preview.ticket_items.MarginsType(
+ this.appState_, this.documentInfo_, this.customMargins_);
+
+ /**
+ * Media size ticket item.
+ * @type {!print_preview.ticket_items.MediaSize}
+ * @private
+ */
+ this.mediaSize_ = new print_preview.ticket_items.MediaSize(
+ this.appState_, this.destinationStore_, this.documentInfo_,
+ this.marginsType_, this.customMargins_);
+
+ /**
+ * Landscape ticket item.
+ * @type {!print_preview.ticket_items.Landscape}
+ * @private
+ */
+ this.landscape_ = new print_preview.ticket_items.Landscape(
+ this.appState_, this.destinationStore_, this.documentInfo_,
+ this.marginsType_, this.customMargins_);
+
+ /**
+ * Header-footer ticket item.
+ * @type {!print_preview.ticket_items.HeaderFooter}
+ * @private
+ */
+ this.headerFooter_ = new print_preview.ticket_items.HeaderFooter(
+ this.appState_, this.documentInfo_, this.marginsType_,
+ this.customMargins_, this.mediaSize_, this.landscape_);
+
+ /**
+ * Fit-to-page ticket item.
+ * @type {!print_preview.ticket_items.FitToPage}
+ * @private
+ */
+ this.fitToPage_ = new print_preview.ticket_items.FitToPage(
+ this.appState_, this.documentInfo_, this.destinationStore_);
+
+ /**
+ * Print CSS backgrounds ticket item.
+ * @type {!print_preview.ticket_items.CssBackground}
+ * @private
+ */
+ this.cssBackground_ = new print_preview.ticket_items.CssBackground(
+ this.appState_, this.documentInfo_);
+
+ /**
+ * Print selection only ticket item.
+ * @type {!print_preview.ticket_items.SelectionOnly}
+ * @private
+ */
+ this.selectionOnly_ =
+ new print_preview.ticket_items.SelectionOnly(this.documentInfo_);
+
+ /**
+ * Vendor ticket items.
+ * @type {!print_preview.ticket_items.VendorItems}
+ * @private
+ */
+ this.vendorItems_ = new print_preview.ticket_items.VendorItems(
+ this.appState_, this.destinationStore_);
+
+ /**
+ * Keeps track of event listeners for the print ticket store.
+ * @type {!EventTracker}
+ * @private
+ */
+ this.tracker_ = new EventTracker();
+
+ /**
+ * Whether the print preview has been initialized.
+ * @type {boolean}
+ * @private
+ */
+ this.isInitialized_ = false;
+
+ this.addEventListeners_();
+ }
- /**
- * Vendor ticket items.
- * @type {!print_preview.ticket_items.VendorItems}
- * @private
- */
- this.vendorItems_ = new print_preview.ticket_items.VendorItems(
- this.appState_, this.destinationStore_);
-
- /**
- * Keeps track of event listeners for the print ticket store.
- * @type {!EventTracker}
- * @private
- */
- this.tracker_ = new EventTracker();
-
- /**
- * Whether the print preview has been initialized.
- * @type {boolean}
- * @private
- */
- this.isInitialized_ = false;
-
- this.addEventListeners_();
- }
-
- /**
- * Event types dispatched by the print ticket store.
- * @enum {string}
- */
- PrintTicketStore.EventType = {
- CAPABILITIES_CHANGE: 'print_preview.PrintTicketStore.CAPABILITIES_CHANGE',
- DOCUMENT_CHANGE: 'print_preview.PrintTicketStore.DOCUMENT_CHANGE',
- INITIALIZE: 'print_preview.PrintTicketStore.INITIALIZE',
- TICKET_CHANGE: 'print_preview.PrintTicketStore.TICKET_CHANGE'
- };
-
- PrintTicketStore.prototype = {
- __proto__: cr.EventTarget.prototype,
-
- /**
- * Whether the print preview has been initialized.
- * @type {boolean}
- */
get isInitialized() {
return this.isInitialized_;
- },
+ }
get collate() {
return this.collate_;
- },
+ }
get color() {
return this.color_;
- },
+ }
get copies() {
return this.copies_;
- },
+ }
get cssBackground() {
return this.cssBackground_;
- },
+ }
get customMargins() {
return this.customMargins_;
- },
+ }
get dpi() {
return this.dpi_;
- },
+ }
get duplex() {
return this.duplex_;
- },
+ }
get fitToPage() {
return this.fitToPage_;
- },
+ }
get headerFooter() {
return this.headerFooter_;
- },
+ }
get mediaSize() {
return this.mediaSize_;
- },
+ }
get landscape() {
return this.landscape_;
- },
+ }
get marginsType() {
return this.marginsType_;
- },
+ }
get pageRange() {
return this.pageRange_;
- },
+ }
get rasterize() {
return this.rasterize_;
- },
+ }
get scaling() {
return this.scaling_;
- },
+ }
get selectionOnly() {
return this.selectionOnly_;
- },
+ }
get vendorItems() {
return this.vendorItems_;
- },
+ }
- /**
- * @return {!print_preview.MeasurementSystem} Measurement system of the
- * local system.
- */
get measurementSystem() {
return this.measurementSystem_;
- },
+ }
/**
* Initializes the print ticket store. Dispatches an INITIALIZE event.
@@ -324,8 +303,7 @@ cr.define('print_preview', function() {
* @param {boolean} selectionOnly Whether only selected content should be
* printed.
*/
- init: function(
- thousandsDelimeter, decimalDelimeter, unitType, selectionOnly) {
+ init(thousandsDelimeter, decimalDelimeter, unitType, selectionOnly) {
this.measurementSystem_.setSystem(
thousandsDelimeter, decimalDelimeter, unitType);
this.selectionOnly_.updateValue(selectionOnly);
@@ -404,35 +382,35 @@ cr.define('print_preview', function() {
/** @type {!Object<string>} */ (this.appState_.getField(
print_preview.AppStateField.VENDOR_OPTIONS)));
}
- },
+ }
/**
* @return {boolean} {@code true} if the stored print ticket is valid,
* {@code false} otherwise.
*/
- isTicketValid: function() {
+ isTicketValid() {
return this.isTicketValidForPreview() &&
(!this.copies_.isCapabilityAvailable() || this.copies_.isValid()) &&
(!this.pageRange_.isCapabilityAvailable() ||
this.pageRange_.isValid());
- },
+ }
/** @return {boolean} Whether the ticket is valid for preview generation. */
- isTicketValidForPreview: function() {
+ isTicketValidForPreview() {
return (
(!this.marginsType_.isCapabilityAvailable() ||
!this.marginsType_.isValueEqual(
print_preview.ticket_items.MarginsTypeValue.CUSTOM) ||
this.customMargins_.isValid()) &&
(!this.scaling_.isCapabilityAvailable() || this.scaling_.isValid()));
- },
+ }
/**
* Creates an object that represents a Google Cloud Print print ticket.
* @param {!print_preview.Destination} destination Destination to print to.
* @return {string} Google Cloud Print print ticket.
*/
- createPrintTicket: function(destination) {
+ createPrintTicket(destination) {
assert(
!destination.isLocal || destination.isPrivet ||
destination.isExtension,
@@ -506,18 +484,13 @@ cr.define('print_preview', function() {
}
}
return JSON.stringify(cjt);
- },
+ }
/**
* Adds event listeners for the print ticket store.
* @private
*/
- addEventListeners_: function() {
- this.tracker_.add(
- this.destinationStore_,
- print_preview.DestinationStore.EventType.DESTINATION_SELECT,
- this.onDestinationSelect_.bind(this));
-
+ addEventListeners_() {
this.tracker_.add(
this.destinationStore_,
print_preview.DestinationStore.EventType
@@ -537,14 +510,13 @@ cr.define('print_preview', function() {
this.tracker_.add(
this.documentInfo_, print_preview.DocumentInfo.EventType.CHANGE,
this.onDocumentInfoChange_.bind(this));
- },
+ }
/**
- * Called when the destination selected.
+ * Called when the capabilities of the selected destination are ready.
* @private
*/
- onDestinationSelect_: function() {
- // Reset user selection for certain ticket items.
+ onSelectedDestinationCapabilitiesReady_() {
if (this.capabilitiesHolder_.get() != null) {
this.customMargins_.updateValue(null);
if (this.marginsType_.getValue() ==
@@ -554,13 +526,6 @@ cr.define('print_preview', function() {
}
this.vendorItems_.updateValue({});
}
- },
-
- /**
- * Called when the capabilities of the selected destination are ready.
- * @private
- */
- onSelectedDestinationCapabilitiesReady_: function() {
var caps =
assert(this.destinationStore_.selectedDestination.capabilities);
var isFirstUpdate = this.capabilitiesHolder_.get() == null;
@@ -572,16 +537,26 @@ cr.define('print_preview', function() {
cr.dispatchSimpleEvent(
this, PrintTicketStore.EventType.CAPABILITIES_CHANGE);
}
- },
+ }
/**
* Called when document data model has changed. Dispatches a print ticket
* store event.
* @private
*/
- onDocumentInfoChange_: function() {
+ onDocumentInfoChange_() {
cr.dispatchSimpleEvent(this, PrintTicketStore.EventType.DOCUMENT_CHANGE);
- },
+ }
+ }
+
+ /**
+ * Event types dispatched by the print ticket store.
+ * @enum {string}
+ */
+ PrintTicketStore.EventType = {
+ CAPABILITIES_CHANGE: 'print_preview.PrintTicketStore.CAPABILITIES_CHANGE',
+ DOCUMENT_CHANGE: 'print_preview.PrintTicketStore.DOCUMENT_CHANGE',
+ INITIALIZE: 'print_preview.PrintTicketStore.INITIALIZE',
};
// Export
diff --git a/chromium/chrome/browser/resources/print_preview/data/printable_area.js b/chromium/chrome/browser/resources/print_preview/data/printable_area.js
index ae0f076096e..83791b717d7 100644
--- a/chromium/chrome/browser/resources/print_preview/data/printable_area.js
+++ b/chromium/chrome/browser/resources/print_preview/data/printable_area.js
@@ -5,56 +5,55 @@
cr.define('print_preview', function() {
'use strict';
- /**
- * Object describing the printable area of a page in the document.
- * @param {!print_preview.Coordinate2d} origin Top left corner of the
- * printable area of the document.
- * @param {!print_preview.Size} size Size of the printable area of the
- * document.
- * @constructor
- */
- function PrintableArea(origin, size) {
+ class PrintableArea {
/**
- * Top left corner of the printable area of the document.
- * @type {!print_preview.Coordinate2d}
- * @private
+ * Object describing the printable area of a page in the document.
+ * @param {!print_preview.Coordinate2d} origin Top left corner of the
+ * printable area of the document.
+ * @param {!print_preview.Size} size Size of the printable area of the
+ * document.
*/
- this.origin_ = origin;
+ constructor(origin, size) {
+ /**
+ * Top left corner of the printable area of the document.
+ * @type {!print_preview.Coordinate2d}
+ * @private
+ */
+ this.origin_ = origin;
- /**
- * Size of the printable area of the document.
- * @type {!print_preview.Size}
- * @private
- */
- this.size_ = size;
- }
+ /**
+ * Size of the printable area of the document.
+ * @type {!print_preview.Size}
+ * @private
+ */
+ this.size_ = size;
+ }
- PrintableArea.prototype = {
/**
* @return {!print_preview.Coordinate2d} Top left corner of the printable
* area of the document.
*/
get origin() {
return this.origin_;
- },
+ }
/**
* @return {!print_preview.Size} Size of the printable area of the document.
*/
get size() {
return this.size_;
- },
+ }
/**
* @param {print_preview.PrintableArea} other Other printable area to check
* for equality.
* @return {boolean} Whether another printable area is equal to this one.
*/
- equals: function(other) {
+ equals(other) {
return other != null && this.origin_.equals(other.origin_) &&
this.size_.equals(other.size_);
}
- };
+ }
// Export
return {PrintableArea: PrintableArea};
diff --git a/chromium/chrome/browser/resources/print_preview/data/size.js b/chromium/chrome/browser/resources/print_preview/data/size.js
index 078ce7d7b1e..8012258284d 100644
--- a/chromium/chrome/browser/resources/print_preview/data/size.js
+++ b/chromium/chrome/browser/resources/print_preview/data/size.js
@@ -5,48 +5,47 @@
cr.define('print_preview', function() {
'use strict';
- /**
- * Immutable two-dimensional size.
- * @param {number} width Width of the size.
- * @param {number} height Height of the size.
- * @constructor
- */
- function Size(width, height) {
+ class Size {
/**
- * Width of the size.
- * @type {number}
- * @private
+ * Immutable two-dimensional size.
+ * @param {number} width Width of the size.
+ * @param {number} height Height of the size.
*/
- this.width_ = width;
+ constructor(width, height) {
+ /**
+ * Width of the size.
+ * @type {number}
+ * @private
+ */
+ this.width_ = width;
- /**
- * Height of the size.
- * @type {number}
- * @private
- */
- this.height_ = height;
- }
+ /**
+ * Height of the size.
+ * @type {number}
+ * @private
+ */
+ this.height_ = height;
+ }
- Size.prototype = {
/** @return {number} Width of the size. */
get width() {
return this.width_;
- },
+ }
/** @return {number} Height of the size. */
get height() {
return this.height_;
- },
+ }
/**
* @param {print_preview.Size} other Other size object to compare against.
* @return {boolean} Whether this size object is equal to another.
*/
- equals: function(other) {
+ equals(other) {
return other != null && this.width_ == other.width_ &&
this.height_ == other.height_;
}
- };
+ }
// Export
return {Size: Size};
diff --git a/chromium/chrome/browser/resources/print_preview/data/ticket_items/collate.js b/chromium/chrome/browser/resources/print_preview/data/ticket_items/collate.js
index ec59d895da3..227cf03cf2d 100644
--- a/chromium/chrome/browser/resources/print_preview/data/ticket_items/collate.js
+++ b/chromium/chrome/browser/resources/print_preview/data/ticket_items/collate.js
@@ -5,57 +5,53 @@
cr.define('print_preview.ticket_items', function() {
'use strict';
- /**
- * Collate ticket item whose value is a {@code boolean} that indicates whether
- * collation is enabled.
- * @param {!print_preview.AppState} appState App state used to persist collate
- * selection.
- * @param {!print_preview.DestinationStore} destinationStore Destination store
- * used determine if a destination has the collate capability.
- * @constructor
- * @extends {print_preview.ticket_items.TicketItem}
- */
- function Collate(appState, destinationStore) {
- print_preview.ticket_items.TicketItem.call(
- this, appState, print_preview.AppStateField.IS_COLLATE_ENABLED,
- destinationStore);
- }
-
- Collate.prototype = {
- __proto__: print_preview.ticket_items.TicketItem.prototype,
+ class Collate extends print_preview.ticket_items.TicketItem {
+ /**
+ * Collate ticket item whose value is a {@code boolean} that indicates
+ * whether collation is enabled.
+ * @param {!print_preview.AppState} appState App state used to persist
+ * collate selection.
+ * @param {!print_preview.DestinationStore} destinationStore Destination
+ * store used determine if a destination has the collate capability.
+ */
+ constructor(appState, destinationStore) {
+ super(
+ appState, print_preview.AppStateField.IS_COLLATE_ENABLED,
+ destinationStore);
+ }
/** @override */
- wouldValueBeValid: function(value) {
+ wouldValueBeValid(value) {
return true;
- },
+ }
/** @override */
- isCapabilityAvailable: function() {
+ isCapabilityAvailable() {
return !!this.getCollateCapability_();
- },
+ }
/** @override */
- getDefaultValueInternal: function() {
+ getDefaultValueInternal() {
var capability = this.getCollateCapability_();
return capability.hasOwnProperty('default') ? capability.default : true;
- },
+ }
/** @override */
- getCapabilityNotAvailableValueInternal: function() {
+ getCapabilityNotAvailableValueInternal() {
return true;
- },
+ }
/**
* @return {Object} Collate capability of the selected destination.
* @private
*/
- getCollateCapability_: function() {
+ getCollateCapability_() {
var dest = this.getSelectedDestInternal();
return (dest && dest.capabilities && dest.capabilities.printer &&
dest.capabilities.printer.collate) ||
null;
}
- };
+ }
// Export
return {Collate: Collate};
diff --git a/chromium/chrome/browser/resources/print_preview/data/ticket_items/color.js b/chromium/chrome/browser/resources/print_preview/data/ticket_items/color.js
index 67d2dec3619..a78d6ccc9e1 100644
--- a/chromium/chrome/browser/resources/print_preview/data/ticket_items/color.js
+++ b/chromium/chrome/browser/resources/print_preview/data/ticket_items/color.js
@@ -5,44 +5,28 @@
cr.define('print_preview.ticket_items', function() {
'use strict';
- /**
- * Color ticket item whose value is a {@code boolean} that indicates whether
- * the document should be printed in color.
- * @param {!print_preview.AppState} appState App state persistence object to
- * save the state of the color selection.
- * @param {!print_preview.DestinationStore} destinationStore Used to determine
- * whether color printing should be available.
- * @constructor
- * @extends {print_preview.ticket_items.TicketItem}
- */
- function Color(appState, destinationStore) {
- print_preview.ticket_items.TicketItem.call(
- this, appState, print_preview.AppStateField.IS_COLOR_ENABLED,
- destinationStore);
- }
-
- /**
- * @private {!Array<string>} List of capability types considered color.
- * @const
- */
- Color.COLOR_TYPES_ = ['STANDARD_COLOR', 'CUSTOM_COLOR'];
-
- /**
- * @private {!Array<string>} List of capability types considered monochrome.
- * @const
- */
- Color.MONOCHROME_TYPES_ = ['STANDARD_MONOCHROME', 'CUSTOM_MONOCHROME'];
-
- Color.prototype = {
- __proto__: print_preview.ticket_items.TicketItem.prototype,
+ class Color extends print_preview.ticket_items.TicketItem {
+ /**
+ * Color ticket item whose value is a {@code boolean} that indicates whether
+ * the document should be printed in color.
+ * @param {!print_preview.AppState} appState App state persistence object to
+ * save the state of the color selection.
+ * @param {!print_preview.DestinationStore} destinationStore Used to
+ * determine whether color printing should be available.
+ */
+ constructor(appState, destinationStore) {
+ super(
+ appState, print_preview.AppStateField.IS_COLOR_ENABLED,
+ destinationStore);
+ }
/** @override */
- wouldValueBeValid: function(value) {
+ wouldValueBeValid(value) {
return true;
- },
+ }
/** @override */
- isCapabilityAvailable: function() {
+ isCapabilityAvailable() {
var capability = this.capability;
if (!capability) {
return false;
@@ -55,7 +39,7 @@ cr.define('print_preview.ticket_items', function() {
(Color.MONOCHROME_TYPES_.indexOf(option.type) >= 0);
});
return hasColor && hasMonochrome;
- },
+ }
/** @return {Object} Color capability of the selected destination. */
get capability() {
@@ -63,10 +47,10 @@ cr.define('print_preview.ticket_items', function() {
return (dest && dest.capabilities && dest.capabilities.printer &&
dest.capabilities.printer.color) ||
null;
- },
+ }
/** @return {Object} Color option corresponding to the current value. */
- getSelectedOption: function() {
+ getSelectedOption() {
var capability = this.capability;
var options = capability ? capability.option : null;
if (options) {
@@ -82,19 +66,19 @@ cr.define('print_preview.ticket_items', function() {
}
}
return null;
- },
+ }
/** @override */
- getDefaultValueInternal: function() {
+ getDefaultValueInternal() {
var capability = this.capability;
var defaultOption =
capability ? this.getDefaultColorOption_(capability.option) : null;
return defaultOption &&
(Color.COLOR_TYPES_.indexOf(defaultOption.type) >= 0);
- },
+ }
/** @override */
- getCapabilityNotAvailableValueInternal: function() {
+ getCapabilityNotAvailableValueInternal() {
// TODO(rltoscano): Get rid of this check based on destination ID. These
// destinations should really update their CDDs to have only one color
// option that has type 'STANDARD_COLOR'.
@@ -106,7 +90,7 @@ cr.define('print_preview.ticket_items', function() {
}
}
return this.getDefaultValueInternal();
- },
+ }
/**
* @param {!Array<!Object<{type: (string|undefined),
@@ -116,13 +100,26 @@ cr.define('print_preview.ticket_items', function() {
* option of the given list.
* @private
*/
- getDefaultColorOption_: function(options) {
+ getDefaultColorOption_(options) {
var defaultOptions = options.filter(function(option) {
return option.is_default;
});
return (defaultOptions.length == 0) ? null : defaultOptions[0];
}
- };
+ }
+
+ /**
+ * @private {!Array<string>} List of capability types considered color.
+ * @const
+ */
+ Color.COLOR_TYPES_ = ['STANDARD_COLOR', 'CUSTOM_COLOR'];
+
+ /**
+ * @private {!Array<string>} List of capability types considered monochrome.
+ * @const
+ */
+ Color.MONOCHROME_TYPES_ = ['STANDARD_MONOCHROME', 'CUSTOM_MONOCHROME'];
+
// Export
return {Color: Color};
diff --git a/chromium/chrome/browser/resources/print_preview/data/ticket_items/copies.js b/chromium/chrome/browser/resources/print_preview/data/ticket_items/copies.js
index 936342cb1d2..84f20a7cb2f 100644
--- a/chromium/chrome/browser/resources/print_preview/data/ticket_items/copies.js
+++ b/chromium/chrome/browser/resources/print_preview/data/ticket_items/copies.js
@@ -5,61 +5,56 @@
cr.define('print_preview.ticket_items', function() {
'use strict';
- /**
- * Copies ticket item whose value is a {@code string} that indicates how many
- * copies of the document should be printed. The ticket item is backed by a
- * string since the user can textually input the copies value.
- * @param {!print_preview.DestinationStore} destinationStore Destination store
- * used determine if a destination has the copies capability.
- * @constructor
- * @extends {print_preview.ticket_items.TicketItem}
- */
- function Copies(destinationStore) {
- print_preview.ticket_items.TicketItem.call(
- this, null /*appState*/, null /*field*/, destinationStore);
- }
-
- Copies.prototype = {
- __proto__: print_preview.ticket_items.TicketItem.prototype,
+ class Copies extends print_preview.ticket_items.TicketItem {
+ /**
+ * Copies ticket item whose value is a {@code string} that indicates how
+ * many copies of the document should be printed. The ticket item is backed
+ * by a string since the user can textually input the copies value.
+ * @param {!print_preview.DestinationStore} destinationStore Destination
+ * store used to determine if a destination has the copies capability.
+ */
+ constructor(destinationStore) {
+ super(null /*appState*/, null /*field*/, destinationStore);
+ }
/** @override */
- wouldValueBeValid: function(value) {
+ wouldValueBeValid(value) {
return value != '';
- },
+ }
/** @override */
- isCapabilityAvailable: function() {
+ isCapabilityAvailable() {
return !!this.getCopiesCapability_();
- },
+ }
/** @return {number} The number of copies indicated by the ticket item. */
- getValueAsNumber: function() {
+ getValueAsNumber() {
var value = this.getValue();
return value == '' ? 0 : parseInt(value, 10);
- },
+ }
/** @override */
- getDefaultValueInternal: function() {
+ getDefaultValueInternal() {
var cap = this.getCopiesCapability_();
return cap.hasOwnProperty('default') ? cap.default : '1';
- },
+ }
/** @override */
- getCapabilityNotAvailableValueInternal: function() {
+ getCapabilityNotAvailableValueInternal() {
return '1';
- },
+ }
/**
* @return {Object} Copies capability of the selected destination.
* @private
*/
- getCopiesCapability_: function() {
+ getCopiesCapability_() {
var dest = this.getSelectedDestInternal();
return (dest && dest.capabilities && dest.capabilities.printer &&
dest.capabilities.printer.copies) ||
null;
}
- };
+ }
// Export
return {Copies: Copies};
diff --git a/chromium/chrome/browser/resources/print_preview/data/ticket_items/css_background.js b/chromium/chrome/browser/resources/print_preview/data/ticket_items/css_background.js
index ab205878a7d..9279d03ec0f 100644
--- a/chromium/chrome/browser/resources/print_preview/data/ticket_items/css_background.js
+++ b/chromium/chrome/browser/resources/print_preview/data/ticket_items/css_background.js
@@ -5,45 +5,41 @@
cr.define('print_preview.ticket_items', function() {
'use strict';
- /**
- * Ticket item whose value is a {@code boolean} that represents whether to
- * print CSS backgrounds.
- * @param {!print_preview.AppState} appState App state to persist CSS
- * background value.
- * @param {!print_preview.DocumentInfo} documentInfo Information about the
- * document to print.
- * @constructor
- * @extends {print_preview.ticket_items.TicketItem}
- */
- function CssBackground(appState, documentInfo) {
- print_preview.ticket_items.TicketItem.call(
- this, appState, print_preview.AppStateField.IS_CSS_BACKGROUND_ENABLED,
- null /*destinationStore*/, documentInfo);
- }
-
- CssBackground.prototype = {
- __proto__: print_preview.ticket_items.TicketItem.prototype,
+ class CssBackground extends print_preview.ticket_items.TicketItem {
+ /**
+ * Ticket item whose value is a {@code boolean} that represents whether to
+ * print CSS backgrounds.
+ * @param {!print_preview.AppState} appState App state to persist CSS
+ * background value.
+ * @param {!print_preview.DocumentInfo} documentInfo Information about the
+ * document to print.
+ */
+ constructor(appState, documentInfo) {
+ super(
+ appState, print_preview.AppStateField.IS_CSS_BACKGROUND_ENABLED,
+ null /*destinationStore*/, documentInfo);
+ }
/** @override */
- wouldValueBeValid: function(value) {
+ wouldValueBeValid(value) {
return true;
- },
+ }
/** @override */
- isCapabilityAvailable: function() {
+ isCapabilityAvailable() {
return this.getDocumentInfoInternal().isModifiable;
- },
+ }
/** @override */
- getDefaultValueInternal: function() {
+ getDefaultValueInternal() {
return false;
- },
+ }
/** @override */
- getCapabilityNotAvailableValueInternal: function() {
+ getCapabilityNotAvailableValueInternal() {
return false;
}
- };
+ }
// Export
return {CssBackground: CssBackground};
diff --git a/chromium/chrome/browser/resources/print_preview/data/ticket_items/custom_margins.js b/chromium/chrome/browser/resources/print_preview/data/ticket_items/custom_margins.js
index 97c0ed8399b..a29bc892378 100644
--- a/chromium/chrome/browser/resources/print_preview/data/ticket_items/custom_margins.js
+++ b/chromium/chrome/browser/resources/print_preview/data/ticket_items/custom_margins.js
@@ -21,51 +21,23 @@ cr.define('print_preview.ticket_items', function() {
var CustomMarginsOrientation =
print_preview.ticket_items.CustomMarginsOrientation;
- /**
- * Custom page margins ticket item whose value is a
- * {@code print_preview.Margins}.
- * @param {!print_preview.AppState} appState App state used to persist custom
- * margins.
- * @param {!print_preview.DocumentInfo} documentInfo Information about the
- * document to print.
- * @constructor
- * @extends {print_preview.ticket_items.TicketItem}
- */
- function CustomMargins(appState, documentInfo) {
- print_preview.ticket_items.TicketItem.call(
- this, appState, print_preview.AppStateField.CUSTOM_MARGINS,
- null /*destinationStore*/, documentInfo);
- }
-
- /**
- * Mapping of a margin orientation to its opposite.
- * @type {!Object<!print_preview.ticket_items.CustomMarginsOrientation,
- * !print_preview.ticket_items.CustomMarginsOrientation>}
- * @private
- */
- CustomMargins.OppositeOrientation_ = {};
- CustomMargins.OppositeOrientation_[CustomMarginsOrientation.TOP] =
- CustomMarginsOrientation.BOTTOM;
- CustomMargins.OppositeOrientation_[CustomMarginsOrientation.RIGHT] =
- CustomMarginsOrientation.LEFT;
- CustomMargins.OppositeOrientation_[CustomMarginsOrientation.BOTTOM] =
- CustomMarginsOrientation.TOP;
- CustomMargins.OppositeOrientation_[CustomMarginsOrientation.LEFT] =
- CustomMarginsOrientation.RIGHT;
-
- /**
- * Minimum distance in points that two margins can be separated by.
- * @type {number}
- * @const
- * @private
- */
- CustomMargins.MINIMUM_MARGINS_DISTANCE_ = 72; // 1 inch.
-
- CustomMargins.prototype = {
- __proto__: print_preview.ticket_items.TicketItem.prototype,
+ class CustomMargins extends print_preview.ticket_items.TicketItem {
+ /**
+ * Custom page margins ticket item whose value is a
+ * {@code print_preview.Margins}.
+ * @param {!print_preview.AppState} appState App state used to persist
+ * custom margins.
+ * @param {!print_preview.DocumentInfo} documentInfo Information about the
+ * document to print.
+ */
+ constructor(appState, documentInfo) {
+ super(
+ appState, print_preview.AppStateField.CUSTOM_MARGINS,
+ null /*destinationStore*/, documentInfo);
+ }
/** @override */
- wouldValueBeValid: function(value) {
+ wouldValueBeValid(value) {
var margins = /** @type {!print_preview.Margins} */ (value);
for (var key in CustomMarginsOrientation) {
var o = CustomMarginsOrientation[key];
@@ -76,31 +48,31 @@ cr.define('print_preview.ticket_items', function() {
}
}
return true;
- },
+ }
/** @override */
- isCapabilityAvailable: function() {
+ isCapabilityAvailable() {
return this.getDocumentInfoInternal().isModifiable;
- },
+ }
/** @override */
- isValueEqual: function(value) {
+ isValueEqual(value) {
return this.getValue().equals(value);
- },
+ }
/**
* @param {!print_preview.ticket_items.CustomMarginsOrientation}
* orientation Specifies the margin to get the maximum value for.
* @return {number} Maximum value in points of the specified margin.
*/
- getMarginMax: function(orientation) {
+ getMarginMax(orientation) {
var oppositeOrient = CustomMargins.OppositeOrientation_[orientation];
var margins = /** @type {!print_preview.Margins} */ (this.getValue());
return this.getMarginMax_(orientation, margins.get(oppositeOrient));
- },
+ }
/** @override */
- updateValue: function(value) {
+ updateValue(value) {
var margins = /** @type {!print_preview.Margins} */ (value);
if (margins != null) {
margins = new print_preview.Margins(
@@ -111,7 +83,7 @@ cr.define('print_preview.ticket_items', function() {
}
print_preview.ticket_items.TicketItem.prototype.updateValue.call(
this, margins);
- },
+ }
/**
* Updates the specified margin in points while keeping the value within
@@ -120,26 +92,26 @@ cr.define('print_preview.ticket_items', function() {
* orientation Specifies the margin to update.
* @param {number} value Updated margin value in points.
*/
- updateMargin: function(orientation, value) {
+ updateMargin(orientation, value) {
var margins = /** @type {!print_preview.Margins} */ (this.getValue());
var oppositeOrientation = CustomMargins.OppositeOrientation_[orientation];
var max =
this.getMarginMax_(orientation, margins.get(oppositeOrientation));
value = Math.max(0, Math.min(max, value));
this.updateValue(margins.set(orientation, value));
- },
+ }
/** @override */
- getDefaultValueInternal: function() {
+ getDefaultValueInternal() {
return this.getDocumentInfoInternal().margins ||
new print_preview.Margins(72, 72, 72, 72);
- },
+ }
/** @override */
- getCapabilityNotAvailableValueInternal: function() {
+ getCapabilityNotAvailableValueInternal() {
return this.getDocumentInfoInternal().margins ||
new print_preview.Margins(72, 72, 72, 72);
- },
+ }
/**
* @param {!print_preview.ticket_items.CustomMarginsOrientation}
@@ -149,7 +121,7 @@ cr.define('print_preview.ticket_items', function() {
* @return {number} Maximum value in points of the specified margin.
* @private
*/
- getMarginMax_: function(orientation, oppositeMargin) {
+ getMarginMax_(orientation, oppositeMargin) {
var dimensionLength = (orientation == CustomMarginsOrientation.TOP ||
orientation == CustomMarginsOrientation.BOTTOM) ?
this.getDocumentInfoInternal().pageSize.height :
@@ -159,7 +131,32 @@ cr.define('print_preview.ticket_items', function() {
dimensionLength - CustomMargins.MINIMUM_MARGINS_DISTANCE_;
return Math.round(totalMargin > 0 ? totalMargin - oppositeMargin : 0);
}
- };
+ }
+
+ /**
+ * Mapping of a margin orientation to its opposite.
+ * @type {!Object<!print_preview.ticket_items.CustomMarginsOrientation,
+ * !print_preview.ticket_items.CustomMarginsOrientation>}
+ * @private
+ */
+ CustomMargins.OppositeOrientation_ = {};
+ CustomMargins.OppositeOrientation_[CustomMarginsOrientation.TOP] =
+ CustomMarginsOrientation.BOTTOM;
+ CustomMargins.OppositeOrientation_[CustomMarginsOrientation.RIGHT] =
+ CustomMarginsOrientation.LEFT;
+ CustomMargins.OppositeOrientation_[CustomMarginsOrientation.BOTTOM] =
+ CustomMarginsOrientation.TOP;
+ CustomMargins.OppositeOrientation_[CustomMarginsOrientation.LEFT] =
+ CustomMarginsOrientation.RIGHT;
+
+ /**
+ * Minimum distance in points that two margins can be separated by.
+ * @type {number}
+ * @const
+ * @private
+ */
+ CustomMargins.MINIMUM_MARGINS_DISTANCE_ = 72; // 1 inch.
+
// Export
return {CustomMargins: CustomMargins};
diff --git a/chromium/chrome/browser/resources/print_preview/data/ticket_items/dpi.js b/chromium/chrome/browser/resources/print_preview/data/ticket_items/dpi.js
index 7a514f1c9d8..218c7cc9b8f 100644
--- a/chromium/chrome/browser/resources/print_preview/data/ticket_items/dpi.js
+++ b/chromium/chrome/browser/resources/print_preview/data/ticket_items/dpi.js
@@ -5,25 +5,20 @@
cr.define('print_preview.ticket_items', function() {
'use strict';
- /**
- * DPI ticket item.
- * @param {!print_preview.AppState} appState App state used to persist DPI
- * selection.
- * @param {!print_preview.DestinationStore} destinationStore Destination store
- * used to determine if a destination has the DPI capability.
- * @constructor
- * @extends {print_preview.ticket_items.TicketItem}
- */
- function Dpi(appState, destinationStore) {
- print_preview.ticket_items.TicketItem.call(
- this, appState, print_preview.AppStateField.DPI, destinationStore);
- }
-
- Dpi.prototype = {
- __proto__: print_preview.ticket_items.TicketItem.prototype,
+ class Dpi extends print_preview.ticket_items.TicketItem {
+ /**
+ * DPI ticket item.
+ * @param {!print_preview.AppState} appState App state used to persist DPI
+ * selection.
+ * @param {!print_preview.DestinationStore} destinationStore Destination
+ * store used to determine if a destination has the DPI capability.
+ */
+ constructor(appState, destinationStore) {
+ super(appState, print_preview.AppStateField.DPI, destinationStore);
+ }
/** @override */
- wouldValueBeValid: function(value) {
+ wouldValueBeValid(value) {
if (!this.isCapabilityAvailable())
return false;
return this.capability.option.some(function(option) {
@@ -31,21 +26,21 @@ cr.define('print_preview.ticket_items', function() {
option.vertical_dpi == value.vertical_dpi &&
option.vendor_id == value.vendor_id;
});
- },
+ }
/** @override */
- isCapabilityAvailable: function() {
+ isCapabilityAvailable() {
return !!this.capability && !!this.capability.option &&
this.capability.option.length > 1;
- },
+ }
/** @override */
- isValueEqual: function(value) {
+ isValueEqual(value) {
var myValue = this.getValue();
return myValue.horizontal_dpi == value.horizontal_dpi &&
myValue.vertical_dpi == value.vertical_dpi &&
myValue.vendor_id == value.vendor_id;
- },
+ }
/** @return {Object} DPI capability of the selected destination. */
get capability() {
@@ -54,21 +49,21 @@ cr.define('print_preview.ticket_items', function() {
destination.capabilities.printer &&
destination.capabilities.printer.dpi) ||
null;
- },
+ }
/** @override */
- getDefaultValueInternal: function() {
+ getDefaultValueInternal() {
var defaultOptions = this.capability.option.filter(function(option) {
return option.is_default;
});
return defaultOptions.length > 0 ? defaultOptions[0] : null;
- },
+ }
/** @override */
- getCapabilityNotAvailableValueInternal: function() {
+ getCapabilityNotAvailableValueInternal() {
return {};
}
- };
+ }
// Export
return {Dpi: Dpi};
diff --git a/chromium/chrome/browser/resources/print_preview/data/ticket_items/duplex.js b/chromium/chrome/browser/resources/print_preview/data/ticket_items/duplex.js
index 9930e1cac0b..6d061d70360 100644
--- a/chromium/chrome/browser/resources/print_preview/data/ticket_items/duplex.js
+++ b/chromium/chrome/browser/resources/print_preview/data/ticket_items/duplex.js
@@ -5,32 +5,28 @@
cr.define('print_preview.ticket_items', function() {
'use strict';
- /**
- * Duplex ticket item whose value is a {@code boolean} that indicates whether
- * the document should be duplex printed.
- * @param {!print_preview.AppState} appState App state used to persist collate
- * selection.
- * @param {!print_preview.DestinationStore} destinationStore Destination store
- * used determine if a destination has the collate capability.
- * @constructor
- * @extends {print_preview.ticket_items.TicketItem}
- */
- function Duplex(appState, destinationStore) {
- print_preview.ticket_items.TicketItem.call(
- this, appState, print_preview.AppStateField.IS_DUPLEX_ENABLED,
- destinationStore);
- }
-
- Duplex.prototype = {
- __proto__: print_preview.ticket_items.TicketItem.prototype,
+ class Duplex extends print_preview.ticket_items.TicketItem {
+ /**
+ * Duplex ticket item whose value is a {@code boolean} that indicates
+ * whether the document should be duplex printed.
+ * @param {!print_preview.AppState} appState App state used to persist
+ * collate selection.
+ * @param {!print_preview.DestinationStore} destinationStore Destination
+ * store used determine if a destination has the collate capability.
+ */
+ constructor(appState, destinationStore) {
+ super(
+ appState, print_preview.AppStateField.IS_DUPLEX_ENABLED,
+ destinationStore);
+ }
/** @override */
- wouldValueBeValid: function(value) {
+ wouldValueBeValid(value) {
return true;
- },
+ }
/** @override */
- isCapabilityAvailable: function() {
+ isCapabilityAvailable() {
var cap = this.getDuplexCapability_();
if (!cap) {
return false;
@@ -42,34 +38,34 @@ cr.define('print_preview.ticket_items', function() {
hasSimplexOption = hasSimplexOption || option.type == 'NO_DUPLEX';
});
return hasLongEdgeOption && hasSimplexOption;
- },
+ }
/** @override */
- getDefaultValueInternal: function() {
+ getDefaultValueInternal() {
var cap = this.getDuplexCapability_();
var defaultOptions = cap.option.filter(function(option) {
return option.is_default;
});
return defaultOptions.length == 0 ? false :
defaultOptions[0].type == 'LONG_EDGE';
- },
+ }
/** @override */
- getCapabilityNotAvailableValueInternal: function() {
+ getCapabilityNotAvailableValueInternal() {
return false;
- },
+ }
/**
* @return {Object} Duplex capability of the selected destination.
* @private
*/
- getDuplexCapability_: function() {
+ getDuplexCapability_() {
var dest = this.getSelectedDestInternal();
return (dest && dest.capabilities && dest.capabilities.printer &&
dest.capabilities.printer.duplex) ||
null;
}
- };
+ }
// Export
return {Duplex: Duplex};
diff --git a/chromium/chrome/browser/resources/print_preview/data/ticket_items/fit_to_page.js b/chromium/chrome/browser/resources/print_preview/data/ticket_items/fit_to_page.js
index 6dc52f782e9..e24c6fd11d2 100644
--- a/chromium/chrome/browser/resources/print_preview/data/ticket_items/fit_to_page.js
+++ b/chromium/chrome/browser/resources/print_preview/data/ticket_items/fit_to_page.js
@@ -5,54 +5,51 @@
cr.define('print_preview.ticket_items', function() {
'use strict';
- /**
- * Fit-to-page ticket item whose value is a {@code boolean} that indicates
- * whether to scale the document to fit the page.
- * @param {!print_preview.AppState} appState App state to persist item value.
- * @param {!print_preview.DocumentInfo} documentInfo Information about the
- * document to print.
- * @param {!print_preview.DestinationStore} destinationStore Used to determine
- * whether fit to page should be available.
- * @constructor
- * @extends {print_preview.ticket_items.TicketItem}
- */
- function FitToPage(appState, documentInfo, destinationStore) {
- print_preview.ticket_items.TicketItem.call(
- this, appState, print_preview.AppStateField.IS_FIT_TO_PAGE_ENABLED,
- destinationStore, documentInfo);
- }
-
- FitToPage.prototype = {
- __proto__: print_preview.ticket_items.TicketItem.prototype,
+ class FitToPage extends print_preview.ticket_items.TicketItem {
+ /**
+ * Fit-to-page ticket item whose value is a {@code boolean} that indicates
+ * whether to scale the document to fit the page.
+ * @param {!print_preview.AppState} appState App state to persist item
+ * value.
+ * @param {!print_preview.DocumentInfo} documentInfo Information about the
+ * document to print.
+ * @param {!print_preview.DestinationStore} destinationStore Used to
+ * determine whether fit to page should be available.
+ */
+ constructor(appState, documentInfo, destinationStore) {
+ super(
+ appState, print_preview.AppStateField.IS_FIT_TO_PAGE_ENABLED,
+ destinationStore, documentInfo);
+ }
/** @override */
- wouldValueBeValid: function(value) {
+ wouldValueBeValid(value) {
return true;
- },
+ }
/** @override */
- isCapabilityAvailable: function() {
+ isCapabilityAvailable() {
return !this.getDocumentInfoInternal().isModifiable &&
(!this.getSelectedDestInternal() ||
this.getSelectedDestInternal().id !=
print_preview.Destination.GooglePromotedId.SAVE_AS_PDF);
- },
+ }
/** @override */
- getDefaultValueInternal: function() {
+ getDefaultValueInternal() {
// It's on by default since it is not a document feature, it is rather
// a property of the printer, hardware margins limitations. User can
// always override it.
return true;
- },
+ }
/** @override */
- getCapabilityNotAvailableValueInternal: function() {
+ getCapabilityNotAvailableValueInternal() {
return !this.getSelectedDestInternal() ||
this.getSelectedDestInternal().id !=
print_preview.Destination.GooglePromotedId.SAVE_AS_PDF;
}
- };
+ }
// Export
return {FitToPage: FitToPage};
diff --git a/chromium/chrome/browser/resources/print_preview/data/ticket_items/header_footer.js b/chromium/chrome/browser/resources/print_preview/data/ticket_items/header_footer.js
index b144537bbd4..f69389f27c9 100644
--- a/chromium/chrome/browser/resources/print_preview/data/ticket_items/header_footer.js
+++ b/chromium/chrome/browser/resources/print_preview/data/ticket_items/header_footer.js
@@ -5,77 +5,64 @@
cr.define('print_preview.ticket_items', function() {
'use strict';
- /**
- * Header-footer ticket item whose value is a {@code boolean} that indicates
- * whether the document should be printed with headers and footers.
- * @param {!print_preview.AppState} appState App state used to persist whether
- * header-footer is enabled.
- * @param {!print_preview.DocumentInfo} documentInfo Information about the
- * document to print.
- * @param {!print_preview.ticket_items.MarginsType} marginsType Ticket item
- * that stores which predefined margins to print with.
- * @param {!print_preview.ticket_items.CustomMargins} customMargins Ticket
- * item that stores custom margin values.
- * @param {!print_preview.ticket_items.MediaSize} mediaSize Ticket item that
- * stores media size values.
- * @param {!print_preview.ticket_items.Landscape} landscape Ticket item that
- * stores landscape values.
- * @constructor
- * @extends {print_preview.ticket_items.TicketItem}
- */
- function HeaderFooter(
- appState, documentInfo, marginsType, customMargins, mediaSize,
- landscape) {
- print_preview.ticket_items.TicketItem.call(
- this, appState, print_preview.AppStateField.IS_HEADER_FOOTER_ENABLED,
- null /*destinationStore*/, documentInfo);
-
+ class HeaderFooter extends print_preview.ticket_items.TicketItem {
/**
- * Ticket item that stores which predefined margins to print with.
- * @private {!print_preview.ticket_items.MarginsType}
+ * Header-footer ticket item whose value is a {@code boolean} that indicates
+ * whether the document should be printed with headers and footers.
+ * @param {!print_preview.AppState} appState App state used to persist
+ * whether header-footer is enabled.
+ * @param {!print_preview.DocumentInfo} documentInfo Information about the
+ * document to print.
+ * @param {!print_preview.ticket_items.MarginsType} marginsType Ticket item
+ * that stores which predefined margins to print with.
+ * @param {!print_preview.ticket_items.CustomMargins} customMargins Ticket
+ * item that stores custom margin values.
+ * @param {!print_preview.ticket_items.MediaSize} mediaSize Ticket item that
+ * stores media size values.
+ * @param {!print_preview.ticket_items.Landscape} landscape Ticket item that
+ * stores landscape values.
*/
- this.marginsType_ = marginsType;
+ constructor(
+ appState, documentInfo, marginsType, customMargins, mediaSize,
+ landscape) {
+ super(
+ appState, print_preview.AppStateField.IS_HEADER_FOOTER_ENABLED,
+ null /*destinationStore*/, documentInfo);
- /**
- * Ticket item that stores custom margin values.
- * @private {!print_preview.ticket_items.CustomMargins}
- */
- this.customMargins_ = customMargins;
+ /**
+ * Ticket item that stores which predefined margins to print with.
+ * @private {!print_preview.ticket_items.MarginsType}
+ */
+ this.marginsType_ = marginsType;
- /**
- * Ticket item that stores media size values.
- * @private {!print_preview.ticket_items.MediaSize}
- */
- this.mediaSize_ = mediaSize;
+ /**
+ * Ticket item that stores custom margin values.
+ * @private {!print_preview.ticket_items.CustomMargins}
+ */
+ this.customMargins_ = customMargins;
- /**
- * Ticket item that stores landscape values.
- * @private {!print_preview.ticket_items.Landscape}
- */
- this.landscape_ = landscape;
+ /**
+ * Ticket item that stores media size values.
+ * @private {!print_preview.ticket_items.MediaSize}
+ */
+ this.mediaSize_ = mediaSize;
- this.addEventListeners_();
- }
+ /**
+ * Ticket item that stores landscape values.
+ * @private {!print_preview.ticket_items.Landscape}
+ */
+ this.landscape_ = landscape;
- /**
- * Minimum height of page in microns to allow headers and footers. Should
- * match the value for min_size_printer_units in printing/print_settings.cc
- * so that we do not request header/footer for margins that will be zero.
- * @private {number}
- * @const
- */
- HeaderFooter.MINIMUM_HEIGHT_MICRONS_ = 25400;
-
- HeaderFooter.prototype = {
- __proto__: print_preview.ticket_items.TicketItem.prototype,
+ this.addEventListeners_();
+ }
/** @override */
- wouldValueBeValid: function(value) {
+ wouldValueBeValid(value) {
return true;
- },
+ }
/** @override */
- isCapabilityAvailable: function() {
+ isCapabilityAvailable() {
if (!this.getDocumentInfoInternal().isModifiable) {
return false;
}
@@ -108,23 +95,23 @@ cr.define('print_preview.ticket_items', function() {
var orientEnum = print_preview.ticket_items.CustomMarginsOrientation;
return margins == null || margins.get(orientEnum.TOP) > 0 ||
margins.get(orientEnum.BOTTOM) > 0;
- },
+ }
/** @override */
- getDefaultValueInternal: function() {
+ getDefaultValueInternal() {
return true;
- },
+ }
/** @override */
- getCapabilityNotAvailableValueInternal: function() {
+ getCapabilityNotAvailableValueInternal() {
return false;
- },
+ }
/**
* Adds CHANGE listeners to dependent ticket items.
* @private
*/
- addEventListeners_: function() {
+ addEventListeners_() {
this.getTrackerInternal().add(
this.marginsType_,
print_preview.ticket_items.TicketItem.EventType.CHANGE,
@@ -142,7 +129,17 @@ cr.define('print_preview.ticket_items', function() {
print_preview.ticket_items.TicketItem.EventType.CHANGE,
this.dispatchChangeEventInternal.bind(this));
}
- };
+ }
+
+ /**
+ * Minimum height of page in microns to allow headers and footers. Should
+ * match the value for min_size_printer_units in printing/print_settings.cc
+ * so that we do not request header/footer for margins that will be zero.
+ * @private {number}
+ * @const
+ */
+ HeaderFooter.MINIMUM_HEIGHT_MICRONS_ = 25400;
+
// Export
return {HeaderFooter: HeaderFooter};
diff --git a/chromium/chrome/browser/resources/print_preview/data/ticket_items/landscape.js b/chromium/chrome/browser/resources/print_preview/data/ticket_items/landscape.js
index df4dc00d0e8..5c8ef4f6438 100644
--- a/chromium/chrome/browser/resources/print_preview/data/ticket_items/landscape.js
+++ b/chromium/chrome/browser/resources/print_preview/data/ticket_items/landscape.js
@@ -5,54 +5,50 @@
cr.define('print_preview.ticket_items', function() {
'use strict';
- /**
- * Landscape ticket item whose value is a {@code boolean} that indicates
- * whether the document should be printed in landscape orientation.
- * @param {!print_preview.AppState} appState App state object used to persist
- * ticket item values.
- * @param {!print_preview.DestinationStore} destinationStore Destination store
- * used to determine the default landscape value and if landscape
- * printing is available.
- * @param {!print_preview.DocumentInfo} documentInfo Information about the
- * document to print.
- * @param {!print_preview.ticket_items.MarginsType} marginsType Reset when
- * landscape value changes.
- * @param {!print_preview.ticket_items.CustomMargins} customMargins Reset when
- * landscape value changes.
- * @constructor
- * @extends {print_preview.ticket_items.TicketItem}
- */
- function Landscape(
- appState, destinationStore, documentInfo, marginsType, customMargins) {
- print_preview.ticket_items.TicketItem.call(
- this, appState, print_preview.AppStateField.IS_LANDSCAPE_ENABLED,
- destinationStore, documentInfo);
-
+ class Landscape extends print_preview.ticket_items.TicketItem {
/**
- * Margins ticket item. Reset when landscape ticket item changes.
- * @type {!print_preview.ticket_items.MarginsType}
- * @private
+ * Landscape ticket item whose value is a {@code boolean} that indicates
+ * whether the document should be printed in landscape orientation.
+ * @param {!print_preview.AppState} appState App state object used to
+ * persist ticket item values.
+ * @param {!print_preview.DestinationStore} destinationStore Destination
+ * store used to determine the default landscape value and if landscape
+ * printing is available.
+ * @param {!print_preview.DocumentInfo} documentInfo Information about the
+ * document to print.
+ * @param {!print_preview.ticket_items.MarginsType} marginsType Reset when
+ * landscape value changes.
+ * @param {!print_preview.ticket_items.CustomMargins} customMargins Reset
+ * when landscape value changes.
*/
- this.marginsType_ = marginsType;
+ constructor(
+ appState, destinationStore, documentInfo, marginsType, customMargins) {
+ super(
+ appState, print_preview.AppStateField.IS_LANDSCAPE_ENABLED,
+ destinationStore, documentInfo);
- /**
- * Custom margins ticket item. Reset when landscape ticket item changes.
- * @type {!print_preview.ticket_items.CustomMargins}
- * @private
- */
- this.customMargins_ = customMargins;
- }
+ /**
+ * Margins ticket item. Reset when landscape ticket item changes.
+ * @type {!print_preview.ticket_items.MarginsType}
+ * @private
+ */
+ this.marginsType_ = marginsType;
- Landscape.prototype = {
- __proto__: print_preview.ticket_items.TicketItem.prototype,
+ /**
+ * Custom margins ticket item. Reset when landscape ticket item changes.
+ * @type {!print_preview.ticket_items.CustomMargins}
+ * @private
+ */
+ this.customMargins_ = customMargins;
+ }
/** @override */
- wouldValueBeValid: function(value) {
+ wouldValueBeValid(value) {
return true;
- },
+ }
/** @override */
- isCapabilityAvailable: function() {
+ isCapabilityAvailable() {
var cap = this.getPageOrientationCapability_();
if (!cap)
return false;
@@ -70,28 +66,28 @@ cr.define('print_preview.ticket_items', function() {
return this.getDocumentInfoInternal().isModifiable &&
!this.getDocumentInfoInternal().hasCssMediaStyles &&
hasAutoOrPortraitOption && hasLandscapeOption;
- },
+ }
/** @override */
- getDefaultValueInternal: function() {
+ getDefaultValueInternal() {
var cap = this.getPageOrientationCapability_();
var defaultOptions = cap.option.filter(function(option) {
return option.is_default;
});
return defaultOptions.length == 0 ? false :
defaultOptions[0].type == 'LANDSCAPE';
- },
+ }
/** @override */
- getCapabilityNotAvailableValueInternal: function() {
+ getCapabilityNotAvailableValueInternal() {
var doc = this.getDocumentInfoInternal();
return doc.hasCssMediaStyles ?
(doc.pageSize.width > doc.pageSize.height) :
false;
- },
+ }
/** @override */
- updateValueInternal: function(value) {
+ updateValueInternal(value) {
var updateMargins = !this.isValueEqual(value);
print_preview.ticket_items.TicketItem.prototype.updateValueInternal.call(
this, value);
@@ -101,32 +97,32 @@ cr.define('print_preview.ticket_items', function() {
print_preview.ticket_items.MarginsTypeValue.DEFAULT);
this.customMargins_.updateValue(null);
}
- },
+ }
/**
* @return {boolean} Whether capability contains the |value|.
* @param {string} value Option to check.
*/
- hasOption: function(value) {
+ hasOption(value) {
var cap = this.getPageOrientationCapability_();
if (!cap)
return false;
return cap.option.some(function(option) {
return option.type == value;
});
- },
+ }
/**
* @return {Object} Page orientation capability of the selected destination.
* @private
*/
- getPageOrientationCapability_: function() {
+ getPageOrientationCapability_() {
var dest = this.getSelectedDestInternal();
return (dest && dest.capabilities && dest.capabilities.printer &&
dest.capabilities.printer.page_orientation) ||
null;
}
- };
+ }
// Export
return {Landscape: Landscape};
diff --git a/chromium/chrome/browser/resources/print_preview/data/ticket_items/margins_type.js b/chromium/chrome/browser/resources/print_preview/data/ticket_items/margins_type.js
index 808e1486464..a9ae4351994 100644
--- a/chromium/chrome/browser/resources/print_preview/data/ticket_items/margins_type.js
+++ b/chromium/chrome/browser/resources/print_preview/data/ticket_items/margins_type.js
@@ -20,57 +20,53 @@ print_preview.ticket_items.MarginsTypeValue = {
cr.define('print_preview.ticket_items', function() {
'use strict';
- /**
- * Margins type ticket item whose value is a
- * print_preview.ticket_items.MarginsTypeValue} that indicates what
- * predefined margins type to use.
- * @param {!print_preview.AppState} appState App state persistence object to
- * save the state of the margins type selection.
- * @param {!print_preview.DocumentInfo} documentInfo Information about the
- * document to print.
- * @param {!print_preview.ticket_items.CustomMargins} customMargins Custom
- * margins ticket item, used to write when margins type changes.
- * @constructor
- * @extends {print_preview.ticket_items.TicketItem}
- */
- function MarginsType(appState, documentInfo, customMargins) {
- print_preview.ticket_items.TicketItem.call(
- this, appState, print_preview.AppStateField.MARGINS_TYPE,
- null /*destinationStore*/, documentInfo);
-
+ class MarginsType extends print_preview.ticket_items.TicketItem {
/**
- * Custom margins ticket item, used to write when margins type changes.
- * @type {!print_preview.ticket_items.CustomMargins}
- * @private
+ * Margins type ticket item whose value is a
+ * print_preview.ticket_items.MarginsTypeValue} that indicates what
+ * predefined margins type to use.
+ * @param {!print_preview.AppState} appState App state persistence object to
+ * save the state of the margins type selection.
+ * @param {!print_preview.DocumentInfo} documentInfo Information about the
+ * document to print.
+ * @param {!print_preview.ticket_items.CustomMargins} customMargins Custom
+ * margins ticket item, used to write when margins type changes.
*/
- this.customMargins_ = customMargins;
- }
+ constructor(appState, documentInfo, customMargins) {
+ super(
+ appState, print_preview.AppStateField.MARGINS_TYPE,
+ null /*destinationStore*/, documentInfo);
- MarginsType.prototype = {
- __proto__: print_preview.ticket_items.TicketItem.prototype,
+ /**
+ * Custom margins ticket item, used to write when margins type changes.
+ * @type {!print_preview.ticket_items.CustomMargins}
+ * @private
+ */
+ this.customMargins_ = customMargins;
+ }
/** @override */
- wouldValueBeValid: function(value) {
+ wouldValueBeValid(value) {
return true;
- },
+ }
/** @override */
- isCapabilityAvailable: function() {
+ isCapabilityAvailable() {
return this.getDocumentInfoInternal().isModifiable;
- },
+ }
/** @override */
- getDefaultValueInternal: function() {
+ getDefaultValueInternal() {
return print_preview.ticket_items.MarginsTypeValue.DEFAULT;
- },
+ }
/** @override */
- getCapabilityNotAvailableValueInternal: function() {
+ getCapabilityNotAvailableValueInternal() {
return print_preview.ticket_items.MarginsTypeValue.DEFAULT;
- },
+ }
/** @override */
- updateValueInternal: function(value) {
+ updateValueInternal(value) {
print_preview.ticket_items.TicketItem.prototype.updateValueInternal.call(
this, value);
if (this.isValueEqual(
@@ -80,7 +76,7 @@ cr.define('print_preview.ticket_items', function() {
this.customMargins_.updateValue(this.customMargins_.getValue());
}
}
- };
+ }
// Export
return {MarginsType: MarginsType};
diff --git a/chromium/chrome/browser/resources/print_preview/data/ticket_items/media_size.js b/chromium/chrome/browser/resources/print_preview/data/ticket_items/media_size.js
index 09abc7a3c91..8f49b7eaaba 100644
--- a/chromium/chrome/browser/resources/print_preview/data/ticket_items/media_size.js
+++ b/chromium/chrome/browser/resources/print_preview/data/ticket_items/media_size.js
@@ -5,45 +5,42 @@
cr.define('print_preview.ticket_items', function() {
'use strict';
- /**
- * Media size ticket item.
- * @param {!print_preview.AppState} appState App state used to persist media
- * size selection.
- * @param {!print_preview.DestinationStore} destinationStore Destination store
- * used to determine if a destination has the media size capability.
- * @param {!print_preview.DocumentInfo} documentInfo Information about the
- * document to print.
- * @param {!print_preview.ticket_items.MarginsType} marginsType Reset when
- * landscape value changes.
- * @param {!print_preview.ticket_items.CustomMargins} customMargins Reset when
- * landscape value changes.
- * @constructor
- * @extends {print_preview.ticket_items.TicketItem}
- */
- function MediaSize(
- appState, destinationStore, documentInfo, marginsType, customMargins) {
- print_preview.ticket_items.TicketItem.call(
- this, appState, print_preview.AppStateField.MEDIA_SIZE,
- destinationStore, documentInfo);
-
+ class MediaSize extends print_preview.ticket_items.TicketItem {
/**
- * Margins ticket item. Reset when this item changes.
- * @private {!print_preview.ticket_items.MarginsType}
+ * Media size ticket item.
+ * @param {!print_preview.AppState} appState App state used to persist media
+ * size selection.
+ * @param {!print_preview.DestinationStore} destinationStore Destination
+ * store used to determine if a destination has the media size
+ * capability.
+ * @param {!print_preview.DocumentInfo} documentInfo Information about the
+ * document to print.
+ * @param {!print_preview.ticket_items.MarginsType} marginsType Reset when
+ * landscape value changes.
+ * @param {!print_preview.ticket_items.CustomMargins} customMargins Reset
+ * when landscape value changes.
*/
- this.marginsType_ = marginsType;
+ constructor(
+ appState, destinationStore, documentInfo, marginsType, customMargins) {
+ super(
+ appState, print_preview.AppStateField.MEDIA_SIZE, destinationStore,
+ documentInfo);
- /**
- * Custom margins ticket item. Reset when this item changes.
- * @private {!print_preview.ticket_items.CustomMargins}
- */
- this.customMargins_ = customMargins;
- }
+ /**
+ * Margins ticket item. Reset when this item changes.
+ * @private {!print_preview.ticket_items.MarginsType}
+ */
+ this.marginsType_ = marginsType;
- MediaSize.prototype = {
- __proto__: print_preview.ticket_items.TicketItem.prototype,
+ /**
+ * Custom margins ticket item. Reset when this item changes.
+ * @private {!print_preview.ticket_items.CustomMargins}
+ */
+ this.customMargins_ = customMargins;
+ }
/** @override */
- wouldValueBeValid: function(value) {
+ wouldValueBeValid(value) {
if (!this.isCapabilityAvailable()) {
return false;
}
@@ -53,10 +50,10 @@ cr.define('print_preview.ticket_items', function() {
option.is_continuous_feed == value.is_continuous_feed &&
option.vendor_id == value.vendor_id;
});
- },
+ }
/** @override */
- isCapabilityAvailable: function() {
+ isCapabilityAvailable() {
var knownSizeToSaveAsPdf =
(!this.getDocumentInfoInternal().isModifiable ||
this.getDocumentInfoInternal().hasCssMediaStyles) &&
@@ -64,16 +61,16 @@ cr.define('print_preview.ticket_items', function() {
this.getSelectedDestInternal().id ==
print_preview.Destination.GooglePromotedId.SAVE_AS_PDF;
return !knownSizeToSaveAsPdf && !!this.capability;
- },
+ }
/** @override */
- isValueEqual: function(value) {
+ isValueEqual(value) {
var myValue = this.getValue();
return myValue.width_microns == value.width_microns &&
myValue.height_microns == value.height_microns &&
myValue.is_continuous_feed == value.is_continuous_feed &&
myValue.vendor_id == value.vendor_id;
- },
+ }
/** @return {Object} Media size capability of the selected destination. */
get capability() {
@@ -82,23 +79,23 @@ cr.define('print_preview.ticket_items', function() {
destination.capabilities.printer &&
destination.capabilities.printer.media_size) ||
null;
- },
+ }
/** @override */
- getDefaultValueInternal: function() {
+ getDefaultValueInternal() {
var defaultOptions = this.capability.option.filter(function(option) {
return option.is_default;
});
return defaultOptions.length > 0 ? defaultOptions[0] : null;
- },
+ }
/** @override */
- getCapabilityNotAvailableValueInternal: function() {
+ getCapabilityNotAvailableValueInternal() {
return {};
- },
+ }
/** @override */
- updateValueInternal: function(value) {
+ updateValueInternal(value) {
var updateMargins = !this.isValueEqual(value);
print_preview.ticket_items.TicketItem.prototype.updateValueInternal.call(
this, value);
@@ -109,7 +106,7 @@ cr.define('print_preview.ticket_items', function() {
this.customMargins_.updateValue(null);
}
}
- };
+ }
// Export
return {MediaSize: MediaSize};
diff --git a/chromium/chrome/browser/resources/print_preview/data/ticket_items/page_range.js b/chromium/chrome/browser/resources/print_preview/data/ticket_items/page_range.js
index 5eb176f8bbe..23de286cfe4 100644
--- a/chromium/chrome/browser/resources/print_preview/data/ticket_items/page_range.js
+++ b/chromium/chrome/browser/resources/print_preview/data/ticket_items/page_range.js
@@ -5,79 +5,67 @@
cr.define('print_preview.ticket_items', function() {
'use strict';
- /**
- * Page range ticket item whose value is a {@code string} that represents
- * which pages in the document should be printed.
- * @param {!print_preview.DocumentInfo} documentInfo Information about the
- * document to print.
- * @constructor
- * @extends {print_preview.ticket_items.TicketItem}
- */
- function PageRange(documentInfo) {
- print_preview.ticket_items.TicketItem.call(
- this, null /*appState*/, null /*field*/, null /*destinationStore*/,
- documentInfo);
- }
-
- /**
- * Impossibly large page number.
- * @type {number}
- * @const
- * @private
- */
- PageRange.MAX_PAGE_NUMBER_ = 1000000000;
-
- PageRange.prototype = {
- __proto__: print_preview.ticket_items.TicketItem.prototype,
+ class PageRange extends print_preview.ticket_items.TicketItem {
+ /**
+ * Page range ticket item whose value is a {@code string} that represents
+ * which pages in the document should be printed.
+ * @param {!print_preview.DocumentInfo} documentInfo Information about the
+ * document to print.
+ */
+ constructor(documentInfo) {
+ super(
+ null /*appState*/, null /*field*/, null /*destinationStore*/,
+ documentInfo);
+ }
/** @override */
- wouldValueBeValid: function(value) {
+ wouldValueBeValid(value) {
var result = pageRangeTextToPageRanges(
value, this.getDocumentInfoInternal().pageCount);
- return result instanceof Array;
- },
+ return Array.isArray(result);
+ }
/**
* @return {!print_preview.PageNumberSet} Set of page numbers defined by the
* page range string.
*/
- getPageNumberSet: function() {
+ getPageNumberSet() {
var pageNumberList = pageRangeTextToPageList(
this.getValueAsString_(), this.getDocumentInfoInternal().pageCount);
return new print_preview.PageNumberSet(pageNumberList);
- },
+ }
/** @override */
- isCapabilityAvailable: function() {
+ isCapabilityAvailable() {
return true;
- },
+ }
/** @override */
- getDefaultValueInternal: function() {
+ getDefaultValueInternal() {
return '';
- },
+ }
/** @override */
- getCapabilityNotAvailableValueInternal: function() {
+ getCapabilityNotAvailableValueInternal() {
return '';
- },
+ }
/**
* @return {string} The value of the ticket item as a string.
* @private
*/
- getValueAsString_: function() {
+ getValueAsString_() {
return /** @type {string} */ (this.getValue());
- },
+ }
/**
* @return {!Array<Object<{from: number, to: number}>>} A list of page
* ranges.
*/
- getPageRanges: function() {
+ getPageRanges() {
var pageRanges = pageRangeTextToPageRanges(this.getValueAsString_());
- return pageRanges instanceof Array ? pageRanges : [];
- },
+ return Array.isArray(pageRanges) ? pageRanges : [];
+ }
/**
* @return {!Array<Object<{from: number, to: number}>>} A list of page
@@ -85,29 +73,37 @@ cr.define('print_preview.ticket_items', function() {
* TODO(vitalybuka): this should be removed when native layer switched to
* page ranges.
*/
- getDocumentPageRanges: function() {
+ getDocumentPageRanges() {
var pageRanges = pageRangeTextToPageRanges(
this.getValueAsString_(), this.getDocumentInfoInternal().pageCount);
- return pageRanges instanceof Array ? pageRanges : [];
- },
+ return Array.isArray(pageRanges) ? pageRanges : [];
+ }
/**
* @return {!number} Number of pages reported by the document.
*/
- getDocumentNumPages: function() {
+ getDocumentNumPages() {
return this.getDocumentInfoInternal().pageCount;
- },
+ }
/**
* @return {!PageRangeStatus}
*/
- checkValidity: function() {
+ checkValidity() {
var pageRanges = pageRangeTextToPageRanges(
this.getValueAsString_(), this.getDocumentInfoInternal().pageCount);
- return pageRanges instanceof Array ? PageRangeStatus.NO_ERROR :
- pageRanges;
- },
- };
+ return Array.isArray(pageRanges) ? PageRangeStatus.NO_ERROR : pageRanges;
+ }
+ }
+
+ /**
+ * Impossibly large page number.
+ * @type {number}
+ * @const
+ * @private
+ */
+ PageRange.MAX_PAGE_NUMBER_ = 1000000000;
+
// Export
return {PageRange: PageRange};
diff --git a/chromium/chrome/browser/resources/print_preview/data/ticket_items/rasterize.js b/chromium/chrome/browser/resources/print_preview/data/ticket_items/rasterize.js
index 5827ba55025..15771711264 100644
--- a/chromium/chrome/browser/resources/print_preview/data/ticket_items/rasterize.js
+++ b/chromium/chrome/browser/resources/print_preview/data/ticket_items/rasterize.js
@@ -5,43 +5,39 @@
cr.define('print_preview.ticket_items', function() {
'use strict';
- /**
- * Rasterize ticket item whose value is a {@code boolean} that indicates
- * whether the PDF document should be rendered as images.
- * @constructor
- * @param {!print_preview.DocumentInfo} documentInfo Information about the
- * document to print, used to determine if document is a PDF.
- * @extends {print_preview.ticket_items.TicketItem}
- */
- function Rasterize(destinationStore, documentInfo) {
- print_preview.ticket_items.TicketItem.call(
- this, null /* appState */, null /* field */,
- null /* destinationStore */, documentInfo);
- }
-
- Rasterize.prototype = {
- __proto__: print_preview.ticket_items.TicketItem.prototype,
+ class Rasterize extends print_preview.ticket_items.TicketItem {
+ /**
+ * Rasterize ticket item whose value is a {@code boolean} that indicates
+ * whether the PDF document should be rendered as images.
+ * @param {!print_preview.DocumentInfo} documentInfo Information about the
+ * document to print, used to determine if document is a PDF.
+ */
+ constructor(destinationStore, documentInfo) {
+ super(
+ null /* appState */, null /* field */, null /* destinationStore */,
+ documentInfo);
+ }
/** @override */
- wouldValueBeValid: function(value) {
+ wouldValueBeValid(value) {
return true;
- },
+ }
/** @override */
- isCapabilityAvailable: function() {
+ isCapabilityAvailable() {
return !this.getDocumentInfoInternal().isModifiable;
- },
+ }
/** @override */
- getDefaultValueInternal: function() {
+ getDefaultValueInternal() {
return false;
- },
+ }
/** @override */
- getCapabilityNotAvailableValueInternal: function() {
+ getCapabilityNotAvailableValueInternal() {
return this.getDefaultValueInternal();
}
- };
+ }
// Export
return {Rasterize: Rasterize};
diff --git a/chromium/chrome/browser/resources/print_preview/data/ticket_items/scaling.js b/chromium/chrome/browser/resources/print_preview/data/ticket_items/scaling.js
index e51252fce26..6ecc989d0e1 100644
--- a/chromium/chrome/browser/resources/print_preview/data/ticket_items/scaling.js
+++ b/chromium/chrome/browser/resources/print_preview/data/ticket_items/scaling.js
@@ -5,39 +5,36 @@
cr.define('print_preview.ticket_items', function() {
'use strict';
- /**
- * Scaling ticket item whose value is a {@code string} that indicates what the
- * scaling (in percent) of the document should be. The ticket item is backed
- * by a string since the user can textually input the scaling value.
- * @param {!print_preview.AppState} appState App state to persist item value.
- * @param {!print_preview.DocumentInfo} documentInfo Information about the
- * document to print.
- * @param {!print_preview.DestinationStore} destinationStore Used to determine
- * whether fit to page should be available.
- * @constructor
- * @extends {print_preview.ticket_items.TicketItem}
- */
- function Scaling(appState, destinationStore, documentInfo) {
- print_preview.ticket_items.TicketItem.call(
- this, appState, print_preview.AppStateField.SCALING, destinationStore,
- documentInfo);
- }
-
- Scaling.prototype = {
- __proto__: print_preview.ticket_items.TicketItem.prototype,
+ class Scaling extends print_preview.ticket_items.TicketItem {
+ /**
+ * Scaling ticket item whose value is a {@code string} that indicates what
+ * the scaling (in percent) of the document should be. The ticket item is
+ * backed by a string since the user can textually input the scaling value.
+ * @param {!print_preview.AppState} appState App state to persist item
+ * value.
+ * @param {!print_preview.DocumentInfo} documentInfo Information about the
+ * document to print.
+ * @param {!print_preview.DestinationStore} destinationStore Used to
+ * determine whether scaling should be available.
+ */
+ constructor(appState, destinationStore, documentInfo) {
+ super(
+ appState, print_preview.AppStateField.SCALING, destinationStore,
+ documentInfo);
+ }
/** @override */
- wouldValueBeValid: function(value) {
+ wouldValueBeValid(value) {
return value != '';
- },
+ }
/** @override */
- isValueEqual: function(value) {
+ isValueEqual(value) {
return this.getValue() == value;
- },
+ }
/** @override */
- isCapabilityAvailable: function() {
+ isCapabilityAvailable() {
// This is not a function of the printer, but should be disabled if we are
// saving a PDF to a PDF.
var knownSizeToSaveAsPdf =
@@ -47,25 +44,25 @@ cr.define('print_preview.ticket_items', function() {
this.getSelectedDestInternal().id ==
print_preview.Destination.GooglePromotedId.SAVE_AS_PDF;
return !knownSizeToSaveAsPdf;
- },
+ }
/** @return {number} The scaling percentage indicated by the ticket item. */
- getValueAsNumber: function() {
+ getValueAsNumber() {
var value = this.getValue() == '' ? 0 : parseInt(this.getValue(), 10);
assert(!isNaN(value));
return value;
- },
+ }
/** @override */
- getDefaultValueInternal: function() {
+ getDefaultValueInternal() {
return '100';
- },
+ }
/** @override */
- getCapabilityNotAvailableValueInternal: function() {
+ getCapabilityNotAvailableValueInternal() {
return '100';
- },
- };
+ }
+ }
// Export
return {Scaling: Scaling};
diff --git a/chromium/chrome/browser/resources/print_preview/data/ticket_items/selection_only.js b/chromium/chrome/browser/resources/print_preview/data/ticket_items/selection_only.js
index f6bfaf73c62..75c5554be5e 100644
--- a/chromium/chrome/browser/resources/print_preview/data/ticket_items/selection_only.js
+++ b/chromium/chrome/browser/resources/print_preview/data/ticket_items/selection_only.js
@@ -5,44 +5,40 @@
cr.define('print_preview.ticket_items', function() {
'use strict';
- /**
- * Ticket item whose value is a {@code boolean} that represents whether to
- * print selection only.
- * @param {!print_preview.DocumentInfo} documentInfo Information about the
- * document to print.
- * @constructor
- * @extends {print_preview.ticket_items.TicketItem}
- */
- function SelectionOnly(documentInfo) {
- print_preview.ticket_items.TicketItem.call(
- this, null /*appState*/, null /*field*/, null /*destinationStore*/,
- documentInfo);
- }
-
- SelectionOnly.prototype = {
- __proto__: print_preview.ticket_items.TicketItem.prototype,
+ class SelectionOnly extends print_preview.ticket_items.TicketItem {
+ /**
+ * Ticket item whose value is a {@code boolean} that represents whether to
+ * print selection only.
+ * @param {!print_preview.DocumentInfo} documentInfo Information about the
+ * document to print.
+ */
+ constructor(documentInfo) {
+ super(
+ null /*appState*/, null /*field*/, null /*destinationStore*/,
+ documentInfo);
+ }
/** @override */
- wouldValueBeValid: function(value) {
+ wouldValueBeValid(value) {
return true;
- },
+ }
/** @override */
- isCapabilityAvailable: function() {
+ isCapabilityAvailable() {
return this.getDocumentInfoInternal().isModifiable &&
this.getDocumentInfoInternal().hasSelection;
- },
+ }
/** @override */
- getDefaultValueInternal: function() {
+ getDefaultValueInternal() {
return false;
- },
+ }
/** @override */
- getCapabilityNotAvailableValueInternal: function() {
+ getCapabilityNotAvailableValueInternal() {
return false;
}
- };
+ }
// Export
return {SelectionOnly: SelectionOnly};
diff --git a/chromium/chrome/browser/resources/print_preview/data/ticket_items/ticket_item.js b/chromium/chrome/browser/resources/print_preview/data/ticket_items/ticket_item.js
index ce3da11b16e..9d543289ea7 100644
--- a/chromium/chrome/browser/resources/print_preview/data/ticket_items/ticket_item.js
+++ b/chromium/chrome/browser/resources/print_preview/data/ticket_items/ticket_item.js
@@ -9,103 +9,92 @@ print_preview.ValueType;
cr.define('print_preview.ticket_items', function() {
'use strict';
- /**
- * An object that represents a user modifiable item in a print ticket. Each
- * ticket item has a value which can be set by the user. Ticket items can also
- * be unavailable for modifying if the print destination doesn't support it or
- * if other ticket item constraints are not met.
- * @param {?print_preview.AppState} appState Application state model to update
- * when ticket items update.
- * @param {?print_preview.AppStateField} field Field of the app state to
- * update when ticket item is updated.
- * @param {?print_preview.DestinationStore} destinationStore Used listen for
- * changes in the currently selected destination's capabilities. Since
- * this is a common dependency of ticket items, it's handled in the base
- * class.
- * @param {?print_preview.DocumentInfo=} opt_documentInfo Used to listen for
- * changes in the document. Since this is a common dependency of ticket
- * items, it's handled in the base class.
- * @constructor
- * @extends {cr.EventTarget}
- */
- function TicketItem(appState, field, destinationStore, opt_documentInfo) {
- cr.EventTarget.call(this);
-
- /**
- * Application state model to update when ticket items update.
- * @type {print_preview.AppState}
- * @private
- */
- this.appState_ = appState || null;
-
- /**
- * Field of the app state to update when ticket item is updated.
- * @type {?print_preview.AppStateField}
- * @private
- */
- this.field_ = field || null;
-
- /**
- * Used listen for changes in the currently selected destination's
- * capabilities.
- * @type {print_preview.DestinationStore}
- * @private
- */
- this.destinationStore_ = destinationStore || null;
-
- /**
- * Used to listen for changes in the document.
- * @type {print_preview.DocumentInfo}
- * @private
- */
- this.documentInfo_ = opt_documentInfo || null;
-
- /**
- * Backing store of the print ticket item.
- * @type {Object}
- * @private
- */
- this.value_ = null;
-
- /**
- * Keeps track of event listeners for the ticket item.
- * @type {!EventTracker}
- * @private
- */
- this.tracker_ = new EventTracker();
-
- this.addEventHandlers_();
- }
-
- /**
- * Event types dispatched by this class.
- * @enum {string}
- */
- TicketItem.EventType = {
- CHANGE: 'print_preview.ticket_items.TicketItem.CHANGE'
- };
-
- TicketItem.prototype = {
- __proto__: cr.EventTarget.prototype,
+ class TicketItem extends cr.EventTarget {
+ /**
+ * An object that represents a user modifiable item in a print ticket. Each
+ * ticket item has a value which can be set by the user. Ticket items can
+ * also be unavailable for modifying if the print destination doesn't
+ * support it or if other ticket item constraints are not met.
+ * @param {?print_preview.AppState} appState Application state model to
+ * update
+ * when ticket items update.
+ * @param {?print_preview.AppStateField} field Field of the app state to
+ * update when ticket item is updated.
+ * @param {?print_preview.DestinationStore} destinationStore Used listen for
+ * changes in the currently selected destination's capabilities. Since
+ * this is a common dependency of ticket items, it's handled in the base
+ * class.
+ * @param {?print_preview.DocumentInfo=} opt_documentInfo Used to listen for
+ * changes in the document. Since this is a common dependency of ticket
+ * items, it's handled in the base class.
+ */
+ constructor(appState, field, destinationStore, opt_documentInfo) {
+ super();
+
+ /**
+ * Application state model to update when ticket items update.
+ * @type {print_preview.AppState}
+ * @private
+ */
+ this.appState_ = appState || null;
+
+ /**
+ * Field of the app state to update when ticket item is updated.
+ * @type {?print_preview.AppStateField}
+ * @private
+ */
+ this.field_ = field || null;
+
+ /**
+ * Used listen for changes in the currently selected destination's
+ * capabilities.
+ * @type {print_preview.DestinationStore}
+ * @private
+ */
+ this.destinationStore_ = destinationStore || null;
+
+ /**
+ * Used to listen for changes in the document.
+ * @type {print_preview.DocumentInfo}
+ * @private
+ */
+ this.documentInfo_ = opt_documentInfo || null;
+
+ /**
+ * Backing store of the print ticket item.
+ * @type {Object}
+ * @private
+ */
+ this.value_ = null;
+
+ /**
+ * Keeps track of event listeners for the ticket item.
+ * @type {!EventTracker}
+ * @private
+ */
+ this.tracker_ = new EventTracker();
+
+ this.addEventHandlers_();
+ }
/**
* Determines whether a given value is valid for the ticket item.
* @param {?} value The value to check for validity.
* @return {boolean} Whether the given value is valid for the ticket item.
*/
- wouldValueBeValid: function(value) {
+ wouldValueBeValid(value) {
throw Error('Abstract method not overridden');
- },
+ }
/**
* @return {boolean} Whether the print destination capability is available.
*/
- isCapabilityAvailable: function() {
+ isCapabilityAvailable() {
throw Error('Abstract method not overridden');
- },
+ }
/** @return {print_preview.ValueType} The value of the ticket item. */
- getValue: function() {
+ getValue() {
if (!this.isCapabilityAvailable()) {
return this.getCapabilityNotAvailableValueInternal();
}
@@ -113,34 +102,34 @@ cr.define('print_preview.ticket_items', function() {
return this.getDefaultValueInternal();
}
return this.value_;
- },
+ }
/** @return {boolean} Whether the ticket item was modified by the user. */
- isUserEdited: function() {
+ isUserEdited() {
return this.value_ != null;
- },
+ }
/** @return {boolean} Whether the ticket item's value is valid. */
- isValid: function() {
+ isValid() {
if (!this.isUserEdited()) {
return true;
}
return this.wouldValueBeValid(this.value_);
- },
+ }
/**
* @param {?} value Value to compare to the value of this ticket item.
* @return {boolean} Whether the given value is equal to the value of the
* ticket item.
*/
- isValueEqual: function(value) {
+ isValueEqual(value) {
return this.getValue() == value;
- },
+ }
/**
* @param {?} value Value to set as the value of the ticket item.
*/
- updateValue: function(value) {
+ updateValue(value) {
// Use comparison with capabilities for event.
var sendUpdateEvent = !this.isValueEqual(value);
// Don't lose requested value if capability is not available.
@@ -152,77 +141,77 @@ cr.define('print_preview.ticket_items', function() {
}
if (sendUpdateEvent)
cr.dispatchSimpleEvent(this, TicketItem.EventType.CHANGE);
- },
+ }
/**
* @return {?} Default value of the ticket item if no value was set by
* the user.
* @protected
*/
- getDefaultValueInternal: function() {
+ getDefaultValueInternal() {
throw Error('Abstract method not overridden');
- },
+ }
/**
* @return {?} Default value of the ticket item if the capability is
* not available.
* @protected
*/
- getCapabilityNotAvailableValueInternal: function() {
+ getCapabilityNotAvailableValueInternal() {
throw Error('Abstract method not overridden');
- },
+ }
/**
* @return {!EventTracker} Event tracker to keep track of events from
* dependencies.
* @protected
*/
- getTrackerInternal: function() {
+ getTrackerInternal() {
return this.tracker_;
- },
+ }
/**
* @return {print_preview.Destination} Selected destination from the
* destination store, or {@code null} if no destination is selected.
* @protected
*/
- getSelectedDestInternal: function() {
+ getSelectedDestInternal() {
return this.destinationStore_ ?
this.destinationStore_.selectedDestination :
null;
- },
+ }
/**
* @return {print_preview.DocumentInfo} Document data model.
* @protected
*/
- getDocumentInfoInternal: function() {
+ getDocumentInfoInternal() {
return this.documentInfo_;
- },
+ }
/**
* Dispatches a CHANGE event.
* @protected
*/
- dispatchChangeEventInternal: function() {
+ dispatchChangeEventInternal() {
cr.dispatchSimpleEvent(
this, print_preview.ticket_items.TicketItem.EventType.CHANGE);
- },
+ }
/**
* Updates the value of the ticket item without dispatching any events or
* persisting the value.
* @protected
*/
- updateValueInternal: function(value) {
+ updateValueInternal(value) {
this.value_ = value;
- },
+ }
/**
* Adds event handlers for this class.
* @private
*/
- addEventHandlers_: function() {
+ addEventHandlers_() {
if (this.destinationStore_) {
this.tracker_.add(
this.destinationStore_,
@@ -235,9 +224,18 @@ cr.define('print_preview.ticket_items', function() {
this.documentInfo_, print_preview.DocumentInfo.EventType.CHANGE,
this.dispatchChangeEventInternal.bind(this));
}
- },
+ }
+ }
+
+ /**
+ * Event types dispatched by this class.
+ * @enum {string}
+ */
+ TicketItem.EventType = {
+ CHANGE: 'print_preview.ticket_items.TicketItem.CHANGE'
};
+
// Export
return {TicketItem: TicketItem};
});
diff --git a/chromium/chrome/browser/resources/print_preview/data/ticket_items/vendor_items.js b/chromium/chrome/browser/resources/print_preview/data/ticket_items/vendor_items.js
index 82a65d361f5..0bdcd9f9e5c 100644
--- a/chromium/chrome/browser/resources/print_preview/data/ticket_items/vendor_items.js
+++ b/chromium/chrome/browser/resources/print_preview/data/ticket_items/vendor_items.js
@@ -5,60 +5,56 @@
cr.define('print_preview.ticket_items', function() {
'use strict';
- /**
- * An object that represents a user modifiable item in a print ticket. Each
- * ticket item has a value which can be set by the user. Ticket items can also
- * be unavailable for modifying if the print destination doesn't support it or
- * if other ticket item constraints are not met.
- * @param {print_preview.AppState} appState Application state model to update
- * when ticket items update.
- * @param {print_preview.DestinationStore} destinationStore Used listen for
- * changes in the currently selected destination's capabilities. Since
- * this is a common dependency of ticket items, it's handled in the base
- * class.
- * @constructor
- * @extends {cr.EventTarget}
- */
- function VendorItems(appState, destinationStore) {
- cr.EventTarget.call(this);
-
+ class VendorItems extends cr.EventTarget {
/**
- * Application state model to update when ticket items update.
- * @private {print_preview.AppState}
+ * An object that represents a user modifiable item in a print ticket. Each
+ * ticket item has a value which can be set by the user. Ticket items can
+ * also be unavailable for modifying if the print destination doesn't
+ * support it or if other ticket item constraints are not met.
+ * @param {print_preview.AppState} appState Application state model to
+ * update when ticket items update.
+ * @param {print_preview.DestinationStore} destinationStore Used listen for
+ * changes in the currently selected destination's capabilities. Since
+ * this is a common dependency of ticket items, it's handled in the
+ * base class.
*/
- this.appState_ = appState || null;
+ constructor(appState, destinationStore) {
+ super();
- /**
- * Used listen for changes in the currently selected destination's
- * capabilities.
- * @private {print_preview.DestinationStore}
- */
- this.destinationStore_ = destinationStore || null;
+ /**
+ * Application state model to update when ticket items update.
+ * @private {print_preview.AppState}
+ */
+ this.appState_ = appState || null;
- /**
- * Vendor ticket items store, maps item id to the item value.
- * @private {!Object<string>}
- */
- this.items_ = {};
- }
+ /**
+ * Used listen for changes in the currently selected destination's
+ * capabilities.
+ * @private {print_preview.DestinationStore}
+ */
+ this.destinationStore_ = destinationStore || null;
- VendorItems.prototype = {
- __proto__: cr.EventTarget.prototype,
+ /**
+ * Vendor ticket items store, maps item id to the item value.
+ * @private {!Object<string>}
+ */
+ this.items_ = {};
+ }
/** @return {boolean} Whether vendor capabilities are available. */
- isCapabilityAvailable: function() {
+ isCapabilityAvailable() {
return !!this.capability;
- },
+ }
/** @return {boolean} Whether the ticket item was modified by the user. */
- isUserEdited: function() {
+ isUserEdited() {
// If there's at least one ticket item stored in values, it was edited.
for (var key in this.items_) {
if (this.items_.hasOwnProperty(key))
return true;
}
return false;
- },
+ }
/** @return {Object} Vendor capabilities of the selected destination. */
get capability() {
@@ -73,7 +69,7 @@ cr.define('print_preview.ticket_items', function() {
return (destination.capabilities && destination.capabilities.printer &&
destination.capabilities.printer.vendor_capability) ||
null;
- },
+ }
/**
* Vendor ticket items store, maps item id to the item value.
@@ -81,13 +77,13 @@ cr.define('print_preview.ticket_items', function() {
*/
get ticketItems() {
return this.items_;
- },
+ }
/**
* @param {!Object<string>} values Values to set as the values of vendor
* ticket items. Maps vendor item id to the value.
*/
- updateValue: function(values) {
+ updateValue(values) {
this.items_ = {};
if (typeof values == 'object') {
for (var key in values) {
@@ -103,7 +99,7 @@ cr.define('print_preview.ticket_items', function() {
print_preview.AppStateField.VENDOR_OPTIONS, this.items_);
}
}
- };
+ }
// Export
return {VendorItems: VendorItems};
diff --git a/chromium/chrome/browser/resources/print_preview/images/printer.png b/chromium/chrome/browser/resources/print_preview/images/1x/printer.png
index a0a85bbc236..a0a85bbc236 100644
--- a/chromium/chrome/browser/resources/print_preview/images/printer.png
+++ b/chromium/chrome/browser/resources/print_preview/images/1x/printer.png
Binary files differ
diff --git a/chromium/chrome/browser/resources/print_preview/images/printer_shared.png b/chromium/chrome/browser/resources/print_preview/images/1x/printer_shared.png
index 026ed450f86..026ed450f86 100644
--- a/chromium/chrome/browser/resources/print_preview/images/printer_shared.png
+++ b/chromium/chrome/browser/resources/print_preview/images/1x/printer_shared.png
Binary files differ
diff --git a/chromium/chrome/browser/resources/print_preview/images/2x/printer.png b/chromium/chrome/browser/resources/print_preview/images/2x/printer.png
new file mode 100644
index 00000000000..b704e02f841
--- /dev/null
+++ b/chromium/chrome/browser/resources/print_preview/images/2x/printer.png
Binary files differ
diff --git a/chromium/chrome/browser/resources/print_preview/images/2x/printer_shared.png b/chromium/chrome/browser/resources/print_preview/images/2x/printer_shared.png
new file mode 100644
index 00000000000..bbddfd04d2c
--- /dev/null
+++ b/chromium/chrome/browser/resources/print_preview/images/2x/printer_shared.png
Binary files differ
diff --git a/chromium/chrome/browser/resources/print_preview/native_layer.js b/chromium/chrome/browser/resources/print_preview/native_layer.js
index 05072dc29e0..3aaa9947da1 100644
--- a/chromium/chrome/browser/resources/print_preview/native_layer.js
+++ b/chromium/chrome/browser/resources/print_preview/native_layer.js
@@ -28,14 +28,22 @@ print_preview.LocalDestinationInfo;
/**
* @typedef {{
- * printerId: string,
+ * isInKioskAutoPrintMode: boolean,
+ * isInAppKioskMode: boolean,
+ * thousandsDelimeter: string,
+ * decimalDelimeter: string,
+ * unitType: !print_preview.MeasurementSystemUnitType,
+ * previewModifiable: boolean,
+ * documentTitle: string,
+ * documentHasSelection: boolean,
+ * shouldPrintSelectionOnly: boolean,
* printerName: string,
- * printerDescription: string,
- * cupsEnterprisePrinter: (boolean | undefined),
- * capabilities: !print_preview.Cdd,
+ * serializedAppStateStr: ?string,
+ * serializedDefaultDestinationSelectionRulesStr: ?string,
* }}
+ * @see corresponding field name definitions in print_preview_handler.cc
*/
-print_preview.PrinterCapabilitiesResponse;
+print_preview.NativeInitialSettings;
/**
* @typedef {{
@@ -51,11 +59,13 @@ print_preview.PrivetPrinterDescription;
/**
* @typedef {{
- * printer: !print_preview.PrivetPrinterDescription,
+ * printer:(print_preview.PrivetPrinterDescription |
+ * print_preview.LocalDestinationInfo |
+ * undefined),
* capabilities: !print_preview.Cdd,
* }}
*/
-print_preview.PrivetPrinterCapabilitiesResponse;
+print_preview.CapabilitiesResponse;
/**
* @typedef {{
@@ -85,6 +95,8 @@ print_preview.ProvisionalDestinationInfo;
print_preview.PrinterType = {
PRIVET_PRINTER: 0,
EXTENSION_PRINTER: 1,
+ PDF_PRINTER: 2,
+ LOCAL_PRINTER: 3,
};
cr.define('print_preview', function() {
@@ -126,104 +138,35 @@ cr.define('print_preview', function() {
* @return {!Promise<!print_preview.NativeInitialSettings>}
*/
getInitialSettings() {
- return cr.sendWithPromise('getInitialSettings')
- .then(
- /**
- * @param {!Object} initialSettings Object containing the raw
- * Print Preview settings.
- */
- function(initialSettings) {
- var numberFormatSymbols =
- print_preview.MeasurementSystem.parseNumberFormat(
- initialSettings['numberFormat']);
- var unitType = print_preview.MeasurementSystemUnitType.IMPERIAL;
- if (initialSettings['measurementSystem'] != null) {
- unitType = initialSettings['measurementSystem'];
- }
- return new print_preview.NativeInitialSettings(
- initialSettings['printAutomaticallyInKioskMode'] || false,
- initialSettings['appKioskMode'] || false,
- numberFormatSymbols[0] || ',',
- numberFormatSymbols[1] || '.', unitType,
- initialSettings['previewModifiable'] || false,
- initialSettings['initiatorTitle'] || '',
- initialSettings['documentHasSelection'] || false,
- initialSettings['shouldPrintSelectionOnly'] || false,
- initialSettings['printerName'] || null,
- initialSettings['appState'] || null,
- initialSettings['defaultDestinationSelectionRules'] ||
- null);
- });
- }
-
- /**
- * Requests the system's local print destinations. The promise will be
- * resolved with a list of the local destinations.
- * @return {!Promise<!Array<print_preview.LocalDestinationInfo>>}
- */
- getPrinters() {
- return cr.sendWithPromise('getPrinters');
+ return cr.sendWithPromise('getInitialSettings');
}
/**
- * Requests the network's privet print destinations. After this is called,
- * a number of privet-printer-changed events may be fired.
- * @return {!Promise} Resolves when privet printer search is completed.
- * Rejected if privet printers are not enabled.
+ * Requests the system's print destinations. The promise will be resolved
+ * when all destinations of that type have been retrieved. One or more
+ * 'printers-added' events may be fired in response before resolution.
+ * @param {!print_preview.PrinterType} type The type of destinations to
+ * request.
+ * @return {!Promise}
*/
- getPrivetPrinters() {
- return cr.sendWithPromise(
- 'getExtensionOrPrivetPrinters',
- print_preview.PrinterType.PRIVET_PRINTER);
- }
-
- /**
- * Request a list of extension printers. Printers are reported as they are
- * found by a series of 'extension-printers-added' events.
- * @return {!Promise} Will be resolved when all extension managed printers
- * have been sent.
- */
- getExtensionPrinters() {
- return cr.sendWithPromise(
- 'getExtensionOrPrivetPrinters',
- print_preview.PrinterType.EXTENSION_PRINTER);
+ getPrinters(type) {
+ return cr.sendWithPromise('getPrinters', type);
}
/**
* Requests the destination's printing capabilities. Returns a promise that
* will be resolved with the capabilities if they are obtained successfully.
* @param {string} destinationId ID of the destination.
- * @return {!Promise<!print_preview.PrinterCapabilitiesResponse>}
- */
- getPrinterCapabilities(destinationId) {
- return cr.sendWithPromise('getPrinterCapabilities', destinationId);
- }
-
- /**
- * Requests the privet destination's printing capabilities. Returns a
- * promise that will be resolved with capabilities and printer information
- * if capabilities are obtained successfully.
- * @param {string} destinationId The ID of the destination
- * @return {!Promise<!print_preview.PrivetPrinterCapabilitiesResponse>}
- */
- getPrivetPrinterCapabilities(destinationId) {
- return cr.sendWithPromise(
- 'getExtensionOrPrivetPrinterCapabilities', destinationId,
- print_preview.PrinterType.PRIVET_PRINTER);
- }
-
- /**
- * Requests the extension destination's printing capabilities. Returns a
- * promise that will be resolved with the capabilities if capabilities are
- * obtained successfully.
- * @param {string} destinationId The ID of the destination whose
- * capabilities are requested.
- * @return {!Promise<!print_preview.Cdd>}
+ * @param {!print_preview.PrinterType} type The destination's printer type.
+ * @return {!Promise<!print_preview.CapabilitiesResponse>}
*/
- getExtensionPrinterCapabilities(destinationId) {
+ getPrinterCapabilities(destinationId, type) {
return cr.sendWithPromise(
- 'getExtensionOrPrivetPrinterCapabilities', destinationId,
- print_preview.PrinterType.EXTENSION_PRINTER);
+ 'getPrinterCapabilities', destinationId,
+ destinationId ==
+ print_preview.Destination.GooglePromotedId.SAVE_AS_PDF ?
+ print_preview.PrinterType.PDF_PRINTER :
+ type);
}
/**
@@ -571,185 +514,8 @@ cr.define('print_preview', function() {
*/
NativeLayer.SERIALIZED_STATE_VERSION_ = 1;
- /**
- * Initial settings retrieved from the native layer.
- */
- class NativeInitialSettings {
- /**
- * @param {boolean} isInKioskAutoPrintMode Whether the print preview should
- * be in auto-print mode.
- * @param {boolean} isInAppKioskMode Whether the print preview is in App
- * Kiosk mode.
- * @param {string} thousandsDelimeter Character delimeter of thousands
- * digits.
- * @param {string} decimalDelimeter Character delimeter of the decimal
- * point.
- * @param {!print_preview.MeasurementSystemUnitType} unitType Unit type of
- * local machine's measurement system.
- * @param {boolean} isDocumentModifiable Whether the document to print is
- * modifiable.
- * @param {string} documentTitle Title of the document.
- * @param {boolean} documentHasSelection Whether the document has selected
- * content.
- * @param {boolean} selectionOnly Whether only selected content should be
- * printed.
- * @param {?string} systemDefaultDestinationId ID of the system default
- * destination.
- * @param {?string} serializedAppStateStr Serialized app state.
- * @param {?string} serializedDefaultDestinationSelectionRulesStr Serialized
- * default destination selection rules.
- */
- constructor(
- isInKioskAutoPrintMode, isInAppKioskMode, thousandsDelimeter,
- decimalDelimeter, unitType, isDocumentModifiable, documentTitle,
- documentHasSelection, selectionOnly, systemDefaultDestinationId,
- serializedAppStateStr, serializedDefaultDestinationSelectionRulesStr) {
- /**
- * Whether the print preview should be in auto-print mode.
- * @private {boolean}
- */
- this.isInKioskAutoPrintMode_ = isInKioskAutoPrintMode;
-
- /**
- * Whether the print preview should switch to App Kiosk mode.
- * @private {boolean}
- */
- this.isInAppKioskMode_ = isInAppKioskMode;
-
- /**
- * Character delimeter of thousands digits.
- * @private {string}
- */
- this.thousandsDelimeter_ = thousandsDelimeter;
-
- /**
- * Character delimeter of the decimal point.
- * @private {string}
- */
- this.decimalDelimeter_ = decimalDelimeter;
-
- /**
- * Unit type of local machine's measurement system.
- * @private {print_preview.MeasurementSystemUnitType}
- */
- this.unitType_ = unitType;
-
- /**
- * Whether the document to print is modifiable.
- * @private {boolean}
- */
- this.isDocumentModifiable_ = isDocumentModifiable;
-
- /**
- * Title of the document.
- * @private {string}
- */
- this.documentTitle_ = documentTitle;
-
- /**
- * Whether the document has selection.
- * @private {boolean}
- */
- this.documentHasSelection_ = documentHasSelection;
-
- /**
- * Whether selection only should be printed.
- * @private {boolean}
- */
- this.selectionOnly_ = selectionOnly;
-
- /**
- * ID of the system default destination.
- * @private {?string}
- */
- this.systemDefaultDestinationId_ = systemDefaultDestinationId;
-
- /**
- * Serialized app state.
- * @private {?string}
- */
- this.serializedAppStateStr_ = serializedAppStateStr;
-
- /**
- * Serialized default destination selection rules.
- * @private {?string}
- */
- this.serializedDefaultDestinationSelectionRulesStr_ =
- serializedDefaultDestinationSelectionRulesStr;
- }
-
- /**
- * @return {boolean} Whether the print preview should be in auto-print mode.
- */
- get isInKioskAutoPrintMode() {
- return this.isInKioskAutoPrintMode_;
- }
-
- /**
- * @return {boolean} Whether the print preview should switch to App Kiosk
- * mode.
- */
- get isInAppKioskMode() {
- return this.isInAppKioskMode_;
- }
-
- /** @return {string} Character delimeter of thousands digits. */
- get thousandsDelimeter() {
- return this.thousandsDelimeter_;
- }
-
- /** @return {string} Character delimeter of the decimal point. */
- get decimalDelimeter() {
- return this.decimalDelimeter_;
- }
-
- /**
- * @return {!print_preview.MeasurementSystemUnitType} Unit type of local
- * machine's measurement system.
- */
- get unitType() {
- return this.unitType_;
- }
-
- /** @return {boolean} Whether the document to print is modifiable. */
- get isDocumentModifiable() {
- return this.isDocumentModifiable_;
- }
-
- /** @return {string} Document title. */
- get documentTitle() {
- return this.documentTitle_;
- }
-
- /** @return {boolean} Whether the document has selection. */
- get documentHasSelection() {
- return this.documentHasSelection_;
- }
-
- /** @return {boolean} Whether selection only should be printed. */
- get selectionOnly() {
- return this.selectionOnly_;
- }
-
- /** @return {?string} ID of the system default destination. */
- get systemDefaultDestinationId() {
- return this.systemDefaultDestinationId_;
- }
-
- /** @return {?string} Serialized app state. */
- get serializedAppStateStr() {
- return this.serializedAppStateStr_;
- }
-
- /** @return {?string} Serialized default destination selection rules. */
- get serializedDefaultDestinationSelectionRulesStr() {
- return this.serializedDefaultDestinationSelectionRulesStr_;
- }
- }
-
// Export
return {
- NativeInitialSettings: NativeInitialSettings,
NativeLayer: NativeLayer
};
});
diff --git a/chromium/chrome/browser/resources/print_preview/previewarea/preview_area.js b/chromium/chrome/browser/resources/print_preview/previewarea/preview_area.js
index 3ef1805c88b..98e8f1c9add 100644
--- a/chromium/chrome/browser/resources/print_preview/previewarea/preview_area.js
+++ b/chromium/chrome/browser/resources/print_preview/previewarea/preview_area.js
@@ -318,8 +318,8 @@ cr.define('print_preview', function() {
this.onOpenSystemDialogButtonClick_.bind(this));
var TicketStoreEvent = print_preview.PrintTicketStore.EventType;
- [TicketStoreEvent.INITIALIZE, TicketStoreEvent.TICKET_CHANGE,
- TicketStoreEvent.CAPABILITIES_CHANGE, TicketStoreEvent.DOCUMENT_CHANGE]
+ [TicketStoreEvent.INITIALIZE, TicketStoreEvent.CAPABILITIES_CHANGE,
+ TicketStoreEvent.DOCUMENT_CHANGE]
.forEach(eventType => {
this.tracker.add(
this.printTicketStore_, eventType,
diff --git a/chromium/chrome/browser/resources/print_preview/print_header.js b/chromium/chrome/browser/resources/print_preview/print_header.js
index 810e286d16f..b8f12871fe8 100644
--- a/chromium/chrome/browser/resources/print_preview/print_header.js
+++ b/chromium/chrome/browser/resources/print_preview/print_header.js
@@ -108,35 +108,19 @@ cr.define('print_preview', function() {
this.tracker.add(
this.printTicketStore_,
print_preview.PrintTicketStore.EventType.INITIALIZE,
- this.onTicketChange_.bind(this));
+ this.onTicketChange.bind(this));
this.tracker.add(
this.printTicketStore_,
print_preview.PrintTicketStore.EventType.DOCUMENT_CHANGE,
- this.onTicketChange_.bind(this));
- this.tracker.add(
- this.printTicketStore_,
- print_preview.PrintTicketStore.EventType.TICKET_CHANGE,
- this.onTicketChange_.bind(this));
+ this.onTicketChange.bind(this));
this.tracker.add(
this.destinationStore_,
print_preview.DestinationStore.EventType.DESTINATION_SELECT,
this.onDestinationSelect_.bind(this));
this.tracker.add(
- this.printTicketStore_.copies,
- print_preview.ticket_items.TicketItem.EventType.CHANGE,
- this.onTicketChange_.bind(this));
- this.tracker.add(
this.printTicketStore_.duplex,
print_preview.ticket_items.TicketItem.EventType.CHANGE,
- this.onTicketChange_.bind(this));
- this.tracker.add(
- this.printTicketStore_.pageRange,
- print_preview.ticket_items.TicketItem.EventType.CHANGE,
- this.onTicketChange_.bind(this));
- this.tracker.add(
- this.printTicketStore_.scaling,
- print_preview.ticket_items.TicketItem.EventType.CHANGE,
- this.updatePrintButtonEnabledState_.bind(this));
+ this.onTicketChange.bind(this));
},
/**
@@ -266,9 +250,8 @@ cr.define('print_preview', function() {
/**
* Called when the print ticket has changed. Disables the print button if
* any of the settings are invalid.
- * @private
*/
- onTicketChange_: function() {
+ onTicketChange: function() {
this.updatePrintButtonEnabledState_();
this.updateSummary_();
if (document.activeElement == null ||
diff --git a/chromium/chrome/browser/resources/print_preview/print_preview.css b/chromium/chrome/browser/resources/print_preview/print_preview.css
index bb69ab6e9ed..d9b3f8f2bdd 100644
--- a/chromium/chrome/browser/resources/print_preview/print_preview.css
+++ b/chromium/chrome/browser/resources/print_preview/print_preview.css
@@ -62,17 +62,6 @@ header {
width: 99%;
}
-.right-column .checkbox,
-.right-column .radio {
- margin: 0;
-}
-
-.right-column .checkbox label,
-.right-column .radio label {
- padding-bottom: 5px;
- padding-top: 10px;
-}
-
.right-column .radio input[type='radio'],
.right-column label input[type='checkbox'] {
--min-size: 13.19px;
@@ -105,7 +94,7 @@ header {
}
.two-column.visible .left-column.multirow {
- padding-top: 16px;
+ padding-top: 13px;
vertical-align: top;
}
@@ -137,12 +126,6 @@ h1 {
margin: 8px 20px;
}
-#print-preview .navbar-link.disabled {
- color: rgba(0, 0, 0, .5);
- cursor: default;
- pointer-events: none;
-}
-
button.loading {
cursor: progress;
}
diff --git a/chromium/chrome/browser/resources/print_preview/print_preview.html b/chromium/chrome/browser/resources/print_preview/print_preview.html
index 3373d046f4c..c59e8e9b0d6 100644
--- a/chromium/chrome/browser/resources/print_preview/print_preview.html
+++ b/chromium/chrome/browser/resources/print_preview/print_preview.html
@@ -15,14 +15,12 @@
<link rel="stylesheet" href="common/search_bubble.css">
<link rel="stylesheet" href="settings/destination_settings.css">
<link rel="stylesheet" href="settings/color_settings.css">
- <link rel="stylesheet" href="settings/copies_settings.css">
<link rel="stylesheet" href="settings/settings_box.css">
<link rel="stylesheet" href="settings/page_settings.css">
<link rel="stylesheet" href="settings/margin_settings.css">
<link rel="stylesheet" href="settings/media_size_settings.css">
<link rel="stylesheet" href="settings/layout_settings.css">
<link rel="stylesheet" href="settings/dpi_settings.css">
- <link rel="stylesheet" href="settings/scaling_settings.css">
<link rel="stylesheet" href="settings/advanced_options_settings.css">
<link rel="stylesheet" href="settings/advanced_settings/advanced_settings.css">
<link rel="stylesheet" href="settings/advanced_settings/advanced_settings_item.css">
diff --git a/chromium/chrome/browser/resources/print_preview/print_preview.js b/chromium/chrome/browser/resources/print_preview/print_preview.js
index 00a9b0e427a..bee9f809d16 100644
--- a/chromium/chrome/browser/resources/print_preview/print_preview.js
+++ b/chromium/chrome/browser/resources/print_preview/print_preview.js
@@ -390,6 +390,10 @@ cr.define('print_preview', function() {
this.printIfReady_.bind(this));
this.tracker.add(
this.destinationStore_,
+ print_preview.DestinationStore.EventType.SELECTED_DESTINATION_INVALID,
+ this.onSelectedDestinationInvalid_.bind(this));
+ this.tracker.add(
+ this.destinationStore_,
print_preview.DestinationStore.EventType.DESTINATION_SELECT,
this.onDestinationSelect_.bind(this));
@@ -435,6 +439,15 @@ cr.define('print_preview', function() {
this.advancedOptionsSettings_,
print_preview.AdvancedOptionsSettings.EventType.BUTTON_ACTIVATED,
this.onAdvancedOptionsButtonActivated_.bind(this));
+
+ /* Ticket items that may be invalid. */
+ [this.printTicketStore_.copies, this.printTicketStore_.pageRange,
+ this.printTicketStore_.scaling,
+ ].forEach((item) => {
+ this.tracker.add(
+ item, print_preview.ticket_items.TicketItem.EventType.CHANGE,
+ this.onTicketChange_.bind(this));
+ });
},
/** @override */
@@ -465,9 +478,9 @@ cr.define('print_preview', function() {
*/
setIsEnabled_: function(isEnabled) {
if ($('system-dialog-link'))
- $('system-dialog-link').classList.toggle('disabled', !isEnabled);
+ $('system-dialog-link').disabled = !isEnabled;
if ($('open-pdf-in-preview-link'))
- $('open-pdf-in-preview-link').classList.toggle('disabled', !isEnabled);
+ $('open-pdf-in-preview-link').disabled = !isEnabled;
this.printHeader_.isEnabled = isEnabled;
this.destinationSettings_.isEnabled = isEnabled;
this.pageSettings_.isEnabled = isEnabled;
@@ -584,7 +597,7 @@ cr.define('print_preview', function() {
print_preview.Destination.GooglePromotedId.SAVE_AS_PDF);
// Save as PDF resolves when file selection is completed or cancelled.
whenPrintDone.then(
- this.onFileSelectionComplete_.bind(this),
+ this.close_.bind(this, false),
this.onFileSelectionCancel_.bind(this));
}
@@ -645,13 +658,13 @@ cr.define('print_preview', function() {
// The following components must be initialized in this order.
this.appState_.init(settings.serializedAppStateStr);
this.documentInfo_.init(
- settings.isDocumentModifiable, settings.documentTitle,
+ settings.previewModifiable, settings.documentTitle,
settings.documentHasSelection);
this.printTicketStore_.init(
settings.thousandsDelimeter, settings.decimalDelimeter,
- settings.unitType, settings.selectionOnly);
+ settings.unitType, settings.shouldPrintSelectionOnly);
this.destinationStore_.init(
- settings.isInAppKioskMode, settings.systemDefaultDestinationId,
+ settings.isInAppKioskMode, settings.printerName,
settings.serializedDefaultDestinationSelectionRulesStr);
this.appState_.setInitialized();
@@ -735,20 +748,6 @@ cr.define('print_preview', function() {
},
/**
- * Called from the native layer when save-to-pdf file selection is complete.
- * @private
- */
- onFileSelectionComplete_: function() {
- assert(
- this.uiState_ == PrintPreviewUiState_.FILE_SELECTION,
- 'File selection completed when not in file-selection state: ' +
- this.uiState_);
- this.previewArea_.showCustomMessage(
- loadTimeData.getString('printingToPDFInProgress'));
- this.uiState_ = PrintPreviewUiState_.PRINTING;
- },
-
- /**
* Called after successfully submitting a job to Google Cloud Print.
* @param {!Event} event Contains the ID of the submitted print job.
* @private
@@ -927,6 +926,17 @@ cr.define('print_preview', function() {
},
/**
+ * Called when the destination store fails to fetch capabilities for the
+ * selected printer.
+ * @private
+ */
+ onSelectedDestinationInvalid_: function() {
+ this.previewArea_.showCustomMessage(
+ loadTimeData.getString('invalidPrinterSettings'));
+ this.onSettingsInvalid_();
+ },
+
+ /**
* Called when native layer receives invalid settings for a print request.
* @private
*/
@@ -937,6 +947,21 @@ cr.define('print_preview', function() {
},
/**
+ * Called when a ticket item that can be invalid is updated. Updates the
+ * enabled state of the system dialog link on Windows and the open pdf in
+ * preview link on Mac.
+ * @private
+ */
+ onTicketChange_: function() {
+ this.printHeader_.onTicketChange();
+ var disable = !this.printHeader_.isPrintButtonEnabled;
+ if (cr.isWindows && $('system-dialog-link'))
+ $('system-dialog-link').disabled = disable;
+ if ($('open-pdf-in-preview-link'))
+ $('open-pdf-in-preview-link').disabled = disable;
+ },
+
+ /**
* Called when the destination settings' change button is activated.
* Displays the destination search component.
* @private
diff --git a/chromium/chrome/browser/resources/print_preview/print_preview_utils.js b/chromium/chrome/browser/resources/print_preview/print_preview_utils.js
index 7836ad7956d..bfd199c3801 100644
--- a/chromium/chrome/browser/resources/print_preview/print_preview_utils.js
+++ b/chromium/chrome/browser/resources/print_preview/print_preview_utils.js
@@ -152,7 +152,7 @@ function pageRangeTextToPageRanges(pageRangeText, opt_totalPageCount) {
function pageRangeTextToPageList(pageRangeText, totalPageCount) {
var pageRanges = pageRangeTextToPageRanges(pageRangeText, totalPageCount);
var pageList = [];
- if (pageRanges instanceof Array) {
+ if (Array.isArray(pageRanges)) {
for (var i = 0; i < pageRanges.length; ++i) {
for (var j = pageRanges[i].from;
j <= Math.min(pageRanges[i].to, totalPageCount); ++j) {
diff --git a/chromium/chrome/browser/resources/print_preview/search/destination_list_item.js b/chromium/chrome/browser/resources/print_preview/search/destination_list_item.js
index d925eef5bda..b52b4938cbd 100644
--- a/chromium/chrome/browser/resources/print_preview/search/destination_list_item.js
+++ b/chromium/chrome/browser/resources/print_preview/search/destination_list_item.js
@@ -140,6 +140,7 @@ cr.define('print_preview', function() {
updateUi_: function() {
var iconImg = this.getChildElement('.destination-list-item-icon');
iconImg.src = this.destination_.iconUrl;
+ iconImg.srcset = this.destination_.srcSet;
var nameEl = this.getChildElement('.destination-list-item-name');
var textContent = this.destination_.displayName;
diff --git a/chromium/chrome/browser/resources/print_preview/settings/copies_settings.css b/chromium/chrome/browser/resources/print_preview/settings/copies_settings.css
deleted file mode 100644
index e2e1b6f9848..00000000000
--- a/chromium/chrome/browser/resources/print_preview/settings/copies_settings.css
+++ /dev/null
@@ -1,12 +0,0 @@
-/* Copyright (c) 2012 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. */
-
-#copies-settings .collate-container {
- -webkit-padding-start: 16px;
- display: inline-block;
-}
-
-#copies-settings .collate-container label {
- padding: 0;
-}
diff --git a/chromium/chrome/browser/resources/print_preview/settings/destination_settings.js b/chromium/chrome/browser/resources/print_preview/settings/destination_settings.js
index f9941182b45..54d1994e9c8 100644
--- a/chromium/chrome/browser/resources/print_preview/settings/destination_settings.js
+++ b/chromium/chrome/browser/resources/print_preview/settings/destination_settings.js
@@ -131,6 +131,7 @@ cr.define('print_preview', function() {
var iconEl = this.getElement().getElementsByClassName(
print_preview.DestinationSettingsClasses_.ICON)[0];
iconEl.src = destination.iconUrl;
+ iconEl.srcset = destination.srcSet;
var hint = destination.hint;
var locationEl = this.getElement().getElementsByClassName(
diff --git a/chromium/chrome/browser/resources/print_preview/settings/page_settings.js b/chromium/chrome/browser/resources/print_preview/settings/page_settings.js
index fe589e1ad3f..edbd64c3e23 100644
--- a/chromium/chrome/browser/resources/print_preview/settings/page_settings.js
+++ b/chromium/chrome/browser/resources/print_preview/settings/page_settings.js
@@ -32,28 +32,35 @@ cr.define('print_preview', function() {
/**
* Custom page range input.
- * @type {HTMLInputElement}
+ * @type {?HTMLInputElement}
* @private
*/
this.customInput_ = null;
/**
* Custom page range radio button.
- * @type {HTMLInputElement}
+ * @type {?HTMLInputElement}
* @private
*/
this.customRadio_ = null;
/**
+ * Custom page range label.
+ * @type {?HTMLElement}
+ * @private
+ */
+ this.customLabel_ = null;
+
+ /**
* All page rage radio button.
- * @type {HTMLInputElement}
+ * @type {?HTMLInputElement}
* @private
*/
this.allRadio_ = null;
/**
* Container of a hint to show when the custom page range is invalid.
- * @type {HTMLElement}
+ * @type {?HTMLElement}
* @private
*/
this.customHintEl_ = null;
@@ -68,6 +75,7 @@ cr.define('print_preview', function() {
ALL_RADIO: 'page-settings-all-radio',
CUSTOM_HINT: 'page-settings-custom-hint',
CUSTOM_INPUT: 'page-settings-custom-input',
+ CUSTOM_LABEL: 'page-settings-print-pages-div',
CUSTOM_RADIO: 'page-settings-custom-radio'
};
@@ -106,7 +114,7 @@ cr.define('print_preview', function() {
assert(this.allRadio_), 'click', this.onAllRadioClick_.bind(this));
this.tracker.add(
assert(this.customRadio_), 'click',
- this.onCustomRadioClick_.bind(this));
+ this.focusCustomInput_.bind(this));
this.tracker.add(customInput, 'blur', this.onCustomInputBlur_.bind(this));
this.tracker.add(
customInput, 'focus', this.onCustomInputFocus_.bind(this));
@@ -115,6 +123,9 @@ cr.define('print_preview', function() {
this.tracker.add(
customInput, 'input', this.onCustomInputChange_.bind(this));
this.tracker.add(
+ assert(this.customLabel_), 'focus',
+ this.focusCustomInput_.bind(this));
+ this.tracker.add(
this.pageRangeTicketItem_,
print_preview.ticket_items.TicketItem.EventType.CHANGE,
this.onPageRangeTicketItemChange_.bind(this));
@@ -139,6 +150,8 @@ cr.define('print_preview', function() {
PageSettings.Classes_.CUSTOM_RADIO)[0];
this.customHintEl_ = this.getElement().getElementsByClassName(
PageSettings.Classes_.CUSTOM_HINT)[0];
+ this.customLabel_ = this.getElement().getElementsByClassName(
+ PageSettings.Classes_.CUSTOM_LABEL)[0];
},
/**
@@ -179,10 +192,11 @@ cr.define('print_preview', function() {
},
/**
- * Called when the custom radio button is clicked. Updates the print ticket.
+ * Focuses the custom input. Called when the custom radio button or custom
+ * input label is clicked.
* @private
*/
- onCustomRadioClick_: function() {
+ focusCustomInput_: function() {
this.customInput_.focus();
},
diff --git a/chromium/chrome/browser/resources/print_preview/settings/scaling_settings.css b/chromium/chrome/browser/resources/print_preview/settings/scaling_settings.css
deleted file mode 100644
index e39db53edd7..00000000000
--- a/chromium/chrome/browser/resources/print_preview/settings/scaling_settings.css
+++ /dev/null
@@ -1,7 +0,0 @@
-/* Copyright 2017 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. */
-
-#scaling-settings .settings-box {
- padding-top: 5px;
-}
diff --git a/chromium/chrome/browser/resources/print_preview/settings/settings_box.css b/chromium/chrome/browser/resources/print_preview/settings/settings_box.css
index cf48b061b00..b95a669f277 100644
--- a/chromium/chrome/browser/resources/print_preview/settings/settings_box.css
+++ b/chromium/chrome/browser/resources/print_preview/settings/settings_box.css
@@ -6,3 +6,14 @@
background: rgb(255, 240, 240);
color: rgb(140, 20, 20);
}
+
+.settings-box input[type='number'] {
+ -webkit-margin-end: 16px;
+ margin-bottom: 2.5px;
+ margin-top: 2.5px;
+}
+
+.settings-box {
+ align-items: center;
+ display: inline-flex;
+}
diff --git a/chromium/chrome/browser/resources/print_preview/settings/settings_section_select.js b/chromium/chrome/browser/resources/print_preview/settings/settings_section_select.js
index 62ec25c45a3..ab8b1d59fc0 100644
--- a/chromium/chrome/browser/resources/print_preview/settings/settings_section_select.js
+++ b/chromium/chrome/browser/resources/print_preview/settings/settings_section_select.js
@@ -8,15 +8,21 @@ cr.define('print_preview', function() {
/**
* Base class for the printer option element visualizing the generic selection
* based option.
- * @param {!print_preview.ticket_items.TicketItem} ticketItem Ticket item
- * visualized by this component.
+ * @param {(!print_preview.ticket_items.Dpi |
+ * !print_preview.ticket_items.MediaSize)} ticketItem
+ * Ticket item visualized by this component. Must have a defined
+ * capability() getter.
* @constructor
* @extends {print_preview.SettingsSection}
*/
function SettingsSectionSelect(ticketItem) {
print_preview.SettingsSection.call(this);
- /** @private {!print_preview.ticket_items.TicketItem} */
+ /**
+ * {(!print_preview.ticket_items.Dpi |
+ * !print_preview.ticket_items.MediaSize)}
+ * @private
+ */
this.ticketItem_ = ticketItem;
}