1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/shell/browser/shell_browser_context.h"
8 #include "base/command_line.h"
9 #include "base/environment.h"
10 #include "base/files/file_util.h"
11 #include "base/logging.h"
12 #include "base/path_service.h"
13 #include "base/threading/thread.h"
14 #include "content/public/browser/browser_thread.h"
15 #include "content/public/browser/storage_partition.h"
16 #include "content/public/common/content_switches.h"
17 #include "content/shell/browser/shell_download_manager_delegate.h"
18 #include "content/shell/common/shell_switches.h"
21 #include "base/base_paths_win.h"
22 #elif defined(OS_LINUX)
23 #include "base/nix/xdg_util.h"
24 #elif defined(OS_MACOSX)
25 #include "base/base_paths_mac.h"
30 ShellBrowserContext::ShellResourceContext::ShellResourceContext()
34 ShellBrowserContext::ShellResourceContext::~ShellResourceContext() {
38 ShellBrowserContext::ShellResourceContext::GetHostResolver() {
40 return getter_->host_resolver();
43 net::URLRequestContext*
44 ShellBrowserContext::ShellResourceContext::GetRequestContext() {
46 return getter_->GetURLRequestContext();
49 ShellBrowserContext::ShellBrowserContext(bool off_the_record,
51 : resource_context_(new ShellResourceContext),
52 ignore_certificate_errors_(false),
53 off_the_record_(off_the_record),
55 guest_manager_(NULL) {
59 ShellBrowserContext::~ShellBrowserContext() {
60 if (resource_context_) {
61 BrowserThread::DeleteSoon(
62 BrowserThread::IO, FROM_HERE, resource_context_.release());
66 void ShellBrowserContext::InitWhileIOAllowed() {
67 CommandLine* cmd_line = CommandLine::ForCurrentProcess();
68 if (cmd_line->HasSwitch(switches::kIgnoreCertificateErrors))
69 ignore_certificate_errors_ = true;
70 if (cmd_line->HasSwitch(switches::kContentShellDataPath)) {
71 path_ = cmd_line->GetSwitchValuePath(switches::kContentShellDataPath);
75 CHECK(PathService::Get(base::DIR_LOCAL_APP_DATA, &path_));
76 path_ = path_.Append(std::wstring(L"content_shell"));
77 #elif defined(OS_LINUX)
78 scoped_ptr<base::Environment> env(base::Environment::Create());
79 base::FilePath config_dir(
80 base::nix::GetXDGDirectory(env.get(),
81 base::nix::kXdgConfigHomeEnvVar,
82 base::nix::kDotConfigDir));
83 path_ = config_dir.Append("content_shell");
84 #elif defined(OS_MACOSX)
85 CHECK(PathService::Get(base::DIR_APP_DATA, &path_));
86 path_ = path_.Append("Chromium Content Shell");
87 #elif defined(OS_ANDROID)
88 CHECK(PathService::Get(base::DIR_ANDROID_APP_DATA, &path_));
89 path_ = path_.Append(FILE_PATH_LITERAL("content_shell"));
94 if (!base::PathExists(path_))
95 base::CreateDirectory(path_);
98 base::FilePath ShellBrowserContext::GetPath() const {
102 bool ShellBrowserContext::IsOffTheRecord() const {
103 return off_the_record_;
106 DownloadManagerDelegate* ShellBrowserContext::GetDownloadManagerDelegate() {
107 if (!download_manager_delegate_.get()) {
108 download_manager_delegate_.reset(new ShellDownloadManagerDelegate());
109 download_manager_delegate_->SetDownloadManager(
110 BrowserContext::GetDownloadManager(this));
113 return download_manager_delegate_.get();
116 net::URLRequestContextGetter* ShellBrowserContext::GetRequestContext() {
117 return GetDefaultStoragePartition(this)->GetURLRequestContext();
120 ShellURLRequestContextGetter*
121 ShellBrowserContext::CreateURLRequestContextGetter(
122 ProtocolHandlerMap* protocol_handlers,
123 URLRequestInterceptorScopedVector request_interceptors) {
124 return new ShellURLRequestContextGetter(
125 ignore_certificate_errors_,
127 BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::IO),
128 BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::FILE),
130 request_interceptors.Pass(),
134 net::URLRequestContextGetter* ShellBrowserContext::CreateRequestContext(
135 ProtocolHandlerMap* protocol_handlers,
136 URLRequestInterceptorScopedVector request_interceptors) {
137 DCHECK(!url_request_getter_.get());
138 url_request_getter_ = CreateURLRequestContextGetter(
139 protocol_handlers, request_interceptors.Pass());
140 resource_context_->set_url_request_context_getter(url_request_getter_.get());
141 return url_request_getter_.get();
144 net::URLRequestContextGetter*
145 ShellBrowserContext::GetRequestContextForRenderProcess(
146 int renderer_child_id) {
147 return GetRequestContext();
150 net::URLRequestContextGetter*
151 ShellBrowserContext::GetMediaRequestContext() {
152 return GetRequestContext();
155 net::URLRequestContextGetter*
156 ShellBrowserContext::GetMediaRequestContextForRenderProcess(
157 int renderer_child_id) {
158 return GetRequestContext();
161 net::URLRequestContextGetter*
162 ShellBrowserContext::GetMediaRequestContextForStoragePartition(
163 const base::FilePath& partition_path,
165 return GetRequestContext();
168 net::URLRequestContextGetter*
169 ShellBrowserContext::CreateRequestContextForStoragePartition(
170 const base::FilePath& partition_path,
172 ProtocolHandlerMap* protocol_handlers,
173 URLRequestInterceptorScopedVector request_interceptors) {
177 ResourceContext* ShellBrowserContext::GetResourceContext() {
178 return resource_context_.get();
181 BrowserPluginGuestManager* ShellBrowserContext::GetGuestManager() {
182 return guest_manager_;
185 storage::SpecialStoragePolicy* ShellBrowserContext::GetSpecialStoragePolicy() {
189 PushMessagingService* ShellBrowserContext::GetPushMessagingService() {
193 SSLHostStateDelegate* ShellBrowserContext::GetSSLHostStateDelegate() {
197 } // namespace content