File: download_bubble_row_view.cc

package info (click to toggle)
chromium 139.0.7258.138-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,120,676 kB
  • sloc: cpp: 35,100,869; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (1024 lines) | stat: -rw-r--r-- 40,368 bytes parent folder | download | duplicates (3)
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

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

#include <string_view>
#include <utility>

#include "base/files/file_path.h"
#include "base/functional/callback.h"
#include "base/metrics/histogram_functions.h"
#include "base/strings/string_util.h"
#include "base/time/time.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/app/vector_icons/vector_icons.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/download/bubble/download_bubble_prefs.h"
#include "chrome/browser/download/bubble/download_bubble_ui_controller.h"
#include "chrome/browser/download/download_item_warning_data.h"
#include "chrome/browser/download/download_stats.h"
#include "chrome/browser/download/download_ui_model.h"
#include "chrome/browser/download/drag_download_item.h"
#include "chrome/browser/icon_manager.h"
#include "chrome/browser/profiles/profile_avatar_icon_util.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/chrome_pages.h"
#include "chrome/browser/ui/layout_constants.h"
#include "chrome/browser/ui/views/chrome_layout_provider.h"
#include "chrome/browser/ui/views/download/bubble/download_bubble_navigation_handler.h"
#include "chrome/browser/ui/views/download/bubble/download_bubble_row_list_view.h"
#include "chrome/browser/ui/views/download/download_shelf_context_menu_view.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/grit/generated_resources.h"
#include "components/download/public/common/download_item.h"
#include "components/vector_icons/vector_icons.h"
#include "ui/base/clipboard/scoped_clipboard_writer.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/l10n/time_format.h"
#include "ui/base/metadata/metadata_header_macros.h"
#include "ui/base/metadata/metadata_impl_macros.h"
#include "ui/base/mojom/menu_source_type.mojom-forward.h"
#include "ui/base/text/bytes_formatting.h"
#include "ui/color/color_id.h"
#include "ui/compositor/layer.h"
#include "ui/display/screen.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/geometry/insets.h"
#include "ui/gfx/image/image_util.h"
#include "ui/views/accessibility/view_accessibility.h"
#include "ui/views/animation/ink_drop.h"
#include "ui/views/controls/button/image_button.h"
#include "ui/views/controls/button/image_button_factory.h"
#include "ui/views/controls/button/md_text_button.h"
#include "ui/views/controls/highlight_path_generator.h"
#include "ui/views/controls/image_view.h"
#include "ui/views/controls/label.h"
#include "ui/views/controls/link_fragment.h"
#include "ui/views/controls/progress_bar.h"
#include "ui/views/controls/styled_label.h"
#include "ui/views/input_event_activation_protector.h"
#include "ui/views/layout/flex_layout.h"
#include "ui/views/layout/flex_layout_types.h"
#include "ui/views/layout/flex_layout_view.h"
#include "ui/views/layout/layout_manager.h"
#include "ui/views/layout/layout_provider.h"
#include "ui/views/layout/layout_types.h"
#include "ui/views/layout/table_layout.h"
#include "ui/views/rect_based_targeting_utils.h"
#include "ui/views/style/typography.h"
#include "ui/views/style/typography_provider.h"
#include "ui/views/vector_icons.h"
#include "ui/views/view_class_properties.h"
#include "ui/views/view_targeter.h"
#include "ui/views/widget/root_view.h"
#include "ui/views/widget/widget.h"

#if BUILDFLAG(IS_CHROMEOS)
#include "base/notreached.h"
#endif

namespace {

ui::ImageModel GetDefaultIcon() {
  return ui::ImageModel::FromVectorIcon(
      vector_icons::kInsertDriveFileOutlineIcon, ui::kColorIcon,
      GetLayoutConstant(DOWNLOAD_ICON_SIZE));
}

gfx::Image GetDefaultIconImage(const ui::ColorProvider* color_provider) {
  return gfx::Image(GetDefaultIcon().Rasterize(color_provider));
}

constexpr int kDownloadButtonHeight = 24;
constexpr int kDownloadSubpageIconMargin = 2;
// Padding between elements in the row (except icon and label).
constexpr gfx::Insets kRowInterElementPadding = gfx::Insets::TLBR(0, 8, 0, 0);
constexpr int kProgressBarHeight = 3;
// Num of columns in the table layout, the width of which progress bar will
// span. The 5 columns are Download Icon, Padding, Status text,
// Main Button, Subpage Icon.
constexpr int kNumColumns = 5;

// A stub subclass of Button that has no visuals.
class DownloadBubbleTransparentButton : public views::Button {
  METADATA_HEADER(DownloadBubbleTransparentButton, views::Button)

 public:
  explicit DownloadBubbleTransparentButton(PressedCallback callback,
                                           DownloadBubbleRowView* row_view)
      : Button(std::move(callback)), row_view_(row_view) {
    views::InkDrop::Get(this)->SetMode(views::InkDropHost::InkDropMode::OFF);
    SetInstallFocusRingOnFocus(false);
    SetFocusBehavior(views::View::FocusBehavior::ALWAYS);
  }
  ~DownloadBubbleTransparentButton() override = default;

  // Forward dragging and capture loss events, since this class doesn't have
  // enough context to handle them. Let the `DownloadBubbleRowView` manage
  // visual transitions.
  bool OnMouseDragged(const ui::MouseEvent& event) override {
    Button::OnMouseDragged(event);
    return parent()->OnMouseDragged(event);
  }

  void OnMouseCaptureLost() override {
    parent()->OnMouseCaptureLost();
    Button::OnMouseCaptureLost();
  }

