blob: b21c9b3432670c3031008e50aea5eb286cd0fbd3 [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]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"
[email protected]c5f1e332011-09-27 01:08:0313#include "net/base/host_resolver.h"
[email protected]c5f1e332011-09-27 01:08:0314#include "net/base/origin_bound_cert_service.h"
15#include "net/base/ssl_config_service_defaults.h"
[email protected]c38831a12011-10-28 12:44:4916#include "net/http/http_auth_handler_factory.h"
17#include "net/http/http_cache.h"
18#include "net/http/http_server_properties_impl.h"
[email protected]c5f1e332011-09-27 01:08:0319#include "net/proxy/proxy_service.h"
20#include "net/url_request/url_request_context.h"
[email protected]98cce3ae2011-10-15 16:19:4121#include "net/url_request/url_request_context_storage.h"
[email protected]c5f1e332011-09-27 01:08:0322#include "net/url_request/url_request_job_factory.h"
23
24namespace content {
25
26ShellURLRequestContextGetter::ShellURLRequestContextGetter(
[email protected]5cba3bf2012-01-14 02:40:3527 const FilePath& base_path,
[email protected]c5f1e332011-09-27 01:08:0328 MessageLoop* io_loop,
29 MessageLoop* file_loop)
[email protected]5cba3bf2012-01-14 02:40:3530 : base_path_(base_path),
31 io_loop_(io_loop),
[email protected]c5f1e332011-09-27 01:08:0332 file_loop_(file_loop) {
[email protected]5cba3bf2012-01-14 02:40:3533 // Must first be created on the UI thread.
34 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
35
36 // We must create the proxy config service on the UI loop on Linux because it
37 // must synchronously run on the glib message loop. This will be passed to
38 // the URLRequestContextStorage on the IO thread in GetURLRequestContext().
39 proxy_config_service_.reset(
40 net::ProxyService::CreateSystemProxyConfigService(
41 io_loop_, file_loop_));
[email protected]c5f1e332011-09-27 01:08:0342}
43
44ShellURLRequestContextGetter::~ShellURLRequestContextGetter() {
45}
46
47net::URLRequestContext* ShellURLRequestContextGetter::GetURLRequestContext() {
48 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
49
50 if (!url_request_context_) {
[email protected]98cce3ae2011-10-15 16:19:4151 url_request_context_ = new net::URLRequestContext();
52 storage_.reset(new net::URLRequestContextStorage(url_request_context_));
53
54 storage_->set_cookie_store(new net::CookieMonster(NULL, NULL));
55 storage_->set_origin_bound_cert_service(new net::OriginBoundCertService(
56 new net::DefaultOriginBoundCertStore(NULL)));
57 url_request_context_->set_accept_language("en-us,en");
58 url_request_context_->set_accept_charset("iso-8859-1,*,utf-8");
59
[email protected]98cce3ae2011-10-15 16:19:4160 storage_->set_host_resolver(
61 net::CreateSystemHostResolver(net::HostResolver::kDefaultParallelism,
62 net::HostResolver::kDefaultRetryAttempts,
63 NULL));
64 storage_->set_cert_verifier(new net::CertVerifier);
65 // TODO(jam): use v8 if possible, look at chrome code.
66 storage_->set_proxy_service(
67 net::ProxyService::CreateUsingSystemProxyResolver(
[email protected]5cba3bf2012-01-14 02:40:3568 proxy_config_service_.release(),
[email protected]98cce3ae2011-10-15 16:19:4169 0,
70 NULL));
71 storage_->set_ssl_config_service(new net::SSLConfigServiceDefaults);
72 storage_->set_http_auth_handler_factory(
73 net::HttpAuthHandlerFactory::CreateDefault(
74 url_request_context_->host_resolver()));
75 storage_->set_http_server_properties(new net::HttpServerPropertiesImpl);
76
[email protected]c5f1e332011-09-27 01:08:0377 FilePath cache_path = base_path_.Append(FILE_PATH_LITERAL("Cache"));
78 net::HttpCache::DefaultBackend* main_backend =
79 new net::HttpCache::DefaultBackend(
80 net::DISK_CACHE,
81 cache_path,
82 0,
83 BrowserThread::GetMessageLoopProxyForThread(
84 BrowserThread::CACHE));
85
[email protected]c5f1e332011-09-27 01:08:0386 net::HttpCache* main_cache = new net::HttpCache(
[email protected]98cce3ae2011-10-15 16:19:4187 url_request_context_->host_resolver(),
88 url_request_context_->cert_verifier(),
89 url_request_context_->origin_bound_cert_service(),
[email protected]3ed7496f2011-12-15 18:27:4090 NULL, // tranport_security_state
[email protected]98cce3ae2011-10-15 16:19:4191 url_request_context_->proxy_service(),
[email protected]3ed7496f2011-12-15 18:27:4092 "", // ssl_session_cache_shard
[email protected]98cce3ae2011-10-15 16:19:4193 url_request_context_->ssl_config_service(),
94 url_request_context_->http_auth_handler_factory(),
[email protected]db96a882011-10-09 02:01:5495 NULL, // network_delegate
[email protected]98cce3ae2011-10-15 16:19:4196 url_request_context_->http_server_properties(),
97 NULL,
[email protected]c5f1e332011-09-27 01:08:0398 main_backend);
[email protected]98cce3ae2011-10-15 16:19:4199 storage_->set_http_transaction_factory(main_cache);
[email protected]c5f1e332011-09-27 01:08:03100
[email protected]98cce3ae2011-10-15 16:19:41101 storage_->set_job_factory(new net::URLRequestJobFactory);
[email protected]c5f1e332011-09-27 01:08:03102 }
103
104 return url_request_context_;
105}
106
107net::CookieStore* ShellURLRequestContextGetter::DONTUSEME_GetCookieStore() {
108 if (BrowserThread::CurrentlyOn(BrowserThread::IO))
109 return GetURLRequestContext()->cookie_store();
110 NOTIMPLEMENTED();
111 return NULL;
112}
113
114scoped_refptr<base::MessageLoopProxy>
115 ShellURLRequestContextGetter::GetIOMessageLoopProxy() const {
116 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO);
117}
118
[email protected]98cce3ae2011-10-15 16:19:41119net::HostResolver* ShellURLRequestContextGetter::host_resolver() {
120 return url_request_context_->host_resolver();
121}
122
[email protected]c5f1e332011-09-27 01:08:03123} // namespace content