| 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_ANDROID_STREAM_READER_URL_REQUEST_JOB_H_ | |
| 6 #define ANDROID_WEBVIEW_NATIVE_ANDROID_STREAM_READER_URL_REQUEST_JOB_H_ | |
| 7 | |
| 8 #include "base/android/scoped_java_ref.h" | |
| 9 #include "base/memory/scoped_ptr.h" | |
| 10 #include "base/memory/weak_ptr.h" | |
| 11 #include "base/threading/non_thread_safe.h" | |
| 12 #include "net/http/http_byte_range.h" | |
| 13 #include "net/url_request/url_request_job.h" | |
| 14 | |
| 15 namespace net { | |
| 16 class URLRequest; | |
| 17 } | |
| 18 | |
| 19 // A request job that reads data from a Java InputStream. | |
| 20 class AndroidStreamReaderURLRequestJob : public net::URLRequestJob { | |
| 21 public: | |
| 22 /* | |
| 23 * We use a delegate so that we can share code for this job in slightly | |
| 24 * different contexts. | |
| 25 */ | |
| 26 class Delegate { | |
| 27 public: | |
| 28 virtual base::android::ScopedJavaLocalRef<jobject> OpenInputStream( | |
| 29 JNIEnv* env, | |
| 30 net::URLRequest* request) = 0; | |
| 31 | |
| 32 virtual bool GetMimeType( | |
| 33 JNIEnv* env, | |
| 34 net::URLRequest* request, | |
| 35 jobject stream, | |
| 36 std::string* mime_type) = 0; | |
| 37 | |
| 38 virtual bool GetCharset( | |
| 39 JNIEnv* env, | |
| 40 net::URLRequest* request, | |
| 41 jobject stream, | |
| 42 std::string* charset) = 0; | |
| 43 | |
| 44 virtual ~Delegate() {} | |
| 45 }; | |
| 46 | |
| 47 AndroidStreamReaderURLRequestJob( | |
| 48 net::URLRequest* request, | |
| 49 net::NetworkDelegate* network_delegate, | |
| 50 scoped_ptr<Delegate> delegate); | |
| 51 | |
| 52 // URLRequestJob: | |
| 53 virtual void Start() OVERRIDE; | |
| 54 virtual bool ReadRawData(net::IOBuffer* buf, | |
| 55 int buf_size, | |
| 56 int* bytes_read) OVERRIDE; | |
| 57 virtual void SetExtraRequestHeaders( | |
| 58 const net::HttpRequestHeaders& headers) OVERRIDE; | |
| 59 virtual bool GetMimeType(std::string* mime_type) const OVERRIDE; | |
| 60 virtual bool GetCharset(std::string* charset) OVERRIDE; | |
| 61 | |
| 62 protected: | |
| 63 virtual ~AndroidStreamReaderURLRequestJob(); | |
| 64 | |
| 65 private: | |
| 66 // Verify the requested range against the stream size. | |
| 67 bool VerifyRequestedRange(JNIEnv* env); | |
| 68 | |
| 69 // Skip to the first byte of the requested read range. | |
| 70 bool SkipToRequestedRange(JNIEnv* env); | |
| 71 | |
| 72 void StartAsync(); | |
| 73 | |
| 74 net::HttpByteRange byte_range_; | |
| 75 scoped_ptr<Delegate> delegate_; | |
| 76 base::android::ScopedJavaGlobalRef<jobject> stream_; | |
| 77 base::android::ScopedJavaGlobalRef<jbyteArray> buffer_; | |
| 78 base::WeakPtrFactory<AndroidStreamReaderURLRequestJob> weak_factory_; | |
| 79 | |
| 80 DISALLOW_COPY_AND_ASSIGN(AndroidStreamReaderURLRequestJob); | |
| 81 }; | |
| 82 | |
| 83 bool RegisterAndroidStreamReaderUrlRequestJob(JNIEnv* env); | |
| 84 | |
| 85 #endif // ANDROID_WEBVIEW_NATIVE_ANDROID_STREAM_READER_URL_REQUEST_JOB_H_ | |
| OLD | NEW |