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
3 // found in the LICENSE file.
5 cr.define('downloads', function() {
10 * @param {!downloads.ThrottledIconLoader} iconLoader
11 * @param {!downloads.ActionService} actionService
13 factoryImpl: function(iconLoader, actionService) {
14 /** @private {!downloads.ThrottledIconLoader} */
15 this.iconLoader_ = iconLoader;
17 /** @private {!downloads.ActionService} */
18 this.actionService_ = actionService;
30 return new Promise(function(resolve, reject) {
31 this.resolveReadyPromise_ = resolve;
37 computed: 'computeCompletelyOnDisk_(' +
38 'data_.state, data_.file_externally_removed)',
48 cancel: loadTimeData.getString('controlCancel'),
49 discard: loadTimeData.getString('dangerDiscard'),
50 pause: loadTimeData.getString('controlPause'),
51 remove: loadTimeData.getString('controlRemoveFromList'),
52 resume: loadTimeData.getString('controlResume'),
53 restore: loadTimeData.getString('dangerRestore'),
54 retry: loadTimeData.getString('controlRetry'),
55 save: loadTimeData.getString('dangerSave'),
56 show: loadTimeData.getString('controlShowInFolder'),
62 computed: 'computeIsActive_(' +
63 'data_.state, data_.file_externally_removed)',
69 computed: 'computeIsDangerous_(data_.state)',
75 computed: 'computeIsInProgress_(data_.state)',
81 computed: 'computeShowCancel_(data_.state)',
87 computed: 'computeShowProgress_(showCancel_, data_.percent)',
93 computed: 'computeIsMalware_(isDangerous_, data_.danger_type)',
104 'observeControlledBy_(data_.by_ext_id, data_.by_ext_name)',
108 this.content = this.$.content;
109 this.resolveReadyPromise_();
112 /** @param {!downloads.Data} data */
113 update: function(data) {
116 if (!this.isDangerous_) {
117 var icon = 'chrome://fileicon/' + encodeURIComponent(data.file_path);
118 this.iconLoader_.loadScaledIcon(this.$['file-icon'], icon);
123 computeClass_: function() {
127 classes.push('is-active');
129 if (this.isDangerous_)
130 classes.push('dangerous');
132 if (this.showProgress_)
133 classes.push('show-progress');
135 return classes.join(' ');
139 computeCompletelyOnDisk_: function() {
140 return this.data_.state == downloads.States.COMPLETE &&
141 !this.data_.file_externally_removed;
145 computeDate_: function() {
148 return assert(this.data_.since_string || this.data_.date_string);
152 computeDescription_: function() {
153 var data = this.data_;
155 switch (data.state) {
156 case downloads.States.DANGEROUS:
157 var fileName = data.file_name;
158 switch (data.danger_type) {
159 case downloads.DangerType.DANGEROUS_FILE:
160 return loadTimeData.getStringF('dangerFileDesc', fileName);
161 case downloads.DangerType.DANGEROUS_URL:
162 return loadTimeData.getString('dangerUrlDesc');
163 case downloads.DangerType.DANGEROUS_CONTENT: // Fall through.
164 case downloads.DangerType.DANGEROUS_HOST:
165 return loadTimeData.getStringF('dangerContentDesc', fileName);
166 case downloads.DangerType.UNCOMMON_CONTENT:
167 return loadTimeData.getStringF('dangerUncommonDesc', fileName);
168 case downloads.DangerType.POTENTIALLY_UNWANTED:
169 return loadTimeData.getStringF('dangerSettingsDesc', fileName);
173 case downloads.States.IN_PROGRESS:
174 case downloads.States.PAUSED: // Fallthrough.
175 return data.progress_status_text;
182 computeElevation_: function() {
183 return this.isActive_ ? 1 : 0;
187 computeIsActive_: function() {
188 return this.data_.state != downloads.States.CANCELLED &&
189 this.data_.state != downloads.States.INTERRUPTED &&
190 !this.data_.file_externally_removed;
194 computeIsDangerous_: function() {
195 return this.data_.state == downloads.States.DANGEROUS;
199 computeIsInProgress_: function() {
200 return this.data_.state == downloads.States.IN_PROGRESS;
204 computeIsMalware_: function() {
205 return this.isDangerous_ &&
206 (this.data_.danger_type == downloads.DangerType.DANGEROUS_CONTENT ||
207 this.data_.danger_type == downloads.DangerType.DANGEROUS_HOST ||
208 this.data_.danger_type == downloads.DangerType.DANGEROUS_URL ||
209 this.data_.danger_type == downloads.DangerType.POTENTIALLY_UNWANTED);
213 computeRemoveStyle_: function() {
214 var canDelete = loadTimeData.getBoolean('allowDeletingHistory');
215 var hideRemove = this.isDangerous_ || this.showCancel_ || !canDelete;
216 return hideRemove ? 'visibility: hidden' : '';
220 computeShowCancel_: function() {
221 return this.data_.state == downloads.States.IN_PROGRESS ||
222 this.data_.state == downloads.States.PAUSED;
226 computeShowProgress_: function() {
227 return this.showCancel_ && this.data_.percent >= -1;
231 computeTag_: function() {
232 switch (this.data_.state) {
233 case downloads.States.CANCELLED:
234 return loadTimeData.getString('statusCancelled');
236 case downloads.States.INTERRUPTED:
237 return this.data_.last_reason_text;
239 case downloads.States.COMPLETE:
240 return this.data_.file_externally_removed ?
241 loadTimeData.getString('statusRemoved') : '';
248 isIndeterminate_: function() {
249 return this.data_.percent == -1;
253 observeControlledBy_: function() {
255 if (this.data_.by_ext_id && this.data_.by_ext_name) {
256 var url = 'chrome://extensions#' + this.data_.by_ext_id;
257 var name = this.data_.by_ext_name;
258 html = loadTimeData.getStringF('controlledByUrl', url, name);
260 this.$['controlled-by'].innerHTML = html;
264 onCancelClick_: function() {
265 this.actionService_.cancel(this.data_.id);
269 onDiscardDangerous_: function() {
270 this.actionService_.discardDangerous(this.data_.id);
277 onDragStart_: function(e) {
279 this.actionService_.drag(this.data_.id);
286 onFileLinkClick_: function(e) {
288 this.actionService_.openFile(this.data_.id);
292 onPauseClick_: function() {
293 this.actionService_.pause(this.data_.id);
297 onRemoveClick_: function() {
298 this.actionService_.remove(this.data_.id);
302 onResumeClick_: function() {
303 this.actionService_.resume(this.data_.id);
307 onRetryClick_: function() {
308 this.actionService_.download(this.$['file-link'].href);
312 onSaveDangerous_: function() {
313 this.actionService_.saveDangerous(this.data_.id);
317 onShowClick_: function() {
318 this.actionService_.show(this.data_.id);