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_user_data.h" | 16 #include "content/public/browser/web_contents_user_data.h" |
17 #include "net/ssl/ssl_info.h" | 17 #include "net/ssl/ssl_info.h" |
18 #include "url/gurl.h" | 18 #include "url/gurl.h" |
19 | 19 |
20 namespace content { | 20 namespace content { |
21 class RenderViewHost; | 21 class RenderViewHost; |
22 class WebContents; | 22 class WebContents; |
23 } | 23 } |
24 | 24 |
| 25 class SafeBrowsingUIManager; |
| 26 |
25 // This class is responsible for deciding whether to show an SSL warning or a | 27 // 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 | 28 // 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 | 29 // 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 | 30 // 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. | 31 // result arrives in this window, a captive portal error page is shown. |
30 // Otherwise, an SSL interstitial is shown. | 32 // Otherwise, an SSL interstitial is shown. |
31 // | 33 // |
32 // An SSLErrorHandler is associated with a particular WebContents, and is | 34 // An SSLErrorHandler is associated with a particular WebContents, and is |
33 // deleted if the WebContents is destroyed, or an interstitial is displayed. | 35 // 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 | 36 // 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 | 37 // captive_portal::CaptivePortalService which can only be accessed on the UI |
36 // thread. | 38 // thread. |
37 class SSLErrorHandler : public content::WebContentsUserData<SSLErrorHandler>, | 39 class SSLErrorHandler : public content::WebContentsUserData<SSLErrorHandler>, |
38 public content::NotificationObserver { | 40 public content::NotificationObserver { |
39 public: | 41 public: |
40 // Type of the delay to display the SSL interstitial. | 42 // Type of the delay to display the SSL interstitial. |
41 enum InterstitialDelayType { | 43 enum InterstitialDelayType { |
42 NORMAL, // Default interstitial timer delay used in production. | 44 NORMAL, // Default interstitial timer delay used in production. |
43 NONE, // No interstitial timer delay (i.e. zero), used in tests. | 45 NONE, // No interstitial timer delay (i.e. zero), used in tests. |
44 LONG // Very long interstitial timer delay (ie. an hour), used in tests. | 46 LONG // Very long interstitial timer delay (ie. an hour), used in tests. |
45 }; | 47 }; |
46 | 48 |
47 static void HandleSSLError(content::WebContents* web_contents, | 49 static void HandleSSLError(content::WebContents* web_contents, |
48 int cert_error, | 50 int cert_error, |
49 const net::SSLInfo& ssl_info, | 51 const net::SSLInfo& ssl_info, |
50 const GURL& request_url, | 52 const GURL& request_url, |
51 int options_mask, | 53 int options_mask, |
| 54 SafeBrowsingUIManager* safe_browsing_ui_manager, |
52 const base::Callback<void(bool)>& callback); | 55 const base::Callback<void(bool)>& callback); |
53 | 56 |
54 static void SetInterstitialDelayTypeForTest(InterstitialDelayType delay); | 57 static void SetInterstitialDelayTypeForTest(InterstitialDelayType delay); |
55 | 58 |
56 typedef base::Callback<void(content::WebContents*)> TimerStartedCallback; | 59 typedef base::Callback<void(content::WebContents*)> TimerStartedCallback; |
57 static void SetInterstitialTimerStartedCallbackForTest( | 60 static void SetInterstitialTimerStartedCallbackForTest( |
58 TimerStartedCallback* callback); | 61 TimerStartedCallback* callback); |
59 | 62 |
60 protected: | 63 protected: |
61 SSLErrorHandler(content::WebContents* web_contents, | 64 SSLErrorHandler(content::WebContents* web_contents, |
62 int cert_error, | 65 int cert_error, |
63 const net::SSLInfo& ssl_info, | 66 const net::SSLInfo& ssl_info, |
64 const GURL& request_url, | 67 const GURL& request_url, |
65 int options_mask, | 68 int options_mask, |
| 69 SafeBrowsingUIManager* safe_browsing_ui_manager, |
66 const base::Callback<void(bool)>& callback); | 70 const base::Callback<void(bool)>& callback); |
67 | 71 |
68 ~SSLErrorHandler() override; | 72 ~SSLErrorHandler() override; |
69 | 73 |
70 // Called when an SSL cert error is encountered. Triggers a captive portal | 74 // 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" | 75 // check and fires a one shot timer to wait for a "captive portal detected" |
72 // result to arrive. | 76 // result to arrive. |
73 void StartHandlingError(); | 77 void StartHandlingError(); |
74 const base::OneShotTimer<SSLErrorHandler>& get_timer() const { | 78 const base::OneShotTimer<SSLErrorHandler>& get_timer() const { |
75 return timer_; | 79 return timer_; |
(...skipping 18 matching lines...) Expand all Loading... |
94 content::WebContents* web_contents_; | 98 content::WebContents* web_contents_; |
95 const int cert_error_; | 99 const int cert_error_; |
96 const net::SSLInfo ssl_info_; | 100 const net::SSLInfo ssl_info_; |
97 const GURL request_url_; | 101 const GURL request_url_; |
98 const int options_mask_; | 102 const int options_mask_; |
99 const base::Callback<void(bool)> callback_; | 103 const base::Callback<void(bool)> callback_; |
100 | 104 |
101 content::NotificationRegistrar registrar_; | 105 content::NotificationRegistrar registrar_; |
102 base::OneShotTimer<SSLErrorHandler> timer_; | 106 base::OneShotTimer<SSLErrorHandler> timer_; |
103 | 107 |
| 108 SafeBrowsingUIManager* safe_browsing_ui_manager_; |
| 109 |
104 DISALLOW_COPY_AND_ASSIGN(SSLErrorHandler); | 110 DISALLOW_COPY_AND_ASSIGN(SSLErrorHandler); |
105 }; | 111 }; |
106 | 112 |
107 #endif // CHROME_BROWSER_SSL_SSL_ERROR_HANDLER_H_ | 113 #endif // CHROME_BROWSER_SSL_SSL_ERROR_HANDLER_H_ |
OLD | NEW |