File: lens_overlay_entry_point_controller.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; 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 (132 lines) | stat: -rw-r--r-- 5,174 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
// 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_LENS_LENS_OVERLAY_ENTRY_POINT_CONTROLLER_H_
#define CHROME_BROWSER_UI_LENS_LENS_OVERLAY_ENTRY_POINT_CONTROLLER_H_

#include "base/memory/raw_ptr.h"
#include "base/scoped_observation.h"
#include "chrome/browser/ui/exclusive_access/fullscreen_controller.h"
#include "chrome/browser/ui/exclusive_access/fullscreen_observer.h"
#include "chrome/browser/ui/lens/lens_url_matcher.h"
#include "components/prefs/pref_change_registrar.h"
#include "components/search_engines/template_url_service.h"
#include "components/search_engines/template_url_service_observer.h"
#include "ui/actions/actions.h"
#include "ui/views/focus/focus_manager.h"
#include "ui/views/view_observer.h"

class BrowserWindowInterface;
class CommandUpdater;

namespace tabs {
class TabInterface;
}  // namespace tabs

namespace views {
class View;
}  // namespace views

namespace lens {

// Per-browser-window class responsible for keeping Lens Overlay entry points in
// their correct state. This functionality needs to be separate from
// LensOverlayController, since LensOverlayController exist per tab, while entry
// points are per browser window.
class LensOverlayEntryPointController : public FullscreenObserver,
                                        public TemplateURLServiceObserver,
                                        public views::FocusChangeListener,
                                        public views::ViewObserver {
 public:
  LensOverlayEntryPointController();
  ~LensOverlayEntryPointController() override;

  // This class does nothing if not initialized. IsEnabled returns false.
  void Initialize(BrowserWindowInterface* browser_window_interface,
                  CommandUpdater* command_updater,
                  views::View* location_bar);

  // Whether the entry points should be enabled. Enabled means the Lens Overlay
  // functionality is available.
  bool IsEnabled() const;

  // Returns true if the Lens Overlay entrypoints should be hidden. This is
  // different from IsEnabled() as IsEnabled() returns true if the Lens Overlay
  // functionality is available, while AreVisible() returns true if the Lens
  // Overlay functionality is available and the entrypoints should be visible at
  // this current moment in time. Sometimes, entrypoints are hidden ephermally,
  // such as when the Lens Overlay is currently active, so entrypoints do
  // nothing.
  bool AreVisible() const;

  // Updates the enable/disable and visibility state of entry points. If
  // hide_toolbar_entrypoint is true, instead of just disabling the toolbar
  // entrypoint, we will also hide the entrypoint from the user. All other
  // entrypoints will be updated to their correct state.
  void UpdateEntryPointsState(bool hide_toolbar_entrypoint);

  // Returns true if the given URL is eligible for EDU promos present on some
  // entrypoints.
  bool IsUrlEduEligible(const GURL& url) const;

  // Invokes the entrypoint action.
  static void InvokeAction(tabs::TabInterface* active_tab,
                           const actions::ActionInvocationContext& context);

 private:
  // FullscreenObserver:
  void OnFullscreenStateChanged() override;

  // TemplateURLServiceObserver:
  void OnTemplateURLServiceChanged() override;
  void OnTemplateURLServiceShuttingDown() override;

  // views::FocusChangeListener
  void OnDidChangeFocus(views::View* before, views::View* now) override;

  // views::ViewObserver
  void OnViewAddedToWidget(views::View* view) override;
  void OnViewRemovedFromWidget(views::View* view) override;

  // Updates the Lens Overlay page action state.
  void UpdatePageActionState();
  bool ShouldShowPageAction(tabs::TabInterface* active_tab) const;

  // Returns the ActionItem corresponding to our pinnable toolbar entrypoint.
  actions::ActionItem* GetToolbarEntrypoint();

  // Return true if the Lens Overlay is active on the current tab.
  bool IsOverlayActive() const;

  // Observer to check for focus changes.
  base::ScopedObservation<views::FocusManager, views::FocusChangeListener>
      focus_manager_observation_{this};

  // Observer to check for browser window entering fullscreen.
  base::ScopedObservation<FullscreenController, FullscreenObserver>
      fullscreen_observation_{this};

  // Observer to check for changes to the users DSE.
  base::ScopedObservation<TemplateURLService, TemplateURLServiceObserver>
      template_url_service_observation_{this};

  // Used to change whether the lens entrypoint is enabled in the 3 dot menu.
  // The CommandUpdater is owned by the BrowserWindowInterface, which also owns
  // this, and thus is guaranteed to outlive this.
  raw_ptr<CommandUpdater> command_updater_;

  // Owns this.
  raw_ptr<BrowserWindowInterface> browser_window_interface_;

  PrefChangeRegistrar pref_change_registrar_;

  raw_ptr<views::View> location_bar_;

  // URL matcher for entrypoints with EDU promos.
  std::unique_ptr<LensUrlMatcher> edu_url_matcher_;
};

}  // namespace lens

#endif  // CHROME_BROWSER_UI_LENS_LENS_OVERLAY_ENTRY_POINT_CONTROLLER_H_