Chromium Code Reviews| 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 1453 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1464 if (pendingFiles.length) { | 1464 if (pendingFiles.length) { |
| 1465 cacheEntrySize(pendingFiles.pop(), cacheNextFile); | 1465 cacheEntrySize(pendingFiles.pop(), cacheNextFile); |
| 1466 } else { | 1466 } else { |
| 1467 self.dispatchEvent(new cr.Event('selection-summarized')); | 1467 self.dispatchEvent(new cr.Event('selection-summarized')); |
| 1468 } | 1468 } |
| 1469 }; | 1469 }; |
| 1470 | 1470 |
| 1471 if (this.dialogType_ == FileManager.DialogType.FULL_PAGE) { | 1471 if (this.dialogType_ == FileManager.DialogType.FULL_PAGE) { |
| 1472 // Since unmount task cannot be defined in terms of file patterns, | 1472 // Since unmount task cannot be defined in terms of file patterns, |
| 1473 // we manually include it here, if all selected items are mount points. | 1473 // we manually include it here, if all selected items are mount points. |
| 1474 this.taskButtons_.innerHTML = ''; | |
| 1474 chrome.fileBrowserPrivate.getFileTasks( | 1475 chrome.fileBrowserPrivate.getFileTasks( |
| 1475 selection.urls, | 1476 selection.urls, |
| 1476 this.onTasksFound_.bind(this, | 1477 this.onTasksFound_.bind(this, |
| 1477 this.shouldShowUnmount_(selection.urls))); | 1478 this.shouldShowUnmount_(selection.urls))); |
| 1478 } | 1479 } |
| 1479 | 1480 |
| 1480 cacheNextFile(); | 1481 cacheNextFile(); |
| 1481 }; | 1482 }; |
| 1482 | 1483 |
| 1483 FileManager.prototype.onMetadataResult_ = function(fileURL, metadata) { | 1484 FileManager.prototype.onMetadataResult_ = function(fileURL, metadata) { |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1542 * @param {Array.<Task>} tasksList The tasks list. | 1543 * @param {Array.<Task>} tasksList The tasks list. |
| 1543 */ | 1544 */ |
| 1544 FileManager.prototype.onTasksFound_ = function(unmount, tasksList) { | 1545 FileManager.prototype.onTasksFound_ = function(unmount, tasksList) { |
| 1545 if (unmount) { | 1546 if (unmount) { |
| 1546 tasksList.push({ | 1547 tasksList.push({ |
| 1547 taskId: this.getExtensionId_() + '|unmount-archive', | 1548 taskId: this.getExtensionId_() + '|unmount-archive', |
| 1548 iconUrl: '', | 1549 iconUrl: '', |
| 1549 title: '' | 1550 title: '' |
| 1550 }); | 1551 }); |
| 1551 } | 1552 } |
| 1552 | |
| 1553 this.taskButtons_.innerHTML = ''; | |
| 1554 for (var i = 0; i < tasksList.length; i++) { | 1553 for (var i = 0; i < tasksList.length; i++) { |
| 1555 var task = tasksList[i]; | 1554 var task = tasksList[i]; |
| 1556 | 1555 |
| 1557 // Tweak images, titles of internal tasks. | 1556 // Tweak images, titles of internal tasks. |
| 1558 var task_parts = task.taskId.split('|'); | 1557 var task_parts = task.taskId.split('|'); |
| 1559 if (task_parts[0] == this.getExtensionId_()) { | 1558 if (task_parts[0] == this.getExtensionId_()) { |
| 1560 if (task_parts[1] == 'preview') { | 1559 if (task_parts[1] == 'preview') { |
| 1561 // TODO(serya): This hack needed until task.iconUrl get working | 1560 // TODO(serya): This hack needed until task.iconUrl get working |
| 1562 // (see GetFileTasksFileBrowserFunction::RunImpl). | 1561 // (see GetFileTasksFileBrowserFunction::RunImpl). |
| 1563 task.iconUrl = | 1562 task.iconUrl = |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 1579 } else if (task_parts[1] == 'mount-archive') { | 1578 } else if (task_parts[1] == 'mount-archive') { |
| 1580 task.iconUrl = | 1579 task.iconUrl = |
| 1581 chrome.extension.getURL('images/icon_mount_archive_16x16.png'); | 1580 chrome.extension.getURL('images/icon_mount_archive_16x16.png'); |
| 1582 task.title = str('MOUNT_ARCHIVE'); | 1581 task.title = str('MOUNT_ARCHIVE'); |
| 1583 } else if (task_parts[1] == 'unmount-archive') { | 1582 } else if (task_parts[1] == 'unmount-archive') { |
| 1584 task.iconUrl = | 1583 task.iconUrl = |
| 1585 chrome.extension.getURL('images/icon_unmount_archive_16x16.png'); | 1584 chrome.extension.getURL('images/icon_unmount_archive_16x16.png'); |
| 1586 task.title = str('UNMOUNT_ARCHIVE'); | 1585 task.title = str('UNMOUNT_ARCHIVE'); |
| 1587 } | 1586 } |
| 1588 } | 1587 } |
| 1588 this.renderTaskButton_(task); | |
| 1589 } | |
| 1590 // This needs to be done in sparate function, as check requires | |
| 1591 // asynchronous function calls. | |
| 1592 this.maybeRenderFormattingTask_(); | |
| 1593 }; | |
| 1589 | 1594 |
| 1590 var button = this.document_.createElement('button'); | 1595 FileManager.prototype.renderTaskButton_ = function(task) { |
| 1591 button.addEventListener('click', this.onTaskButtonClicked_.bind(this)); | 1596 var button = this.document_.createElement('button'); |
| 1592 button.className = 'task-button'; | 1597 button.addEventListener('click', this.onTaskButtonClicked_.bind(this)); |
| 1593 button.task = task; | 1598 button.className = 'task-button'; |
| 1599 button.task = task; | |
| 1594 | 1600 |
| 1595 var img = this.document_.createElement('img'); | 1601 var img = this.document_.createElement('img'); |
| 1596 img.src = task.iconUrl; | 1602 img.src = task.iconUrl; |
| 1597 | 1603 |
| 1598 button.appendChild(img); | 1604 button.appendChild(img); |
| 1599 button.appendChild(this.document_.createTextNode(task.title)); | 1605 button.appendChild(this.document_.createTextNode(task.title)); |
| 1600 | 1606 |
| 1601 this.taskButtons_.appendChild(button); | 1607 this.taskButtons_.appendChild(button); |
| 1608 }; | |
| 1609 | |
| 1610 /** | |
| 1611 * Checks whether formatting task should be displayed and if the answer is | |
| 1612 * affirmative renders it. Includes asynchronous calls, so it's splitted into | |
| 1613 * three parts. | |
| 1614 */ | |
| 1615 FileManager.prototype.maybeRenderFormattingTask_ = function() { | |
| 1616 // Not to make unnecesary getMountPoints() call we doublecheck if there is | |
| 1617 // only one selected entry. | |
| 1618 if(this.selection.entries.length != 1) | |
| 1619 return; | |
| 1620 | |
| 1621 function onMountPointsFound(mountPoints) { | |
| 1622 this.mountPoints_ = mountPoints; | |
| 1623 | |
| 1624 function normalize(x) { | |
| 1625 if(x[0] == '/') | |
| 1626 return x.slice(1); | |
| 1627 else | |
| 1628 return x; | |
| 1629 } | |
| 1630 | |
| 1631 function onVolumeMetadataFound(volumeMetadata) { | |
| 1632 if (volumeMetadata.deviceType == "flash") { | |
| 1633 if (this.selection.entries.length != 1 || | |
| 1634 normalize(this.selection.entries[0].fullPath) != | |
| 1635 normalize(volumeMetadata.mountPath)) { | |
| 1636 return; | |
| 1637 } | |
| 1638 var task = { | |
| 1639 taskId: this.getExtensionId_() + '|format-device', | |
| 1640 iconUrl: chrome.extension.getURL('images/filetype_generic.png'), | |
| 1641 title: str('FORMAT_DEVICE') | |
| 1642 }; | |
| 1643 this.renderTaskButton_(task); | |
| 1644 } | |
| 1645 } | |
| 1646 | |
| 1647 if(this.selection.entries.length != 1) | |
| 1648 return; | |
| 1649 var selectedPath = this.selection.entries[0].fullPath; | |
| 1650 for (var i = 0; i < mountPoints.length; i++) { | |
| 1651 if (mountPoints[i].mountType == "device" && | |
| 1652 normalize(mountPoints[i].mountPath) == normalize(selectedPath)) { | |
| 1653 chrome.fileBrowserPrivate.getVolumeMetadata(mountPoints[i].sourceUrl, | |
| 1654 onVolumeMetadataFound.bind(this)); | |
| 1655 return; | |
| 1656 } | |
| 1657 } | |
| 1602 } | 1658 } |
| 1659 | |
| 1660 chrome.fileBrowserPrivate.getMountPoints(onMountPointsFound.bind(this)); | |
|
rginda
2011/08/11 20:20:14
The convention for nested functions is to create a
sidor.dev
2011/08/12 02:05:20
Done.
| |
| 1603 }; | 1661 }; |
| 1604 | 1662 |
| 1605 FileManager.prototype.getExtensionId_ = function() { | 1663 FileManager.prototype.getExtensionId_ = function() { |
| 1606 return chrome.extension.getURL('').split('/')[2]; | 1664 return chrome.extension.getURL('').split('/')[2]; |
| 1607 }; | 1665 }; |
| 1608 | 1666 |
| 1609 FileManager.prototype.onTaskButtonClicked_ = function(event) { | 1667 FileManager.prototype.onTaskButtonClicked_ = function(event) { |
| 1610 chrome.fileBrowserPrivate.executeTask(event.srcElement.task.taskId, | 1668 chrome.fileBrowserPrivate.executeTask(event.srcElement.task.taskId, |
| 1611 this.selection.urls); | 1669 this.selection.urls); |
| 1612 }; | 1670 }; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1659 chrome.fileBrowserPrivate.viewFiles(urls, id); | 1717 chrome.fileBrowserPrivate.viewFiles(urls, id); |
| 1660 } else if (id == 'mount-archive') { | 1718 } else if (id == 'mount-archive') { |
| 1661 for (var index = 0; index < urls.length; ++index) { | 1719 for (var index = 0; index < urls.length; ++index) { |
| 1662 this.mountRequests_.push(urls[index]); | 1720 this.mountRequests_.push(urls[index]); |
| 1663 chrome.fileBrowserPrivate.addMount(urls[index], 'file', {}); | 1721 chrome.fileBrowserPrivate.addMount(urls[index], 'file', {}); |
| 1664 } | 1722 } |
| 1665 } else if (id == 'unmount-archive') { | 1723 } else if (id == 'unmount-archive') { |
| 1666 for (var index = 0; index < urls.length; ++index) { | 1724 for (var index = 0; index < urls.length; ++index) { |
| 1667 chrome.fileBrowserPrivate.removeMount(urls[index]); | 1725 chrome.fileBrowserPrivate.removeMount(urls[index]); |
| 1668 } | 1726 } |
| 1727 } else if (id == 'format-device') { | |
| 1728 if (!confirm(str('FORMATTING_WARNING'))) | |
|
rginda
2011/08/11 20:20:14
App modal dialogs are no longer allowed here. You
sidor.dev
2011/08/12 02:05:20
Done.
| |
| 1729 return; | |
| 1730 chrome.fileBrowserPrivate.formatDevice(urls[0]); | |
| 1669 } | 1731 } |
| 1670 }; | 1732 }; |
| 1671 | 1733 |
| 1672 /** | 1734 /** |
| 1673 * Determines whether unmount task should present for selected files. | 1735 * Determines whether unmount task should present for selected files. |
| 1674 */ | 1736 */ |
| 1675 FileManager.prototype.shouldShowUnmount_ = function(urls) { | 1737 FileManager.prototype.shouldShowUnmount_ = function(urls) { |
| 1676 for (var index = 0; index < urls.length; ++index) { | 1738 for (var index = 0; index < urls.length; ++index) { |
| 1677 // Each url should be a mount point. | 1739 // Each url should be a mount point. |
| 1678 var path = urls[index]; | 1740 var path = urls[index]; |
| (...skipping 1327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3006 | 3068 |
| 3007 if (msg) { | 3069 if (msg) { |
| 3008 console.log('no no no'); | 3070 console.log('no no no'); |
| 3009 this.alert.show(msg, onAccept); | 3071 this.alert.show(msg, onAccept); |
| 3010 return false; | 3072 return false; |
| 3011 } | 3073 } |
| 3012 | 3074 |
| 3013 return true; | 3075 return true; |
| 3014 }; | 3076 }; |
| 3015 })(); | 3077 })(); |
| OLD | NEW |