Attach a SecurityStyle to each request in ResourceLoader
[chromium-blink-merge.git] / content / browser / ssl / ssl_policy.h
blob8998d1ff2f0309f59693fde8196ec599525065f4
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"
14 class GURL;
16 namespace content {
17 class NavigationEntryImpl;
18 class SSLCertErrorHandler;
19 class SSLPolicyBackend;
20 class SSLRequestInfo;
21 class WebContents;
22 struct SSLStatus;
24 // SSLPolicy
26 // This class is responsible for making the security decisions that concern the
27 // SSL trust indicators. It relies on the SSLPolicyBackend to actually enact
28 // the decisions it reaches.
30 class SSLPolicy {
31 public:
32 explicit SSLPolicy(SSLPolicyBackend* backend);
34 // An error occurred with the certificate in an SSL connection.
35 void OnCertError(SSLCertErrorHandler* handler);
37 void DidRunInsecureContent(NavigationEntryImpl* entry,
38 const std::string& security_origin);
40 // We have started a resource request with the given info.
41 void OnRequestStarted(SSLRequestInfo* info);
43 // Update the SSL information in |entry| to match the current state.
44 // |web_contents| is the WebContents associated with this entry.
45 void UpdateEntry(NavigationEntryImpl* entry, WebContents* web_contents);
47 SSLPolicyBackend* backend() const { return backend_; }
49 // Returns a security style describing an individual resource. Does
50 // not take into account any of the page- or host-level state such as
51 // mixed content or whether the host has run insecure content.
52 static SecurityStyle GetSecurityStyleForResource(const GURL& url,
53 const SSLStatus& ssl);
55 private:
56 enum OnCertErrorInternalOptionsMask {
57 OVERRIDABLE = 1 << 0,
58 STRICT_ENFORCEMENT = 1 << 1,
59 EXPIRED_PREVIOUS_DECISION = 1 << 2
62 // Callback that the user chose to accept or deny the certificate.
63 void OnAllowCertificate(scoped_refptr<SSLCertErrorHandler> handler,
64 bool allow);
66 // Helper method for derived classes handling certificate errors.
68 // Options should be a bitmask combination of OnCertErrorInternalOptionsMask.
69 // OVERRIDABLE indicates whether or not the user could (assuming perfect
70 // knowledge) successfully override the error and still get the security
71 // guarantees of TLS. STRICT_ENFORCEMENT indicates whether or not the site the
72 // user is trying to connect to has requested strict enforcement of
73 // certificate validation (e.g. with HTTP Strict-Transport-Security).
74 // EXPIRED_PREVIOUS_DECISION indicates whether a user decision had been
75 // previously made but the decision has expired.
76 void OnCertErrorInternal(SSLCertErrorHandler* handler, int options_mask);
78 // If the security style of |entry| has not been initialized, then initialize
79 // it with the default style for its URL.
80 void InitializeEntryIfNeeded(NavigationEntryImpl* entry);
82 // Mark |origin| as having run insecure content in the process with ID |pid|.
83 void OriginRanInsecureContent(const std::string& origin, int pid);
85 // The backend we use to enact our decisions.
86 SSLPolicyBackend* backend_;
88 DISALLOW_COPY_AND_ASSIGN(SSLPolicy);
91 } // namespace content
93 #endif // CONTENT_BROWSER_SSL_SSL_POLICY_H_