| 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; |
| 11 | 11 |
| 12 const IMAGE_EDITOR_ENABLED = false; | 12 const GALLERY_ENABLED = true; |
| 13 | 13 |
| 14 /** | 14 /** |
| 15 * FileManager constructor. | 15 * FileManager constructor. |
| 16 * | 16 * |
| 17 * FileManager objects encapsulate the functionality of the file selector | 17 * FileManager objects encapsulate the functionality of the file selector |
| 18 * dialogs, as well as the full screen file manager application (though the | 18 * dialogs, as well as the full screen file manager application (though the |
| 19 * latter is not yet implemented). | 19 * latter is not yet implemented). |
| 20 * | 20 * |
| 21 * @param {HTMLElement} dialogDom The DOM node containing the prototypical | 21 * @param {HTMLElement} dialogDom The DOM node containing the prototypical |
| 22 * dialog UI. | 22 * dialog UI. |
| (...skipping 1640 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1663 // Tweak images, titles of internal tasks. | 1663 // Tweak images, titles of internal tasks. |
| 1664 var task_parts = task.taskId.split('|'); | 1664 var task_parts = task.taskId.split('|'); |
| 1665 if (task_parts[0] == this.getExtensionId_()) { | 1665 if (task_parts[0] == this.getExtensionId_()) { |
| 1666 task.internal = true; | 1666 task.internal = true; |
| 1667 if (task_parts[1] == 'preview') { | 1667 if (task_parts[1] == 'preview') { |
| 1668 // TODO(serya): This hack needed until task.iconUrl get working | 1668 // TODO(serya): This hack needed until task.iconUrl get working |
| 1669 // (see GetFileTasksFileBrowserFunction::RunImpl). | 1669 // (see GetFileTasksFileBrowserFunction::RunImpl). |
| 1670 task.iconUrl = | 1670 task.iconUrl = |
| 1671 chrome.extension.getURL('images/icon_preview_16x16.png'); | 1671 chrome.extension.getURL('images/icon_preview_16x16.png'); |
| 1672 task.title = str('PREVIEW_IMAGE'); | 1672 task.title = str('PREVIEW_IMAGE'); |
| 1673 } else if (task_parts[1] == 'edit') { | |
| 1674 task.iconUrl = | |
| 1675 chrome.extension.getURL('images/icon_preview_16x16.png'); | |
| 1676 task.title = 'Edit'; | |
| 1677 if (!IMAGE_EDITOR_ENABLED) continue; // Skip the button creation. | |
| 1678 } else if (task_parts[1] == 'play') { | 1673 } else if (task_parts[1] == 'play') { |
| 1679 task.iconUrl = | 1674 task.iconUrl = |
| 1680 chrome.extension.getURL('images/icon_play_16x16.png'); | 1675 chrome.extension.getURL('images/icon_play_16x16.png'); |
| 1681 task.title = str('PLAY_MEDIA').replace("&", ""); | 1676 task.title = str('PLAY_MEDIA').replace("&", ""); |
| 1682 } else if (task_parts[1] == 'enqueue') { | 1677 } else if (task_parts[1] == 'enqueue') { |
| 1683 task.iconUrl = | 1678 task.iconUrl = |
| 1684 chrome.extension.getURL('images/icon_add_to_queue_16x16.png'); | 1679 chrome.extension.getURL('images/icon_add_to_queue_16x16.png'); |
| 1685 task.title = str('ENQUEUE'); | 1680 task.title = str('ENQUEUE'); |
| 1686 } else if (task_parts[1] == 'mount-archive') { | 1681 } else if (task_parts[1] == 'mount-archive') { |
| 1687 task.iconUrl = | 1682 task.iconUrl = |
| 1688 chrome.extension.getURL('images/icon_mount_archive_16x16.png'); | 1683 chrome.extension.getURL('images/icon_mount_archive_16x16.png'); |
| 1689 task.title = str('MOUNT_ARCHIVE'); | 1684 task.title = str('MOUNT_ARCHIVE'); |
| 1690 if (str('ENABLE_ARCHIVES') != 'true') | 1685 if (str('ENABLE_ARCHIVES') != 'true') |
| 1691 continue; | 1686 continue; |
| 1687 } else if (task_parts[1] == 'gallery') { |
| 1688 task.iconUrl = |
| 1689 chrome.extension.getURL('images/icon_preview_16x16.png'); |
| 1690 task.title = str('GALLERY'); |
| 1691 if (!GALLERY_ENABLED) continue; // Skip the button creation. |
| 1692 } | 1692 } |
| 1693 } | 1693 } |
| 1694 this.renderTaskButton_(task); | 1694 this.renderTaskButton_(task); |
| 1695 } | 1695 } |
| 1696 | 1696 |
| 1697 // These are done in separate functions, as the checks require | 1697 // These are done in separate functions, as the checks require |
| 1698 // asynchronous function calls. | 1698 // asynchronous function calls. |
| 1699 this.maybeRenderUnmountTask_(selection); | 1699 this.maybeRenderUnmountTask_(selection); |
| 1700 this.maybeRenderFormattingTask_(selection); | 1700 this.maybeRenderFormattingTask_(selection); |
| 1701 }; | 1701 }; |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1868 /** | 1868 /** |
| 1869 * Event handler called when some internal task should be executed. | 1869 * Event handler called when some internal task should be executed. |
| 1870 */ | 1870 */ |
| 1871 FileManager.prototype.onFileTaskExecute_ = function(id, details) { | 1871 FileManager.prototype.onFileTaskExecute_ = function(id, details) { |
| 1872 var urls = details.entries.map(function(entry) { | 1872 var urls = details.entries.map(function(entry) { |
| 1873 return entry.toURL(); | 1873 return entry.toURL(); |
| 1874 }); | 1874 }); |
| 1875 if (id == 'preview') { | 1875 if (id == 'preview') { |
| 1876 g_slideshow_data = urls; | 1876 g_slideshow_data = urls; |
| 1877 chrome.tabs.create({url: "slideshow.html"}); | 1877 chrome.tabs.create({url: "slideshow.html"}); |
| 1878 } else if (id == 'edit') { | |
| 1879 this.openImageEditor_(details.entries[0]); | |
| 1880 } else if (id == 'play' || id == 'enqueue') { | 1878 } else if (id == 'play' || id == 'enqueue') { |
| 1881 chrome.fileBrowserPrivate.viewFiles(urls, id); | 1879 chrome.fileBrowserPrivate.viewFiles(urls, id); |
| 1882 } else if (id == 'mount-archive') { | 1880 } else if (id == 'mount-archive') { |
| 1883 for (var index = 0; index < urls.length; ++index) { | 1881 for (var index = 0; index < urls.length; ++index) { |
| 1884 this.mountRequests_.push(urls[index]); | 1882 this.mountRequests_.push(urls[index]); |
| 1885 chrome.fileBrowserPrivate.addMount(urls[index], 'file', {}); | 1883 chrome.fileBrowserPrivate.addMount(urls[index], 'file', {}); |
| 1886 } | 1884 } |
| 1887 } else if (id == 'unmount-archive') { | 1885 } else if (id == 'unmount-archive') { |
| 1888 for (var index = 0; index < urls.length; ++index) { | 1886 for (var index = 0; index < urls.length; ++index) { |
| 1889 chrome.fileBrowserPrivate.removeMount(urls[index]); | 1887 chrome.fileBrowserPrivate.removeMount(urls[index]); |
| 1890 } | 1888 } |
| 1891 } else if (id == 'format-device') { | 1889 } else if (id == 'format-device') { |
| 1892 this.confirm.show(str('FORMATTING_WARNING'), function() { | 1890 this.confirm.show(str('FORMATTING_WARNING'), function() { |
| 1893 chrome.fileBrowserPrivate.formatDevice(urls[0]); | 1891 chrome.fileBrowserPrivate.formatDevice(urls[0]); |
| 1894 }); | 1892 }); |
| 1893 } else if (id == 'gallery') { |
| 1894 this.openGallery_(details.entries); |
| 1895 } | 1895 } |
| 1896 }; | 1896 }; |
| 1897 | 1897 |
| 1898 FileManager.prototype.getDeviceNumber = function(entry) { | 1898 FileManager.prototype.getDeviceNumber = function(entry) { |
| 1899 if (!entry.isDirectory) return false; | 1899 if (!entry.isDirectory) return false; |
| 1900 for (var i = 0; i < this.mountPoints_.length; i++) { | 1900 for (var i = 0; i < this.mountPoints_.length; i++) { |
| 1901 if (normalizeAbsolutePath(entry.fullPath) == | 1901 if (normalizeAbsolutePath(entry.fullPath) == |
| 1902 normalizeAbsolutePath(this.mountPoints_[i].mountPath)) { | 1902 normalizeAbsolutePath(this.mountPoints_[i].mountPath)) { |
| 1903 return i; | 1903 return i; |
| 1904 } | 1904 } |
| 1905 } | 1905 } |
| 1906 return undefined; | 1906 return undefined; |
| 1907 } | 1907 } |
| 1908 | 1908 |
| 1909 FileManager.prototype.openImageEditor_ = function(entry) { | 1909 FileManager.prototype.openGallery_ = function(entries) { |
| 1910 var self = this; | 1910 var self = this; |
| 1911 | 1911 |
| 1912 var editorFrame = this.document_.createElement('iframe'); | 1912 var galleryFrame = this.document_.createElement('iframe'); |
| 1913 editorFrame.className = 'overlay-pane'; | 1913 galleryFrame.className = 'overlay-pane'; |
| 1914 editorFrame.scrolling = 'no'; | 1914 galleryFrame.scrolling = 'no'; |
| 1915 | 1915 |
| 1916 editorFrame.onload = function() { | 1916 // TODO(dgozman): pass metadata to gallery. |
| 1917 self.cacheMetadata_(entry, function(metadata) { | 1917 galleryFrame.onload = function() { |
| 1918 editorFrame.contentWindow.ImageEditor.open( | 1918 galleryFrame.contentWindow.Gallery.open( |
| 1919 self.onImageEditorSave_.bind(self, entry), | 1919 self.currentDirEntry_, |
| 1920 function () { self.dialogDom_.removeChild(editorFrame) }, | 1920 entries, |
| 1921 entry.toURL(), | 1921 function () { self.dialogDom_.removeChild(galleryFrame) }); |
| 1922 metadata); | |
| 1923 }); | |
| 1924 }; | 1922 }; |
| 1925 | 1923 |
| 1926 editorFrame.src = 'js/image_editor/image_editor.html'; | 1924 galleryFrame.src = 'js/image_editor/gallery.html'; |
| 1927 | 1925 this.dialogDom_.appendChild(galleryFrame); |
| 1928 this.dialogDom_.appendChild(editorFrame); | |
| 1929 }; | |
| 1930 | |
| 1931 FileManager.prototype.onImageEditorSave_ = function(entry, blob) { | |
| 1932 // TODO(kaznacheev): Notify user properly about write failures. | |
| 1933 util.writeBlobToFile(entry, blob, function(){}, | |
| 1934 util.flog('Error writing to ' + entry.fullPath)); | |
| 1935 this.updatePreview_(); // Metadata may have changed. | |
| 1936 }; | 1926 }; |
| 1937 | 1927 |
| 1938 /** | 1928 /** |
| 1939 * Update the breadcrumb display to reflect the current directory. | 1929 * Update the breadcrumb display to reflect the current directory. |
| 1940 */ | 1930 */ |
| 1941 FileManager.prototype.updateBreadcrumbs_ = function() { | 1931 FileManager.prototype.updateBreadcrumbs_ = function() { |
| 1942 var bc = this.dialogDom_.querySelector('.breadcrumbs'); | 1932 var bc = this.dialogDom_.querySelector('.breadcrumbs'); |
| 1943 bc.innerHTML = ''; | 1933 bc.innerHTML = ''; |
| 1944 | 1934 |
| 1945 var fullPath = this.currentDirEntry_.fullPath.replace(/\/$/, ''); | 1935 var fullPath = this.currentDirEntry_.fullPath.replace(/\/$/, ''); |
| (...skipping 1393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3339 | 3329 |
| 3340 if (msg) { | 3330 if (msg) { |
| 3341 console.log('no no no'); | 3331 console.log('no no no'); |
| 3342 this.alert.show(msg, onAccept); | 3332 this.alert.show(msg, onAccept); |
| 3343 return false; | 3333 return false; |
| 3344 } | 3334 } |
| 3345 | 3335 |
| 3346 return true; | 3336 return true; |
| 3347 }; | 3337 }; |
| 3348 })(); | 3338 })(); |
| OLD | NEW |