File: page_action_icon_controller.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 (126 lines) | stat: -rw-r--r-- 4,682 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
124
125
126
// Copyright 2019 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_PAGE_ACTION_PAGE_ACTION_ICON_CONTROLLER_H_
#define CHROME_BROWSER_UI_VIEWS_PAGE_ACTION_PAGE_ACTION_ICON_CONTROLLER_H_

#include "base/containers/flat_map.h"
#include "base/memory/raw_ptr.h"
#include "base/scoped_observation.h"
#include "chrome/browser/ui/page_action/page_action_icon_type.h"
#include "chrome/browser/ui/views/page_action/page_action_icon_view.h"
#include "chrome/browser/ui/views/page_action/page_action_icon_view_observer.h"
#include "components/prefs/pref_change_registrar.h"
#include "components/zoom/zoom_event_manager.h"
#include "components/zoom/zoom_event_manager_observer.h"
#include "content/public/browser/navigation_handle.h"
#include "content/public/browser/page.h"
#include "content/public/browser/web_contents_observer.h"
#include "third_party/skia/include/core/SkColor.h"
#include "ui/gfx/color_palette.h"
#include "ui/views/view.h"

class Browser;
class PageActionIconContainer;
struct PageActionIconParams;
class ZoomView;

class PageActionIconController : public PageActionIconViewObserver,
                                 public zoom::ZoomEventManagerObserver,
                                 public content::WebContentsObserver {
 public:
  PageActionIconController();
  PageActionIconController(const PageActionIconController&) = delete;
  PageActionIconController& operator=(const PageActionIconController&) = delete;
  ~PageActionIconController() override;

  void Init(const PageActionIconParams& params,
            PageActionIconContainer* icon_container);

  PageActionIconView* GetIconView(PageActionIconType type);
  PageActionIconType GetIconType(PageActionIconView* view);

  // Updates the visual state of all enabled page action icons.
  void UpdateAll();

  bool IsAnyIconVisible() const;

  // Update the icons' color.
  void SetIconColor(SkColor icon_color);

  // Update the icons' fonts.
  void SetFontList(const gfx::FontList& font_list);

  // See comment in browser_window.h for more info.
  void ZoomChangedForActiveTab(bool can_show_bubble);

  // Observe the new web contents.
  void UpdateWebContents(content::WebContents* contents);

  // WebContentsObserver
  void ReadyToCommitNavigation(
      content::NavigationHandle* navigation_handle) override;
  void PrimaryPageChanged(content::Page& page) override;

  std::vector<const PageActionIconView*> GetPageActionIconViewsForTesting()
      const;

 private:
  using IconViews =
      base::flat_map<PageActionIconType,
                     raw_ptr<PageActionIconView, CtnExperimental>>;

  // PageActionIconViewObserver:
  void OnPageActionIconViewShown(PageActionIconView* view) override;
  void OnPageActionIconViewClicked(PageActionIconView* view) override;

  // ZoomEventManagerObserver:
  // Updates the view for the zoom icon when default zoom levels change.
  void OnDefaultZoomLevelChanged() override;

  // Returns the number of page actions which are currently visible. Does not
  // include permanent page actions, such as the bookmarks star and sharing
  // hub.
  int VisibleEphemeralActionCount() const;

  // Logs UMA data as appropriate when the current displayed URL changes.
  void RecordMetricsOnURLChange(GURL url);

  // Logs UMA data about the set of currently visible page actions overall, eg.
  // the total number of page actions shown.
  void RecordOverallMetrics();

  // Logs UMA data about an individual visible page action, eg. the type of
  // action shown.
  void RecordIndividualMetrics(PageActionIconType type,
                               PageActionIconView* view) const;

  // Logs UMA data when an individual visible page action is clicked.
  void RecordClickMetrics(PageActionIconType type,
                          PageActionIconView* view) const;

  raw_ptr<Browser> browser_ = nullptr;

  raw_ptr<PageActionIconContainer> icon_container_ = nullptr;

  raw_ptr<ZoomView> zoom_icon_ = nullptr;

  IconViews page_action_icon_views_;

  PrefChangeRegistrar pref_change_registrar_;

  std::map<GURL, std::vector<raw_ptr<PageActionIconView, VectorExperimental>>>
      page_actions_excluded_from_logging_;

  base::ScopedObservation<zoom::ZoomEventManager,
                          zoom::ZoomEventManagerObserver>
      zoom_observation_{this};

  // Max number of actions shown concurrently after the latest page change, as
  // tracked in metrics logging. Used to ensure we don't double-count certain
  // metrics.
  int max_actions_recorded_on_current_page_ = 0;
};

#endif  // CHROME_BROWSER_UI_VIEWS_PAGE_ACTION_PAGE_ACTION_ICON_CONTROLLER_H_