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 void Handle(); | |
47 virtual void OnCaptivePortalResult(); | |
48 virtual void OnTimerExpired(); | |
49 | |
50 protected: | |
51 // Only used in tests. | |
52 bool handled() const { | |
Ryan Sleevi
2014/10/29 23:17:32
was_handled_for_testing then?
Are all of these fo
meacer
2014/11/06 21:21:56
Done.
| |
53 return handled_; | |
54 } | |
55 | |
56 int captive_portal_check_count() const { | |
57 return captive_portal_check_count_; | |
58 } | |
59 | |
60 int ssl_interstitial_show_count() const { | |
61 return ssl_interstitial_show_count_; | |
62 } | |
63 | |
64 int captive_portal_interstitial_show_count() const { | |
65 return captive_portal_interstitial_show_count_; | |
66 } | |
67 | |
68 bool TimerRunning() const { | |
69 return timer_.IsRunning(); | |
70 } | |
71 | |
72 void DontCreateInterstitials() { | |
73 create_interstitials_ = false; | |
74 } | |
75 | |
76 private: | |
77 // content::WebContentsObserver: | |
78 virtual void DidStopLoading( | |
79 content::RenderViewHost* render_view_host) override; | |
80 virtual void WebContentsDestroyed() override; | |
81 | |
82 // content::NotificationObserver: | |
83 virtual void Observe( | |
84 int type, | |
85 const content::NotificationSource& source, | |
86 const content::NotificationDetails& details) override; | |
87 | |
88 bool overridable() const; | |
89 void ShowSSLInterstitial(); | |
90 void ShowCaptivePortalInterstitial(); | |
91 void CheckForCaptivePortal(); | |
92 | |
93 content::WebContents* web_contents_; | |
94 const int cert_error_; | |
95 const net::SSLInfo ssl_info_; | |
96 const GURL request_url_; | |
97 const int options_mask_; | |
98 const base::Callback<void(bool)> callback_; | |
99 bool handled_; | |
100 int captive_portal_check_count_; | |
101 int ssl_interstitial_show_count_; | |
102 int captive_portal_interstitial_show_count_; | |
103 | |
104 // Time to wait before displaying the SSL interstitial. If a captive portal | |
105 // arrives before this, the captive portal interstitial is displayed instead. | |
106 base::TimeDelta ssl_interstitial_display_delay_; | |
107 // If true, interstitials will be created. | |
108 bool create_interstitials_; | |
109 bool timer_expired_; | |
110 content::NotificationRegistrar registrar_; | |
111 base::OneShotTimer<SSLErrorHandler> timer_; | |
112 | |
113 DISALLOW_COPY_AND_ASSIGN(SSLErrorHandler); | |
114 }; | |
115 | |
116 #endif // CHROME_BROWSER_SSL_SSL_ERROR_HANDLER_H_ | |
OLD | NEW |