Commit bde2b01f authored by Joel Hockey's avatar Joel Hockey Committed by Commit Bot

FilesApp crostini: show dialog when sharing root folders

When a user right-clicks and shares a root folder of a volume,
a dialog is shown for the user to confirm the action.

For Drive, the dialog with specific wording for Drive is shown
for My Drive, Team Drives, and Computers.

For other volumes, generic wording is used.

Bug: 878324
Change-Id: I92dad87c8e7b042dd45902d93e08e3cd66abc753
Reviewed-on: https://chromium-review.googlesource.com/c/1337109
Commit-Queue: Joel Hockey <joelhockey@chromium.org>
Reviewed-by: default avatarLuciano Pacheco <lucmult@chromium.org>
Cr-Commit-Position: refs/heads/master@{#608269}
parent 0dde1679
...@@ -1066,6 +1066,15 @@ ...@@ -1066,6 +1066,15 @@
<message name="IDS_FILE_BROWSER_UNABLE_TO_OPEN_CROSTINI" desc="Message shown when a user tries to use a crostini app to open a file which cannot be shared with the crostini container (e.g. in Play or USB). This message will be removed once we support this action."> <message name="IDS_FILE_BROWSER_UNABLE_TO_OPEN_CROSTINI" desc="Message shown when a user tries to use a crostini app to open a file which cannot be shared with the crostini container (e.g. in Play or USB). This message will be removed once we support this action.">
To open files with $1, first copy to Linux files folder. To open files with $1, first copy to Linux files folder.
</message> </message>
<message name="IDS_FILE_BROWSER_SHARE_ROOT_FOLDER_WITH_CROSTINI_TITLE" desc="Message title shown when a user shares the root of a volume such as Downloads with the crostini container.">
Share folder with Linux
</message>
<message name="IDS_FILE_BROWSER_SHARE_ROOT_FOLDER_WITH_CROSTINI" desc="Confirmation message shown when a user shares the root of a volume such as Downloads with the crostini container.">
Give Linux apps permission to open files in the $1 folder
</message>
<message name="IDS_FILE_BROWSER_SHARE_ROOT_FOLDER_WITH_CROSTINI_DRIVE" desc="Confirmation message shown when a user shares the root of a Drive volume (My Drive, Team Drives, Computers) with the crostini container.">
Give Linux apps permission to open files in your Google Drive. Changes will sync to your other devices.
</message>
<message name="IDS_FILE_BROWSER_FOLDER" desc="Folder entry type"> <message name="IDS_FILE_BROWSER_FOLDER" desc="Folder entry type">
Folder Folder
......
3c6b5ddde8e73fb4c40afefbdbb2a65303fa5f3b
\ No newline at end of file
b1d798df58f52d7710837c7e233319e162d85d8f
\ No newline at end of file
3c6b5ddde8e73fb4c40afefbdbb2a65303fa5f3b
\ No newline at end of file
...@@ -749,7 +749,12 @@ ExtensionFunction::ResponseAction FileManagerPrivateGetStringsFunction::Run() { ...@@ -749,7 +749,12 @@ ExtensionFunction::ResponseAction FileManagerPrivateGetStringsFunction::Run() {
SET_STRING("SET_WALLPAPER_BUTTON_LABEL", SET_STRING("SET_WALLPAPER_BUTTON_LABEL",
IDS_FILE_BROWSER_SET_WALLPAPER_BUTTON_LABEL); IDS_FILE_BROWSER_SET_WALLPAPER_BUTTON_LABEL);
SET_STRING("SHARE_ERROR", IDS_FILE_BROWSER_SHARE_ERROR); SET_STRING("SHARE_ERROR", IDS_FILE_BROWSER_SHARE_ERROR);
SET_STRING("SHARE_ROOT_FOLDER_WITH_CROSTINI_TITLE",
IDS_FILE_BROWSER_SHARE_ROOT_FOLDER_WITH_CROSTINI_TITLE);
SET_STRING("SHARE_ROOT_FOLDER_WITH_CROSTINI",
IDS_FILE_BROWSER_SHARE_ROOT_FOLDER_WITH_CROSTINI);
SET_STRING("SHARE_ROOT_FOLDER_WITH_CROSTINI_DRIVE",
IDS_FILE_BROWSER_SHARE_ROOT_FOLDER_WITH_CROSTINI_DRIVE);
SET_STRING("SIZE_BYTES", IDS_FILE_BROWSER_SIZE_BYTES); SET_STRING("SIZE_BYTES", IDS_FILE_BROWSER_SIZE_BYTES);
SET_STRING("SIZE_COLUMN_LABEL", IDS_FILE_BROWSER_SIZE_COLUMN_LABEL); SET_STRING("SIZE_COLUMN_LABEL", IDS_FILE_BROWSER_SIZE_COLUMN_LABEL);
SET_STRING("SIZE_GB", IDS_FILE_BROWSER_SIZE_GB); SET_STRING("SIZE_GB", IDS_FILE_BROWSER_SIZE_GB);
......
...@@ -1634,8 +1634,7 @@ CommandHandler.COMMANDS_['manage-in-drive'] = /** @type {Command} */ ({ ...@@ -1634,8 +1634,7 @@ CommandHandler.COMMANDS_['manage-in-drive'] = /** @type {Command} */ ({
/** /**
* Shares the selected (single only) Downloads subfolder with crostini * Shares the selected (single only) directory with the crostini container.
* container.
* @type {Command} * @type {Command}
*/ */
CommandHandler.COMMANDS_['share-with-linux'] = /** @type {Command} */ ({ CommandHandler.COMMANDS_['share-with-linux'] = /** @type {Command} */ ({
...@@ -1645,8 +1644,13 @@ CommandHandler.COMMANDS_['share-with-linux'] = /** @type {Command} */ ({ ...@@ -1645,8 +1644,13 @@ CommandHandler.COMMANDS_['share-with-linux'] = /** @type {Command} */ ({
*/ */
execute: function(event, fileManager) { execute: function(event, fileManager) {
const entry = CommandUtil.getCommandEntry(event.target); const entry = CommandUtil.getCommandEntry(event.target);
if (entry && entry.isDirectory) { if (!entry || !entry.isDirectory)
const dir = /** @type {!DirectoryEntry} */ (entry); return;
const dir = /** @type {!DirectoryEntry} */ (entry);
const info = fileManager.volumeManager.getLocationInfo(dir);
if (!info)
return;
function share() {
// Always persist shares via right-click > Share with Linux. // Always persist shares via right-click > Share with Linux.
chrome.fileManagerPrivate.sharePathsWithCrostini( chrome.fileManagerPrivate.sharePathsWithCrostini(
[dir], true /* persist */, () => { [dir], true /* persist */, () => {
...@@ -1658,9 +1662,32 @@ CommandHandler.COMMANDS_['share-with-linux'] = /** @type {Command} */ ({ ...@@ -1658,9 +1662,32 @@ CommandHandler.COMMANDS_['share-with-linux'] = /** @type {Command} */ ({
Crostini.registerSharedPath(dir, fileManager.volumeManager); Crostini.registerSharedPath(dir, fileManager.volumeManager);
} }
}); });
CommandHandler.recordMenuItemSelected_(
CommandHandler.MenuCommandsForUMA.SHARE_WITH_LINUX);
} }
// Show a confirmation dialog if we are sharing the root of a volume.
// Non-Drive volume roots are always '/'.
if (dir.fullPath == '/') {
fileManager.ui_.confirmDialog.showHtml(
strf('SHARE_ROOT_FOLDER_WITH_CROSTINI_TITLE'),
strf('SHARE_ROOT_FOLDER_WITH_CROSTINI', info.volumeInfo.label), share,
() => {});
} else if (
info.isRootEntry &&
(info.rootType == VolumeManagerCommon.RootType.DRIVE ||
info.rootType == VolumeManagerCommon.RootType.COMPUTERS_GRAND_ROOT ||
info.rootType ==
VolumeManagerCommon.RootType.TEAM_DRIVES_GRAND_ROOT)) {
// Only show the dialog for My Drive, Team Drives Grand Root and
// Computers Grand Root. Do not show for roots of a single Team Drive
// or Computer.
fileManager.ui_.confirmDialog.showHtml(
strf('SHARE_ROOT_FOLDER_WITH_CROSTINI_TITLE'),
strf('SHARE_ROOT_FOLDER_WITH_CROSTINI_DRIVE'), share, () => {});
} else {
// This is not a root, share it without confirmation dialog.
share();
}
CommandHandler.recordMenuItemSelected_(
CommandHandler.MenuCommandsForUMA.SHARE_WITH_LINUX);
}, },
/** /**
* @param {!Event} event Command event. * @param {!Event} event Command event.
......
...@@ -9,7 +9,14 @@ crostiniShare.testSharePathsCrostiniSuccess = (done) => { ...@@ -9,7 +9,14 @@ crostiniShare.testSharePathsCrostiniSuccess = (done) => {
'[command="#share-with-linux"][hidden][disabled="disabled"]'; '[command="#share-with-linux"][hidden][disabled="disabled"]';
const menuShareWithLinux = '#file-context-menu:not([hidden]) ' + const menuShareWithLinux = '#file-context-menu:not([hidden]) ' +
'[command="#share-with-linux"]:not([hidden]):not([disabled])'; '[command="#share-with-linux"]:not([hidden]):not([disabled])';
const shareWithLinux = '#file-context-menu [command="#share-with-linux"]';
const menuShareWithLinuxDirTree =
'#directory-tree-context-menu:not([hidden]) ' +
'[command="#share-with-linux"]:not([hidden]):not([disabled])';
const shareWithLinuxDirTree =
'#directory-tree-context-menu [command="#share-with-linux"]';
const photos = '#file-list [file-name="photos"]'; const photos = '#file-list [file-name="photos"]';
const downloadsDirTree = '#directory-tree [volume-type-icon="downloads"]';
const oldSharePaths = chrome.fileManagerPrivate.sharePathsWithCrostini; const oldSharePaths = chrome.fileManagerPrivate.sharePathsWithCrostini;
let sharePathsCalled = false; let sharePathsCalled = false;
let sharePathsPersist; let sharePathsPersist;
...@@ -39,10 +46,7 @@ crostiniShare.testSharePathsCrostiniSuccess = (done) => { ...@@ -39,10 +46,7 @@ crostiniShare.testSharePathsCrostiniSuccess = (done) => {
}) })
.then(() => { .then(() => {
// Click on 'Share with Linux'. // Click on 'Share with Linux'.
assertTrue( assertTrue(test.fakeMouseClick(shareWithLinux, 'Share with Linux'));
test.fakeMouseClick(
'#file-context-menu [command="#share-with-linux"]'),
'Share with Linux');
// Check sharePathsWithCrostini is called. // Check sharePathsWithCrostini is called.
return test.repeatUntil(() => { return test.repeatUntil(() => {
return sharePathsCalled || test.pending('wait for sharePathsCalled'); return sharePathsCalled || test.pending('wait for sharePathsCalled');
...@@ -86,6 +90,25 @@ crostiniShare.testSharePathsCrostiniSuccess = (done) => { ...@@ -86,6 +90,25 @@ crostiniShare.testSharePathsCrostiniSuccess = (done) => {
assertTrue(test.fakeMouseRightClick(photos), 'right-click photos'); assertTrue(test.fakeMouseRightClick(photos), 'right-click photos');
return test.waitForElement(menuShareWithLinux); return test.waitForElement(menuShareWithLinux);
}) })
.then(() => {
// Verify dialog is shown for Downloads root.
// Check 'Share with Linux' is shown in menu.
assertTrue(
test.fakeMouseRightClick(downloadsDirTree),
'right-click downloads');
return test.waitForElement(menuShareWithLinuxDirTree);
})
.then(() => {
// Click 'Share with Linux', verify dialog.
assertTrue(
test.fakeMouseClick(shareWithLinuxDirTree, 'Share with Linux'));
return test.waitForElement('.cr-dialog-container.shown');
})
.then(() => {
// Click Cancel button to close.
assertTrue(test.fakeMouseClick('button.cr-dialog-cancel'));
return test.waitForElementLost('.cr-dialog-container');
})
.then(() => { .then(() => {
// Restore fmp.*. // Restore fmp.*.
chrome.fileManagerPrivate.sharePathsWithCrostini = oldSharePaths; chrome.fileManagerPrivate.sharePathsWithCrostini = oldSharePaths;
......
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