Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(311)

Side by Side Diff: chrome/browser/ssl/ssl_error_handler.h

Issue 318213002: Add custom interstitial for captive portals. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove notification, add observer for SSLErrorHandler timer. Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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/timer/timer.h"
13 #include "chrome/browser/chrome_notification_types.h"
14 #include "content/public/browser/notification_observer.h"
15 #include "content/public/browser/notification_registrar.h"
16 #include "content/public/browser/web_contents_observer.h"
17 #include "net/ssl/ssl_info.h"
18 #include "url/gurl.h"
19
20 namespace content {
21 class RenderViewHost;
22 class WebContents;
23 }
24
25 // 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
27 // 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
29 // result arrives in this window, a captive portal error page is shown.
30 // Otherwise, an SSL interstitial is shown.
31 //
32 // This class deletes itself when the interstitial page is closed. It should
33 // only be used on the UI thread because its implementation uses
34 // captive_portal::CaptivePortalService which can only be accessed on the UI
35 // thread.
36 class SSLErrorHandler : public content::WebContentsObserver,
37 public content::NotificationObserver {
38 public:
39 SSLErrorHandler(content::WebContents* web_contents,
40 int cert_error,
41 const net::SSLInfo& ssl_info,
42 const GURL& request_url,
43 int options_mask,
44 const base::Callback<void(bool)>& callback);
45 ~SSLErrorHandler() override;
Bernhard Bauer 2014/12/18 18:10:06 Please make this protected. If this class deletes
meacer 2014/12/19 02:42:24 Done.
46
47 static void HandleSSLError(content::WebContents* web_contents,
48 int cert_error,
49 const net::SSLInfo& ssl_info,
50 const GURL& request_url,
51 int options_mask,
52 const base::Callback<void(bool)>& callback);
53
54 static void SetInterstitialDisplayDelayForTest(
55 base::TimeDelta interstitial_display_delay) {
56 interstitial_display_delay_ = interstitial_display_delay;
57 }
58
59 typedef base::Callback<void(content::WebContents*)> TimerFiredCallback;
60 static void SetInterstitialTimerFiredCallbackForTest(
61 TimerFiredCallback* callback) {
62 timer_fired_callback_ = callback;
63 }
mmenke 2014/12/18 15:44:03 Can't the test just use content::WaitForInterstiti
meacer 2014/12/19 02:42:24 This is used in FastErrorWithInterstitialTimer whe
64
65 protected:
66 // Called when an SSL cert error is encountered. Triggers a captive portal
67 // check and fires a one shot timer to wait for a "captive portal detected"
68 // result to arrive.
69 void StartHandlingError();
70 const base::OneShotTimer<SSLErrorHandler>& get_timer() const {
71 return timer_;
72 }
73
74 private:
75 // Time to wait before displaying the SSL interstitial. If a captive portal
76 // arrives before this, the captive portal interstitial is displayed instead.
77 static base::TimeDelta interstitial_display_delay_;
78
79 // Callback to call when the interstitial timer is fired. Used for testing.
80 static TimerFiredCallback* timer_fired_callback_;
81
82 // Callback for the one-shot timer. When the timer expires, an SSL error is
83 // immediately displayed.
84 void OnTimerExpired();
85
86 // These are virtual for tests:
87 virtual void CheckForCaptivePortal();
88 virtual void ShowCaptivePortalInterstitial();
89 virtual void ShowSSLInterstitial();
90
91 // content::NotificationObserver:
92 void Observe(
93 int type,
94 const content::NotificationSource& source,
95 const content::NotificationDetails& details) override;
96
97 // content::WebContentsObserver:
98 void DidStartNavigationToPendingEntry(
99 const GURL& url,
100 content::NavigationController::ReloadType reload_type) override;
101 void DidStopLoading(
102 content::RenderViewHost* render_view_host) override;
103 void WebContentsDestroyed() override;
104
105 const int cert_error_;
106 const net::SSLInfo ssl_info_;
107 const GURL request_url_;
108 const int options_mask_;
109 const base::Callback<void(bool)> callback_;
110
111 content::NotificationRegistrar registrar_;
112 base::OneShotTimer<SSLErrorHandler> timer_;
113
114 DISALLOW_COPY_AND_ASSIGN(SSLErrorHandler);
115 };
116
117 #endif // CHROME_BROWSER_SSL_SSL_ERROR_HANDLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698