  void AboutToRequestFocusFromTabTraversal(bool reverse) override {
    if (reverse) {
      row_view_->UpdateRowForFocus(
          /*visible=*/true, /*request_focus_on_last_quick_action=*/true);
    }
  }

  void NotifyClickForTesting(const ui::Event& event) { NotifyClick(event); }

 private:
  raw_ptr<DownloadBubbleRowView> row_view_;
};

BEGIN_METADATA(DownloadBubbleTransparentButton)
END_METADATA

}  // namespace

void DownloadBubbleRowView::UpdateRow(bool initial_setup) {
  RecordMetricsOnUpdate();
  SetIcon();
  UpdateButtons();
  RecordDownloadDisplayed();
  UpdateLabels();
  UpdateProgressBar();
  if (!update_status_text_timer_.IsRunning()) {
    update_status_text_timer_.Reset();
  }
}

void DownloadBubbleRowView::AddedToWidget() {
  current_scale_ =
      display::Screen::GetScreen()
          ->GetPreferredScaleFactorForView(GetWidget()->GetNativeView())
          .value_or(1.0);
  SetIcon();
  auto* focus_manager = GetFocusManager();
  if (focus_manager) {
    focus_manager->AddFocusChangeListener(this);
    RegisterAccelerators(focus_manager);
  }
}

void DownloadBubbleRowView::RemovedFromWidget() {
  auto* focus_manager = GetFocusManager();
  if (focus_manager) {
    focus_manager->RemoveFocusChangeListener(this);
    UnregisterAccelerators(focus_manager);
  }
}

void DownloadBubbleRowView::OnDeviceScaleFactorChanged(
    float old_device_scale_factor,
    float new_device_scale_factor) {
  current_scale_ = new_device_scale_factor;
  SetIcon();
}

void DownloadBubbleRowView::SetIconFromImageModel(const ui::ImageModel& icon) {
  if (icon.IsEmpty()) {
    icon_->SetImage(GetDefaultIcon());
  } else {
    icon_->SetImage(icon);
  }
}

void DownloadBubbleRowView::SetIconFromImage(gfx::Image icon) {
  SetIconFromImageModel(ui::ImageModel::FromImage(icon));
}

bool DownloadBubbleRowView::StartLoadFileIcon() {
  base::FilePath file_path = info_->model()->GetTargetFilePath();
  // Use a default icon (drive file outline icon) in case we have an empty
  // target path, which is empty for non download offline items, and newly
  // started in-progress downloads.
  if (file_path.empty()) {
    file_icon_ = GetDefaultIconImage(GetColorProvider());
    SetFileIconAsIcon(/*is_default_icon=*/true);
    return true;
  }

  const IconLoader::IconSize icon_loader_size = IconLoader::NORMAL;
  // IconLoader::SMALL returns 16x16 icon and IconLoader::NORMAL returns 20x20
  // icon.
  IconManager* const im = g_browser_process->icon_manager();
  // Can be null in tests.
  if (!im) {
    return false;
  }
  const gfx::Image* const image =
      im->LookupIconFromFilepath(file_path, icon_loader_size, current_scale_);
  if (image && !image->IsEmpty()) {
    OnFileIconLoaded(*image);
    return true;
  }
#if BUILDFLAG(IS_CHROMEOS)
  // On ChromeOS the LookupIconFromFilepath() call should always succeed.
  NOTREACHED();
#else
  im->LoadIcon(file_path, icon_loader_size, current_scale_,
               base::BindOnce(&DownloadBubbleRowView::OnFileIconLoaded,
                              weak_factory_.GetWeakPtr()),
               &cancelable_task_tracker_);
  return false;
#endif
}

void DownloadBubbleRowView::OnFileIconLoaded(gfx::Image icon) {
  const int icon_size = GetLayoutConstant(DOWNLOAD_ICON_SIZE);
  file_icon_ = ResizedImage(
      icon.IsEmpty() ? GetDefaultIconImage(GetColorProvider()) : icon,
      {icon_size, icon_size});
  // Don't overwrite an override icon from the most recent invocation of
  // SetIcon.
  if (last_overridden_icon_) {
    return;
  }
  SetFileIconAsIcon(/*is_default_icon=*/icon.IsEmpty());
}

void DownloadBubbleRowView::SetFileIconAsIcon(bool is_default_icon) {
  DCHECK(!file_icon_.IsEmpty());
  has_default_icon_ = is_default_icon;
  SetIconFromImage(file_icon_);
}

void DownloadBubbleRowView::SetIcon() {
  // The correct scale_factor is set only in the AddedToWidget()
  if (!GetWidget()) {
    return;
  }

  // Load the file icon unconditionally because it is used for drag-and-drop,
  // even if it is not used as the |icon_|. If this returns true, it set the
  // |icon_| to a |file_icon_|, which may be a filetype icon or a default icon.
  // But if there is an override, it will be re-set below.
  bool file_type_icon_set = StartLoadFileIcon();

  if (info_->icon_override()) {
    last_overridden_icon_ = info_->icon_override();
    has_default_icon_ = false;
    SetIconFromImageModel(ui::ImageModel::FromVectorIcon(
        *info_->icon_override(), info_->secondary_color(),
        GetLayoutConstant(DOWNLOAD_ICON_SIZE)));
    return;
  }

  // For downloads in incognito mode.
  if (info_->model()->profile() &&
      info_->model()->profile()->IsIncognitoProfile()) {
    if (last_overridden_icon_ == &kIncognitoIcon) {
      return;
    }
    last_overridden_icon_ = &kIncognitoIcon;
    has_default_icon_ = false;
    SetIconFromImageModel(ui::ImageModel::FromVectorIcon(
        kIncognitoIcon, ui::kColorIcon, GetLayoutConstant(DOWNLOAD_ICON_SIZE)));
    return;
  }

  // For downloads in guest sessions.
  if (info_->model()->profile() &&
      info_->model()->profile()->IsGuestSession()) {
    if (last_overridden_icon_ == &kUserAccountAvatarIcon) {
      return;
    }
    last_overridden_icon_ = &kUserAccountAvatarIcon;
    has_default_icon_ = false;
    SetIconFromImageModel(
        profiles::GetGuestAvatar(GetLayoutConstant(DOWNLOAD_ICON_SIZE)));
    return;
  }

  last_overridden_icon_ = nullptr;

  if (file_type_icon_set || has_default_icon_) {
    return;
  }
  has_default_icon_ = true;
  // Set the default icon. This may be overwritten with the filetype icon when
  // the IconManager returns a real filetype icon from its lookup.
  SetIconFromImageModel(GetDefaultIcon());
}

