1 // Copyright 2018 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 5 #ifndef HEADLESS_LIB_BROWSER_HEADLESS_REQUEST_CONTEXT_MANAGER_H_ 6 #define HEADLESS_LIB_BROWSER_HEADLESS_REQUEST_CONTEXT_MANAGER_H_ 7 8 #include "base/files/file_path.h" 9 #include "base/macros.h" 10 #include "base/memory/ref_counted.h" 11 #include "build/build_config.h" 12 #include "content/public/browser/browser_context.h" 13 #include "mojo/public/cpp/bindings/pending_remote.h" 14 #include "mojo/public/cpp/bindings/remote.h" 15 #include "services/network/public/mojom/network_context.mojom.h" 16 #include "services/network/public/mojom/network_service.mojom.h" 17 18 #include <string> 19 20 namespace content { 21 class ResourceContext; 22 } 23 24 namespace headless { 25 26 class HeadlessBrowserContextOptions; 27 class HeadlessProxyConfigMonitor; 28 29 class HeadlessRequestContextManager { 30 public: 31 static std::unique_ptr<HeadlessRequestContextManager> CreateSystemContext( 32 const HeadlessBrowserContextOptions* options); 33 34 HeadlessRequestContextManager(const HeadlessBrowserContextOptions* options, 35 base::FilePath user_data_path); 36 ~HeadlessRequestContextManager(); 37 38 void ConfigureNetworkContextParams( 39 bool in_memory, 40 const base::FilePath& relative_partition_path, 41 ::network::mojom::NetworkContextParams* network_context_params, 42 ::network::mojom::CertVerifierCreationParams* 43 cert_verifier_creation_params); 44 GetResourceContext()45 content::ResourceContext* GetResourceContext() { 46 return resource_context_.get(); 47 } 48 49 private: 50 void ConfigureNetworkContextParamsInternal( 51 ::network::mojom::NetworkContextParams* network_context_params, 52 ::network::mojom::CertVerifierCreationParams* 53 cert_verifier_creation_params); 54 55 const bool cookie_encryption_enabled_; 56 57 base::FilePath user_data_path_; 58 std::string accept_language_; 59 std::string user_agent_; 60 std::unique_ptr<net::ProxyConfig> proxy_config_; 61 std::unique_ptr<HeadlessProxyConfigMonitor> proxy_config_monitor_; 62 63 mojo::PendingRemote<::network::mojom::NetworkContext> system_context_; 64 std::unique_ptr<content::ResourceContext> resource_context_; 65 66 DISALLOW_COPY_AND_ASSIGN(HeadlessRequestContextManager); 67 }; 68 69 } // namespace headless 70 71 #endif // HEADLESS_LIB_BROWSER_HEADLESS_REQUEST_CONTEXT_MANAGER_H_ 72