File: permission_prompt_chip_model.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 (98 lines) | stat: -rw-r--r-- 3,587 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
// Copyright 2024 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_VIEWS_PERMISSIONS_CHIP_PERMISSION_PROMPT_CHIP_MODEL_H_
#define CHROME_BROWSER_UI_VIEWS_PERMISSIONS_CHIP_PERMISSION_PROMPT_CHIP_MODEL_H_

#include <string>

#include "base/check.h"
#include "base/memory/raw_ref.h"
#include "chrome/browser/ui/views/permissions/chip/chip_controller.h"
#include "chrome/browser/ui/views/permissions/chip/permission_chip_theme.h"
#include "chrome/grit/generated_resources.h"
#include "components/content_settings/core/common/content_settings_types.h"
#include "components/permissions/features.h"
#include "components/permissions/permission_prompt.h"
#include "components/permissions/permission_request_manager.h"
#include "components/permissions/permission_util.h"
#include "ui/gfx/paint_vector_icon.h"
#include "ui/gfx/vector_icon_types.h"

class PermissionPromptChipModel {
 public:
  explicit PermissionPromptChipModel(
      base::WeakPtr<permissions::PermissionPrompt::Delegate> delegate);
  ~PermissionPromptChipModel();
  PermissionPromptChipModel(const PermissionPromptChipModel&) = delete;
  PermissionPromptChipModel& operator=(const PermissionPromptChipModel&) =
      delete;

  // The delegate representing the permission request.
  const base::WeakPtr<permissions::PermissionPrompt::Delegate>& GetDelegate() {
    return delegate_;
  }

  const gfx::VectorIcon& GetIcon() {
    return should_display_blocked_icon_ ? *blocked_icon_ : *allowed_icon_;
  }

  std::u16string GetChipText() { return chip_text_; }
  std::u16string GetAccessibilityChipText() { return accessibility_chip_text_; }

  PermissionPromptStyle GetPromptStyle() { return prompt_style_; }
  PermissionChipTheme GetChipTheme() { return chip_theme_; }

  bool ShouldDisplayBlockedIcon() { return should_display_blocked_icon_; }
  bool ShouldBubbleStartOpen() { return should_bubble_start_open_; }
  bool ShouldExpand() { return should_expand_; }

  // Updates relevant properties of the model according to the chip's collapse
  // state if it's triggered automatically.
  void UpdateAutoCollapsePromptChipState(bool is_collapsed);

  bool IsExpandAnimationAllowed();

  bool CanDisplayConfirmation() { return chip_text_.length() > 0; }

  // Takes a user decision and updates relevant properties of the model.
  void UpdateWithUserDecision(permissions::PermissionAction permission_action);

  permissions::PermissionAction GetUserDecision() { return user_decision_; }

  ContentSettingsType content_settings_type() const {
    return content_settings_type_;
  }

 private:
  // Delegate holding the current request.
  base::WeakPtr<permissions::PermissionPrompt::Delegate> delegate_;

  // Permission icons and text.
  const raw_ref<const gfx::VectorIcon> allowed_icon_;
  const raw_ref<const gfx::VectorIcon> blocked_icon_;

  std::u16string chip_text_;
  std::u16string accessibility_chip_text_;

  PermissionPromptStyle prompt_style_;
  PermissionChipTheme chip_theme_;

  bool should_display_blocked_icon_ = false;

  // A flag that indicates if a permission popup bubble should be automatically
  // opened.
  bool should_bubble_start_open_ = false;

  // A flag that indicates if a chip should start in the verbose form or as an
  // icon only.
  bool should_expand_ = true;

  ContentSettingsType content_settings_type_;

  permissions::PermissionAction user_decision_ =
      permissions::PermissionAction::NUM;
};

#endif  // CHROME_BROWSER_UI_VIEWS_PERMISSIONS_CHIP_PERMISSION_PROMPT_CHIP_MODEL_H_