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 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 }; | 229 }; |
230 | 230 |
231 const previewArt = { | 231 const previewArt = { |
232 'audio': 'images/filetype_large_audio.png', | 232 'audio': 'images/filetype_large_audio.png', |
233 'folder': 'images/filetype_large_folder.png', | 233 'folder': 'images/filetype_large_folder.png', |
234 'unknown': 'images/filetype_large_generic.png', | 234 'unknown': 'images/filetype_large_generic.png', |
235 'video': 'images/filetype_large_video.png' | 235 'video': 'images/filetype_large_video.png' |
236 }; | 236 }; |
237 | 237 |
238 /** | 238 /** |
| 239 * Regexp for archive files. Used to show mount-archive task. |
| 240 */ |
| 241 const ARCHIVES_REGEXP = /.zip$/; |
| 242 |
| 243 /** |
239 * Return a translated string. | 244 * Return a translated string. |
240 * | 245 * |
241 * Wrapper function to make dealing with translated strings more concise. | 246 * Wrapper function to make dealing with translated strings more concise. |
242 * Equivilant to localStrings.getString(id). | 247 * Equivilant to localStrings.getString(id). |
243 * | 248 * |
244 * @param {string} id The id of the string to return. | 249 * @param {string} id The id of the string to return. |
245 * @return {string} The translated string. | 250 * @return {string} The translated string. |
246 */ | 251 */ |
247 function str(id) { | 252 function str(id) { |
248 return localStrings.getString(id); | 253 return localStrings.getString(id); |
(...skipping 1235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1484 } | 1489 } |
1485 | 1490 |
1486 if (pendingFiles.length) { | 1491 if (pendingFiles.length) { |
1487 cacheEntrySize(pendingFiles.pop(), cacheNextFile); | 1492 cacheEntrySize(pendingFiles.pop(), cacheNextFile); |
1488 } else { | 1493 } else { |
1489 self.dispatchEvent(new cr.Event('selection-summarized')); | 1494 self.dispatchEvent(new cr.Event('selection-summarized')); |
1490 } | 1495 } |
1491 }; | 1496 }; |
1492 | 1497 |
1493 if (this.dialogType_ == FileManager.DialogType.FULL_PAGE) { | 1498 if (this.dialogType_ == FileManager.DialogType.FULL_PAGE) { |
1494 // Since unmount task cannot be defined in terms of file patterns, | 1499 // Some internal tasks cannot be defined in terms of file patterns, |
1495 // we manually include it here, if all selected items are mount points. | 1500 // so we pass selection to check for them manually. |
1496 chrome.fileBrowserPrivate.getFileTasks( | 1501 if (selection.directoryCount == 0 && selection.fileCount > 0) { |
1497 selection.urls, | 1502 // Only files, not directories, are supported for external tasks. |
1498 this.onTasksFound_.bind(this, | 1503 chrome.fileBrowserPrivate.getFileTasks( |
1499 this.shouldShowUnmount_(selection.urls))); | 1504 selection.urls, |
| 1505 this.onTasksFound_.bind(this, selection)); |
| 1506 } else { |
| 1507 // There may be internal tasks for directories. |
| 1508 this.onTasksFound_(selection, []); |
| 1509 } |
1500 } | 1510 } |
1501 | 1511 |
1502 cacheNextFile(); | 1512 cacheNextFile(); |
1503 }; | 1513 }; |
1504 | 1514 |
1505 FileManager.prototype.onMetadataResult_ = function(fileURL, metadata) { | 1515 FileManager.prototype.onMetadataResult_ = function(fileURL, metadata) { |
1506 var observers = this.metadataCache_[fileURL]; | 1516 var observers = this.metadataCache_[fileURL]; |
1507 if (!observers || !(observers instanceof Array)) { | 1517 if (!observers || !(observers instanceof Array)) { |
1508 console.error('Missing or invalid metadata observers: ' + fileURL + ': ' + | 1518 console.error('Missing or invalid metadata observers: ' + fileURL + ': ' + |
1509 observers); | 1519 observers); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1544 if (!(methodName in this)) { | 1554 if (!(methodName in this)) { |
1545 console.log('Unknown message from metadata reader: ' + data.verb, data); | 1555 console.log('Unknown message from metadata reader: ' + data.verb, data); |
1546 return; | 1556 return; |
1547 } | 1557 } |
1548 | 1558 |
1549 this[methodName].apply(this, data.arguments); | 1559 this[methodName].apply(this, data.arguments); |
1550 }; | 1560 }; |
1551 | 1561 |
1552 /** | 1562 /** |
1553 * Callback called when tasks for selected files are determined. | 1563 * Callback called when tasks for selected files are determined. |
1554 * @param {boolean} unmount Whether unmount task should be included. | 1564 * @param {Object} selection Selection is passed here, since this.selection |
| 1565 * can change before tasks were found, and we should be accurate. |
1555 * @param {Array.<Task>} tasksList The tasks list. | 1566 * @param {Array.<Task>} tasksList The tasks list. |
1556 */ | 1567 */ |
1557 FileManager.prototype.onTasksFound_ = function(unmount, tasksList) { | 1568 FileManager.prototype.onTasksFound_ = function(selection, tasksList) { |
1558 if (unmount) { | |
1559 tasksList.push({ | |
1560 taskId: this.getExtensionId_() + '|unmount-archive', | |
1561 iconUrl: '', | |
1562 title: '' | |
1563 }); | |
1564 } | |
1565 | 1569 |
1566 this.taskButtons_.innerHTML = ''; | 1570 this.taskButtons_.innerHTML = ''; |
1567 for (var i = 0; i < tasksList.length; i++) { | 1571 for (var i = 0; i < tasksList.length; i++) { |
1568 var task = tasksList[i]; | 1572 var task = tasksList[i]; |
1569 | 1573 |
1570 // Tweak images, titles of internal tasks. | 1574 // Tweak images, titles of internal tasks. |
1571 var task_parts = task.taskId.split('|'); | 1575 var task_parts = task.taskId.split('|'); |
1572 if (task_parts[0] == this.getExtensionId_()) { | 1576 if (task_parts[0] == this.getExtensionId_()) { |
1573 if (task_parts[1] == 'preview') { | 1577 if (task_parts[1] == 'preview') { |
1574 // TODO(serya): This hack needed until task.iconUrl get working | 1578 // TODO(serya): This hack needed until task.iconUrl get working |
(...skipping 13 matching lines...) Expand all Loading... |
1588 } else if (task_parts[1] == 'enqueue') { | 1592 } else if (task_parts[1] == 'enqueue') { |
1589 task.iconUrl = | 1593 task.iconUrl = |
1590 chrome.extension.getURL('images/icon_add_to_queue_16x16.png'); | 1594 chrome.extension.getURL('images/icon_add_to_queue_16x16.png'); |
1591 task.title = str('ENQUEUE'); | 1595 task.title = str('ENQUEUE'); |
1592 } else if (task_parts[1] == 'mount-archive') { | 1596 } else if (task_parts[1] == 'mount-archive') { |
1593 task.iconUrl = | 1597 task.iconUrl = |
1594 chrome.extension.getURL('images/icon_mount_archive_16x16.png'); | 1598 chrome.extension.getURL('images/icon_mount_archive_16x16.png'); |
1595 task.title = str('MOUNT_ARCHIVE'); | 1599 task.title = str('MOUNT_ARCHIVE'); |
1596 if (str('ENABLE_ARCHIVES') != 'true') | 1600 if (str('ENABLE_ARCHIVES') != 'true') |
1597 continue; | 1601 continue; |
1598 } else if (task_parts[1] == 'unmount-archive') { | |
1599 task.iconUrl = | |
1600 chrome.extension.getURL('images/icon_unmount_archive_16x16.png'); | |
1601 task.title = str('UNMOUNT_ARCHIVE'); | |
1602 if (str('ENABLE_ARCHIVES') != 'true') | |
1603 continue; | |
1604 } | 1602 } |
1605 } | 1603 } |
| 1604 this.renderTaskButton_(task); |
| 1605 } |
| 1606 this.maybeRenderUnmountTask_(selection); |
| 1607 }; |
1606 | 1608 |
1607 var button = this.document_.createElement('button'); | 1609 FileManager.prototype.renderTaskButton_ = function(task) { |
1608 button.addEventListener('click', this.onTaskButtonClicked_.bind(this)); | 1610 var button = this.document_.createElement('button'); |
1609 button.className = 'task-button'; | 1611 button.addEventListener('click', this.onTaskButtonClicked_.bind(this)); |
1610 button.task = task; | 1612 button.className = 'task-button'; |
| 1613 button.task = task; |
1611 | 1614 |
1612 var img = this.document_.createElement('img'); | 1615 var img = this.document_.createElement('img'); |
1613 img.src = task.iconUrl; | 1616 img.src = task.iconUrl; |
1614 | 1617 |
1615 button.appendChild(img); | 1618 button.appendChild(img); |
1616 button.appendChild(this.document_.createTextNode(task.title)); | 1619 button.appendChild(this.document_.createTextNode(task.title)); |
1617 | 1620 |
1618 this.taskButtons_.appendChild(button); | 1621 this.taskButtons_.appendChild(button); |
| 1622 }; |
| 1623 |
| 1624 /** |
| 1625 * Checks whether unmount task should be displayed and if the answer is |
| 1626 * affirmative renders it. |
| 1627 * @param {Object} selection Selected files object. |
| 1628 */ |
| 1629 FileManager.prototype.maybeRenderUnmountTask_ = function(selection) { |
| 1630 for (var index = 0; index < selection.urls.length; ++index) { |
| 1631 // Each url should be a mount point. |
| 1632 var path = selection.urls[index]; |
| 1633 if (!this.mountPoints_.hasOwnProperty(path) || |
| 1634 this.mountPoints_[path].type != 'file') |
| 1635 return; |
1619 } | 1636 } |
1620 }; | 1637 this.renderTaskButton_({ |
| 1638 taskId: this.getExtensionId_() + '|unmount-archive', |
| 1639 iconUrl: |
| 1640 chrome.extension.getURL('images/icon_unmount_archive_16x16.png'), |
| 1641 title: str('UNMOUNT_ARCHIVE') |
| 1642 }); |
| 1643 }; |
1621 | 1644 |
1622 FileManager.prototype.getExtensionId_ = function() { | 1645 FileManager.prototype.getExtensionId_ = function() { |
1623 return chrome.extension.getURL('').split('/')[2]; | 1646 return chrome.extension.getURL('').split('/')[2]; |
1624 }; | 1647 }; |
1625 | 1648 |
1626 FileManager.prototype.onTaskButtonClicked_ = function(event) { | 1649 FileManager.prototype.onTaskButtonClicked_ = function(event) { |
1627 chrome.fileBrowserPrivate.executeTask(event.srcElement.task.taskId, | 1650 chrome.fileBrowserPrivate.executeTask(event.srcElement.task.taskId, |
1628 this.selection.urls); | 1651 this.selection.urls); |
1629 }; | 1652 }; |
1630 | 1653 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1693 this.mountRequests_.push(urls[index]); | 1716 this.mountRequests_.push(urls[index]); |
1694 chrome.fileBrowserPrivate.addMount(urls[index], 'file', {}); | 1717 chrome.fileBrowserPrivate.addMount(urls[index], 'file', {}); |
1695 } | 1718 } |
1696 } else if (id == 'unmount-archive') { | 1719 } else if (id == 'unmount-archive') { |
1697 for (var index = 0; index < urls.length; ++index) { | 1720 for (var index = 0; index < urls.length; ++index) { |
1698 chrome.fileBrowserPrivate.removeMount(urls[index]); | 1721 chrome.fileBrowserPrivate.removeMount(urls[index]); |
1699 } | 1722 } |
1700 } | 1723 } |
1701 }; | 1724 }; |
1702 | 1725 |
1703 /** | |
1704 * Determines whether unmount task should present for selected files. | |
1705 */ | |
1706 FileManager.prototype.shouldShowUnmount_ = function(urls) { | |
1707 for (var index = 0; index < urls.length; ++index) { | |
1708 // Each url should be a mount point. | |
1709 var path = urls[index]; | |
1710 if (!this.mountPoints_.hasOwnProperty(path) || | |
1711 this.mountPoints_[path].type != 'file') { | |
1712 return false; | |
1713 } | |
1714 } | |
1715 return true; | |
1716 }; | |
1717 | |
1718 FileManager.prototype.onImageEditorSave = function(canvas) { | 1726 FileManager.prototype.onImageEditorSave = function(canvas) { |
1719 console.warn('Saving images not implemented'); | 1727 console.warn('Saving images not implemented'); |
1720 }; | 1728 }; |
1721 | 1729 |
1722 FileManager.prototype.onImageEditorClose = function() { | 1730 FileManager.prototype.onImageEditorClose = function() { |
1723 this.imageEditorFrame_.style.display = 'none'; | 1731 this.imageEditorFrame_.style.display = 'none'; |
1724 this.imageEditor_ = null; | 1732 this.imageEditor_ = null; |
1725 }; | 1733 }; |
1726 | 1734 |
1727 /** | 1735 /** |
(...skipping 1210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2938 | 2946 |
2939 if (msg) { | 2947 if (msg) { |
2940 console.log('no no no'); | 2948 console.log('no no no'); |
2941 this.alert.show(msg, onAccept); | 2949 this.alert.show(msg, onAccept); |
2942 return false; | 2950 return false; |
2943 } | 2951 } |
2944 | 2952 |
2945 return true; | 2953 return true; |
2946 }; | 2954 }; |
2947 })(); | 2955 })(); |
OLD | NEW |