Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(419)

Side by Side Diff: chrome/browser/resources/md_downloads/item.js

Issue 1257413004: Keep hackin' on MD downloads (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@dl-items4
Patch Set: stupid whitespace Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 24 matching lines...) Expand all
35 35
36 /** Only set when |isDangerous| is true. */ 36 /** Only set when |isDangerous| is true. */
37 isMalware_: Boolean, 37 isMalware_: Boolean,
38 }, 38 },
39 39
40 /** @param {!downloads.Data} data */ 40 /** @param {!downloads.Data} data */
41 update: function(data) { 41 update: function(data) {
42 assert(!this.id_ || data.id == this.id_); 42 assert(!this.id_ || data.id == this.id_);
43 this.id_ = data.id; // This is the only thing saved from |data|. 43 this.id_ = data.id; // This is the only thing saved from |data|.
44 44
45 // Danger-independent UI and controls.
45 this.ensureTextIs_(this.$.since, data.since_string); 46 this.ensureTextIs_(this.$.since, data.since_string);
46 this.ensureTextIs_(this.$.date, data.date_string); 47 this.ensureTextIs_(this.$.date, data.date_string);
47 48
49 /** @const */ var noFile =
50 data.state == downloads.States.CANCELLED ||
51 data.state == downloads.States.INTERRUPTED ||
52 data.file_externally_removed;
53 this.$.content.classList.toggle('no-file', noFile);
54
55 this.ensureTextIs_(this.$.name, data.file_name);
56 this.ensureTextIs_(this.$.url, data.url);
57 this.$.url.href = data.url;
58
59 // Danger-dependent UI and controls.
48 var dangerText = this.getDangerText_(data); 60 var dangerText = this.getDangerText_(data);
49 this.isDangerous = !!dangerText; 61 this.isDangerous_ = !!dangerText;
62 this.$.content.classList.toggle('dangerous', this.isDangerous_);
50 63
51 if (dangerText) { 64 var description = dangerText || this.getStatusText_(data);
52 this.ensureTextIs_(this.$.description, dangerText);
53 65
66 // Status goes in the "tag" (next to the file name) if there's no file.
67 this.ensureTextIs_(this.$.description, noFile ? '' : description);
68 this.ensureTextIs_(this.$.tag, noFile ? description : '');
69
70 /** @const */ var showProgress =
71 isFinite(data.percent) && !this.isDangerous_;
72 this.$.progress.hidden = !showProgress;
73
74 if (showProgress) {
75 this.$.progress.indeterminate = data.percent < 0;
76 this.$.progress.value = data.percent;
77 }
78
79 var iconUrl = 'chrome://';
80
81 if (this.isDangerous_) {
54 var dangerType = data.danger_type; 82 var dangerType = data.danger_type;
55 var dangerousFile = dangerType == downloads.DangerType.DANGEROUS_FILE;
56 this.$.description.classList.toggle('malware', !dangerousFile);
57
58 var idr = dangerousFile ? 'IDR_WARNING' : 'IDR_SAFEBROWSING_WARNING';
59 var iconUrl = 'chrome://theme/' + idr;
60 this.iconLoader_.loadScaledIcon(this.$['dangerous-icon'], iconUrl);
61 83
62 this.isMalware_ = 84 this.isMalware_ =
63 dangerType == downloads.DangerType.DANGEROUS_CONTENT || 85 dangerType == downloads.DangerType.DANGEROUS_CONTENT ||
64 dangerType == downloads.DangerType.DANGEROUS_HOST || 86 dangerType == downloads.DangerType.DANGEROUS_HOST ||
65 dangerType == downloads.DangerType.DANGEROUS_URL || 87 dangerType == downloads.DangerType.DANGEROUS_URL ||
66 dangerType == downloads.DangerType.POTENTIALLY_UNWANTED; 88 dangerType == downloads.DangerType.POTENTIALLY_UNWANTED;
89
90 // TODO(dbeam): this icon sucks: it's a PNG we have to scale and looks
91 // nothing like the mocks. Find a prettier, more vectorized version.
92 var dangerousFile = dangerType == downloads.DangerType.DANGEROUS_FILE;
93 var idr = dangerousFile ? 'IDR_WARNING' : 'IDR_SAFEBROWSING_WARNING';
94 iconUrl += 'theme/' + idr;
67 } else { 95 } else {
68 var iconUrl = 'chrome://fileicon/' + encodeURIComponent(data.file_path);
69 this.iconLoader_.loadScaledIcon(this.$['safe-icon'], iconUrl);
70
71 /** @const */ var noFile =
72 data.state == downloads.States.CANCELLED ||
73 data.state == downloads.States.INTERRUPTED ||
74 data.file_externally_removed;
75 this.$.safe.classList.toggle('no-file', noFile);
76
77 /** @const */ var completelyOnDisk = 96 /** @const */ var completelyOnDisk =
78 data.state == downloads.States.COMPLETE && 97 data.state == downloads.States.COMPLETE &&
79 !data.file_externally_removed; 98 !data.file_externally_removed;
80 99
81 this.$['file-link'].href = data.url; 100 this.$['file-link'].href = data.url;
82 this.ensureTextIs_(this.$['file-link'], data.file_name); 101 this.ensureTextIs_(this.$['file-link'], data.file_name);
102
83 this.$['file-link'].hidden = !completelyOnDisk; 103 this.$['file-link'].hidden = !completelyOnDisk;
84
85 this.ensureTextIs_(this.$.name, data.file_name);
86 this.$.name.hidden = completelyOnDisk; 104 this.$.name.hidden = completelyOnDisk;
87
88 this.$.show.hidden = !completelyOnDisk; 105 this.$.show.hidden = !completelyOnDisk;
89 106
90 this.$.retry.hidden = !data.retry; 107 this.$.retry.hidden = !data.retry;
91 108
92 /** @const */ var isInProgress = 109 /** @const */ var isInProgress =
93 data.state == downloads.States.IN_PROGRESS; 110 data.state == downloads.States.IN_PROGRESS;
94 this.$.pause.hidden = !isInProgress; 111 this.$.pause.hidden = !isInProgress;
95 112
96 this.$.resume.hidden = !data.resume; 113 this.$.resume.hidden = !data.resume;
97 114
98 /** @const */ var isPaused = data.state == downloads.States.PAUSED; 115 /** @const */ var isPaused = data.state == downloads.States.PAUSED;
99 /** @const */ var showCancel = isPaused || isInProgress; 116 /** @const */ var showCancel = isPaused || isInProgress;
100 this.$.cancel.hidden = !showCancel; 117 this.$.cancel.hidden = !showCancel;
101 118
102 this.$['safe-remove'].hidden = showCancel || 119 this.$.remove.disabled = showCancel ||
103 !loadTimeData.getBoolean('allowDeletingHistory'); 120 !loadTimeData.getBoolean('allowDeletingHistory');
104 121
105 /** @const */ var controlledByExtension = data.by_ext_id && 122 /** @const */ var controlledByExtension = data.by_ext_id &&
106 data.by_ext_name; 123 data.by_ext_name;
107 this.$['controlled-by'].hidden = !controlledByExtension; 124 this.$['controlled-by'].hidden = !controlledByExtension;
108 if (controlledByExtension) { 125 if (controlledByExtension) {
109 var link = this.$['controlled-by'].querySelector('a'); 126 var link = this.$['controlled-by'].querySelector('a');
110 link.href = 'chrome://extensions#' + data.by_ext_id; 127 link.href = 'chrome://extensions#' + data.by_ext_id;
111 link.setAttribute('column-type', 'controlled-by'); 128 link.setAttribute('column-type', 'controlled-by');
112 link.textContent = data.by_ext_name; 129 link.textContent = data.by_ext_name;
113 } 130 }
114 131
115 this.ensureTextIs_(this.$['src-url'], data.url); 132 iconUrl += 'fileicon/' + encodeURIComponent(data.file_path);
116 this.$['src-url'].href = data.url; 133 }
117 134
118 // TODO(dbeam): "Cancelled" should show status next to the file name. 135 this.iconLoader_.loadScaledIcon(this.$.icon, iconUrl);
119 this.ensureTextIs_(this.$.status, this.getStatusText_(data));
120
121 /** @const */ var hasPercent = isFinite(data.percent);
122 this.$.progress.hidden = !hasPercent;
123
124 if (hasPercent) {
125 this.$.progress.indeterminate = data.percent < 0;
126 this.$.progress.value = data.percent;
127 }
128 }
129 }, 136 },
130 137
131 /** 138 /**
132 * Overwrite |el|'s textContent if it differs from |text|. 139 * Overwrite |el|'s textContent if it differs from |text|.
133 * @param {!Element} el 140 * @param {!Element} el
134 * @param {string} text 141 * @param {string} text
135 * @private 142 * @private
136 */ 143 */
137 ensureTextIs_: function(el, text) { 144 ensureTextIs_: function(el, text) {
138 if (el.textContent != text) 145 if (el.textContent != text)
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 } 193 }
187 assertNotReached(); 194 assertNotReached();
188 return ''; 195 return '';
189 }, 196 },
190 197
191 /** @private */ 198 /** @private */
192 onCancelClick_: function() { 199 onCancelClick_: function() {
193 this.actionService_.cancel(this.id_); 200 this.actionService_.cancel(this.id_);
194 }, 201 },
195 202
196 /** @private */
197 onDangerousRemoveOrDiscardClick_: function() {
198 this.actionService_.discardDangerous(this.id_);
199 },
200
201 /** 203 /**
202 * @private 204 * @private
203 * @param {Event} e 205 * @param {Event} e
204 */ 206 */
205 onDragStart_: function(e) { 207 onDragStart_: function(e) {
206 e.preventDefault(); 208 e.preventDefault();
207 this.actionService_.drag(this.id_); 209 this.actionService_.drag(this.id_);
208 }, 210 },
209 211
210 /** 212 /**
211 * @param {Event} e 213 * @param {Event} e
212 * @private 214 * @private
213 */ 215 */
214 onFileLinkClick_: function(e) { 216 onFileLinkClick_: function(e) {
215 e.preventDefault(); 217 e.preventDefault();
216 this.actionService_.openFile(this.id_); 218 this.actionService_.openFile(this.id_);
217 }, 219 },
218 220
219 /** @private */ 221 /** @private */
220 onPauseClick_: function() { 222 onPauseClick_: function() {
221 this.actionService_.pause(this.id_); 223 this.actionService_.pause(this.id_);
222 }, 224 },
223 225
224 /** @private */ 226 /** @private */
225 onRemoveClick_: function() { 227 onRemoveClick_: function() {
226 this.actionService_.remove(this.id_); 228 assert(!this.$.remove.disabled);
michaelpg 2015/07/30 02:39:24 Don't trust Polymer?
Dan Beam 2015/07/30 02:43:21 in assert()s we trust
229
230 if (this.isDangerous_)
231 this.actionService_.discardDangerous(this.id_);
232 else
233 this.actionService_.remove(this.id_);
227 }, 234 },
228 235
229 /** @private */ 236 /** @private */
230 onRestoreOrSaveClick_: function() { 237 onRestoreOrSaveClick_: function() {
231 this.actionService_.saveDangerous(this.id_); 238 this.actionService_.saveDangerous(this.id_);
232 }, 239 },
233 240
234 /** @private */ 241 /** @private */
235 onResumeClick_: function() { 242 onResumeClick_: function() {
236 this.actionService_.resume(this.id_); 243 this.actionService_.resume(this.id_);
(...skipping 19 matching lines...) Expand all
256 }, 263 },
257 264
258 /** @private */ 265 /** @private */
259 onShowClick_: function() { 266 onShowClick_: function() {
260 this.actionService_.show(this.id_); 267 this.actionService_.show(this.id_);
261 }, 268 },
262 }); 269 });
263 270
264 return {Item: Item}; 271 return {Item: Item};
265 }); 272 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698