Commit c427ca03 authored by Joe DeBlasio's avatar Joe DeBlasio Committed by Commit Bot

[MIX-DL] Refactor for future mixed-content download blocking UIs.

This CL changes the mixed content download blocking code to return an
enum indicating what type of blocking should be used (silent, or two
types of blocking UI). Previously, this function returned a boolean that
indicated silent blocking. The CL then propagates that result through
the DownloadTargetDeterminer into the DownloadItem. That state is needed
later to trigger the existing download shelf warning UI.

This CL also renames callbacks in/around the DownloadTargetDeterminer
from "ShouldBlock"-type names to "GetMixedContentStatus"-type names.

This CL causes no functional change to Chrome. Follow-up CLs will add
support for, then trigger, user-visible warnings.

This is part of go/downloads-as-mixed-content .

Bug: 960819
Change-Id: Ic0c3f41caf7e623050d4b75be364f410a46e296d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1982680Reviewed-by: default avatarAvi Drissman <avi@chromium.org>
Reviewed-by: default avatarEvan Stade <estade@chromium.org>
Reviewed-by: default avatarSean Topping <seantopping@chromium.org>
Reviewed-by: default avatarMin Qin <qinmin@chromium.org>
Commit-Queue: Joe DeBlasio <jdeblasio@chromium.org>
Cr-Commit-Position: refs/heads/master@{#732954}
parent 4a9937c9
...@@ -301,10 +301,10 @@ void OnCheckExistingDownloadPathDone( ...@@ -301,10 +301,10 @@ void OnCheckExistingDownloadPathDone(
if (file_exists) if (file_exists)
target_info->result = download::DOWNLOAD_INTERRUPT_REASON_USER_CANCELED; target_info->result = download::DOWNLOAD_INTERRUPT_REASON_USER_CANCELED;
std::move(callback).Run(target_info->target_path, std::move(callback).Run(
target_info->target_disposition, target_info->target_path, target_info->target_disposition,
target_info->danger_type, target_info->danger_type, target_info->mixed_content_status,
target_info->intermediate_path, target_info->result); target_info->intermediate_path, target_info->result);
} }
} // namespace } // namespace
...@@ -780,12 +780,12 @@ DownloadProtectionService* ...@@ -780,12 +780,12 @@ DownloadProtectionService*
return nullptr; return nullptr;
} }
void ChromeDownloadManagerDelegate::ShouldBlockDownload( void ChromeDownloadManagerDelegate::GetMixedContentStatus(
download::DownloadItem* download, download::DownloadItem* download,
const base::FilePath& virtual_path, const base::FilePath& virtual_path,
const ShouldBlockDownloadCallback& callback) { const GetMixedContentStatusCallback& callback) {
DCHECK(download); DCHECK(download);
callback.Run(ShouldBlockFileAsMixedContent(virtual_path, *download)); callback.Run(GetMixedContentStatusForDownload(virtual_path, *download));
} }
void ChromeDownloadManagerDelegate::NotifyExtensions( void ChromeDownloadManagerDelegate::NotifyExtensions(
......
...@@ -164,10 +164,10 @@ class ChromeDownloadManagerDelegate ...@@ -164,10 +164,10 @@ class ChromeDownloadManagerDelegate
const DownloadTargetDeterminerDelegate::ConfirmationCallback& callback); const DownloadTargetDeterminerDelegate::ConfirmationCallback& callback);
// DownloadTargetDeterminerDelegate. Protected for testing. // DownloadTargetDeterminerDelegate. Protected for testing.
void ShouldBlockDownload( void GetMixedContentStatus(
download::DownloadItem* download, download::DownloadItem* download,
const base::FilePath& virtual_path, const base::FilePath& virtual_path,
const ShouldBlockDownloadCallback& callback) override; const GetMixedContentStatusCallback& callback) override;
void NotifyExtensions(download::DownloadItem* download, void NotifyExtensions(download::DownloadItem* download,
const base::FilePath& suggested_virtual_path, const base::FilePath& suggested_virtual_path,
const NotifyExtensionsCallback& callback) override; const NotifyExtensionsCallback& callback) override;
......
...@@ -126,6 +126,7 @@ struct DetermineDownloadTargetResult { ...@@ -126,6 +126,7 @@ struct DetermineDownloadTargetResult {
base::FilePath target_path; base::FilePath target_path;
download::DownloadItem::TargetDisposition disposition; download::DownloadItem::TargetDisposition disposition;
download::DownloadDangerType danger_type; download::DownloadDangerType danger_type;
download::DownloadItem::MixedContentStatus mixed_content_status;
base::FilePath intermediate_path; base::FilePath intermediate_path;
download::DownloadInterruptReason interrupt_reason; download::DownloadInterruptReason interrupt_reason;
}; };
...@@ -133,6 +134,7 @@ struct DetermineDownloadTargetResult { ...@@ -133,6 +134,7 @@ struct DetermineDownloadTargetResult {
DetermineDownloadTargetResult::DetermineDownloadTargetResult() DetermineDownloadTargetResult::DetermineDownloadTargetResult()
: disposition(download::DownloadItem::TARGET_DISPOSITION_OVERWRITE), : disposition(download::DownloadItem::TARGET_DISPOSITION_OVERWRITE),
danger_type(download::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS), danger_type(download::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS),
mixed_content_status(download::DownloadItem::MixedContentStatus::UNKNOWN),
interrupt_reason(download::DOWNLOAD_INTERRUPT_REASON_NONE) {} interrupt_reason(download::DOWNLOAD_INTERRUPT_REASON_NONE) {}
// Subclass of the ChromeDownloadManagerDelegate that replaces a few interaction // Subclass of the ChromeDownloadManagerDelegate that replaces a few interaction
...@@ -390,11 +392,13 @@ void StoreDownloadTargetInfo( ...@@ -390,11 +392,13 @@ void StoreDownloadTargetInfo(
const base::FilePath& target_path, const base::FilePath& target_path,
DownloadItem::TargetDisposition target_disposition, DownloadItem::TargetDisposition target_disposition,
download::DownloadDangerType danger_type, download::DownloadDangerType danger_type,
download::DownloadItem::MixedContentStatus mixed_content_status,
const base::FilePath& intermediate_path, const base::FilePath& intermediate_path,
download::DownloadInterruptReason interrupt_reason) { download::DownloadInterruptReason interrupt_reason) {
result->target_path = target_path; result->target_path = target_path;
result->disposition = target_disposition; result->disposition = target_disposition;
result->danger_type = danger_type; result->danger_type = danger_type;
result->mixed_content_status = mixed_content_status;
result->intermediate_path = intermediate_path; result->intermediate_path = intermediate_path;
result->interrupt_reason = interrupt_reason; result->interrupt_reason = interrupt_reason;
closure.Run(); closure.Run();
......
...@@ -139,8 +139,8 @@ void DownloadTargetDeterminer::DoLoop() { ...@@ -139,8 +139,8 @@ void DownloadTargetDeterminer::DoLoop() {
case STATE_GENERATE_TARGET_PATH: case STATE_GENERATE_TARGET_PATH:
result = DoGenerateTargetPath(); result = DoGenerateTargetPath();
break; break;
case STATE_CHECK_IF_DOWNLOAD_BLOCKED: case STATE_SET_MIXED_CONTENT_STATUS:
result = DoCheckIfDownloadBlocked(); result = DoSetMixedContentStatus();
break; break;
case STATE_NOTIFY_EXTENSIONS: case STATE_NOTIFY_EXTENSIONS:
result = DoNotifyExtensions(); result = DoNotifyExtensions();
...@@ -193,7 +193,7 @@ DownloadTargetDeterminer::Result ...@@ -193,7 +193,7 @@ DownloadTargetDeterminer::Result
DCHECK(!should_notify_extensions_); DCHECK(!should_notify_extensions_);
bool is_forced_path = !download_->GetForcedFilePath().empty(); bool is_forced_path = !download_->GetForcedFilePath().empty();
next_state_ = STATE_CHECK_IF_DOWNLOAD_BLOCKED; next_state_ = STATE_SET_MIXED_CONTENT_STATUS;
// Transient download should use the existing path. // Transient download should use the existing path.
if (download_->IsTransient()) { if (download_->IsTransient()) {
...@@ -309,26 +309,29 @@ DownloadTargetDeterminer::Result ...@@ -309,26 +309,29 @@ DownloadTargetDeterminer::Result
} }
DownloadTargetDeterminer::Result DownloadTargetDeterminer::Result
DownloadTargetDeterminer::DoCheckIfDownloadBlocked() { DownloadTargetDeterminer::DoSetMixedContentStatus() {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
DCHECK(!virtual_path_.empty()); DCHECK(!virtual_path_.empty());
next_state_ = STATE_NOTIFY_EXTENSIONS; next_state_ = STATE_NOTIFY_EXTENSIONS;
delegate_->ShouldBlockDownload( delegate_->GetMixedContentStatus(
download_, virtual_path_, download_, virtual_path_,
base::Bind(&DownloadTargetDeterminer::CheckIfDownloadBlockedDone, base::Bind(&DownloadTargetDeterminer::GetMixedContentStatusDone,
weak_ptr_factory_.GetWeakPtr())); weak_ptr_factory_.GetWeakPtr()));
return QUIT_DOLOOP; return QUIT_DOLOOP;
} }
void DownloadTargetDeterminer::CheckIfDownloadBlockedDone(bool should_block) { void DownloadTargetDeterminer::GetMixedContentStatusDone(
download::DownloadItem::MixedContentStatus status) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
// Delegate should not call back here more than once. // Delegate should not call back here more than once.
DCHECK_EQ(STATE_NOTIFY_EXTENSIONS, next_state_); DCHECK_EQ(STATE_NOTIFY_EXTENSIONS, next_state_);
if (should_block) { mixed_content_status_ = status;
if (status == download::DownloadItem::MixedContentStatus::SILENT_BLOCK) {
ScheduleCallbackAndDeleteSelf( ScheduleCallbackAndDeleteSelf(
download::DOWNLOAD_INTERRUPT_REASON_FILE_BLOCKED); download::DOWNLOAD_INTERRUPT_REASON_FILE_BLOCKED);
return; return;
...@@ -957,6 +960,7 @@ void DownloadTargetDeterminer::ScheduleCallbackAndDeleteSelf( ...@@ -957,6 +960,7 @@ void DownloadTargetDeterminer::ScheduleCallbackAndDeleteSelf(
target_info->intermediate_path = intermediate_path_; target_info->intermediate_path = intermediate_path_;
target_info->mime_type = mime_type_; target_info->mime_type = mime_type_;
target_info->is_filetype_handled_safely = is_filetype_handled_safely_; target_info->is_filetype_handled_safely = is_filetype_handled_safely_;
target_info->mixed_content_status = mixed_content_status_;
base::ThreadTaskRunnerHandle::Get()->PostTask( base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, FROM_HERE,
......
...@@ -97,7 +97,7 @@ class DownloadTargetDeterminer : public download::DownloadItem::Observer { ...@@ -97,7 +97,7 @@ class DownloadTargetDeterminer : public download::DownloadItem::Observer {
// handler returns COMPLETE. // handler returns COMPLETE.
enum State { enum State {
STATE_GENERATE_TARGET_PATH, STATE_GENERATE_TARGET_PATH,
STATE_CHECK_IF_DOWNLOAD_BLOCKED, STATE_SET_MIXED_CONTENT_STATUS,
STATE_NOTIFY_EXTENSIONS, STATE_NOTIFY_EXTENSIONS,
STATE_RESERVE_VIRTUAL_PATH, STATE_RESERVE_VIRTUAL_PATH,
STATE_PROMPT_USER_FOR_DOWNLOAD_PATH, STATE_PROMPT_USER_FOR_DOWNLOAD_PATH,
...@@ -159,20 +159,21 @@ class DownloadTargetDeterminer : public download::DownloadItem::Observer { ...@@ -159,20 +159,21 @@ class DownloadTargetDeterminer : public download::DownloadItem::Observer {
// the download item. // the download item.
// Next state: // Next state:
// - STATE_NONE : If the download is not in progress, returns COMPLETE. // - STATE_NONE : If the download is not in progress, returns COMPLETE.
// - STATE_CHECK_IF_DOWNLOAD_BLOCKED : All other downloads. // - STATE_SET_MIXED_CONTENT_STATUS : All other downloads.
Result DoGenerateTargetPath(); Result DoGenerateTargetPath();
// Determines whether the download ought to be blocked before a user is // Determines the mixed content status of the download, so as to block it
// prompted for file path. Used for active mixed content blocking. This // prior to prompting the user for the file path. This function relies on the
// function relies on the delegate for the actual determination. // delegate for the actual determination.
// //
// Next state: // Next state:
// - STATE_NOTIFY_EXTENSIONS // - STATE_NOTIFY_EXTENSIONS
Result DoCheckIfDownloadBlocked(); Result DoSetMixedContentStatus();
// Callback invoked by delegate after blocking is determined. Does the actual // Callback invoked by delegate after mixed content status is determined.
// cancellation of the download if necessary. // Cancels the download if status indicates blocking is necessary.
void CheckIfDownloadBlockedDone(bool should_block); void GetMixedContentStatusDone(
download::DownloadItem::MixedContentStatus status);
// Notifies downloads extensions. If any extension wishes to override the // Notifies downloads extensions. If any extension wishes to override the
// download filename, it will respond to the OnDeterminingFilename() // download filename, it will respond to the OnDeterminingFilename()
...@@ -340,6 +341,7 @@ class DownloadTargetDeterminer : public download::DownloadItem::Observer { ...@@ -340,6 +341,7 @@ class DownloadTargetDeterminer : public download::DownloadItem::Observer {
base::FilePath intermediate_path_; base::FilePath intermediate_path_;
std::string mime_type_; std::string mime_type_;
bool is_filetype_handled_safely_; bool is_filetype_handled_safely_;
download::DownloadItem::MixedContentStatus mixed_content_status_;
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
bool is_checking_dialog_confirmed_path_; bool is_checking_dialog_confirmed_path_;
#endif #endif
......
...@@ -11,23 +11,21 @@ ...@@ -11,23 +11,21 @@
#include "chrome/browser/download/download_confirmation_reason.h" #include "chrome/browser/download/download_confirmation_reason.h"
#include "chrome/browser/download/download_confirmation_result.h" #include "chrome/browser/download/download_confirmation_result.h"
#include "components/download/public/common/download_danger_type.h" #include "components/download/public/common/download_danger_type.h"
#include "components/download/public/common/download_item.h"
#include "components/download/public/common/download_path_reservation_tracker.h" #include "components/download/public/common/download_path_reservation_tracker.h"
namespace base { namespace base {
class FilePath; class FilePath;
} }
namespace download {
class DownloadItem;
}
// Delegate for DownloadTargetDeterminer. The delegate isn't owned by // Delegate for DownloadTargetDeterminer. The delegate isn't owned by
// DownloadTargetDeterminer and is expected to outlive it. // DownloadTargetDeterminer and is expected to outlive it.
class DownloadTargetDeterminerDelegate { class DownloadTargetDeterminerDelegate {
public: public:
// Callback to be invoked after ShouldBlockDownload() completes. The // Callback to be invoked after GetMixedContentStatus() completes. The
// |should_block| bool represents whether the download should be aborted. // |should_block| bool represents whether the download should be aborted.
typedef base::Callback<void(bool should_block)> ShouldBlockDownloadCallback; using GetMixedContentStatusCallback =
base::Callback<void(download::DownloadItem::MixedContentStatus status)>;
// Callback to be invoked after NotifyExtensions() completes. The // Callback to be invoked after NotifyExtensions() completes. The
// |new_virtual_path| should be set to a new path if an extension wishes to // |new_virtual_path| should be set to a new path if an extension wishes to
...@@ -71,13 +69,12 @@ class DownloadTargetDeterminerDelegate { ...@@ -71,13 +69,12 @@ class DownloadTargetDeterminerDelegate {
// determined, it should be set to the empty string. // determined, it should be set to the empty string.
typedef base::Callback<void(const std::string&)> GetFileMimeTypeCallback; typedef base::Callback<void(const std::string&)> GetFileMimeTypeCallback;
// Checks whether the download should be blocked based on data available // Returns whether the download should be warned/blocked based on its mixed
// such as filename. Functionality used for active content blocking, not Safe // content status, and if so, what kind of warning/blocking should be used.
// Browsing. virtual void GetMixedContentStatus(
virtual void ShouldBlockDownload(
download::DownloadItem* download, download::DownloadItem* download,
const base::FilePath& virtual_path, const base::FilePath& virtual_path,
const ShouldBlockDownloadCallback& callback) = 0; const GetMixedContentStatusCallback& callback) = 0;
// Notifies extensions of the impending filename determination. |virtual_path| // Notifies extensions of the impending filename determination. |virtual_path|
// is the current suggested virtual path. The |callback| should be invoked to // is the current suggested virtual path. The |callback| should be invoked to
......
...@@ -178,10 +178,10 @@ struct DownloadTestCase { ...@@ -178,10 +178,10 @@ struct DownloadTestCase {
class MockDownloadTargetDeterminerDelegate class MockDownloadTargetDeterminerDelegate
: public DownloadTargetDeterminerDelegate { : public DownloadTargetDeterminerDelegate {
public: public:
MOCK_METHOD3(ShouldBlockDownload, MOCK_METHOD3(GetMixedContentStatus,
void(download::DownloadItem*, void(download::DownloadItem*,
const base::FilePath&, const base::FilePath&,
const ShouldBlockDownloadCallback&)); const GetMixedContentStatusCallback&));
MOCK_METHOD3(CheckDownloadUrl, MOCK_METHOD3(CheckDownloadUrl,
void(download::DownloadItem*, void(download::DownloadItem*,
const base::FilePath&, const base::FilePath&,
...@@ -217,8 +217,9 @@ class MockDownloadTargetDeterminerDelegate ...@@ -217,8 +217,9 @@ class MockDownloadTargetDeterminerDelegate
const GetFileMimeTypeCallback&)); const GetFileMimeTypeCallback&));
void SetupDefaults() { void SetupDefaults() {
ON_CALL(*this, ShouldBlockDownload(_, _, _)) ON_CALL(*this, GetMixedContentStatus(_, _, _))
.WillByDefault(WithArg<2>(ScheduleCallback(false))); .WillByDefault(WithArg<2>(ScheduleCallback(
download::DownloadItem::MixedContentStatus::UNKNOWN)));
ON_CALL(*this, CheckDownloadUrl(_, _, _)) ON_CALL(*this, CheckDownloadUrl(_, _, _))
.WillByDefault(WithArg<2>( .WillByDefault(WithArg<2>(
ScheduleCallback(download::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS))); ScheduleCallback(download::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS)));
...@@ -1527,7 +1528,7 @@ TEST_F(DownloadTargetDeterminerTest, ManagedPath) { ...@@ -1527,7 +1528,7 @@ TEST_F(DownloadTargetDeterminerTest, ManagedPath) {
base::size(kManagedPathTestCases)); base::size(kManagedPathTestCases));
} }
// Test basic blocking functionality via ShouldBlockDownloads. // Test basic blocking functionality via GetMixedContentStatus.
TEST_F(DownloadTargetDeterminerTest, BlockDownloads) { TEST_F(DownloadTargetDeterminerTest, BlockDownloads) {
const DownloadTestCase kBlockDownloadsTestCases[] = { const DownloadTestCase kBlockDownloadsTestCases[] = {
{AUTOMATIC, download::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, {AUTOMATIC, download::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS,
...@@ -1536,8 +1537,9 @@ TEST_F(DownloadTargetDeterminerTest, BlockDownloads) { ...@@ -1536,8 +1537,9 @@ TEST_F(DownloadTargetDeterminerTest, BlockDownloads) {
DownloadItem::TARGET_DISPOSITION_OVERWRITE, EXPECT_EMPTY}, DownloadItem::TARGET_DISPOSITION_OVERWRITE, EXPECT_EMPTY},
}; };
ON_CALL(*delegate(), ShouldBlockDownload(_, _, _)) ON_CALL(*delegate(), GetMixedContentStatus(_, _, _))
.WillByDefault(WithArg<2>(ScheduleCallback(true))); .WillByDefault(WithArg<2>(ScheduleCallback(
download::DownloadItem::MixedContentStatus::SILENT_BLOCK)));
RunTestCasesWithActiveItem(kBlockDownloadsTestCases, RunTestCasesWithActiveItem(kBlockDownloadsTestCases,
base::size(kBlockDownloadsTestCases)); base::size(kBlockDownloadsTestCases));
} }
......
...@@ -11,6 +11,8 @@ DownloadTargetInfo::DownloadTargetInfo() ...@@ -11,6 +11,8 @@ DownloadTargetInfo::DownloadTargetInfo()
danger_type(download::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS), danger_type(download::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS),
danger_level(safe_browsing::DownloadFileType::NOT_DANGEROUS), danger_level(safe_browsing::DownloadFileType::NOT_DANGEROUS),
is_filetype_handled_safely(false), is_filetype_handled_safely(false),
result(download::DOWNLOAD_INTERRUPT_REASON_NONE) {} result(download::DOWNLOAD_INTERRUPT_REASON_NONE),
mixed_content_status(
download::DownloadItem::MixedContentStatus::UNKNOWN) {}
DownloadTargetInfo::~DownloadTargetInfo() {} DownloadTargetInfo::~DownloadTargetInfo() {}
...@@ -77,6 +77,9 @@ struct DownloadTargetInfo { ...@@ -77,6 +77,9 @@ struct DownloadTargetInfo {
// Result of the download target determination. // Result of the download target determination.
download::DownloadInterruptReason result; download::DownloadInterruptReason result;
// What sort of blocking should be used if the download is of mixed content.
download::DownloadItem::MixedContentStatus mixed_content_status;
}; };
#endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_TARGET_INFO_H_ #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_TARGET_INFO_H_
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include "url/origin.h" #include "url/origin.h"
using download::DownloadSource; using download::DownloadSource;
using MixedContentStatus = download::DownloadItem::MixedContentStatus;
namespace { namespace {
...@@ -135,9 +136,9 @@ InsecureDownloadSecurityStatus GetDownloadBlockingEnum( ...@@ -135,9 +136,9 @@ InsecureDownloadSecurityStatus GetDownloadBlockingEnum(
} }
} // namespace } // namespace
MixedContentStatus GetMixedContentStatusForDownload(
bool ShouldBlockFileAsMixedContent(const base::FilePath& path, const base::FilePath& path,
const download::DownloadItem& item) { const download::DownloadItem& item) {
// Extensions must be in lower case! Extensions are compared against save path // Extensions must be in lower case! Extensions are compared against save path
// determined by Chrome prior to the user seeing a file picker. // determined by Chrome prior to the user seeing a file picker.
const std::vector<std::string> kDefaultUnsafeExtensions = { const std::vector<std::string> kDefaultUnsafeExtensions = {
...@@ -180,7 +181,7 @@ bool ShouldBlockFileAsMixedContent(const base::FilePath& path, ...@@ -180,7 +181,7 @@ bool ShouldBlockFileAsMixedContent(const base::FilePath& path,
base::UmaHistogramEnumeration( base::UmaHistogramEnumeration(
kInsecureDownloadHistogramName, kInsecureDownloadHistogramName,
InsecureDownloadSecurityStatus::kDownloadIgnored); InsecureDownloadSecurityStatus::kDownloadIgnored);
return false; return MixedContentStatus::SAFE;
} }
// Evaluate download security // Evaluate download security
...@@ -249,7 +250,7 @@ bool ShouldBlockFileAsMixedContent(const base::FilePath& path, ...@@ -249,7 +250,7 @@ bool ShouldBlockFileAsMixedContent(const base::FilePath& path,
!is_download_secure && found_blocked_extension && !is_download_secure && found_blocked_extension &&
base::FeatureList::IsEnabled( base::FeatureList::IsEnabled(
features::kTreatUnsafeDownloadsAsActive))) { features::kTreatUnsafeDownloadsAsActive))) {
return false; return MixedContentStatus::SAFE;
} }
content::WebContents* web_contents = content::WebContents* web_contents =
...@@ -265,5 +266,5 @@ bool ShouldBlockFileAsMixedContent(const base::FilePath& path, ...@@ -265,5 +266,5 @@ bool ShouldBlockFileAsMixedContent(const base::FilePath& path,
(is_redirect_chain_secure ? "loaded over" : "redirected through"))); (is_redirect_chain_secure ? "loaded over" : "redirected through")));
} }
return true; return MixedContentStatus::SILENT_BLOCK;
} }
...@@ -198,9 +198,10 @@ inline std::string GetDLBlockingHistogramName(const std::string& initiator, ...@@ -198,9 +198,10 @@ inline std::string GetDLBlockingHistogramName(const std::string& initiator,
.append(download); .append(download);
} }
// When enabled (via kTreatUnsafeDownloadsAsActive), block unsafe downloads // Returns the correct mixed content download blocking behavior for the given
// that are requested by secure sources but are served insecurely. // |item| saved to |path|. Controlled by kTreatUnsafeDownloadsAsActive.
bool ShouldBlockFileAsMixedContent(const base::FilePath& path, download::DownloadItem::MixedContentStatus GetMixedContentStatusForDownload(
const download::DownloadItem& item); const base::FilePath& path,
const download::DownloadItem& item);
#endif // CHROME_BROWSER_DOWNLOAD_MIXED_CONTENT_DOWNLOAD_BLOCKING_H_ #endif // CHROME_BROWSER_DOWNLOAD_MIXED_CONTENT_DOWNLOAD_BLOCKING_H_
...@@ -225,10 +225,11 @@ class TestDownloadManagerDelegate : public ChromeDownloadManagerDelegate { ...@@ -225,10 +225,11 @@ class TestDownloadManagerDelegate : public ChromeDownloadManagerDelegate {
const base::FilePath& target_path, const base::FilePath& target_path,
download::DownloadItem::TargetDisposition disp, download::DownloadItem::TargetDisposition disp,
download::DownloadDangerType danger_type, download::DownloadDangerType danger_type,
download::DownloadItem::MixedContentStatus mcs,
const base::FilePath& intermediate_path, const base::FilePath& intermediate_path,
download::DownloadInterruptReason reason) { download::DownloadInterruptReason reason) {
std::move(callback).Run(target_path, disp, std::move(callback).Run(target_path, disp,
download::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL, download::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL, mcs,
intermediate_path, reason); intermediate_path, reason);
} }
}; };
......
...@@ -32,7 +32,8 @@ bool CastDownloadManagerDelegate::DetermineDownloadTarget( ...@@ -32,7 +32,8 @@ bool CastDownloadManagerDelegate::DetermineDownloadTarget(
base::FilePath empty; base::FilePath empty;
std::move(*callback).Run( std::move(*callback).Run(
empty, download::DownloadItem::TARGET_DISPOSITION_OVERWRITE, empty, download::DownloadItem::TARGET_DISPOSITION_OVERWRITE,
download::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT, empty, download::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT,
download::DownloadItem::MixedContentStatus::UNKNOWN, empty,
download::DOWNLOAD_INTERRUPT_REASON_USER_CANCELED); download::DOWNLOAD_INTERRUPT_REASON_USER_CANCELED);
return true; return true;
} }
......
...@@ -978,6 +978,11 @@ DownloadDangerType DownloadItemImpl::GetDangerType() const { ...@@ -978,6 +978,11 @@ DownloadDangerType DownloadItemImpl::GetDangerType() const {
return danger_type_; return danger_type_;
} }
DownloadItem::MixedContentStatus DownloadItemImpl::GetMixedContentStatus()
const {
return mixed_content_status_;
}
bool DownloadItemImpl::TimeRemaining(base::TimeDelta* remaining) const { bool DownloadItemImpl::TimeRemaining(base::TimeDelta* remaining) const {
if (total_bytes_ <= 0) if (total_bytes_ <= 0)
return false; // We never received the content_length for this download. return false; // We never received the content_length for this download.
...@@ -1616,6 +1621,7 @@ void DownloadItemImpl::OnDownloadTargetDetermined( ...@@ -1616,6 +1621,7 @@ void DownloadItemImpl::OnDownloadTargetDetermined(
const base::FilePath& target_path, const base::FilePath& target_path,
TargetDisposition disposition, TargetDisposition disposition,
DownloadDangerType danger_type, DownloadDangerType danger_type,
MixedContentStatus mixed_content_status,
const base::FilePath& intermediate_path, const base::FilePath& intermediate_path,
DownloadInterruptReason interrupt_reason) { DownloadInterruptReason interrupt_reason) {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
...@@ -1655,6 +1661,7 @@ void DownloadItemImpl::OnDownloadTargetDetermined( ...@@ -1655,6 +1661,7 @@ void DownloadItemImpl::OnDownloadTargetDetermined(
destination_info_.target_path = target_path; destination_info_.target_path = target_path;
destination_info_.target_disposition = disposition; destination_info_.target_disposition = disposition;
SetDangerType(danger_type); SetDangerType(danger_type);
mixed_content_status_ = mixed_content_status;
// This was an interrupted download that was looking for a filename. Resolve // This was an interrupted download that was looking for a filename. Resolve
// early without performing the intermediate rename. If there is a // early without performing the intermediate rename. If there is a
......
...@@ -36,8 +36,9 @@ void DownloadItemImplDelegate::DetermineDownloadTarget( ...@@ -36,8 +36,9 @@ void DownloadItemImplDelegate::DetermineDownloadTarget(
base::FilePath target_path(download->GetForcedFilePath()); base::FilePath target_path(download->GetForcedFilePath());
std::move(callback).Run(target_path, std::move(callback).Run(target_path,
DownloadItem::TARGET_DISPOSITION_OVERWRITE, DownloadItem::TARGET_DISPOSITION_OVERWRITE,
DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, target_path, DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS,
DOWNLOAD_INTERRUPT_REASON_NONE); DownloadItem::MixedContentStatus::UNKNOWN,
target_path, DOWNLOAD_INTERRUPT_REASON_NONE);
} }
bool DownloadItemImplDelegate::ShouldCompleteDownload( bool DownloadItemImplDelegate::ShouldCompleteDownload(
......
...@@ -159,6 +159,7 @@ void OnDownloadDisplayNamesReturned( ...@@ -159,6 +159,7 @@ void OnDownloadDisplayNamesReturned(
void OnPathReserved(DownloadItemImplDelegate::DownloadTargetCallback callback, void OnPathReserved(DownloadItemImplDelegate::DownloadTargetCallback callback,
DownloadDangerType danger_type, DownloadDangerType danger_type,
DownloadItem::MixedContentStatus mixed_content_status,
const InProgressDownloadManager::IntermediatePathCallback& const InProgressDownloadManager::IntermediatePathCallback&
intermediate_path_cb, intermediate_path_cb,
const base::FilePath& forced_file_path, const base::FilePath& forced_file_path,
...@@ -182,7 +183,7 @@ void OnPathReserved(DownloadItemImplDelegate::DownloadTargetCallback callback, ...@@ -182,7 +183,7 @@ void OnPathReserved(DownloadItemImplDelegate::DownloadTargetCallback callback,
: BackgroudTargetDeterminationResultTypes::kSuccess); : BackgroudTargetDeterminationResultTypes::kSuccess);
std::move(callback).Run( std::move(callback).Run(
target_path, DownloadItem::TARGET_DISPOSITION_OVERWRITE, danger_type, target_path, DownloadItem::TARGET_DISPOSITION_OVERWRITE, danger_type,
intermediate_path, mixed_content_status, intermediate_path,
intermediate_path.empty() ? DOWNLOAD_INTERRUPT_REASON_FILE_FAILED intermediate_path.empty() ? DOWNLOAD_INTERRUPT_REASON_FILE_FAILED
: DOWNLOAD_INTERRUPT_REASON_NONE); : DOWNLOAD_INTERRUPT_REASON_NONE);
} }
...@@ -393,10 +394,10 @@ void InProgressDownloadManager::DetermineDownloadTarget( ...@@ -393,10 +394,10 @@ void InProgressDownloadManager::DetermineDownloadTarget(
: download->GetForcedFilePath(); : download->GetForcedFilePath();
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
if (target_path.empty()) { if (target_path.empty()) {
std::move(callback).Run(target_path, std::move(callback).Run(
DownloadItem::TARGET_DISPOSITION_OVERWRITE, target_path, DownloadItem::TARGET_DISPOSITION_OVERWRITE,
download->GetDangerType(), target_path, download->GetDangerType(), download->GetMixedContentStatus(),
DOWNLOAD_INTERRUPT_REASON_FILE_FAILED); target_path, DOWNLOAD_INTERRUPT_REASON_FILE_FAILED);
RecordBackgroundTargetDeterminationResult( RecordBackgroundTargetDeterminationResult(
BackgroudTargetDeterminationResultTypes::kTargetPathMissing); BackgroudTargetDeterminationResultTypes::kTargetPathMissing);
return; return;
...@@ -407,7 +408,8 @@ void InProgressDownloadManager::DetermineDownloadTarget( ...@@ -407,7 +408,8 @@ void InProgressDownloadManager::DetermineDownloadTarget(
if (target_path.IsContentUri()) { if (target_path.IsContentUri()) {
std::move(callback).Run( std::move(callback).Run(
target_path, DownloadItem::TARGET_DISPOSITION_OVERWRITE, target_path, DownloadItem::TARGET_DISPOSITION_OVERWRITE,
download->GetDangerType(), target_path, DOWNLOAD_INTERRUPT_REASON_NONE); download->GetDangerType(), download->GetMixedContentStatus(),
target_path, DOWNLOAD_INTERRUPT_REASON_NONE);
RecordBackgroundTargetDeterminationResult( RecordBackgroundTargetDeterminationResult(
BackgroudTargetDeterminationResultTypes::kSuccess); BackgroudTargetDeterminationResultTypes::kSuccess);
return; return;
...@@ -420,16 +422,17 @@ void InProgressDownloadManager::DetermineDownloadTarget( ...@@ -420,16 +422,17 @@ void InProgressDownloadManager::DetermineDownloadTarget(
? DownloadPathReservationTracker::UNIQUIFY ? DownloadPathReservationTracker::UNIQUIFY
: DownloadPathReservationTracker::OVERWRITE, : DownloadPathReservationTracker::OVERWRITE,
base::BindOnce(&OnPathReserved, std::move(callback), base::BindOnce(&OnPathReserved, std::move(callback),
download->GetDangerType(), intermediate_path_cb_, download->GetDangerType(),
download->GetMixedContentStatus(), intermediate_path_cb_,
download->GetForcedFilePath())); download->GetForcedFilePath()));
#else #else
// For non-android, the code below is only used by tests. // For non-android, the code below is only used by tests.
base::FilePath intermediate_path = base::FilePath intermediate_path =
download->GetFullPath().empty() ? target_path : download->GetFullPath(); download->GetFullPath().empty() ? target_path : download->GetFullPath();
std::move(callback).Run(target_path, std::move(callback).Run(
DownloadItem::TARGET_DISPOSITION_OVERWRITE, target_path, DownloadItem::TARGET_DISPOSITION_OVERWRITE,
download->GetDangerType(), intermediate_path, download->GetDangerType(), download->GetMixedContentStatus(),
DOWNLOAD_INTERRUPT_REASON_NONE); intermediate_path, DOWNLOAD_INTERRUPT_REASON_NONE);
#endif // defined(OS_ANDROID) #endif // defined(OS_ANDROID)
} }
......
...@@ -101,6 +101,20 @@ class COMPONENTS_DOWNLOAD_EXPORT DownloadItem : public base::SupportsUserData { ...@@ -101,6 +101,20 @@ class COMPONENTS_DOWNLOAD_EXPORT DownloadItem : public base::SupportsUserData {
RESULT_MAX = FAILURE_UNKNOWN RESULT_MAX = FAILURE_UNKNOWN
}; };
// The mixed content status for a download item.
enum MixedContentStatus {
// Target not yet determined, so status not yet available.
UNKNOWN = 0,
// Download is not mixed content.
SAFE = 1,
// Download is mixed content, and the user should be warned.
WARN = 2,
// Download is mixed content, and the user should see an error.
BLOCK = 3,
// Download is mixed content, and it should be silently dropped.
SILENT_BLOCK = 4,
};
// Callback used with AcquireFileAndDeleteDownload(). // Callback used with AcquireFileAndDeleteDownload().
typedef base::Callback<void(const base::FilePath&)> AcquireFileCallback; typedef base::Callback<void(const base::FilePath&)> AcquireFileCallback;
using RenameDownloadCallback = base::OnceCallback<void(DownloadRenameResult)>; using RenameDownloadCallback = base::OnceCallback<void(DownloadRenameResult)>;
...@@ -404,6 +418,11 @@ class COMPONENTS_DOWNLOAD_EXPORT DownloadItem : public base::SupportsUserData { ...@@ -404,6 +418,11 @@ class COMPONENTS_DOWNLOAD_EXPORT DownloadItem : public base::SupportsUserData {
// Why |safety_state_| is not SAFE. // Why |safety_state_| is not SAFE.
virtual DownloadDangerType GetDangerType() const = 0; virtual DownloadDangerType GetDangerType() const = 0;
// Returns the mixed content status of the download, indicating whether the
// download should be blocked or the user warned. This may be UNKNOWN if the
// download target hasn't been determined.
virtual MixedContentStatus GetMixedContentStatus() const = 0;
// Gets the pointer to the DownloadFile owned by this object. // Gets the pointer to the DownloadFile owned by this object.
virtual DownloadFile* GetDownloadFile() = 0; virtual DownloadFile* GetDownloadFile() = 0;
......
...@@ -281,6 +281,7 @@ class COMPONENTS_DOWNLOAD_EXPORT DownloadItemImpl ...@@ -281,6 +281,7 @@ class COMPONENTS_DOWNLOAD_EXPORT DownloadItemImpl
DownloadFile* GetDownloadFile() override; DownloadFile* GetDownloadFile() override;
bool IsDangerous() const override; bool IsDangerous() const override;
DownloadDangerType GetDangerType() const override; DownloadDangerType GetDangerType() const override;
MixedContentStatus GetMixedContentStatus() const override;
bool TimeRemaining(base::TimeDelta* remaining) const override; bool TimeRemaining(base::TimeDelta* remaining) const override;
int64_t CurrentSpeed() const override; int64_t CurrentSpeed() const override;
int PercentComplete() const override; int PercentComplete() const override;
...@@ -563,6 +564,7 @@ class COMPONENTS_DOWNLOAD_EXPORT DownloadItemImpl ...@@ -563,6 +564,7 @@ class COMPONENTS_DOWNLOAD_EXPORT DownloadItemImpl
const base::FilePath& target_path, const base::FilePath& target_path,
TargetDisposition disposition, TargetDisposition disposition,
DownloadDangerType danger_type, DownloadDangerType danger_type,
MixedContentStatus mixed_content_status,
const base::FilePath& intermediate_path, const base::FilePath& intermediate_path,
DownloadInterruptReason interrupt_reason); DownloadInterruptReason interrupt_reason);
...@@ -844,6 +846,9 @@ class COMPONENTS_DOWNLOAD_EXPORT DownloadItemImpl ...@@ -844,6 +846,9 @@ class COMPONENTS_DOWNLOAD_EXPORT DownloadItemImpl
// Whether download has been resumed. // Whether download has been resumed.
bool has_resumed_ = false; bool has_resumed_ = false;
// The MixedContentStatus if determined.
MixedContentStatus mixed_content_status_ = MixedContentStatus::UNKNOWN;
THREAD_CHECKER(thread_checker_); THREAD_CHECKER(thread_checker_);
base::WeakPtrFactory<DownloadItemImpl> weak_ptr_factory_{this}; base::WeakPtrFactory<DownloadItemImpl> weak_ptr_factory_{this};
......
...@@ -39,12 +39,13 @@ class COMPONENTS_DOWNLOAD_EXPORT DownloadItemImplDelegate { ...@@ -39,12 +39,13 @@ class COMPONENTS_DOWNLOAD_EXPORT DownloadItemImplDelegate {
void Attach(); void Attach();
void Detach(); void Detach();
using DownloadTargetCallback = using DownloadTargetCallback = base::OnceCallback<void(
base::OnceCallback<void(const base::FilePath& target_path, const base::FilePath& target_path,
DownloadItem::TargetDisposition disposition, DownloadItem::TargetDisposition disposition,
DownloadDangerType danger_type, DownloadDangerType danger_type,
const base::FilePath& intermediate_path, DownloadItem::MixedContentStatus mixed_content_status,
DownloadInterruptReason interrupt_reason)>; const base::FilePath& intermediate_path,
DownloadInterruptReason interrupt_reason)>;
// Request determination of the download target from the delegate. // Request determination of the download target from the delegate.
virtual void DetermineDownloadTarget(DownloadItemImpl* download, virtual void DetermineDownloadTarget(DownloadItemImpl* download,
DownloadTargetCallback callback); DownloadTargetCallback callback);
......
...@@ -101,6 +101,7 @@ class MockDownloadItem : public DownloadItem { ...@@ -101,6 +101,7 @@ class MockDownloadItem : public DownloadItem {
MOCK_METHOD0(GetDownloadFile, DownloadFile*()); MOCK_METHOD0(GetDownloadFile, DownloadFile*());
MOCK_CONST_METHOD0(IsDangerous, bool()); MOCK_CONST_METHOD0(IsDangerous, bool());
MOCK_CONST_METHOD0(GetDangerType, DownloadDangerType()); MOCK_CONST_METHOD0(GetDangerType, DownloadDangerType());
MOCK_CONST_METHOD0(GetMixedContentStatus, MixedContentStatus());
MOCK_CONST_METHOD1(TimeRemaining, bool(base::TimeDelta*)); MOCK_CONST_METHOD1(TimeRemaining, bool(base::TimeDelta*));
MOCK_CONST_METHOD0(CurrentSpeed, int64_t()); MOCK_CONST_METHOD0(CurrentSpeed, int64_t());
MOCK_CONST_METHOD0(PercentComplete, int()); MOCK_CONST_METHOD0(PercentComplete, int());
...@@ -127,6 +128,7 @@ class MockDownloadItem : public DownloadItem { ...@@ -127,6 +128,7 @@ class MockDownloadItem : public DownloadItem {
MOCK_METHOD1(SetOpened, void(bool)); MOCK_METHOD1(SetOpened, void(bool));
MOCK_METHOD1(SetLastAccessTime, void(base::Time)); MOCK_METHOD1(SetLastAccessTime, void(base::Time));
MOCK_METHOD1(SetDisplayName, void(const base::FilePath&)); MOCK_METHOD1(SetDisplayName, void(const base::FilePath&));
MOCK_METHOD1(SetMixedContentStatus, void(MixedContentStatus));
MOCK_CONST_METHOD1(DebugString, std::string(bool)); MOCK_CONST_METHOD1(DebugString, std::string(bool));
MOCK_METHOD1(SimulateErrorForTesting, void(DownloadInterruptReason)); MOCK_METHOD1(SimulateErrorForTesting, void(DownloadInterruptReason));
MOCK_METHOD2(Rename, void(const base::FilePath&, RenameDownloadCallback)); MOCK_METHOD2(Rename, void(const base::FilePath&, RenameDownloadCallback));
......
...@@ -27,10 +27,11 @@ class MockDownloadItemImpl : public DownloadItemImpl { ...@@ -27,10 +27,11 @@ class MockDownloadItemImpl : public DownloadItemImpl {
explicit MockDownloadItemImpl(DownloadItemImplDelegate* delegate); explicit MockDownloadItemImpl(DownloadItemImplDelegate* delegate);
~MockDownloadItemImpl() override; ~MockDownloadItemImpl() override;
MOCK_METHOD5(OnDownloadTargetDetermined, MOCK_METHOD6(OnDownloadTargetDetermined,
void(const base::FilePath&, void(const base::FilePath&,
TargetDisposition, TargetDisposition,
DownloadDangerType, DownloadDangerType,
MixedContentStatus,
const base::FilePath&, const base::FilePath&,
DownloadInterruptReason)); DownloadInterruptReason));
MOCK_METHOD1(AddObserver, void(DownloadItem::Observer*)); MOCK_METHOD1(AddObserver, void(DownloadItem::Observer*));
...@@ -102,6 +103,7 @@ class MockDownloadItemImpl : public DownloadItemImpl { ...@@ -102,6 +103,7 @@ class MockDownloadItemImpl : public DownloadItemImpl {
MOCK_METHOD1(SetOpenWhenComplete, void(bool)); MOCK_METHOD1(SetOpenWhenComplete, void(bool));
MOCK_CONST_METHOD0(GetFileExternallyRemoved, bool()); MOCK_CONST_METHOD0(GetFileExternallyRemoved, bool());
MOCK_CONST_METHOD0(GetDangerType, DownloadDangerType()); MOCK_CONST_METHOD0(GetDangerType, DownloadDangerType());
MOCK_CONST_METHOD0(GetMixedContentStatus, MixedContentStatus());
MOCK_CONST_METHOD0(IsDangerous, bool()); MOCK_CONST_METHOD0(IsDangerous, bool());
MOCK_METHOD0(GetAutoOpened, bool()); MOCK_METHOD0(GetAutoOpened, bool());
MOCK_CONST_METHOD0(GetForcedFilePath, const base::FilePath&()); MOCK_CONST_METHOD0(GetForcedFilePath, const base::FilePath&());
......
...@@ -102,7 +102,8 @@ bool DevToolsDownloadManagerDelegate::DetermineDownloadTarget( ...@@ -102,7 +102,8 @@ bool DevToolsDownloadManagerDelegate::DetermineDownloadTarget(
base::FilePath empty_path = base::FilePath(); base::FilePath empty_path = base::FilePath();
std::move(*callback).Run( std::move(*callback).Run(
empty_path, download::DownloadItem::TARGET_DISPOSITION_OVERWRITE, empty_path, download::DownloadItem::TARGET_DISPOSITION_OVERWRITE,
download::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, empty_path, download::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS,
download::DownloadItem::MixedContentStatus::UNKNOWN, empty_path,
download::DOWNLOAD_INTERRUPT_REASON_FILE_BLOCKED); download::DOWNLOAD_INTERRUPT_REASON_FILE_BLOCKED);
return true; return true;
} }
...@@ -184,6 +185,7 @@ void DevToolsDownloadManagerDelegate::OnDownloadPathGenerated( ...@@ -184,6 +185,7 @@ void DevToolsDownloadManagerDelegate::OnDownloadPathGenerated(
std::move(callback).Run( std::move(callback).Run(
suggested_path, download::DownloadItem::TARGET_DISPOSITION_OVERWRITE, suggested_path, download::DownloadItem::TARGET_DISPOSITION_OVERWRITE,
download::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT, download::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT,
download::DownloadItem::MixedContentStatus::UNKNOWN,
suggested_path.AddExtension(FILE_PATH_LITERAL(".crdownload")), suggested_path.AddExtension(FILE_PATH_LITERAL(".crdownload")),
download::DOWNLOAD_INTERRUPT_REASON_NONE); download::DOWNLOAD_INTERRUPT_REASON_NONE);
} }
......
...@@ -401,7 +401,8 @@ void DownloadManagerImpl::DetermineDownloadTarget( ...@@ -401,7 +401,8 @@ void DownloadManagerImpl::DetermineDownloadTarget(
// TODO(asanka): Determine a useful path if |target_path| is empty. // TODO(asanka): Determine a useful path if |target_path| is empty.
std::move(callback).Run( std::move(callback).Run(
target_path, download::DownloadItem::TARGET_DISPOSITION_OVERWRITE, target_path, download::DownloadItem::TARGET_DISPOSITION_OVERWRITE,
download::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, target_path, download::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS,
download::DownloadItem::MixedContentStatus::UNKNOWN, target_path,
download::DOWNLOAD_INTERRUPT_REASON_NONE); download::DOWNLOAD_INTERRUPT_REASON_NONE);
} }
} }
......
...@@ -530,6 +530,7 @@ class DownloadManagerTest : public testing::Test { ...@@ -530,6 +530,7 @@ class DownloadManagerTest : public testing::Test {
const base::FilePath& target_path, const base::FilePath& target_path,
download::DownloadItem::TargetDisposition disposition, download::DownloadItem::TargetDisposition disposition,
download::DownloadDangerType danger_type, download::DownloadDangerType danger_type,
download::DownloadItem::MixedContentStatus mixed_content_status,
const base::FilePath& intermediate_path, const base::FilePath& intermediate_path,
download::DownloadInterruptReason interrupt_reason) { download::DownloadInterruptReason interrupt_reason) {
callback_called_ = true; callback_called_ = true;
......
...@@ -63,6 +63,7 @@ using DownloadTargetCallback = base::OnceCallback<void( ...@@ -63,6 +63,7 @@ using DownloadTargetCallback = base::OnceCallback<void(
const base::FilePath& target_path, const base::FilePath& target_path,
download::DownloadItem::TargetDisposition disposition, download::DownloadItem::TargetDisposition disposition,
download::DownloadDangerType danger_type, download::DownloadDangerType danger_type,
download::DownloadItem::MixedContentStatus mixed_content_status,
const base::FilePath& intermediate_path, const base::FilePath& intermediate_path,
download::DownloadInterruptReason interrupt_reason)>; download::DownloadInterruptReason interrupt_reason)>;
......
...@@ -419,6 +419,12 @@ download::DownloadDangerType FakeDownloadItem::GetDangerType() const { ...@@ -419,6 +419,12 @@ download::DownloadDangerType FakeDownloadItem::GetDangerType() const {
return download::DownloadDangerType(); return download::DownloadDangerType();
} }
download::DownloadItem::MixedContentStatus
FakeDownloadItem::GetMixedContentStatus() const {
NOTREACHED();
return download::DownloadItem::MixedContentStatus();
}
bool FakeDownloadItem::TimeRemaining(base::TimeDelta* remaining) const { bool FakeDownloadItem::TimeRemaining(base::TimeDelta* remaining) const {
NOTREACHED(); NOTREACHED();
return false; return false;
......
...@@ -90,6 +90,8 @@ class FakeDownloadItem : public download::DownloadItem { ...@@ -90,6 +90,8 @@ class FakeDownloadItem : public download::DownloadItem {
download::DownloadFile* GetDownloadFile() override; download::DownloadFile* GetDownloadFile() override;
bool IsDangerous() const override; bool IsDangerous() const override;
download::DownloadDangerType GetDangerType() const override; download::DownloadDangerType GetDangerType() const override;
download::DownloadItem::MixedContentStatus GetMixedContentStatus()
const override;
bool TimeRemaining(base::TimeDelta* remaining) const override; bool TimeRemaining(base::TimeDelta* remaining) const override;
int64_t CurrentSpeed() const override; int64_t CurrentSpeed() const override;
int PercentComplete() const override; int PercentComplete() const override;
......
...@@ -75,6 +75,7 @@ bool ShellDownloadManagerDelegate::DetermineDownloadTarget( ...@@ -75,6 +75,7 @@ bool ShellDownloadManagerDelegate::DetermineDownloadTarget(
download->GetForcedFilePath(), download->GetForcedFilePath(),
download::DownloadItem::TARGET_DISPOSITION_OVERWRITE, download::DownloadItem::TARGET_DISPOSITION_OVERWRITE,
download::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, download::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS,
download::DownloadItem::MixedContentStatus::UNKNOWN,
download->GetForcedFilePath(), download->GetForcedFilePath(),
download::DOWNLOAD_INTERRUPT_REASON_NONE); download::DOWNLOAD_INTERRUPT_REASON_NONE);
return true; return true;
...@@ -140,6 +141,7 @@ void ShellDownloadManagerDelegate::OnDownloadPathGenerated( ...@@ -140,6 +141,7 @@ void ShellDownloadManagerDelegate::OnDownloadPathGenerated(
std::move(callback).Run( std::move(callback).Run(
suggested_path, download::DownloadItem::TARGET_DISPOSITION_OVERWRITE, suggested_path, download::DownloadItem::TARGET_DISPOSITION_OVERWRITE,
download::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, download::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS,
download::DownloadItem::MixedContentStatus::UNKNOWN,
suggested_path.AddExtension(FILE_PATH_LITERAL(".crdownload")), suggested_path.AddExtension(FILE_PATH_LITERAL(".crdownload")),
download::DOWNLOAD_INTERRUPT_REASON_NONE); download::DOWNLOAD_INTERRUPT_REASON_NONE);
return; return;
...@@ -190,8 +192,9 @@ void ShellDownloadManagerDelegate::ChooseDownloadPath( ...@@ -190,8 +192,9 @@ void ShellDownloadManagerDelegate::ChooseDownloadPath(
std::move(callback).Run(result, std::move(callback).Run(result,
download::DownloadItem::TARGET_DISPOSITION_PROMPT, download::DownloadItem::TARGET_DISPOSITION_PROMPT,
download::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, result, download::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS,
download::DOWNLOAD_INTERRUPT_REASON_NONE); download::DownloadItem::MixedContentStatus::UNKNOWN,
result, download::DOWNLOAD_INTERRUPT_REASON_NONE);
} }
void ShellDownloadManagerDelegate::SetDownloadBehaviorForTesting( void ShellDownloadManagerDelegate::SetDownloadBehaviorForTesting(
......
...@@ -61,8 +61,9 @@ bool DownloadManagerDelegateImpl::DetermineDownloadTarget( ...@@ -61,8 +61,9 @@ bool DownloadManagerDelegateImpl::DetermineDownloadTarget(
std::move(*callback).Run( std::move(*callback).Run(
item->GetForcedFilePath(), item->GetForcedFilePath(),
download::DownloadItem::TARGET_DISPOSITION_OVERWRITE, download::DownloadItem::TARGET_DISPOSITION_OVERWRITE,
download::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, item->GetForcedFilePath(), download::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS,
download::DOWNLOAD_INTERRUPT_REASON_NONE); download::DownloadItem::MixedContentStatus::UNKNOWN,
item->GetForcedFilePath(), download::DOWNLOAD_INTERRUPT_REASON_NONE);
return true; return true;
} }
...@@ -184,6 +185,7 @@ void DownloadManagerDelegateImpl::OnDownloadPathGenerated( ...@@ -184,6 +185,7 @@ void DownloadManagerDelegateImpl::OnDownloadPathGenerated(
std::move(callback).Run( std::move(callback).Run(
suggested_path, download::DownloadItem::TARGET_DISPOSITION_OVERWRITE, suggested_path, download::DownloadItem::TARGET_DISPOSITION_OVERWRITE,
download::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, download::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS,
download::DownloadItem::MixedContentStatus::UNKNOWN,
suggested_path.AddExtension(FILE_PATH_LITERAL(".crdownload")), suggested_path.AddExtension(FILE_PATH_LITERAL(".crdownload")),
download::DOWNLOAD_INTERRUPT_REASON_NONE); download::DOWNLOAD_INTERRUPT_REASON_NONE);
} }
......
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