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_
10 #include "base/macros.h"
11 #include "base/memory/ref_counted.h"
12 #include "content/browser/loader/resource_handler.h"
13 #include "net/base/mime_util.h"
16 class GrowableIOBuffer
;
18 class URLRequestStatus
;
23 // This class handles certificate mime types such as:
24 // - "application/x-x509-user-cert"
25 // - "application/x-x509-ca-cert"
26 // - "application/x-pkcs12"
28 class CertificateResourceHandler
: public ResourceHandler
{
30 explicit CertificateResourceHandler(net::URLRequest
* request
);
31 ~CertificateResourceHandler() override
;
33 // Not needed, as this event handler ought to be the final resource.
34 bool OnRequestRedirected(const net::RedirectInfo
& redirect_info
,
35 ResourceResponse
* resp
,
36 bool* defer
) override
;
38 // Check if this indeed an X509 cert.
39 bool OnResponseStarted(ResourceResponse
* resp
, bool* defer
) override
;
41 // Pass-through implementation.
42 bool OnWillStart(const GURL
& url
, bool* defer
) override
;
44 // Pass-through implementation.
45 bool OnBeforeNetworkStart(const GURL
& url
, bool* defer
) override
;
47 // Create a new buffer to store received data.
48 bool OnWillRead(scoped_refptr
<net::IOBuffer
>* buf
,
50 int min_size
) override
;
52 // A read was completed, maybe allocate a new buffer for further data.
53 bool OnReadCompleted(int bytes_read
, bool* defer
) override
;
55 // Done downloading the certificate.
56 void OnResponseCompleted(const net::URLRequestStatus
& urs
,
57 const std::string
& sec_info
,
58 bool* defer
) override
;
60 // N/A to cert downloading.
61 void OnDataDownloaded(int bytes_downloaded
) override
;
64 scoped_refptr
<net::GrowableIOBuffer
> buffer_
;
65 net::CertificateMimeType cert_type_
;
67 DISALLOW_COPY_AND_ASSIGN(CertificateResourceHandler
);
70 } // namespace content
72 #endif // CONTENT_BROWSER_LOADER_CERTIFICATE_RESOURCE_HANDLER_H_