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. | |
|
felt
2014/12/28 15:40:52
If this is zero, should it be named "NONE"?
meacer
2015/01/08 14:29:16
Done.
| |
| 44 LONG // Very long interstitial timer delay (ie. an hour), used in tests. | |
| 45 }; | |
| 46 | |
| 47 static void HandleSSLError(content::WebContents* web_contents, | |
| 48 int cert_error, | |
| 49 const net::SSLInfo& ssl_info, | |
| 50 const GURL& request_url, | |
| 51 int options_mask, | |
| 52 const base::Callback<void(bool)>& callback); | |
| 53 | |
| 54 static void SetInterstitialDelayTypeForTest(InterstitialDelayType delay); | |
| 55 | |
| 56 typedef base::Callback<void(content::WebContents*)> TimerStartedCallback; | |
| 57 static void SetInterstitialTimerStartedCallbackForTest( | |
| 58 TimerStartedCallback* callback); | |
| 59 | |
| 60 protected: | |
| 61 SSLErrorHandler(content::WebContents* web_contents, | |
| 62 int cert_error, | |
| 63 const net::SSLInfo& ssl_info, | |
| 64 const GURL& request_url, | |
| 65 int options_mask, | |
| 66 const base::Callback<void(bool)>& callback); | |
| 67 | |
| 68 ~SSLErrorHandler() override; | |
| 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 content::WebContents* web_contents_; | |
| 95 const int cert_error_; | |
| 96 const net::SSLInfo ssl_info_; | |
| 97 const GURL request_url_; | |
| 98 const int options_mask_; | |
| 99 const base::Callback<void(bool)> callback_; | |
| 100 | |
| 101 content::NotificationRegistrar registrar_; | |
| 102 base::OneShotTimer<SSLErrorHandler> timer_; | |
| 103 | |
| 104 DISALLOW_COPY_AND_ASSIGN(SSLErrorHandler); | |
| 105 }; | |
| 106 | |
| 107 #endif // CHROME_BROWSER_SSL_SSL_ERROR_HANDLER_H_ | |
| OLD | NEW |