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.
5 #ifndef CONTENT_BROWSER_LOADER_CERTIFICATE_RESOURCE_HANDLER_H_
6 #define CONTENT_BROWSER_LOADER_CERTIFICATE_RESOURCE_HANDLER_H_
12 #include "base/compiler_specific.h"
13 #include "base/memory/ref_counted.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "content/browser/loader/resource_handler.h"
16 #include "net/base/mime_util.h"
21 class URLRequestStatus
;
26 // This class handles certificate mime types such as:
27 // - "application/x-x509-user-cert"
28 // - "application/x-x509-ca-cert"
29 // - "application/x-pkcs12"
31 class CertificateResourceHandler
: public ResourceHandler
{
33 explicit CertificateResourceHandler(net::URLRequest
* request
);
34 ~CertificateResourceHandler() override
;
36 bool OnUploadProgress(uint64 position
, uint64 size
) override
;
38 // Not needed, as this event handler ought to be the final resource.
39 bool OnRequestRedirected(const net::RedirectInfo
& redirect_info
,
40 ResourceResponse
* resp
,
41 bool* defer
) override
;
43 // Check if this indeed an X509 cert.
44 bool OnResponseStarted(ResourceResponse
* resp
, bool* defer
) override
;
46 // Pass-through implementation.
47 bool OnWillStart(const GURL
& url
, bool* defer
) override
;
49 // Pass-through implementation.
50 bool OnBeforeNetworkStart(const GURL
& url
, bool* defer
) override
;
52 // Create a new buffer to store received data.
53 bool OnWillRead(scoped_refptr
<net::IOBuffer
>* buf
,
55 int min_size
) override
;
57 // A read was completed, maybe allocate a new buffer for further data.
58 bool OnReadCompleted(int bytes_read
, bool* defer
) override
;
60 // Done downloading the certificate.
61 void OnResponseCompleted(const net::URLRequestStatus
& urs
,
62 const std::string
& sec_info
,
63 bool* defer
) override
;
65 // N/A to cert downloading.
66 void OnDataDownloaded(int bytes_downloaded
) override
;
69 typedef std::vector
<std::pair
<scoped_refptr
<net::IOBuffer
>,
70 size_t> > ContentVector
;
72 void AssembleResource();
74 size_t content_length_
;
75 ContentVector buffer_
;
76 scoped_refptr
<net::IOBuffer
> read_buffer_
;
77 scoped_refptr
<net::IOBuffer
> resource_buffer_
; // Downloaded certificate.
78 net::CertificateMimeType cert_type_
;
79 DISALLOW_COPY_AND_ASSIGN(CertificateResourceHandler
);
82 } // namespace content
84 #endif // CONTENT_BROWSER_LOADER_CERTIFICATE_RESOURCE_HANDLER_H_