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))); |
1479 // This needs to be done in sparate function, as check requires | |
1480 // asynchronous function calls. | |
1481 this.DisplayFormattingTask1_(selection.entries); | |
1478 } | 1482 } |
1479 | 1483 |
1480 cacheNextFile(); | 1484 cacheNextFile(); |
1481 }; | 1485 }; |
1482 | 1486 |
1483 FileManager.prototype.onMetadataResult_ = function(fileURL, metadata) { | 1487 FileManager.prototype.onMetadataResult_ = function(fileURL, metadata) { |
1484 var observers = this.metadataCache_[fileURL]; | 1488 var observers = this.metadataCache_[fileURL]; |
1485 if (!observers || !(observers instanceof Array)) { | 1489 if (!observers || !(observers instanceof Array)) { |
1486 console.error('Missing or invalid metadata observers: ' + fileURL + ': ' + | 1490 console.error('Missing or invalid metadata observers: ' + fileURL + ': ' + |
1487 observers); | 1491 observers); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1542 * @param {Array.<Task>} tasksList The tasks list. | 1546 * @param {Array.<Task>} tasksList The tasks list. |
1543 */ | 1547 */ |
1544 FileManager.prototype.onTasksFound_ = function(unmount, tasksList) { | 1548 FileManager.prototype.onTasksFound_ = function(unmount, tasksList) { |
1545 if (unmount) { | 1549 if (unmount) { |
1546 tasksList.push({ | 1550 tasksList.push({ |
1547 taskId: this.getExtensionId_() + '|unmount-archive', | 1551 taskId: this.getExtensionId_() + '|unmount-archive', |
1548 iconUrl: '', | 1552 iconUrl: '', |
1549 title: '' | 1553 title: '' |
1550 }); | 1554 }); |
1551 } | 1555 } |
1552 | |
1553 this.taskButtons_.innerHTML = ''; | |
1554 for (var i = 0; i < tasksList.length; i++) { | 1556 for (var i = 0; i < tasksList.length; i++) { |
1555 var task = tasksList[i]; | 1557 var task = tasksList[i]; |
1556 | 1558 |
1557 // Tweak images, titles of internal tasks. | 1559 // Tweak images, titles of internal tasks. |
1558 var task_parts = task.taskId.split('|'); | 1560 var task_parts = task.taskId.split('|'); |
1559 if (task_parts[0] == this.getExtensionId_()) { | 1561 if (task_parts[0] == this.getExtensionId_()) { |
1560 if (task_parts[1] == 'preview') { | 1562 if (task_parts[1] == 'preview') { |
1561 // TODO(serya): This hack needed until task.iconUrl get working | 1563 // TODO(serya): This hack needed until task.iconUrl get working |
1562 // (see GetFileTasksFileBrowserFunction::RunImpl). | 1564 // (see GetFileTasksFileBrowserFunction::RunImpl). |
1563 task.iconUrl = | 1565 task.iconUrl = |
(...skipping 15 matching lines...) Expand all Loading... | |
1579 } else if (task_parts[1] == 'mount-archive') { | 1581 } else if (task_parts[1] == 'mount-archive') { |
1580 task.iconUrl = | 1582 task.iconUrl = |
1581 chrome.extension.getURL('images/icon_mount_archive_16x16.png'); | 1583 chrome.extension.getURL('images/icon_mount_archive_16x16.png'); |
1582 task.title = str('MOUNT_ARCHIVE'); | 1584 task.title = str('MOUNT_ARCHIVE'); |
1583 } else if (task_parts[1] == 'unmount-archive') { | 1585 } else if (task_parts[1] == 'unmount-archive') { |
1584 task.iconUrl = | 1586 task.iconUrl = |
1585 chrome.extension.getURL('images/icon_unmount_archive_16x16.png'); | 1587 chrome.extension.getURL('images/icon_unmount_archive_16x16.png'); |
1586 task.title = str('UNMOUNT_ARCHIVE'); | 1588 task.title = str('UNMOUNT_ARCHIVE'); |
1587 } | 1589 } |
1588 } | 1590 } |
1589 | 1591 this.renderTaskButton_(task); |
1590 var button = this.document_.createElement('button'); | |
1591 button.addEventListener('click', this.onTaskButtonClicked_.bind(this)); | |
1592 button.className = 'task-button'; | |
1593 button.task = task; | |
1594 | |
1595 var img = this.document_.createElement('img'); | |
1596 img.src = task.iconUrl; | |
1597 | |
1598 button.appendChild(img); | |
1599 button.appendChild(this.document_.createTextNode(task.title)); | |
1600 | |
1601 this.taskButtons_.appendChild(button); | |
1602 } | 1592 } |
1603 }; | 1593 }; |
1604 | 1594 |
1595 FileManager.prototype.renderTaskButton_ = function(task) { | |
1596 var button = this.document_.createElement('button'); | |
1597 button.addEventListener('click', this.onTaskButtonClicked_.bind(this)); | |
1598 button.className = 'task-button'; | |
1599 button.task = task; | |
1600 | |
1601 var img = this.document_.createElement('img'); | |
1602 img.src = task.iconUrl; | |
1603 | |
1604 button.appendChild(img); | |
1605 button.appendChild(this.document_.createTextNode(task.title)); | |
1606 | |
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.DisplayFormattingTask1_ = function(entries) { | |
rginda
2011/08/10 23:08:09
JavaScript naming convention has leadingLowercase
sidor.dev
2011/08/10 23:51:21
Done.
| |
1616 if (entries.length != 1) | |
1617 return; | |
1618 var self = this; | |
1619 chrome.fileBrowserPrivate.getMountPoints( | |
1620 this.DisplayFormattingTask2_.bind(this, entries[0].fullPath)); | |
1621 }; | |
1622 | |
1623 FileManager.prototype.DisplayFormattingTask2_ = function(mountPath, | |
rginda
2011/08/10 23:08:09
The convention elsewhere in this file is to declar
sidor.dev
2011/08/10 23:51:21
Done.
| |
1624 mountPoints) { | |
1625 var normalize = function(x) { | |
1626 if(x[0] == '/') | |
1627 return x.slice(1); | |
1628 else | |
1629 return x; | |
1630 } | |
1631 this.mountPoints_ = mountPoints; | |
1632 for (var i = 0; i < mountPoints.length; ++i) { | |
rginda
2011/08/10 23:08:09
i++
sidor.dev
2011/08/10 23:51:21
Done. Out of curiosity - why is that a convention
| |
1633 if (mountPoints[i].mountType == "device" && | |
1634 normalize(mountPoints[i].mountPath) == normalize(mountPath)) { | |
1635 chrome.fileBrowserPrivate.getVolumeMetadata(mountPoints[i].sourceUrl, | |
1636 this.DisplayFormattingTask3_.bind(this)); | |
1637 return; | |
1638 } | |
1639 } | |
1640 }; | |
1641 | |
1642 FileManager.prototype.DisplayFormattingTask3_ = function(volumeMetadata) { | |
rginda
2011/08/10 23:08:09
and onVolumeMetadataFound
sidor.dev
2011/08/10 23:51:21
Done.
| |
1643 if (volumeMetadata.deviceType == "flash") { | |
1644 var task = { | |
1645 taskId: this.getExtensionId_() + '|format-device', | |
1646 iconUrl: chrome.extension.getURL('images/filetype_generic.png'), | |
1647 title: str('FORMAT_DEVICE') | |
1648 }; | |
1649 this.renderTaskButton_(task); | |
rginda
2011/08/10 23:08:09
You should probably omit the entries parameter to
sidor.dev
2011/08/10 23:51:21
Done.
| |
1650 } | |
1651 }; | |
1652 | |
1605 FileManager.prototype.getExtensionId_ = function() { | 1653 FileManager.prototype.getExtensionId_ = function() { |
1606 return chrome.extension.getURL('').split('/')[2]; | 1654 return chrome.extension.getURL('').split('/')[2]; |
1607 }; | 1655 }; |
1608 | 1656 |
1609 FileManager.prototype.onTaskButtonClicked_ = function(event) { | 1657 FileManager.prototype.onTaskButtonClicked_ = function(event) { |
1610 chrome.fileBrowserPrivate.executeTask(event.srcElement.task.taskId, | 1658 chrome.fileBrowserPrivate.executeTask(event.srcElement.task.taskId, |
1611 this.selection.urls); | 1659 this.selection.urls); |
1612 }; | 1660 }; |
1613 | 1661 |
1614 /** | 1662 /** |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1659 chrome.fileBrowserPrivate.viewFiles(urls, id); | 1707 chrome.fileBrowserPrivate.viewFiles(urls, id); |
1660 } else if (id == 'mount-archive') { | 1708 } else if (id == 'mount-archive') { |
1661 for (var index = 0; index < urls.length; ++index) { | 1709 for (var index = 0; index < urls.length; ++index) { |
1662 this.mountRequests_.push(urls[index]); | 1710 this.mountRequests_.push(urls[index]); |
1663 chrome.fileBrowserPrivate.addMount(urls[index], 'file', {}); | 1711 chrome.fileBrowserPrivate.addMount(urls[index], 'file', {}); |
1664 } | 1712 } |
1665 } else if (id == 'unmount-archive') { | 1713 } else if (id == 'unmount-archive') { |
1666 for (var index = 0; index < urls.length; ++index) { | 1714 for (var index = 0; index < urls.length; ++index) { |
1667 chrome.fileBrowserPrivate.removeMount(urls[index]); | 1715 chrome.fileBrowserPrivate.removeMount(urls[index]); |
1668 } | 1716 } |
1717 } else if (id == 'format-device') { | |
1718 if (!confirm(str('FORMATTING_WARNING'))) | |
1719 return; | |
1720 chrome.fileBrowserPrivate.formatDevice(urls[0]); | |
1669 } | 1721 } |
1670 }; | 1722 }; |
1671 | 1723 |
1672 /** | 1724 /** |
1673 * Determines whether unmount task should present for selected files. | 1725 * Determines whether unmount task should present for selected files. |
1674 */ | 1726 */ |
1675 FileManager.prototype.shouldShowUnmount_ = function(urls) { | 1727 FileManager.prototype.shouldShowUnmount_ = function(urls) { |
1676 for (var index = 0; index < urls.length; ++index) { | 1728 for (var index = 0; index < urls.length; ++index) { |
1677 // Each url should be a mount point. | 1729 // Each url should be a mount point. |
1678 var path = urls[index]; | 1730 var path = urls[index]; |
(...skipping 1327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3006 | 3058 |
3007 if (msg) { | 3059 if (msg) { |
3008 console.log('no no no'); | 3060 console.log('no no no'); |
3009 this.alert.show(msg, onAccept); | 3061 this.alert.show(msg, onAccept); |
3010 return false; | 3062 return false; |
3011 } | 3063 } |
3012 | 3064 |
3013 return true; | 3065 return true; |
3014 }; | 3066 }; |
3015 })(); | 3067 })(); |
OLD | NEW |