Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "url/gurl.h" | 17 #include "url/gurl.h" |
| 17 | 18 |
| 18 namespace net { | 19 namespace net { |
| 19 class SSLInfo; | |
| 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 SSLCertErrorHandler; | |
| 27 class SSLManager; | 26 class SSLManager; |
| 28 class WebContents; | 27 class WebContents; |
| 29 | 28 |
| 30 // An SSLErrorHandler carries information from the IO thread to the UI thread | 29 // An SSLErrorHandler carries information from the IO thread to the UI thread |
| 31 // and is dispatched to the appropriate SSLManager when it arrives on the | 30 // and is dispatched to the appropriate SSLManager when it arrives on the |
| 32 // UI thread. Subclasses should override the OnDispatched/OnDispatchFailed | 31 // UI thread. Subclasses should override the OnDispatched/OnDispatchFailed |
| 33 // methods to implement the actions that should be taken on the UI thread. | 32 // methods to implement the actions that should be taken on the UI thread. |
| 34 // These methods can call the different convenience methods ContinueRequest/ | 33 // These methods can call the different convenience methods ContinueRequest/ |
| 35 // CancelRequest to perform any required action on the net::URLRequest the | 34 // CancelRequest to perform any required action on the net::URLRequest the |
| 36 // ErrorHandler was created with. | 35 // ErrorHandler was created with. |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 53 virtual void CancelSSLRequest(int error, const net::SSLInfo* ssl_info) = 0; | 52 virtual void CancelSSLRequest(int error, const net::SSLInfo* ssl_info) = 0; |
| 54 | 53 |
| 55 // Called when SSLErrorHandler decides to continue the request despite the | 54 // Called when SSLErrorHandler decides to continue the request despite the |
| 56 // SSL error. | 55 // SSL error. |
| 57 virtual void ContinueSSLRequest() = 0; | 56 virtual void ContinueSSLRequest() = 0; |
| 58 | 57 |
| 59 protected: | 58 protected: |
| 60 virtual ~Delegate() {} | 59 virtual ~Delegate() {} |
| 61 }; | 60 }; |
| 62 | 61 |
| 63 virtual SSLCertErrorHandler* AsSSLCertErrorHandler(); | 62 // Construct on the IO thread. |
| 63 SSLErrorHandler(const base::WeakPtr<Delegate>& delegate, | |
| 64 ResourceType resource_type, | |
| 65 const GURL& url, | |
| 66 const net::SSLInfo& ssl_info, | |
| 67 bool fatal); | |
| 64 | 68 |
| 65 // Find the appropriate SSLManager for the net::URLRequest and begin handling | 69 // Find the appropriate SSLManager for the net::URLRequest and begin handling |
| 66 // this error. | 70 // this error. |
| 67 // | 71 // |
| 68 // Call on UI thread. | 72 // Call on UI thread. |
| 69 void Dispatch(const base::Callback<WebContents*(void)>& web_contents_getter); | 73 void Dispatch(const base::Callback<WebContents*(void)>& web_contents_getter); |
| 70 | 74 |
| 71 // Available on either thread. | 75 // These accessors are available on either thread |
| 76 const net::SSLInfo& ssl_info() const { return ssl_info_; } | |
| 77 int cert_error() const { return cert_error_; } | |
| 78 bool fatal() const { return fatal_; } | |
| 72 const GURL& request_url() const { return request_url_; } | 79 const GURL& request_url() const { return request_url_; } |
| 73 | |
| 74 // Available on either thread. | |
| 75 ResourceType resource_type() const { return resource_type_; } | 80 ResourceType resource_type() const { return resource_type_; } |
| 76 | 81 |
| 77 // Cancels the associated net::URLRequest. | 82 // Cancels the associated net::URLRequest. |
| 78 // This method can be called from OnDispatchFailed and OnDispatched. | |
| 79 CONTENT_EXPORT void CancelRequest(); | 83 CONTENT_EXPORT void CancelRequest(); |
| 80 | 84 |
| 81 // Continue the net::URLRequest ignoring any previous errors. Note that some | 85 // Continue the net::URLRequest ignoring any previous errors. Note that some |
| 82 // errors cannot be ignored, in which case this will result in the request | 86 // errors cannot be ignored, in which case this will result in the request |
| 83 // being canceled. | 87 // being canceled. |
| 84 // This method can be called from OnDispatchFailed and OnDispatched. | |
| 85 void ContinueRequest(); | 88 void ContinueRequest(); |
| 86 | 89 |
| 87 // Cancels the associated net::URLRequest and mark it as denied. The renderer | 90 // Cancels the associated net::URLRequest and mark it as denied. The renderer |
| 88 // processes such request in a special manner, optionally replacing them | 91 // processes such request in a special manner, optionally replacing them |
| 89 // with alternate content (typically frames content is replaced with a | 92 // with alternate content (typically frames content is replaced with a |
| 90 // warning message). | 93 // warning message). |
| 91 // This method can be called from OnDispatchFailed and OnDispatched. | |
| 92 void DenyRequest(); | 94 void DenyRequest(); |
| 93 | 95 |
| 94 // Does nothing on the net::URLRequest but ensures the current instance ref | 96 // Does nothing on the net::URLRequest but ensures the current instance ref |
| 95 // count is decremented appropriately. Subclasses that do not want to | 97 // count is decremented appropriately. |
| 96 // take any specific actions in their OnDispatched/OnDispatchFailed should | |
| 97 // call this. | |
| 98 void TakeNoAction(); | 98 void TakeNoAction(); |
| 99 | 99 |
| 100 // Returns the manager associated with this SSLErrorHandler. | 100 // Returns the manager associated with this SSLErrorHandler. |
| 101 // Should only be accessed on the UI thread. | 101 // Should only be accessed on the UI thread. |
| 102 SSLManager* GetManager() const; | 102 SSLManager* GetManager() const; |
| 103 | 103 |
| 104 protected: | 104 protected: |
|
nasko
2016/08/08 18:47:12
Why not remove "protected:"?
estark
2016/08/08 20:13:00
Done.
| |
| 105 private: | |
| 105 friend class base::RefCountedThreadSafe<SSLErrorHandler>; | 106 friend class base::RefCountedThreadSafe<SSLErrorHandler>; |
| 106 | 107 |
| 107 // Construct on the IO thread. | |
| 108 SSLErrorHandler(const base::WeakPtr<Delegate>& delegate, | |
| 109 ResourceType resource_type, | |
| 110 const GURL& url); | |
| 111 | |
| 112 virtual ~SSLErrorHandler(); | 108 virtual ~SSLErrorHandler(); |
| 113 | 109 |
| 114 // The following 2 methods are the methods subclasses should implement. | |
| 115 virtual void OnDispatchFailed(); | 110 virtual void OnDispatchFailed(); |
| 116 | 111 |
| 117 // Can use the manager_ member. | 112 // Can use the manager_ member. |
| 118 virtual void OnDispatched(); | 113 virtual void OnDispatched(); |
| 119 | 114 |
| 120 // Should only be accessed on the UI thread. | 115 // Should only be accessed on the UI thread. |
| 121 SSLManager* manager_; // Our manager. | 116 SSLManager* manager_; // Our manager. |
| 122 | 117 |
| 123 // The delegate we are associated with. | 118 // The delegate we are associated with. |
| 124 base::WeakPtr<Delegate> delegate_; | 119 base::WeakPtr<Delegate> delegate_; |
| 125 | 120 |
| 126 private: | |
| 127 // Completes the CancelRequest operation on the IO thread. | 121 // Completes the CancelRequest operation on the IO thread. |
| 128 // Call on the IO thread. | 122 // Call on the IO thread. |
| 129 void CompleteCancelRequest(int error); | 123 void CompleteCancelRequest(int error); |
| 130 | 124 |
| 131 // Completes the ContinueRequest operation on the IO thread. | 125 // Completes the ContinueRequest operation on the IO thread. |
| 132 // | 126 // |
| 133 // Call on the IO thread. | 127 // Call on the IO thread. |
| 134 void CompleteContinueRequest(); | 128 void CompleteContinueRequest(); |
| 135 | 129 |
| 136 // Derefs this instance. | 130 // Derefs this instance. |
| 137 // Call on the IO thread. | 131 // Call on the IO thread. |
| 138 void CompleteTakeNoAction(); | 132 void CompleteTakeNoAction(); |
| 139 | 133 |
| 140 // The URL that we requested. | |
| 141 // This read-only member can be accessed on any thread. | |
| 142 const GURL request_url_; | |
| 143 | |
| 144 // What kind of resource is associated with the requested that generated | |
| 145 // that error. | |
| 146 // This read-only member can be accessed on any thread. | |
| 147 const ResourceType resource_type_; | |
| 148 | |
| 149 // A flag to make sure we notify the net::URLRequest exactly once. | 134 // A flag to make sure we notify the net::URLRequest exactly once. |
| 150 // Should only be accessed on the IO thread | 135 // Should only be accessed on the IO thread |
| 151 bool request_has_been_notified_; | 136 bool request_has_been_notified_; |
| 152 | 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_; | |
| 142 | |
| 143 // What kind of resource is associated with the requested that generated | |
| 144 // that error. | |
| 145 const ResourceType resource_type_; | |
| 146 | |
|
nasko
2016/08/08 18:47:12
nit: No need for empty lines between the members,
estark
2016/08/08 20:13:01
I ended up adding comments to each of them for con
| |
| 147 const net::SSLInfo ssl_info_; | |
| 148 | |
| 149 const int cert_error_; // The error we represent. | |
|
nasko
2016/08/08 18:47:12
I know this is a code move, but let's clean things
estark
2016/08/08 20:13:01
Done.
| |
| 150 | |
| 151 const bool fatal_; // True if the error is from a host requiring | |
| 152 // certificate errors to be fatal. | |
| 153 | |
| 153 DISALLOW_COPY_AND_ASSIGN(SSLErrorHandler); | 154 DISALLOW_COPY_AND_ASSIGN(SSLErrorHandler); |
| 154 }; | 155 }; |
| 155 | 156 |
| 156 } // namespace content | 157 } // namespace content |
| 157 | 158 |
| 158 #endif // CONTENT_BROWSER_SSL_SSL_ERROR_HANDLER_H_ | 159 #endif // CONTENT_BROWSER_SSL_SSL_ERROR_HANDLER_H_ |
| OLD | NEW |