blob: 870e9233b5fd8883c99ac4b441510047bb62ee28 [file] [log] [blame]
[email protected]de7d61ff2013-08-20 11:30:411// Copyright 2013 The Chromium Authors. All rights reserved.
[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
dchengf63a1252015-12-26 20:43:137#include <utility>
8
[email protected]037edb52011-11-15 21:14:069#include "base/bind.h"
[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"
[email protected]b0f146f2011-09-15 22:14:2513#include "base/logging.h"
14#include "base/path_service.h"
[email protected]2e5b60a22011-11-28 15:56:4115#include "base/threading/thread.h"
avi66a07722015-12-25 23:38:1216#include "build/build_config.h"
juliatuttleca57a11b2016-11-15 19:07:5317#include "components/keyed_service/content/browser_context_dependency_manager.h"
mmenke68a50212017-06-12 20:20:3118#include "components/network_session_configurator/common/network_switches.h"
[email protected]c38831a12011-10-28 12:44:4919#include "content/public/browser/browser_thread.h"
[email protected]6bd30072013-02-08 18:17:1120#include "content/public/browser/storage_partition.h"
21#include "content/public/common/content_switches.h"
[email protected]de7d61ff2013-08-20 11:30:4122#include "content/shell/browser/shell_download_manager_delegate.h"
mlamouri4e372022015-03-29 14:51:0623#include "content/shell/browser/shell_permission_manager.h"
[email protected]b7c504c2013-05-07 14:42:1224#include "content/shell/common/shell_switches.h"
nsatragnodb7b65c642016-02-16 20:14:0225#include "content/test/mock_background_sync_controller.h"
[email protected]b0f146f2011-09-15 22:14:2526
27#if defined(OS_WIN)
28#include "base/base_paths_win.h"
[email protected]5cba3bf2012-01-14 02:40:3529#elif defined(OS_LINUX)
30#include "base/nix/xdg_util.h"
[email protected]80ec0b72012-03-22 22:45:2731#elif defined(OS_MACOSX)
32#include "base/base_paths_mac.h"
[email protected]b0f146f2011-09-15 22:14:2533#endif
34
[email protected]810ddc52012-01-24 01:00:3535namespace content {
36
hanxi3328d992014-10-09 13:27:1137ShellBrowserContext::ShellResourceContext::ShellResourceContext()
38 : getter_(NULL) {
39}
[email protected]6bd30072013-02-08 18:17:1140
hanxi3328d992014-10-09 13:27:1141ShellBrowserContext::ShellResourceContext::~ShellResourceContext() {
42}
[email protected]6bd30072013-02-08 18:17:1143
hanxi3328d992014-10-09 13:27:1144net::HostResolver*
45ShellBrowserContext::ShellResourceContext::GetHostResolver() {
46 CHECK(getter_);
47 return getter_->host_resolver();
48}
[email protected]6bd30072013-02-08 18:17:1149
hanxi3328d992014-10-09 13:27:1150net::URLRequestContext*
51ShellBrowserContext::ShellResourceContext::GetRequestContext() {
52 CHECK(getter_);
53 return getter_->GetURLRequestContext();
54}
[email protected]6bd30072013-02-08 18:17:1155
[email protected]d5869bf2013-07-03 16:21:4756ShellBrowserContext::ShellBrowserContext(bool off_the_record,
57 net::NetLog* net_log)
hanxi3328d992014-10-09 13:27:1158 : resource_context_(new ShellResourceContext),
mkwstd993d06a2014-10-10 11:44:3859 ignore_certificate_errors_(false),
hanxi3328d992014-10-09 13:27:1160 off_the_record_(off_the_record),
[email protected]d5869bf2013-07-03 16:21:4761 net_log_(net_log),
hanxi3328d992014-10-09 13:27:1162 guest_manager_(NULL) {
[email protected]11a65b692012-03-30 11:29:1663 InitWhileIOAllowed();
juliatuttleca57a11b2016-11-15 19:07:5364 BrowserContextDependencyManager::GetInstance()->
65 CreateBrowserContextServices(this);
[email protected]b0f146f2011-09-15 22:14:2566}
67
68ShellBrowserContext::~ShellBrowserContext() {
juliatuttleca57a11b2016-11-15 19:07:5369 BrowserContextDependencyManager::GetInstance()->
70 DestroyBrowserContextServices(this);
jam21e62ae2017-03-21 19:57:4871 // Need to destruct the ResourceContext before posting tasks which may delete
72 // the URLRequestContext because ResourceContext's destructor will remove any
73 // outstanding request while URLRequestContext's destructor ensures that there
74 // are no more outstanding requests.
[email protected]59383c782013-04-17 16:43:2775 if (resource_context_) {
[email protected]e99ca5112011-09-26 17:22:5476 BrowserThread::DeleteSoon(
77 BrowserThread::IO, FROM_HERE, resource_context_.release());
78 }
jam21e62ae2017-03-21 19:57:4879 ShutdownStoragePartitions();
[email protected]b0f146f2011-09-15 22:14:2580}
81
[email protected]11a65b692012-03-30 11:29:1682void ShellBrowserContext::InitWhileIOAllowed() {
avi83883c82014-12-23 00:08:4983 base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess();
mkwstd993d06a2014-10-10 11:44:3884 if (cmd_line->HasSwitch(switches::kIgnoreCertificateErrors))
[email protected]c2dad292012-09-07 21:27:3585 ignore_certificate_errors_ = true;
[email protected]e1cf85a22012-08-17 22:39:2386 if (cmd_line->HasSwitch(switches::kContentShellDataPath)) {
87 path_ = cmd_line->GetSwitchValuePath(switches::kContentShellDataPath);
michaelpg49a54b592016-10-04 02:07:2188 if (base::DirectoryExists(path_) || base::CreateDirectory(path_)) {
89 // BrowserContext needs an absolute path, which we would normally get via
90 // PathService. In this case, manually ensure the path is absolute.
91 if (!path_.IsAbsolute())
92 path_ = base::MakeAbsoluteFilePath(path_);
93 if (!path_.empty()) {
94 BrowserContext::Initialize(this, path_);
95 return;
96 }
97 } else {
98 LOG(WARNING) << "Unable to create data-path directory: " << path_.value();
99 }
[email protected]e1cf85a22012-08-17 22:39:23100 }
michaelpg49a54b592016-10-04 02:07:21101
[email protected]b0f146f2011-09-15 22:14:25102#if defined(OS_WIN)
[email protected]e99ca5112011-09-26 17:22:54103 CHECK(PathService::Get(base::DIR_LOCAL_APP_DATA, &path_));
104 path_ = path_.Append(std::wstring(L"content_shell"));
[email protected]5cba3bf2012-01-14 02:40:35105#elif defined(OS_LINUX)
dcheng6003e0b2016-04-09 18:42:34106 std::unique_ptr<base::Environment> env(base::Environment::Create());
[email protected]d30a36f2013-02-07 04:16:26107 base::FilePath config_dir(
[email protected]9528c9a2012-06-13 23:20:22108 base::nix::GetXDGDirectory(env.get(),
109 base::nix::kXdgConfigHomeEnvVar,
110 base::nix::kDotConfigDir));
[email protected]5cba3bf2012-01-14 02:40:35111 path_ = config_dir.Append("content_shell");
[email protected]80ec0b72012-03-22 22:45:27112#elif defined(OS_MACOSX)
113 CHECK(PathService::Get(base::DIR_APP_DATA, &path_));
114 path_ = path_.Append("Chromium Content Shell");
[email protected]70a7f1192012-06-08 01:31:34115#elif defined(OS_ANDROID)
[email protected]c3bf75252013-03-18 22:11:48116 CHECK(PathService::Get(base::DIR_ANDROID_APP_DATA, &path_));
[email protected]70a7f1192012-06-08 01:31:34117 path_ = path_.Append(FILE_PATH_LITERAL("content_shell"));
[email protected]b0f146f2011-09-15 22:14:25118#else
119 NOTIMPLEMENTED();
120#endif
121
[email protected]7567484142013-07-11 17:36:07122 if (!base::PathExists(path_))
[email protected]426d1c92013-12-03 20:08:54123 base::CreateDirectory(path_);
erge69130f52016-03-02 00:13:28124 BrowserContext::Initialize(this, path_);
[email protected]11a65b692012-03-30 11:29:16125}
[email protected]b0f146f2011-09-15 22:14:25126
mcnee336ea2c2017-05-23 22:50:59127#if !defined(OS_ANDROID)
dcheng6003e0b2016-04-09 18:42:34128std::unique_ptr<ZoomLevelDelegate> ShellBrowserContext::CreateZoomLevelDelegate(
wjmacleancaa7d6d2014-11-12 16:42:11129 const base::FilePath&) {
dcheng6003e0b2016-04-09 18:42:34130 return std::unique_ptr<ZoomLevelDelegate>();
wjmacleancaa7d6d2014-11-12 16:42:11131}
mcnee336ea2c2017-05-23 22:50:59132#endif // !defined(OS_ANDROID)
wjmacleancaa7d6d2014-11-12 16:42:11133
[email protected]4251165a2013-07-17 04:33:40134base::FilePath ShellBrowserContext::GetPath() const {
[email protected]e99ca5112011-09-26 17:22:54135 return path_;
[email protected]b0f146f2011-09-15 22:14:25136}
137
[email protected]27d6e852012-03-02 21:31:32138bool ShellBrowserContext::IsOffTheRecord() const {
[email protected]71d504f2012-07-25 17:15:28139 return off_the_record_;
[email protected]b0f146f2011-09-15 22:14:25140}
141
[email protected]b441a8492012-06-06 14:55:57142DownloadManagerDelegate* ShellBrowserContext::GetDownloadManagerDelegate() {
[email protected]fc72bb12013-06-02 21:13:46143 if (!download_manager_delegate_.get()) {
[email protected]7cef82172013-12-17 06:58:37144 download_manager_delegate_.reset(new ShellDownloadManagerDelegate());
mkwstd993d06a2014-10-10 11:44:38145 download_manager_delegate_->SetDownloadManager(
146 BrowserContext::GetDownloadManager(this));
[email protected]59002092012-08-27 19:42:56147 }
[email protected]08c92ac2012-08-21 23:41:40148
[email protected]b441a8492012-06-06 14:55:57149 return download_manager_delegate_.get();
[email protected]b0f146f2011-09-15 22:14:25150}
151
mkwst94388f792014-10-16 07:36:52152ShellURLRequestContextGetter*
153ShellBrowserContext::CreateURLRequestContextGetter(
[email protected]7571263c2014-03-10 22:57:09154 ProtocolHandlerMap* protocol_handlers,
[email protected]3b90aab2014-05-30 17:56:15155 URLRequestInterceptorScopedVector request_interceptors) {
mkwst94388f792014-10-16 07:36:52156 return new ShellURLRequestContextGetter(
dchengf63a1252015-12-26 20:43:13157 ignore_certificate_errors_, GetPath(),
thestig529ad8a2016-07-08 20:30:12158 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO),
dchengf63a1252015-12-26 20:43:13159 protocol_handlers, std::move(request_interceptors), net_log_);
mkwst94388f792014-10-16 07:36:52160}
161
162net::URLRequestContextGetter* ShellBrowserContext::CreateRequestContext(
163 ProtocolHandlerMap* protocol_handlers,
164 URLRequestInterceptorScopedVector request_interceptors) {
165 DCHECK(!url_request_getter_.get());
166 url_request_getter_ = CreateURLRequestContextGetter(
dchengf63a1252015-12-26 20:43:13167 protocol_handlers, std::move(request_interceptors));
apavlov297746b2014-10-10 08:25:26168 resource_context_->set_url_request_context_getter(url_request_getter_.get());
[email protected]6bd30072013-02-08 18:17:11169 return url_request_getter_.get();
[email protected]b0f146f2011-09-15 22:14:25170}
171
172net::URLRequestContextGetter*
[email protected]7571263c2014-03-10 22:57:09173ShellBrowserContext::CreateRequestContextForStoragePartition(
174 const base::FilePath& partition_path,
175 bool in_memory,
176 ProtocolHandlerMap* protocol_handlers,
[email protected]3b90aab2014-05-30 17:56:15177 URLRequestInterceptorScopedVector request_interceptors) {
jam2503f932016-04-15 20:08:30178 return nullptr;
179}
180
181net::URLRequestContextGetter*
182 ShellBrowserContext::CreateMediaRequestContext() {
183 DCHECK(url_request_getter_.get());
184 return url_request_getter_.get();
185}
186
187net::URLRequestContextGetter*
188 ShellBrowserContext::CreateMediaRequestContextForStoragePartition(
189 const base::FilePath& partition_path,
190 bool in_memory) {
191 return nullptr;
[email protected]55c0eca2012-09-15 05:12:34192}
193
[email protected]df02aca2012-02-09 21:03:20194ResourceContext* ShellBrowserContext::GetResourceContext() {
[email protected]df02aca2012-02-09 21:03:20195 return resource_context_.get();
[email protected]b0f146f2011-09-15 22:14:25196}
197
[email protected]139355f2014-05-11 14:21:28198BrowserPluginGuestManager* ShellBrowserContext::GetGuestManager() {
199 return guest_manager_;
[email protected]24569262014-05-06 03:31:30200}
201
[email protected]cd501a72014-08-22 19:58:31202storage::SpecialStoragePolicy* ShellBrowserContext::GetSpecialStoragePolicy() {
[email protected]55eb70e762012-02-20 17:38:39203 return NULL;
[email protected]b0f146f2011-09-15 22:14:25204}
205
[email protected]c5c89d042014-06-13 14:43:37206PushMessagingService* ShellBrowserContext::GetPushMessagingService() {
207 return NULL;
208}
209
[email protected]c5bbe0e2014-08-01 23:23:30210SSLHostStateDelegate* ShellBrowserContext::GetSSLHostStateDelegate() {
211 return NULL;
212}
213
mlamouri4e372022015-03-29 14:51:06214PermissionManager* ShellBrowserContext::GetPermissionManager() {
215 if (!permission_manager_.get())
216 permission_manager_.reset(new ShellPermissionManager());
217 return permission_manager_.get();
218}
219
jkarlin6f5078ed2015-10-06 15:13:35220BackgroundSyncController* ShellBrowserContext::GetBackgroundSyncController() {
jkarlin428a4a32016-01-08 16:13:24221 if (!background_sync_controller_)
nsatragnodb7b65c642016-02-16 20:14:02222 background_sync_controller_.reset(new MockBackgroundSyncController());
jkarlin428a4a32016-01-08 16:13:24223 return background_sync_controller_.get();
jkarlin6f5078ed2015-10-06 15:13:35224}
225
msramek86b6bc72017-05-31 12:21:10226BrowsingDataRemoverDelegate*
227ShellBrowserContext::GetBrowsingDataRemoverDelegate() {
228 return nullptr;
229}
230
[email protected]b0f146f2011-09-15 22:14:25231} // namespace content