DownloadBubbleRowView::~DownloadBubbleRowView() {
  // Explicit removal of InkDrop for classes that override
  // Add/RemoveLayerFromRegions(). This is done so that the InkDrop doesn't
  // access the non-override versions in ~View.
  views::InkDrop::Remove(this);
  info_->RemoveObserver(this);
}

DownloadBubbleRowView::DownloadBubbleRowView(
    const DownloadBubbleRowViewInfo& info,
    base::WeakPtr<DownloadBubbleUIController> bubble_controller,
    base::WeakPtr<DownloadBubbleNavigationHandler> navigation_handler,
    base::WeakPtr<Browser> browser,
    int fixed_width)
    : info_(info),
      context_menu_(std::make_unique<DownloadShelfContextMenuView>(
          info_->model()->GetWeakPtr(),
          bubble_controller)),
      bubble_controller_(std::move(bubble_controller)),
      navigation_handler_(std::move(navigation_handler)),
      browser_(std::move(browser)),
      inkdrop_container_(
          AddChildView(std::make_unique<views::InkDropContainerView>())),
      update_status_text_timer_(
          FROM_HERE,
          base::Minutes(1),
          base::BindRepeating(&DownloadBubbleRowView::UpdateStatusText,
                              base::Unretained(this))),
      input_protector_(
          std::make_unique<views::InputEventActivationProtector>()),
      fixed_width_(fixed_width) {
  CHECK(info_->model());
  info_->AddObserver(this);
  SetBorder(views::CreateEmptyBorder(GetLayoutInsets(DOWNLOAD_ROW)));

  views::InkDrop::Install(this, std::make_unique<views::InkDropHost>(this));
  views::InstallRectHighlightPathGenerator(this);
  views::InkDrop::Get(this)->SetMode(views::InkDropHost::InkDropMode::ON);
  views::InkDrop::UseInkDropForFloodFillRipple(views::InkDrop::Get(this),
                                               /*highlight_on_hover=*/true,
                                               /*highlight_on_focus=*/true);
  views::InkDrop::Get(this)->SetBaseColorId(kColorDownloadBubbleRowHover);
  views::InkDrop::Get(this)->SetHighlightOpacity(1.0f);

  const int icon_label_spacing = ChromeLayoutProvider::Get()->GetDistanceMetric(
      views::DISTANCE_RELATED_LABEL_HORIZONTAL);

  SetLayoutManager(std::make_unique<views::TableLayout>())
      // Download Icon
      ->AddColumn(views::LayoutAlignment::kCenter,
                  views::LayoutAlignment::kStart,
                  views::TableLayout::kFixedSize,
                  views::TableLayout::ColumnSize::kUsePreferred, 0, 0)
      // Download name label (primary_label_)
      .AddPaddingColumn(views::TableLayout::kFixedSize, icon_label_spacing)
      .AddColumn(views::LayoutAlignment::kStart,
                 views::LayoutAlignment::kCenter, 1.0f,
                 views::TableLayout::ColumnSize::kUsePreferred, 0, 0)
      // Download Buttons: Cancel, Discard, Scan, Open Now, only one may be
      // active
      .AddColumn(views::LayoutAlignment::kCenter,
                 views::LayoutAlignment::kStart, views::TableLayout::kFixedSize,
                 views::TableLayout::ColumnSize::kUsePreferred, 0, 0)
      // Subpage icon
      .AddColumn(views::LayoutAlignment::kCenter,
                 views::LayoutAlignment::kStart, views::TableLayout::kFixedSize,
                 views::TableLayout::ColumnSize::kUsePreferred, 0, 0)
      // Three rows, one for name, one for status, one for the progress bar.
      .AddRows(3, 1.0f);

  inkdrop_container_->SetProperty(views::kViewIgnoredByLayoutKey, true);

  transparent_button_ =
      AddChildView(std::make_unique<DownloadBubbleTransparentButton>(
          base::BindRepeating(&DownloadBubbleRowView::OnMainButtonPressed,
                              base::Unretained(this)),
          this));
  transparent_button_->set_context_menu_controller(this);
  transparent_button_->SetTriggerableEventFlags(ui::EF_LEFT_MOUSE_BUTTON);
  transparent_button_->SetProperty(views::kViewIgnoredByLayoutKey, true);

  icon_ = AddChildView(std::make_unique<views::ImageView>());
  icon_->SetCanProcessEventsWithinSubtree(false);
  icon_->SetBorder(views::CreateEmptyBorder(GetLayoutInsets(DOWNLOAD_ICON)));
  // Make sure the icon is above the inkdrops.
  icon_->SetPaintToLayer();
  icon_->layer()->SetFillsBoundsOpaquely(false);
  icon_->SetProperty(views::kTableColAndRowSpanKey, gfx::Size(1, 2));
  const int icon_size = GetLayoutConstant(DOWNLOAD_ICON_SIZE);
  icon_->SetImageSize({icon_size, icon_size});

  primary_label_ = AddChildView(std::make_unique<views::Label>(
      info_->model()->GetFileNameToReportUser().LossyDisplayName(),
      views::style::CONTEXT_DIALOG_BODY_TEXT, views::style::STYLE_PRIMARY));
  primary_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
  primary_label_->SetCanProcessEventsWithinSubtree(false);
  primary_label_->SetMultiLine(true);
  primary_label_->SetAllowCharacterBreak(true);
  primary_label_->SetTextStyle(views::style::STYLE_BODY_3_MEDIUM);

  main_button_holder_ = AddChildView(std::make_unique<views::FlexLayoutView>());
  AddMainPageButton(DownloadCommands::CANCEL,
                    l10n_util::GetStringUTF16(IDS_DOWNLOAD_LINK_CANCEL));
  AddMainPageButton(DownloadCommands::DISCARD,
                    l10n_util::GetStringUTF16(IDS_DOWNLOAD_BUBBLE_DELETE));
  AddMainPageButton(DownloadCommands::KEEP,
                    l10n_util::GetStringUTF16(IDS_CONFIRM_DOWNLOAD));
  AddMainPageButton(DownloadCommands::DEEP_SCAN,
                    l10n_util::GetStringUTF16(IDS_DOWNLOAD_BUBBLE_SCAN));
  AddMainPageButton(DownloadCommands::BYPASS_DEEP_SCANNING_AND_OPEN,
                    l10n_util::GetStringUTF16(IDS_DOWNLOAD_BUBBLE_OPEN_NOW));
  AddMainPageButton(DownloadCommands::RESUME,
                    l10n_util::GetStringUTF16(IDS_DOWNLOAD_BUBBLE_RESUME));
  AddMainPageButton(DownloadCommands::REVIEW,
                    l10n_util::GetStringUTF16(IDS_DOWNLOAD_BUBBLE_REVIEW));
  AddMainPageButton(DownloadCommands::RETRY,
                    l10n_util::GetStringUTF16(IDS_DOWNLOAD_BUBBLE_RETRY));
  AddMainPageButton(DownloadCommands::OPEN_WHEN_COMPLETE,
                    l10n_util::GetStringUTF16(IDS_DOWNLOAD_BUBBLE_OPEN_ANYWAY));

  // Note that the addition order of these quick actions matches the visible
  // order, i.e. buttons added first will appear first (left in LTR)
  quick_action_holder_ =
      AddChildView(std::make_unique<views::FlexLayoutView>());
  // All the quick action buttons are added as children. Later on, only the ones
  // that are enabled will be made visible in UpdateButtons().
  AddQuickAction(DownloadCommands::RESUME);
  AddQuickAction(DownloadCommands::PAUSE);
  AddQuickAction(DownloadCommands::SHOW_IN_FOLDER);
  AddQuickAction(DownloadCommands::CANCEL);
  AddQuickAction(DownloadCommands::OPEN_WHEN_COMPLETE);
  quick_action_holder_->SetVisible(false);
  quick_action_holder_->SetProperty(views::kViewIgnoredByLayoutKey, true);
  quick_action_holder_->SetBackground(
      views::CreateSolidBackground(ui::kColorDialogBackground));

  subpage_icon_holder_ =
      AddChildView(std::make_unique<views::FlexLayoutView>());
  subpage_icon_holder_->SetCanProcessEventsWithinSubtree(false);
  subpage_icon_ =
      subpage_icon_holder_->AddChildView(std::make_unique<views::ImageView>());
  subpage_icon_->SetImage(ui::ImageModel::FromVectorIcon(
      vector_icons::kSubmenuArrowIcon, ui::kColorIcon));
  subpage_icon_->SetProperty(
      views::kMarginsKey,
      gfx::Insets(kDownloadSubpageIconMargin) + kRowInterElementPadding);
  subpage_icon_->SetVisible(false);
  subpage_icon_->SetImage(ui::ImageModel::FromVectorIcon(
      kChevronRightChromeRefreshIcon, ui::kColorIcon,
      GetLayoutConstant(DOWNLOAD_ICON_SIZE)));

  // The content of the label will be populated in the `UpdateRow` function.
  secondary_label_ = AddChildView(std::make_unique<views::Label>(
      u"", views::style::CONTEXT_LABEL, views::style::STYLE_SECONDARY));
  secondary_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
  // The 2 columns being removed are icon, and padding.
  secondary_label_->SetProperty(views::kTableColAndRowSpanKey,
                                gfx::Size(kNumColumns - 2, 1));
  secondary_label_->SetCanProcessEventsWithinSubtree(false);
  secondary_label_->SetMultiLine(true);
  secondary_label_->SetAllowCharacterBreak(true);
  secondary_label_->SetTextStyle(views::style::STYLE_BODY_5);

  // TODO(crbug.com/40875578): Remove the progress bar holder view here.
  // Currently the animation does not show up on deep scanning without
  // the holder.
  progress_bar_holder_ =
      AddChildView(std::make_unique<views::FlexLayoutView>());
  progress_bar_holder_->SetCanProcessEventsWithinSubtree(false);
  progress_bar_holder_->SetProperty(views::kTableColAndRowSpanKey,
                                    gfx::Size(kNumColumns, 1));
  progress_bar_holder_->SetProperty(views::kTableHorizAlignKey,
                                    views::LayoutAlignment::kStretch);
  progress_bar_ = progress_bar_holder_->AddChildView(
      std::make_unique<views::ProgressBar>());
  progress_bar_->SetPreferredHeight(kProgressBarHeight);
  progress_bar_->SetBorder(views::CreateEmptyBorder(
      gfx::Insets::TLBR(ChromeLayoutProvider::Get()->GetDistanceMetric(
                            views::DISTANCE_RELATED_CONTROL_VERTICAL),
                        0, 0, 0)));
  progress_bar_->SetProperty(
      views::kFlexBehaviorKey,
      views::FlexSpecification(views::MinimumFlexSizeRule::kScaleToMinimum,
                               views::MaximumFlexSizeRule::kUnbounded,
                               /*adjust_height_for_width=*/false));
  // Expect to start not visible, will be updated later.
  progress_bar_->SetVisible(false);

  SetNotifyEnterExitOnChild(true);

  // Set up initial state.
  UpdateRow(/*initial_setup=*/true);
}

