Avi Drissman | 4e1b7bc3 | 2022-09-15 14:03:50 | [diff] [blame] | 1 | // Copyright 2012 The Chromium Authors |
[email protected] | 1d89a82f | 2009-05-14 05:46:24 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 74b962a | 2011-06-03 21:22:54 | [diff] [blame] | 5 | #ifndef CONTENT_BROWSER_SSL_SSL_ERROR_HANDLER_H_ |
| 6 | #define CONTENT_BROWSER_SSL_SSL_ERROR_HANDLER_H_ |
[email protected] | 1d89a82f | 2009-05-14 05:46:24 | [diff] [blame] | 7 | |
Keishi Hattori | 0e45c02 | 2021-11-27 09:25:52 | [diff] [blame] | 8 | #include "base/memory/raw_ptr.h" |
[email protected] | 877182bb | 2012-05-17 17:23:08 | [diff] [blame] | 9 | #include "base/memory/weak_ptr.h" |
John Abd-El-Malek | 576c613 | 2017-11-04 00:33:58 | [diff] [blame] | 10 | #include "content/public/browser/browser_thread.h" |
[email protected] | e5d549d | 2011-12-28 01:29:20 | [diff] [blame] | 11 | #include "content/public/browser/global_request_id.h" |
estark | 01e6444 | 2016-08-09 05:18:12 | [diff] [blame] | 12 | #include "net/ssl/ssl_info.h" |
[email protected] | 707e1c4 | 2013-07-09 21:18:58 | [diff] [blame] | 13 | #include "url/gurl.h" |
[email protected] | 1d89a82f | 2009-05-14 05:46:24 | [diff] [blame] | 14 | |
[email protected] | edfe7fab | 2010-11-28 13:11:52 | [diff] [blame] | 15 | namespace net { |
[email protected] | 1d89a82f | 2009-05-14 05:46:24 | [diff] [blame] | 16 | class URLRequest; |
[email protected] | edfe7fab | 2010-11-28 13:11:52 | [diff] [blame] | 17 | } // namespace net |
[email protected] | 1d89a82f | 2009-05-14 05:46:24 | [diff] [blame] | 18 | |
[email protected] | 89f23a3 | 2012-10-24 22:31:24 | [diff] [blame] | 19 | namespace content { |
| 20 | |
clamy | 0d32d6d | 2015-11-24 11:16:26 | [diff] [blame] | 21 | class WebContents; |
[email protected] | 89f23a3 | 2012-10-24 22:31:24 | [diff] [blame] | 22 | |
estark | dc874b5 | 2016-08-09 15:43:05 | [diff] [blame] | 23 | // SSLErrorHandler is the UI-thread class for handling SSL certificate |
| 24 | // errors. Users of this class can call CancelRequest(), |
| 25 | // ContinueRequest(), or DenyRequest() when a decision about how to |
| 26 | // handle the error has been made. Users of this class must |
| 27 | // call exactly one of those methods exactly once. |
| 28 | class SSLErrorHandler { |
[email protected] | 1d89a82f | 2009-05-14 05:46:24 | [diff] [blame] | 29 | public: |
Lei Zhang | ed9be3a | 2021-11-17 22:01:18 | [diff] [blame] | 30 | class Delegate { |
[email protected] | 043cc11 | 2012-03-13 02:24:34 | [diff] [blame] | 31 | public: |
| 32 | // Called when SSLErrorHandler decides to cancel the request because of |
| 33 | // the SSL error. |
davidben | 21163ec | 2014-10-01 23:05:23 | [diff] [blame] | 34 | virtual void CancelSSLRequest(int error, const net::SSLInfo* ssl_info) = 0; |
[email protected] | 043cc11 | 2012-03-13 02:24:34 | [diff] [blame] | 35 | |
| 36 | // Called when SSLErrorHandler decides to continue the request despite the |
| 37 | // SSL error. |
davidben | 21163ec | 2014-10-01 23:05:23 | [diff] [blame] | 38 | virtual void ContinueSSLRequest() = 0; |
[email protected] | 512d03f | 2012-06-26 01:06:06 | [diff] [blame] | 39 | |
| 40 | protected: |
| 41 | virtual ~Delegate() {} |
[email protected] | 043cc11 | 2012-03-13 02:24:34 | [diff] [blame] | 42 | }; |
| 43 | |
estark | dc874b5 | 2016-08-09 15:43:05 | [diff] [blame] | 44 | SSLErrorHandler(WebContents* web_contents, |
| 45 | const base::WeakPtr<Delegate>& delegate, |
Yeunjoo Choi | 9d00859 | 2022-04-29 03:31:53 | [diff] [blame] | 46 | bool is_primary_main_frame_request, |
estark | 01e6444 | 2016-08-09 05:18:12 | [diff] [blame] | 47 | const GURL& url, |
Emily Stark | d9df3d3 | 2019-04-29 17:54:57 | [diff] [blame] | 48 | int net_error, |
estark | 01e6444 | 2016-08-09 05:18:12 | [diff] [blame] | 49 | const net::SSLInfo& ssl_info, |
| 50 | bool fatal); |
[email protected] | 1d89a82f | 2009-05-14 05:46:24 | [diff] [blame] | 51 | |
Peter Boström | 9b03653 | 2021-10-28 23:37:28 | [diff] [blame] | 52 | SSLErrorHandler(const SSLErrorHandler&) = delete; |
| 53 | SSLErrorHandler& operator=(const SSLErrorHandler&) = delete; |
| 54 | |
estark | dc874b5 | 2016-08-09 15:43:05 | [diff] [blame] | 55 | virtual ~SSLErrorHandler(); |
[email protected] | 1d89a82f | 2009-05-14 05:46:24 | [diff] [blame] | 56 | |
estark | 01e6444 | 2016-08-09 05:18:12 | [diff] [blame] | 57 | const net::SSLInfo& ssl_info() const { return ssl_info_; } |
estark | dc874b5 | 2016-08-09 15:43:05 | [diff] [blame] | 58 | |
[email protected] | 1d89a82f | 2009-05-14 05:46:24 | [diff] [blame] | 59 | const GURL& request_url() const { return request_url_; } |
estark | dc874b5 | 2016-08-09 15:43:05 | [diff] [blame] | 60 | |
Yeunjoo Choi | 9d00859 | 2022-04-29 03:31:53 | [diff] [blame] | 61 | bool is_primary_main_frame_request() const { |
| 62 | return is_primary_main_frame_request_; |
| 63 | } |
[email protected] | 1d89a82f | 2009-05-14 05:46:24 | [diff] [blame] | 64 | |
estark | dc874b5 | 2016-08-09 15:43:05 | [diff] [blame] | 65 | WebContents* web_contents() const { return web_contents_; } |
| 66 | |
| 67 | int cert_error() const { return cert_error_; } |
| 68 | |
| 69 | bool fatal() const { return fatal_; } |
| 70 | |
[email protected] | 6981d963 | 2010-11-30 21:34:02 | [diff] [blame] | 71 | // Cancels the associated net::URLRequest. |
Lei Zhang | ed9be3a | 2021-11-17 22:01:18 | [diff] [blame] | 72 | void CancelRequest(); |
[email protected] | 1d89a82f | 2009-05-14 05:46:24 | [diff] [blame] | 73 | |
[email protected] | 6981d963 | 2010-11-30 21:34:02 | [diff] [blame] | 74 | // Continue the net::URLRequest ignoring any previous errors. Note that some |
[email protected] | 1d89a82f | 2009-05-14 05:46:24 | [diff] [blame] | 75 | // errors cannot be ignored, in which case this will result in the request |
| 76 | // being canceled. |
[email protected] | 1d89a82f | 2009-05-14 05:46:24 | [diff] [blame] | 77 | void ContinueRequest(); |
| 78 | |
[email protected] | 6981d963 | 2010-11-30 21:34:02 | [diff] [blame] | 79 | // Cancels the associated net::URLRequest and mark it as denied. The renderer |
[email protected] | 1d89a82f | 2009-05-14 05:46:24 | [diff] [blame] | 80 | // processes such request in a special manner, optionally replacing them |
| 81 | // with alternate content (typically frames content is replaced with a |
| 82 | // warning message). |
[email protected] | 1d89a82f | 2009-05-14 05:46:24 | [diff] [blame] | 83 | void DenyRequest(); |
| 84 | |
estark | 01e6444 | 2016-08-09 05:18:12 | [diff] [blame] | 85 | private: |
[email protected] | 877182bb | 2012-05-17 17:23:08 | [diff] [blame] | 86 | base::WeakPtr<Delegate> delegate_; |
[email protected] | 1d89a82f | 2009-05-14 05:46:24 | [diff] [blame] | 87 | |
estark | dc874b5 | 2016-08-09 15:43:05 | [diff] [blame] | 88 | // The URL for the request that generated the error. |
estark | 01e6444 | 2016-08-09 05:18:12 | [diff] [blame] | 89 | const GURL request_url_; |
| 90 | |
Yeunjoo Choi | 9d00859 | 2022-04-29 03:31:53 | [diff] [blame] | 91 | // Whether this request is for the primary main frame's html. |
| 92 | const bool is_primary_main_frame_request_; |
estark | 01e6444 | 2016-08-09 05:18:12 | [diff] [blame] | 93 | |
estark | dc874b5 | 2016-08-09 15:43:05 | [diff] [blame] | 94 | // The net::SSLInfo associated with the request that generated the error. |
estark | 01e6444 | 2016-08-09 05:18:12 | [diff] [blame] | 95 | const net::SSLInfo ssl_info_; |
| 96 | |
estark | dc874b5 | 2016-08-09 15:43:05 | [diff] [blame] | 97 | // A net error code describing the error that occurred. |
estark | 01e6444 | 2016-08-09 05:18:12 | [diff] [blame] | 98 | const int cert_error_; |
| 99 | |
| 100 | // True if the error is from a host requiring certificate errors to be fatal. |
| 101 | const bool fatal_; |
| 102 | |
estark | dc874b5 | 2016-08-09 15:43:05 | [diff] [blame] | 103 | // The WebContents associated with the request that generated the error. |
Keishi Hattori | 0e45c02 | 2021-11-27 09:25:52 | [diff] [blame] | 104 | raw_ptr<WebContents> web_contents_; |
[email protected] | 1d89a82f | 2009-05-14 05:46:24 | [diff] [blame] | 105 | }; |
| 106 | |
[email protected] | 89f23a3 | 2012-10-24 22:31:24 | [diff] [blame] | 107 | } // namespace content |
| 108 | |
[email protected] | 74b962a | 2011-06-03 21:22:54 | [diff] [blame] | 109 | #endif // CONTENT_BROWSER_SSL_SSL_ERROR_HANDLER_H_ |