File: site_data_row_view.h

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 (109 lines) | stat: -rw-r--r-- 3,744 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
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
// 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.

#ifndef CHROME_BROWSER_UI_VIEWS_SITE_DATA_SITE_DATA_ROW_VIEW_H_
#define CHROME_BROWSER_UI_VIEWS_SITE_DATA_SITE_DATA_ROW_VIEW_H_

#include "components/content_settings/core/common/content_settings.h"
#include "ui/base/interaction/element_identifier.h"
#include "ui/base/interaction/element_tracker.h"
#include "ui/base/metadata/metadata_header_macros.h"
#include "ui/views/controls/button/image_button.h"
#include "ui/views/view.h"
#include "url/origin.h"

class FaviconCache;
class Profile;

namespace gfx {
class Image;
}  // namespace gfx

namespace views {
class ImageView;
class Label;
class ImageButton;
class MenuRunner;
}  // namespace views

namespace ui {
class MenuModel;
}  // namespace ui

namespace url {
class Origin;
}  // namespace url

DECLARE_CUSTOM_ELEMENT_EVENT_TYPE(kSiteRowMenuItemClicked);

// The view that represents a site that has acesss to the data or was blocked
// from accessing the data in the context of the currently visited website. The
// view is used as a row in the site data dialog. It contains a favicon (with a
// fallback icon), a hostname and a menu icon. The menu allows to change the
// cookies content setting for the site or delete the site data.
class SiteDataRowView : public views::View {
  METADATA_HEADER(SiteDataRowView, views::View)

 public:
  SiteDataRowView(
      Profile* profile,
      const url::Origin& origin,
      ContentSetting setting,
      bool is_fully_partitioned,
      FaviconCache* favicon_cache,
      base::RepeatingCallback<void(const url::Origin&)> delete_callback,
      base::RepeatingCallback<void(const url::Origin&, ContentSetting)>
          create_exception_callback);

  ~SiteDataRowView() override;

  DECLARE_CLASS_ELEMENT_IDENTIFIER_VALUE(kMenuButton);
  DECLARE_CLASS_ELEMENT_IDENTIFIER_VALUE(kDeleteButton);

  DECLARE_CLASS_ELEMENT_IDENTIFIER_VALUE(kAllowMenuItem);
  DECLARE_CLASS_ELEMENT_IDENTIFIER_VALUE(kBlockMenuItem);
  DECLARE_CLASS_ELEMENT_IDENTIFIER_VALUE(kClearOnExitMenuItem);

  views::Label* hostname_label_for_testing() { return hostname_label_; }
  views::Label* state_label_for_testing() { return state_label_; }
  views::ImageButton* menu_button_for_testing() { return menu_button_; }
  views::ImageButton* delete_button_for_testing() { return delete_button_; }

 private:
  friend class PageSpecificSiteDataDialogBrowserTest;

  void SetFaviconImage(const gfx::Image& image);

  void OnMenuIconClicked();
  void OnMenuClosed();

  void OnDeleteIconClicked();

  void OnBlockMenuItemClicked(int event_flags);
  void OnAllowMenuItemClicked(int event_flags);
  void OnClearOnExitMenuItemClicked(int event_flags);

  // Sets a content setting exception for the |origin| with |setting| value.
  // Updates the UI to represent the new state: update the state label and the
  // content menu items. After an update the state label is always visible.
  void SetContentSettingException(ContentSetting setting);

  url::Origin origin_;
  ContentSetting setting_;
  bool is_fully_partitioned_;
  base::RepeatingCallback<void(const url::Origin&)> delete_callback_;
  base::RepeatingCallback<void(const url::Origin&, ContentSetting)>
      create_exception_callback_;

  raw_ptr<views::Label> hostname_label_ = nullptr;
  raw_ptr<views::Label> state_label_ = nullptr;
  raw_ptr<views::ImageView> favicon_image_ = nullptr;
  raw_ptr<views::ImageButton> menu_button_ = nullptr;
  raw_ptr<views::ImageButton> delete_button_ = nullptr;

  std::unique_ptr<ui::MenuModel> dialog_model_;
  std::unique_ptr<views::MenuRunner> menu_runner_;
};

#endif  // CHROME_BROWSER_UI_VIEWS_SITE_DATA_SITE_DATA_ROW_VIEW_H_