blob: e0438a23e486a5fe848877d2d9d97980d6d957dd [file] [log] [blame]
[email protected]5cba3bf2012-01-14 02:40:351// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]c5f1e332011-09-27 01:08:032// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "content/shell/shell_url_request_context_getter.h"
6
7#include "base/logging.h"
8#include "base/string_split.h"
[email protected]5bab49ec2012-05-04 21:13:199#include "base/threading/worker_pool.h"
[email protected]c38831a12011-10-28 12:44:4910#include "content/public/browser/browser_thread.h"
[email protected]33bc2832012-03-29 08:18:1711#include "content/shell/shell_network_delegate.h"
[email protected]c5f1e332011-09-27 01:08:0312#include "net/base/cert_verifier.h"
[email protected]32cb7fb2012-03-22 22:41:1113#include "net/base/default_server_bound_cert_store.h"
[email protected]c5f1e332011-09-27 01:08:0314#include "net/base/host_resolver.h"
[email protected]32cb7fb2012-03-22 22:41:1115#include "net/base/server_bound_cert_service.h"
[email protected]c5f1e332011-09-27 01:08:0316#include "net/base/ssl_config_service_defaults.h"
[email protected]48839bfc2012-03-16 18:19:1117#include "net/cookies/cookie_monster.h"
[email protected]c38831a12011-10-28 12:44:4918#include "net/http/http_auth_handler_factory.h"
19#include "net/http/http_cache.h"
20#include "net/http/http_server_properties_impl.h"
[email protected]c5f1e332011-09-27 01:08:0321#include "net/proxy/proxy_service.h"
22#include "net/url_request/url_request_context.h"
[email protected]98cce3ae2011-10-15 16:19:4123#include "net/url_request/url_request_context_storage.h"
[email protected]c5f1e332011-09-27 01:08:0324#include "net/url_request/url_request_job_factory.h"
25
26namespace content {
27
28ShellURLRequestContextGetter::ShellURLRequestContextGetter(
[email protected]5cba3bf2012-01-14 02:40:3529 const FilePath& base_path,
[email protected]c5f1e332011-09-27 01:08:0330 MessageLoop* io_loop,
31 MessageLoop* file_loop)
[email protected]5cba3bf2012-01-14 02:40:3532 : base_path_(base_path),
33 io_loop_(io_loop),
[email protected]c5f1e332011-09-27 01:08:0334 file_loop_(file_loop) {
[email protected]5cba3bf2012-01-14 02:40:3535 // Must first be created on the UI thread.
36 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
37
38 // We must create the proxy config service on the UI loop on Linux because it
39 // must synchronously run on the glib message loop. This will be passed to
40 // the URLRequestContextStorage on the IO thread in GetURLRequestContext().
41 proxy_config_service_.reset(
42 net::ProxyService::CreateSystemProxyConfigService(
43 io_loop_, file_loop_));
[email protected]c5f1e332011-09-27 01:08:0344}
45
46ShellURLRequestContextGetter::~ShellURLRequestContextGetter() {
47}
48
49net::URLRequestContext* ShellURLRequestContextGetter::GetURLRequestContext() {
50 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
51
52 if (!url_request_context_) {
[email protected]98cce3ae2011-10-15 16:19:4153 url_request_context_ = new net::URLRequestContext();
[email protected]33bc2832012-03-29 08:18:1754 network_delegate_.reset(new ShellNetworkDelegate);
55 url_request_context_->set_network_delegate(network_delegate_.get());
[email protected]98cce3ae2011-10-15 16:19:4156 storage_.reset(new net::URLRequestContextStorage(url_request_context_));
[email protected]98cce3ae2011-10-15 16:19:4157 storage_->set_cookie_store(new net::CookieMonster(NULL, NULL));
[email protected]9c4eff22012-03-20 22:42:2958 storage_->set_server_bound_cert_service(new net::ServerBoundCertService(
[email protected]5bab49ec2012-05-04 21:13:1959 new net::DefaultServerBoundCertStore(NULL),
60 base::WorkerPool::GetTaskRunner(true)));
[email protected]98cce3ae2011-10-15 16:19:4161 url_request_context_->set_accept_language("en-us,en");
62 url_request_context_->set_accept_charset("iso-8859-1,*,utf-8");
63
[email protected]98cce3ae2011-10-15 16:19:4164 storage_->set_host_resolver(
65 net::CreateSystemHostResolver(net::HostResolver::kDefaultParallelism,
66 net::HostResolver::kDefaultRetryAttempts,
67 NULL));
[email protected]9f59fac2012-03-21 23:18:1168 storage_->set_cert_verifier(net::CertVerifier::CreateDefault());
[email protected]98cce3ae2011-10-15 16:19:4169 // TODO(jam): use v8 if possible, look at chrome code.
70 storage_->set_proxy_service(
71 net::ProxyService::CreateUsingSystemProxyResolver(
[email protected]5cba3bf2012-01-14 02:40:3572 proxy_config_service_.release(),
[email protected]98cce3ae2011-10-15 16:19:4173 0,
74 NULL));
75 storage_->set_ssl_config_service(new net::SSLConfigServiceDefaults);
76 storage_->set_http_auth_handler_factory(
77 net::HttpAuthHandlerFactory::CreateDefault(
78 url_request_context_->host_resolver()));
79 storage_->set_http_server_properties(new net::HttpServerPropertiesImpl);
80
[email protected]c5f1e332011-09-27 01:08:0381 FilePath cache_path = base_path_.Append(FILE_PATH_LITERAL("Cache"));
82 net::HttpCache::DefaultBackend* main_backend =
83 new net::HttpCache::DefaultBackend(
84 net::DISK_CACHE,
85 cache_path,
86 0,
87 BrowserThread::GetMessageLoopProxyForThread(
88 BrowserThread::CACHE));
89
[email protected]c5f1e332011-09-27 01:08:0390 net::HttpCache* main_cache = new net::HttpCache(
[email protected]98cce3ae2011-10-15 16:19:4191 url_request_context_->host_resolver(),
92 url_request_context_->cert_verifier(),
[email protected]9c4eff22012-03-20 22:42:2993 url_request_context_->server_bound_cert_service(),
[email protected]61b4efc2012-04-27 18:12:5094 NULL, /* transport_security_state */
[email protected]98cce3ae2011-10-15 16:19:4195 url_request_context_->proxy_service(),
[email protected]61b4efc2012-04-27 18:12:5096 "", /* ssl_session_cache_shard */
[email protected]98cce3ae2011-10-15 16:19:4197 url_request_context_->ssl_config_service(),
98 url_request_context_->http_auth_handler_factory(),
[email protected]33bc2832012-03-29 08:18:1799 url_request_context_->network_delegate(),
[email protected]98cce3ae2011-10-15 16:19:41100 url_request_context_->http_server_properties(),
101 NULL,
[email protected]61b4efc2012-04-27 18:12:50102 main_backend,
103 "" /* trusted_spdy_proxy */ );
[email protected]98cce3ae2011-10-15 16:19:41104 storage_->set_http_transaction_factory(main_cache);
[email protected]c5f1e332011-09-27 01:08:03105
[email protected]98cce3ae2011-10-15 16:19:41106 storage_->set_job_factory(new net::URLRequestJobFactory);
[email protected]c5f1e332011-09-27 01:08:03107 }
108
109 return url_request_context_;
110}
111
[email protected]c5f1e332011-09-27 01:08:03112scoped_refptr<base::MessageLoopProxy>
113 ShellURLRequestContextGetter::GetIOMessageLoopProxy() const {
114 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO);
115}
116
[email protected]98cce3ae2011-10-15 16:19:41117net::HostResolver* ShellURLRequestContextGetter::host_resolver() {
118 return url_request_context_->host_resolver();
119}
120
[email protected]c5f1e332011-09-27 01:08:03121} // namespace content