OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef ANDROID_WEBVIEW_NATIVE_INPUT_STREAM_H_ |
| 6 #define ANDROID_WEBVIEW_NATIVE_INPUT_STREAM_H_ |
| 7 |
| 8 #include "android_webview/browser/input_stream.h" |
| 9 #include "base/android/scoped_java_ref.h" |
| 10 |
| 11 namespace net { |
| 12 class IOBuffer; |
| 13 } |
| 14 |
| 15 namespace android_webview { |
| 16 |
| 17 class InputStreamImpl : public InputStream { |
| 18 public: |
| 19 // Maximum size of |buffer_|. |
| 20 static const int kBufferSize; |
| 21 |
| 22 static const InputStreamImpl* FromInputStream( |
| 23 const InputStream* input_stream); |
| 24 |
| 25 // |stream| should be an instance of the InputStreamImpl Java class. |
| 26 // |stream| can't be null. |
| 27 InputStreamImpl(const base::android::JavaRef<jobject>& stream); |
| 28 virtual ~InputStreamImpl(); |
| 29 |
| 30 // Gets the underlying Java object. Guaranteed non-NULL. |
| 31 const jobject jobj() const { return jobject_.obj(); } |
| 32 |
| 33 // InputStream implementation. |
| 34 virtual bool BytesAvailable(JNIEnv* env, |
| 35 int* bytes_available) const OVERRIDE; |
| 36 virtual bool Skip(JNIEnv* env, int64_t n, int64_t* bytes_skipped) OVERRIDE; |
| 37 virtual bool Read(JNIEnv* env, |
| 38 net::IOBuffer* dest, |
| 39 int length, |
| 40 int* bytes_read) OVERRIDE; |
| 41 protected: |
| 42 // Parameterless constructor exposed for testing. |
| 43 InputStreamImpl(); |
| 44 |
| 45 private: |
| 46 base::android::ScopedJavaGlobalRef<jobject> jobject_; |
| 47 base::android::ScopedJavaGlobalRef<jbyteArray> buffer_; |
| 48 |
| 49 DISALLOW_COPY_AND_ASSIGN(InputStreamImpl); |
| 50 }; |
| 51 |
| 52 bool RegisterInputStream(JNIEnv* env); |
| 53 |
| 54 } // namespace android_webview |
| 55 |
| 56 #endif // ANDROID_WEBVIEW_NATIVE_INPUT_STREAM_H_ |
OLD | NEW |