blob: 64aae2f224c6db79a78529623b2e4745f5e60838 [file] [log] [blame]
sdefresnef40c65a2014-11-13 12:25:021// Copyright 2013 The Chromium Authors. All rights reserved.
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
sdefresnea010b6d2014-11-12 09:32:2010#include "base/supports_user_data.h"
Julie Jeongeun Kim17b2adf12019-10-29 10:24:4811#include "mojo/public/cpp/bindings/pending_receiver.h"
Julie Jeongeun Kimc0827552019-08-27 03:19:3712#include "mojo/public/cpp/bindings/remote.h"
Reilly Grantd055e32c2018-08-15 00:01:1813#include "services/network/public/mojom/cookie_manager.mojom.h"
Matt Menke1f2fb3732018-03-09 19:14:4714#include "services/network/public/mojom/network_service.mojom.h"
Helen Li5f3d96a2018-08-10 20:37:2415#include "services/network/public/mojom/proxy_resolving_socket.mojom.h"
Matt Menke1f2fb3732018-03-09 19:14:4716#include "services/network/public/mojom/url_loader_factory.mojom.h"
sdefresnea010b6d2014-11-12 09:32:2017
sdefresne6f95f8f2014-11-21 11:21:1018namespace base {
19class FilePath;
20}
21
sdefresnea010b6d2014-11-12 09:32:2022namespace net {
23class URLRequestContextGetter;
24}
25
John Abd-El-Malek07a93f12018-02-08 19:28:2526namespace network {
Maks Orlovichd6f27e52018-06-05 16:14:3527class SharedURLLoaderFactory;
28class WeakWrapperSharedURLLoaderFactory;
John Abd-El-Malek07a93f12018-02-08 19:28:2529} // namespace network
30
ssid9b9d6332019-08-08 17:48:2231namespace leveldb_proto {
32class ProtoDatabaseProvider;
33} // namespace leveldb_proto
34
sdefresnea010b6d2014-11-12 09:32:2035namespace web {
Robbie Gibson0abc1372020-05-15 11:29:2736enum class CookieBlockingMode;
stuartmorgand7f6a672015-03-31 22:01:1337class CertificatePolicyCache;
Maks Orlovichc71746a62018-04-27 21:52:1738class NetworkContextOwner;
stuartmorganf0e19f912015-04-29 06:01:0139class URLDataManagerIOS;
40class URLDataManagerIOSBackend;
41class URLRequestChromeJob;
sdefresnea010b6d2014-11-12 09:32:2042
43// This class holds the context needed for a browsing session.
44// It lives on the UI thread. All these methods must only be called on the UI
45// thread.
46class BrowserState : public base::SupportsUserData {
47 public:
sdefresnedb52bdf2014-11-13 09:20:3248 ~BrowserState() override;
sdefresnea010b6d2014-11-12 09:32:2049
stuartmorgand7f6a672015-03-31 22:01:1350 // static
51 static scoped_refptr<CertificatePolicyCache> GetCertificatePolicyCache(
52 BrowserState* browser_state);
53
sdefresne6f95f8f2014-11-21 11:21:1054 // Returns whether this BrowserState is incognito. Default is false.
sdefresnea010b6d2014-11-12 09:32:2055 virtual bool IsOffTheRecord() const = 0;
56
sdefresne6f95f8f2014-11-21 11:21:1057 // Returns the path where the BrowserState data is stored.
sdefresne2bbdeed2015-03-02 14:24:2658 // Unlike Profile::GetPath(), incognito BrowserState do not share their path
59 // with their original BrowserState.
60 virtual base::FilePath GetStatePath() const = 0;
sdefresne6f95f8f2014-11-21 11:21:1061
sdefresnea010b6d2014-11-12 09:32:2062 // Returns the request context information associated with this
63 // BrowserState.
64 virtual net::URLRequestContextGetter* GetRequestContext() = 0;
65
John Abd-El-Malek07a93f12018-02-08 19:28:2566 // Returns a URLLoaderFactory that is backed by GetRequestContext.
67 network::mojom::URLLoaderFactory* GetURLLoaderFactory();
68
Reilly Grantd055e32c2018-08-15 00:01:1869 // Returns a CookieManager that is backed by GetRequestContext.
70 network::mojom::CookieManager* GetCookieManager();
71
ssid9b9d6332019-08-08 17:48:2272 // Returns an provider to create ProtoDatabase tied to the profile directory.
73 leveldb_proto::ProtoDatabaseProvider* GetProtoDatabaseProvider();
74
Julie Jeongeun Kim17b2adf12019-10-29 10:24:4875 // Binds a ProxyResolvingSocketFactory receiver to NetworkContext.
Helen Li5f3d96a2018-08-10 20:37:2476 void GetProxyResolvingSocketFactory(
Julie Jeongeun Kim17b2adf12019-10-29 10:24:4877 mojo::PendingReceiver<network::mojom::ProxyResolvingSocketFactory>
78 receiver);
Helen Li5f3d96a2018-08-10 20:37:2479
Maks Orlovichd6f27e52018-06-05 16:14:3580 // Like URLLoaderFactory, but wrapped inside SharedURLLoaderFactory
Yi Su378627d2018-08-24 22:51:5781 virtual scoped_refptr<network::SharedURLLoaderFactory>
82 GetSharedURLLoaderFactory();
Maks Orlovichd6f27e52018-06-05 16:14:3583
sdefresneb30864ac2014-11-21 12:40:5284 // Safely cast a base::SupportsUserData to a BrowserState. Returns nullptr
85 // if |supports_user_data| is not a BrowserState.
86 static BrowserState* FromSupportsUserData(
87 base::SupportsUserData* supports_user_data);
88
Takashi Toyoshimacd413b42019-04-10 20:33:4689 // Updates |cors_exempt_header_list| field of the given |param| to register
90 // headers that are used in content for special purpose and should not be
91 // blocked by CORS checks.
92 virtual void UpdateCorsExemptHeader(
93 network::mojom::NetworkContextParams* params) {}
94
Robbie Gibson0abc1372020-05-15 11:29:2795 // Returns the current cookie blocking mode for this browser state.
96 CookieBlockingMode GetCookieBlockingMode() const;
97
98 // Sets the cookie blocking mode for this browser state. This will only affect
99 // WebStates that are loaded after this mode is set. WebStates with live web
100 // content will not have the mode correctly setup until they are reloaded.
Robbie Gibson283c9b82020-06-08 20:35:02101 // Some tasks here may be asynchronous, so |callback| will be called after
102 // the cookie blocking mode is set correctly. This may happen immediately.
103 void SetCookieBlockingMode(CookieBlockingMode cookie_blocking_mode,
104 base::OnceClosure callback);
Robbie Gibson0abc1372020-05-15 11:29:27105
sdefresnea010b6d2014-11-12 09:32:20106 protected:
107 BrowserState();
stuartmorganf0e19f912015-04-29 06:01:01108
109 private:
110 friend class URLDataManagerIOS;
111 friend class URLRequestChromeJob;
112
113 // Returns the URLDataManagerIOSBackend instance associated with this
114 // BrowserState, creating it if necessary. Should only be called on the IO
115 // thread.
116 // Not intended for usage outside of //web.
117 URLDataManagerIOSBackend* GetURLDataManagerIOSBackendOnIOThread();
118
Reilly Grantd055e32c2018-08-15 00:01:18119 void CreateNetworkContextIfNecessary();
Helen Li5f3d96a2018-08-10 20:37:24120
Julie Jeongeun Kim1b8bfaf2019-10-28 10:55:52121 mojo::Remote<network::mojom::URLLoaderFactory> url_loader_factory_;
Julie Jeongeun Kimc0827552019-08-27 03:19:37122 mojo::Remote<network::mojom::CookieManager> cookie_manager_;
ssid9b9d6332019-08-08 17:48:22123 std::unique_ptr<leveldb_proto::ProtoDatabaseProvider>
124 proto_database_provider_;
Maks Orlovichd6f27e52018-06-05 16:14:35125 scoped_refptr<network::WeakWrapperSharedURLLoaderFactory>
126 shared_url_loader_factory_;
Julie Jeongeun Kimbd33cf02019-09-12 04:56:23127 mojo::Remote<network::mojom::NetworkContext> network_context_;
Matt Menke1f2fb3732018-03-09 19:14:47128
129 // Owns the network::NetworkContext that backs |url_loader_factory_|. Created
130 // on the UI thread, destroyed on the IO thread.
131 std::unique_ptr<NetworkContextOwner> network_context_owner_;
John Abd-El-Malek07a93f12018-02-08 19:28:25132
stuartmorganf0e19f912015-04-29 06:01:01133 // The URLDataManagerIOSBackend instance associated with this BrowserState.
134 // Created and destroyed on the IO thread, and should be accessed only from
135 // the IO thread.
136 URLDataManagerIOSBackend* url_data_manager_ios_backend_;
Robbie Gibson0abc1372020-05-15 11:29:27137
138 CookieBlockingMode cookie_blocking_mode_;
sdefresnea010b6d2014-11-12 09:32:20139};
140
141} // namespace web
142
143#endif // IOS_WEB_PUBLIC_BROWSER_STATE_H_