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

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

Issue 1240853002: Slice MD downloads into more components (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: license Created 5 years, 5 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 ItemView = Polymer({ 6 var ItemView = Polymer({
7 is: 'item-view', 7 is: 'downloads-item-view',
8 8
9 /** @param {!downloads.ThrottledIconLoader} iconLoader */ 9 /**
10 factoryImpl: function(iconLoader) { 10 * @param {!downloads.ThrottledIconLoader} iconLoader
11 * @param {!downloads.ActionService} actionService
12 */
13 factoryImpl: function(iconLoader, actionService) {
11 /** @private {!downloads.ThrottledIconLoader} */ 14 /** @private {!downloads.ThrottledIconLoader} */
12 this.iconLoader_ = iconLoader; 15 this.iconLoader_ = iconLoader;
16
17 /** @private {!downloads.ActionService} */
18 this.actionService_ = actionService;
13 }, 19 },
14 20
15 properties: { 21 properties: {
16 hideDate: {type: Boolean, value: false}, 22 hideDate: {type: Boolean, value: false},
17 isDangerous: {type: Boolean, value: false},
18 // Only use |isMalware| if |isDangerous| is true.
19 isMalware: Boolean,
20 },
21 23
22 ready: function() { 24 isDangerous_: {type: Boolean, value: false},
23 this.$.safe.ondragstart = this.onSafeDragstart_.bind(this); 25
24 this.$['file-link'].onclick = this.onFileLinkClick_.bind(this); 26 /** Only set when |isDangerous| is true. */
25 this.$.show.onclick = this.onShowClick_.bind(this); 27 isMalware_: Boolean,
26 this.$.pause.onclick = this.onPauseClick_.bind(this);
27 this.$.resume.onclick = this.onResumeClick_.bind(this);
28 this.$['safe-remove'].onclick = this.onSafeRemoveClick_.bind(this);
29 this.$.cancel.onclick = this.onCancelClick_.bind(this);
30 this.$.restore.onclick = this.onRestoreClick_.bind(this);
31 this.$.save.onclick = this.onSaveClick_.bind(this);
32 this.$['dangerous-remove'].onclick = this.onDangerRemoveClick_.bind(this);
33 this.$.discard.onclick = this.onDiscardClick_.bind(this);
34 }, 28 },
35 29
36 /** @param {!downloads.Data} data */ 30 /** @param {!downloads.Data} data */
37 update: function(data) { 31 update: function(data) {
38 assert(!this.id_ || data.id == this.id_); 32 assert(!this.id_ || data.id == this.id_);
39 this.id_ = data.id; // This is the only thing saved from |data|. 33 this.id_ = data.id; // This is the only thing saved from |data|.
40 34
41 this.classList.toggle('otr', data.otr); 35 this.classList.toggle('otr', data.otr);
42 36
43 this.ensureTextIs_(this.$.since, data.since_string); 37 this.ensureTextIs_(this.$.since, data.since_string);
44 this.ensureTextIs_(this.$.date, data.date_string); 38 this.ensureTextIs_(this.$.date, data.date_string);
45 39
46 var dangerText = this.getDangerText_(data); 40 var dangerText = this.getDangerText_(data);
47 this.isDangerous = !!dangerText; 41 this.isDangerous = !!dangerText;
48 42
49 if (dangerText) { 43 if (dangerText) {
50 this.ensureTextIs_(this.$.description, dangerText); 44 this.ensureTextIs_(this.$.description, dangerText);
51 45
52 var dangerType = data.danger_type; 46 var dangerType = data.danger_type;
53 var dangerousFile = dangerType == downloads.DangerType.DANGEROUS_FILE; 47 var dangerousFile = dangerType == downloads.DangerType.DANGEROUS_FILE;
54 this.$.description.classList.toggle('malware', !dangerousFile); 48 this.$.description.classList.toggle('malware', !dangerousFile);
55 49
56 var idr = dangerousFile ? 'IDR_WARNING' : 'IDR_SAFEBROWSING_WARNING'; 50 var idr = dangerousFile ? 'IDR_WARNING' : 'IDR_SAFEBROWSING_WARNING';
57 var iconUrl = 'chrome://theme/' + idr; 51 var iconUrl = 'chrome://theme/' + idr;
58 this.iconLoader_.loadScaledIcon(this.$['dangerous-icon'], iconUrl); 52 this.iconLoader_.loadScaledIcon(this.$['dangerous-icon'], iconUrl);
59 53
60 this.isMalware = 54 this.isMalware_ =
61 dangerType == downloads.DangerType.DANGEROUS_CONTENT || 55 dangerType == downloads.DangerType.DANGEROUS_CONTENT ||
62 dangerType == downloads.DangerType.DANGEROUS_HOST || 56 dangerType == downloads.DangerType.DANGEROUS_HOST ||
63 dangerType == downloads.DangerType.DANGEROUS_URL || 57 dangerType == downloads.DangerType.DANGEROUS_URL ||
64 dangerType == downloads.DangerType.POTENTIALLY_UNWANTED; 58 dangerType == downloads.DangerType.POTENTIALLY_UNWANTED;
65 } else { 59 } else {
66 var iconUrl = 'chrome://fileicon/' + encodeURIComponent(data.file_path); 60 var iconUrl = 'chrome://fileicon/' + encodeURIComponent(data.file_path);
67 this.iconLoader_.loadScaledIcon(this.$['safe-icon'], iconUrl); 61 this.iconLoader_.loadScaledIcon(this.$['safe-icon'], iconUrl);
68 62
69 /** @const */ var isInProgress = 63 /** @const */ var isInProgress =
70 data.state == downloads.States.IN_PROGRESS; 64 data.state == downloads.States.IN_PROGRESS;
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 assert(typeof data.last_reason_text == 'string'); 168 assert(typeof data.last_reason_text == 'string');
175 return data.last_reason_text; 169 return data.last_reason_text;
176 case downloads.States.COMPLETE: 170 case downloads.States.COMPLETE:
177 return data.file_externally_removed ? 171 return data.file_externally_removed ?
178 loadTimeData.getString('statusRemoved') : ''; 172 loadTimeData.getString('statusRemoved') : '';
179 } 173 }
180 assertNotReached(); 174 assertNotReached();
181 return ''; 175 return '';
182 }, 176 },
183 177
178 /** @private */
179 onCancelClick_: function() {
180 this.actionService_.cancel(this.id_);
181 },
182
183 /** @private */
184 onDangerousRemoveOrDiscardClick_: function() {
185 this.actionService_.discardDangerous(this.id_);
186 },
187
184 /** 188 /**
185 * @private 189 * @private
186 * @param {Event} e 190 * @param {Event} e
187 */ 191 */
188 onSafeDragstart_: function(e) { 192 onDragStart_: function(e) {
189 e.preventDefault(); 193 e.preventDefault();
190 chrome.send('drag', [this.id_]); 194 this.actionService_.drag(this.id_);
191 }, 195 },
192 196
193 /** 197 /**
194 * @param {Event} e 198 * @param {Event} e
195 * @private 199 * @private
196 */ 200 */
197 onFileLinkClick_: function(e) { 201 onFileLinkClick_: function(e) {
198 e.preventDefault(); 202 e.preventDefault();
199 chrome.send('openFile', [this.id_]); 203 this.actionService_.openFile(this.id_);
204 },
205
206 /** @private */
207 onPauseClick_: function() {
208 this.actionService_.pause(this.id_);
209 },
210
211 /** @private */
212 onRemoveClick_: function() {
213 this.actionService_.remove(this.id_);
214 },
215
216 /** @private */
217 onRestoreOrSaveClick_: function() {
218 this.actionService_.saveDangerous(this.id_);
219 },
220
221 /** @private */
222 onResumeClick_: function() {
223 this.actionService_.resume(this.id_);
200 }, 224 },
201 225
202 /** @private */ 226 /** @private */
203 onShowClick_: function() { 227 onShowClick_: function() {
204 chrome.send('show', [this.id_]); 228 this.actionService_.show(this.id_);
205 },
206
207 /** @private */
208 onPauseClick_: function() {
209 chrome.send('pause', [this.id_]);
210 },
211
212 /** @private */
213 onResumeClick_: function() {
214 chrome.send('resume', [this.id_]);
215 },
216
217 /** @private */
218 onSafeRemoveClick_: function() {
219 chrome.send('remove', [this.id_]);
220 },
221
222 /** @private */
223 onCancelClick_: function() {
224 chrome.send('cancel', [this.id_]);
225 },
226
227 /** @private */
228 onRestoreClick_: function() {
229 this.onSaveClick_();
230 },
231
232 /** @private */
233 onSaveClick_: function() {
234 chrome.send('saveDangerous', [this.id_]);
235 },
236
237 /** @private */
238 onDangerRemoveClick_: function() {
239 this.onDiscardClick_();
240 },
241
242 /** @private */
243 onDiscardClick_: function() {
244 chrome.send('discardDangerous', [this.id_]);
245 }, 229 },
246 }); 230 });
247 231
248 return {ItemView: ItemView}; 232 return {ItemView: ItemView};
249 }); 233 });
OLDNEW
« no previous file with comments | « chrome/browser/resources/md_downloads/item_view.html ('k') | chrome/browser/resources/md_downloads/manager.css » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698