| 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 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 this.$.content.classList.toggle('dangerous', this.isDangerous_); | 151 this.$.content.classList.toggle('dangerous', this.isDangerous_); |
| 152 | 152 |
| 153 var description = this.getDangerText_(data) || this.getStatusText_(data); | 153 var description = this.getDangerText_(data) || this.getStatusText_(data); |
| 154 | 154 |
| 155 // Status goes in the "tag" (next to the file name) if there's no file. | 155 // Status goes in the "tag" (next to the file name) if there's no file. |
| 156 this.ensureTextIs_(this.$.description, isActive ? description : ''); | 156 this.ensureTextIs_(this.$.description, isActive ? description : ''); |
| 157 this.ensureTextIs_(this.$.tag, isActive ? '' : description); | 157 this.ensureTextIs_(this.$.tag, isActive ? '' : description); |
| 158 | 158 |
| 159 this.$.content.classList.toggle('show-progress', this.showProgress_); | 159 this.$.content.classList.toggle('show-progress', this.showProgress_); |
| 160 | 160 |
| 161 var hideRemove; | 161 if (!this.isDangerous_) { |
| 162 | |
| 163 if (this.isDangerous_) { | |
| 164 hideRemove = true; | |
| 165 } else { | |
| 166 this.$['file-link'].href = data.url; | 162 this.$['file-link'].href = data.url; |
| 167 this.ensureTextIs_(this.$['file-link'], data.file_name); | 163 this.ensureTextIs_(this.$['file-link'], data.file_name); |
| 168 | 164 |
| 169 this.$['file-link'].hidden = !this.completelyOnDisk_; | 165 this.$['file-link'].hidden = !this.completelyOnDisk_; |
| 170 this.$.name.hidden = this.completelyOnDisk_; | 166 this.$.name.hidden = this.completelyOnDisk_; |
| 171 | 167 |
| 172 hideRemove = this.showCancel_ || | |
| 173 !loadTimeData.getBoolean('allowDeletingHistory'); | |
| 174 | |
| 175 /** @const */ var controlledByExtension = data.by_ext_id && | 168 /** @const */ var controlledByExtension = data.by_ext_id && |
| 176 data.by_ext_name; | 169 data.by_ext_name; |
| 177 this.$['controlled-by'].hidden = !controlledByExtension; | 170 this.$['controlled-by'].hidden = !controlledByExtension; |
| 178 if (controlledByExtension) { | 171 if (controlledByExtension) { |
| 179 var link = this.$['controlled-by'].querySelector('a'); | 172 var link = this.$['controlled-by'].querySelector('a'); |
| 180 link.href = 'chrome://extensions#' + data.by_ext_id; | 173 link.href = 'chrome://extensions#' + data.by_ext_id; |
| 181 link.textContent = data.by_ext_name; | 174 link.textContent = data.by_ext_name; |
| 182 } | 175 } |
| 183 | 176 |
| 184 var icon = 'chrome://fileicon/' + encodeURIComponent(data.file_path); | 177 var icon = 'chrome://fileicon/' + encodeURIComponent(data.file_path); |
| 185 this.iconLoader_.loadScaledIcon(this.$['file-icon'], icon); | 178 this.iconLoader_.loadScaledIcon(this.$['file-icon'], icon); |
| 186 } | 179 } |
| 187 | |
| 188 this.$.remove.style.visibility = hideRemove ? 'hidden' : ''; | |
| 189 }, | 180 }, |
| 190 | 181 |
| 191 /** @private */ | 182 /** @private */ |
| 192 computeCompletelyOnDisk_: function() { | 183 computeCompletelyOnDisk_: function() { |
| 193 return this.data_.state == downloads.States.COMPLETE && | 184 return this.data_.state == downloads.States.COMPLETE && |
| 194 !this.data_.file_externally_removed; | 185 !this.data_.file_externally_removed; |
| 195 }, | 186 }, |
| 196 | 187 |
| 197 /** @private */ | 188 /** @private */ |
| 198 computeDate_: function() { | 189 computeDate_: function() { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 213 this.data_.danger_type == downloads.DangerType.DANGEROUS_URL || | 204 this.data_.danger_type == downloads.DangerType.DANGEROUS_URL || |
| 214 this.data_.danger_type == downloads.DangerType.POTENTIALLY_UNWANTED); | 205 this.data_.danger_type == downloads.DangerType.POTENTIALLY_UNWANTED); |
| 215 }, | 206 }, |
| 216 | 207 |
| 217 /** @private */ | 208 /** @private */ |
| 218 computeIsDangerous_: function() { | 209 computeIsDangerous_: function() { |
| 219 return this.data_.state == downloads.States.DANGEROUS; | 210 return this.data_.state == downloads.States.DANGEROUS; |
| 220 }, | 211 }, |
| 221 | 212 |
| 222 /** @private */ | 213 /** @private */ |
| 214 computeRemoveStyle_: function() { |
| 215 var canDelete = loadTimeData.getBoolean('allowDeletingHistory'); |
| 216 var hideRemove = this.isDangerous_ || this.showCancel_ || !canDelete; |
| 217 return hideRemove ? 'visibility: hidden' : ''; |
| 218 }, |
| 219 |
| 220 /** @private */ |
| 223 computeShowCancel_: function() { | 221 computeShowCancel_: function() { |
| 224 return this.data_.state == downloads.States.IN_PROGRESS || | 222 return this.data_.state == downloads.States.IN_PROGRESS || |
| 225 this.data_.state == downloads.States.PAUSED; | 223 this.data_.state == downloads.States.PAUSED; |
| 226 }, | 224 }, |
| 227 | 225 |
| 228 /** @private */ | 226 /** @private */ |
| 229 computeShowProgress_: function() { | 227 computeShowProgress_: function() { |
| 230 return this.showCancel_ && isFinite(this.data_.percent); | 228 return this.showCancel_ && isFinite(this.data_.percent); |
| 231 }, | 229 }, |
| 232 | 230 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 isIndeterminate_: function() { | 293 isIndeterminate_: function() { |
| 296 assert(this.showProgress_); | 294 assert(this.showProgress_); |
| 297 return this.data_.percent == -1; | 295 return this.data_.percent == -1; |
| 298 }, | 296 }, |
| 299 | 297 |
| 300 /** @private */ | 298 /** @private */ |
| 301 onCancelClick_: function() { | 299 onCancelClick_: function() { |
| 302 this.actionService_.cancel(this.data_.id); | 300 this.actionService_.cancel(this.data_.id); |
| 303 }, | 301 }, |
| 304 | 302 |
| 303 /** @private */ |
| 304 onDiscardDangerous_: function() { |
| 305 this.actionService_.discardDangerous(this.data_.id); |
| 306 }, |
| 307 |
| 305 /** | 308 /** |
| 306 * @private | 309 * @private |
| 307 * @param {Event} e | 310 * @param {Event} e |
| 308 */ | 311 */ |
| 309 onDragStart_: function(e) { | 312 onDragStart_: function(e) { |
| 310 e.preventDefault(); | 313 e.preventDefault(); |
| 311 this.actionService_.drag(this.data_.id); | 314 this.actionService_.drag(this.data_.id); |
| 312 }, | 315 }, |
| 313 | 316 |
| 314 /** | 317 /** |
| 315 * @param {Event} e | 318 * @param {Event} e |
| 316 * @private | 319 * @private |
| 317 */ | 320 */ |
| 318 onFileLinkClick_: function(e) { | 321 onFileLinkClick_: function(e) { |
| 319 e.preventDefault(); | 322 e.preventDefault(); |
| 320 this.actionService_.openFile(this.data_.id); | 323 this.actionService_.openFile(this.data_.id); |
| 321 }, | 324 }, |
| 322 | 325 |
| 323 /** @private */ | 326 /** @private */ |
| 324 onPauseClick_: function() { | 327 onPauseClick_: function() { |
| 325 this.actionService_.pause(this.data_.id); | 328 this.actionService_.pause(this.data_.id); |
| 326 }, | 329 }, |
| 327 | 330 |
| 328 /** @private */ | 331 /** @private */ |
| 329 onRemoveClick_: function() { | 332 onRemoveClick_: function() { |
| 330 assert(!this.$.remove.disabled); | |
| 331 this.actionService_.remove(this.data_.id); | 333 this.actionService_.remove(this.data_.id); |
| 332 }, | 334 }, |
| 333 | 335 |
| 334 /** @private */ | 336 /** @private */ |
| 335 onSaveDangerous_: function() { | |
| 336 this.actionService_.saveDangerous(this.data_.id); | |
| 337 }, | |
| 338 | |
| 339 /** @private */ | |
| 340 onDiscardDangerous_: function() { | |
| 341 this.actionService_.discardDangerous(this.data_.id); | |
| 342 }, | |
| 343 | |
| 344 /** @private */ | |
| 345 onResumeClick_: function() { | 337 onResumeClick_: function() { |
| 346 this.actionService_.resume(this.data_.id); | 338 this.actionService_.resume(this.data_.id); |
| 347 }, | 339 }, |
| 348 | 340 |
| 349 /** @private */ | 341 /** @private */ |
| 350 onRetryClick_: function() { | 342 onRetryClick_: function() { |
| 351 this.actionService_.download(this.$['file-link'].href); | 343 this.actionService_.download(this.$['file-link'].href); |
| 352 }, | 344 }, |
| 353 | 345 |
| 354 /** @private */ | 346 /** @private */ |
| 347 onSaveDangerous_: function() { |
| 348 this.actionService_.saveDangerous(this.data_.id); |
| 349 }, |
| 350 |
| 351 /** @private */ |
| 355 onScrollbarWidthChange_: function() { | 352 onScrollbarWidthChange_: function() { |
| 356 if (!this.$) | 353 if (!this.$) |
| 357 return; | 354 return; |
| 358 | 355 |
| 359 var endCap = this.$['end-cap']; | 356 var endCap = this.$['end-cap']; |
| 360 endCap.style.flexBasis = ''; | 357 endCap.style.flexBasis = ''; |
| 361 | 358 |
| 362 if (this.scrollbarWidth) { | 359 if (this.scrollbarWidth) { |
| 363 var basis = parseInt(getComputedStyle(endCap).flexBasis, 10); | 360 var basis = parseInt(getComputedStyle(endCap).flexBasis, 10); |
| 364 endCap.style.flexBasis = basis - this.scrollbarWidth + 'px'; | 361 endCap.style.flexBasis = basis - this.scrollbarWidth + 'px'; |
| 365 } | 362 } |
| 366 }, | 363 }, |
| 367 | 364 |
| 368 /** @private */ | 365 /** @private */ |
| 369 onShowClick_: function() { | 366 onShowClick_: function() { |
| 370 this.actionService_.show(this.data_.id); | 367 this.actionService_.show(this.data_.id); |
| 371 }, | 368 }, |
| 372 }); | 369 }); |
| 373 | 370 |
| 374 return {Item: Item}; | 371 return {Item: Item}; |
| 375 }); | 372 }); |
| OLD | NEW |