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

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: mmenke comments 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;
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 protected:
60 // Called when an SSL cert error is encountered. Triggers a captive portal
61 // check and fires a one shot timer to wait for a "captive portal detected"
62 // result to arrive.
63 void StartHandlingError();
64 const base::OneShotTimer<SSLErrorHandler>& get_timer_for_testing() const {
mmenke 2014/12/15 20:46:08 optional nit: not sure the for testing is needed
meacer 2014/12/16 01:23:19 Done.
65 return timer_;
66 }
67
68 private:
69
mmenke 2014/12/15 20:46:08 nit: No blank line after timer.
meacer 2014/12/16 01:23:19 Done.
70 // Time to wait before displaying the SSL interstitial. If a captive portal
71 // arrives before this, the captive portal interstitial is displayed instead.
72 static base::TimeDelta interstitial_display_delay_;
73
74 // Callback for the one-shot timer. When the timer expires, an SSL error is
75 // immediately displayed.
76 void OnTimerExpired();
77
78 // These are virtual for tests:
79 virtual void CheckForCaptivePortal();
80 virtual void ShowCaptivePortalInterstitial();
81 virtual void ShowSSLInterstitial();
82
83 // content::NotificationObserver:
84 void Observe(
85 int type,
86 const content::NotificationSource& source,
87 const content::NotificationDetails& details) override;
88
89 // content::WebContentsObserver:
90 void DidStartNavigationToPendingEntry(
91 const GURL& url,
92 content::NavigationController::ReloadType reload_type) override;
93 void DidStopLoading(
94 content::RenderViewHost* render_view_host) override;
95 void WebContentsDestroyed() override;
96
97 const int cert_error_;
98 const net::SSLInfo ssl_info_;
99 const GURL request_url_;
100 const int options_mask_;
101 const base::Callback<void(bool)> callback_;
102
103 content::NotificationRegistrar registrar_;
104 base::OneShotTimer<SSLErrorHandler> timer_;
105
106 DISALLOW_COPY_AND_ASSIGN(SSLErrorHandler);
107 };
108
109 #endif // CHROME_BROWSER_SSL_SSL_ERROR_HANDLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698