| Index: chrome/browser/ui/views/select_file_dialog_extension.cc
|
| diff --git a/chrome/browser/ui/views/select_file_dialog_extension.cc b/chrome/browser/ui/views/select_file_dialog_extension.cc
|
| index 1a57202038aeee6fd227bc61479c8a378e03ed92..990fc5e1506a116050e41a213a23522069df6067 100644
|
| --- a/chrome/browser/ui/views/select_file_dialog_extension.cc
|
| +++ b/chrome/browser/ui/views/select_file_dialog_extension.cc
|
| @@ -330,43 +330,79 @@ void SelectFileDialogExtension::SelectFileImpl(
|
| return;
|
| }
|
|
|
| - base::FilePath default_dialog_path;
|
| -
|
| const PrefService* pref_service = profile_->GetPrefs();
|
| -
|
| - if (default_path.empty() && pref_service) {
|
| - default_dialog_path =
|
| - pref_service->GetFilePath(prefs::kDownloadDefaultDirectory);
|
| - } else {
|
| - default_dialog_path = default_path;
|
| + if (!pref_service) {
|
| + LOG(ERROR) << "Could not find the pref service.";
|
| + return;
|
| }
|
|
|
| - base::FilePath virtual_path;
|
| - base::FilePath fallback_path = profile_->last_selected_directory().Append(
|
| - default_dialog_path.BaseName());
|
| - // If an absolute path is specified as the default path, convert it to the
|
| - // virtual path in the file browser extension. Due to the current design,
|
| - // an invalid temporal cache file path may passed as |default_dialog_path|
|
| - // (crbug.com/178013 #9-#11). In such a case, we use the last selected
|
| - // directory as a workaround. Real fix is tracked at crbug.com/110119.
|
| + // All of the paths below are absolute.
|
| + base::FilePath download_default_path(
|
| + pref_service->GetFilePath(prefs::kDownloadDefaultDirectory));
|
| +
|
| + base::FilePath selection_path = default_path.IsAbsolute() ?
|
| + default_path : download_default_path.Append(default_path.BaseName());
|
| + base::FilePath current_directory_path = selection_path.DirName();
|
| +
|
| + base::FilePath current_directory_virtual_path;
|
| + base::FilePath selection_virtual_path;
|
| +
|
| + base::FilePath fallback_path = !profile_->last_selected_directory().empty() ?
|
| + profile_->last_selected_directory() : download_default_path;
|
| +
|
| + // Convert the above absolute paths to virtual paths.
|
| + // TODO(mtomasz): Use URLs instead of paths.
|
| using file_manager::kFileManagerAppId;
|
| - if (default_dialog_path.IsAbsolute() &&
|
| - (file_manager::util::ConvertAbsoluteFilePathToRelativeFileSystemPath(
|
| - profile_, kFileManagerAppId, default_dialog_path, &virtual_path) ||
|
| - file_manager::util::ConvertAbsoluteFilePathToRelativeFileSystemPath(
|
| - profile_, kFileManagerAppId, fallback_path, &virtual_path))) {
|
| - virtual_path = base::FilePath("/").Append(virtual_path);
|
| - } else {
|
| - // If the path was relative, or failed to convert, just use the base name,
|
| - virtual_path = default_dialog_path.BaseName();
|
| + if (!file_manager::util::ConvertAbsoluteFilePathToRelativeFileSystemPath(
|
| + profile_,
|
| + kFileManagerAppId,
|
| + selection_path,
|
| + &selection_virtual_path)) {
|
| + // Due to the current design, an invalid temporal cache file path may passed
|
| + // as |default_path| (crbug.com/178013 #9-#11). In such a case, we use the
|
| + // last selected directory as a workaround. Real fix is tracked at
|
| + // crbug.com/110119.
|
| + if (!file_manager::util::ConvertAbsoluteFilePathToRelativeFileSystemPath(
|
| + profile_,
|
| + kFileManagerAppId,
|
| + fallback_path.Append(selection_path.BaseName()),
|
| + &selection_virtual_path)) {
|
| + LOG(ERROR) << "Unable to resolve the selection path.";
|
| + return;
|
| + }
|
| + }
|
| + selection_virtual_path = base::FilePath("/").Append(selection_virtual_path);
|
| +
|
| + if (!file_manager::util::ConvertAbsoluteFilePathToRelativeFileSystemPath(
|
| + profile_,
|
| + kFileManagerAppId,
|
| + current_directory_path,
|
| + ¤t_directory_virtual_path)) {
|
| + // Fallback if necessary, see the comment above.
|
| + if (!file_manager::util::ConvertAbsoluteFilePathToRelativeFileSystemPath(
|
| + profile_,
|
| + kFileManagerAppId,
|
| + fallback_path,
|
| + ¤t_directory_virtual_path)) {
|
| + LOG(ERROR) << "Unable to resolve the current directory path: "
|
| + << fallback_path.value();
|
| + return;
|
| + }
|
| }
|
| + current_directory_virtual_path = base::FilePath("/").Append(
|
| + current_directory_virtual_path);
|
|
|
| has_multiple_file_type_choices_ =
|
| file_types ? file_types->extensions.size() > 1 : true;
|
|
|
| GURL file_manager_url =
|
| file_manager::util::GetFileManagerMainPageUrlWithParams(
|
| - type, title, virtual_path, file_types, file_type_index,
|
| + type,
|
| + title,
|
| + current_directory_virtual_path,
|
| + selection_virtual_path,
|
| + file_types,
|
| + file_type_index,
|
| default_extension);
|
|
|
| ExtensionDialog* dialog = ExtensionDialog::Show(file_manager_url,
|
|
|