Commit 8d2c055e authored by Jesse McKenna's avatar Jesse McKenna Committed by Commit Bot

Disable opening extensionless downloads on Windows

This change makes the "Open" option in the downloads bar act like
"Show in Folder" for files without file extensions on Windows.

This fixes an issue where Chrome could unexpectedly open the wrong
file when attempting to open an extensionless file while an executable
of the same name was present in the Downloads folder. For example,
downloading and opening "somefile" while "somefile.exe" was already
present in Downloads would result in "somefile.exe" being run. This
behavior is due to Windows' shell open functionality, which appears to
have special logic to interpret extensionless commands as potential
executables.

Prior to this change, if an extensionless file was opened without an
executable of the same name present (the more common scenario),
Windows would display error "No application is associated with the
specified file for this operation", so this change does not remove any
functionality apart from the ability to trigger this error popup.

Showing the extensionless file in folder sets the user up nicely to
open the file however they want from Windows Explorer via right-click
> Open With.

Bug: 1092518
Change-Id: I1a3bb519867548c916070cbfebd64d0017f5937b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2321528
Commit-Queue: Jesse McKenna <jessemckenna@google.com>
Reviewed-by: default avatarShakti Sahu <shaktisahu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#796968}
parent 7857bb23
......@@ -875,6 +875,8 @@ downloads::InterruptReason InterruptReasonContentToExtension(
} // namespace
IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, DownloadExtensionTest_Open) {
platform_util::internal::DisableShellOperationsForTesting();
LoadExtension("downloads_split");
DownloadsOpenFunction* open_function = new DownloadsOpenFunction();
open_function->set_user_gesture(true);
......
......@@ -692,6 +692,16 @@ void DownloadItemImpl::OpenDownload() {
last_access_time_ = base::Time::Now();
for (auto& observer : observers_)
observer.OnDownloadOpened(this);
#if defined(OS_WIN)
// On Windows, don't actually open the file if it has no extension, to prevent
// Windows from interpreting it as the command for an executable of the same
// name.
if (destination_info_.current_path.Extension().empty()) {
delegate_->ShowDownloadInShell(this);
return;
}
#endif
delegate_->OpenDownload(this);
}
......
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