views::View::Views DownloadBubbleRowView::GetChildrenInZOrder() {
  auto children = views::View::GetChildrenInZOrder();
  const auto move_child_to_top = [&](View* child) {
    auto it = std::ranges::find(children, child);
    CHECK(it != children.end());
    std::rotate(it, it + 1, children.end());
  };
  move_child_to_top(transparent_button_);
  move_child_to_top(quick_action_holder_);
  move_child_to_top(main_button_holder_);
  return children;
}

bool DownloadBubbleRowView::OnMouseDragged(const ui::MouseEvent& event) {
  // Handle drag (file copy) operations.
  // Drag and drop should only be activated in normal mode.
  if (info_->mode() != download::DownloadItemMode::kNormal) {
    return true;
  }

  if (!drag_start_point_) {
    drag_start_point_ = event.location();
  }
  if (!dragging_) {
    dragging_ = ExceededDragThreshold(event.location() - *drag_start_point_);
  } else if ((info_->model()->GetState() == download::DownloadItem::COMPLETE) &&
             info_->model()->GetDownloadItem()) {
    const views::Widget* const widget = GetWidget();
    // In most cases we should either have a |file_icon_| already synchronously
    // or the asynchronous lookup should have finished, but in case it hasn't,
    // ensure that we have a nonempty icon to drag.
    if (file_icon_.IsEmpty()) {
      file_icon_ = GetDefaultIconImage(GetColorProvider());
    }
    // Make this a local to avoid UAF if `this` is deleted during dragging.
    std::unique_ptr<DownloadBubbleNavigationHandler::CloseOnDeactivatePin>
        download_dragging_pin;
    if (navigation_handler_) {
      download_dragging_pin =
          navigation_handler_->PreventDialogCloseOnDeactivate();
    }
    DragDownloadItem(info_->model()->GetDownloadItem(), &file_icon_,
                     widget ? widget->GetNativeView() : gfx::NativeView());
    // DragDownloadItem returns when the drag is over.
    // `this` may be deleted by now!
  }
  return true;
}

