OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/profiles/off_the_record_profile_io_data.h" | 5 #include "chrome/browser/profiles/off_the_record_profile_io_data.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
11 #include "base/threading/worker_pool.h" | 11 #include "base/threading/worker_pool.h" |
12 #include "build/build_config.h" | 12 #include "build/build_config.h" |
13 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
| 14 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" |
| 15 #include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h" |
14 #include "chrome/browser/io_thread.h" | 16 #include "chrome/browser/io_thread.h" |
15 #include "chrome/browser/net/about_protocol_handler.h" | 17 #include "chrome/browser/net/about_protocol_handler.h" |
16 #include "chrome/browser/net/chrome_net_log.h" | 18 #include "chrome/browser/net/chrome_net_log.h" |
17 #include "chrome/browser/net/chrome_url_request_context.h" | 19 #include "chrome/browser/net/chrome_url_request_context.h" |
18 #include "chrome/browser/prefs/pref_service.h" | 20 #include "chrome/browser/prefs/pref_service.h" |
19 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
20 #include "chrome/browser/ui/webui/chrome_url_data_manager_backend.h" | 22 #include "chrome/browser/ui/webui/chrome_url_data_manager_backend.h" |
21 #include "chrome/common/chrome_switches.h" | 23 #include "chrome/common/chrome_switches.h" |
22 #include "chrome/common/extensions/extension.h" | 24 #include "chrome/common/extensions/extension.h" |
23 #include "chrome/common/pref_names.h" | 25 #include "chrome/common/pref_names.h" |
24 #include "chrome/common/url_constants.h" | 26 #include "chrome/common/url_constants.h" |
25 #include "content/public/browser/browser_thread.h" | 27 #include "content/public/browser/browser_thread.h" |
26 #include "content/public/browser/resource_context.h" | 28 #include "content/public/browser/resource_context.h" |
27 #include "net/base/default_server_bound_cert_store.h" | 29 #include "net/base/default_server_bound_cert_store.h" |
28 #include "net/base/server_bound_cert_service.h" | 30 #include "net/base/server_bound_cert_service.h" |
29 #include "net/ftp/ftp_network_layer.h" | 31 #include "net/ftp/ftp_network_layer.h" |
30 #include "net/http/http_cache.h" | 32 #include "net/http/http_cache.h" |
31 #include "net/http/http_network_session.h" | 33 #include "net/http/http_network_session.h" |
32 #include "net/http/http_server_properties_impl.h" | 34 #include "net/http/http_server_properties_impl.h" |
33 #include "net/url_request/file_protocol_handler.h" | |
34 #include "net/url_request/ftp_protocol_handler.h" | |
35 #include "net/url_request/url_request_job_factory_impl.h" | 35 #include "net/url_request/url_request_job_factory_impl.h" |
36 #include "webkit/database/database_tracker.h" | 36 #include "webkit/database/database_tracker.h" |
37 | 37 |
38 using content::BrowserThread; | 38 using content::BrowserThread; |
39 | 39 |
40 OffTheRecordProfileIOData::Handle::Handle(Profile* profile) | 40 OffTheRecordProfileIOData::Handle::Handle(Profile* profile) |
41 : io_data_(new OffTheRecordProfileIOData), | 41 : io_data_(new OffTheRecordProfileIOData), |
42 profile_(profile), | 42 profile_(profile), |
43 initialized_(false) { | 43 initialized_(false) { |
44 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 44 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 121 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
122 DCHECK(!app_id.empty()); | 122 DCHECK(!app_id.empty()); |
123 LazyInitialize(); | 123 LazyInitialize(); |
124 | 124 |
125 // Keep a map of request context getters, one per requested app ID. | 125 // Keep a map of request context getters, one per requested app ID. |
126 ChromeURLRequestContextGetterMap::iterator iter = | 126 ChromeURLRequestContextGetterMap::iterator iter = |
127 app_request_context_getter_map_.find(app_id); | 127 app_request_context_getter_map_.find(app_id); |
128 if (iter != app_request_context_getter_map_.end()) | 128 if (iter != app_request_context_getter_map_.end()) |
129 return iter->second; | 129 return iter->second; |
130 | 130 |
| 131 scoped_ptr<net::URLRequestJobFactory::Interceptor> |
| 132 protocol_handler_interceptor( |
| 133 ProtocolHandlerRegistryFactory::GetForProfile(profile_)-> |
| 134 CreateURLInterceptor()); |
131 ChromeURLRequestContextGetter* context = | 135 ChromeURLRequestContextGetter* context = |
132 ChromeURLRequestContextGetter::CreateOffTheRecordForIsolatedApp( | 136 ChromeURLRequestContextGetter::CreateOffTheRecordForIsolatedApp( |
133 profile_, io_data_, app_id); | 137 profile_, io_data_, app_id, protocol_handler_interceptor.Pass()); |
134 app_request_context_getter_map_[app_id] = context; | 138 app_request_context_getter_map_[app_id] = context; |
135 | 139 |
136 return context; | 140 return context; |
137 } | 141 } |
138 | 142 |
139 void OffTheRecordProfileIOData::Handle::LazyInitialize() const { | 143 void OffTheRecordProfileIOData::Handle::LazyInitialize() const { |
140 if (initialized_) | 144 if (initialized_) |
141 return; | 145 return; |
142 | 146 |
143 // Set initialized_ to true at the beginning in case any of the objects | 147 // Set initialized_ to true at the beginning in case any of the objects |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 main_context->set_http_transaction_factory(cache); | 231 main_context->set_http_transaction_factory(cache); |
228 #if !defined(DISABLE_FTP_SUPPORT) | 232 #if !defined(DISABLE_FTP_SUPPORT) |
229 ftp_factory_.reset( | 233 ftp_factory_.reset( |
230 new net::FtpNetworkLayer(main_context->host_resolver())); | 234 new net::FtpNetworkLayer(main_context->host_resolver())); |
231 main_context->set_ftp_transaction_factory(ftp_factory_.get()); | 235 main_context->set_ftp_transaction_factory(ftp_factory_.get()); |
232 #endif // !defined(DISABLE_FTP_SUPPORT) | 236 #endif // !defined(DISABLE_FTP_SUPPORT) |
233 | 237 |
234 main_context->set_chrome_url_data_manager_backend( | 238 main_context->set_chrome_url_data_manager_backend( |
235 chrome_url_data_manager_backend()); | 239 chrome_url_data_manager_backend()); |
236 | 240 |
237 main_job_factory_.reset(new net::URLRequestJobFactoryImpl); | 241 main_job_factory_.reset(new net::URLRequestJobFactoryImpl()); |
238 extensions_job_factory_.reset(new net::URLRequestJobFactoryImpl); | 242 extensions_job_factory_.reset(new net::URLRequestJobFactoryImpl()); |
239 | 243 |
240 int set_protocol = main_job_factory_->SetProtocolHandler( | 244 SetUpJobFactoryDefaults( |
241 chrome::kFileScheme, new net::FileProtocolHandler()); | 245 main_job_factory_.get(), |
242 DCHECK(set_protocol); | 246 profile_params->protocol_handler_interceptor.Pass(), |
243 // TODO(shalev): The extension_job_factory_ has a NULL NetworkDelegate. | 247 network_delegate(), |
| 248 main_context->ftp_transaction_factory(), |
| 249 main_context->ftp_auth_cache()); |
| 250 // TODO(shalev): The extensions_job_factory has a NULL NetworkDelegate. |
244 // Without a network_delegate, this protocol handler will never | 251 // Without a network_delegate, this protocol handler will never |
245 // handle file: requests, but as a side effect it makes | 252 // handle file: requests, but as a side effect it makes |
246 // job_factory::IsHandledProtocol return true, which prevents attempts to | 253 // job_factory::IsHandledProtocol return true, which prevents attempts to |
247 // handle the protocol externally. | 254 // handle the protocol externally. We pass NULL in to |
248 set_protocol = extensions_job_factory_->SetProtocolHandler( | 255 // SetUpJobFactoryDefaults() to get this effect. |
249 chrome::kFileScheme, new net::FileProtocolHandler()); | 256 SetUpJobFactoryDefaults( |
250 DCHECK(set_protocol); | 257 extensions_job_factory_.get(), |
251 | 258 scoped_ptr<net::URLRequestJobFactoryImpl::Interceptor>(NULL), |
252 set_protocol = main_job_factory_->SetProtocolHandler( | 259 NULL, |
253 chrome::kChromeDevToolsScheme, | 260 extensions_context->ftp_transaction_factory(), |
254 CreateDevToolsProtocolHandler(chrome_url_data_manager_backend(), | 261 extensions_context->ftp_auth_cache()); |
255 network_delegate())); | |
256 DCHECK(set_protocol); | |
257 set_protocol = extensions_job_factory_->SetProtocolHandler( | |
258 chrome::kChromeDevToolsScheme, | |
259 CreateDevToolsProtocolHandler(chrome_url_data_manager_backend(), NULL)); | |
260 DCHECK(set_protocol); | |
261 | |
262 net::URLRequestJobFactory* job_factories[2]; | |
263 job_factories[0] = main_job_factory_.get(); | |
264 job_factories[1] = extensions_job_factory_.get(); | |
265 | |
266 net::FtpAuthCache* ftp_auth_caches[2]; | |
267 ftp_auth_caches[0] = main_context->ftp_auth_cache(); | |
268 ftp_auth_caches[1] = extensions_context->ftp_auth_cache(); | |
269 | |
270 for (int i = 0; i < 2; i++) { | |
271 SetUpJobFactoryDefaults(job_factories[i]); | |
272 job_factories[i]->SetProtocolHandler(chrome::kAboutScheme, | |
273 new net::AboutProtocolHandler()); | |
274 CreateFtpProtocolHandler(job_factories[i], ftp_auth_caches[i]); | |
275 } | |
276 | 262 |
277 main_context->set_job_factory(main_job_factory_.get()); | 263 main_context->set_job_factory(main_job_factory_.get()); |
278 extensions_context->set_job_factory(extensions_job_factory_.get()); | 264 extensions_context->set_job_factory(extensions_job_factory_.get()); |
279 } | 265 } |
280 | 266 |
281 ChromeURLRequestContext* | 267 ChromeURLRequestContext* |
282 OffTheRecordProfileIOData::InitializeAppRequestContext( | 268 OffTheRecordProfileIOData::InitializeAppRequestContext( |
283 ChromeURLRequestContext* main_context, | 269 ChromeURLRequestContext* main_context, |
284 const std::string& app_id) const { | 270 const std::string& app_id, |
| 271 scoped_ptr<net::URLRequestJobFactory::Interceptor> |
| 272 protocol_handler_interceptor) const { |
285 AppRequestContext* context = new AppRequestContext(load_time_stats()); | 273 AppRequestContext* context = new AppRequestContext(load_time_stats()); |
286 | 274 |
287 // Copy most state from the main context. | 275 // Copy most state from the main context. |
288 context->CopyFrom(main_context); | 276 context->CopyFrom(main_context); |
289 | 277 |
290 // Use a separate in-memory cookie store for the app. | 278 // Use a separate in-memory cookie store for the app. |
291 // TODO(creis): We should have a cookie delegate for notifying the cookie | 279 // TODO(creis): We should have a cookie delegate for notifying the cookie |
292 // extensions API, but we need to update it to understand isolated apps first. | 280 // extensions API, but we need to update it to understand isolated apps first. |
293 context->SetCookieStore(new net::CookieMonster(NULL, NULL)); | 281 context->SetCookieStore(new net::CookieMonster(NULL, NULL)); |
294 | 282 |
295 // Use a separate in-memory cache for the app. | 283 // Use a separate in-memory cache for the app. |
296 net::HttpCache::BackendFactory* app_backend = | 284 net::HttpCache::BackendFactory* app_backend = |
297 net::HttpCache::DefaultBackend::InMemory(0); | 285 net::HttpCache::DefaultBackend::InMemory(0); |
298 net::HttpNetworkSession* main_network_session = | 286 net::HttpNetworkSession* main_network_session = |
299 main_http_factory_->GetSession(); | 287 main_http_factory_->GetSession(); |
300 net::HttpCache* app_http_cache = | 288 scoped_ptr<net::HttpTransactionFactory> app_http_cache( |
301 new net::HttpCache(main_network_session, app_backend); | 289 new net::HttpCache(main_network_session, app_backend)); |
302 | 290 |
303 context->SetHttpTransactionFactory(app_http_cache); | 291 context->SetHttpTransactionFactory(app_http_cache.Pass()); |
| 292 |
| 293 scoped_ptr<net::URLRequestJobFactory> job_factory( |
| 294 new net::URLRequestJobFactoryImpl()); |
| 295 SetUpJobFactoryDefaults(job_factory.get(), |
| 296 protocol_handler_interceptor.Pass(), |
| 297 network_delegate(), |
| 298 context->ftp_transaction_factory(), |
| 299 context->ftp_auth_cache()); |
| 300 context->SetJobFactory(job_factory.Pass()); |
304 return context; | 301 return context; |
305 } | 302 } |
306 | 303 |
307 ChromeURLRequestContext* | 304 ChromeURLRequestContext* |
308 OffTheRecordProfileIOData::InitializeMediaRequestContext( | 305 OffTheRecordProfileIOData::InitializeMediaRequestContext( |
309 ChromeURLRequestContext* original_context, | 306 ChromeURLRequestContext* original_context, |
310 const std::string& app_id) const { | 307 const std::string& app_id) const { |
311 NOTREACHED(); | 308 NOTREACHED(); |
312 return NULL; | 309 return NULL; |
313 } | 310 } |
314 | 311 |
315 ChromeURLRequestContext* | 312 ChromeURLRequestContext* |
316 OffTheRecordProfileIOData::AcquireMediaRequestContext() const { | 313 OffTheRecordProfileIOData::AcquireMediaRequestContext() const { |
317 NOTREACHED(); | 314 NOTREACHED(); |
318 return NULL; | 315 return NULL; |
319 } | 316 } |
320 | 317 |
321 ChromeURLRequestContext* | 318 ChromeURLRequestContext* |
322 OffTheRecordProfileIOData::AcquireIsolatedAppRequestContext( | 319 OffTheRecordProfileIOData::AcquireIsolatedAppRequestContext( |
323 ChromeURLRequestContext* main_context, | 320 ChromeURLRequestContext* main_context, |
324 const std::string& app_id) const { | 321 const std::string& app_id, |
| 322 scoped_ptr<net::URLRequestJobFactory::Interceptor> |
| 323 protocol_handler_interceptor) const { |
325 // We create per-app contexts on demand, unlike the others above. | 324 // We create per-app contexts on demand, unlike the others above. |
326 ChromeURLRequestContext* app_request_context = | 325 ChromeURLRequestContext* app_request_context = |
327 InitializeAppRequestContext(main_context, app_id); | 326 InitializeAppRequestContext(main_context, app_id, |
| 327 protocol_handler_interceptor.Pass()); |
328 DCHECK(app_request_context); | 328 DCHECK(app_request_context); |
329 return app_request_context; | 329 return app_request_context; |
330 } | 330 } |
331 | 331 |
332 ChromeURLRequestContext* | 332 ChromeURLRequestContext* |
333 OffTheRecordProfileIOData::AcquireIsolatedMediaRequestContext( | 333 OffTheRecordProfileIOData::AcquireIsolatedMediaRequestContext( |
334 ChromeURLRequestContext* app_context, | 334 ChromeURLRequestContext* app_context, |
335 const std::string& app_id) const { | 335 const std::string& app_id) const { |
336 NOTREACHED(); | 336 NOTREACHED(); |
337 return NULL; | 337 return NULL; |
338 } | 338 } |
339 | 339 |
340 void OffTheRecordProfileIOData::CreateFtpProtocolHandler( | |
341 net::URLRequestJobFactory* job_factory, | |
342 net::FtpAuthCache* ftp_auth_cache) const { | |
343 #if !defined(DISABLE_FTP_SUPPORT) | |
344 job_factory->SetProtocolHandler( | |
345 chrome::kFtpScheme, | |
346 new net::FtpProtocolHandler(ftp_factory_.get(), ftp_auth_cache)); | |
347 #endif // !defined(DISABLE_FTP_SUPPORT) | |
348 } | |
349 | |
350 chrome_browser_net::LoadTimeStats* OffTheRecordProfileIOData::GetLoadTimeStats( | 340 chrome_browser_net::LoadTimeStats* OffTheRecordProfileIOData::GetLoadTimeStats( |
351 IOThread::Globals* io_thread_globals) const { | 341 IOThread::Globals* io_thread_globals) const { |
352 return NULL; | 342 return NULL; |
353 } | 343 } |
OLD | NEW |