| 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'); |
| 6 |
| 7 /** |
| 8 * The CDD (Cloud Device Description) describes the capabilities of a print |
| 9 * destination. |
| 10 * |
| 11 * @typedef {{ |
| 12 * version: string, |
| 13 * printer: { |
| 14 * vendor_capability: !Array.<{Object}>, |
| 15 * collate: ({default: (boolean|undefined)}|undefined), |
| 16 * color: ({ |
| 17 * option: !Array.<{ |
| 18 * type: (string|undefined), |
| 19 * vendor_id: (string|undefined), |
| 20 * custom_display_name: (string|undefined), |
| 21 * is_default: (boolean|undefined) |
| 22 * }> |
| 23 * }|undefined), |
| 24 * copies: ({default: (number|undefined), |
| 25 * max: (number|undefined)}|undefined), |
| 26 * duplex: ({option: !Array.<{type: (string|undefined), |
| 27 * is_default: (boolean|undefined)}>}|undefined), |
| 28 * page_orientation: ({ |
| 29 * option: !Array.<{type: (string|undefined), |
| 30 * is_default: (boolean|undefined)}> |
| 31 * }|undefined) |
| 32 * } |
| 33 * }} |
| 34 */ |
| 35 print_preview.Cdd; |
| 36 |
| 5 cr.define('print_preview', function() { | 37 cr.define('print_preview', function() { |
| 6 'use strict'; | 38 'use strict'; |
| 7 | 39 |
| 8 /** | 40 /** |
| 9 * Print destination data object that holds data for both local and cloud | 41 * Print destination data object that holds data for both local and cloud |
| 10 * destinations. | 42 * destinations. |
| 11 * @param {string} id ID of the destination. | 43 * @param {string} id ID of the destination. |
| 12 * @param {!print_preview.Destination.Type} type Type of the destination. | 44 * @param {!print_preview.Destination.Type} type Type of the destination. |
| 13 * @param {!print_preview.Destination.Origin} origin Origin of the | 45 * @param {!print_preview.Destination.Origin} origin Origin of the |
| 14 * destination. | 46 * destination. |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 */ | 139 */ |
| 108 this.lastAccessTime_ = (opt_params && opt_params.lastAccessTime) || | 140 this.lastAccessTime_ = (opt_params && opt_params.lastAccessTime) || |
| 109 Date.now(); | 141 Date.now(); |
| 110 | 142 |
| 111 /** | 143 /** |
| 112 * Whether the user has accepted the terms-of-service for the print | 144 * Whether the user has accepted the terms-of-service for the print |
| 113 * destination. Only applies to the FedEx Office cloud-based printer. | 145 * destination. Only applies to the FedEx Office cloud-based printer. |
| 114 * {@code null} if terms-of-service does not apply to the print destination. | 146 * {@code null} if terms-of-service does not apply to the print destination. |
| 115 * @private {?boolean} | 147 * @private {?boolean} |
| 116 */ | 148 */ |
| 117 this.isTosAccepted_ = opt_params && opt_params.isTosAccepted; | 149 this.isTosAccepted_ = !!(opt_params && opt_params.isTosAccepted); |
| 118 | 150 |
| 119 /** | 151 /** |
| 120 * Cloud ID for Privet printers. | 152 * Cloud ID for Privet printers. |
| 121 * @private {string} | 153 * @private {string} |
| 122 */ | 154 */ |
| 123 this.cloudID_ = (opt_params && opt_params.cloudID) || ''; | 155 this.cloudID_ = (opt_params && opt_params.cloudID) || ''; |
| 124 }; | 156 }; |
| 125 | 157 |
| 126 /** | 158 /** |
| 127 * Prefix of the location destination tag. | 159 * Prefix of the location destination tag. |
| 128 * @type {!Array.<string>} | 160 * @type {!Array.<string>} |
| 129 * @const | 161 * @const |
| 130 */ | 162 */ |
| 131 Destination.LOCATION_TAG_PREFIXES = [ | 163 Destination.LOCATION_TAG_PREFIXES = [ |
| 132 '__cp__location=', | 164 '__cp__location=', |
| 133 '__cp__printer-location=' | 165 '__cp__printer-location=' |
| 134 ]; | 166 ]; |
| 135 | 167 |
| 136 /** | 168 /** |
| 137 * Enumeration of Google-promoted destination IDs. | |
| 138 * @enum {string} | |
| 139 */ | |
| 140 Destination.GooglePromotedId = { | |
| 141 DOCS: '__google__docs', | |
| 142 FEDEX: '__google__fedex', | |
| 143 SAVE_AS_PDF: 'Save as PDF' | |
| 144 }; | |
| 145 | |
| 146 /** | |
| 147 * Enumeration of the types of destinations. | |
| 148 * @enum {string} | |
| 149 */ | |
| 150 Destination.Type = { | |
| 151 GOOGLE: 'google', | |
| 152 LOCAL: 'local', | |
| 153 MOBILE: 'mobile' | |
| 154 }; | |
| 155 | |
| 156 /** | |
| 157 * Enumeration of the origin types for cloud destinations. | |
| 158 * @enum {string} | |
| 159 */ | |
| 160 Destination.Origin = { | |
| 161 LOCAL: 'local', | |
| 162 COOKIES: 'cookies', | |
| 163 PROFILE: 'profile', | |
| 164 DEVICE: 'device', | |
| 165 PRIVET: 'privet' | |
| 166 }; | |
| 167 | |
| 168 /** | |
| 169 * Enumeration of the connection statuses of printer destinations. | |
| 170 * @enum {string} | |
| 171 */ | |
| 172 Destination.ConnectionStatus = { | |
| 173 DORMANT: 'DORMANT', | |
| 174 OFFLINE: 'OFFLINE', | |
| 175 ONLINE: 'ONLINE', | |
| 176 UNKNOWN: 'UNKNOWN', | |
| 177 UNREGISTERED: 'UNREGISTERED' | |
| 178 }; | |
| 179 | |
| 180 /** | |
| 181 * Enumeration of relative icon URLs for various types of destinations. | 169 * Enumeration of relative icon URLs for various types of destinations. |
| 182 * @enum {string} | 170 * @enum {string} |
| 183 * @private | 171 * @private |
| 184 */ | 172 */ |
| 185 Destination.IconUrl_ = { | 173 Destination.IconUrl_ = { |
| 186 CLOUD: 'images/printer.png', | 174 CLOUD: 'images/printer.png', |
| 187 CLOUD_SHARED: 'images/printer_shared.png', | 175 CLOUD_SHARED: 'images/printer_shared.png', |
| 188 LOCAL: 'images/printer.png', | 176 LOCAL: 'images/printer.png', |
| 189 MOBILE: 'images/mobile.png', | 177 MOBILE: 'images/mobile.png', |
| 190 MOBILE_SHARED: 'images/mobile_shared.png', | 178 MOBILE_SHARED: 'images/mobile_shared.png', |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 416 return [this.location, this.description]; | 404 return [this.location, this.description]; |
| 417 }, | 405 }, |
| 418 | 406 |
| 419 /** | 407 /** |
| 420 * Matches a query against the destination. | 408 * Matches a query against the destination. |
| 421 * @param {!RegExp} query Query to match against the destination. | 409 * @param {!RegExp} query Query to match against the destination. |
| 422 * @return {boolean} {@code true} if the query matches this destination, | 410 * @return {boolean} {@code true} if the query matches this destination, |
| 423 * {@code false} otherwise. | 411 * {@code false} otherwise. |
| 424 */ | 412 */ |
| 425 matches: function(query) { | 413 matches: function(query) { |
| 426 return this.displayName_.match(query) || | 414 return !!this.displayName_.match(query) || |
| 427 this.extraPropertiesToMatch.some(function(property) { | 415 this.extraPropertiesToMatch.some(function(property) { |
| 428 return property.match(query); | 416 return property.match(query); |
| 429 }); | 417 }); |
| 430 } | 418 } |
| 431 }; | 419 }; |
| 432 | 420 |
| 433 /** | |
| 434 * The CDD (Cloud Device Description) describes the capabilities of a print | |
| 435 * destination. | |
| 436 * | |
| 437 * @typedef {{ | |
| 438 * version: string, | |
| 439 * printer: { | |
| 440 * vendor_capability: !Array.<{Object}>, | |
| 441 * collate: {default: boolean=}=, | |
| 442 * color: { | |
| 443 * option: !Array.<{ | |
| 444 * type: string=, | |
| 445 * vendor_id: string=, | |
| 446 * custom_display_name: string=, | |
| 447 * is_default: boolean= | |
| 448 * }> | |
| 449 * }=, | |
| 450 * copies: {default: number=, max: number=}=, | |
| 451 * duplex: {option: !Array.<{type: string=, is_default: boolean=}>}=, | |
| 452 * page_orientation: { | |
| 453 * option: !Array.<{type: string=, is_default: boolean=}> | |
| 454 * }= | |
| 455 * } | |
| 456 * }} | |
| 457 */ | |
| 458 var Cdd = Object; | |
| 459 | |
| 460 // Export | 421 // Export |
| 461 return { | 422 return { |
| 462 Destination: Destination, | 423 Destination: Destination, |
| 463 Cdd: Cdd | |
| 464 }; | 424 }; |
| 465 }); | 425 }); |
| 426 |
| 427 /** |
| 428 * Enumeration of Google-promoted destination IDs. |
| 429 * @enum {string} |
| 430 */ |
| 431 print_preview.Destination.GooglePromotedId = { |
| 432 DOCS: '__google__docs', |
| 433 FEDEX: '__google__fedex', |
| 434 SAVE_AS_PDF: 'Save as PDF' |
| 435 }; |
| 436 |
| 437 /** |
| 438 * Enumeration of the types of destinations. |
| 439 * @enum {string} |
| 440 */ |
| 441 print_preview.Destination.Type = { |
| 442 GOOGLE: 'google', |
| 443 GOOGLE_PROMOTED: 'google_promoted', |
| 444 LOCAL: 'local', |
| 445 MOBILE: 'mobile' |
| 446 }; |
| 447 |
| 448 /** |
| 449 * Enumeration of the origin types for cloud destinations. |
| 450 * @enum {string} |
| 451 */ |
| 452 print_preview.Destination.Origin = { |
| 453 LOCAL: 'local', |
| 454 COOKIES: 'cookies', |
| 455 PROFILE: 'profile', |
| 456 DEVICE: 'device', |
| 457 PRIVET: 'privet' |
| 458 }; |
| 459 |
| 460 /** |
| 461 * Enumeration of the connection statuses of printer destinations. |
| 462 * @enum {string} |
| 463 */ |
| 464 print_preview.Destination.ConnectionStatus = { |
| 465 DORMANT: 'DORMANT', |
| 466 OFFLINE: 'OFFLINE', |
| 467 ONLINE: 'ONLINE', |
| 468 UNKNOWN: 'UNKNOWN', |
| 469 UNREGISTERED: 'UNREGISTERED' |
| 470 }; |
| OLD | NEW |