| 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 // TODO(jhawkins): Use hidden instead of showInline* and display:none. | 5 // TODO(jhawkins): Use hidden instead of showInline* and display:none. |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * Sets the display style of a node. | 8 * Sets the display style of a node. |
| 9 */ | 9 */ |
| 10 function showInline(node, isShow) { | 10 function showInline(node, isShow) { |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 */ | 104 */ |
| 105 Downloads.prototype.setSearchText = function(searchText) { | 105 Downloads.prototype.setSearchText = function(searchText) { |
| 106 this.searchText_ = searchText; | 106 this.searchText_ = searchText; |
| 107 }; | 107 }; |
| 108 | 108 |
| 109 /** | 109 /** |
| 110 * Update the summary block above the results | 110 * Update the summary block above the results |
| 111 */ | 111 */ |
| 112 Downloads.prototype.updateSummary = function() { | 112 Downloads.prototype.updateSummary = function() { |
| 113 if (this.searchText_) { | 113 if (this.searchText_) { |
| 114 this.summary_.textContent = localStrings.getStringF('searchresultsfor', | 114 this.summary_.textContent = loadTimeData.getStringF('searchresultsfor', |
| 115 this.searchText_); | 115 this.searchText_); |
| 116 } else { | 116 } else { |
| 117 this.summary_.textContent = localStrings.getString('downloads'); | 117 this.summary_.textContent = loadTimeData.getString('downloads'); |
| 118 } | 118 } |
| 119 | 119 |
| 120 var hasDownloads = false; | 120 var hasDownloads = false; |
| 121 for (var i in this.downloads_) { | 121 for (var i in this.downloads_) { |
| 122 hasDownloads = true; | 122 hasDownloads = true; |
| 123 break; | 123 break; |
| 124 } | 124 } |
| 125 }; | 125 }; |
| 126 | 126 |
| 127 /** | 127 /** |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 this.nodeURL_ = createElementWithClassName('a', 'src-url'); | 282 this.nodeURL_ = createElementWithClassName('a', 'src-url'); |
| 283 this.nodeURL_.target = '_blank'; | 283 this.nodeURL_.target = '_blank'; |
| 284 nodeURLDiv.appendChild(this.nodeURL_); | 284 nodeURLDiv.appendChild(this.nodeURL_); |
| 285 | 285 |
| 286 // Controls. | 286 // Controls. |
| 287 this.nodeControls_ = createElementWithClassName('div', 'controls'); | 287 this.nodeControls_ = createElementWithClassName('div', 'controls'); |
| 288 this.safe_.appendChild(this.nodeControls_); | 288 this.safe_.appendChild(this.nodeControls_); |
| 289 | 289 |
| 290 // We don't need 'show in folder' in chromium os. See download_ui.cc and | 290 // We don't need 'show in folder' in chromium os. See download_ui.cc and |
| 291 // http://code.google.com/p/chromium-os/issues/detail?id=916. | 291 // http://code.google.com/p/chromium-os/issues/detail?id=916. |
| 292 var showinfolder = localStrings.getString('control_showinfolder'); | 292 if (loadTimeData.valueExists('control_showinfolder')) { |
| 293 if (showinfolder) { | 293 this.controlShow_ = createLink(this.show_.bind(this), |
| 294 this.controlShow_ = createLink(this.show_.bind(this), showinfolder); | 294 loadTimeData.getString('control_showinfolder')); |
| 295 this.nodeControls_.appendChild(this.controlShow_); | 295 this.nodeControls_.appendChild(this.controlShow_); |
| 296 } else { | 296 } else { |
| 297 this.controlShow_ = null; | 297 this.controlShow_ = null; |
| 298 } | 298 } |
| 299 | 299 |
| 300 this.controlRetry_ = document.createElement('a'); | 300 this.controlRetry_ = document.createElement('a'); |
| 301 this.controlRetry_.textContent = localStrings.getString('control_retry'); | 301 this.controlRetry_.textContent = loadTimeData.getString('control_retry'); |
| 302 this.nodeControls_.appendChild(this.controlRetry_); | 302 this.nodeControls_.appendChild(this.controlRetry_); |
| 303 | 303 |
| 304 // Pause/Resume are a toggle. | 304 // Pause/Resume are a toggle. |
| 305 this.controlPause_ = createLink(this.togglePause_.bind(this), | 305 this.controlPause_ = createLink(this.togglePause_.bind(this), |
| 306 localStrings.getString('control_pause')); | 306 loadTimeData.getString('control_pause')); |
| 307 this.nodeControls_.appendChild(this.controlPause_); | 307 this.nodeControls_.appendChild(this.controlPause_); |
| 308 | 308 |
| 309 this.controlResume_ = createLink(this.togglePause_.bind(this), | 309 this.controlResume_ = createLink(this.togglePause_.bind(this), |
| 310 localStrings.getString('control_resume')); | 310 loadTimeData.getString('control_resume')); |
| 311 this.nodeControls_.appendChild(this.controlResume_); | 311 this.nodeControls_.appendChild(this.controlResume_); |
| 312 | 312 |
| 313 this.controlRemove_ = createLink(this.remove_.bind(this), | 313 this.controlRemove_ = createLink(this.remove_.bind(this), |
| 314 localStrings.getString('control_removefromlist')); | 314 loadTimeData.getString('control_removefromlist')); |
| 315 this.nodeControls_.appendChild(this.controlRemove_); | 315 this.nodeControls_.appendChild(this.controlRemove_); |
| 316 | 316 |
| 317 this.controlCancel_ = createLink(this.cancel_.bind(this), | 317 this.controlCancel_ = createLink(this.cancel_.bind(this), |
| 318 localStrings.getString('control_cancel')); | 318 loadTimeData.getString('control_cancel')); |
| 319 this.nodeControls_.appendChild(this.controlCancel_); | 319 this.nodeControls_.appendChild(this.controlCancel_); |
| 320 | 320 |
| 321 // Container for 'unsafe download' UI. | 321 // Container for 'unsafe download' UI. |
| 322 this.danger_ = createElementWithClassName('div', 'show-dangerous'); | 322 this.danger_ = createElementWithClassName('div', 'show-dangerous'); |
| 323 this.node.appendChild(this.danger_); | 323 this.node.appendChild(this.danger_); |
| 324 | 324 |
| 325 this.dangerDesc_ = document.createElement('div'); | 325 this.dangerDesc_ = document.createElement('div'); |
| 326 this.danger_.appendChild(this.dangerDesc_); | 326 this.danger_.appendChild(this.dangerDesc_); |
| 327 | 327 |
| 328 this.dangerSave_ = createButton(this.saveDangerous_.bind(this), | 328 this.dangerSave_ = createButton(this.saveDangerous_.bind(this), |
| 329 localStrings.getString('danger_save')); | 329 loadTimeData.getString('danger_save')); |
| 330 this.danger_.appendChild(this.dangerSave_); | 330 this.danger_.appendChild(this.dangerSave_); |
| 331 | 331 |
| 332 this.dangerDiscard_ = createButton(this.discardDangerous_.bind(this), | 332 this.dangerDiscard_ = createButton(this.discardDangerous_.bind(this), |
| 333 localStrings.getString('danger_discard')); | 333 loadTimeData.getString('danger_discard')); |
| 334 this.danger_.appendChild(this.dangerDiscard_); | 334 this.danger_.appendChild(this.dangerDiscard_); |
| 335 | 335 |
| 336 // Update member vars. | 336 // Update member vars. |
| 337 this.update(download); | 337 this.update(download); |
| 338 } | 338 } |
| 339 | 339 |
| 340 /** | 340 /** |
| 341 * The states a download can be in. These correspond to states defined in | 341 * The states a download can be in. These correspond to states defined in |
| 342 * DownloadsDOMHandler::CreateDownloadItemValue | 342 * DownloadsDOMHandler::CreateDownloadItemValue |
| 343 */ | 343 */ |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 392 this.since_ = download.since_string; | 392 this.since_ = download.since_string; |
| 393 this.date_ = download.date_string; | 393 this.date_ = download.date_string; |
| 394 | 394 |
| 395 // See DownloadItem::PercentComplete | 395 // See DownloadItem::PercentComplete |
| 396 this.percent_ = Math.max(download.percent, 0); | 396 this.percent_ = Math.max(download.percent, 0); |
| 397 this.progressStatusText_ = download.progress_status_text; | 397 this.progressStatusText_ = download.progress_status_text; |
| 398 this.received_ = download.received; | 398 this.received_ = download.received; |
| 399 | 399 |
| 400 if (this.state_ == Download.States.DANGEROUS) { | 400 if (this.state_ == Download.States.DANGEROUS) { |
| 401 if (this.dangerType_ == Download.DangerType.DANGEROUS_FILE) { | 401 if (this.dangerType_ == Download.DangerType.DANGEROUS_FILE) { |
| 402 this.dangerDesc_.textContent = localStrings.getStringF('danger_file_desc', | 402 this.dangerDesc_.textContent = loadTimeData.getStringF('danger_file_desc', |
| 403 this.fileName_); | 403 this.fileName_); |
| 404 } else if (this.dangerType_ == Download.DangerType.DANGEROUS_URL) { | 404 } else if (this.dangerType_ == Download.DangerType.DANGEROUS_URL) { |
| 405 this.dangerDesc_.textContent = localStrings.getString('danger_url_desc'); | 405 this.dangerDesc_.textContent = loadTimeData.getString('danger_url_desc'); |
| 406 } else if (this.dangerType_ == Download.DangerType.DANGEROUS_CONTENT) { | 406 } else if (this.dangerType_ == Download.DangerType.DANGEROUS_CONTENT) { |
| 407 this.dangerDesc_.textContent = localStrings.getStringF( | 407 this.dangerDesc_.textContent = loadTimeData.getStringF( |
| 408 'danger_content_desc', this.fileName_); | 408 'danger_content_desc', this.fileName_); |
| 409 } else if (this.dangerType_ == Download.DangerType.UNCOMMON_CONTENT) { | 409 } else if (this.dangerType_ == Download.DangerType.UNCOMMON_CONTENT) { |
| 410 this.dangerDesc_.textContent = localStrings.getStringF( | 410 this.dangerDesc_.textContent = loadTimeData.getStringF( |
| 411 'danger_uncommon_desc', this.fileName_); | 411 'danger_uncommon_desc', this.fileName_); |
| 412 } | 412 } |
| 413 this.danger_.style.display = 'block'; | 413 this.danger_.style.display = 'block'; |
| 414 this.safe_.style.display = 'none'; | 414 this.safe_.style.display = 'none'; |
| 415 } else { | 415 } else { |
| 416 downloads.scheduleIconLoad(this.nodeImg_, | 416 downloads.scheduleIconLoad(this.nodeImg_, |
| 417 'chrome://fileicon/' + | 417 'chrome://fileicon/' + |
| 418 encodeURIComponent(this.filePath_)); | 418 encodeURIComponent(this.filePath_)); |
| 419 | 419 |
| 420 if (this.state_ == Download.States.COMPLETE && | 420 if (this.state_ == Download.States.COMPLETE && |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 517 | 517 |
| 518 /** | 518 /** |
| 519 * @private | 519 * @private |
| 520 * @return {string} User-visible status update text. | 520 * @return {string} User-visible status update text. |
| 521 */ | 521 */ |
| 522 Download.prototype.getStatusText_ = function() { | 522 Download.prototype.getStatusText_ = function() { |
| 523 switch (this.state_) { | 523 switch (this.state_) { |
| 524 case Download.States.IN_PROGRESS: | 524 case Download.States.IN_PROGRESS: |
| 525 return this.progressStatusText_; | 525 return this.progressStatusText_; |
| 526 case Download.States.CANCELLED: | 526 case Download.States.CANCELLED: |
| 527 return localStrings.getString('status_cancelled'); | 527 return loadTimeData.getString('status_cancelled'); |
| 528 case Download.States.PAUSED: | 528 case Download.States.PAUSED: |
| 529 return localStrings.getString('status_paused'); | 529 return loadTimeData.getString('status_paused'); |
| 530 case Download.States.DANGEROUS: | 530 case Download.States.DANGEROUS: |
| 531 // danger_url_desc is also used by DANGEROUS_CONTENT. | 531 // danger_url_desc is also used by DANGEROUS_CONTENT. |
| 532 var desc = this.dangerType_ == Download.DangerType.DANGEROUS_FILE ? | 532 var desc = this.dangerType_ == Download.DangerType.DANGEROUS_FILE ? |
| 533 'danger_file_desc' : 'danger_url_desc'; | 533 'danger_file_desc' : 'danger_url_desc'; |
| 534 return localStrings.getString(desc); | 534 return loadTimeData.getString(desc); |
| 535 case Download.States.INTERRUPTED: | 535 case Download.States.INTERRUPTED: |
| 536 return this.lastReasonDescription_; | 536 return this.lastReasonDescription_; |
| 537 case Download.States.COMPLETE: | 537 case Download.States.COMPLETE: |
| 538 return this.fileExternallyRemoved_ ? | 538 return this.fileExternallyRemoved_ ? |
| 539 localStrings.getString('status_removed') : ''; | 539 loadTimeData.getString('status_removed') : ''; |
| 540 } | 540 } |
| 541 }; | 541 }; |
| 542 | 542 |
| 543 /** | 543 /** |
| 544 * Tells the backend to initiate a drag, allowing users to drag | 544 * Tells the backend to initiate a drag, allowing users to drag |
| 545 * files from the download page and have them appear as native file | 545 * files from the download page and have them appear as native file |
| 546 * drags. | 546 * drags. |
| 547 * @private | 547 * @private |
| 548 */ | 548 */ |
| 549 Download.prototype.drag_ = function() { | 549 Download.prototype.drag_ = function() { |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 610 * Tells the backend to cancel this download. | 610 * Tells the backend to cancel this download. |
| 611 * @private | 611 * @private |
| 612 */ | 612 */ |
| 613 Download.prototype.cancel_ = function() { | 613 Download.prototype.cancel_ = function() { |
| 614 chrome.send('cancel', [this.id_.toString()]); | 614 chrome.send('cancel', [this.id_.toString()]); |
| 615 return false; | 615 return false; |
| 616 }; | 616 }; |
| 617 | 617 |
| 618 /////////////////////////////////////////////////////////////////////////////// | 618 /////////////////////////////////////////////////////////////////////////////// |
| 619 // Page: | 619 // Page: |
| 620 var downloads, localStrings, resultsTimeout; | 620 var downloads, resultsTimeout; |
| 621 | 621 |
| 622 // TODO(benjhayden): Rename Downloads to DownloadManager, downloads to | 622 // TODO(benjhayden): Rename Downloads to DownloadManager, downloads to |
| 623 // downloadManager or theDownloadManager or DownloadManager.get() to prevent | 623 // downloadManager or theDownloadManager or DownloadManager.get() to prevent |
| 624 // confusing Downloads with Download. | 624 // confusing Downloads with Download. |
| 625 | 625 |
| 626 /** | 626 /** |
| 627 * The FIFO array that stores updates of download files to be appeared | 627 * The FIFO array that stores updates of download files to be appeared |
| 628 * on the download page. It is guaranteed that the updates in this array | 628 * on the download page. It is guaranteed that the updates in this array |
| 629 * are reflected to the download page in a FIFO order. | 629 * are reflected to the download page in a FIFO order. |
| 630 */ | 630 */ |
| 631 var fifo_results; | 631 var fifo_results; |
| 632 | 632 |
| 633 function load() { | 633 function load() { |
| 634 chrome.send('onPageLoaded'); | 634 chrome.send('onPageLoaded'); |
| 635 fifo_results = new Array(); | 635 fifo_results = new Array(); |
| 636 localStrings = new LocalStrings(); | |
| 637 downloads = new Downloads(); | 636 downloads = new Downloads(); |
| 638 $('term').focus(); | 637 $('term').focus(); |
| 639 setSearch(''); | 638 setSearch(''); |
| 640 | 639 |
| 641 var clearAllLink = $('clear-all'); | 640 var clearAllLink = $('clear-all'); |
| 642 clearAllLink.onclick = clearAll; | 641 clearAllLink.onclick = clearAll; |
| 643 clearAllLink.oncontextmenu = function() { return false; }; | 642 clearAllLink.oncontextmenu = function() { return false; }; |
| 644 | 643 |
| 645 // TODO(jhawkins): Use a link-button here. | 644 // TODO(jhawkins): Use a link-button here. |
| 646 var openDownloadsFolderLink = $('open-downloads-folder'); | 645 var openDownloadsFolderLink = $('open-downloads-folder'); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 715 if (Date.now() - start > 50) { | 714 if (Date.now() - start > 50) { |
| 716 clearTimeout(resultsTimeout); | 715 clearTimeout(resultsTimeout); |
| 717 resultsTimeout = setTimeout(tryDownloadUpdatedPeriodically, 5); | 716 resultsTimeout = setTimeout(tryDownloadUpdatedPeriodically, 5); |
| 718 break; | 717 break; |
| 719 } | 718 } |
| 720 } | 719 } |
| 721 } | 720 } |
| 722 | 721 |
| 723 // Add handlers to HTML elements. | 722 // Add handlers to HTML elements. |
| 724 window.addEventListener('DOMContentLoaded', load); | 723 window.addEventListener('DOMContentLoaded', load); |
| OLD | NEW |