Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/browser/ssl/ssl_error_handler.h" | 5 #include "chrome/browser/ssl/ssl_error_handler.h" |
| 6 | 6 |
| 7 #include "base/memory/ref_counted.h" | |
| 7 #include "base/metrics/field_trial.h" | 8 #include "base/metrics/field_trial.h" |
| 8 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 9 #include "base/time/time.h" | 10 #include "base/time/time.h" |
| 11 #include "chrome/browser/net/certificate_error_reporter.h" | |
| 10 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
| 11 #include "chrome/browser/ssl/ssl_blocking_page.h" | 13 #include "chrome/browser/ssl/ssl_blocking_page.h" |
| 12 #include "content/public/browser/notification_service.h" | 14 #include "content/public/browser/notification_service.h" |
| 13 #include "content/public/browser/notification_source.h" | 15 #include "content/public/browser/notification_source.h" |
| 14 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
| 15 | 17 |
| 16 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION) | 18 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION) |
| 17 #include "chrome/browser/captive_portal/captive_portal_service.h" | 19 #include "chrome/browser/captive_portal/captive_portal_service.h" |
| 18 #include "chrome/browser/captive_portal/captive_portal_service_factory.h" | 20 #include "chrome/browser/captive_portal/captive_portal_service_factory.h" |
| 19 #include "chrome/browser/captive_portal/captive_portal_tab_helper.h" | 21 #include "chrome/browser/captive_portal/captive_portal_tab_helper.h" |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 81 } // namespace | 83 } // namespace |
| 82 | 84 |
| 83 DEFINE_WEB_CONTENTS_USER_DATA_KEY(SSLErrorHandler); | 85 DEFINE_WEB_CONTENTS_USER_DATA_KEY(SSLErrorHandler); |
| 84 | 86 |
| 85 void SSLErrorHandler::HandleSSLError( | 87 void SSLErrorHandler::HandleSSLError( |
| 86 content::WebContents* web_contents, | 88 content::WebContents* web_contents, |
| 87 int cert_error, | 89 int cert_error, |
| 88 const net::SSLInfo& ssl_info, | 90 const net::SSLInfo& ssl_info, |
| 89 const GURL& request_url, | 91 const GURL& request_url, |
| 90 int options_mask, | 92 int options_mask, |
| 93 const scoped_refptr<chrome_browser_net::CertificateErrorReporter>& | |
| 94 certificate_error_reporter, | |
|
Ryan Sleevi
2015/03/14 03:09:42
Rather than require this to be passed, you could d
| |
| 91 const base::Callback<void(bool)>& callback) { | 95 const base::Callback<void(bool)>& callback) { |
| 92 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION) | 96 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION) |
| 93 CaptivePortalTabHelper* captive_portal_tab_helper = | 97 CaptivePortalTabHelper* captive_portal_tab_helper = |
| 94 CaptivePortalTabHelper::FromWebContents(web_contents); | 98 CaptivePortalTabHelper::FromWebContents(web_contents); |
| 95 if (captive_portal_tab_helper) { | 99 if (captive_portal_tab_helper) { |
| 96 captive_portal_tab_helper->OnSSLCertError(ssl_info); | 100 captive_portal_tab_helper->OnSSLCertError(ssl_info); |
| 97 } | 101 } |
| 98 #endif | 102 #endif |
| 99 DCHECK(!FromWebContents(web_contents)); | 103 DCHECK(!FromWebContents(web_contents)); |
| 100 web_contents->SetUserData(UserDataKey(), | 104 web_contents->SetUserData( |
| 101 new SSLErrorHandler(web_contents, cert_error, | 105 UserDataKey(), |
| 102 ssl_info, request_url, | 106 new SSLErrorHandler(web_contents, cert_error, ssl_info, request_url, |
| 103 options_mask, callback)); | 107 options_mask, certificate_error_reporter, callback)); |
| 104 | 108 |
| 105 SSLErrorHandler* error_handler = | 109 SSLErrorHandler* error_handler = |
| 106 SSLErrorHandler::FromWebContents(web_contents); | 110 SSLErrorHandler::FromWebContents(web_contents); |
| 107 error_handler->StartHandlingError(); | 111 error_handler->StartHandlingError(); |
| 108 } | 112 } |
| 109 | 113 |
| 110 // static | 114 // static |
| 111 void SSLErrorHandler::SetInterstitialDelayTypeForTest( | 115 void SSLErrorHandler::SetInterstitialDelayTypeForTest( |
| 112 SSLErrorHandler::InterstitialDelayType delay) { | 116 SSLErrorHandler::InterstitialDelayType delay) { |
| 113 g_interstitial_delay_type = delay; | 117 g_interstitial_delay_type = delay; |
| 114 } | 118 } |
| 115 | 119 |
| 116 // static | 120 // static |
| 117 void SSLErrorHandler::SetInterstitialTimerStartedCallbackForTest( | 121 void SSLErrorHandler::SetInterstitialTimerStartedCallbackForTest( |
| 118 TimerStartedCallback* callback) { | 122 TimerStartedCallback* callback) { |
| 119 DCHECK(!callback || !callback->is_null()); | 123 DCHECK(!callback || !callback->is_null()); |
| 120 g_timer_started_callback = callback; | 124 g_timer_started_callback = callback; |
| 121 } | 125 } |
| 122 | 126 |
| 123 SSLErrorHandler::SSLErrorHandler(content::WebContents* web_contents, | 127 SSLErrorHandler::SSLErrorHandler( |
| 124 int cert_error, | 128 content::WebContents* web_contents, |
| 125 const net::SSLInfo& ssl_info, | 129 int cert_error, |
| 126 const GURL& request_url, | 130 const net::SSLInfo& ssl_info, |
| 127 int options_mask, | 131 const GURL& request_url, |
| 128 const base::Callback<void(bool)>& callback) | 132 int options_mask, |
| 133 scoped_refptr<chrome_browser_net::CertificateErrorReporter> | |
| 134 certificate_error_reporter, | |
| 135 const base::Callback<void(bool)>& callback) | |
| 129 : web_contents_(web_contents), | 136 : web_contents_(web_contents), |
| 130 cert_error_(cert_error), | 137 cert_error_(cert_error), |
| 131 ssl_info_(ssl_info), | 138 ssl_info_(ssl_info), |
| 132 request_url_(request_url), | 139 request_url_(request_url), |
| 133 options_mask_(options_mask), | 140 options_mask_(options_mask), |
| 141 certificate_error_reporter_(certificate_error_reporter), | |
| 134 callback_(callback) { | 142 callback_(callback) { |
| 135 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION) | 143 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION) |
| 136 Profile* profile = Profile::FromBrowserContext( | 144 Profile* profile = Profile::FromBrowserContext( |
| 137 web_contents->GetBrowserContext()); | 145 web_contents->GetBrowserContext()); |
| 138 registrar_.Add(this, | 146 registrar_.Add(this, |
| 139 chrome::NOTIFICATION_CAPTIVE_PORTAL_CHECK_RESULT, | 147 chrome::NOTIFICATION_CAPTIVE_PORTAL_CHECK_RESULT, |
| 140 content::Source<Profile>(profile)); | 148 content::Source<Profile>(profile)); |
| 141 #endif | 149 #endif |
| 142 } | 150 } |
| 143 | 151 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 194 #endif | 202 #endif |
| 195 } | 203 } |
| 196 | 204 |
| 197 void SSLErrorHandler::ShowSSLInterstitial() { | 205 void SSLErrorHandler::ShowSSLInterstitial() { |
| 198 // Show SSL blocking page. The interstitial owns the blocking page. | 206 // Show SSL blocking page. The interstitial owns the blocking page. |
| 199 RecordUMA(SSLBlockingPage::IsOptionsOverridable(options_mask_) ? | 207 RecordUMA(SSLBlockingPage::IsOptionsOverridable(options_mask_) ? |
| 200 SHOW_SSL_INTERSTITIAL_OVERRIDABLE : | 208 SHOW_SSL_INTERSTITIAL_OVERRIDABLE : |
| 201 SHOW_SSL_INTERSTITIAL_NONOVERRIDABLE); | 209 SHOW_SSL_INTERSTITIAL_NONOVERRIDABLE); |
| 202 (new SSLBlockingPage(web_contents_, cert_error_, ssl_info_, request_url_, | 210 (new SSLBlockingPage(web_contents_, cert_error_, ssl_info_, request_url_, |
| 203 options_mask_, base::Time::NowFromSystemTime(), | 211 options_mask_, base::Time::NowFromSystemTime(), |
| 204 callback_))->Show(); | 212 certificate_error_reporter_, callback_))->Show(); |
|
Ryan Sleevi
2015/03/14 03:09:42
namespace {
void SendReport(const base::WeakPtr<C
| |
| 205 // Once an interstitial is displayed, no need to keep the handler around. | 213 // Once an interstitial is displayed, no need to keep the handler around. |
| 206 // This is the equivalent of "delete this". | 214 // This is the equivalent of "delete this". |
| 207 web_contents_->RemoveUserData(UserDataKey()); | 215 web_contents_->RemoveUserData(UserDataKey()); |
| 208 } | 216 } |
| 209 | 217 |
| 210 void SSLErrorHandler::Observe( | 218 void SSLErrorHandler::Observe( |
| 211 int type, | 219 int type, |
| 212 const content::NotificationSource& source, | 220 const content::NotificationSource& source, |
| 213 const content::NotificationDetails& details) { | 221 const content::NotificationDetails& details) { |
| 214 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION) | 222 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION) |
| 215 if (type == chrome::NOTIFICATION_CAPTIVE_PORTAL_CHECK_RESULT) { | 223 if (type == chrome::NOTIFICATION_CAPTIVE_PORTAL_CHECK_RESULT) { |
| 216 timer_.Stop(); | 224 timer_.Stop(); |
| 217 CaptivePortalService::Results* results = | 225 CaptivePortalService::Results* results = |
| 218 content::Details<CaptivePortalService::Results>(details).ptr(); | 226 content::Details<CaptivePortalService::Results>(details).ptr(); |
| 219 if (results->result == captive_portal::RESULT_BEHIND_CAPTIVE_PORTAL) | 227 if (results->result == captive_portal::RESULT_BEHIND_CAPTIVE_PORTAL) |
| 220 ShowCaptivePortalInterstitial(results->landing_url); | 228 ShowCaptivePortalInterstitial(results->landing_url); |
| 221 else | 229 else |
| 222 ShowSSLInterstitial(); | 230 ShowSSLInterstitial(); |
| 223 } | 231 } |
| 224 #endif | 232 #endif |
| 225 } | 233 } |
| OLD | NEW |