Commit 05cb7c15 authored by Min Qin's avatar Min Qin Committed by Commit Bot

Don't download pdf if it is a file URL and chrome is not the default

pdf viewer

If chrome is not the default pdf viewer, clicking on a pdf will
trigger a download. After download completes, Chrome will invoke
the system viewer to auto-open the pdf file. However, the system
viewer might be chrome itself, and that will trigger downloading
the file URL, and causing an infinite number of download.

This CL fixes the issue by blocking the pdf download if it is a file
URL. An alternative to fix the issue is to block the auto-open if Chrome
is not the default pdf viewer

BUG=851650

Change-Id: Ie12105408f80650463a6eae4f57cb6de23d1a875
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2531217Reviewed-by: default avatarXing Liu <xingliu@chromium.org>
Commit-Queue: Min Qin <qinmin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#826137}
parent 873e8754
...@@ -1549,6 +1549,23 @@ void ChromeDownloadManagerDelegate::CheckDownloadAllowed( ...@@ -1549,6 +1549,23 @@ void ChromeDownloadManagerDelegate::CheckDownloadAllowed(
bool content_initiated, bool content_initiated,
content::CheckDownloadAllowedCallback check_download_allowed_cb) { content::CheckDownloadAllowedCallback check_download_allowed_cb) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
#if defined(OS_WIN) || defined(OS_LINUX) || defined(OS_CHROMEOS) || \
defined(OS_MAC)
// Don't download pdf if it is a file URL, as that might cause an infinite
// download loop if Chrome is not the system pdf viewer.
if (url.SchemeIsFile() && download_prefs_->ShouldOpenPdfInSystemReader()) {
base::FilePath path;
net::FileURLToFilePath(url, &path);
base::FilePath::StringType extension = path.Extension();
if (!extension.empty() && base::FilePath::CompareEqualIgnoreCase(
extension, FILE_PATH_LITERAL(".pdf"))) {
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE,
base::BindOnce(std::move(check_download_allowed_cb), false));
return;
}
}
#endif
CanDownloadCallback cb = base::BindOnce( CanDownloadCallback cb = base::BindOnce(
&ChromeDownloadManagerDelegate::OnCheckDownloadAllowedComplete, &ChromeDownloadManagerDelegate::OnCheckDownloadAllowedComplete,
weak_ptr_factory_.GetWeakPtr(), std::move(check_download_allowed_cb)); weak_ptr_factory_.GetWeakPtr(), std::move(check_download_allowed_cb));
......
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