Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(110)

Side by Side Diff: content/browser/ssl/ssl_error_handler.h

Issue 2213193005: Make SSLErrorHandler UI-thread-only and not-refcounted (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase on top of https://codereview.chromium.org/2222003002/ Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CONTENT_BROWSER_SSL_SSL_ERROR_HANDLER_H_ 5 #ifndef CONTENT_BROWSER_SSL_SSL_ERROR_HANDLER_H_
6 #define CONTENT_BROWSER_SSL_SSL_ERROR_HANDLER_H_ 6 #define CONTENT_BROWSER_SSL_SSL_ERROR_HANDLER_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
12 #include "base/memory/weak_ptr.h" 12 #include "base/memory/weak_ptr.h"
13 #include "content/common/content_export.h" 13 #include "content/common/content_export.h"
14 #include "content/public/browser/global_request_id.h" 14 #include "content/public/browser/global_request_id.h"
15 #include "content/public/common/resource_type.h" 15 #include "content/public/common/resource_type.h"
16 #include "net/ssl/ssl_info.h" 16 #include "net/ssl/ssl_info.h"
17 #include "url/gurl.h" 17 #include "url/gurl.h"
18 18
19 namespace net { 19 namespace net {
20 class URLRequest; 20 class URLRequest;
21 } // namespace net 21 } // namespace net
22 22
23 namespace content { 23 namespace content {
24 24
25 class ResourceDispatcherHostImpl; 25 class ResourceDispatcherHostImpl;
26 class SSLManager; 26 class SSLManager;
27 class WebContents; 27 class WebContents;
28 28
29 // An SSLErrorHandler carries information from the IO thread to the UI thread 29 // SSLErrorHandler is the UI-thread class for handling SSL certificate
30 // and is dispatched to the appropriate SSLManager when it arrives on the 30 // errors. Users of this class can call CancelRequest(),
31 // UI thread. Subclasses should override the OnDispatched/OnDispatchFailed 31 // ContinueRequest(), or DenyRequest() when a decision about how to
32 // methods to implement the actions that should be taken on the UI thread. 32 // handle the error has been made. Users of this class must
33 // These methods can call the different convenience methods ContinueRequest/ 33 // call exactly one of those methods exactly once.
34 // CancelRequest to perform any required action on the net::URLRequest the 34 class SSLErrorHandler {
35 // ErrorHandler was created with.
36 //
37 // IMPORTANT NOTE:
38 //
39 // If you are not doing anything in OnDispatched/OnDispatchFailed, make sure
40 // you call TakeNoAction(). This is necessary for ensuring the instance is
41 // not leaked.
42 //
43 class SSLErrorHandler : public base::RefCountedThreadSafe<SSLErrorHandler> {
44 public: 35 public:
45 // Delegate functions must be called from IO thread. Finally, 36 // SSLErrorHandler's delegate lives on the IO thread, and thus these
46 // CancelSSLRequest() or ContinueSSLRequest() will be called after 37 // delegate methods must be called on the IO thread only.
47 // SSLErrorHandler makes a decision on the SSL error.
48 class CONTENT_EXPORT Delegate { 38 class CONTENT_EXPORT Delegate {
49 public: 39 public:
50 // Called when SSLErrorHandler decides to cancel the request because of 40 // Called when SSLErrorHandler decides to cancel the request because of
51 // the SSL error. 41 // the SSL error.
52 virtual void CancelSSLRequest(int error, const net::SSLInfo* ssl_info) = 0; 42 virtual void CancelSSLRequest(int error, const net::SSLInfo* ssl_info) = 0;
53 43
54 // Called when SSLErrorHandler decides to continue the request despite the 44 // Called when SSLErrorHandler decides to continue the request despite the
55 // SSL error. 45 // SSL error.
56 virtual void ContinueSSLRequest() = 0; 46 virtual void ContinueSSLRequest() = 0;
57 47
58 protected: 48 protected:
59 virtual ~Delegate() {} 49 virtual ~Delegate() {}
60 }; 50 };
61 51
62 // Construct on the IO thread. 52 SSLErrorHandler(WebContents* web_contents,
63 SSLErrorHandler(const base::WeakPtr<Delegate>& delegate, 53 const base::WeakPtr<Delegate>& delegate,
64 ResourceType resource_type, 54 ResourceType resource_type,
65 const GURL& url, 55 const GURL& url,
66 const net::SSLInfo& ssl_info, 56 const net::SSLInfo& ssl_info,
67 bool fatal); 57 bool fatal);
68 58
69 // Find the appropriate SSLManager for the net::URLRequest and begin handling 59 virtual ~SSLErrorHandler();
70 // this error.
71 //
72 // Call on UI thread.
73 void Dispatch(const base::Callback<WebContents*(void)>& web_contents_getter);
74 60
75 // These accessors are available on either thread
76 const net::SSLInfo& ssl_info() const { return ssl_info_; } 61 const net::SSLInfo& ssl_info() const { return ssl_info_; }
62
63 const GURL& request_url() const { return request_url_; }
64
65 ResourceType resource_type() const { return resource_type_; }
66
67 WebContents* web_contents() const { return web_contents_; }
68
77 int cert_error() const { return cert_error_; } 69 int cert_error() const { return cert_error_; }
70
78 bool fatal() const { return fatal_; } 71 bool fatal() const { return fatal_; }
79 const GURL& request_url() const { return request_url_; }
80 ResourceType resource_type() const { return resource_type_; }
81 72
82 // Cancels the associated net::URLRequest. 73 // Cancels the associated net::URLRequest.
83 CONTENT_EXPORT void CancelRequest(); 74 CONTENT_EXPORT void CancelRequest();
84 75
85 // Continue the net::URLRequest ignoring any previous errors. Note that some 76 // Continue the net::URLRequest ignoring any previous errors. Note that some
86 // errors cannot be ignored, in which case this will result in the request 77 // errors cannot be ignored, in which case this will result in the request
87 // being canceled. 78 // being canceled.
88 void ContinueRequest(); 79 void ContinueRequest();
89 80
90 // Cancels the associated net::URLRequest and mark it as denied. The renderer 81 // Cancels the associated net::URLRequest and mark it as denied. The renderer
91 // processes such request in a special manner, optionally replacing them 82 // processes such request in a special manner, optionally replacing them
92 // with alternate content (typically frames content is replaced with a 83 // with alternate content (typically frames content is replaced with a
93 // warning message). 84 // warning message).
94 void DenyRequest(); 85 void DenyRequest();
95 86
96 // Does nothing on the net::URLRequest but ensures the current instance ref
97 // count is decremented appropriately.
98 void TakeNoAction();
99
100 // Returns the manager associated with this SSLErrorHandler.
101 // Should only be accessed on the UI thread.
102 SSLManager* GetManager() const;
103
104 protected:
105 private: 87 private:
106 friend class base::RefCountedThreadSafe<SSLErrorHandler>; 88 // This must not be dereferenced on the UI thread. SSLErrorHandler
107 89 // simply holds on to the reference to be passed back to the IO thread
108 virtual ~SSLErrorHandler(); 90 // to enact a decision about the error once one has been made.
109
110 virtual void OnDispatchFailed();
111
112 // Can use the manager_ member.
113 virtual void OnDispatched();
114
115 // Should only be accessed on the UI thread.
116 SSLManager* manager_; // Our manager.
117
118 // The delegate we are associated with.
119 base::WeakPtr<Delegate> delegate_; 91 base::WeakPtr<Delegate> delegate_;
120 92
121 // Completes the CancelRequest operation on the IO thread.
122 // Call on the IO thread.
123 void CompleteCancelRequest(int error);
124
125 // Completes the ContinueRequest operation on the IO thread.
126 //
127 // Call on the IO thread.
128 void CompleteContinueRequest();
129
130 // Derefs this instance.
131 // Call on the IO thread.
132 void CompleteTakeNoAction();
133
134 // A flag to make sure we notify the net::URLRequest exactly once.
135 // Should only be accessed on the IO thread
136 bool request_has_been_notified_;
137
138 // The below read-only members may be accessed on any thread.
139
140 // The URL that we requested.
141 const GURL request_url_; 93 const GURL request_url_;
142
143 // What kind of resource is associated with the requested that generated 94 // What kind of resource is associated with the requested that generated
144 // that error. 95 // that error.
145 const ResourceType resource_type_; 96 const ResourceType resource_type_;
146
147 const net::SSLInfo ssl_info_; 97 const net::SSLInfo ssl_info_;
148 98 // A net error code describing the error that occurred.
nasko 2016/08/08 20:57:06 nit: Empty lines before comments.
estark 2016/08/09 05:35:01 Done.
149 const int cert_error_; // The error we represent. 99 const int cert_error_;
150 100 // True if the error is from a host requiring certificate errors to be fatal.
151 const bool fatal_; // True if the error is from a host requiring 101 const bool fatal_;
152 // certificate errors to be fatal. 102 WebContents* web_contents_;
153 103
154 DISALLOW_COPY_AND_ASSIGN(SSLErrorHandler); 104 DISALLOW_COPY_AND_ASSIGN(SSLErrorHandler);
155 }; 105 };
156 106
157 } // namespace content 107 } // namespace content
158 108
159 #endif // CONTENT_BROWSER_SSL_SSL_ERROR_HANDLER_H_ 109 #endif // CONTENT_BROWSER_SSL_SSL_ERROR_HANDLER_H_
OLDNEW
« no previous file with comments | « no previous file | content/browser/ssl/ssl_error_handler.cc » ('j') | content/browser/ssl/ssl_manager.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698