| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/ssl/ssl_policy.h" | 5 #include "content/browser/ssl/ssl_policy.h" |
| 6 | 6 |
| 7 #include "base/base_switches.h" | 7 #include "base/base_switches.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/memory/singleton.h" | 10 #include "base/memory/singleton.h" |
| 11 #include "base/metrics/histogram_macros.h" |
| 11 #include "base/strings/string_piece.h" | 12 #include "base/strings/string_piece.h" |
| 12 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
| 13 #include "content/browser/frame_host/navigation_entry_impl.h" | 14 #include "content/browser/frame_host/navigation_entry_impl.h" |
| 14 #include "content/browser/renderer_host/render_process_host_impl.h" | 15 #include "content/browser/renderer_host/render_process_host_impl.h" |
| 15 #include "content/browser/renderer_host/render_view_host_impl.h" | 16 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 16 #include "content/browser/site_instance_impl.h" | 17 #include "content/browser/site_instance_impl.h" |
| 17 #include "content/browser/ssl/ssl_cert_error_handler.h" | 18 #include "content/browser/ssl/ssl_cert_error_handler.h" |
| 18 #include "content/browser/ssl/ssl_request_info.h" | 19 #include "content/browser/ssl/ssl_request_info.h" |
| 19 #include "content/browser/web_contents/web_contents_impl.h" | 20 #include "content/browser/web_contents/web_contents_impl.h" |
| 20 #include "content/public/browser/content_browser_client.h" | 21 #include "content/public/browser/content_browser_client.h" |
| 21 #include "content/public/common/resource_type.h" | 22 #include "content/public/common/resource_type.h" |
| 22 #include "content/public/common/ssl_status.h" | 23 #include "content/public/common/ssl_status.h" |
| 23 #include "content/public/common/url_constants.h" | 24 #include "content/public/common/url_constants.h" |
| 24 #include "net/ssl/ssl_info.h" | 25 #include "net/ssl/ssl_info.h" |
| 25 | 26 |
| 26 | 27 |
| 27 namespace content { | 28 namespace content { |
| 28 | 29 |
| 30 namespace { |
| 31 |
| 32 // Events for UMA. Do not reorder or change! |
| 33 enum SSLGoodCertSeenEvent { |
| 34 NO_PREVIOUS_EXCEPTION = 0, |
| 35 HAD_PREVIOUS_EXCEPTION = 1, |
| 36 END_OF_SSL_GOOD_CERT_SEEN_EVENT = 2 |
| 37 }; |
| 38 } |
| 39 |
| 29 SSLPolicy::SSLPolicy(SSLPolicyBackend* backend) | 40 SSLPolicy::SSLPolicy(SSLPolicyBackend* backend) |
| 30 : backend_(backend) { | 41 : backend_(backend) { |
| 31 DCHECK(backend_); | 42 DCHECK(backend_); |
| 32 } | 43 } |
| 33 | 44 |
| 34 void SSLPolicy::OnCertError(SSLCertErrorHandler* handler) { | 45 void SSLPolicy::OnCertError(SSLCertErrorHandler* handler) { |
| 35 bool expired_previous_decision; | 46 bool expired_previous_decision; |
| 36 // First we check if we know the policy for this error. | 47 // First we check if we know the policy for this error. |
| 37 DCHECK(handler->ssl_info().is_valid()); | 48 DCHECK(handler->ssl_info().is_valid()); |
| 38 SSLHostStateDelegate::CertJudgment judgment = | 49 SSLHostStateDelegate::CertJudgment judgment = |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 | 114 |
| 104 backend_->HostRanInsecureContent(GURL(security_origin).host(), | 115 backend_->HostRanInsecureContent(GURL(security_origin).host(), |
| 105 site_instance->GetProcess()->GetID()); | 116 site_instance->GetProcess()->GetID()); |
| 106 } | 117 } |
| 107 | 118 |
| 108 void SSLPolicy::OnRequestStarted(SSLRequestInfo* info) { | 119 void SSLPolicy::OnRequestStarted(SSLRequestInfo* info) { |
| 109 // TODO(abarth): This mechanism is wrong. What we should be doing is sending | 120 // TODO(abarth): This mechanism is wrong. What we should be doing is sending |
| 110 // this information back through WebKit and out some FrameLoaderClient | 121 // this information back through WebKit and out some FrameLoaderClient |
| 111 // methods. | 122 // methods. |
| 112 | 123 |
| 113 if (net::IsCertStatusError(info->ssl_cert_status())) | 124 if (net::IsCertStatusError(info->ssl_cert_status())) { |
| 114 backend_->HostRanInsecureContent(info->url().host(), info->child_id()); | 125 backend_->HostRanInsecureContent(info->url().host(), info->child_id()); |
| 126 } else { |
| 127 SSLGoodCertSeenEvent event = NO_PREVIOUS_EXCEPTION; |
| 128 if (backend_->HasAllowException(info->url().host())) { |
| 129 // If there's no certificate error, a good certificate has been seen, so |
| 130 // clear out any exceptions that were made by the user for bad |
| 131 // certificates. |
| 132 backend_->RevokeUserAllowExceptions(info->url().host()); |
| 133 event = HAD_PREVIOUS_EXCEPTION; |
| 134 } |
| 135 UMA_HISTOGRAM_ENUMERATION("interstitial.ssl.good_cert_seen", event, |
| 136 END_OF_SSL_GOOD_CERT_SEEN_EVENT); |
| 137 } |
| 115 } | 138 } |
| 116 | 139 |
| 117 void SSLPolicy::UpdateEntry(NavigationEntryImpl* entry, | 140 void SSLPolicy::UpdateEntry(NavigationEntryImpl* entry, |
| 118 WebContentsImpl* web_contents) { | 141 WebContentsImpl* web_contents) { |
| 119 DCHECK(entry); | 142 DCHECK(entry); |
| 120 | 143 |
| 121 InitializeEntryIfNeeded(entry); | 144 InitializeEntryIfNeeded(entry); |
| 122 | 145 |
| 123 if (!entry->GetURL().SchemeIsSecure()) | 146 if (!entry->GetURL().SchemeIsSecure()) |
| 124 return; | 147 return; |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 SECURITY_STYLE_AUTHENTICATED : SECURITY_STYLE_UNAUTHENTICATED; | 255 SECURITY_STYLE_AUTHENTICATED : SECURITY_STYLE_UNAUTHENTICATED; |
| 233 } | 256 } |
| 234 | 257 |
| 235 void SSLPolicy::OriginRanInsecureContent(const std::string& origin, int pid) { | 258 void SSLPolicy::OriginRanInsecureContent(const std::string& origin, int pid) { |
| 236 GURL parsed_origin(origin); | 259 GURL parsed_origin(origin); |
| 237 if (parsed_origin.SchemeIsSecure()) | 260 if (parsed_origin.SchemeIsSecure()) |
| 238 backend_->HostRanInsecureContent(parsed_origin.host(), pid); | 261 backend_->HostRanInsecureContent(parsed_origin.host(), pid); |
| 239 } | 262 } |
| 240 | 263 |
| 241 } // namespace content | 264 } // namespace content |
| OLD | NEW |