OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "android_webview/browser/intercepted_request_data.h" | 5 #include "android_webview/browser/intercepted_request_data.h" |
6 | 6 |
7 #include "android_webview/browser/input_stream.h" | 7 #include "android_webview/browser/input_stream.h" |
8 #include "android_webview/browser/net/android_stream_reader_url_request_job.h" | 8 #include "android_webview/browser/net/android_stream_reader_url_request_job.h" |
| 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "net/http/http_response_headers.h" |
9 | 11 |
10 namespace android_webview { | 12 namespace android_webview { |
11 | 13 |
12 namespace { | 14 namespace { |
13 | 15 |
14 class StreamReaderJobDelegateImpl | 16 class StreamReaderJobDelegateImpl |
15 : public AndroidStreamReaderURLRequestJob::Delegate { | 17 : public AndroidStreamReaderURLRequestJob::Delegate { |
16 public: | 18 public: |
17 StreamReaderJobDelegateImpl( | 19 StreamReaderJobDelegateImpl( |
18 scoped_ptr<InterceptedRequestData> intercepted_request_data) | 20 scoped_ptr<InterceptedRequestData> intercepted_request_data) |
(...skipping 18 matching lines...) Expand all Loading... |
37 return intercepted_request_data_->GetMimeType(env, mime_type); | 39 return intercepted_request_data_->GetMimeType(env, mime_type); |
38 } | 40 } |
39 | 41 |
40 virtual bool GetCharset(JNIEnv* env, | 42 virtual bool GetCharset(JNIEnv* env, |
41 net::URLRequest* request, | 43 net::URLRequest* request, |
42 android_webview::InputStream* stream, | 44 android_webview::InputStream* stream, |
43 std::string* charset) OVERRIDE { | 45 std::string* charset) OVERRIDE { |
44 return intercepted_request_data_->GetCharset(env, charset); | 46 return intercepted_request_data_->GetCharset(env, charset); |
45 } | 47 } |
46 | 48 |
| 49 virtual void UpdateHeaders(JNIEnv* env, |
| 50 net::HttpResponseHeaders* headers) OVERRIDE { |
| 51 int status_code; |
| 52 std::string reason_phrase; |
| 53 if (intercepted_request_data_->GetStatusInfo( |
| 54 env, &status_code, &reason_phrase)) { |
| 55 std::string status_line("HTTP/1.1 "); |
| 56 status_line.append(base::IntToString(status_code)); |
| 57 status_line.append(" "); |
| 58 status_line.append(reason_phrase); |
| 59 headers->ReplaceStatusLine(status_line); |
| 60 } |
| 61 intercepted_request_data_->GetHeaders(env, headers); |
| 62 } |
| 63 |
47 private: | 64 private: |
48 scoped_ptr<InterceptedRequestData> intercepted_request_data_; | 65 scoped_ptr<InterceptedRequestData> intercepted_request_data_; |
49 }; | 66 }; |
50 | 67 |
51 } // namespace | 68 } // namespace |
52 | 69 |
53 // static | 70 // static |
54 net::URLRequestJob* InterceptedRequestData::CreateJobFor( | 71 net::URLRequestJob* InterceptedRequestData::CreateJobFor( |
55 scoped_ptr<InterceptedRequestData> intercepted_request_data, | 72 scoped_ptr<InterceptedRequestData> intercepted_request_data, |
56 net::URLRequest* request, | 73 net::URLRequest* request, |
57 net::NetworkDelegate* network_delegate) { | 74 net::NetworkDelegate* network_delegate) { |
58 DCHECK(intercepted_request_data); | 75 DCHECK(intercepted_request_data); |
59 DCHECK(request); | 76 DCHECK(request); |
60 DCHECK(network_delegate); | 77 DCHECK(network_delegate); |
61 | 78 |
62 return new AndroidStreamReaderURLRequestJob( | 79 return new AndroidStreamReaderURLRequestJob( |
63 request, | 80 request, |
64 network_delegate, | 81 network_delegate, |
65 make_scoped_ptr( | 82 make_scoped_ptr( |
66 new StreamReaderJobDelegateImpl(intercepted_request_data.Pass())) | 83 new StreamReaderJobDelegateImpl(intercepted_request_data.Pass())) |
67 .PassAs<AndroidStreamReaderURLRequestJob::Delegate>()); | 84 .PassAs<AndroidStreamReaderURLRequestJob::Delegate>()); |
68 } | 85 } |
69 | 86 |
70 } // namespace android_webview | 87 } // namespace android_webview |
OLD | NEW |