browser_state.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. // Copyright 2013 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef IOS_WEB_PUBLIC_BROWSER_STATE_H_
  5. #define IOS_WEB_PUBLIC_BROWSER_STATE_H_
  6. #include <memory>
  7. #include "base/supports_user_data.h"
  8. #include "mojo/public/cpp/bindings/pending_receiver.h"
  9. #include "mojo/public/cpp/bindings/remote.h"
  10. #include "services/network/public/mojom/cookie_manager.mojom.h"
  11. #include "services/network/public/mojom/network_context.mojom.h"
  12. #include "services/network/public/mojom/network_service.mojom.h"
  13. #include "services/network/public/mojom/proxy_resolving_socket.mojom.h"
  14. #include "services/network/public/mojom/url_loader_factory.mojom.h"
  15. namespace base {
  16. class FilePath;
  17. }
  18. namespace net {
  19. class URLRequestContextGetter;
  20. }
  21. namespace network {
  22. class SharedURLLoaderFactory;
  23. class WeakWrapperSharedURLLoaderFactory;
  24. } // namespace network
  25. namespace leveldb_proto {
  26. class ProtoDatabaseProvider;
  27. } // namespace leveldb_proto
  28. namespace web {
  29. class CertificatePolicyCache;
  30. class NetworkContextOwner;
  31. class URLDataManagerIOS;
  32. class URLDataManagerIOSBackend;
  33. class URLRequestChromeJob;
  34. // This class holds the context needed for a browsing session.
  35. // It lives on the UI thread. All these methods must only be called on the UI
  36. // thread.
  37. class BrowserState : public base::SupportsUserData {
  38. public:
  39. ~BrowserState() override;
  40. // static
  41. static scoped_refptr<CertificatePolicyCache> GetCertificatePolicyCache(
  42. BrowserState* browser_state);
  43. // Returns whether this BrowserState is incognito. Default is false.
  44. virtual bool IsOffTheRecord() const = 0;
  45. // Returns the path where the BrowserState data is stored.
  46. // Unlike Profile::GetPath(), incognito BrowserState do not share their path
  47. // with their original BrowserState.
  48. virtual base::FilePath GetStatePath() const = 0;
  49. // Returns the request context information associated with this
  50. // BrowserState.
  51. virtual net::URLRequestContextGetter* GetRequestContext() = 0;
  52. // Returns a URLLoaderFactory that is backed by GetRequestContext.
  53. network::mojom::URLLoaderFactory* GetURLLoaderFactory();
  54. // Returns a CookieManager that is backed by GetRequestContext.
  55. network::mojom::CookieManager* GetCookieManager();
  56. // Returns an provider to create ProtoDatabase tied to the profile directory.
  57. leveldb_proto::ProtoDatabaseProvider* GetProtoDatabaseProvider();
  58. // Binds a ProxyResolvingSocketFactory receiver to NetworkContext.
  59. void GetProxyResolvingSocketFactory(
  60. mojo::PendingReceiver<network::mojom::ProxyResolvingSocketFactory>
  61. receiver);
  62. // Like URLLoaderFactory, but wrapped inside SharedURLLoaderFactory
  63. virtual scoped_refptr<network::SharedURLLoaderFactory>
  64. GetSharedURLLoaderFactory();
  65. // Safely cast a base::SupportsUserData to a BrowserState. Returns nullptr
  66. // if |supports_user_data| is not a BrowserState.
  67. static BrowserState* FromSupportsUserData(
  68. base::SupportsUserData* supports_user_data);
  69. // Updates |cors_exempt_header_list| field of the given |param| to register
  70. // headers that are used in content for special purpose and should not be
  71. // blocked by CORS checks.
  72. virtual void UpdateCorsExemptHeader(
  73. network::mojom::NetworkContextParams* params) {}
  74. protected:
  75. BrowserState();
  76. private:
  77. friend class URLDataManagerIOS;
  78. friend class URLRequestChromeJob;
  79. // Returns the URLDataManagerIOSBackend instance associated with this
  80. // BrowserState, creating it if necessary. Should only be called on the IO
  81. // thread.
  82. // Not intended for usage outside of //web.
  83. URLDataManagerIOSBackend* GetURLDataManagerIOSBackendOnIOThread();
  84. void CreateNetworkContextIfNecessary();
  85. mojo::Remote<network::mojom::URLLoaderFactory> url_loader_factory_;
  86. mojo::Remote<network::mojom::CookieManager> cookie_manager_;
  87. std::unique_ptr<leveldb_proto::ProtoDatabaseProvider>
  88. proto_database_provider_;
  89. scoped_refptr<network::WeakWrapperSharedURLLoaderFactory>
  90. shared_url_loader_factory_;
  91. mojo::Remote<network::mojom::NetworkContext> network_context_;
  92. // Owns the network::NetworkContext that backs |url_loader_factory_|. Created
  93. // on the UI thread, destroyed on the IO thread.
  94. std::unique_ptr<NetworkContextOwner> network_context_owner_;
  95. // The URLDataManagerIOSBackend instance associated with this BrowserState.
  96. // Created and destroyed on the IO thread, and should be accessed only from
  97. // the IO thread.
  98. URLDataManagerIOSBackend* url_data_manager_ios_backend_;
  99. };
  100. } // namespace web
  101. #endif // IOS_WEB_PUBLIC_BROWSER_STATE_H_