OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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 "ios/chrome/browser/ssl/ios_chrome_security_state_model_client.h" | 5 #include "ios/chrome/browser/ssl/ios_security_state_tab_helper.h" |
6 | 6 |
| 7 #include "base/bind.h" |
7 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/memory/ptr_util.h" |
8 #include "base/metrics/field_trial.h" | 10 #include "base/metrics/field_trial.h" |
9 #include "base/metrics/histogram_macros.h" | 11 #include "base/metrics/histogram_macros.h" |
| 12 #include "components/security_state/core/security_state.h" |
10 #include "ios/web/public/navigation_item.h" | 13 #include "ios/web/public/navigation_item.h" |
11 #import "ios/web/public/navigation_manager.h" | 14 #import "ios/web/public/navigation_manager.h" |
12 #import "ios/web/public/origin_util.h" | 15 #import "ios/web/public/origin_util.h" |
13 #include "ios/web/public/security_style.h" | 16 #include "ios/web/public/security_style.h" |
14 #include "ios/web/public/ssl_status.h" | 17 #include "ios/web/public/ssl_status.h" |
15 #include "ios/web/public/web_state/web_state.h" | 18 #include "ios/web/public/web_state/web_state.h" |
16 #include "net/cert/x509_certificate.h" | 19 #include "net/cert/x509_certificate.h" |
17 | 20 |
18 DEFINE_WEB_STATE_USER_DATA_KEY(IOSChromeSecurityStateModelClient); | 21 DEFINE_WEB_STATE_USER_DATA_KEY(IOSSecurityStateTabHelper); |
19 | 22 |
20 IOSChromeSecurityStateModelClient::IOSChromeSecurityStateModelClient( | 23 IOSSecurityStateTabHelper::IOSSecurityStateTabHelper(web::WebState* web_state) |
21 web::WebState* web_state) | 24 : web_state_(web_state) {} |
22 : web_state_(web_state), | 25 |
23 security_state_model_(new security_state::SecurityStateModel()) { | 26 IOSSecurityStateTabHelper::~IOSSecurityStateTabHelper() {} |
24 security_state_model_->SetClient(this); | 27 |
| 28 void IOSSecurityStateTabHelper::GetSecurityInfo( |
| 29 security_state::SecurityInfo* result) const { |
| 30 security_state::GetSecurityInfo(GetVisibleSecurityState(), |
| 31 false /* used policy installed certificate */, |
| 32 base::Bind(&web::IsOriginSecure), result); |
25 } | 33 } |
26 | 34 |
27 IOSChromeSecurityStateModelClient::~IOSChromeSecurityStateModelClient() {} | 35 std::unique_ptr<security_state::VisibleSecurityState> |
| 36 IOSSecurityStateTabHelper::GetVisibleSecurityState() const { |
| 37 auto state = base::MakeUnique<security_state::VisibleSecurityState>(); |
28 | 38 |
29 void IOSChromeSecurityStateModelClient::GetSecurityInfo( | |
30 security_state::SecurityStateModel::SecurityInfo* result) const { | |
31 return security_state_model_->GetSecurityInfo(result); | |
32 } | |
33 | |
34 bool IOSChromeSecurityStateModelClient::UsedPolicyInstalledCertificate() { | |
35 return false; | |
36 } | |
37 | |
38 bool IOSChromeSecurityStateModelClient::IsOriginSecure(const GURL& url) { | |
39 return web::IsOriginSecure(url); | |
40 } | |
41 | |
42 void IOSChromeSecurityStateModelClient::GetVisibleSecurityState( | |
43 security_state::SecurityStateModel::VisibleSecurityState* state) { | |
44 web::NavigationItem* item = | 39 web::NavigationItem* item = |
45 web_state_->GetNavigationManager()->GetVisibleItem(); | 40 web_state_->GetNavigationManager()->GetVisibleItem(); |
46 if (!item || item->GetSSL().security_style == web::SECURITY_STYLE_UNKNOWN) { | 41 if (!item || item->GetSSL().security_style == web::SECURITY_STYLE_UNKNOWN) |
47 *state = security_state::SecurityStateModel::VisibleSecurityState(); | 42 return state; |
48 return; | |
49 } | |
50 | 43 |
51 state->connection_info_initialized = true; | 44 state->connection_info_initialized = true; |
52 state->url = item->GetURL(); | 45 state->url = item->GetURL(); |
53 const web::SSLStatus& ssl = item->GetSSL(); | 46 const web::SSLStatus& ssl = item->GetSSL(); |
54 state->certificate = ssl.certificate; | 47 state->certificate = ssl.certificate; |
55 state->cert_status = ssl.cert_status; | 48 state->cert_status = ssl.cert_status; |
56 state->connection_status = ssl.connection_status; | 49 state->connection_status = ssl.connection_status; |
57 state->security_bits = ssl.security_bits; | 50 state->security_bits = ssl.security_bits; |
58 state->displayed_mixed_content = | 51 state->displayed_mixed_content = |
59 (ssl.content_status & web::SSLStatus::DISPLAYED_INSECURE_CONTENT) ? true | 52 (ssl.content_status & web::SSLStatus::DISPLAYED_INSECURE_CONTENT) ? true |
60 : false; | 53 : false; |
| 54 return state; |
61 } | 55 } |
OLD | NEW |