void DownloadBubbleRowView::OnMouseEntered(const ui::MouseEvent& event) {
  View::OnMouseEntered(event);
  UpdateRowForHover(/*hovered=*/true);
}

void DownloadBubbleRowView::OnMouseExited(const ui::MouseEvent& event) {
  View::OnMouseExited(event);
  UpdateRowForHover(/*hovered=*/false);
}

void DownloadBubbleRowView::OnMouseCaptureLost() {
  // Drag and drop should only be activated in normal mode.
  if (info_->mode() != download::DownloadItemMode::kNormal) {
    return;
  }

  if (dragging_) {
    // Starting a drag results in a MouseCaptureLost.
    dragging_ = false;
    drag_start_point_.reset();
  }
}

gfx::Size DownloadBubbleRowView::CalculatePreferredSize(
    const views::SizeBounds& /*available_size*/) const {
  return {fixed_width_,
          GetLayoutManager()->GetPreferredHeightForWidth(this, fixed_width_)};
}

void DownloadBubbleRowView::AddLayerToRegion(ui::Layer* layer,
                                             views::LayerRegion region) {
  inkdrop_container_->AddLayerToRegion(layer, region);
}

void DownloadBubbleRowView::RemoveLayerFromRegions(ui::Layer* layer) {
  inkdrop_container_->RemoveLayerFromRegions(layer);
}

void DownloadBubbleRowView::VisibilityChanged(views::View* starting_from,
                                              bool is_visible) {
  views::View::VisibilityChanged(starting_from, is_visible);
  input_protector_->VisibilityChanged(is_visible);
}

void DownloadBubbleRowView::OnWillChangeFocus(views::View* before,
                                              views::View* now) {
  if (now) {
    UpdateRowForFocus(/*visible=*/Contains(now),
                      /*request_focus_on_last_quick_action=*/false);
  }
}

void DownloadBubbleRowView::UpdateRowForHover(bool hovered) {
  quick_action_holder_->SetVisible(hovered);
}

void DownloadBubbleRowView::UpdateRowForFocus(
    bool visible,
    bool request_focus_on_last_quick_action) {
  quick_action_holder_->SetVisible(visible);
  views::InkDrop::Get(this)->GetInkDrop()->SetFocused(visible);
  // Update focus only if focus received from a different row.
  bool should_set_focus = request_focus_on_last_quick_action &&
                          GetFocusManager() &&
                          !Contains(GetFocusManager()->GetFocusedView());
  if (should_set_focus && !info_->quick_actions().empty()) {
    quick_actions_[info_->quick_actions().back().command]->RequestFocus();
  }
}

