Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(720)

Side by Side Diff: android_webview/browser/net/android_stream_reader_url_request_job.h

Issue 11428052: [android_webview] Fix use after free in intercepted requests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 #ifndef ANDROID_WEBVIEW_NATIVE_ANDROID_STREAM_READER_URL_REQUEST_JOB_H_ 5 #ifndef ANDROID_WEBVIEW_NATIVE_ANDROID_STREAM_READER_URL_REQUEST_JOB_H_
6 #define ANDROID_WEBVIEW_NATIVE_ANDROID_STREAM_READER_URL_REQUEST_JOB_H_ 6 #define ANDROID_WEBVIEW_NATIVE_ANDROID_STREAM_READER_URL_REQUEST_JOB_H_
7 7
8 #include "base/android/scoped_java_ref.h" 8 #include "base/android/scoped_java_ref.h"
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "base/memory/weak_ptr.h" 11 #include "base/memory/weak_ptr.h"
12 #include "base/threading/non_thread_safe.h" 12 #include "base/threading/non_thread_safe.h"
13 #include "net/http/http_byte_range.h" 13 #include "net/http/http_byte_range.h"
14 #include "net/url_request/url_request_job.h" 14 #include "net/url_request/url_request_job.h"
15 15
16 namespace android_webview { 16 namespace android_webview {
17 class InputStream; 17 class InputStream;
18 class InputStreamReader; 18 class InputStreamReader;
19 } 19 }
20 20
21 namespace base { 21 namespace base {
22 class TaskRunner; 22 class TaskRunner;
23 } 23 }
24 24
25 namespace net { 25 namespace net {
26 class URLRequest; 26 class URLRequest;
27 } 27 }
28 28
29 class InputStreamReaderWrapper;
30
29 // A request job that reads data from a Java InputStream. 31 // A request job that reads data from a Java InputStream.
30 class AndroidStreamReaderURLRequestJob : public net::URLRequestJob { 32 class AndroidStreamReaderURLRequestJob : public net::URLRequestJob {
31 public: 33 public:
32 /* 34 /*
33 * We use a delegate so that we can share code for this job in slightly 35 * We use a delegate so that we can share code for this job in slightly
34 * different contexts. 36 * different contexts.
35 */ 37 */
36 class Delegate { 38 class Delegate {
37 public: 39 public:
38 virtual scoped_ptr<android_webview::InputStream> OpenInputStream( 40 virtual scoped_ptr<android_webview::InputStream> OpenInputStream(
39 JNIEnv* env, 41 JNIEnv* env,
40 net::URLRequest* request) = 0; 42 net::URLRequest* request) = 0;
41 43
42 virtual bool GetMimeType( 44 virtual bool GetMimeType(
43 JNIEnv* env, 45 JNIEnv* env,
44 net::URLRequest* request, 46 net::URLRequest* request,
45 const android_webview::InputStream& stream, 47 android_webview::InputStream* stream,
46 std::string* mime_type) = 0; 48 std::string* mime_type) = 0;
47 49
48 virtual bool GetCharset( 50 virtual bool GetCharset(
49 JNIEnv* env, 51 JNIEnv* env,
50 net::URLRequest* request, 52 net::URLRequest* request,
51 const android_webview::InputStream& stream, 53 android_webview::InputStream* stream,
52 std::string* charset) = 0; 54 std::string* charset) = 0;
53 55
54 virtual ~Delegate() {} 56 virtual ~Delegate() {}
55 }; 57 };
56 58
57 AndroidStreamReaderURLRequestJob( 59 AndroidStreamReaderURLRequestJob(
58 net::URLRequest* request, 60 net::URLRequest* request,
59 net::NetworkDelegate* network_delegate, 61 net::NetworkDelegate* network_delegate,
60 scoped_ptr<Delegate> delegate); 62 scoped_ptr<Delegate> delegate);
61 63
(...skipping 10 matching lines...) Expand all
72 74
73 protected: 75 protected:
74 virtual ~AndroidStreamReaderURLRequestJob(); 76 virtual ~AndroidStreamReaderURLRequestJob();
75 77
76 // Gets the TaskRunner for the worker thread. 78 // Gets the TaskRunner for the worker thread.
77 // Overridden in unittests. 79 // Overridden in unittests.
78 virtual base::TaskRunner* GetWorkerThreadRunner(); 80 virtual base::TaskRunner* GetWorkerThreadRunner();
79 81
80 // Creates an InputStreamReader instance. 82 // Creates an InputStreamReader instance.
81 // Overridden in unittests to return a mock. 83 // Overridden in unittests to return a mock.
82 virtual scoped_refptr<android_webview::InputStreamReader> 84 virtual scoped_ptr<android_webview::InputStreamReader>
83 CreateStreamReader(android_webview::InputStream* stream); 85 CreateStreamReader(android_webview::InputStream* stream);
84 86
85 private: 87 private:
86 void StartAsync(); 88 void StartAsync();
87 89
88 void OnReaderSeekCompleted(int content_size); 90 void OnReaderSeekCompleted(int content_size);
89 void OnReaderReadCompleted(int bytes_read); 91 void OnReaderReadCompleted(int bytes_read);
90 92
91 net::HttpByteRange byte_range_; 93 net::HttpByteRange byte_range_;
92 scoped_ptr<Delegate> delegate_; 94 scoped_ptr<Delegate> delegate_;
93 scoped_refptr<android_webview::InputStreamReader> input_stream_reader_; 95 scoped_refptr<InputStreamReaderWrapper> input_stream_reader_wrapper_;
94 scoped_ptr<android_webview::InputStream> stream_;
95 base::WeakPtrFactory<AndroidStreamReaderURLRequestJob> weak_factory_; 96 base::WeakPtrFactory<AndroidStreamReaderURLRequestJob> weak_factory_;
96 97
97 DISALLOW_COPY_AND_ASSIGN(AndroidStreamReaderURLRequestJob); 98 DISALLOW_COPY_AND_ASSIGN(AndroidStreamReaderURLRequestJob);
98 }; 99 };
99 100
100 #endif // ANDROID_WEBVIEW_NATIVE_ANDROID_STREAM_READER_URL_REQUEST_JOB_H_ 101 #endif // ANDROID_WEBVIEW_NATIVE_ANDROID_STREAM_READER_URL_REQUEST_JOB_H_
OLDNEW
« no previous file with comments | « android_webview/browser/input_stream.h ('k') | android_webview/browser/net/android_stream_reader_url_request_job.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698