Avi Drissman | ea1be23 | 2022-09-14 23:29:06 | [diff] [blame] | 1 | // Copyright 2013 The Chromium Authors |
sdefresne | a010b6d | 2014-11-12 09:32:20 | [diff] [blame] | 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 IOS_WEB_PUBLIC_BROWSER_STATE_H_ |
| 6 | #define IOS_WEB_PUBLIC_BROWSER_STATE_H_ |
| 7 | |
John Abd-El-Malek | 07a93f1 | 2018-02-08 19:28:25 | [diff] [blame] | 8 | #include <memory> |
| 9 | |
Asami Doi | e69fa19 | 2024-06-18 14:35:38 | [diff] [blame] | 10 | #include "base/memory/raw_ptr.h" |
sdefresne | a010b6d | 2014-11-12 09:32:20 | [diff] [blame] | 11 | #include "base/supports_user_data.h" |
Sylvain Defresne | 799c76c | 2024-11-28 15:03:02 | [diff] [blame] | 12 | #include "base/uuid.h" |
Julie Jeongeun Kim | 17b2adf1 | 2019-10-29 10:24:48 | [diff] [blame] | 13 | #include "mojo/public/cpp/bindings/pending_receiver.h" |
Julie Jeongeun Kim | c082755 | 2019-08-27 03:19:37 | [diff] [blame] | 14 | #include "mojo/public/cpp/bindings/remote.h" |
Reilly Grant | d055e32c | 2018-08-15 00:01:18 | [diff] [blame] | 15 | #include "services/network/public/mojom/cookie_manager.mojom.h" |
Hans Wennborg | a61b304 | 2021-06-15 12:06:31 | [diff] [blame] | 16 | #include "services/network/public/mojom/network_context.mojom.h" |
Matt Menke | 1f2fb373 | 2018-03-09 19:14:47 | [diff] [blame] | 17 | #include "services/network/public/mojom/network_service.mojom.h" |
Helen Li | 5f3d96a | 2018-08-10 20:37:24 | [diff] [blame] | 18 | #include "services/network/public/mojom/proxy_resolving_socket.mojom.h" |
Matt Menke | 1f2fb373 | 2018-03-09 19:14:47 | [diff] [blame] | 19 | #include "services/network/public/mojom/url_loader_factory.mojom.h" |
sdefresne | a010b6d | 2014-11-12 09:32:20 | [diff] [blame] | 20 | |
sdefresne | 6f95f8f | 2014-11-21 11:21:10 | [diff] [blame] | 21 | namespace base { |
| 22 | class FilePath; |
| 23 | } |
| 24 | |
sdefresne | a010b6d | 2014-11-12 09:32:20 | [diff] [blame] | 25 | namespace net { |
| 26 | class URLRequestContextGetter; |
| 27 | } |
| 28 | |
John Abd-El-Malek | 07a93f1 | 2018-02-08 19:28:25 | [diff] [blame] | 29 | namespace network { |
Maks Orlovich | d6f27e5 | 2018-06-05 16:14:35 | [diff] [blame] | 30 | class SharedURLLoaderFactory; |
| 31 | class WeakWrapperSharedURLLoaderFactory; |
John Abd-El-Malek | 07a93f1 | 2018-02-08 19:28:25 | [diff] [blame] | 32 | } // namespace network |
| 33 | |
ssid | 9b9d633 | 2019-08-08 17:48:22 | [diff] [blame] | 34 | namespace leveldb_proto { |
| 35 | class ProtoDatabaseProvider; |
| 36 | } // namespace leveldb_proto |
| 37 | |
sdefresne | a010b6d | 2014-11-12 09:32:20 | [diff] [blame] | 38 | namespace web { |
stuartmorgan | d7f6a67 | 2015-03-31 22:01:13 | [diff] [blame] | 39 | class CertificatePolicyCache; |
Maks Orlovich | c71746a6 | 2018-04-27 21:52:17 | [diff] [blame] | 40 | class NetworkContextOwner; |
stuartmorgan | f0e19f91 | 2015-04-29 06:01:01 | [diff] [blame] | 41 | class URLDataManagerIOS; |
| 42 | class URLDataManagerIOSBackend; |
| 43 | class URLRequestChromeJob; |
sdefresne | a010b6d | 2014-11-12 09:32:20 | [diff] [blame] | 44 | |
| 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. |
| 48 | class BrowserState : public base::SupportsUserData { |
| 49 | public: |
sdefresne | db52bdf | 2014-11-13 09:20:32 | [diff] [blame] | 50 | ~BrowserState() override; |
sdefresne | a010b6d | 2014-11-12 09:32:20 | [diff] [blame] | 51 | |
stuartmorgan | d7f6a67 | 2015-03-31 22:01:13 | [diff] [blame] | 52 | // static |
| 53 | static scoped_refptr<CertificatePolicyCache> GetCertificatePolicyCache( |
| 54 | BrowserState* browser_state); |
| 55 | |
sdefresne | 6f95f8f | 2014-11-21 11:21:10 | [diff] [blame] | 56 | // Returns whether this BrowserState is incognito. Default is false. |
sdefresne | a010b6d | 2014-11-12 09:32:20 | [diff] [blame] | 57 | virtual bool IsOffTheRecord() const = 0; |
| 58 | |
sdefresne | 6f95f8f | 2014-11-21 11:21:10 | [diff] [blame] | 59 | // Returns the path where the BrowserState data is stored. |
sdefresne | 2bbdeed | 2015-03-02 14:24:26 | [diff] [blame] | 60 | // Unlike Profile::GetPath(), incognito BrowserState do not share their path |
| 61 | // with their original BrowserState. |
| 62 | virtual base::FilePath GetStatePath() const = 0; |
sdefresne | 6f95f8f | 2014-11-21 11:21:10 | [diff] [blame] | 63 | |
sdefresne | a010b6d | 2014-11-12 09:32:20 | [diff] [blame] | 64 | // Returns the request context information associated with this |
| 65 | // BrowserState. |
| 66 | virtual net::URLRequestContextGetter* GetRequestContext() = 0; |
| 67 | |
John Abd-El-Malek | 07a93f1 | 2018-02-08 19:28:25 | [diff] [blame] | 68 | // Returns a URLLoaderFactory that is backed by GetRequestContext. |
| 69 | network::mojom::URLLoaderFactory* GetURLLoaderFactory(); |
| 70 | |
Reilly Grant | d055e32c | 2018-08-15 00:01:18 | [diff] [blame] | 71 | // Returns a CookieManager that is backed by GetRequestContext. |
| 72 | network::mojom::CookieManager* GetCookieManager(); |
| 73 | |
James Lee | 46af878 | 2024-02-13 15:38:40 | [diff] [blame] | 74 | // Returns a NetworkContext that is backed by GetRequestContext. |
| 75 | network::mojom::NetworkContext* GetNetworkContext(); |
| 76 | |
ssid | 9b9d633 | 2019-08-08 17:48:22 | [diff] [blame] | 77 | // Returns an provider to create ProtoDatabase tied to the profile directory. |
| 78 | leveldb_proto::ProtoDatabaseProvider* GetProtoDatabaseProvider(); |
| 79 | |
Julie Jeongeun Kim | 17b2adf1 | 2019-10-29 10:24:48 | [diff] [blame] | 80 | // Binds a ProxyResolvingSocketFactory receiver to NetworkContext. |
Helen Li | 5f3d96a | 2018-08-10 20:37:24 | [diff] [blame] | 81 | void GetProxyResolvingSocketFactory( |
Julie Jeongeun Kim | 17b2adf1 | 2019-10-29 10:24:48 | [diff] [blame] | 82 | mojo::PendingReceiver<network::mojom::ProxyResolvingSocketFactory> |
| 83 | receiver); |
Helen Li | 5f3d96a | 2018-08-10 20:37:24 | [diff] [blame] | 84 | |
Maks Orlovich | d6f27e5 | 2018-06-05 16:14:35 | [diff] [blame] | 85 | // Like URLLoaderFactory, but wrapped inside SharedURLLoaderFactory |
Yi Su | 378627d | 2018-08-24 22:51:57 | [diff] [blame] | 86 | virtual scoped_refptr<network::SharedURLLoaderFactory> |
| 87 | GetSharedURLLoaderFactory(); |
Maks Orlovich | d6f27e5 | 2018-06-05 16:14:35 | [diff] [blame] | 88 | |
sdefresne | b30864ac | 2014-11-21 12:40:52 | [diff] [blame] | 89 | // Safely cast a base::SupportsUserData to a BrowserState. Returns nullptr |
Gauthier Ambard | 29e06306 | 2022-09-08 21:34:12 | [diff] [blame] | 90 | // if `supports_user_data` is not a BrowserState. |
sdefresne | b30864ac | 2014-11-21 12:40:52 | [diff] [blame] | 91 | static BrowserState* FromSupportsUserData( |
| 92 | base::SupportsUserData* supports_user_data); |
| 93 | |
Gauthier Ambard | 29e06306 | 2022-09-08 21:34:12 | [diff] [blame] | 94 | // Updates `cors_exempt_header_list` field of the given `param` to register |
Takashi Toyoshima | cd413b4 | 2019-04-10 20:33:46 | [diff] [blame] | 95 | // 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 Defresne | 799c76c | 2024-11-28 15:03:02 | [diff] [blame] | 100 | // 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 Doi | e69fa19 | 2024-06-18 14:35:38 | [diff] [blame] | 104 | |
sdefresne | a010b6d | 2014-11-12 09:32:20 | [diff] [blame] | 105 | protected: |
| 106 | BrowserState(); |
stuartmorgan | f0e19f91 | 2015-04-29 06:01:01 | [diff] [blame] | 107 | |
| 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 Grant | d055e32c | 2018-08-15 00:01:18 | [diff] [blame] | 118 | void CreateNetworkContextIfNecessary(); |
Helen Li | 5f3d96a | 2018-08-10 20:37:24 | [diff] [blame] | 119 | |
Julie Jeongeun Kim | 1b8bfaf | 2019-10-28 10:55:52 | [diff] [blame] | 120 | mojo::Remote<network::mojom::URLLoaderFactory> url_loader_factory_; |
Julie Jeongeun Kim | c082755 | 2019-08-27 03:19:37 | [diff] [blame] | 121 | mojo::Remote<network::mojom::CookieManager> cookie_manager_; |
ssid | 9b9d633 | 2019-08-08 17:48:22 | [diff] [blame] | 122 | std::unique_ptr<leveldb_proto::ProtoDatabaseProvider> |
| 123 | proto_database_provider_; |
Maks Orlovich | d6f27e5 | 2018-06-05 16:14:35 | [diff] [blame] | 124 | scoped_refptr<network::WeakWrapperSharedURLLoaderFactory> |
| 125 | shared_url_loader_factory_; |
Julie Jeongeun Kim | bd33cf0 | 2019-09-12 04:56:23 | [diff] [blame] | 126 | mojo::Remote<network::mojom::NetworkContext> network_context_; |
Matt Menke | 1f2fb373 | 2018-03-09 19:14:47 | [diff] [blame] | 127 | |
Gauthier Ambard | 29e06306 | 2022-09-08 21:34:12 | [diff] [blame] | 128 | // Owns the network::NetworkContext that backs `url_loader_factory_`. Created |
Matt Menke | 1f2fb373 | 2018-03-09 19:14:47 | [diff] [blame] | 129 | // on the UI thread, destroyed on the IO thread. |
| 130 | std::unique_ptr<NetworkContextOwner> network_context_owner_; |
John Abd-El-Malek | 07a93f1 | 2018-02-08 19:28:25 | [diff] [blame] | 131 | |
stuartmorgan | f0e19f91 | 2015-04-29 06:01:01 | [diff] [blame] | 132 | // 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 Cohen | b161408d | 2024-01-24 19:26:13 | [diff] [blame] | 135 | raw_ptr<URLDataManagerIOSBackend> url_data_manager_ios_backend_; |
sdefresne | a010b6d | 2014-11-12 09:32:20 | [diff] [blame] | 136 | }; |
| 137 | |
| 138 | } // namespace web |
| 139 | |
| 140 | #endif // IOS_WEB_PUBLIC_BROWSER_STATE_H_ |