Skip to content

Commit

Permalink
Show alert icon in download button when insecure download is in-progress
Browse files Browse the repository at this point in the history
  • Loading branch information
simonhong committed Mar 31, 2023
1 parent 3c22732 commit 970c053
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@

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

#include "base/ranges/algorithm.h"
#include "brave/browser/ui/color/brave_color_id.h"
#include "components/vector_icons/vector_icons.h"
#include "ui/gfx/geometry/skia_conversions.h"

namespace gfx {
Expand Down Expand Up @@ -50,3 +52,48 @@ SkColor DownloadToolbarButtonView::GetIconColor() const {
// Otherwise, always use inactive color.
return GetColorProvider()->GetColor(kColorDownloadToolbarButtonInactive);
}

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

DownloadToolbarButtonViewChromium::PaintButtonContents(canvas);
}

void DownloadToolbarButtonView::UpdateIcon() {
if (!GetWidget()) {
return;
}

DownloadToolbarButtonViewChromium::UpdateIcon();

// Replace Icon when insecure download is in-progress.
if (HasInsecureDownloads(bubble_controller()->GetMainView())) {
const gfx::VectorIcon* new_icon = &vector_icons::kNotSecureWarningIcon;
SkColor icon_color =
GetColorProvider()->GetColor(ui::kColorAlertMediumSeverity);

SetImageModel(ButtonState::STATE_NORMAL,
ui::ImageModel::FromVectorIcon(*new_icon, icon_color));
SetImageModel(ButtonState::STATE_HOVERED,
ui::ImageModel::FromVectorIcon(*new_icon, icon_color));
SetImageModel(ButtonState::STATE_PRESSED,
ui::ImageModel::FromVectorIcon(*new_icon, icon_color));
SetImageModel(
Button::STATE_DISABLED,
ui::ImageModel::FromVectorIcon(
*new_icon, GetForegroundColor(ButtonState::STATE_DISABLED)));
}
}

bool DownloadToolbarButtonView::HasInsecureDownloads(
const std::vector<DownloadUIModelPtr>& models) const {
return base::ranges::any_of(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
Expand Up @@ -6,25 +6,26 @@
#ifndef BRAVE_CHROMIUM_SRC_CHROME_BROWSER_UI_VIEWS_DOWNLOAD_BUBBLE_DOWNLOAD_TOOLBAR_BUTTON_VIEW_H_
#define BRAVE_CHROMIUM_SRC_CHROME_BROWSER_UI_VIEWS_DOWNLOAD_BUBBLE_DOWNLOAD_TOOLBAR_BUTTON_VIEW_H_

#include "chrome/browser/download/bubble/download_bubble_controller.h"
#include "chrome/browser/download/bubble/download_display_controller.h"
#include "chrome/browser/ui/views/toolbar/toolbar_button.h"

#define DownloadToolbarButtonView DownloadToolbarButtonViewChromium
#define GetIconColor \
UnUsed() { \
return SK_ColorTRANSPARENT; \
} \
#define PaintButtonContents \
PaintButtonContents_UnUsed() {} \
\
protected: \
DownloadDisplayController::IconInfo GetIconInfo() const { \
return controller_->GetIconInfo(); \
} \
\
public: \
virtual SkColor GetIconColor
void PaintButtonContents

#define GetIconColor virtual GetIconColor

#include "src/chrome/browser/ui/views/download/bubble/download_toolbar_button_view.h" // IWYU pragma: export

#undef GetIconColor
#undef PaintButtonContents
#undef DownloadToolbarButtonView

class DownloadToolbarButtonView : public DownloadToolbarButtonViewChromium {
Expand All @@ -33,6 +34,12 @@ class DownloadToolbarButtonView : public DownloadToolbarButtonViewChromium {

// DownloadToolbarButtonViewChromium overrides:
SkColor GetIconColor() const override;
void PaintButtonContents(gfx::Canvas* canvas) override;
void UpdateIcon() override;

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

#endif // BRAVE_CHROMIUM_SRC_CHROME_BROWSER_UI_VIEWS_DOWNLOAD_BUBBLE_DOWNLOAD_TOOLBAR_BUTTON_VIEW_H_
30 changes: 30 additions & 0 deletions chromium_src/ui/color/core_default_color_mixer.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/* Copyright (c) 2023 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/. */

#define AddCoreDefaultColorMixer AddCoreDefaultColorMixer_Chromium
#include "src/ui/color/core_default_color_mixer.cc"
#undef AddCoreDefaultColorMixer

namespace ui {

void AddBraveCoreDefaultColorMixer(ColorProvider* provider,
const ColorProviderManager::Key& key) {
ColorMixer& mixer = provider->AddMixer();

const bool dark_mode =
key.color_mode == ColorProviderManager::ColorMode::kDark;

mixer[kColorAlertMediumSeverity] = {dark_mode
? SkColorSetRGB(0xBB, 0x88, 0x00)
: SkColorSetRGB(0xE2, 0xA5, 0x00)};
}

void AddCoreDefaultColorMixer(ColorProvider* provider,
const ColorProviderManager::Key& key) {
AddCoreDefaultColorMixer_Chromium(provider, key);
AddBraveCoreDefaultColorMixer(provider, key);
}

} // namespace ui
25 changes: 25 additions & 0 deletions vector_icons/components/vector_icons/not_secure_warning.icon
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright (c) 2023 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/.

CANVAS_DIMENSIONS, 16,
MOVE_TO, 9.67f, 2.97f,
R_CUBIC_TO, -0.74f, -1.29f, -2.6f, -1.29f, -3.34f, 0,
LINE_TO, 1.6f, 11.17f,
R_CUBIC_TO, -0.74f, 1.29f, 0.19f, 2.9f, 1.67f, 2.9f,
R_H_LINE_TO, 9.47f,
R_CUBIC_TO, 1.49f, 0, 2.42f, -1.61f, 1.67f, -2.89f,
LINE_TO, 9.67f, 2.97f,
CLOSE,
MOVE_TO, 8, 5.43f,
R_CUBIC_TO, 0.28f, 0, 0.51f, 0.23f, 0.51f, 0.51f,
R_V_LINE_TO, 2.56f,
R_ARC_TO, 0.51f, 0.51f, 0, 0, 1, -1.03f, 0,
V_LINE_TO, 5.95f,
R_CUBIC_TO, 0, -0.28f, 0.23f, -0.51f, 0.51f, -0.51f,
CLOSE,
R_MOVE_TO, 0.73f, 5.3f,
R_ARC_TO, 0.73f, 0.73f, 0, 1, 1, -1.47f, 0,
R_ARC_TO, 0.73f, 0.73f, 0, 0, 1, 1.47f, 0,
CLOSE

0 comments on commit 970c053

Please sign in to comment.