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 frontend_->CertificateError(++last_cert_error_id_, |
| 166 net::ErrorToShortString(cert_error), |
| 167 request_url.spec()); |
| 168 if (!certificate_errors_overriden_) { |
| 169 return false; |
| 170 } |
| 171 cert_error_callbacks_[last_cert_error_id_] = handler; |
| 172 return true; |
| 173 } |
| 174 |
149 Response SecurityHandler::Enable() { | 175 Response SecurityHandler::Enable() { |
150 enabled_ = true; | 176 enabled_ = true; |
151 if (host_) | 177 if (host_) |
152 AttachToRenderFrameHost(); | 178 AttachToRenderFrameHost(); |
153 | 179 |
154 return Response::OK(); | 180 return Response::OK(); |
155 } | 181 } |
156 | 182 |
157 Response SecurityHandler::Disable() { | 183 Response SecurityHandler::Disable() { |
158 enabled_ = false; | 184 enabled_ = false; |
| 185 certificate_errors_overriden_ = false; |
159 WebContentsObserver::Observe(nullptr); | 186 WebContentsObserver::Observe(nullptr); |
| 187 FlushPendingCertificateErrorNotifications(); |
160 return Response::OK(); | 188 return Response::OK(); |
161 } | 189 } |
162 | 190 |
163 Response SecurityHandler::ShowCertificateViewer() { | 191 Response SecurityHandler::ShowCertificateViewer() { |
164 if (!host_) | 192 if (!host_) |
165 return Response::InternalError(); | 193 return Response::InternalError(); |
166 WebContents* web_contents = WebContents::FromRenderFrameHost(host_); | 194 WebContents* web_contents = WebContents::FromRenderFrameHost(host_); |
167 scoped_refptr<net::X509Certificate> certificate = | 195 scoped_refptr<net::X509Certificate> certificate = |
168 web_contents->GetController().GetVisibleEntry()->GetSSL().certificate; | 196 web_contents->GetController().GetVisibleEntry()->GetSSL().certificate; |
169 if (!certificate) | 197 if (!certificate) |
170 return Response::Error("Could not find certificate"); | 198 return Response::Error("Could not find certificate"); |
171 web_contents->GetDelegate()->ShowCertificateViewerInDevTools( | 199 web_contents->GetDelegate()->ShowCertificateViewerInDevTools( |
172 web_contents, certificate); | 200 web_contents, certificate); |
173 return Response::OK(); | 201 return Response::OK(); |
174 } | 202 } |
175 | 203 |
| 204 Response SecurityHandler::HandleCertificateError(int event_id, |
| 205 const String& action) { |
| 206 if (cert_error_callbacks_.find(event_id) == cert_error_callbacks_.end()) { |
| 207 return Response::Error( |
| 208 String("Unknown event id: " + std::to_string(event_id))); |
| 209 } |
| 210 content::CertificateRequestResultType type = |
| 211 content::CERTIFICATE_REQUEST_RESULT_TYPE_CANCEL; |
| 212 Response response = Response::OK(); |
| 213 if (action == Security::CertificateErrorActionEnum::Continue) { |
| 214 type = content::CERTIFICATE_REQUEST_RESULT_TYPE_CONTINUE; |
| 215 } else if (action == Security::CertificateErrorActionEnum::Cancel) { |
| 216 type = content::CERTIFICATE_REQUEST_RESULT_TYPE_CANCEL; |
| 217 } else { |
| 218 response = |
| 219 Response::Error(String("Unknown Certificate Error Action: " + action)); |
| 220 } |
| 221 cert_error_callbacks_[event_id].Run(type); |
| 222 cert_error_callbacks_.erase(event_id); |
| 223 return response; |
| 224 } |
| 225 |
| 226 Response SecurityHandler::SetOverrideCertificateErrors(bool override) { |
| 227 if (override && !enabled_) |
| 228 return Response::Error("Security domain not enabled"); |
| 229 certificate_errors_overriden_ = override; |
| 230 if (!override) |
| 231 FlushPendingCertificateErrorNotifications(); |
| 232 return Response::OK(); |
| 233 } |
| 234 |
176 } // namespace protocol | 235 } // namespace protocol |
177 } // namespace content | 236 } // namespace content |
OLD | NEW |