Commit ffd2ebc2 authored by Peter Kasting's avatar Peter Kasting Committed by Commit Bot

Small cleanups for DownloadItemView::Mode.

* Convert enum -> enum class
* Rename values for consistency and clarity
* Rename/modify helpers for brevity and clarity
* Move values and helpers to .cc to keep .h shorter
* Use helpers more consistently

Bug: none
Change-Id: I12987b7c7dd8dd4589bbada0f23688309ece95fc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2256362
Commit-Queue: Shakti Sahu <shaktisahu@chromium.org>
Reviewed-by: default avatarShakti Sahu <shaktisahu@chromium.org>
Auto-Submit: Peter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/master@{#781921}
parent 9adcfb10
...@@ -105,6 +105,15 @@ ...@@ -105,6 +105,15 @@
using download::DownloadItem; using download::DownloadItem;
using MixedContentStatus = download::DownloadItem::MixedContentStatus; using MixedContentStatus = download::DownloadItem::MixedContentStatus;
enum class DownloadItemView::Mode {
kNormal, // Showing download item.
kDangerous, // Displaying the dangerous download warning.
kMalicious, // Displaying the malicious download warning.
kMixedContentWarn, // Displaying the mixed-content download warning.
kMixedContentBlock, // Displaying the mixed-content download block error.
kDeepScanning, // Displaying in-progress deep scanning information.
};
namespace { namespace {
// Size of the space used for the progress indicator. // Size of the space used for the progress indicator.
...@@ -216,6 +225,23 @@ void StyleFilename(views::StyledLabel& label, size_t pos, size_t len) { ...@@ -216,6 +225,23 @@ void StyleFilename(views::StyledLabel& label, size_t pos, size_t len) {
label.AddStyleRange(gfx::Range(pos, pos + len), style); label.AddStyleRange(gfx::Range(pos, pos + len), style);
} }
// Whether we are warning about a dangerous/malicious download.
bool is_download_warning(DownloadItemView::Mode mode) {
return (mode == DownloadItemView::Mode::kDangerous) ||
(mode == DownloadItemView::Mode::kMalicious);
}
// Whether we are in the mixed content mode.
bool is_mixed_content(DownloadItemView::Mode mode) {
return (mode == DownloadItemView::Mode::kMixedContentWarn) ||
(mode == DownloadItemView::Mode::kMixedContentBlock);
}
// Whether a warning label is visible.
bool has_warning_label(DownloadItemView::Mode mode) {
return is_download_warning(mode) || is_mixed_content(mode);
}
} // namespace } // namespace
DownloadItemView::DownloadItemView(DownloadUIModel::DownloadUIModelPtr download, DownloadItemView::DownloadItemView(DownloadUIModel::DownloadUIModelPtr download,
...@@ -224,7 +250,7 @@ DownloadItemView::DownloadItemView(DownloadUIModel::DownloadUIModelPtr download, ...@@ -224,7 +250,7 @@ DownloadItemView::DownloadItemView(DownloadUIModel::DownloadUIModelPtr download,
: AnimationDelegateViews(this), : AnimationDelegateViews(this),
shelf_(parent), shelf_(parent),
dropdown_state_(NORMAL), dropdown_state_(NORMAL),
mode_(NORMAL_MODE), mode_(Mode::kNormal),
dragging_(false), dragging_(false),
model_(std::move(download)), model_(std::move(download)),
save_button_(nullptr), save_button_(nullptr),
...@@ -297,7 +323,7 @@ void DownloadItemView::Layout() { ...@@ -297,7 +323,7 @@ void DownloadItemView::Layout() {
open_button_->SetBoundsRect(GetLocalBounds()); open_button_->SetBoundsRect(GetLocalBounds());
if (IsShowingWarningDialog()) { if (is_download_warning(mode_)) {
gfx::Point child_origin( gfx::Point child_origin(
kStartPadding + GetWarningIconSize() + kStartPadding, kStartPadding + GetWarningIconSize() + kStartPadding,
(height() - dangerous_download_label_->height()) / 2); (height() - dangerous_download_label_->height()) / 2);
...@@ -314,7 +340,7 @@ void DownloadItemView::Layout() { ...@@ -314,7 +340,7 @@ void DownloadItemView::Layout() {
discard_button_->SetBoundsRect(gfx::Rect(child_origin, button_size)); discard_button_->SetBoundsRect(gfx::Rect(child_origin, button_size));
if (scan_button_) if (scan_button_)
scan_button_->SetBoundsRect(gfx::Rect(child_origin, button_size)); scan_button_->SetBoundsRect(gfx::Rect(child_origin, button_size));
} else if (IsShowingMixedContentDialog()) { } else if (is_mixed_content(mode_)) {
gfx::Point child_origin( gfx::Point child_origin(
kStartPadding + GetWarningIconSize() + kStartPadding, kStartPadding + GetWarningIconSize() + kStartPadding,
(height() - dangerous_download_label_->height()) / 2); (height() - dangerous_download_label_->height()) / 2);
...@@ -327,7 +353,7 @@ void DownloadItemView::Layout() { ...@@ -327,7 +353,7 @@ void DownloadItemView::Layout() {
save_button_->SetBoundsRect(gfx::Rect(child_origin, button_size)); save_button_->SetBoundsRect(gfx::Rect(child_origin, button_size));
if (discard_button_) if (discard_button_)
discard_button_->SetBoundsRect(gfx::Rect(child_origin, button_size)); discard_button_->SetBoundsRect(gfx::Rect(child_origin, button_size));
} else if (IsShowingDeepScanning()) { } else if (mode_ == Mode::kDeepScanning) {
gfx::Point child_origin( gfx::Point child_origin(
kStartPadding + GetWarningIconSize() + kStartPadding, kStartPadding + GetWarningIconSize() + kStartPadding,
(height() - deep_scanning_label_->height()) / 2); (height() - deep_scanning_label_->height()) / 2);
...@@ -359,7 +385,7 @@ void DownloadItemView::Layout() { ...@@ -359,7 +385,7 @@ void DownloadItemView::Layout() {
status_font_list_.GetHeight())); status_font_list_.GetHeight()));
} }
if (mode_ != DANGEROUS_MODE) { if (mode_ != Mode::kDangerous) {
dropdown_button_->SizeToPreferredSize(); dropdown_button_->SizeToPreferredSize();
dropdown_button_->SetPosition( dropdown_button_->SetPosition(
gfx::Point(width() - dropdown_button_->width() - kEndPadding, gfx::Point(width() - dropdown_button_->width() - kEndPadding,
...@@ -371,7 +397,7 @@ bool DownloadItemView::OnMouseDragged(const ui::MouseEvent& event) { ...@@ -371,7 +397,7 @@ bool DownloadItemView::OnMouseDragged(const ui::MouseEvent& event) {
// Handle drag (file copy) operations. // Handle drag (file copy) operations.
// Mouse should not activate us in dangerous mode. // Mouse should not activate us in dangerous mode.
if (IsShowingWarningDialog() || IsShowingMixedContentDialog()) if (has_warning_label(mode_))
return true; return true;
if (!drag_start_point_) if (!drag_start_point_)
...@@ -394,7 +420,7 @@ bool DownloadItemView::OnMouseDragged(const ui::MouseEvent& event) { ...@@ -394,7 +420,7 @@ bool DownloadItemView::OnMouseDragged(const ui::MouseEvent& event) {
void DownloadItemView::OnMouseCaptureLost() { void DownloadItemView::OnMouseCaptureLost() {
// Mouse should not activate us in dangerous mode. // Mouse should not activate us in dangerous mode.
if (mode_ != NORMAL_MODE) if (mode_ != Mode::kNormal)
return; return;
if (dragging_) { if (dragging_) {
...@@ -405,9 +431,7 @@ void DownloadItemView::OnMouseCaptureLost() { ...@@ -405,9 +431,7 @@ void DownloadItemView::OnMouseCaptureLost() {
} }
base::string16 DownloadItemView::GetTooltipText(const gfx::Point& p) const { base::string16 DownloadItemView::GetTooltipText(const gfx::Point& p) const {
return (IsShowingWarningDialog() || IsShowingMixedContentDialog()) return has_warning_label(mode_) ? base::string16() : tooltip_text_;
? base::string16()
: tooltip_text_;
} }
void DownloadItemView::GetAccessibleNodeData(ui::AXNodeData* node_data) { void DownloadItemView::GetAccessibleNodeData(ui::AXNodeData* node_data) {
...@@ -437,11 +461,11 @@ void DownloadItemView::ButtonPressed(views::Button* sender, ...@@ -437,11 +461,11 @@ void DownloadItemView::ButtonPressed(views::Button* sender,
if (!time_download_warning_shown_.is_null()) if (!time_download_warning_shown_.is_null())
warning_duration = base::Time::Now() - time_download_warning_shown_; warning_duration = base::Time::Now() - time_download_warning_shown_;
if (mode_ == MIX_DL_WARNING_MODE && sender == save_button_) { if (mode_ == Mode::kMixedContentWarn && sender == save_button_) {
DownloadCommands(model_.get()).ExecuteCommand(DownloadCommands::KEEP); DownloadCommands(model_.get()).ExecuteCommand(DownloadCommands::KEEP);
return; return;
} }
if (mode_ == DANGEROUS_MODE && sender == save_button_) { if (mode_ == Mode::kDangerous && sender == save_button_) {
// The user has confirmed a dangerous download. We'd record how quickly the // The user has confirmed a dangerous download. We'd record how quickly the
// user did this to detect whether we're being clickjacked. // user did this to detect whether we're being clickjacked.
UMA_HISTOGRAM_LONG_TIMES("clickjacking.save_download", warning_duration); UMA_HISTOGRAM_LONG_TIMES("clickjacking.save_download", warning_duration);
...@@ -452,7 +476,7 @@ void DownloadItemView::ButtonPressed(views::Button* sender, ...@@ -452,7 +476,7 @@ void DownloadItemView::ButtonPressed(views::Button* sender,
} }
if (sender == open_button_) { if (sender == open_button_) {
if (IsShowingDeepScanning()) { if (mode_ == Mode::kDeepScanning) {
content::WebContents* current_web_contents = content::WebContents* current_web_contents =
shelf_->browser()->tab_strip_model()->GetActiveWebContents(); shelf_->browser()->tab_strip_model()->GetActiveWebContents();
open_now_modal_dialog_ = TabModalConfirmDialog::Create( open_now_modal_dialog_ = TabModalConfirmDialog::Create(
...@@ -475,7 +499,7 @@ void DownloadItemView::ButtonPressed(views::Button* sender, ...@@ -475,7 +499,7 @@ void DownloadItemView::ButtonPressed(views::Button* sender,
weak_ptr_factory_.GetWeakPtr())); weak_ptr_factory_.GetWeakPtr()));
return; return;
} }
if (IsShowingWarningDialog() || IsShowingMixedContentDialog()) if (has_warning_label(mode_))
return; return;
if (complete_animation_.get() && complete_animation_->is_animating()) if (complete_animation_.get() && complete_animation_->is_animating())
complete_animation_->End(); complete_animation_->End();
...@@ -490,7 +514,7 @@ void DownloadItemView::ButtonPressed(views::Button* sender, ...@@ -490,7 +514,7 @@ void DownloadItemView::ButtonPressed(views::Button* sender,
DCHECK_EQ(discard_button_, sender); DCHECK_EQ(discard_button_, sender);
if (mode_ == MIX_DL_BLOCK_MODE || mode_ == MIX_DL_WARNING_MODE) { if (is_mixed_content(mode_)) {
DownloadCommands(model_.get()).ExecuteCommand(DownloadCommands::DISCARD); DownloadCommands(model_.get()).ExecuteCommand(DownloadCommands::DISCARD);
return; return;
} }
...@@ -520,15 +544,15 @@ void DownloadItemView::OnDownloadUpdated() { ...@@ -520,15 +544,15 @@ void DownloadItemView::OnDownloadUpdated() {
(model_->GetDangerType() == (model_->GetDangerType() ==
download::DOWNLOAD_DANGER_TYPE_ASYNC_SCANNING); download::DOWNLOAD_DANGER_TYPE_ASYNC_SCANNING);
if (model_->IsMixedContent()) { if (model_->IsMixedContent()) {
if (!IsShowingMixedContentDialog()) if (!is_mixed_content(mode_))
TransitionToMixedContentDialog(); TransitionToMixedContentDialog();
} else if (model_->IsDangerous() && } else if (model_->IsDangerous() &&
model_->GetState() != DownloadItem::CANCELLED) { model_->GetState() != DownloadItem::CANCELLED) {
if (!IsShowingWarningDialog()) if (!is_download_warning(mode_))
TransitionToWarningDialog(); TransitionToWarningDialog();
} else if (is_danger_type_async_scanning && } else if (is_danger_type_async_scanning &&
model_->GetState() != DownloadItem::CANCELLED) { model_->GetState() != DownloadItem::CANCELLED) {
if (!IsShowingDeepScanning()) if (mode_ != Mode::kDeepScanning)
TransitionToDeepScanningDialog(); TransitionToDeepScanningDialog();
} else { } else {
TransitionToNormalMode(); TransitionToNormalMode();
...@@ -597,7 +621,7 @@ gfx::Size DownloadItemView::CalculatePreferredSize() const { ...@@ -597,7 +621,7 @@ gfx::Size DownloadItemView::CalculatePreferredSize() const {
// We set the height to the height of two rows or text plus margins. // We set the height to the height of two rows or text plus margins.
int child_height = font_list_.GetHeight() + status_font_list_.GetHeight(); int child_height = font_list_.GetHeight() + status_font_list_.GetHeight();
if (IsShowingWarningDialog() || IsShowingMixedContentDialog()) { if (has_warning_label(mode_)) {
// Width. // Width.
width = kStartPadding + GetWarningIconSize() + kStartPadding + width = kStartPadding + GetWarningIconSize() + kStartPadding +
dangerous_download_label_->width() + kLabelPadding; dangerous_download_label_->width() + kLabelPadding;
...@@ -609,7 +633,7 @@ gfx::Size DownloadItemView::CalculatePreferredSize() const { ...@@ -609,7 +633,7 @@ gfx::Size DownloadItemView::CalculatePreferredSize() const {
// Height: make sure the button fits and the warning icon fits. // Height: make sure the button fits and the warning icon fits.
child_height = child_height =
std::max({child_height, button_size.height(), GetWarningIconSize()}); std::max({child_height, button_size.height(), GetWarningIconSize()});
} else if (IsShowingDeepScanning()) { } else if (mode_ == Mode::kDeepScanning) {
width = kStartPadding + GetWarningIconSize() + kStartPadding + width = kStartPadding + GetWarningIconSize() + kStartPadding +
deep_scanning_label_->width() + kLabelPadding; deep_scanning_label_->width() + kLabelPadding;
if (open_now_button_) { if (open_now_button_) {
...@@ -631,7 +655,7 @@ gfx::Size DownloadItemView::CalculatePreferredSize() const { ...@@ -631,7 +655,7 @@ gfx::Size DownloadItemView::CalculatePreferredSize() const {
status_width + kEndPadding; status_width + kEndPadding;
} }
if (mode_ != DANGEROUS_MODE) if (mode_ != Mode::kDangerous)
width += dropdown_button_->GetPreferredSize().width(); width += dropdown_button_->GetPreferredSize().width();
return gfx::Size(width, std::max(kDefaultDownloadItemHeight, return gfx::Size(width, std::max(kDefaultDownloadItemHeight,
...@@ -658,7 +682,7 @@ void DownloadItemView::OnThemeChanged() { ...@@ -658,7 +682,7 @@ void DownloadItemView::OnThemeChanged() {
} }
void DownloadItemView::OpenDownload() { void DownloadItemView::OpenDownload() {
DCHECK(!IsShowingWarningDialog()); DCHECK(!is_download_warning(mode_));
// We're interested in how long it takes users to open downloads. If they // We're interested in how long it takes users to open downloads. If they
// open downloads super quickly, we should be concerned about clickjacking. // open downloads super quickly, we should be concerned about clickjacking.
UMA_HISTOGRAM_LONG_TIMES("clickjacking.open_download", UMA_HISTOGRAM_LONG_TIMES("clickjacking.open_download",
...@@ -706,9 +730,7 @@ int DownloadItemView::GetYForFilenameText() const { ...@@ -706,9 +730,7 @@ int DownloadItemView::GetYForFilenameText() const {
void DownloadItemView::DrawIcon(gfx::Canvas* canvas) { void DownloadItemView::DrawIcon(gfx::Canvas* canvas) {
bool use_new_warnings = bool use_new_warnings =
base::FeatureList::IsEnabled(safe_browsing::kUseNewDownloadWarnings); base::FeatureList::IsEnabled(safe_browsing::kUseNewDownloadWarnings);
bool show_warning_icon = IsShowingWarningDialog() || bool show_warning_icon = mode_ != Mode::kNormal;
IsShowingMixedContentDialog() ||
IsShowingDeepScanning();
if (show_warning_icon && !use_new_warnings) { if (show_warning_icon && !use_new_warnings) {
int icon_x = int icon_x =
(base::i18n::IsRTL() ? width() - GetWarningIconSize() - kStartPadding (base::i18n::IsRTL() ? width() - GetWarningIconSize() - kStartPadding
...@@ -742,7 +764,7 @@ void DownloadItemView::DrawIcon(gfx::Canvas* canvas) { ...@@ -742,7 +764,7 @@ void DownloadItemView::DrawIcon(gfx::Canvas* canvas) {
PaintDownloadProgress(canvas, progress_bounds, progress_time, PaintDownloadProgress(canvas, progress_bounds, progress_time,
model_->PercentComplete()); model_->PercentComplete());
} else if (complete_animation_.get() && complete_animation_->is_animating()) { } else if (complete_animation_.get() && complete_animation_->is_animating()) {
DCHECK_EQ(NORMAL_MODE, mode_); DCHECK_EQ(Mode::kNormal, mode_);
// Loop back and forth five times. // Loop back and forth five times.
double start = 0, end = 5; double start = 0, end = 5;
if (model_->GetState() == download::DownloadItem::INTERRUPTED) if (model_->GetState() == download::DownloadItem::INTERRUPTED)
...@@ -883,11 +905,11 @@ void DownloadItemView::SetMode(Mode mode) { ...@@ -883,11 +905,11 @@ void DownloadItemView::SetMode(Mode mode) {
} }
void DownloadItemView::TransitionToNormalMode() { void DownloadItemView::TransitionToNormalMode() {
if (IsShowingDeepScanning()) if (mode_ == Mode::kDeepScanning)
ClearDeepScanningDialog(); ClearDeepScanningDialog();
if (IsShowingWarningDialog()) if (is_download_warning(mode_))
ClearWarningDialog(); ClearWarningDialog();
if (IsShowingMixedContentDialog()) if (is_mixed_content(mode_))
ClearMixedContentDialog(); ClearMixedContentDialog();
status_label_->SetText(GetStatusText()); status_label_->SetText(GetStatusText());
...@@ -956,9 +978,9 @@ void DownloadItemView::TransitionToNormalMode() { ...@@ -956,9 +978,9 @@ void DownloadItemView::TransitionToNormalMode() {
} }
void DownloadItemView::TransitionToMixedContentDialog() { void DownloadItemView::TransitionToMixedContentDialog() {
if (IsShowingMixedContentDialog()) if (is_mixed_content(mode_))
ClearMixedContentDialog(); ClearMixedContentDialog();
if (IsShowingDeepScanning()) if (mode_ == Mode::kDeepScanning)
ClearDeepScanningDialog(); ClearDeepScanningDialog();
ShowMixedContentDialog(); ShowMixedContentDialog();
...@@ -972,9 +994,9 @@ void DownloadItemView::TransitionToMixedContentDialog() { ...@@ -972,9 +994,9 @@ void DownloadItemView::TransitionToMixedContentDialog() {
} }
void DownloadItemView::ClearMixedContentDialog() { void DownloadItemView::ClearMixedContentDialog() {
DCHECK(IsShowingMixedContentDialog()); DCHECK(is_mixed_content(mode_));
SetMode(NORMAL_MODE); SetMode(Mode::kNormal);
dropdown_state_ = NORMAL; dropdown_state_ = NORMAL;
// Remove the views used by the mixed content dialog. // Remove the views used by the mixed content dialog.
...@@ -999,19 +1021,19 @@ void DownloadItemView::ClearMixedContentDialog() { ...@@ -999,19 +1021,19 @@ void DownloadItemView::ClearMixedContentDialog() {
void DownloadItemView::ShowMixedContentDialog() { void DownloadItemView::ShowMixedContentDialog() {
DCHECK(model_->IsMixedContent()); DCHECK(model_->IsMixedContent());
DCHECK(!IsShowingMixedContentDialog()); DCHECK(!is_mixed_content(mode_));
SetMode(model_->GetMixedContentStatus() == MixedContentStatus::WARN SetMode(model_->GetMixedContentStatus() == MixedContentStatus::WARN
? MIX_DL_WARNING_MODE ? Mode::kMixedContentWarn
: MIX_DL_BLOCK_MODE); : Mode::kMixedContentBlock);
dropdown_state_ = NORMAL; dropdown_state_ = NORMAL;
if (mode_ == MIX_DL_WARNING_MODE) { if (mode_ == Mode::kMixedContentWarn) {
auto save_button = views::MdTextButton::Create( auto save_button = views::MdTextButton::Create(
this, model_->GetWarningConfirmButtonText()); this, model_->GetWarningConfirmButtonText());
save_button_ = AddChildView(std::move(save_button)); save_button_ = AddChildView(std::move(save_button));
} else { // MIX_DL_BLOCK_MODE } else {
auto discard_button = views::MdTextButton::Create( auto discard_button = views::MdTextButton::Create(
this, l10n_util::GetStringUTF16(IDS_DISCARD_DOWNLOAD)); this, l10n_util::GetStringUTF16(IDS_DISCARD_DOWNLOAD));
discard_button_ = AddChildView(std::move(discard_button)); discard_button_ = AddChildView(std::move(discard_button));
...@@ -1037,9 +1059,9 @@ void DownloadItemView::ShowMixedContentDialog() { ...@@ -1037,9 +1059,9 @@ void DownloadItemView::ShowMixedContentDialog() {
} }
void DownloadItemView::TransitionToWarningDialog() { void DownloadItemView::TransitionToWarningDialog() {
if (IsShowingDeepScanning()) if (mode_ == Mode::kDeepScanning)
ClearDeepScanningDialog(); ClearDeepScanningDialog();
if (IsShowingWarningDialog()) if (is_download_warning(mode_))
ClearWarningDialog(); ClearWarningDialog();
ShowWarningDialog(); ShowWarningDialog();
...@@ -1053,9 +1075,9 @@ void DownloadItemView::TransitionToWarningDialog() { ...@@ -1053,9 +1075,9 @@ void DownloadItemView::TransitionToWarningDialog() {
} }
void DownloadItemView::ClearWarningDialog() { void DownloadItemView::ClearWarningDialog() {
DCHECK(IsShowingWarningDialog()); DCHECK(is_download_warning(mode_));
SetMode(NORMAL_MODE); SetMode(Mode::kNormal);
dropdown_state_ = NORMAL; dropdown_state_ = NORMAL;
// Remove the views used by the warning dialog. // Remove the views used by the warning dialog.
...@@ -1079,14 +1101,14 @@ void DownloadItemView::ClearWarningDialog() { ...@@ -1079,14 +1101,14 @@ void DownloadItemView::ClearWarningDialog() {
} }
void DownloadItemView::ShowWarningDialog() { void DownloadItemView::ShowWarningDialog() {
DCHECK(!IsShowingWarningDialog()); DCHECK(!is_download_warning(mode_));
time_download_warning_shown_ = base::Time::Now(); time_download_warning_shown_ = base::Time::Now();
download::DownloadDangerType danger_type = model_->GetDangerType(); download::DownloadDangerType danger_type = model_->GetDangerType();
RecordDangerousDownloadWarningShown(danger_type); RecordDangerousDownloadWarningShown(danger_type);
SetMode(model_->MightBeMalicious() ? MALICIOUS_MODE : DANGEROUS_MODE); SetMode(model_->MightBeMalicious() ? Mode::kMalicious : Mode::kDangerous);
dropdown_state_ = NORMAL; dropdown_state_ = NORMAL;
if (mode_ == DANGEROUS_MODE) { if (mode_ == Mode::kDangerous) {
auto save_button = views::MdTextButton::Create( auto save_button = views::MdTextButton::Create(
this, model_->GetWarningConfirmButtonText()); this, model_->GetWarningConfirmButtonText());
save_button_ = AddChildView(std::move(save_button)); save_button_ = AddChildView(std::move(save_button));
...@@ -1133,13 +1155,13 @@ void DownloadItemView::ShowWarningDialog() { ...@@ -1133,13 +1155,13 @@ void DownloadItemView::ShowWarningDialog() {
open_button_->SetEnabled(open_button_enabled); open_button_->SetEnabled(open_button_enabled);
file_name_label_->SetVisible(false); file_name_label_->SetVisible(false);
status_label_->SetVisible(false); status_label_->SetVisible(false);
dropdown_button_->SetVisible(mode_ == MALICIOUS_MODE); dropdown_button_->SetVisible(mode_ == Mode::kMalicious);
} }
void DownloadItemView::TransitionToDeepScanningDialog() { void DownloadItemView::TransitionToDeepScanningDialog() {
if (IsShowingWarningDialog()) if (is_download_warning(mode_))
ClearWarningDialog(); ClearWarningDialog();
if (IsShowingMixedContentDialog()) if (is_mixed_content(mode_))
ClearMixedContentDialog(); ClearMixedContentDialog();
ShowDeepScanningDialog(); ShowDeepScanningDialog();
...@@ -1159,9 +1181,9 @@ void DownloadItemView::TransitionToDeepScanningDialog() { ...@@ -1159,9 +1181,9 @@ void DownloadItemView::TransitionToDeepScanningDialog() {
} }
void DownloadItemView::ClearDeepScanningDialog() { void DownloadItemView::ClearDeepScanningDialog() {
DCHECK(IsShowingDeepScanning()); DCHECK_EQ(Mode::kDeepScanning, mode_);
SetMode(NORMAL_MODE); SetMode(Mode::kNormal);
dropdown_state_ = NORMAL; dropdown_state_ = NORMAL;
delete deep_scanning_label_; delete deep_scanning_label_;
...@@ -1178,8 +1200,8 @@ void DownloadItemView::ClearDeepScanningDialog() { ...@@ -1178,8 +1200,8 @@ void DownloadItemView::ClearDeepScanningDialog() {
} }
void DownloadItemView::ShowDeepScanningDialog() { void DownloadItemView::ShowDeepScanningDialog() {
DCHECK_EQ(mode_, NORMAL_MODE); DCHECK_EQ(mode_, Mode::kNormal);
SetMode(DEEP_SCANNING_MODE); SetMode(Mode::kDeepScanning);
const int id = (model_->download() && const int id = (model_->download() &&
safe_browsing::DeepScanningRequest::ShouldUploadBinary( safe_browsing::DeepScanningRequest::ShouldUploadBinary(
...@@ -1351,7 +1373,7 @@ void DownloadItemView::StopDownloadProgress() { ...@@ -1351,7 +1373,7 @@ void DownloadItemView::StopDownloadProgress() {
void DownloadItemView::UpdateAccessibleName() { void DownloadItemView::UpdateAccessibleName() {
base::string16 new_name; base::string16 new_name;
if (IsShowingWarningDialog() || IsShowingMixedContentDialog()) { if (has_warning_label(mode_)) {
new_name = dangerous_download_label_->GetText(); new_name = dangerous_download_label_->GetText();
} else { } else {
new_name = status_label_->GetText() + base::char16(' ') + new_name = status_label_->GetText() + base::char16(' ') +
...@@ -1390,8 +1412,7 @@ void DownloadItemView::UpdateAccessibleAlert( ...@@ -1390,8 +1412,7 @@ void DownloadItemView::UpdateAccessibleAlert(
base::string16 DownloadItemView::GetInProgressAccessibleAlertText() { base::string16 DownloadItemView::GetInProgressAccessibleAlertText() {
// If opening when complete or there is a warning, use the full status text. // If opening when complete or there is a warning, use the full status text.
if (model_->GetOpenWhenComplete() || IsShowingWarningDialog() || if (model_->GetOpenWhenComplete() || has_warning_label(mode_)) {
IsShowingMixedContentDialog()) {
UpdateAccessibleName(); UpdateAccessibleName();
return accessible_name_; return accessible_name_;
} }
......
...@@ -62,6 +62,8 @@ class DownloadItemView : public views::View, ...@@ -62,6 +62,8 @@ class DownloadItemView : public views::View,
public DownloadUIModel::Observer, public DownloadUIModel::Observer,
public views::AnimationDelegateViews { public views::AnimationDelegateViews {
public: public:
enum class Mode;
DownloadItemView(DownloadUIModel::DownloadUIModelPtr download, DownloadItemView(DownloadUIModel::DownloadUIModelPtr download,
DownloadShelfView* parent, DownloadShelfView* parent,
views::View* accessible_alert); views::View* accessible_alert);
...@@ -109,16 +111,6 @@ class DownloadItemView : public views::View, ...@@ -109,16 +111,6 @@ class DownloadItemView : public views::View,
private: private:
enum State { NORMAL = 0, HOT, PUSHED }; enum State { NORMAL = 0, HOT, PUSHED };
enum Mode {
NORMAL_MODE = 0, // Showing download item.
DANGEROUS_MODE, // Displaying the dangerous download warning.
MALICIOUS_MODE, // Displaying the malicious download warning.
DEEP_SCANNING_MODE, // Displaying information about in progress deep
// scanning.
MIX_DL_WARNING_MODE, // Displaying the mixed-content download warning.
MIX_DL_BLOCK_MODE, // Displaying the mixed-content download block error.
};
static constexpr int kTextWidth = 140; static constexpr int kTextWidth = 140;
// Padding before the icon and at end of the item. // Padding before the icon and at end of the item.
...@@ -166,19 +158,6 @@ class DownloadItemView : public views::View, ...@@ -166,19 +158,6 @@ class DownloadItemView : public views::View,
void SetMode(Mode mode); void SetMode(Mode mode);
// Whether we are in the dangerous mode.
bool IsShowingWarningDialog() const {
return mode_ == DANGEROUS_MODE || mode_ == MALICIOUS_MODE;
}
// Whether we are in the mixed content mode.
bool IsShowingMixedContentDialog() const {
return mode_ == MIX_DL_WARNING_MODE || mode_ == MIX_DL_BLOCK_MODE;
}
// Whether we are in the deep scanning mode.
bool IsShowingDeepScanning() const { return mode_ == DEEP_SCANNING_MODE; }
// Starts showing the normal mode dialog, clearing the existing dialog. // Starts showing the normal mode dialog, clearing the existing dialog.
void TransitionToNormalMode(); void TransitionToNormalMode();
......
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