OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // Setting the src of an img to an empty string can crash the browser, so we | 5 // Setting the src of an img to an empty string can crash the browser, so we |
6 // use an empty 1x1 gif instead. | 6 // use an empty 1x1 gif instead. |
7 const EMPTY_IMAGE_URI = 'data:image/gif;base64,' | 7 const EMPTY_IMAGE_URI = 'data:image/gif;base64,' |
8 + 'R0lGODlhAQABAPABAP///wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw%3D%3D'; | 8 + 'R0lGODlhAQABAPABAP///wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw%3D%3D'; |
9 | 9 |
10 var g_slideshow_data = null; | 10 var g_slideshow_data = null; |
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
418 * Get the size of a file, caching the result. | 418 * Get the size of a file, caching the result. |
419 * | 419 * |
420 * When this method completes, the fileEntry object will get a | 420 * When this method completes, the fileEntry object will get a |
421 * 'cachedSize_' property (if it doesn't already have one) containing the | 421 * 'cachedSize_' property (if it doesn't already have one) containing the |
422 * size of the file in bytes. | 422 * size of the file in bytes. |
423 * | 423 * |
424 * @param {Entry} entry An HTML5 Entry object. | 424 * @param {Entry} entry An HTML5 Entry object. |
425 * @param {function(Entry)} successCallback The function to invoke once the | 425 * @param {function(Entry)} successCallback The function to invoke once the |
426 * file size is known. | 426 * file size is known. |
427 */ | 427 */ |
428 function cacheEntrySize(entry, successCallback, opt_errorCallback) { | 428 function cacheEntrySize(entry, successCallback, opt_errorCallback, opt_sync) { |
Vladislav Kaznacheev
2011/11/08 09:33:31
Please update JSDoc
dgozman
2011/11/14 09:59:26
Done.
| |
429 if (entry.isDirectory) { | 429 if (entry.isDirectory) { |
430 // No size for a directory, -1 ensures it's sorted before 0 length files. | 430 // No size for a directory, -1 ensures it's sorted before 0 length files. |
431 entry.cachedSize_ = -1; | 431 entry.cachedSize_ = -1; |
432 } | 432 } |
433 | 433 |
434 if ('cachedSize_' in entry) { | 434 if ('cachedSize_' in entry) { |
435 if (successCallback) { | 435 if (successCallback) { |
436 // Callback via a setTimeout so the sync/async semantics don't change | 436 // Callback via a setTimeout so the sync/async semantics don't change |
Vladislav Kaznacheev
2011/11/08 09:33:31
Comment is now obsolete here and below. Here is an
dgozman
2011/11/14 09:59:26
Done.
| |
437 // based on whether or not the value is cached. | 437 // based on whether or not the value is cached. |
438 setTimeout(function() { successCallback(entry) }, 0); | 438 if (opt_sync) { |
439 // If opt_sync, we are safe with synchronous call (which is faster). | |
440 successCallback(entry); | |
441 } else { | |
442 setTimeout(function() { successCallback(entry) }, 0); | |
443 } | |
439 } | 444 } |
440 return; | 445 return; |
441 } | 446 } |
442 | 447 |
443 batchAsyncCall(entry, 'file', function(file) { | 448 batchAsyncCall(entry, 'file', function(file) { |
444 entry.cachedSize_ = file.size; | 449 entry.cachedSize_ = file.size; |
445 if (successCallback) | 450 if (successCallback) |
446 successCallback(entry); | 451 successCallback(entry); |
447 }, opt_errorCallback); | 452 }, opt_errorCallback); |
448 } | 453 } |
449 | 454 |
450 /** | 455 /** |
451 * Get the mtime of a file, caching the result. | 456 * Get the mtime of a file, caching the result. |
452 * | 457 * |
453 * When this method completes, the fileEntry object will get a | 458 * When this method completes, the fileEntry object will get a |
454 * 'cachedMtime_' property (if it doesn't already have one) containing the | 459 * 'cachedMtime_' property (if it doesn't already have one) containing the |
455 * last modified time of the file as a Date object. | 460 * last modified time of the file as a Date object. |
456 * | 461 * |
457 * @param {Entry} entry An HTML5 Entry object. | 462 * @param {Entry} entry An HTML5 Entry object. |
458 * @param {function(Entry)} successCallback The function to invoke once the | 463 * @param {function(Entry)} successCallback The function to invoke once the |
459 * mtime is known. | 464 * mtime is known. |
460 */ | 465 */ |
461 function cacheEntryDate(entry, successCallback, opt_errorCallback) { | 466 function cacheEntryDate(entry, successCallback, opt_errorCallback, opt_sync) { |
Vladislav Kaznacheev
2011/11/08 09:33:32
Please update JSDoc
dgozman
2011/11/14 09:59:26
Done.
| |
462 if ('cachedMtime_' in entry) { | 467 if ('cachedMtime_' in entry) { |
463 if (successCallback) { | 468 if (successCallback) { |
464 // Callback via a setTimeout so the sync/async semantics don't change | 469 if (opt_sync) { |
465 // based on whether or not the value is cached. | 470 // We are safe to make synchronous callback. |
466 setTimeout(function() { successCallback(entry) }, 0); | 471 successCallback(entry); |
472 } else { | |
473 // Callback via a setTimeout so the sync/async semantics don't change | |
474 // based on whether or not the value is cached. | |
475 setTimeout(function() { successCallback(entry) }, 0); | |
476 } | |
467 } | 477 } |
468 return; | 478 return; |
469 } | 479 } |
470 | 480 |
471 if (entry.isFile) { | 481 if (entry.isFile) { |
472 batchAsyncCall(entry, 'file', function(file) { | 482 batchAsyncCall(entry, 'file', function(file) { |
473 entry.cachedMtime_ = file.lastModifiedDate; | 483 entry.cachedMtime_ = file.lastModifiedDate; |
474 if (successCallback) | 484 if (successCallback) |
475 successCallback(entry); | 485 successCallback(entry); |
476 }); | 486 }); |
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
755 /** | 765 /** |
756 * Get the file type of the entry, caching the result. | 766 * Get the file type of the entry, caching the result. |
757 * | 767 * |
758 * When this method completes, the entry object will get a | 768 * When this method completes, the entry object will get a |
759 * 'cachedIconType_' property (if it doesn't already have one) containing the | 769 * 'cachedIconType_' property (if it doesn't already have one) containing the |
760 * icon type of the file as a string. | 770 * icon type of the file as a string. |
761 * | 771 * |
762 * @param {Entry} entry An HTML5 Entry object. | 772 * @param {Entry} entry An HTML5 Entry object. |
763 * @param {function(Entry)} successCallback The function to invoke once the | 773 * @param {function(Entry)} successCallback The function to invoke once the |
764 * file size is known. | 774 * file size is known. |
775 * @param {boolean=} opt_sync If true, we are safe to do synchronous callback. | |
765 */ | 776 */ |
766 FileManager.prototype.cacheEntryFileType = function(entry, successCallback) { | 777 FileManager.prototype.cacheEntryFileType = function( |
778 entry, successCallback, opt_sync) { | |
767 this.getFileType(entry); | 779 this.getFileType(entry); |
768 | 780 |
769 if (successCallback) | 781 if (successCallback) { |
770 setTimeout(function() { successCallback(entry) }, 0); | 782 if (opt_sync) { |
783 successCallback(entry); | |
784 } else { | |
785 setTimeout(function() { successCallback(entry) }, 0); | |
786 } | |
787 } | |
771 }; | 788 }; |
772 | 789 |
773 /** | 790 /** |
774 * Compare by mtime first, then by name. | 791 * Compare by mtime first, then by name. |
775 */ | 792 */ |
776 FileManager.prototype.compareMtime_ = function(a, b) { | 793 FileManager.prototype.compareMtime_ = function(a, b) { |
777 if (a.cachedMtime_ > b.cachedMtime_) | 794 if (a.cachedMtime_ > b.cachedMtime_) |
778 return 1; | 795 return 1; |
779 | 796 |
780 if (a.cachedMtime_ < b.cachedMtime_) | 797 if (a.cachedMtime_ < b.cachedMtime_) |
(...skipping 764 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1545 */ | 1562 */ |
1546 FileManager.prototype.renderIconType_ = function(entry, columnId, table) { | 1563 FileManager.prototype.renderIconType_ = function(entry, columnId, table) { |
1547 var div = this.document_.createElement('div'); | 1564 var div = this.document_.createElement('div'); |
1548 div.className = 'detail-icon-container'; | 1565 div.className = 'detail-icon-container'; |
1549 | 1566 |
1550 if (this.showCheckboxes_) | 1567 if (this.showCheckboxes_) |
1551 div.appendChild(this.renderCheckbox_(entry)); | 1568 div.appendChild(this.renderCheckbox_(entry)); |
1552 | 1569 |
1553 var icon = this.document_.createElement('div'); | 1570 var icon = this.document_.createElement('div'); |
1554 icon.className = 'detail-icon'; | 1571 icon.className = 'detail-icon'; |
1555 this.cacheEntryIconType(entry); | 1572 this.getIconType(entry); |
1556 icon.setAttribute('iconType', entry.cachedIconType_); | 1573 icon.setAttribute('iconType', entry.cachedIconType_); |
1557 div.appendChild(icon); | 1574 div.appendChild(icon); |
1558 | 1575 |
1559 return div; | 1576 return div; |
1560 }; | 1577 }; |
1561 | 1578 |
1562 FileManager.prototype.getLabelForRootPath_ = function(path) { | 1579 FileManager.prototype.getLabelForRootPath_ = function(path) { |
1563 // This hack lets us localize the top level directories. | 1580 // This hack lets us localize the top level directories. |
1564 if (path == 'Downloads') | 1581 if (path == 'Downloads') |
1565 return str('DOWNLOADS_DIRECTORY_LABEL'); | 1582 return str('DOWNLOADS_DIRECTORY_LABEL'); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1606 var div = this.document_.createElement('div'); | 1623 var div = this.document_.createElement('div'); |
1607 div.className = 'detail-size'; | 1624 div.className = 'detail-size'; |
1608 | 1625 |
1609 div.textContent = '...'; | 1626 div.textContent = '...'; |
1610 cacheEntrySize(entry, function(entry) { | 1627 cacheEntrySize(entry, function(entry) { |
1611 if (entry.cachedSize_ == -1) { | 1628 if (entry.cachedSize_ == -1) { |
1612 div.textContent = ''; | 1629 div.textContent = ''; |
1613 } else { | 1630 } else { |
1614 div.textContent = util.bytesToSi(entry.cachedSize_); | 1631 div.textContent = util.bytesToSi(entry.cachedSize_); |
1615 } | 1632 } |
1616 }); | 1633 }, null, true); |
1617 | 1634 |
1618 return div; | 1635 return div; |
1619 }; | 1636 }; |
1620 | 1637 |
1621 /** | 1638 /** |
1622 * Render the Type column of the detail table. | 1639 * Render the Type column of the detail table. |
1623 * | 1640 * |
1624 * @param {Entry} entry The Entry object to render. | 1641 * @param {Entry} entry The Entry object to render. |
1625 * @param {string} columnId The id of the column to be rendered. | 1642 * @param {string} columnId The id of the column to be rendered. |
1626 * @param {cr.ui.Table} table The table doing the rendering. | 1643 * @param {cr.ui.Table} table The table doing the rendering. |
1627 */ | 1644 */ |
1628 FileManager.prototype.renderType_ = function(entry, columnId, table) { | 1645 FileManager.prototype.renderType_ = function(entry, columnId, table) { |
1629 var div = this.document_.createElement('div'); | 1646 var div = this.document_.createElement('div'); |
1630 div.className = 'detail-type'; | 1647 div.className = 'detail-type'; |
1631 | 1648 |
1632 div.textContent = '...'; | |
1633 this.cacheEntryFileType(entry, function(entry) { | 1649 this.cacheEntryFileType(entry, function(entry) { |
1634 var info = entry.cachedFileType_; | 1650 var info = entry.cachedFileType_; |
1635 if (info.name) { | 1651 if (info.name) { |
1636 if (info.subtype) | 1652 if (info.subtype) |
1637 div.textContent = strf(info.name, info.subtype); | 1653 div.textContent = strf(info.name, info.subtype); |
1638 else | 1654 else |
1639 div.textContent = str(info.name); | 1655 div.textContent = str(info.name); |
1640 } else | 1656 } else |
1641 div.textContent = ''; | 1657 div.textContent = ''; |
1642 }); | 1658 }, true); |
1643 | 1659 |
1644 return div; | 1660 return div; |
1645 }; | 1661 }; |
1646 | 1662 |
1647 /** | 1663 /** |
1648 * Render the Date column of the detail table. | 1664 * Render the Date column of the detail table. |
1649 * | 1665 * |
1650 * @param {Entry} entry The Entry object to render. | 1666 * @param {Entry} entry The Entry object to render. |
1651 * @param {string} columnId The id of the column to be rendered. | 1667 * @param {string} columnId The id of the column to be rendered. |
1652 * @param {cr.ui.Table} table The table doing the rendering. | 1668 * @param {cr.ui.Table} table The table doing the rendering. |
1653 */ | 1669 */ |
1654 FileManager.prototype.renderDate_ = function(entry, columnId, table) { | 1670 FileManager.prototype.renderDate_ = function(entry, columnId, table) { |
1655 var div = this.document_.createElement('div'); | 1671 var div = this.document_.createElement('div'); |
1656 div.className = 'detail-date'; | 1672 div.className = 'detail-date'; |
1657 | 1673 |
1658 div.textContent = '...'; | 1674 div.textContent = '...'; |
1659 | 1675 |
1660 var self = this; | 1676 var self = this; |
1661 cacheEntryDate(entry, function(entry) { | 1677 cacheEntryDate(entry, function(entry) { |
1662 if (isSystemDirEntry(self.currentDirEntry_) && | 1678 if (isSystemDirEntry(self.currentDirEntry_) && |
1663 entry.cachedMtime_.getTime() == 0) { | 1679 entry.cachedMtime_.getTime() == 0) { |
1664 // Mount points for FAT volumes have this time associated with them. | 1680 // Mount points for FAT volumes have this time associated with them. |
1665 // We'd rather display nothing than this bogus date. | 1681 // We'd rather display nothing than this bogus date. |
1666 div.textContent = ''; | 1682 div.textContent = ''; |
1667 } else { | 1683 } else { |
1668 div.textContent = self.shortDateFormatter_.format(entry.cachedMtime_); | 1684 div.textContent = self.shortDateFormatter_.format(entry.cachedMtime_); |
1669 } | 1685 } |
1670 }); | 1686 }, null, true); |
1671 | 1687 |
1672 return div; | 1688 return div; |
1673 }; | 1689 }; |
1674 | 1690 |
1675 /** | 1691 /** |
1676 * Compute summary information about the current selection. | 1692 * Compute summary information about the current selection. |
1677 * | 1693 * |
1678 * This method dispatches the 'selection-summarized' event when it completes. | 1694 * This method dispatches the 'selection-summarized' event when it completes. |
1679 * Depending on how many of the selected files already have known sizes, the | 1695 * Depending on how many of the selected files already have known sizes, the |
1680 * dispatch may happen immediately, or after a number of async calls complete. | 1696 * dispatch may happen immediately, or after a number of async calls complete. |
(...skipping 1901 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3582 | 3598 |
3583 if (msg) { | 3599 if (msg) { |
3584 console.log('no no no'); | 3600 console.log('no no no'); |
3585 this.alert.show(msg, onAccept); | 3601 this.alert.show(msg, onAccept); |
3586 return false; | 3602 return false; |
3587 } | 3603 } |
3588 | 3604 |
3589 return true; | 3605 return true; |
3590 }; | 3606 }; |
3591 })(); | 3607 })(); |
OLD | NEW |