| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 cr.exportPath('print_preview'); | 5 cr.exportPath('print_preview'); |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * Enumeration of the types of destinations. | 8 * Enumeration of the types of destinations. |
| 9 * @enum {string} | 9 * @enum {string} |
| 10 */ | 10 */ |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 * lastAccessTime: (number|undefined), | 115 * lastAccessTime: (number|undefined), |
| 116 * cloudID: (string|undefined), | 116 * cloudID: (string|undefined), |
| 117 * provisionalType: | 117 * provisionalType: |
| 118 * (print_preview.DestinationProvisionalType|undefined), | 118 * (print_preview.DestinationProvisionalType|undefined), |
| 119 * extensionId: (string|undefined), | 119 * extensionId: (string|undefined), |
| 120 * extensionName: (string|undefined), | 120 * extensionName: (string|undefined), |
| 121 * description: (string|undefined)}=} opt_params Optional parameters | 121 * description: (string|undefined)}=} opt_params Optional parameters |
| 122 * for the destination. | 122 * for the destination. |
| 123 * @constructor | 123 * @constructor |
| 124 */ | 124 */ |
| 125 function Destination(id, type, origin, displayName, isRecent, | 125 function Destination( |
| 126 connectionStatus, opt_params) { | 126 id, type, origin, displayName, isRecent, connectionStatus, opt_params) { |
| 127 /** | 127 /** |
| 128 * ID of the destination. | 128 * ID of the destination. |
| 129 * @private {string} | 129 * @private {string} |
| 130 */ | 130 */ |
| 131 this.id_ = id; | 131 this.id_ = id; |
| 132 | 132 |
| 133 /** | 133 /** |
| 134 * Type of the destination. | 134 * Type of the destination. |
| 135 * @private {!print_preview.DestinationType} | 135 * @private {!print_preview.DestinationType} |
| 136 */ | 136 */ |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 * Connection status of the destination. | 201 * Connection status of the destination. |
| 202 * @private {!print_preview.DestinationConnectionStatus} | 202 * @private {!print_preview.DestinationConnectionStatus} |
| 203 */ | 203 */ |
| 204 this.connectionStatus_ = connectionStatus; | 204 this.connectionStatus_ = connectionStatus; |
| 205 | 205 |
| 206 /** | 206 /** |
| 207 * Number of milliseconds since the epoch when the printer was last | 207 * Number of milliseconds since the epoch when the printer was last |
| 208 * accessed. | 208 * accessed. |
| 209 * @private {number} | 209 * @private {number} |
| 210 */ | 210 */ |
| 211 this.lastAccessTime_ = (opt_params && opt_params.lastAccessTime) || | 211 this.lastAccessTime_ = |
| 212 Date.now(); | 212 (opt_params && opt_params.lastAccessTime) || Date.now(); |
| 213 | 213 |
| 214 /** | 214 /** |
| 215 * Cloud ID for Privet printers. | 215 * Cloud ID for Privet printers. |
| 216 * @private {string} | 216 * @private {string} |
| 217 */ | 217 */ |
| 218 this.cloudID_ = (opt_params && opt_params.cloudID) || ''; | 218 this.cloudID_ = (opt_params && opt_params.cloudID) || ''; |
| 219 | 219 |
| 220 /** | 220 /** |
| 221 * Extension ID for extension managed printers. | 221 * Extension ID for extension managed printers. |
| 222 * @private {string} | 222 * @private {string} |
| (...skipping 10 matching lines...) Expand all Loading... |
| 233 * Different from {@code print_preview.DestinationProvisionalType.NONE} if | 233 * Different from {@code print_preview.DestinationProvisionalType.NONE} if |
| 234 * the destination is provisional. Provisional destinations cannot be | 234 * the destination is provisional. Provisional destinations cannot be |
| 235 * selected as they are, but have to be resolved first (i.e. extra steps | 235 * selected as they are, but have to be resolved first (i.e. extra steps |
| 236 * have to be taken to get actual destination properties, which should | 236 * have to be taken to get actual destination properties, which should |
| 237 * replace the provisional ones). Provisional destination resolvment flow | 237 * replace the provisional ones). Provisional destination resolvment flow |
| 238 * will be started when the user attempts to select the destination in | 238 * will be started when the user attempts to select the destination in |
| 239 * search UI. | 239 * search UI. |
| 240 * @private {print_preview.DestinationProvisionalType} | 240 * @private {print_preview.DestinationProvisionalType} |
| 241 */ | 241 */ |
| 242 this.provisionalType_ = (opt_params && opt_params.provisionalType) || | 242 this.provisionalType_ = (opt_params && opt_params.provisionalType) || |
| 243 print_preview.DestinationProvisionalType.NONE; | 243 print_preview.DestinationProvisionalType.NONE; |
| 244 | 244 |
| 245 assert(this.provisionalType_ != | 245 assert( |
| 246 print_preview.DestinationProvisionalType.NEEDS_USB_PERMISSION || | 246 this.provisionalType_ != |
| 247 this.isExtension, | 247 print_preview.DestinationProvisionalType.NEEDS_USB_PERMISSION || |
| 248 'Provisional USB destination only supprted with extension origin.'); | 248 this.isExtension, |
| 249 'Provisional USB destination only supprted with extension origin.'); |
| 249 } | 250 } |
| 250 | 251 |
| 251 /** | 252 /** |
| 252 * Prefix of the location destination tag. | 253 * Prefix of the location destination tag. |
| 253 * @type {!Array<string>} | 254 * @type {!Array<string>} |
| 254 * @const | 255 * @const |
| 255 */ | 256 */ |
| 256 Destination.LOCATION_TAG_PREFIXES = [ | 257 Destination.LOCATION_TAG_PREFIXES = |
| 257 '__cp__location=', | 258 ['__cp__location=', '__cp__printer-location=']; |
| 258 '__cp__printer-location=' | |
| 259 ]; | |
| 260 | 259 |
| 261 /** | 260 /** |
| 262 * Enumeration of Google-promoted destination IDs. | 261 * Enumeration of Google-promoted destination IDs. |
| 263 * @enum {string} | 262 * @enum {string} |
| 264 */ | 263 */ |
| 265 Destination.GooglePromotedId = { | 264 Destination.GooglePromotedId = { |
| 266 DOCS: '__google__docs', | 265 DOCS: '__google__docs', |
| 267 SAVE_AS_PDF: 'Save as PDF' | 266 SAVE_AS_PDF: 'Save as PDF' |
| 268 }; | 267 }; |
| 269 | 268 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 330 /** | 329 /** |
| 331 * @return {string} Account this destination is registered for, if known. | 330 * @return {string} Account this destination is registered for, if known. |
| 332 */ | 331 */ |
| 333 get account() { | 332 get account() { |
| 334 return this.account_; | 333 return this.account_; |
| 335 }, | 334 }, |
| 336 | 335 |
| 337 /** @return {boolean} Whether the destination is local or cloud-based. */ | 336 /** @return {boolean} Whether the destination is local or cloud-based. */ |
| 338 get isLocal() { | 337 get isLocal() { |
| 339 return this.origin_ == print_preview.DestinationOrigin.LOCAL || | 338 return this.origin_ == print_preview.DestinationOrigin.LOCAL || |
| 340 this.origin_ == print_preview.DestinationOrigin.EXTENSION || | 339 this.origin_ == print_preview.DestinationOrigin.EXTENSION || |
| 341 this.origin_ == print_preview.DestinationOrigin.CROS || | 340 this.origin_ == print_preview.DestinationOrigin.CROS || |
| 342 (this.origin_ == print_preview.DestinationOrigin.PRIVET && | 341 (this.origin_ == print_preview.DestinationOrigin.PRIVET && |
| 343 this.connectionStatus_ != | 342 this.connectionStatus_ != |
| 344 print_preview.DestinationConnectionStatus.UNREGISTERED); | 343 print_preview.DestinationConnectionStatus.UNREGISTERED); |
| 345 }, | 344 }, |
| 346 | 345 |
| 347 /** @return {boolean} Whether the destination is a Privet local printer */ | 346 /** @return {boolean} Whether the destination is a Privet local printer */ |
| 348 get isPrivet() { | 347 get isPrivet() { |
| 349 return this.origin_ == print_preview.DestinationOrigin.PRIVET; | 348 return this.origin_ == print_preview.DestinationOrigin.PRIVET; |
| 350 }, | 349 }, |
| 351 | 350 |
| 352 /** | 351 /** |
| 353 * @return {boolean} Whether the destination is an extension managed | 352 * @return {boolean} Whether the destination is an extension managed |
| 354 * printer. | 353 * printer. |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 445 /** | 444 /** |
| 446 * @param {!print_preview.DestinationConnectionStatus} status Connection | 445 * @param {!print_preview.DestinationConnectionStatus} status Connection |
| 447 * status of the print destination. | 446 * status of the print destination. |
| 448 */ | 447 */ |
| 449 set connectionStatus(status) { | 448 set connectionStatus(status) { |
| 450 this.connectionStatus_ = status; | 449 this.connectionStatus_ = status; |
| 451 }, | 450 }, |
| 452 | 451 |
| 453 /** @return {boolean} Whether the destination is considered offline. */ | 452 /** @return {boolean} Whether the destination is considered offline. */ |
| 454 get isOffline() { | 453 get isOffline() { |
| 455 return arrayContains([print_preview.DestinationConnectionStatus.OFFLINE, | 454 return arrayContains( |
| 456 print_preview.DestinationConnectionStatus.DORMANT], | 455 [ |
| 457 this.connectionStatus_); | 456 print_preview.DestinationConnectionStatus.OFFLINE, |
| 457 print_preview.DestinationConnectionStatus.DORMANT |
| 458 ], |
| 459 this.connectionStatus_); |
| 458 }, | 460 }, |
| 459 | 461 |
| 460 /** @return {string} Human readable status for offline destination. */ | 462 /** @return {string} Human readable status for offline destination. */ |
| 461 get offlineStatusText() { | 463 get offlineStatusText() { |
| 462 if (!this.isOffline) { | 464 if (!this.isOffline) { |
| 463 return ''; | 465 return ''; |
| 464 } | 466 } |
| 465 var offlineDurationMs = Date.now() - this.lastAccessTime_; | 467 var offlineDurationMs = Date.now() - this.lastAccessTime_; |
| 466 var offlineMessageId; | 468 var offlineMessageId; |
| 467 if (offlineDurationMs > 31622400000.0) { // One year. | 469 if (offlineDurationMs > 31622400000.0) { // One year. |
| (...skipping 23 matching lines...) Expand all Loading... |
| 491 } | 493 } |
| 492 if (this.id_ == Destination.GooglePromotedId.SAVE_AS_PDF) { | 494 if (this.id_ == Destination.GooglePromotedId.SAVE_AS_PDF) { |
| 493 return Destination.IconUrl_.PDF; | 495 return Destination.IconUrl_.PDF; |
| 494 } | 496 } |
| 495 if (this.isEnterprisePrinter) { | 497 if (this.isEnterprisePrinter) { |
| 496 return Destination.IconUrl_.ENTERPRISE; | 498 return Destination.IconUrl_.ENTERPRISE; |
| 497 } | 499 } |
| 498 if (this.isLocal) { | 500 if (this.isLocal) { |
| 499 return Destination.IconUrl_.LOCAL; | 501 return Destination.IconUrl_.LOCAL; |
| 500 } | 502 } |
| 501 if (this.type_ == print_preview.DestinationType.MOBILE && | 503 if (this.type_ == print_preview.DestinationType.MOBILE && this.isOwned_) { |
| 502 this.isOwned_) { | |
| 503 return Destination.IconUrl_.MOBILE; | 504 return Destination.IconUrl_.MOBILE; |
| 504 } | 505 } |
| 505 if (this.type_ == print_preview.DestinationType.MOBILE) { | 506 if (this.type_ == print_preview.DestinationType.MOBILE) { |
| 506 return Destination.IconUrl_.MOBILE_SHARED; | 507 return Destination.IconUrl_.MOBILE_SHARED; |
| 507 } | 508 } |
| 508 if (this.isOwned_) { | 509 if (this.isOwned_) { |
| 509 return Destination.IconUrl_.CLOUD; | 510 return Destination.IconUrl_.CLOUD; |
| 510 } | 511 } |
| 511 return Destination.IconUrl_.CLOUD_SHARED; | 512 return Destination.IconUrl_.CLOUD_SHARED; |
| 512 }, | 513 }, |
| (...skipping 27 matching lines...) Expand all Loading... |
| 540 get provisionalType() { | 541 get provisionalType() { |
| 541 return this.provisionalType_; | 542 return this.provisionalType_; |
| 542 }, | 543 }, |
| 543 | 544 |
| 544 /** | 545 /** |
| 545 * Whether the destinaion is provisional. | 546 * Whether the destinaion is provisional. |
| 546 * @return {boolean} | 547 * @return {boolean} |
| 547 */ | 548 */ |
| 548 get isProvisional() { | 549 get isProvisional() { |
| 549 return this.provisionalType_ != | 550 return this.provisionalType_ != |
| 550 print_preview.DestinationProvisionalType.NONE; | 551 print_preview.DestinationProvisionalType.NONE; |
| 551 }, | 552 }, |
| 552 | 553 |
| 553 /** | 554 /** |
| 554 * Whether the printer is enterprise policy controlled printer. | 555 * Whether the printer is enterprise policy controlled printer. |
| 555 * @return {boolean} | 556 * @return {boolean} |
| 556 */ | 557 */ |
| 557 get isEnterprisePrinter() { | 558 get isEnterprisePrinter() { |
| 558 return this.isEnterprisePrinter_; | 559 return this.isEnterprisePrinter_; |
| 559 }, | 560 }, |
| 560 }; | 561 }; |
| 561 | 562 |
| 562 // Export | 563 // Export |
| 563 return { | 564 return { |
| 564 Destination: Destination, | 565 Destination: Destination, |
| 565 }; | 566 }; |
| 566 }); | 567 }); |
| OLD | NEW |