Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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('downloads', function() { | 5 cr.define('downloads', function() { |
| 6 var Item = Polymer({ | 6 var Item = Polymer({ |
| 7 is: 'downloads-item', | 7 is: 'downloads-item', |
| 8 | 8 |
| 9 /** | 9 /** |
| 10 * @param {!downloads.ThrottledIconLoader} iconLoader | 10 * @param {!downloads.ThrottledIconLoader} iconLoader |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 33 }.bind(this)); | 33 }.bind(this)); |
| 34 }, | 34 }, |
| 35 }, | 35 }, |
| 36 | 36 |
| 37 scrollbarWidth: { | 37 scrollbarWidth: { |
| 38 type: Number, | 38 type: Number, |
| 39 value: 0, | 39 value: 0, |
| 40 observer: 'onScrollbarWidthChange_', | 40 observer: 'onScrollbarWidthChange_', |
| 41 }, | 41 }, |
| 42 | 42 |
| 43 completelyOnDisk_: { | |
| 44 type: Boolean, | |
| 45 value: true, | |
| 46 computed: 'computeCompletelyOnDisk_(data_.state, data_.file_externally_r emoved)', | |
|
Dan Beam
2015/09/05 01:00:44
can these wrap?
| |
| 47 }, | |
| 48 | |
| 49 i18n_: { | |
| 50 type: Object, | |
| 51 value: function() { | |
| 52 return { | |
| 53 cancel: loadTimeData.getString('controlCancel'), | |
| 54 pause: loadTimeData.getString('controlPause'), | |
| 55 resume: loadTimeData.getString('controlResume'), | |
| 56 retry: loadTimeData.getString('controlRetry'), | |
| 57 showInFolder: loadTimeData.getString('controlShowInFolder'), | |
| 58 }; | |
| 59 }, | |
| 60 readOnly: true, | |
| 61 }, | |
| 62 | |
| 43 isDangerous_: { | 63 isDangerous_: { |
| 44 type: Boolean, | 64 type: Boolean, |
| 45 value: false, | 65 value: false, |
| 66 computed: 'computeIsDangerous_(data_.state)', | |
| 67 }, | |
| 68 | |
| 69 isInProgress_: { | |
| 70 type: Boolean, | |
| 71 value: false, | |
| 72 computed: 'computeIsInProgress_(data_.state)', | |
| 73 }, | |
| 74 | |
| 75 showCancel_: { | |
| 76 type: Boolean, | |
| 77 value: false, | |
| 78 computed: 'computeShowCancel_(isInProgress_, data_.state)', | |
| 79 }, | |
| 80 | |
| 81 showProgress_: { | |
| 82 type: Boolean, | |
| 83 value: false, | |
| 84 computed: 'computeShowProgress_(isDangerous_, data_.percent)', | |
| 46 }, | 85 }, |
| 47 | 86 |
| 48 /** Only set when |isDangerous| is true. */ | 87 /** Only set when |isDangerous| is true. */ |
| 49 isMalware_: Boolean, | 88 isMalware_: Boolean, |
| 50 | 89 |
| 51 // TODO(dbeam): move all properties to |data_|. | 90 // TODO(dbeam): move all properties to |data_|. |
| 52 data_: { | 91 data_: { |
| 53 type: Object, | 92 type: Object, |
| 54 value: function() { return {}; }, | 93 value: function() { return {}; }, |
| 55 }, | 94 }, |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 94 } | 133 } |
| 95 | 134 |
| 96 /** @const */ var isActive = | 135 /** @const */ var isActive = |
| 97 data.state != downloads.States.CANCELLED && | 136 data.state != downloads.States.CANCELLED && |
| 98 data.state != downloads.States.INTERRUPTED && | 137 data.state != downloads.States.INTERRUPTED && |
| 99 !data.file_externally_removed; | 138 !data.file_externally_removed; |
| 100 this.$.content.classList.toggle('is-active', isActive); | 139 this.$.content.classList.toggle('is-active', isActive); |
| 101 this.$.content.elevation = isActive ? 1 : 0; | 140 this.$.content.elevation = isActive ? 1 : 0; |
| 102 | 141 |
| 103 // Danger-dependent UI and controls. | 142 // Danger-dependent UI and controls. |
| 104 var dangerText = this.getDangerText_(data); | |
| 105 this.isDangerous_ = !!dangerText; | |
| 106 this.$.content.classList.toggle('dangerous', this.isDangerous_); | 143 this.$.content.classList.toggle('dangerous', this.isDangerous_); |
| 107 | 144 |
| 108 var description = dangerText || this.getStatusText_(data); | 145 var description = this.getDangerText_(data) || this.getStatusText_(data); |
| 109 | 146 |
| 110 // Status goes in the "tag" (next to the file name) if there's no file. | 147 // Status goes in the "tag" (next to the file name) if there's no file. |
| 111 this.ensureTextIs_(this.$.description, isActive ? description : ''); | 148 this.ensureTextIs_(this.$.description, isActive ? description : ''); |
| 112 this.ensureTextIs_(this.$.tag, isActive ? '' : description); | 149 this.ensureTextIs_(this.$.tag, isActive ? '' : description); |
| 113 | 150 |
| 114 /** @const */ var showProgress = | 151 this.$.content.classList.toggle('show-progress', this.showProgress_); |
| 115 isFinite(data.percent) && !this.isDangerous_; | |
| 116 this.$.content.classList.toggle('show-progress', showProgress); | |
| 117 | |
| 118 if (showProgress) { | |
| 119 this.$.progress.indeterminate = data.percent < 0; | |
| 120 this.$.progress.value = data.percent; | |
| 121 } | |
| 122 | 152 |
| 123 var hideRemove; | 153 var hideRemove; |
| 124 | 154 |
| 125 if (this.isDangerous_) { | 155 if (this.isDangerous_) { |
| 126 this.isMalware_ = | 156 this.isMalware_ = |
| 127 data.danger_type == downloads.DangerType.DANGEROUS_CONTENT || | 157 data.danger_type == downloads.DangerType.DANGEROUS_CONTENT || |
| 128 data.danger_type == downloads.DangerType.DANGEROUS_HOST || | 158 data.danger_type == downloads.DangerType.DANGEROUS_HOST || |
| 129 data.danger_type == downloads.DangerType.DANGEROUS_URL || | 159 data.danger_type == downloads.DangerType.DANGEROUS_URL || |
| 130 data.danger_type == downloads.DangerType.POTENTIALLY_UNWANTED; | 160 data.danger_type == downloads.DangerType.POTENTIALLY_UNWANTED; |
| 131 hideRemove = true; | 161 hideRemove = true; |
| 132 } else { | 162 } else { |
| 133 /** @const */ var completelyOnDisk = | |
| 134 data.state == downloads.States.COMPLETE && | |
| 135 !data.file_externally_removed; | |
| 136 | |
| 137 this.$['file-link'].href = data.url; | 163 this.$['file-link'].href = data.url; |
| 138 this.ensureTextIs_(this.$['file-link'], data.file_name); | 164 this.ensureTextIs_(this.$['file-link'], data.file_name); |
| 139 | 165 |
| 140 this.$['file-link'].hidden = !completelyOnDisk; | 166 this.$['file-link'].hidden = !this.completelyOnDisk_; |
| 141 this.$.name.hidden = completelyOnDisk; | 167 this.$.name.hidden = this.completelyOnDisk_; |
| 142 this.$.show.hidden = !completelyOnDisk; | |
| 143 | 168 |
| 144 this.$.retry.hidden = !data.retry; | 169 hideRemove = this.showCancel_ || |
| 145 | |
| 146 /** @const */ var isInProgress = | |
| 147 data.state == downloads.States.IN_PROGRESS; | |
| 148 this.$.pause.hidden = !isInProgress; | |
| 149 | |
| 150 this.$.resume.hidden = !data.resume; | |
| 151 | |
| 152 /** @const */ var isPaused = data.state == downloads.States.PAUSED; | |
| 153 /** @const */ var showCancel = isPaused || isInProgress; | |
| 154 this.$.cancel.hidden = !showCancel; | |
| 155 | |
| 156 hideRemove = showCancel || | |
| 157 !loadTimeData.getBoolean('allowDeletingHistory'); | 170 !loadTimeData.getBoolean('allowDeletingHistory'); |
| 158 | 171 |
| 159 /** @const */ var controlledByExtension = data.by_ext_id && | 172 /** @const */ var controlledByExtension = data.by_ext_id && |
| 160 data.by_ext_name; | 173 data.by_ext_name; |
| 161 this.$['controlled-by'].hidden = !controlledByExtension; | 174 this.$['controlled-by'].hidden = !controlledByExtension; |
| 162 if (controlledByExtension) { | 175 if (controlledByExtension) { |
| 163 var link = this.$['controlled-by'].querySelector('a'); | 176 var link = this.$['controlled-by'].querySelector('a'); |
| 164 link.href = 'chrome://extensions#' + data.by_ext_id; | 177 link.href = 'chrome://extensions#' + data.by_ext_id; |
| 165 link.textContent = data.by_ext_name; | 178 link.textContent = data.by_ext_name; |
| 166 } | 179 } |
| 167 | 180 |
| 168 var icon = 'chrome://fileicon/' + encodeURIComponent(data.file_path); | 181 var icon = 'chrome://fileicon/' + encodeURIComponent(data.file_path); |
| 169 this.iconLoader_.loadScaledIcon(this.$['file-icon'], icon); | 182 this.iconLoader_.loadScaledIcon(this.$['file-icon'], icon); |
| 170 } | 183 } |
| 171 | 184 |
| 172 this.$.remove.style.visibility = hideRemove ? 'hidden' : ''; | 185 this.$.remove.style.visibility = hideRemove ? 'hidden' : ''; |
|
Dan Beam
2015/09/05 01:00:44
^ everything here possible will be data binding
| |
| 173 }, | 186 }, |
| 174 | 187 |
| 188 computeCompletelyOnDisk_: function() { | |
| 189 return this.data_.state == downloads.States.COMPLETE && | |
| 190 !this.data_.file_externally_removed; | |
| 191 }, | |
| 192 | |
| 193 /** @private */ | |
| 194 computeDate_: function() { | |
| 195 assert(!this.hideDate); | |
| 196 return assert(this.data_.since_string || this.data_.date_string); | |
| 197 }, | |
| 198 | |
| 199 /** @private */ | |
| 200 computeIsInProgress_: function() { | |
| 201 return this.data_.state == downloads.States.IN_PROGRESS; | |
| 202 }, | |
| 203 | |
| 204 /** @private */ | |
| 205 computeIsDangerous_: function() { | |
| 206 return this.data_.state == downloads.States.DANGEROUS; | |
| 207 }, | |
| 208 | |
| 209 /** @private */ | |
| 210 computeShowCancel_: function() { | |
| 211 return this.isInProgress_ || this.data_.state == downloads.States.PAUSED; | |
| 212 }, | |
| 213 | |
| 214 /** @private */ | |
| 215 computeShowProgress_: function() { | |
| 216 return !this.isDangerous_ && isFinite(this.data_.percent); | |
| 217 }, | |
| 218 | |
| 175 /** | 219 /** |
| 176 * Overwrite |el|'s textContent if it differs from |text|. This is done | 220 * Overwrite |el|'s textContent if it differs from |text|. This is done |
| 177 * generally so quickly updating text can be copied via text selection. | 221 * generally so quickly updating text can be copied via text selection. |
| 178 * @param {!Element} el | 222 * @param {!Element} el |
| 179 * @param {string} text | 223 * @param {string} text |
| 180 * @private | 224 * @private |
| 181 */ | 225 */ |
| 182 ensureTextIs_: function(el, text) { | 226 ensureTextIs_: function(el, text) { |
| 183 if (el.textContent != text) | 227 if (el.textContent != text) |
| 184 el.textContent = text; | 228 el.textContent = text; |
| 185 }, | 229 }, |
| 186 | 230 |
| 187 /** @private */ | |
| 188 computeDate_: function() { | |
| 189 assert(!this.hideDate); | |
| 190 return assert(this.data_.since_string || this.data_.date_string); | |
| 191 }, | |
| 192 | |
| 193 /** | 231 /** |
| 194 * @param {!downloads.Data} data | 232 * @param {!downloads.Data} data |
| 195 * @return {string} Text describing the danger of a download. Empty if not | 233 * @return {string} Text describing the danger of a download. Empty if not |
| 196 * dangerous. | 234 * dangerous. |
| 197 */ | 235 */ |
| 198 getDangerText_: function(data) { | 236 getDangerText_: function(data) { |
| 199 switch (data.danger_type) { | 237 switch (data.danger_type) { |
| 200 case downloads.DangerType.DANGEROUS_FILE: | 238 case downloads.DangerType.DANGEROUS_FILE: |
| 201 return loadTimeData.getStringF('dangerFileDesc', data.file_name); | 239 return loadTimeData.getStringF('dangerFileDesc', data.file_name); |
| 202 case downloads.DangerType.DANGEROUS_URL: | 240 case downloads.DangerType.DANGEROUS_URL: |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 233 return data.last_reason_text; | 271 return data.last_reason_text; |
| 234 case downloads.States.COMPLETE: | 272 case downloads.States.COMPLETE: |
| 235 return data.file_externally_removed ? | 273 return data.file_externally_removed ? |
| 236 loadTimeData.getString('statusRemoved') : ''; | 274 loadTimeData.getString('statusRemoved') : ''; |
| 237 } | 275 } |
| 238 assertNotReached(); | 276 assertNotReached(); |
| 239 return ''; | 277 return ''; |
| 240 }, | 278 }, |
| 241 | 279 |
| 242 /** @private */ | 280 /** @private */ |
| 281 isIndeterminate_: function() { | |
| 282 assert(this.showProgress_); | |
| 283 return this.data_.percent == -1; | |
| 284 }, | |
| 285 | |
| 286 /** @private */ | |
| 243 onCancelClick_: function() { | 287 onCancelClick_: function() { |
| 244 this.actionService_.cancel(this.data_.id); | 288 this.actionService_.cancel(this.data_.id); |
| 245 }, | 289 }, |
| 246 | 290 |
| 247 /** | 291 /** |
| 248 * @private | 292 * @private |
| 249 * @param {Event} e | 293 * @param {Event} e |
| 250 */ | 294 */ |
| 251 onDragStart_: function(e) { | 295 onDragStart_: function(e) { |
| 252 e.preventDefault(); | 296 e.preventDefault(); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 301 var endCap = this.$['end-cap']; | 345 var endCap = this.$['end-cap']; |
| 302 endCap.style.flexBasis = ''; | 346 endCap.style.flexBasis = ''; |
| 303 | 347 |
| 304 if (this.scrollbarWidth) { | 348 if (this.scrollbarWidth) { |
| 305 var basis = parseInt(getComputedStyle(endCap).flexBasis, 10); | 349 var basis = parseInt(getComputedStyle(endCap).flexBasis, 10); |
| 306 endCap.style.flexBasis = basis - this.scrollbarWidth + 'px'; | 350 endCap.style.flexBasis = basis - this.scrollbarWidth + 'px'; |
| 307 } | 351 } |
| 308 }, | 352 }, |
| 309 | 353 |
| 310 /** @private */ | 354 /** @private */ |
| 311 onShowClick_: function() { | 355 onShowInFolderClick_: function() { |
| 312 this.actionService_.show(this.data_.id); | 356 this.actionService_.showInFolder(this.data_.id); |
| 313 }, | 357 }, |
| 314 }); | 358 }); |
| 315 | 359 |
| 316 return {Item: Item}; | 360 return {Item: Item}; |
| 317 }); | 361 }); |
| OLD | NEW |