blob: c16359e93e3f7a8052d6f7d2c5316792dfdcee66 [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"
[email protected]c38831a12011-10-28 12:44:4918#include "content/public/browser/browser_thread.h"
[email protected]6bd30072013-02-08 18:17:1119#include "content/public/browser/storage_partition.h"
20#include "content/public/common/content_switches.h"
[email protected]de7d61ff2013-08-20 11:30:4121#include "content/shell/browser/shell_download_manager_delegate.h"
mlamouri4e372022015-03-29 14:51:0622#include "content/shell/browser/shell_permission_manager.h"
[email protected]b7c504c2013-05-07 14:42:1223#include "content/shell/common/shell_switches.h"
nsatragnodb7b65c642016-02-16 20:14:0224#include "content/test/mock_background_sync_controller.h"
[email protected]b0f146f2011-09-15 22:14:2525
26#if defined(OS_WIN)
27#include "base/base_paths_win.h"
[email protected]5cba3bf2012-01-14 02:40:3528#elif defined(OS_LINUX)
29#include "base/nix/xdg_util.h"
[email protected]80ec0b72012-03-22 22:45:2730#elif defined(OS_MACOSX)
31#include "base/base_paths_mac.h"
[email protected]b0f146f2011-09-15 22:14:2532#endif
33
[email protected]810ddc52012-01-24 01:00:3534namespace content {
35
hanxi3328d992014-10-09 13:27:1136ShellBrowserContext::ShellResourceContext::ShellResourceContext()
37 : getter_(NULL) {
38}
[email protected]6bd30072013-02-08 18:17:1139
hanxi3328d992014-10-09 13:27:1140ShellBrowserContext::ShellResourceContext::~ShellResourceContext() {
41}
[email protected]6bd30072013-02-08 18:17:1142
hanxi3328d992014-10-09 13:27:1143net::HostResolver*
44ShellBrowserContext::ShellResourceContext::GetHostResolver() {
45 CHECK(getter_);
46 return getter_->host_resolver();
47}
[email protected]6bd30072013-02-08 18:17:1148
hanxi3328d992014-10-09 13:27:1149net::URLRequestContext*
50ShellBrowserContext::ShellResourceContext::GetRequestContext() {
51 CHECK(getter_);
52 return getter_->GetURLRequestContext();
53}
[email protected]6bd30072013-02-08 18:17:1154
[email protected]d5869bf2013-07-03 16:21:4755ShellBrowserContext::ShellBrowserContext(bool off_the_record,
56 net::NetLog* net_log)
hanxi3328d992014-10-09 13:27:1157 : resource_context_(new ShellResourceContext),
mkwstd993d06a2014-10-10 11:44:3858 ignore_certificate_errors_(false),
hanxi3328d992014-10-09 13:27:1159 off_the_record_(off_the_record),
[email protected]d5869bf2013-07-03 16:21:4760 net_log_(net_log),
hanxi3328d992014-10-09 13:27:1161 guest_manager_(NULL) {
[email protected]11a65b692012-03-30 11:29:1662 InitWhileIOAllowed();
juliatuttleca57a11b2016-11-15 19:07:5363 BrowserContextDependencyManager::GetInstance()->
64 CreateBrowserContextServices(this);
[email protected]b0f146f2011-09-15 22:14:2565}
66
67ShellBrowserContext::~ShellBrowserContext() {
juliatuttleca57a11b2016-11-15 19:07:5368 BrowserContextDependencyManager::GetInstance()->
69 DestroyBrowserContextServices(this);
kinukof6ed359c2016-07-26 13:27:2170 ShutdownStoragePartitions();
[email protected]59383c782013-04-17 16:43:2771 if (resource_context_) {
[email protected]e99ca5112011-09-26 17:22:5472 BrowserThread::DeleteSoon(
73 BrowserThread::IO, FROM_HERE, resource_context_.release());
74 }
[email protected]b0f146f2011-09-15 22:14:2575}
76
[email protected]11a65b692012-03-30 11:29:1677void ShellBrowserContext::InitWhileIOAllowed() {
avi83883c82014-12-23 00:08:4978 base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess();
mkwstd993d06a2014-10-10 11:44:3879 if (cmd_line->HasSwitch(switches::kIgnoreCertificateErrors))
[email protected]c2dad292012-09-07 21:27:3580 ignore_certificate_errors_ = true;
[email protected]e1cf85a22012-08-17 22:39:2381 if (cmd_line->HasSwitch(switches::kContentShellDataPath)) {
82 path_ = cmd_line->GetSwitchValuePath(switches::kContentShellDataPath);
michaelpg49a54b592016-10-04 02:07:2183 if (base::DirectoryExists(path_) || base::CreateDirectory(path_)) {
84 // BrowserContext needs an absolute path, which we would normally get via
85 // PathService. In this case, manually ensure the path is absolute.
86 if (!path_.IsAbsolute())
87 path_ = base::MakeAbsoluteFilePath(path_);
88 if (!path_.empty()) {
89 BrowserContext::Initialize(this, path_);
90 return;
91 }
92 } else {
93 LOG(WARNING) << "Unable to create data-path directory: " << path_.value();
94 }
[email protected]e1cf85a22012-08-17 22:39:2395 }
michaelpg49a54b592016-10-04 02:07:2196
[email protected]b0f146f2011-09-15 22:14:2597#if defined(OS_WIN)
[email protected]e99ca5112011-09-26 17:22:5498 CHECK(PathService::Get(base::DIR_LOCAL_APP_DATA, &path_));
99 path_ = path_.Append(std::wstring(L"content_shell"));
[email protected]5cba3bf2012-01-14 02:40:35100#elif defined(OS_LINUX)
dcheng6003e0b2016-04-09 18:42:34101 std::unique_ptr<base::Environment> env(base::Environment::Create());
[email protected]d30a36f2013-02-07 04:16:26102 base::FilePath config_dir(
[email protected]9528c9a2012-06-13 23:20:22103 base::nix::GetXDGDirectory(env.get(),
104 base::nix::kXdgConfigHomeEnvVar,
105 base::nix::kDotConfigDir));
[email protected]5cba3bf2012-01-14 02:40:35106 path_ = config_dir.Append("content_shell");
[email protected]80ec0b72012-03-22 22:45:27107#elif defined(OS_MACOSX)
108 CHECK(PathService::Get(base::DIR_APP_DATA, &path_));
109 path_ = path_.Append("Chromium Content Shell");
[email protected]70a7f1192012-06-08 01:31:34110#elif defined(OS_ANDROID)
[email protected]c3bf75252013-03-18 22:11:48111 CHECK(PathService::Get(base::DIR_ANDROID_APP_DATA, &path_));
[email protected]70a7f1192012-06-08 01:31:34112 path_ = path_.Append(FILE_PATH_LITERAL("content_shell"));
[email protected]b0f146f2011-09-15 22:14:25113#else
114 NOTIMPLEMENTED();
115#endif
116
[email protected]7567484142013-07-11 17:36:07117 if (!base::PathExists(path_))
[email protected]426d1c92013-12-03 20:08:54118 base::CreateDirectory(path_);
erge69130f52016-03-02 00:13:28119 BrowserContext::Initialize(this, path_);
[email protected]11a65b692012-03-30 11:29:16120}
[email protected]b0f146f2011-09-15 22:14:25121
dcheng6003e0b2016-04-09 18:42:34122std::unique_ptr<ZoomLevelDelegate> ShellBrowserContext::CreateZoomLevelDelegate(
wjmacleancaa7d6d2014-11-12 16:42:11123 const base::FilePath&) {
dcheng6003e0b2016-04-09 18:42:34124 return std::unique_ptr<ZoomLevelDelegate>();
wjmacleancaa7d6d2014-11-12 16:42:11125}
126
[email protected]4251165a2013-07-17 04:33:40127base::FilePath ShellBrowserContext::GetPath() const {
[email protected]e99ca5112011-09-26 17:22:54128 return path_;
[email protected]b0f146f2011-09-15 22:14:25129}
130
[email protected]27d6e852012-03-02 21:31:32131bool ShellBrowserContext::IsOffTheRecord() const {
[email protected]71d504f2012-07-25 17:15:28132 return off_the_record_;
[email protected]b0f146f2011-09-15 22:14:25133}
134
[email protected]b441a8492012-06-06 14:55:57135DownloadManagerDelegate* ShellBrowserContext::GetDownloadManagerDelegate() {
[email protected]fc72bb12013-06-02 21:13:46136 if (!download_manager_delegate_.get()) {
[email protected]7cef82172013-12-17 06:58:37137 download_manager_delegate_.reset(new ShellDownloadManagerDelegate());
mkwstd993d06a2014-10-10 11:44:38138 download_manager_delegate_->SetDownloadManager(
139 BrowserContext::GetDownloadManager(this));
[email protected]59002092012-08-27 19:42:56140 }
[email protected]08c92ac2012-08-21 23:41:40141
[email protected]b441a8492012-06-06 14:55:57142 return download_manager_delegate_.get();
[email protected]b0f146f2011-09-15 22:14:25143}
144
mkwst94388f792014-10-16 07:36:52145ShellURLRequestContextGetter*
146ShellBrowserContext::CreateURLRequestContextGetter(
[email protected]7571263c2014-03-10 22:57:09147 ProtocolHandlerMap* protocol_handlers,
[email protected]3b90aab2014-05-30 17:56:15148 URLRequestInterceptorScopedVector request_interceptors) {
mkwst94388f792014-10-16 07:36:52149 return new ShellURLRequestContextGetter(
dchengf63a1252015-12-26 20:43:13150 ignore_certificate_errors_, GetPath(),
thestig529ad8a2016-07-08 20:30:12151 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO),
152 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE),
dchengf63a1252015-12-26 20:43:13153 protocol_handlers, std::move(request_interceptors), net_log_);
mkwst94388f792014-10-16 07:36:52154}
155
156net::URLRequestContextGetter* ShellBrowserContext::CreateRequestContext(
157 ProtocolHandlerMap* protocol_handlers,
158 URLRequestInterceptorScopedVector request_interceptors) {
159 DCHECK(!url_request_getter_.get());
160 url_request_getter_ = CreateURLRequestContextGetter(
dchengf63a1252015-12-26 20:43:13161 protocol_handlers, std::move(request_interceptors));
apavlov297746b2014-10-10 08:25:26162 resource_context_->set_url_request_context_getter(url_request_getter_.get());
[email protected]6bd30072013-02-08 18:17:11163 return url_request_getter_.get();
[email protected]b0f146f2011-09-15 22:14:25164}
165
166net::URLRequestContextGetter*
[email protected]7571263c2014-03-10 22:57:09167ShellBrowserContext::CreateRequestContextForStoragePartition(
168 const base::FilePath& partition_path,
169 bool in_memory,
170 ProtocolHandlerMap* protocol_handlers,
[email protected]3b90aab2014-05-30 17:56:15171 URLRequestInterceptorScopedVector request_interceptors) {
jam2503f932016-04-15 20:08:30172 return nullptr;
173}
174
175net::URLRequestContextGetter*
176 ShellBrowserContext::CreateMediaRequestContext() {
177 DCHECK(url_request_getter_.get());
178 return url_request_getter_.get();
179}
180
181net::URLRequestContextGetter*
182 ShellBrowserContext::CreateMediaRequestContextForStoragePartition(
183 const base::FilePath& partition_path,
184 bool in_memory) {
185 return nullptr;
[email protected]55c0eca2012-09-15 05:12:34186}
187
[email protected]df02aca2012-02-09 21:03:20188ResourceContext* ShellBrowserContext::GetResourceContext() {
[email protected]df02aca2012-02-09 21:03:20189 return resource_context_.get();
[email protected]b0f146f2011-09-15 22:14:25190}
191
[email protected]139355f2014-05-11 14:21:28192BrowserPluginGuestManager* ShellBrowserContext::GetGuestManager() {
193 return guest_manager_;
[email protected]24569262014-05-06 03:31:30194}
195
[email protected]cd501a72014-08-22 19:58:31196storage::SpecialStoragePolicy* ShellBrowserContext::GetSpecialStoragePolicy() {
[email protected]55eb70e762012-02-20 17:38:39197 return NULL;
[email protected]b0f146f2011-09-15 22:14:25198}
199
[email protected]c5c89d042014-06-13 14:43:37200PushMessagingService* ShellBrowserContext::GetPushMessagingService() {
201 return NULL;
202}
203
[email protected]c5bbe0e2014-08-01 23:23:30204SSLHostStateDelegate* ShellBrowserContext::GetSSLHostStateDelegate() {
205 return NULL;
206}
207
mlamouri4e372022015-03-29 14:51:06208PermissionManager* ShellBrowserContext::GetPermissionManager() {
209 if (!permission_manager_.get())
210 permission_manager_.reset(new ShellPermissionManager());
211 return permission_manager_.get();
212}
213
jkarlin6f5078ed2015-10-06 15:13:35214BackgroundSyncController* ShellBrowserContext::GetBackgroundSyncController() {
jkarlin428a4a32016-01-08 16:13:24215 if (!background_sync_controller_)
nsatragnodb7b65c642016-02-16 20:14:02216 background_sync_controller_.reset(new MockBackgroundSyncController());
jkarlin428a4a32016-01-08 16:13:24217 return background_sync_controller_.get();
jkarlin6f5078ed2015-10-06 15:13:35218}
219
[email protected]b0f146f2011-09-15 22:14:25220} // namespace content