blob: e8969e3d8e36b20c31324dbf73a7748bdc8c99b2 [file] [log] [blame]
Avi Drissman4e1b7bc32022-09-15 14:03:501// Copyright 2019 The Chromium Authors
Alex Moshchuk8e5c1952019-01-15 03:39:502// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef CONTENT_BROWSER_ISOLATION_CONTEXT_H_
6#define CONTENT_BROWSER_ISOLATION_CONTEXT_H_
7
Albert J. Wong1b6dc962021-07-09 18:06:578#include "base/types/id_type.h"
W. James MacLeane66843c2023-04-26 19:15:579#include "content/browser/origin_agent_cluster_isolation_state.h"
Alex Moshchuk8e5c1952019-01-15 03:39:5010#include "content/common/content_export.h"
Alex Moshchuk99b795422019-03-07 00:27:3211#include "content/public/browser/browser_or_resource_context.h"
Lukasz Anforowicz15ba43e2021-07-21 22:50:0912#include "content/public/browser/browsing_instance_id.h"
Alex Moshchuk8e5c1952019-01-15 03:39:5013
14namespace content {
15
Alex Moshchuk8e5c1952019-01-15 03:39:5016// This class is used to specify the context in which process model decisions
17// need to be made. For example, dynamically added isolated origins only take
18// effect in future BrowsingInstances, and this class can be used to specify
19// that a process model decision is being made from a specific
20// BrowsingInstance, so that only isolated origins that are applicable to that
21// BrowsingInstance are used. This object may be used on UI or IO threads.
22class CONTENT_EXPORT IsolationContext {
23 public:
Alex Moshchuk99b795422019-03-07 00:27:3224 // Normal use cases should create an IsolationContext associated with both a
25 // BrowsingInstance and a BrowserContext (profile). The constructor that
26 // takes in a BrowserContext* may only be used on the UI thread; when
27 // creating this object on the IO thread, the BrowserOrResourceContext
28 // version should be used instead.
29 IsolationContext(BrowsingInstanceId browsing_instance_id,
Alex Moshchukdf15d8e2022-02-01 04:43:4930 BrowserContext* browser_context,
Adithya Srinivasanf6377b12022-08-31 21:58:4431 bool is_guest,
W. James MacLeane66843c2023-04-26 19:15:5732 bool is_fenced,
33 OriginAgentClusterIsolationState default_isolation_state);
Alex Moshchuk99b795422019-03-07 00:27:3234 IsolationContext(BrowsingInstanceId browsing_instance_id,
Alex Moshchukdf15d8e2022-02-01 04:43:4935 BrowserOrResourceContext browser_or_resource_context,
Adithya Srinivasanf6377b12022-08-31 21:58:4436 bool is_guest,
W. James MacLeane66843c2023-04-26 19:15:5737 bool is_fenced,
38 OriginAgentClusterIsolationState default_isolation_state);
Alex Moshchuk99b795422019-03-07 00:27:3239
40 // Also temporarily allow constructing an IsolationContext not associated
41 // with a specific BrowsingInstance. Callers can use this when they don't
42 // know the current BrowsingInstance, or aren't associated with one.
Wez2ef77e72024-06-03 15:40:3843 //
44 // TODO(alexmos): This is primarily used in tests, as well as in call sites
45 // which do not yet plumb proper BrowsingInstance information. Once the
46 // remaining non-test call sites are removed or updated, this should become a
47 // test-only API.
48 explicit IsolationContext(BrowserContext* browser_context);
Alex Moshchuk8e5c1952019-01-15 03:39:5049
Alex Moshchuk8e5c1952019-01-15 03:39:5050 ~IsolationContext() = default;
51
52 // Returns the BrowsingInstance ID associated with this isolation context.
53 // BrowsingInstance IDs are ordered such that BrowsingInstances with lower
54 // IDs were created earlier than BrowsingInstances with higher IDs.
55 //
56 // If this is not specified (i.e., |browsing_instance_id().is_null()| is
57 // true), then this IsolationContext isn't restricted to any particular
58 // BrowsingInstance. Asking for isolated origins from an IsolationContext
59 // with a null |browsing_instance_id()| will return the latest available
60 // isolated origins.
61 BrowsingInstanceId browsing_instance_id() const {
62 return browsing_instance_id_;
63 }
64
Alex Moshchuk99b795422019-03-07 00:27:3265 // Return the BrowserOrResourceContext associated with this IsolationContext.
66 // This represents the profile associated with this IsolationContext, and can
67 // be used on both UI and IO threads.
68 const BrowserOrResourceContext& browser_or_resource_context() const {
69 return browser_or_resource_context_;
70 }
71
Alex Moshchukdf15d8e2022-02-01 04:43:4972 // True when the BrowsingInstance associated with this context is used in a
73 // <webview> guest.
74 bool is_guest() const { return is_guest_; }
75
Adithya Srinivasanf6377b12022-08-31 21:58:4476 bool is_fenced() const { return is_fenced_; }
77
W. James MacLeane66843c2023-04-26 19:15:5778 // Returns the default isolation state used in this BrowsingInstance, which is
79 // a snapshot of the default isolation within the BrowserContext at the time
80 // when this BrowsingInstance was created. Since the BrowserContext's default
81 // isolation state can change dynamically, and since it's important that the
82 // default isolation state remain consistent within a BrowsingInstance, it's
83 // important that all uses in the BrowsingInstance requiring default isolation
84 // reference this value.
85 const OriginAgentClusterIsolationState& default_isolation_state() const {
86 return default_isolation_state_;
87 }
88
Alex Moshchuk8e5c1952019-01-15 03:39:5089 private:
90 // When non-null, associates this context with a particular BrowsingInstance.
Alex Moshchukab80d7d2022-02-04 23:55:0991 const BrowsingInstanceId browsing_instance_id_;
Alex Moshchuk8e5c1952019-01-15 03:39:5092
Alex Moshchukab80d7d2022-02-04 23:55:0993 const BrowserOrResourceContext browser_or_resource_context_;
Alex Moshchukdf15d8e2022-02-01 04:43:4994
95 // Specifies whether the BrowsingInstance associated with this context is for
96 // a <webview> guest.
97 const bool is_guest_;
Adithya Srinivasanf6377b12022-08-31 21:58:4498
99 // Specifies whether the BrowsingInstance associated with this context is for
100 // a <fencedframe>.
101 const bool is_fenced_;
W. James MacLeane66843c2023-04-26 19:15:57102
103 // A snapshot of the default OriginAgentClusterIsolationState at the time this
104 // IsolationContext was created.
105 const OriginAgentClusterIsolationState default_isolation_state_;
Alex Moshchuk8e5c1952019-01-15 03:39:50106};
107
108} // namespace content
109
110#endif // CONTENT_BROWSER_ISOLATION_CONTEXT_H_