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

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: bauerb and mmenke comments - make SSLErrorHandler a WebContentsUserData 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_user_data.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 // An SSLErrorHandler is associated with a particular WebContents, and is
33 // 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
35 // captive_portal::CaptivePortalService which can only be accessed on the UI
36 // thread.
37 class SSLErrorHandler : public content::WebContentsUserData<SSLErrorHandler>,
38 public content::NotificationObserver {
39 public:
40 ~SSLErrorHandler() override;
41
42 static void HandleSSLError(content::WebContents* web_contents,
43 int cert_error,
44 const net::SSLInfo& ssl_info,
45 const GURL& request_url,
46 int options_mask,
47 const base::Callback<void(bool)>& callback);
48
49 static void SetInterstitialDisplayDelayForTest(
50 base::TimeDelta interstitial_display_delay);
51
52 typedef base::Callback<void(content::WebContents*)> TimerFiredCallback;
53 static void SetInterstitialTimerFiredCallbackForTest(
54 TimerFiredCallback* callback);
55
56 protected:
57 SSLErrorHandler(content::WebContents* web_contents,
58 int cert_error,
59 const net::SSLInfo& ssl_info,
60 const GURL& request_url,
61 int options_mask,
62 const base::Callback<void(bool)>& callback);
63
64 // Called when an SSL cert error is encountered. Triggers a captive portal
65 // check and fires a one shot timer to wait for a "captive portal detected"
66 // result to arrive.
67 void StartHandlingError();
68 const base::OneShotTimer<SSLErrorHandler>& get_timer() const {
69 return timer_;
70 }
71
72 private:
73 // Creates an SSLErrorHandler and attaches it to the specified WebContents.
74 // Shouldn't be called if an instance is already attached.
75 static void CreateForWebContents(content::WebContents* web_contents,
Bernhard Bauer 2014/12/19 10:14:25 You could move this to an anonymous namespace in t
meacer 2014/12/19 19:04:24 Inlined.
76 int cert_error,
77 const net::SSLInfo& ssl_info,
78 const GURL& request_url,
79 int options_mask,
80 const base::Callback<void(bool)>& 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 // Time to wait before displaying the SSL interstitial. If a captive portal
98 // arrives before this, the captive portal interstitial is displayed instead.
99 static base::TimeDelta interstitial_display_delay_;
100
101 // Callback to call when the interstitial timer is fired. Used for testing.
102 static TimerFiredCallback* timer_fired_callback_;
103
104 content::WebContents* web_contents_;
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