1 // Copyright 2013 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "android_webview/browser/intercepted_request_data.h" 6 7 #include "android_webview/browser/input_stream.h" 8 #include "android_webview/browser/net/android_stream_reader_url_request_job.h" 9 10 namespace android_webview { 11 12 namespace { 13 14 class StreamReaderJobDelegateImpl 15 : public AndroidStreamReaderURLRequestJob::Delegate { 16 public: 17 StreamReaderJobDelegateImpl( 18 scoped_ptr<InterceptedRequestData> intercepted_request_data) 19 : intercepted_request_data_(intercepted_request_data.Pass()) { 20 DCHECK(intercepted_request_data_); 21 } 22 23 virtual scoped_ptr<InputStream> OpenInputStream(JNIEnv* env, 24 const GURL& url) OVERRIDE { 25 return intercepted_request_data_->GetInputStream(env).Pass(); 26 } 27 28 virtual void OnInputStreamOpenFailed(net::URLRequest* request, 29 bool* restart) OVERRIDE { 30 *restart = false; 31 } 32 33 virtual bool GetMimeType(JNIEnv* env, 34 net::URLRequest* request, 35 android_webview::InputStream* stream, 36 std::string* mime_type) OVERRIDE { 37 return intercepted_request_data_->GetMimeType(env, mime_type); 38 } 39 40 virtual bool GetCharset(JNIEnv* env, 41 net::URLRequest* request, 42 android_webview::InputStream* stream, 43 std::string* charset) OVERRIDE { 44 return intercepted_request_data_->GetCharset(env, charset); 45 } 46 47 private: 48 scoped_ptr<InterceptedRequestData> intercepted_request_data_; 49 }; 50 51 } // namespace 52 53 // static 54 net::URLRequestJob* InterceptedRequestData::CreateJobFor( 55 scoped_ptr<InterceptedRequestData> intercepted_request_data, 56 net::URLRequest* request, 57 net::NetworkDelegate* network_delegate) { 58 DCHECK(intercepted_request_data); 59 DCHECK(request); 60 DCHECK(network_delegate); 61 62 return new AndroidStreamReaderURLRequestJob( 63 request, 64 network_delegate, 65 make_scoped_ptr( 66 new StreamReaderJobDelegateImpl(intercepted_request_data.Pass())) 67 .PassAs<AndroidStreamReaderURLRequestJob::Delegate>()); 68 } 69 70 } // namespace android_webview 71