blob: 2612eb2372de8acab3bc2ba5068fbec2430e33c1 [file] [log] [blame]
Avi Drissman4e1b7bc32022-09-15 14:03:501// Copyright 2013 The Chromium Authors
[email protected]b0f146f2011-09-15 22:14:252// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]de7d61ff2013-08-20 11:30:415#include "content/shell/browser/shell_browser_context.h"
[email protected]b0f146f2011-09-15 22:14:256
Peter Boströmdd7e40ec2021-04-05 20:40:107#include <memory>
dchengf63a1252015-12-26 20:43:138#include <utility>
9
[email protected]2f2b9512012-06-08 17:31:0010#include "base/command_line.h"
[email protected]5cba3bf2012-01-14 02:40:3511#include "base/environment.h"
thestigb7aad54f2014-09-05 18:25:3912#include "base/files/file_util.h"
Avi Drissmanadac21992023-01-11 23:46:3913#include "base/functional/bind.h"
[email protected]b0f146f2011-09-15 22:14:2514#include "base/logging.h"
15#include "base/path_service.h"
[email protected]2e5b60a22011-11-28 15:56:4116#include "base/threading/thread.h"
avi66a07722015-12-25 23:38:1217#include "build/build_config.h"
juliatuttleca57a11b2016-11-15 19:07:5318#include "components/keyed_service/content/browser_context_dependency_manager.h"
Henrique Nakashimadd1cdd12019-04-25 15:47:0419#include "components/keyed_service/core/simple_dependency_manager.h"
Xi Han720a2a22019-05-21 17:39:5920#include "components/keyed_service/core/simple_factory_key.h"
Henrique Nakashima7bb9d522019-04-16 20:57:3621#include "components/keyed_service/core/simple_key_map.h"
mmenke68a50212017-06-12 20:20:3122#include "components/network_session_configurator/common/network_switches.h"
Peter Birk Pakkenbergd927c942022-11-17 14:30:4223#include "components/origin_trials/browser/leveldb_persistence_provider.h"
24#include "components/origin_trials/browser/origin_trials.h"
25#include "components/origin_trials/common/features.h"
Eric Seckler8652dcd52018-09-20 10:42:2826#include "content/public/browser/browser_task_traits.h"
[email protected]c38831a12011-10-28 12:44:4927#include "content/public/browser/browser_thread.h"
Peter Birk Pakkenbergd927c942022-11-17 14:30:4228#include "content/public/browser/origin_trials_controller_delegate.h"
[email protected]6bd30072013-02-08 18:17:1129#include "content/public/browser/storage_partition.h"
30#include "content/public/common/content_switches.h"
Victor Tan10d93aca2022-08-12 16:46:2831#include "content/shell/browser/shell_content_browser_client.h"
danakjdd5bb4ef2020-06-26 23:29:2232#include "content/shell/browser/shell_content_index_provider.h"
[email protected]de7d61ff2013-08-20 11:30:4133#include "content/shell/browser/shell_download_manager_delegate.h"
Christian Biesingerdcca1722022-03-18 15:02:4834#include "content/shell/browser/shell_federated_permission_context.h"
John Abd-El-Malek22763052021-06-15 03:35:5335#include "content/shell/browser/shell_paths.h"
mlamouri4e372022015-03-29 14:51:0636#include "content/shell/browser/shell_permission_manager.h"
[email protected]b7c504c2013-05-07 14:42:1237#include "content/shell/common/shell_switches.h"
nsatragnodb7b65c642016-02-16 20:14:0238#include "content/test/mock_background_sync_controller.h"
Victor Tan10d93aca2022-08-12 16:46:2839#include "content/test/mock_reduce_accept_language_controller_delegate.h"
Peter Birk Pakkenbergd927c942022-11-17 14:30:4240#include "third_party/blink/public/common/origin_trials/trial_token_validator.h"
[email protected]b0f146f2011-09-15 22:14:2541
[email protected]810ddc52012-01-24 01:00:3542namespace content {
43
[email protected]d5869bf2013-07-03 16:21:4744ShellBrowserContext::ShellBrowserContext(bool off_the_record,
Michael Giuffridac55719602018-02-09 17:10:3545 bool delay_services_creation)
Arthur Sonzogniff837582023-12-22 10:05:4546 : off_the_record_(off_the_record) {
[email protected]11a65b692012-03-30 11:29:1647 InitWhileIOAllowed();
Will Harris7ddd8502023-01-10 23:51:3448#if BUILDFLAG(IS_WIN)
49 base::SetExtraNoExecuteAllowedPath(SHELL_DIR_USER_DATA);
50#endif // BUILDFLAG(IS_WIN)
51
Michael Giuffridac55719602018-02-09 17:10:3552 if (!delay_services_creation) {
53 BrowserContextDependencyManager::GetInstance()
54 ->CreateBrowserContextServices(this);
55 }
[email protected]b0f146f2011-09-15 22:14:2556}
57
58ShellBrowserContext::~ShellBrowserContext() {
Lukasz Anforowiczeda637d22021-05-20 00:32:2359 NotifyWillBeDestroyed();
Lukasz Anforowicz58d0dac2018-03-23 15:48:1060
Henrique Nakashimadd1cdd12019-04-25 15:47:0461 // The SimpleDependencyManager should always be passed after the
62 // BrowserContextDependencyManager. This is because the KeyedService instances
63 // in the BrowserContextDependencyManager's dependency graph can depend on the
64 // ones in the SimpleDependencyManager's graph.
65 DependencyManager::PerformInterlockedTwoPhaseShutdown(
66 BrowserContextDependencyManager::GetInstance(), this,
67 SimpleDependencyManager::GetInstance(), key_.get());
Henrique Nakashima7bb9d522019-04-16 20:57:3668
69 SimpleKeyMap::GetInstance()->Dissociate(this);
70
jam21e62ae2017-03-21 19:57:4871 ShutdownStoragePartitions();
[email protected]b0f146f2011-09-15 22:14:2572}
73
[email protected]11a65b692012-03-30 11:29:1674void ShellBrowserContext::InitWhileIOAllowed() {
avi83883c82014-12-23 00:08:4975 base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess();
mkwstd993d06a2014-10-10 11:44:3876 if (cmd_line->HasSwitch(switches::kIgnoreCertificateErrors))
[email protected]c2dad292012-09-07 21:27:3577 ignore_certificate_errors_ = true;
[email protected]e1cf85a22012-08-17 22:39:2378 if (cmd_line->HasSwitch(switches::kContentShellDataPath)) {
79 path_ = cmd_line->GetSwitchValuePath(switches::kContentShellDataPath);
michaelpg49a54b592016-10-04 02:07:2180 if (base::DirectoryExists(path_) || base::CreateDirectory(path_)) {
81 // BrowserContext needs an absolute path, which we would normally get via
82 // PathService. In this case, manually ensure the path is absolute.
83 if (!path_.IsAbsolute())
84 path_ = base::MakeAbsoluteFilePath(path_);
85 if (!path_.empty()) {
Henrique Nakashima7bb9d522019-04-16 20:57:3686 FinishInitWhileIOAllowed();
Will Harrisd5478a02022-08-05 22:21:1087 base::PathService::OverrideAndCreateIfNeeded(
88 SHELL_DIR_USER_DATA, path_, /*is_absolute=*/true, /*create=*/false);
michaelpg49a54b592016-10-04 02:07:2189 return;
90 }
91 } else {
92 LOG(WARNING) << "Unable to create data-path directory: " << path_.value();
93 }
[email protected]e1cf85a22012-08-17 22:39:2394 }
michaelpg49a54b592016-10-04 02:07:2195
John Abd-El-Malek22763052021-06-15 03:35:5396 CHECK(base::PathService::Get(SHELL_DIR_USER_DATA, &path_));
Henrique Nakashima7bb9d522019-04-16 20:57:3697
98 FinishInitWhileIOAllowed();
99}
100
101void ShellBrowserContext::FinishInitWhileIOAllowed() {
Xi Han720a2a22019-05-21 17:39:59102 key_ = std::make_unique<SimpleFactoryKey>(path_, off_the_record_);
Henrique Nakashima7bb9d522019-04-16 20:57:36103 SimpleKeyMap::GetInstance()->Associate(this, key_.get());
[email protected]11a65b692012-03-30 11:29:16104}
[email protected]b0f146f2011-09-15 22:14:25105
dcheng6003e0b2016-04-09 18:42:34106std::unique_ptr<ZoomLevelDelegate> ShellBrowserContext::CreateZoomLevelDelegate(
wjmacleancaa7d6d2014-11-12 16:42:11107 const base::FilePath&) {
Lei Zhangdf291f62021-04-14 17:23:44108 return nullptr;
wjmacleancaa7d6d2014-11-12 16:42:11109}
110
Lucas Furukawa Gadanif45223862019-06-21 23:11:14111base::FilePath ShellBrowserContext::GetPath() {
[email protected]e99ca5112011-09-26 17:22:54112 return path_;
[email protected]b0f146f2011-09-15 22:14:25113}
114
Lucas Furukawa Gadanif45223862019-06-21 23:11:14115bool ShellBrowserContext::IsOffTheRecord() {
[email protected]71d504f2012-07-25 17:15:28116 return off_the_record_;
[email protected]b0f146f2011-09-15 22:14:25117}
118
[email protected]b441a8492012-06-06 14:55:57119DownloadManagerDelegate* ShellBrowserContext::GetDownloadManagerDelegate() {
[email protected]fc72bb12013-06-02 21:13:46120 if (!download_manager_delegate_.get()) {
Peter Boströmdd7e40ec2021-04-05 20:40:10121 download_manager_delegate_ =
122 std::make_unique<ShellDownloadManagerDelegate>();
Lukasz Anforowicz48d83452021-05-12 02:58:20123 download_manager_delegate_->SetDownloadManager(GetDownloadManager());
[email protected]59002092012-08-27 19:42:56124 }
[email protected]08c92ac2012-08-21 23:41:40125
[email protected]b441a8492012-06-06 14:55:57126 return download_manager_delegate_.get();
[email protected]b0f146f2011-09-15 22:14:25127}
128
[email protected]139355f2014-05-11 14:21:28129BrowserPluginGuestManager* ShellBrowserContext::GetGuestManager() {
Kevin McNee6f0513b2020-09-29 19:37:01130 return nullptr;
[email protected]24569262014-05-06 03:31:30131}
132
[email protected]cd501a72014-08-22 19:58:31133storage::SpecialStoragePolicy* ShellBrowserContext::GetSpecialStoragePolicy() {
Ivan Kotenkov2c0d2bb32017-11-01 15:41:28134 return nullptr;
[email protected]b0f146f2011-09-15 22:14:25135}
136
Richard Knoll77b8b2b2021-09-08 09:29:01137PlatformNotificationService*
138ShellBrowserContext::GetPlatformNotificationService() {
139 return nullptr;
140}
141
[email protected]c5c89d042014-06-13 14:43:37142PushMessagingService* ShellBrowserContext::GetPushMessagingService() {
Ivan Kotenkov2c0d2bb32017-11-01 15:41:28143 return nullptr;
[email protected]c5c89d042014-06-13 14:43:37144}
145
Jarryd20733d32019-10-02 23:27:17146StorageNotificationService*
147ShellBrowserContext::GetStorageNotificationService() {
148 return nullptr;
149}
150
[email protected]c5bbe0e2014-08-01 23:23:30151SSLHostStateDelegate* ShellBrowserContext::GetSSLHostStateDelegate() {
Ivan Kotenkov2c0d2bb32017-11-01 15:41:28152 return nullptr;
[email protected]c5bbe0e2014-08-01 23:23:30153}
154
Andrey Lushnikovf3500102018-07-16 19:55:22155PermissionControllerDelegate*
156ShellBrowserContext::GetPermissionControllerDelegate() {
mlamouri4e372022015-03-29 14:51:06157 if (!permission_manager_.get())
Peter Boströmdd7e40ec2021-04-05 20:40:10158 permission_manager_ = std::make_unique<ShellPermissionManager>();
mlamouri4e372022015-03-29 14:51:06159 return permission_manager_.get();
160}
161
Tarun Bansal1ff665c2019-01-09 16:35:52162ClientHintsControllerDelegate*
163ShellBrowserContext::GetClientHintsControllerDelegate() {
Scott Violet3cd8d362020-04-30 22:18:24164 return client_hints_controller_delegate_;
Tarun Bansal1ff665c2019-01-09 16:35:52165}
166
Dan Elphick975213182017-09-22 10:37:47167BackgroundFetchDelegate* ShellBrowserContext::GetBackgroundFetchDelegate() {
168 return nullptr;
169}
170
jkarlin6f5078ed2015-10-06 15:13:35171BackgroundSyncController* ShellBrowserContext::GetBackgroundSyncController() {
Peter Boströmdd7e40ec2021-04-05 20:40:10172 if (!background_sync_controller_) {
173 background_sync_controller_ =
174 std::make_unique<MockBackgroundSyncController>();
175 }
jkarlin428a4a32016-01-08 16:13:24176 return background_sync_controller_.get();
jkarlin6f5078ed2015-10-06 15:13:35177}
178
msramek86b6bc72017-05-31 12:21:10179BrowsingDataRemoverDelegate*
180ShellBrowserContext::GetBrowsingDataRemoverDelegate() {
181 return nullptr;
182}
183
Rayan Kanso4f753a672019-08-12 17:30:07184ContentIndexProvider* ShellBrowserContext::GetContentIndexProvider() {
185 if (!content_index_provider_)
danakjdd5bb4ef2020-06-26 23:29:22186 content_index_provider_ = std::make_unique<ShellContentIndexProvider>();
Rayan Kanso4f753a672019-08-12 17:30:07187 return content_index_provider_.get();
188}
189
Peter Kotwicz153898a2022-05-05 18:48:39190FederatedIdentityApiPermissionContextDelegate*
191ShellBrowserContext::GetFederatedIdentityApiPermissionContext() {
Christian Biesinger4b36fa12023-08-18 01:43:07192 return GetShellFederatedPermissionContext();
Peter Kotwicz153898a2022-05-05 18:48:39193}
194
Zachary Tancef872422023-02-17 14:45:49195FederatedIdentityAutoReauthnPermissionContextDelegate*
196ShellBrowserContext::GetFederatedIdentityAutoReauthnPermissionContext() {
Christian Biesinger4b36fa12023-08-18 01:43:07197 return GetShellFederatedPermissionContext();
Zachary Tan3d1c32c2023-01-31 16:50:54198}
199
Peter Kotwiczc18ea672022-11-30 23:58:27200FederatedIdentityPermissionContextDelegate*
201ShellBrowserContext::GetFederatedIdentityPermissionContext() {
Christian Biesinger4b36fa12023-08-18 01:43:07202 return GetShellFederatedPermissionContext();
203}
204
205ShellFederatedPermissionContext*
206ShellBrowserContext::GetShellFederatedPermissionContext() {
Christian Biesingerdcca1722022-03-18 15:02:48207 if (!federated_permission_context_)
208 federated_permission_context_ =
209 std::make_unique<ShellFederatedPermissionContext>();
210 return federated_permission_context_.get();
211}
212
Victor Tan10d93aca2022-08-12 16:46:28213ReduceAcceptLanguageControllerDelegate*
214ShellBrowserContext::GetReduceAcceptLanguageControllerDelegate() {
215 if (!reduce_accept_lang_controller_delegate_) {
216 reduce_accept_lang_controller_delegate_ =
217 std::make_unique<MockReduceAcceptLanguageControllerDelegate>(
218 GetShellLanguage());
219 }
220 return reduce_accept_lang_controller_delegate_.get();
221}
222
Peter Birk Pakkenbergd927c942022-11-17 14:30:42223OriginTrialsControllerDelegate*
224ShellBrowserContext::GetOriginTrialsControllerDelegate() {
225 if (!origin_trials::features::IsPersistentOriginTrialsEnabled())
226 return nullptr;
227
228 if (!origin_trials_controller_delegate_) {
229 origin_trials_controller_delegate_ =
230 std::make_unique<origin_trials::OriginTrials>(
231 std::make_unique<origin_trials::LevelDbPersistenceProvider>(
232 GetPath(),
233 GetDefaultStoragePartition()->GetProtoDatabaseProvider()),
234 std::make_unique<blink::TrialTokenValidator>());
235 }
236 return origin_trials_controller_delegate_.get();
237}
238
[email protected]b0f146f2011-09-15 22:14:25239} // namespace content