/**
* This object encapsulates everything related to tasks execution.
*
+ * TODO(hirono): Pass each component instead of the entire FileManager.
* @param {FileManager} fileManager FileManager instance.
* @param {Object=} opt_params File manager load parameters.
* @constructor
}
/**
- * Location of the FAQ about the file actions.
- *
- * @const
- * @type {string}
- */
-FileTasks.NO_ACTION_FOR_FILE_URL = 'http://support.google.com/chromeos/bin/' +
- 'answer.py?answer=1700055&topic=29026&ctx=topic';
-
-/**
* Location of the Chrome Web Store.
*
* @const
* @type {Array.<string>}
* @private
*/
-FileTasks.knownExtensions_ = [
+FileTasks.UMA_INDEX_KNOWN_EXTENSIONS_ = Object.freeze([
'other', '.3ga', '.3gp', '.aac', '.alac', '.asf', '.avi', '.bmp', '.csv',
- '.doc', '.docx', '.flac', '.gif', '.ico', '.jpeg', '.jpg', '.log', '.m3u',
- '.m3u8', '.m4a', '.m4v', '.mid', '.mkv', '.mov', '.mp3', '.mp4', '.mpg',
- '.odf', '.odp', '.ods', '.odt', '.oga', '.ogg', '.ogv', '.pdf', '.png',
- '.ppt', '.pptx', '.ra', '.ram', '.rar', '.rm', '.rtf', '.wav', '.webm',
- '.webp', '.wma', '.wmv', '.xls', '.xlsx',
-];
+ '.doc', '.docx', '.flac', '.gif', '.jpeg', '.jpg', '.log', '.m3u', '.m3u8',
+ '.m4a', '.m4v', '.mid', '.mkv', '.mov', '.mp3', '.mp4', '.mpg', '.odf',
+ '.odp', '.ods', '.odt', '.oga', '.ogg', '.ogv', '.pdf', '.png', '.ppt',
+ '.pptx', '.ra', '.ram', '.rar', '.rm', '.rtf', '.wav', '.webm', '.webp',
+ '.wma', '.wmv', '.xls', '.xlsx',
+]);
/**
* The list of excutable file extensions.
for (var i = 0; i < entries.length; i++) {
var entry = entries[i];
var extension = FileType.getExtension(entry).toLowerCase();
- if (FileTasks.knownExtensions_.indexOf(extension) < 0) {
+ if (FileTasks.UMA_INDEX_KNOWN_EXTENSIONS_.indexOf(extension) < 0) {
extension = 'other';
}
metrics.recordEnum(
- 'ViewingFileType', extension, FileTasks.knownExtensions_);
+ 'ViewingFileType', extension, FileTasks.UMA_INDEX_KNOWN_EXTENSIONS_);
}
};
this.tasks_ = [];
var id = chrome.runtime.id;
var isOnDrive = false;
+ var fm = this.fileManager_;
for (var index = 0; index < this.entries_.length; ++index) {
- // TODO(mtomasz): Use Entry instead of paths.
- if (PathUtil.isDriveBasedPath(this.entries_[index].fullPath)) {
+ var locationInfo = fm.volumeManager.getLocationInfo(this.entries_[index]);
+ if (locationInfo && locationInfo.isDriveBased) {
isOnDrive = true;
break;
}
}
var webStoreUrl = FileTasks.createWebStoreLink(extension, mimeType);
- var text = strf(textMessageId,
- webStoreUrl,
- FileTasks.NO_ACTION_FOR_FILE_URL);
+ var text = strf(textMessageId, webStoreUrl, str('NO_ACTION_FOR_FILE_URL'));
var title = titleMessageId ? str(titleMessageId) : filename;
this.fileManager_.alert.showHtml(title, text, function() {});
callback(false, urls);
var onViewFilesFailure = function() {
var fm = this.fileManager_;
- if (fm.enableExperimentalWebStoreIntegration_) {
- showAlert();
- return;
- }
-
if (!fm.isOnDrive() ||
!entries[0] ||
FileTasks.EXTENSIONS_TO_SKIP_SUGGEST_APPS_.indexOf(extension) !== -1) {
showAlert);
}.bind(this);
- var onViewFiles = function(success) {
- if (success)
- callback(success, entries);
- else
- onViewFilesFailure();
+ var onViewFiles = function(result) {
+ switch (result) {
+ case 'opened':
+ callback(success, entries);
+ break;
+ case 'message_sent':
+ util.isTeleported(window).then(function(teleported) {
+ if (teleported) {
+ util.showOpenInOtherDesktopAlert(
+ this.fileManager_.ui.alertDialog, entries);
+ }
+ }.bind(this));
+ callback(success, entries);
+ break;
+ case 'empty':
+ callback(success, entries);
+ break;
+ case 'failed':
+ onViewFilesFailure();
+ break;
+ }
}.bind(this);
this.checkAvailability_(function() {
// TODO(mtomasz): Pass entries instead.
var urls = util.entriesToURLs(entries);
- util.viewFilesInBrowser(urls, onViewFiles);
+ var taskId = chrome.runtime.id + '|file|view-in-browser';
+ chrome.fileBrowserPrivate.executeTask(taskId, urls, onViewFiles);
}.bind(this));
};
} else {
// TODO(mtomasz): Pass entries instead.
var urls = util.entriesToURLs(entries);
- chrome.fileBrowserPrivate.executeTask(taskId, urls);
+ chrome.fileBrowserPrivate.executeTask(taskId, urls, function(result) {
+ if (result !== 'message_sent')
+ return;
+ util.isTeleported(window).then(function(teleported) {
+ if (teleported) {
+ util.showOpenInOtherDesktopAlert(
+ this.fileManager_.ui.alertDialog, entries);
+ }
+ }.bind(this));
+ }.bind(this));
}
}.bind(this));
};
}
// TODO(mtomasz): Pass entries instead.
var urls = util.entriesToURLs(entries);
- fm.backgroundPage.launchAudioPlayer({items: urls, position: position});
+ chrome.fileBrowserPrivate.getProfiles(function(profiles,
+ currentId,
+ displayedId) {
+ fm.backgroundPage.launchAudioPlayer({items: urls, position: position},
+ displayedId);
+ });
return;
}
if (id === 'watch') {
console.assert(entries.length === 1, 'Cannot open multiple videos');
// TODO(mtomasz): Pass an entry instead.
- fm.backgroundPage.launchVideoPlayer(entries[0].toURL());
+ chrome.fileBrowserPrivate.getProfiles(function(profiles,
+ currentId,
+ displayedId) {
+ fm.backgroundPage.launchVideoPlayer(entries[0].toURL(), displayedId);
+ });
return;
}
for (var index = 0; index < resolvedURLs.length; ++index) {
// TODO(mtomasz): Pass Entry instead of URL.
fm.volumeManager.mountArchive(resolvedURLs[index],
- function(mountPath) {
+ function(volumeInfo) {
if (tracker.hasChanged) {
tracker.stop();
return;
}
- var volumeInfo = fm.volumeManager.getVolumeInfo(mountPath);
- if (!volumeInfo) {
- tracker.stop();
- return;
- }
volumeInfo.resolveDisplayRoot(function(displayRoot) {
if (tracker.hasChanged) {
tracker.stop();
if (this.params_ && this.params_.gallery) {
// Remove the Gallery state from the location, we do not need it any more.
- util.updateAppState(null /* keep path */, '' /* remove search. */);
+ // TODO(mtomasz): Consider keeping the selection path.
+ util.updateAppState(
+ null, /* keep current directory */
+ '', /* remove current selection */
+ '' /* remove search. */);
}
- var savedAppState = window.appState;
+ var savedAppState = JSON.parse(JSON.stringify(window.appState));
var savedTitle = document.title;
// Push a temporary state which will be replaced every time the selection
onClose: onClose,
onMaximize: onMaximize,
onAppRegionChanged: onAppRegionChanged,
- displayStringFunction: strf
+ loadTimeData: fm.backgroundPage.background.stringData
};
galleryFrame.contentWindow.Gallery.open(
context, fm.volumeManager, allEntries, entries);
};
};
-
-/**
- * Decorates a FileTasks method, so it will be actually executed after the tasks
- * are available.
- * This decorator expects an implementation called |method + '_'|.
- *
- * @param {string} method The method name.
- */
-FileTasks.decorate = function(method) {
- var privateMethod = method + '_';
- FileTasks.prototype[method] = function() {
- if (this.tasks_) {
- this[privateMethod].apply(this, arguments);
- } else {
- this.pendingInvocations_.push([privateMethod, arguments]);
- }
- return this;
- };
-};
-
/**
* Shows modal action picker dialog with currently available list of tasks.
*
});
};
+/**
+ * Decorates a FileTasks method, so it will be actually executed after the tasks
+ * are available.
+ * This decorator expects an implementation called |method + '_'|.
+ *
+ * @param {string} method The method name.
+ */
+FileTasks.decorate = function(method) {
+ var privateMethod = method + '_';
+ FileTasks.prototype[method] = function() {
+ if (this.tasks_) {
+ this[privateMethod].apply(this, arguments);
+ } else {
+ this.pendingInvocations_.push([privateMethod, arguments]);
+ }
+ return this;
+ };
+};
+
FileTasks.decorate('display');
FileTasks.decorate('updateMenuItem');
FileTasks.decorate('execute');