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 /** @const */ var Item = downloads.Item; | 6 /** @const */ var Item = downloads.Item; |
| 7 | 7 |
| 8 /** | 8 /** |
| 9 * Creates and updates the DOM representation for a download. | 9 * Creates and updates the DOM representation for a download. |
| 10 * @constructor | 10 * @constructor |
| 11 */ | 11 */ |
| 12 function ItemView() { | 12 function ItemView() { |
| 13 this.node = $('templates').querySelector('.download').cloneNode(true); | 13 this.node = $('templates').querySelector('.download').cloneNode(true); |
| 14 | 14 |
| 15 this.safe_ = this.queryRequired_('.safe'); | 15 this.safe_ = this.queryRequired_('.safe'); |
| 16 this.since_ = this.queryRequired_('.since'); | 16 this.since_ = this.queryRequired_('.since'); |
| 17 this.dateContainer = this.queryRequired_('.date-container'); | 17 this.dateContainer = this.queryRequired_('.date-container'); |
| 18 this.date_ = this.queryRequired_('.date'); | 18 this.date_ = this.queryRequired_('.date'); |
| 19 this.save_ = this.queryRequired_('.save'); | 19 this.save_ = this.queryRequired_('.save'); |
| 20 this.backgroundProgress_ = this.queryRequired_('.progress.background'); | 20 this.backgroundProgress_ = this.queryRequired_('.progress.background'); |
| 21 this.foregroundProgress_ = /** @type !HTMLCanvasElement */( | 21 this.foregroundProgress_ = /** @type !HTMLCanvasElement */( |
| 22 this.queryRequired_('canvas.progress')); | 22 this.queryRequired_('canvas.progress')); |
| 23 this.safeImg_ = /** @type !HTMLImageElement */( | 23 this.safeImg_ = /** @type !HTMLImageElement */( |
| 24 this.queryRequired_('.safe img')); | 24 this.queryRequired_('.safe img')); |
| 25 this.fileName_ = this.queryRequired_('span.name'); | 25 this.fileName_ = this.queryRequired_('span.name'); |
| 26 this.fileLink = this.queryRequired_('[is="action-link"].name'); | 26 this.fileLink_ = this.queryRequired_('[is="action-link"].name'); |
| 27 this.status_ = this.queryRequired_('.status'); | 27 this.status_ = this.queryRequired_('.status'); |
| 28 this.srcUrl = this.queryRequired_('.src-url'); | 28 this.srcUrl_ = this.queryRequired_('.src-url'); |
| 29 this.show = this.queryRequired_('.show'); | 29 this.show_ = this.queryRequired_('.show'); |
| 30 this.retry = this.queryRequired_('.retry'); | 30 this.retry_ = this.queryRequired_('.retry'); |
| 31 this.pause = this.queryRequired_('.pause'); | 31 this.pause_ = this.queryRequired_('.pause'); |
| 32 this.resume = this.queryRequired_('.resume'); | 32 this.resume_ = this.queryRequired_('.resume'); |
| 33 this.safeRemove = this.queryRequired_('.safe .remove'); | 33 this.safeRemove_ = this.queryRequired_('.safe .remove'); |
| 34 this.cancel = this.queryRequired_('.cancel'); | 34 this.cancel_ = this.queryRequired_('.cancel'); |
| 35 this.controlledBy = this.queryRequired_('.controlled-by'); | 35 this.controlledBy_ = this.queryRequired_('.controlled-by'); |
| 36 | 36 |
| 37 this.dangerous_ = this.queryRequired_('.dangerous'); | 37 this.dangerous_ = this.queryRequired_('.dangerous'); |
| 38 this.dangerImg_ = /** @type {!HTMLImageElement} */( | 38 this.dangerImg_ = /** @type {!HTMLImageElement} */( |
| 39 this.queryRequired_('.dangerous img')); | 39 this.queryRequired_('.dangerous img')); |
| 40 this.description_ = this.queryRequired_('.description'); | 40 this.description_ = this.queryRequired_('.description'); |
| 41 this.malwareControls_ = this.queryRequired_('.dangerous .controls'); | 41 this.malwareControls_ = this.queryRequired_('.dangerous .controls'); |
| 42 this.restore = this.queryRequired_('.restore'); | 42 this.restore_ = this.queryRequired_('.restore'); |
| 43 this.dangerRemove = this.queryRequired_('.dangerous .remove'); | 43 this.dangerRemove_ = this.queryRequired_('.dangerous .remove'); |
| 44 this.save = this.queryRequired_('.save'); | 44 this.save_ = this.queryRequired_('.save'); |
| 45 this.discard = this.queryRequired_('.discard'); | 45 this.discard_ = this.queryRequired_('.discard'); |
| 46 | 46 |
| 47 // Event handlers (bound once on creation). | 47 // Event handlers (bound once on creation). |
| 48 this.safe_.ondragstart = this.onSafeDragstart_.bind(this); | 48 this.safe_.ondragstart = this.onSafeDragstart_.bind(this); |
| 49 this.fileLink.onclick = this.onFileLinkClick_.bind(this); | 49 this.fileLink_.onclick = this.onFileLinkClick_.bind(this); |
| 50 this.show.onclick = this.onShowClick_.bind(this); | 50 this.show_.onclick = this.onShowClick_.bind(this); |
| 51 this.pause.onclick = this.onPauseClick_.bind(this); | 51 this.pause_.onclick = this.onPauseClick_.bind(this); |
| 52 this.resume.onclick = this.onResumeClick_.bind(this); | 52 this.resume_.onclick = this.onResumeClick_.bind(this); |
| 53 this.safeRemove.onclick = this.onSafeRemoveClick_.bind(this); | 53 this.safeRemove_.onclick = this.onSafeRemoveClick_.bind(this); |
| 54 this.cancel.onclick = this.onCancelClick_.bind(this); | 54 this.cancel_.onclick = this.onCancelClick_.bind(this); |
| 55 this.restore.onclick = this.onRestoreClick_.bind(this); | 55 this.restore_.onclick = this.onRestoreClick_.bind(this); |
| 56 this.save.onclick = this.onSaveClick_.bind(this); | 56 this.save_.onclick = this.onSaveClick_.bind(this); |
| 57 this.dangerRemove.onclick = this.onDangerRemoveClick_.bind(this); | 57 this.dangerRemove_.onclick = this.onDangerRemoveClick_.bind(this); |
| 58 this.discard.onclick = this.onDiscardClick_.bind(this); | 58 this.discard_.onclick = this.onDiscardClick_.bind(this); |
| 59 } | 59 } |
| 60 | 60 |
| 61 /** Progress meter constants. */ | 61 /** Progress meter constants. */ |
| 62 ItemView.Progress = { | 62 ItemView.Progress = { |
| 63 /** @const {number} */ | 63 /** @const {number} */ |
| 64 START_ANGLE: -0.5 * Math.PI, | 64 START_ANGLE: -0.5 * Math.PI, |
| 65 /** @const {number} */ | 65 /** @const {number} */ |
| 66 SIDE: 48, | 66 SIDE: 48, |
| 67 }; | 67 }; |
| 68 | 68 |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 179 var idr = dangerousFile ? 'IDR_WARNING' : 'IDR_SAFEBROWSING_WARNING'; | 179 var idr = dangerousFile ? 'IDR_WARNING' : 'IDR_SAFEBROWSING_WARNING'; |
| 180 ItemView.loadScaledIcon(this.dangerImg_, 'chrome://theme/' + idr); | 180 ItemView.loadScaledIcon(this.dangerImg_, 'chrome://theme/' + idr); |
| 181 | 181 |
| 182 var showMalwareControls = | 182 var showMalwareControls = |
| 183 data.danger_type == Item.DangerType.DANGEROUS_CONTENT || | 183 data.danger_type == Item.DangerType.DANGEROUS_CONTENT || |
| 184 data.danger_type == Item.DangerType.DANGEROUS_HOST || | 184 data.danger_type == Item.DangerType.DANGEROUS_HOST || |
| 185 data.danger_type == Item.DangerType.DANGEROUS_URL || | 185 data.danger_type == Item.DangerType.DANGEROUS_URL || |
| 186 data.danger_type == Item.DangerType.POTENTIALLY_UNWANTED; | 186 data.danger_type == Item.DangerType.POTENTIALLY_UNWANTED; |
| 187 | 187 |
| 188 this.malwareControls_.hidden = !showMalwareControls; | 188 this.malwareControls_.hidden = !showMalwareControls; |
| 189 this.discard.hidden = showMalwareControls; | 189 this.discard_.hidden = showMalwareControls; |
| 190 this.save.hidden = showMalwareControls; | 190 this.save_.hidden = showMalwareControls; |
| 191 } else { | 191 } else { |
| 192 var path = encodeURIComponent(data.file_path); | 192 var path = encodeURIComponent(data.file_path); |
| 193 ItemView.loadScaledIcon(this.safeImg_, 'chrome://fileicon/' + path); | 193 ItemView.loadScaledIcon(this.safeImg_, 'chrome://fileicon/' + path); |
| 194 | 194 |
| 195 /** @const */ var isInProgress = data.state == Item.States.IN_PROGRESS; | 195 /** @const */ var isInProgress = data.state == Item.States.IN_PROGRESS; |
| 196 this.node.classList.toggle('in-progress', isInProgress); | 196 this.node.classList.toggle('in-progress', isInProgress); |
| 197 | 197 |
| 198 /** @const */ var completelyOnDisk = | 198 /** @const */ var completelyOnDisk = |
| 199 data.state == Item.States.COMPLETE && !data.file_externally_removed; | 199 data.state == Item.States.COMPLETE && !data.file_externally_removed; |
| 200 | 200 |
| 201 this.fileLink.href = data.url; | 201 this.fileLink_.href = data.url; |
| 202 this.ensureTextIs_(this.fileLink, data.file_name); | 202 this.ensureTextIs_(this.fileLink_, data.file_name); |
| 203 this.fileLink.hidden = !completelyOnDisk; | 203 this.fileLink_.hidden = !completelyOnDisk; |
| 204 | 204 |
| 205 /** @const */ var isInterrupted = data.state == Item.States.INTERRUPTED; | 205 /** @const */ var isInterrupted = data.state == Item.States.INTERRUPTED; |
| 206 this.fileName_.classList.toggle('interrupted', isInterrupted); | 206 this.fileName_.classList.toggle('interrupted', isInterrupted); |
| 207 this.ensureTextIs_(this.fileName_, data.file_name); | 207 this.ensureTextIs_(this.fileName_, data.file_name); |
| 208 this.fileName_.hidden = completelyOnDisk; | 208 this.fileName_.hidden = completelyOnDisk; |
| 209 | 209 |
| 210 this.show.hidden = !completelyOnDisk; | 210 this.show_.hidden = !completelyOnDisk; |
| 211 | 211 |
| 212 this.retry.href = data.url; | 212 this.retry_.href = data.url; |
| 213 this.retry.hidden = !data.retry; | 213 this.retry_.hidden = !data.retry; |
| 214 | 214 |
| 215 this.pause.hidden = !isInProgress; | 215 this.pause_.hidden = !isInProgress; |
| 216 | 216 |
| 217 this.resume.hidden = !data.resume; | 217 this.resume_.hidden = !data.resume; |
| 218 | 218 |
| 219 /** @const */ var isPaused = data.state == Item.States.PAUSED; | 219 /** @const */ var isPaused = data.state == Item.States.PAUSED; |
| 220 /** @const */ var showCancel = isPaused || isInProgress; | 220 /** @const */ var showCancel = isPaused || isInProgress; |
| 221 this.cancel.hidden = !showCancel; | 221 this.cancel_.hidden = !showCancel; |
| 222 | 222 |
| 223 this.safeRemove.hidden = showCancel || | 223 this.safeRemove_.hidden = showCancel || |
| 224 !loadTimeData.getBoolean('allow_deleting_history'); | 224 !loadTimeData.getBoolean('allow_deleting_history'); |
| 225 | 225 |
| 226 /** @const */ var controlledByExtension = data.by_ext_id && | 226 /** @const */ var controlledByExtension = data.by_ext_id && |
| 227 data.by_ext_name; | 227 data.by_ext_name; |
| 228 this.controlledBy.hidden = !controlledByExtension; | 228 this.controlledBy_.hidden = !controlledByExtension; |
| 229 if (controlledByExtension) { | 229 if (controlledByExtension) { |
| 230 var link = this.controlledBy.querySelector('a'); | 230 var link = this.controlledBy_.querySelector('a'); |
|
hcarmona
2015/03/12 17:28:32
|link| should be the focusable element rather than
Dan Beam
2015/03/12 18:52:39
i noticed this but figured that's what downloads.j
| |
| 231 link.href = 'chrome://extensions#' + data.by_ext_id; | 231 link.href = 'chrome://extensions#' + data.by_ext_id; |
| 232 link.textContent = data.by_ext_name; | 232 link.textContent = data.by_ext_name; |
| 233 } | 233 } |
| 234 | 234 |
| 235 this.ensureTextIs_(this.since_, data.since_string); | 235 this.ensureTextIs_(this.since_, data.since_string); |
| 236 this.ensureTextIs_(this.date_, data.date_string); | 236 this.ensureTextIs_(this.date_, data.date_string); |
| 237 this.ensureTextIs_(this.srcUrl, data.url); | 237 this.ensureTextIs_(this.srcUrl_, data.url); |
| 238 this.srcUrl.href = data.url; | 238 this.srcUrl_.href = data.url; |
| 239 this.ensureTextIs_(this.status_, this.getStatusText_(data)); | 239 this.ensureTextIs_(this.status_, this.getStatusText_(data)); |
| 240 | 240 |
| 241 this.foregroundProgress_.hidden = !isInProgress; | 241 this.foregroundProgress_.hidden = !isInProgress; |
| 242 this.backgroundProgress_.hidden = !isInProgress; | 242 this.backgroundProgress_.hidden = !isInProgress; |
| 243 | 243 |
| 244 if (isInProgress) { | 244 if (isInProgress) { |
| 245 this.foregroundProgress_.width = ItemView.Progress.width; | 245 this.foregroundProgress_.width = ItemView.Progress.width; |
| 246 this.foregroundProgress_.height = ItemView.Progress.height; | 246 this.foregroundProgress_.height = ItemView.Progress.height; |
| 247 | 247 |
| 248 if (!this.progressContext_) { | 248 if (!this.progressContext_) { |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 419 }, | 419 }, |
| 420 | 420 |
| 421 /** @private */ | 421 /** @private */ |
| 422 onDiscardClick_: function() { | 422 onDiscardClick_: function() { |
| 423 chrome.send('discardDangerous', [this.id_]); | 423 chrome.send('discardDangerous', [this.id_]); |
| 424 }, | 424 }, |
| 425 }; | 425 }; |
| 426 | 426 |
| 427 return {ItemView: ItemView}; | 427 return {ItemView: ItemView}; |
| 428 }); | 428 }); |
| OLD | NEW |