OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #include "content/browser/devtools/protocol/security_handler.h" | 5 #include "content/browser/devtools/protocol/security_handler.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "content/browser/devtools/devtools_session.h" | 9 #include "content/browser/devtools/devtools_session.h" |
10 #include "content/browser/frame_host/render_frame_host_impl.h" | 10 #include "content/browser/frame_host/render_frame_host_impl.h" |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
139 .Build(); | 139 .Build(); |
140 | 140 |
141 frontend_->SecurityStateChanged( | 141 frontend_->SecurityStateChanged( |
142 security_state, | 142 security_state, |
143 security_style_explanations.scheme_is_cryptographic, | 143 security_style_explanations.scheme_is_cryptographic, |
144 std::move(explanations), | 144 std::move(explanations), |
145 std::move(insecure_status), | 145 std::move(insecure_status), |
146 Maybe<std::string>(security_style_explanations.summary)); | 146 Maybe<std::string>(security_style_explanations.summary)); |
147 } | 147 } |
148 | 148 |
149 void SecurityHandler::DidFinishNavigation(NavigationHandle* navigation_handle) { | |
150 if (certificate_errors_overriden_) | |
151 FlushPendingCertificateErrorNotifications(); | |
152 } | |
153 | |
154 void SecurityHandler::FlushPendingCertificateErrorNotifications() { | |
155 for (auto callback : cert_error_callbacks_) | |
156 callback.second.Run(content::CERTIFICATE_REQUEST_RESULT_TYPE_CANCEL); | |
157 cert_error_callbacks_.clear(); | |
158 } | |
159 | |
160 bool SecurityHandler::NotifyCertificateError(int cert_error, | |
161 const GURL& request_url, | |
162 CertErrorCallback handler) { | |
163 if (!enabled_) | |
164 return false; | |
165 if (!certificate_errors_overriden_) { | |
166 // Send certificateError to devtools frontend to inform, but do not | |
pfeldman
2017/03/22 00:47:32
I would always generate the id, regardless on whet
irisu
2017/03/22 02:48:58
Done.
| |
167 // assign a cert error id, since we do not want the error to be | |
168 // handled by devtools. | |
169 frontend_->CertificateError(-1, net::ErrorToShortString(cert_error), | |
170 request_url.spec()); | |
171 return false; | |
172 } | |
173 frontend_->CertificateError(++last_cert_error_id_, | |
174 net::ErrorToShortString(cert_error), | |
175 request_url.spec()); | |
176 cert_error_callbacks_[last_cert_error_id_] = handler; | |
pfeldman
2017/03/22 00:47:32
But still put it into the map conditionally.
irisu
2017/03/22 02:48:58
Done.
| |
177 return true; | |
178 } | |
179 | |
149 Response SecurityHandler::Enable() { | 180 Response SecurityHandler::Enable() { |
150 enabled_ = true; | 181 enabled_ = true; |
151 if (host_) | 182 if (host_) |
152 AttachToRenderFrameHost(); | 183 AttachToRenderFrameHost(); |
153 | 184 |
154 return Response::OK(); | 185 return Response::OK(); |
155 } | 186 } |
156 | 187 |
157 Response SecurityHandler::Disable() { | 188 Response SecurityHandler::Disable() { |
158 enabled_ = false; | 189 enabled_ = false; |
190 certificate_errors_overriden_ = false; | |
159 WebContentsObserver::Observe(nullptr); | 191 WebContentsObserver::Observe(nullptr); |
192 FlushPendingCertificateErrorNotifications(); | |
160 return Response::OK(); | 193 return Response::OK(); |
161 } | 194 } |
162 | 195 |
163 Response SecurityHandler::ShowCertificateViewer() { | 196 Response SecurityHandler::ShowCertificateViewer() { |
164 if (!host_) | 197 if (!host_) |
165 return Response::InternalError(); | 198 return Response::InternalError(); |
166 WebContents* web_contents = WebContents::FromRenderFrameHost(host_); | 199 WebContents* web_contents = WebContents::FromRenderFrameHost(host_); |
167 scoped_refptr<net::X509Certificate> certificate = | 200 scoped_refptr<net::X509Certificate> certificate = |
168 web_contents->GetController().GetVisibleEntry()->GetSSL().certificate; | 201 web_contents->GetController().GetVisibleEntry()->GetSSL().certificate; |
169 if (!certificate) | 202 if (!certificate) |
170 return Response::Error("Could not find certificate"); | 203 return Response::Error("Could not find certificate"); |
171 web_contents->GetDelegate()->ShowCertificateViewerInDevTools( | 204 web_contents->GetDelegate()->ShowCertificateViewerInDevTools( |
172 web_contents, certificate); | 205 web_contents, certificate); |
173 return Response::OK(); | 206 return Response::OK(); |
174 } | 207 } |
175 | 208 |
209 Response SecurityHandler::HandleCertificateError(int event_id, | |
210 const String& action) { | |
211 if (cert_error_callbacks_.find(event_id) == cert_error_callbacks_.end()) { | |
212 return Response::Error( | |
213 String("Unknown event id: " + std::to_string(event_id))); | |
214 } | |
215 content::CertificateRequestResultType type = | |
216 content::CERTIFICATE_REQUEST_RESULT_TYPE_CANCEL; | |
217 Response response = Response::OK(); | |
218 if (action == Security::CertificateErrorActionEnum::Continue) { | |
219 type = content::CERTIFICATE_REQUEST_RESULT_TYPE_CONTINUE; | |
220 } else if (action == Security::CertificateErrorActionEnum::Cancel) { | |
221 type = content::CERTIFICATE_REQUEST_RESULT_TYPE_CANCEL; | |
222 } else { | |
223 response = | |
224 Response::Error(String("Unknown Certificate Error Action: " + action)); | |
225 } | |
226 cert_error_callbacks_[event_id].Run(type); | |
227 cert_error_callbacks_.erase(event_id); | |
228 return response; | |
229 } | |
230 | |
231 Response SecurityHandler::SetOverrideCertificateErrors(bool override) { | |
232 if (override && !enabled_) | |
233 return Response::Error("Security domain not enabled"); | |
234 certificate_errors_overriden_ = override; | |
235 if (!override) | |
236 FlushPendingCertificateErrorNotifications(); | |
237 return Response::OK(); | |
238 } | |
239 | |
176 } // namespace protocol | 240 } // namespace protocol |
177 } // namespace content | 241 } // namespace content |
OLD | NEW |