OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 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 #include "base/callback.h" |
| 10 #include "base/memory/weak_ptr.h" |
| 11 #include "base/timer/timer.h" |
| 12 #include "chrome/browser/chrome_notification_types.h" |
| 13 #include "content/public/browser/notification_observer.h" |
| 14 #include "content/public/browser/notification_registrar.h" |
| 15 #include "content/public/browser/web_contents_observer.h" |
| 16 #include "url/gurl.h" |
| 17 |
| 18 namespace content { |
| 19 class RenderViewHost; |
| 20 class WebContents; |
| 21 } |
| 22 |
| 23 namespace net { |
| 24 class SSLInfo; |
| 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 bool overridable, |
| 42 bool strict_enforcement, |
| 43 const base::Callback<void(bool)>& callback); |
| 44 virtual ~SSLErrorHandler(); |
| 45 |
| 46 void Handle(); |
| 47 virtual void OnCaptivePortalResult(); |
| 48 virtual void OnTimerExpired(); |
| 49 bool handled() const { |
| 50 return handled_; |
| 51 } |
| 52 |
| 53 protected: |
| 54 // Only used in tests. |
| 55 void set_ssl_interstitial_display_delay(base::TimeDelta delay) { |
| 56 ssl_interstitial_display_delay_ = delay; |
| 57 } |
| 58 base::OneShotTimer<SSLErrorHandler> timer_; |
| 59 |
| 60 private: |
| 61 // content::WebContentsObserver: |
| 62 virtual void DidStopLoading( |
| 63 content::RenderViewHost* render_view_host) OVERRIDE; |
| 64 virtual void WebContentsDestroyed() OVERRIDE; |
| 65 |
| 66 // content::NotificationObserver: |
| 67 virtual void Observe( |
| 68 int type, |
| 69 const content::NotificationSource& source, |
| 70 const content::NotificationDetails& details) OVERRIDE; |
| 71 |
| 72 virtual void ShowSSLInterstitial(); |
| 73 virtual void ShowCaptivePortalInterstitial(); |
| 74 virtual void CheckForCaptivePortal(); |
| 75 |
| 76 content::WebContents* web_contents_; |
| 77 int cert_error_; |
| 78 const net::SSLInfo& ssl_info_; |
| 79 const GURL& request_url_; |
| 80 bool overridable_; |
| 81 bool strict_enforcement_; |
| 82 base::Callback<void(bool)> callback_; |
| 83 bool captive_portal_detection_enabled_; |
| 84 bool handled_; |
| 85 |
| 86 // Time to wait before displaying the SSL interstitial. If a captive portal |
| 87 // arrives before this, the captive portal interstitial is displayed instead. |
| 88 base::TimeDelta ssl_interstitial_display_delay_; |
| 89 |
| 90 content::NotificationRegistrar registrar_; |
| 91 |
| 92 DISALLOW_COPY_AND_ASSIGN(SSLErrorHandler); |
| 93 }; |
| 94 |
| 95 #endif // CHROME_BROWSER_SSL_SSL_ERROR_HANDLER_H_ |
OLD | NEW |