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.
5 #include "android_webview/browser/intercepted_request_data.h"
7 #include "android_webview/browser/input_stream.h"
8 #include "android_webview/browser/net/android_stream_reader_url_request_job.h"
10 namespace android_webview
{
14 class StreamReaderJobDelegateImpl
15 : public AndroidStreamReaderURLRequestJob::Delegate
{
17 StreamReaderJobDelegateImpl(
18 scoped_ptr
<InterceptedRequestData
> intercepted_request_data
)
19 : intercepted_request_data_(intercepted_request_data
.Pass()) {
20 DCHECK(intercepted_request_data_
);
23 virtual scoped_ptr
<InputStream
> OpenInputStream(JNIEnv
* env
,
24 const GURL
& url
) OVERRIDE
{
25 return intercepted_request_data_
->GetInputStream(env
).Pass();
28 virtual void OnInputStreamOpenFailed(net::URLRequest
* request
,
29 bool* restart
) OVERRIDE
{
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
);
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
);
48 scoped_ptr
<InterceptedRequestData
> intercepted_request_data_
;
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
);
60 DCHECK(network_delegate
);
62 return new AndroidStreamReaderURLRequestJob(
66 new StreamReaderJobDelegateImpl(intercepted_request_data
.Pass()))
67 .PassAs
<AndroidStreamReaderURLRequestJob::Delegate
>());
70 } // namespace android_webview