summaryrefslogtreecommitdiff
path: root/chromium/weblayer/public/browser.h
blob: 8932998183b0c14111c9aa80e2099794bf1e0a9a (plain)
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
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef WEBLAYER_PUBLIC_BROWSER_H_
#define WEBLAYER_PUBLIC_BROWSER_H_

#include <stddef.h>

#include <memory>
#include <string>
#include <vector>

namespace weblayer {

class BrowserObserver;
class Profile;
class Tab;

// Represents an ordered list of Tabs, with one active. Browser does not own
// the set of Tabs.
class Browser {
 public:
  struct PersistenceInfo {
    PersistenceInfo();
    PersistenceInfo(const PersistenceInfo& other);
    ~PersistenceInfo();

    // Uniquely identifies this browser for session restore, empty is not a
    // valid id.
    std::string id;

    // Last key used to encrypt incognito profile.
    std::vector<uint8_t> last_crypto_key;

    // If non-empty used to restore the state of the browser. This is only used
    // if |id| is empty.
    std::vector<uint8_t> minimal_state;
  };

  // Creates a new Browser. |persistence_info|, if non-null, is used for saving
  // and restoring the state of the browser.
  static std::unique_ptr<Browser> Create(
      Profile* profile,
      const PersistenceInfo* persistence_info);

  virtual ~Browser() {}

  virtual void AddTab(Tab* tab) = 0;
  virtual void DestroyTab(Tab* tab) = 0;
  virtual void SetActiveTab(Tab* tab) = 0;
  virtual Tab* GetActiveTab() = 0;
  virtual std::vector<Tab*> GetTabs() = 0;

  // Creates a tab attached to this browser. The returned tab is owned by the
  // browser.
  virtual Tab* CreateTab() = 0;

  // Called early on in shutdown, before any tabs have been removed.
  virtual void PrepareForShutdown() = 0;

  // Returns the id supplied to Create() that is used for persistence.
  virtual std::string GetPersistenceId() = 0;

  // Returns the tabs and navigations in a format suitable for serialization.
  // This state can be later restored via |PersistenceInfo::minimal_state|.
  // This is not the full state, only a minimal snapshot intended for
  // lightweight restore when full persistence is not desirable.
  virtual std::vector<uint8_t> GetMinimalPersistenceState() = 0;

  virtual void AddObserver(BrowserObserver* observer) = 0;
  virtual void RemoveObserver(BrowserObserver* observer) = 0;

  virtual void VisibleSecurityStateOfActiveTabChanged() = 0;
};

}  // namespace weblayer

#endif  // WEBLAYER_PUBLIC_BROWSER_H_