| 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/chrome_stream.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 // Redirect this resource to a stream. |
| 28 // - "application/x-x509-user-cert" | 21 class StreamResourceHandler : public ChromeStreamObserver, |
| 29 // - "application/x-x509-ca-cert" | 22 public ResourceHandler { |
| 30 // - "application/x-pkcs12" | |
| 31 // | |
| 32 class CertificateResourceHandler : public ResourceHandler { | |
| 33 public: | 23 public: |
| 34 CertificateResourceHandler(net::URLRequest* request, | 24 StreamResourceHandler(net::URLRequest* request, |
| 35 int render_process_host_id, | 25 scoped_refptr<ChromeStream> stream); |
| 36 int render_view_id); | 26 virtual ~StreamResourceHandler(); |
| 37 virtual ~CertificateResourceHandler(); | |
| 38 | 27 |
| 39 virtual bool OnUploadProgress(int request_id, | 28 virtual bool OnUploadProgress(int request_id, |
| 40 uint64 position, | 29 uint64 position, |
| 41 uint64 size) OVERRIDE; | 30 uint64 size) OVERRIDE; |
| 42 | 31 |
| 43 // Not needed, as this event handler ought to be the final resource. | 32 // Not needed, as this event handler ought to be the final resource. |
| 44 virtual bool OnRequestRedirected(int request_id, | 33 virtual bool OnRequestRedirected(int request_id, |
| 45 const GURL& url, | 34 const GURL& url, |
| 46 ResourceResponse* resp, | 35 ResourceResponse* resp, |
| 47 bool* defer) OVERRIDE; | 36 bool* defer) OVERRIDE; |
| 48 | 37 |
| 49 // Check if this indeed an X509 cert. | |
| 50 virtual bool OnResponseStarted(int request_id, | 38 virtual bool OnResponseStarted(int request_id, |
| 51 ResourceResponse* resp, | 39 ResourceResponse* resp, |
| 52 bool* defer) OVERRIDE; | 40 bool* defer) OVERRIDE; |
| 53 | 41 |
| 54 // Pass-through implementation. | |
| 55 virtual bool OnWillStart(int request_id, | 42 virtual bool OnWillStart(int request_id, |
| 56 const GURL& url, | 43 const GURL& url, |
| 57 bool* defer) OVERRIDE; | 44 bool* defer) OVERRIDE; |
| 58 | 45 |
| 59 // Create a new buffer to store received data. | 46 // Create a new buffer to store received data. |
| 60 virtual bool OnWillRead(int request_id, | 47 virtual bool OnWillRead(int request_id, |
| 61 net::IOBuffer** buf, | 48 net::IOBuffer** buf, |
| 62 int* buf_size, | 49 int* buf_size, |
| 63 int min_size) OVERRIDE; | 50 int min_size) OVERRIDE; |
| 64 | 51 |
| 65 // A read was completed, maybe allocate a new buffer for further data. | 52 // A read was completed, forward the data to the Stream. |
| 66 virtual bool OnReadCompleted(int request_id, | 53 virtual bool OnReadCompleted(int request_id, |
| 67 int bytes_read, | 54 int bytes_read, |
| 68 bool* defer) OVERRIDE; | 55 bool* defer) OVERRIDE; |
| 69 | 56 |
| 70 // Done downloading the certificate. | |
| 71 virtual bool OnResponseCompleted(int request_id, | 57 virtual bool OnResponseCompleted(int request_id, |
| 72 const net::URLRequestStatus& urs, | 58 const net::URLRequestStatus& urs, |
| 73 const std::string& sec_info) OVERRIDE; | 59 const std::string& sec_info) OVERRIDE; |
| 74 | 60 |
| 75 // N/A to cert downloading. | |
| 76 virtual void OnDataDownloaded(int request_id, int bytes_downloaded) OVERRIDE; | 61 virtual void OnDataDownloaded(int request_id, int bytes_downloaded) OVERRIDE; |
| 77 | 62 |
| 78 private: | 63 private: |
| 79 typedef std::vector<std::pair<scoped_refptr<net::IOBuffer>, | 64 virtual void OnDataAvailable(ChromeStream* stream) OVERRIDE; |
| 80 size_t> > ContentVector; | 65 virtual void OnStreamComplete(ChromeStream* stream) OVERRIDE; |
| 66 virtual void OnBufferAvailable(ChromeStream* stream) OVERRIDE; |
| 81 | 67 |
| 82 void AssembleResource(); | |
| 83 | |
| 84 GURL url_; | |
| 85 net::URLRequest* request_; | 68 net::URLRequest* request_; |
| 86 size_t content_length_; | 69 scoped_refptr<ChromeStream> stream_; |
| 87 ContentVector buffer_; | |
| 88 scoped_refptr<net::IOBuffer> read_buffer_; | 70 scoped_refptr<net::IOBuffer> read_buffer_; |
| 89 scoped_refptr<net::IOBuffer> resource_buffer_; // Downloaded certificate. | 71 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 }; | 72 }; |
| 97 | 73 |
| 98 } // namespace content | 74 } // namespace content |
| 99 | 75 |
| 100 #endif // CONTENT_BROWSER_LOADER_CERTIFICATE_RESOURCE_HANDLER_H_ | 76 #endif // CONTENT_BROWSER_LOADER_STREAM_RESOURCE_HANDLER_H_ |
| 77 |
| OLD | NEW |