1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
|
// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "content/shell/browser/shell_browser_context.h"
#include <memory>
#include <utility>
#include "base/command_line.h"
#include "base/environment.h"
#include "base/files/file_util.h"
#include "base/functional/bind.h"
#include "base/path_service.h"
#include "base/threading/thread.h"
#include "build/build_config.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "components/keyed_service/core/simple_dependency_manager.h"
#include "components/keyed_service/core/simple_factory_key.h"
#include "components/keyed_service/core/simple_key_map.h"
#include "components/network_session_configurator/common/network_switches.h"
#include "components/origin_trials/browser/leveldb_persistence_provider.h"
#include "components/origin_trials/browser/origin_trials.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/origin_trials_controller_delegate.h"
#include "content/public/browser/storage_partition.h"
#include "content/public/common/content_switches.h"
#include "content/shell/browser/shell_content_browser_client.h"
#include "content/shell/browser/shell_content_index_provider.h"
#include "content/shell/browser/shell_download_manager_delegate.h"
#include "content/shell/browser/shell_permission_manager.h"
#include "content/shell/common/shell_paths.h"
#include "content/shell/common/shell_switches.h"
#include "content/test/mock_background_sync_controller.h"
#include "content/test/mock_reduce_accept_language_controller_delegate.h"
#include "third_party/blink/public/common/origin_trials/trial_token_validator.h"
namespace content {
ShellBrowserContext::ShellBrowserContext(bool off_the_record,
bool delay_services_creation)
: off_the_record_(off_the_record) {
InitWhileIOAllowed();
#if BUILDFLAG(IS_WIN)
base::SetExtraNoExecuteAllowedPath(SHELL_DIR_USER_DATA);
#endif // BUILDFLAG(IS_WIN)
if (!delay_services_creation) {
BrowserContextDependencyManager::GetInstance()
->CreateBrowserContextServices(this);
}
}
ShellBrowserContext::~ShellBrowserContext() {
NotifyWillBeDestroyed();
// The SimpleDependencyManager should always be passed after the
// BrowserContextDependencyManager. This is because the KeyedService instances
// in the BrowserContextDependencyManager's dependency graph can depend on the
// ones in the SimpleDependencyManager's graph.
DependencyManager::PerformInterlockedTwoPhaseShutdown(
BrowserContextDependencyManager::GetInstance(), this,
SimpleDependencyManager::GetInstance(), key_.get());
SimpleKeyMap::GetInstance()->Dissociate(this);
ShutdownStoragePartitions();
}
void ShellBrowserContext::InitWhileIOAllowed() {
base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess();
if (cmd_line->HasSwitch(switches::kIgnoreCertificateErrors))
ignore_certificate_errors_ = true;
CHECK(base::PathService::Get(SHELL_DIR_USER_DATA, &path_));
FinishInitWhileIOAllowed();
}
void ShellBrowserContext::FinishInitWhileIOAllowed() {
key_ = std::make_unique<SimpleFactoryKey>(path_, off_the_record_);
SimpleKeyMap::GetInstance()->Associate(this, key_.get());
}
std::unique_ptr<ZoomLevelDelegate> ShellBrowserContext::CreateZoomLevelDelegate(
const base::FilePath&) {
return nullptr;
}
base::FilePath ShellBrowserContext::GetPath() {
return path_;
}
bool ShellBrowserContext::IsOffTheRecord() {
return off_the_record_;
}
DownloadManagerDelegate* ShellBrowserContext::GetDownloadManagerDelegate() {
if (!download_manager_delegate_.get()) {
download_manager_delegate_ =
std::make_unique<ShellDownloadManagerDelegate>();
download_manager_delegate_->SetDownloadManager(GetDownloadManager());
}
return download_manager_delegate_.get();
}
BrowserPluginGuestManager* ShellBrowserContext::GetGuestManager() {
return nullptr;
}
storage::SpecialStoragePolicy* ShellBrowserContext::GetSpecialStoragePolicy() {
return nullptr;
}
PlatformNotificationService*
ShellBrowserContext::GetPlatformNotificationService() {
return nullptr;
}
PushMessagingService* ShellBrowserContext::GetPushMessagingService() {
return nullptr;
}
StorageNotificationService*
ShellBrowserContext::GetStorageNotificationService() {
return nullptr;
}
SSLHostStateDelegate* ShellBrowserContext::GetSSLHostStateDelegate() {
return nullptr;
}
PermissionControllerDelegate*
ShellBrowserContext::GetPermissionControllerDelegate() {
if (!permission_manager_.get())
permission_manager_ = std::make_unique<ShellPermissionManager>();
return permission_manager_.get();
}
ClientHintsControllerDelegate*
ShellBrowserContext::GetClientHintsControllerDelegate() {
return client_hints_controller_delegate_;
}
BackgroundFetchDelegate* ShellBrowserContext::GetBackgroundFetchDelegate() {
return nullptr;
}
BackgroundSyncController* ShellBrowserContext::GetBackgroundSyncController() {
if (!background_sync_controller_) {
background_sync_controller_ =
std::make_unique<MockBackgroundSyncController>();
}
return background_sync_controller_.get();
}
BrowsingDataRemoverDelegate*
ShellBrowserContext::GetBrowsingDataRemoverDelegate() {
return nullptr;
}
ContentIndexProvider* ShellBrowserContext::GetContentIndexProvider() {
if (!content_index_provider_)
content_index_provider_ = std::make_unique<ShellContentIndexProvider>();
return content_index_provider_.get();
}
ReduceAcceptLanguageControllerDelegate*
ShellBrowserContext::GetReduceAcceptLanguageControllerDelegate() {
if (!reduce_accept_lang_controller_delegate_) {
reduce_accept_lang_controller_delegate_ =
std::make_unique<MockReduceAcceptLanguageControllerDelegate>(
GetShellLanguage());
}
return reduce_accept_lang_controller_delegate_.get();
}
OriginTrialsControllerDelegate*
ShellBrowserContext::GetOriginTrialsControllerDelegate() {
if (!origin_trials_controller_delegate_) {
origin_trials_controller_delegate_ =
std::make_unique<origin_trials::OriginTrials>(
std::make_unique<origin_trials::LevelDbPersistenceProvider>(
GetPath(),
GetDefaultStoragePartition()->GetProtoDatabaseProvider()),
std::make_unique<blink::TrialTokenValidator>());
}
return origin_trials_controller_delegate_.get();
}
} // namespace content
|