Index: chrome/browser/ssl/ssl_error_handler.cc |
diff --git a/chrome/browser/ssl/ssl_error_handler.cc b/chrome/browser/ssl/ssl_error_handler.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..cf89921a8522a9ef113be9300f17780bb640604a |
--- /dev/null |
+++ b/chrome/browser/ssl/ssl_error_handler.cc |
@@ -0,0 +1,130 @@ |
+// Copyright (c) 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/browser/ssl/ssl_error_handler.h" |
+ |
+#include "base/time/time.h" |
+#include "base/timer/timer.h" |
+#include "chrome/browser/profiles/profile.h" |
+#include "chrome/browser/ssl/captive_portal_blocking_page.h" |
+#include "chrome/browser/ssl/ssl_blocking_page.h" |
+#include "content/public/browser/notification_service.h" |
+#include "content/public/browser/notification_source.h" |
+#include "content/public/browser/web_contents.h" |
+ |
+#if defined(ENABLE_CAPTIVE_PORTAL_DETECTION) |
+#include "chrome/browser/captive_portal/captive_portal_service.h" |
+#include "chrome/browser/captive_portal/captive_portal_service_factory.h" |
+#endif |
+ |
+// The delay before displaying the SSL interstitial, during which we wait for a |
+// captive portal result. |
+const int kDefaultSSLInterstitialDisplayDelay = 2; |
+ |
+SSLErrorHandler::SSLErrorHandler(content::WebContents* web_contents, |
+ int cert_error, |
+ const net::SSLInfo& ssl_info, |
+ const GURL& request_url, |
+ bool overridable, |
+ bool strict_enforcement, |
+ const base::Callback<void(bool)>& callback) |
+ : content::WebContentsObserver(web_contents), |
+ web_contents_(web_contents), |
+ cert_error_(cert_error), |
+ ssl_info_(ssl_info), |
+ request_url_(request_url), |
+ overridable_(overridable), |
+ strict_enforcement_(strict_enforcement), |
+ callback_(callback), |
+ captive_portal_detection_enabled_(false), |
+ handled_(false), |
+ ssl_interstitial_display_delay_( |
+ base::TimeDelta::FromSeconds(kDefaultSSLInterstitialDisplayDelay)) { |
+} |
+ |
+SSLErrorHandler::~SSLErrorHandler() { |
+} |
+ |
+void SSLErrorHandler::Handle() { |
+#if defined(ENABLE_CAPTIVE_PORTAL_DETECTION) |
+ CheckForCaptivePortal(); |
+ timer_.Start(FROM_HERE, ssl_interstitial_display_delay_, |
+ base::Bind(&SSLErrorHandler::OnTimerExpired, |
+ base::Unretained(this))); |
+#else |
+ ShowSSLInterstitial(); |
+#endif |
+} |
+ |
+void SSLErrorHandler::CheckForCaptivePortal() { |
+#if defined(ENABLE_CAPTIVE_PORTAL_DETECTION) |
+ Profile* profile = Profile::FromBrowserContext( |
+ web_contents_->GetBrowserContext()); |
+ CaptivePortalService* captive_portal_service = |
+ CaptivePortalServiceFactory::GetForProfile(profile); |
+ captive_portal_detection_enabled_ = captive_portal_service->enabled(); |
+ captive_portal_service->DetectCaptivePortal(); |
+ registrar_.Add(this, |
+ chrome::NOTIFICATION_CAPTIVE_PORTAL_CHECK_RESULT, |
+ content::Source<Profile>(profile)); |
+#endif |
+} |
+ |
+void SSLErrorHandler::Observe( |
+ int type, |
+ const content::NotificationSource& source, |
+ const content::NotificationDetails& details) { |
+ // TODO(meacer): Refactor this method in SSLBlockingPage. |
+#if defined(ENABLE_CAPTIVE_PORTAL_DETECTION) |
+ // When detection is disabled, captive portal service always sends |
+ // RESULT_INTERNET_CONNECTED. Ignore any probe results in that case. |
+ if (!captive_portal_detection_enabled_) |
+ 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.
|
+ if (type == chrome::NOTIFICATION_CAPTIVE_PORTAL_CHECK_RESULT) { |
+ CaptivePortalService::Results* results = |
+ content::Details<CaptivePortalService::Results>(details).ptr(); |
+ bool captive_portal_detected = |
+ (results->result == captive_portal::RESULT_BEHIND_CAPTIVE_PORTAL); |
+ if (captive_portal_detected) |
+ 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
|
+ } |
+#endif |
+} |
+ |
+void SSLErrorHandler::OnCaptivePortalResult() { |
+ if (handled_ || !timer_.IsRunning()) |
+ return; |
+ timer_.Stop(); |
+ ShowCaptivePortalInterstitial(); |
+ handled_ = true; |
+} |
+ |
+void SSLErrorHandler::OnTimerExpired() { |
+ if (handled_) |
+ return; |
+ ShowSSLInterstitial(); |
+ handled_ = true; |
+} |
+ |
+void SSLErrorHandler::ShowCaptivePortalInterstitial() { |
+ // Show captive portal blocking page. The interstitial owns the blocking page. |
+ new CaptivePortalBlockingPage(web_contents_, request_url_); |
+} |
+ |
+void SSLErrorHandler::ShowSSLInterstitial() { |
+ // Show SSL blocking page. The interstitial owns the blocking page. |
+ new SSLBlockingPage(web_contents_, cert_error_, ssl_info_, request_url_, |
+ overridable_, strict_enforcement_, callback_); |
+} |
+ |
+void SSLErrorHandler::DidStopLoading( |
+ content::RenderViewHost* render_view_host) { |
+ timer_.Stop(); |
+ delete this; |
+} |
+ |
+void SSLErrorHandler::WebContentsDestroyed() { |
+ timer_.Stop(); |
+ delete this; |
+} |