File: isolation_context.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 (110 lines) | stat: -rw-r--r-- 4,980 bytes parent folder | download | duplicates (8)
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
// Copyright 2019 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_ISOLATION_CONTEXT_H_
#define CONTENT_BROWSER_ISOLATION_CONTEXT_H_

#include "base/types/id_type.h"
#include "content/browser/origin_agent_cluster_isolation_state.h"
#include "content/common/content_export.h"
#include "content/public/browser/browser_or_resource_context.h"
#include "content/public/browser/browsing_instance_id.h"

namespace content {

// This class is used to specify the context in which process model decisions
// need to be made.  For example, dynamically added isolated origins only take
// effect in future BrowsingInstances, and this class can be used to specify
// that a process model decision is being made from a specific
// BrowsingInstance, so that only isolated origins that are applicable to that
// BrowsingInstance are used. This object may be used on UI or IO threads.
class CONTENT_EXPORT IsolationContext {
 public:
  // Normal use cases should create an IsolationContext associated with both a
  // BrowsingInstance and a BrowserContext (profile).  The constructor that
  // takes in a BrowserContext* may only be used on the UI thread; when
  // creating this object on the IO thread, the BrowserOrResourceContext
  // version should be used instead.
  IsolationContext(BrowsingInstanceId browsing_instance_id,
                   BrowserContext* browser_context,
                   bool is_guest,
                   bool is_fenced,
                   OriginAgentClusterIsolationState default_isolation_state);
  IsolationContext(BrowsingInstanceId browsing_instance_id,
                   BrowserOrResourceContext browser_or_resource_context,
                   bool is_guest,
                   bool is_fenced,
                   OriginAgentClusterIsolationState default_isolation_state);

  // Also temporarily allow constructing an IsolationContext not associated
  // with a specific BrowsingInstance.  Callers can use this when they don't
  // know the current BrowsingInstance, or aren't associated with one.
  //
  // TODO(alexmos):  This is primarily used in tests, as well as in call sites
  // which do not yet plumb proper BrowsingInstance information.  Once the
  // remaining non-test call sites are removed or updated, this should become a
  // test-only API.
  explicit IsolationContext(BrowserContext* browser_context);

  ~IsolationContext() = default;

  // Returns the BrowsingInstance ID associated with this isolation context.
  // BrowsingInstance IDs are ordered such that BrowsingInstances with lower
  // IDs were created earlier than BrowsingInstances with higher IDs.
  //
  // If this is not specified (i.e., |browsing_instance_id().is_null()| is
  // true), then this IsolationContext isn't restricted to any particular
  // BrowsingInstance.  Asking for isolated origins from an IsolationContext
  // with a null |browsing_instance_id()| will return the latest available
  // isolated origins.
  BrowsingInstanceId browsing_instance_id() const {
    return browsing_instance_id_;
  }

  // Return the BrowserOrResourceContext associated with this IsolationContext.
  // This represents the profile associated with this IsolationContext, and can
  // be used on both UI and IO threads.
  const BrowserOrResourceContext& browser_or_resource_context() const {
    return browser_or_resource_context_;
  }

  // True when the BrowsingInstance associated with this context is used in a
  // <webview> guest.
  bool is_guest() const { return is_guest_; }

  bool is_fenced() const { return is_fenced_; }

  // Returns the default isolation state used in this BrowsingInstance, which is
  // a snapshot of the default isolation within the BrowserContext at the time
  // when this BrowsingInstance was created. Since the BrowserContext's default
  // isolation state can change dynamically, and since it's important that the
  // default isolation state remain consistent within a BrowsingInstance, it's
  // important that all uses in the BrowsingInstance requiring default isolation
  // reference this value.
  const OriginAgentClusterIsolationState& default_isolation_state() const {
    return default_isolation_state_;
  }

 private:
  // When non-null, associates this context with a particular BrowsingInstance.
  const BrowsingInstanceId browsing_instance_id_;

  const BrowserOrResourceContext browser_or_resource_context_;

  // Specifies whether the BrowsingInstance associated with this context is for
  // a <webview> guest.
  const bool is_guest_;

  // Specifies whether the BrowsingInstance associated with this context is for
  // a <fencedframe>.
  const bool is_fenced_;

  // A snapshot of the default OriginAgentClusterIsolationState at the time this
  // IsolationContext was created.
  const OriginAgentClusterIsolationState default_isolation_state_;
};

}  // namespace content

#endif  // CONTENT_BROWSER_ISOLATION_CONTEXT_H_