blob: 04008fefbfabc57c36e102c859214de904597cb1 [file] [log] [blame]
Avi Drissmanea1be232022-09-14 23:29:061// Copyright 2013 The Chromium Authors
sdefresnea010b6d2014-11-12 09:32:202// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef IOS_WEB_PUBLIC_BROWSER_STATE_H_
6#define IOS_WEB_PUBLIC_BROWSER_STATE_H_
7
John Abd-El-Malek07a93f12018-02-08 19:28:258#include <memory>
9
Justin Cohenb161408d2024-01-24 19:26:1310#import "base/memory/raw_ptr.h"
sdefresnea010b6d2014-11-12 09:32:2011#include "base/supports_user_data.h"
Julie Jeongeun Kim17b2adf12019-10-29 10:24:4812#include "mojo/public/cpp/bindings/pending_receiver.h"
Julie Jeongeun Kimc0827552019-08-27 03:19:3713#include "mojo/public/cpp/bindings/remote.h"
Reilly Grantd055e32c2018-08-15 00:01:1814#include "services/network/public/mojom/cookie_manager.mojom.h"
Hans Wennborga61b3042021-06-15 12:06:3115#include "services/network/public/mojom/network_context.mojom.h"
Matt Menke1f2fb3732018-03-09 19:14:4716#include "services/network/public/mojom/network_service.mojom.h"
Helen Li5f3d96a2018-08-10 20:37:2417#include "services/network/public/mojom/proxy_resolving_socket.mojom.h"
Matt Menke1f2fb3732018-03-09 19:14:4718#include "services/network/public/mojom/url_loader_factory.mojom.h"
sdefresnea010b6d2014-11-12 09:32:2019
sdefresne6f95f8f2014-11-21 11:21:1020namespace base {
21class FilePath;
22}
23
sdefresnea010b6d2014-11-12 09:32:2024namespace net {
25class URLRequestContextGetter;
26}
27
John Abd-El-Malek07a93f12018-02-08 19:28:2528namespace network {
Maks Orlovichd6f27e52018-06-05 16:14:3529class SharedURLLoaderFactory;
30class WeakWrapperSharedURLLoaderFactory;
John Abd-El-Malek07a93f12018-02-08 19:28:2531} // namespace network
32
ssid9b9d6332019-08-08 17:48:2233namespace leveldb_proto {
34class ProtoDatabaseProvider;
35} // namespace leveldb_proto
36
sdefresnea010b6d2014-11-12 09:32:2037namespace web {
stuartmorgand7f6a672015-03-31 22:01:1338class CertificatePolicyCache;
Maks Orlovichc71746a62018-04-27 21:52:1739class NetworkContextOwner;
stuartmorganf0e19f912015-04-29 06:01:0140class URLDataManagerIOS;
41class URLDataManagerIOSBackend;
42class URLRequestChromeJob;
sdefresnea010b6d2014-11-12 09:32:2043
44// This class holds the context needed for a browsing session.
45// It lives on the UI thread. All these methods must only be called on the UI
46// thread.
47class BrowserState : public base::SupportsUserData {
48 public:
sdefresnedb52bdf2014-11-13 09:20:3249 ~BrowserState() override;
sdefresnea010b6d2014-11-12 09:32:2050
stuartmorgand7f6a672015-03-31 22:01:1351 // static
52 static scoped_refptr<CertificatePolicyCache> GetCertificatePolicyCache(
53 BrowserState* browser_state);
54
sdefresne6f95f8f2014-11-21 11:21:1055 // Returns whether this BrowserState is incognito. Default is false.
sdefresnea010b6d2014-11-12 09:32:2056 virtual bool IsOffTheRecord() const = 0;
57
sdefresne6f95f8f2014-11-21 11:21:1058 // Returns the path where the BrowserState data is stored.
sdefresne2bbdeed2015-03-02 14:24:2659 // Unlike Profile::GetPath(), incognito BrowserState do not share their path
60 // with their original BrowserState.
61 virtual base::FilePath GetStatePath() const = 0;
sdefresne6f95f8f2014-11-21 11:21:1062
sdefresnea010b6d2014-11-12 09:32:2063 // Returns the request context information associated with this
64 // BrowserState.
65 virtual net::URLRequestContextGetter* GetRequestContext() = 0;
66
John Abd-El-Malek07a93f12018-02-08 19:28:2567 // Returns a URLLoaderFactory that is backed by GetRequestContext.
68 network::mojom::URLLoaderFactory* GetURLLoaderFactory();
69
Reilly Grantd055e32c2018-08-15 00:01:1870 // Returns a CookieManager that is backed by GetRequestContext.
71 network::mojom::CookieManager* GetCookieManager();
72
ssid9b9d6332019-08-08 17:48:2273 // Returns an provider to create ProtoDatabase tied to the profile directory.
74 leveldb_proto::ProtoDatabaseProvider* GetProtoDatabaseProvider();
75
Julie Jeongeun Kim17b2adf12019-10-29 10:24:4876 // Binds a ProxyResolvingSocketFactory receiver to NetworkContext.
Helen Li5f3d96a2018-08-10 20:37:2477 void GetProxyResolvingSocketFactory(
Julie Jeongeun Kim17b2adf12019-10-29 10:24:4878 mojo::PendingReceiver<network::mojom::ProxyResolvingSocketFactory>
79 receiver);
Helen Li5f3d96a2018-08-10 20:37:2480
Maks Orlovichd6f27e52018-06-05 16:14:3581 // Like URLLoaderFactory, but wrapped inside SharedURLLoaderFactory
Yi Su378627d2018-08-24 22:51:5782 virtual scoped_refptr<network::SharedURLLoaderFactory>
83 GetSharedURLLoaderFactory();
Maks Orlovichd6f27e52018-06-05 16:14:3584
sdefresneb30864ac2014-11-21 12:40:5285 // Safely cast a base::SupportsUserData to a BrowserState. Returns nullptr
Gauthier Ambard29e063062022-09-08 21:34:1286 // if `supports_user_data` is not a BrowserState.
sdefresneb30864ac2014-11-21 12:40:5287 static BrowserState* FromSupportsUserData(
88 base::SupportsUserData* supports_user_data);
89
Gauthier Ambard29e063062022-09-08 21:34:1290 // Updates `cors_exempt_header_list` field of the given `param` to register
Takashi Toyoshimacd413b42019-04-10 20:33:4691 // headers that are used in content for special purpose and should not be
92 // blocked by CORS checks.
93 virtual void UpdateCorsExemptHeader(
94 network::mojom::NetworkContextParams* params) {}
95
sdefresnea010b6d2014-11-12 09:32:2096 protected:
97 BrowserState();
stuartmorganf0e19f912015-04-29 06:01:0198
99 private:
100 friend class URLDataManagerIOS;
101 friend class URLRequestChromeJob;
102
103 // Returns the URLDataManagerIOSBackend instance associated with this
104 // BrowserState, creating it if necessary. Should only be called on the IO
105 // thread.
106 // Not intended for usage outside of //web.
107 URLDataManagerIOSBackend* GetURLDataManagerIOSBackendOnIOThread();
108
Reilly Grantd055e32c2018-08-15 00:01:18109 void CreateNetworkContextIfNecessary();
Helen Li5f3d96a2018-08-10 20:37:24110
Julie Jeongeun Kim1b8bfaf2019-10-28 10:55:52111 mojo::Remote<network::mojom::URLLoaderFactory> url_loader_factory_;
Julie Jeongeun Kimc0827552019-08-27 03:19:37112 mojo::Remote<network::mojom::CookieManager> cookie_manager_;
ssid9b9d6332019-08-08 17:48:22113 std::unique_ptr<leveldb_proto::ProtoDatabaseProvider>
114 proto_database_provider_;
Maks Orlovichd6f27e52018-06-05 16:14:35115 scoped_refptr<network::WeakWrapperSharedURLLoaderFactory>
116 shared_url_loader_factory_;
Julie Jeongeun Kimbd33cf02019-09-12 04:56:23117 mojo::Remote<network::mojom::NetworkContext> network_context_;
Matt Menke1f2fb3732018-03-09 19:14:47118
Gauthier Ambard29e063062022-09-08 21:34:12119 // Owns the network::NetworkContext that backs `url_loader_factory_`. Created
Matt Menke1f2fb3732018-03-09 19:14:47120 // on the UI thread, destroyed on the IO thread.
121 std::unique_ptr<NetworkContextOwner> network_context_owner_;
John Abd-El-Malek07a93f12018-02-08 19:28:25122
stuartmorganf0e19f912015-04-29 06:01:01123 // The URLDataManagerIOSBackend instance associated with this BrowserState.
124 // Created and destroyed on the IO thread, and should be accessed only from
125 // the IO thread.
Justin Cohenb161408d2024-01-24 19:26:13126 raw_ptr<URLDataManagerIOSBackend> url_data_manager_ios_backend_;
sdefresnea010b6d2014-11-12 09:32:20127};
128
129} // namespace web
130
131#endif // IOS_WEB_PUBLIC_BROWSER_STATE_H_