Fire an error if a pref used in the UI is missing once all prefs are fetched.
[chromium-blink-merge.git] / chrome / browser / ssl / ssl_error_handler.h
blob4679f4ac1b3cddfa76460d7a767a9bfd26a40a8f
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 "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 "content/public/browser/web_contents_user_data.h"
18 #include "net/ssl/ssl_info.h"
19 #include "url/gurl.h"
21 namespace content {
22 class RenderViewHost;
23 class WebContents;
26 // This class is responsible for deciding whether to show an SSL warning or a
27 // captive portal error page. It makes this decision by delaying the display of
28 // SSL interstitial for a few seconds (2 by default), and waiting for a captive
29 // portal result to arrive during this window. If a captive portal detected
30 // result arrives in this window, a captive portal error page is shown.
31 // Otherwise, an SSL interstitial is shown.
33 // An SSLErrorHandler is associated with a particular WebContents, and is
34 // deleted if the WebContents is destroyed, or an interstitial is displayed.
35 // It should only be used on the UI thread because its implementation uses
36 // captive_portal::CaptivePortalService which can only be accessed on the UI
37 // thread.
38 class SSLErrorHandler : public content::WebContentsUserData<SSLErrorHandler>,
39 public content::WebContentsObserver,
40 public content::NotificationObserver {
41 public:
42 // Type of the delay to display the SSL interstitial.
43 enum InterstitialDelayType {
44 NORMAL, // Default interstitial timer delay used in production.
45 NONE, // No interstitial timer delay (i.e. zero), used in tests.
46 LONG // Very long interstitial timer delay (ie. an hour), used in tests.
49 static void HandleSSLError(content::WebContents* web_contents,
50 int cert_error,
51 const net::SSLInfo& ssl_info,
52 const GURL& request_url,
53 int options_mask,
54 const base::Callback<void(bool)>& callback);
56 static void SetInterstitialDelayTypeForTest(InterstitialDelayType delay);
58 typedef base::Callback<void(content::WebContents*)> TimerStartedCallback;
59 static void SetInterstitialTimerStartedCallbackForTest(
60 TimerStartedCallback* callback);
62 protected:
63 SSLErrorHandler(content::WebContents* web_contents,
64 int cert_error,
65 const net::SSLInfo& ssl_info,
66 const GURL& request_url,
67 int options_mask,
68 const base::Callback<void(bool)>& callback);
70 ~SSLErrorHandler() override;
72 // Called when an SSL cert error is encountered. Triggers a captive portal
73 // check and fires a one shot timer to wait for a "captive portal detected"
74 // result to arrive.
75 void StartHandlingError();
76 const base::OneShotTimer<SSLErrorHandler>& get_timer() const {
77 return timer_;
80 private:
81 // Callback for the one-shot timer. When the timer expires, an SSL error is
82 // immediately displayed.
83 void OnTimerExpired();
85 // These are virtual for tests:
86 virtual void CheckForCaptivePortal();
87 virtual void ShowCaptivePortalInterstitial(const GURL& landing_url);
88 virtual void ShowSSLInterstitial();
90 // content::NotificationObserver:
91 void Observe(
92 int type,
93 const content::NotificationSource& source,
94 const content::NotificationDetails& details) override;
96 // content::WebContentsObserver:
97 void DidStartNavigationToPendingEntry(
98 const GURL& url,
99 content::NavigationController::ReloadType reload_type) override;
101 content::WebContents* web_contents_;
102 const int cert_error_;
103 const net::SSLInfo ssl_info_;
104 const GURL request_url_;
105 const int options_mask_;
106 base::Callback<void(bool)> callback_;
108 content::NotificationRegistrar registrar_;
109 base::OneShotTimer<SSLErrorHandler> timer_;
111 DISALLOW_COPY_AND_ASSIGN(SSLErrorHandler);
114 #endif // CHROME_BROWSER_SSL_SSL_ERROR_HANDLER_H_