Give names to all utility processes.
[chromium-blink-merge.git] / chrome / browser / ssl / ssl_error_handler.h
blobc069b47a55627c86cd31989a81b75e77b4c5de4d
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 class SafeBrowsingUIManager;
28 // This class is responsible for deciding whether to show an SSL warning or a
29 // captive portal error page. It makes this decision by delaying the display of
30 // SSL interstitial for a few seconds (2 by default), and waiting for a captive
31 // portal result to arrive during this window. If a captive portal detected
32 // result arrives in this window, a captive portal error page is shown.
33 // Otherwise, an SSL interstitial is shown.
35 // An SSLErrorHandler is associated with a particular WebContents, and is
36 // deleted if the WebContents is destroyed, or an interstitial is displayed.
37 // It should only be used on the UI thread because its implementation uses
38 // captive_portal::CaptivePortalService which can only be accessed on the UI
39 // thread.
40 class SSLErrorHandler : public content::WebContentsUserData<SSLErrorHandler>,
41 public content::WebContentsObserver,
42 public content::NotificationObserver {
43 public:
44 // Type of the delay to display the SSL interstitial.
45 enum InterstitialDelayType {
46 NORMAL, // Default interstitial timer delay used in production.
47 NONE, // No interstitial timer delay (i.e. zero), used in tests.
48 LONG // Very long interstitial timer delay (ie. an hour), used in tests.
51 static void HandleSSLError(content::WebContents* web_contents,
52 int cert_error,
53 const net::SSLInfo& ssl_info,
54 const GURL& request_url,
55 int options_mask,
56 SafeBrowsingUIManager* safe_browsing_ui_manager,
57 const base::Callback<void(bool)>& callback);
59 static void SetInterstitialDelayTypeForTest(InterstitialDelayType delay);
61 typedef base::Callback<void(content::WebContents*)> TimerStartedCallback;
62 static void SetInterstitialTimerStartedCallbackForTest(
63 TimerStartedCallback* callback);
65 protected:
66 SSLErrorHandler(content::WebContents* web_contents,
67 int cert_error,
68 const net::SSLInfo& ssl_info,
69 const GURL& request_url,
70 int options_mask,
71 SafeBrowsingUIManager* safe_browsing_ui_manager,
72 const base::Callback<void(bool)>& callback);
74 ~SSLErrorHandler() override;
76 // Called when an SSL cert error is encountered. Triggers a captive portal
77 // check and fires a one shot timer to wait for a "captive portal detected"
78 // result to arrive.
79 void StartHandlingError();
80 const base::OneShotTimer<SSLErrorHandler>& get_timer() const {
81 return timer_;
84 private:
85 // Callback for the one-shot timer. When the timer expires, an SSL error is
86 // immediately displayed.
87 void OnTimerExpired();
89 // These are virtual for tests:
90 virtual void CheckForCaptivePortal();
91 virtual void ShowCaptivePortalInterstitial(const GURL& landing_url);
92 virtual void ShowSSLInterstitial();
94 // content::NotificationObserver:
95 void Observe(
96 int type,
97 const content::NotificationSource& source,
98 const content::NotificationDetails& details) override;
100 // content::WebContentsObserver:
101 void DidStartNavigationToPendingEntry(
102 const GURL& url,
103 content::NavigationController::ReloadType reload_type) override;
105 content::WebContents* web_contents_;
106 const int cert_error_;
107 const net::SSLInfo ssl_info_;
108 const GURL request_url_;
109 const int options_mask_;
110 base::Callback<void(bool)> callback_;
112 content::NotificationRegistrar registrar_;
113 base::OneShotTimer<SSLErrorHandler> timer_;
115 SafeBrowsingUIManager* safe_browsing_ui_manager_;
117 DISALLOW_COPY_AND_ASSIGN(SSLErrorHandler);
120 #endif // CHROME_BROWSER_SSL_SSL_ERROR_HANDLER_H_