void DownloadBubbleRowView::Layout(PassKey) {
  LayoutSuperclass<views::View>(this);
  transparent_button_->SetBoundsRect(GetLocalBounds());
  gfx::Size quick_actions_size = quick_action_holder_->GetPreferredSize();
  gfx::Insets insets = GetLayoutInsets(DOWNLOAD_ROW);
  quick_action_holder_->SetBoundsRect(
      gfx::Rect(gfx::Point(GetLocalBounds().width() -
                               quick_actions_size.width() - insets.right(),
                           insets.top()),
                quick_actions_size));
  inkdrop_container_->SetBoundsRect(GetLocalBounds());
}

void DownloadBubbleRowView::OnMainButtonPressed(const ui::Event& event) {
  if (!bubble_controller_ || !navigation_handler_ ||
      !info_->main_button_enabled() || !info_->model()) {
    return;
  }
  if (input_protector_->IsPossiblyUnintendedInteraction(
          event, /*allow_key_events=*/true)) {
    return;
  }
  if (info_->has_subpage()) {
    DownloadItemWarningData::AddWarningActionEvent(
        info_->model()->GetDownloadItem(),
        DownloadItemWarningData::WarningSurface::BUBBLE_MAINPAGE,
        DownloadItemWarningData::WarningAction::OPEN_SUBPAGE);
    navigation_handler_->OpenSecurityDialog(info_->model()->GetContentId());
  } else {
    info_->model()->OpenDownload();
  }
}

void DownloadBubbleRowView::OnActionButtonPressed(
    DownloadCommands::Command command,
    const ui::Event& event) {
  if (!bubble_controller_ || !info_->model() ||
      input_protector_->IsPossiblyUnintendedInteraction(
          event, /*allow_key_events=*/true)) {
    return;
  }
  bubble_controller_->ProcessDownloadButtonPress(info_->model()->GetWeakPtr(),
                                                 command,
                                                 /*is_main_view=*/true);
}

void DownloadBubbleRowView::UpdateButtons() {
  // Things like focus and tooltips are broken if we make an action
  // button invisible, then visible. Instead, keep track of which action
  // buttons should be made invisible so we only change visibility once.
  base::flat_map<DownloadCommands::Command, raw_ptr<views::ImageButton>>
      buttons_to_remove = quick_actions_;
  for (const auto& action : info_->quick_actions()) {
    if (!DownloadCommands(info_->model()->GetWeakPtr())
             .IsCommandEnabled(action.command)) {
      continue;
    }
    views::ImageButton* action_button = quick_actions_[action.command];
    action_button->SetImageModel(
        views::Button::STATE_NORMAL,
        ui::ImageModel::FromVectorIcon(*(action.icon), ui::kColorIcon,
                                       GetLayoutConstant(DOWNLOAD_ICON_SIZE)));
    action_button->GetViewAccessibility().SetName(
        GetAccessibleNameForQuickAction(action.command));
    action_button->SetTooltipText(action.hover_text);
    action_button->SetVisible(true);
    buttons_to_remove.erase(action.command);
  }

  for (const auto& pair : buttons_to_remove) {
    pair.second->SetVisible(false);
  }

  for (const auto& [command, button] : main_page_buttons_) {
    button->SetVisible(false);
  }

  if (info_->primary_button_command()) {
    views::MdTextButton* main_button =
        main_page_buttons_[*info_->primary_button_command()];
    main_button->GetViewAccessibility().SetName(
        GetAccessibleNameForMainPageButton(
            info_->primary_button_command().value()));
    main_button->SetVisible(true);
  }

  subpage_icon_->SetVisible(info_->has_subpage());
}

void DownloadBubbleRowView::UpdateProgressBar() {
  if (!navigation_handler_) {
    return;
  }
  if (info_->has_progress_bar()) {
    if (!progress_bar_->GetVisible()) {
      progress_bar_->SetVisible(true);
    }
    progress_bar_->SetValue(
        info_->is_progress_bar_looping()
            ? -1
            : static_cast<double>(info_->model()->PercentComplete()) / 100);
    progress_bar_->SetPaused(info_->model()->IsPaused());
  } else if (progress_bar_->GetVisible()) {
    // Hide the progress bar.
    progress_bar_->SetVisible(false);
  }
}

void DownloadBubbleRowView::UpdateLabels() {
  primary_label_->SetText(
      info_->model()->GetFileNameToReportUser().LossyDisplayName());
  UpdateStatusText();

  if (info_->has_subpage()) {
    transparent_button_->GetViewAccessibility().SetName(
        l10n_util::GetStringFUTF16(
            IDS_DOWNLOAD_BUBBLE_MAIN_BUTTON_SUBPAGE,
            std::u16string(primary_label_->GetText()),
            std::u16string(secondary_label_->GetText())));
  } else {
    transparent_button_->GetViewAccessibility().SetName(base::JoinString(
        {primary_label_->GetText(), secondary_label_->GetText()}, u" "));
  }

  secondary_label_->SetEnabledColor(info_->secondary_text_color());
}

void DownloadBubbleRowView::RecordMetricsOnUpdate() {
  // This should only be logged once per download.
  MaybeRecordDangerousDownloadWarningShown(*info_->model());
  if (!has_download_completion_been_logged_ &&
      info_->model()->GetState() == download::DownloadItem::COMPLETE) {
    has_download_completion_been_logged_ = true;
  }
}

void DownloadBubbleRowView::RecordDownloadDisplayed() {
  if (info_->model()->IsDangerous()) {
    DownloadItemWarningData::AddWarningActionEvent(
        info_->model()->GetDownloadItem(),
        DownloadItemWarningData::WarningSurface::BUBBLE_MAINPAGE,
        DownloadItemWarningData::WarningAction::SHOWN);
  }
  if (!info_->model()->GetEphemeralWarningUiShownTime().has_value() &&
      info_->model()->IsEphemeralWarning()) {
    info_->model()->SetEphemeralWarningUiShownTime(base::Time::Now());
    if (bubble_controller_) {
      bubble_controller_->ScheduleCancelForEphemeralWarning(
          info_->model()->GetDownloadItem()->GetGuid());
    }
  }
}

