blob: 332c8ac289b2431bcba8337d3189b4eafb4f42a4 [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
Asami Doie69fa192024-06-18 14:35:3810#include "base/memory/raw_ptr.h"
sdefresnea010b6d2014-11-12 09:32:2011#include "base/supports_user_data.h"
Sylvain Defresne799c76c2024-11-28 15:03:0212#include "base/uuid.h"
Julie Jeongeun Kim17b2adf12019-10-29 10:24:4813#include "mojo/public/cpp/bindings/pending_receiver.h"
Julie Jeongeun Kimc0827552019-08-27 03:19:3714#include "mojo/public/cpp/bindings/remote.h"
Reilly Grantd055e32c2018-08-15 00:01:1815#include "services/network/public/mojom/cookie_manager.mojom.h"
Hans Wennborga61b3042021-06-15 12:06:3116#include "services/network/public/mojom/network_context.mojom.h"
Matt Menke1f2fb3732018-03-09 19:14:4717#include "services/network/public/mojom/network_service.mojom.h"
Helen Li5f3d96a2018-08-10 20:37:2418#include "services/network/public/mojom/proxy_resolving_socket.mojom.h"
Matt Menke1f2fb3732018-03-09 19:14:4719#include "services/network/public/mojom/url_loader_factory.mojom.h"
sdefresnea010b6d2014-11-12 09:32:2020
sdefresne6f95f8f2014-11-21 11:21:1021namespace base {
22class FilePath;
23}
24
sdefresnea010b6d2014-11-12 09:32:2025namespace net {
26class URLRequestContextGetter;
27}
28
John Abd-El-Malek07a93f12018-02-08 19:28:2529namespace network {
Maks Orlovichd6f27e52018-06-05 16:14:3530class SharedURLLoaderFactory;
31class WeakWrapperSharedURLLoaderFactory;
John Abd-El-Malek07a93f12018-02-08 19:28:2532} // namespace network
33
ssid9b9d6332019-08-08 17:48:2234namespace leveldb_proto {
35class ProtoDatabaseProvider;
36} // namespace leveldb_proto
37
sdefresnea010b6d2014-11-12 09:32:2038namespace web {
stuartmorgand7f6a672015-03-31 22:01:1339class CertificatePolicyCache;
Maks Orlovichc71746a62018-04-27 21:52:1740class NetworkContextOwner;
stuartmorganf0e19f912015-04-29 06:01:0141class URLDataManagerIOS;
42class URLDataManagerIOSBackend;
43class URLRequestChromeJob;
sdefresnea010b6d2014-11-12 09:32:2044
45// This class holds the context needed for a browsing session.
46// It lives on the UI thread. All these methods must only be called on the UI
47// thread.
48class BrowserState : public base::SupportsUserData {
49 public:
sdefresnedb52bdf2014-11-13 09:20:3250 ~BrowserState() override;
sdefresnea010b6d2014-11-12 09:32:2051
stuartmorgand7f6a672015-03-31 22:01:1352 // static
53 static scoped_refptr<CertificatePolicyCache> GetCertificatePolicyCache(
54 BrowserState* browser_state);
55
sdefresne6f95f8f2014-11-21 11:21:1056 // Returns whether this BrowserState is incognito. Default is false.
sdefresnea010b6d2014-11-12 09:32:2057 virtual bool IsOffTheRecord() const = 0;
58
sdefresne6f95f8f2014-11-21 11:21:1059 // Returns the path where the BrowserState data is stored.
sdefresne2bbdeed2015-03-02 14:24:2660 // Unlike Profile::GetPath(), incognito BrowserState do not share their path
61 // with their original BrowserState.
62 virtual base::FilePath GetStatePath() const = 0;
sdefresne6f95f8f2014-11-21 11:21:1063
sdefresnea010b6d2014-11-12 09:32:2064 // Returns the request context information associated with this
65 // BrowserState.
66 virtual net::URLRequestContextGetter* GetRequestContext() = 0;
67
John Abd-El-Malek07a93f12018-02-08 19:28:2568 // Returns a URLLoaderFactory that is backed by GetRequestContext.
69 network::mojom::URLLoaderFactory* GetURLLoaderFactory();
70
Reilly Grantd055e32c2018-08-15 00:01:1871 // Returns a CookieManager that is backed by GetRequestContext.
72 network::mojom::CookieManager* GetCookieManager();
73
James Lee46af8782024-02-13 15:38:4074 // Returns a NetworkContext that is backed by GetRequestContext.
75 network::mojom::NetworkContext* GetNetworkContext();
76
ssid9b9d6332019-08-08 17:48:2277 // Returns an provider to create ProtoDatabase tied to the profile directory.
78 leveldb_proto::ProtoDatabaseProvider* GetProtoDatabaseProvider();
79
Julie Jeongeun Kim17b2adf12019-10-29 10:24:4880 // Binds a ProxyResolvingSocketFactory receiver to NetworkContext.
Helen Li5f3d96a2018-08-10 20:37:2481 void GetProxyResolvingSocketFactory(
Julie Jeongeun Kim17b2adf12019-10-29 10:24:4882 mojo::PendingReceiver<network::mojom::ProxyResolvingSocketFactory>
83 receiver);
Helen Li5f3d96a2018-08-10 20:37:2484
Maks Orlovichd6f27e52018-06-05 16:14:3585 // Like URLLoaderFactory, but wrapped inside SharedURLLoaderFactory
Yi Su378627d2018-08-24 22:51:5786 virtual scoped_refptr<network::SharedURLLoaderFactory>
87 GetSharedURLLoaderFactory();
Maks Orlovichd6f27e52018-06-05 16:14:3588
sdefresneb30864ac2014-11-21 12:40:5289 // Safely cast a base::SupportsUserData to a BrowserState. Returns nullptr
Gauthier Ambard29e063062022-09-08 21:34:1290 // if `supports_user_data` is not a BrowserState.
sdefresneb30864ac2014-11-21 12:40:5291 static BrowserState* FromSupportsUserData(
92 base::SupportsUserData* supports_user_data);
93
Gauthier Ambard29e063062022-09-08 21:34:1294 // Updates `cors_exempt_header_list` field of the given `param` to register
Takashi Toyoshimacd413b42019-04-10 20:33:4695 // headers that are used in content for special purpose and should not be
96 // blocked by CORS checks.
97 virtual void UpdateCorsExemptHeader(
98 network::mojom::NetworkContextParams* params) {}
99
Sylvain Defresne799c76c2024-11-28 15:03:02100 // Returns the identifier used to access the WebKit storage for the WebState
101 // attached to this BrowserState. Use the default data store if UUID is not
102 // valid.
103 virtual const base::Uuid& GetWebKitStorageID() const;
Asami Doie69fa192024-06-18 14:35:38104
sdefresnea010b6d2014-11-12 09:32:20105 protected:
106 BrowserState();
stuartmorganf0e19f912015-04-29 06:01:01107
108 private:
109 friend class URLDataManagerIOS;
110 friend class URLRequestChromeJob;
111
112 // Returns the URLDataManagerIOSBackend instance associated with this
113 // BrowserState, creating it if necessary. Should only be called on the IO
114 // thread.
115 // Not intended for usage outside of //web.
116 URLDataManagerIOSBackend* GetURLDataManagerIOSBackendOnIOThread();
117
Reilly Grantd055e32c2018-08-15 00:01:18118 void CreateNetworkContextIfNecessary();
Helen Li5f3d96a2018-08-10 20:37:24119
Julie Jeongeun Kim1b8bfaf2019-10-28 10:55:52120 mojo::Remote<network::mojom::URLLoaderFactory> url_loader_factory_;
Julie Jeongeun Kimc0827552019-08-27 03:19:37121 mojo::Remote<network::mojom::CookieManager> cookie_manager_;
ssid9b9d6332019-08-08 17:48:22122 std::unique_ptr<leveldb_proto::ProtoDatabaseProvider>
123 proto_database_provider_;
Maks Orlovichd6f27e52018-06-05 16:14:35124 scoped_refptr<network::WeakWrapperSharedURLLoaderFactory>
125 shared_url_loader_factory_;
Julie Jeongeun Kimbd33cf02019-09-12 04:56:23126 mojo::Remote<network::mojom::NetworkContext> network_context_;
Matt Menke1f2fb3732018-03-09 19:14:47127
Gauthier Ambard29e063062022-09-08 21:34:12128 // Owns the network::NetworkContext that backs `url_loader_factory_`. Created
Matt Menke1f2fb3732018-03-09 19:14:47129 // on the UI thread, destroyed on the IO thread.
130 std::unique_ptr<NetworkContextOwner> network_context_owner_;
John Abd-El-Malek07a93f12018-02-08 19:28:25131
stuartmorganf0e19f912015-04-29 06:01:01132 // The URLDataManagerIOSBackend instance associated with this BrowserState.
133 // Created and destroyed on the IO thread, and should be accessed only from
134 // the IO thread.
Justin Cohenb161408d2024-01-24 19:26:13135 raw_ptr<URLDataManagerIOSBackend> url_data_manager_ios_backend_;
sdefresnea010b6d2014-11-12 09:32:20136};
137
138} // namespace web
139
140#endif // IOS_WEB_PUBLIC_BROWSER_STATE_H_