OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 CONTENT_BROWSER_LOADER_CERTIFICATE_RESOURCE_HANDLER_H_ | 5 #ifndef CONTENT_BROWSER_LOADER_STREAM_RESOURCE_HANDLER_H_ |
6 #define CONTENT_BROWSER_LOADER_CERTIFICATE_RESOURCE_HANDLER_H_ | 6 #define CONTENT_BROWSER_LOADER_STREAM_RESOURCE_HANDLER_H_ |
7 | 7 |
8 #include <string> | |
9 #include <utility> | |
10 #include <vector> | |
11 | |
12 #include "base/compiler_specific.h" | |
13 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
14 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
15 #include "content/browser/loader/resource_handler.h" | 10 #include "content/browser/loader/resource_handler.h" |
| 11 #include "content/browser/streams/stream_write_observer.h" |
16 #include "googleurl/src/gurl.h" | 12 #include "googleurl/src/gurl.h" |
17 #include "net/base/mime_util.h" | |
18 | 13 |
19 namespace net { | 14 namespace net { |
20 class IOBuffer; | |
21 class URLRequest; | 15 class URLRequest; |
22 class URLRequestStatus; | |
23 } // namespace net | 16 } // namespace net |
24 | 17 |
25 namespace content { | 18 namespace content { |
26 | 19 |
27 // This class handles certificate mime types such as: | 20 class StreamRegistry; |
28 // - "application/x-x509-user-cert" | 21 |
29 // - "application/x-x509-ca-cert" | 22 // Redirect this resource to a stream. |
30 // - "application/x-pkcs12" | 23 class StreamResourceHandler : public StreamWriteObserver, |
31 // | 24 public ResourceHandler { |
32 class CertificateResourceHandler : public ResourceHandler { | |
33 public: | 25 public: |
34 CertificateResourceHandler(net::URLRequest* request, | 26 StreamResourceHandler(net::URLRequest* request, |
35 int render_process_host_id, | 27 StreamRegistry* registry, |
36 int render_view_id); | 28 const GURL& security_origin); |
37 virtual ~CertificateResourceHandler(); | 29 virtual ~StreamResourceHandler(); |
38 | 30 |
39 virtual bool OnUploadProgress(int request_id, | 31 virtual bool OnUploadProgress(int request_id, |
40 uint64 position, | 32 uint64 position, |
41 uint64 size) OVERRIDE; | 33 uint64 size) OVERRIDE; |
42 | 34 |
43 // Not needed, as this event handler ought to be the final resource. | 35 // Not needed, as this event handler ought to be the final resource. |
44 virtual bool OnRequestRedirected(int request_id, | 36 virtual bool OnRequestRedirected(int request_id, |
45 const GURL& url, | 37 const GURL& url, |
46 ResourceResponse* resp, | 38 ResourceResponse* resp, |
47 bool* defer) OVERRIDE; | 39 bool* defer) OVERRIDE; |
48 | 40 |
49 // Check if this indeed an X509 cert. | |
50 virtual bool OnResponseStarted(int request_id, | 41 virtual bool OnResponseStarted(int request_id, |
51 ResourceResponse* resp, | 42 ResourceResponse* resp, |
52 bool* defer) OVERRIDE; | 43 bool* defer) OVERRIDE; |
53 | 44 |
54 // Pass-through implementation. | |
55 virtual bool OnWillStart(int request_id, | 45 virtual bool OnWillStart(int request_id, |
56 const GURL& url, | 46 const GURL& url, |
57 bool* defer) OVERRIDE; | 47 bool* defer) OVERRIDE; |
58 | 48 |
59 // Create a new buffer to store received data. | 49 // Create a new buffer to store received data. |
60 virtual bool OnWillRead(int request_id, | 50 virtual bool OnWillRead(int request_id, |
61 net::IOBuffer** buf, | 51 net::IOBuffer** buf, |
62 int* buf_size, | 52 int* buf_size, |
63 int min_size) OVERRIDE; | 53 int min_size) OVERRIDE; |
64 | 54 |
65 // A read was completed, maybe allocate a new buffer for further data. | 55 // A read was completed, forward the data to the Stream. |
66 virtual bool OnReadCompleted(int request_id, | 56 virtual bool OnReadCompleted(int request_id, |
67 int bytes_read, | 57 int bytes_read, |
68 bool* defer) OVERRIDE; | 58 bool* defer) OVERRIDE; |
69 | 59 |
70 // Done downloading the certificate. | |
71 virtual bool OnResponseCompleted(int request_id, | 60 virtual bool OnResponseCompleted(int request_id, |
72 const net::URLRequestStatus& urs, | 61 const net::URLRequestStatus& urs, |
73 const std::string& sec_info) OVERRIDE; | 62 const std::string& sec_info) OVERRIDE; |
74 | 63 |
75 // N/A to cert downloading. | |
76 virtual void OnDataDownloaded(int request_id, int bytes_downloaded) OVERRIDE; | 64 virtual void OnDataDownloaded(int request_id, int bytes_downloaded) OVERRIDE; |
77 | 65 |
| 66 scoped_refptr<Stream> stream() { return stream_; } |
| 67 |
78 private: | 68 private: |
79 typedef std::vector<std::pair<scoped_refptr<net::IOBuffer>, | 69 virtual void OnSpaceAvailable(Stream* stream) OVERRIDE; |
80 size_t> > ContentVector; | |
81 | 70 |
82 void AssembleResource(); | |
83 | |
84 GURL url_; | |
85 net::URLRequest* request_; | 71 net::URLRequest* request_; |
86 size_t content_length_; | 72 scoped_refptr<Stream> stream_; |
87 ContentVector buffer_; | |
88 scoped_refptr<net::IOBuffer> read_buffer_; | 73 scoped_refptr<net::IOBuffer> read_buffer_; |
89 scoped_refptr<net::IOBuffer> resource_buffer_; // Downloaded certificate. | 74 DISALLOW_COPY_AND_ASSIGN(StreamResourceHandler); |
90 // The id of the |RenderProcessHost| which started the download. | |
91 int render_process_host_id_; | |
92 // The id of the |RenderView| which started the download. | |
93 int render_view_id_; | |
94 net::CertificateMimeType cert_type_; | |
95 DISALLOW_COPY_AND_ASSIGN(CertificateResourceHandler); | |
96 }; | 75 }; |
97 | 76 |
98 } // namespace content | 77 } // namespace content |
99 | 78 |
100 #endif // CONTENT_BROWSER_LOADER_CERTIFICATE_RESOURCE_HANDLER_H_ | 79 #endif // CONTENT_BROWSER_LOADER_STREAM_RESOURCE_HANDLER_H_ |
| 80 |
OLD | NEW |