blob: 636326e3be9b9f6efc2f434ea3fcee9d6d9c2d1f [file] [log] [blame]
Avi Drissman4e1b7bc32022-09-15 14:03:501// Copyright 2012 The Chromium Authors
[email protected]1d89a82f2009-05-14 05:46:242// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]74b962a2011-06-03 21:22:545#ifndef CONTENT_BROWSER_SSL_SSL_ERROR_HANDLER_H_
6#define CONTENT_BROWSER_SSL_SSL_ERROR_HANDLER_H_
[email protected]1d89a82f2009-05-14 05:46:247
Keishi Hattori0e45c022021-11-27 09:25:528#include "base/memory/raw_ptr.h"
[email protected]877182bb2012-05-17 17:23:089#include "base/memory/weak_ptr.h"
John Abd-El-Malek576c6132017-11-04 00:33:5810#include "content/public/browser/browser_thread.h"
[email protected]e5d549d2011-12-28 01:29:2011#include "content/public/browser/global_request_id.h"
estark01e64442016-08-09 05:18:1212#include "net/ssl/ssl_info.h"
[email protected]707e1c42013-07-09 21:18:5813#include "url/gurl.h"
[email protected]1d89a82f2009-05-14 05:46:2414
[email protected]edfe7fab2010-11-28 13:11:5215namespace net {
[email protected]1d89a82f2009-05-14 05:46:2416class URLRequest;
[email protected]edfe7fab2010-11-28 13:11:5217} // namespace net
[email protected]1d89a82f2009-05-14 05:46:2418
[email protected]89f23a32012-10-24 22:31:2419namespace content {
20
clamy0d32d6d2015-11-24 11:16:2621class WebContents;
[email protected]89f23a32012-10-24 22:31:2422
estarkdc874b52016-08-09 15:43:0523// 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.
28class SSLErrorHandler {
[email protected]1d89a82f2009-05-14 05:46:2429 public:
Lei Zhanged9be3a2021-11-17 22:01:1830 class Delegate {
[email protected]043cc112012-03-13 02:24:3431 public:
32 // Called when SSLErrorHandler decides to cancel the request because of
33 // the SSL error.
davidben21163ec2014-10-01 23:05:2334 virtual void CancelSSLRequest(int error, const net::SSLInfo* ssl_info) = 0;
[email protected]043cc112012-03-13 02:24:3435
36 // Called when SSLErrorHandler decides to continue the request despite the
37 // SSL error.
davidben21163ec2014-10-01 23:05:2338 virtual void ContinueSSLRequest() = 0;
[email protected]512d03f2012-06-26 01:06:0639
40 protected:
41 virtual ~Delegate() {}
[email protected]043cc112012-03-13 02:24:3442 };
43
estarkdc874b52016-08-09 15:43:0544 SSLErrorHandler(WebContents* web_contents,
45 const base::WeakPtr<Delegate>& delegate,
Yeunjoo Choi9d008592022-04-29 03:31:5346 bool is_primary_main_frame_request,
estark01e64442016-08-09 05:18:1247 const GURL& url,
Emily Starkd9df3d32019-04-29 17:54:5748 int net_error,
estark01e64442016-08-09 05:18:1249 const net::SSLInfo& ssl_info,
50 bool fatal);
[email protected]1d89a82f2009-05-14 05:46:2451
Peter Boström9b036532021-10-28 23:37:2852 SSLErrorHandler(const SSLErrorHandler&) = delete;
53 SSLErrorHandler& operator=(const SSLErrorHandler&) = delete;
54
estarkdc874b52016-08-09 15:43:0555 virtual ~SSLErrorHandler();
[email protected]1d89a82f2009-05-14 05:46:2456
estark01e64442016-08-09 05:18:1257 const net::SSLInfo& ssl_info() const { return ssl_info_; }
estarkdc874b52016-08-09 15:43:0558
[email protected]1d89a82f2009-05-14 05:46:2459 const GURL& request_url() const { return request_url_; }
estarkdc874b52016-08-09 15:43:0560
Yeunjoo Choi9d008592022-04-29 03:31:5361 bool is_primary_main_frame_request() const {
62 return is_primary_main_frame_request_;
63 }
[email protected]1d89a82f2009-05-14 05:46:2464
estarkdc874b52016-08-09 15:43:0565 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]6981d9632010-11-30 21:34:0271 // Cancels the associated net::URLRequest.
Lei Zhanged9be3a2021-11-17 22:01:1872 void CancelRequest();
[email protected]1d89a82f2009-05-14 05:46:2473
[email protected]6981d9632010-11-30 21:34:0274 // Continue the net::URLRequest ignoring any previous errors. Note that some
[email protected]1d89a82f2009-05-14 05:46:2475 // errors cannot be ignored, in which case this will result in the request
76 // being canceled.
[email protected]1d89a82f2009-05-14 05:46:2477 void ContinueRequest();
78
[email protected]6981d9632010-11-30 21:34:0279 // Cancels the associated net::URLRequest and mark it as denied. The renderer
[email protected]1d89a82f2009-05-14 05:46:2480 // 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]1d89a82f2009-05-14 05:46:2483 void DenyRequest();
84
estark01e64442016-08-09 05:18:1285 private:
[email protected]877182bb2012-05-17 17:23:0886 base::WeakPtr<Delegate> delegate_;
[email protected]1d89a82f2009-05-14 05:46:2487
estarkdc874b52016-08-09 15:43:0588 // The URL for the request that generated the error.
estark01e64442016-08-09 05:18:1289 const GURL request_url_;
90
Yeunjoo Choi9d008592022-04-29 03:31:5391 // Whether this request is for the primary main frame's html.
92 const bool is_primary_main_frame_request_;
estark01e64442016-08-09 05:18:1293
estarkdc874b52016-08-09 15:43:0594 // The net::SSLInfo associated with the request that generated the error.
estark01e64442016-08-09 05:18:1295 const net::SSLInfo ssl_info_;
96
estarkdc874b52016-08-09 15:43:0597 // A net error code describing the error that occurred.
estark01e64442016-08-09 05:18:1298 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
estarkdc874b52016-08-09 15:43:05103 // The WebContents associated with the request that generated the error.
Keishi Hattori0e45c022021-11-27 09:25:52104 raw_ptr<WebContents> web_contents_;
[email protected]1d89a82f2009-05-14 05:46:24105};
106
[email protected]89f23a32012-10-24 22:31:24107} // namespace content
108
[email protected]74b962a2011-06-03 21:22:54109#endif // CONTENT_BROWSER_SSL_SSL_ERROR_HANDLER_H_