void DownloadBubbleRowView::AddMainPageButton(
    DownloadCommands::Command command,
    const std::u16string& button_string) {
  // Unretained is safe because this owns and outlives the main page button.
  views::MdTextButton* button =
      main_button_holder_->AddChildView(std::make_unique<views::MdTextButton>(
          base::BindRepeating(&DownloadBubbleRowView::OnActionButtonPressed,
                              base::Unretained(this), command),
          button_string));
  button->SetMaxSize(gfx::Size(0, kDownloadButtonHeight));
  button->SetProperty(views::kMarginsKey, kRowInterElementPadding);
  button->SetVisible(false);
  button->SetStyle(ui::ButtonStyle::kText);

  main_page_buttons_[command] = button;
}

void DownloadBubbleRowView::AddQuickAction(DownloadCommands::Command command) {
  // Unretained is safe because this owns and outlives the quick action button.
  views::ImageButton* quick_action =
      quick_action_holder_->AddChildView(views::CreateVectorImageButton(
          base::BindRepeating(&DownloadBubbleRowView::OnActionButtonPressed,
                              base::Unretained(this), command)));
  InstallCircleHighlightPathGenerator(quick_action);
  quick_action->SetBorder(
      views::CreateEmptyBorder(GetLayoutInsets(DOWNLOAD_ICON)));
  quick_action->SetProperty(views::kMarginsKey, kRowInterElementPadding);
  quick_action->SetVisible(false);
  views::InkDrop::Get(quick_action)
      ->SetBaseColorId(views::TypographyProvider::Get().GetColorId(
          views::style::CONTEXT_BUTTON, views::style::STYLE_SECONDARY));
  quick_actions_[command] = quick_action;
}

std::u16string DownloadBubbleRowView::GetAccessibleNameForQuickAction(
    DownloadCommands::Command command) {
  switch (command) {
    case DownloadCommands::RESUME:
      return l10n_util::GetStringFUTF16(
          IDS_DOWNLOAD_BUBBLE_RESUME_QUICK_ACTION_ACCESSIBILITY,
          info_->model()->GetFileNameToReportUser().LossyDisplayName());
    case DownloadCommands::PAUSE:
      return l10n_util::GetStringFUTF16(
          IDS_DOWNLOAD_BUBBLE_PAUSE_QUICK_ACTION_ACCESSIBILITY,
          info_->model()->GetFileNameToReportUser().LossyDisplayName());
    case DownloadCommands::OPEN_WHEN_COMPLETE:
      return l10n_util::GetStringFUTF16(
          IDS_DOWNLOAD_BUBBLE_OPEN_QUICK_ACTION_ACCESSIBILITY,
          info_->model()->GetFileNameToReportUser().LossyDisplayName());
    case DownloadCommands::CANCEL:
      return l10n_util::GetStringFUTF16(
          IDS_DOWNLOAD_BUBBLE_CANCEL_QUICK_ACTION_ACCESSIBILITY,
          info_->model()->GetFileNameToReportUser().LossyDisplayName());
    case DownloadCommands::SHOW_IN_FOLDER:
      return l10n_util::GetStringFUTF16(
          IDS_DOWNLOAD_BUBBLE_SHOW_IN_FOLDER_QUICK_ACTION_ACCESSIBILITY,
          info_->model()->GetFileNameToReportUser().LossyDisplayName());
    default:
      NOTREACHED();
  }
}

std::u16string DownloadBubbleRowView::GetAccessibleNameForMainPageButton(
    DownloadCommands::Command command) {
  switch (command) {
    case DownloadCommands::CANCEL:
      return l10n_util::GetStringFUTF16(
          IDS_DOWNLOAD_BUBBLE_CANCEL_MAIN_BUTTON_ACCESSIBILITY,
          info_->model()->GetFileNameToReportUser().LossyDisplayName());
    case DownloadCommands::RESUME:
      return l10n_util::GetStringFUTF16(
          IDS_DOWNLOAD_BUBBLE_RESUME_MAIN_BUTTON_ACCESSIBILITY,
          info_->model()->GetFileNameToReportUser().LossyDisplayName());
    case DownloadCommands::DISCARD:
      return l10n_util::GetStringFUTF16(
          IDS_DOWNLOAD_BUBBLE_DELETE_MAIN_BUTTON_ACCESSIBILITY,
          info_->model()->GetFileNameToReportUser().LossyDisplayName());
    case DownloadCommands::KEEP:
      return l10n_util::GetStringFUTF16(
          IDS_DOWNLOAD_BUBBLE_KEEP_MAIN_BUTTON_ACCESSIBILITY,
          info_->model()->GetFileNameToReportUser().LossyDisplayName());
    case DownloadCommands::DEEP_SCAN:
      return l10n_util::GetStringFUTF16(
          IDS_DOWNLOAD_BUBBLE_SCAN_MAIN_BUTTON_ACCESSIBILITY,
          info_->model()->GetFileNameToReportUser().LossyDisplayName());
    case DownloadCommands::BYPASS_DEEP_SCANNING_AND_OPEN:
      return l10n_util::GetStringFUTF16(
          IDS_DOWNLOAD_BUBBLE_OPEN_NOW_MAIN_BUTTON_ACCESSIBILITY,
          info_->model()->GetFileNameToReportUser().LossyDisplayName());
    case DownloadCommands::REVIEW:
      return l10n_util::GetStringFUTF16(
          IDS_DOWNLOAD_BUBBLE_REVIEW_MAIN_BUTTON_ACCESSIBILITY,
          info_->model()->GetFileNameToReportUser().LossyDisplayName());
    case DownloadCommands::RETRY:
      return l10n_util::GetStringFUTF16(
          IDS_DOWNLOAD_BUBBLE_RETRY_MAIN_BUTTON_ACCESSIBILITY,
          info_->model()->GetFileNameToReportUser().LossyDisplayName());
    case DownloadCommands::OPEN_WHEN_COMPLETE:
      return l10n_util::GetStringFUTF16(
          IDS_DOWNLOAD_BUBBLE_OPEN_MAIN_BUTTON_ACCESSIBILITY,
          info_->model()->GetFileNameToReportUser().LossyDisplayName());
    default:
      NOTREACHED();
  }
}

