Make sure the win_chromium_gn_x64_dbg bot is using symbol_level=1
[chromium-blink-merge.git] / chrome / browser / ssl / ssl_error_handler.h
blob48bc6746d1c6e14f3e15c6945468a09760ee21b3
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/profiles/profile.h"
15 #include "chrome/browser/ssl/common_name_mismatch_handler.h"
16 #include "chrome/browser/ssl/ssl_cert_reporter.h"
17 #include "content/public/browser/notification_observer.h"
18 #include "content/public/browser/notification_registrar.h"
19 #include "content/public/browser/web_contents_observer.h"
20 #include "content/public/browser/web_contents_user_data.h"
21 #include "net/ssl/ssl_info.h"
22 #include "url/gurl.h"
24 class Profile;
25 class CommonNameMismatchHandler;
27 namespace content {
28 class RenderViewHost;
29 class WebContents;
32 // Decides between showing an SSL warning, showing a captive portal interstitial
33 // or redirecting to a name-mismatch suggested URL. This is done by delaying the
34 // display of the interstitial for a few seconds (2 by default), and waiting for
35 // name-mismatch suggested URL or a captive portal result to arrive during this
36 // window. If there is a name mismatch error and a corresponding suggested URL
37 // available result arrives in this window, the user is redirected to the
38 // suggested URL. Failing that, if a captive portal detected result arrives in
39 // the same time window, a captive portal error page is shown. Otherwise, an
40 // SSL interstitial is shown.
42 // This class should only be used on the UI thread because its implementation
43 // uses captive_portal::CaptivePortalService which can only be accessed on the
44 // UI thread.
45 class SSLErrorHandler : public content::WebContentsUserData<SSLErrorHandler>,
46 public content::WebContentsObserver,
47 public content::NotificationObserver {
48 public:
49 typedef base::Callback<void(content::WebContents*)> TimerStartedCallback;
51 // Entry point for the class. The parameters are the same as SSLBlockingPage
52 // constructor.
53 static void HandleSSLError(content::WebContents* web_contents,
54 int cert_error,
55 const net::SSLInfo& ssl_info,
56 const GURL& request_url,
57 int options_mask,
58 scoped_ptr<SSLCertReporter> ssl_cert_reporter,
59 const base::Callback<void(bool)>& callback);
61 static void SetInterstitialDelayForTest(base::TimeDelta delay);
63 // The callback pointer must remain valid for the duration of error handling.
64 static void SetInterstitialTimerStartedCallbackForTest(
65 TimerStartedCallback* callback);
67 protected:
68 // The parameters are the same as SSLBlockingPage's constructor.
69 SSLErrorHandler(content::WebContents* web_contents,
70 int cert_error,
71 const net::SSLInfo& ssl_info,
72 const GURL& request_url,
73 int options_mask,
74 scoped_ptr<SSLCertReporter> ssl_cert_reporter,
75 const base::Callback<void(bool)>& callback);
77 ~SSLErrorHandler() override;
79 // Called when an SSL cert error is encountered. Triggers a captive portal
80 // check and fires a one shot timer to wait for a "captive portal detected"
81 // result to arrive.
82 void StartHandlingError();
83 const base::OneShotTimer<SSLErrorHandler>& get_timer() const {
84 return timer_;
87 // These are virtual for tests:
88 virtual void CheckForCaptivePortal();
89 virtual bool GetSuggestedUrl(const std::vector<std::string>& dns_names,
90 GURL* suggested_url) const;
91 virtual void CheckSuggestedUrl(const GURL& suggested_url);
92 virtual void NavigateToSuggestedURL(const GURL& suggested_url);
93 virtual bool IsErrorOverridable() const;
94 virtual void ShowCaptivePortalInterstitial(const GURL& landing_url);
95 virtual void ShowSSLInterstitial();
97 // Gets the result of whether the suggested URL is valid. Displays
98 // common name mismatch interstitial or ssl interstitial accordingly.
99 void CommonNameMismatchHandlerCallback(
100 const CommonNameMismatchHandler::SuggestedUrlCheckResult& result,
101 const GURL& suggested_url);
103 private:
104 // content::NotificationObserver:
105 void Observe(
106 int type,
107 const content::NotificationSource& source,
108 const content::NotificationDetails& details) override;
110 // content::WebContentsObserver:
111 void DidStartNavigationToPendingEntry(
112 const GURL& url,
113 content::NavigationController::ReloadType reload_type) override;
115 // content::WebContentsObserver:
116 void NavigationStopped() override;
118 // Deletes the SSLErrorHandler. This method is called when the page
119 // load stops or when there is a new navigation.
120 void DeleteSSLErrorHandler();
122 content::WebContents* web_contents_;
123 const int cert_error_;
124 const net::SSLInfo ssl_info_;
125 const GURL request_url_;
126 const int options_mask_;
127 base::Callback<void(bool)> callback_;
128 Profile* const profile_;
130 content::NotificationRegistrar registrar_;
131 base::OneShotTimer<SSLErrorHandler> timer_;
133 scoped_ptr<CommonNameMismatchHandler> common_name_mismatch_handler_;
135 scoped_ptr<SSLCertReporter> ssl_cert_reporter_;
137 DISALLOW_COPY_AND_ASSIGN(SSLErrorHandler);
140 #endif // CHROME_BROWSER_SSL_SSL_ERROR_HANDLER_H_