| 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/callback_helpers.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" |
| 10 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 11 #include "chrome/browser/ssl/ssl_blocking_page.h" | 12 #include "chrome/browser/ssl/ssl_blocking_page.h" |
| 12 #include "content/public/browser/notification_service.h" | 13 #include "content/public/browser/notification_service.h" |
| 13 #include "content/public/browser/notification_source.h" | 14 #include "content/public/browser/notification_source.h" |
| 14 #include "content/public/browser/web_contents.h" | 15 #include "content/public/browser/web_contents.h" |
| 15 | 16 |
| 16 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION) | 17 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION) |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 DCHECK(!callback || !callback->is_null()); | 120 DCHECK(!callback || !callback->is_null()); |
| 120 g_timer_started_callback = callback; | 121 g_timer_started_callback = callback; |
| 121 } | 122 } |
| 122 | 123 |
| 123 SSLErrorHandler::SSLErrorHandler(content::WebContents* web_contents, | 124 SSLErrorHandler::SSLErrorHandler(content::WebContents* web_contents, |
| 124 int cert_error, | 125 int cert_error, |
| 125 const net::SSLInfo& ssl_info, | 126 const net::SSLInfo& ssl_info, |
| 126 const GURL& request_url, | 127 const GURL& request_url, |
| 127 int options_mask, | 128 int options_mask, |
| 128 const base::Callback<void(bool)>& callback) | 129 const base::Callback<void(bool)>& callback) |
| 129 : web_contents_(web_contents), | 130 : content::WebContentsObserver(web_contents), |
| 131 web_contents_(web_contents), |
| 130 cert_error_(cert_error), | 132 cert_error_(cert_error), |
| 131 ssl_info_(ssl_info), | 133 ssl_info_(ssl_info), |
| 132 request_url_(request_url), | 134 request_url_(request_url), |
| 133 options_mask_(options_mask), | 135 options_mask_(options_mask), |
| 134 callback_(callback) { | 136 callback_(callback) { |
| 135 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION) | 137 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION) |
| 136 Profile* profile = Profile::FromBrowserContext( | 138 Profile* profile = Profile::FromBrowserContext( |
| 137 web_contents->GetBrowserContext()); | 139 web_contents->GetBrowserContext()); |
| 138 registrar_.Add(this, | 140 registrar_.Add(this, |
| 139 chrome::NOTIFICATION_CAPTIVE_PORTAL_CHECK_RESULT, | 141 chrome::NOTIFICATION_CAPTIVE_PORTAL_CHECK_RESULT, |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 timer_.Stop(); | 218 timer_.Stop(); |
| 217 CaptivePortalService::Results* results = | 219 CaptivePortalService::Results* results = |
| 218 content::Details<CaptivePortalService::Results>(details).ptr(); | 220 content::Details<CaptivePortalService::Results>(details).ptr(); |
| 219 if (results->result == captive_portal::RESULT_BEHIND_CAPTIVE_PORTAL) | 221 if (results->result == captive_portal::RESULT_BEHIND_CAPTIVE_PORTAL) |
| 220 ShowCaptivePortalInterstitial(results->landing_url); | 222 ShowCaptivePortalInterstitial(results->landing_url); |
| 221 else | 223 else |
| 222 ShowSSLInterstitial(); | 224 ShowSSLInterstitial(); |
| 223 } | 225 } |
| 224 #endif | 226 #endif |
| 225 } | 227 } |
| 228 |
| 229 // Destroy the error handler on all new navigations. This ensures that the |
| 230 // handler is properly recreated when a hanging page is navigated to an SSL |
| 231 // error, even when the tab's WebContents doesn't change. |
| 232 void SSLErrorHandler::DidStartNavigationToPendingEntry( |
| 233 const GURL& url, |
| 234 content::NavigationController::ReloadType reload_type) { |
| 235 // Need to explicity deny the certificate via the callback, otherwise memory |
| 236 // is leaked. |
| 237 if (!callback_.is_null()) { |
| 238 base::ResetAndReturn(&callback_).Run(false); |
| 239 } |
| 240 web_contents_->RemoveUserData(UserDataKey()); |
| 241 } |
| OLD | NEW |