| 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/memory/weak_ptr.h" |
| 13 #include "base/metrics/histogram.h" |
| 14 #include "base/timer/timer.h" |
| 15 #include "chrome/browser/chrome_notification_types.h" |
| 16 #include "content/public/browser/notification_observer.h" |
| 17 #include "content/public/browser/notification_registrar.h" |
| 18 #include "content/public/browser/web_contents_observer.h" |
| 19 #include "net/ssl/ssl_info.h" |
| 20 #include "url/gurl.h" |
| 21 |
| 22 namespace content { |
| 23 class RenderViewHost; |
| 24 class WebContents; |
| 25 } |
| 26 |
| 27 // This class is responsible for deciding whether to show an SSL warning or a |
| 28 // captive portal error page. |
| 29 // It deletes itself when the interstitial page is closed. |
| 30 // |
| 31 // This class should only be used on the UI thread because its implementation |
| 32 // uses captive_portal::CaptivePortalService which can only be accessed on the |
| 33 // UI thread. |
| 34 class SSLErrorHandler : public content::WebContentsObserver, |
| 35 public content::NotificationObserver { |
| 36 public: |
| 37 SSLErrorHandler(content::WebContents* web_contents, |
| 38 int cert_error, |
| 39 const net::SSLInfo& ssl_info, |
| 40 const GURL& request_url, |
| 41 int options_mask, |
| 42 const base::TimeDelta ssl_error_delay, |
| 43 const base::Callback<void(bool)>& callback); |
| 44 ~SSLErrorHandler() override; |
| 45 |
| 46 static void HandleSSLError(content::WebContents* web_contents, |
| 47 int cert_error, |
| 48 const net::SSLInfo& ssl_info, |
| 49 const GURL& request_url, |
| 50 int options_mask, |
| 51 const base::Callback<void(bool)>& callback); |
| 52 |
| 53 private: |
| 54 bool was_handled_for_testing() const { |
| 55 return handled_; |
| 56 } |
| 57 |
| 58 bool IsTimerRunningForTests() const { |
| 59 return timer_.IsRunning(); |
| 60 } |
| 61 |
| 62 void Handle(); |
| 63 virtual void CheckForCaptivePortal(); |
| 64 virtual void ShowCaptivePortalInterstitial(); |
| 65 virtual void ShowSSLInterstitial(); |
| 66 void OnTimerExpired(); |
| 67 |
| 68 // content::NotificationObserver: |
| 69 void Observe( |
| 70 int type, |
| 71 const content::NotificationSource& source, |
| 72 const content::NotificationDetails& details) override; |
| 73 |
| 74 // content::WebContentsObserver: |
| 75 void DidStopLoading( |
| 76 content::RenderViewHost* render_view_host) override; |
| 77 void WebContentsDestroyed() override; |
| 78 |
| 79 content::WebContents* web_contents_; |
| 80 const int cert_error_; |
| 81 const net::SSLInfo ssl_info_; |
| 82 const GURL request_url_; |
| 83 const int options_mask_; |
| 84 const base::Callback<void(bool)> callback_; |
| 85 bool handled_; |
| 86 |
| 87 // Time to wait before displaying the SSL interstitial. If a captive portal |
| 88 // arrives before this, the captive portal interstitial is displayed instead. |
| 89 base::TimeDelta ssl_interstitial_display_delay_; |
| 90 bool timer_expired_; |
| 91 content::NotificationRegistrar registrar_; |
| 92 base::OneShotTimer<SSLErrorHandler> timer_; |
| 93 |
| 94 friend class TestSSLErrorHandler; |
| 95 |
| 96 DISALLOW_COPY_AND_ASSIGN(SSLErrorHandler); |
| 97 }; |
| 98 |
| 99 #endif // CHROME_BROWSER_SSL_SSL_ERROR_HANDLER_H_ |
| OLD | NEW |