blob: 96fc8f880e63e6a40ec62958b5050ee439d8a663 [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"
9#include "content/browser/browser_thread.h"
10#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"
15#include "net/http/http_auth_handler_factory.h"
16#include "net/http/http_cache.h"
17#include "net/base/origin_bound_cert_service.h"
18#include "net/base/ssl_config_service_defaults.h"
19#include "net/proxy/proxy_service.h"
20#include "net/url_request/url_request_context.h"
21#include "net/url_request/url_request_context_getter.h"
22#include "net/url_request/url_request_job_factory.h"
23
24namespace content {
25
26ShellURLRequestContextGetter::ShellURLRequestContextGetter(
27 const FilePath& base_path_,
28 MessageLoop* io_loop,
29 MessageLoop* file_loop)
30 : io_loop_(io_loop),
31 file_loop_(file_loop) {
32}
33
34ShellURLRequestContextGetter::~ShellURLRequestContextGetter() {
35}
36
37net::URLRequestContext* ShellURLRequestContextGetter::GetURLRequestContext() {
38 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
39
40 if (!url_request_context_) {
41 FilePath cache_path = base_path_.Append(FILE_PATH_LITERAL("Cache"));
42 net::HttpCache::DefaultBackend* main_backend =
43 new net::HttpCache::DefaultBackend(
44 net::DISK_CACHE,
45 cache_path,
46 0,
47 BrowserThread::GetMessageLoopProxyForThread(
48 BrowserThread::CACHE));
49
50 net::NetLog* net_log = NULL;
51 host_resolver_.reset(net::CreateSystemHostResolver(
52 net::HostResolver::kDefaultParallelism,
53 net::HostResolver::kDefaultRetryAttempts,
54 net_log));
55
56 cert_verifier_.reset(new net::CertVerifier());
57
58 origin_bound_cert_service_.reset(new net::OriginBoundCertService(
59 new net::DefaultOriginBoundCertStore(NULL)));
60
61 dnsrr_resolver_.reset(new net::DnsRRResolver());
62
63 net::ProxyConfigService* proxy_config_service =
64 net::ProxyService::CreateSystemProxyConfigService(
65 io_loop_,
66 file_loop_);
67
68 // TODO(jam): use v8 if possible, look at chrome code.
69 proxy_service_.reset(
70 net::ProxyService::CreateUsingSystemProxyResolver(
71 proxy_config_service,
72 0,
73 net_log));
74
75 url_security_manager_.reset(net::URLSecurityManager::Create(NULL, NULL));
76
77 std::vector<std::string> supported_schemes;
78 base::SplitString("basic,digest,ntlm,negotiate", ',', &supported_schemes);
79 http_auth_handler_factory_.reset(
80 net::HttpAuthHandlerRegistryFactory::Create(
81 supported_schemes,
82 url_security_manager_.get(),
83 host_resolver_.get(),
84 std::string(), // gssapi_library_name
85 false, // negotiate_disable_cname_lookup
86 false)); // negotiate_enable_port
87
88 net::HttpCache* main_cache = new net::HttpCache(
89 host_resolver_.get(),
90 cert_verifier_.get(),
91 origin_bound_cert_service_.get(),
92 dnsrr_resolver_.get(),
93 NULL, //dns_cert_checker
94 proxy_service_.get(),
95 new net::SSLConfigServiceDefaults(),
96 http_auth_handler_factory_.get(),
97 NULL, // network_delegate
98 net_log,
99 main_backend);
100 main_http_factory_.reset(main_cache);
101
102 scoped_refptr<net::CookieStore> cookie_store =
103 new net::CookieMonster(NULL, NULL);
104
105 url_request_context_ = new net::URLRequestContext();
106 job_factory_.reset(new net::URLRequestJobFactory);
107 url_request_context_->set_job_factory(job_factory_.get());
108 url_request_context_->set_http_transaction_factory(main_cache);
109 url_request_context_->set_origin_bound_cert_service(
110 origin_bound_cert_service_.get());
111 url_request_context_->set_dnsrr_resolver(dnsrr_resolver_.get());
112 url_request_context_->set_proxy_service(proxy_service_.get());
113 url_request_context_->set_cookie_store(cookie_store);
114 }
115
116 return url_request_context_;
117}
118
119net::CookieStore* ShellURLRequestContextGetter::DONTUSEME_GetCookieStore() {
120 if (BrowserThread::CurrentlyOn(BrowserThread::IO))
121 return GetURLRequestContext()->cookie_store();
122 NOTIMPLEMENTED();
123 return NULL;
124}
125
126scoped_refptr<base::MessageLoopProxy>
127 ShellURLRequestContextGetter::GetIOMessageLoopProxy() const {
128 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO);
129}
130
131} // namespace content