Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / browser / ssl / ssl_error_handler.h
blob49f0c35e7cce28dec9d9ef5058ee572f06282ab0
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.
5 #ifndef CHROME_BROWSER_SSL_SSL_ERROR_HANDLER_H_
6 #define CHROME_BROWSER_SSL_SSL_ERROR_HANDLER_H_
8 #include <string>
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 "chrome/browser/ssl/ssl_cert_reporter.h"
15 #include "content/public/browser/notification_observer.h"
16 #include "content/public/browser/notification_registrar.h"
17 #include "content/public/browser/web_contents_observer.h"
18 #include "content/public/browser/web_contents_user_data.h"
19 #include "net/ssl/ssl_info.h"
20 #include "url/gurl.h"
22 namespace content {
23 class RenderViewHost;
24 class WebContents;
27 // This class is responsible for deciding whether to show an SSL warning or a
28 // captive portal error page. It makes this decision by delaying the display of
29 // SSL interstitial for a few seconds (2 by default), and waiting for a captive
30 // portal result to arrive during this window. If a captive portal detected
31 // result arrives in this window, a captive portal error page is shown.
32 // Otherwise, an SSL interstitial is shown.
34 // An SSLErrorHandler is associated with a particular WebContents, and is
35 // deleted if the WebContents is destroyed, or an interstitial is displayed.
36 // It should only be used on the UI thread because its implementation uses
37 // captive_portal::CaptivePortalService which can only be accessed on the UI
38 // thread.
39 class SSLErrorHandler : public content::WebContentsUserData<SSLErrorHandler>,
40 public content::WebContentsObserver,
41 public content::NotificationObserver {
42 public:
43 // Type of the delay to display the SSL interstitial.
44 enum InterstitialDelayType {
45 NORMAL, // Default interstitial timer delay used in production.
46 NONE, // No interstitial timer delay (i.e. zero), used in tests.
47 LONG // Very long interstitial timer delay (ie. an hour), used in tests.
50 static void HandleSSLError(content::WebContents* web_contents,
51 int cert_error,
52 const net::SSLInfo& ssl_info,
53 const GURL& request_url,
54 int options_mask,
55 scoped_ptr<SSLCertReporter> ssl_cert_reporter,
56 const base::Callback<void(bool)>& callback);
58 static void SetInterstitialDelayTypeForTest(InterstitialDelayType delay);
60 typedef base::Callback<void(content::WebContents*)> TimerStartedCallback;
61 static void SetInterstitialTimerStartedCallbackForTest(
62 TimerStartedCallback* callback);
64 protected:
65 SSLErrorHandler(content::WebContents* web_contents,
66 int cert_error,
67 const net::SSLInfo& ssl_info,
68 const GURL& request_url,
69 int options_mask,
70 scoped_ptr<SSLCertReporter> ssl_cert_reporter,
71 const base::Callback<void(bool)>& callback);
73 ~SSLErrorHandler() override;
75 // Called when an SSL cert error is encountered. Triggers a captive portal
76 // check and fires a one shot timer to wait for a "captive portal detected"
77 // result to arrive.
78 void StartHandlingError();
79 const base::OneShotTimer<SSLErrorHandler>& get_timer() const {
80 return timer_;
83 private:
84 // Callback for the one-shot timer. When the timer expires, an SSL error is
85 // immediately displayed.
86 void OnTimerExpired();
88 // These are virtual for tests:
89 virtual void CheckForCaptivePortal();
90 virtual void ShowCaptivePortalInterstitial(const GURL& landing_url);
91 virtual void ShowSSLInterstitial();
93 // content::NotificationObserver:
94 void Observe(
95 int type,
96 const content::NotificationSource& source,
97 const content::NotificationDetails& details) override;
99 // content::WebContentsObserver:
100 void DidStartNavigationToPendingEntry(
101 const GURL& url,
102 content::NavigationController::ReloadType reload_type) override;
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 base::Callback<void(bool)> callback_;
111 content::NotificationRegistrar registrar_;
112 base::OneShotTimer<SSLErrorHandler> timer_;
114 scoped_ptr<SSLCertReporter> ssl_cert_reporter_;
116 DISALLOW_COPY_AND_ASSIGN(SSLErrorHandler);
119 #endif // CHROME_BROWSER_SSL_SSL_ERROR_HANDLER_H_