Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2014 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. | |
| 4 | |
| 5 #include "chrome/browser/ssl/ssl_error_handler.h" | |
| 6 | |
| 7 #include "base/time/time.h" | |
| 8 #include "base/timer/timer.h" | |
| 9 #include "chrome/browser/profiles/profile.h" | |
| 10 #include "chrome/browser/ssl/captive_portal_blocking_page.h" | |
| 11 #include "chrome/browser/ssl/ssl_blocking_page.h" | |
| 12 #include "content/public/browser/notification_service.h" | |
| 13 #include "content/public/browser/notification_source.h" | |
| 14 #include "content/public/browser/web_contents.h" | |
| 15 | |
| 16 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION) | |
| 17 #include "chrome/browser/captive_portal/captive_portal_service.h" | |
| 18 #include "chrome/browser/captive_portal/captive_portal_service_factory.h" | |
| 19 #endif | |
| 20 | |
| 21 // The delay before displaying the SSL interstitial, during which we wait for a | |
| 22 // captive portal result. | |
| 23 const int kDefaultSSLInterstitialDisplayDelay = 2; | |
| 24 | |
| 25 SSLErrorHandler::SSLErrorHandler(content::WebContents* web_contents, | |
| 26 int cert_error, | |
| 27 const net::SSLInfo& ssl_info, | |
| 28 const GURL& request_url, | |
| 29 bool overridable, | |
| 30 bool strict_enforcement, | |
| 31 const base::Callback<void(bool)>& callback) | |
| 32 : content::WebContentsObserver(web_contents), | |
| 33 web_contents_(web_contents), | |
| 34 cert_error_(cert_error), | |
| 35 ssl_info_(ssl_info), | |
| 36 request_url_(request_url), | |
| 37 overridable_(overridable), | |
| 38 strict_enforcement_(strict_enforcement), | |
| 39 callback_(callback), | |
| 40 captive_portal_detection_enabled_(false), | |
| 41 handled_(false), | |
| 42 ssl_interstitial_display_delay_( | |
| 43 base::TimeDelta::FromSeconds(kDefaultSSLInterstitialDisplayDelay)) { | |
| 44 } | |
| 45 | |
| 46 SSLErrorHandler::~SSLErrorHandler() { | |
| 47 } | |
| 48 | |
| 49 void SSLErrorHandler::Handle() { | |
| 50 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION) | |
| 51 CheckForCaptivePortal(); | |
| 52 timer_.Start(FROM_HERE, ssl_interstitial_display_delay_, | |
| 53 base::Bind(&SSLErrorHandler::OnTimerExpired, | |
| 54 base::Unretained(this))); | |
| 55 #else | |
| 56 ShowSSLInterstitial(); | |
| 57 #endif | |
| 58 } | |
| 59 | |
| 60 void SSLErrorHandler::CheckForCaptivePortal() { | |
| 61 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION) | |
| 62 Profile* profile = Profile::FromBrowserContext( | |
| 63 web_contents_->GetBrowserContext()); | |
| 64 CaptivePortalService* captive_portal_service = | |
| 65 CaptivePortalServiceFactory::GetForProfile(profile); | |
| 66 captive_portal_detection_enabled_ = captive_portal_service->enabled(); | |
| 67 captive_portal_service->DetectCaptivePortal(); | |
| 68 registrar_.Add(this, | |
| 69 chrome::NOTIFICATION_CAPTIVE_PORTAL_CHECK_RESULT, | |
| 70 content::Source<Profile>(profile)); | |
| 71 #endif | |
| 72 } | |
| 73 | |
| 74 void SSLErrorHandler::Observe( | |
| 75 int type, | |
| 76 const content::NotificationSource& source, | |
| 77 const content::NotificationDetails& details) { | |
| 78 // TODO(meacer): Refactor this method in SSLBlockingPage. | |
| 79 #if defined(ENABLE_CAPTIVE_PORTAL_DETECTION) | |
| 80 // When detection is disabled, captive portal service always sends | |
| 81 // RESULT_INTERNET_CONNECTED. Ignore any probe results in that case. | |
| 82 if (!captive_portal_detection_enabled_) | |
| 83 return; | |
|
mmenke
2014/06/17 19:17:03
Why is this needed? Doesn't look like we're recor
meacer
2014/06/18 21:23:08
Done.
| |
| 84 if (type == chrome::NOTIFICATION_CAPTIVE_PORTAL_CHECK_RESULT) { | |
| 85 CaptivePortalService::Results* results = | |
| 86 content::Details<CaptivePortalService::Results>(details).ptr(); | |
| 87 bool captive_portal_detected = | |
| 88 (results->result == captive_portal::RESULT_BEHIND_CAPTIVE_PORTAL); | |
| 89 if (captive_portal_detected) | |
| 90 OnCaptivePortalResult(); | |
|
mmenke
2014/06/17 19:17:03
Think it's a little weird that we just always wait
meacer
2014/06/18 21:23:08
If portal detection isn't enabled, we immediately
| |
| 91 } | |
| 92 #endif | |
| 93 } | |
| 94 | |
| 95 void SSLErrorHandler::OnCaptivePortalResult() { | |
| 96 if (handled_ || !timer_.IsRunning()) | |
| 97 return; | |
| 98 timer_.Stop(); | |
| 99 ShowCaptivePortalInterstitial(); | |
| 100 handled_ = true; | |
| 101 } | |
| 102 | |
| 103 void SSLErrorHandler::OnTimerExpired() { | |
| 104 if (handled_) | |
| 105 return; | |
| 106 ShowSSLInterstitial(); | |
| 107 handled_ = true; | |
| 108 } | |
| 109 | |
| 110 void SSLErrorHandler::ShowCaptivePortalInterstitial() { | |
| 111 // Show captive portal blocking page. The interstitial owns the blocking page. | |
| 112 new CaptivePortalBlockingPage(web_contents_, request_url_); | |
| 113 } | |
| 114 | |
| 115 void SSLErrorHandler::ShowSSLInterstitial() { | |
| 116 // Show SSL blocking page. The interstitial owns the blocking page. | |
| 117 new SSLBlockingPage(web_contents_, cert_error_, ssl_info_, request_url_, | |
| 118 overridable_, strict_enforcement_, callback_); | |
| 119 } | |
| 120 | |
| 121 void SSLErrorHandler::DidStopLoading( | |
| 122 content::RenderViewHost* render_view_host) { | |
| 123 timer_.Stop(); | |
| 124 delete this; | |
| 125 } | |
| 126 | |
| 127 void SSLErrorHandler::WebContentsDestroyed() { | |
| 128 timer_.Stop(); | |
| 129 delete this; | |
| 130 } | |
| OLD | NEW |