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 <vector> | 7 #include <vector> |
8 | 8 |
9 #include "android_webview/browser/aw_browser_context.h" | 9 #include "android_webview/browser/aw_browser_context.h" |
10 #include "android_webview/browser/aw_content_browser_client.h" | 10 #include "android_webview/browser/aw_content_browser_client.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 BrowserThread::SetDelegate(BrowserThread::IO, this); | 47 BrowserThread::SetDelegate(BrowserThread::IO, this); |
48 } | 48 } |
49 | 49 |
50 AwURLRequestContextGetter::~AwURLRequestContextGetter() { | 50 AwURLRequestContextGetter::~AwURLRequestContextGetter() { |
51 BrowserThread::SetDelegate(BrowserThread::IO, NULL); | 51 BrowserThread::SetDelegate(BrowserThread::IO, NULL); |
52 } | 52 } |
53 | 53 |
54 void AwURLRequestContextGetter::Init() { | 54 void AwURLRequestContextGetter::Init() { |
55 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 55 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
56 | 56 |
| 57 cookie_store_ = content::CreatePersistentCookieStore( |
| 58 browser_context_->GetPath().Append(FILE_PATH_LITERAL("Cookies")), |
| 59 true, |
| 60 NULL, |
| 61 NULL); |
| 62 cookie_store_->GetCookieMonster()->SetPersistSessionCookies(true); |
| 63 |
| 64 // The CookieMonster must be passed here so it happens synchronously to |
| 65 // the main thread initialization (to avoid race condition in another |
| 66 // thread trying to access the CookieManager API). |
| 67 DidCreateCookieMonster(cookie_store_->GetCookieMonster()); |
| 68 } |
| 69 |
| 70 void AwURLRequestContextGetter::InitAsync() { |
| 71 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 72 |
57 net::URLRequestContextBuilder builder; | 73 net::URLRequestContextBuilder builder; |
58 builder.set_user_agent(content::GetUserAgent(GURL())); | 74 builder.set_user_agent(content::GetUserAgent(GURL())); |
59 builder.set_network_delegate(new AwNetworkDelegate()); | 75 builder.set_network_delegate(new AwNetworkDelegate()); |
60 #if !defined(DISABLE_FTP_SUPPORT) | 76 #if !defined(DISABLE_FTP_SUPPORT) |
61 builder.set_ftp_enabled(false); // Android WebView does not support ftp yet. | 77 builder.set_ftp_enabled(false); // Android WebView does not support ftp yet. |
62 #endif | 78 #endif |
63 builder.set_proxy_config_service(proxy_config_service_.release()); | 79 builder.set_proxy_config_service(proxy_config_service_.release()); |
64 builder.set_accept_language(net::HttpUtil::GenerateAcceptLanguageHeader( | 80 builder.set_accept_language(net::HttpUtil::GenerateAcceptLanguageHeader( |
65 AwContentBrowserClient::GetAcceptLangsImpl())); | 81 AwContentBrowserClient::GetAcceptLangsImpl())); |
66 | 82 |
(...skipping 10 matching lines...) Expand all Loading... |
77 net::HttpCache* main_cache = new net::HttpCache( | 93 net::HttpCache* main_cache = new net::HttpCache( |
78 network_session_params, | 94 network_session_params, |
79 new net::HttpCache::DefaultBackend( | 95 new net::HttpCache::DefaultBackend( |
80 net::DISK_CACHE, | 96 net::DISK_CACHE, |
81 cache_type, | 97 cache_type, |
82 browser_context_->GetPath().Append(FILE_PATH_LITERAL("Cache")), | 98 browser_context_->GetPath().Append(FILE_PATH_LITERAL("Cache")), |
83 10 * 1024 * 1024, // 10M | 99 10 * 1024 * 1024, // 10M |
84 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE))); | 100 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE))); |
85 main_http_factory_.reset(main_cache); | 101 main_http_factory_.reset(main_cache); |
86 url_request_context_->set_http_transaction_factory(main_cache); | 102 url_request_context_->set_http_transaction_factory(main_cache); |
87 | 103 url_request_context_->set_cookie_store(cookie_store_.get()); |
88 scoped_refptr<net::CookieStore> cookie_store = | |
89 content::CreatePersistentCookieStore( | |
90 browser_context_->GetPath().Append(FILE_PATH_LITERAL("Cookies")), | |
91 true, | |
92 NULL, | |
93 NULL); | |
94 cookie_store->GetCookieMonster()->SetPersistSessionCookies(true); | |
95 url_request_context_->set_cookie_store(cookie_store.get()); | |
96 | |
97 // The CookieMonster must be passed here so it happens synchronously to | |
98 // the main thread initialization (to avoid race condition in another | |
99 // thread trying to access the CookieManager API). | |
100 DidCreateCookieMonster( | |
101 url_request_context_->cookie_store()->GetCookieMonster()); | |
102 } | 104 } |
103 | 105 |
104 void AwURLRequestContextGetter::PopulateNetworkSessionParams( | 106 void AwURLRequestContextGetter::PopulateNetworkSessionParams( |
105 net::HttpNetworkSession::Params* params) { | 107 net::HttpNetworkSession::Params* params) { |
106 net::URLRequestContext* context = url_request_context_.get(); | 108 net::URLRequestContext* context = url_request_context_.get(); |
107 params->host_resolver = context->host_resolver(); | 109 params->host_resolver = context->host_resolver(); |
108 params->cert_verifier = context->cert_verifier(); | 110 params->cert_verifier = context->cert_verifier(); |
109 params->server_bound_cert_service = context->server_bound_cert_service(); | 111 params->server_bound_cert_service = context->server_bound_cert_service(); |
110 params->transport_security_state = context->transport_security_state(); | 112 params->transport_security_state = context->transport_security_state(); |
111 params->proxy_service = context->proxy_service(); | 113 params->proxy_service = context->proxy_service(); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 AwURLRequestContextGetter::GetNetworkTaskRunner() const { | 189 AwURLRequestContextGetter::GetNetworkTaskRunner() const { |
188 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); | 190 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); |
189 } | 191 } |
190 | 192 |
191 void AwURLRequestContextGetter::SetProtocolHandlers( | 193 void AwURLRequestContextGetter::SetProtocolHandlers( |
192 content::ProtocolHandlerMap* protocol_handlers) { | 194 content::ProtocolHandlerMap* protocol_handlers) { |
193 std::swap(protocol_handlers_, *protocol_handlers); | 195 std::swap(protocol_handlers_, *protocol_handlers); |
194 } | 196 } |
195 | 197 |
196 } // namespace android_webview | 198 } // namespace android_webview |
OLD | NEW |