blob: 505729904fe4a4020f52657698f0d3ad70376ef7 [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"
[email protected]c38831a12011-10-28 12:44:4917#include "content/public/browser/browser_thread.h"
[email protected]6bd30072013-02-08 18:17:1118#include "content/public/browser/storage_partition.h"
19#include "content/public/common/content_switches.h"
[email protected]de7d61ff2013-08-20 11:30:4120#include "content/shell/browser/shell_download_manager_delegate.h"
mlamouri4e372022015-03-29 14:51:0621#include "content/shell/browser/shell_permission_manager.h"
[email protected]b7c504c2013-05-07 14:42:1222#include "content/shell/common/shell_switches.h"
nsatragnodb7b65c642016-02-16 20:14:0223#include "content/test/mock_background_sync_controller.h"
[email protected]b0f146f2011-09-15 22:14:2524
25#if defined(OS_WIN)
26#include "base/base_paths_win.h"
[email protected]5cba3bf2012-01-14 02:40:3527#elif defined(OS_LINUX)
28#include "base/nix/xdg_util.h"
[email protected]80ec0b72012-03-22 22:45:2729#elif defined(OS_MACOSX)
30#include "base/base_paths_mac.h"
[email protected]b0f146f2011-09-15 22:14:2531#endif
32
[email protected]810ddc52012-01-24 01:00:3533namespace content {
34
hanxi3328d992014-10-09 13:27:1135ShellBrowserContext::ShellResourceContext::ShellResourceContext()
36 : getter_(NULL) {
37}
[email protected]6bd30072013-02-08 18:17:1138
hanxi3328d992014-10-09 13:27:1139ShellBrowserContext::ShellResourceContext::~ShellResourceContext() {
40}
[email protected]6bd30072013-02-08 18:17:1141
hanxi3328d992014-10-09 13:27:1142net::HostResolver*
43ShellBrowserContext::ShellResourceContext::GetHostResolver() {
44 CHECK(getter_);
45 return getter_->host_resolver();
46}
[email protected]6bd30072013-02-08 18:17:1147
hanxi3328d992014-10-09 13:27:1148net::URLRequestContext*
49ShellBrowserContext::ShellResourceContext::GetRequestContext() {
50 CHECK(getter_);
51 return getter_->GetURLRequestContext();
52}
[email protected]6bd30072013-02-08 18:17:1153
[email protected]d5869bf2013-07-03 16:21:4754ShellBrowserContext::ShellBrowserContext(bool off_the_record,
55 net::NetLog* net_log)
hanxi3328d992014-10-09 13:27:1156 : resource_context_(new ShellResourceContext),
mkwstd993d06a2014-10-10 11:44:3857 ignore_certificate_errors_(false),
hanxi3328d992014-10-09 13:27:1158 off_the_record_(off_the_record),
[email protected]d5869bf2013-07-03 16:21:4759 net_log_(net_log),
hanxi3328d992014-10-09 13:27:1160 guest_manager_(NULL) {
[email protected]11a65b692012-03-30 11:29:1661 InitWhileIOAllowed();
[email protected]b0f146f2011-09-15 22:14:2562}
63
64ShellBrowserContext::~ShellBrowserContext() {
[email protected]59383c782013-04-17 16:43:2765 if (resource_context_) {
[email protected]e99ca5112011-09-26 17:22:5466 BrowserThread::DeleteSoon(
67 BrowserThread::IO, FROM_HERE, resource_context_.release());
68 }
[email protected]b0f146f2011-09-15 22:14:2569}
70
[email protected]11a65b692012-03-30 11:29:1671void ShellBrowserContext::InitWhileIOAllowed() {
avi83883c82014-12-23 00:08:4972 base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess();
mkwstd993d06a2014-10-10 11:44:3873 if (cmd_line->HasSwitch(switches::kIgnoreCertificateErrors))
[email protected]c2dad292012-09-07 21:27:3574 ignore_certificate_errors_ = true;
[email protected]e1cf85a22012-08-17 22:39:2375 if (cmd_line->HasSwitch(switches::kContentShellDataPath)) {
76 path_ = cmd_line->GetSwitchValuePath(switches::kContentShellDataPath);
erge69130f52016-03-02 00:13:2877 BrowserContext::Initialize(this, path_);
[email protected]e1cf85a22012-08-17 22:39:2378 return;
79 }
[email protected]b0f146f2011-09-15 22:14:2580#if defined(OS_WIN)
[email protected]e99ca5112011-09-26 17:22:5481 CHECK(PathService::Get(base::DIR_LOCAL_APP_DATA, &path_));
82 path_ = path_.Append(std::wstring(L"content_shell"));
[email protected]5cba3bf2012-01-14 02:40:3583#elif defined(OS_LINUX)
dcheng6003e0b2016-04-09 18:42:3484 std::unique_ptr<base::Environment> env(base::Environment::Create());
[email protected]d30a36f2013-02-07 04:16:2685 base::FilePath config_dir(
[email protected]9528c9a2012-06-13 23:20:2286 base::nix::GetXDGDirectory(env.get(),
87 base::nix::kXdgConfigHomeEnvVar,
88 base::nix::kDotConfigDir));
[email protected]5cba3bf2012-01-14 02:40:3589 path_ = config_dir.Append("content_shell");
[email protected]80ec0b72012-03-22 22:45:2790#elif defined(OS_MACOSX)
91 CHECK(PathService::Get(base::DIR_APP_DATA, &path_));
92 path_ = path_.Append("Chromium Content Shell");
[email protected]70a7f1192012-06-08 01:31:3493#elif defined(OS_ANDROID)
[email protected]c3bf7522013-03-18 22:11:4894 CHECK(PathService::Get(base::DIR_ANDROID_APP_DATA, &path_));
[email protected]70a7f1192012-06-08 01:31:3495 path_ = path_.Append(FILE_PATH_LITERAL("content_shell"));
[email protected]b0f146f2011-09-15 22:14:2596#else
97 NOTIMPLEMENTED();
98#endif
99
[email protected]7567484142013-07-11 17:36:07100 if (!base::PathExists(path_))
[email protected]426d1c92013-12-03 20:08:54101 base::CreateDirectory(path_);
erge69130f52016-03-02 00:13:28102 BrowserContext::Initialize(this, path_);
[email protected]11a65b692012-03-30 11:29:16103}
[email protected]b0f146f2011-09-15 22:14:25104
dcheng6003e0b2016-04-09 18:42:34105std::unique_ptr<ZoomLevelDelegate> ShellBrowserContext::CreateZoomLevelDelegate(
wjmacleancaa7d6d2014-11-12 16:42:11106 const base::FilePath&) {
dcheng6003e0b2016-04-09 18:42:34107 return std::unique_ptr<ZoomLevelDelegate>();
wjmacleancaa7d6d2014-11-12 16:42:11108}
109
[email protected]4251165a2013-07-17 04:33:40110base::FilePath ShellBrowserContext::GetPath() const {
[email protected]e99ca5112011-09-26 17:22:54111 return path_;
[email protected]b0f146f2011-09-15 22:14:25112}
113
[email protected]27d6e852012-03-02 21:31:32114bool ShellBrowserContext::IsOffTheRecord() const {
[email protected]71d504f2012-07-25 17:15:28115 return off_the_record_;
[email protected]b0f146f2011-09-15 22:14:25116}
117
[email protected]b441a8492012-06-06 14:55:57118DownloadManagerDelegate* ShellBrowserContext::GetDownloadManagerDelegate() {
[email protected]fc72bb12013-06-02 21:13:46119 if (!download_manager_delegate_.get()) {
[email protected]7cef82172013-12-17 06:58:37120 download_manager_delegate_.reset(new ShellDownloadManagerDelegate());
mkwstd993d06a2014-10-10 11:44:38121 download_manager_delegate_->SetDownloadManager(
122 BrowserContext::GetDownloadManager(this));
[email protected]59002092012-08-27 19:42:56123 }
[email protected]08c92ac2012-08-21 23:41:40124
[email protected]b441a8492012-06-06 14:55:57125 return download_manager_delegate_.get();
[email protected]b0f146f2011-09-15 22:14:25126}
127
[email protected]b0f146f2011-09-15 22:14:25128net::URLRequestContextGetter* ShellBrowserContext::GetRequestContext() {
[email protected]6bd30072013-02-08 18:17:11129 return GetDefaultStoragePartition(this)->GetURLRequestContext();
130}
131
mkwst94388f792014-10-16 07:36:52132ShellURLRequestContextGetter*
133ShellBrowserContext::CreateURLRequestContextGetter(
[email protected]7571263c2014-03-10 22:57:09134 ProtocolHandlerMap* protocol_handlers,
[email protected]3b90aab2014-05-30 17:56:15135 URLRequestInterceptorScopedVector request_interceptors) {
mkwst94388f792014-10-16 07:36:52136 return new ShellURLRequestContextGetter(
dchengf63a1252015-12-26 20:43:13137 ignore_certificate_errors_, GetPath(),
skyostilabeb69ff2016-02-25 10:52:36138 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO),
139 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE),
dchengf63a1252015-12-26 20:43:13140 protocol_handlers, std::move(request_interceptors), net_log_);
mkwst94388f792014-10-16 07:36:52141}
142
143net::URLRequestContextGetter* ShellBrowserContext::CreateRequestContext(
144 ProtocolHandlerMap* protocol_handlers,
145 URLRequestInterceptorScopedVector request_interceptors) {
146 DCHECK(!url_request_getter_.get());
147 url_request_getter_ = CreateURLRequestContextGetter(
dchengf63a1252015-12-26 20:43:13148 protocol_handlers, std::move(request_interceptors));
apavlov297746b2014-10-10 08:25:26149 resource_context_->set_url_request_context_getter(url_request_getter_.get());
[email protected]6bd30072013-02-08 18:17:11150 return url_request_getter_.get();
[email protected]b0f146f2011-09-15 22:14:25151}
152
153net::URLRequestContextGetter*
[email protected]10705a7b2012-08-21 19:07:08154 ShellBrowserContext::GetMediaRequestContext() {
155 return GetRequestContext();
156}
157
158net::URLRequestContextGetter*
159 ShellBrowserContext::GetMediaRequestContextForRenderProcess(
160 int renderer_child_id) {
[email protected]b0f146f2011-09-15 22:14:25161 return GetRequestContext();
162}
163
[email protected]55c0eca2012-09-15 05:12:34164net::URLRequestContextGetter*
[email protected]10eb28162012-09-18 03:04:09165 ShellBrowserContext::GetMediaRequestContextForStoragePartition(
[email protected]d30a36f2013-02-07 04:16:26166 const base::FilePath& partition_path,
[email protected]27ddfed22012-10-30 23:22:43167 bool in_memory) {
[email protected]10eb28162012-09-18 03:04:09168 return GetRequestContext();
169}
170
171net::URLRequestContextGetter*
[email protected]7571263c2014-03-10 22:57:09172ShellBrowserContext::CreateRequestContextForStoragePartition(
173 const base::FilePath& partition_path,
174 bool in_memory,
175 ProtocolHandlerMap* protocol_handlers,
[email protected]3b90aab2014-05-30 17:56:15176 URLRequestInterceptorScopedVector request_interceptors) {
[email protected]55c0eca2012-09-15 05:12:34177 return NULL;
178}
179
[email protected]df02aca2012-02-09 21:03:20180ResourceContext* ShellBrowserContext::GetResourceContext() {
[email protected]df02aca2012-02-09 21:03:20181 return resource_context_.get();
[email protected]b0f146f2011-09-15 22:14:25182}
183
[email protected]139355f2014-05-11 14:21:28184BrowserPluginGuestManager* ShellBrowserContext::GetGuestManager() {
185 return guest_manager_;
[email protected]24569262014-05-06 03:31:30186}
187
[email protected]cd501a72014-08-22 19:58:31188storage::SpecialStoragePolicy* ShellBrowserContext::GetSpecialStoragePolicy() {
[email protected]55eb70e762012-02-20 17:38:39189 return NULL;
[email protected]b0f146f2011-09-15 22:14:25190}
191
[email protected]c5c89d042014-06-13 14:43:37192PushMessagingService* ShellBrowserContext::GetPushMessagingService() {
193 return NULL;
194}
195
[email protected]c5bbe0e2014-08-01 23:23:30196SSLHostStateDelegate* ShellBrowserContext::GetSSLHostStateDelegate() {
197 return NULL;
198}
199
mlamouri4e372022015-03-29 14:51:06200PermissionManager* ShellBrowserContext::GetPermissionManager() {
201 if (!permission_manager_.get())
202 permission_manager_.reset(new ShellPermissionManager());
203 return permission_manager_.get();
204}
205
jkarlin6f5078ed2015-10-06 15:13:35206BackgroundSyncController* ShellBrowserContext::GetBackgroundSyncController() {
jkarlin428a4a32016-01-08 16:13:24207 if (!background_sync_controller_)
nsatragnodb7b65c642016-02-16 20:14:02208 background_sync_controller_.reset(new MockBackgroundSyncController());
jkarlin428a4a32016-01-08 16:13:24209 return background_sync_controller_.get();
jkarlin6f5078ed2015-10-06 15:13:35210}
211
[email protected]b0f146f2011-09-15 22:14:25212} // namespace content