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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 58 remove: loadTimeData.getString('controlRemoveFromList'), | 58 remove: loadTimeData.getString('controlRemoveFromList'), |
| 59 resume: loadTimeData.getString('controlResume'), | 59 resume: loadTimeData.getString('controlResume'), |
| 60 restore: loadTimeData.getString('dangerRestore'), | 60 restore: loadTimeData.getString('dangerRestore'), |
| 61 retry: loadTimeData.getString('controlRetry'), | 61 retry: loadTimeData.getString('controlRetry'), |
| 62 save: loadTimeData.getString('dangerSave'), | 62 save: loadTimeData.getString('dangerSave'), |
| 63 show: loadTimeData.getString('controlShowInFolder'), | 63 show: loadTimeData.getString('controlShowInFolder'), |
| 64 }; | 64 }; |
| 65 }, | 65 }, |
| 66 }, | 66 }, |
| 67 | 67 |
| 68 isActive_: { | |
| 69 computed: 'computeIsActive_(' + | |
| 70 'data_.state, data_.file_externally_removed)', | |
| 71 type: Boolean, | |
| 72 value: true, | |
| 73 }, | |
| 74 | |
| 68 isDangerous_: { | 75 isDangerous_: { |
| 69 computed: 'computeIsDangerous_(data_.state)', | 76 computed: 'computeIsDangerous_(data_.state)', |
| 70 type: Boolean, | 77 type: Boolean, |
| 71 value: false, | 78 value: false, |
| 72 }, | 79 }, |
| 73 | 80 |
| 74 isInProgress_: { | 81 isInProgress_: { |
| 75 computed: 'computeIsInProgress_(data_.state)', | 82 computed: 'computeIsInProgress_(data_.state)', |
| 76 type: Boolean, | 83 type: Boolean, |
| 77 value: false, | 84 value: false, |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 133 data.total == this.data_.total && | 140 data.total == this.data_.total && |
| 134 data.url == this.data_.url) { | 141 data.url == this.data_.url) { |
| 135 // TODO(dbeam): remove this once data binding is fully in place. | 142 // TODO(dbeam): remove this once data binding is fully in place. |
| 136 return; | 143 return; |
| 137 } | 144 } |
| 138 | 145 |
| 139 for (var key in data) { | 146 for (var key in data) { |
| 140 this.set('data_.' + key, data[key]); | 147 this.set('data_.' + key, data[key]); |
| 141 } | 148 } |
| 142 | 149 |
| 143 /** @const */ var isActive = | 150 // TODO(dbeam): Move to a computeClass_() method + data binding. |
| 144 data.state != downloads.States.CANCELLED && | 151 this.$.content.classList.toggle('is-active', this.isActive_); |
| 145 data.state != downloads.States.INTERRUPTED && | 152 this.$.content.classList.toggle('dangerous', this.isDangerous_); |
| 146 !data.file_externally_removed; | 153 this.$.content.classList.toggle('show-progress', this.showProgress_); |
| 147 this.$.content.classList.toggle('is-active', isActive); | |
| 148 this.$.content.elevation = isActive ? 1 : 0; | |
| 149 | 154 |
| 150 // Danger-dependent UI and controls. | 155 var desc = this.getDangerText_(data) || this.getStatusText_(data); |
| 151 this.$.content.classList.toggle('dangerous', this.isDangerous_); | |
| 152 | |
| 153 var description = this.getDangerText_(data) || this.getStatusText_(data); | |
| 154 | 156 |
| 155 // Status goes in the "tag" (next to the file name) if there's no file. | 157 // Status goes in the "tag" (next to the file name) if there's no file. |
| 156 this.ensureTextIs_(this.$.description, isActive ? description : ''); | 158 this.ensureTextIs_(this.$.description, this.isActive_ ? desc : ''); |
| 157 this.ensureTextIs_(this.$.tag, isActive ? '' : description); | 159 this.ensureTextIs_(this.$.tag, this.isActive_ ? '' : desc); |
| 158 | |
| 159 this.$.content.classList.toggle('show-progress', this.showProgress_); | |
| 160 | 160 |
| 161 if (!this.isDangerous_) { | 161 if (!this.isDangerous_) { |
| 162 this.$['file-link'].href = data.url; | |
| 163 this.ensureTextIs_(this.$['file-link'], data.file_name); | |
| 164 | |
| 165 this.$['file-link'].hidden = !this.completelyOnDisk_; | |
| 166 this.$.name.hidden = this.completelyOnDisk_; | |
| 167 | |
| 168 /** @const */ var controlledByExtension = data.by_ext_id && | 162 /** @const */ var controlledByExtension = data.by_ext_id && |
| 169 data.by_ext_name; | 163 data.by_ext_name; |
| 170 this.$['controlled-by'].hidden = !controlledByExtension; | 164 this.$['controlled-by'].hidden = !controlledByExtension; |
| 171 if (controlledByExtension) { | 165 if (controlledByExtension) { |
| 172 var link = this.$['controlled-by'].querySelector('a'); | 166 var link = this.$['controlled-by'].querySelector('a'); |
| 173 link.href = 'chrome://extensions#' + data.by_ext_id; | 167 link.href = 'chrome://extensions#' + data.by_ext_id; |
| 174 link.textContent = data.by_ext_name; | 168 link.textContent = data.by_ext_name; |
| 175 } | 169 } |
| 176 | 170 |
| 177 var icon = 'chrome://fileicon/' + encodeURIComponent(data.file_path); | 171 var icon = 'chrome://fileicon/' + encodeURIComponent(data.file_path); |
| 178 this.iconLoader_.loadScaledIcon(this.$['file-icon'], icon); | 172 this.iconLoader_.loadScaledIcon(this.$['file-icon'], icon); |
| 179 } | 173 } |
| 180 }, | 174 }, |
| 181 | 175 |
| 182 /** @private */ | 176 /** @private */ |
| 183 computeCompletelyOnDisk_: function() { | 177 computeCompletelyOnDisk_: function() { |
| 184 return this.data_.state == downloads.States.COMPLETE && | 178 return this.data_.state == downloads.States.COMPLETE && |
| 185 !this.data_.file_externally_removed; | 179 !this.data_.file_externally_removed; |
| 186 }, | 180 }, |
| 187 | 181 |
| 188 /** @private */ | 182 /** @private */ |
| 189 computeDate_: function() { | 183 computeDate_: function() { |
| 190 assert(!this.hideDate); | 184 assert(!this.hideDate); |
| 191 return assert(this.data_.since_string || this.data_.date_string); | 185 return assert(this.data_.since_string || this.data_.date_string); |
| 192 }, | 186 }, |
| 193 | 187 |
| 194 /** @private */ | 188 /** @private */ |
| 189 computeElevation_: function() { | |
|
tommycli
2015/09/09 20:49:16
I still feel uneasy about this.
But I talked to m
Dan Beam
2015/09/09 21:00:15
Acknowledged.
| |
| 190 return this.isActive_ ? 1 : 0; | |
| 191 }, | |
| 192 | |
| 193 /** @private */ | |
| 194 computeIsActive_: function() { | |
| 195 return this.data_.state != downloads.States.CANCELLED && | |
| 196 this.data_.state != downloads.States.INTERRUPTED && | |
| 197 !this.data_.file_externally_removed; | |
| 198 }, | |
| 199 | |
| 200 /** @private */ | |
| 195 computeIsInProgress_: function() { | 201 computeIsInProgress_: function() { |
| 196 return this.data_.state == downloads.States.IN_PROGRESS; | 202 return this.data_.state == downloads.States.IN_PROGRESS; |
| 197 }, | 203 }, |
| 198 | 204 |
| 199 /** @private */ | 205 /** @private */ |
| 200 computeIsMalware_: function() { | 206 computeIsMalware_: function() { |
| 201 return this.isDangerous_ && | 207 return this.isDangerous_ && |
| 202 (this.data_.danger_type == downloads.DangerType.DANGEROUS_CONTENT || | 208 (this.data_.danger_type == downloads.DangerType.DANGEROUS_CONTENT || |
| 203 this.data_.danger_type == downloads.DangerType.DANGEROUS_HOST || | 209 this.data_.danger_type == downloads.DangerType.DANGEROUS_HOST || |
| 204 this.data_.danger_type == downloads.DangerType.DANGEROUS_URL || | 210 this.data_.danger_type == downloads.DangerType.DANGEROUS_URL || |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 363 }, | 369 }, |
| 364 | 370 |
| 365 /** @private */ | 371 /** @private */ |
| 366 onShowClick_: function() { | 372 onShowClick_: function() { |
| 367 this.actionService_.show(this.data_.id); | 373 this.actionService_.show(this.data_.id); |
| 368 }, | 374 }, |
| 369 }); | 375 }); |
| 370 | 376 |
| 371 return {Item: Item}; | 377 return {Item: Item}; |
| 372 }); | 378 }); |
| OLD | NEW |