[refactor] More post-NSS WebCrypto cleanups (utility functions).
[chromium-blink-merge.git] / content / browser / ssl / ssl_policy.h
blob2855a1bbb8c6c912317331219cdc9333fbaee1aa
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_SSL_SSL_POLICY_H_
6 #define CONTENT_BROWSER_SSL_SSL_POLICY_H_
8 #include <string>
10 #include "base/memory/ref_counted.h"
11 #include "content/public/common/resource_type.h"
12 #include "content/public/common/security_style.h"
13 #include "net/cert/cert_status_flags.h"
15 class GURL;
17 namespace content {
18 class NavigationEntryImpl;
19 class SSLCertErrorHandler;
20 class SSLPolicyBackend;
21 class SSLRequestInfo;
22 class WebContents;
23 struct SSLStatus;
25 // SSLPolicy
27 // This class is responsible for making the security decisions that concern the
28 // SSL trust indicators. It relies on the SSLPolicyBackend to actually enact
29 // the decisions it reaches.
31 class SSLPolicy {
32 public:
33 explicit SSLPolicy(SSLPolicyBackend* backend);
35 // An error occurred with the certificate in an SSL connection.
36 void OnCertError(SSLCertErrorHandler* handler);
38 void DidRunInsecureContent(NavigationEntryImpl* entry,
39 const std::string& security_origin);
41 // We have started a resource request with the given info.
42 void OnRequestStarted(SSLRequestInfo* info);
44 // Update the SSL information in |entry| to match the current state.
45 // |web_contents| is the WebContents associated with this entry.
46 void UpdateEntry(NavigationEntryImpl* entry, WebContents* web_contents);
48 SSLPolicyBackend* backend() const { return backend_; }
50 // Returns a security style describing an individual resource. Does
51 // not take into account any of the page- or host-level state such as
52 // mixed content or whether the host has run insecure content.
53 static SecurityStyle GetSecurityStyleForResource(const GURL& url,
54 int cert_id,
55 net::CertStatus cert_status);
57 private:
58 enum OnCertErrorInternalOptionsMask {
59 OVERRIDABLE = 1 << 0,
60 STRICT_ENFORCEMENT = 1 << 1,
61 EXPIRED_PREVIOUS_DECISION = 1 << 2
64 // Callback that the user chose to accept or deny the certificate.
65 void OnAllowCertificate(scoped_refptr<SSLCertErrorHandler> handler,
66 bool allow);
68 // Helper method for derived classes handling certificate errors.
70 // Options should be a bitmask combination of OnCertErrorInternalOptionsMask.
71 // OVERRIDABLE indicates whether or not the user could (assuming perfect
72 // knowledge) successfully override the error and still get the security
73 // guarantees of TLS. STRICT_ENFORCEMENT indicates whether or not the site the
74 // user is trying to connect to has requested strict enforcement of
75 // certificate validation (e.g. with HTTP Strict-Transport-Security).
76 // EXPIRED_PREVIOUS_DECISION indicates whether a user decision had been
77 // previously made but the decision has expired.
78 void OnCertErrorInternal(SSLCertErrorHandler* handler, int options_mask);
80 // If the security style of |entry| has not been initialized, then initialize
81 // it with the default style for its URL.
82 void InitializeEntryIfNeeded(NavigationEntryImpl* entry);
84 // Mark |origin| as having run insecure content in the process with ID |pid|.
85 void OriginRanInsecureContent(const std::string& origin, int pid);
87 // The backend we use to enact our decisions.
88 SSLPolicyBackend* backend_;
90 DISALLOW_COPY_AND_ASSIGN(SSLPolicy);
93 } // namespace content
95 #endif // CONTENT_BROWSER_SSL_SSL_POLICY_H_