Chromium Code Reviews| Index: android_webview/native/android_protocol_handler.cc |
| diff --git a/android_webview/native/android_protocol_handler.cc b/android_webview/native/android_protocol_handler.cc |
| index a5da6fdde488d95f732e1249f65c3f8e53d0e1d0..1060de215a6217661d3563e68f242ee11201681c 100644 |
| --- a/android_webview/native/android_protocol_handler.cc |
| +++ b/android_webview/native/android_protocol_handler.cc |
| @@ -20,6 +20,7 @@ |
| #include "net/base/net_errors.h" |
| #include "net/base/net_util.h" |
| #include "net/http/http_util.h" |
| +#include "net/url_request/protocol_intercept_job_factory.h" |
| #include "net/url_request/url_request.h" |
| using android_webview::InputStream; |
| @@ -66,22 +67,17 @@ class AndroidStreamReaderURLRequestJobDelegateImpl |
| }; |
| class AssetFileProtocolInterceptor : |
| - public net::URLRequestJobFactory::Interceptor { |
| + public net::URLRequestJobFactory::ProtocolHandler { |
| public: |
| - AssetFileProtocolInterceptor(); |
| + static scoped_ptr<net::URLRequestJobFactory> CreateURLRequestJobFactory( |
| + scoped_ptr<net::URLRequestJobFactory> base_job_factory); |
| virtual ~AssetFileProtocolInterceptor() OVERRIDE; |
|
mmenke
2012/12/18 20:32:15
nit: Destructor should go before other methods.
|
| - virtual net::URLRequestJob* MaybeIntercept( |
| - net::URLRequest* request, |
| - net::NetworkDelegate* network_delegate) const OVERRIDE; |
| - virtual net::URLRequestJob* MaybeInterceptRedirect( |
| - const GURL& location, |
| - net::URLRequest* request, |
| - net::NetworkDelegate* network_delegate) const OVERRIDE; |
| - virtual net::URLRequestJob* MaybeInterceptResponse( |
| + virtual net::URLRequestJob* MaybeCreateJob( |
| net::URLRequest* request, |
| net::NetworkDelegate* network_delegate) const OVERRIDE; |
| private: |
| + AssetFileProtocolInterceptor(); |
|
mmenke
2012/12/18 20:32:15
nit: Blank line between methods and data.
|
| // file:///android_asset/ |
| const std::string asset_prefix_; |
| // file:///android_res/ |
| @@ -196,7 +192,19 @@ AssetFileProtocolInterceptor::AssetFileProtocolInterceptor() |
| AssetFileProtocolInterceptor::~AssetFileProtocolInterceptor() { |
| } |
| -net::URLRequestJob* AssetFileProtocolInterceptor::MaybeIntercept( |
| +// static |
| +scoped_ptr<net::URLRequestJobFactory> |
| +AssetFileProtocolInterceptor::CreateURLRequestJobFactory( |
| + scoped_ptr<net::URLRequestJobFactory> base_job_factory) { |
| + scoped_ptr<net::URLRequestJobFactory> top_job_factory( |
| + new net::ProtocolInterceptJobFactory( |
| + base_job_factory.Pass(), |
| + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>( |
| + new AssetFileProtocolInterceptor()))); |
| + return top_job_factory.Pass(); |
| +} |
| + |
| +net::URLRequestJob* AssetFileProtocolInterceptor::MaybeCreateJob( |
| net::URLRequest* request, net::NetworkDelegate* network_delegate) const { |
| if (!request->url().SchemeIsFile()) return NULL; |
| @@ -213,19 +221,6 @@ net::URLRequestJob* AssetFileProtocolInterceptor::MaybeIntercept( |
| new AndroidStreamReaderURLRequestJobDelegateImpl())); |
| } |
| -net::URLRequestJob* AssetFileProtocolInterceptor::MaybeInterceptRedirect( |
| - const GURL& location, |
| - net::URLRequest* request, |
| - net::NetworkDelegate* network_delegate) const { |
| - return NULL; |
| -} |
| - |
| -net::URLRequestJob* AssetFileProtocolInterceptor::MaybeInterceptResponse( |
| - net::URLRequest* request, |
| - net::NetworkDelegate* network_delegate) const { |
| - return NULL; |
| -} |
| - |
| } // namespace |
| namespace android_webview { |
| @@ -235,18 +230,18 @@ bool RegisterAndroidProtocolHandler(JNIEnv* env) { |
| } |
| // static |
| -void RegisterAndroidProtocolsOnIOThread( |
| - net::URLRequestContext* context, |
| - AwURLRequestJobFactory* job_factory) { |
| +scoped_ptr<net::URLRequestJobFactory> CreateAndroidRequestJobFactory( |
| + scoped_ptr<AwURLRequestJobFactory> job_factory) { |
| // Register content://. Note that even though a scheme is |
| // registered here, it cannot be used by child processes until access to it is |
| // granted via ChildProcessSecurityPolicy::GrantScheme(). This is done in |
| // AwContentBrowserClient. |
| // The job factory takes ownership of the handler. |
| - job_factory->SetProtocolHandler(android_webview::kContentScheme, |
| - new ContentSchemeProtocolHandler()); |
| - // The job factory takes ownership of the interceptor. |
| - job_factory->AddInterceptor(new AssetFileProtocolInterceptor()); |
| + bool set_protocol = job_factory->SetProtocolHandler( |
| + android_webview::kContentScheme, new ContentSchemeProtocolHandler()); |
| + DCHECK(set_protocol); |
| + return AssetFileProtocolInterceptor::CreateURLRequestJobFactory( |
| + job_factory.PassAs<net::URLRequestJobFactory>()); |
| } |
| // Set a context object to be used for resolving resource queries. This can |