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

Side by Side Diff: ios/chrome/browser/ssl/ios_chrome_security_state_model_client.mm

Issue 2448943002: Refactor SecurityStateModel/Clients for simplicity and reusability. (Closed)
Patch Set: Remove *SecurityModelClient. Created 4 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 2016 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 "ios/chrome/browser/ssl/ios_chrome_security_state_model_client.h"
6
7 #include "base/command_line.h"
8 #include "base/metrics/field_trial.h"
9 #include "base/metrics/histogram_macros.h"
10 #include "ios/web/public/navigation_item.h"
11 #import "ios/web/public/navigation_manager.h"
12 #import "ios/web/public/origin_util.h"
13 #include "ios/web/public/security_style.h"
14 #include "ios/web/public/ssl_status.h"
15 #include "ios/web/public/web_state/web_state.h"
16 #include "net/cert/x509_certificate.h"
17
18 DEFINE_WEB_STATE_USER_DATA_KEY(IOSChromeSecurityStateModelClient);
19
20 namespace {
21
22 // Converts a web::SecurityStyle (an indicator of a request's
23 // overall security level computed by //ios/web) into a
24 // SecurityStateModel::SecurityLevel (a finer-grained SecurityStateModel
25 // concept that can express all of SecurityStateModel's policies that
26 // //ios/web doesn't necessarily know about).
27 security_state::SecurityStateModel::SecurityLevel
28 GetSecurityLevelForSecurityStyle(web::SecurityStyle style) {
29 switch (style) {
30 case web::SECURITY_STYLE_UNKNOWN:
31 NOTREACHED();
32 return security_state::SecurityStateModel::NONE;
33 case web::SECURITY_STYLE_UNAUTHENTICATED:
34 return security_state::SecurityStateModel::NONE;
35 case web::SECURITY_STYLE_AUTHENTICATION_BROKEN:
36 return security_state::SecurityStateModel::DANGEROUS;
37 case web::SECURITY_STYLE_WARNING:
38 // //ios/web currently doesn't use this style.
39 NOTREACHED();
40 return security_state::SecurityStateModel::SECURITY_WARNING;
41 case web::SECURITY_STYLE_AUTHENTICATED:
42 return security_state::SecurityStateModel::SECURE;
43 }
44 return security_state::SecurityStateModel::NONE;
45 }
46
47 } // namespace
48
49 IOSChromeSecurityStateModelClient::IOSChromeSecurityStateModelClient(
50 web::WebState* web_state)
51 : web_state_(web_state),
52 security_state_model_(new security_state::SecurityStateModel()) {
53 security_state_model_->SetClient(this);
54 }
55
56 IOSChromeSecurityStateModelClient::~IOSChromeSecurityStateModelClient() {}
57
58 void IOSChromeSecurityStateModelClient::GetSecurityInfo(
59 security_state::SecurityStateModel::SecurityInfo* result) const {
60 return security_state_model_->GetSecurityInfo(result);
61 }
62
63 bool IOSChromeSecurityStateModelClient::UsedPolicyInstalledCertificate() {
64 return false;
65 }
66
67 bool IOSChromeSecurityStateModelClient::IsOriginSecure(const GURL& url) {
68 return web::IsOriginSecure(url);
69 }
70
71 void IOSChromeSecurityStateModelClient::GetVisibleSecurityState(
72 security_state::SecurityStateModel::VisibleSecurityState* state) {
73 web::NavigationItem* item =
74 web_state_->GetNavigationManager()->GetVisibleItem();
75 if (!item || item->GetSSL().security_style == web::SECURITY_STYLE_UNKNOWN) {
76 *state = security_state::SecurityStateModel::VisibleSecurityState();
77 return;
78 }
79
80 state->connection_info_initialized = true;
81 state->url = item->GetURL();
82 const web::SSLStatus& ssl = item->GetSSL();
83 state->certificate = ssl.certificate;
84 state->cert_status = ssl.cert_status;
85 state->connection_status = ssl.connection_status;
86 state->security_bits = ssl.security_bits;
87 state->displayed_mixed_content =
88 (ssl.content_status & web::SSLStatus::DISPLAYED_INSECURE_CONTENT) ? true
89 : false;
90 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698