blob: 52c66837de78c62c6d275a6b06869a3d8d5e8dc7 [file] [log] [blame]
[email protected]c5f1e332011-09-27 01:08:031// Copyright (c) 2011 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.
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]c38831a12011-10-28 12:44:499#include "content/public/browser/browser_thread.h"
[email protected]c5f1e332011-09-27 01:08:0310#include "net/base/cert_verifier.h"
11#include "net/base/cookie_monster.h"
12#include "net/base/default_origin_bound_cert_store.h"
13#include "net/base/dnsrr_resolver.h"
14#include "net/base/host_resolver.h"
[email protected]c5f1e332011-09-27 01:08:0315#include "net/base/origin_bound_cert_service.h"
16#include "net/base/ssl_config_service_defaults.h"
[email protected]c38831a12011-10-28 12:44:4917#include "net/http/http_auth_handler_factory.h"
18#include "net/http/http_cache.h"
19#include "net/http/http_server_properties_impl.h"
[email protected]c5f1e332011-09-27 01:08:0320#include "net/proxy/proxy_service.h"
21#include "net/url_request/url_request_context.h"
[email protected]98cce3ae2011-10-15 16:19:4122#include "net/url_request/url_request_context_storage.h"
[email protected]c5f1e332011-09-27 01:08:0323#include "net/url_request/url_request_job_factory.h"
24
25namespace content {
26
27ShellURLRequestContextGetter::ShellURLRequestContextGetter(
28 const FilePath& base_path_,
29 MessageLoop* io_loop,
30 MessageLoop* file_loop)
31 : io_loop_(io_loop),
32 file_loop_(file_loop) {
33}
34
35ShellURLRequestContextGetter::~ShellURLRequestContextGetter() {
36}
37
38net::URLRequestContext* ShellURLRequestContextGetter::GetURLRequestContext() {
39 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
40
41 if (!url_request_context_) {
[email protected]98cce3ae2011-10-15 16:19:4142 url_request_context_ = new net::URLRequestContext();
43 storage_.reset(new net::URLRequestContextStorage(url_request_context_));
44
45 storage_->set_cookie_store(new net::CookieMonster(NULL, NULL));
46 storage_->set_origin_bound_cert_service(new net::OriginBoundCertService(
47 new net::DefaultOriginBoundCertStore(NULL)));
48 url_request_context_->set_accept_language("en-us,en");
49 url_request_context_->set_accept_charset("iso-8859-1,*,utf-8");
50
51 scoped_ptr<net::ProxyConfigService> proxy_config_service(
52 net::ProxyService::CreateSystemProxyConfigService(
53 io_loop_, file_loop_));
54 storage_->set_host_resolver(
55 net::CreateSystemHostResolver(net::HostResolver::kDefaultParallelism,
56 net::HostResolver::kDefaultRetryAttempts,
57 NULL));
58 storage_->set_cert_verifier(new net::CertVerifier);
59 // TODO(jam): use v8 if possible, look at chrome code.
60 storage_->set_proxy_service(
61 net::ProxyService::CreateUsingSystemProxyResolver(
62 proxy_config_service.release(),
63 0,
64 NULL));
65 storage_->set_ssl_config_service(new net::SSLConfigServiceDefaults);
66 storage_->set_http_auth_handler_factory(
67 net::HttpAuthHandlerFactory::CreateDefault(
68 url_request_context_->host_resolver()));
69 storage_->set_http_server_properties(new net::HttpServerPropertiesImpl);
70
[email protected]c5f1e332011-09-27 01:08:0371 FilePath cache_path = base_path_.Append(FILE_PATH_LITERAL("Cache"));
72 net::HttpCache::DefaultBackend* main_backend =
73 new net::HttpCache::DefaultBackend(
74 net::DISK_CACHE,
75 cache_path,
76 0,
77 BrowserThread::GetMessageLoopProxyForThread(
78 BrowserThread::CACHE));
79
[email protected]98cce3ae2011-10-15 16:19:4180 storage_->set_dnsrr_resolver(new net::DnsRRResolver());
[email protected]c5f1e332011-09-27 01:08:0381
82 net::HttpCache* main_cache = new net::HttpCache(
[email protected]98cce3ae2011-10-15 16:19:4183 url_request_context_->host_resolver(),
84 url_request_context_->cert_verifier(),
85 url_request_context_->origin_bound_cert_service(),
86 url_request_context_->dnsrr_resolver(),
[email protected]c5f1e332011-09-27 01:08:0387 NULL, //dns_cert_checker
[email protected]98cce3ae2011-10-15 16:19:4188 url_request_context_->proxy_service(),
89 url_request_context_->ssl_config_service(),
90 url_request_context_->http_auth_handler_factory(),
[email protected]db96a882011-10-09 02:01:5491 NULL, // network_delegate
[email protected]98cce3ae2011-10-15 16:19:4192 url_request_context_->http_server_properties(),
93 NULL,
[email protected]c5f1e332011-09-27 01:08:0394 main_backend);
[email protected]98cce3ae2011-10-15 16:19:4195 storage_->set_http_transaction_factory(main_cache);
[email protected]c5f1e332011-09-27 01:08:0396
[email protected]98cce3ae2011-10-15 16:19:4197 storage_->set_job_factory(new net::URLRequestJobFactory);
[email protected]c5f1e332011-09-27 01:08:0398 }
99
100 return url_request_context_;
101}
102
103net::CookieStore* ShellURLRequestContextGetter::DONTUSEME_GetCookieStore() {
104 if (BrowserThread::CurrentlyOn(BrowserThread::IO))
105 return GetURLRequestContext()->cookie_store();
106 NOTIMPLEMENTED();
107 return NULL;
108}
109
110scoped_refptr<base::MessageLoopProxy>
111 ShellURLRequestContextGetter::GetIOMessageLoopProxy() const {
112 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO);
113}
114
[email protected]98cce3ae2011-10-15 16:19:41115net::HostResolver* ShellURLRequestContextGetter::host_resolver() {
116 return url_request_context_->host_resolver();
117}
118
[email protected]c5f1e332011-09-27 01:08:03119} // namespace content