| 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 #ifndef CONTENT_BROWSER_DEVTOOLS_PROTOCOL_SECURITY_HANDLER_H_ | 5 #ifndef CONTENT_BROWSER_DEVTOOLS_PROTOCOL_SECURITY_HANDLER_H_ |
| 6 #define CONTENT_BROWSER_DEVTOOLS_PROTOCOL_SECURITY_HANDLER_H_ | 6 #define CONTENT_BROWSER_DEVTOOLS_PROTOCOL_SECURITY_HANDLER_H_ |
| 7 | 7 |
| 8 #include <unordered_map> |
| 9 |
| 8 #include "base/macros.h" | 10 #include "base/macros.h" |
| 9 #include "content/browser/devtools/protocol/devtools_domain_handler.h" | 11 #include "content/browser/devtools/protocol/devtools_domain_handler.h" |
| 10 #include "content/browser/devtools/protocol/security.h" | 12 #include "content/browser/devtools/protocol/security.h" |
| 13 #include "content/public/browser/certificate_request_result_type.h" |
| 11 #include "content/public/browser/web_contents_observer.h" | 14 #include "content/public/browser/web_contents_observer.h" |
| 12 | 15 |
| 13 namespace content { | 16 namespace content { |
| 14 | 17 |
| 15 class DevToolsAgentHostImpl; | 18 class DevToolsAgentHostImpl; |
| 16 class RenderFrameHostImpl; | 19 class RenderFrameHostImpl; |
| 17 | 20 |
| 18 namespace protocol { | 21 namespace protocol { |
| 19 | 22 |
| 20 class SecurityHandler : public DevToolsDomainHandler, | 23 class SecurityHandler : public DevToolsDomainHandler, |
| 21 public Security::Backend, | 24 public Security::Backend, |
| 22 public WebContentsObserver { | 25 public WebContentsObserver { |
| 23 public: | 26 public: |
| 27 using CertErrorCallback = |
| 28 base::Callback<void(content::CertificateRequestResultType)>; |
| 29 |
| 24 SecurityHandler(); | 30 SecurityHandler(); |
| 25 ~SecurityHandler() override; | 31 ~SecurityHandler() override; |
| 26 | 32 |
| 33 static SecurityHandler* FromAgentHost(DevToolsAgentHostImpl* host); |
| 34 |
| 35 // DevToolsDomainHandler overrides |
| 27 void Wire(UberDispatcher* dispatcher) override; | 36 void Wire(UberDispatcher* dispatcher) override; |
| 28 void SetRenderFrameHost(RenderFrameHostImpl* host) override; | 37 void SetRenderFrameHost(RenderFrameHostImpl* host) override; |
| 29 | 38 |
| 30 static SecurityHandler* FromAgentHost(DevToolsAgentHostImpl* host); | 39 // Security::Backend overrides. |
| 31 | |
| 32 Response Enable() override; | 40 Response Enable() override; |
| 33 Response Disable() override; | 41 Response Disable() override; |
| 34 Response ShowCertificateViewer() override; | 42 Response ShowCertificateViewer() override; |
| 43 Response HandleCertificateError(int event_id, const String& action) override; |
| 44 Response SetOverrideCertificateErrors(bool override) override; |
| 45 |
| 46 // NotifyCertificateError will send a CertificateError event. Returns true if |
| 47 // the error is expected to be handled by a corresponding |
| 48 // HandleCertificateError command, and false otherwise. |
| 49 bool NotifyCertificateError(int cert_error, |
| 50 const GURL& request_url, |
| 51 CertErrorCallback callback); |
| 35 | 52 |
| 36 private: | 53 private: |
| 54 using CertErrorCallbackMap = std::unordered_map<int, CertErrorCallback>; |
| 55 |
| 37 void AttachToRenderFrameHost(); | 56 void AttachToRenderFrameHost(); |
| 57 void FlushPendingCertificateErrorNotifications(); |
| 38 | 58 |
| 39 // WebContentsObserver overrides | 59 // WebContentsObserver overrides |
| 40 void DidChangeVisibleSecurityState() override; | 60 void DidChangeVisibleSecurityState() override; |
| 61 void DidFinishNavigation(NavigationHandle* navigation_handle) override; |
| 41 | 62 |
| 42 std::unique_ptr<Security::Frontend> frontend_; | 63 std::unique_ptr<Security::Frontend> frontend_; |
| 43 bool enabled_; | 64 bool enabled_; |
| 44 RenderFrameHostImpl* host_; | 65 RenderFrameHostImpl* host_; |
| 66 int last_cert_error_id_ = 0; |
| 67 CertErrorCallbackMap cert_error_callbacks_; |
| 68 bool certificate_errors_overriden_ = false; |
| 45 | 69 |
| 46 DISALLOW_COPY_AND_ASSIGN(SecurityHandler); | 70 DISALLOW_COPY_AND_ASSIGN(SecurityHandler); |
| 47 }; | 71 }; |
| 48 | 72 |
| 49 } // namespace protocol | 73 } // namespace protocol |
| 50 } // namespace content | 74 } // namespace content |
| 51 | 75 |
| 52 #endif // CONTENT_BROWSER_DEVTOOLS_PROTOCOL_SECURITY_HANDLER_H_ | 76 #endif // CONTENT_BROWSER_DEVTOOLS_PROTOCOL_SECURITY_HANDLER_H_ |
| OLD | NEW |