sdefresne | f40c65a | 2014-11-13 12:25:02 | [diff] [blame] | 1 | // Copyright 2013 The Chromium Authors. All rights reserved. |
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 | |
sdefresne | a010b6d | 2014-11-12 09:32:20 | [diff] [blame] | 10 | #include "base/supports_user_data.h" |
Julie Jeongeun Kim | 17b2adf1 | 2019-10-29 10:24:48 | [diff] [blame] | 11 | #include "mojo/public/cpp/bindings/pending_receiver.h" |
Julie Jeongeun Kim | c082755 | 2019-08-27 03:19:37 | [diff] [blame] | 12 | #include "mojo/public/cpp/bindings/remote.h" |
Reilly Grant | d055e32c | 2018-08-15 00:01:18 | [diff] [blame] | 13 | #include "services/network/public/mojom/cookie_manager.mojom.h" |
Hans Wennborg | a61b304 | 2021-06-15 12:06:31 | [diff] [blame^] | 14 | #include "services/network/public/mojom/network_context.mojom.h" |
Matt Menke | 1f2fb373 | 2018-03-09 19:14:47 | [diff] [blame] | 15 | #include "services/network/public/mojom/network_service.mojom.h" |
Helen Li | 5f3d96a | 2018-08-10 20:37:24 | [diff] [blame] | 16 | #include "services/network/public/mojom/proxy_resolving_socket.mojom.h" |
Matt Menke | 1f2fb373 | 2018-03-09 19:14:47 | [diff] [blame] | 17 | #include "services/network/public/mojom/url_loader_factory.mojom.h" |
sdefresne | a010b6d | 2014-11-12 09:32:20 | [diff] [blame] | 18 | |
sdefresne | 6f95f8f | 2014-11-21 11:21:10 | [diff] [blame] | 19 | namespace base { |
| 20 | class FilePath; |
| 21 | } |
| 22 | |
sdefresne | a010b6d | 2014-11-12 09:32:20 | [diff] [blame] | 23 | namespace net { |
| 24 | class URLRequestContextGetter; |
| 25 | } |
| 26 | |
John Abd-El-Malek | 07a93f1 | 2018-02-08 19:28:25 | [diff] [blame] | 27 | namespace network { |
Maks Orlovich | d6f27e5 | 2018-06-05 16:14:35 | [diff] [blame] | 28 | class SharedURLLoaderFactory; |
| 29 | class WeakWrapperSharedURLLoaderFactory; |
John Abd-El-Malek | 07a93f1 | 2018-02-08 19:28:25 | [diff] [blame] | 30 | } // namespace network |
| 31 | |
ssid | 9b9d633 | 2019-08-08 17:48:22 | [diff] [blame] | 32 | namespace leveldb_proto { |
| 33 | class ProtoDatabaseProvider; |
| 34 | } // namespace leveldb_proto |
| 35 | |
sdefresne | a010b6d | 2014-11-12 09:32:20 | [diff] [blame] | 36 | namespace web { |
Robbie Gibson | 0abc137 | 2020-05-15 11:29:27 | [diff] [blame] | 37 | enum class CookieBlockingMode; |
stuartmorgan | d7f6a67 | 2015-03-31 22:01:13 | [diff] [blame] | 38 | class CertificatePolicyCache; |
Maks Orlovich | c71746a6 | 2018-04-27 21:52:17 | [diff] [blame] | 39 | class NetworkContextOwner; |
stuartmorgan | f0e19f91 | 2015-04-29 06:01:01 | [diff] [blame] | 40 | class URLDataManagerIOS; |
| 41 | class URLDataManagerIOSBackend; |
| 42 | class URLRequestChromeJob; |
sdefresne | a010b6d | 2014-11-12 09:32:20 | [diff] [blame] | 43 | |
| 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. |
| 47 | class BrowserState : public base::SupportsUserData { |
| 48 | public: |
sdefresne | db52bdf | 2014-11-13 09:20:32 | [diff] [blame] | 49 | ~BrowserState() override; |
sdefresne | a010b6d | 2014-11-12 09:32:20 | [diff] [blame] | 50 | |
stuartmorgan | d7f6a67 | 2015-03-31 22:01:13 | [diff] [blame] | 51 | // static |
| 52 | static scoped_refptr<CertificatePolicyCache> GetCertificatePolicyCache( |
| 53 | BrowserState* browser_state); |
| 54 | |
sdefresne | 6f95f8f | 2014-11-21 11:21:10 | [diff] [blame] | 55 | // Returns whether this BrowserState is incognito. Default is false. |
sdefresne | a010b6d | 2014-11-12 09:32:20 | [diff] [blame] | 56 | virtual bool IsOffTheRecord() const = 0; |
| 57 | |
sdefresne | 6f95f8f | 2014-11-21 11:21:10 | [diff] [blame] | 58 | // Returns the path where the BrowserState data is stored. |
sdefresne | 2bbdeed | 2015-03-02 14:24:26 | [diff] [blame] | 59 | // Unlike Profile::GetPath(), incognito BrowserState do not share their path |
| 60 | // with their original BrowserState. |
| 61 | virtual base::FilePath GetStatePath() const = 0; |
sdefresne | 6f95f8f | 2014-11-21 11:21:10 | [diff] [blame] | 62 | |
sdefresne | a010b6d | 2014-11-12 09:32:20 | [diff] [blame] | 63 | // Returns the request context information associated with this |
| 64 | // BrowserState. |
| 65 | virtual net::URLRequestContextGetter* GetRequestContext() = 0; |
| 66 | |
John Abd-El-Malek | 07a93f1 | 2018-02-08 19:28:25 | [diff] [blame] | 67 | // Returns a URLLoaderFactory that is backed by GetRequestContext. |
| 68 | network::mojom::URLLoaderFactory* GetURLLoaderFactory(); |
| 69 | |
Reilly Grant | d055e32c | 2018-08-15 00:01:18 | [diff] [blame] | 70 | // Returns a CookieManager that is backed by GetRequestContext. |
| 71 | network::mojom::CookieManager* GetCookieManager(); |
| 72 | |
ssid | 9b9d633 | 2019-08-08 17:48:22 | [diff] [blame] | 73 | // Returns an provider to create ProtoDatabase tied to the profile directory. |
| 74 | leveldb_proto::ProtoDatabaseProvider* GetProtoDatabaseProvider(); |
| 75 | |
Julie Jeongeun Kim | 17b2adf1 | 2019-10-29 10:24:48 | [diff] [blame] | 76 | // Binds a ProxyResolvingSocketFactory receiver to NetworkContext. |
Helen Li | 5f3d96a | 2018-08-10 20:37:24 | [diff] [blame] | 77 | void GetProxyResolvingSocketFactory( |
Julie Jeongeun Kim | 17b2adf1 | 2019-10-29 10:24:48 | [diff] [blame] | 78 | mojo::PendingReceiver<network::mojom::ProxyResolvingSocketFactory> |
| 79 | receiver); |
Helen Li | 5f3d96a | 2018-08-10 20:37:24 | [diff] [blame] | 80 | |
Maks Orlovich | d6f27e5 | 2018-06-05 16:14:35 | [diff] [blame] | 81 | // Like URLLoaderFactory, but wrapped inside SharedURLLoaderFactory |
Yi Su | 378627d | 2018-08-24 22:51:57 | [diff] [blame] | 82 | virtual scoped_refptr<network::SharedURLLoaderFactory> |
| 83 | GetSharedURLLoaderFactory(); |
Maks Orlovich | d6f27e5 | 2018-06-05 16:14:35 | [diff] [blame] | 84 | |
sdefresne | b30864ac | 2014-11-21 12:40:52 | [diff] [blame] | 85 | // Safely cast a base::SupportsUserData to a BrowserState. Returns nullptr |
| 86 | // if |supports_user_data| is not a BrowserState. |
| 87 | static BrowserState* FromSupportsUserData( |
| 88 | base::SupportsUserData* supports_user_data); |
| 89 | |
Takashi Toyoshima | cd413b4 | 2019-04-10 20:33:46 | [diff] [blame] | 90 | // Updates |cors_exempt_header_list| field of the given |param| to register |
| 91 | // 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 | |
Robbie Gibson | 0abc137 | 2020-05-15 11:29:27 | [diff] [blame] | 96 | // Returns the current cookie blocking mode for this browser state. |
| 97 | CookieBlockingMode GetCookieBlockingMode() const; |
| 98 | |
| 99 | // Sets the cookie blocking mode for this browser state. This will only affect |
| 100 | // WebStates that are loaded after this mode is set. WebStates with live web |
| 101 | // content will not have the mode correctly setup until they are reloaded. |
Robbie Gibson | 283c9b8 | 2020-06-08 20:35:02 | [diff] [blame] | 102 | // Some tasks here may be asynchronous, so |callback| will be called after |
| 103 | // the cookie blocking mode is set correctly. This may happen immediately. |
| 104 | void SetCookieBlockingMode(CookieBlockingMode cookie_blocking_mode, |
| 105 | base::OnceClosure callback); |
Robbie Gibson | 0abc137 | 2020-05-15 11:29:27 | [diff] [blame] | 106 | |
sdefresne | a010b6d | 2014-11-12 09:32:20 | [diff] [blame] | 107 | protected: |
| 108 | BrowserState(); |
stuartmorgan | f0e19f91 | 2015-04-29 06:01:01 | [diff] [blame] | 109 | |
| 110 | private: |
| 111 | friend class URLDataManagerIOS; |
| 112 | friend class URLRequestChromeJob; |
| 113 | |
| 114 | // Returns the URLDataManagerIOSBackend instance associated with this |
| 115 | // BrowserState, creating it if necessary. Should only be called on the IO |
| 116 | // thread. |
| 117 | // Not intended for usage outside of //web. |
| 118 | URLDataManagerIOSBackend* GetURLDataManagerIOSBackendOnIOThread(); |
| 119 | |
Reilly Grant | d055e32c | 2018-08-15 00:01:18 | [diff] [blame] | 120 | void CreateNetworkContextIfNecessary(); |
Helen Li | 5f3d96a | 2018-08-10 20:37:24 | [diff] [blame] | 121 | |
Julie Jeongeun Kim | 1b8bfaf | 2019-10-28 10:55:52 | [diff] [blame] | 122 | mojo::Remote<network::mojom::URLLoaderFactory> url_loader_factory_; |
Julie Jeongeun Kim | c082755 | 2019-08-27 03:19:37 | [diff] [blame] | 123 | mojo::Remote<network::mojom::CookieManager> cookie_manager_; |
ssid | 9b9d633 | 2019-08-08 17:48:22 | [diff] [blame] | 124 | std::unique_ptr<leveldb_proto::ProtoDatabaseProvider> |
| 125 | proto_database_provider_; |
Maks Orlovich | d6f27e5 | 2018-06-05 16:14:35 | [diff] [blame] | 126 | scoped_refptr<network::WeakWrapperSharedURLLoaderFactory> |
| 127 | shared_url_loader_factory_; |
Julie Jeongeun Kim | bd33cf0 | 2019-09-12 04:56:23 | [diff] [blame] | 128 | mojo::Remote<network::mojom::NetworkContext> network_context_; |
Matt Menke | 1f2fb373 | 2018-03-09 19:14:47 | [diff] [blame] | 129 | |
| 130 | // Owns the network::NetworkContext that backs |url_loader_factory_|. Created |
| 131 | // on the UI thread, destroyed on the IO thread. |
| 132 | std::unique_ptr<NetworkContextOwner> network_context_owner_; |
John Abd-El-Malek | 07a93f1 | 2018-02-08 19:28:25 | [diff] [blame] | 133 | |
stuartmorgan | f0e19f91 | 2015-04-29 06:01:01 | [diff] [blame] | 134 | // The URLDataManagerIOSBackend instance associated with this BrowserState. |
| 135 | // Created and destroyed on the IO thread, and should be accessed only from |
| 136 | // the IO thread. |
| 137 | URLDataManagerIOSBackend* url_data_manager_ios_backend_; |
Robbie Gibson | 0abc137 | 2020-05-15 11:29:27 | [diff] [blame] | 138 | |
| 139 | CookieBlockingMode cookie_blocking_mode_; |
sdefresne | a010b6d | 2014-11-12 09:32:20 | [diff] [blame] | 140 | }; |
| 141 | |
| 142 | } // namespace web |
| 143 | |
| 144 | #endif // IOS_WEB_PUBLIC_BROWSER_STATE_H_ |