OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 cr.define('print_preview', function() { |
| 6 'use strict'; |
| 7 |
| 8 /** |
| 9 * Print destination data object that holds data for both local and cloud |
| 10 * destinations. |
| 11 * @param {string} id ID of the destination. |
| 12 * @param {string} displayName Display name of the destination. |
| 13 * @param {boolean} isRecent Whether the destination has been used recently. |
| 14 * @param {boolean} isLocal Whether the destination is local or cloud-based. |
| 15 * @param {Array.<string>=} opt_tags Tags associated with the destination. |
| 16 * @constructor |
| 17 */ |
| 18 function Destination(id, displayName, isRecent, isLocal, opt_tags) { |
| 19 /** |
| 20 * ID of the destination. |
| 21 * @type {string} |
| 22 * @private |
| 23 */ |
| 24 this.id_ = id; |
| 25 |
| 26 /** |
| 27 * Display name of the destination. |
| 28 * @type {string} |
| 29 * @private |
| 30 */ |
| 31 this.displayName_ = displayName; |
| 32 |
| 33 /** |
| 34 * Whether the destination has been used recently. |
| 35 * @type {boolean} |
| 36 * @private |
| 37 */ |
| 38 this.isRecent_ = isRecent; |
| 39 |
| 40 /** |
| 41 * Whether the destination is local or cloud-based. |
| 42 * @type {boolean} |
| 43 * @private |
| 44 */ |
| 45 this.isLocal_ = isLocal; |
| 46 |
| 47 /** |
| 48 * Tags associated with the destination. |
| 49 * @type {!Array.<string>} |
| 50 * @private |
| 51 */ |
| 52 this.tags_ = opt_tags || []; |
| 53 |
| 54 /** |
| 55 * Print capabilities of the destination. |
| 56 * @type {print_preview.ChromiumCapabilities} |
| 57 * @private |
| 58 */ |
| 59 this.capabilities_ = null; |
| 60 |
| 61 /** |
| 62 * Cache of destination location fetched from tags. |
| 63 * @type {string} |
| 64 * @private |
| 65 */ |
| 66 this.location_ = null; |
| 67 }; |
| 68 |
| 69 /** |
| 70 * Prefix of the location destination tag. |
| 71 * @type {string} |
| 72 * @const |
| 73 */ |
| 74 Destination.LOCATION_TAG_PREFIX = '__cp__printer-location='; |
| 75 |
| 76 /** |
| 77 * Enumeration of Google-promoted destination IDs. |
| 78 * @enum {string} |
| 79 */ |
| 80 Destination.GooglePromotedId = { |
| 81 DOCS: '__google__docs', |
| 82 SAVE_AS_PDF: 'Save as PDF', |
| 83 PRINT_WITH_CLOUD_PRINT: 'printWithCloudPrint' |
| 84 }; |
| 85 |
| 86 Destination.prototype = { |
| 87 /** @return {string} ID of the destination. */ |
| 88 get id() { |
| 89 return this.id_; |
| 90 }, |
| 91 |
| 92 /** @return {string} Display name of the destination. */ |
| 93 get displayName() { |
| 94 return this.displayName_; |
| 95 }, |
| 96 |
| 97 /** @return {boolean} Whether the destination has been used recently. */ |
| 98 get isRecent() { |
| 99 return this.isRecent_; |
| 100 }, |
| 101 |
| 102 /** |
| 103 * @param {boolean} isRecent Whether the destination has been used recently. |
| 104 */ |
| 105 set isRecent(isRecent) { |
| 106 this.isRecent_ = isRecent; |
| 107 }, |
| 108 |
| 109 /** @return {boolean} Whether the destination is local or cloud-based. */ |
| 110 get isLocal() { |
| 111 return this.isLocal_; |
| 112 }, |
| 113 |
| 114 /** @return {boolean} Whether the destination is promoted by Google. */ |
| 115 get isGooglePromoted() { |
| 116 for (var key in Destination.GooglePromotedId) { |
| 117 if (Destination.GooglePromotedId[key] == this.id_) { |
| 118 return true; |
| 119 } |
| 120 } |
| 121 return false; |
| 122 }, |
| 123 |
| 124 /** |
| 125 * @return {boolean} Whether the destination is the "Print with Cloud Print" |
| 126 * destination. |
| 127 */ |
| 128 get isPrintWithCloudPrint() { |
| 129 return this.id_ == Destination.GooglePromotedId.PRINT_WITH_CLOUD_PRINT; |
| 130 }, |
| 131 |
| 132 /** |
| 133 * @return {string} The location of the destination, or an empty string if |
| 134 * the location is unknown. |
| 135 */ |
| 136 get location() { |
| 137 if (this.location_ == null) { |
| 138 for (var tag, i = 0; tag = this.tags_[i]; i++) { |
| 139 if (tag.indexOf(Destination.LOCATION_TAG_PREFIX) == 0) { |
| 140 this.location_ = tag.substring( |
| 141 Destination.LOCATION_TAG_PREFIX.length); |
| 142 } |
| 143 } |
| 144 if (this.location_ == null) { |
| 145 this.location_ = ''; |
| 146 } |
| 147 } |
| 148 return this.location_; |
| 149 }, |
| 150 |
| 151 /** @return {!Array.<string>} Tags associated with the destination. */ |
| 152 get tags() { |
| 153 return this.tags_.slice(0); |
| 154 }, |
| 155 |
| 156 /** |
| 157 * @return {print_preview.ChromiumCapabilities} Print capabilities of the |
| 158 * destination. |
| 159 */ |
| 160 get capabilities() { |
| 161 return this.capabilities_; |
| 162 }, |
| 163 |
| 164 /** |
| 165 * @param {!print_preview.ChromiumCapabilities} capabilities Print |
| 166 * capabilities of the destination. |
| 167 */ |
| 168 set capabilities(capabilities) { |
| 169 this.capabilities_ = capabilities; |
| 170 }, |
| 171 |
| 172 /** |
| 173 * Matches a query against the destination. |
| 174 * @param {string} query Query to match against the destination. |
| 175 * @return {boolean} {@code true} if the query matches this destination, |
| 176 * {@code false} otherwise. |
| 177 */ |
| 178 matches: function(query) { |
| 179 return this.displayName_.toLowerCase().indexOf( |
| 180 query.toLowerCase().trim()) != -1; |
| 181 } |
| 182 }; |
| 183 |
| 184 // Export |
| 185 return { |
| 186 Destination: Destination |
| 187 }; |
| 188 }); |
OLD | NEW |