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> | |
8 | |
9 #include "content/public/browser/web_contents.h" | |
10 | |
7 namespace content { | 11 namespace content { |
8 namespace devtools { | 12 namespace devtools { |
9 namespace security { | 13 namespace security { |
10 | 14 |
11 typedef DevToolsProtocolClient::Response Response; | 15 typedef DevToolsProtocolClient::Response Response; |
12 | 16 |
13 SecurityHandler::SecurityHandler() { | 17 SecurityHandler::SecurityHandler() : enabled_(false), host_(nullptr) { |
pfeldman
2015/06/11 06:45:50
http://google-styleguide.googlecode.com/svn/trunk/
lgarron
2015/06/11 22:00:53
This matches the "all on one line" case from the s
| |
14 } | 18 } |
15 | 19 |
16 SecurityHandler::~SecurityHandler() { | 20 SecurityHandler::~SecurityHandler() { |
17 } | 21 } |
18 | 22 |
19 void SecurityHandler::SetClient(scoped_ptr<DevToolsProtocolClient> client) { | 23 void SecurityHandler::SetClient(scoped_ptr<Client> client) { |
24 client_.swap(client); | |
25 } | |
26 | |
27 void SecurityHandler::SetRenderFrameHost(RenderFrameHost* host) { | |
28 host_ = host; | |
29 if (enabled_ && host_) | |
30 WebContentsObserver::Observe(WebContents::FromRenderFrameHost(host_)); | |
31 } | |
32 | |
33 void SecurityHandler::SecurityStyleChanged(SecurityStyle security_style) { | |
34 if (!enabled_) | |
pfeldman
2015/06/11 06:45:50
DCHECK(enabled_);
lgarron
2015/06/11 22:00:53
Done.
| |
35 return; | |
36 | |
37 const std::string security_state = | |
38 SecurityStyleToProtocolSecurityState(security_style); | |
39 client_->SecurityStateChanged( | |
40 SecurityStateChangedParams::Create()->set_security_state(security_state)); | |
20 } | 41 } |
21 | 42 |
22 Response SecurityHandler::Enable() { | 43 Response SecurityHandler::Enable() { |
44 enabled_ = true; | |
45 if (host_) | |
46 WebContentsObserver::Observe(WebContents::FromRenderFrameHost(host_)); | |
23 return Response::OK(); | 47 return Response::OK(); |
24 } | 48 } |
25 | 49 |
26 Response SecurityHandler::Disable() { | 50 Response SecurityHandler::Disable() { |
51 enabled_ = false; | |
52 WebContentsObserver::Observe(nullptr); | |
27 return Response::OK(); | 53 return Response::OK(); |
28 } | 54 } |
29 | 55 |
56 std::string SecurityHandler::SecurityStyleToProtocolSecurityState( | |
pfeldman
2015/06/11 06:45:50
Utility function could be defined in a local stati
lgarron
2015/06/11 22:00:53
Done.
| |
57 SecurityStyle security_style) { | |
58 switch (security_style) { | |
59 case SECURITY_STYLE_UNKNOWN: | |
60 return kSecurityStateUnknown; | |
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 return kSecurityStateUnknown; | |
72 } | |
73 } | |
74 | |
30 } // namespace security | 75 } // namespace security |
31 } // namespace devtools | 76 } // namespace devtools |
32 } // namespace content | 77 } // namespace content |
OLD | NEW |