Skip to content

Commit

Permalink
Fixed download bubble is not displayed when download completed
Browse files Browse the repository at this point in the history
fix brave/brave-browser#30882

If we call bubble_controller()->GetMainView(), it makes every item "was_actioned".
When download completed, bubble includes un-actioned items.
But, it was all set as actioned already via GetMainView(), bubble doesn't have any
items to display. To get all items list w/o touching actioned state,
use DownloadBubbleUpdateService::GetAllModelsToDisplay().
  • Loading branch information
simonhong committed Jun 7, 2023
1 parent 287fb0a commit 231b76d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ SkColor DownloadToolbarButtonView::GetIconColor() const {

void DownloadToolbarButtonView::PaintButtonContents(gfx::Canvas* canvas) {
// Don't draw anything but alert icon when insecure download is in-progress.
if (HasInsecureDownloads(bubble_controller()->GetMainView())) {
if (HasInsecureDownloads()) {
return;
}

Expand All @@ -72,7 +72,7 @@ void DownloadToolbarButtonView::UpdateIcon() {
DownloadToolbarButtonViewChromium::UpdateIcon();

// Replace Icon when insecure download is in-progress.
if (HasInsecureDownloads(bubble_controller()->GetMainView())) {
if (HasInsecureDownloads()) {
const gfx::VectorIcon* new_icon = &vector_icons::kNotSecureWarningIcon;
SkColor icon_color =
GetColorProvider()->GetColor(ui::kColorAlertMediumSeverityIcon);
Expand All @@ -95,9 +95,17 @@ void DownloadToolbarButtonView::UpdateIcon() {
}
}

bool DownloadToolbarButtonView::HasInsecureDownloads(
const std::vector<DownloadUIModel::DownloadUIModelPtr>& models) const {
return base::ranges::any_of(models, [](const auto& model) {
bool DownloadToolbarButtonView::HasInsecureDownloads() {
auto* update_service = bubble_controller()->update_service();
if (!update_service || !update_service->IsInitialized()) {
return false;
}

std::vector<DownloadUIModel::DownloadUIModelPtr> all_models;
update_service->GetAllModelsToDisplay(all_models,
/*force_backfill_download_items=*/true);

return base::ranges::any_of(all_models, [](const auto& model) {
return (model->GetInsecureDownloadStatus() ==
download::DownloadItem::InsecureDownloadStatus::BLOCK ||
model->GetInsecureDownloadStatus() ==
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ class DownloadToolbarButtonView : public DownloadToolbarButtonViewChromium {
void UpdateIcon() override;

private:
bool HasInsecureDownloads(
const std::vector<DownloadUIModel::DownloadUIModelPtr>& models) const;
bool HasInsecureDownloads();
};

#endif // BRAVE_CHROMIUM_SRC_CHROME_BROWSER_UI_VIEWS_DOWNLOAD_BUBBLE_DOWNLOAD_TOOLBAR_BUTTON_VIEW_H_

0 comments on commit 231b76d

Please sign in to comment.