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 1498 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1509 if (pendingFiles.length) { | 1509 if (pendingFiles.length) { |
1510 cacheEntrySize(pendingFiles.pop(), cacheNextFile); | 1510 cacheEntrySize(pendingFiles.pop(), cacheNextFile); |
1511 } else { | 1511 } else { |
1512 self.dispatchEvent(new cr.Event('selection-summarized')); | 1512 self.dispatchEvent(new cr.Event('selection-summarized')); |
1513 } | 1513 } |
1514 }; | 1514 }; |
1515 | 1515 |
1516 if (this.dialogType_ == FileManager.DialogType.FULL_PAGE) { | 1516 if (this.dialogType_ == FileManager.DialogType.FULL_PAGE) { |
1517 // Since unmount task cannot be defined in terms of file patterns, | 1517 // Since unmount task cannot be defined in terms of file patterns, |
1518 // we manually include it here, if all selected items are mount points. | 1518 // we manually include it here, if all selected items are mount points. |
| 1519 this.taskButtons_.innerHTML = ''; |
1519 chrome.fileBrowserPrivate.getFileTasks( | 1520 chrome.fileBrowserPrivate.getFileTasks( |
1520 selection.urls, | 1521 selection.urls, |
1521 this.onTasksFound_.bind(this, | 1522 this.onTasksFound_.bind(this, |
1522 this.shouldShowUnmount_(selection.urls))); | 1523 this.shouldShowUnmount_(selection.urls))); |
1523 } | 1524 } |
1524 | 1525 |
1525 cacheNextFile(); | 1526 cacheNextFile(); |
1526 }; | 1527 }; |
1527 | 1528 |
1528 FileManager.prototype.onMetadataResult_ = function(fileURL, metadata) { | 1529 FileManager.prototype.onMetadataResult_ = function(fileURL, metadata) { |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1587 * @param {Array.<Task>} tasksList The tasks list. | 1588 * @param {Array.<Task>} tasksList The tasks list. |
1588 */ | 1589 */ |
1589 FileManager.prototype.onTasksFound_ = function(unmount, tasksList) { | 1590 FileManager.prototype.onTasksFound_ = function(unmount, tasksList) { |
1590 if (unmount) { | 1591 if (unmount) { |
1591 tasksList.push({ | 1592 tasksList.push({ |
1592 taskId: this.getExtensionId_() + '|unmount-archive', | 1593 taskId: this.getExtensionId_() + '|unmount-archive', |
1593 iconUrl: '', | 1594 iconUrl: '', |
1594 title: '' | 1595 title: '' |
1595 }); | 1596 }); |
1596 } | 1597 } |
1597 | |
1598 this.taskButtons_.innerHTML = ''; | |
1599 for (var i = 0; i < tasksList.length; i++) { | 1598 for (var i = 0; i < tasksList.length; i++) { |
1600 var task = tasksList[i]; | 1599 var task = tasksList[i]; |
1601 | 1600 |
1602 // Tweak images, titles of internal tasks. | 1601 // Tweak images, titles of internal tasks. |
1603 var task_parts = task.taskId.split('|'); | 1602 var task_parts = task.taskId.split('|'); |
1604 if (task_parts[0] == this.getExtensionId_()) { | 1603 if (task_parts[0] == this.getExtensionId_()) { |
1605 if (task_parts[1] == 'preview') { | 1604 if (task_parts[1] == 'preview') { |
1606 // TODO(serya): This hack needed until task.iconUrl get working | 1605 // TODO(serya): This hack needed until task.iconUrl get working |
1607 // (see GetFileTasksFileBrowserFunction::RunImpl). | 1606 // (see GetFileTasksFileBrowserFunction::RunImpl). |
1608 task.iconUrl = | 1607 task.iconUrl = |
(...skipping 15 matching lines...) Expand all Loading... |
1624 } else if (task_parts[1] == 'mount-archive') { | 1623 } else if (task_parts[1] == 'mount-archive') { |
1625 task.iconUrl = | 1624 task.iconUrl = |
1626 chrome.extension.getURL('images/icon_mount_archive_16x16.png'); | 1625 chrome.extension.getURL('images/icon_mount_archive_16x16.png'); |
1627 task.title = str('MOUNT_ARCHIVE'); | 1626 task.title = str('MOUNT_ARCHIVE'); |
1628 } else if (task_parts[1] == 'unmount-archive') { | 1627 } else if (task_parts[1] == 'unmount-archive') { |
1629 task.iconUrl = | 1628 task.iconUrl = |
1630 chrome.extension.getURL('images/icon_unmount_archive_16x16.png'); | 1629 chrome.extension.getURL('images/icon_unmount_archive_16x16.png'); |
1631 task.title = str('UNMOUNT_ARCHIVE'); | 1630 task.title = str('UNMOUNT_ARCHIVE'); |
1632 } | 1631 } |
1633 } | 1632 } |
| 1633 this.renderTaskButton_(task); |
| 1634 } |
| 1635 // This needs to be done in sparate function, as check requires |
| 1636 // asynchronous function calls. |
| 1637 this.maybeRenderFormattingTask_(); |
| 1638 }; |
1634 | 1639 |
1635 var button = this.document_.createElement('button'); | 1640 FileManager.prototype.renderTaskButton_ = function(task) { |
1636 button.addEventListener('click', this.onTaskButtonClicked_.bind(this)); | 1641 var button = this.document_.createElement('button'); |
1637 button.className = 'task-button'; | 1642 button.addEventListener('click', this.onTaskButtonClicked_.bind(this)); |
1638 button.task = task; | 1643 button.className = 'task-button'; |
| 1644 button.task = task; |
1639 | 1645 |
1640 var img = this.document_.createElement('img'); | 1646 var img = this.document_.createElement('img'); |
1641 img.src = task.iconUrl; | 1647 img.src = task.iconUrl; |
1642 | 1648 |
1643 button.appendChild(img); | 1649 button.appendChild(img); |
1644 button.appendChild(this.document_.createTextNode(task.title)); | 1650 button.appendChild(this.document_.createTextNode(task.title)); |
1645 | 1651 |
1646 this.taskButtons_.appendChild(button); | 1652 this.taskButtons_.appendChild(button); |
| 1653 }; |
| 1654 |
| 1655 /** |
| 1656 * Checks whether formatting task should be displayed and if the answer is |
| 1657 * affirmative renders it. Includes asynchronous calls, so it's splitted into |
| 1658 * three parts. |
| 1659 */ |
| 1660 FileManager.prototype.maybeRenderFormattingTask_ = function() { |
| 1661 // Not to make unnecesary getMountPoints() call we doublecheck if there is |
| 1662 // only one selected entry. |
| 1663 if (this.selection.entries.length != 1) |
| 1664 return; |
| 1665 var self = this; |
| 1666 function onMountPointsFound(mountPoints) { |
| 1667 self.mountPoints_ = mountPoints; |
| 1668 |
| 1669 function normalize(x) { |
| 1670 if (x[0] == '/') |
| 1671 return x.slice(1); |
| 1672 else |
| 1673 return x; |
| 1674 } |
| 1675 |
| 1676 function onVolumeMetadataFound(volumeMetadata) { |
| 1677 if (volumeMetadata.deviceType == "flash") { |
| 1678 if (self.selection.entries.length != 1 || |
| 1679 normalize(self.selection.entries[0].fullPath) != |
| 1680 normalize(volumeMetadata.mountPath)) { |
| 1681 return; |
| 1682 } |
| 1683 var task = { |
| 1684 taskId: self.getExtensionId_() + '|format-device', |
| 1685 iconUrl: chrome.extension.getURL('images/filetype_generic.png'), |
| 1686 title: str('FORMAT_DEVICE') |
| 1687 }; |
| 1688 self.renderTaskButton_(task); |
| 1689 } |
| 1690 } |
| 1691 |
| 1692 if (self.selection.entries.length != 1) |
| 1693 return; |
| 1694 var selectedPath = self.selection.entries[0].fullPath; |
| 1695 for (var i = 0; i < mountPoints.length; i++) { |
| 1696 if (mountPoints[i].mountType == "device" && |
| 1697 normalize(mountPoints[i].mountPath) == normalize(selectedPath)) { |
| 1698 chrome.fileBrowserPrivate.getVolumeMetadata(mountPoints[i].sourceUrl, |
| 1699 onVolumeMetadataFound); |
| 1700 return; |
| 1701 } |
| 1702 } |
1647 } | 1703 } |
| 1704 |
| 1705 chrome.fileBrowserPrivate.getMountPoints(onMountPointsFound); |
1648 }; | 1706 }; |
1649 | 1707 |
1650 FileManager.prototype.getExtensionId_ = function() { | 1708 FileManager.prototype.getExtensionId_ = function() { |
1651 return chrome.extension.getURL('').split('/')[2]; | 1709 return chrome.extension.getURL('').split('/')[2]; |
1652 }; | 1710 }; |
1653 | 1711 |
1654 FileManager.prototype.onTaskButtonClicked_ = function(event) { | 1712 FileManager.prototype.onTaskButtonClicked_ = function(event) { |
1655 chrome.fileBrowserPrivate.executeTask(event.srcElement.task.taskId, | 1713 chrome.fileBrowserPrivate.executeTask(event.srcElement.task.taskId, |
1656 this.selection.urls); | 1714 this.selection.urls); |
1657 }; | 1715 }; |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1713 chrome.fileBrowserPrivate.viewFiles(urls, id); | 1771 chrome.fileBrowserPrivate.viewFiles(urls, id); |
1714 } else if (id == 'mount-archive') { | 1772 } else if (id == 'mount-archive') { |
1715 for (var index = 0; index < urls.length; ++index) { | 1773 for (var index = 0; index < urls.length; ++index) { |
1716 this.mountRequests_.push(urls[index]); | 1774 this.mountRequests_.push(urls[index]); |
1717 chrome.fileBrowserPrivate.addMount(urls[index], 'file', {}); | 1775 chrome.fileBrowserPrivate.addMount(urls[index], 'file', {}); |
1718 } | 1776 } |
1719 } else if (id == 'unmount-archive') { | 1777 } else if (id == 'unmount-archive') { |
1720 for (var index = 0; index < urls.length; ++index) { | 1778 for (var index = 0; index < urls.length; ++index) { |
1721 chrome.fileBrowserPrivate.removeMount(urls[index]); | 1779 chrome.fileBrowserPrivate.removeMount(urls[index]); |
1722 } | 1780 } |
| 1781 } else if (id == 'format-device') { |
| 1782 this.confirm.show(str('FORMATTING_WARNING'), function() { |
| 1783 chrome.fileBrowserPrivate.formatDevice(urls[0]); |
| 1784 }); |
1723 } | 1785 } |
1724 }; | 1786 }; |
1725 | 1787 |
1726 /** | 1788 /** |
1727 * Determines whether unmount task should present for selected files. | 1789 * Determines whether unmount task should present for selected files. |
1728 */ | 1790 */ |
1729 FileManager.prototype.shouldShowUnmount_ = function(urls) { | 1791 FileManager.prototype.shouldShowUnmount_ = function(urls) { |
1730 for (var index = 0; index < urls.length; ++index) { | 1792 for (var index = 0; index < urls.length; ++index) { |
1731 // Each url should be a mount point. | 1793 // Each url should be a mount point. |
1732 var path = urls[index]; | 1794 var path = urls[index]; |
(...skipping 1337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3070 | 3132 |
3071 if (msg) { | 3133 if (msg) { |
3072 console.log('no no no'); | 3134 console.log('no no no'); |
3073 this.alert.show(msg, onAccept); | 3135 this.alert.show(msg, onAccept); |
3074 return false; | 3136 return false; |
3075 } | 3137 } |
3076 | 3138 |
3077 return true; | 3139 return true; |
3078 }; | 3140 }; |
3079 })(); | 3141 })(); |
OLD | NEW |