| 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 /** | |
| 10 * @param {!downloads.ThrottledIconLoader} iconLoader | |
| 11 */ | |
| 12 factoryImpl: function(iconLoader) { | |
| 13 /** @private {!downloads.ThrottledIconLoader} */ | |
| 14 this.iconLoader_ = iconLoader; | |
| 15 }, | |
| 16 | |
| 17 properties: { | 9 properties: { |
| 18 data: { | 10 data: { |
| 19 type: Object, | 11 type: Object, |
| 20 }, | 12 }, |
| 21 | 13 |
| 22 hideDate: { | 14 hideDate: { |
| 23 type: Boolean, | 15 type: Boolean, |
| 24 value: true, | 16 value: true, |
| 25 }, | 17 }, |
| 26 | 18 |
| 27 readyPromise: { | |
| 28 type: Object, | |
| 29 value: function() { | |
| 30 return new Promise(function(resolve, reject) { | |
| 31 this.resolveReadyPromise_ = resolve; | |
| 32 }.bind(this)); | |
| 33 }, | |
| 34 }, | |
| 35 | |
| 36 completelyOnDisk_: { | 19 completelyOnDisk_: { |
| 37 computed: 'computeCompletelyOnDisk_(' + | 20 computed: 'computeCompletelyOnDisk_(' + |
| 38 'data.state, data.file_externally_removed)', | 21 'data.state, data.file_externally_removed)', |
| 39 type: Boolean, | 22 type: Boolean, |
| 40 value: true, | 23 value: true, |
| 41 }, | 24 }, |
| 42 | 25 |
| 43 controlledBy_: { | 26 controlledBy_: { |
| 44 computed: 'computeControlledBy_(data.by_ext_id, data.by_ext_name)', | 27 computed: 'computeControlledBy_(data.by_ext_id, data.by_ext_name)', |
| 45 type: String, | 28 type: String, |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 computed: 'computeIsMalware_(isDangerous_, data.danger_type)', | 81 computed: 'computeIsMalware_(isDangerous_, data.danger_type)', |
| 99 type: Boolean, | 82 type: Boolean, |
| 100 value: false, | 83 value: false, |
| 101 }, | 84 }, |
| 102 }, | 85 }, |
| 103 | 86 |
| 104 observers: [ | 87 observers: [ |
| 105 // TODO(dbeam): this gets called way more when I observe data.by_ext_id | 88 // TODO(dbeam): this gets called way more when I observe data.by_ext_id |
| 106 // and data.by_ext_name directly. Why? | 89 // and data.by_ext_name directly. Why? |
| 107 'observeControlledBy_(controlledBy_)', | 90 'observeControlledBy_(controlledBy_)', |
| 91 'observeIsDangerous_(isDangerous_, data.file_path)', |
| 108 ], | 92 ], |
| 109 | 93 |
| 110 ready: function() { | 94 ready: function() { |
| 111 this.content = this.$.content; | 95 this.content = this.$.content; |
| 112 this.resolveReadyPromise_(); | |
| 113 }, | |
| 114 | |
| 115 /** @param {!downloads.Data} data */ | |
| 116 update: function(data) { | |
| 117 this.data = data; | |
| 118 | |
| 119 if (!this.isDangerous_) { | |
| 120 var icon = 'chrome://fileicon/' + encodeURIComponent(data.file_path); | |
| 121 this.iconLoader_.loadScaledIcon(this.$['file-icon'], icon); | |
| 122 } | |
| 123 }, | 96 }, |
| 124 | 97 |
| 125 /** @private */ | 98 /** @private */ |
| 126 computeClass_: function() { | 99 computeClass_: function() { |
| 127 var classes = []; | 100 var classes = []; |
| 128 | 101 |
| 129 if (this.isActive_) | 102 if (this.isActive_) |
| 130 classes.push('is-active'); | 103 classes.push('is-active'); |
| 131 | 104 |
| 132 if (this.isDangerous_) | 105 if (this.isDangerous_) |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 isIndeterminate_: function() { | 246 isIndeterminate_: function() { |
| 274 return this.data.percent == -1; | 247 return this.data.percent == -1; |
| 275 }, | 248 }, |
| 276 | 249 |
| 277 /** @private */ | 250 /** @private */ |
| 278 observeControlledBy_: function() { | 251 observeControlledBy_: function() { |
| 279 this.$['controlled-by'].innerHTML = this.controlledBy_; | 252 this.$['controlled-by'].innerHTML = this.controlledBy_; |
| 280 }, | 253 }, |
| 281 | 254 |
| 282 /** @private */ | 255 /** @private */ |
| 256 observeIsDangerous_: function() { |
| 257 if (this.data && !this.isDangerous_) { |
| 258 var filePath = encodeURIComponent(this.data.file_path); |
| 259 this.$['file-icon'].src = 'chrome://fileicon/' + filePath; |
| 260 } |
| 261 }, |
| 262 |
| 263 /** @private */ |
| 283 onCancelTap_: function() { | 264 onCancelTap_: function() { |
| 284 downloads.ActionService.getInstance().cancel(this.data.id); | 265 downloads.ActionService.getInstance().cancel(this.data.id); |
| 285 }, | 266 }, |
| 286 | 267 |
| 287 /** @private */ | 268 /** @private */ |
| 288 onDiscardDangerousTap_: function() { | 269 onDiscardDangerousTap_: function() { |
| 289 downloads.ActionService.getInstance().discardDangerous(this.data.id); | 270 downloads.ActionService.getInstance().discardDangerous(this.data.id); |
| 290 }, | 271 }, |
| 291 | 272 |
| 292 /** | 273 /** |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 }, | 314 }, |
| 334 | 315 |
| 335 /** @private */ | 316 /** @private */ |
| 336 onShowTap_: function() { | 317 onShowTap_: function() { |
| 337 downloads.ActionService.getInstance().show(this.data.id); | 318 downloads.ActionService.getInstance().show(this.data.id); |
| 338 }, | 319 }, |
| 339 }); | 320 }); |
| 340 | 321 |
| 341 return {Item: Item}; | 322 return {Item: Item}; |
| 342 }); | 323 }); |
| OLD | NEW |