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 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 }; | 222 }; |
223 | 223 |
224 const previewArt = { | 224 const previewArt = { |
225 'audio': 'images/filetype_large_audio.png', | 225 'audio': 'images/filetype_large_audio.png', |
226 'folder': 'images/filetype_large_folder.png', | 226 'folder': 'images/filetype_large_folder.png', |
227 'unknown': 'images/filetype_large_generic.png', | 227 'unknown': 'images/filetype_large_generic.png', |
228 'video': 'images/filetype_large_video.png' | 228 'video': 'images/filetype_large_video.png' |
229 }; | 229 }; |
230 | 230 |
231 /** | 231 /** |
| 232 * Regexp for archive files. Used to show mount-archive task. |
| 233 */ |
| 234 const ARCHIVES_REGEXP = /.zip$/; |
| 235 |
| 236 /** |
232 * Return a translated string. | 237 * Return a translated string. |
233 * | 238 * |
234 * Wrapper function to make dealing with translated strings more concise. | 239 * Wrapper function to make dealing with translated strings more concise. |
235 * Equivilant to localStrings.getString(id). | 240 * Equivilant to localStrings.getString(id). |
236 * | 241 * |
237 * @param {string} id The id of the string to return. | 242 * @param {string} id The id of the string to return. |
238 * @return {string} The translated string. | 243 * @return {string} The translated string. |
239 */ | 244 */ |
240 function str(id) { | 245 function str(id) { |
241 return localStrings.getString(id); | 246 return localStrings.getString(id); |
(...skipping 1283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1525 } | 1530 } |
1526 | 1531 |
1527 if (pendingFiles.length) { | 1532 if (pendingFiles.length) { |
1528 cacheEntrySize(pendingFiles.pop(), cacheNextFile); | 1533 cacheEntrySize(pendingFiles.pop(), cacheNextFile); |
1529 } else { | 1534 } else { |
1530 self.dispatchEvent(new cr.Event('selection-summarized')); | 1535 self.dispatchEvent(new cr.Event('selection-summarized')); |
1531 } | 1536 } |
1532 }; | 1537 }; |
1533 | 1538 |
1534 if (this.dialogType_ == FileManager.DialogType.FULL_PAGE) { | 1539 if (this.dialogType_ == FileManager.DialogType.FULL_PAGE) { |
1535 // Since unmount task cannot be defined in terms of file patterns, | |
1536 // we manually include it here, if all selected items are mount points. | |
1537 this.taskButtons_.innerHTML = ''; | 1540 this.taskButtons_.innerHTML = ''; |
1538 chrome.fileBrowserPrivate.getFileTasks( | 1541 // Some internal tasks cannot be defined in terms of file patterns, |
1539 selection.urls, | 1542 // so we pass selection to check for them manually. |
1540 this.onTasksFound_.bind(this, | 1543 if (selection.directoryCount == 0 && selection.fileCount > 0) { |
1541 this.shouldShowUnmount_(selection.urls))); | 1544 // Only files, not directories, are supported for external tasks. |
| 1545 chrome.fileBrowserPrivate.getFileTasks( |
| 1546 selection.urls, |
| 1547 this.onTasksFound_.bind(this, selection)); |
| 1548 } else { |
| 1549 // There may be internal tasks for directories. |
| 1550 this.onTasksFound_(selection, []); |
| 1551 } |
1542 } | 1552 } |
1543 | 1553 |
1544 cacheNextFile(); | 1554 cacheNextFile(); |
1545 }; | 1555 }; |
1546 | 1556 |
1547 FileManager.prototype.onMetadataResult_ = function(fileURL, metadata) { | 1557 FileManager.prototype.onMetadataResult_ = function(fileURL, metadata) { |
1548 var observers = this.metadataCache_[fileURL]; | 1558 var observers = this.metadataCache_[fileURL]; |
1549 if (!observers || !(observers instanceof Array)) { | 1559 if (!observers || !(observers instanceof Array)) { |
1550 console.error('Missing or invalid metadata observers: ' + fileURL + ': ' + | 1560 console.error('Missing or invalid metadata observers: ' + fileURL + ': ' + |
1551 observers); | 1561 observers); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1595 if (!(methodName in this)) { | 1605 if (!(methodName in this)) { |
1596 console.log('Unknown message from metadata reader: ' + data.verb, data); | 1606 console.log('Unknown message from metadata reader: ' + data.verb, data); |
1597 return; | 1607 return; |
1598 } | 1608 } |
1599 | 1609 |
1600 this[methodName].apply(this, data.arguments); | 1610 this[methodName].apply(this, data.arguments); |
1601 }; | 1611 }; |
1602 | 1612 |
1603 /** | 1613 /** |
1604 * Callback called when tasks for selected files are determined. | 1614 * Callback called when tasks for selected files are determined. |
1605 * @param {boolean} unmount Whether unmount task should be included. | 1615 * @param {Object} selection Selection is passed here, since this.selection |
| 1616 * can change before tasks were found, and we should be accurate. |
1606 * @param {Array.<Task>} tasksList The tasks list. | 1617 * @param {Array.<Task>} tasksList The tasks list. |
1607 */ | 1618 */ |
1608 FileManager.prototype.onTasksFound_ = function(unmount, tasksList) { | 1619 FileManager.prototype.onTasksFound_ = function(selection, tasksList) { |
1609 if (unmount) { | |
1610 tasksList.push({ | |
1611 taskId: this.getExtensionId_() + '|unmount-archive', | |
1612 iconUrl: '', | |
1613 title: '' | |
1614 }); | |
1615 } | |
1616 for (var i = 0; i < tasksList.length; i++) { | 1620 for (var i = 0; i < tasksList.length; i++) { |
1617 var task = tasksList[i]; | 1621 var task = tasksList[i]; |
1618 | 1622 |
1619 // Tweak images, titles of internal tasks. | 1623 // Tweak images, titles of internal tasks. |
1620 var task_parts = task.taskId.split('|'); | 1624 var task_parts = task.taskId.split('|'); |
1621 if (task_parts[0] == this.getExtensionId_()) { | 1625 if (task_parts[0] == this.getExtensionId_()) { |
1622 if (task_parts[1] == 'preview') { | 1626 if (task_parts[1] == 'preview') { |
1623 // TODO(serya): This hack needed until task.iconUrl get working | 1627 // TODO(serya): This hack needed until task.iconUrl get working |
1624 // (see GetFileTasksFileBrowserFunction::RunImpl). | 1628 // (see GetFileTasksFileBrowserFunction::RunImpl). |
1625 task.iconUrl = | 1629 task.iconUrl = |
1626 chrome.extension.getURL('images/icon_preview_16x16.png'); | 1630 chrome.extension.getURL('images/icon_preview_16x16.png'); |
1627 task.title = str('PREVIEW_IMAGE'); | 1631 task.title = str('PREVIEW_IMAGE'); |
1628 } else if (task_parts[1] == 'edit') { | 1632 } else if (task_parts[1] == 'edit') { |
1629 task.iconUrl = | 1633 task.iconUrl = |
1630 chrome.extension.getURL('images/icon_preview_16x16.png'); | 1634 chrome.extension.getURL('images/icon_preview_16x16.png'); |
1631 task.title = 'Edit'; | 1635 task.title = 'Edit'; |
1632 if (!IMAGE_EDITOR_ENABLED) continue; // Skip the button creation. | 1636 if (!IMAGE_EDITOR_ENABLED) continue; // Skip the button creation. |
1633 } else if (task_parts[1] == 'play') { | 1637 } else if (task_parts[1] == 'play') { |
1634 task.iconUrl = | 1638 task.iconUrl = |
1635 chrome.extension.getURL('images/icon_play_16x16.png'); | 1639 chrome.extension.getURL('images/icon_play_16x16.png'); |
1636 task.title = str('PLAY_MEDIA').replace("&", ""); | 1640 task.title = str('PLAY_MEDIA').replace("&", ""); |
1637 } else if (task_parts[1] == 'enqueue') { | 1641 } else if (task_parts[1] == 'enqueue') { |
1638 task.iconUrl = | 1642 task.iconUrl = |
1639 chrome.extension.getURL('images/icon_add_to_queue_16x16.png'); | 1643 chrome.extension.getURL('images/icon_add_to_queue_16x16.png'); |
1640 task.title = str('ENQUEUE'); | 1644 task.title = str('ENQUEUE'); |
1641 } else if (task_parts[1] == 'mount-archive') { | 1645 } else if (task_parts[1] == 'mount-archive') { |
1642 task.iconUrl = | 1646 task.iconUrl = |
1643 chrome.extension.getURL('images/icon_mount_archive_16x16.png'); | 1647 chrome.extension.getURL('images/icon_mount_archive_16x16.png'); |
1644 task.title = str('MOUNT_ARCHIVE'); | 1648 task.title = str('MOUNT_ARCHIVE'); |
1645 } else if (task_parts[1] == 'unmount-archive') { | |
1646 task.iconUrl = | |
1647 chrome.extension.getURL('images/icon_unmount_archive_16x16.png'); | |
1648 task.title = str('UNMOUNT_ARCHIVE'); | |
1649 } | 1649 } |
1650 } | 1650 } |
1651 this.renderTaskButton_(task); | 1651 this.renderTaskButton_(task); |
1652 } | 1652 } |
1653 // This needs to be done in sparate function, as check requires | 1653 this.maybeRenderUnmountTask_(selection); |
| 1654 // This needs to be done in separate function, as check requires |
1654 // asynchronous function calls. | 1655 // asynchronous function calls. |
1655 this.maybeRenderFormattingTask_(); | 1656 this.maybeRenderFormattingTask_(selection); |
1656 }; | 1657 }; |
1657 | 1658 |
1658 FileManager.prototype.renderTaskButton_ = function(task) { | 1659 FileManager.prototype.renderTaskButton_ = function(task) { |
1659 var button = this.document_.createElement('button'); | 1660 var button = this.document_.createElement('button'); |
1660 button.addEventListener('click', this.onTaskButtonClicked_.bind(this)); | 1661 button.addEventListener('click', this.onTaskButtonClicked_.bind(this)); |
1661 button.className = 'task-button'; | 1662 button.className = 'task-button'; |
1662 button.task = task; | 1663 button.task = task; |
1663 | 1664 |
1664 var img = this.document_.createElement('img'); | 1665 var img = this.document_.createElement('img'); |
1665 img.src = task.iconUrl; | 1666 img.src = task.iconUrl; |
1666 | 1667 |
1667 button.appendChild(img); | 1668 button.appendChild(img); |
1668 button.appendChild(this.document_.createTextNode(task.title)); | 1669 button.appendChild(this.document_.createTextNode(task.title)); |
1669 | 1670 |
1670 this.taskButtons_.appendChild(button); | 1671 this.taskButtons_.appendChild(button); |
1671 }; | 1672 }; |
1672 | 1673 |
1673 /** | 1674 /** |
| 1675 * Checks whether unmount task should be displayed and if the answer is |
| 1676 * affirmative renders it. |
| 1677 * @param {Object} selection Selected files object. |
| 1678 */ |
| 1679 FileManager.prototype.maybeRenderUnmountTask_ = function(selection) { |
| 1680 for (var index = 0; index < selection.urls.length; ++index) { |
| 1681 // Each url should be a mount point. |
| 1682 var path = selection.urls[index]; |
| 1683 if (!this.mountPoints_.hasOwnProperty(path) || |
| 1684 this.mountPoints_[path].type != 'file') |
| 1685 return; |
| 1686 } |
| 1687 this.renderTaskButton_({ |
| 1688 taskId: this.getExtensionId_() + '|unmount-archive', |
| 1689 iconUrl: |
| 1690 chrome.extension.getURL('images/icon_unmount_archive_16x16.png'), |
| 1691 title: str('UNMOUNT_ARCHIVE') |
| 1692 }); |
| 1693 }; |
| 1694 |
| 1695 /** |
1674 * Checks whether formatting task should be displayed and if the answer is | 1696 * Checks whether formatting task should be displayed and if the answer is |
1675 * affirmative renders it. Includes asynchronous calls, so it's splitted into | 1697 * affirmative renders it. Includes asynchronous calls, so it's splitted into |
1676 * three parts. | 1698 * three parts. |
| 1699 * @param {Object} selection Selected files object. |
1677 */ | 1700 */ |
1678 FileManager.prototype.maybeRenderFormattingTask_ = function() { | 1701 FileManager.prototype.maybeRenderFormattingTask_ = function(selection) { |
1679 // Not to make unnecesary getMountPoints() call we doublecheck if there is | 1702 // Not to make unnecessary getMountPoints() call we doublecheck if there is |
1680 // only one selected entry. | 1703 // only one selected entry. |
1681 if (this.selection.entries.length != 1) | 1704 if (selection.entries.length != 1) |
1682 return; | 1705 return; |
1683 var self = this; | 1706 var self = this; |
1684 function onMountPointsFound(mountPoints) { | 1707 function onMountPointsFound(mountPoints) { |
1685 self.mountPoints_ = mountPoints; | 1708 self.mountPoints_ = mountPoints; |
1686 | 1709 |
1687 function normalize(x) { | 1710 function normalize(x) { |
1688 if (x[0] == '/') | 1711 if (x[0] == '/') |
1689 return x.slice(1); | 1712 return x.slice(1); |
1690 else | 1713 else |
1691 return x; | 1714 return x; |
1692 } | 1715 } |
1693 | 1716 |
1694 function onVolumeMetadataFound(volumeMetadata) { | 1717 function onVolumeMetadataFound(volumeMetadata) { |
1695 if (volumeMetadata.deviceType == "flash") { | 1718 if (volumeMetadata.deviceType == "flash") { |
1696 if (self.selection.entries.length != 1 || | 1719 if (selection.entries.length != 1 || |
1697 normalize(self.selection.entries[0].fullPath) != | 1720 normalize(selection.entries[0].fullPath) != |
1698 normalize(volumeMetadata.mountPath)) { | 1721 normalize(volumeMetadata.mountPath)) { |
1699 return; | 1722 return; |
1700 } | 1723 } |
1701 var task = { | 1724 var task = { |
1702 taskId: self.getExtensionId_() + '|format-device', | 1725 taskId: self.getExtensionId_() + '|format-device', |
1703 iconUrl: chrome.extension.getURL('images/filetype_generic.png'), | 1726 iconUrl: chrome.extension.getURL('images/filetype_generic.png'), |
1704 title: str('FORMAT_DEVICE') | 1727 title: str('FORMAT_DEVICE') |
1705 }; | 1728 }; |
1706 self.renderTaskButton_(task); | 1729 self.renderTaskButton_(task); |
1707 } | 1730 } |
1708 } | 1731 } |
1709 | 1732 |
1710 if (self.selection.entries.length != 1) | 1733 if (selection.entries.length != 1) |
1711 return; | 1734 return; |
1712 var selectedPath = self.selection.entries[0].fullPath; | 1735 var selectedPath = selection.entries[0].fullPath; |
1713 for (var i = 0; i < mountPoints.length; i++) { | 1736 for (var i = 0; i < mountPoints.length; i++) { |
1714 if (mountPoints[i].mountType == "device" && | 1737 if (mountPoints[i].mountType == "device" && |
1715 normalize(mountPoints[i].mountPath) == normalize(selectedPath)) { | 1738 normalize(mountPoints[i].mountPath) == normalize(selectedPath)) { |
1716 chrome.fileBrowserPrivate.getVolumeMetadata(mountPoints[i].sourceUrl, | 1739 chrome.fileBrowserPrivate.getVolumeMetadata(mountPoints[i].sourceUrl, |
1717 onVolumeMetadataFound); | 1740 onVolumeMetadataFound); |
1718 return; | 1741 return; |
1719 } | 1742 } |
1720 } | 1743 } |
1721 } | 1744 } |
1722 | 1745 |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1796 for (var index = 0; index < urls.length; ++index) { | 1819 for (var index = 0; index < urls.length; ++index) { |
1797 chrome.fileBrowserPrivate.removeMount(urls[index]); | 1820 chrome.fileBrowserPrivate.removeMount(urls[index]); |
1798 } | 1821 } |
1799 } else if (id == 'format-device') { | 1822 } else if (id == 'format-device') { |
1800 this.confirm.show(str('FORMATTING_WARNING'), function() { | 1823 this.confirm.show(str('FORMATTING_WARNING'), function() { |
1801 chrome.fileBrowserPrivate.formatDevice(urls[0]); | 1824 chrome.fileBrowserPrivate.formatDevice(urls[0]); |
1802 }); | 1825 }); |
1803 } | 1826 } |
1804 }; | 1827 }; |
1805 | 1828 |
1806 /** | |
1807 * Determines whether unmount task should present for selected files. | |
1808 */ | |
1809 FileManager.prototype.shouldShowUnmount_ = function(urls) { | |
1810 for (var index = 0; index < urls.length; ++index) { | |
1811 // Each url should be a mount point. | |
1812 var path = urls[index]; | |
1813 if (!this.mountPoints_.hasOwnProperty(path) || | |
1814 this.mountPoints_[path].type != 'file') { | |
1815 return false; | |
1816 } | |
1817 } | |
1818 return true; | |
1819 }; | |
1820 | |
1821 FileManager.prototype.openImageEditor_ = function(entry) { | 1829 FileManager.prototype.openImageEditor_ = function(entry) { |
1822 var self = this; | 1830 var self = this; |
1823 | 1831 |
1824 var editorFrame = this.document_.createElement('iframe'); | 1832 var editorFrame = this.document_.createElement('iframe'); |
1825 editorFrame.className = 'overlay-pane'; | 1833 editorFrame.className = 'overlay-pane'; |
1826 editorFrame.scrolling = 'no'; | 1834 editorFrame.scrolling = 'no'; |
1827 | 1835 |
1828 editorFrame.onload = function() { | 1836 editorFrame.onload = function() { |
1829 self.cacheMetadata_(entry, function(metadata) { | 1837 self.cacheMetadata_(entry, function(metadata) { |
1830 editorFrame.contentWindow.ImageEditor.open( | 1838 editorFrame.contentWindow.ImageEditor.open( |
(...skipping 1306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3137 | 3145 |
3138 if (msg) { | 3146 if (msg) { |
3139 console.log('no no no'); | 3147 console.log('no no no'); |
3140 this.alert.show(msg, onAccept); | 3148 this.alert.show(msg, onAccept); |
3141 return false; | 3149 return false; |
3142 } | 3150 } |
3143 | 3151 |
3144 return true; | 3152 return true; |
3145 }; | 3153 }; |
3146 })(); | 3154 })(); |
OLD | NEW |