| 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_observer.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 // This class deletes itself when the interstitial page is closed. It should |
| 33 // only be used on the UI thread because its implementation uses |
| 34 // captive_portal::CaptivePortalService which can only be accessed on the UI |
| 35 // thread. |
| 36 class SSLErrorHandler : public content::WebContentsObserver, |
| 37 public content::NotificationObserver { |
| 38 public: |
| 39 SSLErrorHandler(content::WebContents* web_contents, |
| 40 int cert_error, |
| 41 const net::SSLInfo& ssl_info, |
| 42 const GURL& request_url, |
| 43 int options_mask, |
| 44 const base::Callback<void(bool)>& callback); |
| 45 ~SSLErrorHandler() override; |
| 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 SetInterstitialDisplayDelayForTest( |
| 55 base::TimeDelta interstitial_display_delay) { |
| 56 interstitial_display_delay_ = interstitial_display_delay; |
| 57 } |
| 58 |
| 59 protected: |
| 60 // Called when an SSL cert error is encountered. Triggers a captive portal |
| 61 // check and fires a one shot timer to wait for a "captive portal detected" |
| 62 // result to arrive. |
| 63 void StartHandlingError(); |
| 64 const base::OneShotTimer<SSLErrorHandler>& get_timer() const { |
| 65 return timer_; |
| 66 } |
| 67 |
| 68 private: |
| 69 // Time to wait before displaying the SSL interstitial. If a captive portal |
| 70 // arrives before this, the captive portal interstitial is displayed instead. |
| 71 static base::TimeDelta interstitial_display_delay_; |
| 72 |
| 73 // Callback for the one-shot timer. When the timer expires, an SSL error is |
| 74 // immediately displayed. |
| 75 void OnTimerExpired(); |
| 76 |
| 77 // These are virtual for tests: |
| 78 virtual void CheckForCaptivePortal(); |
| 79 virtual void ShowCaptivePortalInterstitial(); |
| 80 virtual void ShowSSLInterstitial(); |
| 81 |
| 82 // content::NotificationObserver: |
| 83 void Observe( |
| 84 int type, |
| 85 const content::NotificationSource& source, |
| 86 const content::NotificationDetails& details) override; |
| 87 |
| 88 // content::WebContentsObserver: |
| 89 void DidStartNavigationToPendingEntry( |
| 90 const GURL& url, |
| 91 content::NavigationController::ReloadType reload_type) override; |
| 92 void DidStopLoading( |
| 93 content::RenderViewHost* render_view_host) override; |
| 94 void WebContentsDestroyed() override; |
| 95 |
| 96 const int cert_error_; |
| 97 const net::SSLInfo ssl_info_; |
| 98 const GURL request_url_; |
| 99 const int options_mask_; |
| 100 const base::Callback<void(bool)> callback_; |
| 101 |
| 102 content::NotificationRegistrar registrar_; |
| 103 base::OneShotTimer<SSLErrorHandler> timer_; |
| 104 |
| 105 DISALLOW_COPY_AND_ASSIGN(SSLErrorHandler); |
| 106 }; |
| 107 |
| 108 #endif // CHROME_BROWSER_SSL_SSL_ERROR_HANDLER_H_ |
| OLD | NEW |