Chromium Code Reviews| 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 "android_webview/browser/net/aw_url_request_context_getter.h" | 5 #include "android_webview/browser/net/aw_url_request_context_getter.h" |
| 6 | 6 |
| 7 #include "android_webview/browser/aw_browser_context.h" | 7 #include "android_webview/browser/aw_browser_context.h" |
| 8 #include "android_webview/browser/aw_request_interceptor.h" | 8 #include "android_webview/browser/aw_request_interceptor.h" |
| 9 #include "android_webview/browser/net/aw_network_delegate.h" | 9 #include "android_webview/browser/net/aw_network_delegate.h" |
| 10 #include "android_webview/browser/net/aw_url_request_job_factory.h" | 10 #include "android_webview/browser/net/aw_url_request_job_factory.h" |
| 11 #include "android_webview/browser/net/init_native_callback.h" | 11 #include "android_webview/browser/net/init_native_callback.h" |
| 12 #include "content/public/browser/browser_thread.h" | 12 #include "content/public/browser/browser_thread.h" |
| 13 #include "content/public/browser/content_browser_client.h" | 13 #include "content/public/browser/content_browser_client.h" |
| 14 #include "content/public/browser/resource_context.h" | 14 #include "content/public/browser/resource_context.h" |
| 15 #include "content/public/common/content_client.h" | 15 #include "content/public/common/content_client.h" |
| 16 #include "content/public/common/url_constants.h" | 16 #include "content/public/common/url_constants.h" |
| 17 #include "net/http/http_cache.h" | |
| 17 #include "net/proxy/proxy_service.h" | 18 #include "net/proxy/proxy_service.h" |
| 18 #include "net/url_request/data_protocol_handler.h" | 19 #include "net/url_request/data_protocol_handler.h" |
| 19 #include "net/url_request/file_protocol_handler.h" | 20 #include "net/url_request/file_protocol_handler.h" |
| 20 #include "net/url_request/url_request_context_builder.h" | 21 #include "net/url_request/url_request_context_builder.h" |
| 21 #include "net/url_request/url_request_context.h" | 22 #include "net/url_request/url_request_context.h" |
| 22 | 23 |
| 23 using content::BrowserThread; | 24 using content::BrowserThread; |
| 24 | 25 |
| 25 namespace android_webview { | 26 namespace android_webview { |
| 26 | 27 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 85 builder.set_ftp_enabled(false); // Android WebView does not support ftp yet. | 86 builder.set_ftp_enabled(false); // Android WebView does not support ftp yet. |
| 86 builder.set_proxy_config_service(proxy_config_service_.release()); | 87 builder.set_proxy_config_service(proxy_config_service_.release()); |
| 87 builder.set_accept_language(net::HttpUtil::GenerateAcceptLanguageHeader( | 88 builder.set_accept_language(net::HttpUtil::GenerateAcceptLanguageHeader( |
| 88 content::GetContentClient()->browser()->GetAcceptLangs( | 89 content::GetContentClient()->browser()->GetAcceptLangs( |
| 89 browser_context_))); | 90 browser_context_))); |
| 90 | 91 |
| 91 // TODO(boliu): Values from chrome/app/resources/locale_settings_en-GB.xtb | 92 // TODO(boliu): Values from chrome/app/resources/locale_settings_en-GB.xtb |
| 92 builder.set_accept_charset( | 93 builder.set_accept_charset( |
| 93 net::HttpUtil::GenerateAcceptCharsetHeader("ISO-8859-1")); | 94 net::HttpUtil::GenerateAcceptCharsetHeader("ISO-8859-1")); |
| 94 | 95 |
| 95 net::URLRequestContextBuilder::HttpCacheParams cache_params; | |
| 96 cache_params.type = net::URLRequestContextBuilder::HttpCacheParams::DISK; | |
| 97 cache_params.max_size = 10 * 1024 * 1024; // 10M | |
| 98 cache_params.path = | |
| 99 browser_context_->GetPath().Append(FILE_PATH_LITERAL("Cache")), | |
|
boliu
2012/12/06 15:36:39
Unrelated: comma at the end of line...how did this
mnaganov (inactive)
2012/12/06 16:44:56
That's http://en.wikipedia.org/wiki/Comma_operator
boliu
2012/12/06 17:44:02
Mind blown...
| |
| 100 builder.EnableHttpCache(cache_params); | |
| 101 | |
| 102 url_request_context_.reset(builder.Build()); | 96 url_request_context_.reset(builder.Build()); |
| 103 | 97 |
| 104 job_factory_.reset(new AwURLRequestJobFactory); | 98 job_factory_.reset(new AwURLRequestJobFactory); |
| 105 bool set_protocol = job_factory_->SetProtocolHandler( | 99 bool set_protocol = job_factory_->SetProtocolHandler( |
| 106 chrome::kFileScheme, new net::FileProtocolHandler()); | 100 chrome::kFileScheme, new net::FileProtocolHandler()); |
| 107 DCHECK(set_protocol); | 101 DCHECK(set_protocol); |
| 108 set_protocol = job_factory_->SetProtocolHandler( | 102 set_protocol = job_factory_->SetProtocolHandler( |
| 109 chrome::kDataScheme, new net::DataProtocolHandler()); | 103 chrome::kDataScheme, new net::DataProtocolHandler()); |
| 110 DCHECK(set_protocol); | 104 DCHECK(set_protocol); |
| 111 job_factory_->AddInterceptor(new AwRequestInterceptor()); | 105 job_factory_->AddInterceptor(new AwRequestInterceptor()); |
| 112 url_request_context_->set_job_factory(job_factory_.get()); | 106 url_request_context_->set_job_factory(job_factory_.get()); |
| 113 | 107 |
| 108 net::HttpCache::DefaultBackend* main_backend = | |
|
boliu
2012/12/06 15:36:39
Can we add a TODO or NOTE saying builder doesn't s
mnaganov (inactive)
2012/12/06 16:44:56
Done.
| |
| 109 new net::HttpCache::DefaultBackend( | |
| 110 net::DISK_CACHE, | |
| 111 browser_context_->GetPath().Append(FILE_PATH_LITERAL("Cache")), | |
| 112 10 * 1024 * 1024, // 10M | |
| 113 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE)); | |
| 114 net::HttpNetworkSession::Params network_session_params; | |
| 115 PopulateNetworkSessionParams(&network_session_params); | |
| 116 net::HttpCache* main_cache = new net::HttpCache( | |
| 117 network_session_params, main_backend); | |
| 118 main_http_factory_.reset(main_cache); | |
|
boliu
2012/12/06 15:36:39
nit: combine this line and above so we never decla
mnaganov (inactive)
2012/12/06 16:44:56
Done.
| |
| 119 url_request_context_->set_http_transaction_factory(main_cache); | |
| 120 | |
| 114 OnNetworkStackInitialized(url_request_context_.get(), | 121 OnNetworkStackInitialized(url_request_context_.get(), |
| 115 job_factory_.get()); | 122 job_factory_.get()); |
| 116 } | 123 } |
| 117 | 124 |
| 125 void AwURLRequestContextGetter::PopulateNetworkSessionParams( | |
| 126 net::HttpNetworkSession::Params* params) { | |
| 127 net::URLRequestContext* context = url_request_context_.get(); | |
| 128 params->host_resolver = context->host_resolver(); | |
| 129 params->cert_verifier = context->cert_verifier(); | |
| 130 params->server_bound_cert_service = context->server_bound_cert_service(); | |
| 131 params->transport_security_state = context->transport_security_state(); | |
| 132 params->proxy_service = context->proxy_service(); | |
| 133 params->ssl_config_service = context->ssl_config_service(); | |
| 134 params->http_auth_handler_factory = context->http_auth_handler_factory(); | |
| 135 params->network_delegate = context->network_delegate(); | |
| 136 params->http_server_properties = context->http_server_properties(); | |
| 137 params->net_log = context->net_log(); | |
| 138 } | |
| 139 | |
| 118 content::ResourceContext* AwURLRequestContextGetter::GetResourceContext() { | 140 content::ResourceContext* AwURLRequestContextGetter::GetResourceContext() { |
| 119 DCHECK(url_request_context_); | 141 DCHECK(url_request_context_); |
| 120 if (!resource_context_) | 142 if (!resource_context_) |
| 121 resource_context_.reset(new AwResourceContext(url_request_context_.get())); | 143 resource_context_.reset(new AwResourceContext(url_request_context_.get())); |
| 122 return resource_context_.get(); | 144 return resource_context_.get(); |
| 123 } | 145 } |
| 124 | 146 |
| 125 net::URLRequestContext* AwURLRequestContextGetter::GetURLRequestContext() { | 147 net::URLRequestContext* AwURLRequestContextGetter::GetURLRequestContext() { |
| 126 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 148 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 127 return url_request_context_.get(); | 149 return url_request_context_.get(); |
| 128 } | 150 } |
| 129 | 151 |
| 130 scoped_refptr<base::SingleThreadTaskRunner> | 152 scoped_refptr<base::SingleThreadTaskRunner> |
| 131 AwURLRequestContextGetter::GetNetworkTaskRunner() const { | 153 AwURLRequestContextGetter::GetNetworkTaskRunner() const { |
| 132 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); | 154 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); |
| 133 } | 155 } |
| 134 | 156 |
| 135 } // namespace android_webview | 157 } // namespace android_webview |
| OLD | NEW |