Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(202)

Side by Side Diff: android_webview/browser/net/aw_url_request_context_getter.cc

Issue 12377051: [android_webview] Don't intercept resource and asset URLRequests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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>
8
7 #include "android_webview/browser/aw_browser_context.h" 9 #include "android_webview/browser/aw_browser_context.h"
8 #include "android_webview/browser/aw_request_interceptor.h" 10 #include "android_webview/browser/aw_request_interceptor.h"
9 #include "android_webview/browser/net/aw_network_delegate.h" 11 #include "android_webview/browser/net/aw_network_delegate.h"
10 #include "android_webview/browser/net/aw_url_request_job_factory.h" 12 #include "android_webview/browser/net/aw_url_request_job_factory.h"
11 #include "android_webview/browser/net/init_native_callback.h" 13 #include "android_webview/browser/net/init_native_callback.h"
12 #include "content/public/browser/browser_thread.h" 14 #include "content/public/browser/browser_thread.h"
13 #include "content/public/browser/content_browser_client.h" 15 #include "content/public/browser/content_browser_client.h"
14 #include "content/public/common/content_client.h" 16 #include "content/public/common/content_client.h"
15 #include "content/public/common/url_constants.h" 17 #include "content/public/common/url_constants.h"
16 #include "net/http/http_cache.h" 18 #include "net/http/http_cache.h"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 PopulateNetworkSessionParams(&network_session_params); 67 PopulateNetworkSessionParams(&network_session_params);
66 net::HttpCache* main_cache = new net::HttpCache( 68 net::HttpCache* main_cache = new net::HttpCache(
67 network_session_params, 69 network_session_params,
68 new net::HttpCache::DefaultBackend( 70 new net::HttpCache::DefaultBackend(
69 net::DISK_CACHE, 71 net::DISK_CACHE,
70 browser_context_->GetPath().Append(FILE_PATH_LITERAL("Cache")), 72 browser_context_->GetPath().Append(FILE_PATH_LITERAL("Cache")),
71 10 * 1024 * 1024, // 10M 73 10 * 1024 * 1024, // 10M
72 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE))); 74 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE)));
73 main_http_factory_.reset(main_cache); 75 main_http_factory_.reset(main_cache);
74 url_request_context_->set_http_transaction_factory(main_cache); 76 url_request_context_->set_http_transaction_factory(main_cache);
77
78 CreateCookieMonster(url_request_context_.get());
boliu 2013/03/01 18:44:11 This bit is already fixed in https://codereview.ch
mkosiba (inactive) 2013/03/05 16:34:43 Ok, looks like I need to rebase.
75 } 79 }
76 80
77 void AwURLRequestContextGetter::PopulateNetworkSessionParams( 81 void AwURLRequestContextGetter::PopulateNetworkSessionParams(
78 net::HttpNetworkSession::Params* params) { 82 net::HttpNetworkSession::Params* params) {
79 net::URLRequestContext* context = url_request_context_.get(); 83 net::URLRequestContext* context = url_request_context_.get();
80 params->host_resolver = context->host_resolver(); 84 params->host_resolver = context->host_resolver();
81 params->cert_verifier = context->cert_verifier(); 85 params->cert_verifier = context->cert_verifier();
82 params->server_bound_cert_service = context->server_bound_cert_service(); 86 params->server_bound_cert_service = context->server_bound_cert_service();
83 params->transport_security_state = context->transport_security_state(); 87 params->transport_security_state = context->transport_security_state();
84 params->proxy_service = context->proxy_service(); 88 params->proxy_service = context->proxy_service();
85 params->ssl_config_service = context->ssl_config_service(); 89 params->ssl_config_service = context->ssl_config_service();
86 params->http_auth_handler_factory = context->http_auth_handler_factory(); 90 params->http_auth_handler_factory = context->http_auth_handler_factory();
87 params->network_delegate = context->network_delegate(); 91 params->network_delegate = context->network_delegate();
88 params->http_server_properties = context->http_server_properties(); 92 params->http_server_properties = context->http_server_properties();
89 params->net_log = context->net_log(); 93 params->net_log = context->net_log();
90 } 94 }
91 95
96 namespace {
97
98 typedef std::vector<net::URLRequestJobFactory::ProtocolHandler*>
99 ProtocolHandlerVector;
100
101 scoped_ptr<net::URLRequestJobFactory> WrapFactoryWithProtocolHandlers(
102 scoped_ptr<net::URLRequestJobFactory> job_factory,
103 const ProtocolHandlerVector& protocol_handlers) {
104 // The chain of responsibility is constructed in reverse of the order in
105 // which we want the particular protocol handlers invoked.
106 for (ProtocolHandlerVector::const_reverse_iterator
107 i = protocol_handlers.rbegin();
108 i != protocol_handlers.rend();
109 ++i) {
110 job_factory.reset(new net::ProtocolInterceptJobFactory(
111 job_factory.Pass(), make_scoped_ptr(*i)));
112 }
113 return job_factory.Pass();
114 }
115
116 } // namespace
117
92 net::URLRequestContext* AwURLRequestContextGetter::GetURLRequestContext() { 118 net::URLRequestContext* AwURLRequestContextGetter::GetURLRequestContext() {
93 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 119 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
94 if (!job_factory_) { 120 if (!job_factory_) {
95 scoped_ptr<AwURLRequestJobFactory> job_factory(new AwURLRequestJobFactory); 121 scoped_ptr<AwURLRequestJobFactory> job_factory(new AwURLRequestJobFactory);
96 bool set_protocol = job_factory->SetProtocolHandler( 122 bool set_protocol = job_factory->SetProtocolHandler(
97 chrome::kFileScheme, new net::FileProtocolHandler()); 123 chrome::kFileScheme, new net::FileProtocolHandler());
98 DCHECK(set_protocol); 124 DCHECK(set_protocol);
99 set_protocol = job_factory->SetProtocolHandler( 125 set_protocol = job_factory->SetProtocolHandler(
100 chrome::kDataScheme, new net::DataProtocolHandler()); 126 chrome::kDataScheme, new net::DataProtocolHandler());
101 DCHECK(set_protocol); 127 DCHECK(set_protocol);
102 DCHECK(blob_protocol_handler_); 128 DCHECK(blob_protocol_handler_);
103 set_protocol = job_factory->SetProtocolHandler( 129 set_protocol = job_factory->SetProtocolHandler(
104 chrome::kBlobScheme, blob_protocol_handler_.release()); 130 chrome::kBlobScheme, blob_protocol_handler_.release());
105 DCHECK(set_protocol); 131 DCHECK(set_protocol);
106 DCHECK(file_system_protocol_handler_); 132 DCHECK(file_system_protocol_handler_);
107 set_protocol = job_factory->SetProtocolHandler( 133 set_protocol = job_factory->SetProtocolHandler(
108 chrome::kFileSystemScheme, file_system_protocol_handler_.release()); 134 chrome::kFileSystemScheme, file_system_protocol_handler_.release());
109 DCHECK(set_protocol); 135 DCHECK(set_protocol);
110 DCHECK(chrome_protocol_handler_); 136 DCHECK(chrome_protocol_handler_);
111 set_protocol = job_factory->SetProtocolHandler( 137 set_protocol = job_factory->SetProtocolHandler(
112 chrome::kChromeUIScheme, chrome_protocol_handler_.release()); 138 chrome::kChromeUIScheme, chrome_protocol_handler_.release());
113 DCHECK(set_protocol); 139 DCHECK(set_protocol);
114 DCHECK(chrome_devtools_protocol_handler_); 140 DCHECK(chrome_devtools_protocol_handler_);
115 set_protocol = job_factory->SetProtocolHandler( 141 set_protocol = job_factory->SetProtocolHandler(
116 chrome::kChromeDevToolsScheme, 142 chrome::kChromeDevToolsScheme,
117 chrome_devtools_protocol_handler_.release()); 143 chrome_devtools_protocol_handler_.release());
118 DCHECK(set_protocol); 144 DCHECK(set_protocol);
119 // Create a chain of URLRequestJobFactories. Keep |job_factory_| pointed 145
120 // at the beginning of the chain. 146 // Create a chain of URLRequestJobFactories.
121 job_factory_ = CreateAndroidJobFactoryAndCookieMonster( 147 ProtocolHandlerVector protocol_handlers;
122 url_request_context_.get(), job_factory.Pass()); 148
123 job_factory_.reset(new net::ProtocolInterceptJobFactory( 149 protocol_handlers.push_back(
124 job_factory_.Pass(), 150 CreateAndroidContentProtocolHandler().release());
125 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>( 151 protocol_handlers.push_back(
126 new AwRequestInterceptor()))); 152 CreateAndroidAssetFileProtocolHandler().release());
127 job_factory_.reset(new net::ProtocolInterceptJobFactory( 153 protocol_handlers.push_back(developer_protocol_handler_.release());
128 job_factory_.Pass(), 154 // The AwRequestInterceptor must come after the content and asset file job
129 developer_protocol_handler_.Pass())); 155 // factories. This for WebViewClassic compatibility where it was not
156 // possible to intercept resource loads to resolvable content:// and
157 // file:// URIs.
158 // This is achieved by the Content and AssetFile jobs handling only
159 // resolvable URLRequests
160 protocol_handlers.push_back(new AwRequestInterceptor());
161 job_factory_ = WrapFactoryWithProtocolHandlers(
162 job_factory.PassAs<net::URLRequestJobFactory>(), protocol_handlers);
163
164 #if 0
165 // Alternative approach:
boliu 2013/03/01 18:44:11 I like this alternative approach better, because i
mnaganov (inactive) 2013/03/04 09:53:44 But on the other hand, it's more consistent with t
boliu 2013/03/04 19:55:46 I don't feel very strongly about this. Seems too m
166 job_factory_ = new net::ProtocolInterceptJobFactory(
167 job_factory.Pass(),
168 new FallbackProtocolHandler(
169 &protocol_handlers,
170 make_scoped_ptr(new AwRequestInterceptor()));
171 #endif
172
130 url_request_context_->set_job_factory(job_factory_.get()); 173 url_request_context_->set_job_factory(job_factory_.get());
131 } 174 }
175
132 return url_request_context_.get(); 176 return url_request_context_.get();
133 } 177 }
134 178
135 scoped_refptr<base::SingleThreadTaskRunner> 179 scoped_refptr<base::SingleThreadTaskRunner>
136 AwURLRequestContextGetter::GetNetworkTaskRunner() const { 180 AwURLRequestContextGetter::GetNetworkTaskRunner() const {
137 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); 181 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO);
138 } 182 }
139 183
140 void AwURLRequestContextGetter::SetProtocolHandlers( 184 void AwURLRequestContextGetter::SetProtocolHandlers(
141 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> 185 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
142 blob_protocol_handler, 186 blob_protocol_handler,
143 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> 187 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
144 file_system_protocol_handler, 188 file_system_protocol_handler,
145 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> 189 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
146 developer_protocol_handler, 190 developer_protocol_handler,
147 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> 191 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
148 chrome_protocol_handler, 192 chrome_protocol_handler,
149 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> 193 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>
150 chrome_devtools_protocol_handler) { 194 chrome_devtools_protocol_handler) {
151 blob_protocol_handler_ = blob_protocol_handler.Pass(); 195 blob_protocol_handler_ = blob_protocol_handler.Pass();
152 file_system_protocol_handler_ = file_system_protocol_handler.Pass(); 196 file_system_protocol_handler_ = file_system_protocol_handler.Pass();
153 developer_protocol_handler_ = developer_protocol_handler.Pass(); 197 developer_protocol_handler_ = developer_protocol_handler.Pass();
154 chrome_protocol_handler_ = chrome_protocol_handler.Pass(); 198 chrome_protocol_handler_ = chrome_protocol_handler.Pass();
155 chrome_devtools_protocol_handler_ = chrome_devtools_protocol_handler.Pass(); 199 chrome_devtools_protocol_handler_ = chrome_devtools_protocol_handler.Pass();
156 } 200 }
157 201
158 } // namespace android_webview 202 } // namespace android_webview
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698