summaryrefslogtreecommitdiffstats
path: root/android_webview/native/android_protocol_handler.cc
diff options
context:
space:
mode:
authormkosiba@chromium.org <mkosiba@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-10-24 10:07:56 +0000
committermkosiba@chromium.org <mkosiba@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-10-24 10:07:56 +0000
commit5c8453994c3fe90856adf357342e70916b52b496 (patch)
tree0baeb233ec3e35da4379a12456a3a48d5dcf987b /android_webview/native/android_protocol_handler.cc
parent74f05e5f6b235f4d6ab81af8aa5a855ffea46def (diff)
downloadchromium_src-5c8453994c3fe90856adf357342e70916b52b496.zip
chromium_src-5c8453994c3fe90856adf357342e70916b52b496.tar.gz
chromium_src-5c8453994c3fe90856adf357342e70916b52b496.tar.bz2
[android_webview] Support intercepting for unhandled schemes.
This makes it possible to intercept navigations and resource requests for otherwise unsupported schemes. BUG=156354,148369 Review URL: https://codereview.chromium.org/11185051 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@163804 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'android_webview/native/android_protocol_handler.cc')
-rw-r--r--android_webview/native/android_protocol_handler.cc50
1 files changed, 20 insertions, 30 deletions
diff --git a/android_webview/native/android_protocol_handler.cc b/android_webview/native/android_protocol_handler.cc
index 5edb3e7..c80c217 100644
--- a/android_webview/native/android_protocol_handler.cc
+++ b/android_webview/native/android_protocol_handler.cc
@@ -20,10 +20,10 @@
#include "net/base/net_errors.h"
#include "net/base/net_util.h"
#include "net/http/http_util.h"
+#include "net/url_request/url_request.h"
#include "net/url_request/url_request_context.h"
#include "net/url_request/url_request_context_getter.h"
#include "net/url_request/url_request_job_factory.h"
-#include "net/url_request/url_request_job_manager.h"
using base::android::AttachCurrentThread;
using base::android::ClearException;
@@ -89,52 +89,42 @@ class AssetFileProtocolInterceptor :
const std::string resource_prefix_;
};
-} // namespace
+// Protocol handler for content:// scheme requests.
+class ContentSchemeProtocolHandler :
+ public net::URLRequestJobFactory::ProtocolHandler {
+ public:
+ ContentSchemeProtocolHandler() {}
-// static
-net::URLRequestJob* AndroidProtocolHandler::Factory(
- net::URLRequest* request,
- net::NetworkDelegate* network_delegate,
- const std::string& scheme) {
- DCHECK(scheme == android_webview::kContentScheme);
+ virtual net::URLRequestJob* MaybeCreateJob(
+ net::URLRequest* request,
+ net::NetworkDelegate* network_delegate) const OVERRIDE {
+ DCHECK(request->url().SchemeIs(android_webview::kContentScheme));
return new AndroidStreamReaderURLRequestJob(
request,
network_delegate,
scoped_ptr<AndroidStreamReaderURLRequestJob::Delegate>(
new AndroidStreamReaderURLRequestJobDelegateImpl()));
-}
+ }
+};
-static void AddFileSchemeInterceptorOnIOThread(
- net::URLRequestContextGetter* context_getter) {
- // The job factory takes ownership of the interceptor.
- const_cast<net::URLRequestJobFactory*>(
- context_getter->GetURLRequestContext()->job_factory())->AddInterceptor(
- new AssetFileProtocolInterceptor());
-}
+} // namespace
bool RegisterAndroidProtocolHandler(JNIEnv* env) {
return RegisterNativesImpl(env);
}
// static
-void AndroidProtocolHandler::RegisterProtocols(
- net::URLRequestContextGetter* context_getter) {
+void AndroidProtocolHandler::RegisterProtocolsOnIOThread(
+ net::URLRequestJobFactory* 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.
- // TODO(mnaganov): Convert into a ProtocolHandler.
- net::URLRequestJobManager* job_manager =
- net::URLRequestJobManager::GetInstance();
- job_manager->RegisterProtocolFactory(android_webview::kContentScheme,
- &AndroidProtocolHandler::Factory);
-
- // Register a file: scheme interceptor for application assets.
- context_getter->GetNetworkTaskRunner()->PostTask(
- FROM_HERE,
- base::Bind(&AddFileSchemeInterceptorOnIOThread,
- make_scoped_refptr(context_getter)));
- // TODO(mnaganov): Add an interceptor for the incognito profile?
+ // 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());
}
// Set a context object to be used for resolving resource queries. This can