Skip to content

[cr135 follow up] Restores download button icon change for insecure downloads. (uplift to 1.77.x) #28503

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/* Copyright (c) 2025 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/. */

#include "chrome/browser/ui/views/download/bubble/download_toolbar_ui_controller.h"

#include "chrome/browser/download/bubble/download_bubble_update_service.h"
#include "chrome/browser/download/bubble/download_bubble_update_service_factory.h"
#include "chrome/browser/download/download_ui_model.h"
#include "components/vector_icons/vector_icons.h"

#define DownloadToolbarUIController DownloadToolbarUIController_ChromiumImpl
#include "src/chrome/browser/ui/views/download/bubble/download_toolbar_ui_controller.cc"
#undef DownloadToolbarUIController

SkColor DownloadToolbarUIController_ChromiumImpl::GetIconColor(
bool is_dormant,
DownloadDisplay::IconActive active,
const ui::ColorProvider* color_provider) const {
return ::GetIconColor(is_dormant, active, color_provider);
}

SkColor DownloadToolbarUIController::GetIconColor(
bool is_dormant,
DownloadDisplay::IconActive active,
const ui::ColorProvider* color_provider) const {
// Apply active color only when download is completed and user doesn't
// interact with this button.
if (state_ == IconState::kComplete && active == IconActive::kActive) {
return color_provider->GetColor(kColorDownloadToolbarButtonActive);
}

// Otherwise, always use inactive color.
return color_provider->GetColor(kColorDownloadToolbarButtonInactive);
}

void DownloadToolbarUIController::UpdateIcon() {
DownloadToolbarUIController_ChromiumImpl::UpdateIcon();

if (!action_item_.get()) {
return;
}

auto* button = GetDownloadsButton(browser_view_);
if (!button) {
return;
}

// Use an exclamation point icon while there's an insecure download in the
// download models.
if (HasInsecureDownloads()) {
auto icon_color = browser_view_->GetColorProvider()->GetColor(
ui::kColorAlertMediumSeverityIcon);
button->SetIconEnabledColorsOverride(icon_color);
button->SetVectorIcon(vector_icons::kNotSecureWarningIcon);
const gfx::VectorIcon* new_icon = &vector_icons::kNotSecureWarningIcon;
const int icon_size = action_item_->GetImage().Size().height();
action_item_->SetImage(
ui::ImageModel::FromVectorIcon(*new_icon, icon_color, icon_size));
} else {
button->SetIconEnabledColorsOverride(std::nullopt);
}
}

