File: roll_back_mode_b_infobar_delegate.cc

package info (click to toggle)
chromium 143.0.7499.109-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,786,824 kB
  • sloc: cpp: 35,783,839; ansic: 7,477,365; javascript: 3,962,116; python: 1,480,521; xml: 764,832; asm: 710,816; pascal: 188,028; sh: 88,717; perl: 88,692; objc: 79,984; sql: 57,625; cs: 42,265; fortran: 24,101; makefile: 22,509; tcl: 15,277; php: 14,018; yacc: 9,043; ruby: 7,553; awk: 3,720; lisp: 3,233; lex: 1,330; ada: 727; jsp: 228; sed: 36
file content (79 lines) | stat: -rw-r--r-- 2,954 bytes parent folder | download | duplicates (6)
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
// Copyright 2025 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/cookie_controls/roll_back_mode_b_infobar_delegate.h"

#include "base/metrics/histogram_functions.h"
#include "chrome/browser/infobars/confirm_infobar_creator.h"
#include "chrome/common/webui_url_constants.h"
#include "components/infobars/content/content_infobar_manager.h"
#include "components/infobars/core/infobar.h"
#include "components/strings/grit/privacy_sandbox_strings.h"
#include "components/vector_icons/vector_icons.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/gfx/text_constants.h"

// static
infobars::InfoBar* RollBackModeBInfoBarDelegate::Create(
    infobars::ContentInfoBarManager* infobar_manager) {
  return infobar_manager->AddInfoBar(
      CreateConfirmInfoBar(std::unique_ptr<ConfirmInfoBarDelegate>(
          new RollBackModeBInfoBarDelegate())));
}

RollBackModeBInfoBarDelegate::RollBackModeBInfoBarDelegate() = default;

RollBackModeBInfoBarDelegate::~RollBackModeBInfoBarDelegate() {
  base::UmaHistogramBoolean(
      "Privacy.3PCD.RollbackNotice.AutomaticallyDismissed", !user_action_);
}

infobars::InfoBarDelegate::InfoBarIdentifier
RollBackModeBInfoBarDelegate::GetIdentifier() const {
  return ROLL_BACK_MODE_B_INFOBAR_DELEGATE;
}

const gfx::VectorIcon& RollBackModeBInfoBarDelegate::GetVectorIcon() const {
  return vector_icons::kCookieChromeRefreshIcon;
}

std::u16string RollBackModeBInfoBarDelegate::GetMessageText() const {
  return l10n_util::GetStringUTF16(IDS_MODE_B_ROLLBACK_DESCRIPTION);
}

bool RollBackModeBInfoBarDelegate::Cancel() {
  // The "cancel" button is a link to cookie settings.
  user_action_ = true;
  base::UmaHistogramEnumeration("Privacy.3PCD.RollbackNotice.Action",
                                RollBack3pcdNoticeAction::kSettings);
  infobar()->owner()->OpenURL(GURL(chrome::kChromeUICookieSettingsURL),
                              WindowOpenDisposition::NEW_FOREGROUND_TAB);
  return false;
}

bool RollBackModeBInfoBarDelegate::Accept() {
  user_action_ = true;
  base::UmaHistogramEnumeration("Privacy.3PCD.RollbackNotice.Action",
                                RollBack3pcdNoticeAction::kGotIt);
  return ConfirmInfoBarDelegate::Accept();
}

std::u16string RollBackModeBInfoBarDelegate::GetButtonLabel(
    InfoBarButton button) const {
  DCHECK(button == BUTTON_OK || button == BUTTON_CANCEL);
  return l10n_util::GetStringUTF16((button == BUTTON_OK)
                                       ? IDS_MODE_B_ROLLBACK_GOT_IT
                                       : IDS_MODE_B_ROLLBACK_SETTINGS);
}

bool RollBackModeBInfoBarDelegate::IsCloseable() const {
  return false;
}

bool RollBackModeBInfoBarDelegate::ShouldExpire(
    const NavigationDetails& details) const {
  // Let the infobar persist indefinitely on the current tab; it will be closed
  // when the user switches tabs.
  return false;
}