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

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

Issue 1325853006: MD Downloads: wrap some <paper-buttons>s in <template is="dom-if"> (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove InFolder Created 5 years, 3 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
« no previous file with comments | « chrome/browser/resources/md_downloads/item.html ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 22 matching lines...) Expand all
33 }.bind(this)); 33 }.bind(this));
34 }, 34 },
35 }, 35 },
36 36
37 scrollbarWidth: { 37 scrollbarWidth: {
38 type: Number, 38 type: Number,
39 value: 0, 39 value: 0,
40 observer: 'onScrollbarWidthChange_', 40 observer: 'onScrollbarWidthChange_',
41 }, 41 },
42 42
43 completelyOnDisk_: {
44 type: Boolean,
45 value: true,
46 computed: 'computeCompletelyOnDisk_(' +
47 'data_.state, data_.file_externally_removed)',
48 },
49
50 i18n_: {
tommycli 2015/09/08 22:41:24 This is unfortunate, but I was bitten by the same
Dan Beam 2015/09/08 23:18:45 Acknowledged.
51 type: Object,
52 value: function() {
53 return {
54 cancel: loadTimeData.getString('controlCancel'),
55 pause: loadTimeData.getString('controlPause'),
56 resume: loadTimeData.getString('controlResume'),
57 retry: loadTimeData.getString('controlRetry'),
58 show: loadTimeData.getString('controlShowInFolder'),
59 };
60 },
61 readOnly: true,
62 },
63
43 isDangerous_: { 64 isDangerous_: {
44 type: Boolean, 65 type: Boolean,
45 value: false, 66 value: false,
67 computed: 'computeIsDangerous_(data_.state)',
68 },
69
70 isInProgress_: {
71 type: Boolean,
72 value: false,
73 computed: 'computeIsInProgress_(data_.state)',
74 },
75
76 showCancel_: {
77 type: Boolean,
78 value: false,
79 computed: 'computeShowCancel_(data_.state)',
80 },
81
82 showProgress_: {
83 type: Boolean,
84 value: false,
85 computed: 'computeShowProgress_(showCancel_, data_.percent)',
46 }, 86 },
47 87
48 /** Only set when |isDangerous| is true. */ 88 /** Only set when |isDangerous| is true. */
49 isMalware_: Boolean, 89 isMalware_: Boolean,
50 90
51 // TODO(dbeam): move all properties to |data_|. 91 // TODO(dbeam): move all properties to |data_|.
52 data_: { 92 data_: {
53 type: Object, 93 type: Object,
54 value: function() { return {}; }, 94 value: function() { return {}; },
55 }, 95 },
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 } 134 }
95 135
96 /** @const */ var isActive = 136 /** @const */ var isActive =
97 data.state != downloads.States.CANCELLED && 137 data.state != downloads.States.CANCELLED &&
98 data.state != downloads.States.INTERRUPTED && 138 data.state != downloads.States.INTERRUPTED &&
99 !data.file_externally_removed; 139 !data.file_externally_removed;
100 this.$.content.classList.toggle('is-active', isActive); 140 this.$.content.classList.toggle('is-active', isActive);
101 this.$.content.elevation = isActive ? 1 : 0; 141 this.$.content.elevation = isActive ? 1 : 0;
102 142
103 // Danger-dependent UI and controls. 143 // Danger-dependent UI and controls.
104 var dangerText = this.getDangerText_(data);
105 this.isDangerous_ = !!dangerText;
106 this.$.content.classList.toggle('dangerous', this.isDangerous_); 144 this.$.content.classList.toggle('dangerous', this.isDangerous_);
107 145
108 var description = dangerText || this.getStatusText_(data); 146 var description = this.getDangerText_(data) || this.getStatusText_(data);
109 147
110 // Status goes in the "tag" (next to the file name) if there's no file. 148 // Status goes in the "tag" (next to the file name) if there's no file.
111 this.ensureTextIs_(this.$.description, isActive ? description : ''); 149 this.ensureTextIs_(this.$.description, isActive ? description : '');
112 this.ensureTextIs_(this.$.tag, isActive ? '' : description); 150 this.ensureTextIs_(this.$.tag, isActive ? '' : description);
113 151
114 /** @const */ var showProgress = 152 this.$.content.classList.toggle('show-progress', this.showProgress_);
115 isFinite(data.percent) && !this.isDangerous_;
116 this.$.content.classList.toggle('show-progress', showProgress);
117
118 if (showProgress) {
119 this.$.progress.indeterminate = data.percent < 0;
120 this.$.progress.value = data.percent;
121 }
122 153
123 var hideRemove; 154 var hideRemove;
124 155
125 if (this.isDangerous_) { 156 if (this.isDangerous_) {
126 this.isMalware_ = 157 this.isMalware_ =
127 data.danger_type == downloads.DangerType.DANGEROUS_CONTENT || 158 data.danger_type == downloads.DangerType.DANGEROUS_CONTENT ||
128 data.danger_type == downloads.DangerType.DANGEROUS_HOST || 159 data.danger_type == downloads.DangerType.DANGEROUS_HOST ||
129 data.danger_type == downloads.DangerType.DANGEROUS_URL || 160 data.danger_type == downloads.DangerType.DANGEROUS_URL ||
130 data.danger_type == downloads.DangerType.POTENTIALLY_UNWANTED; 161 data.danger_type == downloads.DangerType.POTENTIALLY_UNWANTED;
131 hideRemove = true; 162 hideRemove = true;
132 } else { 163 } else {
133 /** @const */ var completelyOnDisk =
134 data.state == downloads.States.COMPLETE &&
135 !data.file_externally_removed;
136
137 this.$['file-link'].href = data.url; 164 this.$['file-link'].href = data.url;
138 this.ensureTextIs_(this.$['file-link'], data.file_name); 165 this.ensureTextIs_(this.$['file-link'], data.file_name);
139 166
140 this.$['file-link'].hidden = !completelyOnDisk; 167 this.$['file-link'].hidden = !this.completelyOnDisk_;
141 this.$.name.hidden = completelyOnDisk; 168 this.$.name.hidden = this.completelyOnDisk_;
142 this.$.show.hidden = !completelyOnDisk;
143 169
144 this.$.retry.hidden = !data.retry; 170 hideRemove = this.showCancel_ ||
145
146 /** @const */ var isInProgress =
147 data.state == downloads.States.IN_PROGRESS;
148 this.$.pause.hidden = !isInProgress;
149
150 this.$.resume.hidden = !data.resume;
151
152 /** @const */ var isPaused = data.state == downloads.States.PAUSED;
153 /** @const */ var showCancel = isPaused || isInProgress;
154 this.$.cancel.hidden = !showCancel;
155
156 hideRemove = showCancel ||
157 !loadTimeData.getBoolean('allowDeletingHistory'); 171 !loadTimeData.getBoolean('allowDeletingHistory');
158 172
159 /** @const */ var controlledByExtension = data.by_ext_id && 173 /** @const */ var controlledByExtension = data.by_ext_id &&
160 data.by_ext_name; 174 data.by_ext_name;
161 this.$['controlled-by'].hidden = !controlledByExtension; 175 this.$['controlled-by'].hidden = !controlledByExtension;
162 if (controlledByExtension) { 176 if (controlledByExtension) {
163 var link = this.$['controlled-by'].querySelector('a'); 177 var link = this.$['controlled-by'].querySelector('a');
164 link.href = 'chrome://extensions#' + data.by_ext_id; 178 link.href = 'chrome://extensions#' + data.by_ext_id;
165 link.textContent = data.by_ext_name; 179 link.textContent = data.by_ext_name;
166 } 180 }
167 181
168 var icon = 'chrome://fileicon/' + encodeURIComponent(data.file_path); 182 var icon = 'chrome://fileicon/' + encodeURIComponent(data.file_path);
169 this.iconLoader_.loadScaledIcon(this.$['file-icon'], icon); 183 this.iconLoader_.loadScaledIcon(this.$['file-icon'], icon);
170 } 184 }
171 185
172 this.$.remove.style.visibility = hideRemove ? 'hidden' : ''; 186 this.$.remove.style.visibility = hideRemove ? 'hidden' : '';
173 }, 187 },
174 188
189 /** @private */
190 computeCompletelyOnDisk_: function() {
191 return this.data_.state == downloads.States.COMPLETE &&
192 !this.data_.file_externally_removed;
193 },
194
195 /** @private */
196 computeDate_: function() {
197 assert(!this.hideDate);
198 return assert(this.data_.since_string || this.data_.date_string);
199 },
200
201 /** @private */
202 computeIsInProgress_: function() {
203 return this.data_.state == downloads.States.IN_PROGRESS;
204 },
205
206 /** @private */
207 computeIsDangerous_: function() {
208 return this.data_.state == downloads.States.DANGEROUS;
209 },
210
211 /** @private */
212 computeShowCancel_: function() {
213 return this.data_.state == downloads.States.IN_PROGRESS ||
214 this.data_.state == downloads.States.PAUSED;
215 },
216
217 /** @private */
218 computeShowProgress_: function() {
219 return this.showCancel_ && isFinite(this.data_.percent);
220 },
221
175 /** 222 /**
176 * Overwrite |el|'s textContent if it differs from |text|. This is done 223 * Overwrite |el|'s textContent if it differs from |text|. This is done
177 * generally so quickly updating text can be copied via text selection. 224 * generally so quickly updating text can be copied via text selection.
178 * @param {!Element} el 225 * @param {!Element} el
179 * @param {string} text 226 * @param {string} text
180 * @private 227 * @private
181 */ 228 */
182 ensureTextIs_: function(el, text) { 229 ensureTextIs_: function(el, text) {
183 if (el.textContent != text) 230 if (el.textContent != text)
184 el.textContent = text; 231 el.textContent = text;
185 }, 232 },
186 233
187 /** @private */
188 computeDate_: function() {
189 assert(!this.hideDate);
190 return assert(this.data_.since_string || this.data_.date_string);
191 },
192
193 /** 234 /**
194 * @param {!downloads.Data} data 235 * @param {!downloads.Data} data
195 * @return {string} Text describing the danger of a download. Empty if not 236 * @return {string} Text describing the danger of a download. Empty if not
196 * dangerous. 237 * dangerous.
197 */ 238 */
198 getDangerText_: function(data) { 239 getDangerText_: function(data) {
199 switch (data.danger_type) { 240 switch (data.danger_type) {
200 case downloads.DangerType.DANGEROUS_FILE: 241 case downloads.DangerType.DANGEROUS_FILE:
201 return loadTimeData.getStringF('dangerFileDesc', data.file_name); 242 return loadTimeData.getStringF('dangerFileDesc', data.file_name);
202 case downloads.DangerType.DANGEROUS_URL: 243 case downloads.DangerType.DANGEROUS_URL:
(...skipping 30 matching lines...) Expand all
233 return data.last_reason_text; 274 return data.last_reason_text;
234 case downloads.States.COMPLETE: 275 case downloads.States.COMPLETE:
235 return data.file_externally_removed ? 276 return data.file_externally_removed ?
236 loadTimeData.getString('statusRemoved') : ''; 277 loadTimeData.getString('statusRemoved') : '';
237 } 278 }
238 assertNotReached(); 279 assertNotReached();
239 return ''; 280 return '';
240 }, 281 },
241 282
242 /** @private */ 283 /** @private */
284 isIndeterminate_: function() {
tommycli 2015/09/08 22:41:24 This is called from the HTML with a parameter. Is
Dan Beam 2015/09/08 23:18:45 it could but this.data_.percent is the same as the
tommycli 2015/09/09 00:04:32 Acknowledged.
285 assert(this.showProgress_);
286 return this.data_.percent == -1;
287 },
288
289 /** @private */
243 onCancelClick_: function() { 290 onCancelClick_: function() {
244 this.actionService_.cancel(this.data_.id); 291 this.actionService_.cancel(this.data_.id);
245 }, 292 },
246 293
247 /** 294 /**
248 * @private 295 * @private
249 * @param {Event} e 296 * @param {Event} e
250 */ 297 */
251 onDragStart_: function(e) { 298 onDragStart_: function(e) {
252 e.preventDefault(); 299 e.preventDefault();
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 }, 355 },
309 356
310 /** @private */ 357 /** @private */
311 onShowClick_: function() { 358 onShowClick_: function() {
312 this.actionService_.show(this.data_.id); 359 this.actionService_.show(this.data_.id);
313 }, 360 },
314 }); 361 });
315 362
316 return {Item: Item}; 363 return {Item: Item};
317 }); 364 });
OLDNEW
« no previous file with comments | « chrome/browser/resources/md_downloads/item.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698