| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/aw_web_resource_response.h" | 5 #include "android_webview/browser/aw_web_resource_response.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" | 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "net/http/http_response_headers.h" | 10 #include "net/http/http_response_headers.h" |
| 11 | 11 |
| 12 namespace android_webview { | 12 namespace android_webview { |
| 13 | 13 |
| 14 namespace { | 14 namespace { |
| 15 | 15 |
| 16 class StreamReaderJobDelegateImpl | 16 class StreamReaderJobDelegateImpl |
| 17 : public AndroidStreamReaderURLRequestJob::Delegate { | 17 : public AndroidStreamReaderURLRequestJob::Delegate { |
| 18 public: | 18 public: |
| 19 StreamReaderJobDelegateImpl( | 19 StreamReaderJobDelegateImpl( |
| 20 scoped_ptr<AwWebResourceResponse> aw_web_resource_response) | 20 scoped_ptr<AwWebResourceResponse> aw_web_resource_response) |
| 21 : aw_web_resource_response_(aw_web_resource_response.Pass()) { | 21 : aw_web_resource_response_(aw_web_resource_response.Pass()) { |
| 22 DCHECK(aw_web_resource_response_); | 22 DCHECK(aw_web_resource_response_); |
| 23 } | 23 } |
| 24 | 24 |
| 25 virtual scoped_ptr<InputStream> OpenInputStream(JNIEnv* env, | 25 virtual scoped_ptr<InputStream> OpenInputStream(JNIEnv* env, |
| 26 const GURL& url) OVERRIDE { | 26 const GURL& url) override { |
| 27 return aw_web_resource_response_->GetInputStream(env).Pass(); | 27 return aw_web_resource_response_->GetInputStream(env).Pass(); |
| 28 } | 28 } |
| 29 | 29 |
| 30 virtual void OnInputStreamOpenFailed(net::URLRequest* request, | 30 virtual void OnInputStreamOpenFailed(net::URLRequest* request, |
| 31 bool* restart) OVERRIDE { | 31 bool* restart) override { |
| 32 *restart = false; | 32 *restart = false; |
| 33 } | 33 } |
| 34 | 34 |
| 35 virtual bool GetMimeType(JNIEnv* env, | 35 virtual bool GetMimeType(JNIEnv* env, |
| 36 net::URLRequest* request, | 36 net::URLRequest* request, |
| 37 android_webview::InputStream* stream, | 37 android_webview::InputStream* stream, |
| 38 std::string* mime_type) OVERRIDE { | 38 std::string* mime_type) override { |
| 39 return aw_web_resource_response_->GetMimeType(env, mime_type); | 39 return aw_web_resource_response_->GetMimeType(env, mime_type); |
| 40 } | 40 } |
| 41 | 41 |
| 42 virtual bool GetCharset(JNIEnv* env, | 42 virtual bool GetCharset(JNIEnv* env, |
| 43 net::URLRequest* request, | 43 net::URLRequest* request, |
| 44 android_webview::InputStream* stream, | 44 android_webview::InputStream* stream, |
| 45 std::string* charset) OVERRIDE { | 45 std::string* charset) override { |
| 46 return aw_web_resource_response_->GetCharset(env, charset); | 46 return aw_web_resource_response_->GetCharset(env, charset); |
| 47 } | 47 } |
| 48 | 48 |
| 49 virtual void AppendResponseHeaders( | 49 virtual void AppendResponseHeaders( |
| 50 JNIEnv* env, | 50 JNIEnv* env, |
| 51 net::HttpResponseHeaders* headers) OVERRIDE { | 51 net::HttpResponseHeaders* headers) override { |
| 52 int status_code; | 52 int status_code; |
| 53 std::string reason_phrase; | 53 std::string reason_phrase; |
| 54 if (aw_web_resource_response_->GetStatusInfo( | 54 if (aw_web_resource_response_->GetStatusInfo( |
| 55 env, &status_code, &reason_phrase)) { | 55 env, &status_code, &reason_phrase)) { |
| 56 std::string status_line("HTTP/1.1 "); | 56 std::string status_line("HTTP/1.1 "); |
| 57 status_line.append(base::IntToString(status_code)); | 57 status_line.append(base::IntToString(status_code)); |
| 58 status_line.append(" "); | 58 status_line.append(" "); |
| 59 status_line.append(reason_phrase); | 59 status_line.append(reason_phrase); |
| 60 headers->ReplaceStatusLine(status_line); | 60 headers->ReplaceStatusLine(status_line); |
| 61 } | 61 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 79 | 79 |
| 80 return new AndroidStreamReaderURLRequestJob( | 80 return new AndroidStreamReaderURLRequestJob( |
| 81 request, | 81 request, |
| 82 network_delegate, | 82 network_delegate, |
| 83 make_scoped_ptr( | 83 make_scoped_ptr( |
| 84 new StreamReaderJobDelegateImpl(aw_web_resource_response.Pass())) | 84 new StreamReaderJobDelegateImpl(aw_web_resource_response.Pass())) |
| 85 .PassAs<AndroidStreamReaderURLRequestJob::Delegate>()); | 85 .PassAs<AndroidStreamReaderURLRequestJob::Delegate>()); |
| 86 } | 86 } |
| 87 | 87 |
| 88 } // namespace android_webview | 88 } // namespace android_webview |
| OLD | NEW |