• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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:
StreamReaderJobDelegateImpl(scoped_ptr<InterceptedRequestData> intercepted_request_data)17   StreamReaderJobDelegateImpl(
18       scoped_ptr<InterceptedRequestData> intercepted_request_data)
19       : intercepted_request_data_(intercepted_request_data.Pass()) {
20     DCHECK(intercepted_request_data_);
21   }
22 
OpenInputStream(JNIEnv * env,const GURL & url)23   virtual scoped_ptr<InputStream> OpenInputStream(JNIEnv* env,
24                                                   const GURL& url) OVERRIDE {
25     return intercepted_request_data_->GetInputStream(env).Pass();
26   }
27 
OnInputStreamOpenFailed(net::URLRequest * request,bool * restart)28   virtual void OnInputStreamOpenFailed(net::URLRequest* request,
29                                        bool* restart) OVERRIDE {
30     *restart = false;
31   }
32 
GetMimeType(JNIEnv * env,net::URLRequest * request,android_webview::InputStream * stream,std::string * mime_type)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 
GetCharset(JNIEnv * env,net::URLRequest * request,android_webview::InputStream * stream,std::string * charset)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
CreateJobFor(scoped_ptr<InterceptedRequestData> intercepted_request_data,net::URLRequest * request,net::NetworkDelegate * network_delegate)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