Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(264)

Side by Side Diff: chrome/browser/ssl/chrome_security_state_model_delegate.cc

Issue 1440303002: Componentize SecurityStateModel (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: android/cros fixes Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 "chrome/browser/ssl/chrome_security_state_model_delegate.h"
6
7 #include "base/command_line.h"
8 #include "base/metrics/field_trial.h"
9 #include "base/metrics/histogram_macros.h"
10 #include "chrome/browser/chromeos/policy/policy_cert_service.h"
11 #include "chrome/browser/chromeos/policy/policy_cert_service_factory.h"
12 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/common/chrome_constants.h"
14 #include "chrome/common/chrome_switches.h"
15 #include "content/public/browser/cert_store.h"
16 #include "content/public/browser/navigation_entry.h"
17 #include "content/public/common/origin_util.h"
18
19 DEFINE_WEB_CONTENTS_USER_DATA_KEY(ChromeSecurityStateModelDelegate);
20
21 ChromeSecurityStateModelDelegate::~ChromeSecurityStateModelDelegate() {}
22
23 const security_state::SecurityInfo&
24 ChromeSecurityStateModelDelegate::GetSecurityInfo() const {
25 return security_state_model_->GetSecurityInfo();
26 }
27
28 bool ChromeSecurityStateModelDelegate::VisibleSecurityStateChanged() {
29 content::NavigationEntry* entry =
30 web_contents_->GetController().GetVisibleEntry();
31 if (!entry)
32 return true;
33
34 const GURL& new_url = entry->GetURL();
35 const content::SSLStatus& new_ssl = entry->GetSSL();
36 if (new_url == visible_url_ && new_ssl.Equals(visible_ssl_status_))
37 return false;
38 visible_url_ = new_url;
39 visible_ssl_status_ = new_ssl;
40 return true;
41 }
42
43 bool ChromeSecurityStateModelDelegate::RetrieveCert(
44 scoped_refptr<net::X509Certificate>* cert) {
45 return content::CertStore::GetInstance()->RetrieveCert(
46 visible_ssl_status_.cert_id, cert);
47 }
48
49 security_state::SecurityLevel
50 ChromeSecurityStateModelDelegate::GetInitialSecurityLevel() {
51 content::SecurityStyle security_style = visible_ssl_status_.security_style;
52 switch (security_style) {
53 case content::SECURITY_STYLE_UNKNOWN:
54 case content::SECURITY_STYLE_UNAUTHENTICATED:
55 return security_state::NONE;
56 case content::SECURITY_STYLE_AUTHENTICATION_BROKEN:
57 return security_state::SECURITY_ERROR;
58 case content::SECURITY_STYLE_WARNING:
59 return security_state::SECURITY_WARNING;
60 case content::SECURITY_STYLE_AUTHENTICATED:
61 return security_state::SECURE;
62 }
63 return security_state::NONE;
64 }
65
66 security_state::SecurityLevel
67 ChromeSecurityStateModelDelegate::GetSecurityLevelForNonSecure(
68 const GURL& url) {
69 if (content::IsOriginSecure(url) || !url.IsStandard())
70 return security_state::NONE;
71
72 std::string choice =
73 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
74 switches::kMarkNonSecureAs);
75 std::string group = base::FieldTrialList::FindFullName("MarkNonSecureAs");
76
77 // Do not change this enum. It is used in the histogram.
78 enum MarkNonSecureStatus { NEUTRAL, DUBIOUS, NON_SECURE, LAST_STATUS };
79 const char kEnumeration[] = "MarkNonSecureAs";
80
81 security_state::SecurityLevel level = security_state::NONE;
82 MarkNonSecureStatus status;
83
84 if (choice == switches::kMarkNonSecureAsNeutral) {
85 status = NEUTRAL;
86 level = security_state::NONE;
87 } else if (choice == switches::kMarkNonSecureAsNonSecure) {
88 status = NON_SECURE;
89 level = security_state::SECURITY_ERROR;
90 } else if (group == switches::kMarkNonSecureAsNeutral) {
91 status = NEUTRAL;
92 level = security_state::NONE;
93 } else if (group == switches::kMarkNonSecureAsNonSecure) {
94 status = NON_SECURE;
95 level = security_state::SECURITY_ERROR;
96 } else {
97 status = NEUTRAL;
98 level = security_state::NONE;
99 }
100
101 UMA_HISTOGRAM_ENUMERATION(kEnumeration, status, LAST_STATUS);
102 return level;
103 }
104
105 bool ChromeSecurityStateModelDelegate::UsedKnownMITMCertificate() {
106 #if defined(OS_CHROMEOS)
107 policy::PolicyCertService* service =
108 policy::PolicyCertServiceFactory::GetForProfile(
109 Profile::FromBrowserContext(web_contents_->GetBrowserContext()));
110 if (service && service->UsedPolicyCertificates())
111 return true;
112 #endif
113 return false;
114 }
115
116 int ChromeSecurityStateModelDelegate::GetCertId() {
117 return visible_ssl_status_.cert_id;
118 }
119
120 net::CertStatus ChromeSecurityStateModelDelegate::GetCertStatus() {
121 return visible_ssl_status_.cert_status;
122 }
123
124 int ChromeSecurityStateModelDelegate::GetConnectionStatus() {
125 return visible_ssl_status_.connection_status;
126 }
127
128 int ChromeSecurityStateModelDelegate::GetSecurityBits() {
129 return visible_ssl_status_.security_bits;
130 }
131
132 const GURL& ChromeSecurityStateModelDelegate::GetURL() {
133 content::NavigationEntry* entry =
134 web_contents_->GetController().GetVisibleEntry();
135 if (!entry)
136 return empty_url_;
137 return entry->GetURL();
138 }
139
140 bool ChromeSecurityStateModelDelegate::RanMixedContent() {
141 if (visible_ssl_status_.content_status &
142 content::SSLStatus::RAN_INSECURE_CONTENT) {
143 return true;
144 }
145 return false;
146 }
147
148 bool ChromeSecurityStateModelDelegate::DisplayedMixedContent() {
149 if (visible_ssl_status_.content_status &
150 content::SSLStatus::DISPLAYED_INSECURE_CONTENT) {
151 return true;
152 }
153 return false;
154 }
155
156 void ChromeSecurityStateModelDelegate::GetSCTVerifyStatuses(
157 std::vector<net::ct::SCTVerifyStatus>* sct_verify_statuses) {
158 for (const auto& sct : visible_ssl_status_.signed_certificate_timestamp_ids) {
159 sct_verify_statuses->push_back(sct.status);
160 }
161 }
162
163 ChromeSecurityStateModelDelegate::ChromeSecurityStateModelDelegate(
164 content::WebContents* web_contents)
165 : web_contents_(web_contents),
166 security_state_model_(new security_state::SecurityStateModel()) {
167 security_state_model_->SetDelegate(this);
168 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698