[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 | |
[email protected] | 037edb5 | 2011-11-15 21:14:06 | [diff] [blame] | 7 | #include "base/bind.h" |
[email protected] | 2f2b951 | 2012-06-08 17:31:00 | [diff] [blame] | 8 | #include "base/command_line.h" |
[email protected] | 5cba3bf | 2012-01-14 02:40:35 | [diff] [blame] | 9 | #include "base/environment.h" |
[email protected] | b0f146f | 2011-09-15 22:14:25 | [diff] [blame] | 10 | #include "base/file_util.h" |
| 11 | #include "base/logging.h" |
| 12 | #include "base/path_service.h" |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 13 | #include "base/threading/thread.h" |
[email protected] | c38831a1 | 2011-10-28 12:44:49 | [diff] [blame] | 14 | #include "content/public/browser/browser_thread.h" |
[email protected] | 6bd3007 | 2013-02-08 18:17:11 | [diff] [blame] | 15 | #include "content/public/browser/resource_context.h" |
| 16 | #include "content/public/browser/storage_partition.h" |
| 17 | #include "content/public/common/content_switches.h" |
[email protected] | de7d61ff | 2013-08-20 11:30:41 | [diff] [blame] | 18 | #include "content/shell/browser/shell_download_manager_delegate.h" |
| 19 | #include "content/shell/browser/shell_url_request_context_getter.h" |
[email protected] | b7c504c | 2013-05-07 14:42:12 | [diff] [blame] | 20 | #include "content/shell/common/shell_switches.h" |
[email protected] | b0f146f | 2011-09-15 22:14:25 | [diff] [blame] | 21 | |
| 22 | #if defined(OS_WIN) |
| 23 | #include "base/base_paths_win.h" |
[email protected] | 5cba3bf | 2012-01-14 02:40:35 | [diff] [blame] | 24 | #elif defined(OS_LINUX) |
| 25 | #include "base/nix/xdg_util.h" |
[email protected] | 80ec0b7 | 2012-03-22 22:45:27 | [diff] [blame] | 26 | #elif defined(OS_MACOSX) |
| 27 | #include "base/base_paths_mac.h" |
[email protected] | b0f146f | 2011-09-15 22:14:25 | [diff] [blame] | 28 | #endif |
| 29 | |
[email protected] | 810ddc5 | 2012-01-24 01:00:35 | [diff] [blame] | 30 | namespace content { |
| 31 | |
[email protected] | 6bd3007 | 2013-02-08 18:17:11 | [diff] [blame] | 32 | class ShellBrowserContext::ShellResourceContext : public ResourceContext { |
| 33 | public: |
| 34 | ShellResourceContext() : getter_(NULL) {} |
| 35 | virtual ~ShellResourceContext() {} |
| 36 | |
| 37 | // ResourceContext implementation: |
| 38 | virtual net::HostResolver* GetHostResolver() OVERRIDE { |
| 39 | CHECK(getter_); |
| 40 | return getter_->host_resolver(); |
| 41 | } |
| 42 | virtual net::URLRequestContext* GetRequestContext() OVERRIDE { |
| 43 | CHECK(getter_); |
| 44 | return getter_->GetURLRequestContext(); |
| 45 | } |
[email protected] | d07190a | 2013-08-06 22:12:39 | [diff] [blame] | 46 | virtual bool AllowMicAccess(const GURL& origin) OVERRIDE { |
| 47 | return false; |
| 48 | } |
| 49 | virtual bool AllowCameraAccess(const GURL& origin) OVERRIDE { |
| 50 | return false; |
| 51 | } |
[email protected] | 6bd3007 | 2013-02-08 18:17:11 | [diff] [blame] | 52 | |
| 53 | void set_url_request_context_getter(ShellURLRequestContextGetter* getter) { |
| 54 | getter_ = getter; |
| 55 | } |
| 56 | |
| 57 | private: |
| 58 | ShellURLRequestContextGetter* getter_; |
| 59 | |
| 60 | DISALLOW_COPY_AND_ASSIGN(ShellResourceContext); |
| 61 | }; |
| 62 | |
[email protected] | d5869bf | 2013-07-03 16:21:47 | [diff] [blame] | 63 | ShellBrowserContext::ShellBrowserContext(bool off_the_record, |
| 64 | net::NetLog* net_log) |
[email protected] | c2dad29 | 2012-09-07 21:27:35 | [diff] [blame] | 65 | : off_the_record_(off_the_record), |
[email protected] | d5869bf | 2013-07-03 16:21:47 | [diff] [blame] | 66 | net_log_(net_log), |
[email protected] | 6bd3007 | 2013-02-08 18:17:11 | [diff] [blame] | 67 | ignore_certificate_errors_(false), |
[email protected] | 139355f | 2014-05-11 14:21:28 | [diff] [blame] | 68 | guest_manager_(NULL), |
[email protected] | 6bd3007 | 2013-02-08 18:17:11 | [diff] [blame] | 69 | resource_context_(new ShellResourceContext) { |
[email protected] | 11a65b69 | 2012-03-30 11:29:16 | [diff] [blame] | 70 | InitWhileIOAllowed(); |
[email protected] | b0f146f | 2011-09-15 22:14:25 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | ShellBrowserContext::~ShellBrowserContext() { |
[email protected] | 59383c78 | 2013-04-17 16:43:27 | [diff] [blame] | 74 | if (resource_context_) { |
[email protected] | e99ca511 | 2011-09-26 17:22:54 | [diff] [blame] | 75 | BrowserThread::DeleteSoon( |
| 76 | BrowserThread::IO, FROM_HERE, resource_context_.release()); |
| 77 | } |
[email protected] | b0f146f | 2011-09-15 22:14:25 | [diff] [blame] | 78 | } |
| 79 | |
[email protected] | 11a65b69 | 2012-03-30 11:29:16 | [diff] [blame] | 80 | void ShellBrowserContext::InitWhileIOAllowed() { |
[email protected] | aae3406 | 2012-07-19 15:52:15 | [diff] [blame] | 81 | CommandLine* cmd_line = CommandLine::ForCurrentProcess(); |
[email protected] | d22dc09 | 2012-11-19 20:35:56 | [diff] [blame] | 82 | if (cmd_line->HasSwitch(switches::kIgnoreCertificateErrors) || |
| 83 | cmd_line->HasSwitch(switches::kDumpRenderTree)) { |
[email protected] | c2dad29 | 2012-09-07 21:27:35 | [diff] [blame] | 84 | ignore_certificate_errors_ = true; |
[email protected] | d22dc09 | 2012-11-19 20:35:56 | [diff] [blame] | 85 | } |
[email protected] | e1cf85a2 | 2012-08-17 22:39:23 | [diff] [blame] | 86 | if (cmd_line->HasSwitch(switches::kContentShellDataPath)) { |
| 87 | path_ = cmd_line->GetSwitchValuePath(switches::kContentShellDataPath); |
| 88 | return; |
| 89 | } |
[email protected] | b0f146f | 2011-09-15 22:14:25 | [diff] [blame] | 90 | #if defined(OS_WIN) |
[email protected] | e99ca511 | 2011-09-26 17:22:54 | [diff] [blame] | 91 | CHECK(PathService::Get(base::DIR_LOCAL_APP_DATA, &path_)); |
| 92 | path_ = path_.Append(std::wstring(L"content_shell")); |
[email protected] | 5cba3bf | 2012-01-14 02:40:35 | [diff] [blame] | 93 | #elif defined(OS_LINUX) |
| 94 | scoped_ptr<base::Environment> env(base::Environment::Create()); |
[email protected] | d30a36f | 2013-02-07 04:16:26 | [diff] [blame] | 95 | base::FilePath config_dir( |
[email protected] | 9528c9a | 2012-06-13 23:20:22 | [diff] [blame] | 96 | base::nix::GetXDGDirectory(env.get(), |
| 97 | base::nix::kXdgConfigHomeEnvVar, |
| 98 | base::nix::kDotConfigDir)); |
[email protected] | 5cba3bf | 2012-01-14 02:40:35 | [diff] [blame] | 99 | path_ = config_dir.Append("content_shell"); |
[email protected] | 80ec0b7 | 2012-03-22 22:45:27 | [diff] [blame] | 100 | #elif defined(OS_MACOSX) |
| 101 | CHECK(PathService::Get(base::DIR_APP_DATA, &path_)); |
| 102 | path_ = path_.Append("Chromium Content Shell"); |
[email protected] | 70a7f119 | 2012-06-08 01:31:34 | [diff] [blame] | 103 | #elif defined(OS_ANDROID) |
[email protected] | c3bf7525 | 2013-03-18 22:11:48 | [diff] [blame] | 104 | CHECK(PathService::Get(base::DIR_ANDROID_APP_DATA, &path_)); |
[email protected] | 70a7f119 | 2012-06-08 01:31:34 | [diff] [blame] | 105 | path_ = path_.Append(FILE_PATH_LITERAL("content_shell")); |
[email protected] | b0f146f | 2011-09-15 22:14:25 | [diff] [blame] | 106 | #else |
| 107 | NOTIMPLEMENTED(); |
| 108 | #endif |
| 109 | |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 110 | if (!base::PathExists(path_)) |
[email protected] | 426d1c9 | 2013-12-03 20:08:54 | [diff] [blame] | 111 | base::CreateDirectory(path_); |
[email protected] | 11a65b69 | 2012-03-30 11:29:16 | [diff] [blame] | 112 | } |
[email protected] | b0f146f | 2011-09-15 22:14:25 | [diff] [blame] | 113 | |
[email protected] | 4251165a | 2013-07-17 04:33:40 | [diff] [blame] | 114 | base::FilePath ShellBrowserContext::GetPath() const { |
[email protected] | e99ca511 | 2011-09-26 17:22:54 | [diff] [blame] | 115 | return path_; |
[email protected] | b0f146f | 2011-09-15 22:14:25 | [diff] [blame] | 116 | } |
| 117 | |
[email protected] | 27d6e85 | 2012-03-02 21:31:32 | [diff] [blame] | 118 | bool ShellBrowserContext::IsOffTheRecord() const { |
[email protected] | 71d504f | 2012-07-25 17:15:28 | [diff] [blame] | 119 | return off_the_record_; |
[email protected] | b0f146f | 2011-09-15 22:14:25 | [diff] [blame] | 120 | } |
| 121 | |
[email protected] | b441a849 | 2012-06-06 14:55:57 | [diff] [blame] | 122 | DownloadManagerDelegate* ShellBrowserContext::GetDownloadManagerDelegate() { |
[email protected] | 08c92ac | 2012-08-21 23:41:40 | [diff] [blame] | 123 | DownloadManager* manager = BrowserContext::GetDownloadManager(this); |
| 124 | |
[email protected] | fc72bb1 | 2013-06-02 21:13:46 | [diff] [blame] | 125 | if (!download_manager_delegate_.get()) { |
[email protected] | 7cef8217 | 2013-12-17 06:58:37 | [diff] [blame] | 126 | download_manager_delegate_.reset(new ShellDownloadManagerDelegate()); |
[email protected] | 5900209 | 2012-08-27 19:42:56 | [diff] [blame] | 127 | download_manager_delegate_->SetDownloadManager(manager); |
[email protected] | 17bc408b2 | 2013-01-10 18:40:08 | [diff] [blame] | 128 | CommandLine* cmd_line = CommandLine::ForCurrentProcess(); |
| 129 | if (cmd_line->HasSwitch(switches::kDumpRenderTree)) { |
| 130 | download_manager_delegate_->SetDownloadBehaviorForTesting( |
| 131 | path_.Append(FILE_PATH_LITERAL("downloads"))); |
| 132 | } |
[email protected] | 5900209 | 2012-08-27 19:42:56 | [diff] [blame] | 133 | } |
[email protected] | 08c92ac | 2012-08-21 23:41:40 | [diff] [blame] | 134 | |
[email protected] | b441a849 | 2012-06-06 14:55:57 | [diff] [blame] | 135 | return download_manager_delegate_.get(); |
[email protected] | b0f146f | 2011-09-15 22:14:25 | [diff] [blame] | 136 | } |
| 137 | |
[email protected] | b0f146f | 2011-09-15 22:14:25 | [diff] [blame] | 138 | net::URLRequestContextGetter* ShellBrowserContext::GetRequestContext() { |
[email protected] | 6bd3007 | 2013-02-08 18:17:11 | [diff] [blame] | 139 | return GetDefaultStoragePartition(this)->GetURLRequestContext(); |
| 140 | } |
| 141 | |
| 142 | net::URLRequestContextGetter* ShellBrowserContext::CreateRequestContext( |
[email protected] | 7571263c | 2014-03-10 22:57:09 | [diff] [blame] | 143 | ProtocolHandlerMap* protocol_handlers, |
[email protected] | 3b90aab | 2014-05-30 17:56:15 | [diff] [blame] | 144 | URLRequestInterceptorScopedVector request_interceptors) { |
[email protected] | fc72bb1 | 2013-06-02 21:13:46 | [diff] [blame] | 145 | DCHECK(!url_request_getter_.get()); |
[email protected] | 6bd3007 | 2013-02-08 18:17:11 | [diff] [blame] | 146 | url_request_getter_ = new ShellURLRequestContextGetter( |
| 147 | ignore_certificate_errors_, |
| 148 | GetPath(), |
| 149 | BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::IO), |
| 150 | BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::FILE), |
[email protected] | d5869bf | 2013-07-03 16:21:47 | [diff] [blame] | 151 | protocol_handlers, |
[email protected] | 3b90aab | 2014-05-30 17:56:15 | [diff] [blame] | 152 | request_interceptors.Pass(), |
[email protected] | d5869bf | 2013-07-03 16:21:47 | [diff] [blame] | 153 | net_log_); |
[email protected] | 6bd3007 | 2013-02-08 18:17:11 | [diff] [blame] | 154 | resource_context_->set_url_request_context_getter(url_request_getter_.get()); |
| 155 | return url_request_getter_.get(); |
[email protected] | b0f146f | 2011-09-15 22:14:25 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | net::URLRequestContextGetter* |
| 159 | ShellBrowserContext::GetRequestContextForRenderProcess( |
| 160 | int renderer_child_id) { |
| 161 | return GetRequestContext(); |
| 162 | } |
| 163 | |
| 164 | net::URLRequestContextGetter* |
[email protected] | 10705a7b | 2012-08-21 19:07:08 | [diff] [blame] | 165 | ShellBrowserContext::GetMediaRequestContext() { |
| 166 | return GetRequestContext(); |
| 167 | } |
| 168 | |
| 169 | net::URLRequestContextGetter* |
| 170 | ShellBrowserContext::GetMediaRequestContextForRenderProcess( |
| 171 | int renderer_child_id) { |
[email protected] | b0f146f | 2011-09-15 22:14:25 | [diff] [blame] | 172 | return GetRequestContext(); |
| 173 | } |
| 174 | |
[email protected] | 55c0eca | 2012-09-15 05:12:34 | [diff] [blame] | 175 | net::URLRequestContextGetter* |
[email protected] | 10eb2816 | 2012-09-18 03:04:09 | [diff] [blame] | 176 | ShellBrowserContext::GetMediaRequestContextForStoragePartition( |
[email protected] | d30a36f | 2013-02-07 04:16:26 | [diff] [blame] | 177 | const base::FilePath& partition_path, |
[email protected] | 27ddfed2 | 2012-10-30 23:22:43 | [diff] [blame] | 178 | bool in_memory) { |
[email protected] | 10eb2816 | 2012-09-18 03:04:09 | [diff] [blame] | 179 | return GetRequestContext(); |
| 180 | } |
| 181 | |
[email protected] | 6e068ea | 2014-02-04 07:05:47 | [diff] [blame] | 182 | void ShellBrowserContext::RequestMidiSysExPermission( |
[email protected] | 8aca725 | 2013-07-12 19:18:59 | [diff] [blame] | 183 | int render_process_id, |
| 184 | int render_view_id, |
[email protected] | 00880a0 | 2013-10-30 03:18:30 | [diff] [blame] | 185 | int bridge_id, |
[email protected] | 8aca725 | 2013-07-12 19:18:59 | [diff] [blame] | 186 | const GURL& requesting_frame, |
[email protected] | 7c6d948 | 2014-03-28 20:19:31 | [diff] [blame] | 187 | bool user_gesture, |
[email protected] | 6e068ea | 2014-02-04 07:05:47 | [diff] [blame] | 188 | const MidiSysExPermissionCallback& callback) { |
[email protected] | 1902732 | 2013-07-23 11:46:52 | [diff] [blame] | 189 | // Always reject requests for LayoutTests for now. |
[email protected] | 8aca725 | 2013-07-12 19:18:59 | [diff] [blame] | 190 | // TODO(toyoshim): Make it programmable to improve test coverage. |
[email protected] | 6e068ea | 2014-02-04 07:05:47 | [diff] [blame] | 191 | if (!CommandLine::ForCurrentProcess()->HasSwitch( |
| 192 | switches::kDumpRenderTree)) { |
[email protected] | 1902732 | 2013-07-23 11:46:52 | [diff] [blame] | 193 | callback.Run(false); |
| 194 | return; |
| 195 | } |
[email protected] | bccdcd9 | 2014-01-03 05:30:03 | [diff] [blame] | 196 | callback.Run(true); |
[email protected] | 8aca725 | 2013-07-12 19:18:59 | [diff] [blame] | 197 | } |
| 198 | |
[email protected] | 6e068ea | 2014-02-04 07:05:47 | [diff] [blame] | 199 | void ShellBrowserContext::CancelMidiSysExPermissionRequest( |
[email protected] | 00880a0 | 2013-10-30 03:18:30 | [diff] [blame] | 200 | int render_process_id, |
| 201 | int render_view_id, |
| 202 | int bridge_id, |
| 203 | const GURL& requesting_frame) { |
| 204 | } |
| 205 | |
[email protected] | 566755f8 | 2014-01-08 01:14:57 | [diff] [blame] | 206 | void ShellBrowserContext::RequestProtectedMediaIdentifierPermission( |
| 207 | int render_process_id, |
| 208 | int render_view_id, |
[email protected] | 5e170a5 | 2014-05-29 03:09:02 | [diff] [blame] | 209 | const GURL& origin, |
[email protected] | 566755f8 | 2014-01-08 01:14:57 | [diff] [blame] | 210 | const ProtectedMediaIdentifierPermissionCallback& callback) { |
| 211 | callback.Run(true); |
| 212 | } |
| 213 | |
| 214 | void ShellBrowserContext::CancelProtectedMediaIdentifierPermissionRequests( |
[email protected] | 5e170a5 | 2014-05-29 03:09:02 | [diff] [blame] | 215 | int render_process_id, |
| 216 | int render_view_id, |
| 217 | const GURL& origin) { |
[email protected] | 566755f8 | 2014-01-08 01:14:57 | [diff] [blame] | 218 | } |
| 219 | |
[email protected] | 10eb2816 | 2012-09-18 03:04:09 | [diff] [blame] | 220 | net::URLRequestContextGetter* |
[email protected] | 7571263c | 2014-03-10 22:57:09 | [diff] [blame] | 221 | ShellBrowserContext::CreateRequestContextForStoragePartition( |
| 222 | const base::FilePath& partition_path, |
| 223 | bool in_memory, |
| 224 | ProtocolHandlerMap* protocol_handlers, |
[email protected] | 3b90aab | 2014-05-30 17:56:15 | [diff] [blame] | 225 | URLRequestInterceptorScopedVector request_interceptors) { |
[email protected] | 55c0eca | 2012-09-15 05:12:34 | [diff] [blame] | 226 | return NULL; |
| 227 | } |
| 228 | |
[email protected] | df02aca | 2012-02-09 21:03:20 | [diff] [blame] | 229 | ResourceContext* ShellBrowserContext::GetResourceContext() { |
[email protected] | df02aca | 2012-02-09 21:03:20 | [diff] [blame] | 230 | return resource_context_.get(); |
[email protected] | b0f146f | 2011-09-15 22:14:25 | [diff] [blame] | 231 | } |
| 232 | |
[email protected] | b0f146f | 2011-09-15 22:14:25 | [diff] [blame] | 233 | GeolocationPermissionContext* |
| 234 | ShellBrowserContext::GetGeolocationPermissionContext() { |
[email protected] | 30e3e9a6 | 2012-06-07 20:46:57 | [diff] [blame] | 235 | return NULL; |
[email protected] | b0f146f | 2011-09-15 22:14:25 | [diff] [blame] | 236 | } |
| 237 | |
[email protected] | 139355f | 2014-05-11 14:21:28 | [diff] [blame] | 238 | BrowserPluginGuestManager* ShellBrowserContext::GetGuestManager() { |
| 239 | return guest_manager_; |
[email protected] | 2456926 | 2014-05-06 03:31:30 | [diff] [blame] | 240 | } |
| 241 | |
[email protected] | 55eb70e76 | 2012-02-20 17:38:39 | [diff] [blame] | 242 | quota::SpecialStoragePolicy* ShellBrowserContext::GetSpecialStoragePolicy() { |
| 243 | return NULL; |
[email protected] | b0f146f | 2011-09-15 22:14:25 | [diff] [blame] | 244 | } |
| 245 | |
[email protected] | c5c89d04 | 2014-06-13 14:43:37 | [diff] [blame^] | 246 | PushMessagingService* ShellBrowserContext::GetPushMessagingService() { |
| 247 | return NULL; |
| 248 | } |
| 249 | |
[email protected] | b0f146f | 2011-09-15 22:14:25 | [diff] [blame] | 250 | } // namespace content |