| 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/protocol/devtools_protocol_dispatcher.h" | 9 #include "content/browser/devtools/protocol/devtools_protocol_dispatcher.h" |
| 10 #include "content/public/browser/navigation_controller.h" | 10 #include "content/public/browser/navigation_controller.h" |
| 11 #include "content/public/browser/navigation_entry.h" | 11 #include "content/public/browser/navigation_entry.h" |
| 12 #include "content/public/browser/security_style_explanations.h" | 12 #include "content/public/browser/security_style_explanations.h" |
| 13 #include "content/public/browser/ssl_status.h" | 13 #include "content/public/browser/ssl_status.h" |
| 14 #include "content/public/browser/web_contents.h" | 14 #include "content/public/browser/web_contents.h" |
| 15 #include "content/public/browser/web_contents_delegate.h" | 15 #include "content/public/browser/web_contents_delegate.h" |
| 16 | 16 |
| 17 namespace content { | 17 namespace content { |
| 18 namespace devtools { | 18 namespace devtools { |
| 19 namespace security { | 19 namespace security { |
| 20 | 20 |
| 21 typedef DevToolsProtocolClient::Response Response; | 21 typedef DevToolsProtocolClient::Response Response; |
| 22 | 22 |
| 23 namespace { | 23 namespace { |
| 24 | 24 |
| 25 std::string SecurityStyleToProtocolSecurityState( | 25 std::string SecurityStyleToProtocolSecurityState( |
| 26 SecurityStyle security_style) { | 26 blink::WebSecurityStyle security_style) { |
| 27 switch (security_style) { | 27 switch (security_style) { |
| 28 case SECURITY_STYLE_UNKNOWN: | 28 case blink::WebSecurityStyleUnknown: |
| 29 return kSecurityStateUnknown; | 29 return kSecurityStateUnknown; |
| 30 case SECURITY_STYLE_UNAUTHENTICATED: | 30 case blink::WebSecurityStyleUnauthenticated: |
| 31 return kSecurityStateNeutral; | 31 return kSecurityStateNeutral; |
| 32 case SECURITY_STYLE_AUTHENTICATION_BROKEN: | 32 case blink::WebSecurityStyleAuthenticationBroken: |
| 33 return kSecurityStateInsecure; | 33 return kSecurityStateInsecure; |
| 34 case SECURITY_STYLE_WARNING: | 34 case blink::WebSecurityStyleWarning: |
| 35 return kSecurityStateWarning; | 35 return kSecurityStateWarning; |
| 36 case SECURITY_STYLE_AUTHENTICATED: | 36 case blink::WebSecurityStyleAuthenticated: |
| 37 return kSecurityStateSecure; | 37 return kSecurityStateSecure; |
| 38 default: | 38 default: |
| 39 NOTREACHED(); | 39 NOTREACHED(); |
| 40 return kSecurityStateUnknown; | 40 return kSecurityStateUnknown; |
| 41 } | 41 } |
| 42 } | 42 } |
| 43 | 43 |
| 44 void AddExplanations( | 44 void AddExplanations( |
| 45 const std::string& security_style, | 45 const std::string& security_style, |
| 46 const std::vector<SecurityStyleExplanation>& explanations_to_add, | 46 const std::vector<SecurityStyleExplanation>& explanations_to_add, |
| (...skipping 24 matching lines...) Expand all Loading... |
| 71 } | 71 } |
| 72 | 72 |
| 73 void SecurityHandler::AttachToRenderFrameHost() { | 73 void SecurityHandler::AttachToRenderFrameHost() { |
| 74 DCHECK(host_); | 74 DCHECK(host_); |
| 75 WebContents* web_contents = WebContents::FromRenderFrameHost(host_); | 75 WebContents* web_contents = WebContents::FromRenderFrameHost(host_); |
| 76 WebContentsObserver::Observe(web_contents); | 76 WebContentsObserver::Observe(web_contents); |
| 77 | 77 |
| 78 // Send an initial SecurityStyleChanged event. | 78 // Send an initial SecurityStyleChanged event. |
| 79 DCHECK(enabled_); | 79 DCHECK(enabled_); |
| 80 SecurityStyleExplanations security_style_explanations; | 80 SecurityStyleExplanations security_style_explanations; |
| 81 SecurityStyle security_style = | 81 blink::WebSecurityStyle security_style = |
| 82 web_contents->GetDelegate()->GetSecurityStyle( | 82 web_contents->GetDelegate()->GetSecurityStyle( |
| 83 web_contents, &security_style_explanations); | 83 web_contents, &security_style_explanations); |
| 84 SecurityStyleChanged(security_style, security_style_explanations); | 84 SecurityStyleChanged(security_style, security_style_explanations); |
| 85 } | 85 } |
| 86 | 86 |
| 87 void SecurityHandler::SetRenderFrameHost(RenderFrameHost* host) { | 87 void SecurityHandler::SetRenderFrameHost(RenderFrameHost* host) { |
| 88 host_ = host; | 88 host_ = host; |
| 89 if (enabled_ && host_) | 89 if (enabled_ && host_) |
| 90 AttachToRenderFrameHost(); | 90 AttachToRenderFrameHost(); |
| 91 } | 91 } |
| 92 | 92 |
| 93 void SecurityHandler::SecurityStyleChanged( | 93 void SecurityHandler::SecurityStyleChanged( |
| 94 SecurityStyle security_style, | 94 blink::WebSecurityStyle security_style, |
| 95 const SecurityStyleExplanations& security_style_explanations) { | 95 const SecurityStyleExplanations& security_style_explanations) { |
| 96 DCHECK(enabled_); | 96 DCHECK(enabled_); |
| 97 | 97 |
| 98 const std::string security_state = | 98 const std::string security_state = |
| 99 SecurityStyleToProtocolSecurityState(security_style); | 99 SecurityStyleToProtocolSecurityState(security_style); |
| 100 | 100 |
| 101 std::vector<scoped_refptr<SecurityStateExplanation>> explanations; | 101 std::vector<scoped_refptr<SecurityStateExplanation>> explanations; |
| 102 AddExplanations(kSecurityStateInsecure, | 102 AddExplanations(kSecurityStateInsecure, |
| 103 security_style_explanations.broken_explanations, | 103 security_style_explanations.broken_explanations, |
| 104 &explanations); | 104 &explanations); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 if (!certificate) | 159 if (!certificate) |
| 160 return Response::InternalError("Could not find certificate"); | 160 return Response::InternalError("Could not find certificate"); |
| 161 web_contents->GetDelegate()->ShowCertificateViewerInDevTools( | 161 web_contents->GetDelegate()->ShowCertificateViewerInDevTools( |
| 162 web_contents, certificate); | 162 web_contents, certificate); |
| 163 return Response::OK(); | 163 return Response::OK(); |
| 164 } | 164 } |
| 165 | 165 |
| 166 } // namespace security | 166 } // namespace security |
| 167 } // namespace devtools | 167 } // namespace devtools |
| 168 } // namespace content | 168 } // namespace content |
| OLD | NEW |