File: tab_data.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 (88 lines) | stat: -rw-r--r-- 2,944 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
// Copyright 2023 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_TABS_ORGANIZATION_TAB_DATA_H_
#define CHROME_BROWSER_UI_TABS_ORGANIZATION_TAB_DATA_H_

#include <optional>

#include "base/callback_list.h"
#include "base/memory/raw_ptr.h"
#include "base/observer_list.h"
#include "chrome/browser/ui/tabs/tab_model.h"
#include "chrome/browser/ui/tabs/tab_strip_model_observer.h"
#include "components/tab_groups/tab_group_id.h"
#include "components/tabs/public/tab_interface.h"
#include "content/public/browser/web_contents_observer.h"
#include "url/gurl.h"

class TabStripModel;

namespace content {
class NavigationHandle;
}  // namespace content

class TabData : public TabStripModelObserver,
                public content::WebContentsObserver {
 public:
  // TODO(crbug.com/40070608) replace with opaque tab handle
  using TabID = int;

  class Observer {
   public:
    virtual ~Observer() = default;

    virtual void OnTabDataUpdated(const TabData* tab_data) {}
    virtual void OnTabDataDestroyed(TabID tab_id) {}
  };

  explicit TabData(tabs::TabInterface* tab);
  ~TabData() override;
  TabID tab_id() const { return tab_.raw_value(); }
  const TabStripModel* original_tab_strip_model() const {
    return original_tab_strip_model_;
  }
  TabStripModel* original_tab_strip_model() {
    return original_tab_strip_model_;
  }
  tabs::TabInterface* tab() const { return tab_.Get(); }
  const GURL& original_url() const { return original_url_; }

  void AddObserver(Observer* new_observer);
  void RemoveObserver(Observer* new_observer);

  // Checks if the Tab is still valid for an organization. If allowed_group_id
  // is provided, will not exclude tabs on the basis of being part of that
  // group.
  bool IsValidForOrganizing(std::optional<tab_groups::TabGroupId>
                                allowed_group_id = std::nullopt) const;

  // TabStripModelObserver:
  void OnTabStripModelDestroyed(TabStripModel* tab_strip_model) override;

  // content::WebContentsObserver
  void DidFinishNavigation(
      content::NavigationHandle* navigation_handle) override;

 private:
  void OnTabWillDetach(tabs::TabInterface* tab,
                       tabs::TabInterface::DetachReason reason);
  void OnTabWillDiscardContents(tabs::TabInterface* tab,
                                content::WebContents* old_contents,
                                content::WebContents* new_contents);

  // Notifies observers of the tab data that it has been updated.
  void NotifyObserversOfUpdate();

  raw_ptr<TabStripModel> original_tab_strip_model_;
  tabs::TabHandle tab_;
  const GURL original_url_;

  base::ObserverList<Observer>::Unchecked observers_;

  // Holds subscriptions for TabInterface callbacks.
  std::vector<base::CallbackListSubscription> tab_subscriptions_;
};

#endif  // CHROME_BROWSER_UI_TABS_ORGANIZATION_TAB_DATA_H_