Chromium Code Reviews| Index: content/browser/devtools/protocol/security_handler.cc |
| diff --git a/content/browser/devtools/protocol/security_handler.cc b/content/browser/devtools/protocol/security_handler.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..681353b559a31c24ecc4fc47fe046259dd47ffda |
| --- /dev/null |
| +++ b/content/browser/devtools/protocol/security_handler.cc |
| @@ -0,0 +1,76 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "content/browser/devtools/protocol/security_handler.h" |
| + |
| +#include <string> |
| + |
| +namespace content { |
| +namespace devtools { |
| +namespace security { |
| + |
| +typedef DevToolsProtocolClient::Response Response; |
| + |
| +SecurityHandler::SecurityHandler() : enabled_(false), host_(nullptr) { |
| +} |
| + |
| +SecurityHandler::~SecurityHandler() { |
| +} |
| + |
| +void SecurityHandler::SetClient(scoped_ptr<Client> client) { |
| + client_.swap(client); |
| +} |
| + |
| +void SecurityHandler::SetRenderFrameHost(RenderFrameHost* host) { |
| + host_ = host; |
| + if (enabled_ && host_) |
| + WebContentsObserver::Observe(WebContents::FromRenderFrameHost(host_)); |
| +} |
| + |
| +void SecurityHandler::SecurityStyleChanged(SecurityStyle security_style) { |
| + if (!enabled_) |
| + return; |
| + |
| + const std::string security_state = |
| + SecurityStyleToProtocolSecurityState(security_style); |
| + client_->SecurityStateChanged( |
| + SecurityStateChangedParams::Create()->set_security_state(security_state)); |
| +} |
| + |
| +Response SecurityHandler::Enable() { |
| + enabled_ = true; |
| + if (host_) |
| + WebContentsObserver::Observe(WebContents::FromRenderFrameHost(host_)); |
| + return Response::OK(); |
| +} |
| + |
| +Response SecurityHandler::Disable() { |
| + enabled_ = false; |
| + WebContentsObserver::Observe(nullptr); |
| + return Response::OK(); |
| +} |
| + |
| +std::string SecurityHandler::SecurityStyleToProtocolSecurityState( |
| + SecurityStyle security_style) { |
| + // TODO: Replace these values with literals once the Security domain has |
| + // landed in protocol.json. |
| + switch (security_style) { |
| + case SECURITY_STYLE_UNKNOWN: |
| + return "unknown"; |
|
lgarron
2015/06/09 18:33:56
estark@: Since this value can theoretically be pas
|
| + case SECURITY_STYLE_UNAUTHENTICATED: |
| + return kSecurityStateHttp; |
| + case SECURITY_STYLE_AUTHENTICATION_BROKEN: |
| + return kSecurityStateInsecure; |
| + case SECURITY_STYLE_WARNING: |
| + return kSecurityStateWarning; |
| + case SECURITY_STYLE_AUTHENTICATED: |
| + return kSecurityStateSecure; |
| + default: |
| + NOTREACHED(); |
| + } |
| +} |
| + |
| +} // namespace security |
| +} // namespace devtools |
| +} // namespace content |