| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/native/input_stream_impl.h" | 5 #include "android_webview/native/input_stream_impl.h" |
| 6 | 6 |
| 7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
| 8 // Disable "Warnings treated as errors" for input_stream_jni as it's a Java | 8 // Disable "Warnings treated as errors" for input_stream_jni as it's a Java |
| 9 // system class and we have to generate C++ hooks for all methods in the class | 9 // system class and we have to generate C++ hooks for all methods in the class |
| 10 // even if they're unused. | 10 // even if they're unused. |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 | 30 |
| 31 // Maximum number of bytes to be read in a single read. | 31 // Maximum number of bytes to be read in a single read. |
| 32 const int InputStreamImpl::kBufferSize = 4096; | 32 const int InputStreamImpl::kBufferSize = 4096; |
| 33 | 33 |
| 34 //static | 34 //static |
| 35 const InputStreamImpl* InputStreamImpl::FromInputStream( | 35 const InputStreamImpl* InputStreamImpl::FromInputStream( |
| 36 const InputStream* input_stream) { | 36 const InputStream* input_stream) { |
| 37 return static_cast<const InputStreamImpl*>(input_stream); | 37 return static_cast<const InputStreamImpl*>(input_stream); |
| 38 } | 38 } |
| 39 | 39 |
| 40 // TODO: Use unsafe version for all Java_InputStream methods in this file |
| 41 // once BUG 157880 is fixed and implement graceful exception handling. |
| 42 |
| 40 InputStreamImpl::InputStreamImpl() { | 43 InputStreamImpl::InputStreamImpl() { |
| 41 } | 44 } |
| 42 | 45 |
| 43 InputStreamImpl::InputStreamImpl(const JavaRef<jobject>& stream) | 46 InputStreamImpl::InputStreamImpl(const JavaRef<jobject>& stream) |
| 44 : jobject_(stream) { | 47 : jobject_(stream) { |
| 45 DCHECK(!stream.is_null()); | 48 DCHECK(!stream.is_null()); |
| 46 } | 49 } |
| 47 | 50 |
| 48 InputStreamImpl::~InputStreamImpl() { | 51 InputStreamImpl::~InputStreamImpl() { |
| 49 JNIEnv* env = AttachCurrentThread(); | 52 JNIEnv* env = AttachCurrentThread(); |
| 50 Java_InputStream_close(env, jobject_.obj()); | 53 Java_InputStream_close(env, jobject_.obj()); |
| 51 DCHECK(!ClearException(env)); | |
| 52 } | 54 } |
| 53 | 55 |
| 54 bool InputStreamImpl::BytesAvailable(int* bytes_available) const { | 56 bool InputStreamImpl::BytesAvailable(int* bytes_available) const { |
| 55 JNIEnv* env = AttachCurrentThread(); | 57 JNIEnv* env = AttachCurrentThread(); |
| 56 // TODO: Use unsafe version for all Java_InputStream methods in this file | |
| 57 // once BUG 157880 is fixed. | |
| 58 int bytes = Java_InputStream_available(env, jobject_.obj()); | 58 int bytes = Java_InputStream_available(env, jobject_.obj()); |
| 59 if (ClearException(env)) | 59 if (ClearException(env)) |
| 60 return false; | 60 return false; |
| 61 *bytes_available = bytes; | 61 *bytes_available = bytes; |
| 62 return true; | 62 return true; |
| 63 } | 63 } |
| 64 | 64 |
| 65 bool InputStreamImpl::Skip(int64_t n, int64_t* bytes_skipped) { | 65 bool InputStreamImpl::Skip(int64_t n, int64_t* bytes_skipped) { |
| 66 JNIEnv* env = AttachCurrentThread(); | 66 JNIEnv* env = AttachCurrentThread(); |
| 67 int bytes = Java_InputStream_skip(env, jobject_.obj(), n); | 67 int bytes = Java_InputStream_skip(env, jobject_.obj(), n); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 env->GetByteArrayRegion(buffer, 0, byte_count, | 119 env->GetByteArrayRegion(buffer, 0, byte_count, |
| 120 reinterpret_cast<jbyte*>(dest->data() + *bytes_read)); | 120 reinterpret_cast<jbyte*>(dest->data() + *bytes_read)); |
| 121 if (ClearException(env)) | 121 if (ClearException(env)) |
| 122 return false; | 122 return false; |
| 123 | 123 |
| 124 *bytes_read = byte_count; | 124 *bytes_read = byte_count; |
| 125 return true; | 125 return true; |
| 126 } | 126 } |
| 127 | 127 |
| 128 } // namespace android_webview | 128 } // namespace android_webview |
| OLD | NEW |