bool DownloadToolbarUIController::HasInsecureDownloads() {
auto* update_service = DownloadBubbleUpdateServiceFactory::GetForProfile(
browser_view_->GetProfile());
if (!update_service || !update_service->IsInitialized()) {
return false;
}

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

return std::ranges::any_of(all_models, [](const auto& model) {
return (model->GetInsecureDownloadStatus() ==
download::DownloadItem::InsecureDownloadStatus::BLOCK ||
model->GetInsecureDownloadStatus() ==
download::DownloadItem::InsecureDownloadStatus::WARN);
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/* Copyright (c) 2025 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/. */

#ifndef BRAVE_CHROMIUM_SRC_CHROME_BROWSER_UI_VIEWS_DOWNLOAD_BUBBLE_DOWNLOAD_TOOLBAR_UI_CONTROLLER_H_
#define BRAVE_CHROMIUM_SRC_CHROME_BROWSER_UI_VIEWS_DOWNLOAD_BUBBLE_DOWNLOAD_TOOLBAR_UI_CONTROLLER_H_

#define DownloadToolbarUIController DownloadToolbarUIController_ChromiumImpl

// Apply active color only when download is completed and user doesn't
// interact with this button.
#define UpdateIconDormant \
UpdateIconDormant(); \
\
protected: \
virtual SkColor GetIconColor(bool is_dormant, \
DownloadDisplay::IconActive active, \
const ui::ColorProvider* color_provider) const; \
void UnUsed

// Override to show warning icon in the toolbar when there's an insecure
// download in progress.
#define UpdateIcon virtual UpdateIcon

#include "src/chrome/browser/ui/views/download/bubble/download_toolbar_ui_controller.h" // IWYU pragma: export
#undef UpdateIcon
#undef UpdateIconDormant
#undef DownloadToolbarUIController

class DownloadToolbarUIController
: public DownloadToolbarUIController_ChromiumImpl {
public:
using DownloadToolbarUIController_ChromiumImpl::
DownloadToolbarUIController_ChromiumImpl;

SkColor GetIconColor(bool is_dormant,
DownloadDisplay::IconActive active,
const ui::ColorProvider* color_provider) const override;

void UpdateIcon() override;

private:
bool HasInsecureDownloads();
};

#endif // BRAVE_CHROMIUM_SRC_CHROME_BROWSER_UI_VIEWS_DOWNLOAD_BUBBLE_DOWNLOAD_TOOLBAR_UI_CONTROLLER_H_
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,21 @@

#include "chrome/browser/ui/views/toolbar/pinned_action_toolbar_button.h"

#include "chrome/browser/ui/views/toolbar/pinned_toolbar_actions_container.h"
#include "chrome/browser/ui/views/toolbar/toolbar_button.h"

#define UpdateIcon UpdateIcon_ChromiumImpl
#include "src/chrome/browser/ui/views/toolbar/pinned_action_toolbar_button.cc"
#undef UpdateIcon

bool PinnedActionToolbarButton::ShouldShowMenu() {
return false;
}

void PinnedActionToolbarButton::UpdateIcon() {
if (HasIconEnabledColorsOverride() && action_engaged_) {
ToolbarButton::UpdateIcon();
return;
}
UpdateIcon_ChromiumImpl();
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,22 @@
#ifndef BRAVE_CHROMIUM_SRC_CHROME_BROWSER_UI_VIEWS_TOOLBAR_PINNED_ACTION_TOOLBAR_BUTTON_H_
#define BRAVE_CHROMIUM_SRC_CHROME_BROWSER_UI_VIEWS_TOOLBAR_PINNED_ACTION_TOOLBAR_BUTTON_H_

#include "chrome/browser/ui/views/toolbar/toolbar_button.h"

// We don't want to show context menu for pinned container buttons. For now we
// only allow downloads button and we don't want to show any customization UI
// elements yet.
#define ShouldShowEphemerallyInToolbar(...) \
ShouldShowEphemerallyInToolbar(__VA_ARGS__); \
bool ShouldShowMenu() override

// Allow ToolbarButton's color override to persist.
#define UpdateIcon \
UpdateIcon_ChromiumImpl(); \
void UpdateIcon

#include "src/chrome/browser/ui/views/toolbar/pinned_action_toolbar_button.h" // IWYU pragma: export
#undef UpdateIcon
#undef ShouldShowEphemerallyInToolbar

#endif // BRAVE_CHROMIUM_SRC_CHROME_BROWSER_UI_VIEWS_TOOLBAR_PINNED_ACTION_TOOLBAR_BUTTON_H_
21 changes: 20 additions & 1 deletion chromium_src/chrome/browser/ui/views/toolbar/toolbar_button.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
// you can obtain one at http://mozilla.org/MPL/2.0/.

#include "chrome/browser/ui/views/toolbar/toolbar_button.h"

#include <utility>

#include "brave/browser/ui/color/brave_color_id.h"
#include "chrome/browser/ui/views/toolbar/toolbar_button.h"
#include "ui/views/controls/highlight_path_generator.h"

#define ToolbarButton ToolbarButton_ChromiumImpl
Expand Down Expand Up @@ -52,7 +53,25 @@ void ToolbarButton::InkDropRippleAnimationEnded(views::InkDropState state) {
OnInkDropStateChanged(state);
}

void ToolbarButton::UpdateIcon() {
if (HasVectorIcons() && icon_enabled_colors_override_) {
UpdateIconsWithColors(
ui::TouchUiController::Get()->touch_ui() ? GetVectorTouchIcon()
: GetVectorIcon(),
*icon_enabled_colors_override_, *icon_enabled_colors_override_,
*icon_enabled_colors_override_,
GetForegroundColor(ButtonState::STATE_DISABLED));
return;
}

ToolbarButton_ChromiumImpl::UpdateIcon();
}

void ToolbarButton::OnInkDropStateChanged(views::InkDropState state) {
if (icon_enabled_colors_override_) {
return UpdateIcon();
}

// Use different color for icon when activated.
activated_ = state == views::InkDropState::ACTIVATED;

Expand Down
10 changes: 10 additions & 0 deletions chromium_src/chrome/browser/ui/views/toolbar/toolbar_button.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,17 @@ class ToolbarButton : public ToolbarButton_ChromiumImpl,
using ToolbarButton_ChromiumImpl::ToolbarButton_ChromiumImpl;
~ToolbarButton() override;

// Override icon color for non-disabled button states.
void SetIconEnabledColorsOverride(std::optional<SkColor> color) {
icon_enabled_colors_override_ = color;
}
bool HasIconEnabledColorsOverride() const {
return icon_enabled_colors_override_.has_value();
}

// ToolbarButton_ChromiumImpl overrides:
void OnThemeChanged() override;
void UpdateIcon() override;

virtual void OnInkDropStateChanged(views::InkDropState state);

Expand All @@ -47,6 +56,7 @@ class ToolbarButton : public ToolbarButton_ChromiumImpl,
void InkDropRippleAnimationEnded(views::InkDropState state) override;

bool activated_ = false;
std::optional<SkColor> icon_enabled_colors_override_;
};

#endif // BRAVE_CHROMIUM_SRC_CHROME_BROWSER_UI_VIEWS_TOOLBAR_TOOLBAR_BUTTON_H_
Loading