blob: a607fdb89bf8bed17cc4b7538b9da19e70cfde8f [file] [log] [blame]
Alex Moshchuk8e5c1952019-01-15 03:39:501// Copyright 2019 The Chromium Authors. All rights reserved.
2// 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
8#include "base/optional.h"
Maciej Pawlowskia37782a02019-05-16 06:40:289#include "base/util/type_safety/id_type.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"
Alex Moshchuk8e5c1952019-01-15 03:39:5012
13namespace content {
14
15class BrowsingInstance;
Maciej Pawlowski4a3ac6852019-05-09 17:06:1416using BrowsingInstanceId = util::IdType32<BrowsingInstance>;
Alex Moshchuk8e5c1952019-01-15 03:39:5017
18// This class is used to specify the context in which process model decisions
19// need to be made. For example, dynamically added isolated origins only take
20// effect in future BrowsingInstances, and this class can be used to specify
21// that a process model decision is being made from a specific
22// BrowsingInstance, so that only isolated origins that are applicable to that
23// BrowsingInstance are used. This object may be used on UI or IO threads.
24class CONTENT_EXPORT IsolationContext {
25 public:
Alex Moshchuk99b795422019-03-07 00:27:3226 // Normal use cases should create an IsolationContext associated with both a
27 // BrowsingInstance and a BrowserContext (profile). The constructor that
28 // takes in a BrowserContext* may only be used on the UI thread; when
29 // creating this object on the IO thread, the BrowserOrResourceContext
30 // version should be used instead.
31 IsolationContext(BrowsingInstanceId browsing_instance_id,
32 BrowserContext* browser_context);
33 IsolationContext(BrowsingInstanceId browsing_instance_id,
34 BrowserOrResourceContext browser_or_resource_context);
35
36 // Also temporarily allow constructing an IsolationContext not associated
37 // with a specific BrowsingInstance. Callers can use this when they don't
38 // know the current BrowsingInstance, or aren't associated with one.
Alex Moshchuk8e5c1952019-01-15 03:39:5039 //
40 // TODO(alexmos): This is primarily used in tests, as well as in call sites
41 // which do not yet plumb proper BrowsingInstance information. Once the
42 // remaining non-test call sites are removed or updated, this should become a
43 // test-only API.
Alex Moshchuk99b795422019-03-07 00:27:3244 explicit IsolationContext(BrowserContext* browser_context);
Alex Moshchuk8e5c1952019-01-15 03:39:5045
Alex Moshchuk8e5c1952019-01-15 03:39:5046 ~IsolationContext() = default;
47
48 // Returns the BrowsingInstance ID associated with this isolation context.
49 // BrowsingInstance IDs are ordered such that BrowsingInstances with lower
50 // IDs were created earlier than BrowsingInstances with higher IDs.
51 //
52 // If this is not specified (i.e., |browsing_instance_id().is_null()| is
53 // true), then this IsolationContext isn't restricted to any particular
54 // BrowsingInstance. Asking for isolated origins from an IsolationContext
55 // with a null |browsing_instance_id()| will return the latest available
56 // isolated origins.
57 BrowsingInstanceId browsing_instance_id() const {
58 return browsing_instance_id_;
59 }
60
Alex Moshchuk99b795422019-03-07 00:27:3261 // Return the BrowserOrResourceContext associated with this IsolationContext.
62 // This represents the profile associated with this IsolationContext, and can
63 // be used on both UI and IO threads.
64 const BrowserOrResourceContext& browser_or_resource_context() const {
65 return browser_or_resource_context_;
66 }
67
Alex Moshchuk8e5c1952019-01-15 03:39:5068 private:
69 // When non-null, associates this context with a particular BrowsingInstance.
70 BrowsingInstanceId browsing_instance_id_;
71
Alex Moshchuk99b795422019-03-07 00:27:3272 BrowserOrResourceContext browser_or_resource_context_;
Alex Moshchuk8e5c1952019-01-15 03:39:5073};
74
75} // namespace content
76
77#endif // CONTENT_BROWSER_ISOLATION_CONTEXT_H_