[email protected] | de7d61ff | 2013-08-20 11:30:41 | [diff] [blame] | 1 | // Copyright 2013 The Chromium Authors. All rights reserved. |
[email protected] | b0f146f | 2011-09-15 22:14:25 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | de7d61ff | 2013-08-20 11:30:41 | [diff] [blame] | 5 | #include "content/shell/browser/shell_browser_context.h" |
[email protected] | b0f146f | 2011-09-15 22:14:25 | [diff] [blame] | 6 | |
dcheng | f63a125 | 2015-12-26 20:43:13 | [diff] [blame] | 7 | #include <utility> |
| 8 | |
[email protected] | 037edb5 | 2011-11-15 21:14:06 | [diff] [blame] | 9 | #include "base/bind.h" |
[email protected] | 2f2b951 | 2012-06-08 17:31:00 | [diff] [blame] | 10 | #include "base/command_line.h" |
[email protected] | 5cba3bf | 2012-01-14 02:40:35 | [diff] [blame] | 11 | #include "base/environment.h" |
thestig | b7aad54f | 2014-09-05 18:25:39 | [diff] [blame] | 12 | #include "base/files/file_util.h" |
[email protected] | b0f146f | 2011-09-15 22:14:25 | [diff] [blame] | 13 | #include "base/logging.h" |
| 14 | #include "base/path_service.h" |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 15 | #include "base/threading/thread.h" |
avi | 66a0772 | 2015-12-25 23:38:12 | [diff] [blame] | 16 | #include "build/build_config.h" |
[email protected] | c38831a1 | 2011-10-28 12:44:49 | [diff] [blame] | 17 | #include "content/public/browser/browser_thread.h" |
[email protected] | 6bd3007 | 2013-02-08 18:17:11 | [diff] [blame] | 18 | #include "content/public/browser/storage_partition.h" |
| 19 | #include "content/public/common/content_switches.h" |
[email protected] | de7d61ff | 2013-08-20 11:30:41 | [diff] [blame] | 20 | #include "content/shell/browser/shell_download_manager_delegate.h" |
mlamouri | 4e37202 | 2015-03-29 14:51:06 | [diff] [blame] | 21 | #include "content/shell/browser/shell_permission_manager.h" |
[email protected] | b7c504c | 2013-05-07 14:42:12 | [diff] [blame] | 22 | #include "content/shell/common/shell_switches.h" |
nsatragno | db7b65c64 | 2016-02-16 20:14:02 | [diff] [blame] | 23 | #include "content/test/mock_background_sync_controller.h" |
[email protected] | b0f146f | 2011-09-15 22:14:25 | [diff] [blame] | 24 | |
| 25 | #if defined(OS_WIN) |
| 26 | #include "base/base_paths_win.h" |
[email protected] | 5cba3bf | 2012-01-14 02:40:35 | [diff] [blame] | 27 | #elif defined(OS_LINUX) |
| 28 | #include "base/nix/xdg_util.h" |
[email protected] | 80ec0b7 | 2012-03-22 22:45:27 | [diff] [blame] | 29 | #elif defined(OS_MACOSX) |
| 30 | #include "base/base_paths_mac.h" |
[email protected] | b0f146f | 2011-09-15 22:14:25 | [diff] [blame] | 31 | #endif |
| 32 | |
[email protected] | 810ddc5 | 2012-01-24 01:00:35 | [diff] [blame] | 33 | namespace content { |
| 34 | |
hanxi | 3328d99 | 2014-10-09 13:27:11 | [diff] [blame] | 35 | ShellBrowserContext::ShellResourceContext::ShellResourceContext() |
| 36 | : getter_(NULL) { |
| 37 | } |
[email protected] | 6bd3007 | 2013-02-08 18:17:11 | [diff] [blame] | 38 | |
hanxi | 3328d99 | 2014-10-09 13:27:11 | [diff] [blame] | 39 | ShellBrowserContext::ShellResourceContext::~ShellResourceContext() { |
| 40 | } |
[email protected] | 6bd3007 | 2013-02-08 18:17:11 | [diff] [blame] | 41 | |
hanxi | 3328d99 | 2014-10-09 13:27:11 | [diff] [blame] | 42 | net::HostResolver* |
| 43 | ShellBrowserContext::ShellResourceContext::GetHostResolver() { |
| 44 | CHECK(getter_); |
| 45 | return getter_->host_resolver(); |
| 46 | } |
[email protected] | 6bd3007 | 2013-02-08 18:17:11 | [diff] [blame] | 47 | |
hanxi | 3328d99 | 2014-10-09 13:27:11 | [diff] [blame] | 48 | net::URLRequestContext* |
| 49 | ShellBrowserContext::ShellResourceContext::GetRequestContext() { |
| 50 | CHECK(getter_); |
| 51 | return getter_->GetURLRequestContext(); |
| 52 | } |
[email protected] | 6bd3007 | 2013-02-08 18:17:11 | [diff] [blame] | 53 | |
[email protected] | d5869bf | 2013-07-03 16:21:47 | [diff] [blame] | 54 | ShellBrowserContext::ShellBrowserContext(bool off_the_record, |
| 55 | net::NetLog* net_log) |
hanxi | 3328d99 | 2014-10-09 13:27:11 | [diff] [blame] | 56 | : resource_context_(new ShellResourceContext), |
mkwst | d993d06a | 2014-10-10 11:44:38 | [diff] [blame] | 57 | ignore_certificate_errors_(false), |
hanxi | 3328d99 | 2014-10-09 13:27:11 | [diff] [blame] | 58 | off_the_record_(off_the_record), |
[email protected] | d5869bf | 2013-07-03 16:21:47 | [diff] [blame] | 59 | net_log_(net_log), |
hanxi | 3328d99 | 2014-10-09 13:27:11 | [diff] [blame] | 60 | guest_manager_(NULL) { |
[email protected] | 11a65b69 | 2012-03-30 11:29:16 | [diff] [blame] | 61 | InitWhileIOAllowed(); |
[email protected] | b0f146f | 2011-09-15 22:14:25 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | ShellBrowserContext::~ShellBrowserContext() { |
[email protected] | 59383c78 | 2013-04-17 16:43:27 | [diff] [blame] | 65 | if (resource_context_) { |
[email protected] | e99ca511 | 2011-09-26 17:22:54 | [diff] [blame] | 66 | BrowserThread::DeleteSoon( |
| 67 | BrowserThread::IO, FROM_HERE, resource_context_.release()); |
| 68 | } |
[email protected] | b0f146f | 2011-09-15 22:14:25 | [diff] [blame] | 69 | } |
| 70 | |
[email protected] | 11a65b69 | 2012-03-30 11:29:16 | [diff] [blame] | 71 | void ShellBrowserContext::InitWhileIOAllowed() { |
avi | 83883c8 | 2014-12-23 00:08:49 | [diff] [blame] | 72 | base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); |
mkwst | d993d06a | 2014-10-10 11:44:38 | [diff] [blame] | 73 | if (cmd_line->HasSwitch(switches::kIgnoreCertificateErrors)) |
[email protected] | c2dad29 | 2012-09-07 21:27:35 | [diff] [blame] | 74 | ignore_certificate_errors_ = true; |
[email protected] | e1cf85a2 | 2012-08-17 22:39:23 | [diff] [blame] | 75 | if (cmd_line->HasSwitch(switches::kContentShellDataPath)) { |
| 76 | path_ = cmd_line->GetSwitchValuePath(switches::kContentShellDataPath); |
erg | e69130f5 | 2016-03-02 00:13:28 | [diff] [blame] | 77 | BrowserContext::Initialize(this, path_); |
[email protected] | e1cf85a2 | 2012-08-17 22:39:23 | [diff] [blame] | 78 | return; |
| 79 | } |
[email protected] | b0f146f | 2011-09-15 22:14:25 | [diff] [blame] | 80 | #if defined(OS_WIN) |
[email protected] | e99ca511 | 2011-09-26 17:22:54 | [diff] [blame] | 81 | CHECK(PathService::Get(base::DIR_LOCAL_APP_DATA, &path_)); |
| 82 | path_ = path_.Append(std::wstring(L"content_shell")); |
[email protected] | 5cba3bf | 2012-01-14 02:40:35 | [diff] [blame] | 83 | #elif defined(OS_LINUX) |
dcheng | 6003e0b | 2016-04-09 18:42:34 | [diff] [blame^] | 84 | std::unique_ptr<base::Environment> env(base::Environment::Create()); |
[email protected] | d30a36f | 2013-02-07 04:16:26 | [diff] [blame] | 85 | base::FilePath config_dir( |
[email protected] | 9528c9a | 2012-06-13 23:20:22 | [diff] [blame] | 86 | base::nix::GetXDGDirectory(env.get(), |
| 87 | base::nix::kXdgConfigHomeEnvVar, |
| 88 | base::nix::kDotConfigDir)); |
[email protected] | 5cba3bf | 2012-01-14 02:40:35 | [diff] [blame] | 89 | path_ = config_dir.Append("content_shell"); |
[email protected] | 80ec0b7 | 2012-03-22 22:45:27 | [diff] [blame] | 90 | #elif defined(OS_MACOSX) |
| 91 | CHECK(PathService::Get(base::DIR_APP_DATA, &path_)); |
| 92 | path_ = path_.Append("Chromium Content Shell"); |
[email protected] | 70a7f119 | 2012-06-08 01:31:34 | [diff] [blame] | 93 | #elif defined(OS_ANDROID) |
[email protected] | c3bf752 | 2013-03-18 22:11:48 | [diff] [blame] | 94 | CHECK(PathService::Get(base::DIR_ANDROID_APP_DATA, &path_)); |
[email protected] | 70a7f119 | 2012-06-08 01:31:34 | [diff] [blame] | 95 | path_ = path_.Append(FILE_PATH_LITERAL("content_shell")); |
[email protected] | b0f146f | 2011-09-15 22:14:25 | [diff] [blame] | 96 | #else |
| 97 | NOTIMPLEMENTED(); |
| 98 | #endif |
| 99 | |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 100 | if (!base::PathExists(path_)) |
[email protected] | 426d1c9 | 2013-12-03 20:08:54 | [diff] [blame] | 101 | base::CreateDirectory(path_); |
erg | e69130f5 | 2016-03-02 00:13:28 | [diff] [blame] | 102 | BrowserContext::Initialize(this, path_); |
[email protected] | 11a65b69 | 2012-03-30 11:29:16 | [diff] [blame] | 103 | } |
[email protected] | b0f146f | 2011-09-15 22:14:25 | [diff] [blame] | 104 | |
dcheng | 6003e0b | 2016-04-09 18:42:34 | [diff] [blame^] | 105 | std::unique_ptr<ZoomLevelDelegate> ShellBrowserContext::CreateZoomLevelDelegate( |
wjmaclean | caa7d6d | 2014-11-12 16:42:11 | [diff] [blame] | 106 | const base::FilePath&) { |
dcheng | 6003e0b | 2016-04-09 18:42:34 | [diff] [blame^] | 107 | return std::unique_ptr<ZoomLevelDelegate>(); |
wjmaclean | caa7d6d | 2014-11-12 16:42:11 | [diff] [blame] | 108 | } |
| 109 | |
[email protected] | 4251165a | 2013-07-17 04:33:40 | [diff] [blame] | 110 | base::FilePath ShellBrowserContext::GetPath() const { |
[email protected] | e99ca511 | 2011-09-26 17:22:54 | [diff] [blame] | 111 | return path_; |
[email protected] | b0f146f | 2011-09-15 22:14:25 | [diff] [blame] | 112 | } |
| 113 | |
[email protected] | 27d6e85 | 2012-03-02 21:31:32 | [diff] [blame] | 114 | bool ShellBrowserContext::IsOffTheRecord() const { |
[email protected] | 71d504f | 2012-07-25 17:15:28 | [diff] [blame] | 115 | return off_the_record_; |
[email protected] | b0f146f | 2011-09-15 22:14:25 | [diff] [blame] | 116 | } |
| 117 | |
[email protected] | b441a849 | 2012-06-06 14:55:57 | [diff] [blame] | 118 | DownloadManagerDelegate* ShellBrowserContext::GetDownloadManagerDelegate() { |
[email protected] | fc72bb1 | 2013-06-02 21:13:46 | [diff] [blame] | 119 | if (!download_manager_delegate_.get()) { |
[email protected] | 7cef8217 | 2013-12-17 06:58:37 | [diff] [blame] | 120 | download_manager_delegate_.reset(new ShellDownloadManagerDelegate()); |
mkwst | d993d06a | 2014-10-10 11:44:38 | [diff] [blame] | 121 | download_manager_delegate_->SetDownloadManager( |
| 122 | BrowserContext::GetDownloadManager(this)); |
[email protected] | 5900209 | 2012-08-27 19:42:56 | [diff] [blame] | 123 | } |
[email protected] | 08c92ac | 2012-08-21 23:41:40 | [diff] [blame] | 124 | |
[email protected] | b441a849 | 2012-06-06 14:55:57 | [diff] [blame] | 125 | return download_manager_delegate_.get(); |
[email protected] | b0f146f | 2011-09-15 22:14:25 | [diff] [blame] | 126 | } |
| 127 | |
[email protected] | b0f146f | 2011-09-15 22:14:25 | [diff] [blame] | 128 | net::URLRequestContextGetter* ShellBrowserContext::GetRequestContext() { |
[email protected] | 6bd3007 | 2013-02-08 18:17:11 | [diff] [blame] | 129 | return GetDefaultStoragePartition(this)->GetURLRequestContext(); |
| 130 | } |
| 131 | |
mkwst | 94388f79 | 2014-10-16 07:36:52 | [diff] [blame] | 132 | ShellURLRequestContextGetter* |
| 133 | ShellBrowserContext::CreateURLRequestContextGetter( |
[email protected] | 7571263c | 2014-03-10 22:57:09 | [diff] [blame] | 134 | ProtocolHandlerMap* protocol_handlers, |
[email protected] | 3b90aab | 2014-05-30 17:56:15 | [diff] [blame] | 135 | URLRequestInterceptorScopedVector request_interceptors) { |
mkwst | 94388f79 | 2014-10-16 07:36:52 | [diff] [blame] | 136 | return new ShellURLRequestContextGetter( |
dcheng | f63a125 | 2015-12-26 20:43:13 | [diff] [blame] | 137 | ignore_certificate_errors_, GetPath(), |
skyostil | abeb69ff | 2016-02-25 10:52:36 | [diff] [blame] | 138 | BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO), |
| 139 | BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE), |
dcheng | f63a125 | 2015-12-26 20:43:13 | [diff] [blame] | 140 | protocol_handlers, std::move(request_interceptors), net_log_); |
mkwst | 94388f79 | 2014-10-16 07:36:52 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | net::URLRequestContextGetter* ShellBrowserContext::CreateRequestContext( |
| 144 | ProtocolHandlerMap* protocol_handlers, |
| 145 | URLRequestInterceptorScopedVector request_interceptors) { |
| 146 | DCHECK(!url_request_getter_.get()); |
| 147 | url_request_getter_ = CreateURLRequestContextGetter( |
dcheng | f63a125 | 2015-12-26 20:43:13 | [diff] [blame] | 148 | protocol_handlers, std::move(request_interceptors)); |
apavlov | 297746b | 2014-10-10 08:25:26 | [diff] [blame] | 149 | resource_context_->set_url_request_context_getter(url_request_getter_.get()); |
[email protected] | 6bd3007 | 2013-02-08 18:17:11 | [diff] [blame] | 150 | return url_request_getter_.get(); |
[email protected] | b0f146f | 2011-09-15 22:14:25 | [diff] [blame] | 151 | } |
| 152 | |
| 153 | net::URLRequestContextGetter* |
[email protected] | 10705a7b | 2012-08-21 19:07:08 | [diff] [blame] | 154 | ShellBrowserContext::GetMediaRequestContext() { |
| 155 | return GetRequestContext(); |
| 156 | } |
| 157 | |
| 158 | net::URLRequestContextGetter* |
| 159 | ShellBrowserContext::GetMediaRequestContextForRenderProcess( |
| 160 | int renderer_child_id) { |
[email protected] | b0f146f | 2011-09-15 22:14:25 | [diff] [blame] | 161 | return GetRequestContext(); |
| 162 | } |
| 163 | |
[email protected] | 55c0eca | 2012-09-15 05:12:34 | [diff] [blame] | 164 | net::URLRequestContextGetter* |
[email protected] | 10eb2816 | 2012-09-18 03:04:09 | [diff] [blame] | 165 | ShellBrowserContext::GetMediaRequestContextForStoragePartition( |
[email protected] | d30a36f | 2013-02-07 04:16:26 | [diff] [blame] | 166 | const base::FilePath& partition_path, |
[email protected] | 27ddfed2 | 2012-10-30 23:22:43 | [diff] [blame] | 167 | bool in_memory) { |
[email protected] | 10eb2816 | 2012-09-18 03:04:09 | [diff] [blame] | 168 | return GetRequestContext(); |
| 169 | } |
| 170 | |
| 171 | net::URLRequestContextGetter* |
[email protected] | 7571263c | 2014-03-10 22:57:09 | [diff] [blame] | 172 | ShellBrowserContext::CreateRequestContextForStoragePartition( |
| 173 | const base::FilePath& partition_path, |
| 174 | bool in_memory, |
| 175 | ProtocolHandlerMap* protocol_handlers, |
[email protected] | 3b90aab | 2014-05-30 17:56:15 | [diff] [blame] | 176 | URLRequestInterceptorScopedVector request_interceptors) { |
[email protected] | 55c0eca | 2012-09-15 05:12:34 | [diff] [blame] | 177 | return NULL; |
| 178 | } |
| 179 | |
[email protected] | df02aca | 2012-02-09 21:03:20 | [diff] [blame] | 180 | ResourceContext* ShellBrowserContext::GetResourceContext() { |
[email protected] | df02aca | 2012-02-09 21:03:20 | [diff] [blame] | 181 | return resource_context_.get(); |
[email protected] | b0f146f | 2011-09-15 22:14:25 | [diff] [blame] | 182 | } |
| 183 | |
[email protected] | 139355f | 2014-05-11 14:21:28 | [diff] [blame] | 184 | BrowserPluginGuestManager* ShellBrowserContext::GetGuestManager() { |
| 185 | return guest_manager_; |
[email protected] | 2456926 | 2014-05-06 03:31:30 | [diff] [blame] | 186 | } |
| 187 | |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame] | 188 | storage::SpecialStoragePolicy* ShellBrowserContext::GetSpecialStoragePolicy() { |
[email protected] | 55eb70e76 | 2012-02-20 17:38:39 | [diff] [blame] | 189 | return NULL; |
[email protected] | b0f146f | 2011-09-15 22:14:25 | [diff] [blame] | 190 | } |
| 191 | |
[email protected] | c5c89d04 | 2014-06-13 14:43:37 | [diff] [blame] | 192 | PushMessagingService* ShellBrowserContext::GetPushMessagingService() { |
| 193 | return NULL; |
| 194 | } |
| 195 | |
[email protected] | c5bbe0e | 2014-08-01 23:23:30 | [diff] [blame] | 196 | SSLHostStateDelegate* ShellBrowserContext::GetSSLHostStateDelegate() { |
| 197 | return NULL; |
| 198 | } |
| 199 | |
mlamouri | 4e37202 | 2015-03-29 14:51:06 | [diff] [blame] | 200 | PermissionManager* ShellBrowserContext::GetPermissionManager() { |
| 201 | if (!permission_manager_.get()) |
| 202 | permission_manager_.reset(new ShellPermissionManager()); |
| 203 | return permission_manager_.get(); |
| 204 | } |
| 205 | |
jkarlin | 6f5078ed | 2015-10-06 15:13:35 | [diff] [blame] | 206 | BackgroundSyncController* ShellBrowserContext::GetBackgroundSyncController() { |
jkarlin | 428a4a3 | 2016-01-08 16:13:24 | [diff] [blame] | 207 | if (!background_sync_controller_) |
nsatragno | db7b65c64 | 2016-02-16 20:14:02 | [diff] [blame] | 208 | background_sync_controller_.reset(new MockBackgroundSyncController()); |
jkarlin | 428a4a3 | 2016-01-08 16:13:24 | [diff] [blame] | 209 | return background_sync_controller_.get(); |
jkarlin | 6f5078ed | 2015-10-06 15:13:35 | [diff] [blame] | 210 | } |
| 211 | |
[email protected] | b0f146f | 2011-09-15 22:14:25 | [diff] [blame] | 212 | } // namespace content |