| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_SSL_SSL_ERROR_HANDLER_H_ | 5 #ifndef CHROME_BROWSER_SSL_SSL_ERROR_HANDLER_H_ |
| 6 #define CHROME_BROWSER_SSL_SSL_ERROR_HANDLER_H_ | 6 #define CHROME_BROWSER_SSL_SSL_ERROR_HANDLER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/callback_forward.h" | 10 #include "base/callback_forward.h" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/timer/timer.h" | 12 #include "base/timer/timer.h" |
| 13 #include "chrome/browser/chrome_notification_types.h" | 13 #include "chrome/browser/chrome_notification_types.h" |
| 14 #include "content/public/browser/notification_observer.h" | 14 #include "content/public/browser/notification_observer.h" |
| 15 #include "content/public/browser/notification_registrar.h" | 15 #include "content/public/browser/notification_registrar.h" |
| 16 #include "content/public/browser/web_contents_observer.h" | 16 #include "content/public/browser/web_contents_observer.h" |
| 17 #include "content/public/browser/web_contents_user_data.h" | 17 #include "content/public/browser/web_contents_user_data.h" |
| 18 #include "net/ssl/ssl_info.h" | 18 #include "net/ssl/ssl_info.h" |
| 19 #include "url/gurl.h" | 19 #include "url/gurl.h" |
| 20 | 20 |
| 21 namespace content { | 21 namespace content { |
| 22 class RenderViewHost; | 22 class RenderViewHost; |
| 23 class WebContents; | 23 class WebContents; |
| 24 } | 24 } |
| 25 | 25 |
| 26 class SafeBrowsingUIManager; |
| 27 |
| 26 // This class is responsible for deciding whether to show an SSL warning or a | 28 // This class is responsible for deciding whether to show an SSL warning or a |
| 27 // captive portal error page. It makes this decision by delaying the display of | 29 // captive portal error page. It makes this decision by delaying the display of |
| 28 // SSL interstitial for a few seconds (2 by default), and waiting for a captive | 30 // SSL interstitial for a few seconds (2 by default), and waiting for a captive |
| 29 // portal result to arrive during this window. If a captive portal detected | 31 // portal result to arrive during this window. If a captive portal detected |
| 30 // result arrives in this window, a captive portal error page is shown. | 32 // result arrives in this window, a captive portal error page is shown. |
| 31 // Otherwise, an SSL interstitial is shown. | 33 // Otherwise, an SSL interstitial is shown. |
| 32 // | 34 // |
| 33 // An SSLErrorHandler is associated with a particular WebContents, and is | 35 // An SSLErrorHandler is associated with a particular WebContents, and is |
| 34 // deleted if the WebContents is destroyed, or an interstitial is displayed. | 36 // deleted if the WebContents is destroyed, or an interstitial is displayed. |
| 35 // It should only be used on the UI thread because its implementation uses | 37 // It should only be used on the UI thread because its implementation uses |
| 36 // captive_portal::CaptivePortalService which can only be accessed on the UI | 38 // captive_portal::CaptivePortalService which can only be accessed on the UI |
| 37 // thread. | 39 // thread. |
| 38 class SSLErrorHandler : public content::WebContentsUserData<SSLErrorHandler>, | 40 class SSLErrorHandler : public content::WebContentsUserData<SSLErrorHandler>, |
| 39 public content::WebContentsObserver, | 41 public content::WebContentsObserver, |
| 40 public content::NotificationObserver { | 42 public content::NotificationObserver { |
| 41 public: | 43 public: |
| 42 // Type of the delay to display the SSL interstitial. | 44 // Type of the delay to display the SSL interstitial. |
| 43 enum InterstitialDelayType { | 45 enum InterstitialDelayType { |
| 44 NORMAL, // Default interstitial timer delay used in production. | 46 NORMAL, // Default interstitial timer delay used in production. |
| 45 NONE, // No interstitial timer delay (i.e. zero), used in tests. | 47 NONE, // No interstitial timer delay (i.e. zero), used in tests. |
| 46 LONG // Very long interstitial timer delay (ie. an hour), used in tests. | 48 LONG // Very long interstitial timer delay (ie. an hour), used in tests. |
| 47 }; | 49 }; |
| 48 | 50 |
| 49 static void HandleSSLError(content::WebContents* web_contents, | 51 static void HandleSSLError(content::WebContents* web_contents, |
| 50 int cert_error, | 52 int cert_error, |
| 51 const net::SSLInfo& ssl_info, | 53 const net::SSLInfo& ssl_info, |
| 52 const GURL& request_url, | 54 const GURL& request_url, |
| 53 int options_mask, | 55 int options_mask, |
| 56 SafeBrowsingUIManager* safe_browsing_ui_manager, |
| 54 const base::Callback<void(bool)>& callback); | 57 const base::Callback<void(bool)>& callback); |
| 55 | 58 |
| 56 static void SetInterstitialDelayTypeForTest(InterstitialDelayType delay); | 59 static void SetInterstitialDelayTypeForTest(InterstitialDelayType delay); |
| 57 | 60 |
| 58 typedef base::Callback<void(content::WebContents*)> TimerStartedCallback; | 61 typedef base::Callback<void(content::WebContents*)> TimerStartedCallback; |
| 59 static void SetInterstitialTimerStartedCallbackForTest( | 62 static void SetInterstitialTimerStartedCallbackForTest( |
| 60 TimerStartedCallback* callback); | 63 TimerStartedCallback* callback); |
| 61 | 64 |
| 62 protected: | 65 protected: |
| 63 SSLErrorHandler(content::WebContents* web_contents, | 66 SSLErrorHandler(content::WebContents* web_contents, |
| 64 int cert_error, | 67 int cert_error, |
| 65 const net::SSLInfo& ssl_info, | 68 const net::SSLInfo& ssl_info, |
| 66 const GURL& request_url, | 69 const GURL& request_url, |
| 67 int options_mask, | 70 int options_mask, |
| 71 SafeBrowsingUIManager* safe_browsing_ui_manager, |
| 68 const base::Callback<void(bool)>& callback); | 72 const base::Callback<void(bool)>& callback); |
| 69 | 73 |
| 70 ~SSLErrorHandler() override; | 74 ~SSLErrorHandler() override; |
| 71 | 75 |
| 72 // Called when an SSL cert error is encountered. Triggers a captive portal | 76 // Called when an SSL cert error is encountered. Triggers a captive portal |
| 73 // check and fires a one shot timer to wait for a "captive portal detected" | 77 // check and fires a one shot timer to wait for a "captive portal detected" |
| 74 // result to arrive. | 78 // result to arrive. |
| 75 void StartHandlingError(); | 79 void StartHandlingError(); |
| 76 const base::OneShotTimer<SSLErrorHandler>& get_timer() const { | 80 const base::OneShotTimer<SSLErrorHandler>& get_timer() const { |
| 77 return timer_; | 81 return timer_; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 101 content::WebContents* web_contents_; | 105 content::WebContents* web_contents_; |
| 102 const int cert_error_; | 106 const int cert_error_; |
| 103 const net::SSLInfo ssl_info_; | 107 const net::SSLInfo ssl_info_; |
| 104 const GURL request_url_; | 108 const GURL request_url_; |
| 105 const int options_mask_; | 109 const int options_mask_; |
| 106 base::Callback<void(bool)> callback_; | 110 base::Callback<void(bool)> callback_; |
| 107 | 111 |
| 108 content::NotificationRegistrar registrar_; | 112 content::NotificationRegistrar registrar_; |
| 109 base::OneShotTimer<SSLErrorHandler> timer_; | 113 base::OneShotTimer<SSLErrorHandler> timer_; |
| 110 | 114 |
| 115 SafeBrowsingUIManager* safe_browsing_ui_manager_; |
| 116 |
| 111 DISALLOW_COPY_AND_ASSIGN(SSLErrorHandler); | 117 DISALLOW_COPY_AND_ASSIGN(SSLErrorHandler); |
| 112 }; | 118 }; |
| 113 | 119 |
| 114 #endif // CHROME_BROWSER_SSL_SSL_ERROR_HANDLER_H_ | 120 #endif // CHROME_BROWSER_SSL_SSL_ERROR_HANDLER_H_ |
| OLD | NEW |