Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "content/browser/devtools/protocol/security_handler.h" | |
| 6 | |
| 7 #include <string> | |
| 8 | |
| 9 namespace content { | |
| 10 namespace devtools { | |
| 11 namespace security { | |
| 12 | |
| 13 typedef DevToolsProtocolClient::Response Response; | |
| 14 | |
| 15 SecurityHandler::SecurityHandler() : enabled_(false), host_(nullptr) { | |
| 16 } | |
| 17 | |
| 18 SecurityHandler::~SecurityHandler() { | |
| 19 } | |
| 20 | |
| 21 void SecurityHandler::SetClient(scoped_ptr<Client> client) { | |
| 22 client_.swap(client); | |
| 23 } | |
| 24 | |
| 25 void SecurityHandler::SetRenderFrameHost(RenderFrameHost* host) { | |
| 26 host_ = host; | |
| 27 if (enabled_ && host_) | |
| 28 WebContentsObserver::Observe(WebContents::FromRenderFrameHost(host_)); | |
| 29 } | |
| 30 | |
| 31 void SecurityHandler::SecurityStyleChanged(SecurityStyle security_style) { | |
| 32 if (!enabled_) | |
| 33 return; | |
| 34 | |
| 35 const std::string security_state = | |
| 36 SecurityStyleToProtocolSecurityState(security_style); | |
| 37 client_->SecurityStateChanged( | |
| 38 SecurityStateChangedParams::Create()->set_security_state(security_state)); | |
| 39 } | |
| 40 | |
| 41 Response SecurityHandler::Enable() { | |
| 42 enabled_ = true; | |
| 43 if (host_) | |
| 44 WebContentsObserver::Observe(WebContents::FromRenderFrameHost(host_)); | |
| 45 return Response::OK(); | |
| 46 } | |
| 47 | |
| 48 Response SecurityHandler::Disable() { | |
| 49 enabled_ = false; | |
| 50 WebContentsObserver::Observe(nullptr); | |
| 51 return Response::OK(); | |
| 52 } | |
| 53 | |
| 54 std::string SecurityHandler::SecurityStyleToProtocolSecurityState( | |
| 55 SecurityStyle security_style) { | |
| 56 // TODO: Replace these values with literals once the Security domain has | |
| 57 // landed in protocol.json. | |
| 58 switch (security_style) { | |
| 59 case SECURITY_STYLE_UNKNOWN: | |
| 60 return "unknown"; | |
|
lgarron
2015/06/09 18:33:56
estark@: Since this value can theoretically be pas
| |
| 61 case SECURITY_STYLE_UNAUTHENTICATED: | |
| 62 return kSecurityStateHttp; | |
| 63 case SECURITY_STYLE_AUTHENTICATION_BROKEN: | |
| 64 return kSecurityStateInsecure; | |
| 65 case SECURITY_STYLE_WARNING: | |
| 66 return kSecurityStateWarning; | |
| 67 case SECURITY_STYLE_AUTHENTICATED: | |
| 68 return kSecurityStateSecure; | |
| 69 default: | |
| 70 NOTREACHED(); | |
| 71 } | |
| 72 } | |
| 73 | |
| 74 } // namespace security | |
| 75 } // namespace devtools | |
| 76 } // namespace content | |
| OLD | NEW |