diff options
author | hirono <hirono@chromium.org> | 2016-02-17 18:39:52 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-02-18 02:40:53 +0000 |
commit | e820f8581d44df14269df140fc71d70adde7262b (patch) | |
tree | a25d883002e5d63cf63fa1d4b041304961fa6108 /ui/file_manager | |
parent | 1e98e71f2553af527d1c1641e55fa26fb3076396 (diff) | |
download | chromium_src-e820f8581d44df14269df140fc71d70adde7262b.zip chromium_src-e820f8581d44df14269df140fc71d70adde7262b.tar.gz chromium_src-e820f8581d44df14269df140fc71d70adde7262b.tar.bz2 |
Hide non-native volumes when saving files from the browser.
Chrome browser opens Files app as a file saving dialog. The caller of saving
dialog has a special handling for drive paths, but it does not handle other
non-native paths (e.g. FSP, MTP)
The CL lets Files app know which types of paths are handled by caller and hide
volumes that are not supported by caller.
BUG=581984
TEST=Check with standalone Files app, save dialog, open dialog
Review URL: https://codereview.chromium.org/1701163003
Cr-Commit-Position: refs/heads/master@{#376073}
Diffstat (limited to 'ui/file_manager')
8 files changed, 111 insertions, 90 deletions
diff --git a/ui/file_manager/audio_player/js/audio_player.js b/ui/file_manager/audio_player/js/audio_player.js index 4c25498..8241903 100644 --- a/ui/file_manager/audio_player/js/audio_player.js +++ b/ui/file_manager/audio_player/js/audio_player.js @@ -14,8 +14,7 @@ ContentMetadataProvider.WORKER_SCRIPT = '/js/metadata_worker.js'; */ function AudioPlayer(container) { this.container_ = container; - this.volumeManager_ = new VolumeManagerWrapper( - VolumeManagerWrapper.NonNativeVolumeStatus.ENABLED); + this.volumeManager_ = new VolumeManagerWrapper(AllowedPaths.ANY_PATH); this.metadataModel_ = MetadataModel.create(this.volumeManager_); this.selectedEntry_ = null; this.invalidTracks_ = {}; diff --git a/ui/file_manager/file_manager/common/js/volume_manager_common.js b/ui/file_manager/file_manager/common/js/volume_manager_common.js index 46a1a07..62e3c96 100644 --- a/ui/file_manager/file_manager/common/js/volume_manager_common.js +++ b/ui/file_manager/file_manager/common/js/volume_manager_common.js @@ -9,6 +9,17 @@ var VolumeManagerCommon = {}; /** + * Paths that can be handled by the dialog opener in native code. + * @enum {string} + * @const + */ +var AllowedPaths = { + NATIVE_PATH: 'nativePath', + NATIVE_OR_DRIVE_PATH: 'nativeOrDrivePath', + ANY_PATH: 'anyPath' +}; + +/** * Type of a root directory. * @enum {string} * @const diff --git a/ui/file_manager/file_manager/foreground/js/dialog_action_controller.js b/ui/file_manager/file_manager/foreground/js/dialog_action_controller.js index 1aa179f..5fc24d99 100644 --- a/ui/file_manager/file_manager/foreground/js/dialog_action_controller.js +++ b/ui/file_manager/file_manager/foreground/js/dialog_action_controller.js @@ -94,11 +94,11 @@ function DialogActionController( this.fileTypes_ = launchParam.typeList || []; /** - * @type {boolean} + * @type {!AllowedPaths} * @const * @private */ - this.shouldReturnLocalPath_ = launchParam.shouldReturnLocalPath; + this.allowedPaths_ = launchParam.allowedPaths; /** * Bound function for onCancel_. @@ -287,14 +287,14 @@ DialogActionController.prototype.selectFilesAndClose_ = function(selection) { if (selection.multiple) { chrome.fileManagerPrivate.selectFiles( selection.urls, - this.shouldReturnLocalPath_, + this.allowedPaths_ === AllowedPaths.NATIVE_PATH, onFileSelected); } else { chrome.fileManagerPrivate.selectFile( selection.urls[0], selection.filterIndex, this.dialogType_ !== DialogType.SELECT_SAVEAS_FILE /* for opening */, - this.shouldReturnLocalPath_, + this.allowedPaths_ === AllowedPaths.NATIVE_PATH, onFileSelected); } }.bind(this); diff --git a/ui/file_manager/file_manager/foreground/js/file_manager.js b/ui/file_manager/file_manager/foreground/js/file_manager.js index 404bb3cb..811a998 100644 --- a/ui/file_manager/file_manager/foreground/js/file_manager.js +++ b/ui/file_manager/file_manager/foreground/js/file_manager.js @@ -745,24 +745,27 @@ FileManager.prototype = /** @struct */ { * @private */ FileManager.prototype.initVolumeManager_ = function() { - // Auto resolving to local path does not work for folders (e.g., dialog for - // loading unpacked extensions). - var noLocalPathResolution = - DialogType.isFolderDialog(this.launchParams_.type); + var allowedPaths = this.launchParams_.allowedPaths; + // Files.app native implementation create snapshot files for non-native + // files. But it does not work for folders (e.g., dialog for loading + // unpacked extensions). + if (allowedPaths === AllowedPaths.NATIVE_PATH && + !DialogType.isFolderDialog(this.launchParams_.type) && + this.launchParams_.type != DialogType.SELECT_SAVEAS_FILE) { + allowedPaths = AllowedPaths.ANY_PATH; + } - // If this condition is false, VolumeManagerWrapper hides all drive - // related event and data, even if Drive is enabled on preference. + // VolumeManagerWrapper hides virtual file system related event and data + // even depends on the value of |supportVirtualPath|. If it is + // VirtualPathSupport.NO_VIRTUAL_PATH, it hides Drive even if Drive is + // enabled on preference. // In other words, even if Drive is disabled on preference but Files.app // should show Drive when it is re-enabled, then the value should be set to // true. // Note that the Drive enabling preference change is listened by // DriveIntegrationService, so here we don't need to take care about it. - var nonNativeEnabled = - !noLocalPathResolution || !this.launchParams_.shouldReturnLocalPath; this.volumeManager_ = new VolumeManagerWrapper( - /** @type {VolumeManagerWrapper.NonNativeVolumeStatus} */ - (nonNativeEnabled), - this.backgroundPage_); + allowedPaths, this.backgroundPage_); }; /** diff --git a/ui/file_manager/file_manager/foreground/js/launch_param.js b/ui/file_manager/file_manager/foreground/js/launch_param.js index a987dd7..47f121a 100644 --- a/ui/file_manager/file_manager/foreground/js/launch_param.js +++ b/ui/file_manager/file_manager/foreground/js/launch_param.js @@ -61,10 +61,11 @@ function LaunchParam(unformatted) { this.includeAllFiles = !!unformatted['includeAllFiles']; /** - * @type {boolean} + * @type {!AllowedPaths} * @const */ - this.shouldReturnLocalPath = !!unformatted['shouldReturnLocalPath']; + this.allowedPaths = unformatted['allowedPaths'] ? + unformatted['allowedPaths'] : AllowedPaths.ANY_PATH; /** * @type {!SuggestAppDialogState} diff --git a/ui/file_manager/file_manager/foreground/js/volume_manager_wrapper.js b/ui/file_manager/file_manager/foreground/js/volume_manager_wrapper.js index c2bb574..c3e8002 100644 --- a/ui/file_manager/file_manager/foreground/js/volume_manager_wrapper.js +++ b/ui/file_manager/file_manager/foreground/js/volume_manager_wrapper.js @@ -11,18 +11,17 @@ * @extends {cr.EventTarget} * @implements {VolumeManagerCommon.VolumeInfoProvider} * - * @param {VolumeManagerWrapper.NonNativeVolumeStatus} nonNativeEnabled ENABLED - * if non-native volumes should be available. DISABLED if non-native volumes - * related data/events should be hidden. + * @param {!AllowedPaths} allowedPaths Which paths are supported in the Files + * app dialog. * @param {Window=} opt_backgroundPage Window object of the background * page. If this is specified, the class skips to get background page. * TOOD(hirono): Let all clients of the class pass the background page and * make the argument not optional. */ -function VolumeManagerWrapper(nonNativeEnabled, opt_backgroundPage) { +function VolumeManagerWrapper(allowedPaths, opt_backgroundPage) { cr.EventTarget.call(this); - this.nonNativeEnabled_ = nonNativeEnabled; + this.allowedPaths_ = allowedPaths; this.volumeInfoList = new cr.ui.ArrayDataModel([]); this.volumeManager_ = null; @@ -57,18 +56,31 @@ function VolumeManagerWrapper(nonNativeEnabled, opt_backgroundPage) { } /** - * If the non-native volumes are enabled on the wrapper. - * @enum {boolean} + * Extends cr.EventTarget. */ -VolumeManagerWrapper.NonNativeVolumeStatus = { - ENABLED: true, - DISABLED: false -}; +VolumeManagerWrapper.prototype.__proto__ = cr.EventTarget.prototype; /** - * Extends cr.EventTarget. + * @param {VolumeManagerCommon.VolumeType} volumeType + * @return {boolean} */ -VolumeManagerWrapper.prototype.__proto__ = cr.EventTarget.prototype; +VolumeManagerWrapper.prototype.isAllowedVolume_ = function(volumeType) { + if (this.allowedPaths_ === AllowedPaths.ANY_PATH) + return true; + + if (this.allowedPaths_ === AllowedPaths.NATIVE_OR_DRIVE_PATH && + (VolumeManagerCommon.VolumeType.isNative(volumeType) || + volumeType == VolumeManagerCommon.VolumeType.DRIVE)) { + return true; + } + + if (this.allowedPaths_ === AllowedPaths.NATIVE_PATH && + VolumeManagerCommon.VolumeType.isNative(volumeType)) { + return true; + } + + return false; +}; /** * Called when the VolumeManager gets ready for post initialization. @@ -97,10 +109,8 @@ VolumeManagerWrapper.prototype.onReady_ = function(volumeManager) { for (var i = 0; i < this.volumeManager_.volumeInfoList.length; i++) { var volumeInfo = this.volumeManager_.volumeInfoList.item(i); // TODO(hidehiko): Filter mounted volumes located on Drive File System. - if (!this.nonNativeEnabled_ && - !VolumeManagerCommon.VolumeType.isNative(volumeInfo.volumeType)) { + if (!this.isAllowedVolume_(volumeInfo.volumeType)) continue; - } volumeInfoList.push(volumeInfo); } this.volumeInfoList.splice.apply( @@ -143,18 +153,18 @@ VolumeManagerWrapper.prototype.dispose = function() { * @private */ VolumeManagerWrapper.prototype.onEvent_ = function(event) { - if (!this.nonNativeEnabled_) { - // If non-native volumes are disabled, ignore all the events related with - // the non-native volumes. - if (event.type === 'drive-connection-changed' || - (event.type === 'externally-unmounted' && - !VolumeManagerCommon.VolumeType.isNative( - event.volumeInfo.volumeType))) { - return; - } + var eventVolumeType; + switch (event.type) { + case 'drive-connection-changed': + eventVolumeType = VolumeManagerCommon.VolumeType.DRIVE; + break; + case 'externally-unmounted': + eventVolumeType = event.volumeInfo.volumeType; + break; } - this.dispatchEvent(event); + if (this.isAllowedVolume_(eventVolumeType)) + this.dispatchEvent(event); }; /** @@ -163,42 +173,38 @@ VolumeManagerWrapper.prototype.onEvent_ = function(event) { * @private */ VolumeManagerWrapper.prototype.onVolumeInfoListUpdated_ = function(event) { - if (this.nonNativeEnabled_) { + if (this.allowedPaths_ === AllowedPaths.ANY_PATH) { // Apply the splice as is. this.volumeInfoList.splice.apply( - this.volumeInfoList, - [event.index, event.removed.length].concat(event.added)); - } else { - // Filters drive related volumes. - var index = event.index; - for (var i = 0; i < event.index; i++) { - if (!VolumeManagerCommon.VolumeType.isNative( - this.volumeManager_.volumeInfoList.item(i).volumeType)) { - index--; - } - } + this.volumeInfoList, + [event.index, event.removed.length].concat(event.added)); + return; + } - var numRemovedVolumes = 0; - for (var i = 0; i < event.removed.length; i++) { - if (VolumeManagerCommon.VolumeType.isNative( - event.removed[i].volumeType)) { - numRemovedVolumes++; - } - } + // Filters Drive related volumes. + var index = event.index; + for (var i = 0; i < event.index; i++) { + var volumeType = this.volumeManager_.volumeInfoList.item(i).volumeType; + if (!this.isAllowedVolume_(volumeType)) + index--; + } - var addedVolumes = []; - for (var i = 0; i < event.added.length; i++) { - var volumeInfo = event.added[i]; - if (VolumeManagerCommon.VolumeType.isNative( - event.removed[i].volumeType)) { - addedVolumes.push(volumeInfo); - } - } + var numRemovedVolumes = 0; + for (var i = 0; i < event.removed.length; i++) { + if (this.isAllowedVolume_(event.removed[i].volumeType)) + numRemovedVolumes++; + } - this.volumeInfoList.splice.apply( - this.volumeInfoList, - [index, numRemovedVolumes].concat(addedVolumes)); + var addedVolumes = []; + for (var i = 0; i < event.added.length; i++) { + var volumeInfo = event.added[i]; + if (this.isAllowedVolume_(volumeInfo.volumeType)) { + addedVolumes.push(volumeInfo); + } } + + this.volumeInfoList.splice.apply( + this.volumeInfoList, [index, numRemovedVolumes].concat(addedVolumes)); }; /** @@ -229,7 +235,8 @@ VolumeManagerWrapper.prototype.ensureInitialized = function(callback) { * state. */ VolumeManagerWrapper.prototype.getDriveConnectionState = function() { - if (!this.nonNativeEnabled_ || !this.volumeManager_) { + if (!this.isAllowedVolume_(VolumeManagerCommon.VolumeType.DRIVE) || + !this.volumeManager_) { return { type: VolumeManagerCommon.DriveConnectionType.OFFLINE, reason: VolumeManagerCommon.DriveConnectionReason.NO_SERVICE @@ -241,7 +248,7 @@ VolumeManagerWrapper.prototype.getDriveConnectionState = function() { /** @override */ VolumeManagerWrapper.prototype.getVolumeInfo = function(entry) { - return this.filterDisabledDriveVolume_( + return this.filterDisabledVolume_( this.volumeManager_ && this.volumeManager_.getVolumeInfo(entry)); }; @@ -252,7 +259,7 @@ VolumeManagerWrapper.prototype.getVolumeInfo = function(entry) { */ VolumeManagerWrapper.prototype.getCurrentProfileVolumeInfo = function(volumeType) { - return this.filterDisabledDriveVolume_( + return this.filterDisabledVolume_( this.volumeManager_ && this.volumeManager_.getCurrentProfileVolumeInfo(volumeType)); }; @@ -285,7 +292,7 @@ VolumeManagerWrapper.prototype.getLocationInfo = function(entry) { this.volumeManager_ && this.volumeManager_.getLocationInfo(entry); if (!locationInfo) return null; - if (!this.filterDisabledDriveVolume_(locationInfo.volumeInfo)) + if (!this.filterDisabledVolume_(locationInfo.volumeInfo)) return null; return locationInfo; }; @@ -346,18 +353,20 @@ VolumeManagerWrapper.prototype.configure = function(volumeInfo) { }; /** - * Filters volume info by referring nonNativeEnabled. + * Filters volume info by referring allowedPaths_. * * @param {VolumeInfo} volumeInfo Volume info. - * @return {VolumeInfo} Null if the drive is disabled and the given volume is - * drive. Otherwise just returns the volume. + * @return {VolumeInfo} Null if the volume is disabled. Otherwise just returns + * the volume. * @private */ -VolumeManagerWrapper.prototype.filterDisabledDriveVolume_ = +VolumeManagerWrapper.prototype.filterDisabledVolume_ = function(volumeInfo) { - var isNative = volumeInfo && - VolumeManagerCommon.VolumeType.isNative(volumeInfo.volumeType); - return this.nonNativeEnabled_ || isNative ? volumeInfo : null; + if (volumeInfo && this.isAllowedVolume_(volumeInfo.volumeType)) { + return volumeInfo; + } else { + return null; + } }; /** diff --git a/ui/file_manager/gallery/js/gallery.js b/ui/file_manager/gallery/js/gallery.js index 7a19a7d..ae0f21f 100644 --- a/ui/file_manager/gallery/js/gallery.js +++ b/ui/file_manager/gallery/js/gallery.js @@ -1059,8 +1059,7 @@ var loadTimeDataPromise = new Promise(function(fulfill, reject) { * @type {!Promise} */ var volumeManagerPromise = new Promise(function(fulfill, reject) { - var volumeManager = new VolumeManagerWrapper( - VolumeManagerWrapper.NonNativeVolumeStatus.ENABLED); + var volumeManager = new VolumeManagerWrapper(AllowedPaths.ANY_PATH); volumeManager.ensureInitialized(fulfill.bind(null, volumeManager)); }); diff --git a/ui/file_manager/video_player/js/video_player.js b/ui/file_manager/video_player/js/video_player.js index e34ff5e..bed41ba 100644 --- a/ui/file_manager/video_player/js/video_player.js +++ b/ui/file_manager/video_player/js/video_player.js @@ -692,8 +692,7 @@ function initStrings(callback) { } function initVolumeManager(callback) { - var volumeManager = new VolumeManagerWrapper( - VolumeManagerWrapper.NonNativeVolumeStatus.ENABLED); + var volumeManager = new VolumeManagerWrapper(AllowedPaths.ANY_PATH); volumeManager.ensureInitialized(callback); } |