Commit 17ad40a9 authored by Shakti Sahu's avatar Shakti Sahu Committed by Commit Bot

Prevent intercepting background service downloads by offline pages

This fixes a bug for uploads not getting completed as they have mime type
as text/html. The fix is to not let offline page backend intercept the
downloads if they are spawn from background service.

Bug: 976614
Change-Id: I99ebf8f0d9766baa4867ae17df470c72e2fe6c90
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1669878
Commit-Queue: Shakti Sahu <shaktisahu@chromium.org>
Reviewed-by: default avatarCharlie Reis <creis@chromium.org>
Reviewed-by: default avatarShakti Sahu <shaktisahu@chromium.org>
Reviewed-by: default avatarDavid Trainor <dtrainor@chromium.org>
Reviewed-by: default avatarChangwan Ryu <changwan@chromium.org>
Reviewed-by: default avatarMin Qin <qinmin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#672792}
parent 9ce7f82f
......@@ -71,6 +71,7 @@ bool AwDownloadManagerDelegate::InterceptDownloadIfApplicable(
const std::string& mime_type,
const std::string& request_origin,
int64_t content_length,
bool is_transient,
content::WebContents* web_contents) {
if (!base::FeatureList::IsEnabled(network::features::kNetworkService))
return false;
......
......@@ -41,6 +41,7 @@ class AwDownloadManagerDelegate : public content::DownloadManagerDelegate,
const std::string& mime_type,
const std::string& request_origin,
int64_t content_length,
bool is_transient,
content::WebContents* web_contents) override;
void GetNextId(const content::DownloadIdCallback& callback) override;
};
......
......@@ -584,10 +584,15 @@ bool ChromeDownloadManagerDelegate::InterceptDownloadIfApplicable(
const std::string& mime_type,
const std::string& request_origin,
int64_t content_length,
bool is_transient,
content::WebContents* web_contents) {
#if BUILDFLAG(ENABLE_OFFLINE_PAGES)
DCHECK_CURRENTLY_ON(BrowserThread::UI);
if (offline_pages::OfflinePageUtils::CanDownloadAsOfflinePage(url,
// For background service downloads we don't want offline pages backend to
// intercept the download. |is_transient| flag is used to determine whether
// the download corresponds to background service.
if (!is_transient &&
offline_pages::OfflinePageUtils::CanDownloadAsOfflinePage(url,
mime_type)) {
offline_pages::OfflinePageUtils::ScheduleDownload(
web_contents, offline_pages::kDownloadNamespace, url,
......
......@@ -98,6 +98,7 @@ class ChromeDownloadManagerDelegate
const std::string& mime_type,
const std::string& request_origin,
int64_t content_length,
bool is_transient,
content::WebContents* web_contents) override;
void GetSaveDir(content::BrowserContext* browser_context,
base::FilePath* website_save_dir,
......
......@@ -847,6 +847,20 @@ TEST_F(ChromeDownloadManagerDelegateTest, BlockedAsActiveContent_HttpPageOk) {
kInsecureDownloadHistogramInitiatorInsecureTargetInsecure, histograms);
}
#if defined(OS_ANDROID)
TEST_F(ChromeDownloadManagerDelegateTest, InterceptDownloadByOfflinePages) {
const GURL kUrl("http://example.com/foo");
std::string mime_type = "text/html";
bool should_intercept = delegate()->InterceptDownloadIfApplicable(
kUrl, "", "", mime_type, "", 10, false /*is_transient*/, nullptr);
EXPECT_TRUE(should_intercept);
should_intercept = delegate()->InterceptDownloadIfApplicable(
kUrl, "", "", mime_type, "", 10, true /*is_transient*/, nullptr);
EXPECT_FALSE(should_intercept);
}
#endif
TEST_F(ChromeDownloadManagerDelegateTest, BlockedAsActiveContent_HttpChain) {
// Tests blocking unsafe active content downloads when a step in the referrer
// chain is HTTP, using the default mime-type matching policy.
......
......@@ -567,10 +567,10 @@ bool DownloadManagerImpl::InterceptDownload(
}
}
if (delegate_ &&
delegate_->InterceptDownloadIfApplicable(
info.url(), user_agent, info.content_disposition, info.mime_type,
info.request_origin, info.total_bytes, web_contents)) {
if (delegate_ && delegate_->InterceptDownloadIfApplicable(
info.url(), user_agent, info.content_disposition,
info.mime_type, info.request_origin, info.total_bytes,
info.transient, web_contents)) {
if (info.request_handle)
info.request_handle->CancelRequest(false);
return true;
......
......@@ -44,6 +44,7 @@ bool DownloadManagerDelegate::InterceptDownloadIfApplicable(
const std::string& mime_type,
const std::string& request_origin,
int64_t content_length,
bool is_transient,
WebContents* web_contents) {
return false;
}
......
......@@ -131,6 +131,7 @@ class CONTENT_EXPORT DownloadManagerDelegate {
const std::string& mime_type,
const std::string& request_origin,
int64_t content_length,
bool is_transient,
WebContents* web_contents);
// Retrieve the directories to save html pages and downloads to.
......
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