File: download_bubble_row_view_info.h

package info (click to toggle)
chromium 138.0.7204.183-1~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-proposed-updates
  • size: 6,080,960 kB
  • sloc: cpp: 34,937,079; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,954; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,811; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (123 lines) | stat: -rw-r--r-- 4,806 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_UI_DOWNLOAD_DOWNLOAD_BUBBLE_ROW_VIEW_INFO_H_
#define CHROME_BROWSER_UI_DOWNLOAD_DOWNLOAD_BUBBLE_ROW_VIEW_INFO_H_

#include "chrome/browser/download/download_commands.h"
#include "chrome/browser/download/download_ui_model.h"
#include "chrome/browser/ui/download/download_bubble_info.h"
#include "chrome/browser/ui/download/download_bubble_info_utils.h"
#include "chrome/browser/ui/download/download_item_mode.h"
#include "components/download/public/common/download_danger_type.h"
#include "ui/color/color_id.h"
#include "ui/gfx/vector_icon_types.h"

namespace offline_items_collection {
struct ContentId;
}  // namespace offline_items_collection

// Interface for observers of changes to a download row
class DownloadBubbleRowViewInfoObserver : public base::CheckedObserver {
 public:
  DownloadBubbleRowViewInfoObserver();
  ~DownloadBubbleRowViewInfoObserver() override;

  // Called whenever the info changes
  virtual void OnInfoChanged() {}

  // Called when the download changes state.
  virtual void OnDownloadStateChanged(
      download::DownloadItem::DownloadState old_state,
      download::DownloadItem::DownloadState new_state) {}

  // Called when the download is destroyed.
  virtual void OnDownloadDestroyed(
      const offline_items_collection::ContentId& id) {}
};

// Info class for a DownloadBubbleRowView
class DownloadBubbleRowViewInfo
    : public DownloadBubbleInfo<DownloadBubbleRowViewInfoObserver>,
      public DownloadUIModel::Delegate {
 public:
  explicit DownloadBubbleRowViewInfo(DownloadUIModel::DownloadUIModelPtr model);
  ~DownloadBubbleRowViewInfo() override;

  // Accessors
  DownloadUIModel* model() const { return model_.get(); }
  download::DownloadItemMode mode() const {
    return download::GetDesiredDownloadItemMode(model_.get());
  }
  const gfx::VectorIcon* icon_override() const { return icon_and_color_.icon; }
  ui::ColorId secondary_color() const { return icon_and_color_.color; }
  ui::ColorId secondary_text_color() const {
    return secondary_text_color_.value_or(secondary_color());
  }
  const std::vector<DownloadBubbleQuickAction>& quick_actions() const {
    return quick_actions_;
  }
  bool main_button_enabled() const { return main_button_enabled_; }
  bool has_subpage() const { return has_subpage_; }
  std::optional<DownloadCommands::Command> primary_button_command() const {
    return primary_button_command_;
  }
  bool has_progress_bar() const { return progress_bar_.is_visible; }
  bool is_progress_bar_looping() const { return progress_bar_.is_looping; }

  void SetQuickActionsForTesting(
      const std::vector<DownloadBubbleQuickAction>& actions);

 private:
  // Overrides DownloadUIModel::Delegate:
  void OnDownloadOpened() override;
  void OnDownloadUpdated() override;
  void OnDownloadDestroyed(
      const offline_items_collection::ContentId& id) override;

  // Update the current state to reflect `model_`.
  void PopulateFromModel();
  void PopulateForInProgressOrComplete();
  void PopulateForInterrupted(offline_items_collection::FailState fail_state);
  void PopulateForTailoredWarning(
      DownloadUIModel::TailoredWarningType tailored_warning_type);
  void PopulateForFileTypeWarningNoSafeBrowsing();

  void PopulateSuspiciousUiPattern();
  void PopulateDangerousUiPattern();

  // Clear all fields. This helps keep the Populate* methods focused on only
  // non-default settings.
  void Reset();

  DownloadUIModel::DownloadUIModelPtr model_;
  download::DownloadItem::DownloadState state_ =
      download::DownloadItem::IN_PROGRESS;

  // Information for displaying the row. This must all be cleared in Reset() or
  // updates will keep attributes of the previously displayed state.
  IconAndColor icon_and_color_{};

  // Color used for alert text, which may be different from |secondary_color|,
  // used for icons. If this is nullopt, |secondary_color| will be used for
  // text.
  std::optional<ui::ColorId> secondary_text_color_ = std::nullopt;
  // List of quick actions
  std::vector<DownloadBubbleQuickAction> quick_actions_;
  // Whether the main button (clicking the row itself) should be enabled. When
  // true, the main button will either:
  // - Open the subpage, if it exists
  // - Open the download, if no subpage exists
  bool main_button_enabled_ = true;
  // Whether this row has a subpage.
  bool has_subpage_ = false;
  // The command for the primary button (the button always displayed over the
  // row).
  std::optional<DownloadCommands::Command> primary_button_command_ =
      std::nullopt;

  DownloadBubbleProgressBar progress_bar_;
};

#endif  // CHROME_BROWSER_UI_DOWNLOAD_DOWNLOAD_BUBBLE_ROW_VIEW_INFO_H_