15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 52a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)'use strict'; 62a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/** 85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * This object encapsulates everything related to tasks execution. 92a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) * 105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * @param {FileManager} fileManager FileManager instance. 112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) * @param {Object=} opt_params File manager load parameters. 122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) * @constructor 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) */ 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)function FileTasks(fileManager, opt_params) { 155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) this.fileManager_ = fileManager; 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) this.params_ = opt_params; 175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) this.tasks_ = null; 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) this.defaultTask_ = null; 19a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) this.entries_ = null; 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /** 225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * List of invocations to be called once tasks are available. 232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) * 242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) * @private 25ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch * @type {Array.<Object>} 265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) */ 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) this.pendingInvocations_ = []; 285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/** 31868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) * Location of the FAQ about the file actions. 32868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) * 33868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) * @const 34868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) * @type {string} 35868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) */ 365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)FileTasks.NO_ACTION_FOR_FILE_URL = 'http://support.google.com/chromeos/bin/' + 375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 'answer.py?answer=1700055&topic=29026&ctx=topic'; 385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/** 4058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) * Location of the Chrome Web Store. 4158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) * 4258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) * @const 4358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) * @type {string} 4458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) */ 4558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)FileTasks.CHROME_WEB_STORE_URL = 'https://chrome.google.com/webstore'; 4658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) 4758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)/** 48868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) * Base URL of apps list in the Chrome Web Store. This constant is used in 49868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) * FileTasks.createWebStoreLink(). 5058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) * 51868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) * @const 52868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) * @type {string} 53868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) */ 54868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)FileTasks.WEB_STORE_HANDLER_BASE_URL = 55868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 'https://chrome.google.com/webstore/category/collection/file_handlers'; 56868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 57868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)/** 58868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) * Returns URL of the Chrome Web Store which show apps supporting the given 59868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) * file-extension and mime-type. 60868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) * 61a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) * @param {string} extension Extension of the file (with the first dot). 62868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) * @param {string} mimeType Mime type of the file. 63868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) * @return {string} URL 64868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) */ 65868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)FileTasks.createWebStoreLink = function(extension, mimeType) { 664e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) if (!extension) 6758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) return FileTasks.CHROME_WEB_STORE_URL; 6858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) 69a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) if (extension[0] === '.') 70a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) extension = extension.substr(1); 71a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) else 72a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) console.warn('Please pass an extension with a dot to createWebStoreLink.'); 73a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 74868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) var url = FileTasks.WEB_STORE_HANDLER_BASE_URL; 75868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) url += '?_fe=' + extension.toLowerCase().replace(/[^\w]/g, ''); 764e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 774e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // If a mime is given, add it into the URL. 78868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) if (mimeType) 79868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) url += '&_fmt=' + mimeType.replace(/[^-\w\/]/g, ''); 80868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) return url; 81868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)}; 82868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 83868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)/** 845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * Complete the initialization. 855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * 86a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) * @param {Array.<Entry>} entries List of file entries. 875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * @param {Array.<string>=} opt_mimeTypes List of MIME types for each 885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * of the files. 895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) */ 90a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)FileTasks.prototype.init = function(entries, opt_mimeTypes) { 91a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) this.entries_ = entries; 921e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) this.mimeTypes_ = opt_mimeTypes || []; 93a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 94a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // TODO(mtomasz): Move conversion from entry to url to custom bindings. 95a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) var urls = util.entriesToURLs(entries); 961e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) if (urls.length > 0) { 971e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) chrome.fileBrowserPrivate.getFileTasks(urls, this.mimeTypes_, 981e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) this.onTasks_.bind(this)); 991e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) } 1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/** 1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * Returns amount of tasks. 1042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) * 1052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) * @return {number} amount of tasks. 1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) */ 1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)FileTasks.prototype.size = function() { 1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return (this.tasks_ && this.tasks_.length) || 0; 1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/** 1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * Callback when tasks found. 1132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) * 1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * @param {Array.<Object>} tasks The tasks. 1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * @private 1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) */ 1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)FileTasks.prototype.onTasks_ = function(tasks) { 1185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) this.processTasks_(tasks); 1195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) for (var index = 0; index < this.pendingInvocations_.length; index++) { 1205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) var name = this.pendingInvocations_[index][0]; 1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) var args = this.pendingInvocations_[index][1]; 1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) this[name].apply(this, args); 1235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) this.pendingInvocations_ = []; 1255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 1265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/** 128c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) * The list of known extensions to record UMA. 129c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) * Note: Because the data is recorded by the index, so new item shouldn't be 130c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) * inserted. 131c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) * 132c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) * @const 133c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) * @type {Array.<string>} 134c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) * @private 135c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) */ 136c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)FileTasks.knownExtensions_ = [ 137c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 'other', '.3ga', '.3gp', '.aac', '.alac', '.asf', '.avi', '.bmp', '.csv', 138a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) '.doc', '.docx', '.flac', '.gif', '.ico', '.jpeg', '.jpg', '.log', '.m3u', 139a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) '.m3u8', '.m4a', '.m4v', '.mid', '.mkv', '.mov', '.mp3', '.mp4', '.mpg', 140a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) '.odf', '.odp', '.ods', '.odt', '.oga', '.ogg', '.ogv', '.pdf', '.png', 141a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) '.ppt', '.pptx', '.ra', '.ram', '.rar', '.rm', '.rtf', '.wav', '.webm', 142a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) '.webp', '.wma', '.wmv', '.xls', '.xlsx', 143c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)]; 144c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 145c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)/** 1460f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) * The list of excutable file extensions. 1470f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) * 1480f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) * @const 1490f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) * @type {Array.<string>} 1500f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) */ 1510f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)FileTasks.EXECUTABLE_EXTENSIONS = Object.freeze([ 152a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) '.exe', '.lnk', '.deb', '.dmg', '.jar', '.msi', 1530f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)]); 1540f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 1550f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)/** 1561e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) * The list of extensions to skip the suggest app dialog. 1571e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) * @const 1581e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) * @type {Array.<string>} 1591e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) * @private 1601e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) */ 1611e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)FileTasks.EXTENSIONS_TO_SKIP_SUGGEST_APPS_ = Object.freeze([ 162a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) '.crdownload', '.dsc', '.inf', '.crx', 1631e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)]); 1641e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 1651e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)/** 166c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) * Records trial of opening file grouped by extensions. 167c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) * 168a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) * @param {Array.<Entry>} entries The entries to be opened. 169c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) * @private 170c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) */ 171a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)FileTasks.recordViewingFileTypeUMA_ = function(entries) { 172a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) for (var i = 0; i < entries.length; i++) { 173a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) var entry = entries[i]; 174a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) var extension = FileType.getExtension(entry).toLowerCase(); 175c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) if (FileTasks.knownExtensions_.indexOf(extension) < 0) { 176c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) extension = 'other'; 177c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) } 178c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) metrics.recordEnum( 179c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 'ViewingFileType', extension, FileTasks.knownExtensions_); 180c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) } 181c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)}; 182c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 183c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)/** 1843551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) * Returns true if the taskId is for an internal task. 1853551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) * 1863551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) * @param {string} taskId Task identifier. 1873551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) * @return {boolean} True if the task ID is for an internal task. 1883551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) * @private 1893551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) */ 1903551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)FileTasks.isInternalTask_ = function(taskId) { 1913551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) var taskParts = taskId.split('|'); 1923551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) var appId = taskParts[0]; 1933551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) var taskType = taskParts[1]; 1943551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) var actionId = taskParts[2]; 1953551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // The action IDs here should match ones used in executeInternalTask_(). 196a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) return (appId === chrome.runtime.id && 197a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) taskType === 'file' && 198a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) (actionId === 'play' || 199a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) actionId === 'watch' || 200a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) actionId === 'mount-archive' || 201a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) actionId === 'gallery')); 2023551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)}; 2033551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 2043551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)/** 2055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * Processes internal tasks. 2062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) * 2075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * @param {Array.<Object>} tasks The tasks. 2085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * @private 2095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) */ 2105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)FileTasks.prototype.processTasks_ = function(tasks) { 2115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) this.tasks_ = []; 2127d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) var id = chrome.runtime.id; 2132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) var isOnDrive = false; 214a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) for (var index = 0; index < this.entries_.length; ++index) { 215a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) if (FileType.isOnDrive(this.entries_[index])) { 2162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) isOnDrive = true; 2175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) break; 2185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 2195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 2205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) for (var i = 0; i < tasks.length; i++) { 2225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) var task = tasks[i]; 223b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) var taskParts = task.taskId.split('|'); 2245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 225b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) // Skip internal Files.app's handlers. 226a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) if (taskParts[0] === id && (taskParts[2] === 'auto-open' || 227a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) taskParts[2] === 'select' || taskParts[2] === 'open')) { 228b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) continue; 229b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) } 230b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) 2315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Tweak images, titles of internal tasks. 232a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) if (taskParts[0] === id && taskParts[1] === 'file') { 233a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) if (taskParts[2] === 'play') { 2345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // TODO(serya): This hack needed until task.iconUrl is working 2355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // (see GetFileTasksFileBrowserFunction::RunImpl). 2365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) task.iconType = 'audio'; 2375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) task.title = loadTimeData.getString('ACTION_LISTEN'); 238a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) } else if (taskParts[2] === 'mount-archive') { 2395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) task.iconType = 'archive'; 2405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) task.title = loadTimeData.getString('MOUNT_ARCHIVE'); 241a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) } else if (taskParts[2] === 'gallery') { 2425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) task.iconType = 'image'; 2435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) task.title = loadTimeData.getString('ACTION_OPEN'); 244a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) } else if (taskParts[2] === 'watch') { 2455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) task.iconType = 'video'; 2465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) task.title = loadTimeData.getString('ACTION_WATCH'); 247a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) } else if (taskParts[2] === 'open-hosted-generic') { 248a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) if (this.entries_.length > 1) 2495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) task.iconType = 'generic'; 2505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) else // Use specific icon. 251a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) task.iconType = FileType.getIcon(this.entries_[0]); 2525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) task.title = loadTimeData.getString('ACTION_OPEN'); 253a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) } else if (taskParts[2] === 'open-hosted-gdoc') { 2545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) task.iconType = 'gdoc'; 2555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) task.title = loadTimeData.getString('ACTION_OPEN_GDOC'); 256a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) } else if (taskParts[2] === 'open-hosted-gsheet') { 2575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) task.iconType = 'gsheet'; 2585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) task.title = loadTimeData.getString('ACTION_OPEN_GSHEET'); 259a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) } else if (taskParts[2] === 'open-hosted-gslides') { 2605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) task.iconType = 'gslides'; 2615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) task.title = loadTimeData.getString('ACTION_OPEN_GSLIDES'); 262a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) } else if (taskParts[2] === 'view-swf') { 2632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Do not render this task if disabled. 2642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (!loadTimeData.getBoolean('SWF_VIEW_ENABLED')) 2652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) continue; 2662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) task.iconType = 'generic'; 2672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) task.title = loadTimeData.getString('ACTION_VIEW'); 268a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) } else if (taskParts[2] === 'view-pdf') { 2695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Do not render this task if disabled. 2705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (!loadTimeData.getBoolean('PDF_VIEW_ENABLED')) 2715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) continue; 2725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) task.iconType = 'pdf'; 2735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) task.title = loadTimeData.getString('ACTION_VIEW'); 274a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) } else if (taskParts[2] === 'view-in-browser') { 2755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) task.iconType = 'generic'; 2765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) task.title = loadTimeData.getString('ACTION_VIEW'); 2775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 2785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 2795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 280a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) if (!task.iconType && taskParts[1] === 'web-intent') { 2815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) task.iconType = 'generic'; 2825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 2835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) this.tasks_.push(task); 285a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) if (this.defaultTask_ === null && task.isDefault) { 2865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) this.defaultTask_ = task; 2875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 2885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 2895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (!this.defaultTask_ && this.tasks_.length > 0) { 2905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // If we haven't picked a default task yet, then just pick the first one. 2915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // This is not the preferred way we want to pick this, but better this than 2925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // no default at all if the C++ code didn't set one. 2935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) this.defaultTask_ = this.tasks_[0]; 2945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 2955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 2965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/** 2985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * Executes default task. 2992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) * 3004e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) * @param {function(boolean, Array.<string>)=} opt_callback Called when the 3014e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) * default task is executed, or the error is occurred. 3025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * @private 3035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) */ 304424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)FileTasks.prototype.executeDefault_ = function(opt_callback) { 305a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) FileTasks.recordViewingFileTypeUMA_(this.entries_); 306a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) this.executeDefaultInternal_(this.entries_, opt_callback); 307c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)}; 308c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 309c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)/** 310c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) * Executes default task. 311c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) * 312a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) * @param {Array.<Entry>} entries Entries to execute. 313a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) * @param {function(boolean, Array.<Entry>)=} opt_callback Called when the 3144e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) * default task is executed, or the error is occurred. 315c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) * @private 316c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) */ 317a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)FileTasks.prototype.executeDefaultInternal_ = function(entries, opt_callback) { 318424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) var callback = opt_callback || function(arg1, arg2) {}; 319424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 320a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) if (this.defaultTask_ !== null) { 321a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) this.executeInternal_(this.defaultTask_.taskId, entries); 322a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) callback(true, entries); 3235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return; 3245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 3255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // We don't have tasks, so try to show a file in a browser tab. 3275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // We only do that for single selection to avoid confusion. 328a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) if (entries.length !== 1 || !entries[0]) 329424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) return; 3305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 331a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) var filename = entries[0].name; 332a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) var extension = PathUtil.splitExtension(filename)[1]; 3331e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) var mimeType = this.mimeTypes_[0]; 3341e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 3351e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) var showAlert = function() { 336a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) var textMessageId; 337a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) var titleMessageId; 338a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) switch (extension) { 339a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) case '.exe': 340a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) textMessageId = 'NO_ACTION_FOR_EXECUTABLE'; 341a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) break; 342a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) case '.crx': 343a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) textMessageId = 'NO_ACTION_FOR_CRX'; 344a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) titleMessageId = 'NO_ACTION_FOR_CRX_TITLE'; 345a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) break; 346a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) default: 347a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) textMessageId = 'NO_ACTION_FOR_FILE'; 348a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) } 349a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 3501e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) var webStoreUrl = FileTasks.createWebStoreLink(extension, mimeType); 351a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) var text = strf(textMessageId, 352a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) webStoreUrl, 353a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) FileTasks.NO_ACTION_FOR_FILE_URL); 354a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) var title = titleMessageId ? str(titleMessageId) : filename; 355a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) this.fileManager_.alert.showHtml(title, text, function() {}); 3561e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) callback(false, urls); 3571e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) }.bind(this); 3581e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 3591e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) var onViewFilesFailure = function() { 3601e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) var fm = this.fileManager_; 3611e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) if (fm.enableExperimentalWebStoreIntegration_) { 3621e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) showAlert(); 3631e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) return; 3641e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) } 3651e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 3661e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) if (!fm.isOnDrive() || 367a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) !entries[0] || 368a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) FileTasks.EXTENSIONS_TO_SKIP_SUGGEST_APPS_.indexOf(extension) !== -1) { 3691e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) showAlert(); 3701e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) return; 3711e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) } 3721e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 3731e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) fm.openSuggestAppsDialog( 374a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) entries[0], 3751e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) function() { 3761e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) var newTasks = new FileTasks(fm); 377a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) newTasks.init(entries, this.mimeTypes_); 378f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) newTasks.executeDefault(); 379a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) callback(true, entries); 3801e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) }.bind(this), 3811e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // Cancelled callback. 3821e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) function() { 383a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) callback(false, entries); 3841e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) }, 3851e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) showAlert); 3861e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) }.bind(this); 3871e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 388424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) var onViewFiles = function(success) { 3891e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) if (success) 390a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) callback(success, entries); 3911e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) else 3921e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) onViewFilesFailure(); 393424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) }.bind(this); 3945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 395424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) this.checkAvailability_(function() { 396a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // TODO(mtomasz): Pass entries instead. 397a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) var urls = util.entriesToURLs(entries); 398424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) util.viewFilesInBrowser(urls, onViewFiles); 399424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) }.bind(this)); 4005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 4015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/** 4035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * Executes a single task. 4042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) * 4055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * @param {string} taskId Task identifier. 406a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) * @param {Array.<Entry>=} opt_entries Entries to xecute on instead of 407a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) * this.entries_|. 4085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * @private 4095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) */ 410a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)FileTasks.prototype.execute_ = function(taskId, opt_entries) { 411a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) var entries = opt_entries || this.entries_; 412a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) FileTasks.recordViewingFileTypeUMA_(entries); 413a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) this.executeInternal_(taskId, entries); 414c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)}; 415c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 416c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)/** 417c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) * The core implementation to execute a single task. 418c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) * 419c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) * @param {string} taskId Task identifier. 420a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) * @param {Array.<Entry>} entries Entries to execute. 421c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) * @private 422c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) */ 423a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)FileTasks.prototype.executeInternal_ = function(taskId, entries) { 4245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) this.checkAvailability_(function() { 4253551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) if (FileTasks.isInternalTask_(taskId)) { 4263551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) var taskParts = taskId.split('|'); 427a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) this.executeInternalTask_(taskParts[2], entries); 4285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } else { 429a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // TODO(mtomasz): Pass entries instead. 430a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) var urls = util.entriesToURLs(entries); 4315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) chrome.fileBrowserPrivate.executeTask(taskId, urls); 4325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 4335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) }.bind(this)); 4345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 4355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/** 4375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * Checks whether the remote files are available right now. 4382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) * 4395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * @param {function} callback The callback. 4405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * @private 4415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) */ 4425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)FileTasks.prototype.checkAvailability_ = function(callback) { 4432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) var areAll = function(props, name) { 4442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) var isOne = function(e) { 4455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // If got no properties, we safely assume that item is unavailable. 4465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return e && e[name]; 4472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) }; 448a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) return props.filter(isOne).length === props.length; 4492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) }; 4505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) var fm = this.fileManager_; 452a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) var entries = this.entries_; 4535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (fm.isOnDrive() && fm.isDriveOffline()) { 455a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) fm.metadataCache_.get(entries, 'drive', function(props) { 4565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (areAll(props, 'availableOffline')) { 4575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) callback(); 4585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return; 4595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 4605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) fm.alert.showHtml( 4625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) loadTimeData.getString('OFFLINE_HEADER'), 4635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) props[0].hosted ? 4645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) loadTimeData.getStringF( 465a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) entries.length === 1 ? 4665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 'HOSTED_OFFLINE_MESSAGE' : 4675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 'HOSTED_OFFLINE_MESSAGE_PLURAL') : 4685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) loadTimeData.getStringF( 469a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) entries.length === 1 ? 4705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 'OFFLINE_MESSAGE' : 4715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 'OFFLINE_MESSAGE_PLURAL', 4725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) loadTimeData.getString('OFFLINE_COLUMN_LABEL'))); 4735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) }); 4745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return; 4755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 4765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (fm.isOnDrive() && fm.isDriveOnMeteredConnection()) { 478a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) fm.metadataCache_.get(entries, 'drive', function(driveProps) { 4792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (areAll(driveProps, 'availableWhenMetered')) { 4805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) callback(); 4815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return; 4825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 4835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 484a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) fm.metadataCache_.get(entries, 'filesystem', function(fileProps) { 4855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) var sizeToDownload = 0; 486a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) for (var i = 0; i !== entries.length; i++) { 4872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) if (!driveProps[i].availableWhenMetered) 4885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) sizeToDownload += fileProps[i].size; 4895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 4905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) fm.confirm.show( 4915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) loadTimeData.getStringF( 492a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) entries.length === 1 ? 4935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 'CONFIRM_MOBILE_DATA_USE' : 4945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 'CONFIRM_MOBILE_DATA_USE_PLURAL', 4952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) util.bytesToString(sizeToDownload)), 4965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) callback); 4975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) }); 4985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) }); 4995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return; 5005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 5015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) callback(); 5035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 5045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/** 5065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * Executes an internal task. 5072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) * 5085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * @param {string} id The short task id. 509a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) * @param {Array.<Entry>} entries The entries to execute on. 5105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * @private 5115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) */ 512a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)FileTasks.prototype.executeInternalTask_ = function(id, entries) { 5135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) var fm = this.fileManager_; 5145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 515a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) if (id === 'play') { 5165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) var position = 0; 517a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) if (entries.length === 1) { 5185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // If just a single audio file is selected pass along every audio file 5195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // in the directory. 520a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) var selectedEntries = entries[0]; 521a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) entries = fm.getAllEntriesInCurrentDirectory().filter(FileType.isAudio); 522a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) position = entries.indexOf(selectedEntries); 5235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 524a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // TODO(mtomasz): Pass entries instead. 525a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) var urls = util.entriesToURLs(entries); 526a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) fm.backgroundPage.launchAudioPlayer({items: urls, position: position}); 5275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return; 5285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 5295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 530a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) if (id === 'watch') { 531a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) console.assert(entries.length === 1, 'Cannot open multiple videos'); 532a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // TODO(mtomasz): Pass an entry instead. 533a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) fm.backgroundPage.launchVideoPlayer(entries[0].toURL()); 5347d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) return; 5355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 5365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 537a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) if (id === 'mount-archive') { 538a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) this.mountArchivesInternal_(entries); 5395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return; 5405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 5415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 542a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) if (id === 'gallery') { 543a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) this.openGalleryInternal_(entries); 5445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return; 5455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 5465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5473551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) console.error('Unexpected action ID: ' + id); 5485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 5495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/** 5515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * Mounts archives. 5522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) * 553a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) * @param {Array.<Entry>} entries Mount file entries list. 554c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) */ 555a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)FileTasks.prototype.mountArchives = function(entries) { 556a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) FileTasks.recordViewingFileTypeUMA_(entries); 557a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) this.mountArchivesInternal_(entries); 558c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)}; 559c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 560c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)/** 561c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) * The core implementation of mounts archives. 562c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) * 563a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) * @param {Array.<Entry>} entries Mount file entries list. 5645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * @private 5655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) */ 566a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)FileTasks.prototype.mountArchivesInternal_ = function(entries) { 5675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) var fm = this.fileManager_; 5685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 569a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) var tracker = fm.directoryModel.createDirectoryChangeTracker(); 5705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) tracker.start(); 5715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 572a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // TODO(mtomasz): Pass Entries instead of URLs. 573a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) var urls = util.entriesToURLs(entries); 574a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) fm.resolveSelectResults_(urls, function(resolvedURLs) { 575a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) for (var index = 0; index < resolvedURLs.length; ++index) { 576a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // TODO(mtomasz): Pass Entry instead of URL. 577a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) fm.volumeManager.mountArchive(resolvedURLs[index], 578a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) function(mountPath) { 579a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) tracker.stop(); 580a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) if (!tracker.hasChanged) 581a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) fm.directoryModel.changeDirectory(mountPath); 582a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) }, function(url, error) { 583a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) tracker.stop(); 584a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) var path = util.extractFilePath(url); 585a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) var namePos = path.lastIndexOf('/'); 586a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) fm.alert.show(strf('ARCHIVE_MOUNT_FAILED', 587a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) path.substr(namePos + 1), error)); 588a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) }.bind(null, resolvedURLs[index])); 589a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) } 5905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) }); 5915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 5925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/** 5945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * Open the Gallery. 5952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) * 596a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) * @param {Array.<Entry>} entries List of selected entries. 5975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) */ 598a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)FileTasks.prototype.openGallery = function(entries) { 599a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) FileTasks.recordViewingFileTypeUMA_(entries); 600a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) this.openGalleryInternal_(entries); 601c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)}; 602c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 603c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)/** 604c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) * The core implementation to open the Gallery. 605c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) * 606a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) * @param {Array.<Entry>} entries List of selected entries. 607c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) * @private 608c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) */ 609a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)FileTasks.prototype.openGalleryInternal_ = function(entries) { 6105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) var fm = this.fileManager_; 6115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 612a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) var allEntries = 613a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) fm.getAllEntriesInCurrentDirectory().filter(FileType.isImageOrVideo); 6145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) var galleryFrame = fm.document_.createElement('iframe'); 6165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) galleryFrame.className = 'overlay-pane'; 6175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) galleryFrame.scrolling = 'no'; 6185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) galleryFrame.setAttribute('webkitallowfullscreen', true); 6195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (this.params_ && this.params_.gallery) { 6215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Remove the Gallery state from the location, we do not need it any more. 6227d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) util.updateAppState(null /* keep path */, '' /* remove search. */); 6235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 6245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) var savedAppState = window.appState; 6262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) var savedTitle = document.title; 6272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 6285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Push a temporary state which will be replaced every time the selection 6295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // changes in the Gallery and popped when the Gallery is closed. 6307d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) util.updateAppState(); 6315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 632a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) var onBack = function(selectedEntries) { 633a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) fm.directoryModel.selectEntries(selectedEntries); 6341e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) fm.closeFilePopup(); // Will call Gallery.unload. 6357d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) window.appState = savedAppState; 6367d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) util.saveAppState(); 6377d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) document.title = savedTitle; 6382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) }; 6395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 640b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) var onClose = function() { 641b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) fm.onClose(); 642b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) }; 643b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) 644b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) var onMaximize = function() { 645b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) fm.onMaximize(); 646b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) }; 647b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) 6481e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) var onAppRegionChanged = function(visible) { 6491e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) fm.onFilePopupAppRegionChanged(visible); 6501e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) }; 6511e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 6525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) galleryFrame.onload = function() { 6535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) galleryFrame.contentWindow.ImageUtil.metrics = metrics; 6545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // TODO(haruki): isOnReadonlyDirectory() only checks the permission for the 6562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // root. We should check more granular permission to know whether the file 6572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // is writable or not. 6585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) var readonly = fm.isOnReadonlyDirectory(); 6594e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) var currentDir = fm.getCurrentDirectoryEntry(); 660424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) var downloadsVolume = 661a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) fm.volumeManager.getCurrentProfileVolumeInfo(RootType.DOWNLOADS); 662424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) var downloadsDir = downloadsVolume && downloadsVolume.root; 6635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) var readonlyDirName = null; 6644e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) if (readonly && currentDir) { 6654e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) var rootPath = PathUtil.getRootPath(currentDir.fullPath); 6662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) readonlyDirName = fm.isOnDrive() ? 6674e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) PathUtil.getRootLabel(rootPath) : 6684e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) PathUtil.basename(rootPath); 6695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 6705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) var context = { 6725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // We show the root label in readonly warning (e.g. archive name). 6735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) readonlyDirName: readonlyDirName, 6745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) curDirEntry: currentDir, 6752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) saveDirEntry: readonly ? downloadsDir : null, 676a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) searchResults: fm.directoryModel.isSearching(), 6775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) metadataCache: fm.metadataCache_, 6785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) pageState: this.params_, 6797d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) appWindow: chrome.app.window.current(), 680b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) onBack: onBack, 6815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) onClose: onClose, 682b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) onMaximize: onMaximize, 6831e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) onAppRegionChanged: onAppRegionChanged, 6845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) displayStringFunction: strf 6855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) }; 6863551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) galleryFrame.contentWindow.Gallery.open( 687a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) context, fm.volumeManager, allEntries, entries); 6885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) }.bind(this); 6895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) galleryFrame.src = 'gallery.html'; 6911e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) fm.openFilePopup(galleryFrame, fm.updateTitle_.bind(fm)); 6925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 6935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/** 6955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * Displays the list of tasks in a task picker combobutton. 6962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) * 6975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * @param {cr.ui.ComboButton} combobutton The task picker element. 6985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * @private 6995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) */ 7005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)FileTasks.prototype.display_ = function(combobutton) { 701a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) if (this.tasks_.length === 0) { 7025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) combobutton.hidden = true; 7035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return; 7045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 7055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) combobutton.clear(); 7075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) combobutton.hidden = false; 7085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) combobutton.defaultItem = this.createCombobuttonItem_(this.defaultTask_); 7095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) var items = this.createItems_(); 7115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (items.length > 1) { 7135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) var defaultIdx = 0; 7145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) for (var j = 0; j < items.length; j++) { 7165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) combobutton.addDropDownItem(items[j]); 717a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) if (items[j].task.taskId === this.defaultTask_.taskId) 7185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) defaultIdx = j; 7195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 7205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) combobutton.addSeparator(); 722c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) var changeDefaultMenuItem = combobutton.addDropDownItem({ 723c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) label: loadTimeData.getString('CHANGE_DEFAULT_MENU_ITEM') 724c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) }); 725c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) changeDefaultMenuItem.classList.add('change-default'); 7265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 7275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 7285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/** 7305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * Creates sorted array of available task descriptions such as title and icon. 7312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) * 7325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * @return {Array} created array can be used to feed combobox, menus and so on. 7335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * @private 7345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) */ 7355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)FileTasks.prototype.createItems_ = function() { 7365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) var items = []; 7375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) var title = this.defaultTask_.title + ' ' + 7385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) loadTimeData.getString('DEFAULT_ACTION_LABEL'); 7395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) items.push(this.createCombobuttonItem_(this.defaultTask_, title, true)); 7405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) for (var index = 0; index < this.tasks_.length; index++) { 7425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) var task = this.tasks_[index]; 743a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) if (task !== this.defaultTask_) 7445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) items.push(this.createCombobuttonItem_(task)); 7455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 7465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) items.sort(function(a, b) { 7485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return a.label.localeCompare(b.label); 7495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) }); 7505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return items; 7525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 7535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/** 7555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * Updates context menu with default item. 7565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * @private 7575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) */ 7582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 7595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)FileTasks.prototype.updateMenuItem_ = function() { 7605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) this.fileManager_.updateContextMenuActionItems(this.defaultTask_, 7615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) this.tasks_.length > 1); 7625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 7635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/** 7655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * Creates combobutton item based on task. 7662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) * 7675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * @param {Object} task Task to convert. 7685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * @param {string=} opt_title Title. 7692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) * @param {boolean=} opt_bold Make a menu item bold. 7705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * @return {Object} Item appendable to combobutton drop-down list. 7715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * @private 7725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) */ 7735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)FileTasks.prototype.createCombobuttonItem_ = function(task, opt_title, 7745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) opt_bold) { 7755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return { 7765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) label: opt_title || task.title, 7775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) iconUrl: task.iconUrl, 7785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) iconType: task.iconType, 7795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) task: task, 7805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bold: opt_bold || false 7815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) }; 7825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 7835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/** 7865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * Decorates a FileTasks method, so it will be actually executed after the tasks 7875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * are available. 7885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * This decorator expects an implementation called |method + '_'|. 7892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) * 7905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * @param {string} method The method name. 7915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) */ 7925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)FileTasks.decorate = function(method) { 7935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) var privateMethod = method + '_'; 7945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) FileTasks.prototype[method] = function() { 7955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (this.tasks_) { 7965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) this[privateMethod].apply(this, arguments); 7975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } else { 7985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) this.pendingInvocations_.push([privateMethod, arguments]); 7995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 8005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return this; 8015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) }; 8025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 8035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/** 8055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * Shows modal action picker dialog with currently available list of tasks. 8065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * 8075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * @param {DefaultActionDialog} actionDialog Action dialog to show and update. 8082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) * @param {string} title Title to use. 8092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) * @param {string} message Message to use. 8105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * @param {function(Object)} onSuccess Callback to pass selected task. 8115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) */ 8125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)FileTasks.prototype.showTaskPicker = function(actionDialog, title, message, 8135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) onSuccess) { 8145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) var items = this.createItems_(); 8155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) var defaultIdx = 0; 8175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) for (var j = 0; j < items.length; j++) { 818a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) if (items[j].task.taskId === this.defaultTask_.taskId) 8195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) defaultIdx = j; 8205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 8215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) actionDialog.show( 8235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) title, 8245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) message, 8255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) items, defaultIdx, 826c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) function(item) { 827c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) onSuccess(item.task); 828c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) }); 8295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 8305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)FileTasks.decorate('display'); 8325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)FileTasks.decorate('updateMenuItem'); 8335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)FileTasks.decorate('execute'); 8345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)FileTasks.decorate('executeDefault'); 835