| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 /////////////////////////////////////////////////////////////////////////////// | 5 // TODO(jhawkins): Use hidden instead of showInline* and display:none. |
| 6 // Helper functions | |
| 7 function $(o) {return document.getElementById(o);} | |
| 8 | 6 |
| 9 /** | 7 /** |
| 10 * Sets the display style of a node. | 8 * Sets the display style of a node. |
| 11 */ | 9 */ |
| 12 function showInline(node, isShow) { | 10 function showInline(node, isShow) { |
| 13 node.style.display = isShow ? 'inline' : 'none'; | 11 node.style.display = isShow ? 'inline' : 'none'; |
| 14 } | 12 } |
| 15 | 13 |
| 16 function showInlineBlock(node, isShow) { | 14 function showInlineBlock(node, isShow) { |
| 17 node.style.display = isShow ? 'inline-block' : 'none'; | 15 node.style.display = isShow ? 'inline-block' : 'none'; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 button.type = 'button'; | 50 button.type = 'button'; |
| 53 button.value = value; | 51 button.value = value; |
| 54 button.onclick = onclick; | 52 button.onclick = onclick; |
| 55 return button; | 53 return button; |
| 56 } | 54 } |
| 57 | 55 |
| 58 /////////////////////////////////////////////////////////////////////////////// | 56 /////////////////////////////////////////////////////////////////////////////// |
| 59 // Downloads | 57 // Downloads |
| 60 /** | 58 /** |
| 61 * Class to hold all the information about the visible downloads. | 59 * Class to hold all the information about the visible downloads. |
| 60 * @constructor |
| 62 */ | 61 */ |
| 63 function Downloads() { | 62 function Downloads() { |
| 64 this.downloads_ = {}; | 63 this.downloads_ = {}; |
| 65 this.node_ = $('downloads-display'); | 64 this.node_ = $('downloads-display'); |
| 66 this.summary_ = $('downloads-summary-text'); | 65 this.summary_ = $('downloads-summary-text'); |
| 67 this.searchText_ = ''; | 66 this.searchText_ = ''; |
| 68 | 67 |
| 69 // Keep track of the dates of the newest and oldest downloads so that we | 68 // Keep track of the dates of the newest and oldest downloads so that we |
| 70 // know where to insert them. | 69 // know where to insert them. |
| 71 this.newestTime_ = -1; | 70 this.newestTime_ = -1; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 90 // display order are new ones and so we can add them to the top of the | 89 // display order are new ones and so we can add them to the top of the |
| 91 // list. | 90 // list. |
| 92 if (download.started > this.newestTime_) { | 91 if (download.started > this.newestTime_) { |
| 93 this.node_.insertBefore(this.downloads_[id].node, this.node_.firstChild); | 92 this.node_.insertBefore(this.downloads_[id].node, this.node_.firstChild); |
| 94 this.newestTime_ = download.started; | 93 this.newestTime_ = download.started; |
| 95 } else { | 94 } else { |
| 96 this.node_.appendChild(this.downloads_[id].node); | 95 this.node_.appendChild(this.downloads_[id].node); |
| 97 } | 96 } |
| 98 this.updateDateDisplay_(); | 97 this.updateDateDisplay_(); |
| 99 } | 98 } |
| 100 } | 99 }; |
| 101 | 100 |
| 102 /** | 101 /** |
| 103 * Set our display search text. | 102 * Set our display search text. |
| 104 * @param {string} searchText The string we're searching for. | 103 * @param {string} searchText The string we're searching for. |
| 105 */ | 104 */ |
| 106 Downloads.prototype.setSearchText = function(searchText) { | 105 Downloads.prototype.setSearchText = function(searchText) { |
| 107 this.searchText_ = searchText; | 106 this.searchText_ = searchText; |
| 108 } | 107 }; |
| 109 | 108 |
| 110 /** | 109 /** |
| 111 * Update the summary block above the results | 110 * Update the summary block above the results |
| 112 */ | 111 */ |
| 113 Downloads.prototype.updateSummary = function() { | 112 Downloads.prototype.updateSummary = function() { |
| 114 if (this.searchText_) { | 113 if (this.searchText_) { |
| 115 this.summary_.textContent = localStrings.getStringF('searchresultsfor', | 114 this.summary_.textContent = localStrings.getStringF('searchresultsfor', |
| 116 this.searchText_); | 115 this.searchText_); |
| 117 } else { | 116 } else { |
| 118 this.summary_.textContent = localStrings.getString('downloads'); | 117 this.summary_.textContent = localStrings.getString('downloads'); |
| 119 } | 118 } |
| 120 | 119 |
| 121 var hasDownloads = false; | 120 var hasDownloads = false; |
| 122 for (var i in this.downloads_) { | 121 for (var i in this.downloads_) { |
| 123 hasDownloads = true; | 122 hasDownloads = true; |
| 124 break; | 123 break; |
| 125 } | 124 } |
| 126 | 125 |
| 127 if (!hasDownloads) { | 126 if (!hasDownloads) { |
| 128 this.node_.textContent = localStrings.getString('noresults'); | 127 this.node_.textContent = localStrings.getString('noresults'); |
| 129 } | 128 } |
| 130 } | 129 }; |
| 131 | 130 |
| 132 /** | 131 /** |
| 133 * Update the date visibility in our nodes so that no date is | 132 * Update the date visibility in our nodes so that no date is |
| 134 * repeated. | 133 * repeated. |
| 134 * @private |
| 135 */ | 135 */ |
| 136 Downloads.prototype.updateDateDisplay_ = function() { | 136 Downloads.prototype.updateDateDisplay_ = function() { |
| 137 var dateContainers = document.getElementsByClassName('date-container'); | 137 var dateContainers = document.getElementsByClassName('date-container'); |
| 138 var displayed = {}; | 138 var displayed = {}; |
| 139 for (var i = 0, container; container = dateContainers[i]; i++) { | 139 for (var i = 0, container; container = dateContainers[i]; i++) { |
| 140 var dateString = container.getElementsByClassName('date')[0].innerHTML; | 140 var dateString = container.getElementsByClassName('date')[0].innerHTML; |
| 141 if (!!displayed[dateString]) { | 141 if (!!displayed[dateString]) { |
| 142 container.style.display = 'none'; | 142 container.style.display = 'none'; |
| 143 } else { | 143 } else { |
| 144 displayed[dateString] = true; | 144 displayed[dateString] = true; |
| 145 container.style.display = 'block'; | 145 container.style.display = 'block'; |
| 146 } | 146 } |
| 147 } | 147 } |
| 148 } | 148 }; |
| 149 | 149 |
| 150 /** | 150 /** |
| 151 * Remove a download. | 151 * Remove a download. |
| 152 * @param {number} id The id of the download to remove. | 152 * @param {number} id The id of the download to remove. |
| 153 */ | 153 */ |
| 154 Downloads.prototype.remove = function(id) { | 154 Downloads.prototype.remove = function(id) { |
| 155 this.node_.removeChild(this.downloads_[id].node); | 155 this.node_.removeChild(this.downloads_[id].node); |
| 156 delete this.downloads_[id]; | 156 delete this.downloads_[id]; |
| 157 this.updateDateDisplay_(); | 157 this.updateDateDisplay_(); |
| 158 } | 158 }; |
| 159 | 159 |
| 160 /** | 160 /** |
| 161 * Clear all downloads and reset us back to a null state. | 161 * Clear all downloads and reset us back to a null state. |
| 162 */ | 162 */ |
| 163 Downloads.prototype.clear = function() { | 163 Downloads.prototype.clear = function() { |
| 164 for (var id in this.downloads_) { | 164 for (var id in this.downloads_) { |
| 165 this.downloads_[id].clear(); | 165 this.downloads_[id].clear(); |
| 166 this.remove(id); | 166 this.remove(id); |
| 167 } | 167 } |
| 168 } | 168 }; |
| 169 | 169 |
| 170 /** | 170 /** |
| 171 * Schedule icon load. | 171 * Schedule icon load. |
| 172 * @param {HTMLImageElement} elem Image element that should contain the icon. | 172 * @param {HTMLImageElement} elem Image element that should contain the icon. |
| 173 * @param {string} iconURL URL to the icon. | 173 * @param {string} iconURL URL to the icon. |
| 174 */ | 174 */ |
| 175 Downloads.prototype.scheduleIconLoad = function(elem, iconURL) { | 175 Downloads.prototype.scheduleIconLoad = function(elem, iconURL) { |
| 176 var self = this; | 176 var self = this; |
| 177 | 177 |
| 178 // Sends request to the next icon in the queue and schedules | 178 // Sends request to the next icon in the queue and schedules |
| (...skipping 12 matching lines...) Expand all Loading... |
| 191 self.isIconLoading_ = false; | 191 self.isIconLoading_ = false; |
| 192 } | 192 } |
| 193 | 193 |
| 194 // Create new request | 194 // Create new request |
| 195 var loadRequest = {element: elem, url: iconURL}; | 195 var loadRequest = {element: elem, url: iconURL}; |
| 196 this.iconLoadQueue_.push(loadRequest); | 196 this.iconLoadQueue_.push(loadRequest); |
| 197 | 197 |
| 198 // Start loading if none scheduled yet | 198 // Start loading if none scheduled yet |
| 199 if (!this.isIconLoading_) | 199 if (!this.isIconLoading_) |
| 200 loadNext(); | 200 loadNext(); |
| 201 } | 201 }; |
| 202 | 202 |
| 203 /////////////////////////////////////////////////////////////////////////////// | 203 /////////////////////////////////////////////////////////////////////////////// |
| 204 // Download | 204 // Download |
| 205 /** | 205 /** |
| 206 * A download and the DOM representation for that download. | 206 * A download and the DOM representation for that download. |
| 207 * @param {Object} download A backend download object (see downloads_ui.cc) | 207 * @param {Object} download A backend download object (see downloads_ui.cc) |
| 208 * @constructor |
| 208 */ | 209 */ |
| 209 function Download(download) { | 210 function Download(download) { |
| 210 // Create DOM | 211 // Create DOM |
| 211 this.node = createElementWithClassName('div','download' + | 212 this.node = createElementWithClassName( |
| 212 (download.otr ? ' otr' : '')); | 213 'div', 'download' + (download.otr ? ' otr' : '')); |
| 213 | 214 |
| 214 // Dates | 215 // Dates |
| 215 this.dateContainer_ = createElementWithClassName('div', 'date-container'); | 216 this.dateContainer_ = createElementWithClassName('div', 'date-container'); |
| 216 this.node.appendChild(this.dateContainer_); | 217 this.node.appendChild(this.dateContainer_); |
| 217 | 218 |
| 218 this.nodeSince_ = createElementWithClassName('div', 'since'); | 219 this.nodeSince_ = createElementWithClassName('div', 'since'); |
| 219 this.nodeDate_ = createElementWithClassName('div', 'date'); | 220 this.nodeDate_ = createElementWithClassName('div', 'date'); |
| 220 this.dateContainer_.appendChild(this.nodeSince_); | 221 this.dateContainer_.appendChild(this.nodeSince_); |
| 221 this.dateContainer_.appendChild(this.nodeDate_); | 222 this.dateContainer_.appendChild(this.nodeDate_); |
| 222 | 223 |
| 223 // Container for all 'safe download' UI. | 224 // Container for all 'safe download' UI. |
| 224 this.safe_ = createElementWithClassName('div', 'safe'); | 225 this.safe_ = createElementWithClassName('div', 'safe'); |
| 225 this.safe_.ondragstart = this.drag_.bind(this); | 226 this.safe_.ondragstart = this.drag_.bind(this); |
| 226 this.node.appendChild(this.safe_); | 227 this.node.appendChild(this.safe_); |
| 227 | 228 |
| 228 if (download.state != Download.States.COMPLETE) { | 229 if (download.state != Download.States.COMPLETE) { |
| 229 this.nodeProgressBackground_ = | 230 this.nodeProgressBackground_ = |
| 230 createElementWithClassName('div', 'progress background'); | 231 createElementWithClassName('div', 'progress background'); |
| 231 this.safe_.appendChild(this.nodeProgressBackground_); | 232 this.safe_.appendChild(this.nodeProgressBackground_); |
| 232 | 233 |
| 233 this.canvasProgress_ = | 234 this.canvasProgress_ = |
| 234 document.getCSSCanvasContext('2d', 'canvas_' + download.id, | 235 document.getCSSCanvasContext('2d', 'canvas_' + download.id, |
| 235 Download.Progress.width, | 236 Download.Progress.width, |
| 236 Download.Progress.height); | 237 Download.Progress.height); |
| 237 | 238 |
| 238 this.nodeProgressForeground_ = | 239 this.nodeProgressForeground_ = |
| 239 createElementWithClassName('div', 'progress foreground'); | 240 createElementWithClassName('div', 'progress foreground'); |
| 240 this.nodeProgressForeground_.style.webkitMask = | 241 this.nodeProgressForeground_.style.webkitMask = |
| 241 '-webkit-canvas(canvas_'+download.id+')'; | 242 '-webkit-canvas(canvas_' + download.id + ')'; |
| 242 this.safe_.appendChild(this.nodeProgressForeground_); | 243 this.safe_.appendChild(this.nodeProgressForeground_); |
| 243 } | 244 } |
| 244 | 245 |
| 245 this.nodeImg_ = createElementWithClassName('img', 'icon'); | 246 this.nodeImg_ = createElementWithClassName('img', 'icon'); |
| 246 this.safe_.appendChild(this.nodeImg_); | 247 this.safe_.appendChild(this.nodeImg_); |
| 247 | 248 |
| 248 // FileLink is used for completed downloads, otherwise we show FileName. | 249 // FileLink is used for completed downloads, otherwise we show FileName. |
| 249 this.nodeTitleArea_ = createElementWithClassName('div', 'title-area'); | 250 this.nodeTitleArea_ = createElementWithClassName('div', 'title-area'); |
| 250 this.safe_.appendChild(this.nodeTitleArea_); | 251 this.safe_.appendChild(this.nodeTitleArea_); |
| 251 | 252 |
| 252 this.nodeFileLink_ = createLink(this.openFile_.bind(this), ''); | 253 this.nodeFileLink_ = createLink(this.openFile_.bind(this), ''); |
| 253 this.nodeFileLink_.className = 'name'; | 254 this.nodeFileLink_.className = 'name'; |
| 254 this.nodeFileLink_.style.display = 'none'; | 255 this.nodeFileLink_.style.display = 'none'; |
| 255 this.nodeTitleArea_.appendChild(this.nodeFileLink_); | 256 this.nodeTitleArea_.appendChild(this.nodeFileLink_); |
| 256 | 257 |
| 257 this.nodeFileName_ = createElementWithClassName('span', 'name'); | 258 this.nodeFileName_ = createElementWithClassName('span', 'name'); |
| 258 this.nodeFileName_.style.display = 'none'; | 259 this.nodeFileName_.style.display = 'none'; |
| 259 this.nodeTitleArea_.appendChild(this.nodeFileName_); | 260 this.nodeTitleArea_.appendChild(this.nodeFileName_); |
| 260 | 261 |
| 261 this.nodeStatus_ = createElementWithClassName('span', 'status'); | 262 this.nodeStatus_ = createElementWithClassName('span', 'status'); |
| 262 this.nodeTitleArea_.appendChild(this.nodeStatus_); | 263 this.nodeTitleArea_.appendChild(this.nodeStatus_); |
| 263 | 264 |
| 264 var nodeURLDiv = createElementWithClassName('div', 'url-container'); | 265 var nodeURLDiv = createElementWithClassName('div', 'url-container'); |
| 265 this.safe_.appendChild(nodeURLDiv); | 266 this.safe_.appendChild(nodeURLDiv); |
| 266 | 267 |
| 267 this.nodeURL_ = createElementWithClassName('a', 'src-url'); | 268 this.nodeURL_ = createElementWithClassName('a', 'src-url'); |
| 268 this.nodeURL_.target = "_blank"; | 269 this.nodeURL_.target = '_blank'; |
| 269 nodeURLDiv.appendChild(this.nodeURL_); | 270 nodeURLDiv.appendChild(this.nodeURL_); |
| 270 | 271 |
| 271 // Controls. | 272 // Controls. |
| 272 this.nodeControls_ = createElementWithClassName('div', 'controls'); | 273 this.nodeControls_ = createElementWithClassName('div', 'controls'); |
| 273 this.safe_.appendChild(this.nodeControls_); | 274 this.safe_.appendChild(this.nodeControls_); |
| 274 | 275 |
| 275 // We don't need "show in folder" in chromium os. See download_ui.cc and | 276 // We don't need 'show in folder' in chromium os. See download_ui.cc and |
| 276 // http://code.google.com/p/chromium-os/issues/detail?id=916. | 277 // http://code.google.com/p/chromium-os/issues/detail?id=916. |
| 277 var showinfolder = localStrings.getString('control_showinfolder'); | 278 var showinfolder = localStrings.getString('control_showinfolder'); |
| 278 if (showinfolder) { | 279 if (showinfolder) { |
| 279 this.controlShow_ = createLink(this.show_.bind(this), showinfolder); | 280 this.controlShow_ = createLink(this.show_.bind(this), showinfolder); |
| 280 this.nodeControls_.appendChild(this.controlShow_); | 281 this.nodeControls_.appendChild(this.controlShow_); |
| 281 } else { | 282 } else { |
| 282 this.controlShow_ = null; | 283 this.controlShow_ = null; |
| 283 } | 284 } |
| 284 | 285 |
| 285 this.controlRetry_ = document.createElement('a'); | 286 this.controlRetry_ = document.createElement('a'); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 | 321 |
| 321 // Update member vars. | 322 // Update member vars. |
| 322 this.update(download); | 323 this.update(download); |
| 323 } | 324 } |
| 324 | 325 |
| 325 /** | 326 /** |
| 326 * The states a download can be in. These correspond to states defined in | 327 * The states a download can be in. These correspond to states defined in |
| 327 * DownloadsDOMHandler::CreateDownloadItemValue | 328 * DownloadsDOMHandler::CreateDownloadItemValue |
| 328 */ | 329 */ |
| 329 Download.States = { | 330 Download.States = { |
| 330 IN_PROGRESS : "IN_PROGRESS", | 331 IN_PROGRESS: 'IN_PROGRESS', |
| 331 CANCELLED : "CANCELLED", | 332 CANCELLED: 'CANCELLED', |
| 332 COMPLETE : "COMPLETE", | 333 COMPLETE: 'COMPLETE', |
| 333 PAUSED : "PAUSED", | 334 PAUSED: 'PAUSED', |
| 334 DANGEROUS : "DANGEROUS", | 335 DANGEROUS: 'DANGEROUS', |
| 335 INTERRUPTED : "INTERRUPTED", | 336 INTERRUPTED: 'INTERRUPTED', |
| 336 } | 337 }; |
| 337 | 338 |
| 338 /** | 339 /** |
| 339 * Explains why a download is in DANGEROUS state. | 340 * Explains why a download is in DANGEROUS state. |
| 340 */ | 341 */ |
| 341 Download.DangerType = { | 342 Download.DangerType = { |
| 342 NOT_DANGEROUS: "NOT_DANGEROUS", | 343 NOT_DANGEROUS: 'NOT_DANGEROUS', |
| 343 DANGEROUS_FILE: "DANGEROUS_FILE", | 344 DANGEROUS_FILE: 'DANGEROUS_FILE', |
| 344 DANGEROUS_URL: "DANGEROUS_URL", | 345 DANGEROUS_URL: 'DANGEROUS_URL', |
| 345 DANGEROUS_CONTENT: "DANGEROUS_CONTENT" | 346 DANGEROUS_CONTENT: 'DANGEROUS_CONTENT' |
| 346 } | 347 }; |
| 347 | 348 |
| 348 /** | 349 /** |
| 349 * Constants for the progress meter. | 350 * Constants for the progress meter. |
| 350 */ | 351 */ |
| 351 Download.Progress = { | 352 Download.Progress = { |
| 352 width : 48, | 353 width: 48, |
| 353 height : 48, | 354 height: 48, |
| 354 radius : 24, | 355 radius: 24, |
| 355 centerX : 24, | 356 centerX: 24, |
| 356 centerY : 24, | 357 centerY: 24, |
| 357 base : -0.5 * Math.PI, | 358 base: -0.5 * Math.PI, |
| 358 dir : false, | 359 dir: false, |
| 359 } | 360 }; |
| 360 | 361 |
| 361 /** | 362 /** |
| 362 * Updates the download to reflect new data. | 363 * Updates the download to reflect new data. |
| 363 * @param {Object} download A backend download object (see downloads_ui.cc) | 364 * @param {Object} download A backend download object (see downloads_ui.cc) |
| 364 */ | 365 */ |
| 365 Download.prototype.update = function(download) { | 366 Download.prototype.update = function(download) { |
| 366 this.id_ = download.id; | 367 this.id_ = download.id; |
| 367 this.filePath_ = download.file_path; | 368 this.filePath_ = download.file_path; |
| 368 this.fileUrl_ = download.file_url; | 369 this.fileUrl_ = download.file_url; |
| 369 this.fileName_ = download.file_name; | 370 this.fileName_ = download.file_name; |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 467 // text selection the user has started (http://crbug.com/44982). | 468 // text selection the user has started (http://crbug.com/44982). |
| 468 if (this.nodeURL_.textContent != this.url_) { | 469 if (this.nodeURL_.textContent != this.url_) { |
| 469 this.nodeURL_.textContent = this.url_; | 470 this.nodeURL_.textContent = this.url_; |
| 470 this.nodeURL_.href = this.url_; | 471 this.nodeURL_.href = this.url_; |
| 471 } | 472 } |
| 472 this.nodeStatus_.textContent = this.getStatusText_(); | 473 this.nodeStatus_.textContent = this.getStatusText_(); |
| 473 | 474 |
| 474 this.danger_.style.display = 'none'; | 475 this.danger_.style.display = 'none'; |
| 475 this.safe_.style.display = 'block'; | 476 this.safe_.style.display = 'block'; |
| 476 } | 477 } |
| 477 } | 478 }; |
| 478 | 479 |
| 479 /** | 480 /** |
| 480 * Removes applicable bits from the DOM in preparation for deletion. | 481 * Removes applicable bits from the DOM in preparation for deletion. |
| 481 */ | 482 */ |
| 482 Download.prototype.clear = function() { | 483 Download.prototype.clear = function() { |
| 483 this.safe_.ondragstart = null; | 484 this.safe_.ondragstart = null; |
| 484 this.nodeFileLink_.onclick = null; | 485 this.nodeFileLink_.onclick = null; |
| 485 if (this.controlShow_) { | 486 if (this.controlShow_) { |
| 486 this.controlShow_.onclick = null; | 487 this.controlShow_.onclick = null; |
| 487 } | 488 } |
| 488 this.controlCancel_.onclick = null; | 489 this.controlCancel_.onclick = null; |
| 489 this.controlPause_.onclick = null; | 490 this.controlPause_.onclick = null; |
| 490 this.controlResume_.onclick = null; | 491 this.controlResume_.onclick = null; |
| 491 this.dangerDiscard_.onclick = null; | 492 this.dangerDiscard_.onclick = null; |
| 492 | 493 |
| 493 this.node.innerHTML = ''; | 494 this.node.innerHTML = ''; |
| 494 } | 495 }; |
| 495 | 496 |
| 496 /** | 497 /** |
| 498 * @private |
| 497 * @return {string} User-visible status update text. | 499 * @return {string} User-visible status update text. |
| 498 */ | 500 */ |
| 499 Download.prototype.getStatusText_ = function() { | 501 Download.prototype.getStatusText_ = function() { |
| 500 switch (this.state_) { | 502 switch (this.state_) { |
| 501 case Download.States.IN_PROGRESS: | 503 case Download.States.IN_PROGRESS: |
| 502 return this.progressStatusText_; | 504 return this.progressStatusText_; |
| 503 case Download.States.CANCELLED: | 505 case Download.States.CANCELLED: |
| 504 return localStrings.getString('status_cancelled'); | 506 return localStrings.getString('status_cancelled'); |
| 505 case Download.States.PAUSED: | 507 case Download.States.PAUSED: |
| 506 return localStrings.getString('status_paused'); | 508 return localStrings.getString('status_paused'); |
| 507 case Download.States.DANGEROUS: | 509 case Download.States.DANGEROUS: |
| 508 // danger_url_desc is also used by DANGEROUS_CONTENT. | 510 // danger_url_desc is also used by DANGEROUS_CONTENT. |
| 509 var desc = this.dangerType_ == Download.DangerType.DANGEROUS_FILE ? | 511 var desc = this.dangerType_ == Download.DangerType.DANGEROUS_FILE ? |
| 510 'danger_file_desc' : 'danger_url_desc'; | 512 'danger_file_desc' : 'danger_url_desc'; |
| 511 return localStrings.getString(desc); | 513 return localStrings.getString(desc); |
| 512 case Download.States.INTERRUPTED: | 514 case Download.States.INTERRUPTED: |
| 513 return localStrings.getString('status_interrupted'); | 515 return localStrings.getString('status_interrupted'); |
| 514 case Download.States.COMPLETE: | 516 case Download.States.COMPLETE: |
| 515 return this.fileExternallyRemoved_ ? | 517 return this.fileExternallyRemoved_ ? |
| 516 localStrings.getString('status_removed') : ''; | 518 localStrings.getString('status_removed') : ''; |
| 517 } | 519 } |
| 518 } | 520 }; |
| 519 | 521 |
| 520 /** | 522 /** |
| 521 * Tells the backend to initiate a drag, allowing users to drag | 523 * Tells the backend to initiate a drag, allowing users to drag |
| 522 * files from the download page and have them appear as native file | 524 * files from the download page and have them appear as native file |
| 523 * drags. | 525 * drags. |
| 526 * @private |
| 524 */ | 527 */ |
| 525 Download.prototype.drag_ = function() { | 528 Download.prototype.drag_ = function() { |
| 526 chrome.send('drag', [this.id_.toString()]); | 529 chrome.send('drag', [this.id_.toString()]); |
| 527 return false; | 530 return false; |
| 528 } | 531 }; |
| 529 | 532 |
| 530 /** | 533 /** |
| 531 * Tells the backend to open this file. | 534 * Tells the backend to open this file. |
| 535 * @private |
| 532 */ | 536 */ |
| 533 Download.prototype.openFile_ = function() { | 537 Download.prototype.openFile_ = function() { |
| 534 chrome.send('openFile', [this.id_.toString()]); | 538 chrome.send('openFile', [this.id_.toString()]); |
| 535 return false; | 539 return false; |
| 536 } | 540 }; |
| 537 | 541 |
| 538 /** | 542 /** |
| 539 * Tells the backend that the user chose to save a dangerous file. | 543 * Tells the backend that the user chose to save a dangerous file. |
| 544 * @private |
| 540 */ | 545 */ |
| 541 Download.prototype.saveDangerous_ = function() { | 546 Download.prototype.saveDangerous_ = function() { |
| 542 chrome.send('saveDangerous', [this.id_.toString()]); | 547 chrome.send('saveDangerous', [this.id_.toString()]); |
| 543 return false; | 548 return false; |
| 544 } | 549 }; |
| 545 | 550 |
| 546 /** | 551 /** |
| 547 * Tells the backend that the user chose to discard a dangerous file. | 552 * Tells the backend that the user chose to discard a dangerous file. |
| 553 * @private |
| 548 */ | 554 */ |
| 549 Download.prototype.discardDangerous_ = function() { | 555 Download.prototype.discardDangerous_ = function() { |
| 550 chrome.send('discardDangerous', [this.id_.toString()]); | 556 chrome.send('discardDangerous', [this.id_.toString()]); |
| 551 downloads.remove(this.id_); | 557 downloads.remove(this.id_); |
| 552 return false; | 558 return false; |
| 553 } | 559 }; |
| 554 | 560 |
| 555 /** | 561 /** |
| 556 * Tells the backend to show the file in explorer. | 562 * Tells the backend to show the file in explorer. |
| 563 * @private |
| 557 */ | 564 */ |
| 558 Download.prototype.show_ = function() { | 565 Download.prototype.show_ = function() { |
| 559 chrome.send('show', [this.id_.toString()]); | 566 chrome.send('show', [this.id_.toString()]); |
| 560 return false; | 567 return false; |
| 561 } | 568 }; |
| 562 | 569 |
| 563 /** | 570 /** |
| 564 * Tells the backend to pause this download. | 571 * Tells the backend to pause this download. |
| 572 * @private |
| 565 */ | 573 */ |
| 566 Download.prototype.togglePause_ = function() { | 574 Download.prototype.togglePause_ = function() { |
| 567 chrome.send('togglepause', [this.id_.toString()]); | 575 chrome.send('togglepause', [this.id_.toString()]); |
| 568 return false; | 576 return false; |
| 569 } | 577 }; |
| 570 | 578 |
| 571 /** | 579 /** |
| 572 * Tells the backend to remove this download from history and download shelf. | 580 * Tells the backend to remove this download from history and download shelf. |
| 581 * @private |
| 573 */ | 582 */ |
| 574 Download.prototype.remove_ = function() { | 583 Download.prototype.remove_ = function() { |
| 575 chrome.send('remove', [this.id_.toString()]); | 584 chrome.send('remove', [this.id_.toString()]); |
| 576 return false; | 585 return false; |
| 577 } | 586 }; |
| 578 | 587 |
| 579 /** | 588 /** |
| 580 * Tells the backend to cancel this download. | 589 * Tells the backend to cancel this download. |
| 590 * @private |
| 581 */ | 591 */ |
| 582 Download.prototype.cancel_ = function() { | 592 Download.prototype.cancel_ = function() { |
| 583 chrome.send('cancel', [this.id_.toString()]); | 593 chrome.send('cancel', [this.id_.toString()]); |
| 584 return false; | 594 return false; |
| 585 } | 595 }; |
| 586 | 596 |
| 587 /////////////////////////////////////////////////////////////////////////////// | 597 /////////////////////////////////////////////////////////////////////////////// |
| 588 // Page: | 598 // Page: |
| 589 var downloads, localStrings, resultsTimeout; | 599 var downloads, localStrings, resultsTimeout; |
| 590 | 600 |
| 591 // TODO(benjhayden): Rename Downloads to DownloadManager, downloads to | 601 // TODO(benjhayden): Rename Downloads to DownloadManager, downloads to |
| 592 // downloadManager or theDownloadManager or DownloadManager.get() to prevent | 602 // downloadManager or theDownloadManager or DownloadManager.get() to prevent |
| 593 // confusing Downloads with Download. | 603 // confusing Downloads with Download. |
| 594 | 604 |
| 595 /** | 605 /** |
| 596 * The FIFO array that stores updates of download files to be appeared | 606 * The FIFO array that stores updates of download files to be appeared |
| 597 * on the download page. It is guaranteed that the updates in this array | 607 * on the download page. It is guaranteed that the updates in this array |
| 598 * are reflected to the download page in a FIFO order. | 608 * are reflected to the download page in a FIFO order. |
| 599 */ | 609 */ |
| 600 var fifo_results; | 610 var fifo_results; |
| 601 | 611 |
| 602 function load() { | 612 function load() { |
| 603 chrome.send('onPageLoaded'); | 613 chrome.send('onPageLoaded'); |
| 604 fifo_results = new Array(); | 614 fifo_results = new Array(); |
| 605 localStrings = new LocalStrings(); | 615 localStrings = new LocalStrings(); |
| 606 downloads = new Downloads(); | 616 downloads = new Downloads(); |
| 607 $('term').focus(); | 617 $('term').focus(); |
| 608 $('term').setAttribute('aria-labelledby', 'search-submit'); | 618 $('term').setAttribute('aria-labelledby', 'search-submit'); |
| 609 setSearch(''); | 619 setSearch(''); |
| 620 |
| 621 var clearAllLink = $('clear-all'); |
| 622 clearAllLink.onclick = clearAll; |
| 623 clearAllLink.oncontextmenu = function() { return false; }; |
| 624 |
| 625 // TODO(jhawkins): Use a link-button here. |
| 626 var openDownloadsFolderLink = $('open-downloads-folder'); |
| 627 openDownloadsFolderLink.onclick = |
| 628 chrome.send.bind(chrome, 'openDownloadsFolder'); |
| 629 openDownloadsFolderLink.oncontextmenu = function() { return false; }; |
| 630 |
| 631 $('search-link').onclick = function(e) { |
| 632 setSearch(''); |
| 633 e.preventDefault(); |
| 634 return false; |
| 635 }; |
| 636 |
| 637 $('search-form').onsubmit = function(e) { |
| 638 setSearch(this.term.value); |
| 639 e.preventDefault(); |
| 640 return false; |
| 641 }; |
| 610 } | 642 } |
| 611 | 643 |
| 612 function setSearch(searchText) { | 644 function setSearch(searchText) { |
| 613 fifo_results.length = 0; | 645 fifo_results.length = 0; |
| 614 downloads.clear(); | 646 downloads.clear(); |
| 615 downloads.setSearchText(searchText); | 647 downloads.setSearchText(searchText); |
| 616 chrome.send('getDownloads', [searchText.toString()]); | 648 chrome.send('getDownloads', [searchText.toString()]); |
| 617 } | 649 } |
| 618 | 650 |
| 619 function clearAll() { | 651 function clearAll() { |
| 620 fifo_results.length = 0; | 652 fifo_results.length = 0; |
| 621 downloads.clear(); | 653 downloads.clear(); |
| 622 downloads.setSearchText(''); | 654 downloads.setSearchText(''); |
| 623 chrome.send('clearAll', []); | 655 chrome.send('clearAll'); |
| 624 return false; | |
| 625 } | |
| 626 | |
| 627 function openDownloadsFolder() { | |
| 628 chrome.send('openDownloadsFolder'); | |
| 629 return false; | |
| 630 } | 656 } |
| 631 | 657 |
| 632 /////////////////////////////////////////////////////////////////////////////// | 658 /////////////////////////////////////////////////////////////////////////////// |
| 633 // Chrome callbacks: | 659 // Chrome callbacks: |
| 634 /** | 660 /** |
| 635 * Our history system calls this function with results from searches or when | 661 * Our history system calls this function with results from searches or when |
| 636 * downloads are added or removed. | 662 * downloads are added or removed. |
| 637 */ | 663 */ |
| 638 function downloadsList(results) { | 664 function downloadsList(results) { |
| 639 if (resultsTimeout) | 665 if (resultsTimeout) |
| (...skipping 29 matching lines...) Expand all Loading... |
| 669 if (Date.now() - start > 50) { | 695 if (Date.now() - start > 50) { |
| 670 clearTimeout(resultsTimeout); | 696 clearTimeout(resultsTimeout); |
| 671 resultsTimeout = setTimeout(tryDownloadUpdatedPeriodically, 5); | 697 resultsTimeout = setTimeout(tryDownloadUpdatedPeriodically, 5); |
| 672 break; | 698 break; |
| 673 } | 699 } |
| 674 } | 700 } |
| 675 } | 701 } |
| 676 | 702 |
| 677 // Add handlers to HTML elements. | 703 // Add handlers to HTML elements. |
| 678 window.addEventListener('DOMContentLoaded', load); | 704 window.addEventListener('DOMContentLoaded', load); |
| 679 | |
| 680 var clearAllLink = $('clear-all'); | |
| 681 clearAllLink.onclick = function () { clearAll(''); }; | |
| 682 clearAllLink.oncontextmenu = function() { return false; }; | |
| 683 | |
| 684 var openDownloadsFolderLink = $('open-downloads-folder'); | |
| 685 openDownloadsFolderLink.onclick = openDownloadsFolder; | |
| 686 openDownloadsFolderLink.oncontextmenu = function() { return false; }; | |
| 687 | |
| 688 $('search-link').onclick = function () { | |
| 689 setSearch(''); | |
| 690 return false; | |
| 691 }; | |
| 692 $('search-form').onsubmit = function () { | |
| 693 setSearch(this.term.value); | |
| 694 return false; | |
| 695 }; | |
| OLD | NEW |