Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / content / browser / loader / certificate_resource_handler.h
blob743bf9d71dcec59b2b1ef8481c411bade2b7c511
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_
8 #include <string>
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"
15 namespace net {
16 class GrowableIOBuffer;
17 class URLRequest;
18 class URLRequestStatus;
19 } // namespace net
21 namespace content {
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 {
29 public:
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,
49 int* buf_size,
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;
63 private:
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_