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

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

Issue 1303993006: MD Downloads: compute description and tag via data binding (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@dom-if5
Patch Set: nit 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
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 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 data.since_string == this.data_.since_string && 137 data.since_string == this.data_.since_string &&
138 data.started == this.data_.started && 138 data.started == this.data_.started &&
139 data.state == this.data_.state && 139 data.state == this.data_.state &&
140 data.total == this.data_.total && 140 data.total == this.data_.total &&
141 data.url == this.data_.url) { 141 data.url == this.data_.url) {
142 // TODO(dbeam): remove this once data binding is fully in place. 142 // TODO(dbeam): remove this once data binding is fully in place.
143 return; 143 return;
144 } 144 }
145 145
146 for (var key in data) { 146 for (var key in data) {
147 // TODO(dbeam): does update order matter? Right now it seems to be
148 // alphabetical.
147 this.set('data_.' + key, data[key]); 149 this.set('data_.' + key, data[key]);
148 } 150 }
149 151
150 var desc = this.getDangerText_(data) || this.getStatusText_(data);
151
152 // Status goes in the "tag" (next to the file name) if there's no file.
153 this.ensureTextIs_(this.$.description, this.isActive_ ? desc : '');
154 this.ensureTextIs_(this.$.tag, this.isActive_ ? '' : desc);
155
156 if (!this.isDangerous_) { 152 if (!this.isDangerous_) {
157 /** @const */ var controlledByExtension = data.by_ext_id && 153 /** @const */ var controlledByExtension = data.by_ext_id &&
158 data.by_ext_name; 154 data.by_ext_name;
159 this.$['controlled-by'].hidden = !controlledByExtension; 155 this.$['controlled-by'].hidden = !controlledByExtension;
160 if (controlledByExtension) { 156 if (controlledByExtension) {
161 var link = this.$['controlled-by'].querySelector('a'); 157 var link = this.$['controlled-by'].querySelector('a');
162 link.href = 'chrome://extensions#' + data.by_ext_id; 158 link.href = 'chrome://extensions#' + data.by_ext_id;
163 link.textContent = data.by_ext_name; 159 link.textContent = data.by_ext_name;
164 } 160 }
165 161
(...skipping 24 matching lines...) Expand all
190 !this.data_.file_externally_removed; 186 !this.data_.file_externally_removed;
191 }, 187 },
192 188
193 /** @private */ 189 /** @private */
194 computeDate_: function() { 190 computeDate_: function() {
195 assert(!this.hideDate); 191 assert(!this.hideDate);
196 return assert(this.data_.since_string || this.data_.date_string); 192 return assert(this.data_.since_string || this.data_.date_string);
197 }, 193 },
198 194
199 /** @private */ 195 /** @private */
196 computeDescription_: function() {
197 var data = this.data_;
198
199 switch (data.state) {
200 case downloads.States.DANGEROUS:
201 var fileName = data.file_name;
202 switch (data.danger_type) {
203 case downloads.DangerType.DANGEROUS_FILE:
204 return loadTimeData.getStringF('dangerFileDesc', fileName);
205 case downloads.DangerType.DANGEROUS_URL:
206 return loadTimeData.getString('dangerUrlDesc');
207 case downloads.DangerType.DANGEROUS_CONTENT: // Fall through.
208 case downloads.DangerType.DANGEROUS_HOST:
209 return loadTimeData.getStringF('dangerContentDesc', fileName);
210 case downloads.DangerType.UNCOMMON_CONTENT:
211 return loadTimeData.getStringF('dangerUncommonDesc', fileName);
212 case downloads.DangerType.POTENTIALLY_UNWANTED:
213 return loadTimeData.getStringF('dangerSettingsDesc', fileName);
214 }
215 break;
216
217 case downloads.States.IN_PROGRESS:
218 case downloads.States.PAUSED: // Fallthrough.
219 return data.progress_status_text;
220 }
221
222 return '';
223 },
224
225 /** @private */
200 computeElevation_: function() { 226 computeElevation_: function() {
201 return this.isActive_ ? 1 : 0; 227 return this.isActive_ ? 1 : 0;
202 }, 228 },
203 229
204 /** @private */ 230 /** @private */
205 computeIsActive_: function() { 231 computeIsActive_: function() {
206 return this.data_.state != downloads.States.CANCELLED && 232 return this.data_.state != downloads.States.CANCELLED &&
207 this.data_.state != downloads.States.INTERRUPTED && 233 this.data_.state != downloads.States.INTERRUPTED &&
208 !this.data_.file_externally_removed; 234 !this.data_.file_externally_removed;
209 }, 235 },
(...skipping 28 matching lines...) Expand all
238 computeShowCancel_: function() { 264 computeShowCancel_: function() {
239 return this.data_.state == downloads.States.IN_PROGRESS || 265 return this.data_.state == downloads.States.IN_PROGRESS ||
240 this.data_.state == downloads.States.PAUSED; 266 this.data_.state == downloads.States.PAUSED;
241 }, 267 },
242 268
243 /** @private */ 269 /** @private */
244 computeShowProgress_: function() { 270 computeShowProgress_: function() {
245 return this.showCancel_ && isFinite(this.data_.percent); 271 return this.showCancel_ && isFinite(this.data_.percent);
246 }, 272 },
247 273
248 /** 274 /** @private */
249 * Overwrite |el|'s textContent if it differs from |text|. This is done 275 computeTag_: function() {
250 * generally so quickly updating text can be copied via text selection. 276 switch (this.data_.state) {
251 * @param {!Element} el
252 * @param {string} text
253 * @private
254 */
255 ensureTextIs_: function(el, text) {
256 if (el.textContent != text)
257 el.textContent = text;
258 },
259
260 /**
261 * @param {!downloads.Data} data
262 * @return {string} Text describing the danger of a download. Empty if not
263 * dangerous.
264 */
265 getDangerText_: function(data) {
266 switch (data.danger_type) {
267 case downloads.DangerType.DANGEROUS_FILE:
268 return loadTimeData.getStringF('dangerFileDesc', data.file_name);
269 case downloads.DangerType.DANGEROUS_URL:
270 return loadTimeData.getString('dangerUrlDesc');
271 case downloads.DangerType.DANGEROUS_CONTENT: // Fall through.
272 case downloads.DangerType.DANGEROUS_HOST:
273 return loadTimeData.getStringF('dangerContentDesc', data.file_name);
274 case downloads.DangerType.UNCOMMON_CONTENT:
275 return loadTimeData.getStringF('dangerUncommonDesc', data.file_name);
276 case downloads.DangerType.POTENTIALLY_UNWANTED:
277 return loadTimeData.getStringF('dangerSettingsDesc', data.file_name);
278 default:
279 return '';
280 }
281 },
282
283 /**
284 * @param {!downloads.Data} data
285 * @return {string} User-visible status update text.
286 * @private
287 */
288 getStatusText_: function(data) {
289 switch (data.state) {
290 case downloads.States.IN_PROGRESS:
291 case downloads.States.PAUSED: // Fallthrough.
292 assert(typeof data.progress_status_text == 'string');
293 return data.progress_status_text;
294 case downloads.States.CANCELLED: 277 case downloads.States.CANCELLED:
295 return loadTimeData.getString('statusCancelled'); 278 return loadTimeData.getString('statusCancelled');
296 case downloads.States.DANGEROUS: 279
297 break; // Intentionally hit assertNotReached(); at bottom.
298 case downloads.States.INTERRUPTED: 280 case downloads.States.INTERRUPTED:
299 assert(typeof data.last_reason_text == 'string'); 281 return this.data_.last_reason_text;
300 return data.last_reason_text; 282
301 case downloads.States.COMPLETE: 283 case downloads.States.COMPLETE:
302 return data.file_externally_removed ? 284 return this.data_.file_externally_removed ?
303 loadTimeData.getString('statusRemoved') : ''; 285 loadTimeData.getString('statusRemoved') : '';
304 } 286 }
305 assertNotReached(); 287
306 return ''; 288 return '';
307 }, 289 },
308 290
309 /** @private */ 291 /** @private */
310 isIndeterminate_: function() { 292 isIndeterminate_: function() {
311 assert(this.showProgress_); 293 assert(this.showProgress_);
312 return this.data_.percent == -1; 294 return this.data_.percent == -1;
313 }, 295 },
314 296
315 /** @private */ 297 /** @private */
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 }, 362 },
381 363
382 /** @private */ 364 /** @private */
383 onShowClick_: function() { 365 onShowClick_: function() {
384 this.actionService_.show(this.data_.id); 366 this.actionService_.show(this.data_.id);
385 }, 367 },
386 }); 368 });
387 369
388 return {Item: Item}; 370 return {Item: Item};
389 }); 371 });
OLDNEW
« no previous file with comments | « chrome/browser/resources/md_downloads/item.html ('k') | chrome/browser/ui/webui/downloads_dom_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698