blob: 9f835624181515958f9d46f7292938822e79760c [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
[email protected]037edb52011-11-15 21:14:067#include "base/bind.h"
[email protected]2f2b9512012-06-08 17:31:008#include "base/command_line.h"
[email protected]5cba3bf2012-01-14 02:40:359#include "base/environment.h"
thestigb7aad54f2014-09-05 18:25:3910#include "base/files/file_util.h"
[email protected]b0f146f2011-09-15 22:14:2511#include "base/logging.h"
12#include "base/path_service.h"
[email protected]2e5b60a22011-11-28 15:56:4113#include "base/threading/thread.h"
[email protected]c38831a12011-10-28 12:44:4914#include "content/public/browser/browser_thread.h"
[email protected]6bd30072013-02-08 18:17:1115#include "content/public/browser/storage_partition.h"
16#include "content/public/common/content_switches.h"
[email protected]de7d61ff2013-08-20 11:30:4117#include "content/shell/browser/shell_download_manager_delegate.h"
[email protected]b7c504c2013-05-07 14:42:1218#include "content/shell/common/shell_switches.h"
[email protected]b0f146f2011-09-15 22:14:2519
20#if defined(OS_WIN)
21#include "base/base_paths_win.h"
[email protected]5cba3bf2012-01-14 02:40:3522#elif defined(OS_LINUX)
23#include "base/nix/xdg_util.h"
[email protected]80ec0b72012-03-22 22:45:2724#elif defined(OS_MACOSX)
25#include "base/base_paths_mac.h"
[email protected]b0f146f2011-09-15 22:14:2526#endif
27
[email protected]810ddc52012-01-24 01:00:3528namespace content {
29
hanxi3328d992014-10-09 13:27:1130ShellBrowserContext::ShellResourceContext::ShellResourceContext()
31 : getter_(NULL) {
32}
[email protected]6bd30072013-02-08 18:17:1133
hanxi3328d992014-10-09 13:27:1134ShellBrowserContext::ShellResourceContext::~ShellResourceContext() {
35}
[email protected]6bd30072013-02-08 18:17:1136
hanxi3328d992014-10-09 13:27:1137net::HostResolver*
38ShellBrowserContext::ShellResourceContext::GetHostResolver() {
39 CHECK(getter_);
40 return getter_->host_resolver();
41}
[email protected]6bd30072013-02-08 18:17:1142
hanxi3328d992014-10-09 13:27:1143net::URLRequestContext*
44ShellBrowserContext::ShellResourceContext::GetRequestContext() {
45 CHECK(getter_);
46 return getter_->GetURLRequestContext();
47}
[email protected]6bd30072013-02-08 18:17:1148
[email protected]d5869bf2013-07-03 16:21:4749ShellBrowserContext::ShellBrowserContext(bool off_the_record,
50 net::NetLog* net_log)
hanxi3328d992014-10-09 13:27:1151 : resource_context_(new ShellResourceContext),
mkwstd993d06a2014-10-10 11:44:3852 ignore_certificate_errors_(false),
hanxi3328d992014-10-09 13:27:1153 off_the_record_(off_the_record),
[email protected]d5869bf2013-07-03 16:21:4754 net_log_(net_log),
hanxi3328d992014-10-09 13:27:1155 guest_manager_(NULL) {
[email protected]11a65b692012-03-30 11:29:1656 InitWhileIOAllowed();
[email protected]b0f146f2011-09-15 22:14:2557}
58
59ShellBrowserContext::~ShellBrowserContext() {
[email protected]59383c782013-04-17 16:43:2760 if (resource_context_) {
[email protected]e99ca5112011-09-26 17:22:5461 BrowserThread::DeleteSoon(
62 BrowserThread::IO, FROM_HERE, resource_context_.release());
63 }
[email protected]b0f146f2011-09-15 22:14:2564}
65
[email protected]11a65b692012-03-30 11:29:1666void ShellBrowserContext::InitWhileIOAllowed() {
[email protected]aae34062012-07-19 15:52:1567 CommandLine* cmd_line = CommandLine::ForCurrentProcess();
mkwstd993d06a2014-10-10 11:44:3868 if (cmd_line->HasSwitch(switches::kIgnoreCertificateErrors))
[email protected]c2dad292012-09-07 21:27:3569 ignore_certificate_errors_ = true;
[email protected]e1cf85a22012-08-17 22:39:2370 if (cmd_line->HasSwitch(switches::kContentShellDataPath)) {
71 path_ = cmd_line->GetSwitchValuePath(switches::kContentShellDataPath);
72 return;
73 }
[email protected]b0f146f2011-09-15 22:14:2574#if defined(OS_WIN)
[email protected]e99ca5112011-09-26 17:22:5475 CHECK(PathService::Get(base::DIR_LOCAL_APP_DATA, &path_));
76 path_ = path_.Append(std::wstring(L"content_shell"));
[email protected]5cba3bf2012-01-14 02:40:3577#elif defined(OS_LINUX)
78 scoped_ptr<base::Environment> env(base::Environment::Create());
[email protected]d30a36f2013-02-07 04:16:2679 base::FilePath config_dir(
[email protected]9528c9a2012-06-13 23:20:2280 base::nix::GetXDGDirectory(env.get(),
81 base::nix::kXdgConfigHomeEnvVar,
82 base::nix::kDotConfigDir));
[email protected]5cba3bf2012-01-14 02:40:3583 path_ = config_dir.Append("content_shell");
[email protected]80ec0b72012-03-22 22:45:2784#elif defined(OS_MACOSX)
85 CHECK(PathService::Get(base::DIR_APP_DATA, &path_));
86 path_ = path_.Append("Chromium Content Shell");
[email protected]70a7f1192012-06-08 01:31:3487#elif defined(OS_ANDROID)
[email protected]c3bf75252013-03-18 22:11:4888 CHECK(PathService::Get(base::DIR_ANDROID_APP_DATA, &path_));
[email protected]70a7f1192012-06-08 01:31:3489 path_ = path_.Append(FILE_PATH_LITERAL("content_shell"));
[email protected]b0f146f2011-09-15 22:14:2590#else
91 NOTIMPLEMENTED();
92#endif
93
[email protected]7567484142013-07-11 17:36:0794 if (!base::PathExists(path_))
[email protected]426d1c92013-12-03 20:08:5495 base::CreateDirectory(path_);
[email protected]11a65b692012-03-30 11:29:1696}
[email protected]b0f146f2011-09-15 22:14:2597
wjmacleancaa7d6d2014-11-12 16:42:1198scoped_ptr<ZoomLevelDelegate> ShellBrowserContext::CreateZoomLevelDelegate(
99 const base::FilePath&) {
100 return scoped_ptr<ZoomLevelDelegate>();
101}
102
[email protected]4251165a2013-07-17 04:33:40103base::FilePath ShellBrowserContext::GetPath() const {
[email protected]e99ca5112011-09-26 17:22:54104 return path_;
[email protected]b0f146f2011-09-15 22:14:25105}
106
[email protected]27d6e852012-03-02 21:31:32107bool ShellBrowserContext::IsOffTheRecord() const {
[email protected]71d504f2012-07-25 17:15:28108 return off_the_record_;
[email protected]b0f146f2011-09-15 22:14:25109}
110
[email protected]b441a8492012-06-06 14:55:57111DownloadManagerDelegate* ShellBrowserContext::GetDownloadManagerDelegate() {
[email protected]fc72bb12013-06-02 21:13:46112 if (!download_manager_delegate_.get()) {
[email protected]7cef82172013-12-17 06:58:37113 download_manager_delegate_.reset(new ShellDownloadManagerDelegate());
mkwstd993d06a2014-10-10 11:44:38114 download_manager_delegate_->SetDownloadManager(
115 BrowserContext::GetDownloadManager(this));
[email protected]59002092012-08-27 19:42:56116 }
[email protected]08c92ac2012-08-21 23:41:40117
[email protected]b441a8492012-06-06 14:55:57118 return download_manager_delegate_.get();
[email protected]b0f146f2011-09-15 22:14:25119}
120
[email protected]b0f146f2011-09-15 22:14:25121net::URLRequestContextGetter* ShellBrowserContext::GetRequestContext() {
[email protected]6bd30072013-02-08 18:17:11122 return GetDefaultStoragePartition(this)->GetURLRequestContext();
123}
124
mkwst94388f792014-10-16 07:36:52125ShellURLRequestContextGetter*
126ShellBrowserContext::CreateURLRequestContextGetter(
[email protected]7571263c2014-03-10 22:57:09127 ProtocolHandlerMap* protocol_handlers,
[email protected]3b90aab2014-05-30 17:56:15128 URLRequestInterceptorScopedVector request_interceptors) {
mkwst94388f792014-10-16 07:36:52129 return new ShellURLRequestContextGetter(
[email protected]6bd30072013-02-08 18:17:11130 ignore_certificate_errors_,
131 GetPath(),
132 BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::IO),
133 BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::FILE),
[email protected]d5869bf2013-07-03 16:21:47134 protocol_handlers,
[email protected]3b90aab2014-05-30 17:56:15135 request_interceptors.Pass(),
[email protected]d5869bf2013-07-03 16:21:47136 net_log_);
mkwst94388f792014-10-16 07:36:52137}
138
139net::URLRequestContextGetter* ShellBrowserContext::CreateRequestContext(
140 ProtocolHandlerMap* protocol_handlers,
141 URLRequestInterceptorScopedVector request_interceptors) {
142 DCHECK(!url_request_getter_.get());
143 url_request_getter_ = CreateURLRequestContextGetter(
144 protocol_handlers, request_interceptors.Pass());
apavlov297746b2014-10-10 08:25:26145 resource_context_->set_url_request_context_getter(url_request_getter_.get());
[email protected]6bd30072013-02-08 18:17:11146 return url_request_getter_.get();
[email protected]b0f146f2011-09-15 22:14:25147}
148
149net::URLRequestContextGetter*
150 ShellBrowserContext::GetRequestContextForRenderProcess(
151 int renderer_child_id) {
152 return GetRequestContext();
153}
154
155net::URLRequestContextGetter*
[email protected]10705a7b2012-08-21 19:07:08156 ShellBrowserContext::GetMediaRequestContext() {
157 return GetRequestContext();
158}
159
160net::URLRequestContextGetter*
161 ShellBrowserContext::GetMediaRequestContextForRenderProcess(
162 int renderer_child_id) {
[email protected]b0f146f2011-09-15 22:14:25163 return GetRequestContext();
164}
165
[email protected]55c0eca2012-09-15 05:12:34166net::URLRequestContextGetter*
[email protected]10eb28162012-09-18 03:04:09167 ShellBrowserContext::GetMediaRequestContextForStoragePartition(
[email protected]d30a36f2013-02-07 04:16:26168 const base::FilePath& partition_path,
[email protected]27ddfed22012-10-30 23:22:43169 bool in_memory) {
[email protected]10eb28162012-09-18 03:04:09170 return GetRequestContext();
171}
172
173net::URLRequestContextGetter*
[email protected]7571263c2014-03-10 22:57:09174ShellBrowserContext::CreateRequestContextForStoragePartition(
175 const base::FilePath& partition_path,
176 bool in_memory,
177 ProtocolHandlerMap* protocol_handlers,
[email protected]3b90aab2014-05-30 17:56:15178 URLRequestInterceptorScopedVector request_interceptors) {
[email protected]55c0eca2012-09-15 05:12:34179 return NULL;
180}
181
[email protected]df02aca2012-02-09 21:03:20182ResourceContext* ShellBrowserContext::GetResourceContext() {
[email protected]df02aca2012-02-09 21:03:20183 return resource_context_.get();
[email protected]b0f146f2011-09-15 22:14:25184}
185
[email protected]139355f2014-05-11 14:21:28186BrowserPluginGuestManager* ShellBrowserContext::GetGuestManager() {
187 return guest_manager_;
[email protected]24569262014-05-06 03:31:30188}
189
[email protected]cd501a72014-08-22 19:58:31190storage::SpecialStoragePolicy* ShellBrowserContext::GetSpecialStoragePolicy() {
[email protected]55eb70e762012-02-20 17:38:39191 return NULL;
[email protected]b0f146f2011-09-15 22:14:25192}
193
[email protected]c5c89d042014-06-13 14:43:37194PushMessagingService* ShellBrowserContext::GetPushMessagingService() {
195 return NULL;
196}
197
[email protected]c5bbe0e2014-08-01 23:23:30198SSLHostStateDelegate* ShellBrowserContext::GetSSLHostStateDelegate() {
199 return NULL;
200}
201
[email protected]b0f146f2011-09-15 22:14:25202} // namespace content