void DownloadBubbleRowView::ShowContextMenuForViewImpl(
    View* source,
    const gfx::Point& point,
    ui::mojom::MenuSourceType source_type) {
  // Similar hack as in MenuButtonController and DownloadItemView.
  // We're about to show the menu from a mouse press. By showing from the
  // mouse press event we block RootView in mouse dispatching. This also
  // appears to cause RootView to get a mouse pressed BEFORE the mouse
  // release is seen, which means RootView sends us another mouse press no
  // matter where the user pressed. To force RootView to recalculate the
  // mouse target during the mouse press we explicitly set the mouse handler
  // to null.
  static_cast<views::internal::RootView*>(GetWidget()->GetRootView())
      ->SetMouseAndGestureHandler(nullptr);

  context_menu_->Run(GetWidget()->GetTopLevelWidget(),
                     gfx::Rect(point, gfx::Size()), source_type,
                     base::RepeatingClosure());
}

void DownloadBubbleRowView::UpdateStatusText() {
  secondary_label_->SetText(info_->model()->GetStatusTextForLabel(
      secondary_label_->font_list(), secondary_label_->width()));
}

bool DownloadBubbleRowView::AcceleratorPressed(
    const ui::Accelerator& accelerator) {
  if (info_->model()->GetState() != download::DownloadItem::COMPLETE) {
    return false;
  }

  // The only accelerator we registered is for copy, so we know that's what
  // `accelerator` contains. If DCHECKs are enabled, we can confirm that.
#if DCHECK_IS_ON()
  if (browser_) {
    BrowserView* browser_view =
        BrowserView::GetBrowserViewForBrowser(browser_.get());
    ui::Accelerator registered_accelerator;
    if (browser_view &&
        browser_view->GetAccelerator(IDC_COPY, &registered_accelerator)) {
      DCHECK(accelerator == registered_accelerator);
    }
  }
#endif

  ui::ScopedClipboardWriter scw(ui::ClipboardBuffer::kCopyPaste);
  std::string uri_list = ui::FileInfosToURIList(
      {ui::FileInfo(info_->model()->GetTargetFilePath(),
                    info_->model()->GetFileNameToReportUser())});
  scw.WriteFilenames(uri_list);
  return true;
}

bool DownloadBubbleRowView::CanHandleAccelerators() const {
  bool focused = Contains(GetFocusManager()->GetFocusedView());
  return focused;
}

std::u16string_view DownloadBubbleRowView::GetSecondaryLabelTextForTesting() {
  return secondary_label_->GetText();
}

void DownloadBubbleRowView::RegisterAccelerators(
    views::FocusManager* focus_manager) {
  if (!browser_) {
    return;
  }
  BrowserView* browser_view =
      BrowserView::GetBrowserViewForBrowser(browser_.get());
  if (!browser_view) {
    return;
  }

  ui::Accelerator accelerator;
  if (!browser_view->GetAccelerator(IDC_COPY, &accelerator)) {
    return;
  }

  focus_manager->RegisterAccelerator(
      accelerator, ui::AcceleratorManager::kNormalPriority, this);
}

void DownloadBubbleRowView::UnregisterAccelerators(
    views::FocusManager* focus_manager) {
  if (!browser_) {
    return;
  }
  BrowserView* browser_view =
      BrowserView::GetBrowserViewForBrowser(browser_.get());
  if (!browser_view) {
    return;
  }

  ui::Accelerator accelerator;
  if (!browser_view->GetAccelerator(IDC_COPY, &accelerator)) {
    return;
  }

  focus_manager->UnregisterAccelerator(accelerator, this);
}

void DownloadBubbleRowView::OnInfoChanged() {
  if (!navigation_handler_) {
    return;
  }
  UpdateRow(/*initial_setup=*/false);
  // Resize is needed because the height of the row can change when the text
  // (primary_label_ or secondary_label_) is updated.
  PreferredSizeChanged();
}

void DownloadBubbleRowView::SimulateMainButtonClickForTesting(
    const ui::Event& event) {
  static_cast<DownloadBubbleTransparentButton*>(transparent_button_)
      ->NotifyClickForTesting(event);  // IN-TEST
}

bool DownloadBubbleRowView::IsQuickActionButtonVisibleForTesting(
    DownloadCommands::Command command) {
  auto it = quick_actions_.find(command);
  CHECK(it != quick_actions_.end());
  return it->second->GetVisible();
}

views::ImageButton* DownloadBubbleRowView::GetQuickActionButtonForTesting(
    DownloadCommands::Command command) {
  auto it = quick_actions_.find(command);
  CHECK(it != quick_actions_.end());
  return it->second;
}

void DownloadBubbleRowView::SetInputProtectorForTesting(
    std::unique_ptr<views::InputEventActivationProtector> input_protector) {
  input_protector_ = std::move(input_protector);
}

BEGIN_METADATA(DownloadBubbleRowView)
END_METADATA