| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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.define('print_preview', function() { | 5 cr.define('print_preview', function() { |
| 6 'use strict'; | 6 'use strict'; |
| 7 | 7 |
| 8 /** | 8 /** |
| 9 * A set of key parameters describing a destination used to determine | 9 * A set of key parameters describing a destination used to determine |
| 10 * if two destinations are the same. | 10 * if two destinations are the same. |
| 11 * @param {!Array<!print_preview.DestinationOrigin>} origins Match | 11 * @param {!Array<!print_preview.DestinationOrigin>} origins Match |
| 12 * destinations from these origins. | 12 * destinations from these origins. |
| 13 * @param {RegExp} idRegExp Match destination's id. | 13 * @param {RegExp} idRegExp Match destination's id. |
| 14 * @param {RegExp} displayNameRegExp Match destination's displayName. | 14 * @param {RegExp} displayNameRegExp Match destination's displayName. |
| 15 * @param {boolean} skipVirtualDestinations Whether to ignore virtual | 15 * @param {boolean} skipVirtualDestinations Whether to ignore virtual |
| 16 * destinations, for example, Save as PDF. | 16 * destinations, for example, Save as PDF. |
| 17 * @constructor | 17 * @constructor |
| 18 */ | 18 */ |
| 19 function DestinationMatch( | 19 function DestinationMatch( |
| 20 origins, idRegExp, displayNameRegExp, skipVirtualDestinations) { | 20 origins, idRegExp, displayNameRegExp, skipVirtualDestinations) { |
| 21 | |
| 22 /** @private {!Array<!print_preview.DestinationOrigin>} */ | 21 /** @private {!Array<!print_preview.DestinationOrigin>} */ |
| 23 this.origins_ = origins; | 22 this.origins_ = origins; |
| 24 | 23 |
| 25 /** @private {RegExp} */ | 24 /** @private {RegExp} */ |
| 26 this.idRegExp_ = idRegExp; | 25 this.idRegExp_ = idRegExp; |
| 27 | 26 |
| 28 /** @private {RegExp} */ | 27 /** @private {RegExp} */ |
| 29 this.displayNameRegExp_ = displayNameRegExp; | 28 this.displayNameRegExp_ = displayNameRegExp; |
| 30 | 29 |
| 31 /** @private {boolean} */ | 30 /** @private {boolean} */ |
| 32 this.skipVirtualDestinations_ = skipVirtualDestinations; | 31 this.skipVirtualDestinations_ = skipVirtualDestinations; |
| 33 } | 32 } |
| 34 | 33 |
| 35 DestinationMatch.prototype = { | 34 DestinationMatch.prototype = { |
| 36 | 35 |
| 37 /** | 36 /** |
| 38 * @param {string} origin Origin to match. | 37 * @param {string} origin Origin to match. |
| 39 * @return {boolean} Whether the origin is one of the {@code origins_}. | 38 * @return {boolean} Whether the origin is one of the {@code origins_}. |
| 40 */ | 39 */ |
| 41 matchOrigin: function(origin) { | 40 matchOrigin: function(origin) { |
| 42 return arrayContains(this.origins_, origin); | 41 return arrayContains(this.origins_, origin); |
| 43 }, | 42 }, |
| 44 | 43 |
| 45 /** | 44 /** |
| 46 * @param {string} id Id of the destination. | 45 * @param {string} id Id of the destination. |
| 47 * @param {string} origin Origin of the destination. | 46 * @param {string} origin Origin of the destination. |
| 48 * @return {boolean} Whether destination is the same as initial. | 47 * @return {boolean} Whether destination is the same as initial. |
| 49 */ | 48 */ |
| 50 matchIdAndOrigin: function(id, origin) { | 49 matchIdAndOrigin: function(id, origin) { |
| 51 return this.matchOrigin(origin) && | 50 return this.matchOrigin(origin) && !!this.idRegExp_ && |
| 52 !!this.idRegExp_ && | 51 this.idRegExp_.test(id); |
| 53 this.idRegExp_.test(id); | |
| 54 }, | 52 }, |
| 55 | 53 |
| 56 /** | 54 /** |
| 57 * @param {!print_preview.Destination} destination Destination to match. | 55 * @param {!print_preview.Destination} destination Destination to match. |
| 58 * @return {boolean} Whether {@code destination} matches the last user | 56 * @return {boolean} Whether {@code destination} matches the last user |
| 59 * selected one. | 57 * selected one. |
| 60 */ | 58 */ |
| 61 match: function(destination) { | 59 match: function(destination) { |
| 62 if (!this.matchOrigin(destination.origin)) { | 60 if (!this.matchOrigin(destination.origin)) { |
| 63 return false; | 61 return false; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 82 * destination selection. | 80 * destination selection. |
| 83 * @private | 81 * @private |
| 84 */ | 82 */ |
| 85 isVirtualDestination_: function(destination) { | 83 isVirtualDestination_: function(destination) { |
| 86 if (destination.origin == print_preview.DestinationOrigin.LOCAL) { | 84 if (destination.origin == print_preview.DestinationOrigin.LOCAL) { |
| 87 return arrayContains( | 85 return arrayContains( |
| 88 [print_preview.Destination.GooglePromotedId.SAVE_AS_PDF], | 86 [print_preview.Destination.GooglePromotedId.SAVE_AS_PDF], |
| 89 destination.id); | 87 destination.id); |
| 90 } | 88 } |
| 91 return arrayContains( | 89 return arrayContains( |
| 92 [print_preview.Destination.GooglePromotedId.DOCS], | 90 [print_preview.Destination.GooglePromotedId.DOCS], destination.id); |
| 93 destination.id); | |
| 94 } | 91 } |
| 95 }; | 92 }; |
| 96 | 93 |
| 97 // Export | 94 // Export |
| 98 return { | 95 return {DestinationMatch: DestinationMatch}; |
| 99 DestinationMatch: DestinationMatch | |
| 100 }; | |
| 101 }); | 96 }); |
| OLD | NEW |