File: side_panel_registry.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,985 bytes parent folder | download | duplicates (4)
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 2021 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_SIDE_PANEL_SIDE_PANEL_REGISTRY_H_
#define CHROME_BROWSER_UI_VIEWS_SIDE_PANEL_SIDE_PANEL_REGISTRY_H_

#include <memory>
#include <variant>
#include <vector>

#include "base/supports_user_data.h"
#include "chrome/browser/ui/views/side_panel/side_panel_entry.h"
#include "chrome/browser/ui/views/side_panel/side_panel_entry_key.h"
#include "chrome/browser/ui/views/side_panel/side_panel_entry_observer.h"
#include "chrome/browser/ui/views/side_panel/side_panel_entry_scope.h"

class SidePanelCoordinator;

namespace content {
class WebContents;
}  // namespace content

// This class is used for storing SidePanelEntries specific to a context. This
// context can be one per tab or one per window. See also SidePanelCoordinator.
class SidePanelRegistry final : public SidePanelEntryObserver,
                                public SidePanelEntryScope {
 public:
  using SidePanelEntryScope::GetBrowserWindowInterface;
  using SidePanelEntryScope::GetTabInterface;

  explicit SidePanelRegistry(tabs::TabInterface* tab_interface);
  explicit SidePanelRegistry(BrowserWindowInterface* browser_window_interface);
  SidePanelRegistry(const SidePanelRegistry&) = delete;
  SidePanelRegistry& operator=(const SidePanelRegistry&) = delete;
  ~SidePanelRegistry() override;

  // The tab-scoped registry should be obtained from the tab, e.g.
  // tab->GetTabFeatures()->side_panel_registry(). This is the fallback for old
  // code that is conceptually tab-scoped but does not use TabInterface.
  //
  // Gets the contextual registry for the tab associated with |web_contents|.
  // Can return null for non-tab contents.
  static SidePanelRegistry* GetDeprecated(content::WebContents* web_contents);

  SidePanelEntry* GetEntryForKey(const SidePanelEntry::Key& entry_key);
  void ResetActiveEntry();
  void ResetLastActiveEntry();

  // Clear cached view for all owned entries.
  void ClearCachedEntryViews();

  // Registers a SidePanelEntry. Returns true if the entry is successfully
  // registered and false if a SidePanelEntry already exists in the registry for
  // the provided SidePanelEntry::Id.
  bool Register(std::unique_ptr<SidePanelEntry> entry);

  // Deregisters the entry for the given SidePanelEntry::Key. Returns true if
  // successful and false if there is no entry registered for the `key`.
  bool Deregister(const SidePanelEntry::Key& key);

  // Set the active entry in the side panel to be |entry|.
  void SetActiveEntry(SidePanelEntry* entry);

  std::optional<SidePanelEntry*> active_entry() { return active_entry_; }
  std::optional<SidePanelEntry*> last_active_entry() {
    return last_active_entry_;
  }
  std::vector<std::unique_ptr<SidePanelEntry>>& entries() { return entries_; }

  // SidePanelEntryObserver:
  void OnEntryShown(SidePanelEntry* id) override;

  // SidePanelEntryScope:
  const tabs::TabInterface& GetTabInterface() const override;
  const BrowserWindowInterface& GetBrowserWindowInterface() const override;

 private:
  SidePanelCoordinator* GetCoordinator();

  // The active entry hosted in the side panel used to determine what entry
  // should be visible. This is reset by the coordinator when the panel is
  // closed. When there are multiple registries, this may not be the entry
  // currently visible in the side panel.
  std::optional<SidePanelEntry*> active_entry_;

  // The last active entry hosted in the side panel before it was closed. This
  // is set when the active entry is reset i.e. when the panel is closed.
  std::optional<SidePanelEntry*> last_active_entry_;

  std::vector<std::unique_ptr<SidePanelEntry>> entries_;

  const std::variant<tabs::TabInterface*, BrowserWindowInterface*> owner_;

  std::optional<SidePanelEntryKey> deregistering_entry_key_ = std::nullopt;
};

#endif  // CHROME_BROWSER_UI_VIEWS_SIDE_PANEL_SIDE_PANEL_REGISTRY_H_