Commit 0e2e9f24 authored by mtomasz's avatar mtomasz Committed by Commit bot

Add a menu item for configuring configurable providers.

TEST=Tested manually with a fake provider extension.
BUG=474146

Review URL: https://codereview.chromium.org/1136193002

Cr-Commit-Position: refs/heads/master@{#329796}
parent b10c773c
...@@ -244,6 +244,9 @@ Press any key to continue exploring. ...@@ -244,6 +244,9 @@ Press any key to continue exploring.
<message name="IDS_FILE_BROWSER_FORMAT_DEVICE_BUTTON_LABEL" desc="Title of the action for formatting removable device."> <message name="IDS_FILE_BROWSER_FORMAT_DEVICE_BUTTON_LABEL" desc="Title of the action for formatting removable device.">
Format device Format device
</message> </message>
<message name="IDS_FILE_BROWSER_CONFIGURE_VOLUME_BUTTON_LABEL" desc="Title of the action for configuring the selected volume.">
Configure
</message>
<message name="IDS_FILE_BROWSER_UNMOUNT_DEVICE_BUTTON_LABEL" desc="Title of the action for unmounting removable device."> <message name="IDS_FILE_BROWSER_UNMOUNT_DEVICE_BUTTON_LABEL" desc="Title of the action for unmounting removable device.">
Eject device Eject device
</message> </message>
......
...@@ -309,6 +309,8 @@ bool FileManagerPrivateGetStringsFunction::RunSync() { ...@@ -309,6 +309,8 @@ bool FileManagerPrivateGetStringsFunction::RunSync() {
SET_STRING("CLOUD_IMPORT_TOOLTIP_SCANNING", SET_STRING("CLOUD_IMPORT_TOOLTIP_SCANNING",
IDS_FILE_BROWSER_CLOUD_IMPORT_TOOLTIP_SCANNING); IDS_FILE_BROWSER_CLOUD_IMPORT_TOOLTIP_SCANNING);
SET_STRING("CONFIGURE_VOLUME_BUTTON_LABEL",
IDS_FILE_BROWSER_CONFIGURE_VOLUME_BUTTON_LABEL);
SET_STRING("CONFIRM_MOBILE_DATA_USE", SET_STRING("CONFIRM_MOBILE_DATA_USE",
IDS_FILE_BROWSER_CONFIRM_MOBILE_DATA_USE); IDS_FILE_BROWSER_CONFIRM_MOBILE_DATA_USE);
SET_STRING("CONFIRM_MOBILE_DATA_USE_PLURAL", SET_STRING("CONFIRM_MOBILE_DATA_USE_PLURAL",
......
...@@ -110,14 +110,15 @@ MockVolumeManager.createMockVolumeInfo = function(type, volumeId, label) { ...@@ -110,14 +110,15 @@ MockVolumeManager.createMockVolumeInfo = function(type, volumeId, label) {
type, type,
volumeId, volumeId,
fileSystem, fileSystem,
'', // error '', // error
'', // deviceType '', // deviceType
'', // devicePath '', // devicePath
false, // isReadonly false, // isReadonly
{isCurrentProfile: true, displayName: ''}, // profile {isCurrentProfile: true, displayName: ''}, // profile
label, // label label, // label
'', // extensionId '', // extensionId
false); // hasMedia false, // hasMedia
false); // configurable
return volumeInfo; return volumeInfo;
}; };
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
* volume. Empty for native volumes. * volume. Empty for native volumes.
* @param {boolean} hasMedia When true the volume has been identified * @param {boolean} hasMedia When true the volume has been identified
* as containing media such as photos or videos. * as containing media such as photos or videos.
* @param {boolean} configurable When true, then the volume can be configured.
*/ */
function VolumeInfo( function VolumeInfo(
volumeType, volumeType,
...@@ -38,7 +39,8 @@ function VolumeInfo( ...@@ -38,7 +39,8 @@ function VolumeInfo(
profile, profile,
label, label,
extensionId, extensionId,
hasMedia) { hasMedia,
configurable) {
this.volumeType_ = volumeType; this.volumeType_ = volumeType;
this.volumeId_ = volumeId; this.volumeId_ = volumeId;
this.fileSystem_ = fileSystem; this.fileSystem_ = fileSystem;
...@@ -80,6 +82,7 @@ function VolumeInfo( ...@@ -80,6 +82,7 @@ function VolumeInfo(
this.profile_ = Object.freeze(profile); this.profile_ = Object.freeze(profile);
this.extensionId_ = extensionId; this.extensionId_ = extensionId;
this.hasMedia_ = hasMedia; this.hasMedia_ = hasMedia;
this.configurable_ = configurable;
} }
VolumeInfo.prototype = /** @struct */ { VolumeInfo.prototype = /** @struct */ {
...@@ -161,6 +164,12 @@ VolumeInfo.prototype = /** @struct */ { ...@@ -161,6 +164,12 @@ VolumeInfo.prototype = /** @struct */ {
*/ */
get hasMedia() { get hasMedia() {
return this.hasMedia_; return this.hasMedia_;
},
/**
* @return {boolean} True if the volume is configurable.
*/
get configurable() {
return this.configurable_;
} }
}; };
...@@ -245,20 +254,44 @@ volumeManagerUtil.createVolumeInfo = function(volumeMetadata) { ...@@ -245,20 +254,44 @@ volumeManagerUtil.createVolumeInfo = function(volumeMetadata) {
} }
console.debug('Requesting file system.'); console.debug('Requesting file system.');
var configurable = false;
return new Promise( return new Promise(
function(resolve, reject) { function(resolve, reject) {
chrome.fileSystem.requestFileSystem( if (volumeMetadata.volumeType !==
{ VolumeManagerCommon.VolumeType.PROVIDED) {
volumeId: volumeMetadata.volumeId, resolve();
writable: !volumeMetadata.isReadOnly }
},
function(isolatedFileSystem) { chrome.fileManagerPrivate.getProvidingExtensions(
if (chrome.runtime.lastError) function(extensions) {
if (chrome.runtime.lastError) {
reject(chrome.runtime.lastError.message); reject(chrome.runtime.lastError.message);
else return;
resolve(isolatedFileSystem); }
configurable = extensions.some(function(extension) {
return extension.extensionId === volumeMetadata.extensionId &&
extension.configurable;
});
resolve();
}); });
}) })
.then(
function() {
return new Promise(function(resolve, reject) {
chrome.fileSystem.requestFileSystem(
{
volumeId: volumeMetadata.volumeId,
writable: !volumeMetadata.isReadOnly
},
function(isolatedFileSystem) {
if (chrome.runtime.lastError)
reject(chrome.runtime.lastError.message);
else
resolve(isolatedFileSystem);
});
});
})
.then( .then(
/** /**
* @param {!FileSystem} isolatedFileSystem * @param {!FileSystem} isolatedFileSystem
...@@ -313,7 +346,8 @@ volumeManagerUtil.createVolumeInfo = function(volumeMetadata) { ...@@ -313,7 +346,8 @@ volumeManagerUtil.createVolumeInfo = function(volumeMetadata) {
volumeMetadata.profile, volumeMetadata.profile,
localizedLabel, localizedLabel,
volumeMetadata.extensionId, volumeMetadata.extensionId,
volumeMetadata.hasMedia); volumeMetadata.hasMedia,
configurable);
}) })
.catch( .catch(
/** /**
...@@ -335,7 +369,8 @@ volumeManagerUtil.createVolumeInfo = function(volumeMetadata) { ...@@ -335,7 +369,8 @@ volumeManagerUtil.createVolumeInfo = function(volumeMetadata) {
volumeMetadata.profile, volumeMetadata.profile,
localizedLabel, localizedLabel,
volumeMetadata.extensionId, volumeMetadata.extensionId,
volumeMetadata.hasMedia); volumeMetadata.hasMedia,
configurable);
}); });
}; };
......
...@@ -254,7 +254,8 @@ function testVolumeInfoListWhenReady(callback) { ...@@ -254,7 +254,8 @@ function testVolumeInfoListWhenReady(callback) {
/* profile */ {}, /* profile */ {},
/* label */ null, /* label */ null,
/* extensionid */ null, /* extensionid */ null,
/* hasMedia */ false); /* hasMedia */ false,
/* configurable */ false);
list.add(volumeInfo); list.add(volumeInfo);
var promiseAfterAdd = list.whenVolumeInfoReady('volumeId'); var promiseAfterAdd = list.whenVolumeInfoReady('volumeId');
reportPromise(Promise.all([promiseBeforeAdd, promiseAfterAdd]).then( reportPromise(Promise.all([promiseBeforeAdd, promiseAfterAdd]).then(
......
...@@ -321,7 +321,8 @@ CommandHandler.prototype.onCommand_ = function(event) { ...@@ -321,7 +321,8 @@ CommandHandler.prototype.onCommand_ = function(event) {
if (this.shouldIgnoreEvents_()) if (this.shouldIgnoreEvents_())
return; return;
var handler = CommandHandler.COMMANDS_[event.command.id]; var handler = CommandHandler.COMMANDS_[event.command.id];
handler.execute.call(/** @type {Command} */ (this), event, this.fileManager_); handler.execute.call(/** @type {Command} */ (handler), event,
this.fileManager_);
}; };
/** /**
...@@ -333,7 +334,7 @@ CommandHandler.prototype.onCanExecute_ = function(event) { ...@@ -333,7 +334,7 @@ CommandHandler.prototype.onCanExecute_ = function(event) {
if (this.shouldIgnoreEvents_()) if (this.shouldIgnoreEvents_())
return; return;
var handler = CommandHandler.COMMANDS_[event.command.id]; var handler = CommandHandler.COMMANDS_[event.command.id];
handler.canExecute.call(/** @type {Command} */ (this), event, handler.canExecute.call(/** @type {Command} */ (handler), event,
this.fileManager_); this.fileManager_);
}; };
...@@ -383,7 +384,7 @@ CommandHandler.COMMANDS_['unmount'] = /** @type {Command} */ ({ ...@@ -383,7 +384,7 @@ CommandHandler.COMMANDS_['unmount'] = /** @type {Command} */ ({
var root = CommandUtil.getCommandEntry(event.target); var root = CommandUtil.getCommandEntry(event.target);
if (!root) if (!root)
return; return;
var locationInfo = this.fileManager_.volumeManager.getLocationInfo(root); var locationInfo = fileManager.volumeManager.getLocationInfo(root);
var rootType = var rootType =
locationInfo && locationInfo.isRootEntry && locationInfo.rootType; locationInfo && locationInfo.isRootEntry && locationInfo.rootType;
...@@ -1320,3 +1321,73 @@ CommandHandler.COMMANDS_['install-new-extension'] = /** @type {Command} */ ({ ...@@ -1320,3 +1321,73 @@ CommandHandler.COMMANDS_['install-new-extension'] = /** @type {Command} */ ({
}, },
canExecute: CommandUtil.canExecuteAlways canExecute: CommandUtil.canExecuteAlways
}); });
/**
* Configures the currently selected volume.
*/
CommandHandler.COMMANDS_['configure'] = (function() {
/**
* @constructor
* @implements {Command}
*/
var ConfigureCommand = function() {
};
ConfigureCommand.prototype = {
__proto__: Command.prototype,
/**
* @param {EventTarget} element
* @param {!FileManager} fileManager
* @return {VolumeInfo}
* @private
*/
getElementVolumeInfo_: function(element, fileManager) {
if (element instanceof VolumeItem)
return element.volumeInfo;
if (element instanceof ShortcutItem) {
return element.entry && fileManager.volumeManager.getVolumeInfo(
element.entry);
}
},
/**
* If the command is executed on the navigation list, then use it's volume
* info, otherwise use the currently opened volume.
*
* @param {!Event} event
* @param {!FileManager} fileManager
* @return {VolumeInfo}
* @private
*/
getCommandVolumeInfo_: function(event, fileManager) {
var currentDirEntry = fileManager.directoryModel.getCurrentDirEntry();
return this.getElementVolumeInfo_(event.target, fileManager) ||
currentDirEntry && fileManager.volumeManager.getVolumeInfo(
currentDirEntry);
},
/**
* @override
*/
execute: function(event, fileManager) {
var volumeInfo = this.getCommandVolumeInfo_(event, fileManager);
if (volumeInfo && volumeInfo.configurable) {
fileManager.providersModel.requestConfigure(
assert(volumeInfo.extensionId));
}
},
/**
* @override
*/
canExecute: function(event, fileManager) {
var volumeInfo = this.getCommandVolumeInfo_(event, fileManager);
event.canExecute = volumeInfo && volumeInfo.configurable;
event.command.setHidden(!event.canExecute);
}
};
return new ConfigureCommand();
})();
...@@ -145,3 +145,15 @@ ProvidersModel.prototype.requestMount = function(extensionId) { ...@@ -145,3 +145,15 @@ ProvidersModel.prototype.requestMount = function(extensionId) {
console.error(chrome.runtime.lastError.message); console.error(chrome.runtime.lastError.message);
}); });
}; };
/**
* @param {string} extensionId
*/
ProvidersModel.prototype.requestConfigure = function(extensionId) {
chrome.fileManagerPrivate.configureProvidedFileSystem(
assert(extensionId),
function() {
if (chrome.runtime.lastError)
console.error(chrome.runtime.lastError.message);
});
};
...@@ -460,6 +460,15 @@ VolumeItem.prototype = { ...@@ -460,6 +460,15 @@ VolumeItem.prototype = {
get entry() { get entry() {
return this.volumeInfo_.displayRoot; return this.volumeInfo_.displayRoot;
}, },
/**
* @type {!VolumeInfo}
*/
get volumeInfo() {
return this.volumeInfo_;
},
/**
* @type {!NavigationModelVolumeItem}
*/
get modelItem() { get modelItem() {
return this.modelItem_; return this.modelItem_;
} }
......
...@@ -235,6 +235,7 @@ ...@@ -235,6 +235,7 @@
<command id="unmount" i18n-values="label:UNMOUNT_DEVICE_BUTTON_LABEL" <command id="unmount" i18n-values="label:UNMOUNT_DEVICE_BUTTON_LABEL"
shortcut="U+0045-Shift-Ctrl"><!-- Shortcut: 'Shift-Ctrl-E' --> shortcut="U+0045-Shift-Ctrl"><!-- Shortcut: 'Shift-Ctrl-E' -->
<command id="format" i18n-values="label:FORMAT_DEVICE_BUTTON_LABEL"> <command id="format" i18n-values="label:FORMAT_DEVICE_BUTTON_LABEL">
<command id="configure" i18n-values="label:CONFIGURE_VOLUME_BUTTON_LABEL">
<command id="volume-help" i18n-values="label:DRIVE_MENU_HELP"> <command id="volume-help" i18n-values="label:DRIVE_MENU_HELP">
<command id="drive-buy-more-space" <command id="drive-buy-more-space"
...@@ -297,6 +298,7 @@ ...@@ -297,6 +298,7 @@
</cr-menu> </cr-menu>
<cr-menu id="roots-context-menu" class="chrome-menu" > <cr-menu id="roots-context-menu" class="chrome-menu" >
<cr-menu-item command="#configure"></cr-menu-item>
<cr-menu-item command="#unmount"></cr-menu-item> <cr-menu-item command="#unmount"></cr-menu-item>
<cr-menu-item command="#format"></cr-menu-item> <cr-menu-item command="#format"></cr-menu-item>
<cr-menu-item command="#remove-folder-shortcut"></cr-menu-item> <cr-menu-item command="#remove-folder-shortcut"></cr-menu-item>
...@@ -322,6 +324,7 @@ ...@@ -322,6 +324,7 @@
<cr-menu-item id="gear-menu-newwindow" command="#new-window"></cr-menu-item> <cr-menu-item id="gear-menu-newwindow" command="#new-window"></cr-menu-item>
<cr-menu-item id="gear-menu-newfolder" command="#new-folder"></cr-menu-item> <cr-menu-item id="gear-menu-newfolder" command="#new-folder"></cr-menu-item>
<hr> <hr>
<cr-menu-item command="#configure"></cr-menu-item>
<cr-menu-item id="gear-menu-toggle-hidden-files" <cr-menu-item id="gear-menu-toggle-hidden-files"
command="#toggle-hidden-files"></cr-menu-item> command="#toggle-hidden-files"></cr-menu-item>
<cr-menu-item id="gear-menu-drive-sync-settings" <cr-menu-item id="gear-menu-drive-sync-settings"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment