File: origin_agent_cluster_isolation_state.h

package info (click to toggle)
chromium 141.0.7390.107-1~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-proposed-updates
  • size: 6,254,812 kB
  • sloc: cpp: 35,264,957; ansic: 7,169,920; javascript: 4,250,185; python: 1,460,636; asm: 950,788; xml: 751,751; pascal: 187,972; sh: 89,459; perl: 88,691; objc: 79,953; sql: 53,924; cs: 44,622; fortran: 24,137; makefile: 22,319; tcl: 15,277; php: 14,018; yacc: 8,995; ruby: 7,553; awk: 3,720; lisp: 3,096; lex: 1,330; ada: 727; jsp: 228; sed: 36
file content (108 lines) | stat: -rw-r--r-- 5,066 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
// 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 CONTENT_BROWSER_ORIGIN_AGENT_CLUSTER_ISOLATION_STATE_H_
#define CONTENT_BROWSER_ORIGIN_AGENT_CLUSTER_ISOLATION_STATE_H_

#include "base/tracing/protos/chrome_track_event.pbzero.h"
#include "content/browser/agent_cluster_key.h"
#include "content/common/content_export.h"

namespace content {

class BrowserContext;

// This class contains the OAC isolation state applied to an origin. If
// `logical_oac_status` is kSiteKeyedByHeader or kSiteKeyedByDefault, then
// there's no OAC isolation. If it's kOriginKeyedByHeader or
// kOriginKeyedByDefault, but `process_isolation_oac_status` is
// kSiteKeyedByHeader or kSiteKeyedByDefault, then the origin has logical
// (within renderer) isolation, but not process isolation. If
// `process_isolation_oac_status` is kOriginKeyedByHeader or
// kOriginKeyedByDefault, then the origin has process isolation as well.
class CONTENT_EXPORT OriginAgentClusterIsolationState {
 public:
  // With the OriginAgentCluster-by-default flag controlling whether default
  // isolation is non-isolated (flag off) or OriginAgentCluster but without
  // origin-keyed process (flag on), this function is used to get the correct
  // default state without having to know the flag setting.
  static OriginAgentClusterIsolationState CreateForDefaultIsolation(
      BrowserContext* context);

  // This creates an OriginAgentClusterIsolationState with both logical and
  // process-isolation values site-keyed. This should be used when a document
  // has explicitly requested site-keyed agent clusters through the OAC header.
  static OriginAgentClusterIsolationState CreateNonIsolatedByHeader() {
    return OriginAgentClusterIsolationState(
        AgentClusterKey::OACStatus::kSiteKeyedByHeader,
        AgentClusterKey::OACStatus::kSiteKeyedByHeader);
  }

  // This creates an OriginAgentClusterIsolationState with both logical and
  // process-isolation values site-keyed. This should be used for a default
  // site-keyed OAC state for a document without OAC headers. For regular
  // contexts, prefer using CreateForDefaultIsolation, which will accurately
  // make the OAC origin-keyed when Origin Isolation by default is enabled.
  static OriginAgentClusterIsolationState CreateNonIsolatedByDefault() {
    return OriginAgentClusterIsolationState(
        AgentClusterKey::OACStatus::kSiteKeyedByDefault,
        AgentClusterKey::OACStatus::kSiteKeyedByDefault);
  }

  // This creates an OriginIsolationClusterIsolationState for a context with
  // either logical or process-isolated origin isolation enabled via
  // Origin-Agent-Cluster. |had_oac_request| is true when the context had an OAC
  // header requesting an origin-keyed agent cluster. When it is false, it means
  // that the agent cluster was made origin-keyed by default.
  // |requires_origin_keyed_process| indicates whether the agent cluster should
  // also be process isolated, on top of logical isolation in the renderer
  // process.
  static OriginAgentClusterIsolationState CreateForOriginAgentCluster(
      bool had_oac_request,
      bool requires_origin_keyed_process);

  AgentClusterKey::OACStatus logical_oac_status() const {
    return logical_oac_status_;
  }
  AgentClusterKey::OACStatus process_isolation_oac_status() const {
    return process_isolation_oac_status_;
  }

  // Whether this OriginAgentClusterIsolationState corresponds to an
  // origin-keyed agent cluster with logical isolation.
  bool is_origin_agent_cluster() const {
    return logical_oac_status_ ==
               AgentClusterKey::OACStatus::kOriginKeyedByHeader ||
           logical_oac_status_ ==
               AgentClusterKey::OACStatus::kOriginKeyedByDefault;
  }

  // Whether this OriginAgentClusterIsolationState corresponds to an
  // origin-keyed agent cluster backed by process isolation.
  bool requires_origin_keyed_process() const {
    return process_isolation_oac_status_ ==
               AgentClusterKey::OACStatus::kOriginKeyedByHeader ||
           process_isolation_oac_status_ ==
               AgentClusterKey::OACStatus::kOriginKeyedByDefault;
  }

  bool operator==(const OriginAgentClusterIsolationState&) const = default;

 private:
  OriginAgentClusterIsolationState(
      AgentClusterKey::OACStatus logical_oac_status,
      AgentClusterKey::OACStatus process_isolation_oac_status);

  // Whether this uses an origin-keyed agent cluster in the renderer process,
  // affecting web visible behavior. See
  // https://html.spec.whatwg.org/multipage/origin.html#origin-keyed-agent-clusters.
  AgentClusterKey::OACStatus logical_oac_status_;
  // Whether this uses an origin-keyed process in the browser's process model.
  // Note that if this has an origin-keyed value, `logical_oac_status_` must
  // have an origin-keyed value as well.
  AgentClusterKey::OACStatus process_isolation_oac_status_;
};

}  // namespace content
#endif  // CONTENT_BROWSER_ORIGIN_AGENT_CLUSTER_ISOLATION_STATE_H_