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 * The CDD (Cloud Device Description) describes the capabilities of a print | 8 * The CDD (Cloud Device Description) describes the capabilities of a print |
9 * destination. | 9 * destination. |
10 * | 10 * |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
48 * @param {boolean} isRecent Whether the destination has been used recently. | 48 * @param {boolean} isRecent Whether the destination has been used recently. |
49 * @param {!print_preview.Destination.ConnectionStatus} connectionStatus | 49 * @param {!print_preview.Destination.ConnectionStatus} connectionStatus |
50 * Connection status of the print destination. | 50 * Connection status of the print destination. |
51 * @param {{tags: (Array<string>|undefined), | 51 * @param {{tags: (Array<string>|undefined), |
52 * isOwned: (boolean|undefined), | 52 * isOwned: (boolean|undefined), |
53 * account: (string|undefined), | 53 * account: (string|undefined), |
54 * lastAccessTime: (number|undefined), | 54 * lastAccessTime: (number|undefined), |
55 * isTosAccepted: (boolean|undefined), | 55 * isTosAccepted: (boolean|undefined), |
56 * cloudID: (string|undefined), | 56 * cloudID: (string|undefined), |
57 * extensionId: (string|undefined), | 57 * extensionId: (string|undefined), |
58 * extensionName: (string|undefined), | |
58 * description: (string|undefined)}=} opt_params Optional parameters | 59 * description: (string|undefined)}=} opt_params Optional parameters |
59 * for the destination. | 60 * for the destination. |
60 * @constructor | 61 * @constructor |
61 */ | 62 */ |
62 function Destination(id, type, origin, displayName, isRecent, | 63 function Destination(id, type, origin, displayName, isRecent, |
63 connectionStatus, opt_params) { | 64 connectionStatus, opt_params) { |
64 /** | 65 /** |
65 * ID of the destination. | 66 * ID of the destination. |
66 * @private {string} | 67 * @private {string} |
67 */ | 68 */ |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
153 * Cloud ID for Privet printers. | 154 * Cloud ID for Privet printers. |
154 * @private {string} | 155 * @private {string} |
155 */ | 156 */ |
156 this.cloudID_ = (opt_params && opt_params.cloudID) || ''; | 157 this.cloudID_ = (opt_params && opt_params.cloudID) || ''; |
157 | 158 |
158 /** | 159 /** |
159 * Extension ID for extension managed printers. | 160 * Extension ID for extension managed printers. |
160 * @private {string} | 161 * @private {string} |
161 */ | 162 */ |
162 this.extensionId_ = (opt_params && opt_params.extensionId) || ''; | 163 this.extensionId_ = (opt_params && opt_params.extensionId) || ''; |
164 | |
165 /** | |
166 * Extension name for extension managed printers. | |
167 * @private {string} | |
168 */ | |
169 this.extensionName_ = (opt_params && opt_params.extensionName) || ''; | |
163 }; | 170 }; |
164 | 171 |
165 /** | 172 /** |
166 * Prefix of the location destination tag. | 173 * Prefix of the location destination tag. |
167 * @type {!Array<string>} | 174 * @type {!Array<string>} |
168 * @const | 175 * @const |
169 */ | 176 */ |
170 Destination.LOCATION_TAG_PREFIXES = [ | 177 Destination.LOCATION_TAG_PREFIXES = [ |
171 '__cp__location=', | 178 '__cp__location=', |
172 '__cp__printer-location=' | 179 '__cp__printer-location=' |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
336 | 343 |
337 /** | 344 /** |
338 * @return {string} Most relevant string to help user to identify this | 345 * @return {string} Most relevant string to help user to identify this |
339 * destination. | 346 * destination. |
340 */ | 347 */ |
341 get hint() { | 348 get hint() { |
342 if (this.id_ == Destination.GooglePromotedId.DOCS || | 349 if (this.id_ == Destination.GooglePromotedId.DOCS || |
343 this.id_ == Destination.GooglePromotedId.FEDEX) { | 350 this.id_ == Destination.GooglePromotedId.FEDEX) { |
344 return this.account_; | 351 return this.account_; |
345 } | 352 } |
346 return this.location || this.description; | 353 return this.location || this.extensionName || this.description; |
347 }, | 354 }, |
348 | 355 |
349 /** @return {!Array<string>} Tags associated with the destination. */ | 356 /** @return {!Array<string>} Tags associated with the destination. */ |
350 get tags() { | 357 get tags() { |
351 return this.tags_.slice(0); | 358 return this.tags_.slice(0); |
352 }, | 359 }, |
353 | 360 |
354 /** @return {string} Cloud ID associated with the destination */ | 361 /** @return {string} Cloud ID associated with the destination */ |
355 get cloudID() { | 362 get cloudID() { |
356 return this.cloudID_; | 363 return this.cloudID_; |
357 }, | 364 }, |
358 | 365 |
359 /** | 366 /** |
360 * @return {string} Extension ID associated with the destination. Non-empty | 367 * @return {string} Extension ID associated with the destination. Non-empty |
361 * only for extension managed printers. | 368 * only for extension managed printers. |
362 */ | 369 */ |
363 get extensionId() { | 370 get extensionId() { |
364 return this.extensionId_; | 371 return this.extensionId_; |
365 }, | 372 }, |
366 | 373 |
374 /** | |
375 * @return {string} Extension name associated with the destination. | |
376 * Non-empty only for extension managed printers. | |
377 */ | |
378 get extensionName() { | |
379 return this.extensionName_; | |
380 }, | |
381 | |
367 /** @return {?print_preview.Cdd} Print capabilities of the destination. */ | 382 /** @return {?print_preview.Cdd} Print capabilities of the destination. */ |
368 get capabilities() { | 383 get capabilities() { |
369 return this.capabilities_; | 384 return this.capabilities_; |
370 }, | 385 }, |
371 | 386 |
372 /** | 387 /** |
373 * @param {!print_preview.Cdd} capabilities Print capabilities of the | 388 * @param {!print_preview.Cdd} capabilities Print capabilities of the |
374 * destination. | 389 * destination. |
375 */ | 390 */ |
376 set capabilities(capabilities) { | 391 set capabilities(capabilities) { |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
428 }, | 443 }, |
429 | 444 |
430 /** @return {string} Relative URL of the destination's icon. */ | 445 /** @return {string} Relative URL of the destination's icon. */ |
431 get iconUrl() { | 446 get iconUrl() { |
432 if (this.id_ == Destination.GooglePromotedId.DOCS) { | 447 if (this.id_ == Destination.GooglePromotedId.DOCS) { |
433 return Destination.IconUrl_.DOCS; | 448 return Destination.IconUrl_.DOCS; |
434 } else if (this.id_ == Destination.GooglePromotedId.FEDEX) { | 449 } else if (this.id_ == Destination.GooglePromotedId.FEDEX) { |
435 return Destination.IconUrl_.FEDEX; | 450 return Destination.IconUrl_.FEDEX; |
436 } else if (this.id_ == Destination.GooglePromotedId.SAVE_AS_PDF) { | 451 } else if (this.id_ == Destination.GooglePromotedId.SAVE_AS_PDF) { |
437 return Destination.IconUrl_.PDF; | 452 return Destination.IconUrl_.PDF; |
438 } else if (this.isExtension) { | |
439 // TODO(tbarzic): Update the way extension printers are displayed in the | |
440 // destination list when the desired UX is defined. | |
441 return 'chrome://extension-icon/' + this.extensionId + '/48/1'; | |
442 } else if (this.isLocal) { | 453 } else if (this.isLocal) { |
443 return Destination.IconUrl_.LOCAL; | 454 return Destination.IconUrl_.LOCAL; |
444 } else if (this.type_ == Destination.Type.MOBILE && this.isOwned_) { | 455 } else if (this.type_ == Destination.Type.MOBILE && this.isOwned_) { |
445 return Destination.IconUrl_.MOBILE; | 456 return Destination.IconUrl_.MOBILE; |
446 } else if (this.type_ == Destination.Type.MOBILE) { | 457 } else if (this.type_ == Destination.Type.MOBILE) { |
447 return Destination.IconUrl_.MOBILE_SHARED; | 458 return Destination.IconUrl_.MOBILE_SHARED; |
448 } else if (this.isOwned_) { | 459 } else if (this.isOwned_) { |
449 return Destination.IconUrl_.CLOUD; | 460 return Destination.IconUrl_.CLOUD; |
450 } else { | 461 } else { |
451 return Destination.IconUrl_.CLOUD_SHARED; | 462 return Destination.IconUrl_.CLOUD_SHARED; |
452 } | 463 } |
453 }, | 464 }, |
454 | 465 |
455 /** | 466 /** |
467 * @return {string} For extension destinations returns the backgournd-image | |
468 * style property of extension icon associated with the destination. The | |
469 * icon should be used to attribute the destination to an extension. | |
470 * For non extension destination, returns empty string. | |
471 */ | |
472 get extensionIconImageStyle() { | |
473 if (!this.extensionId_) | |
474 return ''; | |
475 return '-webkit-image-set(' + | |
476 'url(chrome://extension-icon/' + this.extensionId_ + '/24/1) 1x,' + | |
477 'url(chrome://extension-icon/' + this.extensionId_ + '/48/1) 2x)'; | |
478 }, | |
Aleksey Shlyapnikov
2015/03/06 00:27:39
If it's not part of the generic iconUrl logic, can
tbarzic
2015/03/06 03:16:11
Done.
| |
479 | |
480 /** | |
456 * @return {?boolean} Whether the user has accepted the terms-of-service of | 481 * @return {?boolean} Whether the user has accepted the terms-of-service of |
457 * the print destination or {@code null} if a terms-of-service does not | 482 * the print destination or {@code null} if a terms-of-service does not |
458 * apply. | 483 * apply. |
459 */ | 484 */ |
460 get isTosAccepted() { | 485 get isTosAccepted() { |
461 return this.isTosAccepted_; | 486 return this.isTosAccepted_; |
462 }, | 487 }, |
463 | 488 |
464 /** | 489 /** |
465 * @param {?boolean} isTosAccepted Whether the user has accepted the | 490 * @param {?boolean} isTosAccepted Whether the user has accepted the |
(...skipping 13 matching lines...) Expand all Loading... | |
479 }, | 504 }, |
480 | 505 |
481 /** | 506 /** |
482 * Matches a query against the destination. | 507 * Matches a query against the destination. |
483 * @param {!RegExp} query Query to match against the destination. | 508 * @param {!RegExp} query Query to match against the destination. |
484 * @return {boolean} {@code true} if the query matches this destination, | 509 * @return {boolean} {@code true} if the query matches this destination, |
485 * {@code false} otherwise. | 510 * {@code false} otherwise. |
486 */ | 511 */ |
487 matches: function(query) { | 512 matches: function(query) { |
488 return !!this.displayName_.match(query) || | 513 return !!this.displayName_.match(query) || |
514 !!this.extensionName_.match(query) || | |
489 this.extraPropertiesToMatch.some(function(property) { | 515 this.extraPropertiesToMatch.some(function(property) { |
490 return property.match(query); | 516 return property.match(query); |
491 }); | 517 }); |
492 } | 518 } |
493 }; | 519 }; |
494 | 520 |
495 // Export | 521 // Export |
496 return { | 522 return { |
497 Destination: Destination, | 523 Destination: Destination, |
498 }; | 524 }; |
499 }); | 525 }); |
OLD | NEW |