blob: fa6b9d1c2cf30df71cdfb659b97617ea6d32e419 [file] [log] [blame]
Avi Drissman4e1b7bc32022-09-15 14:03:501// Copyright 2012 The Chromium Authors
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]74b962a2011-06-03 21:22:545#ifndef CONTENT_BROWSER_SSL_SSL_MANAGER_H_
6#define CONTENT_BROWSER_SSL_SSL_MANAGER_H_
initial.commit09911bf2008-07-26 23:55:297
dcheng59716272016-04-09 05:19:088#include <memory>
initial.commit09911bf2008-07-26 23:55:299
Keishi Hattori0e45c022021-11-27 09:25:5210#include "base/memory/raw_ptr.h"
[email protected]877182bb2012-05-17 17:23:0811#include "base/memory/weak_ptr.h"
[email protected]043cc112012-03-13 02:24:3412#include "content/browser/ssl/ssl_error_handler.h"
[email protected]043cc112012-03-13 02:24:3413#include "content/public/browser/global_request_id.h"
estarkc2273502016-10-12 22:03:0214#include "content/public/browser/ssl_status.h"
initial.commit09911bf2008-07-26 23:55:2915#include "net/base/net_errors.h"
[email protected]707e1c42013-07-09 21:18:5816#include "net/cert/cert_status_flags.h"
17#include "url/gurl.h"
Yoshisato Yanagisawa66845bf2022-05-12 04:04:0218#include "url/scheme_host_port.h"
initial.commit09911bf2008-07-26 23:55:2919
[email protected]89f23a32012-10-24 22:31:2420namespace net {
21class SSLInfo;
22}
[email protected]edfe7fab2010-11-28 13:11:5223
[email protected]10f417c52011-12-28 21:04:2324namespace content {
[email protected]e67ebf32013-02-13 11:07:1925class BrowserContext;
[email protected]10f417c52011-12-28 21:04:2326class NavigationEntryImpl;
[email protected]8ff00d72012-10-23 19:12:2127class NavigationControllerImpl;
Yeunjoo Choi2ffd21cc2022-04-08 05:26:3328class NavigationOrDocumentHandle;
estarkf83ac122016-10-05 19:06:0629class SSLHostStateDelegate;
[email protected]b0f724c2013-09-05 04:21:1330struct LoadCommittedDetails;
initial.commit09911bf2008-07-26 23:55:2931
estarkf83ac122016-10-05 19:06:0632// The SSLManager controls the SSL UI elements in a WebContents. It
initial.commit09911bf2008-07-26 23:55:2933// 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 Zhanged9be3a2021-11-17 22:01:1839class SSLManager {
initial.commit09911bf2008-07-26 23:55:2940 public:
initial.commit09911bf2008-07-26 23:55:2941 // Entry point for SSLCertificateErrors. This function begins the process
42 // of resolving a certificate error during an SSL connection. SSLManager
[email protected]043cc112012-03-13 02:24:3443 // will adjust the security UI and either call |CancelSSLRequest| or
Yeunjoo Choi9d008592022-04-29 03:31:5344 // |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.commit09911bf2008-07-26 23:55:2946 //
John Abd-El-Malek576c6132017-11-04 00:33:5847 // This can be called on the UI or IO thread. It will call |delegate| on the
48 // same thread.
[email protected]877182bb2012-05-17 17:23:0849 static void OnSSLCertificateError(
[email protected]5385c442012-05-31 11:01:3250 const base::WeakPtr<SSLErrorHandler::Delegate>& delegate,
Yeunjoo Choi9d008592022-04-29 03:31:5351 bool is_primary_main_frame_request,
[email protected]877182bb2012-05-17 17:23:0852 const GURL& url,
Yeunjoo Choi2ffd21cc2022-04-08 05:26:3353 NavigationOrDocumentHandle* navigation_or_document,
Emily Starkd9df3d32019-04-29 17:54:5754 int net_error,
clamy0d32d6d2015-11-24 11:16:2655 const net::SSLInfo& ssl_info,
56 bool fatal);
57
[email protected]f17a0ee2010-05-17 17:38:4758 // Construct an SSLManager for the specified tab.
[email protected]89f23a32012-10-24 22:31:2459 explicit SSLManager(NavigationControllerImpl* controller);
Peter Boström828b9022021-09-21 02:28:4360
61 SSLManager(const SSLManager&) = delete;
62 SSLManager& operator=(const SSLManager&) = delete;
63
[email protected]3690ebe02011-05-25 09:08:1964 virtual ~SSLManager();
[email protected]f17a0ee2010-05-17 17:38:4765
[email protected]f17a0ee2010-05-17 17:38:4766 // The navigation controller associated with this SSLManager. The
67 // NavigationController is guaranteed to outlive the SSLManager.
[email protected]89f23a32012-10-24 22:31:2468 NavigationControllerImpl* controller() { return controller_; }
[email protected]f17a0ee2010-05-17 17:38:4769
[email protected]b0f724c2013-09-05 04:21:1370 void DidCommitProvisionalLoad(const LoadCommittedDetails& details);
Aman Vermae9fc8402022-11-16 20:16:3371
Victor Hugo Vianna Silvac230b462024-12-11 13:31:0872 void DidStartResourceResponse(const url::SchemeHostPort& final_response_url,
Yoshisato Yanagisawa66845bf2022-05-12 04:04:0273 bool has_certificate_errors);
[email protected]f17a0ee2010-05-17 17:38:4774
estarkc2273502016-10-12 22:03:0275 // 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
dalecurtis6c58ed02016-10-28 23:02:3779 // DidChangeVisibleSecurityState();
Carlos IL86684ef02021-03-11 21:27:4080 // These methods are not called for resource preloads.
estarkc2273502016-10-12 22:03:0281 void DidDisplayMixedContent();
elawrenceb2ac2a232017-03-27 21:46:2582 void DidContainInsecureFormAction();
estarkc2273502016-10-12 22:03:0283 void DidDisplayContentWithCertErrors();
estarkc2273502016-10-12 22:03:0284 void DidRunMixedContent(const GURL& security_origin);
estarkcd2e30c2016-08-12 06:51:1585 void DidRunContentWithCertErrors(const GURL& security_origin);
86
estarkf83ac122016-10-05 19:06:0687 // An error occurred with the certificate in an SSL connection.
88 void OnCertError(std::unique_ptr<SSLErrorHandler> handler);
89
Aman Vermaa4b33cf2023-06-13 19:32:3390 // Returns true if any HTTPS-related warning exceptions has been allowed by
91 // the user for any host.
92 bool HasAllowExceptionForAnyHost();
93
initial.commit09911bf2008-07-26 23:55:2994 private:
estarkf83ac122016-10-05 19:06:0695 // Helper method for handling certificate errors.
David Benjamin06f0ef52019-08-01 05:40:5696 void OnCertErrorInternal(std::unique_ptr<SSLErrorHandler> handler);
estarkf83ac122016-10-05 19:06:0697
Emily Stark9f784d2742017-08-02 21:25:5498 // Updates the NavigationEntry's |content_status| flags according to state in
Robert Lin540dbd12022-04-28 22:07:2499 // |ssl_host_state_delegate|, and calls NotifyDidChangeVisibleSSLState
100 // according to |notify_changes|. |add_content_status_flags| and
Emily Stark9f784d2742017-08-02 21:25:54101 // |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 Lawrence6789f8392017-08-08 12:31:14104 // 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,
estarkfae6b5872016-11-04 05:20:31107 int add_content_status_flags,
Robert Lin540dbd12022-04-28 22:07:24108 int remove_content_status_flags,
109 bool notify_changes);
estarkc2273502016-10-12 22:03:02110
111 // Helper function for UpdateEntry().
estarkfae6b5872016-11-04 05:20:31112 void UpdateLastCommittedEntry(int add_content_status_flags,
113 int remove_content_status_flags);
initial.commit09911bf2008-07-26 23:55:29114
estark294fbd92015-07-31 18:36:24115 // Notifies the WebContents that the SSL state changed.
116 void NotifyDidChangeVisibleSSLState();
117
estarkc2273502016-10-12 22:03:02118 // 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.commit09911bf2008-07-26 23:55:29123 // The NavigationController that owns this SSLManager. We are responsible
124 // for the security UI of this tab.
Keishi Hattori0e45c022021-11-27 09:25:52125 raw_ptr<NavigationControllerImpl> controller_;
initial.commit09911bf2008-07-26 23:55:29126
estarkf83ac122016-10-05 19:06:06127 // Delegate that manages SSL state specific to each host.
Keishi Hattori0e45c022021-11-27 09:25:52128 raw_ptr<SSLHostStateDelegate> ssl_host_state_delegate_;
initial.commit09911bf2008-07-26 23:55:29129};
130
[email protected]89f23a32012-10-24 22:31:24131} // namespace content
132
[email protected]74b962a2011-06-03 21:22:54133#endif // CONTENT_BROWSER_SSL_SSL_MANAGER_H_