1 // Copyright (c) 2012 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/shell_browser_context.h"
8 #include "base/command_line.h"
9 #include "base/environment.h"
10 #include "base/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/shell/shell_download_manager_delegate.h"
16 #include "content/shell/shell_resource_context.h"
17 #include "content/shell/shell_switches.h"
18 #include "content/shell/shell_url_request_context_getter.h"
19 #include "content/public/common/content_switches.h"
22 #include "base/base_paths_win.h"
23 #elif defined(OS_LINUX)
24 #include "base/nix/xdg_util.h"
25 #elif defined(OS_MACOSX)
26 #include "base/base_paths_mac.h"
31 ShellBrowserContext::ShellBrowserContext(bool off_the_record
)
32 : off_the_record_(off_the_record
),
33 ignore_certificate_errors_(false) {
37 ShellBrowserContext::~ShellBrowserContext() {
38 if (resource_context_
.get()) {
39 BrowserThread::DeleteSoon(
40 BrowserThread::IO
, FROM_HERE
, resource_context_
.release());
44 void ShellBrowserContext::InitWhileIOAllowed() {
45 CommandLine
* cmd_line
= CommandLine::ForCurrentProcess();
46 if (cmd_line
->HasSwitch(switches::kIgnoreCertificateErrors
) ||
47 cmd_line
->HasSwitch(switches::kDumpRenderTree
)) {
48 ignore_certificate_errors_
= true;
50 if (cmd_line
->HasSwitch(switches::kContentShellDataPath
)) {
51 path_
= cmd_line
->GetSwitchValuePath(switches::kContentShellDataPath
);
55 CHECK(PathService::Get(base::DIR_LOCAL_APP_DATA
, &path_
));
56 path_
= path_
.Append(std::wstring(L
"content_shell"));
57 #elif defined(OS_LINUX)
58 scoped_ptr
<base::Environment
> env(base::Environment::Create());
60 base::nix::GetXDGDirectory(env
.get(),
61 base::nix::kXdgConfigHomeEnvVar
,
62 base::nix::kDotConfigDir
));
63 path_
= config_dir
.Append("content_shell");
64 #elif defined(OS_MACOSX)
65 CHECK(PathService::Get(base::DIR_APP_DATA
, &path_
));
66 path_
= path_
.Append("Chromium Content Shell");
67 #elif defined(OS_ANDROID)
68 DCHECK(PathService::Get(base::DIR_ANDROID_APP_DATA
, &path_
));
69 path_
= path_
.Append(FILE_PATH_LITERAL("content_shell"));
74 if (!file_util::PathExists(path_
))
75 file_util::CreateDirectory(path_
);
78 FilePath
ShellBrowserContext::GetPath() {
82 bool ShellBrowserContext::IsOffTheRecord() const {
83 return off_the_record_
;
86 DownloadManagerDelegate
* ShellBrowserContext::GetDownloadManagerDelegate() {
87 DownloadManager
* manager
= BrowserContext::GetDownloadManager(this);
89 if (!download_manager_delegate_
.get()) {
90 download_manager_delegate_
= new ShellDownloadManagerDelegate();
91 download_manager_delegate_
->SetDownloadManager(manager
);
94 return download_manager_delegate_
.get();
97 net::URLRequestContextGetter
* ShellBrowserContext::GetRequestContext() {
98 if (!url_request_getter_
) {
99 url_request_getter_
= new ShellURLRequestContextGetter(
100 ignore_certificate_errors_
,
102 BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::IO
),
103 BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::FILE));
105 return url_request_getter_
;
108 net::URLRequestContextGetter
*
109 ShellBrowserContext::GetRequestContextForRenderProcess(
110 int renderer_child_id
) {
111 return GetRequestContext();
114 net::URLRequestContextGetter
*
115 ShellBrowserContext::GetMediaRequestContext() {
116 return GetRequestContext();
119 net::URLRequestContextGetter
*
120 ShellBrowserContext::GetMediaRequestContextForRenderProcess(
121 int renderer_child_id
) {
122 return GetRequestContext();
125 net::URLRequestContextGetter
*
126 ShellBrowserContext::GetMediaRequestContextForStoragePartition(
127 const FilePath
& partition_path
,
129 return GetRequestContext();
132 net::URLRequestContextGetter
*
133 ShellBrowserContext::GetRequestContextForStoragePartition(
134 const FilePath
& partition_path
,
139 ResourceContext
* ShellBrowserContext::GetResourceContext() {
140 if (!resource_context_
.get()) {
141 resource_context_
.reset(new ShellResourceContext(
142 static_cast<ShellURLRequestContextGetter
*>(GetRequestContext())));
144 return resource_context_
.get();
147 GeolocationPermissionContext
*
148 ShellBrowserContext::GetGeolocationPermissionContext() {
152 SpeechRecognitionPreferences
*
153 ShellBrowserContext::GetSpeechRecognitionPreferences() {
157 quota::SpecialStoragePolicy
* ShellBrowserContext::GetSpecialStoragePolicy() {
161 } // namespace content