Avi Drissman | 4e1b7bc3 | 2022-09-15 14:03:50 | [diff] [blame] | 1 | // Copyright 2012 The Chromium Authors |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4 | |
[email protected] | 74b962a | 2011-06-03 21:22:54 | [diff] [blame] | 5 | #ifndef CONTENT_BROWSER_SSL_SSL_MANAGER_H_ |
| 6 | #define CONTENT_BROWSER_SSL_SSL_MANAGER_H_ |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 7 | |
dcheng | 5971627 | 2016-04-09 05:19:08 | [diff] [blame] | 8 | #include <memory> |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 9 | |
Keishi Hattori | 0e45c02 | 2021-11-27 09:25:52 | [diff] [blame] | 10 | #include "base/memory/raw_ptr.h" |
[email protected] | 877182bb | 2012-05-17 17:23:08 | [diff] [blame] | 11 | #include "base/memory/weak_ptr.h" |
[email protected] | 043cc11 | 2012-03-13 02:24:34 | [diff] [blame] | 12 | #include "content/browser/ssl/ssl_error_handler.h" |
[email protected] | 043cc11 | 2012-03-13 02:24:34 | [diff] [blame] | 13 | #include "content/public/browser/global_request_id.h" |
estark | c227350 | 2016-10-12 22:03:02 | [diff] [blame] | 14 | #include "content/public/browser/ssl_status.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 15 | #include "net/base/net_errors.h" |
[email protected] | 707e1c4 | 2013-07-09 21:18:58 | [diff] [blame] | 16 | #include "net/cert/cert_status_flags.h" |
| 17 | #include "url/gurl.h" |
Yoshisato Yanagisawa | 66845bf | 2022-05-12 04:04:02 | [diff] [blame] | 18 | #include "url/scheme_host_port.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 19 | |
[email protected] | 89f23a3 | 2012-10-24 22:31:24 | [diff] [blame] | 20 | namespace net { |
| 21 | class SSLInfo; |
| 22 | } |
[email protected] | edfe7fab | 2010-11-28 13:11:52 | [diff] [blame] | 23 | |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 24 | namespace content { |
[email protected] | e67ebf3 | 2013-02-13 11:07:19 | [diff] [blame] | 25 | class BrowserContext; |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 26 | class NavigationEntryImpl; |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 27 | class NavigationControllerImpl; |
Yeunjoo Choi | 2ffd21cc | 2022-04-08 05:26:33 | [diff] [blame] | 28 | class NavigationOrDocumentHandle; |
estark | f83ac12 | 2016-10-05 19:06:06 | [diff] [blame] | 29 | class SSLHostStateDelegate; |
[email protected] | b0f724c | 2013-09-05 04:21:13 | [diff] [blame] | 30 | struct LoadCommittedDetails; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 31 | |
estark | f83ac12 | 2016-10-05 19:06:06 | [diff] [blame] | 32 | // The SSLManager controls the SSL UI elements in a WebContents. It |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 33 | // listens for various events that influence when these elements should or |
| 34 | // should not be displayed and adjusts them accordingly. |
| 35 | // |
| 36 | // There is one SSLManager per tab. |
| 37 | // The security state (secure/insecure) is stored in the navigation entry. |
| 38 | // Along with it are stored any SSL error code and the associated cert. |
Lei Zhang | ed9be3a | 2021-11-17 22:01:18 | [diff] [blame] | 39 | class SSLManager { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 40 | public: |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 41 | // Entry point for SSLCertificateErrors. This function begins the process |
| 42 | // of resolving a certificate error during an SSL connection. SSLManager |
[email protected] | 043cc11 | 2012-03-13 02:24:34 | [diff] [blame] | 43 | // will adjust the security UI and either call |CancelSSLRequest| or |
Yeunjoo Choi | 9d00859 | 2022-04-29 03:31:53 | [diff] [blame] | 44 | // |ContinueSSLRequest| of |delegate|. |is_primary_main_frame_request| is true |
| 45 | // only when the request is for a navigation in the primary main frame. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 46 | // |
John Abd-El-Malek | 576c613 | 2017-11-04 00:33:58 | [diff] [blame] | 47 | // This can be called on the UI or IO thread. It will call |delegate| on the |
| 48 | // same thread. |
[email protected] | 877182bb | 2012-05-17 17:23:08 | [diff] [blame] | 49 | static void OnSSLCertificateError( |
[email protected] | 5385c44 | 2012-05-31 11:01:32 | [diff] [blame] | 50 | const base::WeakPtr<SSLErrorHandler::Delegate>& delegate, |
Yeunjoo Choi | 9d00859 | 2022-04-29 03:31:53 | [diff] [blame] | 51 | bool is_primary_main_frame_request, |
[email protected] | 877182bb | 2012-05-17 17:23:08 | [diff] [blame] | 52 | const GURL& url, |
Yeunjoo Choi | 2ffd21cc | 2022-04-08 05:26:33 | [diff] [blame] | 53 | NavigationOrDocumentHandle* navigation_or_document, |
Emily Stark | d9df3d3 | 2019-04-29 17:54:57 | [diff] [blame] | 54 | int net_error, |
clamy | 0d32d6d | 2015-11-24 11:16:26 | [diff] [blame] | 55 | const net::SSLInfo& ssl_info, |
| 56 | bool fatal); |
| 57 | |
[email protected] | f17a0ee | 2010-05-17 17:38:47 | [diff] [blame] | 58 | // Construct an SSLManager for the specified tab. |
[email protected] | 89f23a3 | 2012-10-24 22:31:24 | [diff] [blame] | 59 | explicit SSLManager(NavigationControllerImpl* controller); |
Peter Boström | 828b902 | 2021-09-21 02:28:43 | [diff] [blame] | 60 | |
| 61 | SSLManager(const SSLManager&) = delete; |
| 62 | SSLManager& operator=(const SSLManager&) = delete; |
| 63 | |
[email protected] | 3690ebe0 | 2011-05-25 09:08:19 | [diff] [blame] | 64 | virtual ~SSLManager(); |
[email protected] | f17a0ee | 2010-05-17 17:38:47 | [diff] [blame] | 65 | |
[email protected] | f17a0ee | 2010-05-17 17:38:47 | [diff] [blame] | 66 | // The navigation controller associated with this SSLManager. The |
| 67 | // NavigationController is guaranteed to outlive the SSLManager. |
[email protected] | 89f23a3 | 2012-10-24 22:31:24 | [diff] [blame] | 68 | NavigationControllerImpl* controller() { return controller_; } |
[email protected] | f17a0ee | 2010-05-17 17:38:47 | [diff] [blame] | 69 | |
[email protected] | b0f724c | 2013-09-05 04:21:13 | [diff] [blame] | 70 | void DidCommitProvisionalLoad(const LoadCommittedDetails& details); |
Aman Verma | e9fc840 | 2022-11-16 20:16:33 | [diff] [blame] | 71 | |
Victor Hugo Vianna Silva | c230b46 | 2024-12-11 13:31:08 | [diff] [blame] | 72 | void DidStartResourceResponse(const url::SchemeHostPort& final_response_url, |
Yoshisato Yanagisawa | 66845bf | 2022-05-12 04:04:02 | [diff] [blame] | 73 | bool has_certificate_errors); |
[email protected] | f17a0ee | 2010-05-17 17:38:47 | [diff] [blame] | 74 | |
estark | c227350 | 2016-10-12 22:03:02 | [diff] [blame] | 75 | // The following methods are called when a page includes insecure |
| 76 | // content. These methods update the SSLStatus on the NavigationEntry |
| 77 | // appropriately. If the result could change the visible SSL state, |
| 78 | // they notify the WebContents of the change via |
dalecurtis | 6c58ed0 | 2016-10-28 23:02:37 | [diff] [blame] | 79 | // DidChangeVisibleSecurityState(); |
Carlos IL | 86684ef0 | 2021-03-11 21:27:40 | [diff] [blame] | 80 | // These methods are not called for resource preloads. |
estark | c227350 | 2016-10-12 22:03:02 | [diff] [blame] | 81 | void DidDisplayMixedContent(); |
elawrence | b2ac2a23 | 2017-03-27 21:46:25 | [diff] [blame] | 82 | void DidContainInsecureFormAction(); |
estark | c227350 | 2016-10-12 22:03:02 | [diff] [blame] | 83 | void DidDisplayContentWithCertErrors(); |
estark | c227350 | 2016-10-12 22:03:02 | [diff] [blame] | 84 | void DidRunMixedContent(const GURL& security_origin); |
estark | cd2e30c | 2016-08-12 06:51:15 | [diff] [blame] | 85 | void DidRunContentWithCertErrors(const GURL& security_origin); |
| 86 | |
estark | f83ac12 | 2016-10-05 19:06:06 | [diff] [blame] | 87 | // An error occurred with the certificate in an SSL connection. |
| 88 | void OnCertError(std::unique_ptr<SSLErrorHandler> handler); |
| 89 | |
Aman Verma | a4b33cf | 2023-06-13 19:32:33 | [diff] [blame] | 90 | // Returns true if any HTTPS-related warning exceptions has been allowed by |
| 91 | // the user for any host. |
| 92 | bool HasAllowExceptionForAnyHost(); |
| 93 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 94 | private: |
estark | f83ac12 | 2016-10-05 19:06:06 | [diff] [blame] | 95 | // Helper method for handling certificate errors. |
David Benjamin | 06f0ef5 | 2019-08-01 05:40:56 | [diff] [blame] | 96 | void OnCertErrorInternal(std::unique_ptr<SSLErrorHandler> handler); |
estark | f83ac12 | 2016-10-05 19:06:06 | [diff] [blame] | 97 | |
Emily Stark | 9f784d274 | 2017-08-02 21:25:54 | [diff] [blame] | 98 | // Updates the NavigationEntry's |content_status| flags according to state in |
Robert Lin | 540dbd1 | 2022-04-28 22:07:24 | [diff] [blame] | 99 | // |ssl_host_state_delegate|, and calls NotifyDidChangeVisibleSSLState |
| 100 | // according to |notify_changes|. |add_content_status_flags| and |
Emily Stark | 9f784d274 | 2017-08-02 21:25:54 | [diff] [blame] | 101 | // |remove_content_status_flags| are bitmasks of SSLStatus::ContentStatusFlags |
| 102 | // that will be added or removed from the |content_status| field. (Pass 0 to |
| 103 | // add/remove no content status flags.) |remove_content_status_flags| are |
Eric Lawrence | 6789f839 | 2017-08-08 12:31:14 | [diff] [blame] | 104 | // removed before |add_content_status_flags| are added. If the final set of |
| 105 | // flags changes, this method will notify the WebContents and return true. |
| 106 | bool UpdateEntry(NavigationEntryImpl* entry, |
estark | fae6b587 | 2016-11-04 05:20:31 | [diff] [blame] | 107 | int add_content_status_flags, |
Robert Lin | 540dbd1 | 2022-04-28 22:07:24 | [diff] [blame] | 108 | int remove_content_status_flags, |
| 109 | bool notify_changes); |
estark | c227350 | 2016-10-12 22:03:02 | [diff] [blame] | 110 | |
| 111 | // Helper function for UpdateEntry(). |
estark | fae6b587 | 2016-11-04 05:20:31 | [diff] [blame] | 112 | void UpdateLastCommittedEntry(int add_content_status_flags, |
| 113 | int remove_content_status_flags); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 114 | |
estark | 294fbd9 | 2015-07-31 18:36:24 | [diff] [blame] | 115 | // Notifies the WebContents that the SSL state changed. |
| 116 | void NotifyDidChangeVisibleSSLState(); |
| 117 | |
estark | c227350 | 2016-10-12 22:03:02 | [diff] [blame] | 118 | // Updates the last committed entries of all |context|'s |
| 119 | // SSLManagers. Notifies each WebContents of visible SSL state changes |
| 120 | // if necessary. |
| 121 | static void NotifySSLInternalStateChanged(BrowserContext* context); |
| 122 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 123 | // The NavigationController that owns this SSLManager. We are responsible |
| 124 | // for the security UI of this tab. |
Keishi Hattori | 0e45c02 | 2021-11-27 09:25:52 | [diff] [blame] | 125 | raw_ptr<NavigationControllerImpl> controller_; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 126 | |
estark | f83ac12 | 2016-10-05 19:06:06 | [diff] [blame] | 127 | // Delegate that manages SSL state specific to each host. |
Keishi Hattori | 0e45c02 | 2021-11-27 09:25:52 | [diff] [blame] | 128 | raw_ptr<SSLHostStateDelegate> ssl_host_state_delegate_; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 129 | }; |
| 130 | |
[email protected] | 89f23a3 | 2012-10-24 22:31:24 | [diff] [blame] | 131 | } // namespace content |
| 132 | |
[email protected] | 74b962a | 2011-06-03 21:22:54 | [diff] [blame] | 133 | #endif // CONTENT_BROWSER_SSL_SSL_MANAGER_H_ |