Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_SSL_SSL_ERROR_HANDLER_H_ | |
| 6 #define CHROME_BROWSER_SSL_SSL_ERROR_HANDLER_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 | |
| 10 #include "base/callback_forward.h" | |
| 11 #include "base/macros.h" | |
| 12 #include "base/timer/timer.h" | |
| 13 #include "chrome/browser/chrome_notification_types.h" | |
| 14 #include "content/public/browser/notification_observer.h" | |
| 15 #include "content/public/browser/notification_registrar.h" | |
| 16 #include "content/public/browser/web_contents_user_data.h" | |
| 17 #include "net/ssl/ssl_info.h" | |
| 18 #include "url/gurl.h" | |
| 19 | |
| 20 namespace content { | |
| 21 class RenderViewHost; | |
| 22 class WebContents; | |
| 23 } | |
| 24 | |
| 25 // This class is responsible for deciding whether to show an SSL warning or a | |
| 26 // captive portal error page. It makes this decision by delaying the display of | |
| 27 // SSL interstitial for a few seconds (2 by default), and waiting for a captive | |
| 28 // portal result to arrive during this window. If a captive portal detected | |
| 29 // result arrives in this window, a captive portal error page is shown. | |
| 30 // Otherwise, an SSL interstitial is shown. | |
| 31 // | |
| 32 // An SSLErrorHandler is associated with a particular WebContents, and is | |
| 33 // deleted if the WebContents is destroyed, or an interstitial is displayed. | |
| 34 // It should only be used on the UI thread because its implementation uses | |
| 35 // captive_portal::CaptivePortalService which can only be accessed on the UI | |
| 36 // thread. | |
| 37 class SSLErrorHandler : public content::WebContentsUserData<SSLErrorHandler>, | |
| 38 public content::NotificationObserver { | |
| 39 public: | |
| 40 // Type of the delay to display the SSL interstitial. | |
| 41 enum InterstitialDelayType { | |
| 42 NORMAL, // Default interstitial timer delay used in production. | |
| 43 SHORT, // Very short interstitial timer delay (ie. zero), used in tests. | |
| 44 LONG // Very long interstitial timer delay (ie. an hour), used in tests. | |
| 45 }; | |
| 46 | |
| 47 ~SSLErrorHandler() override; | |
|
Bernhard Bauer
2014/12/20 11:21:23
You could make the destructor protected as well, b
meacer
2014/12/22 20:01:23
Done.
| |
| 48 | |
| 49 static void HandleSSLError(content::WebContents* web_contents, | |
| 50 int cert_error, | |
| 51 const net::SSLInfo& ssl_info, | |
| 52 const GURL& request_url, | |
| 53 int options_mask, | |
| 54 const base::Callback<void(bool)>& callback); | |
| 55 | |
| 56 static void SetInterstitialDelayTypeForTest(InterstitialDelayType delay); | |
| 57 | |
| 58 typedef base::Callback<void(content::WebContents*)> TimerFiredCallback; | |
| 59 static void SetInterstitialTimerFiredCallbackForTest( | |
| 60 TimerFiredCallback* callback); | |
| 61 | |
| 62 protected: | |
| 63 SSLErrorHandler(content::WebContents* web_contents, | |
| 64 int cert_error, | |
| 65 const net::SSLInfo& ssl_info, | |
| 66 const GURL& request_url, | |
| 67 int options_mask, | |
| 68 const base::Callback<void(bool)>& callback); | |
| 69 | |
| 70 // Called when an SSL cert error is encountered. Triggers a captive portal | |
| 71 // check and fires a one shot timer to wait for a "captive portal detected" | |
| 72 // result to arrive. | |
| 73 void StartHandlingError(); | |
| 74 const base::OneShotTimer<SSLErrorHandler>& get_timer() const { | |
| 75 return timer_; | |
| 76 } | |
| 77 | |
| 78 private: | |
| 79 // Callback for the one-shot timer. When the timer expires, an SSL error is | |
| 80 // immediately displayed. | |
| 81 void OnTimerExpired(); | |
| 82 | |
| 83 // These are virtual for tests: | |
| 84 virtual void CheckForCaptivePortal(); | |
| 85 virtual void ShowCaptivePortalInterstitial(); | |
| 86 virtual void ShowSSLInterstitial(); | |
| 87 | |
| 88 // content::NotificationObserver: | |
| 89 void Observe( | |
| 90 int type, | |
| 91 const content::NotificationSource& source, | |
| 92 const content::NotificationDetails& details) override; | |
| 93 | |
| 94 // Time to wait before displaying the SSL interstitial. If a captive portal | |
| 95 // arrives before this, the captive portal interstitial is displayed instead. | |
| 96 static base::TimeDelta interstitial_display_delay_; | |
| 97 | |
| 98 // Callback to call when the interstitial timer is fired. Used for testing. | |
| 99 static TimerFiredCallback* timer_fired_callback_; | |
| 100 | |
| 101 content::WebContents* web_contents_; | |
| 102 const int cert_error_; | |
| 103 const net::SSLInfo ssl_info_; | |
| 104 const GURL request_url_; | |
| 105 const int options_mask_; | |
| 106 const base::Callback<void(bool)> callback_; | |
| 107 | |
| 108 content::NotificationRegistrar registrar_; | |
| 109 base::OneShotTimer<SSLErrorHandler> timer_; | |
| 110 | |
| 111 DISALLOW_COPY_AND_ASSIGN(SSLErrorHandler); | |
| 112 }; | |
| 113 | |
| 114 #endif // CHROME_BROWSER_SSL_SSL_ERROR_HANDLER_H_ | |
| OLD | NEW |