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

Unified 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, 10 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 side-by-side diff with in-line comments
Download patch
Index: android_webview/browser/net/aw_url_request_context_getter.cc
diff --git a/android_webview/browser/net/aw_url_request_context_getter.cc b/android_webview/browser/net/aw_url_request_context_getter.cc
index 6ec1aad7db56be9a00b7ec48b95294e4e9187db7..ebb729e2381c946fc30072baa5a23658cf5e5922 100644
--- a/android_webview/browser/net/aw_url_request_context_getter.cc
+++ b/android_webview/browser/net/aw_url_request_context_getter.cc
@@ -4,6 +4,8 @@
#include "android_webview/browser/net/aw_url_request_context_getter.h"
+#include <vector>
+
#include "android_webview/browser/aw_browser_context.h"
#include "android_webview/browser/aw_request_interceptor.h"
#include "android_webview/browser/net/aw_network_delegate.h"
@@ -72,6 +74,8 @@ void AwURLRequestContextGetter::Init() {
BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE)));
main_http_factory_.reset(main_cache);
url_request_context_->set_http_transaction_factory(main_cache);
+
+ 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.
}
void AwURLRequestContextGetter::PopulateNetworkSessionParams(
@@ -89,6 +93,28 @@ void AwURLRequestContextGetter::PopulateNetworkSessionParams(
params->net_log = context->net_log();
}
+namespace {
+
+typedef std::vector<net::URLRequestJobFactory::ProtocolHandler*>
+ ProtocolHandlerVector;
+
+scoped_ptr<net::URLRequestJobFactory> WrapFactoryWithProtocolHandlers(
+ scoped_ptr<net::URLRequestJobFactory> job_factory,
+ const ProtocolHandlerVector& protocol_handlers) {
+ // The chain of responsibility is constructed in reverse of the order in
+ // which we want the particular protocol handlers invoked.
+ for (ProtocolHandlerVector::const_reverse_iterator
+ i = protocol_handlers.rbegin();
+ i != protocol_handlers.rend();
+ ++i) {
+ job_factory.reset(new net::ProtocolInterceptJobFactory(
+ job_factory.Pass(), make_scoped_ptr(*i)));
+ }
+ return job_factory.Pass();
+}
+
+} // namespace
+
net::URLRequestContext* AwURLRequestContextGetter::GetURLRequestContext() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
if (!job_factory_) {
@@ -116,19 +142,37 @@ net::URLRequestContext* AwURLRequestContextGetter::GetURLRequestContext() {
chrome::kChromeDevToolsScheme,
chrome_devtools_protocol_handler_.release());
DCHECK(set_protocol);
- // Create a chain of URLRequestJobFactories. Keep |job_factory_| pointed
- // at the beginning of the chain.
- job_factory_ = CreateAndroidJobFactoryAndCookieMonster(
- url_request_context_.get(), job_factory.Pass());
- job_factory_.reset(new net::ProtocolInterceptJobFactory(
- job_factory_.Pass(),
- scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>(
- new AwRequestInterceptor())));
- job_factory_.reset(new net::ProtocolInterceptJobFactory(
- job_factory_.Pass(),
- developer_protocol_handler_.Pass()));
+
+ // Create a chain of URLRequestJobFactories.
+ ProtocolHandlerVector protocol_handlers;
+
+ protocol_handlers.push_back(
+ CreateAndroidContentProtocolHandler().release());
+ protocol_handlers.push_back(
+ CreateAndroidAssetFileProtocolHandler().release());
+ protocol_handlers.push_back(developer_protocol_handler_.release());
+ // The AwRequestInterceptor must come after the content and asset file job
+ // factories. This for WebViewClassic compatibility where it was not
+ // possible to intercept resource loads to resolvable content:// and
+ // file:// URIs.
+ // This is achieved by the Content and AssetFile jobs handling only
+ // resolvable URLRequests
+ protocol_handlers.push_back(new AwRequestInterceptor());
+ job_factory_ = WrapFactoryWithProtocolHandlers(
+ job_factory.PassAs<net::URLRequestJobFactory>(), protocol_handlers);
+
+ #if 0
+ // 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
+ job_factory_ = new net::ProtocolInterceptJobFactory(
+ job_factory.Pass(),
+ new FallbackProtocolHandler(
+ &protocol_handlers,
+ make_scoped_ptr(new AwRequestInterceptor()));
+ #endif
+
url_request_context_->set_job_factory(job_factory_.get());
}
+
return url_request_context_.get();
}

Powered by Google App Engine
This is Rietveld 408576698